]> Creatis software - crea.git/blob - lib/creaDevManagerLib/wxCDMPackageDescriptionPanel.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / wxCDMPackageDescriptionPanel.cpp
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 #                        pour la Sant�)
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
9 #
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.
16 #
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
21 #  liability.
22 #
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 # ------------------------------------------------------------------------
26  */
27
28 /*
29  * wxCDMPackageDescriptionPanel.cpp
30  *
31  *  Created on: Nov 27, 2012
32  *      Author: Daniel Felipe Gonzalez Obando
33  */
34
35 #include "wxCDMPackageDescriptionPanel.h"
36
37 #include "wxCDMMainFrame.h"
38
39 #include "creaDevManagerIds.h"
40 #include "images/PkIcon64.xpm"
41
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)
48 END_EVENT_TABLE()
49
50 wxCDMPackageDescriptionPanel::wxCDMPackageDescriptionPanel(
51     wxWindow* parent,
52     modelCDMPackage* package,
53     wxWindowID id,
54     const wxString& caption,
55     const wxPoint& pos,
56     const wxSize& size,
57     long style
58 )
59 {
60   wxCDMPackageDescriptionPanel::Create(parent, package, id, caption, pos, size, style);
61 }
62
63 wxCDMPackageDescriptionPanel::~wxCDMPackageDescriptionPanel()
64 {
65 }
66
67 bool wxCDMPackageDescriptionPanel::Create(
68     wxWindow* parent,
69     modelCDMPackage* package,
70     wxWindowID id,
71     const wxString& caption,
72     const wxPoint& pos,
73     const wxSize& size,
74     long style
75 )
76 {
77   wxPanel::Create(parent, id, pos, size, style);
78   this->package = package;
79   CreateControls();
80   return TRUE;
81 }
82
83 void wxCDMPackageDescriptionPanel::CreateControls()
84 {
85   wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
86
87   //Link to return
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);
91
92   //Title
93   sizer->Add(new wxStaticText(this, -1, _("Package")),0, wxALIGN_CENTER, 0);
94
95   //Image
96   sizer->Add(new wxStaticBitmap(this, -1, wxBitmap(PkIcon64)),0, wxALIGN_CENTER, 0);
97
98   //Package Name
99   sizer->Add(new wxStaticText(this, -1, crea::std2wx(this->package->GetNamePackage())),0, wxALIGN_CENTER, 0);
100
101   //Package Properties
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);
106
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"));
110
111   // author
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);
118
119   // version
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);
126
127   // description
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);
134
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);
141
142   propertiesPanelSizer -> Add(propertiesGridSizer, 1, wxEXPAND);
143   propertiesPanel->SetSizer(propertiesPanelSizer);
144   propertiesPanelSizer->Fit(propertiesPanel);
145   propertiesBox->Add(propertiesPanel, 0, wxALL, 5);
146
147   sizer->Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
148
149   //Black Boxes
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);
154
155   std::vector<modelCDMBlackBox*> blackBoxes = this->package->GetBlackBoxes();
156   for (int i = 0; i < blackBoxes.size(); i++)
157     {
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       BBPanelSizer -> Add(pBBlk, 0, wxALIGN_LEFT | wxALL, 5);
162     }
163
164   BBPanel->SetSizer(BBPanelSizer);
165   BBPanelSizer->Fit(BBPanel);
166   BBBox->Add(BBPanel, 0, wxALL, 5);
167
168   sizer -> Add(BBBox, 0, wxEXPAND | wxALL, 10);
169
170   //Actions
171   wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions"));
172   wxPanel* actionsPanel = new wxPanel(this);
173   wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
174
175   wxButton* createBBbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_BLACKBOX, _T("Create Black Box"));
176   createBBbt->SetToolTip(wxT("Create a new black box for the active project inside this package."));
177   actionsPanelSizer->Add(createBBbt, 0, wxALL, 5);
178   wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists File"));
179   editCMakebt->SetToolTip(wxT("Open the system default text editor to edit the package's CMakeLists.txt file."));
180   actionsPanelSizer->Add(editCMakebt, 0, wxALL, 5);
181   wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("Open Package Folder"));
182   openFolderbt->SetToolTip(wxT("Open the package folder in the file explorer."));
183   actionsPanelSizer->Add(openFolderbt, 0, wxALL, 5);
184
185   actionsPanel->SetSizer(actionsPanelSizer);
186   actionsPanelSizer->Fit(actionsPanel);
187   actionsBox->Add(actionsPanel, 0, wxEXPAND);
188   sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 10);
189
190   //Assign sizer
191   SetSizer(sizer);
192   sizer->SetSizeHints(this);
193 }
194
195 void wxCDMPackageDescriptionPanel::OnBtnReturn(wxCommandEvent& event)
196 {
197   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
198   newEvent->SetInt(((wxCDMMainFrame*)this->GetParent())->GetModel()->GetProject()->GetId());
199   newEvent->SetId(0);
200   wxPostEvent(this->GetParent(), *newEvent);
201 }
202
203 void wxCDMPackageDescriptionPanel::OnLnkBlackBoxSelect(wxHyperlinkEvent& event)
204 {
205   int bbId = 0;
206   std::vector<modelCDMBlackBox*> bbs = this->package->GetBlackBoxes();
207   for (int i = 0; i < bbs.size(); i++)
208     {
209       if(bbs[i]->GetName() == crea::wx2std(event.GetURL()))
210         {
211           bbId = bbs[i]->GetId();
212           break;
213         }
214     }
215
216   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
217   newEvent->SetInt(bbId);
218   newEvent->SetId(0);
219   wxPostEvent(this->GetParent(), *newEvent);
220
221 }
222
223 void wxCDMPackageDescriptionPanel::OnBtnCreateBlackBox(wxCommandEvent& event)
224 {
225   //TODO: implement method
226   std::cerr << "Event OnBtnCreateBlackBox not implemented" << std::endl;
227   event.Skip();
228 }
229
230 void wxCDMPackageDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
231 {
232   //TODO: implement method
233   std::cerr << "Event OnBtnEditCMakeLists not implemented" << std::endl;
234   event.Skip();
235 }
236
237 void wxCDMPackageDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
238 {
239   //TODO: implement method
240   std::cerr << "Event OnBtnOpenFolder not implemented" << std::endl;
241   event.Skip();
242 }
243