]> Creatis software - crea.git/blob - lib/creaDevManagerLib/wxCDMProjectDescriptionPanel.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / wxCDMProjectDescriptionPanel.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  * wxCDMProjectDescriptionPanel.cpp
30  *
31  *  Created on: Nov 27, 2012
32  *      Author: Daniel Felipe Gonzalez Obando
33  */
34
35 #include "wxCDMProjectDescriptionPanel.h"
36
37 #include "wxCDMMainFrame.h"
38 #include "wxCDMNewPackageDialog.h"
39
40 #include "creaDevManagerIds.h"
41 #include "images/PrIcon64.xpm"
42
43 BEGIN_EVENT_TABLE(wxCDMProjectDescriptionPanel, wxPanel)
44 EVT_BUTTON(ID_BUTTON_GOTO_PACKAGE_MANAGER, wxCDMProjectDescriptionPanel::OnBtnManagePackages)
45 EVT_BUTTON(ID_BUTTON_GOTO_LIB_MANAGER, wxCDMProjectDescriptionPanel::OnBtnManageLibraries)
46 EVT_BUTTON(ID_BUTTON_GOTO_APPLI_MANAGER, wxCDMProjectDescriptionPanel::OnBtnManageApplications)
47 EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMProjectDescriptionPanel::OnBtnEditCMakeLists)
48
49 END_EVENT_TABLE()
50
51 wxCDMProjectDescriptionPanel::wxCDMProjectDescriptionPanel(
52     wxWindow* parent,
53     modelCDMProject* project,
54     wxWindowID id,
55     const wxString& caption,
56     const wxPoint& pos,
57     const wxSize& size,
58     long style
59 )
60 {
61   wxCDMProjectDescriptionPanel::Create(parent, project, id, caption, pos, size, style);
62 }
63
64 wxCDMProjectDescriptionPanel::~wxCDMProjectDescriptionPanel()
65 {
66 }
67
68 bool wxCDMProjectDescriptionPanel::Create(
69     wxWindow* parent,
70     modelCDMProject* project,
71     wxWindowID id,
72     const wxString& caption,
73     const wxPoint& pos,
74     const wxSize& size,
75     long style
76 )
77 {
78   wxPanel::Create(parent, id, pos, size, style);
79   this->project = project;
80   CreateControls();
81   return TRUE;
82 }
83
84 void wxCDMProjectDescriptionPanel::CreateControls()
85 {
86   wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
87
88   //Welcome
89   sizer->Add(new wxStaticText(this, -1, _("Project")),0, wxALIGN_CENTER, 0);
90
91   //Image
92   sizer->Add(new wxStaticBitmap(this, -1, wxBitmap(PrIcon64)),0, wxALIGN_CENTER, 0);
93
94   //Project Name
95   sizer->Add(new wxStaticText(this, -1, crea::std2wx(this->project->GetName())),0, wxALIGN_CENTER, 0);
96
97   //----------------------------------Project Properties-----------------------------------
98   //properties StaticBoxSizer
99   wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, _T("&Properties"));
100   //properties Panel
101   wxPanel* propertiesPanel = new wxPanel(this);
102   //properties Sizer
103   wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL);
104   //propertiesGrid Sizer
105   wxFlexGridSizer* propertiesGridSizer = new wxFlexGridSizer(4, 2, 9, 15);
106   //properties elements
107   //labels
108   wxStaticText* pVersion = new wxStaticText(propertiesPanel, wxID_ANY, wxT("Version"));
109   wxStaticText* pVersionDate = new wxStaticText(propertiesPanel, wxID_ANY, wxT("Version Date"));
110   wxStaticText* pSourceLocation = new wxStaticText(propertiesPanel, wxID_ANY, wxT("Source Location"));
111   wxStaticText* pBuildLocation = new wxStaticText(propertiesPanel, wxID_ANY, wxT("Build Location"));
112   //values
113   // version
114   wxBoxSizer* pVersionsz = new wxBoxSizer(wxHORIZONTAL);
115   wxStaticText* pVersiontc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->project->GetVersion()));
116   wxButton* pVersionbt = new wxButton(propertiesPanel, ID_BUTTON_SET_VERSION, wxT("Set"));
117   pVersionbt->SetToolTip(wxT("Update the version of the project."));
118   pVersionsz->Add(pVersiontc, 0, wxALIGN_CENTER_VERTICAL, 0);
119   pVersionsz->Add(pVersionbt, 0, wxALIGN_CENTER | wxLEFT, 10);
120   // versionDate
121   wxStaticText* pVersionDatetc = new wxStaticText(propertiesPanel, -1, crea::std2wx(this->project->GetVersionDate()));
122   // sourceLocation
123   wxStaticText* pSourceLocationtc = new wxStaticText(propertiesPanel, -1, crea::std2wx(this->project->GetPath()));
124   pSourceLocationtc->SetMaxSize(wxSize(350,-1));
125   // buildLocation
126   wxBoxSizer* pBuildLocationsz = new wxBoxSizer(wxHORIZONTAL);
127   wxStaticText* pBuildLocationtc = new wxStaticText(propertiesPanel, -1, crea::std2wx(this->project->GetBuildPath()));
128   pBuildLocationtc->SetMaxSize(wxSize(350,-1));
129   wxButton* pBuildLocationbt = new wxButton(propertiesPanel, ID_BUTTON_SET_BUILD_PATH, wxT("Choose"));
130   pBuildLocationbt->SetToolTip(wxT("Select a new location for compiling the project."));
131   pBuildLocationsz->Add(pBuildLocationtc, 0, wxALIGN_CENTER, 0);
132   pBuildLocationsz->Add(pBuildLocationbt, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 10);
133
134   propertiesGridSizer->Add(pVersion, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
135   propertiesGridSizer->Add(pVersionsz, 1, wxEXPAND);
136   propertiesGridSizer->Add(pVersionDate, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
137   propertiesGridSizer->Add(pVersionDatetc, 1, wxEXPAND);
138   propertiesGridSizer->Add(pSourceLocation, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
139   propertiesGridSizer->Add(pSourceLocationtc, 1, wxEXPAND);
140   propertiesGridSizer->Add(pBuildLocation, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
141   propertiesGridSizer->Add(pBuildLocationsz, 1, wxEXPAND);
142
143   propertiesGridSizer->AddGrowableCol(1,1);
144
145   propertiesPanelSizer-> Add(propertiesGridSizer, 0, wxALL | wxEXPAND, 5);
146
147   //SetPanel sizer and box
148   propertiesPanel->SetSizer(propertiesPanelSizer);
149   propertiesPanelSizer->Fit(propertiesPanel);
150   propertiesBox->Add(propertiesPanel, 1, wxEXPAND);
151   sizer->Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
152
153   //----------------------------------Project Actions--------------------------------------
154   //actions StaticBoxSizer
155   wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL,this, _T("&Actions"));
156   //actions Panel
157   wxPanel* actionsPanel = new wxPanel(this);
158   //actions Sizer
159   wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
160   //buttons
161   // package manager
162   wxButton* packageMgrbt = new wxButton(actionsPanel, ID_BUTTON_GOTO_PACKAGE_MANAGER, _T("Package Manager"));
163   packageMgrbt->SetToolTip(wxT("Find the current available packages into this project. You can also create new Packages in this section."));
164   actionsPanelSizer->Add(packageMgrbt, 0, wxALL, 5);
165   // lib manager
166   // show only if there is a lib folder
167   if(this->project->GetLib() != NULL)
168     {
169       wxButton* libMgrbt = new wxButton(actionsPanel, ID_BUTTON_GOTO_LIB_MANAGER, _T("Library Manager"));
170       libMgrbt->SetToolTip(wxT("Find the current available libraries into this project. You can also create new Libraries in this section as well as edit the lib folder's CMakeLists.txt file."));
171       actionsPanelSizer->Add(libMgrbt, 0, wxALL, 5);
172     }
173   // appli manager
174   // show only if there is a appli folder
175   if(this->project->GetAppli() != NULL)
176     {
177       wxButton* appliMgrbt = new wxButton(actionsPanel, ID_BUTTON_GOTO_APPLI_MANAGER, _T("Application Manager"));
178       appliMgrbt->SetToolTip(wxT("Find the current available applications into this project. You can also create new Applications in this section as well as edit the appli folder's CMakeLists.txt file."));
179       actionsPanelSizer->Add(appliMgrbt, 0, wxALL, 5);
180     }
181   // edit CMakeLists file
182   wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists File"));
183   editCMakebt->SetToolTip(wxT("Edit the CMakeLists.txt file of this project."));
184   actionsPanelSizer->Add(editCMakebt, 0, wxALL, 5);
185
186   //SetPanel sizer and box
187   actionsPanel->SetSizer(actionsPanelSizer);
188   actionsPanelSizer->Fit(actionsPanel);
189   actionsBox->Add(actionsPanel, 1, wxEXPAND);
190   sizer->Add(actionsBox, 0, wxEXPAND | wxALL, 10);
191
192
193   //Assign sizer
194   this->SetSizer(sizer);
195   sizer->SetSizeHints(this);
196 }
197
198
199 void wxCDMProjectDescriptionPanel::OnBtnCreateLibrary(wxCommandEvent& event)
200 {
201   //get name
202   wxString libraryName = wxGetTextFromUser(
203       _T("Enter the new library name"),
204       _T("New Library - creaDevManager"),
205       _T("")
206   );
207   //check name
208   if(libraryName.Len() > 0)
209     {
210       std::string* result;
211       //create library
212       modelCDMIProjectTreeNode* library = this->project->CreateLibrary(crea::wx2std(libraryName),result);
213       //check library created
214       if(library == NULL)
215         {
216           wxMessageBox(crea::std2wx(*result),_T("New Library - Error!"),wxOK | wxICON_ERROR);
217           event.Skip();
218           return;
219         }
220       wxMessageBox(crea::std2wx("Library successfully created."),_T("New Library - Success!"),wxOK | wxICON_INFORMATION);
221
222       //refreshing tree and description
223       //send event instead of calling parent to avoid crashing
224
225       ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
226
227       wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
228       newEvent->SetInt(library->GetId());
229       wxPostEvent(this->GetParent(), *newEvent);
230       event.Skip();
231     }
232 }
233
234 void wxCDMProjectDescriptionPanel::OnBtnCreateApplication(wxCommandEvent& event)
235 {
236   //get name
237   wxString applicationName = wxGetTextFromUser(
238       _T("Enter the new application name"),
239       _T("New Application - creaDevManager"),
240       _T("")
241   );
242   //check name
243   if(applicationName.Len() > 0)
244     {
245       std::string* result;
246       //create library
247       modelCDMIProjectTreeNode* application = this->project->CreateApplication(crea::wx2std(applicationName),result);
248       //check library created
249       if(application == NULL)
250         {
251           wxMessageBox(crea::std2wx(*result),_T("New Application - Error!"),wxOK | wxICON_ERROR);
252           event.Skip();
253           return;
254         }
255       wxMessageBox(crea::std2wx("Application successfully created."),_T("New Application - Success!"),wxOK | wxICON_INFORMATION);
256
257       //refreshing tree and description
258       //send event instead of calling parent to avoid crashing
259
260       ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
261
262       wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
263       newEvent->SetInt(application->GetId());
264       wxPostEvent(this->GetParent(), *newEvent);
265       event.Skip();
266     }
267 }
268
269 void wxCDMProjectDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
270 {
271   //TODO: implement method
272   std::cerr << "Event OnBtnEditCMakeLists not implemented" << std::endl;
273   event.Skip();
274 }
275
276 void
277 wxCDMProjectDescriptionPanel::OnBtnManagePackages(wxCommandEvent& event)
278 {
279   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
280   newEvent->SetId(1);
281   newEvent->SetString(wxT("manage_packages"));
282   newEvent->SetInt(this->project->GetId());
283   wxPostEvent(this->GetParent(), *newEvent);
284   event.Skip();
285 }
286
287 void
288 wxCDMProjectDescriptionPanel::OnBtnManageLibraries(wxCommandEvent& event)
289 {
290   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
291   newEvent->SetId(1);
292   newEvent->SetString(wxT("manage_libraries"));
293   wxPostEvent(this->GetParent(), *newEvent);
294   event.Skip();
295 }
296
297 void
298 wxCDMProjectDescriptionPanel::OnBtnManageApplications(wxCommandEvent& event)
299 {
300   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
301   newEvent->SetId(1);
302   newEvent->SetString(wxT("manage_applications"));
303   wxPostEvent(this->GetParent(), *newEvent);
304   event.Skip();
305 }