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