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 "wxCDMApplicationHelpDialog.h"
42 #include "creaDevManagerIds.h"
43 #include "images/AIcon64.xpm"
45 BEGIN_EVENT_TABLE(wxCDMApplicationDescriptionPanel, wxPanel)
46 EVT_BUTTON(ID_BUTTON_SET_NAME, wxCDMApplicationDescriptionPanel::OnBtnSetExeName)
47 EVT_HYPERLINK(ID_BUTTON_PREV, wxCDMApplicationDescriptionPanel::OnBtnReturn)
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 EVT_BUTTON(ID_BUTTON_OPEN_CXX, wxCDMApplicationDescriptionPanel::OnBtnOpenMain)
55 wxCDMApplicationDescriptionPanel::wxCDMApplicationDescriptionPanel(
57 modelCDMApplication* application,
59 const wxString& caption,
65 wxCDMApplicationDescriptionPanel::Create(parent, application, id, caption, pos, size, style);
68 wxCDMApplicationDescriptionPanel::~wxCDMApplicationDescriptionPanel()
72 bool wxCDMApplicationDescriptionPanel::Create(
74 modelCDMApplication* application,
76 const wxString& caption,
82 wxPanel::Create(parent, id, pos, size, style);
83 this->application = application;
88 void wxCDMApplicationDescriptionPanel::CreateControls()
90 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
93 wxBoxSizer *linksSizer = new wxBoxSizer(wxHORIZONTAL);
94 std::vector<modelCDMIProjectTreeNode*> parents = this->application->GetParents();
95 for (int i = 0; i < (int)(parents.size()); i++)
97 wxHyperlinkCtrl* returnLnk = new wxHyperlinkCtrl(this, ID_BUTTON_PREV, crea::std2wx(parents[parents.size()-1-i]->GetName()), crea::std2wx(parents[parents.size()-1-i]->GetPath()), wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE);
98 returnLnk->SetWindowStyle(wxNO_BORDER);
99 returnLnk->SetToolTip(crea::std2wx("Return to " + parents[parents.size()-1-i]->GetName() + "."));
100 linksSizer->Add(returnLnk, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 5);
101 linksSizer->Add(new wxStaticText(this,wxID_ANY, wxT("/")), 0, wxALIGN_CENTER, 0);
103 linksSizer->Add(new wxStaticText(this, wxID_ANY, crea::std2wx(this->application->GetName())), 0, wxALIGN_CENTER, 0);
104 sizer->Add(linksSizer, 0, wxALIGN_CENTER | wxALL, 5);
107 wxBoxSizer* headerSizer = new wxBoxSizer(wxHORIZONTAL);
110 headerSizer->Add(new wxStaticBitmap(this, -1, wxBitmap(AIcon64)),0, wxALIGN_CENTER, 0);
111 wxBoxSizer* textSizer = new wxBoxSizer(wxVERTICAL);
113 textSizer->Add(new wxStaticText(this, -1, _("Application")),0, wxALIGN_LEFT, 0);
115 textSizer->Add(new wxStaticText(this, -1, crea::std2wx(this->application->GetName())),0, wxALIGN_LEFT, 0);
116 headerSizer->Add(textSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
118 sizer->Add(headerSizer, 0, wxALIGN_CENTER);
121 wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Properties"));
122 wxPanel* propertiesPanel = new wxPanel(this);
123 wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL);
125 wxFlexGridSizer* propertiesGridSizer = new wxFlexGridSizer(4, 2, 9, 15);
127 wxStaticText *pMainFile = new wxStaticText(propertiesPanel, -1, wxT("Executable Name"));
128 wxBoxSizer* pMainFilesz = new wxBoxSizer(wxHORIZONTAL);
129 this->executableNametc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->application->GetExecutableName()));
130 wxButton* pMainFilebt = new wxButton(propertiesPanel, ID_BUTTON_SET_NAME, wxT("Set"));
131 pMainFilebt->SetToolTip(wxT("Set the name of the executable file for the application."));
132 pMainFilesz->Add(this->executableNametc, 0, wxALIGN_CENTER_VERTICAL, 0);
133 pMainFilesz->Add(pMainFilebt, 0, wxALIGN_CENTER | wxLEFT, 10);
135 propertiesGridSizer->Add(pMainFile, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
136 propertiesGridSizer->Add(pMainFilesz, 1, wxEXPAND);
138 propertiesGridSizer->AddGrowableCol(1,1);
140 propertiesPanelSizer->Add(propertiesGridSizer, 0, wxEXPAND);
141 propertiesPanel->SetSizer(propertiesPanelSizer);
142 propertiesPanelSizer->Fit(propertiesPanel);
143 propertiesBox->Add(propertiesPanel, 0, wxEXPAND);
144 sizer->Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
147 //actions StaticBoxSizer
148 wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Actions"));
149 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."));
151 wxPanel* actionsPanel = new wxPanel(this);
153 wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
155 wxFlexGridSizer* actionsGridSizer = new wxFlexGridSizer(3, 2, 9, 15);
157 wxButton* createClassbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_CLASS, _T("Create Class (Optional)"));
158 createClassbt->SetToolTip(wxT("Create a new Class (.h and .cxx files)."));
159 wxButton* createFolderbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_FOLDER, _T("Create Folder (Optional)"));
160 createFolderbt->SetToolTip(wxT("Create a new Folder inside the application folder."));
161 wxButton* openMainbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_CXX, _T("A. Open Main File"));
162 openMainbt->SetToolTip(wxT("Open the main file in the application folder with the default code editor."));
163 openMainbt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMApplicationDescriptionPanel::OnMainMouseEnter,NULL,this);
164 openMainbt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMApplicationDescriptionPanel::OnMainMouseExit,NULL,this);
165 wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("C. Edit CMakeLists File"));
166 editCMakebt->SetToolTip(wxT("Edit the CMakeLists.txt file inside this application."));
167 editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMApplicationDescriptionPanel::OnCMakeMouseEnter,NULL,this);
168 editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMApplicationDescriptionPanel::OnCMakeMouseExit,NULL,this);
169 wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("B. Open Application Folder"));
170 openFolderbt->SetToolTip(wxT("Open the application folder in the file explorer."));
173 actionsGridSizer->Add(openMainbt, 1, wxALL | wxEXPAND, 5);
174 actionsGridSizer->Add(openFolderbt, 1, wxALL | wxEXPAND, 5);
175 actionsGridSizer->Add(editCMakebt, 1, wxALL | wxEXPAND, 5);
176 actionsGridSizer->Add(createClassbt, 1, wxALL | wxEXPAND, 5);
177 actionsGridSizer->Add(createFolderbt, 1, wxALL | wxEXPAND, 5);
179 //SetPanel sizer and box
180 actionsGridSizer->AddGrowableCol(0,1);
181 actionsGridSizer->AddGrowableCol(1,1);
183 actionsPanelSizer->Add(actionsGridSizer, 1, wxEXPAND, 0);
184 actionsPanel->SetSizer(actionsPanelSizer);
185 actionsPanelSizer->Fit(actionsPanel);
186 actionsBox->Add(actionsPanel, 1, wxALL | wxEXPAND, 5);
187 sizer->Add(actionsBox, 0, wxEXPAND | wxALL, 10);
191 sizer->SetSizeHints(this);
193 if (((wxCDMMainFrame*)this->GetParent())->isHelp())
195 wxCDMApplicationHelpDialog* helpDialog = new wxCDMApplicationHelpDialog(this->GetParent(), this->application, wxID_ANY);
196 helpDialog->Show(true);
200 void wxCDMApplicationDescriptionPanel::OnBtnReturn(wxHyperlinkEvent& event)
202 std::vector<modelCDMIProjectTreeNode*> parents = this->application->GetParents();
203 std::string parentURL = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
204 //std::cout << parentURL << std::endl;
205 for (int i = 0; i < (int)(parents.size()); i++)
207 if (parents[i]->GetPath() == parentURL)
209 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
210 newEvent->SetClientData(parents[i]);
212 wxPostEvent(this->GetParent(), *newEvent);
218 void wxCDMApplicationDescriptionPanel::OnBtnSetExeName(wxCommandEvent& event)
221 wxString versionWx = wxGetTextFromUser(
222 wxT("Enter the new executable name"),
223 wxT("Change Application Executable Name - creaDevManager"),
224 crea::std2wx(this->application->GetExecutableName())
227 std::vector<std::string> parts;
228 CDMUtilities::splitter::split(parts, crea::wx2std(versionWx), " .", CDMUtilities::splitter::no_empties);
232 if(!this->application->SetExecutableName(crea::wx2std(versionWx), result))
233 wxMessageBox(crea::std2wx(*result),_T("Change Application Executable Name - Error!"),wxOK | wxICON_ERROR);
237 wxMessageBox(crea::std2wx("No name specified"),_T("Set Application Executable Name - Error!"),wxOK | wxICON_ERROR);
239 this->executableNametc->SetLabel(crea::std2wx(this->application->GetExecutableName()));
242 void wxCDMApplicationDescriptionPanel::OnBtnCreateClass(wxCommandEvent& event)
244 //get class name from user
245 wxTextEntryDialog* newClassDlg = new wxTextEntryDialog(
247 wxT("Please enter the new class name."),
248 wxT("New Class - creaDevManager"),
253 if (newClassDlg->ShowModal() == wxID_OK)
255 std::string className = crea::wx2std(newClassDlg->GetValue());
257 if(className.size() > 0)
259 if(!this->application->CreateClass(className))
260 wxMessageBox(crea::std2wx("Something has gone wrong with the creation of the class."),_T("New Class - Error!"),wxOK | wxICON_ERROR);
262 ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
264 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
266 newEvent->SetClientData(this->application);
267 wxPostEvent(this->GetParent(), *newEvent);
269 wxMessageBox(crea::std2wx("The class has been created successfully."),_T("New Class - Success"),wxOK | wxICON_INFORMATION);
273 wxMessageBox(crea::std2wx("The new class name cannot be empty."),_T("New Class - Error!"),wxOK | wxICON_ERROR);
278 void wxCDMApplicationDescriptionPanel::OnBtnCreateFolder(wxCommandEvent& event)
281 wxString folderName = wxGetTextFromUser(
282 wxT("Enter the name of the new folder:"),
283 wxT("Create Folder - creaDevManager")
286 std::vector<std::string> parts;
287 CDMUtilities::splitter::split(parts, crea::wx2std(folderName), " /\\\"", CDMUtilities::splitter::no_empties);
291 modelCDMFolder* folderC = this->application->CreateFolder(crea::wx2std(folderName), result);
294 wxMessageBox(crea::std2wx(*result),_T("Create Folder - Error!"),wxOK | wxICON_ERROR);
297 ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
298 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
299 newEvent->SetClientData(folderC);
300 wxPostEvent(this->GetParent(), *newEvent);
301 wxMessageBox(crea::std2wx("The folder was successfully created"),_T("Create Folder - Success"),wxOK | wxICON_INFORMATION);
305 wxMessageBox(crea::std2wx("No name specified"),_T("Create Folder - Error!"),wxOK | wxICON_ERROR);
309 void wxCDMApplicationDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
312 if(!this->application->OpenCMakeListsFile(result))
313 wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
315 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
317 if(this->application->GetCMakeLists() != NULL)
319 newEvent->SetClientData(this->application->GetCMakeLists());
321 wxPostEvent(this->GetParent(), *newEvent);
327 void wxCDMApplicationDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
330 if(!this->application->OpenInFileExplorer(result))
331 wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
334 void wxCDMApplicationDescriptionPanel::OnCMakeMouseEnter(wxMouseEvent& event)
336 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
338 if(this->application->GetCMakeLists() != NULL)
340 newEvent->SetClientData(this->application->GetCMakeLists());
342 wxPostEvent(this->GetParent(), *newEvent);
347 void wxCDMApplicationDescriptionPanel::OnCMakeMouseExit(wxMouseEvent& event)
349 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
351 if(this->application->GetCMakeLists() != NULL)
353 newEvent->SetClientData(this->application->GetCMakeLists());
355 wxPostEvent(this->GetParent(), *newEvent);
360 void wxCDMApplicationDescriptionPanel::OnBtnOpenMain(wxCommandEvent& event)
362 if (this->application->GetMainFile() != NULL)
364 if (CDMUtilities::openTextEditor(this->application->GetMainFile()->GetPath()))
366 wxMessageBox(crea::std2wx("The main file couldn't be opened."),_T("Open Main File - Error!"),wxOK | wxICON_ERROR);
369 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
371 newEvent->SetClientData(this->application->GetMainFile());
373 wxPostEvent(this->GetParent(), *newEvent);
379 wxMessageBox(crea::std2wx("There is no main file or it couldn't be detected."),_T("Open Main File - Error!"),wxOK | wxICON_ERROR);
383 void wxCDMApplicationDescriptionPanel::OnMainMouseEnter(wxMouseEvent& event)
385 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
387 if(this->application->GetMainFile() != NULL)
389 newEvent->SetClientData(this->application->GetMainFile());
391 wxPostEvent(this->GetParent(), *newEvent);
396 void wxCDMApplicationDescriptionPanel::OnMainMouseExit(wxMouseEvent& event)
398 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
400 if(this->application->GetMainFile() != NULL)
402 newEvent->SetClientData(this->application->GetMainFile());
404 wxPostEvent(this->GetParent(), *newEvent);