]> Creatis software - crea.git/blob - lib/creaDevManagerLib/wxCDMBlackBoxDescriptionPanel.cpp
Black Box view and folder structure implemented
[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 "creaDevManagerIds.h"
40 #include "images/BBIcon64.xpm"
41
42 BEGIN_EVENT_TABLE(wxCDMBlackBoxDescriptionPanel, wxPanel)
43 EVT_BUTTON(ID_BUTTON_PREV, wxCDMBlackBoxDescriptionPanel::OnBtnReturn)
44 EVT_BUTTON(ID_BUTTON_SET_AUTHOR, wxCDMBlackBoxDescriptionPanel::OnBtnSetAuthor)
45 EVT_BUTTON(ID_BUTTON_SET_DESCRIPTION, wxCDMBlackBoxDescriptionPanel::OnBtnSetDescription)
46 EVT_BUTTON(ID_BUTTON_SET_CATEGORY, wxCDMBlackBoxDescriptionPanel::OnBtnSetCategories)
47 EVT_BUTTON(ID_BUTTON_OPEN_CXX, wxCDMBlackBoxDescriptionPanel::OnBtnOpenCxx)
48 EVT_BUTTON(ID_BUTTON_OPEN_HXX, wxCDMBlackBoxDescriptionPanel::OnBtnOpenHxx)
49 EVT_BUTTON(ID_BUTTON_OPEN_FOLDER, wxCDMBlackBoxDescriptionPanel::OnBtnOpenFolder)
50 END_EVENT_TABLE()
51
52 wxCDMBlackBoxDescriptionPanel::wxCDMBlackBoxDescriptionPanel(
53     wxWindow* parent,
54     modelCDMBlackBox* blackBox,
55     wxWindowID id,
56     const wxString& caption,
57     const wxPoint& pos,
58     const wxSize& size,
59     long style
60 )
61 {
62   wxCDMBlackBoxDescriptionPanel::Create(parent, blackBox, id, caption, pos, size, style);
63 }
64
65 wxCDMBlackBoxDescriptionPanel::~wxCDMBlackBoxDescriptionPanel()
66 {
67 }
68
69 bool wxCDMBlackBoxDescriptionPanel::Create(
70     wxWindow* parent,
71     modelCDMBlackBox* blackBox,
72     wxWindowID id,
73     const wxString& caption,
74     const wxPoint& pos,
75     const wxSize& size,
76     long style
77 )
78 {
79   wxPanel::Create(parent, id, pos, size, style);
80   this->blackBox = blackBox;
81   CreateControls();
82   return TRUE;
83 }
84
85 void wxCDMBlackBoxDescriptionPanel::CreateControls()
86 {
87   wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
88
89   //Link to return
90   wxButton* returnbt = new wxButton(this, ID_BUTTON_PREV, wxT("Return to project"));
91   returnbt->SetToolTip(wxT("Return to the active project description."));
92   sizer->Add(returnbt, 0, wxALIGN_CENTER | wxALL, 5);
93
94   //Welcome
95   sizer->Add(new wxStaticText(this, -1, _("Black Box")),0, wxALIGN_CENTER, 0);
96
97   //Image
98   sizer->Add(new wxStaticBitmap(this, -1, wxBitmap(BBIcon64)),0, wxALIGN_CENTER, 0);
99
100   //BlackBox Name
101   sizer->Add(new wxStaticText(this, -1, crea::std2wx(this->blackBox->GetNameBlackBox())),0, wxALIGN_CENTER, 0);
102
103   //BlackBox Properties
104   wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Properties"));
105   wxPanel* propertiesPanel = new wxPanel(this);
106   wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL);
107   wxFlexGridSizer* propertiesGridSizer = new wxFlexGridSizer(4, 2, 9, 15);
108
109   wxStaticText *pAuthor = new wxStaticText(propertiesPanel, -1, wxT("Author"));
110   wxStaticText *pDescription = new wxStaticText(propertiesPanel, -1, wxT("Description"));
111   wxStaticText *pCategories = new wxStaticText(propertiesPanel, -1, wxT("Categories"));
112
113   // author
114   wxBoxSizer* pAuthorsz = new wxBoxSizer(wxHORIZONTAL);
115   this->authortc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->blackBox->GetAuthors()));
116   wxButton* pAuthorbt = new wxButton(propertiesPanel, ID_BUTTON_SET_AUTHOR, wxT("Change"));
117   pAuthorbt->SetToolTip(wxT("Update the author/s of the package."));
118   pAuthorsz->Add(this->authortc, 0, wxALIGN_CENTER_VERTICAL, 0);
119   pAuthorsz->Add(pAuthorbt, 0, wxALIGN_CENTER | wxLEFT, 10);
120
121   // description
122   wxBoxSizer* pDescriptionsz = new wxBoxSizer(wxHORIZONTAL);
123   this->descriptiontc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->blackBox->GetDescription()));
124   wxButton* pDescriptionbt = new wxButton(propertiesPanel, ID_BUTTON_SET_DESCRIPTION, wxT("Change"));
125   pDescriptionbt->SetToolTip(wxT("Update the description of the project."));
126   pDescriptionsz->Add(this->descriptiontc, 0, wxALIGN_CENTER_VERTICAL, 0);
127   pDescriptionsz->Add(pDescriptionbt, 0, wxALIGN_CENTER | wxLEFT, 10);
128
129   // categories
130   wxBoxSizer* pCategoriessz = new wxBoxSizer(wxHORIZONTAL);
131   this->categoriestc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->blackBox->GetCategories()));
132   wxButton* pCategoriesbt = new wxButton(propertiesPanel, ID_BUTTON_SET_CATEGORY, wxT("Change"));
133   pCategoriesbt->SetToolTip(wxT("Update the categories of the project."));
134   pCategoriessz->Add(this->categoriestc, 0, wxALIGN_CENTER_VERTICAL, 0);
135   pCategoriessz->Add(pCategoriesbt, 0, wxALIGN_CENTER | wxLEFT, 10);
136
137   propertiesGridSizer->Add(pAuthor, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
138   propertiesGridSizer->Add(pAuthorsz, 1, wxEXPAND);
139   propertiesGridSizer->Add(pDescription, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
140   propertiesGridSizer->Add(pDescriptionsz, 1, wxEXPAND);
141   propertiesGridSizer->Add(pCategories, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
142   propertiesGridSizer->Add(pCategoriessz, 1, wxEXPAND);
143
144   propertiesGridSizer->AddGrowableCol(1,1);
145
146   propertiesPanelSizer -> Add(propertiesGridSizer, 1, wxEXPAND);
147   propertiesPanel->SetSizer(propertiesPanelSizer);
148   propertiesPanelSizer->Fit(propertiesPanel);
149   propertiesBox->Add(propertiesPanel, 0, wxALL, 5);
150
151   sizer->Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
152
153
154   //Actions
155   wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions"));
156   wxPanel* actionsPanel = new wxPanel(this);
157   wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
158
159   wxButton* openCxxbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_CXX, _T("Open .cxx"));
160   openCxxbt->SetToolTip(wxT("Open the .cxx file in the default text editor."));
161   actionsPanelSizer->Add(openCxxbt, 0, wxALL, 5);
162   wxButton* openHxxbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_HXX, _T("Open .h"));
163   openHxxbt->SetToolTip(wxT("Open the .h file in the default text editor."));
164   actionsPanelSizer->Add(openHxxbt, 0, wxALL, 5);
165   wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("Open Source Folder"));
166   openFolderbt->SetToolTip(wxT("Open the source folder in the file explorer."));
167   actionsPanelSizer->Add(openFolderbt, 0, wxALL, 5);
168
169   actionsPanel->SetSizer(actionsPanelSizer);
170   actionsPanelSizer->Fit(actionsPanel);
171   actionsBox->Add(actionsPanel, 0, wxEXPAND);
172   sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 10);
173
174   //Assign sizer
175   SetSizer(sizer);
176   sizer->SetSizeHints(this);
177 }
178
179 void wxCDMBlackBoxDescriptionPanel::OnBtnReturn(wxCommandEvent& event)
180 {
181   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
182   newEvent->SetInt(((wxCDMMainFrame*)this->GetParent())->GetModel()->GetProject()->GetId());
183   newEvent->SetId(0);
184   wxPostEvent(this->GetParent(), *newEvent);
185 }
186
187 void wxCDMBlackBoxDescriptionPanel::OnBtnSetAuthor(wxCommandEvent& event)
188 {
189   //get author from user
190   wxTextEntryDialog* authDlg = new wxTextEntryDialog(
191       this,
192       wxT("Enter the new authors name. Separate each author with a '/'."),
193       wxT("Change Black Box Author - creaDevManager"),
194       crea::std2wx(this->blackBox->GetAuthors()),
195       wxOK | wxCANCEL
196   );
197
198   if (authDlg->ShowModal() == wxID_OK)
199     {
200       std::string authorsStr = crea::wx2std(authDlg->GetValue());
201       //check name
202       if(authorsStr.size() > 0)
203         {
204           std::string* result;
205           if(!this->blackBox->SetAuthors(authorsStr, result))
206             wxMessageBox(crea::std2wx(*result),_T("Change Black Box Author - Error!"),wxOK | wxICON_ERROR);
207
208         }
209
210       this->authortc->SetLabel(crea::std2wx(this->blackBox->GetAuthors()));
211       this->authortc->GetParent()->GetSizer()->RecalcSizes();
212     }
213
214 }
215
216 void wxCDMBlackBoxDescriptionPanel::OnBtnSetDescription(wxCommandEvent& event)
217 {
218   //get author from user
219   wxTextEntryDialog* descDlg = new wxTextEntryDialog(
220       this,
221       wxT("Edit the black box description."),
222       wxT("Change Black Box Description - creaDevManager"),
223       crea::std2wx(this->blackBox->GetDescription()),
224       wxTE_MULTILINE | wxOK | wxCANCEL
225   );
226
227   if (descDlg->ShowModal() == wxID_OK)
228     {
229       std::string descriptionStr = crea::wx2std(descDlg->GetValue());
230       //check name
231       if(descriptionStr.size() > 0)
232         {
233           std::string* result;
234           if(!this->blackBox->SetDescription(descriptionStr, result))
235             wxMessageBox(crea::std2wx(*result),_T("Change Black Box Description - Error!"),wxOK | wxICON_ERROR);
236         }
237       this->descriptiontc->SetLabel(crea::std2wx(this->blackBox->GetDescription()));
238       this->descriptiontc->GetParent()->GetSizer()->RecalcSizes();
239     }
240 }
241
242 void wxCDMBlackBoxDescriptionPanel::OnBtnSetCategories(wxCommandEvent& event)
243 {
244   //get author from user
245   wxTextEntryDialog* catsDlg = new wxTextEntryDialog(
246       this,
247       wxT("Edit the black box categories separated by '/'."),
248       wxT("Change Black Box Categories - creaDevManager"),
249       crea::std2wx(this->blackBox->GetCategories()),
250       wxTE_MULTILINE | wxOK | wxCANCEL
251   );
252
253   if (catsDlg->ShowModal() == wxID_OK)
254     {
255       std::string categoriesStr = crea::wx2std(catsDlg->GetValue());
256       //check name
257       if(categoriesStr.size() > 0)
258         {
259           std::string* result;
260           if(!this->blackBox->SetCategories(categoriesStr, result))
261             wxMessageBox(crea::std2wx(*result),_T("Change Black Box Categories - Error!"),wxOK | wxICON_ERROR);
262         }
263       this->categoriestc->SetLabel(crea::std2wx(this->blackBox->GetCategories()));
264       this->categoriestc->GetParent()->GetSizer()->RecalcSizes();
265     }
266 }
267
268 void wxCDMBlackBoxDescriptionPanel::OnBtnOpenCxx(wxCommandEvent& event)
269 {
270   std::string* result;
271   if(!this->blackBox->OpenCxx(result))
272     wxMessageBox(crea::std2wx(*result),_T("Open Source File - Error!"),wxOK | wxICON_ERROR);
273 }
274
275 void wxCDMBlackBoxDescriptionPanel::OnBtnOpenHxx(wxCommandEvent& event)
276 {
277   std::string* result;
278   if(!this->blackBox->OpenHxx(result))
279     wxMessageBox(crea::std2wx(*result),_T("Open Header File - Error!"),wxOK | wxICON_ERROR);
280 }
281
282 void wxCDMBlackBoxDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
283 {
284   std::string* result;
285   if(!this->blackBox->OpenInFileExplorer(result))
286     wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
287 }