]> 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 "wxCDMProjectHelpDialog.h"
41
42 #include "creaDevManagerIds.h"
43 #include "images/PrIcon64.xpm"
44 #include "CDMUtilities.h"
45
46 BEGIN_EVENT_TABLE(wxCDMProjectDescriptionPanel, wxPanel)
47 EVT_BUTTON(ID_BUTTON_GOTO_PACKAGE_MANAGER, wxCDMProjectDescriptionPanel::OnBtnManagePackages)
48 EVT_BUTTON(ID_BUTTON_GOTO_LIB_MANAGER, wxCDMProjectDescriptionPanel::OnBtnManageLibraries)
49 EVT_BUTTON(ID_BUTTON_GOTO_APPLI_MANAGER, wxCDMProjectDescriptionPanel::OnBtnManageApplications)
50 EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMProjectDescriptionPanel::OnBtnEditCMakeLists)
51 EVT_BUTTON(ID_BUTTON_SET_BUILD_PATH, wxCDMProjectDescriptionPanel::OnBtnSetBuildPath)
52 EVT_BUTTON(ID_BUTTON_OPEN_FOLDER, wxCDMProjectDescriptionPanel::OnBtnOpenFolder)
53 EVT_BUTTON(ID_BUTTON_SET_VERSION, wxCDMProjectDescriptionPanel::OnBtnSetVersion)
54 END_EVENT_TABLE()
55
56 wxCDMProjectDescriptionPanel::wxCDMProjectDescriptionPanel(
57     wxWindow* parent,
58     modelCDMProject* project,
59     wxWindowID id,
60     const wxString& caption,
61     const wxPoint& pos,
62     const wxSize& size,
63     long style
64 )
65 {
66   wxCDMProjectDescriptionPanel::Create(parent, project, id, caption, pos, size, style);
67 }
68
69 wxCDMProjectDescriptionPanel::~wxCDMProjectDescriptionPanel()
70 {
71 }
72
73 bool wxCDMProjectDescriptionPanel::Create(
74     wxWindow* parent,
75     modelCDMProject* project,
76     wxWindowID id,
77     const wxString& caption,
78     const wxPoint& pos,
79     const wxSize& size,
80     long style
81 )
82 {
83   wxPanel::Create(parent, id, pos, size, style);
84   this->project = project;
85   CreateControls();
86   return TRUE;
87 }
88
89 void wxCDMProjectDescriptionPanel::CreateControls()
90 {
91   wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
92
93   //Welcome
94   sizer->Add(new wxStaticText(this, -1, _("Project")),0, wxALIGN_CENTER, 0);
95
96   //Image
97   sizer->Add(new wxStaticBitmap(this, -1, wxBitmap(PrIcon64)),0, wxALIGN_CENTER, 0);
98
99   //Project Name
100   sizer->Add(new wxStaticText(this, -1, crea::std2wx(this->project->GetName())),0, wxALIGN_CENTER, 0);
101
102   //----------------------------------Project Properties-----------------------------------
103   //properties StaticBoxSizer
104   wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, _T("&Properties"));
105   //properties Panel
106   wxPanel* propertiesPanel = new wxPanel(this);
107   //properties Sizer
108   wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL);
109   //propertiesGrid Sizer
110   wxFlexGridSizer* propertiesGridSizer = new wxFlexGridSizer(4, 2, 9, 15);
111   //properties elements
112   //labels
113   wxStaticText* pVersion = new wxStaticText(propertiesPanel, wxID_ANY, wxT("Version"));
114   wxStaticText* pVersionDate = new wxStaticText(propertiesPanel, wxID_ANY, wxT("Version Date"));
115   wxStaticText* pSourceLocation = new wxStaticText(propertiesPanel, wxID_ANY, wxT("Source Location"));
116   wxStaticText* pBuildLocation = new wxStaticText(propertiesPanel, wxID_ANY, wxT("Build Location"));
117   //values
118   // version
119   wxBoxSizer* pVersionsz = new wxBoxSizer(wxHORIZONTAL);
120   this->versiontc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->project->GetVersion()));
121   wxButton* pVersionbt = new wxButton(propertiesPanel, ID_BUTTON_SET_VERSION, wxT("Set"));
122   pVersionbt->SetToolTip(wxT("Update the version of the project."));
123   pVersionsz->Add(this->versiontc, 1, wxALIGN_CENTER, 1);
124   pVersionsz->Add(pVersionbt, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 10);
125   // versionDate
126   this->versionDatetc = new wxStaticText(propertiesPanel, -1, crea::std2wx(this->project->GetVersionDate()));
127   // sourceLocation
128   wxBoxSizer* pSourceLocationsz = new wxBoxSizer(wxHORIZONTAL);
129   wxStaticText* pSourceLocationtc = new wxStaticText(propertiesPanel, -1, crea::std2wx(this->project->GetPath()));
130   //pSourceLocationtc->SetMaxSize(wxSize(350,-1));
131   wxButton* pSourceLocationbt = new wxButton(propertiesPanel, ID_BUTTON_OPEN_FOLDER, wxT("Open"));
132   pSourceLocationbt->SetToolTip(wxT("Open the source folder in the file explorer."));
133   pSourceLocationsz->Add(pSourceLocationtc, 1, wxALIGN_CENTER, 1);
134   pSourceLocationsz->Add(pSourceLocationbt, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 10);
135   // buildLocation
136   wxBoxSizer* pBuildLocationsz = new wxBoxSizer(wxHORIZONTAL);
137   this->buildPathtc = new wxStaticText(propertiesPanel, -1, crea::std2wx(this->project->GetBuildPath()));
138   //this->buildPathtc->SetMaxSize(wxSize(350,-1));
139   wxButton* pBuildLocationbt = new wxButton(propertiesPanel, ID_BUTTON_SET_BUILD_PATH, wxT("Choose"));
140   pBuildLocationbt->SetToolTip(wxT("Select a new location for compiling the project."));
141   pBuildLocationsz->Add(this->buildPathtc, 1, wxALIGN_CENTER, 1);
142   pBuildLocationsz->Add(pBuildLocationbt, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 10);
143
144   propertiesGridSizer->Add(pVersion, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
145   propertiesGridSizer->Add(pVersionsz, 1, wxEXPAND);
146   propertiesGridSizer->Add(pVersionDate, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
147   propertiesGridSizer->Add(this->versionDatetc, 1, wxEXPAND);
148   propertiesGridSizer->Add(pSourceLocation, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
149   propertiesGridSizer->Add(pSourceLocationsz, 1, wxEXPAND);
150   propertiesGridSizer->Add(pBuildLocation, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
151   propertiesGridSizer->Add(pBuildLocationsz, 1, wxEXPAND);
152
153   propertiesGridSizer->AddGrowableCol(1,1);
154
155   propertiesPanelSizer-> Add(propertiesGridSizer, 1, wxALL | wxEXPAND, 5);
156
157   //SetPanel sizer and box
158   propertiesPanel->SetSizer(propertiesPanelSizer);
159   propertiesPanelSizer->Fit(propertiesPanel);
160   propertiesBox->Add(propertiesPanel, 1, wxEXPAND);
161   sizer->Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
162
163   //----------------------------------Project Actions--------------------------------------
164   //actions StaticBoxSizer
165   wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL,this, _T("&Actions"));
166   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."));
167   //actions Panel
168   wxPanel* actionsPanel = new wxPanel(this);
169   //actions Sizer
170   wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
171   //buttons
172   // package manager
173   wxButton* packageMgrbt = new wxButton(actionsPanel, ID_BUTTON_GOTO_PACKAGE_MANAGER, _T("Package Manager"));
174   packageMgrbt->SetToolTip(wxT("Find the current available packages into this project. You can also create new Packages in this section."));
175   actionsPanelSizer->Add(packageMgrbt, 1, wxALL, 5);
176   // lib manager
177   // show only if there is a lib folder
178   if(this->project->GetLib() != NULL)
179     {
180       wxButton* libMgrbt = new wxButton(actionsPanel, ID_BUTTON_GOTO_LIB_MANAGER, _T("Library Manager"));
181       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."));
182       libMgrbt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMProjectDescriptionPanel::OnLibMouseEnter,NULL,this);
183       libMgrbt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMProjectDescriptionPanel::OnLibMouseExit,NULL,this);
184       actionsPanelSizer->Add(libMgrbt, 1, wxALL, 5);
185     }
186   // appli manager
187   // show only if there is a appli folder
188   if(this->project->GetAppli() != NULL)
189     {
190       wxButton* appliMgrbt = new wxButton(actionsPanel, ID_BUTTON_GOTO_APPLI_MANAGER, _T("Application Manager"));
191       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."));
192       appliMgrbt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMProjectDescriptionPanel::OnAppliMouseEnter,NULL,this);
193       appliMgrbt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMProjectDescriptionPanel::OnAppliMouseExit,NULL,this);
194       actionsPanelSizer->Add(appliMgrbt, 1, wxALL, 5);
195     }
196   // edit CMakeLists file
197   wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists File"));
198   editCMakebt->SetToolTip(wxT("Edit the CMakeLists.txt file of this project."));
199   editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMProjectDescriptionPanel::OnCMakeMouseEnter,NULL,this);
200   editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMProjectDescriptionPanel::OnCMakeMouseExit,NULL,this);
201   actionsPanelSizer->Add(editCMakebt, 1, wxALL, 5);
202
203   //SetPanel sizer and box
204   actionsPanel->SetSizer(actionsPanelSizer);
205   actionsPanelSizer->Fit(actionsPanel);
206   actionsBox->Add(actionsPanel, 1, wxALL | wxEXPAND, 5);
207   sizer->Add(actionsBox, 0, wxEXPAND | wxALL, 10);
208
209
210   //Assign sizer
211   this->SetSizer(sizer);
212   sizer->SetSizeHints(this);
213
214   if(((wxCDMMainFrame*)this->GetParent())->isHelp())
215     {
216       wxCDMProjectHelpDialog* helpDialog = new wxCDMProjectHelpDialog(this->GetParent(), this, wxID_ANY);
217       helpDialog->Show(true);
218     }
219 }
220
221 modelCDMProject* wxCDMProjectDescriptionPanel::GetProject() const
222 {
223   return this->project;
224 }
225
226 void wxCDMProjectDescriptionPanel::OnBtnManagePackages(wxCommandEvent& event)
227 {
228   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
229   newEvent->SetId(1);
230   newEvent->SetString(wxT("manage_packages"));
231   newEvent->SetInt(this->project->GetId());
232   wxPostEvent(this->GetParent(), *newEvent);
233   event.Skip();
234 }
235
236 void wxCDMProjectDescriptionPanel::OnBtnManageLibraries(wxCommandEvent& event)
237 {
238   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
239   newEvent->SetId(1);
240   newEvent->SetString(wxT("manage_libraries"));
241   wxPostEvent(this->GetParent(), *newEvent);
242
243   wxCommandEvent* newEvent1 = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
244
245   if(this->project->GetLib() != NULL)
246     {
247       int CMId = this->project->GetLib()->GetId();
248       newEvent1->SetInt(CMId);
249       newEvent1->SetId(0);
250       wxPostEvent(this->GetParent(), *newEvent1);
251     }
252
253   event.Skip();
254 }
255
256 void wxCDMProjectDescriptionPanel::OnBtnManageApplications(wxCommandEvent& event)
257 {
258   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
259   newEvent->SetId(1);
260   newEvent->SetString(wxT("manage_applications"));
261   wxPostEvent(this->GetParent(), *newEvent);
262
263   wxCommandEvent* newEvent1 = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
264
265     if(this->project->GetAppli() != NULL)
266       {
267         int CMId = this->project->GetAppli()->GetId();
268         newEvent1->SetInt(CMId);
269         newEvent1->SetId(0);
270         wxPostEvent(this->GetParent(), *newEvent1);
271       }
272
273   event.Skip();
274 }
275
276 void wxCDMProjectDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
277 {
278   std::string* result;
279   if(!this->project->OpenCMakeListsFile(result))
280     wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
281
282   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
283
284   if(this->project->GetCMakeLists() != NULL)
285     {
286       int CMId = this->project->GetCMakeLists()->GetId();
287       newEvent->SetInt(CMId);
288       newEvent->SetId(0);
289       wxPostEvent(this->GetParent(), *newEvent);
290     }
291 }
292
293 void
294 wxCDMProjectDescriptionPanel::OnBtnSetBuildPath(wxCommandEvent& event)
295 {
296   wxDirDialog* dialog = new wxDirDialog(this, wxT("Choose the new build location for the project"));
297   if(dialog->ShowModal())
298     {
299       std::string* result;
300       if(!this->project->SetBuildPath(crea::wx2std(dialog->GetPath()), result))
301         wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
302     }
303   this->buildPathtc->SetLabel(crea::std2wx(this->project->GetBuildPath()));
304 }
305
306 void
307 wxCDMProjectDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
308 {
309   std::string* result;
310   if(!this->project->OpenInFileExplorer(result))
311     wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
312 }
313
314 void wxCDMProjectDescriptionPanel::OnBtnSetVersion(wxCommandEvent& event)
315 {
316   //get version
317   wxString libraryName = wxGetTextFromUser(
318       wxT("Enter the new version name"),
319       wxT("Change Project Version - creaDevManager"),
320       crea::std2wx(this->project->GetVersion())
321   );
322   //check name
323   std::vector<std::string> parts;
324   CDMUtilities::splitter::split(parts, crea::wx2std(libraryName), " .", CDMUtilities::splitter::no_empties);
325   if(parts.size() == 3)
326     {
327       std::string* result;
328       if(!this->project->SetVersion(crea::wx2std(libraryName), result))
329         wxMessageBox(crea::std2wx(*result),_T("Open File - Error!"),wxOK | wxICON_ERROR);
330     }
331   else
332     {
333       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);
334     }
335   this->versiontc->SetLabel(crea::std2wx(this->project->GetVersion()));
336   this->versionDatetc->SetLabel(crea::std2wx(this->project->GetVersionDate()));
337
338 }
339
340 void wxCDMProjectDescriptionPanel::OnCMakeMouseEnter(wxMouseEvent& event)
341 {
342   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
343
344   if(this->project->GetCMakeLists() != NULL)
345     {
346       int CMId = this->project->GetCMakeLists()->GetId();
347       newEvent->SetInt(CMId);
348       newEvent->SetId(0);
349       wxPostEvent(this->GetParent(), *newEvent);
350     }
351   event.Skip();
352 }
353
354 void wxCDMProjectDescriptionPanel::OnCMakeMouseExit(wxMouseEvent& event)
355 {
356   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
357
358   if(this->project->GetCMakeLists() != NULL)
359     {
360       int CMId = this->project->GetCMakeLists()->GetId();
361       newEvent->SetInt(CMId);
362       newEvent->SetId(0);
363       wxPostEvent(this->GetParent(), *newEvent);
364     }
365   event.Skip();
366 }
367
368 void wxCDMProjectDescriptionPanel::OnAppliMouseEnter(wxMouseEvent& event)
369 {
370   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
371   std::cout << "entra appli " << this->project->GetAppli()->GetCMakeLists();
372   if(this->project->GetAppli() != NULL)
373     {
374       int AppId = this->project->GetAppli()->GetId();
375       newEvent->SetInt(AppId);
376       newEvent->SetId(0);
377       wxPostEvent(this->GetParent(), *newEvent);
378     }
379   event.Skip();
380 }
381
382 void wxCDMProjectDescriptionPanel::OnAppliMouseExit(wxMouseEvent& event)
383 {
384   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
385
386   if(this->project->GetAppli() != NULL)
387     {
388       int AppId = this->project->GetAppli()->GetId();
389       newEvent->SetInt(AppId);
390       newEvent->SetId(0);
391       wxPostEvent(this->GetParent(), *newEvent);
392     }
393   event.Skip();
394 }
395
396 void wxCDMProjectDescriptionPanel::OnLibMouseEnter(wxMouseEvent& event)
397 {
398   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
399
400   if(this->project->GetLib() != NULL)
401     {
402       int LbId = this->project->GetLib()->GetId();
403       newEvent->SetInt(LbId);
404       newEvent->SetId(0);
405       wxPostEvent(this->GetParent(), *newEvent);
406     }
407   event.Skip();
408 }
409
410 void wxCDMProjectDescriptionPanel::OnLibMouseExit(wxMouseEvent& event)
411 {
412   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
413
414   if(this->project->GetLib() != NULL)
415     {
416       int LbId = this->project->GetLib()->GetId();
417       newEvent->SetInt(LbId);
418       newEvent->SetId(0);
419       wxPostEvent(this->GetParent(), *newEvent);
420     }
421   event.Skip();
422 }