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