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;
86 // this part makes the scrollbars show up
87 this->FitInside(); // ask the sizer about the needed size
88 this->SetScrollRate(5, 5);
92 void wxCDMLibraryDescriptionPanel::CreateControls()
94 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
97 wxBoxSizer *linksSizer = new wxBoxSizer(wxHORIZONTAL);
98 std::vector<modelCDMIProjectTreeNode*> parents = this->library->GetParents();
99 for (int i = 0; i < (int)(parents.size()); i++)
101 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);
102 returnLnk->SetWindowStyle(wxNO_BORDER);
103 returnLnk->SetToolTip(crea::std2wx("Return to " + parents[parents.size()-1-i]->GetName() + "."));
104 linksSizer->Add(returnLnk, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 5);
105 linksSizer->Add(new wxStaticText(this,wxID_ANY, wxT("/")), 0, wxALIGN_CENTER, 0);
108 linksSizer->Add(new wxStaticText(this, wxID_ANY, crea::std2wx(this->library->GetName())), 0, wxALIGN_CENTER, 0);
110 sizer->Add(linksSizer, 0, wxALIGN_CENTER | wxALL, 5);
113 wxBoxSizer* headerSizer = new wxBoxSizer(wxHORIZONTAL);
116 headerSizer->Add(new wxStaticBitmap(this, -1, wxBitmap(LIcon64)),0, wxALIGN_CENTER, 0);
117 wxBoxSizer* textSizer = new wxBoxSizer(wxVERTICAL);
119 textSizer->Add(new wxStaticText(this, -1, _("Library")),0, wxALIGN_LEFT, 0);
121 textSizer->Add(new wxStaticText(this, -1, crea::std2wx(this->library->GetName())),0, wxALIGN_LEFT, 0);
122 headerSizer->Add(textSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
124 sizer->Add(headerSizer, 0, wxALIGN_CENTER);
127 wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Properties"));
128 wxPanel* propertiesPanel = new wxPanel(this);
129 wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL);
131 wxFlexGridSizer* propertiesGridSizer = new wxFlexGridSizer(4, 2, 9, 15);
133 wxStaticText *pMainFile = new wxStaticText(propertiesPanel, -1, wxT("Library Name"));
134 wxBoxSizer* pMainFilesz = new wxBoxSizer(wxHORIZONTAL);
135 this->libraryNametc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->library->GetNameLibrary()));
136 wxButton* pMainFilebt = new wxButton(propertiesPanel, ID_BUTTON_SET_NAME, wxT("Set"));
137 pMainFilebt->SetToolTip(wxT("Set the name of the library for the project."));
138 pMainFilesz->Add(this->libraryNametc, 0, wxALIGN_CENTER_VERTICAL, 0);
139 pMainFilesz->Add(pMainFilebt, 0, wxALIGN_CENTER | wxLEFT, 10);
141 propertiesGridSizer->Add(pMainFile, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
142 propertiesGridSizer->Add(pMainFilesz, 1, wxEXPAND);
144 propertiesGridSizer->AddGrowableCol(1,1);
146 propertiesPanelSizer->Add(propertiesGridSizer, 0, wxEXPAND);
147 propertiesPanel->SetSizer(propertiesPanelSizer);
148 propertiesPanelSizer->Fit(propertiesPanel);
149 propertiesBox->Add(propertiesPanel, 0, wxEXPAND);
150 sizer->Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
154 wxStaticBoxSizer* includesBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Used Libraries"));
155 includesBox->SetMinSize(250,250);
156 wxScrolledWindow* includesPanel = new wxScrolledWindow(this);
157 wxBoxSizer* includesPanelSizer = new wxBoxSizer(wxVERTICAL);
159 //Third Party Libraries
160 wxStaticText* Title1 = new wxStaticText(includesPanel, wxID_ANY, wxT("Third Party Libraries:"));
161 wxFont font = Title1->GetFont();
162 font.SetWeight(wxFONTWEIGHT_BOLD);
163 Title1->SetFont(font);
164 includesPanelSizer->Add(Title1, 0, wxEXPAND);
167 std::map<std::string, bool> inclusions = this->library->Get3rdPartyLibraries();
169 wxFlexGridSizer* includesGridSizer = new wxFlexGridSizer(inclusions.size()+1, 2, 0, 5);
171 wxStaticText* ChBTitle = new wxStaticText(
179 wxStaticText* LNmTitle = new wxStaticText(
188 includesGridSizer->Add(ChBTitle, 1, wxEXPAND);
189 includesGridSizer->Add(LNmTitle, 1, wxEXPAND);
191 for (std::map<std::string, bool>::iterator it = inclusions.begin(); it != inclusions.end(); ++it) {
192 wxCheckBox* ChBIncl = new wxCheckBox(
193 includesPanel, ID_CHECK_INCLUDE_3RDLIBRARY, wxT(""), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT
195 ChBIncl->SetToolTip(crea::std2wx("When this box is checked the " + it->first + " library is included in the project configuration for this library."));
196 ChBIncl->SetName(crea::std2wx(it->first));
197 ChBIncl->SetValue(it->second);
198 includesGridSizer->Add(ChBIncl, 1, wxEXPAND);
200 wxStaticText* LNmIncl = new wxStaticText(includesPanel, wxID_ANY, crea::std2wx(it->first));
201 includesGridSizer->Add(LNmIncl, 1, wxEXPAND);
204 includesGridSizer->AddGrowableCol(1,1);
206 includesPanelSizer->Add(includesGridSizer, 0, wxEXPAND | wxLEFT, 5);
209 wxStaticText* Title2 = new wxStaticText(includesPanel, wxID_ANY, wxT("Custom Libraries:"));
210 font = Title2->GetFont();
211 font.SetWeight(wxFONTWEIGHT_BOLD);
212 Title2->SetFont(font);
213 includesPanelSizer->Add(Title2, 0, wxEXPAND);
216 std::map<std::string, bool> inclusionsLibs = this->library->GetCustomLibraries();
218 wxFlexGridSizer* includesLibGridSizer = new wxFlexGridSizer(inclusionsLibs.size()+1, 2, 0, 5);
220 wxStaticText* ChBTitle1 = new wxStaticText(
228 wxStaticText* LNmTitle1 = new wxStaticText(
237 includesLibGridSizer->Add(ChBTitle1, 1, wxEXPAND);
238 includesLibGridSizer->Add(LNmTitle1, 1, wxEXPAND);
240 for (std::map<std::string, bool>::iterator it = inclusionsLibs.begin(); it != inclusionsLibs.end(); ++it) {
241 wxCheckBox* ChBIncl = new wxCheckBox(
242 includesPanel, ID_CHECK_INCLUDE_LIBRARY, wxT(""), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT
244 ChBIncl->SetToolTip(crea::std2wx("When this box is checked the " + it->first + " custom library is included in the project configuration for this library."));
245 ChBIncl->SetName(crea::std2wx(it->first));
246 ChBIncl->SetValue(it->second);
247 includesLibGridSizer->Add(ChBIncl, 1, wxEXPAND);
249 wxStaticText* LNmIncl = new wxStaticText(includesPanel, wxID_ANY, crea::std2wx(it->first));
250 includesLibGridSizer->Add(LNmIncl, 1, wxEXPAND);
253 includesLibGridSizer->AddGrowableCol(1,1);
255 includesPanelSizer->Add(includesLibGridSizer, 0, wxEXPAND | wxLEFT, 5);
257 includesPanel->SetSizer(includesPanelSizer);
258 includesPanelSizer->Fit(includesPanel);
260 includesPanel->FitInside();
261 includesPanel->SetScrollRate(5,5);
263 includesBox->Add(includesPanel, 1, wxEXPAND);
264 sizer -> Add(includesBox, 0, wxALL | wxEXPAND, 10);
269 wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions"));
270 wxPanel* actionsPanel = new wxPanel(this);
271 wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
274 wxFlexGridSizer* actionsGridSizer = new wxFlexGridSizer(2, 2, 9, 15);
276 wxButton* createClassbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_CLASS, _T("A. Create Class"));
277 createClassbt->SetToolTip(wxT("Create a new class for this library."));
278 actionsGridSizer->Add(createClassbt, 1, wxALL | wxEXPAND, 5);
279 wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("B. Open Library Folder"));
280 openFolderbt->SetToolTip(wxT("Open the library folder in the file explorer."));
281 actionsGridSizer->Add(openFolderbt, 1, wxALL | wxEXPAND, 5);
282 wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists File"));
283 editCMakebt->SetToolTip(wxT("Edit the CMakeLists.txt of this library in the default text editor."));
284 editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMLibraryDescriptionPanel::OnCMakeMouseEnter,NULL,this);
285 editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMLibraryDescriptionPanel::OnCMakeMouseExit,NULL,this);
286 actionsGridSizer->Add(editCMakebt, 1, wxALL | wxEXPAND, 5);
287 wxButton* createFolderbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_FOLDER, _T("Create Folder"));
288 createFolderbt->SetToolTip(wxT("Create a new folder for this library."));
289 actionsGridSizer->Add(createFolderbt, 1, wxALL | wxEXPAND, 5);
291 actionsGridSizer->AddGrowableCol(0,1);
292 actionsGridSizer->AddGrowableCol(1,1);
294 actionsPanelSizer->Add(actionsGridSizer, 1, wxEXPAND, 0);
295 actionsPanel->SetSizer(actionsPanelSizer);
296 actionsPanelSizer->Fit(actionsPanel);
297 actionsBox->Add(actionsPanel, 1, wxEXPAND);
298 sizer -> Add(actionsBox, 0, wxALL | wxEXPAND, 10);
302 sizer->SetSizeHints(this);
304 if (((wxCDMMainFrame*)this->GetParent())->isHelp())
306 wxCDMLibraryHelpDialog* helpDialog = new wxCDMLibraryHelpDialog(this->GetParent(), this->library, wxID_ANY);
307 helpDialog->Show(true);
311 void wxCDMLibraryDescriptionPanel::OnBtnReturn(wxHyperlinkEvent& event)
313 std::vector<modelCDMIProjectTreeNode*> parents = this->library->GetParents();
314 std::string parentURL = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
315 //std::cout << parentURL << std::endl;
316 for (int i = 0; i < (int)(parents.size()); i++)
318 if (parents[i]->GetPath() == parentURL)
320 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
321 newEvent->SetClientData(parents[i]);
323 wxPostEvent(this->GetParent(), *newEvent);
328 void wxCDMLibraryDescriptionPanel::OnBtnSetExeName(wxCommandEvent& event)
331 wxString versionWx = wxGetTextFromUser(
332 wxT("Enter the new executable name"),
333 wxT("Change Library Name - creaDevManager"),
334 crea::std2wx(this->library->GetNameLibrary())
337 std::vector<std::string> parts;
338 CDMUtilities::splitter::split(parts, crea::wx2std(versionWx), " .", CDMUtilities::splitter::no_empties);
342 if(!this->library->SetNameLibrary(crea::wx2std(versionWx), result))
343 wxMessageBox(crea::std2wx(*result),_T("Change Library Name - Error!"),wxOK | wxICON_ERROR);
347 wxMessageBox(crea::std2wx("No name specified"),_T("Set Library Name - Error!"),wxOK | wxICON_ERROR);
349 this->libraryNametc->SetLabel(crea::std2wx(this->library->GetNameLibrary()));
352 void wxCDMLibraryDescriptionPanel::On3rdLibraryChBChange(wxCommandEvent& event)
354 if(this->library->Set3rdPartyLibrary(crea::wx2std(((wxCheckBox*)event.GetEventObject())->GetName()), ((wxCheckBox*)event.GetEventObject())->GetValue()))
355 ((wxCheckBox*)event.GetEventObject())->SetValue(((wxCheckBox*)event.GetEventObject())->GetValue());
357 ((wxCheckBox*)event.GetEventObject())->SetValue(!((wxCheckBox*)event.GetEventObject())->GetValue());
360 void wxCDMLibraryDescriptionPanel::OnLibraryChBChange(wxCommandEvent& event)
362 this->library->SetCustomLibrary(crea::wx2std(((wxCheckBox*)event.GetEventObject())->GetName()), ((wxCheckBox*)event.GetEventObject())->GetValue());
365 void wxCDMLibraryDescriptionPanel::OnBtnCreateClass(wxCommandEvent& event)
367 //get class name from user
368 wxTextEntryDialog* newClassDlg = new wxTextEntryDialog(
370 wxT("Please enter the new class name."),
371 wxT("New Class - creaDevManager"),
376 if (newClassDlg->ShowModal() == wxID_OK)
378 std::string className = crea::wx2std(newClassDlg->GetValue());
380 if(className.size() > 0)
382 if(!this->library->CreateClass(className))
383 wxMessageBox(crea::std2wx("Something has gone wrong with the creation of the class."),_T("New Class - Error!"),wxOK | wxICON_ERROR);
385 ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
387 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
389 newEvent->SetClientData(this->library);
390 wxPostEvent(this->GetParent(), *newEvent);
392 wxMessageBox(crea::std2wx("The class has been created successfully."),_T("New Class - Success"),wxOK | wxICON_INFORMATION);
396 wxMessageBox(crea::std2wx("The new class name cannot be empty."),_T("New Class - Error!"),wxOK | wxICON_ERROR);
401 void wxCDMLibraryDescriptionPanel::OnBtnCreateFolder(wxCommandEvent& event)
404 wxString folderName = wxGetTextFromUser(
405 wxT("Enter the name of the new folder:"),
406 wxT("Create Folder - creaDevManager")
409 std::vector<std::string> parts;
410 CDMUtilities::splitter::split(parts, crea::wx2std(folderName), " /\\\"", CDMUtilities::splitter::no_empties);
414 modelCDMFolder* folderC = this->library->CreateFolder(crea::wx2std(folderName), result);
417 wxMessageBox(crea::std2wx(*result),_T("Create Folder - Error!"),wxOK | wxICON_ERROR);
420 ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
421 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
422 newEvent->SetClientData(folderC);
423 wxPostEvent(this->GetParent(), *newEvent);
424 wxMessageBox(crea::std2wx("The folder was successfully created"),_T("Create Folder - Success"),wxOK | wxICON_INFORMATION);
428 wxMessageBox(crea::std2wx("No name specified"),_T("Create Folder - Error!"),wxOK | wxICON_ERROR);
432 void wxCDMLibraryDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
435 if(!this->library->OpenCMakeListsFile(result))
436 wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
438 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
440 if(this->library->GetCMakeLists() != NULL)
442 newEvent->SetClientData(this->library->GetCMakeLists());
444 wxPostEvent(this->GetParent(), *newEvent);
450 void wxCDMLibraryDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
453 if(!this->library->OpenInFileExplorer(result))
454 wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
457 void wxCDMLibraryDescriptionPanel::OnCMakeMouseEnter(wxMouseEvent& event)
459 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
461 if(this->library->GetCMakeLists() != NULL)
463 newEvent->SetClientData(this->library->GetCMakeLists());
465 wxPostEvent(this->GetParent(), *newEvent);
470 void wxCDMLibraryDescriptionPanel::OnCMakeMouseExit(wxMouseEvent& event)
472 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
474 if(this->library->GetCMakeLists() != NULL)
476 newEvent->SetClientData(this->library->GetCMakeLists());
478 wxPostEvent(this->GetParent(), *newEvent);