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 * wxCDMPackageDescriptionPanel.cpp
31 * Created on: Nov 27, 2012
32 * Author: Daniel Felipe Gonzalez Obando
35 #include "wxCDMPackageDescriptionPanel.h"
37 #include "wxCDMMainFrame.h"
39 #include "creaDevManagerIds.h"
40 #include "images/PkIcon64.xpm"
42 #include "wxCDMNewBlackBoxDialog.h"
43 #include <wx/textdlg.h>
44 #include "CDMUtilities.h"
47 #include "modelCDMCMakeListsFile.h"
48 #include "wxCDMPackageHelpDialog.h"
51 BEGIN_EVENT_TABLE(wxCDMPackageDescriptionPanel, wxPanel)
52 EVT_HYPERLINK(ID_BUTTON_PREV, wxCDMPackageDescriptionPanel::OnBtnReturn)
53 EVT_BUTTON(ID_BUTTON_SET_AUTHOR, wxCDMPackageDescriptionPanel::OnBtnSetAuthor)
54 EVT_BUTTON(ID_BUTTON_SET_VERSION, wxCDMPackageDescriptionPanel::OnBtnSetVersion)
55 EVT_BUTTON(ID_BUTTON_SET_DESCRIPTION, wxCDMPackageDescriptionPanel::OnBtnSetDescription)
56 EVT_HYPERLINK(ID_LINK_SELECT_BLACKBOX, wxCDMPackageDescriptionPanel::OnLnkBlackBoxSelect)
57 EVT_BUTTON(ID_BUTTON_CREATE_BLACKBOX, wxCDMPackageDescriptionPanel::OnBtnCreateBlackBox)
58 EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMPackageDescriptionPanel::OnBtnEditCMakeLists)
59 EVT_BUTTON(ID_BUTTON_OPEN_FOLDER, wxCDMPackageDescriptionPanel::OnBtnOpenFolder)
62 wxCDMPackageDescriptionPanel::wxCDMPackageDescriptionPanel(
64 modelCDMPackage* package,
66 const wxString& caption,
72 wxCDMPackageDescriptionPanel::Create(parent, package, id, caption, pos, size, style);
75 wxCDMPackageDescriptionPanel::~wxCDMPackageDescriptionPanel()
79 bool wxCDMPackageDescriptionPanel::Create(
81 modelCDMPackage* package,
83 const wxString& caption,
89 wxPanel::Create(parent, id, pos, size, style);
90 this->package = package;
95 void wxCDMPackageDescriptionPanel::CreateControls()
97 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
100 wxBoxSizer *linksSizer = new wxBoxSizer(wxHORIZONTAL);
101 std::vector<modelCDMIProjectTreeNode*> parents = this->package->GetParents();
102 for (int i = 0; i < (int)(parents.size()); i++)
104 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);
105 returnLnk->SetWindowStyle(wxNO_BORDER);
106 returnLnk->SetToolTip(crea::std2wx("Return to " + parents[parents.size()-1-i]->GetName() + "."));
107 linksSizer->Add(returnLnk, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 5);
108 linksSizer->Add(new wxStaticText(this,wxID_ANY, wxT("/")), 0, wxALIGN_CENTER, 0);
111 linksSizer->Add(new wxStaticText(this, wxID_ANY, crea::std2wx(this->package->GetName())), 0, wxALIGN_CENTER, 0);
113 sizer->Add(linksSizer, 0, wxALIGN_CENTER | wxALL, 5);
116 wxBoxSizer* headerSizer = new wxBoxSizer(wxHORIZONTAL);
119 headerSizer->Add(new wxStaticBitmap(this, -1, wxBitmap(PkIcon64)),0, wxALIGN_CENTER, 0);
120 wxBoxSizer* textSizer = new wxBoxSizer(wxVERTICAL);
122 textSizer->Add(new wxStaticText(this, -1, _("Package")),0, wxALIGN_LEFT, 0);
124 textSizer->Add(new wxStaticText(this, -1, crea::std2wx(this->package->GetNamePackage())),0, wxALIGN_LEFT, 0);
125 headerSizer->Add(textSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
127 sizer->Add(headerSizer, 0, wxALIGN_CENTER);
130 wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Properties"));
131 wxPanel* propertiesPanel = new wxPanel(this);
132 wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL);
133 wxFlexGridSizer* propertiesGridSizer = new wxFlexGridSizer(4, 2, 9, 15);
135 wxStaticText *pAuthor = new wxStaticText(propertiesPanel, -1, wxT("Author"));
136 wxStaticText *pVersion = new wxStaticText(propertiesPanel, -1, wxT("Version"));
137 wxStaticText *pDescription = new wxStaticText(propertiesPanel, -1, wxT("Description"));
140 wxBoxSizer* pAuthorsz = new wxBoxSizer(wxHORIZONTAL);
141 this->authortc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->package->GetAuthors()));
142 wxButton* pAuthorbt = new wxButton(propertiesPanel, ID_BUTTON_SET_AUTHOR, wxT("Change"));
143 pAuthorbt->SetToolTip(wxT("Update the author/s of the package."));
144 pAuthorsz->Add(this->authortc, 1, wxALIGN_CENTER_VERTICAL);
145 pAuthorsz->Add(pAuthorbt, 0, wxALIGN_CENTER | wxLEFT, 10);
148 wxBoxSizer* pVersionsz = new wxBoxSizer(wxHORIZONTAL);
149 this->versiontc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->package->GetVersion()));
150 wxButton* pVersionbt = new wxButton(propertiesPanel, ID_BUTTON_SET_VERSION, wxT("Set"));
151 pVersionbt->SetToolTip(wxT("Update the version of the package."));
152 pVersionsz->Add(this->versiontc, 1, wxALIGN_CENTER_VERTICAL);
153 pVersionsz->Add(pVersionbt, 0, wxALIGN_CENTER | wxLEFT, 10);
156 wxBoxSizer* pDescriptionsz = new wxBoxSizer(wxHORIZONTAL);
157 this->descriptiontc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->package->GetDescription()));
158 wxButton* pDescriptionbt = new wxButton(propertiesPanel, ID_BUTTON_SET_DESCRIPTION, wxT("Change"));
159 pDescriptionbt->SetToolTip(wxT("Update the description of the project."));
160 pDescriptionsz->Add(this->descriptiontc, 1, wxALIGN_CENTER_VERTICAL);
161 pDescriptionsz->Add(pDescriptionbt, 0, wxALIGN_CENTER | wxLEFT, 10);
163 propertiesGridSizer->Add(pAuthor, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
164 propertiesGridSizer->Add(pAuthorsz, 1, wxEXPAND);
165 propertiesGridSizer->Add(pVersion, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
166 propertiesGridSizer->Add(pVersionsz, 1, wxEXPAND);
167 propertiesGridSizer->Add(pDescription, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
168 propertiesGridSizer->Add(pDescriptionsz, 1, wxEXPAND);
170 propertiesGridSizer->AddGrowableCol(1,1);
172 propertiesPanelSizer -> Add(propertiesGridSizer, 1, wxEXPAND);
173 propertiesPanel->SetSizer(propertiesPanelSizer);
174 propertiesPanelSizer->Fit(propertiesPanel);
175 propertiesBox->Add(propertiesPanel, 0, wxEXPAND | wxALL, 5);
177 sizer->Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
180 wxStaticBoxSizer* BBBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("A&vailable Black Boxes"));
181 BBBox->GetStaticBox()->SetToolTip(wxT("Select any of the available black boxes to see its details or modify them."));
182 wxPanel* BBPanel = new wxPanel(this);
183 wxBoxSizer* BBPanelSizer = new wxBoxSizer(wxVERTICAL);
186 std::vector<modelCDMBlackBox*> blackBoxes = this->package->GetSrc()->GetBlackBoxes();
187 for (int i = 0; i < (int)(blackBoxes.size()); i++)
190 if(blackBoxes[i] != NULL)
193 wxHyperlinkCtrl* pBBlk = new wxHyperlinkCtrl(BBPanel,ID_LINK_SELECT_BLACKBOX, crea::std2wx(blackBoxes[i]->GetName().c_str()), crea::std2wx(blackBoxes[i]->GetName().c_str()), wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE);
194 pBBlk->SetWindowStyle(wxALIGN_LEFT | wxNO_BORDER);
195 std::string tt = "Author: " + blackBoxes[i]->GetAuthors() + "\nDescription: " + blackBoxes[i]->GetDescription() + "\nCategories: " + blackBoxes[i]->GetCategories();
196 pBBlk->SetToolTip(crea::std2wx(tt));
197 pBBlk->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnMouseEnter,NULL,this);
198 pBBlk->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnMouseExit,NULL,this);
199 BBPanelSizer -> Add(pBBlk, 0, wxEXPAND | wxALL, 5);
203 BBPanel->SetSizer(BBPanelSizer);
204 BBPanelSizer->Fit(BBPanel);
205 BBBox->Add(BBPanel, 1, wxEXPAND | wxALL, 5);
206 sizer -> Add(BBBox, 0, wxEXPAND | wxALL, 10);
209 wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions"));
210 wxPanel* actionsPanel = new wxPanel(this);
211 wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
213 wxFlexGridSizer* actionsGridSizer = new wxFlexGridSizer(2, 2, 9, 15);
215 wxButton* createBBbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_BLACKBOX, _T("A. Create Black Box"));
216 createBBbt->SetToolTip(wxT("Create a new black box for the active project inside this package."));
217 actionsGridSizer->Add(createBBbt, 1, wxALL | wxEXPAND, 5);
218 wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("B. Edit CMakeLists File"));
219 editCMakebt->SetToolTip(wxT("Open the system default text editor to edit the package's CMakeLists.txt file."));
220 editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnCMakeMouseEnter,NULL,this);
221 editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnCMakeMouseExit,NULL,this);
222 actionsGridSizer->Add(editCMakebt, 1, wxALL | wxEXPAND, 5);
223 wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("C. Open Package Folder"));
224 openFolderbt->SetToolTip(wxT("Open the package folder in the file explorer."));
225 actionsGridSizer->Add(openFolderbt, 1, wxALL | wxEXPAND, 5);
227 actionsGridSizer->AddGrowableCol(0,1);
228 actionsGridSizer->AddGrowableCol(1,1);
230 actionsPanelSizer->Add(actionsGridSizer, 1, wxEXPAND, 0);
231 actionsPanel->SetSizer(actionsPanelSizer);
232 actionsPanelSizer->Fit(actionsPanel);
233 actionsBox->Add(actionsPanel, 1, wxEXPAND);
234 sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 10);
238 sizer->SetSizeHints(this);
240 if (((wxCDMMainFrame*)this->GetParent())->isHelp())
242 wxCDMPackageHelpDialog* helpDialog = new wxCDMPackageHelpDialog(this->GetParent(), this->package, wxID_ANY);
243 helpDialog->Show(true);
247 void wxCDMPackageDescriptionPanel::OnBtnReturn(wxHyperlinkEvent& event)
249 std::vector<modelCDMIProjectTreeNode*> parents = this->package->GetParents();
250 std::string parentURL = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
251 //std::cout << parentURL << std::endl;
252 for (int i = 0; i < (int)(parents.size()); i++)
254 if (parents[i]->GetPath() == parentURL)
256 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
257 newEvent->SetClientData(parents[i]);
259 wxPostEvent(this->GetParent(), *newEvent);
264 void wxCDMPackageDescriptionPanel::OnBtnSetAuthor(wxCommandEvent& event)
266 //get author from user
267 wxTextEntryDialog* authDlg = new wxTextEntryDialog(
269 wxT("Enter the new authors name. Separate each author with a '/'."),
270 wxT("Change Package Author - creaDevManager"),
271 crea::std2wx(this->package->GetAuthors()),
272 wxTE_MULTILINE | wxOK | wxCANCEL
275 if (authDlg->ShowModal() == wxID_OK)
277 std::string authorsStr = crea::wx2std(authDlg->GetValue());
279 if(authorsStr.size() > 0)
282 if(!this->package->SetAuthors(authorsStr, result))
283 wxMessageBox(crea::std2wx(*result),_T("Change Package Author - Error!"),wxOK | wxICON_ERROR);
285 this->authortc->SetLabel(crea::std2wx(this->package->GetAuthors()));
286 this->authortc->GetParent()->GetSizer()->RecalcSizes();
291 void wxCDMPackageDescriptionPanel::OnBtnSetVersion(wxCommandEvent& event)
294 wxString versionWx = wxGetTextFromUser(
295 wxT("Enter the new version name"),
296 wxT("Change Package Version - creaDevManager"),
297 crea::std2wx(this->package->GetVersion())
300 std::vector<std::string> parts;
301 CDMUtilities::splitter::split(parts, crea::wx2std(versionWx), " .", CDMUtilities::splitter::no_empties);
302 if(parts.size() == 3)
305 if(!this->package->SetVersion(crea::wx2std(versionWx), result))
306 wxMessageBox(crea::std2wx(*result),_T("Change Package Version - Error!"),wxOK | wxICON_ERROR);
310 wxMessageBox(crea::std2wx("The version format is incorrect, please follow the following format:\nX.Y.Z\nX: Major Version\nY: Minor Version\nZ: Build Version"),_T("Set Project Version - Error!"),wxOK | wxICON_ERROR);
312 this->versiontc->SetLabel(crea::std2wx(this->package->GetVersion()));
315 void wxCDMPackageDescriptionPanel::OnBtnSetDescription(wxCommandEvent& event)
317 //get description from user
318 wxTextEntryDialog* descDlg = new wxTextEntryDialog(
320 wxT("Edit the package description."),
321 wxT("Change Package Description - creaDevManager"),
322 crea::std2wx(this->package->GetDescription()),
323 wxTE_MULTILINE | wxOK | wxCANCEL
326 if (descDlg->ShowModal() == wxID_OK)
328 std::string descriptionStr = crea::wx2std(descDlg->GetValue());
330 if(descriptionStr.size() > 0)
333 if(!this->package->SetDescription(descriptionStr, result))
334 wxMessageBox(crea::std2wx(*result),_T("Change Package Description - Error!"),wxOK | wxICON_ERROR);
336 this->descriptiontc->SetLabel(crea::std2wx(this->package->GetDescription()));
337 this->descriptiontc->GetParent()->GetSizer()->RecalcSizes();
341 void wxCDMPackageDescriptionPanel::OnLnkBlackBoxSelect(wxHyperlinkEvent& event)
343 modelCDMBlackBox* bb;
344 std::vector<modelCDMBlackBox*> bbs = this->package->GetSrc()->GetBlackBoxes();
345 for (int i = 0; i < (int)(bbs.size()); i++)
347 if(bbs[i]->GetName() == crea::wx2std(event.GetURL()))
354 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
355 newEvent->SetClientData(bb);
357 newEvent->SetString(wxT("blackbox"));
358 wxPostEvent(this->GetParent(), *newEvent);
360 wxCommandEvent* newEvent1 = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
361 newEvent1->SetClientData(bb->GetHeaderFile());
363 wxPostEvent(this->GetParent(), *newEvent1);
367 void wxCDMPackageDescriptionPanel::OnBtnCreateBlackBox(wxCommandEvent& event)
370 wxCDMNewBlackBoxDialog* dialog = new wxCDMNewBlackBoxDialog(this);
372 userResponse = dialog->ShowModal();
374 if(userResponse == wxID_FORWARD)
378 modelCDMIProjectTreeNode* blackBox = this->package->CreateBlackBox(
380 crea::wx2std(dialog->GetBlackBoxName()),
381 crea::wx2std(dialog->GetBlackBoxType()),
382 crea::wx2std(dialog->GetBlackBoxFormat()),
383 crea::wx2std(dialog->GetBlackBoxCategories()),
384 crea::wx2std(dialog->GetBlackBoxAuthor()),
385 crea::wx2std(dialog->GetBlackBoxAuthorEmail()),
386 crea::wx2std(dialog->GetBlackBoxDescription())
388 //check black box created
391 wxMessageBox(crea::std2wx(*result),_T("New Black Box - Error!"),wxOK | wxICON_ERROR);
394 wxMessageBox(crea::std2wx("Black box successfully created."),_T("New Black Box - Success!"),wxOK | wxICON_INFORMATION);
396 //refreshing tree and description
397 //send event instead of calling parent to avoid crashing
399 ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
401 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
403 newEvent->SetClientData(blackBox);
404 newEvent->SetString(wxT("blackbox"));
405 newEvent->SetClientData(blackBox);
406 wxPostEvent(this->GetParent(), *newEvent);
410 void wxCDMPackageDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
413 if(!this->package->OpenCMakeListsFile(result))
414 wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
416 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
418 if(this->package->GetCMakeLists() != NULL)
420 newEvent->SetClientData(this->package->GetCMakeLists());
422 wxPostEvent(this->GetParent(), *newEvent);
428 void wxCDMPackageDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
431 if(!this->package->OpenInFileExplorer(result))
432 wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
435 void wxCDMPackageDescriptionPanel::OnMouseEnter(wxMouseEvent& event)
437 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
438 std::string BBName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
440 modelCDMFile* bbHeader = NULL;
441 std::vector<modelCDMBlackBox*> boxes = this->package->GetSrc()->GetBlackBoxes();
442 for (int i = 0; i < (int)(boxes.size()); i++)
444 if(boxes[i]->GetName() == BBName)
446 bbHeader = boxes[i]->GetHeaderFile();
450 newEvent->SetClientData(bbHeader);
452 wxPostEvent(this->GetParent(), *newEvent);
456 void wxCDMPackageDescriptionPanel::OnMouseExit(wxMouseEvent& event)
458 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
459 std::string BBName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
460 modelCDMFile* bbHeader = NULL;
461 std::vector<modelCDMBlackBox*> boxes = this->package->GetSrc()->GetBlackBoxes();
462 for (int i = 0; i < (int)(boxes.size()); i++)
464 if(boxes[i]->GetName() == BBName)
466 bbHeader = boxes[i]->GetHeaderFile();
470 newEvent->SetClientData(bbHeader);
472 wxPostEvent(this->GetParent(), *newEvent);
476 void wxCDMPackageDescriptionPanel::OnCMakeMouseEnter(wxMouseEvent& event)
478 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
480 if(this->package->GetCMakeLists() != NULL)
482 newEvent->SetClientData(this->package->GetCMakeLists());
484 wxPostEvent(this->GetParent(), *newEvent);
489 void wxCDMPackageDescriptionPanel::OnCMakeMouseExit(wxMouseEvent& event)
491 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
493 if(this->package->GetCMakeLists() != NULL)
495 newEvent->SetClientData(this->package->GetCMakeLists());
497 wxPostEvent(this->GetParent(), *newEvent);