]> Creatis software - crea.git/blob - lib/creaDevManagerLib/wxCDMPackageDescriptionPanel.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / wxCDMPackageDescriptionPanel.cpp
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 #                        pour la Sant�)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 #
10 #  This software is governed by the CeCILL-B license under French law and
11 #  abiding by the rules of distribution of free software. You can  use,
12 #  modify and/ or redistribute the software under the terms of the CeCILL-B
13 #  license as circulated by CEA, CNRS and INRIA at the following URL
14 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 #  or in the file LICENSE.txt.
16 #
17 #  As a counterpart to the access to the source code and  rights to copy,
18 #  modify and redistribute granted by the license, users are provided only
19 #  with a limited warranty  and the software's author,  the holder of the
20 #  economic rights,  and the successive licensors  have only  limited
21 #  liability.
22 #
23 #  The fact that you are presently reading this means that you have had
24 #  knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------
26  */
27
28 /*
29  * wxCDMPackageDescriptionPanel.cpp
30  *
31  *  Created on: Nov 27, 2012
32  *      Author: Daniel Felipe Gonzalez Obando
33  */
34
35 #include "wxCDMPackageDescriptionPanel.h"
36
37 #include "wxCDMMainFrame.h"
38
39 #include "creaDevManagerIds.h"
40 #include "images/PkIcon64.xpm"
41
42 BEGIN_EVENT_TABLE(wxCDMPackageDescriptionPanel, wxPanel)
43 EVT_BUTTON(ID_BUTTON_PREV, wxCDMPackageDescriptionPanel::OnBtnReturn)
44 EVT_HYPERLINK(ID_LINK_SELECT_BLACKBOX, wxCDMPackageDescriptionPanel::OnLnkBlackBoxSelect)
45 EVT_BUTTON(ID_BUTTON_CREATE_BLACKBOX, wxCDMPackageDescriptionPanel::OnBtnCreateBlackBox)
46 EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMPackageDescriptionPanel::OnBtnEditCMakeLists)
47 EVT_BUTTON(ID_BUTTON_OPEN_FOLDER, wxCDMPackageDescriptionPanel::OnBtnOpenFolder)
48 END_EVENT_TABLE()
49
50 wxCDMPackageDescriptionPanel::wxCDMPackageDescriptionPanel(
51     wxWindow* parent,
52     modelCDMPackage* package,
53     wxWindowID id,
54     const wxString& caption,
55     const wxPoint& pos,
56     const wxSize& size,
57     long style
58 )
59 {
60   wxCDMPackageDescriptionPanel::Create(parent, package, id, caption, pos, size, style);
61 }
62
63 wxCDMPackageDescriptionPanel::~wxCDMPackageDescriptionPanel()
64 {
65 }
66
67 bool wxCDMPackageDescriptionPanel::Create(
68     wxWindow* parent,
69     modelCDMPackage* package,
70     wxWindowID id,
71     const wxString& caption,
72     const wxPoint& pos,
73     const wxSize& size,
74     long style
75 )
76 {
77   wxPanel::Create(parent, id, pos, size, style);
78   this->package = package;
79   CreateControls();
80   return TRUE;
81 }
82
83 void wxCDMPackageDescriptionPanel::CreateControls()
84 {
85   wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
86
87   //Link to return
88   wxButton* returnbt = new wxButton(this, ID_BUTTON_PREV, wxT("Return to project"));
89   returnbt->SetToolTip(wxT("Return to the active project description."));
90   sizer->Add(returnbt, 0, wxALIGN_CENTER | wxALL, 5);
91
92   //Title
93   sizer->Add(new wxStaticText(this, -1, _("Package")),0, wxALIGN_CENTER, 0);
94
95   //Image
96   sizer->Add(new wxStaticBitmap(this, -1, wxBitmap(PkIcon64)),0, wxALIGN_CENTER, 0);
97
98   //Package Name
99   sizer->Add(new wxStaticText(this, -1, crea::std2wx(this->package->GetNamePackage())),0, wxALIGN_CENTER, 0);
100
101   //Package Properties
102   wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Properties"));
103   wxPanel* propertiesPanel = new wxPanel(this);
104   wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL);
105   wxFlexGridSizer* propertiesGridSizer = new wxFlexGridSizer(4, 2, 9, 15);
106
107   wxStaticText *pAuthor = new wxStaticText(propertiesPanel, -1, wxT("Author"));
108   wxStaticText *pVersion = new wxStaticText(propertiesPanel, -1, wxT("Version"));
109   wxStaticText *pDescription = new wxStaticText(propertiesPanel, -1, wxT("Description"));
110
111   // author
112   wxBoxSizer* pAuthorsz = new wxBoxSizer(wxHORIZONTAL);
113   wxStaticText* pAuthortc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->package->GetAuthors()));
114   wxButton* pAuthorbt = new wxButton(propertiesPanel, ID_BUTTON_SET_VERSION, wxT("Change"));
115   pAuthorbt->SetToolTip(wxT("Update the author/s of the package."));
116   pAuthorsz->Add(pAuthortc, 0, wxALIGN_CENTER_VERTICAL, 0);
117   pAuthorsz->Add(pAuthorbt, 0, wxALIGN_CENTER | wxLEFT, 10);
118
119   // version
120   wxBoxSizer* pVersionsz = new wxBoxSizer(wxHORIZONTAL);
121   wxStaticText* pVersiontc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->package->GetVersion()));
122   wxButton* pVersionbt = new wxButton(propertiesPanel, ID_BUTTON_SET_VERSION, wxT("Set"));
123   pVersionbt->SetToolTip(wxT("Update the version of the package."));
124   pVersionsz->Add(pVersiontc, 0, wxALIGN_CENTER_VERTICAL, 0);
125   pVersionsz->Add(pVersionbt, 0, wxALIGN_CENTER | wxLEFT, 10);
126
127   // description
128   wxBoxSizer* pDescriptionsz = new wxBoxSizer(wxHORIZONTAL);
129   wxStaticText* pDescriptiontc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->package->GetDescription()));
130   wxButton* pDescriptionbt = new wxButton(propertiesPanel, ID_BUTTON_SET_VERSION, wxT("Change"));
131   pDescriptionbt->SetToolTip(wxT("Update the description of the project."));
132   pDescriptionsz->Add(pDescriptiontc, 0, wxALIGN_CENTER_VERTICAL, 0);
133   pDescriptionsz->Add(pDescriptionbt, 0, wxALIGN_CENTER | wxLEFT, 10);
134
135   propertiesGridSizer->Add(pAuthor, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
136   propertiesGridSizer->Add(pAuthorsz, 1, wxEXPAND);
137   propertiesGridSizer->Add(pVersion, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
138   propertiesGridSizer->Add(pVersionsz, 1, wxEXPAND);
139   propertiesGridSizer->Add(pDescription, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
140   propertiesGridSizer->Add(pDescriptionsz, 1, wxEXPAND);
141
142   propertiesPanelSizer -> Add(propertiesGridSizer, 1, wxEXPAND);
143   propertiesPanel->SetSizer(propertiesPanelSizer);
144   propertiesPanelSizer->Fit(propertiesPanel);
145   propertiesBox->Add(propertiesPanel, 0, wxALL, 5);
146
147   sizer->Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
148
149   //Black Boxes
150   wxStaticBoxSizer* BBBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("A&vailable Black Boxes"));
151   BBBox->GetStaticBox()->SetToolTip(wxT("Select any of the available black boxes to see its details or modify them."));
152   wxPanel* BBPanel = new wxPanel(this);
153   wxBoxSizer* BBPanelSizer = new wxBoxSizer(wxVERTICAL);
154
155   std::vector<modelCDMBlackBox*> blackBoxes = this->package->GetBlackBoxes();
156   for (int i = 0; i < blackBoxes.size(); i++)
157     {
158       wxHyperlinkCtrl* pBBlk = new wxHyperlinkCtrl(BBPanel,ID_LINK_SELECT_BLACKBOX, crea::std2wx(blackBoxes[i]->GetName().c_str()), crea::std2wx(blackBoxes[i]->GetName().c_str()));
159       std::string tt = "Author: " + blackBoxes[i]->GetAuthors() + "\nDescription: " + blackBoxes[i]->GetDescription() + "\nCategories: " + blackBoxes[i]->GetCategories();
160       pBBlk->SetToolTip(crea::std2wx(tt));
161       pBBlk->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnMouseEnter,NULL,this);
162       pBBlk->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnMouseExit,NULL,this);
163       BBPanelSizer -> Add(pBBlk, 0, wxALIGN_LEFT | wxALL, 5);
164     }
165
166   BBPanel->SetSizer(BBPanelSizer);
167   BBPanelSizer->Fit(BBPanel);
168   BBBox->Add(BBPanel, 0, wxALL, 5);
169
170   sizer -> Add(BBBox, 0, wxEXPAND | wxALL, 10);
171
172   //Actions
173   wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions"));
174   wxPanel* actionsPanel = new wxPanel(this);
175   wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
176
177   wxButton* createBBbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_BLACKBOX, _T("Create Black Box"));
178   createBBbt->SetToolTip(wxT("Create a new black box for the active project inside this package."));
179   actionsPanelSizer->Add(createBBbt, 0, wxALL, 5);
180   wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists File"));
181   editCMakebt->SetToolTip(wxT("Open the system default text editor to edit the package's CMakeLists.txt file."));
182   editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnCMakeMouseEnter,NULL,this);
183   editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnCMakeMouseExit,NULL,this);
184   actionsPanelSizer->Add(editCMakebt, 0, wxALL, 5);
185   wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("Open Package Folder"));
186   openFolderbt->SetToolTip(wxT("Open the package folder in the file explorer."));
187   actionsPanelSizer->Add(openFolderbt, 0, wxALL, 5);
188
189   actionsPanel->SetSizer(actionsPanelSizer);
190   actionsPanelSizer->Fit(actionsPanel);
191   actionsBox->Add(actionsPanel, 0, wxEXPAND);
192   sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 10);
193
194   //Assign sizer
195   SetSizer(sizer);
196   sizer->SetSizeHints(this);
197 }
198
199 void wxCDMPackageDescriptionPanel::OnBtnReturn(wxCommandEvent& event)
200 {
201   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
202   newEvent->SetInt(((wxCDMMainFrame*)this->GetParent())->GetModel()->GetProject()->GetId());
203   newEvent->SetId(0);
204   wxPostEvent(this->GetParent(), *newEvent);
205 }
206
207 void wxCDMPackageDescriptionPanel::OnLnkBlackBoxSelect(wxHyperlinkEvent& event)
208 {
209   int bbId = 0;
210   std::vector<modelCDMBlackBox*> bbs = this->package->GetBlackBoxes();
211   for (int i = 0; i < bbs.size(); i++)
212     {
213       if(bbs[i]->GetName() == crea::wx2std(event.GetURL()))
214         {
215           bbId = bbs[i]->GetId();
216           break;
217         }
218     }
219
220   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
221   newEvent->SetInt(bbId);
222   newEvent->SetId(0);
223   wxPostEvent(this->GetParent(), *newEvent);
224
225   wxCommandEvent* newEvent1 = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
226   newEvent1->SetInt(bbId);
227   newEvent1->SetId(0);
228   wxPostEvent(this->GetParent(), *newEvent1);
229
230 }
231
232 void wxCDMPackageDescriptionPanel::OnBtnCreateBlackBox(wxCommandEvent& event)
233 {
234   //TODO: implement method
235   std::cerr << "Event OnBtnCreateBlackBox not implemented" << std::endl;
236   event.Skip();
237 }
238
239 void wxCDMPackageDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
240 {
241   //TODO: implement method
242   std::cerr << "Event OnBtnEditCMakeLists not implemented" << std::endl;
243
244   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
245
246   if(this->package->GetCMakeLists() != NULL)
247     {
248       int CMId = this->package->GetCMakeLists()->GetId();
249       newEvent->SetInt(CMId);
250       newEvent->SetId(0);
251       wxPostEvent(this->GetParent(), *newEvent);
252     }
253
254   event.Skip();
255 }
256
257 void wxCDMPackageDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
258 {
259   //TODO: implement method
260   std::cerr << "Event OnBtnOpenFolder not implemented" << std::endl;
261   event.Skip();
262 }
263
264 void wxCDMPackageDescriptionPanel::OnMouseEnter(wxMouseEvent& event)
265 {
266   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
267   std::string BBName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
268   int bbId = 0;
269   std::vector<modelCDMBlackBox*> boxes = this->package->GetBlackBoxes();
270   for (int i = 0; i < boxes.size(); i++)
271     {
272       if(boxes[i]->GetName() == BBName)
273         {
274           bbId = boxes[i]->GetId();
275           break;
276         }
277     }
278   newEvent->SetInt(bbId);
279   newEvent->SetId(0);
280   wxPostEvent(this->GetParent(), *newEvent);
281   event.Skip();
282 }
283
284 void wxCDMPackageDescriptionPanel::OnMouseExit(wxMouseEvent& event)
285 {
286   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
287   std::string BBName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
288   int bbId = 0;
289   std::vector<modelCDMBlackBox*> boxes = this->package->GetBlackBoxes();
290   for (int i = 0; i < boxes.size(); i++)
291     {
292       if(boxes[i]->GetName() == BBName)
293         {
294           bbId = boxes[i]->GetId();
295           break;
296         }
297     }
298   newEvent->SetInt(bbId);
299   newEvent->SetId(0);
300   wxPostEvent(this->GetParent(), *newEvent);
301   event.Skip();
302 }
303
304 void wxCDMPackageDescriptionPanel::OnCMakeMouseEnter(wxMouseEvent& event)
305 {
306   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
307
308   if(this->package->GetCMakeLists() != NULL)
309     {
310       int CMId = this->package->GetCMakeLists()->GetId();
311       newEvent->SetInt(CMId);
312       newEvent->SetId(0);
313       wxPostEvent(this->GetParent(), *newEvent);
314     }
315   event.Skip();
316 }
317
318 void wxCDMPackageDescriptionPanel::OnCMakeMouseExit(wxMouseEvent& event)
319 {
320   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
321
322   if(this->package->GetCMakeLists() != NULL)
323     {
324       int CMId = this->package->GetCMakeLists()->GetId();
325       newEvent->SetInt(CMId);
326       newEvent->SetId(0);
327       wxPostEvent(this->GetParent(), *newEvent);
328     }
329   event.Skip();
330 }
331
332