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 < 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()));
105 returnLnk->SetToolTip(crea::std2wx("Return to " + parents[parents.size()-1-i]->GetName() + "."));
106 linksSizer->Add(returnLnk, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 5);
107 if (i < parents.size()-1)
109 linksSizer->Add(new wxStaticText(this,wxID_ANY, wxT("/")), 0, wxALIGN_CENTER, 0);
112 sizer->Add(linksSizer, 0, wxALIGN_CENTER | wxALL, 5);
115 wxBoxSizer* headerSizer = new wxBoxSizer(wxHORIZONTAL);
118 headerSizer->Add(new wxStaticBitmap(this, -1, wxBitmap(PkIcon64)),0, wxALIGN_CENTER, 0);
119 wxBoxSizer* textSizer = new wxBoxSizer(wxVERTICAL);
121 textSizer->Add(new wxStaticText(this, -1, _("Package")),0, wxALIGN_LEFT, 0);
123 textSizer->Add(new wxStaticText(this, -1, crea::std2wx(this->package->GetNamePackage())),0, wxALIGN_LEFT, 0);
124 headerSizer->Add(textSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
126 sizer->Add(headerSizer, 0, wxALIGN_CENTER);
129 wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Properties"));
130 wxPanel* propertiesPanel = new wxPanel(this);
131 wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL);
132 wxFlexGridSizer* propertiesGridSizer = new wxFlexGridSizer(4, 2, 9, 15);
134 wxStaticText *pAuthor = new wxStaticText(propertiesPanel, -1, wxT("Author"));
135 wxStaticText *pVersion = new wxStaticText(propertiesPanel, -1, wxT("Version"));
136 wxStaticText *pDescription = new wxStaticText(propertiesPanel, -1, wxT("Description"));
139 wxBoxSizer* pAuthorsz = new wxBoxSizer(wxHORIZONTAL);
140 this->authortc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->package->GetAuthors()));
141 wxButton* pAuthorbt = new wxButton(propertiesPanel, ID_BUTTON_SET_AUTHOR, wxT("Change"));
142 pAuthorbt->SetToolTip(wxT("Update the author/s of the package."));
143 pAuthorsz->Add(this->authortc, 1, wxALIGN_CENTER_VERTICAL);
144 pAuthorsz->Add(pAuthorbt, 0, wxALIGN_CENTER | wxLEFT, 10);
147 wxBoxSizer* pVersionsz = new wxBoxSizer(wxHORIZONTAL);
148 this->versiontc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->package->GetVersion()));
149 wxButton* pVersionbt = new wxButton(propertiesPanel, ID_BUTTON_SET_VERSION, wxT("Set"));
150 pVersionbt->SetToolTip(wxT("Update the version of the package."));
151 pVersionsz->Add(this->versiontc, 1, wxALIGN_CENTER_VERTICAL);
152 pVersionsz->Add(pVersionbt, 0, wxALIGN_CENTER | wxLEFT, 10);
155 wxBoxSizer* pDescriptionsz = new wxBoxSizer(wxHORIZONTAL);
156 this->descriptiontc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->package->GetDescription()));
157 wxButton* pDescriptionbt = new wxButton(propertiesPanel, ID_BUTTON_SET_DESCRIPTION, wxT("Change"));
158 pDescriptionbt->SetToolTip(wxT("Update the description of the project."));
159 pDescriptionsz->Add(this->descriptiontc, 1, wxALIGN_CENTER_VERTICAL);
160 pDescriptionsz->Add(pDescriptionbt, 0, wxALIGN_CENTER | wxLEFT, 10);
162 propertiesGridSizer->Add(pAuthor, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
163 propertiesGridSizer->Add(pAuthorsz, 1, wxEXPAND);
164 propertiesGridSizer->Add(pVersion, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
165 propertiesGridSizer->Add(pVersionsz, 1, wxEXPAND);
166 propertiesGridSizer->Add(pDescription, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
167 propertiesGridSizer->Add(pDescriptionsz, 1, wxEXPAND);
169 propertiesGridSizer->AddGrowableCol(1,1);
171 propertiesPanelSizer -> Add(propertiesGridSizer, 1, wxEXPAND);
172 propertiesPanel->SetSizer(propertiesPanelSizer);
173 propertiesPanelSizer->Fit(propertiesPanel);
174 propertiesBox->Add(propertiesPanel, 0, wxEXPAND | wxALL, 5);
176 sizer->Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
179 wxStaticBoxSizer* BBBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("A&vailable Black Boxes"));
180 BBBox->GetStaticBox()->SetToolTip(wxT("Select any of the available black boxes to see its details or modify them."));
181 wxPanel* BBPanel = new wxPanel(this);
182 wxBoxSizer* BBPanelSizer = new wxBoxSizer(wxVERTICAL);
185 std::vector<modelCDMBlackBox*> blackBoxes = this->package->GetSrc()->GetBlackBoxes();
186 for (int i = 0; i < blackBoxes.size(); i++)
189 if(blackBoxes[i] != NULL)
192 wxHyperlinkCtrl* pBBlk = new wxHyperlinkCtrl(BBPanel,ID_LINK_SELECT_BLACKBOX, crea::std2wx(blackBoxes[i]->GetName().c_str()), crea::std2wx(blackBoxes[i]->GetName().c_str()));
193 pBBlk->SetWindowStyle(wxALIGN_LEFT);
194 std::string tt = "Author: " + blackBoxes[i]->GetAuthors() + "\nDescription: " + blackBoxes[i]->GetDescription() + "\nCategories: " + blackBoxes[i]->GetCategories();
195 pBBlk->SetToolTip(crea::std2wx(tt));
196 pBBlk->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnMouseEnter,NULL,this);
197 pBBlk->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnMouseExit,NULL,this);
198 BBPanelSizer -> Add(pBBlk, 0, wxEXPAND | wxALL, 5);
202 BBPanel->SetSizer(BBPanelSizer);
203 BBPanelSizer->Fit(BBPanel);
204 BBBox->Add(BBPanel, 1, wxEXPAND | wxALL, 5);
205 sizer -> Add(BBBox, 0, wxEXPAND | wxALL, 10);
208 wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions"));
209 wxPanel* actionsPanel = new wxPanel(this);
210 wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
212 wxFlexGridSizer* actionsGridSizer = new wxFlexGridSizer(2, 2, 9, 15);
214 wxButton* createBBbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_BLACKBOX, _T("A. Create Black Box"));
215 createBBbt->SetToolTip(wxT("Create a new black box for the active project inside this package."));
216 actionsGridSizer->Add(createBBbt, 1, wxALL | wxEXPAND, 5);
217 wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("B. Edit CMakeLists File"));
218 editCMakebt->SetToolTip(wxT("Open the system default text editor to edit the package's CMakeLists.txt file."));
219 editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnCMakeMouseEnter,NULL,this);
220 editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnCMakeMouseExit,NULL,this);
221 actionsGridSizer->Add(editCMakebt, 1, wxALL | wxEXPAND, 5);
222 wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("C. Open Package Folder"));
223 openFolderbt->SetToolTip(wxT("Open the package folder in the file explorer."));
224 actionsGridSizer->Add(openFolderbt, 1, wxALL | wxEXPAND, 5);
226 actionsGridSizer->AddGrowableCol(0,1);
227 actionsGridSizer->AddGrowableCol(1,1);
229 actionsPanelSizer->Add(actionsGridSizer, 1, wxEXPAND, 0);
230 actionsPanel->SetSizer(actionsPanelSizer);
231 actionsPanelSizer->Fit(actionsPanel);
232 actionsBox->Add(actionsPanel, 1, wxEXPAND);
233 sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 10);
237 sizer->SetSizeHints(this);
239 if (((wxCDMMainFrame*)this->GetParent())->isHelp())
241 wxCDMPackageHelpDialog* helpDialog = new wxCDMPackageHelpDialog(this->GetParent(), this->package, wxID_ANY);
242 helpDialog->Show(true);
246 void wxCDMPackageDescriptionPanel::OnBtnReturn(wxHyperlinkEvent& event)
248 std::vector<modelCDMIProjectTreeNode*> parents = this->package->GetParents();
249 std::string parentURL = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
250 //std::cout << parentURL << std::endl;
251 for (int i = 0; i < parents.size(); i++)
253 if (parents[i]->GetPath() == parentURL)
255 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
256 newEvent->SetInt(parents[i]->GetId());
258 wxPostEvent(this->GetParent(), *newEvent);
263 void wxCDMPackageDescriptionPanel::OnBtnSetAuthor(wxCommandEvent& event)
265 //get author from user
266 wxTextEntryDialog* authDlg = new wxTextEntryDialog(
268 wxT("Enter the new authors name. Separate each author with a '/'."),
269 wxT("Change Package Author - creaDevManager"),
270 crea::std2wx(this->package->GetAuthors()),
271 wxTE_MULTILINE | wxOK | wxCANCEL
274 if (authDlg->ShowModal() == wxID_OK)
276 std::string authorsStr = crea::wx2std(authDlg->GetValue());
278 if(authorsStr.size() > 0)
281 if(!this->package->SetAuthors(authorsStr, result))
282 wxMessageBox(crea::std2wx(*result),_T("Change Package Author - Error!"),wxOK | wxICON_ERROR);
284 this->authortc->SetLabel(crea::std2wx(this->package->GetAuthors()));
285 this->authortc->GetParent()->GetSizer()->RecalcSizes();
290 void wxCDMPackageDescriptionPanel::OnBtnSetVersion(wxCommandEvent& event)
293 wxString versionWx = wxGetTextFromUser(
294 wxT("Enter the new version name"),
295 wxT("Change Package Version - creaDevManager"),
296 crea::std2wx(this->package->GetVersion())
299 std::vector<std::string> parts;
300 CDMUtilities::splitter::split(parts, crea::wx2std(versionWx), " .", CDMUtilities::splitter::no_empties);
301 if(parts.size() == 3)
304 if(!this->package->SetVersion(crea::wx2std(versionWx), result))
305 wxMessageBox(crea::std2wx(*result),_T("Change Package Version - Error!"),wxOK | wxICON_ERROR);
309 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);
311 this->versiontc->SetLabel(crea::std2wx(this->package->GetVersion()));
314 void wxCDMPackageDescriptionPanel::OnBtnSetDescription(wxCommandEvent& event)
316 //get description from user
317 wxTextEntryDialog* descDlg = new wxTextEntryDialog(
319 wxT("Edit the package description."),
320 wxT("Change Package Description - creaDevManager"),
321 crea::std2wx(this->package->GetDescription()),
322 wxTE_MULTILINE | wxOK | wxCANCEL
325 if (descDlg->ShowModal() == wxID_OK)
327 std::string descriptionStr = crea::wx2std(descDlg->GetValue());
329 if(descriptionStr.size() > 0)
332 if(!this->package->SetDescription(descriptionStr, result))
333 wxMessageBox(crea::std2wx(*result),_T("Change Package Description - Error!"),wxOK | wxICON_ERROR);
335 this->descriptiontc->SetLabel(crea::std2wx(this->package->GetDescription()));
336 this->descriptiontc->GetParent()->GetSizer()->RecalcSizes();
340 void wxCDMPackageDescriptionPanel::OnLnkBlackBoxSelect(wxHyperlinkEvent& event)
343 modelCDMBlackBox* bb;
344 std::vector<modelCDMBlackBox*> bbs = this->package->GetSrc()->GetBlackBoxes();
345 for (int i = 0; i < bbs.size(); i++)
347 if(bbs[i]->GetName() == crea::wx2std(event.GetURL()))
349 bbId = bbs[i]->GetHeaderFile()->GetId();
355 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
356 newEvent->SetClientData(bb);
358 newEvent->SetString(wxT("blackbox"));
359 wxPostEvent(this->GetParent(), *newEvent);
361 wxCommandEvent* newEvent1 = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
362 newEvent1->SetInt(bbId);
364 wxPostEvent(this->GetParent(), *newEvent1);
368 void wxCDMPackageDescriptionPanel::OnBtnCreateBlackBox(wxCommandEvent& event)
371 wxCDMNewBlackBoxDialog* dialog = new wxCDMNewBlackBoxDialog(this);
373 userResponse = dialog->ShowModal();
375 if(userResponse == wxID_FORWARD)
379 modelCDMIProjectTreeNode* blackBox = this->package->CreateBlackBox(
381 crea::wx2std(dialog->GetBlackBoxName()),
382 crea::wx2std(dialog->GetBlackBoxType()),
383 crea::wx2std(dialog->GetBlackBoxFormat()),
384 crea::wx2std(dialog->GetBlackBoxCategories()),
385 crea::wx2std(dialog->GetBlackBoxAuthor()),
386 crea::wx2std(dialog->GetBlackBoxAuthorEmail()),
387 crea::wx2std(dialog->GetBlackBoxDescription())
389 //check black box created
392 wxMessageBox(crea::std2wx(*result),_T("New Black Box - Error!"),wxOK | wxICON_ERROR);
395 wxMessageBox(crea::std2wx("Black box successfully created."),_T("New Black Box - Success!"),wxOK | wxICON_INFORMATION);
397 //refreshing tree and description
398 //send event instead of calling parent to avoid crashing
400 ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
402 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
404 newEvent->SetInt(blackBox->GetId());
405 newEvent->SetString(wxT("blackbox"));
406 newEvent->SetClientData(blackBox);
407 wxPostEvent(this->GetParent(), *newEvent);
411 void wxCDMPackageDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
414 if(!this->package->OpenCMakeListsFile(result))
415 wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
417 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
419 if(this->package->GetCMakeLists() != NULL)
421 int CMId = this->package->GetCMakeLists()->GetId();
422 newEvent->SetInt(CMId);
424 wxPostEvent(this->GetParent(), *newEvent);
430 void wxCDMPackageDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
433 if(!this->package->OpenInFileExplorer(result))
434 wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
437 void wxCDMPackageDescriptionPanel::OnMouseEnter(wxMouseEvent& event)
439 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
440 std::string BBName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
443 std::vector<modelCDMBlackBox*> boxes = this->package->GetSrc()->GetBlackBoxes();
444 for (int i = 0; i < boxes.size(); i++)
446 if(boxes[i]->GetName() == BBName)
448 bbId = boxes[i]->GetHeaderFile()->GetId();
452 newEvent->SetInt(bbId);
454 wxPostEvent(this->GetParent(), *newEvent);
458 void wxCDMPackageDescriptionPanel::OnMouseExit(wxMouseEvent& event)
460 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
461 std::string BBName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
463 std::vector<modelCDMBlackBox*> boxes = this->package->GetSrc()->GetBlackBoxes();
464 for (int i = 0; i < boxes.size(); i++)
466 if(boxes[i]->GetName() == BBName)
468 bbId = boxes[i]->GetHeaderFile()->GetId();
472 newEvent->SetInt(bbId);
474 wxPostEvent(this->GetParent(), *newEvent);
478 void wxCDMPackageDescriptionPanel::OnCMakeMouseEnter(wxMouseEvent& event)
480 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
482 if(this->package->GetCMakeLists() != NULL)
484 int CMId = this->package->GetCMakeLists()->GetId();
485 newEvent->SetInt(CMId);
487 wxPostEvent(this->GetParent(), *newEvent);
492 void wxCDMPackageDescriptionPanel::OnCMakeMouseExit(wxMouseEvent& event)
494 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
496 if(this->package->GetCMakeLists() != NULL)
498 int CMId = this->package->GetCMakeLists()->GetId();
499 newEvent->SetInt(CMId);
501 wxPostEvent(this->GetParent(), *newEvent);