]> Creatis software - crea.git/blob - lib/creaDevManagerLib/wxCDMAppliDescriptionPanel.cpp
ec0dc0486fdca8d3e9a4d5766a53fa5e40565d11
[crea.git] / lib / creaDevManagerLib / wxCDMAppliDescriptionPanel.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  * wxCDMAppliDescriptionPanel.cpp
30  *
31  *  Created on: Nov 27, 2012
32  *      Author: Daniel Felipe Gonzalez Obando
33  */
34
35 #include "wxCDMAppliDescriptionPanel.h"
36
37
38
39 #include "wxCDMMainFrame.h"
40
41 #include "wxCDMAppliHelpDialog.h"
42
43 #include "creaDevManagerIds.h"
44 #include "images/ApIcon64.xpm"
45
46 BEGIN_EVENT_TABLE(wxCDMAppliDescriptionPanel, wxPanel)
47 EVT_BUTTON(ID_BUTTON_PREV, wxCDMAppliDescriptionPanel::OnBtnReturn)
48 EVT_HYPERLINK(ID_LINK_SELECT_APPLICATION, wxCDMAppliDescriptionPanel::OnLnkApplicationSelect)
49 EVT_BUTTON(ID_BUTTON_CREATE_APPLICATION, wxCDMAppliDescriptionPanel::OnBtnCreateApplication)
50 EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMAppliDescriptionPanel::OnBtnEditCMakeLists)
51 EVT_BUTTON(ID_BUTTON_OPEN_FOLDER, wxCDMAppliDescriptionPanel::OnBtnOpenFolder)
52 END_EVENT_TABLE()
53
54 wxCDMAppliDescriptionPanel::wxCDMAppliDescriptionPanel(
55     wxWindow* parent,
56     modelCDMAppli* appli,
57     wxWindowID id,
58     const wxString& caption,
59     const wxPoint& pos,
60     const wxSize& size,
61     long style
62 )
63 {
64   wxCDMAppliDescriptionPanel::Create(parent, appli, id, caption, pos, size, style);
65 }
66
67 wxCDMAppliDescriptionPanel::~wxCDMAppliDescriptionPanel()
68 {
69 }
70
71 bool wxCDMAppliDescriptionPanel::Create(
72     wxWindow* parent,
73     modelCDMAppli* appli,
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->appli = appli;
83   CreateControls();
84   return TRUE;
85 }
86
87 void wxCDMAppliDescriptionPanel::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   //Header
96   wxBoxSizer* headerSizer = new wxBoxSizer(wxHORIZONTAL);
97   {
98     //Image
99     headerSizer->Add(new wxStaticBitmap(this, -1, wxBitmap(ApIcon64)),0, wxALIGN_CENTER, 0);
100     wxBoxSizer* textSizer = new wxBoxSizer(wxVERTICAL);
101     //Title
102     textSizer->Add(new wxStaticText(this, -1, _("Application Management")),0, wxALIGN_LEFT, 0);
103
104     headerSizer->Add(textSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
105   }
106   sizer->Add(headerSizer, 0, wxALIGN_CENTER);
107
108   //Applications
109   wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("A&vailable Applications"));
110   propertiesBox->GetStaticBox()->SetToolTip(wxT("Select any of the available applications to see its details or the modify them."));
111   wxPanel* propertiesPanel = new wxPanel(this);
112   wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL);
113
114   std::vector<modelCDMApplication*> applications = this->appli->GetApplications();
115   for (int i = 0; i < applications.size(); i++)
116     {
117       wxHyperlinkCtrl* pApplicationlk = new wxHyperlinkCtrl(propertiesPanel,ID_LINK_SELECT_APPLICATION, crea::std2wx(applications[i]->GetName().c_str()), crea::std2wx(applications[i]->GetName().c_str()));
118       pApplicationlk->SetWindowStyle(wxALIGN_LEFT);
119       std::string tt = "Name: " + applications[i]->GetName() + "\n";
120       tt += "Location: " + applications[i]->GetPath();
121       pApplicationlk->SetToolTip(crea::std2wx(tt.c_str()));
122       pApplicationlk->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMAppliDescriptionPanel::OnMouseEnter,NULL,this);
123       pApplicationlk->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMAppliDescriptionPanel::OnMouseExit,NULL,this);
124       propertiesPanelSizer -> Add(pApplicationlk, 1, wxEXPAND | wxALL, 5);
125     }
126
127   propertiesPanel->SetSizer(propertiesPanelSizer);
128   propertiesPanelSizer->Fit(propertiesPanel);
129   propertiesBox->Add(propertiesPanel, 1, wxEXPAND | wxALL, 5);
130   sizer -> Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
131
132   //Actions
133   wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Actions"));
134   actionsBox->GetStaticBox()->SetToolTip(wxT("Create a new application or make any change to the appli's CMakeLists.txt file by selecting the desired action."));
135   wxPanel* actionsPanel = new wxPanel(this);
136   wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
137   //actionsGrid Sizer
138   wxFlexGridSizer* actionsGridSizer = new wxFlexGridSizer(2, 2, 9, 15);
139
140   wxButton* createApplicationbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_APPLICATION, _T("A. Create Application"));
141   createApplicationbt->SetToolTip(wxT("Create a new application for this project."));
142   actionsGridSizer->Add(createApplicationbt, 1, wxALL | wxEXPAND, 5);
143   wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("B. Edit CMakeLists File"));
144   editCMakebt->SetToolTip(wxT("Open the system default text editor to edit the CMakeLists.txt file."));
145   editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMAppliDescriptionPanel::OnCMakeMouseEnter,NULL,this);
146   editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMAppliDescriptionPanel::OnCMakeMouseExit,NULL,this);
147   actionsGridSizer->Add(editCMakebt, 1, wxALL | wxEXPAND, 5);
148   wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("C. Open Applications Folder"));
149   openFolderbt->SetToolTip(wxT("Open the appli folder in the file explorer."));
150   actionsGridSizer->Add(openFolderbt, 1, wxALL | wxEXPAND, 5);
151
152   actionsGridSizer->AddGrowableCol(0,1);
153   actionsGridSizer->AddGrowableCol(1,1);
154
155   actionsPanelSizer->Add(actionsGridSizer, 1, wxEXPAND, 0);
156   actionsPanel->SetSizer(actionsPanelSizer);
157   actionsPanelSizer->Fit(actionsPanel);
158   actionsBox->Add(actionsPanel, 0, wxALL | wxEXPAND, 5);
159   sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 10);
160
161   //Assign sizer
162   SetSizer(sizer);
163   sizer->SetSizeHints(this);
164
165   if (((wxCDMMainFrame*)this->GetParent())->isHelp())
166     {
167       wxCDMAppliHelpDialog* helpDialog = new wxCDMAppliHelpDialog(this->GetParent(), this->appli, wxID_ANY);
168       helpDialog->Show(true);
169     }
170 }
171
172 void wxCDMAppliDescriptionPanel::OnBtnCreateApplication(wxCommandEvent& event)
173 {
174   //get name
175   wxString applicationName = wxGetTextFromUser(
176       _T("Enter the new application name"),
177       _T("New Application - creaDevManager"),
178       _T("")
179   );
180   //check name
181   if(applicationName.Len() > 0)
182     {
183       std::string* result;
184       //create library
185       modelCDMIProjectTreeNode* application = this->appli->CreateApplication(crea::wx2std(applicationName),result);
186       //check library created
187       if(application == NULL)
188         {
189           wxMessageBox(crea::std2wx(*result),_T("New Application - Error!"),wxOK | wxICON_ERROR);
190           event.Skip();
191           return;
192         }
193       wxMessageBox(crea::std2wx("Application successfully created."),_T("New Application - Success!"),wxOK | wxICON_INFORMATION);
194
195       //refreshing tree and description
196       //send event instead of calling parent to avoid crashing
197
198       ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
199
200       wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
201       newEvent->SetInt(application->GetId());
202       wxPostEvent(this->GetParent(), *newEvent);
203       event.Skip();
204     }
205 }
206
207 void wxCDMAppliDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
208 {
209   std::string* result;
210   if(!this->appli->OpenCMakeListsFile(result))
211     wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
212
213   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
214
215   if(this->appli->GetCMakeLists() != NULL)
216     {
217       int CMId = this->appli->GetCMakeLists()->GetId();
218       newEvent->SetInt(CMId);
219       newEvent->SetId(0);
220       wxPostEvent(this->GetParent(), *newEvent);
221     }
222 }
223
224 void wxCDMAppliDescriptionPanel::OnLnkApplicationSelect(wxHyperlinkEvent& event)
225 {
226   int applicationId = 0;
227   std::vector<modelCDMApplication*> applications = this->appli->GetApplications();
228   for (int i = 0; i < applications.size(); i++)
229     {
230       if(applications[i]->GetName() == crea::wx2std(event.GetURL()))
231         {
232           applicationId = applications[i]->GetId();
233           break;
234         }
235     }
236   wxCommandEvent* newEvent1 = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
237   newEvent1->SetInt(applicationId);
238   newEvent1->SetId(0);
239   wxPostEvent(this->GetParent(), *newEvent1);
240
241   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
242   newEvent->SetInt(applicationId);
243   newEvent->SetId(0);
244   wxPostEvent(this->GetParent(), *newEvent);
245 }
246
247 void wxCDMAppliDescriptionPanel::OnBtnReturn(wxCommandEvent& event)
248 {
249   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
250   newEvent->SetInt(((wxCDMMainFrame*)this->GetParent())->GetModel()->GetProject()->GetId());
251   newEvent->SetId(0);
252   wxPostEvent(this->GetParent(), *newEvent);
253 }
254
255 void wxCDMAppliDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
256 {
257   std::string* result;
258   if(!this->appli->OpenInFileExplorer(result))
259     wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
260 }
261
262 void wxCDMAppliDescriptionPanel::OnMouseEnter(wxMouseEvent& event)
263 {
264   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
265   std::string AppName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
266   int appId = 0;
267   std::vector<modelCDMApplication*> applications = this->appli->GetApplications();
268   for (int i = 0; i < applications.size(); i++)
269     {
270       if(applications[i]->GetName() == AppName)
271         {
272           appId = applications[i]->GetId();
273           break;
274         }
275     }
276   newEvent->SetInt(appId);
277   newEvent->SetId(0);
278   wxPostEvent(this->GetParent(), *newEvent);
279   event.Skip();
280 }
281
282 void wxCDMAppliDescriptionPanel::OnMouseExit(wxMouseEvent& event)
283 {
284   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
285   std::string AppName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
286   int appId = 0;
287   std::vector<modelCDMApplication*> applications = this->appli->GetApplications();
288   for (int i = 0; i < applications.size(); i++)
289     {
290       if(applications[i]->GetName() == AppName)
291         {
292           appId = applications[i]->GetId();
293           break;
294         }
295     }
296   newEvent->SetInt(appId);
297   newEvent->SetId(0);
298   wxPostEvent(this->GetParent(), *newEvent);
299   event.Skip();
300 }
301
302 void wxCDMAppliDescriptionPanel::OnCMakeMouseEnter(wxMouseEvent& event)
303 {
304   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
305
306   if(this->appli->GetCMakeLists() != NULL)
307     {
308       int CMId = this->appli->GetCMakeLists()->GetId();
309       newEvent->SetInt(CMId);
310       newEvent->SetId(0);
311       wxPostEvent(this->GetParent(), *newEvent);
312     }
313   event.Skip();
314 }
315
316 void wxCDMAppliDescriptionPanel::OnCMakeMouseExit(wxMouseEvent& event)
317 {
318   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
319
320   if(this->appli->GetCMakeLists() != NULL)
321     {
322       int CMId = this->appli->GetCMakeLists()->GetId();
323       newEvent->SetInt(CMId);
324       newEvent->SetId(0);
325       wxPostEvent(this->GetParent(), *newEvent);
326     }
327   event.Skip();
328 }