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_BUTTON(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)
52 wxCDMLibDescriptionPanel::wxCDMLibDescriptionPanel(
56 const wxString& caption,
62 wxCDMLibDescriptionPanel::Create(parent, lib, id, caption, pos, size, style);
65 wxCDMLibDescriptionPanel::~wxCDMLibDescriptionPanel()
69 bool wxCDMLibDescriptionPanel::Create(
73 const wxString& caption,
79 wxPanel::Create(parent, id, pos, size, style);
85 void wxCDMLibDescriptionPanel::CreateControls()
87 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
90 wxButton* returnbt = new wxButton(this, ID_BUTTON_PREV, wxT("Return to project"));
91 returnbt->SetToolTip(wxT("Return to the active project description."));
92 sizer->Add(returnbt, 0, wxALIGN_CENTER | wxALL, 5);
94 wxBoxSizer* headerSizer = new wxBoxSizer(wxHORIZONTAL);
97 headerSizer->Add(new wxStaticBitmap(this, -1, wxBitmap(LbIcon64)),0, wxALIGN_CENTER, 0);
98 wxBoxSizer* textSizer = new wxBoxSizer(wxVERTICAL);
100 textSizer->Add(new wxStaticText(this, -1, _("Library Management")),0, wxALIGN_LEFT, 0);
101 headerSizer->Add(textSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
103 sizer->Add(headerSizer, 0, wxALIGN_CENTER);
106 wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("A&vailable Libraries"));
107 propertiesBox->GetStaticBox()->SetToolTip(wxT("Select any of the available libraries to see its details or modify them."));
108 wxPanel* propertiesPanel = new wxPanel(this);
109 wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL);
111 std::vector<modelCDMLibrary*> libraries = this->lib->GetLibraries();
112 for (int i = 0; i < libraries.size(); i++)
114 wxHyperlinkCtrl* pLibrarylk = new wxHyperlinkCtrl(propertiesPanel, ID_LINK_SELECT_LIBRARY, crea::std2wx(libraries[i]->GetName().c_str()), crea::std2wx(libraries[i]->GetName().c_str()));
115 pLibrarylk->SetWindowStyle(wxALIGN_LEFT);
116 std::string tt = "Name: " + libraries[i]->GetName() + "\n";
117 tt += "Location: " + libraries[i]->GetPath();
118 pLibrarylk->SetToolTip(crea::std2wx(tt.c_str()));
119 pLibrarylk->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMLibDescriptionPanel::OnMouseEnter,NULL,this);
120 pLibrarylk->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMLibDescriptionPanel::OnMouseExit,NULL,this);
121 propertiesPanelSizer -> Add(pLibrarylk, 0, wxEXPAND | wxALL, 5);
124 propertiesPanel->SetSizer(propertiesPanelSizer);
125 propertiesPanelSizer->Fit(propertiesPanel);
126 propertiesBox->Add(propertiesPanel, 1, wxALL | wxEXPAND, 5);
127 sizer -> Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
130 wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Actions"));
131 actionsBox->GetStaticBox()->SetToolTip(wxT("Create a new library or make any change to the lib's CMakeLists.txt file by selecting the desired action."));
132 wxPanel* actionsPanel = new wxPanel(this);
133 wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
136 wxFlexGridSizer* actionsGridSizer = new wxFlexGridSizer(2, 2, 9, 15);
138 wxButton* createLibrarybt = new wxButton(actionsPanel, ID_BUTTON_CREATE_LIBRARY, _T("A. Create Library"));
139 createLibrarybt->SetToolTip(wxT("Create a new library for this project."));
140 actionsGridSizer->Add(createLibrarybt, 1, wxALL | wxEXPAND, 5);
141 wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("B. Edit CMakeLists File"));
142 editCMakebt->SetToolTip(wxT("Open the system default text editor to edit the Lib's CMakeLists.txt file."));
143 editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMLibDescriptionPanel::OnCMakeMouseEnter,NULL,this);
144 editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMLibDescriptionPanel::OnCMakeMouseExit,NULL,this);
145 actionsGridSizer->Add(editCMakebt, 1, wxALL | wxEXPAND, 5);
146 wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("C. Open Libraries Folder"));
147 openFolderbt->SetToolTip(wxT("Open the lib folder in the file explorer."));
148 actionsGridSizer->Add(openFolderbt, 1, wxALL | wxEXPAND, 5);
150 actionsGridSizer->AddGrowableCol(0,1);
151 actionsGridSizer->AddGrowableCol(1,1);
153 actionsPanelSizer->Add(actionsGridSizer, 1, wxEXPAND, 0);
155 actionsPanel->SetSizer(actionsPanelSizer);
156 actionsPanelSizer->Fit(actionsPanel);
157 actionsBox->Add(actionsPanel, 0, wxALL, 5);
158 sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 10);
162 sizer->SetSizeHints(this);
164 if (((wxCDMMainFrame*)this->GetParent())->isHelp())
166 wxCDMLibHelpDialog* helpDialog = new wxCDMLibHelpDialog(this->GetParent(), this->lib, wxID_ANY);
167 helpDialog->Show(true);
171 void wxCDMLibDescriptionPanel::OnBtnCreateLibrary(wxCommandEvent& event)
174 wxString libraryName = wxGetTextFromUser(
175 _T("Enter the new library name"),
176 _T("New Library - creaDevManager"),
180 if(libraryName.Len() > 0)
184 modelCDMIProjectTreeNode* library = this->lib->CreateLibrary(crea::wx2std(libraryName),result);
185 //check library created
188 wxMessageBox(crea::std2wx(*result),_T("New Library - Error!"),wxOK | wxICON_ERROR);
191 wxMessageBox(crea::std2wx("Library successfully created."),_T("New Library - Success!"),wxOK | wxICON_INFORMATION);
193 //refreshing tree and description
194 //send event instead of calling parent to avoid crashing
196 ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
198 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
199 newEvent->SetInt(library->GetId());
200 wxPostEvent(this->GetParent(), *newEvent);
204 void wxCDMLibDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
207 if(!this->lib->OpenCMakeListsFile(result))
208 wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
210 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
212 if(this->lib->GetCMakeLists() != NULL)
214 int CMId = this->lib->GetCMakeLists()->GetId();
215 newEvent->SetInt(CMId);
217 wxPostEvent(this->GetParent(), *newEvent);
221 void wxCDMLibDescriptionPanel::OnLnkLibrarySelect(wxHyperlinkEvent& event)
224 std::vector<modelCDMLibrary*> libraries = this->lib->GetLibraries();
225 for (int i = 0; i < libraries.size(); i++)
227 if(libraries[i]->GetName() == crea::wx2std(event.GetURL()))
229 libraryId = libraries[i]->GetId();
234 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
235 newEvent->SetInt(libraryId);
237 wxPostEvent(this->GetParent(), *newEvent);
239 wxCommandEvent* newEvent1 = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
240 newEvent1->SetInt(libraryId);
242 wxPostEvent(this->GetParent(), *newEvent1);
246 void wxCDMLibDescriptionPanel::OnBtnReturn(wxCommandEvent& event)
248 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
249 newEvent->SetInt(((wxCDMMainFrame*)this->GetParent())->GetModel()->GetProject()->GetId());
251 wxPostEvent(this->GetParent(), *newEvent);
254 void wxCDMLibDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
257 if(!this->lib->OpenInFileExplorer(result))
258 wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
261 void wxCDMLibDescriptionPanel::OnMouseEnter(wxMouseEvent& event)
263 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
264 std::string LibName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
266 std::vector<modelCDMLibrary*> libraries = this->lib->GetLibraries();
267 for (int i = 0; i < libraries.size(); i++)
269 if(libraries[i]->GetName() == LibName)
271 lbId = libraries[i]->GetId();
275 newEvent->SetInt(lbId);
277 wxPostEvent(this->GetParent(), *newEvent);
281 void wxCDMLibDescriptionPanel::OnMouseExit(wxMouseEvent& event)
283 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
284 std::string LibName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
286 std::vector<modelCDMLibrary*> libraries = this->lib->GetLibraries();
287 for (int i = 0; i < libraries.size(); i++)
289 if(libraries[i]->GetName() == LibName)
291 lbId = libraries[i]->GetId();
295 newEvent->SetInt(lbId);
297 wxPostEvent(this->GetParent(), *newEvent);
301 void wxCDMLibDescriptionPanel::OnCMakeMouseEnter(wxMouseEvent& event)
303 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
305 if(this->lib->GetCMakeLists() != NULL)
307 int CMId = this->lib->GetCMakeLists()->GetId();
308 newEvent->SetInt(CMId);
310 wxPostEvent(this->GetParent(), *newEvent);
315 void wxCDMLibDescriptionPanel::OnCMakeMouseExit(wxMouseEvent& event)
317 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
319 if(this->lib->GetCMakeLists() != NULL)
321 int CMId = this->lib->GetCMakeLists()->GetId();
322 newEvent->SetInt(CMId);
324 wxPostEvent(this->GetParent(), *newEvent);