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