]> 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   //Header
97   wxBoxSizer* headerSizer = new wxBoxSizer(wxHORIZONTAL);
98   {
99     //Image
100     headerSizer->Add(new wxStaticBitmap(this, -1, wxBitmap(AIcon64)),0, wxALIGN_CENTER, 0);
101     wxBoxSizer* textSizer = new wxBoxSizer(wxVERTICAL);
102     //Title
103     textSizer->Add(new wxStaticText(this, -1, _("Application")),0, wxALIGN_LEFT, 0);
104     //Application Name
105     textSizer->Add(new wxStaticText(this, -1, crea::std2wx(this->application->GetName())),0, wxALIGN_LEFT, 0);
106     headerSizer->Add(textSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
107   }
108   sizer->Add(headerSizer, 0, wxALIGN_CENTER);
109
110   /*  //Properties
111   wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Properties"));
112   wxPanel* propertiesPanel = new wxPanel(this);
113   wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL);
114
115   wxFlexGridSizer* propertiesGridSizer = new wxFlexGridSizer(4, 2, 9, 15);
116
117   wxStaticText *pMainFile = new wxStaticText(propertiesPanel, -1, wxT("Executable Name"));
118   wxBoxSizer* pMainFilesz = new wxBoxSizer(wxHORIZONTAL);
119   this->executableNametc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->application->GetExecutableName()));
120   wxButton* pMainFilebt = new wxButton(propertiesPanel, ID_BUTTON_SET_NAME, wxT("Set"));
121   pMainFilebt->SetToolTip(wxT("Set the name of the executable file for the application."));
122   pMainFilesz->Add(this->executableNametc, 0, wxALIGN_CENTER_VERTICAL, 0);
123   pMainFilesz->Add(pMainFilebt, 0, wxALIGN_CENTER | wxLEFT, 10);
124
125   propertiesGridSizer->Add(pMainFile, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
126   propertiesGridSizer->Add(pMainFilesz, 1, wxEXPAND);
127
128   propertiesGridSizer->AddGrowableCol(1,1);
129
130   propertiesPanelSizer->Add(propertiesGridSizer, 0, wxEXPAND);
131   propertiesPanel->SetSizer(propertiesPanelSizer);
132   propertiesPanelSizer->Fit(propertiesPanel);
133   propertiesBox->Add(propertiesPanel, 0, wxEXPAND);
134   sizer->Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
135    */
136   //Actions
137   //actions StaticBoxSizer
138   wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Actions"));
139   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."));
140   //actions Panel
141   wxPanel* actionsPanel = new wxPanel(this);
142   //actions Sizer
143   wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
144   //actionsGrid Sizer
145   wxFlexGridSizer* actionsGridSizer = new wxFlexGridSizer(2, 2, 9, 15);
146
147   wxButton* createClassbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_CLASS, _T("A. Create Class"));
148   createClassbt->SetToolTip(wxT("Create a new Class (.h and .cxx files)."));
149   wxButton* createFolderbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_FOLDER, _T("Create Folder (Optional)"));
150   createFolderbt->SetToolTip(wxT("Create a new Folder inside the application folder."));
151   wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("B. Edit CMakeLists File"));
152   editCMakebt->SetToolTip(wxT("Edit the CMakeLists.txt file inside this application."));
153   editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMApplicationDescriptionPanel::OnCMakeMouseEnter,NULL,this);
154   editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMApplicationDescriptionPanel::OnCMakeMouseExit,NULL,this);
155   wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("C. Open Application Folder"));
156   openFolderbt->SetToolTip(wxT("Open the application folder in the file explorer."));
157
158
159   actionsGridSizer->Add(createClassbt, 1, wxALL | wxEXPAND, 5);
160   actionsGridSizer->Add(editCMakebt, 1, wxALL | wxEXPAND, 5);
161   actionsGridSizer->Add(openFolderbt, 1, wxALL | wxEXPAND, 5);
162   actionsGridSizer->Add(createFolderbt, 1, wxALL | wxEXPAND, 5);
163
164   //SetPanel sizer and box
165   actionsGridSizer->AddGrowableCol(0,1);
166   actionsGridSizer->AddGrowableCol(1,1);
167
168   actionsPanelSizer->Add(actionsGridSizer, 1, wxEXPAND, 0);
169   actionsPanel->SetSizer(actionsPanelSizer);
170   actionsPanelSizer->Fit(actionsPanel);
171   actionsBox->Add(actionsPanel, 1, wxALL | wxEXPAND, 5);
172   sizer->Add(actionsBox, 0, wxEXPAND | wxALL, 10);
173
174   //Assign sizer
175   SetSizer(sizer);
176   sizer->SetSizeHints(this);
177
178   if (((wxCDMMainFrame*)this->GetParent())->isHelp())
179     {
180       wxCDMApplicationHelpDialog* helpDialog = new wxCDMApplicationHelpDialog(this->GetParent(), this->application, wxID_ANY);
181       helpDialog->Show(true);
182     }
183 }
184
185 void wxCDMApplicationDescriptionPanel::OnBtnReturn(wxCommandEvent& event)
186 {
187   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
188   newEvent->SetInt(((wxCDMMainFrame*)this->GetParent())->GetModel()->GetProject()->GetId());
189   newEvent->SetId(0);
190   wxPostEvent(this->GetParent(), *newEvent);
191 }
192
193 void wxCDMApplicationDescriptionPanel::OnBtnSetExeName(wxCommandEvent& event)
194 {
195   //get name
196   wxString versionWx = wxGetTextFromUser(
197       wxT("Enter the new executable name"),
198       wxT("Change Application Executable Name - creaDevManager"),
199       crea::std2wx(this->application->GetExecutableName())
200   );
201   //check name
202   std::vector<std::string> parts;
203   CDMUtilities::splitter::split(parts, crea::wx2std(versionWx), " .", CDMUtilities::splitter::no_empties);
204   if(parts.size() > 0)
205     {
206       std::string* result;
207       if(!this->application->SetExecutableName(crea::wx2std(versionWx), result))
208         wxMessageBox(crea::std2wx(*result),_T("Change Application Executable Name - Error!"),wxOK | wxICON_ERROR);
209     }
210   else
211     {
212       wxMessageBox(crea::std2wx("No name specified"),_T("Set Application Executable Name - Error!"),wxOK | wxICON_ERROR);
213     }
214   this->executableNametc->SetLabel(crea::std2wx(this->application->GetExecutableName()));
215 }
216
217 void wxCDMApplicationDescriptionPanel::OnBtnCreateClass(wxCommandEvent& event)
218 {
219   //TODO: implement method
220   std::cerr << "Event OnBtnCreateClass not implemented" << std::endl;
221   event.Skip();
222 }
223
224 void wxCDMApplicationDescriptionPanel::OnBtnCreateFolder(wxCommandEvent& event)
225 {
226   //get name
227   wxString folderName = wxGetTextFromUser(
228       wxT("Enter the name of the new folder:"),
229       wxT("Create Folder - creaDevManager")
230   );
231   //check name
232   std::vector<std::string> parts;
233   CDMUtilities::splitter::split(parts, crea::wx2std(folderName), " /\\\"", CDMUtilities::splitter::no_empties);
234   if(parts.size() > 0)
235     {
236       std::string* result;
237       modelCDMFolder* folderC = this->application->CreateFolder(crea::wx2std(folderName), result);
238       if(folderC == NULL)
239         {
240           wxMessageBox(crea::std2wx(*result),_T("Create Folder - Error!"),wxOK | wxICON_ERROR);
241           return;
242         }
243       ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
244       wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
245       newEvent->SetInt(folderC->GetId());
246       wxPostEvent(this->GetParent(), *newEvent);
247       wxMessageBox(crea::std2wx("The folder was successfully created"),_T("Create Folder - Success"),wxOK | wxICON_INFORMATION);
248     }
249   else
250     {
251       wxMessageBox(crea::std2wx("No name specified"),_T("Create Folder - Error!"),wxOK | wxICON_ERROR);
252     }
253 }
254
255 void wxCDMApplicationDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
256 {
257   std::string* result;
258   if(!this->application->OpenCMakeListsFile(result))
259     wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
260
261   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
262
263   if(this->application->GetCMakeLists() != NULL)
264     {
265       int CMId = this->application->GetCMakeLists()->GetId();
266       newEvent->SetInt(CMId);
267       newEvent->SetId(0);
268       wxPostEvent(this->GetParent(), *newEvent);
269     }
270
271   event.Skip();
272 }
273
274 void wxCDMApplicationDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
275 {
276   std::string* result;
277   if(!this->application->OpenInFileExplorer(result))
278     wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
279 }
280
281 void wxCDMApplicationDescriptionPanel::OnCMakeMouseEnter(wxMouseEvent& event)
282 {
283   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
284
285   if(this->application->GetCMakeLists() != NULL)
286     {
287       int CMId = this->application->GetCMakeLists()->GetId();
288       newEvent->SetInt(CMId);
289       newEvent->SetId(0);
290       wxPostEvent(this->GetParent(), *newEvent);
291     }
292   event.Skip();
293 }
294
295 void wxCDMApplicationDescriptionPanel::OnCMakeMouseExit(wxMouseEvent& event)
296 {
297   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
298
299   if(this->application->GetCMakeLists() != NULL)
300     {
301       int CMId = this->application->GetCMakeLists()->GetId();
302       newEvent->SetInt(CMId);
303       newEvent->SetId(0);
304       wxPostEvent(this->GetParent(), *newEvent);
305     }
306   event.Skip();
307 }