2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------
29 * wxCDMAppliDescriptionPanel.cpp
31 * Created on: Nov 27, 2012
32 * Author: Daniel Felipe Gonzalez Obando
35 #include "wxCDMAppliDescriptionPanel.h"
39 #include "wxCDMMainFrame.h"
41 #include "wxCDMAppliHelpDialog.h"
43 #include "creaDevManagerIds.h"
44 #include "images/ApIcon64.xpm"
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)
54 wxCDMAppliDescriptionPanel::wxCDMAppliDescriptionPanel(
58 const wxString& caption,
64 wxCDMAppliDescriptionPanel::Create(parent, appli, id, caption, pos, size, style);
67 wxCDMAppliDescriptionPanel::~wxCDMAppliDescriptionPanel()
71 bool wxCDMAppliDescriptionPanel::Create(
75 const wxString& caption,
81 wxPanel::Create(parent, id, pos, size, style);
87 void wxCDMAppliDescriptionPanel::CreateControls()
89 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
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);
96 wxBoxSizer* headerSizer = new wxBoxSizer(wxHORIZONTAL);
99 headerSizer->Add(new wxStaticBitmap(this, -1, wxBitmap(ApIcon64)),0, wxALIGN_CENTER, 0);
100 wxBoxSizer* textSizer = new wxBoxSizer(wxVERTICAL);
102 textSizer->Add(new wxStaticText(this, -1, _("Application Management")),0, wxALIGN_LEFT, 0);
104 headerSizer->Add(textSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
106 sizer->Add(headerSizer, 0, wxALIGN_CENTER);
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);
114 std::vector<modelCDMApplication*> applications = this->appli->GetApplications();
115 for (int i = 0; i < applications.size(); i++)
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 std::string tt = "Name: " + applications[i]->GetName() + "\n";
119 tt += "Location: " + applications[i]->GetPath();
120 pApplicationlk->SetToolTip(crea::std2wx(tt.c_str()));
121 pApplicationlk->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMAppliDescriptionPanel::OnMouseEnter,NULL,this);
122 pApplicationlk->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMAppliDescriptionPanel::OnMouseExit,NULL,this);
123 propertiesPanelSizer -> Add(pApplicationlk, 0, wxALIGN_LEFT | wxALL, 5);
126 propertiesPanel->SetSizer(propertiesPanelSizer);
127 propertiesPanelSizer->Fit(propertiesPanel);
128 propertiesBox->Add(propertiesPanel, 0, wxALL, 5);
129 sizer -> Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
132 wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Actions"));
133 actionsBox->GetStaticBox()->SetToolTip(wxT("Create a new application or make any change to the appli's CMakeLists.txt file by selecting the desired action."));
134 wxPanel* actionsPanel = new wxPanel(this);
135 wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
137 wxFlexGridSizer* actionsGridSizer = new wxFlexGridSizer(2, 2, 9, 15);
139 wxButton* createApplicationbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_APPLICATION, _T("A. Create Application"));
140 createApplicationbt->SetToolTip(wxT("Create a new application for this project."));
141 actionsGridSizer->Add(createApplicationbt, 1, wxALL | wxEXPAND, 5);
142 wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("B. Edit CMakeLists File"));
143 editCMakebt->SetToolTip(wxT("Open the system default text editor to edit the CMakeLists.txt file."));
144 editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMAppliDescriptionPanel::OnCMakeMouseEnter,NULL,this);
145 editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMAppliDescriptionPanel::OnCMakeMouseExit,NULL,this);
146 actionsGridSizer->Add(editCMakebt, 1, wxALL | wxEXPAND, 5);
147 wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("C. Open Applications Folder"));
148 openFolderbt->SetToolTip(wxT("Open the appli folder in the file explorer."));
149 actionsGridSizer->Add(openFolderbt, 1, wxALL | wxEXPAND, 5);
151 actionsGridSizer->AddGrowableCol(0,1);
152 actionsGridSizer->AddGrowableCol(1,1);
154 actionsPanelSizer->Add(actionsGridSizer, 1, wxEXPAND, 0);
155 actionsPanel->SetSizer(actionsPanelSizer);
156 actionsPanelSizer->Fit(actionsPanel);
157 actionsBox->Add(actionsPanel, 0, wxALL | wxEXPAND, 5);
158 sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 10);
162 sizer->SetSizeHints(this);
164 if (((wxCDMMainFrame*)this->GetParent())->isHelp())
166 wxCDMAppliHelpDialog* helpDialog = new wxCDMAppliHelpDialog(this->GetParent(), this->appli, wxID_ANY);
167 helpDialog->Show(true);
171 void wxCDMAppliDescriptionPanel::OnBtnCreateApplication(wxCommandEvent& event)
174 wxString applicationName = wxGetTextFromUser(
175 _T("Enter the new application name"),
176 _T("New Application - creaDevManager"),
180 if(applicationName.Len() > 0)
184 modelCDMIProjectTreeNode* application = this->appli->CreateApplication(crea::wx2std(applicationName),result);
185 //check library created
186 if(application == NULL)
188 wxMessageBox(crea::std2wx(*result),_T("New Application - Error!"),wxOK | wxICON_ERROR);
192 wxMessageBox(crea::std2wx("Application successfully created."),_T("New Application - Success!"),wxOK | wxICON_INFORMATION);
194 //refreshing tree and description
195 //send event instead of calling parent to avoid crashing
197 ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
199 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
200 newEvent->SetInt(application->GetId());
201 wxPostEvent(this->GetParent(), *newEvent);
206 void wxCDMAppliDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
209 if(!this->appli->OpenCMakeListsFile(result))
210 wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
212 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
214 if(this->appli->GetCMakeLists() != NULL)
216 int CMId = this->appli->GetCMakeLists()->GetId();
217 newEvent->SetInt(CMId);
219 wxPostEvent(this->GetParent(), *newEvent);
223 void wxCDMAppliDescriptionPanel::OnLnkApplicationSelect(wxHyperlinkEvent& event)
225 int applicationId = 0;
226 std::vector<modelCDMApplication*> applications = this->appli->GetApplications();
227 for (int i = 0; i < applications.size(); i++)
229 if(applications[i]->GetName() == crea::wx2std(event.GetURL()))
231 applicationId = applications[i]->GetId();
235 wxCommandEvent* newEvent1 = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
236 newEvent1->SetInt(applicationId);
238 wxPostEvent(this->GetParent(), *newEvent1);
240 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
241 newEvent->SetInt(applicationId);
243 wxPostEvent(this->GetParent(), *newEvent);
246 void wxCDMAppliDescriptionPanel::OnBtnReturn(wxCommandEvent& event)
248 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
249 newEvent->SetInt(((wxCDMMainFrame*)this->GetParent())->GetModel()->GetProject()->GetId());
251 wxPostEvent(this->GetParent(), *newEvent);
254 void wxCDMAppliDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
257 if(!this->appli->OpenInFileExplorer(result))
258 wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
261 void wxCDMAppliDescriptionPanel::OnMouseEnter(wxMouseEvent& event)
263 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
264 std::string AppName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
266 std::vector<modelCDMApplication*> applications = this->appli->GetApplications();
267 for (int i = 0; i < applications.size(); i++)
269 if(applications[i]->GetName() == AppName)
271 appId = applications[i]->GetId();
275 newEvent->SetInt(appId);
277 wxPostEvent(this->GetParent(), *newEvent);
281 void wxCDMAppliDescriptionPanel::OnMouseExit(wxMouseEvent& event)
283 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
284 std::string AppName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
286 std::vector<modelCDMApplication*> applications = this->appli->GetApplications();
287 for (int i = 0; i < applications.size(); i++)
289 if(applications[i]->GetName() == AppName)
291 appId = applications[i]->GetId();
295 newEvent->SetInt(appId);
297 wxPostEvent(this->GetParent(), *newEvent);
301 void wxCDMAppliDescriptionPanel::OnCMakeMouseEnter(wxMouseEvent& event)
303 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
305 if(this->appli->GetCMakeLists() != NULL)
307 int CMId = this->appli->GetCMakeLists()->GetId();
308 newEvent->SetInt(CMId);
310 wxPostEvent(this->GetParent(), *newEvent);
315 void wxCDMAppliDescriptionPanel::OnCMakeMouseExit(wxMouseEvent& event)
317 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
319 if(this->appli->GetCMakeLists() != NULL)
321 int CMId = this->appli->GetCMakeLists()->GetId();
322 newEvent->SetInt(CMId);
324 wxPostEvent(this->GetParent(), *newEvent);