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)
52 EVT_CHECKBOX(ID_CHECK_INCLUDE_3RDLIBRARY, wxCDMLibraryDescriptionPanel::On3rdLibraryChBChange)
53 EVT_CHECKBOX(ID_CHECK_INCLUDE_LIBRARY, wxCDMLibraryDescriptionPanel::OnLibraryChBChange)
56 wxCDMLibraryDescriptionPanel::wxCDMLibraryDescriptionPanel(
58 modelCDMLibrary* library,
60 const wxString& caption,
66 wxCDMLibraryDescriptionPanel::Create(parent, library, id, caption, pos, size, style);
69 wxCDMLibraryDescriptionPanel::~wxCDMLibraryDescriptionPanel()
73 bool wxCDMLibraryDescriptionPanel::Create(
75 modelCDMLibrary* library,
77 const wxString& caption,
83 wxPanel::Create(parent, id, pos, size, style);
84 this->library = library;
89 void wxCDMLibraryDescriptionPanel::CreateControls()
91 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
94 wxBoxSizer *linksSizer = new wxBoxSizer(wxHORIZONTAL);
95 std::vector<modelCDMIProjectTreeNode*> parents = this->library->GetParents();
96 for (int i = 0; i < (int)(parents.size()); i++)
98 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);
99 returnLnk->SetWindowStyle(wxNO_BORDER);
100 returnLnk->SetToolTip(crea::std2wx("Return to " + parents[parents.size()-1-i]->GetName() + "."));
101 linksSizer->Add(returnLnk, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 5);
102 linksSizer->Add(new wxStaticText(this,wxID_ANY, wxT("/")), 0, wxALIGN_CENTER, 0);
105 linksSizer->Add(new wxStaticText(this, wxID_ANY, crea::std2wx(this->library->GetName())), 0, wxALIGN_CENTER, 0);
107 sizer->Add(linksSizer, 0, wxALIGN_CENTER | wxALL, 5);
110 wxBoxSizer* headerSizer = new wxBoxSizer(wxHORIZONTAL);
113 headerSizer->Add(new wxStaticBitmap(this, -1, wxBitmap(LIcon64)),0, wxALIGN_CENTER, 0);
114 wxBoxSizer* textSizer = new wxBoxSizer(wxVERTICAL);
116 textSizer->Add(new wxStaticText(this, -1, _("Library")),0, wxALIGN_LEFT, 0);
118 textSizer->Add(new wxStaticText(this, -1, crea::std2wx(this->library->GetName())),0, wxALIGN_LEFT, 0);
119 headerSizer->Add(textSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
121 sizer->Add(headerSizer, 0, wxALIGN_CENTER);
124 wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Properties"));
125 wxPanel* propertiesPanel = new wxPanel(this);
126 wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL);
128 wxFlexGridSizer* propertiesGridSizer = new wxFlexGridSizer(4, 2, 9, 15);
130 wxStaticText *pMainFile = new wxStaticText(propertiesPanel, -1, wxT("Library Name"));
131 wxBoxSizer* pMainFilesz = new wxBoxSizer(wxHORIZONTAL);
132 this->libraryNametc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->library->GetNameLibrary()));
133 wxButton* pMainFilebt = new wxButton(propertiesPanel, ID_BUTTON_SET_NAME, wxT("Set"));
134 pMainFilebt->SetToolTip(wxT("Set the name of the library for the project."));
135 pMainFilesz->Add(this->libraryNametc, 0, wxALIGN_CENTER_VERTICAL, 0);
136 pMainFilesz->Add(pMainFilebt, 0, wxALIGN_CENTER | wxLEFT, 10);
138 propertiesGridSizer->Add(pMainFile, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
139 propertiesGridSizer->Add(pMainFilesz, 1, wxEXPAND);
141 propertiesGridSizer->AddGrowableCol(1,1);
143 propertiesPanelSizer->Add(propertiesGridSizer, 0, wxEXPAND);
144 propertiesPanel->SetSizer(propertiesPanelSizer);
145 propertiesPanelSizer->Fit(propertiesPanel);
146 propertiesBox->Add(propertiesPanel, 0, wxEXPAND);
147 sizer->Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
151 wxStaticBoxSizer* includesBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Used Libraries"));
152 wxPanel* includesPanel = new wxPanel(this);
153 wxBoxSizer* includesPanelSizer = new wxBoxSizer(wxVERTICAL);
155 //Third Party Libraries
156 wxStaticText* Title1 = new wxStaticText(includesPanel, wxID_ANY, wxT("Third Party Libraries:"));
157 wxFont font = Title1->GetFont();
158 font.SetWeight(wxFONTWEIGHT_BOLD);
159 Title1->SetFont(font);
160 includesPanelSizer->Add(Title1, 0, wxEXPAND | wxALL, 5);
163 std::map<std::string, bool> inclusions = this->library->Get3rdPartyLibraries();
165 wxFlexGridSizer* includesGridSizer = new wxFlexGridSizer(inclusions.size()+1, 2, 0, 5);
167 wxStaticText* ChBTitle = new wxStaticText(
175 wxStaticText* LNmTitle = new wxStaticText(
184 includesGridSizer->Add(ChBTitle, 1, wxEXPAND);
185 includesGridSizer->Add(LNmTitle, 1, wxEXPAND);
187 for (std::map<std::string, bool>::iterator it = inclusions.begin(); it != inclusions.end(); ++it) {
188 wxCheckBox* ChBIncl = new wxCheckBox(
189 includesPanel, ID_CHECK_INCLUDE_3RDLIBRARY, wxT(""), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT
191 ChBIncl->SetToolTip(crea::std2wx("When this box is checked the " + it->first + " library is included in the project configuration for this library."));
192 ChBIncl->SetName(crea::std2wx(it->first));
193 ChBIncl->SetValue(it->second);
194 includesGridSizer->Add(ChBIncl, 1, wxEXPAND);
196 wxStaticText* LNmIncl = new wxStaticText(includesPanel, wxID_ANY, crea::std2wx(it->first));
197 includesGridSizer->Add(LNmIncl, 1, wxEXPAND);
200 includesGridSizer->AddGrowableCol(1,1);
202 includesPanelSizer->Add(includesGridSizer, 1, wxEXPAND, 0);
205 wxStaticText* Title2 = new wxStaticText(includesPanel, wxID_ANY, wxT("Custom Libraries:"));
206 font = Title2->GetFont();
207 font.SetWeight(wxFONTWEIGHT_BOLD);
208 Title2->SetFont(font);
209 includesPanelSizer->Add(Title2, 0, wxEXPAND | wxALL, 5);
212 std::map<std::string, bool> inclusionsLibs = this->library->GetCustomLibraries();
214 wxFlexGridSizer* includesLibGridSizer = new wxFlexGridSizer(inclusionsLibs.size()+1, 2, 0, 5);
216 wxStaticText* ChBTitle1 = new wxStaticText(
224 wxStaticText* LNmTitle1 = new wxStaticText(
233 includesLibGridSizer->Add(ChBTitle1, 1, wxEXPAND);
234 includesLibGridSizer->Add(LNmTitle1, 1, wxEXPAND);
236 for (std::map<std::string, bool>::iterator it = inclusionsLibs.begin(); it != inclusionsLibs.end(); ++it) {
237 wxCheckBox* ChBIncl = new wxCheckBox(
238 includesPanel, ID_CHECK_INCLUDE_LIBRARY, wxT(""), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT
240 ChBIncl->SetToolTip(crea::std2wx("When this box is checked the " + it->first + " custom library is included in the project configuration for this library."));
241 ChBIncl->SetName(crea::std2wx(it->first));
242 ChBIncl->SetValue(it->second);
243 includesLibGridSizer->Add(ChBIncl, 1, wxEXPAND);
245 wxStaticText* LNmIncl = new wxStaticText(includesPanel, wxID_ANY, crea::std2wx(it->first));
246 includesLibGridSizer->Add(LNmIncl, 1, wxEXPAND);
249 includesLibGridSizer->AddGrowableCol(1,1);
251 includesPanelSizer->Add(includesLibGridSizer, 1, wxEXPAND, 0);
253 includesPanel->SetSizer(includesPanelSizer);
254 includesPanelSizer->Fit(includesPanel);
255 includesBox->Add(includesPanel, 1, wxEXPAND);
256 sizer -> Add(includesBox, 0, wxALL | wxEXPAND, 10);
261 wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions"));
262 wxPanel* actionsPanel = new wxPanel(this);
263 wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
266 wxFlexGridSizer* actionsGridSizer = new wxFlexGridSizer(2, 2, 9, 15);
268 wxButton* createClassbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_CLASS, _T("A. Create Class"));
269 createClassbt->SetToolTip(wxT("Create a new class for this library."));
270 actionsGridSizer->Add(createClassbt, 1, wxALL | wxEXPAND, 5);
271 wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("B. Open Library Folder"));
272 openFolderbt->SetToolTip(wxT("Open the library folder in the file explorer."));
273 actionsGridSizer->Add(openFolderbt, 1, wxALL | wxEXPAND, 5);
274 wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("C. Edit CMakeLists File"));
275 editCMakebt->SetToolTip(wxT("Edit the CMakeLists.txt of this library in the default text editor."));
276 editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMLibraryDescriptionPanel::OnCMakeMouseEnter,NULL,this);
277 editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMLibraryDescriptionPanel::OnCMakeMouseExit,NULL,this);
278 actionsGridSizer->Add(editCMakebt, 1, wxALL | wxEXPAND, 5);
279 wxButton* createFolderbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_FOLDER, _T("Create Folder (Optional)"));
280 createFolderbt->SetToolTip(wxT("Create a new folder for this library."));
281 actionsGridSizer->Add(createFolderbt, 1, wxALL | wxEXPAND, 5);
283 actionsGridSizer->AddGrowableCol(0,1);
284 actionsGridSizer->AddGrowableCol(1,1);
286 actionsPanelSizer->Add(actionsGridSizer, 1, wxEXPAND, 0);
287 actionsPanel->SetSizer(actionsPanelSizer);
288 actionsPanelSizer->Fit(actionsPanel);
289 actionsBox->Add(actionsPanel, 1, wxEXPAND);
290 sizer -> Add(actionsBox, 0, wxALL | wxEXPAND, 10);
294 sizer->SetSizeHints(this);
296 if (((wxCDMMainFrame*)this->GetParent())->isHelp())
298 wxCDMLibraryHelpDialog* helpDialog = new wxCDMLibraryHelpDialog(this->GetParent(), this->library, wxID_ANY);
299 helpDialog->Show(true);
303 void wxCDMLibraryDescriptionPanel::OnBtnReturn(wxHyperlinkEvent& event)
305 std::vector<modelCDMIProjectTreeNode*> parents = this->library->GetParents();
306 std::string parentURL = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
307 //std::cout << parentURL << std::endl;
308 for (int i = 0; i < (int)(parents.size()); i++)
310 if (parents[i]->GetPath() == parentURL)
312 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
313 newEvent->SetClientData(parents[i]);
315 wxPostEvent(this->GetParent(), *newEvent);
320 void wxCDMLibraryDescriptionPanel::OnBtnSetExeName(wxCommandEvent& event)
323 wxString versionWx = wxGetTextFromUser(
324 wxT("Enter the new executable name"),
325 wxT("Change Library Name - creaDevManager"),
326 crea::std2wx(this->library->GetNameLibrary())
329 std::vector<std::string> parts;
330 CDMUtilities::splitter::split(parts, crea::wx2std(versionWx), " .", CDMUtilities::splitter::no_empties);
334 if(!this->library->SetNameLibrary(crea::wx2std(versionWx), result))
335 wxMessageBox(crea::std2wx(*result),_T("Change Library Name - Error!"),wxOK | wxICON_ERROR);
339 wxMessageBox(crea::std2wx("No name specified"),_T("Set Library Name - Error!"),wxOK | wxICON_ERROR);
341 this->libraryNametc->SetLabel(crea::std2wx(this->library->GetNameLibrary()));
344 void wxCDMLibraryDescriptionPanel::On3rdLibraryChBChange(wxCommandEvent& event)
346 this->library->Set3rdPartyLibrary(crea::wx2std(((wxCheckBox*)event.GetEventObject())->GetName()), ((wxCheckBox*)event.GetEventObject())->GetValue());
349 void wxCDMLibraryDescriptionPanel::OnLibraryChBChange(wxCommandEvent& event)
351 this->library->SetCustomLibrary(crea::wx2std(((wxCheckBox*)event.GetEventObject())->GetName()), ((wxCheckBox*)event.GetEventObject())->GetValue());
354 void wxCDMLibraryDescriptionPanel::OnBtnCreateClass(wxCommandEvent& event)
356 //get class name from user
357 wxTextEntryDialog* newClassDlg = new wxTextEntryDialog(
359 wxT("Please enter the new class name."),
360 wxT("New Class - creaDevManager"),
365 if (newClassDlg->ShowModal() == wxID_OK)
367 std::string className = crea::wx2std(newClassDlg->GetValue());
369 if(className.size() > 0)
371 if(!this->library->CreateClass(className))
372 wxMessageBox(crea::std2wx("Something has gone wrong with the creation of the class."),_T("New Class - Error!"),wxOK | wxICON_ERROR);
374 ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
376 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
378 newEvent->SetClientData(this->library);
379 wxPostEvent(this->GetParent(), *newEvent);
381 wxMessageBox(crea::std2wx("The class has been created successfully."),_T("New Class - Success"),wxOK | wxICON_INFORMATION);
385 wxMessageBox(crea::std2wx("The new class name cannot be empty."),_T("New Class - Error!"),wxOK | wxICON_ERROR);
390 void wxCDMLibraryDescriptionPanel::OnBtnCreateFolder(wxCommandEvent& event)
393 wxString folderName = wxGetTextFromUser(
394 wxT("Enter the name of the new folder:"),
395 wxT("Create Folder - creaDevManager")
398 std::vector<std::string> parts;
399 CDMUtilities::splitter::split(parts, crea::wx2std(folderName), " /\\\"", CDMUtilities::splitter::no_empties);
403 modelCDMFolder* folderC = this->library->CreateFolder(crea::wx2std(folderName), result);
406 wxMessageBox(crea::std2wx(*result),_T("Create Folder - Error!"),wxOK | wxICON_ERROR);
409 ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
410 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
411 newEvent->SetClientData(folderC);
412 wxPostEvent(this->GetParent(), *newEvent);
413 wxMessageBox(crea::std2wx("The folder was successfully created"),_T("Create Folder - Success"),wxOK | wxICON_INFORMATION);
417 wxMessageBox(crea::std2wx("No name specified"),_T("Create Folder - Error!"),wxOK | wxICON_ERROR);
421 void wxCDMLibraryDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
424 if(!this->library->OpenCMakeListsFile(result))
425 wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
427 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
429 if(this->library->GetCMakeLists() != NULL)
431 newEvent->SetClientData(this->library->GetCMakeLists());
433 wxPostEvent(this->GetParent(), *newEvent);
439 void wxCDMLibraryDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
442 if(!this->library->OpenInFileExplorer(result))
443 wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
446 void wxCDMLibraryDescriptionPanel::OnCMakeMouseEnter(wxMouseEvent& event)
448 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
450 if(this->library->GetCMakeLists() != NULL)
452 newEvent->SetClientData(this->library->GetCMakeLists());
454 wxPostEvent(this->GetParent(), *newEvent);
459 void wxCDMLibraryDescriptionPanel::OnCMakeMouseExit(wxMouseEvent& event)
461 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
463 if(this->library->GetCMakeLists() != NULL)
465 newEvent->SetClientData(this->library->GetCMakeLists());
467 wxPostEvent(this->GetParent(), *newEvent);