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