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