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