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