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 "wxCDMLibraryHelpDialog.h"
42 #include "creaDevManagerIds.h"
43 #include "images/LIcon64.xpm"
45 BEGIN_EVENT_TABLE(wxCDMLibraryDescriptionPanel, wxPanel)
46 EVT_HYPERLINK(ID_BUTTON_PREV, wxCDMLibraryDescriptionPanel::OnBtnReturn)
47 EVT_BUTTON(ID_BUTTON_SET_NAME, wxCDMLibraryDescriptionPanel::OnBtnSetExeName)
48 EVT_BUTTON(ID_BUTTON_CREATE_CLASS, wxCDMLibraryDescriptionPanel::OnBtnCreateClass)
49 EVT_BUTTON(ID_BUTTON_CREATE_FOLDER, wxCDMLibraryDescriptionPanel::OnBtnCreateFolder)
50 EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMLibraryDescriptionPanel::OnBtnEditCMakeLists)
51 EVT_BUTTON(ID_BUTTON_OPEN_FOLDER, wxCDMLibraryDescriptionPanel::OnBtnOpenFolder)
54 wxCDMLibraryDescriptionPanel::wxCDMLibraryDescriptionPanel(
56 modelCDMLibrary* library,
58 const wxString& caption,
64 wxCDMLibraryDescriptionPanel::Create(parent, library, id, caption, pos, size, style);
67 wxCDMLibraryDescriptionPanel::~wxCDMLibraryDescriptionPanel()
71 bool wxCDMLibraryDescriptionPanel::Create(
73 modelCDMLibrary* library,
75 const wxString& caption,
81 wxPanel::Create(parent, id, pos, size, style);
82 this->library = library;
87 void wxCDMLibraryDescriptionPanel::CreateControls()
89 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
92 wxBoxSizer *linksSizer = new wxBoxSizer(wxHORIZONTAL);
93 std::vector<modelCDMIProjectTreeNode*> parents = this->library->GetParents();
94 for (int i = 0; i < parents.size(); i++)
96 wxHyperlinkCtrl* returnLnk = new wxHyperlinkCtrl(this, ID_BUTTON_PREV, crea::std2wx(parents[parents.size()-1-i]->GetName()), crea::std2wx(parents[parents.size()-1-i]->GetPath()));
97 returnLnk->SetToolTip(crea::std2wx("Return to " + parents[parents.size()-1-i]->GetName() + "."));
98 linksSizer->Add(returnLnk, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 5);
99 if (i < parents.size()-1)
101 linksSizer->Add(new wxStaticText(this,wxID_ANY, wxT("/")), 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(LIcon64)),0, wxALIGN_CENTER, 0);
111 wxBoxSizer* textSizer = new wxBoxSizer(wxVERTICAL);
113 textSizer->Add(new wxStaticText(this, -1, _("Library")),0, wxALIGN_LEFT, 0);
115 textSizer->Add(new wxStaticText(this, -1, crea::std2wx(this->library->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("Library Name"));
128 wxBoxSizer* pMainFilesz = new wxBoxSizer(wxHORIZONTAL);
129 this->libraryNametc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->library->GetNameLibrary()));
130 wxButton* pMainFilebt = new wxButton(propertiesPanel, ID_BUTTON_SET_NAME, wxT("Set"));
131 pMainFilebt->SetToolTip(wxT("Set the name of the library for the project."));
132 pMainFilesz->Add(this->libraryNametc, 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 wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions"));
148 wxPanel* actionsPanel = new wxPanel(this);
149 wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
152 wxFlexGridSizer* actionsGridSizer = new wxFlexGridSizer(2, 2, 9, 15);
154 wxButton* createClassbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_CLASS, _T("A. Create Class"));
155 createClassbt->SetToolTip(wxT("Create a new class for this library."));
156 actionsGridSizer->Add(createClassbt, 1, wxALL | wxEXPAND, 5);
157 wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("B. Edit CMakeLists File"));
158 editCMakebt->SetToolTip(wxT("Edit the CMakeLists.txt of this library in the default text editor."));
159 editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMLibraryDescriptionPanel::OnCMakeMouseEnter,NULL,this);
160 editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMLibraryDescriptionPanel::OnCMakeMouseExit,NULL,this);
161 actionsGridSizer->Add(editCMakebt, 1, wxALL | wxEXPAND, 5);
162 wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("C. Open Library Folder"));
163 openFolderbt->SetToolTip(wxT("Open the library folder in the file explorer."));
164 actionsGridSizer->Add(openFolderbt, 1, wxALL | wxEXPAND, 5);
165 wxButton* createFolderbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_FOLDER, _T("Create Folder (Optional)"));
166 createFolderbt->SetToolTip(wxT("Create a new folder for this library."));
167 actionsGridSizer->Add(createFolderbt, 1, wxALL | wxEXPAND, 5);
169 actionsGridSizer->AddGrowableCol(0,1);
170 actionsGridSizer->AddGrowableCol(1,1);
172 actionsPanelSizer->Add(actionsGridSizer, 1, wxEXPAND, 0);
173 actionsPanel->SetSizer(actionsPanelSizer);
174 actionsPanelSizer->Fit(actionsPanel);
175 actionsBox->Add(actionsPanel, 1, wxEXPAND);
176 sizer -> Add(actionsBox, 0, wxALL | wxEXPAND, 10);
180 sizer->SetSizeHints(this);
182 if (((wxCDMMainFrame*)this->GetParent())->isHelp())
184 wxCDMLibraryHelpDialog* helpDialog = new wxCDMLibraryHelpDialog(this->GetParent(), this->library, wxID_ANY);
185 helpDialog->Show(true);
189 void wxCDMLibraryDescriptionPanel::OnBtnReturn(wxHyperlinkEvent& event)
191 std::vector<modelCDMIProjectTreeNode*> parents = this->library->GetParents();
192 std::string parentURL = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
193 //std::cout << parentURL << std::endl;
194 for (int i = 0; i < parents.size(); i++)
196 if (parents[i]->GetPath() == parentURL)
198 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
199 newEvent->SetInt(parents[i]->GetId());
201 wxPostEvent(this->GetParent(), *newEvent);
206 void wxCDMLibraryDescriptionPanel::OnBtnSetExeName(wxCommandEvent& event)
209 wxString versionWx = wxGetTextFromUser(
210 wxT("Enter the new executable name"),
211 wxT("Change Library Name - creaDevManager"),
212 crea::std2wx(this->library->GetNameLibrary())
215 std::vector<std::string> parts;
216 CDMUtilities::splitter::split(parts, crea::wx2std(versionWx), " .", CDMUtilities::splitter::no_empties);
220 if(!this->library->SetNameLibrary(crea::wx2std(versionWx), result))
221 wxMessageBox(crea::std2wx(*result),_T("Change Library Name - Error!"),wxOK | wxICON_ERROR);
225 wxMessageBox(crea::std2wx("No name specified"),_T("Set Library Name - Error!"),wxOK | wxICON_ERROR);
227 this->libraryNametc->SetLabel(crea::std2wx(this->library->GetNameLibrary()));
230 void wxCDMLibraryDescriptionPanel::OnBtnCreateClass(wxCommandEvent& event)
232 //get class name from user
233 wxTextEntryDialog* newClassDlg = new wxTextEntryDialog(
235 wxT("Please enter the new class name."),
236 wxT("New Class - creaDevManager"),
241 if (newClassDlg->ShowModal() == wxID_OK)
243 std::string className = crea::wx2std(newClassDlg->GetValue());
245 if(className.size() > 0)
247 if(!this->library->CreateClass(className))
248 wxMessageBox(crea::std2wx("Something has gone wrong with the creation of the class."),_T("New Class - Error!"),wxOK | wxICON_ERROR);
250 ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
252 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
254 newEvent->SetInt(this->library->GetId());
255 wxPostEvent(this->GetParent(), *newEvent);
257 wxMessageBox(crea::std2wx("The class has been created successfully."),_T("New Class - Success"),wxOK | wxICON_INFORMATION);
261 wxMessageBox(crea::std2wx("The new class name cannot be empty."),_T("New Class - Error!"),wxOK | wxICON_ERROR);
266 void wxCDMLibraryDescriptionPanel::OnBtnCreateFolder(wxCommandEvent& event)
269 wxString folderName = wxGetTextFromUser(
270 wxT("Enter the name of the new folder:"),
271 wxT("Create Folder - creaDevManager")
274 std::vector<std::string> parts;
275 CDMUtilities::splitter::split(parts, crea::wx2std(folderName), " /\\\"", CDMUtilities::splitter::no_empties);
279 modelCDMFolder* folderC = this->library->CreateFolder(crea::wx2std(folderName), result);
282 wxMessageBox(crea::std2wx(*result),_T("Create Folder - Error!"),wxOK | wxICON_ERROR);
285 ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
286 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
287 newEvent->SetInt(folderC->GetId());
288 wxPostEvent(this->GetParent(), *newEvent);
289 wxMessageBox(crea::std2wx("The folder was successfully created"),_T("Create Folder - Success"),wxOK | wxICON_INFORMATION);
293 wxMessageBox(crea::std2wx("No name specified"),_T("Create Folder - Error!"),wxOK | wxICON_ERROR);
297 void wxCDMLibraryDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
300 if(!this->library->OpenCMakeListsFile(result))
301 wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
303 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
305 if(this->library->GetCMakeLists() != NULL)
307 int CMId = this->library->GetCMakeLists()->GetId();
308 newEvent->SetInt(CMId);
310 wxPostEvent(this->GetParent(), *newEvent);
316 void wxCDMLibraryDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
319 if(!this->library->OpenInFileExplorer(result))
320 wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
323 void wxCDMLibraryDescriptionPanel::OnCMakeMouseEnter(wxMouseEvent& event)
325 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
327 if(this->library->GetCMakeLists() != NULL)
329 int CMId = this->library->GetCMakeLists()->GetId();
330 newEvent->SetInt(CMId);
332 wxPostEvent(this->GetParent(), *newEvent);
337 void wxCDMLibraryDescriptionPanel::OnCMakeMouseExit(wxMouseEvent& event)
339 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
341 if(this->library->GetCMakeLists() != NULL)
343 int CMId = this->library->GetCMakeLists()->GetId();
344 newEvent->SetInt(CMId);
346 wxPostEvent(this->GetParent(), *newEvent);