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 * wxCDMLibDescriptionPanel.cpp
31 * Created on: Nov 27, 2012
32 * Author: Daniel Felipe Gonzalez Obando
35 #include "wxCDMLibDescriptionPanel.h"
37 #include "wxCDMMainFrame.h"
39 #include "wxCDMLibHelpDialog.h"
41 #include "creaDevManagerIds.h"
42 #include "images/LbIcon64.xpm"
44 BEGIN_EVENT_TABLE(wxCDMLibDescriptionPanel, wxPanel)
45 EVT_HYPERLINK(ID_BUTTON_PREV, wxCDMLibDescriptionPanel::OnBtnReturn)
46 EVT_HYPERLINK(ID_LINK_SELECT_LIBRARY, wxCDMLibDescriptionPanel::OnLnkLibrarySelect)
47 EVT_BUTTON(ID_BUTTON_CREATE_LIBRARY, wxCDMLibDescriptionPanel::OnBtnCreateLibrary)
48 EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMLibDescriptionPanel::OnBtnEditCMakeLists)
49 EVT_BUTTON(ID_BUTTON_OPEN_FOLDER, wxCDMLibDescriptionPanel::OnBtnOpenFolder)
50 EVT_CHECKBOX(ID_CHECK_INCLUDE_LIBRARY, wxCDMLibDescriptionPanel::OnChBLibraryChange)
53 wxCDMLibDescriptionPanel::wxCDMLibDescriptionPanel(
57 const wxString& caption,
63 wxCDMLibDescriptionPanel::Create(parent, lib, id, caption, pos, size, style);
66 wxCDMLibDescriptionPanel::~wxCDMLibDescriptionPanel()
70 bool wxCDMLibDescriptionPanel::Create(
74 const wxString& caption,
80 wxPanel::Create(parent, id, pos, size, style);
81 // this part makes the scrollbars show up
82 this->FitInside(); // ask the sizer about the needed size
83 this->SetScrollRate(5, 5);
90 void wxCDMLibDescriptionPanel::CreateControls()
92 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
95 wxBoxSizer *linksSizer = new wxBoxSizer(wxHORIZONTAL);
96 std::vector<modelCDMIProjectTreeNode*> parents = this->lib->GetParents();
97 for (int i = 0; i < (int)(parents.size()); i++)
99 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);
100 returnLnk->SetWindowStyle(wxNO_BORDER);
101 returnLnk->SetToolTip(crea::std2wx("Return to " + parents[parents.size()-1-i]->GetName() + "."));
102 linksSizer->Add(returnLnk, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 5);
103 linksSizer->Add(new wxStaticText(this,wxID_ANY, wxT("/")), 0, wxALIGN_CENTER, 0);
106 linksSizer->Add(new wxStaticText(this, wxID_ANY, crea::std2wx(this->lib->GetName())), 0, wxALIGN_CENTER, 0);
108 sizer->Add(linksSizer, 0, wxALIGN_CENTER | wxALL, 5);
111 wxBoxSizer* headerSizer = new wxBoxSizer(wxHORIZONTAL);
114 headerSizer->Add(new wxStaticBitmap(this, -1, wxBitmap(LbIcon64)),0, wxALIGN_CENTER, 0);
115 wxBoxSizer* textSizer = new wxBoxSizer(wxVERTICAL);
117 textSizer->Add(new wxStaticText(this, -1, _("Library Management")),0, wxALIGN_LEFT, 0);
118 headerSizer->Add(textSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
120 sizer->Add(headerSizer, 0, wxALIGN_CENTER);
123 wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("A&vailable Libraries"));
124 propertiesBox->GetStaticBox()->SetToolTip(wxT("Select any of the available libraries to see its details or modify them."));
125 wxPanel* propertiesPanel = new wxPanel(this);
127 std::vector<modelCDMLibrary*> libraries = this->lib->GetLibraries();
128 wxFlexGridSizer* propertiesGridSizer = new wxFlexGridSizer(libraries.size()+1, 3, 9, 5);
130 wxStaticText* ChBTitle = new wxStaticText(propertiesPanel, wxID_ANY, wxT("Include in\nCMake"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE_HORIZONTAL);
131 wxStaticText* LkTitle = new wxStaticText(propertiesPanel, wxID_ANY, wxT("Library Name"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE_HORIZONTAL);
132 wxStaticText* HlpTitle = new wxStaticText(propertiesPanel, wxID_ANY, wxT("Help"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE_HORIZONTAL);
134 propertiesGridSizer -> Add(ChBTitle, 0, wxEXPAND | wxALL, 5);
135 propertiesGridSizer -> Add(LkTitle, 0, wxEXPAND | wxALL, 5);
136 propertiesGridSizer -> Add(HlpTitle, 0, wxEXPAND | wxALL, 5);
138 for (int i = 0; i < (int)(libraries.size()); i++)
140 //checkbox for cmake inclusion
141 wxCheckBox* pLibraryChB = new wxCheckBox(propertiesPanel, ID_CHECK_INCLUDE_LIBRARY, wxT(""), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
142 pLibraryChB->SetName(crea::std2wx(libraries[i]->GetName()));
143 std::string tt = "if this box is checked the the " + libraries[i]->GetName() + " library is included in the project compilation.";
144 pLibraryChB->SetToolTip(crea::std2wx(tt));
145 pLibraryChB->SetValue(this->lib->IsLibraryIncluded(libraries[i]->GetName()));
146 propertiesGridSizer -> Add(pLibraryChB, 0, wxEXPAND | wxALIGN_CENTER);
148 //link to library with description
149 wxHyperlinkCtrl* pLibrarylk = new wxHyperlinkCtrl(propertiesPanel, ID_LINK_SELECT_LIBRARY, crea::std2wx(libraries[i]->GetName().c_str()), crea::std2wx(libraries[i]->GetName().c_str()), wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE);
150 pLibrarylk->SetWindowStyle(wxALIGN_LEFT | wxNO_BORDER);
151 tt = "Name: " + libraries[i]->GetName() + "\n";
152 tt += "Location: " + libraries[i]->GetPath();
153 pLibrarylk->SetToolTip(crea::std2wx(tt));
154 pLibrarylk->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMLibDescriptionPanel::OnMouseEnter,NULL,this);
155 pLibrarylk->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMLibDescriptionPanel::OnMouseExit,NULL,this);
156 propertiesGridSizer -> Add(pLibrarylk, 0, wxEXPAND);
159 wxButton* pLibraryHlp = new wxButton(propertiesPanel, wxID_ANY, wxT("?"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
160 propertiesGridSizer -> Add(pLibraryHlp, 0, wxEXPAND | wxALIGN_CENTER);
163 propertiesGridSizer->AddGrowableCol(1,1);
165 propertiesPanel->SetSizer(propertiesGridSizer);
166 propertiesGridSizer->Fit(propertiesPanel);
167 propertiesBox->Add(propertiesPanel, 1, wxALL | wxEXPAND, 5);
168 sizer -> Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
171 wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Actions"));
172 actionsBox->GetStaticBox()->SetToolTip(wxT("Create a new library or make any change to the lib's CMakeLists.txt file by selecting the desired action."));
173 wxPanel* actionsPanel = new wxPanel(this);
174 wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
177 wxFlexGridSizer* actionsGridSizer = new wxFlexGridSizer(2, 2, 9, 15);
179 wxButton* createLibrarybt = new wxButton(actionsPanel, ID_BUTTON_CREATE_LIBRARY, _T("A. Create Library"));
180 createLibrarybt->SetToolTip(wxT("Create a new library for this project."));
181 actionsGridSizer->Add(createLibrarybt, 1, wxALL | wxEXPAND, 5);
182 wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists File"));
183 editCMakebt->SetToolTip(wxT("Open the system default text editor to edit the Lib's CMakeLists.txt file."));
184 editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMLibDescriptionPanel::OnCMakeMouseEnter,NULL,this);
185 editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMLibDescriptionPanel::OnCMakeMouseExit,NULL,this);
186 actionsGridSizer->Add(editCMakebt, 1, wxALL | wxEXPAND, 5);
187 wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("Open Libraries Folder"));
188 openFolderbt->SetToolTip(wxT("Open the lib folder in the file explorer."));
189 actionsGridSizer->Add(openFolderbt, 1, wxALL | wxEXPAND, 5);
191 actionsGridSizer->AddGrowableCol(0,1);
192 actionsGridSizer->AddGrowableCol(1,1);
194 actionsPanelSizer->Add(actionsGridSizer, 1, wxEXPAND, 0);
196 actionsPanel->SetSizer(actionsPanelSizer);
197 actionsPanelSizer->Fit(actionsPanel);
198 actionsBox->Add(actionsPanel, 0, wxALL, 5);
199 sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 10);
203 sizer->SetSizeHints(this);
205 if (((wxCDMMainFrame*)this->GetParent())->isHelp())
207 wxCDMLibHelpDialog* helpDialog = new wxCDMLibHelpDialog(this->GetParent(), this->lib, wxID_ANY);
208 helpDialog->Show(true);
212 void wxCDMLibDescriptionPanel::OnBtnCreateLibrary(wxCommandEvent& event)
215 wxString libraryName = wxGetTextFromUser(
216 _T("Enter the new library name"),
217 _T("New Library - creaDevManager"),
221 if(libraryName.Len() > 0)
225 modelCDMIProjectTreeNode* library = this->lib->CreateLibrary(crea::wx2std(libraryName),result);
226 //check library created
229 wxMessageBox(crea::std2wx(*result),_T("New Library - Error!"),wxOK | wxICON_ERROR);
232 wxMessageBox(crea::std2wx("Library successfully created."),_T("New Library - Success!"),wxOK | wxICON_INFORMATION);
234 //refreshing tree and description
235 //send event instead of calling parent to avoid crashing
237 ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
239 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
240 newEvent->SetClientData(library);
241 wxPostEvent(this->GetParent(), *newEvent);
245 void wxCDMLibDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
248 if(!this->lib->OpenCMakeListsFile(result))
249 wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
251 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
253 if(this->lib->GetCMakeLists() != NULL)
255 newEvent->SetClientData(this->lib->GetCMakeLists());
257 wxPostEvent(this->GetParent(), *newEvent);
261 void wxCDMLibDescriptionPanel::OnChBLibraryChange(wxCommandEvent& event)
263 this->lib->SetLibraryInclude(
264 crea::wx2std(((wxCheckBox*)event.GetEventObject())->GetName()),
265 ((wxCheckBox*)event.GetEventObject())->GetValue()
269 void wxCDMLibDescriptionPanel::OnLnkLibrarySelect(wxHyperlinkEvent& event)
271 modelCDMLibrary* theLibrary = NULL;
272 std::vector<modelCDMLibrary*> libraries = this->lib->GetLibraries();
273 for (int i = 0; i < (int)(libraries.size()); i++)
275 if(libraries[i]->GetName() == crea::wx2std(event.GetURL()))
277 theLibrary = libraries[i];
282 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
283 newEvent->SetClientData(theLibrary);
285 wxPostEvent(this->GetParent(), *newEvent);
287 wxCommandEvent* newEvent1 = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
288 newEvent1->SetClientData(theLibrary);
290 wxPostEvent(this->GetParent(), *newEvent1);
294 void wxCDMLibDescriptionPanel::OnBtnReturn(wxHyperlinkEvent& event)
296 std::vector<modelCDMIProjectTreeNode*> parents = this->lib->GetParents();
297 std::string parentURL = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
298 //std::cout << parentURL << std::endl;
299 for (int i = 0; i < (int)(parents.size()); i++)
301 if (parents[i]->GetPath() == parentURL)
303 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
304 newEvent->SetClientData(parents[i]);
306 wxPostEvent(this->GetParent(), *newEvent);
311 void wxCDMLibDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
314 if(!this->lib->OpenInFileExplorer(result))
315 wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
318 void wxCDMLibDescriptionPanel::OnMouseEnter(wxMouseEvent& event)
320 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
321 std::string LibName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
322 modelCDMLibrary* theLibrary = NULL;
323 std::vector<modelCDMLibrary*> libraries = this->lib->GetLibraries();
324 for (int i = 0; i < (int)(libraries.size()); i++)
326 if(libraries[i]->GetName() == LibName)
328 theLibrary = libraries[i];
332 newEvent->SetClientData(theLibrary);
334 wxPostEvent(this->GetParent(), *newEvent);
338 void wxCDMLibDescriptionPanel::OnMouseExit(wxMouseEvent& event)
340 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
341 std::string LibName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
342 modelCDMLibrary* theLibrary = NULL;
343 std::vector<modelCDMLibrary*> libraries = this->lib->GetLibraries();
344 for (int i = 0; i < (int)(libraries.size()); i++)
346 if(libraries[i]->GetName() == LibName)
348 theLibrary = libraries[i];
352 newEvent->SetClientData(theLibrary);
354 wxPostEvent(this->GetParent(), *newEvent);
358 void wxCDMLibDescriptionPanel::OnCMakeMouseEnter(wxMouseEvent& event)
360 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
362 if(this->lib->GetCMakeLists() != NULL)
364 newEvent->SetClientData(this->lib->GetCMakeLists());
366 wxPostEvent(this->GetParent(), *newEvent);
371 void wxCDMLibDescriptionPanel::OnCMakeMouseExit(wxMouseEvent& event)
373 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
375 if(this->lib->GetCMakeLists() != NULL)
377 newEvent->SetClientData(this->lib->GetCMakeLists());
379 wxPostEvent(this->GetParent(), *newEvent);