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 wxBoxSizer* headerSizer = new wxBoxSizer(wxHORIZONTAL);
108 headerSizer->Add(new wxStaticBitmap(this, -1, wxBitmap(PkIcon64)),0, wxALIGN_CENTER, 0);
109 wxBoxSizer* textSizer = new wxBoxSizer(wxVERTICAL);
111 textSizer->Add(new wxStaticText(this, -1, _("Package")),0, wxALIGN_LEFT, 0);
113 textSizer->Add(new wxStaticText(this, -1, crea::std2wx(this->package->GetNamePackage())),0, wxALIGN_LEFT, 0);
114 headerSizer->Add(textSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
116 sizer->Add(headerSizer, 0, wxALIGN_CENTER);
119 wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Properties"));
120 wxPanel* propertiesPanel = new wxPanel(this);
121 wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL);
122 wxFlexGridSizer* propertiesGridSizer = new wxFlexGridSizer(4, 2, 9, 15);
124 wxStaticText *pAuthor = new wxStaticText(propertiesPanel, -1, wxT("Author"));
125 wxStaticText *pVersion = new wxStaticText(propertiesPanel, -1, wxT("Version"));
126 wxStaticText *pDescription = new wxStaticText(propertiesPanel, -1, wxT("Description"));
129 wxBoxSizer* pAuthorsz = new wxBoxSizer(wxHORIZONTAL);
130 this->authortc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->package->GetAuthors()));
131 wxButton* pAuthorbt = new wxButton(propertiesPanel, ID_BUTTON_SET_AUTHOR, wxT("Change"));
132 pAuthorbt->SetToolTip(wxT("Update the author/s of the package."));
133 pAuthorsz->Add(this->authortc, 1, wxALIGN_CENTER_VERTICAL);
134 pAuthorsz->Add(pAuthorbt, 0, wxALIGN_CENTER | wxLEFT, 10);
137 wxBoxSizer* pVersionsz = new wxBoxSizer(wxHORIZONTAL);
138 this->versiontc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->package->GetVersion()));
139 wxButton* pVersionbt = new wxButton(propertiesPanel, ID_BUTTON_SET_VERSION, wxT("Set"));
140 pVersionbt->SetToolTip(wxT("Update the version of the package."));
141 pVersionsz->Add(this->versiontc, 1, wxALIGN_CENTER_VERTICAL);
142 pVersionsz->Add(pVersionbt, 0, wxALIGN_CENTER | wxLEFT, 10);
145 wxBoxSizer* pDescriptionsz = new wxBoxSizer(wxHORIZONTAL);
146 this->descriptiontc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->package->GetDescription()));
147 wxButton* pDescriptionbt = new wxButton(propertiesPanel, ID_BUTTON_SET_DESCRIPTION, wxT("Change"));
148 pDescriptionbt->SetToolTip(wxT("Update the description of the project."));
149 pDescriptionsz->Add(this->descriptiontc, 1, wxALIGN_CENTER_VERTICAL);
150 pDescriptionsz->Add(pDescriptionbt, 0, wxALIGN_CENTER | wxLEFT, 10);
152 propertiesGridSizer->Add(pAuthor, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
153 propertiesGridSizer->Add(pAuthorsz, 1, wxEXPAND);
154 propertiesGridSizer->Add(pVersion, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
155 propertiesGridSizer->Add(pVersionsz, 1, wxEXPAND);
156 propertiesGridSizer->Add(pDescription, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
157 propertiesGridSizer->Add(pDescriptionsz, 1, wxEXPAND);
159 propertiesGridSizer->AddGrowableCol(1,1);
161 propertiesPanelSizer -> Add(propertiesGridSizer, 1, wxEXPAND);
162 propertiesPanel->SetSizer(propertiesPanelSizer);
163 propertiesPanelSizer->Fit(propertiesPanel);
164 propertiesBox->Add(propertiesPanel, 0, wxEXPAND | wxALL, 5);
166 sizer->Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
169 wxStaticBoxSizer* BBBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("A&vailable Black Boxes"));
170 BBBox->GetStaticBox()->SetToolTip(wxT("Select any of the available black boxes to see its details or modify them."));
171 wxPanel* BBPanel = new wxPanel(this);
172 wxBoxSizer* BBPanelSizer = new wxBoxSizer(wxVERTICAL);
175 std::vector<modelCDMBlackBox*> blackBoxes = this->package->GetSrc()->GetBlackBoxes();
176 for (int i = 0; i < blackBoxes.size(); i++)
179 if(blackBoxes[i] != NULL)
182 wxHyperlinkCtrl* pBBlk = new wxHyperlinkCtrl(BBPanel,ID_LINK_SELECT_BLACKBOX, crea::std2wx(blackBoxes[i]->GetName().c_str()), crea::std2wx(blackBoxes[i]->GetName().c_str()));
183 pBBlk->SetWindowStyle(wxALIGN_LEFT);
184 std::string tt = "Author: " + blackBoxes[i]->GetAuthors() + "\nDescription: " + blackBoxes[i]->GetDescription() + "\nCategories: " + blackBoxes[i]->GetCategories();
185 pBBlk->SetToolTip(crea::std2wx(tt));
186 pBBlk->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnMouseEnter,NULL,this);
187 pBBlk->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnMouseExit,NULL,this);
188 BBPanelSizer -> Add(pBBlk, 0, wxEXPAND | wxALL, 5);
192 BBPanel->SetSizer(BBPanelSizer);
193 BBPanelSizer->Fit(BBPanel);
194 BBBox->Add(BBPanel, 1, wxEXPAND | wxALL, 5);
195 sizer -> Add(BBBox, 0, wxEXPAND | wxALL, 10);
198 wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions"));
199 wxPanel* actionsPanel = new wxPanel(this);
200 wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
202 wxFlexGridSizer* actionsGridSizer = new wxFlexGridSizer(2, 2, 9, 15);
204 wxButton* createBBbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_BLACKBOX, _T("A. Create Black Box"));
205 createBBbt->SetToolTip(wxT("Create a new black box for the active project inside this package."));
206 actionsGridSizer->Add(createBBbt, 1, wxALL | wxEXPAND, 5);
207 wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("B. Edit CMakeLists File"));
208 editCMakebt->SetToolTip(wxT("Open the system default text editor to edit the package's CMakeLists.txt file."));
209 editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnCMakeMouseEnter,NULL,this);
210 editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnCMakeMouseExit,NULL,this);
211 actionsGridSizer->Add(editCMakebt, 1, wxALL | wxEXPAND, 5);
212 wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("C. Open Package Folder"));
213 openFolderbt->SetToolTip(wxT("Open the package folder in the file explorer."));
214 actionsGridSizer->Add(openFolderbt, 1, wxALL | wxEXPAND, 5);
216 actionsGridSizer->AddGrowableCol(0,1);
217 actionsGridSizer->AddGrowableCol(1,1);
219 actionsPanelSizer->Add(actionsGridSizer, 1, wxEXPAND, 0);
220 actionsPanel->SetSizer(actionsPanelSizer);
221 actionsPanelSizer->Fit(actionsPanel);
222 actionsBox->Add(actionsPanel, 1, wxEXPAND);
223 sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 10);
227 sizer->SetSizeHints(this);
229 if (((wxCDMMainFrame*)this->GetParent())->isHelp())
231 wxCDMPackageHelpDialog* helpDialog = new wxCDMPackageHelpDialog(this->GetParent(), this->package, wxID_ANY);
232 helpDialog->Show(true);
236 void wxCDMPackageDescriptionPanel::OnBtnReturn(wxCommandEvent& event)
238 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
239 newEvent->SetInt(((wxCDMMainFrame*)this->GetParent())->GetModel()->GetProject()->GetId());
241 wxPostEvent(this->GetParent(), *newEvent);
244 void wxCDMPackageDescriptionPanel::OnBtnSetAuthor(wxCommandEvent& event)
246 //get author from user
247 wxTextEntryDialog* authDlg = new wxTextEntryDialog(
249 wxT("Enter the new authors name. Separate each author with a '/'."),
250 wxT("Change Package Author - creaDevManager"),
251 crea::std2wx(this->package->GetAuthors()),
252 wxTE_MULTILINE | wxOK | wxCANCEL
255 if (authDlg->ShowModal() == wxID_OK)
257 std::string authorsStr = crea::wx2std(authDlg->GetValue());
259 if(authorsStr.size() > 0)
262 if(!this->package->SetAuthors(authorsStr, result))
263 wxMessageBox(crea::std2wx(*result),_T("Change Package Author - Error!"),wxOK | wxICON_ERROR);
265 this->authortc->SetLabel(crea::std2wx(this->package->GetAuthors()));
266 this->authortc->GetParent()->GetSizer()->RecalcSizes();
271 void wxCDMPackageDescriptionPanel::OnBtnSetVersion(wxCommandEvent& event)
274 wxString versionWx = wxGetTextFromUser(
275 wxT("Enter the new version name"),
276 wxT("Change Package Version - creaDevManager"),
277 crea::std2wx(this->package->GetVersion())
280 std::vector<std::string> parts;
281 CDMUtilities::splitter::split(parts, crea::wx2std(versionWx), " .", CDMUtilities::splitter::no_empties);
282 if(parts.size() == 3)
285 if(!this->package->SetVersion(crea::wx2std(versionWx), result))
286 wxMessageBox(crea::std2wx(*result),_T("Change Package Version - Error!"),wxOK | wxICON_ERROR);
290 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);
292 this->versiontc->SetLabel(crea::std2wx(this->package->GetVersion()));
295 void wxCDMPackageDescriptionPanel::OnBtnSetDescription(wxCommandEvent& event)
297 //get description from user
298 wxTextEntryDialog* descDlg = new wxTextEntryDialog(
300 wxT("Edit the package description."),
301 wxT("Change Package Description - creaDevManager"),
302 crea::std2wx(this->package->GetDescription()),
303 wxTE_MULTILINE | wxOK | wxCANCEL
306 if (descDlg->ShowModal() == wxID_OK)
308 std::string descriptionStr = crea::wx2std(descDlg->GetValue());
310 if(descriptionStr.size() > 0)
313 if(!this->package->SetDescription(descriptionStr, result))
314 wxMessageBox(crea::std2wx(*result),_T("Change Package Description - Error!"),wxOK | wxICON_ERROR);
316 this->descriptiontc->SetLabel(crea::std2wx(this->package->GetDescription()));
317 this->descriptiontc->GetParent()->GetSizer()->RecalcSizes();
321 void wxCDMPackageDescriptionPanel::OnLnkBlackBoxSelect(wxHyperlinkEvent& event)
324 modelCDMBlackBox* bb;
325 std::vector<modelCDMBlackBox*> bbs = this->package->GetSrc()->GetBlackBoxes();
326 for (int i = 0; i < bbs.size(); i++)
328 if(bbs[i]->GetName() == crea::wx2std(event.GetURL()))
330 bbId = bbs[i]->GetHeaderFile()->GetId();
336 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
337 newEvent->SetClientData(bb);
339 newEvent->SetString(wxT("blackbox"));
340 wxPostEvent(this->GetParent(), *newEvent);
342 wxCommandEvent* newEvent1 = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
343 newEvent1->SetInt(bbId);
345 wxPostEvent(this->GetParent(), *newEvent1);
349 void wxCDMPackageDescriptionPanel::OnBtnCreateBlackBox(wxCommandEvent& event)
352 wxCDMNewBlackBoxDialog* dialog = new wxCDMNewBlackBoxDialog(this);
354 userResponse = dialog->ShowModal();
356 if(userResponse == wxID_FORWARD)
360 modelCDMIProjectTreeNode* blackBox = this->package->CreateBlackBox(
362 crea::wx2std(dialog->GetBlackBoxName()),
363 crea::wx2std(dialog->GetBlackBoxType()),
364 crea::wx2std(dialog->GetBlackBoxFormat()),
365 crea::wx2std(dialog->GetBlackBoxCategories()),
366 crea::wx2std(dialog->GetBlackBoxAuthor()),
367 crea::wx2std(dialog->GetBlackBoxAuthorEmail()),
368 crea::wx2std(dialog->GetBlackBoxDescription())
370 //check black box created
373 wxMessageBox(crea::std2wx(*result),_T("New Black Box - Error!"),wxOK | wxICON_ERROR);
376 wxMessageBox(crea::std2wx("Black box successfully created."),_T("New Black Box - Success!"),wxOK | wxICON_INFORMATION);
378 //refreshing tree and description
379 //send event instead of calling parent to avoid crashing
381 ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
383 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
385 newEvent->SetInt(blackBox->GetId());
386 newEvent->SetString(wxT("blackbox"));
387 newEvent->SetClientData(blackBox);
388 wxPostEvent(this->GetParent(), *newEvent);
392 void wxCDMPackageDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
395 if(!this->package->OpenCMakeListsFile(result))
396 wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
398 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
400 if(this->package->GetCMakeLists() != NULL)
402 int CMId = this->package->GetCMakeLists()->GetId();
403 newEvent->SetInt(CMId);
405 wxPostEvent(this->GetParent(), *newEvent);
411 void wxCDMPackageDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
414 if(!this->package->OpenInFileExplorer(result))
415 wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
418 void wxCDMPackageDescriptionPanel::OnMouseEnter(wxMouseEvent& event)
420 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
421 std::string BBName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
424 std::vector<modelCDMBlackBox*> boxes = this->package->GetSrc()->GetBlackBoxes();
425 for (int i = 0; i < boxes.size(); i++)
427 if(boxes[i]->GetName() == BBName)
429 bbId = boxes[i]->GetHeaderFile()->GetId();
433 newEvent->SetInt(bbId);
435 wxPostEvent(this->GetParent(), *newEvent);
439 void wxCDMPackageDescriptionPanel::OnMouseExit(wxMouseEvent& event)
441 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
442 std::string BBName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
444 std::vector<modelCDMBlackBox*> boxes = this->package->GetSrc()->GetBlackBoxes();
445 for (int i = 0; i < boxes.size(); i++)
447 if(boxes[i]->GetName() == BBName)
449 bbId = boxes[i]->GetHeaderFile()->GetId();
453 newEvent->SetInt(bbId);
455 wxPostEvent(this->GetParent(), *newEvent);
459 void wxCDMPackageDescriptionPanel::OnCMakeMouseEnter(wxMouseEvent& event)
461 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
463 if(this->package->GetCMakeLists() != NULL)
465 int CMId = this->package->GetCMakeLists()->GetId();
466 newEvent->SetInt(CMId);
468 wxPostEvent(this->GetParent(), *newEvent);
473 void wxCDMPackageDescriptionPanel::OnCMakeMouseExit(wxMouseEvent& event)
475 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
477 if(this->package->GetCMakeLists() != NULL)
479 int CMId = this->package->GetCMakeLists()->GetId();
480 newEvent->SetInt(CMId);
482 wxPostEvent(this->GetParent(), *newEvent);