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_BUTTON(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 wxButton* returnbt = new wxButton(this, ID_BUTTON_PREV, wxT("Return to project"));
101 returnbt->SetToolTip(wxT("Return to the active project description."));
102 sizer->Add(returnbt, 0, wxALIGN_CENTER | wxALL, 5);
105 sizer->Add(new wxStaticText(this, -1, _("Package")),0, wxALIGN_CENTER, 0);
108 sizer->Add(new wxStaticBitmap(this, -1, wxBitmap(PkIcon64)),0, wxALIGN_CENTER, 0);
111 sizer->Add(new wxStaticText(this, -1, crea::std2wx(this->package->GetNamePackage())),0, wxALIGN_CENTER, 0);
114 wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Properties"));
115 wxPanel* propertiesPanel = new wxPanel(this);
116 wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL);
117 wxFlexGridSizer* propertiesGridSizer = new wxFlexGridSizer(4, 2, 9, 15);
119 wxStaticText *pAuthor = new wxStaticText(propertiesPanel, -1, wxT("Author"));
120 wxStaticText *pVersion = new wxStaticText(propertiesPanel, -1, wxT("Version"));
121 wxStaticText *pDescription = new wxStaticText(propertiesPanel, -1, wxT("Description"));
124 wxBoxSizer* pAuthorsz = new wxBoxSizer(wxHORIZONTAL);
125 this->authortc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->package->GetAuthors()));
126 wxButton* pAuthorbt = new wxButton(propertiesPanel, ID_BUTTON_SET_AUTHOR, wxT("Change"));
127 pAuthorbt->SetToolTip(wxT("Update the author/s of the package."));
128 pAuthorsz->Add(this->authortc, 1, wxALIGN_CENTER_VERTICAL);
129 pAuthorsz->Add(pAuthorbt, 0, wxALIGN_CENTER | wxLEFT, 10);
132 wxBoxSizer* pVersionsz = new wxBoxSizer(wxHORIZONTAL);
133 this->versiontc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->package->GetVersion()));
134 wxButton* pVersionbt = new wxButton(propertiesPanel, ID_BUTTON_SET_VERSION, wxT("Set"));
135 pVersionbt->SetToolTip(wxT("Update the version of the package."));
136 pVersionsz->Add(this->versiontc, 1, wxALIGN_CENTER_VERTICAL);
137 pVersionsz->Add(pVersionbt, 0, wxALIGN_CENTER | wxLEFT, 10);
140 wxBoxSizer* pDescriptionsz = new wxBoxSizer(wxHORIZONTAL);
141 this->descriptiontc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->package->GetDescription()));
142 wxButton* pDescriptionbt = new wxButton(propertiesPanel, ID_BUTTON_SET_DESCRIPTION, wxT("Change"));
143 pDescriptionbt->SetToolTip(wxT("Update the description of the project."));
144 pDescriptionsz->Add(this->descriptiontc, 1, wxALIGN_CENTER_VERTICAL);
145 pDescriptionsz->Add(pDescriptionbt, 0, wxALIGN_CENTER | wxLEFT, 10);
147 propertiesGridSizer->Add(pAuthor, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
148 propertiesGridSizer->Add(pAuthorsz, 1, wxEXPAND);
149 propertiesGridSizer->Add(pVersion, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
150 propertiesGridSizer->Add(pVersionsz, 1, wxEXPAND);
151 propertiesGridSizer->Add(pDescription, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
152 propertiesGridSizer->Add(pDescriptionsz, 1, wxEXPAND);
154 propertiesGridSizer->AddGrowableCol(1,1);
156 propertiesPanelSizer -> Add(propertiesGridSizer, 1, wxEXPAND);
157 propertiesPanel->SetSizer(propertiesPanelSizer);
158 propertiesPanelSizer->Fit(propertiesPanel);
159 propertiesBox->Add(propertiesPanel, 0, wxEXPAND | wxALL, 5);
161 sizer->Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
164 wxStaticBoxSizer* BBBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("A&vailable Black Boxes"));
165 BBBox->GetStaticBox()->SetToolTip(wxT("Select any of the available black boxes to see its details or modify them."));
166 wxPanel* BBPanel = new wxPanel(this);
167 wxBoxSizer* BBPanelSizer = new wxBoxSizer(wxVERTICAL);
170 std::vector<modelCDMBlackBox*> blackBoxes = this->package->GetSrc()->GetBlackBoxes();
171 for (int i = 0; i < blackBoxes.size(); i++)
174 if(blackBoxes[i] != NULL)
177 wxHyperlinkCtrl* pBBlk = new wxHyperlinkCtrl(BBPanel,ID_LINK_SELECT_BLACKBOX, crea::std2wx(blackBoxes[i]->GetName().c_str()), crea::std2wx(blackBoxes[i]->GetName().c_str()));
178 std::string tt = "Author: " + blackBoxes[i]->GetAuthors() + "\nDescription: " + blackBoxes[i]->GetDescription() + "\nCategories: " + blackBoxes[i]->GetCategories();
179 pBBlk->SetToolTip(crea::std2wx(tt));
180 pBBlk->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnMouseEnter,NULL,this);
181 pBBlk->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnMouseExit,NULL,this);
182 BBPanelSizer -> Add(pBBlk, 0, wxALIGN_LEFT | wxALL, 5);
186 BBPanel->SetSizer(BBPanelSizer);
187 BBPanelSizer->Fit(BBPanel);
188 BBBox->Add(BBPanel, 0, wxALL, 5);
190 sizer -> Add(BBBox, 0, wxEXPAND | wxALL, 10);
193 wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions"));
194 wxPanel* actionsPanel = new wxPanel(this);
195 wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
197 wxButton* createBBbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_BLACKBOX, _T("Create Black Box"));
198 createBBbt->SetToolTip(wxT("Create a new black box for the active project inside this package."));
199 actionsPanelSizer->Add(createBBbt, 0, wxALL, 5);
200 wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists File"));
201 editCMakebt->SetToolTip(wxT("Open the system default text editor to edit the package's CMakeLists.txt file."));
202 editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnCMakeMouseEnter,NULL,this);
203 editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnCMakeMouseExit,NULL,this);
204 actionsPanelSizer->Add(editCMakebt, 0, wxALL, 5);
205 wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("Open Package Folder"));
206 openFolderbt->SetToolTip(wxT("Open the package folder in the file explorer."));
207 actionsPanelSizer->Add(openFolderbt, 0, wxALL, 5);
209 actionsPanel->SetSizer(actionsPanelSizer);
210 actionsPanelSizer->Fit(actionsPanel);
211 actionsBox->Add(actionsPanel, 0, wxEXPAND);
212 sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 10);
216 sizer->SetSizeHints(this);
218 if (((wxCDMMainFrame*)this->GetParent())->isHelp())
220 wxCDMPackageHelpDialog* helpDialog = new wxCDMPackageHelpDialog(this->GetParent(), this->package, wxID_ANY);
221 helpDialog->Show(true);
225 void wxCDMPackageDescriptionPanel::OnBtnReturn(wxCommandEvent& event)
227 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
228 newEvent->SetInt(((wxCDMMainFrame*)this->GetParent())->GetModel()->GetProject()->GetId());
230 wxPostEvent(this->GetParent(), *newEvent);
233 void wxCDMPackageDescriptionPanel::OnBtnSetAuthor(wxCommandEvent& event)
235 //get author from user
236 wxTextEntryDialog* authDlg = new wxTextEntryDialog(
238 wxT("Enter the new authors name. Separate each author with a '/'."),
239 wxT("Change Package Author - creaDevManager"),
240 crea::std2wx(this->package->GetAuthors()),
241 wxTE_MULTILINE | wxOK | wxCANCEL
244 if (authDlg->ShowModal() == wxID_OK)
246 std::string authorsStr = crea::wx2std(authDlg->GetValue());
248 if(authorsStr.size() > 0)
251 if(!this->package->SetAuthors(authorsStr, result))
252 wxMessageBox(crea::std2wx(*result),_T("Change Package Author - Error!"),wxOK | wxICON_ERROR);
254 this->authortc->SetLabel(crea::std2wx(this->package->GetAuthors()));
255 this->authortc->GetParent()->GetSizer()->RecalcSizes();
260 void wxCDMPackageDescriptionPanel::OnBtnSetVersion(wxCommandEvent& event)
263 wxString versionWx = wxGetTextFromUser(
264 wxT("Enter the new version name"),
265 wxT("Change Package Version - creaDevManager"),
266 crea::std2wx(this->package->GetVersion())
269 std::vector<std::string> parts;
270 CDMUtilities::splitter::split(parts, crea::wx2std(versionWx), " .", CDMUtilities::splitter::no_empties);
271 if(parts.size() == 3)
274 if(!this->package->SetVersion(crea::wx2std(versionWx), result))
275 wxMessageBox(crea::std2wx(*result),_T("Change Package Version - Error!"),wxOK | wxICON_ERROR);
279 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);
281 this->versiontc->SetLabel(crea::std2wx(this->package->GetVersion()));
284 void wxCDMPackageDescriptionPanel::OnBtnSetDescription(wxCommandEvent& event)
286 //get description from user
287 wxTextEntryDialog* descDlg = new wxTextEntryDialog(
289 wxT("Edit the package description."),
290 wxT("Change Package Description - creaDevManager"),
291 crea::std2wx(this->package->GetDescription()),
292 wxTE_MULTILINE | wxOK | wxCANCEL
295 if (descDlg->ShowModal() == wxID_OK)
297 std::string descriptionStr = crea::wx2std(descDlg->GetValue());
299 if(descriptionStr.size() > 0)
302 if(!this->package->SetDescription(descriptionStr, result))
303 wxMessageBox(crea::std2wx(*result),_T("Change Package Description - Error!"),wxOK | wxICON_ERROR);
305 this->descriptiontc->SetLabel(crea::std2wx(this->package->GetDescription()));
306 this->descriptiontc->GetParent()->GetSizer()->RecalcSizes();
310 void wxCDMPackageDescriptionPanel::OnLnkBlackBoxSelect(wxHyperlinkEvent& event)
313 modelCDMBlackBox* bb;
314 std::vector<modelCDMBlackBox*> bbs = this->package->GetSrc()->GetBlackBoxes();
315 for (int i = 0; i < bbs.size(); i++)
317 if(bbs[i]->GetName() == crea::wx2std(event.GetURL()))
319 bbId = bbs[i]->GetHeaderFile()->GetId();
325 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
326 newEvent->SetClientData(bb);
328 newEvent->SetString(wxT("blackbox"));
329 wxPostEvent(this->GetParent(), *newEvent);
331 wxCommandEvent* newEvent1 = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
332 newEvent1->SetInt(bbId);
334 wxPostEvent(this->GetParent(), *newEvent1);
338 void wxCDMPackageDescriptionPanel::OnBtnCreateBlackBox(wxCommandEvent& event)
341 wxCDMNewBlackBoxDialog* dialog = new wxCDMNewBlackBoxDialog(this);
343 userResponse = dialog->ShowModal();
345 if(userResponse == wxID_FORWARD)
349 modelCDMIProjectTreeNode* blackBox = this->package->CreateBlackBox(
351 crea::wx2std(dialog->GetBlackBoxName()),
352 crea::wx2std(dialog->GetBlackBoxType()),
353 crea::wx2std(dialog->GetBlackBoxFormat()),
354 crea::wx2std(dialog->GetBlackBoxCategories()),
355 crea::wx2std(dialog->GetBlackBoxAuthor()),
356 crea::wx2std(dialog->GetBlackBoxAuthorEmail()),
357 crea::wx2std(dialog->GetBlackBoxDescription())
359 //check black box created
362 wxMessageBox(crea::std2wx(*result),_T("New Black Box - Error!"),wxOK | wxICON_ERROR);
365 wxMessageBox(crea::std2wx("Black box successfully created."),_T("New Black Box - Success!"),wxOK | wxICON_INFORMATION);
367 //refreshing tree and description
368 //send event instead of calling parent to avoid crashing
370 ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
372 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
374 newEvent->SetInt(blackBox->GetId());
375 newEvent->SetString(wxT("blackbox"));
376 newEvent->SetClientData(blackBox);
377 wxPostEvent(this->GetParent(), *newEvent);
381 void wxCDMPackageDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
384 if(!this->package->OpenCMakeListsFile(result))
385 wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
387 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
389 if(this->package->GetCMakeLists() != NULL)
391 int CMId = this->package->GetCMakeLists()->GetId();
392 newEvent->SetInt(CMId);
394 wxPostEvent(this->GetParent(), *newEvent);
400 void wxCDMPackageDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
403 if(!this->package->OpenInFileExplorer(result))
404 wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
407 void wxCDMPackageDescriptionPanel::OnMouseEnter(wxMouseEvent& event)
409 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
410 std::string BBName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
413 std::vector<modelCDMBlackBox*> boxes = this->package->GetSrc()->GetBlackBoxes();
414 for (int i = 0; i < boxes.size(); i++)
416 if(boxes[i]->GetName() == BBName)
418 bbId = boxes[i]->GetHeaderFile()->GetId();
422 newEvent->SetInt(bbId);
424 wxPostEvent(this->GetParent(), *newEvent);
428 void wxCDMPackageDescriptionPanel::OnMouseExit(wxMouseEvent& event)
430 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
431 std::string BBName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
433 std::vector<modelCDMBlackBox*> boxes = this->package->GetSrc()->GetBlackBoxes();
434 for (int i = 0; i < boxes.size(); i++)
436 if(boxes[i]->GetName() == BBName)
438 bbId = boxes[i]->GetHeaderFile()->GetId();
442 newEvent->SetInt(bbId);
444 wxPostEvent(this->GetParent(), *newEvent);
448 void wxCDMPackageDescriptionPanel::OnCMakeMouseEnter(wxMouseEvent& event)
450 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
452 if(this->package->GetCMakeLists() != NULL)
454 int CMId = this->package->GetCMakeLists()->GetId();
455 newEvent->SetInt(CMId);
457 wxPostEvent(this->GetParent(), *newEvent);
462 void wxCDMPackageDescriptionPanel::OnCMakeMouseExit(wxMouseEvent& event)
464 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
466 if(this->package->GetCMakeLists() != NULL)
468 int CMId = this->package->GetCMakeLists()->GetId();
469 newEvent->SetInt(CMId);
471 wxPostEvent(this->GetParent(), *newEvent);