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