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 <wx/textdlg.h>
43 #include "CDMUtilities.h"
45 BEGIN_EVENT_TABLE(wxCDMPackageDescriptionPanel, wxPanel)
46 EVT_BUTTON(ID_BUTTON_PREV, wxCDMPackageDescriptionPanel::OnBtnReturn)
47 EVT_BUTTON(ID_BUTTON_SET_AUTHOR, wxCDMPackageDescriptionPanel::OnBtnSetAuthor)
48 EVT_BUTTON(ID_BUTTON_SET_VERSION, wxCDMPackageDescriptionPanel::OnBtnSetVersion)
49 EVT_BUTTON(ID_BUTTON_SET_DESCRIPTION, wxCDMPackageDescriptionPanel::OnBtnSetDescription)
50 EVT_HYPERLINK(ID_LINK_SELECT_BLACKBOX, wxCDMPackageDescriptionPanel::OnLnkBlackBoxSelect)
51 EVT_BUTTON(ID_BUTTON_CREATE_BLACKBOX, wxCDMPackageDescriptionPanel::OnBtnCreateBlackBox)
52 EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMPackageDescriptionPanel::OnBtnEditCMakeLists)
53 EVT_BUTTON(ID_BUTTON_OPEN_FOLDER, wxCDMPackageDescriptionPanel::OnBtnOpenFolder)
56 wxCDMPackageDescriptionPanel::wxCDMPackageDescriptionPanel(
58 modelCDMPackage* package,
60 const wxString& caption,
66 wxCDMPackageDescriptionPanel::Create(parent, package, id, caption, pos, size, style);
69 wxCDMPackageDescriptionPanel::~wxCDMPackageDescriptionPanel()
73 bool wxCDMPackageDescriptionPanel::Create(
75 modelCDMPackage* package,
77 const wxString& caption,
83 wxPanel::Create(parent, id, pos, size, style);
84 this->package = package;
89 void wxCDMPackageDescriptionPanel::CreateControls()
91 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
94 wxButton* returnbt = new wxButton(this, ID_BUTTON_PREV, wxT("Return to project"));
95 returnbt->SetToolTip(wxT("Return to the active project description."));
96 sizer->Add(returnbt, 0, wxALIGN_CENTER | wxALL, 5);
99 sizer->Add(new wxStaticText(this, -1, _("Package")),0, wxALIGN_CENTER, 0);
102 sizer->Add(new wxStaticBitmap(this, -1, wxBitmap(PkIcon64)),0, wxALIGN_CENTER, 0);
105 sizer->Add(new wxStaticText(this, -1, crea::std2wx(this->package->GetNamePackage())),0, wxALIGN_CENTER, 0);
108 wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Properties"));
109 wxPanel* propertiesPanel = new wxPanel(this);
110 wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL);
111 wxFlexGridSizer* propertiesGridSizer = new wxFlexGridSizer(4, 2, 9, 15);
113 wxStaticText *pAuthor = new wxStaticText(propertiesPanel, -1, wxT("Author"));
114 wxStaticText *pVersion = new wxStaticText(propertiesPanel, -1, wxT("Version"));
115 wxStaticText *pDescription = new wxStaticText(propertiesPanel, -1, wxT("Description"));
118 wxBoxSizer* pAuthorsz = new wxBoxSizer(wxHORIZONTAL);
119 this->authortc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->package->GetAuthors()));
120 wxButton* pAuthorbt = new wxButton(propertiesPanel, ID_BUTTON_SET_AUTHOR, wxT("Change"));
121 pAuthorbt->SetToolTip(wxT("Update the author/s of the package."));
122 pAuthorsz->Add(this->authortc, 1, wxALIGN_CENTER_VERTICAL);
123 pAuthorsz->Add(pAuthorbt, 0, wxALIGN_CENTER | wxLEFT, 10);
126 wxBoxSizer* pVersionsz = new wxBoxSizer(wxHORIZONTAL);
127 this->versiontc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->package->GetVersion()));
128 wxButton* pVersionbt = new wxButton(propertiesPanel, ID_BUTTON_SET_VERSION, wxT("Set"));
129 pVersionbt->SetToolTip(wxT("Update the version of the package."));
130 pVersionsz->Add(this->versiontc, 1, wxALIGN_CENTER_VERTICAL);
131 pVersionsz->Add(pVersionbt, 0, wxALIGN_CENTER | wxLEFT, 10);
134 wxBoxSizer* pDescriptionsz = new wxBoxSizer(wxHORIZONTAL);
135 this->descriptiontc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->package->GetDescription()));
136 wxButton* pDescriptionbt = new wxButton(propertiesPanel, ID_BUTTON_SET_DESCRIPTION, wxT("Change"));
137 pDescriptionbt->SetToolTip(wxT("Update the description of the project."));
138 pDescriptionsz->Add(this->descriptiontc, 1, wxALIGN_CENTER_VERTICAL);
139 pDescriptionsz->Add(pDescriptionbt, 0, wxALIGN_CENTER | wxLEFT, 10);
141 propertiesGridSizer->Add(pAuthor, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
142 propertiesGridSizer->Add(pAuthorsz, 1, wxEXPAND);
143 propertiesGridSizer->Add(pVersion, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
144 propertiesGridSizer->Add(pVersionsz, 1, wxEXPAND);
145 propertiesGridSizer->Add(pDescription, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
146 propertiesGridSizer->Add(pDescriptionsz, 1, wxEXPAND);
148 propertiesGridSizer->AddGrowableCol(1,1);
150 propertiesPanelSizer -> Add(propertiesGridSizer, 1, wxEXPAND);
151 propertiesPanel->SetSizer(propertiesPanelSizer);
152 propertiesPanelSizer->Fit(propertiesPanel);
153 propertiesBox->Add(propertiesPanel, 0, wxEXPAND | wxALL, 5);
155 sizer->Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
158 wxStaticBoxSizer* BBBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("A&vailable Black Boxes"));
159 BBBox->GetStaticBox()->SetToolTip(wxT("Select any of the available black boxes to see its details or modify them."));
160 wxPanel* BBPanel = new wxPanel(this);
161 wxBoxSizer* BBPanelSizer = new wxBoxSizer(wxVERTICAL);
164 std::vector<modelCDMBlackBox*> blackBoxes = this->package->GetSrc()->GetBlackBoxes();
165 for (int i = 0; i < blackBoxes.size(); i++)
168 if(blackBoxes[i] != NULL)
171 wxHyperlinkCtrl* pBBlk = new wxHyperlinkCtrl(BBPanel,ID_LINK_SELECT_BLACKBOX, crea::std2wx(blackBoxes[i]->GetName().c_str()), crea::std2wx(blackBoxes[i]->GetName().c_str()));
172 std::string tt = "Author: " + blackBoxes[i]->GetAuthors() + "\nDescription: " + blackBoxes[i]->GetDescription() + "\nCategories: " + blackBoxes[i]->GetCategories();
173 pBBlk->SetToolTip(crea::std2wx(tt));
174 pBBlk->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnMouseEnter,NULL,this);
175 pBBlk->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnMouseExit,NULL,this);
176 BBPanelSizer -> Add(pBBlk, 0, wxALIGN_LEFT | wxALL, 5);
180 BBPanel->SetSizer(BBPanelSizer);
181 BBPanelSizer->Fit(BBPanel);
182 BBBox->Add(BBPanel, 0, wxALL, 5);
184 sizer -> Add(BBBox, 0, wxEXPAND | wxALL, 10);
187 wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions"));
188 wxPanel* actionsPanel = new wxPanel(this);
189 wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
191 wxButton* createBBbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_BLACKBOX, _T("Create Black Box"));
192 createBBbt->SetToolTip(wxT("Create a new black box for the active project inside this package."));
193 actionsPanelSizer->Add(createBBbt, 0, wxALL, 5);
194 wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists File"));
195 editCMakebt->SetToolTip(wxT("Open the system default text editor to edit the package's CMakeLists.txt file."));
196 editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnCMakeMouseEnter,NULL,this);
197 editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnCMakeMouseExit,NULL,this);
198 actionsPanelSizer->Add(editCMakebt, 0, wxALL, 5);
199 wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("Open Package Folder"));
200 openFolderbt->SetToolTip(wxT("Open the package folder in the file explorer."));
201 actionsPanelSizer->Add(openFolderbt, 0, wxALL, 5);
203 actionsPanel->SetSizer(actionsPanelSizer);
204 actionsPanelSizer->Fit(actionsPanel);
205 actionsBox->Add(actionsPanel, 0, wxEXPAND);
206 sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 10);
210 sizer->SetSizeHints(this);
213 void wxCDMPackageDescriptionPanel::OnBtnReturn(wxCommandEvent& event)
215 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
216 newEvent->SetInt(((wxCDMMainFrame*)this->GetParent())->GetModel()->GetProject()->GetId());
218 wxPostEvent(this->GetParent(), *newEvent);
221 void wxCDMPackageDescriptionPanel::OnBtnSetAuthor(wxCommandEvent& event)
223 //get author from user
224 wxTextEntryDialog* authDlg = new wxTextEntryDialog(
226 wxT("Enter the new authors name. Separate each author with a '/'."),
227 wxT("Change Package Author - creaDevManager"),
228 crea::std2wx(this->package->GetAuthors()),
229 wxTE_MULTILINE | wxOK | wxCANCEL
232 if (authDlg->ShowModal() == wxID_OK)
234 std::string authorsStr = crea::wx2std(authDlg->GetValue());
236 if(authorsStr.size() > 0)
239 if(!this->package->SetAuthors(authorsStr, result))
240 wxMessageBox(crea::std2wx(*result),_T("Change Package Author - Error!"),wxOK | wxICON_ERROR);
242 this->authortc->SetLabel(crea::std2wx(this->package->GetAuthors()));
243 this->authortc->GetParent()->GetSizer()->RecalcSizes();
248 void wxCDMPackageDescriptionPanel::OnBtnSetVersion(wxCommandEvent& event)
251 wxString versionWx = wxGetTextFromUser(
252 wxT("Enter the new version name"),
253 wxT("Change Package Version - creaDevManager"),
254 crea::std2wx(this->package->GetVersion())
257 std::vector<std::string> parts;
258 CDMUtilities::splitter::split(parts, crea::wx2std(versionWx), " .", CDMUtilities::splitter::no_empties);
259 if(parts.size() == 3)
262 if(!this->package->SetVersion(crea::wx2std(versionWx), result))
263 wxMessageBox(crea::std2wx(*result),_T("Change Package Version - Error!"),wxOK | wxICON_ERROR);
267 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);
269 this->versiontc->SetLabel(crea::std2wx(this->package->GetVersion()));
272 void wxCDMPackageDescriptionPanel::OnBtnSetDescription(wxCommandEvent& event)
274 //get description from user
275 wxTextEntryDialog* descDlg = new wxTextEntryDialog(
277 wxT("Edit the package description."),
278 wxT("Change Package Description - creaDevManager"),
279 crea::std2wx(this->package->GetDescription()),
280 wxTE_MULTILINE | wxOK | wxCANCEL
283 if (descDlg->ShowModal() == wxID_OK)
285 std::string descriptionStr = crea::wx2std(descDlg->GetValue());
287 if(descriptionStr.size() > 0)
290 if(!this->package->SetDescription(descriptionStr, result))
291 wxMessageBox(crea::std2wx(*result),_T("Change Package Description - Error!"),wxOK | wxICON_ERROR);
293 this->descriptiontc->SetLabel(crea::std2wx(this->package->GetDescription()));
294 this->descriptiontc->GetParent()->GetSizer()->RecalcSizes();
298 void wxCDMPackageDescriptionPanel::OnLnkBlackBoxSelect(wxHyperlinkEvent& event)
301 modelCDMBlackBox* bb;
302 std::vector<modelCDMBlackBox*> bbs = this->package->GetSrc()->GetBlackBoxes();
303 for (int i = 0; i < bbs.size(); i++)
305 if(bbs[i]->GetName() == crea::wx2std(event.GetURL()))
307 bbId = bbs[i]->GetHeaderFile()->GetId();
313 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
314 newEvent->SetClientData(bb);
316 newEvent->SetString(wxT("blackbox"));
317 wxPostEvent(this->GetParent(), *newEvent);
319 wxCommandEvent* newEvent1 = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
320 newEvent1->SetInt(bbId);
322 wxPostEvent(this->GetParent(), *newEvent1);
326 void wxCDMPackageDescriptionPanel::OnBtnCreateBlackBox(wxCommandEvent& event)
328 //TODO: implement method
329 std::cerr << "Event OnBtnCreateBlackBox not implemented" << std::endl;
333 void wxCDMPackageDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
336 if(!this->package->OpenCMakeListsFile(result))
337 wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
339 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
341 if(this->package->GetCMakeLists() != NULL)
343 int CMId = this->package->GetCMakeLists()->GetId();
344 newEvent->SetInt(CMId);
346 wxPostEvent(this->GetParent(), *newEvent);
352 void wxCDMPackageDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
355 if(!this->package->OpenInFileExplorer(result))
356 wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
359 void wxCDMPackageDescriptionPanel::OnMouseEnter(wxMouseEvent& event)
361 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
362 std::string BBName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
365 std::vector<modelCDMBlackBox*> boxes = this->package->GetSrc()->GetBlackBoxes();
366 for (int i = 0; i < boxes.size(); i++)
368 if(boxes[i]->GetName() == BBName)
370 bbId = boxes[i]->GetHeaderFile()->GetId();
374 newEvent->SetInt(bbId);
376 wxPostEvent(this->GetParent(), *newEvent);
380 void wxCDMPackageDescriptionPanel::OnMouseExit(wxMouseEvent& event)
382 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
383 std::string BBName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
385 std::vector<modelCDMBlackBox*> boxes = this->package->GetSrc()->GetBlackBoxes();
386 for (int i = 0; i < boxes.size(); i++)
388 if(boxes[i]->GetName() == BBName)
390 bbId = boxes[i]->GetHeaderFile()->GetId();
394 newEvent->SetInt(bbId);
396 wxPostEvent(this->GetParent(), *newEvent);
400 void wxCDMPackageDescriptionPanel::OnCMakeMouseEnter(wxMouseEvent& event)
402 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
404 if(this->package->GetCMakeLists() != NULL)
406 int CMId = this->package->GetCMakeLists()->GetId();
407 newEvent->SetInt(CMId);
409 wxPostEvent(this->GetParent(), *newEvent);
414 void wxCDMPackageDescriptionPanel::OnCMakeMouseExit(wxMouseEvent& event)
416 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
418 if(this->package->GetCMakeLists() != NULL)
420 int CMId = this->package->GetCMakeLists()->GetId();
421 newEvent->SetInt(CMId);
423 wxPostEvent(this->GetParent(), *newEvent);