]> Creatis software - crea.git/blob - lib/creaDevManagerLib/wxCDMAppliDescriptionPanel.cpp
9fb749ddfe6ac0002777c1ae6d5fec99c7afaa78
[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
96   //Title
97   sizer->Add(new wxStaticText(this, -1, _("Application Management")),0, wxALIGN_CENTER, 0);
98
99   //Image
100   sizer->Add(new wxStaticBitmap(this, -1, wxBitmap(ApIcon64)),0, wxALIGN_CENTER, 0);
101
102   //Applications
103   wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("A&vailable Applications"));
104   propertiesBox->GetStaticBox()->SetToolTip(wxT("Select any of the available applications to see its details or the modify them."));
105   wxPanel* propertiesPanel = new wxPanel(this);
106   wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL);
107
108   std::vector<modelCDMApplication*> applications = this->appli->GetApplications();
109   for (int i = 0; i < applications.size(); i++)
110     {
111       wxHyperlinkCtrl* pApplicationlk = new wxHyperlinkCtrl(propertiesPanel,ID_LINK_SELECT_APPLICATION, crea::std2wx(applications[i]->GetName().c_str()), crea::std2wx(applications[i]->GetName().c_str()));
112       std::string tt = "Name: " + applications[i]->GetName() + "\n";
113       tt += "Location: " + applications[i]->GetPath();
114       pApplicationlk->SetToolTip(crea::std2wx(tt.c_str()));
115       pApplicationlk->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMAppliDescriptionPanel::OnMouseEnter,NULL,this);
116       pApplicationlk->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMAppliDescriptionPanel::OnMouseExit,NULL,this);
117       propertiesPanelSizer -> Add(pApplicationlk, 0, wxALIGN_LEFT | wxALL, 5);
118     }
119
120   propertiesPanel->SetSizer(propertiesPanelSizer);
121   propertiesPanelSizer->Fit(propertiesPanel);
122   propertiesBox->Add(propertiesPanel, 0, wxALL, 5);
123   sizer -> Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
124
125   //Actions
126   wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Actions"));
127   actionsBox->GetStaticBox()->SetToolTip(wxT("Create a new application or make any change to the appli's CMakeLists.txt file by selecting the desired action."));
128   wxPanel* actionsPanel = new wxPanel(this);
129   wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
130
131   wxButton* createApplicationbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_APPLICATION, _T("Create Application"));
132   createApplicationbt->SetToolTip(wxT("Create a new application for this project."));
133   actionsPanelSizer->Add(createApplicationbt, 0, wxALL, 5);
134   wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists File"));
135   editCMakebt->SetToolTip(wxT("Open the system default text editor to edit the CMakeLists.txt file."));
136   editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMAppliDescriptionPanel::OnCMakeMouseEnter,NULL,this);
137   editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMAppliDescriptionPanel::OnCMakeMouseExit,NULL,this);
138   actionsPanelSizer->Add(editCMakebt, 0, wxALL, 5);
139   wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("Open Applications Folder"));
140   openFolderbt->SetToolTip(wxT("Open the appli folder in the file explorer."));
141   actionsPanelSizer->Add(openFolderbt, 0, wxALL, 5);
142
143   actionsPanel->SetSizer(actionsPanelSizer);
144   actionsPanelSizer->Fit(actionsPanel);
145   actionsBox->Add(actionsPanel, 0, wxALL, 5);
146   sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 10);
147
148   //Assign sizer
149   SetSizer(sizer);
150   sizer->SetSizeHints(this);
151
152   if (((wxCDMMainFrame*)this->GetParent())->isHelp())
153     {
154       wxCDMAppliHelpDialog* helpDialog = new wxCDMAppliHelpDialog(this->GetParent(), this->appli, wxID_ANY);
155       helpDialog->Show(true);
156     }
157 }
158
159 void wxCDMAppliDescriptionPanel::OnBtnCreateApplication(wxCommandEvent& event)
160 {
161   //get name
162   wxString applicationName = wxGetTextFromUser(
163       _T("Enter the new application name"),
164       _T("New Application - creaDevManager"),
165       _T("")
166   );
167   //check name
168   if(applicationName.Len() > 0)
169     {
170       std::string* result;
171       //create library
172       modelCDMIProjectTreeNode* application = this->appli->CreateApplication(crea::wx2std(applicationName),result);
173       //check library created
174       if(application == NULL)
175         {
176           wxMessageBox(crea::std2wx(*result),_T("New Application - Error!"),wxOK | wxICON_ERROR);
177           event.Skip();
178           return;
179         }
180       wxMessageBox(crea::std2wx("Application successfully created."),_T("New Application - 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(application->GetId());
189       wxPostEvent(this->GetParent(), *newEvent);
190       event.Skip();
191     }
192 }
193
194 void wxCDMAppliDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
195 {
196   std::string* result;
197   if(!this->appli->OpenCMakeListsFile(result))
198     wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
199
200   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
201
202   if(this->appli->GetCMakeLists() != NULL)
203     {
204       int CMId = this->appli->GetCMakeLists()->GetId();
205       newEvent->SetInt(CMId);
206       newEvent->SetId(0);
207       wxPostEvent(this->GetParent(), *newEvent);
208     }
209 }
210
211 void wxCDMAppliDescriptionPanel::OnLnkApplicationSelect(wxHyperlinkEvent& event)
212 {
213   int applicationId = 0;
214   std::vector<modelCDMApplication*> applications = this->appli->GetApplications();
215   for (int i = 0; i < applications.size(); i++)
216     {
217       if(applications[i]->GetName() == crea::wx2std(event.GetURL()))
218         {
219           applicationId = applications[i]->GetId();
220           break;
221         }
222     }
223   wxCommandEvent* newEvent1 = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
224   newEvent1->SetInt(applicationId);
225   newEvent1->SetId(0);
226   wxPostEvent(this->GetParent(), *newEvent1);
227
228   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
229   newEvent->SetInt(applicationId);
230   newEvent->SetId(0);
231   wxPostEvent(this->GetParent(), *newEvent);
232 }
233
234 void wxCDMAppliDescriptionPanel::OnBtnReturn(wxCommandEvent& event)
235 {
236   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
237   newEvent->SetInt(((wxCDMMainFrame*)this->GetParent())->GetModel()->GetProject()->GetId());
238   newEvent->SetId(0);
239   wxPostEvent(this->GetParent(), *newEvent);
240 }
241
242 void wxCDMAppliDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
243 {
244   std::string* result;
245   if(!this->appli->OpenInFileExplorer(result))
246     wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
247 }
248
249 void wxCDMAppliDescriptionPanel::OnMouseEnter(wxMouseEvent& event)
250 {
251   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
252   std::string AppName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
253   int appId = 0;
254   std::vector<modelCDMApplication*> applications = this->appli->GetApplications();
255   for (int i = 0; i < applications.size(); i++)
256     {
257       if(applications[i]->GetName() == AppName)
258         {
259           appId = applications[i]->GetId();
260           break;
261         }
262     }
263   newEvent->SetInt(appId);
264   newEvent->SetId(0);
265   wxPostEvent(this->GetParent(), *newEvent);
266   event.Skip();
267 }
268
269 void wxCDMAppliDescriptionPanel::OnMouseExit(wxMouseEvent& event)
270 {
271   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
272   std::string AppName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
273   int appId = 0;
274   std::vector<modelCDMApplication*> applications = this->appli->GetApplications();
275   for (int i = 0; i < applications.size(); i++)
276     {
277       if(applications[i]->GetName() == AppName)
278         {
279           appId = applications[i]->GetId();
280           break;
281         }
282     }
283   newEvent->SetInt(appId);
284   newEvent->SetId(0);
285   wxPostEvent(this->GetParent(), *newEvent);
286   event.Skip();
287 }
288
289 void wxCDMAppliDescriptionPanel::OnCMakeMouseEnter(wxMouseEvent& event)
290 {
291   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
292
293   if(this->appli->GetCMakeLists() != NULL)
294     {
295       int CMId = this->appli->GetCMakeLists()->GetId();
296       newEvent->SetInt(CMId);
297       newEvent->SetId(0);
298       wxPostEvent(this->GetParent(), *newEvent);
299     }
300   event.Skip();
301 }
302
303 void wxCDMAppliDescriptionPanel::OnCMakeMouseExit(wxMouseEvent& event)
304 {
305   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
306
307   if(this->appli->GetCMakeLists() != NULL)
308     {
309       int CMId = this->appli->GetCMakeLists()->GetId();
310       newEvent->SetInt(CMId);
311       newEvent->SetId(0);
312       wxPostEvent(this->GetParent(), *newEvent);
313     }
314   event.Skip();
315 }