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 * wxCDMLibraryDescriptionPanel.cpp
31 * Created on: Nov 27, 2012
32 * Author: Daniel Felipe Gonzalez Obando
35 #include "wxCDMLibraryDescriptionPanel.h"
37 #include "CDMUtilities.h"
38 #include "wxCDMMainFrame.h"
40 #include "creaDevManagerIds.h"
41 #include "images/LIcon64.xpm"
43 BEGIN_EVENT_TABLE(wxCDMLibraryDescriptionPanel, wxPanel)
44 EVT_BUTTON(ID_BUTTON_PREV, wxCDMLibraryDescriptionPanel::OnBtnReturn)
45 EVT_BUTTON(ID_BUTTON_SET_NAME, wxCDMLibraryDescriptionPanel::OnBtnSetExeName)
46 EVT_BUTTON(ID_BUTTON_CREATE_CLASS, wxCDMLibraryDescriptionPanel::OnBtnCreateClass)
47 EVT_BUTTON(ID_BUTTON_CREATE_FOLDER, wxCDMLibraryDescriptionPanel::OnBtnCreateFolder)
48 EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMLibraryDescriptionPanel::OnBtnEditCMakeLists)
49 EVT_BUTTON(ID_BUTTON_OPEN_FOLDER, wxCDMLibraryDescriptionPanel::OnBtnOpenFolder)
52 wxCDMLibraryDescriptionPanel::wxCDMLibraryDescriptionPanel(
54 modelCDMLibrary* library,
56 const wxString& caption,
62 wxCDMLibraryDescriptionPanel::Create(parent, library, id, caption, pos, size, style);
65 wxCDMLibraryDescriptionPanel::~wxCDMLibraryDescriptionPanel()
69 bool wxCDMLibraryDescriptionPanel::Create(
71 modelCDMLibrary* library,
73 const wxString& caption,
79 wxPanel::Create(parent, id, pos, size, style);
80 this->library = library;
85 void wxCDMLibraryDescriptionPanel::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, _("Library")),0, wxALIGN_CENTER, 0);
98 sizer->Add(new wxStaticBitmap(this, -1, wxBitmap(LIcon64)),0, wxALIGN_CENTER, 0);
101 sizer->Add(new wxStaticText(this, -1, crea::std2wx(this->library->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("Library Name"));
111 wxBoxSizer* pMainFilesz = new wxBoxSizer(wxHORIZONTAL);
112 this->libraryNametc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->library->GetNameLibrary()));
113 wxButton* pMainFilebt = new wxButton(propertiesPanel, ID_BUTTON_SET_NAME, wxT("Set"));
114 pMainFilebt->SetToolTip(wxT("Set the name of the library for the project."));
115 pMainFilesz->Add(this->libraryNametc, 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 wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions"));
131 wxPanel* actionsPanel = new wxPanel(this);
132 wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
134 wxButton* createClassbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_CLASS, _T("Create Class"));
135 createClassbt->SetToolTip(wxT("Create a new class for this library."));
136 actionsPanelSizer->Add(createClassbt, 0, wxALL, 5);
137 wxButton* createFolderbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_FOLDER, _T("Create Folder"));
138 createFolderbt->SetToolTip(wxT("Create a new folder for this library."));
139 actionsPanelSizer->Add(createFolderbt, 0, wxALL, 5);
140 wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists File"));
141 editCMakebt->SetToolTip(wxT("Edit the CMakeLists.txt of this library in the default text editor."));
142 editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMLibraryDescriptionPanel::OnCMakeMouseEnter,NULL,this);
143 editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMLibraryDescriptionPanel::OnCMakeMouseExit,NULL,this);
144 actionsPanelSizer->Add(editCMakebt, 0, wxALL, 5);
145 wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("Open Library Folder"));
146 openFolderbt->SetToolTip(wxT("Open the library folder in the file explorer."));
147 actionsPanelSizer->Add(openFolderbt, 0, wxALL, 5);
149 actionsPanel->SetSizer(actionsPanelSizer);
150 actionsPanelSizer->Fit(actionsPanel);
151 actionsBox->Add(actionsPanel, 1, wxEXPAND);
152 sizer -> Add(actionsBox, 0, wxALL | wxEXPAND, 10);
156 sizer->SetSizeHints(this);
159 void wxCDMLibraryDescriptionPanel::OnBtnReturn(wxCommandEvent& event)
161 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
162 newEvent->SetInt(((wxCDMMainFrame*)this->GetParent())->GetModel()->GetProject()->GetId());
164 wxPostEvent(this->GetParent(), *newEvent);
167 void wxCDMLibraryDescriptionPanel::OnBtnSetExeName(wxCommandEvent& event)
170 wxString versionWx = wxGetTextFromUser(
171 wxT("Enter the new executable name"),
172 wxT("Change Library Name - creaDevManager"),
173 crea::std2wx(this->library->GetNameLibrary())
176 std::vector<std::string> parts;
177 CDMUtilities::splitter::split(parts, crea::wx2std(versionWx), " .", CDMUtilities::splitter::no_empties);
181 if(!this->library->SetNameLibrary(crea::wx2std(versionWx), result))
182 wxMessageBox(crea::std2wx(*result),_T("Change Library Name - Error!"),wxOK | wxICON_ERROR);
186 wxMessageBox(crea::std2wx("No name specified"),_T("Set Library Name - Error!"),wxOK | wxICON_ERROR);
188 this->libraryNametc->SetLabel(crea::std2wx(this->library->GetNameLibrary()));
191 void wxCDMLibraryDescriptionPanel::OnBtnCreateClass(wxCommandEvent& event)
193 //TODO: implement method
194 std::cerr << "Event OnBtnCreateClass not implemented" << std::endl;
198 void wxCDMLibraryDescriptionPanel::OnBtnCreateFolder(wxCommandEvent& event)
201 wxString folderName = wxGetTextFromUser(
202 wxT("Enter the name of the new folder:"),
203 wxT("Create Folder - creaDevManager")
206 std::vector<std::string> parts;
207 CDMUtilities::splitter::split(parts, crea::wx2std(folderName), " /\\\"", CDMUtilities::splitter::no_empties);
211 modelCDMFolder* folderC = this->library->CreateFolder(crea::wx2std(folderName), result);
214 wxMessageBox(crea::std2wx(*result),_T("Create Folder - Error!"),wxOK | wxICON_ERROR);
217 ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
218 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
219 newEvent->SetInt(folderC->GetId());
220 wxPostEvent(this->GetParent(), *newEvent);
221 wxMessageBox(crea::std2wx("The folder was successfully created"),_T("Create Folder - Success"),wxOK | wxICON_INFORMATION);
225 wxMessageBox(crea::std2wx("No name specified"),_T("Create Folder - Error!"),wxOK | wxICON_ERROR);
229 void wxCDMLibraryDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
232 if(!this->library->OpenCMakeListsFile(result))
233 wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
235 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
237 if(this->library->GetCMakeLists() != NULL)
239 int CMId = this->library->GetCMakeLists()->GetId();
240 newEvent->SetInt(CMId);
242 wxPostEvent(this->GetParent(), *newEvent);
248 void wxCDMLibraryDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
251 if(!this->library->OpenInFileExplorer(result))
252 wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
255 void wxCDMLibraryDescriptionPanel::OnCMakeMouseEnter(wxMouseEvent& event)
257 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
259 if(this->library->GetCMakeLists() != NULL)
261 int CMId = this->library->GetCMakeLists()->GetId();
262 newEvent->SetInt(CMId);
264 wxPostEvent(this->GetParent(), *newEvent);
269 void wxCDMLibraryDescriptionPanel::OnCMakeMouseExit(wxMouseEvent& event)
271 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
273 if(this->library->GetCMakeLists() != NULL)
275 int CMId = this->library->GetCMakeLists()->GetId();
276 newEvent->SetInt(CMId);
278 wxPostEvent(this->GetParent(), *newEvent);