]> Creatis software - crea.git/blob - lib/creaDevManagerLib/wxCDMBlackBoxDescriptionPanel.cpp
c562ef74054392b4e6c70c6b3ca60baa5057d228
[crea.git] / lib / creaDevManagerLib / wxCDMBlackBoxDescriptionPanel.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  * wxCDMBlackBoxDescriptionPanel.cpp
30  *
31  *  Created on: Nov 27, 2012
32  *      Author: Daniel Felipe Gonzalez Obando
33  */
34
35 #include "wxCDMBlackBoxDescriptionPanel.h"
36
37 #include "wxCDMMainFrame.h"
38
39 #include "wxCDMBlackBoxHelpDialog.h"
40
41 #include "creaDevManagerIds.h"
42 #include "images/BBIcon64.xpm"
43
44 BEGIN_EVENT_TABLE(wxCDMBlackBoxDescriptionPanel, wxPanel)
45 EVT_HYPERLINK(ID_BUTTON_PREV, wxCDMBlackBoxDescriptionPanel::OnBtnReturn)
46 EVT_BUTTON(ID_BUTTON_SET_AUTHOR, wxCDMBlackBoxDescriptionPanel::OnBtnSetAuthor)
47 EVT_BUTTON(ID_BUTTON_SET_DESCRIPTION, wxCDMBlackBoxDescriptionPanel::OnBtnSetDescription)
48 EVT_BUTTON(ID_BUTTON_SET_CATEGORY, wxCDMBlackBoxDescriptionPanel::OnBtnSetCategories)
49 EVT_BUTTON(ID_BUTTON_OPEN_CXX, wxCDMBlackBoxDescriptionPanel::OnBtnOpenCxx)
50 EVT_BUTTON(ID_BUTTON_OPEN_HXX, wxCDMBlackBoxDescriptionPanel::OnBtnOpenHxx)
51 EVT_BUTTON(ID_BUTTON_OPEN_FOLDER, wxCDMBlackBoxDescriptionPanel::OnBtnOpenFolder)
52 END_EVENT_TABLE()
53
54 wxCDMBlackBoxDescriptionPanel::wxCDMBlackBoxDescriptionPanel(
55     wxWindow* parent,
56     modelCDMBlackBox* blackBox,
57     wxWindowID id,
58     const wxString& caption,
59     const wxPoint& pos,
60     const wxSize& size,
61     long style
62 )
63 {
64   wxCDMBlackBoxDescriptionPanel::Create(parent, blackBox, id, caption, pos, size, style);
65 }
66
67 wxCDMBlackBoxDescriptionPanel::~wxCDMBlackBoxDescriptionPanel()
68 {
69 }
70
71 bool wxCDMBlackBoxDescriptionPanel::Create(
72     wxWindow* parent,
73     modelCDMBlackBox* blackBox,
74     wxWindowID id,
75     const wxString& caption,
76     const wxPoint& pos,
77     const wxSize& size,
78     long style
79 )
80 {
81   wxPanel::Create(parent, id, pos, size, style);
82
83   // this part makes the scrollbars show up
84   this->FitInside(); // ask the sizer about the needed size
85   this->SetScrollRate(5, 5);
86
87   this->blackBox = blackBox;
88   CreateControls();
89   return TRUE;
90 }
91
92 void wxCDMBlackBoxDescriptionPanel::CreateControls()
93 {
94   wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
95
96   //Links to return
97   wxBoxSizer *linksSizer = new wxBoxSizer(wxHORIZONTAL);
98   std::vector<modelCDMIProjectTreeNode*> parents = this->blackBox->GetParents();
99   for (int i = 0; i < (int)(parents.size()); i++)
100     {
101       wxHyperlinkCtrl* returnLnk = new wxHyperlinkCtrl(this, ID_BUTTON_PREV, crea::std2wx(parents[parents.size()-1-i]->GetName()), crea::std2wx(parents[parents.size()-1-i]->GetPath()), wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE);
102       returnLnk->SetWindowStyle(wxNO_BORDER);
103       returnLnk->SetToolTip(crea::std2wx("Return to " + parents[parents.size()-1-i]->GetName() + "."));
104       linksSizer->Add(returnLnk, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 5);
105       linksSizer->Add(new wxStaticText(this,wxID_ANY, wxT("/")), 0, wxALIGN_CENTER, 0);
106     }
107
108   linksSizer->Add(new wxStaticText(this, wxID_ANY, crea::std2wx(this->blackBox->GetName())), 0, wxALIGN_CENTER, 0);
109
110   sizer->Add(linksSizer, 0, wxALIGN_CENTER | wxALL, 5);
111
112   //Header
113   wxBoxSizer* headerSizer = new wxBoxSizer(wxHORIZONTAL);
114   {
115     //Image
116     headerSizer->Add(new wxStaticBitmap(this, -1, wxBitmap(BBIcon64)),0, wxALIGN_CENTER, 0);
117     wxBoxSizer* textSizer = new wxBoxSizer(wxVERTICAL);
118     //Title
119     textSizer->Add(new wxStaticText(this, -1, _("Black Box")),0, wxALIGN_LEFT, 0);
120     //Black Box Name
121     textSizer->Add(new wxStaticText(this, -1, crea::std2wx(this->blackBox->GetNameBlackBox())),0, wxALIGN_LEFT, 0);
122     headerSizer->Add(textSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
123   }
124   sizer->Add(headerSizer, 0, wxALIGN_CENTER);
125
126   //BlackBox Properties
127   wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Properties"));
128   wxPanel* propertiesPanel = new wxPanel(this);
129   wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL);
130   wxFlexGridSizer* propertiesGridSizer = new wxFlexGridSizer(4, 2, 9, 15);
131
132   wxStaticText *pAuthor = new wxStaticText(propertiesPanel, -1, wxT("Author"));
133   wxStaticText *pDescription = new wxStaticText(propertiesPanel, -1, wxT("Description"));
134   wxStaticText *pCategories = new wxStaticText(propertiesPanel, -1, wxT("Categories"));
135
136   // author
137   wxBoxSizer* pAuthorsz = new wxBoxSizer(wxHORIZONTAL);
138   this->authortc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->blackBox->GetAuthors()));
139   wxButton* pAuthorbt = new wxButton(propertiesPanel, ID_BUTTON_SET_AUTHOR, wxT("Change"));
140   pAuthorbt->SetToolTip(wxT("Update the author/s of the package."));
141   pAuthorsz->Add(this->authortc, 1, wxALIGN_CENTER, 0);
142   pAuthorsz->Add(pAuthorbt, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 10);
143
144   // description
145   wxBoxSizer* pDescriptionsz = new wxBoxSizer(wxHORIZONTAL);
146   this->descriptiontc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->blackBox->GetDescription()));
147   wxButton* pDescriptionbt = new wxButton(propertiesPanel, ID_BUTTON_SET_DESCRIPTION, wxT("Change"));
148   pDescriptionbt->SetToolTip(wxT("Update the description of the project."));
149   pDescriptionsz->Add(this->descriptiontc, 1, wxALIGN_CENTER, 1);
150   pDescriptionsz->Add(pDescriptionbt, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 10);
151
152   // categories
153   wxBoxSizer* pCategoriessz = new wxBoxSizer(wxHORIZONTAL);
154   this->categoriestc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->blackBox->GetCategories()));
155   wxButton* pCategoriesbt = new wxButton(propertiesPanel, ID_BUTTON_SET_CATEGORY, wxT("Change"));
156   pCategoriesbt->SetToolTip(wxT("Update the categories of the project."));
157   pCategoriessz->Add(this->categoriestc, 1, wxALIGN_CENTER, 0);
158   pCategoriessz->Add(pCategoriesbt, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 10);
159
160   propertiesGridSizer->Add(pAuthor, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
161   propertiesGridSizer->Add(pAuthorsz, 1, wxEXPAND);
162   propertiesGridSizer->Add(pDescription, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
163   propertiesGridSizer->Add(pDescriptionsz, 1, wxEXPAND);
164   propertiesGridSizer->Add(pCategories, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
165   propertiesGridSizer->Add(pCategoriessz, 1, wxEXPAND);
166
167   propertiesGridSizer->AddGrowableCol(1,1);
168
169   propertiesPanelSizer -> Add(propertiesGridSizer, 1, wxEXPAND | wxALL, 5);
170   propertiesPanel->SetSizer(propertiesPanelSizer);
171   propertiesPanelSizer->Fit(propertiesPanel);
172   propertiesBox->Add(propertiesPanel, 1, wxEXPAND, 5);
173
174   sizer->Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
175
176
177   //Actions
178   wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions"));
179   wxPanel* actionsPanel = new wxPanel(this);
180   wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
181   //actionsGrid Sizer
182   wxFlexGridSizer* actionsGridSizer = new wxFlexGridSizer(2, 2, 9, 15);
183
184   wxButton* openHxxbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_HXX, _T("A. Open .h"));
185   openHxxbt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMBlackBoxDescriptionPanel::OnHxxMouseEnter,NULL,this);
186   openHxxbt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMBlackBoxDescriptionPanel::OnHxxMouseExit,NULL,this);
187   openHxxbt->SetToolTip(wxT("Open the .h file in the default text editor."));
188   actionsGridSizer->Add(openHxxbt, 1, wxALL | wxEXPAND, 5);
189   wxButton* openCxxbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_CXX, _T("B. Open .cxx"));
190   openCxxbt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMBlackBoxDescriptionPanel::OnCxxMouseEnter,NULL,this);
191   openCxxbt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMBlackBoxDescriptionPanel::OnCxxMouseExit,NULL,this);
192   openCxxbt->SetToolTip(wxT("Open the .cxx file in the default text editor."));
193   actionsGridSizer->Add(openCxxbt, 1, wxALL | wxEXPAND, 5);
194   wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("Open Source Folder"));
195   openFolderbt->SetToolTip(wxT("Open the source folder in the file explorer."));
196   actionsGridSizer->Add(openFolderbt, 1, wxALL | wxEXPAND, 5);
197
198   actionsGridSizer->AddGrowableCol(0,1);
199   actionsGridSizer->AddGrowableCol(1,1);
200
201   actionsPanelSizer->Add(actionsGridSizer, 1, wxEXPAND, 0);
202   actionsPanel->SetSizer(actionsPanelSizer);
203   actionsPanelSizer->Fit(actionsPanel);
204   actionsBox->Add(actionsPanel, 1, wxEXPAND);
205   sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 10);
206
207   //Assign sizer
208   SetSizer(sizer);
209   sizer->SetSizeHints(this);
210
211   if (((wxCDMMainFrame*)this->GetParent())->isHelp())
212     {
213       wxCDMBlackBoxHelpDialog* helpDialog = new wxCDMBlackBoxHelpDialog(this->GetParent(), this->blackBox, wxID_ANY);
214       helpDialog->Show(true);
215     }
216 }
217
218 void wxCDMBlackBoxDescriptionPanel::OnBtnReturn(wxHyperlinkEvent& event)
219 {
220   std::vector<modelCDMIProjectTreeNode*> parents = this->blackBox->GetParents();
221   std::string parentURL = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
222   //std::cout << parentURL << std::endl;
223   for (int i = 0; i < (int)(parents.size()); i++)
224     {
225       if (parents[i]->GetPath() == parentURL)
226         {
227           wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
228           newEvent->SetClientData(parents[i]);
229           newEvent->SetId(0);
230           wxPostEvent(this->GetParent(), *newEvent);
231         }
232     }
233
234 }
235
236 void wxCDMBlackBoxDescriptionPanel::OnBtnSetAuthor(wxCommandEvent& event)
237 {
238   //get author from user
239   wxTextEntryDialog* authDlg = new wxTextEntryDialog(
240       this,
241       wxT("Enter the new authors name. Separate each author with a '/'."),
242       wxT("Change Black Box Author - creaDevManager"),
243       crea::std2wx(this->blackBox->GetAuthors()),
244       wxOK | wxCANCEL
245   );
246
247   if (authDlg->ShowModal() == wxID_OK)
248     {
249       std::string authorsStr = crea::wx2std(authDlg->GetValue());
250       //check name
251       if(authorsStr.size() > 0)
252         {
253           std::string* result;
254           if(!this->blackBox->SetAuthors(authorsStr, result))
255             wxMessageBox(crea::std2wx(*result),_T("Change Black Box Author - Error!"),wxOK | wxICON_ERROR);
256
257         }
258
259       this->authortc->SetLabel(crea::std2wx(this->blackBox->GetAuthors()));
260       this->authortc->GetParent()->GetSizer()->RecalcSizes();
261     }
262
263 }
264
265 void wxCDMBlackBoxDescriptionPanel::OnBtnSetDescription(wxCommandEvent& event)
266 {
267   //get author from user
268   wxTextEntryDialog* descDlg = new wxTextEntryDialog(
269       this,
270       wxT("Edit the black box description."),
271       wxT("Change Black Box Description - creaDevManager"),
272       crea::std2wx(this->blackBox->GetDescription()),
273       wxTE_MULTILINE | wxOK | wxCANCEL
274   );
275
276   if (descDlg->ShowModal() == wxID_OK)
277     {
278       std::string descriptionStr = crea::wx2std(descDlg->GetValue());
279       //check name
280       if(descriptionStr.size() > 0)
281         {
282           std::string* result;
283           if(!this->blackBox->SetDescription(descriptionStr, result))
284             wxMessageBox(crea::std2wx(*result),_T("Change Black Box Description - Error!"),wxOK | wxICON_ERROR);
285         }
286       this->descriptiontc->SetLabel(crea::std2wx(this->blackBox->GetDescription()));
287       this->descriptiontc->GetParent()->GetSizer()->RecalcSizes();
288     }
289 }
290
291 void wxCDMBlackBoxDescriptionPanel::OnBtnSetCategories(wxCommandEvent& event)
292 {
293   //get author from user
294   wxTextEntryDialog* catsDlg = new wxTextEntryDialog(
295       this,
296       wxT("Edit the black box categories separated by '/'."),
297       wxT("Change Black Box Categories - creaDevManager"),
298       crea::std2wx(this->blackBox->GetCategories()),
299       wxTE_MULTILINE | wxOK | wxCANCEL
300   );
301
302   if (catsDlg->ShowModal() == wxID_OK)
303     {
304       std::string categoriesStr = crea::wx2std(catsDlg->GetValue());
305       //check name
306       if(categoriesStr.size() > 0)
307         {
308           std::string* result;
309           if(!this->blackBox->SetCategories(categoriesStr, result))
310             wxMessageBox(crea::std2wx(*result),_T("Change Black Box Categories - Error!"),wxOK | wxICON_ERROR);
311         }
312       this->categoriestc->SetLabel(crea::std2wx(this->blackBox->GetCategories()));
313       this->categoriestc->GetParent()->GetSizer()->RecalcSizes();
314     }
315 }
316
317 void wxCDMBlackBoxDescriptionPanel::OnBtnOpenCxx(wxCommandEvent& event)
318 {
319   std::string* result;
320   if(!this->blackBox->OpenCxx(result))
321     wxMessageBox(crea::std2wx(*result),_T("Open Source File - Error!"),wxOK | wxICON_ERROR);
322
323   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
324
325   if(this->blackBox->GetSourceFile() != NULL)
326     {
327       newEvent->SetClientData(this->blackBox->GetSourceFile());
328       newEvent->SetId(0);
329       wxPostEvent(this->GetParent(), *newEvent);
330     }
331
332   event.Skip();
333 }
334
335 void wxCDMBlackBoxDescriptionPanel::OnBtnOpenHxx(wxCommandEvent& event)
336 {
337   std::string* result;
338   if(!this->blackBox->OpenHxx(result))
339     wxMessageBox(crea::std2wx(*result),_T("Open Header File - Error!"),wxOK | wxICON_ERROR);
340
341   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
342
343   if(this->blackBox->GetHeaderFile() != NULL)
344     {
345       newEvent->SetClientData(this->blackBox->GetHeaderFile());
346       newEvent->SetId(0);
347       wxPostEvent(this->GetParent(), *newEvent);
348     }
349
350   event.Skip();
351 }
352
353 void wxCDMBlackBoxDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
354 {
355   std::string* result;
356   if(!this->blackBox->OpenInFileExplorer(result))
357     wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
358 }
359
360 void wxCDMBlackBoxDescriptionPanel::OnCxxMouseEnter(wxMouseEvent& event)
361 {
362   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
363
364   if(this->blackBox->GetSourceFile() != NULL)
365     {
366       newEvent->SetClientData(this->blackBox->GetSourceFile());
367       newEvent->SetId(0);
368       wxPostEvent(this->GetParent(), *newEvent);
369     }
370   event.Skip();
371 }
372
373 void wxCDMBlackBoxDescriptionPanel::OnCxxMouseExit(wxMouseEvent& event)
374 {
375   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
376
377   if(this->blackBox->GetSourceFile() != NULL)
378     {
379       newEvent->SetClientData(this->blackBox->GetSourceFile());
380       newEvent->SetId(0);
381       wxPostEvent(this->GetParent(), *newEvent);
382     }
383   event.Skip();
384 }
385
386 void wxCDMBlackBoxDescriptionPanel::OnHxxMouseEnter(wxMouseEvent& event)
387 {
388   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
389
390   if(this->blackBox->GetHeaderFile() != NULL)
391     {
392       newEvent->SetClientData(this->blackBox->GetHeaderFile());
393       newEvent->SetId(0);
394       wxPostEvent(this->GetParent(), *newEvent);
395     }
396   event.Skip();
397 }
398
399 void wxCDMBlackBoxDescriptionPanel::OnHxxMouseExit(wxMouseEvent& event)
400 {
401   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
402
403   if(this->blackBox->GetHeaderFile() != NULL)
404     {
405       newEvent->SetClientData(this->blackBox->GetHeaderFile());
406       newEvent->SetId(0);
407       wxPostEvent(this->GetParent(), *newEvent);
408     }
409   event.Skip();
410 }