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_HYPERLINK(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 wxBoxSizer *linksSizer = new wxBoxSizer(wxHORIZONTAL);
93 std::vector<modelCDMIProjectTreeNode*> parents = this->appli->GetParents();
94 for (int i = 0; i < parents.size(); i++)
96 wxHyperlinkCtrl* returnLnk = new wxHyperlinkCtrl(this, ID_BUTTON_PREV, crea::std2wx(parents[parents.size()-1-i]->GetName()), crea::std2wx(parents[parents.size()-1-i]->GetPath()));
97 returnLnk->SetToolTip(crea::std2wx("Return to " + parents[parents.size()-1-i]->GetName() + "."));
98 linksSizer->Add(returnLnk, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 5);
99 if (i < parents.size()-1)
101 linksSizer->Add(new wxStaticText(this,wxID_ANY, wxT("/")), 0, wxALIGN_CENTER, 0);
104 sizer->Add(linksSizer, 0, wxALIGN_CENTER | wxALL, 5);
107 wxBoxSizer* headerSizer = new wxBoxSizer(wxHORIZONTAL);
110 headerSizer->Add(new wxStaticBitmap(this, -1, wxBitmap(ApIcon64)),0, wxALIGN_CENTER, 0);
111 wxBoxSizer* textSizer = new wxBoxSizer(wxVERTICAL);
113 textSizer->Add(new wxStaticText(this, -1, _("Application Management")),0, wxALIGN_LEFT, 0);
115 headerSizer->Add(textSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
117 sizer->Add(headerSizer, 0, wxALIGN_CENTER);
120 wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("A&vailable Applications"));
121 propertiesBox->GetStaticBox()->SetToolTip(wxT("Select any of the available applications to see its details or the modify them."));
122 wxPanel* propertiesPanel = new wxPanel(this);
123 wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL);
125 std::vector<modelCDMApplication*> applications = this->appli->GetApplications();
126 for (int i = 0; i < applications.size(); i++)
128 wxHyperlinkCtrl* pApplicationlk = new wxHyperlinkCtrl(propertiesPanel,ID_LINK_SELECT_APPLICATION, crea::std2wx(applications[i]->GetName().c_str()), crea::std2wx(applications[i]->GetName().c_str()));
129 pApplicationlk->SetWindowStyle(wxALIGN_LEFT);
130 std::string tt = "Name: " + applications[i]->GetName() + "\n";
131 tt += "Location: " + applications[i]->GetPath();
132 pApplicationlk->SetToolTip(crea::std2wx(tt.c_str()));
133 pApplicationlk->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMAppliDescriptionPanel::OnMouseEnter,NULL,this);
134 pApplicationlk->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMAppliDescriptionPanel::OnMouseExit,NULL,this);
135 propertiesPanelSizer -> Add(pApplicationlk, 1, wxEXPAND | wxALL, 5);
138 propertiesPanel->SetSizer(propertiesPanelSizer);
139 propertiesPanelSizer->Fit(propertiesPanel);
140 propertiesBox->Add(propertiesPanel, 1, wxEXPAND | wxALL, 5);
141 sizer -> Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
144 wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Actions"));
145 actionsBox->GetStaticBox()->SetToolTip(wxT("Create a new application or make any change to the appli's CMakeLists.txt file by selecting the desired action."));
146 wxPanel* actionsPanel = new wxPanel(this);
147 wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
149 wxFlexGridSizer* actionsGridSizer = new wxFlexGridSizer(2, 2, 9, 15);
151 wxButton* createApplicationbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_APPLICATION, _T("A. Create Application"));
152 createApplicationbt->SetToolTip(wxT("Create a new application for this project."));
153 actionsGridSizer->Add(createApplicationbt, 1, wxALL | wxEXPAND, 5);
154 wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("B. Edit CMakeLists File"));
155 editCMakebt->SetToolTip(wxT("Open the system default text editor to edit the CMakeLists.txt file."));
156 editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMAppliDescriptionPanel::OnCMakeMouseEnter,NULL,this);
157 editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMAppliDescriptionPanel::OnCMakeMouseExit,NULL,this);
158 actionsGridSizer->Add(editCMakebt, 1, wxALL | wxEXPAND, 5);
159 wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("C. Open Applications Folder"));
160 openFolderbt->SetToolTip(wxT("Open the appli folder in the file explorer."));
161 actionsGridSizer->Add(openFolderbt, 1, wxALL | wxEXPAND, 5);
163 actionsGridSizer->AddGrowableCol(0,1);
164 actionsGridSizer->AddGrowableCol(1,1);
166 actionsPanelSizer->Add(actionsGridSizer, 1, wxEXPAND, 0);
167 actionsPanel->SetSizer(actionsPanelSizer);
168 actionsPanelSizer->Fit(actionsPanel);
169 actionsBox->Add(actionsPanel, 0, wxALL | wxEXPAND, 5);
170 sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 10);
174 sizer->SetSizeHints(this);
176 if (((wxCDMMainFrame*)this->GetParent())->isHelp())
178 wxCDMAppliHelpDialog* helpDialog = new wxCDMAppliHelpDialog(this->GetParent(), this->appli, wxID_ANY);
179 helpDialog->Show(true);
183 void wxCDMAppliDescriptionPanel::OnBtnCreateApplication(wxCommandEvent& event)
186 wxString applicationName = wxGetTextFromUser(
187 _T("Enter the new application name"),
188 _T("New Application - creaDevManager"),
192 if(applicationName.Len() > 0)
196 modelCDMIProjectTreeNode* application = this->appli->CreateApplication(crea::wx2std(applicationName),result);
197 //check library created
198 if(application == NULL)
200 wxMessageBox(crea::std2wx(*result),_T("New Application - Error!"),wxOK | wxICON_ERROR);
204 wxMessageBox(crea::std2wx("Application successfully created."),_T("New Application - Success!"),wxOK | wxICON_INFORMATION);
206 //refreshing tree and description
207 //send event instead of calling parent to avoid crashing
209 ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
211 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
212 newEvent->SetInt(application->GetId());
213 wxPostEvent(this->GetParent(), *newEvent);
218 void wxCDMAppliDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
221 if(!this->appli->OpenCMakeListsFile(result))
222 wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
224 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
226 if(this->appli->GetCMakeLists() != NULL)
228 int CMId = this->appli->GetCMakeLists()->GetId();
229 newEvent->SetInt(CMId);
231 wxPostEvent(this->GetParent(), *newEvent);
235 void wxCDMAppliDescriptionPanel::OnLnkApplicationSelect(wxHyperlinkEvent& event)
237 int applicationId = 0;
238 std::vector<modelCDMApplication*> applications = this->appli->GetApplications();
239 for (int i = 0; i < applications.size(); i++)
241 if(applications[i]->GetName() == crea::wx2std(event.GetURL()))
243 applicationId = applications[i]->GetId();
247 wxCommandEvent* newEvent1 = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
248 newEvent1->SetInt(applicationId);
250 wxPostEvent(this->GetParent(), *newEvent1);
252 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
253 newEvent->SetInt(applicationId);
255 wxPostEvent(this->GetParent(), *newEvent);
258 void wxCDMAppliDescriptionPanel::OnBtnReturn(wxHyperlinkEvent& event)
260 std::vector<modelCDMIProjectTreeNode*> parents = this->appli->GetParents();
261 std::string parentURL = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
262 //std::cout << parentURL << std::endl;
263 for (int i = 0; i < parents.size(); i++)
265 if (parents[i]->GetPath() == parentURL)
267 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
268 newEvent->SetInt(parents[i]->GetId());
270 wxPostEvent(this->GetParent(), *newEvent);
275 void wxCDMAppliDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
278 if(!this->appli->OpenInFileExplorer(result))
279 wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
282 void wxCDMAppliDescriptionPanel::OnMouseEnter(wxMouseEvent& event)
284 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
285 std::string AppName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
287 std::vector<modelCDMApplication*> applications = this->appli->GetApplications();
288 for (int i = 0; i < applications.size(); i++)
290 if(applications[i]->GetName() == AppName)
292 appId = applications[i]->GetId();
296 newEvent->SetInt(appId);
298 wxPostEvent(this->GetParent(), *newEvent);
302 void wxCDMAppliDescriptionPanel::OnMouseExit(wxMouseEvent& event)
304 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
305 std::string AppName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
307 std::vector<modelCDMApplication*> applications = this->appli->GetApplications();
308 for (int i = 0; i < applications.size(); i++)
310 if(applications[i]->GetName() == AppName)
312 appId = applications[i]->GetId();
316 newEvent->SetInt(appId);
318 wxPostEvent(this->GetParent(), *newEvent);
322 void wxCDMAppliDescriptionPanel::OnCMakeMouseEnter(wxMouseEvent& event)
324 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
326 if(this->appli->GetCMakeLists() != NULL)
328 int CMId = this->appli->GetCMakeLists()->GetId();
329 newEvent->SetInt(CMId);
331 wxPostEvent(this->GetParent(), *newEvent);
336 void wxCDMAppliDescriptionPanel::OnCMakeMouseExit(wxMouseEvent& event)
338 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
340 if(this->appli->GetCMakeLists() != NULL)
342 int CMId = this->appli->GetCMakeLists()->GetId();
343 newEvent->SetInt(CMId);
345 wxPostEvent(this->GetParent(), *newEvent);