]> 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 "creaDevManagerIds.h"
41 #include "images/PrIcon64.xpm"
42
43 BEGIN_EVENT_TABLE(wxCDMProjectDescriptionPanel, wxPanel)
44 EVT_BUTTON(ID_BUTTON_GOTO_PACKAGE_MANAGER, wxCDMProjectDescriptionPanel::OnBtnManagePackages)
45 EVT_BUTTON(ID_BUTTON_GOTO_LIB_MANAGER, wxCDMProjectDescriptionPanel::OnBtnManageLibraries)
46 EVT_BUTTON(ID_BUTTON_GOTO_APPLI_MANAGER, wxCDMProjectDescriptionPanel::OnBtnManageApplications)
47 EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMProjectDescriptionPanel::OnBtnEditCMakeLists)
48
49 END_EVENT_TABLE()
50
51 wxCDMProjectDescriptionPanel::wxCDMProjectDescriptionPanel(
52     wxWindow* parent,
53     modelCDMProject* project,
54     wxWindowID id,
55     const wxString& caption,
56     const wxPoint& pos,
57     const wxSize& size,
58     long style
59 )
60 {
61   wxCDMProjectDescriptionPanel::Create(parent, project, id, caption, pos, size, style);
62 }
63
64 wxCDMProjectDescriptionPanel::~wxCDMProjectDescriptionPanel()
65 {
66 }
67
68 bool wxCDMProjectDescriptionPanel::Create(
69     wxWindow* parent,
70     modelCDMProject* project,
71     wxWindowID id,
72     const wxString& caption,
73     const wxPoint& pos,
74     const wxSize& size,
75     long style
76 )
77 {
78   wxPanel::Create(parent, id, pos, size, style);
79   this->project = project;
80   CreateControls();
81   return TRUE;
82 }
83
84 void wxCDMProjectDescriptionPanel::CreateControls()
85 {
86   wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
87
88   //Welcome
89   sizer->Add(new wxStaticText(this, -1, _("Project")),0, wxALIGN_CENTER, 0);
90
91   //Image
92   sizer->Add(new wxStaticBitmap(this, -1, wxBitmap(PrIcon64)),0, wxALIGN_CENTER, 0);
93
94   //Project Name
95   sizer->Add(new wxStaticText(this, -1, crea::std2wx(this->project->GetName())),0, wxALIGN_CENTER, 0);
96
97   //Project Properties
98   wxStaticBox* propertiesBox = new wxStaticBox(this, -1, _T("&Properties"));
99   wxStaticBoxSizer* propertiesBoxInnerSizer = new wxStaticBoxSizer(propertiesBox, wxVERTICAL);
100
101   wxFlexGridSizer* flexGridSizer = new wxFlexGridSizer(4, 2, 9, 15);
102
103   wxStaticText* pVersion = new wxStaticText(this, -1, wxT("Version"));
104   wxStaticText* pVersionDate = new wxStaticText(this, -1, wxT("Version Date"));
105   wxStaticText* pSourceLocation = new wxStaticText(this, -1, wxT("Source Location"));
106   wxStaticText* pBuildLocation = new wxStaticText(this, -1, wxT("Build Location"));
107
108   wxStaticText* pVersiontc = new wxStaticText(this, -1, crea::std2wx(this->project->GetVersion()));
109   wxStaticText* pVersionDatetc = new wxStaticText(this, -1, crea::std2wx(this->project->GetVersionDate()));
110   wxStaticText* pSourceLocationtc = new wxStaticText(this, -1, crea::std2wx(this->project->GetPath()));
111   wxStaticText* pBuildLocationtc = new wxStaticText(this, -1, crea::std2wx(this->project->GetBuildPath()));
112
113   wxButton* pVersionbt = new wxButton(this, ID_BUTTON_SET_VERSION, wxT("Set"));
114   wxButton* pBuildLocationbt = new wxButton(this, ID_BUTTON_SET_BUILD_PATH, wxT("Choose"));
115
116   wxBoxSizer* pVersionsz = new wxBoxSizer(wxHORIZONTAL);
117   wxBoxSizer* pBuildLocationsz = new wxBoxSizer(wxHORIZONTAL);
118
119   pVersionsz->Add(pVersiontc, 0, wxALIGN_CENTER_VERTICAL, 0);
120   pVersionsz->Add(pVersionbt, 0, wxALIGN_CENTER | wxLEFT, 10);
121   pBuildLocationsz->Add(pBuildLocationtc, 0, wxALIGN_CENTER, 0);
122   pBuildLocationsz->Add(pBuildLocationbt, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 10);
123
124   flexGridSizer->Add(pVersion, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
125   flexGridSizer->Add(pVersionsz, 1, wxEXPAND);
126   flexGridSizer->Add(pVersionDate, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
127   flexGridSizer->Add(pVersionDatetc, 1, wxEXPAND);
128   flexGridSizer->Add(pSourceLocation, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
129   flexGridSizer->Add(pSourceLocationtc, 1, wxEXPAND);
130   flexGridSizer->Add(pBuildLocation, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
131   flexGridSizer->Add(pBuildLocationsz, 1, wxEXPAND);
132
133   flexGridSizer->AddGrowableCol(1,1);
134
135   propertiesBoxInnerSizer -> Add(flexGridSizer, 0, wxALL | wxEXPAND, 5);
136   sizer -> Add(propertiesBoxInnerSizer, 0, wxEXPAND | wxALL, 10);
137
138   //Actions
139   wxStaticBox* actionsBox = new wxStaticBox(this, -1, _T("&Actions"));
140   wxStaticBoxSizer* actionsBoxInnerSizer = new wxStaticBoxSizer(actionsBox, wxHORIZONTAL);
141   sizer -> Add(actionsBoxInnerSizer, 0, wxEXPAND | wxALL, 10);
142
143   actionsBoxInnerSizer->Add(new wxButton(this, ID_BUTTON_GOTO_PACKAGE_MANAGER, _T("Package Manager")), 0, wxALL, 5);
144   //TODO: show only if there is a lib folder
145   actionsBoxInnerSizer->Add(new wxButton(this, ID_BUTTON_GOTO_LIB_MANAGER, _T("Library Manager")), 0, wxALL, 5);
146   //TODO: show only if there is a appli folder
147   actionsBoxInnerSizer->Add(new wxButton(this, ID_BUTTON_GOTO_APPLI_MANAGER, _T("Application Manager")), 0, wxALL, 5);
148
149   actionsBoxInnerSizer->Add(new wxButton(this, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists File")), 0, wxALL, 5);
150
151   //Assign sizer
152   actionsBoxInnerSizer->SetSizeHints(this);
153
154   SetSizer(sizer);
155   sizer->SetSizeHints(this);
156 }
157
158
159 void wxCDMProjectDescriptionPanel::OnBtnCreateLibrary(wxCommandEvent& event)
160 {
161   //get name
162   wxString libraryName = wxGetTextFromUser(
163       _T("Enter the new library name"),
164       _T("New Library - creaDevManager"),
165       _T("")
166   );
167   //check name
168   if(libraryName.Len() > 0)
169     {
170       std::string* result;
171       //create library
172       modelCDMIProjectTreeNode* library = this->project->CreateLibrary(crea::wx2std(libraryName),result);
173       //check library created
174       if(library == NULL)
175         {
176           wxMessageBox(crea::std2wx(*result),_T("New Library - Error!"),wxOK | wxICON_ERROR);
177           event.Skip();
178           return;
179         }
180       wxMessageBox(crea::std2wx("Library successfully created."),_T("New Library - Success!"),wxOK | wxICON_INFORMATION);
181
182       //refreshing tree and description
183       //send event instead of calling parent to avoid crashing
184
185       ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
186
187       wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
188       newEvent->SetInt(library->GetId());
189       wxPostEvent(this->GetParent(), *newEvent);
190       event.Skip();
191     }
192 }
193
194 void wxCDMProjectDescriptionPanel::OnBtnCreateApplication(wxCommandEvent& event)
195 {
196   //get name
197   wxString applicationName = wxGetTextFromUser(
198       _T("Enter the new application name"),
199       _T("New Application - creaDevManager"),
200       _T("")
201   );
202   //check name
203   if(applicationName.Len() > 0)
204     {
205       std::string* result;
206       //create library
207       modelCDMIProjectTreeNode* application = this->project->CreateApplication(crea::wx2std(applicationName),result);
208       //check library created
209       if(application == NULL)
210         {
211           wxMessageBox(crea::std2wx(*result),_T("New Application - Error!"),wxOK | wxICON_ERROR);
212           event.Skip();
213           return;
214         }
215       wxMessageBox(crea::std2wx("Application successfully created."),_T("New Application - Success!"),wxOK | wxICON_INFORMATION);
216
217       //refreshing tree and description
218       //send event instead of calling parent to avoid crashing
219
220       ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
221
222       wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
223       newEvent->SetInt(application->GetId());
224       wxPostEvent(this->GetParent(), *newEvent);
225       event.Skip();
226     }
227 }
228
229 void wxCDMProjectDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
230 {
231   //TODO: implement method
232   std::cerr << "Event OnBtnCreatePackage not implemented" << std::endl;
233   event.Skip();
234 }
235
236 void
237 wxCDMProjectDescriptionPanel::OnBtnManagePackages(wxCommandEvent& event)
238 {
239   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
240   newEvent->SetId(1);
241   newEvent->SetString(wxT("manage_packages"));
242   newEvent->SetInt(this->project->GetId());
243   wxPostEvent(this->GetParent(), *newEvent);
244   event.Skip();
245 }
246
247 void
248 wxCDMProjectDescriptionPanel::OnBtnManageLibraries(wxCommandEvent& event)
249 {
250   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
251   newEvent->SetId(1);
252   newEvent->SetString(wxT("manage_libraries"));
253   //TODO: implement GetLib in project
254   //newEvent->SetInt(this->project->GetLib()->GetId());
255   wxPostEvent(this->GetParent(), *newEvent);
256   event.Skip();
257 }
258
259 void
260 wxCDMProjectDescriptionPanel::OnBtnManageApplications(wxCommandEvent& event)
261 {
262   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
263   newEvent->SetId(1);
264   newEvent->SetString(wxT("manage_applications"));
265   //TODO: implement GetAppli in project
266   //newEvent->SetInt(this->project->GetAppli->GetId());
267   wxPostEvent(this->GetParent(), *newEvent);
268   event.Skip();
269 }