]> Creatis software - crea.git/blob - lib/creaDevManagerLib/wxCDMProjectDescriptionPanel.cpp
8a4c438592c516125cf3204c6a82190c63dd8c42
[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->SetInt(this->project->GetId());
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       int CMId = this->project->GetLib()->GetId();
264       newEvent1->SetInt(CMId);
265       newEvent1->SetId(0);
266       wxPostEvent(this->GetParent(), *newEvent1);
267     }
268
269   event.Skip();
270 }
271
272 void wxCDMProjectDescriptionPanel::OnBtnManageApplications(wxCommandEvent& event)
273 {
274   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
275   newEvent->SetId(1);
276   newEvent->SetString(wxT("manage_applications"));
277   wxPostEvent(this->GetParent(), *newEvent);
278
279   wxCommandEvent* newEvent1 = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
280
281   if(this->project->GetAppli() != NULL)
282     {
283       int CMId = this->project->GetAppli()->GetId();
284       newEvent1->SetInt(CMId);
285       newEvent1->SetId(0);
286       wxPostEvent(this->GetParent(), *newEvent1);
287     }
288
289   event.Skip();
290 }
291
292 void wxCDMProjectDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
293 {
294   std::string* result;
295   if(!this->project->OpenCMakeListsFile(result))
296     wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
297
298   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
299
300   if(this->project->GetCMakeLists() != NULL)
301     {
302       int CMId = this->project->GetCMakeLists()->GetId();
303       newEvent->SetInt(CMId);
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       int CMId = this->project->GetCMakeLists()->GetId();
363       newEvent->SetInt(CMId);
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       int CMId = this->project->GetCMakeLists()->GetId();
377       newEvent->SetInt(CMId);
378       newEvent->SetId(0);
379       wxPostEvent(this->GetParent(), *newEvent);
380     }
381   event.Skip();
382 }
383
384 void wxCDMProjectDescriptionPanel::OnAppliMouseEnter(wxMouseEvent& event)
385 {
386   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
387   std::cout << "entra appli " << this->project->GetAppli()->GetCMakeLists();
388   if(this->project->GetAppli() != NULL)
389     {
390       int AppId = this->project->GetAppli()->GetId();
391       newEvent->SetInt(AppId);
392       newEvent->SetId(0);
393       wxPostEvent(this->GetParent(), *newEvent);
394     }
395   event.Skip();
396 }
397
398 void wxCDMProjectDescriptionPanel::OnAppliMouseExit(wxMouseEvent& event)
399 {
400   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
401
402   if(this->project->GetAppli() != NULL)
403     {
404       int AppId = this->project->GetAppli()->GetId();
405       newEvent->SetInt(AppId);
406       newEvent->SetId(0);
407       wxPostEvent(this->GetParent(), *newEvent);
408     }
409   event.Skip();
410 }
411
412 void wxCDMProjectDescriptionPanel::OnLibMouseEnter(wxMouseEvent& event)
413 {
414   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
415
416   if(this->project->GetLib() != NULL)
417     {
418       int LbId = this->project->GetLib()->GetId();
419       newEvent->SetInt(LbId);
420       newEvent->SetId(0);
421       wxPostEvent(this->GetParent(), *newEvent);
422     }
423   event.Skip();
424 }
425
426 void wxCDMProjectDescriptionPanel::OnLibMouseExit(wxMouseEvent& event)
427 {
428   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
429
430   if(this->project->GetLib() != NULL)
431     {
432       int LbId = this->project->GetLib()->GetId();
433       newEvent->SetInt(LbId);
434       newEvent->SetId(0);
435       wxPostEvent(this->GetParent(), *newEvent);
436     }
437   event.Skip();
438 }