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