]> 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_BUTTON(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   //Link to return
92   wxButton* returnbt = new wxButton(this, ID_BUTTON_PREV, wxT("Return to project"));
93   returnbt->SetToolTip(wxT("Return to the active project description."));
94   sizer->Add(returnbt, 0, wxALIGN_CENTER | wxALL, 5);
95
96   //Header
97   wxBoxSizer* headerSizer = new wxBoxSizer(wxHORIZONTAL);
98   {
99     //Image
100     headerSizer->Add(new wxStaticBitmap(this, -1, wxBitmap(BBIcon64)),0, wxALIGN_CENTER, 0);
101     wxBoxSizer* textSizer = new wxBoxSizer(wxVERTICAL);
102     //Title
103     textSizer->Add(new wxStaticText(this, -1, _("Black Box")),0, wxALIGN_LEFT, 0);
104     //Black Box Name
105     textSizer->Add(new wxStaticText(this, -1, crea::std2wx(this->blackBox->GetNameBlackBox())),0, wxALIGN_LEFT, 0);
106     headerSizer->Add(textSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
107   }
108   sizer->Add(headerSizer, 0, wxALIGN_CENTER);
109
110   //BlackBox Properties
111   wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Properties"));
112   wxPanel* propertiesPanel = new wxPanel(this);
113   wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL);
114   wxFlexGridSizer* propertiesGridSizer = new wxFlexGridSizer(4, 2, 9, 15);
115
116   wxStaticText *pAuthor = new wxStaticText(propertiesPanel, -1, wxT("Author"));
117   wxStaticText *pDescription = new wxStaticText(propertiesPanel, -1, wxT("Description"));
118   wxStaticText *pCategories = new wxStaticText(propertiesPanel, -1, wxT("Categories"));
119
120   // author
121   wxBoxSizer* pAuthorsz = new wxBoxSizer(wxHORIZONTAL);
122   this->authortc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->blackBox->GetAuthors()));
123   wxButton* pAuthorbt = new wxButton(propertiesPanel, ID_BUTTON_SET_AUTHOR, wxT("Change"));
124   pAuthorbt->SetToolTip(wxT("Update the author/s of the package."));
125   pAuthorsz->Add(this->authortc, 1, wxALIGN_CENTER, 0);
126   pAuthorsz->Add(pAuthorbt, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 10);
127
128   // description
129   wxBoxSizer* pDescriptionsz = new wxBoxSizer(wxHORIZONTAL);
130   this->descriptiontc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->blackBox->GetDescription()));
131   wxButton* pDescriptionbt = new wxButton(propertiesPanel, ID_BUTTON_SET_DESCRIPTION, wxT("Change"));
132   pDescriptionbt->SetToolTip(wxT("Update the description of the project."));
133   pDescriptionsz->Add(this->descriptiontc, 1, wxALIGN_CENTER, 1);
134   pDescriptionsz->Add(pDescriptionbt, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 10);
135
136   // categories
137   wxBoxSizer* pCategoriessz = new wxBoxSizer(wxHORIZONTAL);
138   this->categoriestc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->blackBox->GetCategories()));
139   wxButton* pCategoriesbt = new wxButton(propertiesPanel, ID_BUTTON_SET_CATEGORY, wxT("Change"));
140   pCategoriesbt->SetToolTip(wxT("Update the categories of the project."));
141   pCategoriessz->Add(this->categoriestc, 1, wxALIGN_CENTER, 0);
142   pCategoriessz->Add(pCategoriesbt, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 10);
143
144   propertiesGridSizer->Add(pAuthor, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
145   propertiesGridSizer->Add(pAuthorsz, 1, wxEXPAND);
146   propertiesGridSizer->Add(pDescription, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
147   propertiesGridSizer->Add(pDescriptionsz, 1, wxEXPAND);
148   propertiesGridSizer->Add(pCategories, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
149   propertiesGridSizer->Add(pCategoriessz, 1, wxEXPAND);
150
151   propertiesGridSizer->AddGrowableCol(1,1);
152
153   propertiesPanelSizer -> Add(propertiesGridSizer, 1, wxEXPAND | wxALL, 5);
154   propertiesPanel->SetSizer(propertiesPanelSizer);
155   propertiesPanelSizer->Fit(propertiesPanel);
156   propertiesBox->Add(propertiesPanel, 1, wxEXPAND, 5);
157
158   sizer->Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
159
160
161   //Actions
162   wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions"));
163   wxPanel* actionsPanel = new wxPanel(this);
164   wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
165   //actionsGrid Sizer
166   wxFlexGridSizer* actionsGridSizer = new wxFlexGridSizer(2, 2, 9, 15);
167
168   wxButton* openHxxbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_HXX, _T("A. Open .h"));
169   openHxxbt->SetToolTip(wxT("Open the .h file in the default text editor."));
170   actionsGridSizer->Add(openHxxbt, 1, wxALL | wxEXPAND, 5);
171   wxButton* openCxxbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_CXX, _T("B. Open .cxx"));
172   openCxxbt->SetToolTip(wxT("Open the .cxx file in the default text editor."));
173   actionsGridSizer->Add(openCxxbt, 1, wxALL | wxEXPAND, 5);
174   wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("C. Open Source Folder"));
175   openFolderbt->SetToolTip(wxT("Open the source folder in the file explorer."));
176   actionsGridSizer->Add(openFolderbt, 1, wxALL | wxEXPAND, 5);
177
178   actionsGridSizer->AddGrowableCol(0,1);
179   actionsGridSizer->AddGrowableCol(1,1);
180
181   actionsPanelSizer->Add(actionsGridSizer, 1, wxEXPAND, 0);
182   actionsPanel->SetSizer(actionsPanelSizer);
183   actionsPanelSizer->Fit(actionsPanel);
184   actionsBox->Add(actionsPanel, 1, wxEXPAND);
185   sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 10);
186
187   //Assign sizer
188   SetSizer(sizer);
189   sizer->SetSizeHints(this);
190
191   if (((wxCDMMainFrame*)this->GetParent())->isHelp())
192     {
193       wxCDMBlackBoxHelpDialog* helpDialog = new wxCDMBlackBoxHelpDialog(this->GetParent(), this->blackBox, wxID_ANY);
194       helpDialog->Show(true);
195     }
196 }
197
198 void wxCDMBlackBoxDescriptionPanel::OnBtnReturn(wxCommandEvent& event)
199 {
200   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
201   newEvent->SetInt(((wxCDMMainFrame*)this->GetParent())->GetModel()->GetProject()->GetId());
202   newEvent->SetId(0);
203   wxPostEvent(this->GetParent(), *newEvent);
204 }
205
206 void wxCDMBlackBoxDescriptionPanel::OnBtnSetAuthor(wxCommandEvent& event)
207 {
208   //get author from user
209   wxTextEntryDialog* authDlg = new wxTextEntryDialog(
210       this,
211       wxT("Enter the new authors name. Separate each author with a '/'."),
212       wxT("Change Black Box Author - creaDevManager"),
213       crea::std2wx(this->blackBox->GetAuthors()),
214       wxOK | wxCANCEL
215   );
216
217   if (authDlg->ShowModal() == wxID_OK)
218     {
219       std::string authorsStr = crea::wx2std(authDlg->GetValue());
220       //check name
221       if(authorsStr.size() > 0)
222         {
223           std::string* result;
224           if(!this->blackBox->SetAuthors(authorsStr, result))
225             wxMessageBox(crea::std2wx(*result),_T("Change Black Box Author - Error!"),wxOK | wxICON_ERROR);
226
227         }
228
229       this->authortc->SetLabel(crea::std2wx(this->blackBox->GetAuthors()));
230       this->authortc->GetParent()->GetSizer()->RecalcSizes();
231     }
232
233 }
234
235 void wxCDMBlackBoxDescriptionPanel::OnBtnSetDescription(wxCommandEvent& event)
236 {
237   //get author from user
238   wxTextEntryDialog* descDlg = new wxTextEntryDialog(
239       this,
240       wxT("Edit the black box description."),
241       wxT("Change Black Box Description - creaDevManager"),
242       crea::std2wx(this->blackBox->GetDescription()),
243       wxTE_MULTILINE | wxOK | wxCANCEL
244   );
245
246   if (descDlg->ShowModal() == wxID_OK)
247     {
248       std::string descriptionStr = crea::wx2std(descDlg->GetValue());
249       //check name
250       if(descriptionStr.size() > 0)
251         {
252           std::string* result;
253           if(!this->blackBox->SetDescription(descriptionStr, result))
254             wxMessageBox(crea::std2wx(*result),_T("Change Black Box Description - Error!"),wxOK | wxICON_ERROR);
255         }
256       this->descriptiontc->SetLabel(crea::std2wx(this->blackBox->GetDescription()));
257       this->descriptiontc->GetParent()->GetSizer()->RecalcSizes();
258     }
259 }
260
261 void wxCDMBlackBoxDescriptionPanel::OnBtnSetCategories(wxCommandEvent& event)
262 {
263   //get author from user
264   wxTextEntryDialog* catsDlg = new wxTextEntryDialog(
265       this,
266       wxT("Edit the black box categories separated by '/'."),
267       wxT("Change Black Box Categories - creaDevManager"),
268       crea::std2wx(this->blackBox->GetCategories()),
269       wxTE_MULTILINE | wxOK | wxCANCEL
270   );
271
272   if (catsDlg->ShowModal() == wxID_OK)
273     {
274       std::string categoriesStr = crea::wx2std(catsDlg->GetValue());
275       //check name
276       if(categoriesStr.size() > 0)
277         {
278           std::string* result;
279           if(!this->blackBox->SetCategories(categoriesStr, result))
280             wxMessageBox(crea::std2wx(*result),_T("Change Black Box Categories - Error!"),wxOK | wxICON_ERROR);
281         }
282       this->categoriestc->SetLabel(crea::std2wx(this->blackBox->GetCategories()));
283       this->categoriestc->GetParent()->GetSizer()->RecalcSizes();
284     }
285 }
286
287 void wxCDMBlackBoxDescriptionPanel::OnBtnOpenCxx(wxCommandEvent& event)
288 {
289   std::string* result;
290   if(!this->blackBox->OpenCxx(result))
291     wxMessageBox(crea::std2wx(*result),_T("Open Source File - Error!"),wxOK | wxICON_ERROR);
292 }
293
294 void wxCDMBlackBoxDescriptionPanel::OnBtnOpenHxx(wxCommandEvent& event)
295 {
296   std::string* result;
297   if(!this->blackBox->OpenHxx(result))
298     wxMessageBox(crea::std2wx(*result),_T("Open Header File - Error!"),wxOK | wxICON_ERROR);
299 }
300
301 void wxCDMBlackBoxDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
302 {
303   std::string* result;
304   if(!this->blackBox->OpenInFileExplorer(result))
305     wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
306 }