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