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);
85 // this part makes the scrollbars show up
86 this->FitInside(); // ask the sizer about the needed size
87 this->SetScrollRate(5, 5);
91 void wxCDMAppliDescriptionPanel::CreateControls()
93 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
96 wxBoxSizer *linksSizer = new wxBoxSizer(wxHORIZONTAL);
97 std::vector<modelCDMIProjectTreeNode*> parents = this->appli->GetParents();
98 for (int i = 0; i < (int)(parents.size()); i++)
100 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);
101 returnLnk->SetWindowStyle(wxNO_BORDER);
102 returnLnk->SetToolTip(crea::std2wx("Return to " + parents[parents.size()-1-i]->GetName() + "."));
103 linksSizer->Add(returnLnk, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 5);
104 linksSizer->Add(new wxStaticText(this,wxID_ANY, wxT("/")), 0, wxALIGN_CENTER, 0);
106 linksSizer->Add(new wxStaticText(this, wxID_ANY, crea::std2wx(this->appli->GetName())), 0, wxALIGN_CENTER, 0);
108 sizer->Add(linksSizer, 0, wxALIGN_CENTER | wxALL, 5);
111 wxBoxSizer* headerSizer = new wxBoxSizer(wxHORIZONTAL);
114 headerSizer->Add(new wxStaticBitmap(this, -1, wxBitmap(ApIcon64)),0, wxALIGN_CENTER, 0);
115 wxBoxSizer* textSizer = new wxBoxSizer(wxVERTICAL);
117 textSizer->Add(new wxStaticText(this, -1, _("Application Management")),0, wxALIGN_LEFT, 0);
119 headerSizer->Add(textSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
121 sizer->Add(headerSizer, 0, wxALIGN_CENTER);
124 wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("A&vailable Applications"));
125 propertiesBox->GetStaticBox()->SetToolTip(wxT("Select any of the available applications to see its details or the modify them."));
126 wxPanel* propertiesPanel = new wxPanel(this);
128 std::vector<modelCDMApplication*> applications = this->appli->GetApplications();
129 wxFlexGridSizer* propertiesGridSizer = new wxFlexGridSizer(applications.size()+1, 3, 9, 5);
131 wxStaticText* ChBTitle = new wxStaticText(propertiesPanel, wxID_ANY, wxT("Include in\nCMake"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE_HORIZONTAL);
132 wxStaticText* LkTitle = new wxStaticText(propertiesPanel, wxID_ANY, wxT("Application Name"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE_HORIZONTAL);
133 wxStaticText* HlpTitle = new wxStaticText(propertiesPanel, wxID_ANY, wxT("Help"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE_HORIZONTAL);
135 propertiesGridSizer -> Add(ChBTitle, 0, wxEXPAND | wxALL, 5);
136 propertiesGridSizer -> Add(LkTitle, 0, wxEXPAND | wxALL, 5);
137 propertiesGridSizer -> Add(HlpTitle, 0, wxEXPAND | wxALL, 5);
139 for (int i = 0; i < (int)(applications.size()); i++)
141 //checkbox for cmake inclusion
142 wxCheckBox* pApplicationChB = new wxCheckBox(propertiesPanel, ID_CHECK_INCLUDE_APPLICATION, wxT(""), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
143 pApplicationChB->SetName(crea::std2wx(applications[i]->GetName()));
144 std::string tt = "if this box is checked the the " + applications[i]->GetName() + " application is included in the project compilation.";
145 pApplicationChB->SetToolTip(crea::std2wx(tt));
146 pApplicationChB->SetValue(this->appli->IsApplicationIncluded(applications[i]->GetName()));
147 propertiesGridSizer -> Add(pApplicationChB, 0, wxEXPAND | wxALIGN_CENTER);
149 //link to library with description
150 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);
151 pApplicationlk->SetWindowStyle(wxALIGN_LEFT | wxNO_BORDER);
152 tt = "Name: " + applications[i]->GetName() + "\n";
153 tt += "Location: " + applications[i]->GetPath();
154 pApplicationlk->SetToolTip(crea::std2wx(tt));
155 pApplicationlk->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMAppliDescriptionPanel::OnMouseEnter,NULL,this);
156 pApplicationlk->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMAppliDescriptionPanel::OnMouseExit,NULL,this);
157 propertiesGridSizer -> Add(pApplicationlk, 0, wxEXPAND);
160 wxButton* pApplicationHlp = new wxButton(propertiesPanel, wxID_ANY, wxT("?"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
161 pApplicationHlp->Enable(false);
162 tt = "When this application is included in the CMakeLists file, the\nfollowing line is included in the CMakeList.txt file in the\nappli folder:\n"
163 "ADD_SUBDIRECTORY(" + applications[i]->GetName() + ")";
164 pApplicationHlp->SetToolTip(crea::std2wx(tt));
166 propertiesGridSizer -> Add(pApplicationHlp, 0, wxEXPAND | wxALIGN_CENTER);
169 propertiesGridSizer->AddGrowableCol(1,1);
171 propertiesPanel->SetSizer(propertiesGridSizer);
172 propertiesGridSizer->Fit(propertiesPanel);
174 propertiesBox->Add(propertiesPanel, 1, wxEXPAND | wxALL, 5);
175 sizer -> Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
178 wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Actions"));
179 actionsBox->GetStaticBox()->SetToolTip(wxT("Create a new application or make any change to the appli's CMakeLists.txt file by selecting the desired action."));
180 wxPanel* actionsPanel = new wxPanel(this);
181 wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
183 wxFlexGridSizer* actionsGridSizer = new wxFlexGridSizer(2, 2, 9, 15);
185 wxButton* createApplicationbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_APPLICATION, _T("A. Create Application"));
186 createApplicationbt->SetToolTip(wxT("Create a new application for this project."));
187 actionsGridSizer->Add(createApplicationbt, 1, wxALL | wxEXPAND, 5);
188 wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists File"));
189 editCMakebt->SetToolTip(wxT("Open the system default text editor to edit the CMakeLists.txt file."));
190 editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMAppliDescriptionPanel::OnCMakeMouseEnter,NULL,this);
191 editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMAppliDescriptionPanel::OnCMakeMouseExit,NULL,this);
192 actionsGridSizer->Add(editCMakebt, 1, wxALL | wxEXPAND, 5);
193 wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("Open Applications Folder"));
194 openFolderbt->SetToolTip(wxT("Open the appli folder in the file explorer."));
195 actionsGridSizer->Add(openFolderbt, 1, wxALL | wxEXPAND, 5);
197 actionsGridSizer->AddGrowableCol(0,1);
198 actionsGridSizer->AddGrowableCol(1,1);
200 actionsPanelSizer->Add(actionsGridSizer, 1, wxEXPAND, 0);
201 actionsPanel->SetSizer(actionsPanelSizer);
202 actionsPanelSizer->Fit(actionsPanel);
203 actionsBox->Add(actionsPanel, 0, wxALL | wxEXPAND, 5);
204 sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 10);
208 sizer->SetSizeHints(this);
210 if (((wxCDMMainFrame*)this->GetParent())->isHelp())
212 wxCDMAppliHelpDialog* helpDialog = new wxCDMAppliHelpDialog(this->GetParent(), this->appli, wxID_ANY);
213 helpDialog->Show(true);
217 void wxCDMAppliDescriptionPanel::OnBtnCreateApplication(wxCommandEvent& event)
220 wxTextEntryDialog* appDlg = new wxTextEntryDialog(
222 wxT("Enter the new application name (NO white spaces)"),
223 wxT("New Application - creaDevManager"),
228 if (appDlg->ShowModal() == wxID_OK)
230 std::string applicationName = crea::wx2std(appDlg->GetValue());
232 if(applicationName.size() > 0)
235 types.Add(wxT("Console Application"));
236 types.Add(wxT("GUI Application (wxWidgets)"));
237 int applicationType = wxGetSingleChoiceIndex(
238 wxT("Select the application type"),
239 wxT("New Application - creaDevManager"),
243 if (applicationType != -1)
247 modelCDMIProjectTreeNode* application = this->appli->CreateApplication(applicationName, applicationType ,result);
248 //check library created
249 if(application == NULL)
251 wxMessageBox(crea::std2wx(*result),_T("New Application - Error!"),wxOK | wxICON_ERROR);
255 wxMessageBox(crea::std2wx("Application successfully created."),_T("New Application - Success!"),wxOK | wxICON_INFORMATION);
257 //refreshing tree and description
258 //send event instead of calling parent to avoid crashing
260 ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
262 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
263 newEvent->SetClientData(application);
264 wxPostEvent(this->GetParent(), *newEvent);
270 wxMessageBox(crea::std2wx("Invalid application name, please try again with a valid name."),_T("New Application - Error!"),wxOK | wxICON_INFORMATION);
275 void wxCDMAppliDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
278 if(!this->appli->OpenCMakeListsFile(result))
279 wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
281 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
283 if(this->appli->GetCMakeLists() != NULL)
285 newEvent->SetClientData(this->appli->GetCMakeLists());
287 wxPostEvent(this->GetParent(), *newEvent);
291 void wxCDMAppliDescriptionPanel::OnChBApplicationChange(wxCommandEvent& event)
293 this->appli->SetApplicationInclude(
294 crea::wx2std(((wxCheckBox*)event.GetEventObject())->GetName()),
295 ((wxCheckBox*)event.GetEventObject())->GetValue()
299 void wxCDMAppliDescriptionPanel::OnLnkApplicationSelect(wxHyperlinkEvent& event)
301 modelCDMApplication* applicationFound = NULL;
302 std::vector<modelCDMApplication*> applications = this->appli->GetApplications();
303 for (int i = 0; i < (int)(applications.size()); i++)
305 if(applications[i]->GetName() == crea::wx2std(event.GetURL()))
307 applicationFound = applications[i];
311 wxCommandEvent* newEvent1 = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
312 newEvent1->SetClientData(applicationFound);
314 wxPostEvent(this->GetParent(), *newEvent1);
316 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
317 newEvent->SetClientData(applicationFound);
319 wxPostEvent(this->GetParent(), *newEvent);
322 void wxCDMAppliDescriptionPanel::OnBtnReturn(wxHyperlinkEvent& event)
324 std::vector<modelCDMIProjectTreeNode*> parents = this->appli->GetParents();
325 std::string parentURL = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
326 //std::cout << parentURL << std::endl;
327 for (int i = 0; i < (int)(parents.size()); i++)
329 if (parents[i]->GetPath() == parentURL)
331 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
332 newEvent->SetClientData(parents[i]);
334 wxPostEvent(this->GetParent(), *newEvent);
339 void wxCDMAppliDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
342 if(!this->appli->OpenInFileExplorer(result))
343 wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
346 void wxCDMAppliDescriptionPanel::OnMouseEnter(wxMouseEvent& event)
348 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
349 std::string AppName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
350 modelCDMApplication* theApp = NULL;
351 std::vector<modelCDMApplication*> applications = this->appli->GetApplications();
352 for (int i = 0; i < (int)(applications.size()); i++)
354 if(applications[i]->GetName() == AppName)
356 theApp = applications[i];
360 newEvent->SetClientData(theApp);
362 wxPostEvent(this->GetParent(), *newEvent);
366 void wxCDMAppliDescriptionPanel::OnMouseExit(wxMouseEvent& event)
368 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
369 std::string AppName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
370 modelCDMApplication* theApp = NULL;
371 std::vector<modelCDMApplication*> applications = this->appli->GetApplications();
372 for (int i = 0; i < (int)(applications.size()); i++)
374 if(applications[i]->GetName() == AppName)
376 theApp = applications[i];
380 newEvent->SetClientData(theApp);
382 wxPostEvent(this->GetParent(), *newEvent);
386 void wxCDMAppliDescriptionPanel::OnCMakeMouseEnter(wxMouseEvent& event)
388 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
390 if(this->appli->GetCMakeLists() != NULL)
392 newEvent->SetClientData(this->appli->GetCMakeLists());
394 wxPostEvent(this->GetParent(), *newEvent);
399 void wxCDMAppliDescriptionPanel::OnCMakeMouseExit(wxMouseEvent& event)
401 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
403 if(this->appli->GetCMakeLists() != NULL)
405 newEvent->SetClientData(this->appli->GetCMakeLists());
407 wxPostEvent(this->GetParent(), *newEvent);