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 BEGIN_EVENT_TABLE(wxCDMPackageDescriptionPanel, wxPanel)
43 EVT_BUTTON(ID_BUTTON_PREV, wxCDMPackageDescriptionPanel::OnBtnReturn)
44 EVT_HYPERLINK(ID_LINK_SELECT_BLACKBOX, wxCDMPackageDescriptionPanel::OnLnkBlackBoxSelect)
45 EVT_BUTTON(ID_BUTTON_CREATE_BLACKBOX, wxCDMPackageDescriptionPanel::OnBtnCreateBlackBox)
46 EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMPackageDescriptionPanel::OnBtnEditCMakeLists)
47 EVT_BUTTON(ID_BUTTON_OPEN_FOLDER, wxCDMPackageDescriptionPanel::OnBtnOpenFolder)
50 wxCDMPackageDescriptionPanel::wxCDMPackageDescriptionPanel(
52 modelCDMPackage* package,
54 const wxString& caption,
60 wxCDMPackageDescriptionPanel::Create(parent, package, id, caption, pos, size, style);
63 wxCDMPackageDescriptionPanel::~wxCDMPackageDescriptionPanel()
67 bool wxCDMPackageDescriptionPanel::Create(
69 modelCDMPackage* package,
71 const wxString& caption,
77 wxPanel::Create(parent, id, pos, size, style);
78 this->package = package;
83 void wxCDMPackageDescriptionPanel::CreateControls()
85 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
88 wxButton* returnbt = new wxButton(this, ID_BUTTON_PREV, wxT("Return to project"));
89 returnbt->SetToolTip(wxT("Return to the active project description."));
90 sizer->Add(returnbt, 0, wxALIGN_CENTER | wxALL, 5);
93 sizer->Add(new wxStaticText(this, -1, _("Package")),0, wxALIGN_CENTER, 0);
96 sizer->Add(new wxStaticBitmap(this, -1, wxBitmap(PkIcon64)),0, wxALIGN_CENTER, 0);
99 sizer->Add(new wxStaticText(this, -1, crea::std2wx(this->package->GetNamePackage())),0, wxALIGN_CENTER, 0);
102 wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Properties"));
103 wxPanel* propertiesPanel = new wxPanel(this);
104 wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL);
105 wxFlexGridSizer* propertiesGridSizer = new wxFlexGridSizer(4, 2, 9, 15);
107 wxStaticText *pAuthor = new wxStaticText(propertiesPanel, -1, wxT("Author"));
108 wxStaticText *pVersion = new wxStaticText(propertiesPanel, -1, wxT("Version"));
109 wxStaticText *pDescription = new wxStaticText(propertiesPanel, -1, wxT("Description"));
112 wxBoxSizer* pAuthorsz = new wxBoxSizer(wxHORIZONTAL);
113 wxStaticText* pAuthortc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->package->GetAuthors()));
114 wxButton* pAuthorbt = new wxButton(propertiesPanel, ID_BUTTON_SET_VERSION, wxT("Change"));
115 pAuthorbt->SetToolTip(wxT("Update the author/s of the package."));
116 pAuthorsz->Add(pAuthortc, 0, wxALIGN_CENTER_VERTICAL, 0);
117 pAuthorsz->Add(pAuthorbt, 0, wxALIGN_CENTER | wxLEFT, 10);
120 wxBoxSizer* pVersionsz = new wxBoxSizer(wxHORIZONTAL);
121 wxStaticText* pVersiontc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->package->GetVersion()));
122 wxButton* pVersionbt = new wxButton(propertiesPanel, ID_BUTTON_SET_VERSION, wxT("Set"));
123 pVersionbt->SetToolTip(wxT("Update the version of the package."));
124 pVersionsz->Add(pVersiontc, 0, wxALIGN_CENTER_VERTICAL, 0);
125 pVersionsz->Add(pVersionbt, 0, wxALIGN_CENTER | wxLEFT, 10);
128 wxBoxSizer* pDescriptionsz = new wxBoxSizer(wxHORIZONTAL);
129 wxStaticText* pDescriptiontc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->package->GetDescription()));
130 wxButton* pDescriptionbt = new wxButton(propertiesPanel, ID_BUTTON_SET_VERSION, wxT("Change"));
131 pDescriptionbt->SetToolTip(wxT("Update the description of the project."));
132 pDescriptionsz->Add(pDescriptiontc, 0, wxALIGN_CENTER_VERTICAL, 0);
133 pDescriptionsz->Add(pDescriptionbt, 0, wxALIGN_CENTER | wxLEFT, 10);
135 propertiesGridSizer->Add(pAuthor, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
136 propertiesGridSizer->Add(pAuthorsz, 1, wxEXPAND);
137 propertiesGridSizer->Add(pVersion, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
138 propertiesGridSizer->Add(pVersionsz, 1, wxEXPAND);
139 propertiesGridSizer->Add(pDescription, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
140 propertiesGridSizer->Add(pDescriptionsz, 1, wxEXPAND);
142 propertiesPanelSizer -> Add(propertiesGridSizer, 1, wxEXPAND);
143 propertiesPanel->SetSizer(propertiesPanelSizer);
144 propertiesPanelSizer->Fit(propertiesPanel);
145 propertiesBox->Add(propertiesPanel, 0, wxALL, 5);
147 sizer->Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
150 wxStaticBoxSizer* BBBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("A&vailable Black Boxes"));
151 BBBox->GetStaticBox()->SetToolTip(wxT("Select any of the available black boxes to see its details or modify them."));
152 wxPanel* BBPanel = new wxPanel(this);
153 wxBoxSizer* BBPanelSizer = new wxBoxSizer(wxVERTICAL);
155 std::vector<modelCDMBlackBox*> blackBoxes = this->package->GetBlackBoxes();
156 for (int i = 0; i < blackBoxes.size(); i++)
158 wxHyperlinkCtrl* pBBlk = new wxHyperlinkCtrl(BBPanel,ID_LINK_SELECT_BLACKBOX, crea::std2wx(blackBoxes[i]->GetName().c_str()), crea::std2wx(blackBoxes[i]->GetName().c_str()));
159 std::string tt = "Author: " + blackBoxes[i]->GetAuthors() + "\nDescription: " + blackBoxes[i]->GetDescription() + "\nCategories: " + blackBoxes[i]->GetCategories();
160 pBBlk->SetToolTip(crea::std2wx(tt));
161 pBBlk->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnMouseEnter,NULL,this);
162 pBBlk->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnMouseExit,NULL,this);
163 BBPanelSizer -> Add(pBBlk, 0, wxALIGN_LEFT | wxALL, 5);
166 BBPanel->SetSizer(BBPanelSizer);
167 BBPanelSizer->Fit(BBPanel);
168 BBBox->Add(BBPanel, 0, wxALL, 5);
170 sizer -> Add(BBBox, 0, wxEXPAND | wxALL, 10);
173 wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions"));
174 wxPanel* actionsPanel = new wxPanel(this);
175 wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
177 wxButton* createBBbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_BLACKBOX, _T("Create Black Box"));
178 createBBbt->SetToolTip(wxT("Create a new black box for the active project inside this package."));
179 actionsPanelSizer->Add(createBBbt, 0, wxALL, 5);
180 wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists File"));
181 editCMakebt->SetToolTip(wxT("Open the system default text editor to edit the package's CMakeLists.txt file."));
182 editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnCMakeMouseEnter,NULL,this);
183 editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnCMakeMouseExit,NULL,this);
184 actionsPanelSizer->Add(editCMakebt, 0, wxALL, 5);
185 wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("Open Package Folder"));
186 openFolderbt->SetToolTip(wxT("Open the package folder in the file explorer."));
187 actionsPanelSizer->Add(openFolderbt, 0, wxALL, 5);
189 actionsPanel->SetSizer(actionsPanelSizer);
190 actionsPanelSizer->Fit(actionsPanel);
191 actionsBox->Add(actionsPanel, 0, wxEXPAND);
192 sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 10);
196 sizer->SetSizeHints(this);
199 void wxCDMPackageDescriptionPanel::OnBtnReturn(wxCommandEvent& event)
201 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
202 newEvent->SetInt(((wxCDMMainFrame*)this->GetParent())->GetModel()->GetProject()->GetId());
204 wxPostEvent(this->GetParent(), *newEvent);
207 void wxCDMPackageDescriptionPanel::OnLnkBlackBoxSelect(wxHyperlinkEvent& event)
210 std::vector<modelCDMBlackBox*> bbs = this->package->GetBlackBoxes();
211 for (int i = 0; i < bbs.size(); i++)
213 if(bbs[i]->GetName() == crea::wx2std(event.GetURL()))
215 bbId = bbs[i]->GetId();
220 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
221 newEvent->SetInt(bbId);
223 wxPostEvent(this->GetParent(), *newEvent);
225 wxCommandEvent* newEvent1 = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
226 newEvent1->SetInt(bbId);
228 wxPostEvent(this->GetParent(), *newEvent1);
232 void wxCDMPackageDescriptionPanel::OnBtnCreateBlackBox(wxCommandEvent& event)
234 //TODO: implement method
235 std::cerr << "Event OnBtnCreateBlackBox not implemented" << std::endl;
239 void wxCDMPackageDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
241 //TODO: implement method
242 std::cerr << "Event OnBtnEditCMakeLists not implemented" << std::endl;
244 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
246 if(this->package->GetCMakeLists() != NULL)
248 int CMId = this->package->GetCMakeLists()->GetId();
249 newEvent->SetInt(CMId);
251 wxPostEvent(this->GetParent(), *newEvent);
257 void wxCDMPackageDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
259 //TODO: implement method
260 std::cerr << "Event OnBtnOpenFolder not implemented" << std::endl;
264 void wxCDMPackageDescriptionPanel::OnMouseEnter(wxMouseEvent& event)
266 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
267 std::string BBName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
269 std::vector<modelCDMBlackBox*> boxes = this->package->GetBlackBoxes();
270 for (int i = 0; i < boxes.size(); i++)
272 if(boxes[i]->GetName() == BBName)
274 bbId = boxes[i]->GetId();
278 newEvent->SetInt(bbId);
280 wxPostEvent(this->GetParent(), *newEvent);
284 void wxCDMPackageDescriptionPanel::OnMouseExit(wxMouseEvent& event)
286 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
287 std::string BBName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
289 std::vector<modelCDMBlackBox*> boxes = this->package->GetBlackBoxes();
290 for (int i = 0; i < boxes.size(); i++)
292 if(boxes[i]->GetName() == BBName)
294 bbId = boxes[i]->GetId();
298 newEvent->SetInt(bbId);
300 wxPostEvent(this->GetParent(), *newEvent);
304 void wxCDMPackageDescriptionPanel::OnCMakeMouseEnter(wxMouseEvent& event)
306 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
308 if(this->package->GetCMakeLists() != NULL)
310 int CMId = this->package->GetCMakeLists()->GetId();
311 newEvent->SetInt(CMId);
313 wxPostEvent(this->GetParent(), *newEvent);
318 void wxCDMPackageDescriptionPanel::OnCMakeMouseExit(wxMouseEvent& event)
320 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
322 if(this->package->GetCMakeLists() != NULL)
324 int CMId = this->package->GetCMakeLists()->GetId();
325 newEvent->SetInt(CMId);
327 wxPostEvent(this->GetParent(), *newEvent);