]> Creatis software - crea.git/blob - lib/creaDevManagerLib/wxCDMApplicationDescriptionPanel.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / wxCDMApplicationDescriptionPanel.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  * wxCDMApplicationDescriptionPanel.cpp
30  *
31  *  Created on: Nov 27, 2012
32  *      Author: Daniel Felipe Gonzalez Obando
33  */
34
35 #include "wxCDMApplicationDescriptionPanel.h"
36
37 #include "CDMUtilities.h"
38 #include "wxCDMMainFrame.h"
39
40 #include "wxCDMApplicationHelpDialog.h"
41
42 #include "creaDevManagerIds.h"
43 #include "images/AIcon64.xpm"
44
45 BEGIN_EVENT_TABLE(wxCDMApplicationDescriptionPanel, wxPanel)
46 EVT_BUTTON(ID_BUTTON_PREV, wxCDMApplicationDescriptionPanel::OnBtnReturn)
47 EVT_BUTTON(ID_BUTTON_SET_NAME, wxCDMApplicationDescriptionPanel::OnBtnSetExeName)
48 EVT_BUTTON(ID_BUTTON_CREATE_CLASS, wxCDMApplicationDescriptionPanel::OnBtnCreateClass)
49 EVT_BUTTON(ID_BUTTON_CREATE_FOLDER, wxCDMApplicationDescriptionPanel::OnBtnCreateFolder)
50 EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMApplicationDescriptionPanel::OnBtnEditCMakeLists)
51 EVT_BUTTON(ID_BUTTON_OPEN_FOLDER, wxCDMApplicationDescriptionPanel::OnBtnOpenFolder)
52 END_EVENT_TABLE()
53
54 wxCDMApplicationDescriptionPanel::wxCDMApplicationDescriptionPanel(
55     wxWindow* parent,
56     modelCDMApplication* application,
57     wxWindowID id,
58     const wxString& caption,
59     const wxPoint& pos,
60     const wxSize& size,
61     long style
62 )
63 {
64   wxCDMApplicationDescriptionPanel::Create(parent, application, id, caption, pos, size, style);
65 }
66
67 wxCDMApplicationDescriptionPanel::~wxCDMApplicationDescriptionPanel()
68 {
69 }
70
71 bool wxCDMApplicationDescriptionPanel::Create(
72     wxWindow* parent,
73     modelCDMApplication* application,
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->application = application;
83   CreateControls();
84   return TRUE;
85 }
86
87 void wxCDMApplicationDescriptionPanel::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   //Title
97   sizer->Add(new wxStaticText(this, -1, _("Application")),0, wxALIGN_CENTER, 0);
98
99   //Image
100   sizer->Add(new wxStaticBitmap(this, -1, wxBitmap(AIcon64)),0, wxALIGN_CENTER, 0);
101
102   //Application Name
103   sizer->Add(new wxStaticText(this, -1, crea::std2wx(this->application->GetName())),0, wxALIGN_CENTER, 0);
104
105   //Properties
106   wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Properties"));
107   wxPanel* propertiesPanel = new wxPanel(this);
108   wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL);
109
110   wxFlexGridSizer* propertiesGridSizer = new wxFlexGridSizer(4, 2, 9, 15);
111
112   wxStaticText *pMainFile = new wxStaticText(propertiesPanel, -1, wxT("Executable Name"));
113   wxBoxSizer* pMainFilesz = new wxBoxSizer(wxHORIZONTAL);
114   this->executableNametc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->application->GetExecutableName()));
115   wxButton* pMainFilebt = new wxButton(propertiesPanel, ID_BUTTON_SET_NAME, wxT("Set"));
116   pMainFilebt->SetToolTip(wxT("Set the name of the executable file for the application."));
117   pMainFilesz->Add(this->executableNametc, 0, wxALIGN_CENTER_VERTICAL, 0);
118   pMainFilesz->Add(pMainFilebt, 0, wxALIGN_CENTER | wxLEFT, 10);
119
120   propertiesGridSizer->Add(pMainFile, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
121   propertiesGridSizer->Add(pMainFilesz, 1, wxEXPAND);
122
123   propertiesGridSizer->AddGrowableCol(1,1);
124
125   propertiesPanelSizer->Add(propertiesGridSizer, 0, wxEXPAND);
126   propertiesPanel->SetSizer(propertiesPanelSizer);
127   propertiesPanelSizer->Fit(propertiesPanel);
128   propertiesBox->Add(propertiesPanel, 0, wxEXPAND);
129   sizer->Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
130
131   //Actions
132   //actions StaticBoxSizer
133   wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Actions"));
134   actionsBox->GetStaticBox()->SetToolTip(wxT("Create classes or edit them for this application, as well as editing the application's CMakeLists.txt file by selecting the desired action."));
135   //actions Panel
136   wxPanel* actionsPanel = new wxPanel(this);
137   //actions Sizer
138   wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
139
140   wxButton* createClassbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_CLASS, _T("Create Class"));
141   createClassbt->SetToolTip(wxT("Create a new Class (.h and .cxx files)."));
142   wxButton* createFolderbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_FOLDER, _T("Create Folder"));
143   createFolderbt->SetToolTip(wxT("Create a new Folder inside the application folder."));
144   wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists File"));
145   editCMakebt->SetToolTip(wxT("Edit the CMakeLists.txt file inside this application."));
146   editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMApplicationDescriptionPanel::OnCMakeMouseEnter,NULL,this);
147   editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMApplicationDescriptionPanel::OnCMakeMouseExit,NULL,this);
148   wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("Open Application Folder"));
149   openFolderbt->SetToolTip(wxT("Open the application folder in the file explorer."));
150
151
152   actionsPanelSizer->Add(createClassbt, 0, wxALL, 5);
153   actionsPanelSizer->Add(createFolderbt, 0, wxALL, 5);
154   actionsPanelSizer->Add(editCMakebt, 0, wxALL, 5);
155   actionsPanelSizer->Add(openFolderbt, 0, wxALL, 5);
156
157   //SetPanel sizer and box
158   actionsPanel->SetSizer(actionsPanelSizer);
159   actionsPanelSizer->Fit(actionsPanel);
160   actionsBox->Add(actionsPanel, 0, wxALL, 5);
161   sizer->Add(actionsBox, 0, wxEXPAND | wxALL, 10);
162
163   //Assign sizer
164   SetSizer(sizer);
165   sizer->SetSizeHints(this);
166
167   if (((wxCDMMainFrame*)this->GetParent())->isHelp())
168     {
169       wxCDMApplicationHelpDialog* helpDialog = new wxCDMApplicationHelpDialog(this->GetParent(), this->application, wxID_ANY);
170       helpDialog->Show(true);
171     }
172 }
173
174 void wxCDMApplicationDescriptionPanel::OnBtnReturn(wxCommandEvent& event)
175 {
176   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
177   newEvent->SetInt(((wxCDMMainFrame*)this->GetParent())->GetModel()->GetProject()->GetId());
178   newEvent->SetId(0);
179   wxPostEvent(this->GetParent(), *newEvent);
180 }
181
182 void wxCDMApplicationDescriptionPanel::OnBtnSetExeName(wxCommandEvent& event)
183 {
184   //get name
185   wxString versionWx = wxGetTextFromUser(
186       wxT("Enter the new executable name"),
187       wxT("Change Application Executable Name - creaDevManager"),
188       crea::std2wx(this->application->GetExecutableName())
189   );
190   //check name
191   std::vector<std::string> parts;
192   CDMUtilities::splitter::split(parts, crea::wx2std(versionWx), " .", CDMUtilities::splitter::no_empties);
193   if(parts.size() > 0)
194     {
195       std::string* result;
196       if(!this->application->SetExecutableName(crea::wx2std(versionWx), result))
197         wxMessageBox(crea::std2wx(*result),_T("Change Application Executable Name - Error!"),wxOK | wxICON_ERROR);
198     }
199   else
200     {
201       wxMessageBox(crea::std2wx("No name specified"),_T("Set Application Executable Name - Error!"),wxOK | wxICON_ERROR);
202     }
203   this->executableNametc->SetLabel(crea::std2wx(this->application->GetExecutableName()));
204 }
205
206 void wxCDMApplicationDescriptionPanel::OnBtnCreateClass(wxCommandEvent& event)
207 {
208   //TODO: implement method
209   std::cerr << "Event OnBtnCreateClass not implemented" << std::endl;
210   event.Skip();
211 }
212
213 void wxCDMApplicationDescriptionPanel::OnBtnCreateFolder(wxCommandEvent& event)
214 {
215   //get name
216   wxString folderName = wxGetTextFromUser(
217       wxT("Enter the name of the new folder:"),
218       wxT("Create Folder - creaDevManager")
219   );
220   //check name
221   std::vector<std::string> parts;
222   CDMUtilities::splitter::split(parts, crea::wx2std(folderName), " /\\\"", CDMUtilities::splitter::no_empties);
223   if(parts.size() > 0)
224     {
225       std::string* result;
226       modelCDMFolder* folderC = this->application->CreateFolder(crea::wx2std(folderName), result);
227       if(folderC == NULL)
228         {
229           wxMessageBox(crea::std2wx(*result),_T("Create Folder - Error!"),wxOK | wxICON_ERROR);
230           return;
231         }
232       ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
233       wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
234       newEvent->SetInt(folderC->GetId());
235       wxPostEvent(this->GetParent(), *newEvent);
236       wxMessageBox(crea::std2wx("The folder was successfully created"),_T("Create Folder - Success"),wxOK | wxICON_INFORMATION);
237     }
238   else
239     {
240       wxMessageBox(crea::std2wx("No name specified"),_T("Create Folder - Error!"),wxOK | wxICON_ERROR);
241     }
242 }
243
244 void wxCDMApplicationDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
245 {
246   std::string* result;
247   if(!this->application->OpenCMakeListsFile(result))
248     wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
249
250   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
251
252   if(this->application->GetCMakeLists() != NULL)
253     {
254       int CMId = this->application->GetCMakeLists()->GetId();
255       newEvent->SetInt(CMId);
256       newEvent->SetId(0);
257       wxPostEvent(this->GetParent(), *newEvent);
258     }
259
260   event.Skip();
261 }
262
263 void wxCDMApplicationDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
264 {
265   std::string* result;
266   if(!this->application->OpenInFileExplorer(result))
267     wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
268 }
269
270 void wxCDMApplicationDescriptionPanel::OnCMakeMouseEnter(wxMouseEvent& event)
271 {
272   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
273
274   if(this->application->GetCMakeLists() != NULL)
275     {
276       int CMId = this->application->GetCMakeLists()->GetId();
277       newEvent->SetInt(CMId);
278       newEvent->SetId(0);
279       wxPostEvent(this->GetParent(), *newEvent);
280     }
281   event.Skip();
282 }
283
284 void wxCDMApplicationDescriptionPanel::OnCMakeMouseExit(wxMouseEvent& event)
285 {
286   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
287
288   if(this->application->GetCMakeLists() != NULL)
289     {
290       int CMId = this->application->GetCMakeLists()->GetId();
291       newEvent->SetInt(CMId);
292       newEvent->SetId(0);
293       wxPostEvent(this->GetParent(), *newEvent);
294     }
295   event.Skip();
296 }