2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------
29 * wxCDMApplicationDescriptionPanel.cpp
31 * Created on: Nov 27, 2012
32 * Author: Daniel Felipe Gonzalez Obando
35 #include "wxCDMApplicationDescriptionPanel.h"
37 #include "CDMUtilities.h"
38 #include "wxCDMMainFrame.h"
40 #include "creaDevManagerIds.h"
41 #include "images/AIcon64.xpm"
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)
52 wxCDMApplicationDescriptionPanel::wxCDMApplicationDescriptionPanel(
54 modelCDMApplication* application,
56 const wxString& caption,
62 wxCDMApplicationDescriptionPanel::Create(parent, application, id, caption, pos, size, style);
65 wxCDMApplicationDescriptionPanel::~wxCDMApplicationDescriptionPanel()
69 bool wxCDMApplicationDescriptionPanel::Create(
71 modelCDMApplication* application,
73 const wxString& caption,
79 wxPanel::Create(parent, id, pos, size, style);
80 this->application = application;
85 void wxCDMApplicationDescriptionPanel::CreateControls()
87 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
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);
95 sizer->Add(new wxStaticText(this, -1, _("Application")),0, wxALIGN_CENTER, 0);
98 sizer->Add(new wxStaticBitmap(this, -1, wxBitmap(AIcon64)),0, wxALIGN_CENTER, 0);
101 sizer->Add(new wxStaticText(this, -1, crea::std2wx(this->application->GetName())),0, wxALIGN_CENTER, 0);
104 wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Properties"));
105 wxPanel* propertiesPanel = new wxPanel(this);
106 wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL);
108 wxFlexGridSizer* propertiesGridSizer = new wxFlexGridSizer(4, 2, 9, 15);
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);
118 propertiesGridSizer->Add(pMainFile, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
119 propertiesGridSizer->Add(pMainFilesz, 1, wxEXPAND);
121 propertiesGridSizer->AddGrowableCol(1,1);
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);
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."));
134 wxPanel* actionsPanel = new wxPanel(this);
136 wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
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."));
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);
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);
163 sizer->SetSizeHints(this);
166 void wxCDMApplicationDescriptionPanel::OnBtnReturn(wxCommandEvent& event)
168 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
169 newEvent->SetInt(((wxCDMMainFrame*)this->GetParent())->GetModel()->GetProject()->GetId());
171 wxPostEvent(this->GetParent(), *newEvent);
174 void wxCDMApplicationDescriptionPanel::OnBtnSetExeName(wxCommandEvent& event)
177 wxString versionWx = wxGetTextFromUser(
178 wxT("Enter the new executable name"),
179 wxT("Change Application Executable Name - creaDevManager"),
180 crea::std2wx(this->application->GetExecutableName())
183 std::vector<std::string> parts;
184 CDMUtilities::splitter::split(parts, crea::wx2std(versionWx), " .", CDMUtilities::splitter::no_empties);
188 if(!this->application->SetExecutableName(crea::wx2std(versionWx), result))
189 wxMessageBox(crea::std2wx(*result),_T("Change Application Executable Name - Error!"),wxOK | wxICON_ERROR);
193 wxMessageBox(crea::std2wx("No name specified"),_T("Set Application Executable Name - Error!"),wxOK | wxICON_ERROR);
195 this->executableNametc->SetLabel(crea::std2wx(this->application->GetExecutableName()));
198 void wxCDMApplicationDescriptionPanel::OnBtnCreateClass(wxCommandEvent& event)
200 //TODO: implement method
201 std::cerr << "Event OnBtnCreateClass not implemented" << std::endl;
205 void wxCDMApplicationDescriptionPanel::OnBtnCreateFolder(wxCommandEvent& event)
208 wxString folderName = wxGetTextFromUser(
209 wxT("Enter the name of the new folder:"),
210 wxT("Create Folder - creaDevManager")
213 std::vector<std::string> parts;
214 CDMUtilities::splitter::split(parts, crea::wx2std(folderName), " /\\\"", CDMUtilities::splitter::no_empties);
218 modelCDMFolder* folderC = this->application->CreateFolder(crea::wx2std(folderName), result);
221 wxMessageBox(crea::std2wx(*result),_T("Create Folder - Error!"),wxOK | wxICON_ERROR);
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);
232 wxMessageBox(crea::std2wx("No name specified"),_T("Create Folder - Error!"),wxOK | wxICON_ERROR);
236 void wxCDMApplicationDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
239 if(!this->application->OpenCMakeListsFile(result))
240 wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
242 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
244 if(this->application->GetCMakeLists() != NULL)
246 int CMId = this->application->GetCMakeLists()->GetId();
247 newEvent->SetInt(CMId);
249 wxPostEvent(this->GetParent(), *newEvent);
255 void wxCDMApplicationDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
258 if(!this->application->OpenInFileExplorer(result))
259 wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
262 void wxCDMApplicationDescriptionPanel::OnCMakeMouseEnter(wxMouseEvent& event)
264 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
266 if(this->application->GetCMakeLists() != NULL)
268 int CMId = this->application->GetCMakeLists()->GetId();
269 newEvent->SetInt(CMId);
271 wxPostEvent(this->GetParent(), *newEvent);
276 void wxCDMApplicationDescriptionPanel::OnCMakeMouseExit(wxMouseEvent& event)
278 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
280 if(this->application->GetCMakeLists() != NULL)
282 int CMId = this->application->GetCMakeLists()->GetId();
283 newEvent->SetInt(CMId);
285 wxPostEvent(this->GetParent(), *newEvent);