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"
46 BEGIN_EVENT_TABLE(wxCDMPackageDescriptionPanel, wxPanel)
47 EVT_BUTTON(ID_BUTTON_PREV, wxCDMPackageDescriptionPanel::OnBtnReturn)
48 EVT_BUTTON(ID_BUTTON_SET_AUTHOR, wxCDMPackageDescriptionPanel::OnBtnSetAuthor)
49 EVT_BUTTON(ID_BUTTON_SET_VERSION, wxCDMPackageDescriptionPanel::OnBtnSetVersion)
50 EVT_BUTTON(ID_BUTTON_SET_DESCRIPTION, wxCDMPackageDescriptionPanel::OnBtnSetDescription)
51 EVT_HYPERLINK(ID_LINK_SELECT_BLACKBOX, wxCDMPackageDescriptionPanel::OnLnkBlackBoxSelect)
52 EVT_BUTTON(ID_BUTTON_CREATE_BLACKBOX, wxCDMPackageDescriptionPanel::OnBtnCreateBlackBox)
53 EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMPackageDescriptionPanel::OnBtnEditCMakeLists)
54 EVT_BUTTON(ID_BUTTON_OPEN_FOLDER, wxCDMPackageDescriptionPanel::OnBtnOpenFolder)
57 wxCDMPackageDescriptionPanel::wxCDMPackageDescriptionPanel(
59 modelCDMPackage* package,
61 const wxString& caption,
67 wxCDMPackageDescriptionPanel::Create(parent, package, id, caption, pos, size, style);
70 wxCDMPackageDescriptionPanel::~wxCDMPackageDescriptionPanel()
74 bool wxCDMPackageDescriptionPanel::Create(
76 modelCDMPackage* package,
78 const wxString& caption,
84 wxPanel::Create(parent, id, pos, size, style);
85 this->package = package;
90 void wxCDMPackageDescriptionPanel::CreateControls()
92 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
95 wxButton* returnbt = new wxButton(this, ID_BUTTON_PREV, wxT("Return to project"));
96 returnbt->SetToolTip(wxT("Return to the active project description."));
97 sizer->Add(returnbt, 0, wxALIGN_CENTER | wxALL, 5);
100 sizer->Add(new wxStaticText(this, -1, _("Package")),0, wxALIGN_CENTER, 0);
103 sizer->Add(new wxStaticBitmap(this, -1, wxBitmap(PkIcon64)),0, wxALIGN_CENTER, 0);
106 sizer->Add(new wxStaticText(this, -1, crea::std2wx(this->package->GetNamePackage())),0, wxALIGN_CENTER, 0);
109 wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Properties"));
110 wxPanel* propertiesPanel = new wxPanel(this);
111 wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL);
112 wxFlexGridSizer* propertiesGridSizer = new wxFlexGridSizer(4, 2, 9, 15);
114 wxStaticText *pAuthor = new wxStaticText(propertiesPanel, -1, wxT("Author"));
115 wxStaticText *pVersion = new wxStaticText(propertiesPanel, -1, wxT("Version"));
116 wxStaticText *pDescription = new wxStaticText(propertiesPanel, -1, wxT("Description"));
119 wxBoxSizer* pAuthorsz = new wxBoxSizer(wxHORIZONTAL);
120 this->authortc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->package->GetAuthors()));
121 wxButton* pAuthorbt = new wxButton(propertiesPanel, ID_BUTTON_SET_AUTHOR, wxT("Change"));
122 pAuthorbt->SetToolTip(wxT("Update the author/s of the package."));
123 pAuthorsz->Add(this->authortc, 1, wxALIGN_CENTER_VERTICAL);
124 pAuthorsz->Add(pAuthorbt, 0, wxALIGN_CENTER | wxLEFT, 10);
127 wxBoxSizer* pVersionsz = new wxBoxSizer(wxHORIZONTAL);
128 this->versiontc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->package->GetVersion()));
129 wxButton* pVersionbt = new wxButton(propertiesPanel, ID_BUTTON_SET_VERSION, wxT("Set"));
130 pVersionbt->SetToolTip(wxT("Update the version of the package."));
131 pVersionsz->Add(this->versiontc, 1, wxALIGN_CENTER_VERTICAL);
132 pVersionsz->Add(pVersionbt, 0, wxALIGN_CENTER | wxLEFT, 10);
135 wxBoxSizer* pDescriptionsz = new wxBoxSizer(wxHORIZONTAL);
136 this->descriptiontc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->package->GetDescription()));
137 wxButton* pDescriptionbt = new wxButton(propertiesPanel, ID_BUTTON_SET_DESCRIPTION, wxT("Change"));
138 pDescriptionbt->SetToolTip(wxT("Update the description of the project."));
139 pDescriptionsz->Add(this->descriptiontc, 1, wxALIGN_CENTER_VERTICAL);
140 pDescriptionsz->Add(pDescriptionbt, 0, wxALIGN_CENTER | wxLEFT, 10);
142 propertiesGridSizer->Add(pAuthor, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
143 propertiesGridSizer->Add(pAuthorsz, 1, wxEXPAND);
144 propertiesGridSizer->Add(pVersion, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
145 propertiesGridSizer->Add(pVersionsz, 1, wxEXPAND);
146 propertiesGridSizer->Add(pDescription, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
147 propertiesGridSizer->Add(pDescriptionsz, 1, wxEXPAND);
149 propertiesGridSizer->AddGrowableCol(1,1);
151 propertiesPanelSizer -> Add(propertiesGridSizer, 1, wxEXPAND);
152 propertiesPanel->SetSizer(propertiesPanelSizer);
153 propertiesPanelSizer->Fit(propertiesPanel);
154 propertiesBox->Add(propertiesPanel, 0, wxEXPAND | wxALL, 5);
156 sizer->Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
159 wxStaticBoxSizer* BBBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("A&vailable Black Boxes"));
160 BBBox->GetStaticBox()->SetToolTip(wxT("Select any of the available black boxes to see its details or modify them."));
161 wxPanel* BBPanel = new wxPanel(this);
162 wxBoxSizer* BBPanelSizer = new wxBoxSizer(wxVERTICAL);
165 std::vector<modelCDMBlackBox*> blackBoxes = this->package->GetSrc()->GetBlackBoxes();
166 for (int i = 0; i < blackBoxes.size(); i++)
169 if(blackBoxes[i] != NULL)
172 wxHyperlinkCtrl* pBBlk = new wxHyperlinkCtrl(BBPanel,ID_LINK_SELECT_BLACKBOX, crea::std2wx(blackBoxes[i]->GetName().c_str()), crea::std2wx(blackBoxes[i]->GetName().c_str()));
173 std::string tt = "Author: " + blackBoxes[i]->GetAuthors() + "\nDescription: " + blackBoxes[i]->GetDescription() + "\nCategories: " + blackBoxes[i]->GetCategories();
174 pBBlk->SetToolTip(crea::std2wx(tt));
175 pBBlk->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnMouseEnter,NULL,this);
176 pBBlk->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnMouseExit,NULL,this);
177 BBPanelSizer -> Add(pBBlk, 0, wxALIGN_LEFT | wxALL, 5);
181 BBPanel->SetSizer(BBPanelSizer);
182 BBPanelSizer->Fit(BBPanel);
183 BBBox->Add(BBPanel, 0, wxALL, 5);
185 sizer -> Add(BBBox, 0, wxEXPAND | wxALL, 10);
188 wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions"));
189 wxPanel* actionsPanel = new wxPanel(this);
190 wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
192 wxButton* createBBbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_BLACKBOX, _T("Create Black Box"));
193 createBBbt->SetToolTip(wxT("Create a new black box for the active project inside this package."));
194 actionsPanelSizer->Add(createBBbt, 0, wxALL, 5);
195 wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists File"));
196 editCMakebt->SetToolTip(wxT("Open the system default text editor to edit the package's CMakeLists.txt file."));
197 editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnCMakeMouseEnter,NULL,this);
198 editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnCMakeMouseExit,NULL,this);
199 actionsPanelSizer->Add(editCMakebt, 0, wxALL, 5);
200 wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("Open Package Folder"));
201 openFolderbt->SetToolTip(wxT("Open the package folder in the file explorer."));
202 actionsPanelSizer->Add(openFolderbt, 0, wxALL, 5);
204 actionsPanel->SetSizer(actionsPanelSizer);
205 actionsPanelSizer->Fit(actionsPanel);
206 actionsBox->Add(actionsPanel, 0, wxEXPAND);
207 sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 10);
211 sizer->SetSizeHints(this);
214 void wxCDMPackageDescriptionPanel::OnBtnReturn(wxCommandEvent& event)
216 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
217 newEvent->SetInt(((wxCDMMainFrame*)this->GetParent())->GetModel()->GetProject()->GetId());
219 wxPostEvent(this->GetParent(), *newEvent);
222 void wxCDMPackageDescriptionPanel::OnBtnSetAuthor(wxCommandEvent& event)
224 //get author from user
225 wxTextEntryDialog* authDlg = new wxTextEntryDialog(
227 wxT("Enter the new authors name. Separate each author with a '/'."),
228 wxT("Change Package Author - creaDevManager"),
229 crea::std2wx(this->package->GetAuthors()),
230 wxTE_MULTILINE | wxOK | wxCANCEL
233 if (authDlg->ShowModal() == wxID_OK)
235 std::string authorsStr = crea::wx2std(authDlg->GetValue());
237 if(authorsStr.size() > 0)
240 if(!this->package->SetAuthors(authorsStr, result))
241 wxMessageBox(crea::std2wx(*result),_T("Change Package Author - Error!"),wxOK | wxICON_ERROR);
243 this->authortc->SetLabel(crea::std2wx(this->package->GetAuthors()));
244 this->authortc->GetParent()->GetSizer()->RecalcSizes();
249 void wxCDMPackageDescriptionPanel::OnBtnSetVersion(wxCommandEvent& event)
252 wxString versionWx = wxGetTextFromUser(
253 wxT("Enter the new version name"),
254 wxT("Change Package Version - creaDevManager"),
255 crea::std2wx(this->package->GetVersion())
258 std::vector<std::string> parts;
259 CDMUtilities::splitter::split(parts, crea::wx2std(versionWx), " .", CDMUtilities::splitter::no_empties);
260 if(parts.size() == 3)
263 if(!this->package->SetVersion(crea::wx2std(versionWx), result))
264 wxMessageBox(crea::std2wx(*result),_T("Change Package Version - Error!"),wxOK | wxICON_ERROR);
268 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);
270 this->versiontc->SetLabel(crea::std2wx(this->package->GetVersion()));
273 void wxCDMPackageDescriptionPanel::OnBtnSetDescription(wxCommandEvent& event)
275 //get description from user
276 wxTextEntryDialog* descDlg = new wxTextEntryDialog(
278 wxT("Edit the package description."),
279 wxT("Change Package Description - creaDevManager"),
280 crea::std2wx(this->package->GetDescription()),
281 wxTE_MULTILINE | wxOK | wxCANCEL
284 if (descDlg->ShowModal() == wxID_OK)
286 std::string descriptionStr = crea::wx2std(descDlg->GetValue());
288 if(descriptionStr.size() > 0)
291 if(!this->package->SetDescription(descriptionStr, result))
292 wxMessageBox(crea::std2wx(*result),_T("Change Package Description - Error!"),wxOK | wxICON_ERROR);
294 this->descriptiontc->SetLabel(crea::std2wx(this->package->GetDescription()));
295 this->descriptiontc->GetParent()->GetSizer()->RecalcSizes();
299 void wxCDMPackageDescriptionPanel::OnLnkBlackBoxSelect(wxHyperlinkEvent& event)
302 modelCDMBlackBox* bb;
303 std::vector<modelCDMBlackBox*> bbs = this->package->GetSrc()->GetBlackBoxes();
304 for (int i = 0; i < bbs.size(); i++)
306 if(bbs[i]->GetName() == crea::wx2std(event.GetURL()))
308 bbId = bbs[i]->GetHeaderFile()->GetId();
314 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
315 newEvent->SetClientData(bb);
317 newEvent->SetString(wxT("blackbox"));
318 wxPostEvent(this->GetParent(), *newEvent);
320 wxCommandEvent* newEvent1 = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
321 newEvent1->SetInt(bbId);
323 wxPostEvent(this->GetParent(), *newEvent1);
327 void wxCDMPackageDescriptionPanel::OnBtnCreateBlackBox(wxCommandEvent& event)
330 wxCDMNewBlackBoxDialog* dialog = new wxCDMNewBlackBoxDialog(this);
332 userResponse = dialog->ShowModal();
334 if(userResponse == wxID_FORWARD)
338 modelCDMIProjectTreeNode* blackBox = this->package->CreateBlackBox(
340 crea::wx2std(dialog->GetBlackBoxName()),
341 crea::wx2std(dialog->GetBlackBoxType()),
342 crea::wx2std(dialog->GetBlackBoxFormat()),
343 crea::wx2std(dialog->GetBlackBoxCategories()),
344 crea::wx2std(dialog->GetBlackBoxAuthor()),
345 crea::wx2std(dialog->GetBlackBoxAuthorEmail()),
346 crea::wx2std(dialog->GetBlackBoxDescription())
348 //check black box created
351 wxMessageBox(crea::std2wx(*result),_T("New Black Box - Error!"),wxOK | wxICON_ERROR);
354 wxMessageBox(crea::std2wx("Black box successfully created."),_T("New Black Box - Success!"),wxOK | wxICON_INFORMATION);
356 //refreshing tree and description
357 //send event instead of calling parent to avoid crashing
359 ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
361 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
363 newEvent->SetInt(blackBox->GetId());
364 newEvent->SetString(wxT("blackbox"));
365 newEvent->SetClientData(blackBox);
366 wxPostEvent(this->GetParent(), *newEvent);
370 void wxCDMPackageDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
373 if(!this->package->OpenCMakeListsFile(result))
374 wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
376 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
378 if(this->package->GetCMakeLists() != NULL)
380 int CMId = this->package->GetCMakeLists()->GetId();
381 newEvent->SetInt(CMId);
383 wxPostEvent(this->GetParent(), *newEvent);
389 void wxCDMPackageDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
392 if(!this->package->OpenInFileExplorer(result))
393 wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
396 void wxCDMPackageDescriptionPanel::OnMouseEnter(wxMouseEvent& event)
398 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
399 std::string BBName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
402 std::vector<modelCDMBlackBox*> boxes = this->package->GetSrc()->GetBlackBoxes();
403 for (int i = 0; i < boxes.size(); i++)
405 if(boxes[i]->GetName() == BBName)
407 bbId = boxes[i]->GetHeaderFile()->GetId();
411 newEvent->SetInt(bbId);
413 wxPostEvent(this->GetParent(), *newEvent);
417 void wxCDMPackageDescriptionPanel::OnMouseExit(wxMouseEvent& event)
419 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
420 std::string BBName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
422 std::vector<modelCDMBlackBox*> boxes = this->package->GetSrc()->GetBlackBoxes();
423 for (int i = 0; i < boxes.size(); i++)
425 if(boxes[i]->GetName() == BBName)
427 bbId = boxes[i]->GetHeaderFile()->GetId();
431 newEvent->SetInt(bbId);
433 wxPostEvent(this->GetParent(), *newEvent);
437 void wxCDMPackageDescriptionPanel::OnCMakeMouseEnter(wxMouseEvent& event)
439 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
441 if(this->package->GetCMakeLists() != NULL)
443 int CMId = this->package->GetCMakeLists()->GetId();
444 newEvent->SetInt(CMId);
446 wxPostEvent(this->GetParent(), *newEvent);
451 void wxCDMPackageDescriptionPanel::OnCMakeMouseExit(wxMouseEvent& event)
453 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
455 if(this->package->GetCMakeLists() != NULL)
457 int CMId = this->package->GetCMakeLists()->GetId();
458 newEvent->SetInt(CMId);
460 wxPostEvent(this->GetParent(), *newEvent);