]> 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, 1, wxALIGN_CENTER, 1);
122   pVersionsz->Add(pVersionbt, 0, wxALIGN_CENTER_VERTICAL | 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, 1, wxALIGN_CENTER, 1);
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, 1, wxALIGN_CENTER, 1);
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, 1, wxALL | wxEXPAND, 5);
154
155   //SetPanel sizer and box
156   propertiesPanel->SetSizer(propertiesPanelSizer);
157   propertiesPanelSizer->Fit(propertiesPanel);
158   propertiesBox->Add(propertiesPanel, 1, 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, 1, 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       libMgrbt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMProjectDescriptionPanel::OnLibMouseEnter,NULL,this);
181       libMgrbt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMProjectDescriptionPanel::OnLibMouseExit,NULL,this);
182       actionsPanelSizer->Add(libMgrbt, 1, wxALL, 5);
183     }
184   // appli manager
185   // show only if there is a appli folder
186   if(this->project->GetAppli() != NULL)
187     {
188       wxButton* appliMgrbt = new wxButton(actionsPanel, ID_BUTTON_GOTO_APPLI_MANAGER, _T("Application Manager"));
189       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."));
190       appliMgrbt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMProjectDescriptionPanel::OnAppliMouseEnter,NULL,this);
191       appliMgrbt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMProjectDescriptionPanel::OnAppliMouseExit,NULL,this);
192       actionsPanelSizer->Add(appliMgrbt, 1, wxALL, 5);
193     }
194   // edit CMakeLists file
195   wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists File"));
196   editCMakebt->SetToolTip(wxT("Edit the CMakeLists.txt file of this project."));
197   editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMProjectDescriptionPanel::OnCMakeMouseEnter,NULL,this);
198   editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMProjectDescriptionPanel::OnCMakeMouseExit,NULL,this);
199   actionsPanelSizer->Add(editCMakebt, 1, wxALL, 5);
200
201   //SetPanel sizer and box
202   actionsPanel->SetSizer(actionsPanelSizer);
203   actionsPanelSizer->Fit(actionsPanel);
204   actionsBox->Add(actionsPanel, 1, wxALL | wxEXPAND, 5);
205   sizer->Add(actionsBox, 0, wxEXPAND | wxALL, 10);
206
207
208   //Assign sizer
209   this->SetSizer(sizer);
210   sizer->SetSizeHints(this);
211 }
212
213 void wxCDMProjectDescriptionPanel::OnBtnManagePackages(wxCommandEvent& event)
214 {
215   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
216   newEvent->SetId(1);
217   newEvent->SetString(wxT("manage_packages"));
218   newEvent->SetInt(this->project->GetId());
219   wxPostEvent(this->GetParent(), *newEvent);
220   event.Skip();
221 }
222
223 void wxCDMProjectDescriptionPanel::OnBtnManageLibraries(wxCommandEvent& event)
224 {
225   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
226   newEvent->SetId(1);
227   newEvent->SetString(wxT("manage_libraries"));
228   wxPostEvent(this->GetParent(), *newEvent);
229
230   wxCommandEvent* newEvent1 = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
231
232   if(this->project->GetLib() != NULL)
233     {
234       int CMId = this->project->GetLib()->GetId();
235       newEvent1->SetInt(CMId);
236       newEvent1->SetId(0);
237       wxPostEvent(this->GetParent(), *newEvent1);
238     }
239
240   event.Skip();
241 }
242
243 void wxCDMProjectDescriptionPanel::OnBtnManageApplications(wxCommandEvent& event)
244 {
245   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
246   newEvent->SetId(1);
247   newEvent->SetString(wxT("manage_applications"));
248   wxPostEvent(this->GetParent(), *newEvent);
249
250   wxCommandEvent* newEvent1 = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
251
252     if(this->project->GetAppli() != NULL)
253       {
254         int CMId = this->project->GetAppli()->GetId();
255         newEvent1->SetInt(CMId);
256         newEvent1->SetId(0);
257         wxPostEvent(this->GetParent(), *newEvent1);
258       }
259
260   event.Skip();
261 }
262
263 void wxCDMProjectDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
264 {
265   std::string* result;
266   if(!this->project->OpenCMakeListsFile(result))
267     wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
268
269   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
270
271   if(this->project->GetCMakeLists() != NULL)
272     {
273       int CMId = this->project->GetCMakeLists()->GetId();
274       newEvent->SetInt(CMId);
275       newEvent->SetId(0);
276       wxPostEvent(this->GetParent(), *newEvent);
277     }
278 }
279
280 void
281 wxCDMProjectDescriptionPanel::OnBtnSetBuildPath(wxCommandEvent& event)
282 {
283   wxDirDialog* dialog = new wxDirDialog(this, wxT("Choose the new build location for the project"));
284   if(dialog->ShowModal())
285     {
286       std::string* result;
287       if(!this->project->SetBuildPath(crea::wx2std(dialog->GetPath()), result))
288         wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
289     }
290   this->buildPathtc->SetLabel(crea::std2wx(this->project->GetBuildPath()));
291 }
292
293 void
294 wxCDMProjectDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
295 {
296   std::string* result;
297   if(!this->project->OpenInFileExplorer(result))
298     wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
299 }
300
301 void wxCDMProjectDescriptionPanel::OnBtnSetVersion(wxCommandEvent& event)
302 {
303   //get version
304   wxString libraryName = wxGetTextFromUser(
305       wxT("Enter the new version name"),
306       wxT("Change Project Version - creaDevManager"),
307       crea::std2wx(this->project->GetVersion())
308   );
309   //check name
310   std::vector<std::string> parts;
311   CDMUtilities::splitter::split(parts, crea::wx2std(libraryName), " .", CDMUtilities::splitter::no_empties);
312   if(parts.size() == 3)
313     {
314       std::string* result;
315       if(!this->project->SetVersion(crea::wx2std(libraryName), result))
316         wxMessageBox(crea::std2wx(*result),_T("Open File - Error!"),wxOK | wxICON_ERROR);
317     }
318   else
319     {
320       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);
321     }
322   this->versiontc->SetLabel(crea::std2wx(this->project->GetVersion()));
323   this->versionDatetc->SetLabel(crea::std2wx(this->project->GetVersionDate()));
324
325 }
326
327 void wxCDMProjectDescriptionPanel::OnCMakeMouseEnter(wxMouseEvent& event)
328 {
329   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
330
331   if(this->project->GetCMakeLists() != NULL)
332     {
333       int CMId = this->project->GetCMakeLists()->GetId();
334       newEvent->SetInt(CMId);
335       newEvent->SetId(0);
336       wxPostEvent(this->GetParent(), *newEvent);
337     }
338   event.Skip();
339 }
340
341 void wxCDMProjectDescriptionPanel::OnCMakeMouseExit(wxMouseEvent& event)
342 {
343   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
344
345   if(this->project->GetCMakeLists() != NULL)
346     {
347       int CMId = this->project->GetCMakeLists()->GetId();
348       newEvent->SetInt(CMId);
349       newEvent->SetId(0);
350       wxPostEvent(this->GetParent(), *newEvent);
351     }
352   event.Skip();
353 }
354
355 void wxCDMProjectDescriptionPanel::OnAppliMouseEnter(wxMouseEvent& event)
356 {
357   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
358   std::cout << "entra appli " << this->project->GetAppli()->GetCMakeLists();
359   if(this->project->GetAppli() != NULL)
360     {
361       int AppId = this->project->GetAppli()->GetId();
362       newEvent->SetInt(AppId);
363       newEvent->SetId(0);
364       wxPostEvent(this->GetParent(), *newEvent);
365     }
366   event.Skip();
367 }
368
369 void wxCDMProjectDescriptionPanel::OnAppliMouseExit(wxMouseEvent& event)
370 {
371   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
372
373   if(this->project->GetAppli() != NULL)
374     {
375       int AppId = this->project->GetAppli()->GetId();
376       newEvent->SetInt(AppId);
377       newEvent->SetId(0);
378       wxPostEvent(this->GetParent(), *newEvent);
379     }
380   event.Skip();
381 }
382
383 void wxCDMProjectDescriptionPanel::OnLibMouseEnter(wxMouseEvent& event)
384 {
385   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
386
387   if(this->project->GetLib() != NULL)
388     {
389       int LbId = this->project->GetLib()->GetId();
390       newEvent->SetInt(LbId);
391       newEvent->SetId(0);
392       wxPostEvent(this->GetParent(), *newEvent);
393     }
394   event.Skip();
395 }
396
397 void wxCDMProjectDescriptionPanel::OnLibMouseExit(wxMouseEvent& event)
398 {
399   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
400
401   if(this->project->GetLib() != NULL)
402     {
403       int LbId = this->project->GetLib()->GetId();
404       newEvent->SetInt(LbId);
405       newEvent->SetId(0);
406       wxPostEvent(this->GetParent(), *newEvent);
407     }
408   event.Skip();
409 }