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