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 < (int)(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()), wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE);
97 returnLnk->SetWindowStyle(wxNO_BORDER);
98 returnLnk->SetToolTip(crea::std2wx("Return to " + parents[parents.size()-1-i]->GetName() + "."));
99 linksSizer->Add(returnLnk, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 5);
100 if (i < (int)(parents.size())-1)
102 linksSizer->Add(new wxStaticText(this,wxID_ANY, wxT("/")), 0, wxALIGN_CENTER, 0);
105 sizer->Add(linksSizer, 0, wxALIGN_CENTER | wxALL, 5);
108 wxBoxSizer* headerSizer = new wxBoxSizer(wxHORIZONTAL);
111 headerSizer->Add(new wxStaticBitmap(this, -1, wxBitmap(LIcon64)),0, wxALIGN_CENTER, 0);
112 wxBoxSizer* textSizer = new wxBoxSizer(wxVERTICAL);
114 textSizer->Add(new wxStaticText(this, -1, _("Library")),0, wxALIGN_LEFT, 0);
116 textSizer->Add(new wxStaticText(this, -1, crea::std2wx(this->library->GetName())),0, wxALIGN_LEFT, 0);
117 headerSizer->Add(textSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
119 sizer->Add(headerSizer, 0, wxALIGN_CENTER);
122 wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Properties"));
123 wxPanel* propertiesPanel = new wxPanel(this);
124 wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL);
126 wxFlexGridSizer* propertiesGridSizer = new wxFlexGridSizer(4, 2, 9, 15);
128 wxStaticText *pMainFile = new wxStaticText(propertiesPanel, -1, wxT("Library Name"));
129 wxBoxSizer* pMainFilesz = new wxBoxSizer(wxHORIZONTAL);
130 this->libraryNametc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->library->GetNameLibrary()));
131 wxButton* pMainFilebt = new wxButton(propertiesPanel, ID_BUTTON_SET_NAME, wxT("Set"));
132 pMainFilebt->SetToolTip(wxT("Set the name of the library for the project."));
133 pMainFilesz->Add(this->libraryNametc, 0, wxALIGN_CENTER_VERTICAL, 0);
134 pMainFilesz->Add(pMainFilebt, 0, wxALIGN_CENTER | wxLEFT, 10);
136 propertiesGridSizer->Add(pMainFile, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
137 propertiesGridSizer->Add(pMainFilesz, 1, wxEXPAND);
139 propertiesGridSizer->AddGrowableCol(1,1);
141 propertiesPanelSizer->Add(propertiesGridSizer, 0, wxEXPAND);
142 propertiesPanel->SetSizer(propertiesPanelSizer);
143 propertiesPanelSizer->Fit(propertiesPanel);
144 propertiesBox->Add(propertiesPanel, 0, wxEXPAND);
145 sizer->Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
148 wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions"));
149 wxPanel* actionsPanel = new wxPanel(this);
150 wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
153 wxFlexGridSizer* actionsGridSizer = new wxFlexGridSizer(2, 2, 9, 15);
155 wxButton* createClassbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_CLASS, _T("A. Create Class"));
156 createClassbt->SetToolTip(wxT("Create a new class for this library."));
157 actionsGridSizer->Add(createClassbt, 1, wxALL | wxEXPAND, 5);
158 wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("B. Edit CMakeLists File"));
159 editCMakebt->SetToolTip(wxT("Edit the CMakeLists.txt of this library in the default text editor."));
160 editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMLibraryDescriptionPanel::OnCMakeMouseEnter,NULL,this);
161 editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMLibraryDescriptionPanel::OnCMakeMouseExit,NULL,this);
162 actionsGridSizer->Add(editCMakebt, 1, wxALL | wxEXPAND, 5);
163 wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("C. Open Library Folder"));
164 openFolderbt->SetToolTip(wxT("Open the library folder in the file explorer."));
165 actionsGridSizer->Add(openFolderbt, 1, wxALL | wxEXPAND, 5);
166 wxButton* createFolderbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_FOLDER, _T("Create Folder (Optional)"));
167 createFolderbt->SetToolTip(wxT("Create a new folder for this library."));
168 actionsGridSizer->Add(createFolderbt, 1, wxALL | wxEXPAND, 5);
170 actionsGridSizer->AddGrowableCol(0,1);
171 actionsGridSizer->AddGrowableCol(1,1);
173 actionsPanelSizer->Add(actionsGridSizer, 1, wxEXPAND, 0);
174 actionsPanel->SetSizer(actionsPanelSizer);
175 actionsPanelSizer->Fit(actionsPanel);
176 actionsBox->Add(actionsPanel, 1, wxEXPAND);
177 sizer -> Add(actionsBox, 0, wxALL | wxEXPAND, 10);
181 sizer->SetSizeHints(this);
183 if (((wxCDMMainFrame*)this->GetParent())->isHelp())
185 wxCDMLibraryHelpDialog* helpDialog = new wxCDMLibraryHelpDialog(this->GetParent(), this->library, wxID_ANY);
186 helpDialog->Show(true);
190 void wxCDMLibraryDescriptionPanel::OnBtnReturn(wxHyperlinkEvent& event)
192 std::vector<modelCDMIProjectTreeNode*> parents = this->library->GetParents();
193 std::string parentURL = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
194 //std::cout << parentURL << std::endl;
195 for (int i = 0; i < (int)(parents.size()); i++)
197 if (parents[i]->GetPath() == parentURL)
199 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
200 newEvent->SetClientData(parents[i]);
202 wxPostEvent(this->GetParent(), *newEvent);
207 void wxCDMLibraryDescriptionPanel::OnBtnSetExeName(wxCommandEvent& event)
210 wxString versionWx = wxGetTextFromUser(
211 wxT("Enter the new executable name"),
212 wxT("Change Library Name - creaDevManager"),
213 crea::std2wx(this->library->GetNameLibrary())
216 std::vector<std::string> parts;
217 CDMUtilities::splitter::split(parts, crea::wx2std(versionWx), " .", CDMUtilities::splitter::no_empties);
221 if(!this->library->SetNameLibrary(crea::wx2std(versionWx), result))
222 wxMessageBox(crea::std2wx(*result),_T("Change Library Name - Error!"),wxOK | wxICON_ERROR);
226 wxMessageBox(crea::std2wx("No name specified"),_T("Set Library Name - Error!"),wxOK | wxICON_ERROR);
228 this->libraryNametc->SetLabel(crea::std2wx(this->library->GetNameLibrary()));
231 void wxCDMLibraryDescriptionPanel::OnBtnCreateClass(wxCommandEvent& event)
233 //get class name from user
234 wxTextEntryDialog* newClassDlg = new wxTextEntryDialog(
236 wxT("Please enter the new class name."),
237 wxT("New Class - creaDevManager"),
242 if (newClassDlg->ShowModal() == wxID_OK)
244 std::string className = crea::wx2std(newClassDlg->GetValue());
246 if(className.size() > 0)
248 if(!this->library->CreateClass(className))
249 wxMessageBox(crea::std2wx("Something has gone wrong with the creation of the class."),_T("New Class - Error!"),wxOK | wxICON_ERROR);
251 ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
253 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
255 newEvent->SetClientData(this->library);
256 wxPostEvent(this->GetParent(), *newEvent);
258 wxMessageBox(crea::std2wx("The class has been created successfully."),_T("New Class - Success"),wxOK | wxICON_INFORMATION);
262 wxMessageBox(crea::std2wx("The new class name cannot be empty."),_T("New Class - Error!"),wxOK | wxICON_ERROR);
267 void wxCDMLibraryDescriptionPanel::OnBtnCreateFolder(wxCommandEvent& event)
270 wxString folderName = wxGetTextFromUser(
271 wxT("Enter the name of the new folder:"),
272 wxT("Create Folder - creaDevManager")
275 std::vector<std::string> parts;
276 CDMUtilities::splitter::split(parts, crea::wx2std(folderName), " /\\\"", CDMUtilities::splitter::no_empties);
280 modelCDMFolder* folderC = this->library->CreateFolder(crea::wx2std(folderName), result);
283 wxMessageBox(crea::std2wx(*result),_T("Create Folder - Error!"),wxOK | wxICON_ERROR);
286 ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
287 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
288 newEvent->SetClientData(folderC);
289 wxPostEvent(this->GetParent(), *newEvent);
290 wxMessageBox(crea::std2wx("The folder was successfully created"),_T("Create Folder - Success"),wxOK | wxICON_INFORMATION);
294 wxMessageBox(crea::std2wx("No name specified"),_T("Create Folder - Error!"),wxOK | wxICON_ERROR);
298 void wxCDMLibraryDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
301 if(!this->library->OpenCMakeListsFile(result))
302 wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
304 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
306 if(this->library->GetCMakeLists() != NULL)
308 newEvent->SetClientData(this->library->GetCMakeLists());
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 newEvent->SetClientData(this->library->GetCMakeLists());
331 wxPostEvent(this->GetParent(), *newEvent);
336 void wxCDMLibraryDescriptionPanel::OnCMakeMouseExit(wxMouseEvent& event)
338 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
340 if(this->library->GetCMakeLists() != NULL)
342 newEvent->SetClientData(this->library->GetCMakeLists());
344 wxPostEvent(this->GetParent(), *newEvent);