]> Creatis software - crea.git/blob - lib/creaDevManagerLib/wxCDMLibraryDescriptionPanel.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / wxCDMLibraryDescriptionPanel.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  * wxCDMLibraryDescriptionPanel.cpp
30  *
31  *  Created on: Nov 27, 2012
32  *      Author: Daniel Felipe Gonzalez Obando
33  */
34
35 #include "wxCDMLibraryDescriptionPanel.h"
36
37 #include "CDMUtilities.h"
38 #include "wxCDMMainFrame.h"
39
40 #include "wxCDMLibraryHelpDialog.h"
41
42 #include "creaDevManagerIds.h"
43 #include "images/LIcon64.xpm"
44
45 BEGIN_EVENT_TABLE(wxCDMLibraryDescriptionPanel, wxPanel)
46 EVT_BUTTON(ID_BUTTON_PREV, wxCDMLibraryDescriptionPanel::OnBtnReturn)
47 EVT_BUTTON(ID_BUTTON_SET_NAME, wxCDMLibraryDescriptionPanel::OnBtnSetExeName)
48 EVT_BUTTON(ID_BUTTON_CREATE_CLASS, wxCDMLibraryDescriptionPanel::OnBtnCreateClass)
49 EVT_BUTTON(ID_BUTTON_CREATE_FOLDER, wxCDMLibraryDescriptionPanel::OnBtnCreateFolder)
50 EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMLibraryDescriptionPanel::OnBtnEditCMakeLists)
51 EVT_BUTTON(ID_BUTTON_OPEN_FOLDER, wxCDMLibraryDescriptionPanel::OnBtnOpenFolder)
52 END_EVENT_TABLE()
53
54 wxCDMLibraryDescriptionPanel::wxCDMLibraryDescriptionPanel(
55     wxWindow* parent,
56     modelCDMLibrary* library,
57     wxWindowID id,
58     const wxString& caption,
59     const wxPoint& pos,
60     const wxSize& size,
61     long style
62 )
63 {
64   wxCDMLibraryDescriptionPanel::Create(parent, library, id, caption, pos, size, style);
65 }
66
67 wxCDMLibraryDescriptionPanel::~wxCDMLibraryDescriptionPanel()
68 {
69 }
70
71 bool wxCDMLibraryDescriptionPanel::Create(
72     wxWindow* parent,
73     modelCDMLibrary* library,
74     wxWindowID id,
75     const wxString& caption,
76     const wxPoint& pos,
77     const wxSize& size,
78     long style
79 )
80 {
81   wxPanel::Create(parent, id, pos, size, style);
82   this->library = library;
83   CreateControls();
84   return TRUE;
85 }
86
87 void wxCDMLibraryDescriptionPanel::CreateControls()
88 {
89   wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
90
91   //Link to return
92   wxButton* returnbt = new wxButton(this, ID_BUTTON_PREV, wxT("Return to project"));
93   returnbt->SetToolTip(wxT("Return to the active project description."));
94   sizer->Add(returnbt, 0, wxALIGN_CENTER | wxALL, 5);
95
96   //Title
97   sizer->Add(new wxStaticText(this, -1, _("Library")),0, wxALIGN_CENTER, 0);
98
99   //Image
100   sizer->Add(new wxStaticBitmap(this, -1, wxBitmap(LIcon64)),0, wxALIGN_CENTER, 0);
101
102   //Application Name
103   sizer->Add(new wxStaticText(this, -1, crea::std2wx(this->library->GetName())),0, wxALIGN_CENTER, 0);
104
105   //Properties
106   wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Properties"));
107   wxPanel* propertiesPanel = new wxPanel(this);
108   wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL);
109
110   wxFlexGridSizer* propertiesGridSizer = new wxFlexGridSizer(4, 2, 9, 15);
111
112   wxStaticText *pMainFile = new wxStaticText(propertiesPanel, -1, wxT("Library Name"));
113   wxBoxSizer* pMainFilesz = new wxBoxSizer(wxHORIZONTAL);
114   this->libraryNametc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->library->GetNameLibrary()));
115   wxButton* pMainFilebt = new wxButton(propertiesPanel, ID_BUTTON_SET_NAME, wxT("Set"));
116   pMainFilebt->SetToolTip(wxT("Set the name of the library for the project."));
117   pMainFilesz->Add(this->libraryNametc, 0, wxALIGN_CENTER_VERTICAL, 0);
118   pMainFilesz->Add(pMainFilebt, 0, wxALIGN_CENTER | wxLEFT, 10);
119
120   propertiesGridSizer->Add(pMainFile, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
121   propertiesGridSizer->Add(pMainFilesz, 1, wxEXPAND);
122
123   propertiesGridSizer->AddGrowableCol(1,1);
124
125   propertiesPanelSizer->Add(propertiesGridSizer, 0, wxEXPAND);
126   propertiesPanel->SetSizer(propertiesPanelSizer);
127   propertiesPanelSizer->Fit(propertiesPanel);
128   propertiesBox->Add(propertiesPanel, 0, wxEXPAND);
129   sizer->Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
130
131   //Actions
132   wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions"));
133   wxPanel* actionsPanel = new wxPanel(this);
134   wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
135
136   wxButton* createClassbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_CLASS, _T("Create Class"));
137   createClassbt->SetToolTip(wxT("Create a new class for this library."));
138   actionsPanelSizer->Add(createClassbt, 0, wxALL, 5);
139   wxButton* createFolderbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_FOLDER, _T("Create Folder"));
140   createFolderbt->SetToolTip(wxT("Create a new folder for this library."));
141   actionsPanelSizer->Add(createFolderbt, 0, wxALL, 5);
142   wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists File"));
143   editCMakebt->SetToolTip(wxT("Edit the CMakeLists.txt of this library in the default text editor."));
144   editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMLibraryDescriptionPanel::OnCMakeMouseEnter,NULL,this);
145   editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMLibraryDescriptionPanel::OnCMakeMouseExit,NULL,this);
146   actionsPanelSizer->Add(editCMakebt, 0, wxALL, 5);
147   wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("Open Library Folder"));
148   openFolderbt->SetToolTip(wxT("Open the library folder in the file explorer."));
149   actionsPanelSizer->Add(openFolderbt, 0, wxALL, 5);
150
151   actionsPanel->SetSizer(actionsPanelSizer);
152   actionsPanelSizer->Fit(actionsPanel);
153   actionsBox->Add(actionsPanel, 1, wxEXPAND);
154   sizer -> Add(actionsBox, 0, wxALL | wxEXPAND, 10);
155
156   //Assign sizer
157   SetSizer(sizer);
158   sizer->SetSizeHints(this);
159
160   if (((wxCDMMainFrame*)this->GetParent())->isHelp())
161     {
162       wxCDMLibraryHelpDialog* helpDialog = new wxCDMLibraryHelpDialog(this->GetParent(), this->library, wxID_ANY);
163       helpDialog->Show(true);
164     }
165 }
166
167 void wxCDMLibraryDescriptionPanel::OnBtnReturn(wxCommandEvent& event)
168 {
169   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
170   newEvent->SetInt(((wxCDMMainFrame*)this->GetParent())->GetModel()->GetProject()->GetId());
171   newEvent->SetId(0);
172   wxPostEvent(this->GetParent(), *newEvent);
173 }
174
175 void wxCDMLibraryDescriptionPanel::OnBtnSetExeName(wxCommandEvent& event)
176 {
177   //get name
178   wxString versionWx = wxGetTextFromUser(
179       wxT("Enter the new executable name"),
180       wxT("Change Library Name - creaDevManager"),
181       crea::std2wx(this->library->GetNameLibrary())
182   );
183   //check name
184   std::vector<std::string> parts;
185   CDMUtilities::splitter::split(parts, crea::wx2std(versionWx), " .", CDMUtilities::splitter::no_empties);
186   if(parts.size() > 0)
187     {
188       std::string* result;
189       if(!this->library->SetNameLibrary(crea::wx2std(versionWx), result))
190         wxMessageBox(crea::std2wx(*result),_T("Change Library Name - Error!"),wxOK | wxICON_ERROR);
191     }
192   else
193     {
194       wxMessageBox(crea::std2wx("No name specified"),_T("Set Library Name - Error!"),wxOK | wxICON_ERROR);
195     }
196   this->libraryNametc->SetLabel(crea::std2wx(this->library->GetNameLibrary()));
197 }
198
199 void wxCDMLibraryDescriptionPanel::OnBtnCreateClass(wxCommandEvent& event)
200 {
201   //TODO: implement method
202   std::cerr << "Event OnBtnCreateClass not implemented" << std::endl;
203   event.Skip();
204 }
205
206 void wxCDMLibraryDescriptionPanel::OnBtnCreateFolder(wxCommandEvent& event)
207 {
208   //get name
209   wxString folderName = wxGetTextFromUser(
210       wxT("Enter the name of the new folder:"),
211       wxT("Create Folder - creaDevManager")
212   );
213   //check name
214   std::vector<std::string> parts;
215   CDMUtilities::splitter::split(parts, crea::wx2std(folderName), " /\\\"", CDMUtilities::splitter::no_empties);
216   if(parts.size() > 0)
217     {
218       std::string* result;
219       modelCDMFolder* folderC = this->library->CreateFolder(crea::wx2std(folderName), result);
220       if(folderC == NULL)
221         {
222           wxMessageBox(crea::std2wx(*result),_T("Create Folder - Error!"),wxOK | wxICON_ERROR);
223           return;
224         }
225       ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
226       wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
227       newEvent->SetInt(folderC->GetId());
228       wxPostEvent(this->GetParent(), *newEvent);
229       wxMessageBox(crea::std2wx("The folder was successfully created"),_T("Create Folder - Success"),wxOK | wxICON_INFORMATION);
230     }
231   else
232     {
233       wxMessageBox(crea::std2wx("No name specified"),_T("Create Folder - Error!"),wxOK | wxICON_ERROR);
234     }
235 }
236
237 void wxCDMLibraryDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
238 {
239   std::string* result;
240   if(!this->library->OpenCMakeListsFile(result))
241     wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
242
243   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
244
245   if(this->library->GetCMakeLists() != NULL)
246     {
247       int CMId = this->library->GetCMakeLists()->GetId();
248       newEvent->SetInt(CMId);
249       newEvent->SetId(0);
250       wxPostEvent(this->GetParent(), *newEvent);
251     }
252
253   event.Skip();
254 }
255
256 void wxCDMLibraryDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
257 {
258   std::string* result;
259   if(!this->library->OpenInFileExplorer(result))
260     wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
261 }
262
263 void wxCDMLibraryDescriptionPanel::OnCMakeMouseEnter(wxMouseEvent& event)
264 {
265   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
266
267   if(this->library->GetCMakeLists() != NULL)
268     {
269       int CMId = this->library->GetCMakeLists()->GetId();
270       newEvent->SetInt(CMId);
271       newEvent->SetId(0);
272       wxPostEvent(this->GetParent(), *newEvent);
273     }
274   event.Skip();
275 }
276
277 void wxCDMLibraryDescriptionPanel::OnCMakeMouseExit(wxMouseEvent& event)
278 {
279   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
280
281   if(this->library->GetCMakeLists() != NULL)
282     {
283       int CMId = this->library->GetCMakeLists()->GetId();
284       newEvent->SetInt(CMId);
285       newEvent->SetId(0);
286       wxPostEvent(this->GetParent(), *newEvent);
287     }
288   event.Skip();
289 }