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