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)
52 EVT_CHECKBOX(ID_CHECK_INCLUDE_APPLICATION, wxCDMAppliDescriptionPanel::OnChBApplicationChange)
55 wxCDMAppliDescriptionPanel::wxCDMAppliDescriptionPanel(
59 const wxString& caption,
65 wxCDMAppliDescriptionPanel::Create(parent, appli, id, caption, pos, size, style);
68 wxCDMAppliDescriptionPanel::~wxCDMAppliDescriptionPanel()
72 bool wxCDMAppliDescriptionPanel::Create(
76 const wxString& caption,
82 wxPanel::Create(parent, id, pos, size, style);
84 // this part makes the scrollbars show up
85 this->FitInside(); // ask the sizer about the needed size
86 this->SetScrollRate(5, 5);
93 void wxCDMAppliDescriptionPanel::CreateControls()
95 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
98 wxBoxSizer *linksSizer = new wxBoxSizer(wxHORIZONTAL);
99 std::vector<modelCDMIProjectTreeNode*> parents = this->appli->GetParents();
100 for (int i = 0; i < (int)(parents.size()); i++)
102 wxHyperlinkCtrl* returnLnk = new wxHyperlinkCtrl(this, ID_BUTTON_PREV, crea::std2wx(parents[parents.size()-1-i]->GetName()), crea::std2wx(parents[parents.size()-1-i]->GetPath()), wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE);
103 returnLnk->SetWindowStyle(wxNO_BORDER);
104 returnLnk->SetToolTip(crea::std2wx("Return to " + parents[parents.size()-1-i]->GetName() + "."));
105 linksSizer->Add(returnLnk, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 5);
106 linksSizer->Add(new wxStaticText(this,wxID_ANY, wxT("/")), 0, wxALIGN_CENTER, 0);
108 linksSizer->Add(new wxStaticText(this, wxID_ANY, crea::std2wx(this->appli->GetName())), 0, wxALIGN_CENTER, 0);
110 sizer->Add(linksSizer, 0, wxALIGN_CENTER | wxALL, 5);
113 wxBoxSizer* headerSizer = new wxBoxSizer(wxHORIZONTAL);
116 headerSizer->Add(new wxStaticBitmap(this, -1, wxBitmap(ApIcon64)),0, wxALIGN_CENTER, 0);
117 wxBoxSizer* textSizer = new wxBoxSizer(wxVERTICAL);
119 textSizer->Add(new wxStaticText(this, -1, _("Application Management")),0, wxALIGN_LEFT, 0);
121 headerSizer->Add(textSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
123 sizer->Add(headerSizer, 0, wxALIGN_CENTER);
126 wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("A&vailable Applications"));
127 propertiesBox->GetStaticBox()->SetToolTip(wxT("Select any of the available applications to see its details or the modify them."));
128 wxPanel* propertiesPanel = new wxPanel(this);
130 std::vector<modelCDMApplication*> applications = this->appli->GetApplications();
131 wxFlexGridSizer* propertiesGridSizer = new wxFlexGridSizer(applications.size()+1, 3, 9, 5);
133 wxStaticText* ChBTitle = new wxStaticText(propertiesPanel, wxID_ANY, wxT("Include in\nCMake"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE_HORIZONTAL);
134 wxStaticText* LkTitle = new wxStaticText(propertiesPanel, wxID_ANY, wxT("Application Name"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE_HORIZONTAL);
135 wxStaticText* HlpTitle = new wxStaticText(propertiesPanel, wxID_ANY, wxT("Help"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE_HORIZONTAL);
137 propertiesGridSizer -> Add(ChBTitle, 0, wxEXPAND | wxALL, 5);
138 propertiesGridSizer -> Add(LkTitle, 0, wxEXPAND | wxALL, 5);
139 propertiesGridSizer -> Add(HlpTitle, 0, wxEXPAND | wxALL, 5);
141 for (int i = 0; i < (int)(applications.size()); i++)
143 //checkbox for cmake inclusion
144 wxCheckBox* pApplicationChB = new wxCheckBox(propertiesPanel, ID_CHECK_INCLUDE_APPLICATION, wxT(""), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
145 pApplicationChB->SetName(crea::std2wx(applications[i]->GetName()));
146 std::string tt = "if this box is checked the the " + applications[i]->GetName() + " application is included in the project compilation.";
147 pApplicationChB->SetToolTip(crea::std2wx(tt));
148 pApplicationChB->SetValue(this->appli->IsApplicationIncluded(applications[i]->GetName()));
149 propertiesGridSizer -> Add(pApplicationChB, 0, wxEXPAND | wxALIGN_CENTER);
151 //link to library with description
152 wxHyperlinkCtrl* pApplicationlk = new wxHyperlinkCtrl(propertiesPanel, ID_LINK_SELECT_APPLICATION, crea::std2wx(applications[i]->GetName().c_str()), crea::std2wx(applications[i]->GetName().c_str()), wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE);
153 pApplicationlk->SetWindowStyle(wxALIGN_LEFT | wxNO_BORDER);
154 tt = "Name: " + applications[i]->GetName() + "\n";
155 tt += "Location: " + applications[i]->GetPath();
156 pApplicationlk->SetToolTip(crea::std2wx(tt));
157 pApplicationlk->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMAppliDescriptionPanel::OnMouseEnter,NULL,this);
158 pApplicationlk->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMAppliDescriptionPanel::OnMouseExit,NULL,this);
159 propertiesGridSizer -> Add(pApplicationlk, 0, wxEXPAND);
162 wxButton* pApplicationHlp = new wxButton(propertiesPanel, wxID_ANY, wxT("?"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
163 propertiesGridSizer -> Add(pApplicationHlp, 0, wxEXPAND | wxALIGN_CENTER);
166 propertiesGridSizer->AddGrowableCol(1,1);
168 propertiesPanel->SetSizer(propertiesGridSizer);
169 propertiesGridSizer->Fit(propertiesPanel);
171 propertiesBox->Add(propertiesPanel, 1, wxEXPAND | wxALL, 5);
172 sizer -> Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
175 wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Actions"));
176 actionsBox->GetStaticBox()->SetToolTip(wxT("Create a new application or make any change to the appli's CMakeLists.txt file by selecting the desired action."));
177 wxPanel* actionsPanel = new wxPanel(this);
178 wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
180 wxFlexGridSizer* actionsGridSizer = new wxFlexGridSizer(2, 2, 9, 15);
182 wxButton* createApplicationbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_APPLICATION, _T("A. Create Application"));
183 createApplicationbt->SetToolTip(wxT("Create a new application for this project."));
184 actionsGridSizer->Add(createApplicationbt, 1, wxALL | wxEXPAND, 5);
185 wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists File"));
186 editCMakebt->SetToolTip(wxT("Open the system default text editor to edit the CMakeLists.txt file."));
187 editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMAppliDescriptionPanel::OnCMakeMouseEnter,NULL,this);
188 editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMAppliDescriptionPanel::OnCMakeMouseExit,NULL,this);
189 actionsGridSizer->Add(editCMakebt, 1, wxALL | wxEXPAND, 5);
190 wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("Open Applications Folder"));
191 openFolderbt->SetToolTip(wxT("Open the appli folder in the file explorer."));
192 actionsGridSizer->Add(openFolderbt, 1, wxALL | wxEXPAND, 5);
194 actionsGridSizer->AddGrowableCol(0,1);
195 actionsGridSizer->AddGrowableCol(1,1);
197 actionsPanelSizer->Add(actionsGridSizer, 1, wxEXPAND, 0);
198 actionsPanel->SetSizer(actionsPanelSizer);
199 actionsPanelSizer->Fit(actionsPanel);
200 actionsBox->Add(actionsPanel, 0, wxALL | wxEXPAND, 5);
201 sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 10);
205 sizer->SetSizeHints(this);
207 if (((wxCDMMainFrame*)this->GetParent())->isHelp())
209 wxCDMAppliHelpDialog* helpDialog = new wxCDMAppliHelpDialog(this->GetParent(), this->appli, wxID_ANY);
210 helpDialog->Show(true);
214 void wxCDMAppliDescriptionPanel::OnBtnCreateApplication(wxCommandEvent& event)
217 wxTextEntryDialog* appDlg = new wxTextEntryDialog(
219 wxT("Enter the new application name (NO white spaces)"),
220 wxT("New Application - creaDevManager"),
225 if (appDlg->ShowModal() == wxID_OK)
227 std::string applicationName = crea::wx2std(appDlg->GetValue());
229 if(applicationName.size() > 0)
232 types.Add(wxT("Console Application"));
233 types.Add(wxT("GUI Application (wxWidgets)"));
234 int applicationType = wxGetSingleChoiceIndex(
235 wxT("Select the application type"),
236 wxT("New Application - creaDevManager"),
240 if (applicationType != -1)
244 modelCDMIProjectTreeNode* application = this->appli->CreateApplication(applicationName, applicationType ,result);
245 //check library created
246 if(application == NULL)
248 wxMessageBox(crea::std2wx(*result),_T("New Application - Error!"),wxOK | wxICON_ERROR);
252 wxMessageBox(crea::std2wx("Application successfully created."),_T("New Application - Success!"),wxOK | wxICON_INFORMATION);
254 //refreshing tree and description
255 //send event instead of calling parent to avoid crashing
257 ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
259 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
260 newEvent->SetClientData(application);
261 wxPostEvent(this->GetParent(), *newEvent);
267 wxMessageBox(crea::std2wx("Invalid application name, please try again with a valid name."),_T("New Application - Error!"),wxOK | wxICON_INFORMATION);
272 void wxCDMAppliDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
275 if(!this->appli->OpenCMakeListsFile(result))
276 wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
278 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
280 if(this->appli->GetCMakeLists() != NULL)
282 newEvent->SetClientData(this->appli->GetCMakeLists());
284 wxPostEvent(this->GetParent(), *newEvent);
288 void wxCDMAppliDescriptionPanel::OnChBApplicationChange(wxCommandEvent& event)
290 this->appli->SetApplicationInclude(
291 crea::wx2std(((wxCheckBox*)event.GetEventObject())->GetName()),
292 ((wxCheckBox*)event.GetEventObject())->GetValue()
296 void wxCDMAppliDescriptionPanel::OnLnkApplicationSelect(wxHyperlinkEvent& event)
298 modelCDMApplication* applicationFound = NULL;
299 std::vector<modelCDMApplication*> applications = this->appli->GetApplications();
300 for (int i = 0; i < (int)(applications.size()); i++)
302 if(applications[i]->GetName() == crea::wx2std(event.GetURL()))
304 applicationFound = applications[i];
308 wxCommandEvent* newEvent1 = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
309 newEvent1->SetClientData(applicationFound);
311 wxPostEvent(this->GetParent(), *newEvent1);
313 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
314 newEvent->SetClientData(applicationFound);
316 wxPostEvent(this->GetParent(), *newEvent);
319 void wxCDMAppliDescriptionPanel::OnBtnReturn(wxHyperlinkEvent& event)
321 std::vector<modelCDMIProjectTreeNode*> parents = this->appli->GetParents();
322 std::string parentURL = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
323 //std::cout << parentURL << std::endl;
324 for (int i = 0; i < (int)(parents.size()); i++)
326 if (parents[i]->GetPath() == parentURL)
328 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
329 newEvent->SetClientData(parents[i]);
331 wxPostEvent(this->GetParent(), *newEvent);
336 void wxCDMAppliDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
339 if(!this->appli->OpenInFileExplorer(result))
340 wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
343 void wxCDMAppliDescriptionPanel::OnMouseEnter(wxMouseEvent& event)
345 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
346 std::string AppName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
347 modelCDMApplication* theApp = NULL;
348 std::vector<modelCDMApplication*> applications = this->appli->GetApplications();
349 for (int i = 0; i < (int)(applications.size()); i++)
351 if(applications[i]->GetName() == AppName)
353 theApp = applications[i];
357 newEvent->SetClientData(theApp);
359 wxPostEvent(this->GetParent(), *newEvent);
363 void wxCDMAppliDescriptionPanel::OnMouseExit(wxMouseEvent& event)
365 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
366 std::string AppName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
367 modelCDMApplication* theApp = NULL;
368 std::vector<modelCDMApplication*> applications = this->appli->GetApplications();
369 for (int i = 0; i < (int)(applications.size()); i++)
371 if(applications[i]->GetName() == AppName)
373 theApp = applications[i];
377 newEvent->SetClientData(theApp);
379 wxPostEvent(this->GetParent(), *newEvent);
383 void wxCDMAppliDescriptionPanel::OnCMakeMouseEnter(wxMouseEvent& event)
385 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
387 if(this->appli->GetCMakeLists() != NULL)
389 newEvent->SetClientData(this->appli->GetCMakeLists());
391 wxPostEvent(this->GetParent(), *newEvent);
396 void wxCDMAppliDescriptionPanel::OnCMakeMouseExit(wxMouseEvent& event)
398 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
400 if(this->appli->GetCMakeLists() != NULL)
402 newEvent->SetClientData(this->appli->GetCMakeLists());
404 wxPostEvent(this->GetParent(), *newEvent);