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 * wxCDMPackageManagerPanel.cpp
31 * Created on: Dec 10, 2012
32 * Author: Daniel Felipe Gonzalez Obando
35 #include "wxCDMPackageManagerPanel.h"
37 #include "wxCDMMainFrame.h"
38 #include "wxCDMNewPackageDialog.h"
40 #include "wxCDMPackageManagerHelpDialog.h"
42 #include "creaDevManagerIds.h"
43 #include "images/PkIcon64.xpm"
45 BEGIN_EVENT_TABLE(wxCDMPackageManagerPanel, wxPanel)
46 EVT_HYPERLINK(ID_BUTTON_PREV, wxCDMPackageManagerPanel::OnBtnReturn)
47 EVT_HYPERLINK(ID_LINK_SELECT_PACKAGE, wxCDMPackageManagerPanel::OnLnkPackageSelect)
48 EVT_BUTTON(ID_BUTTON_CREATE_PACKAGE, wxCDMPackageManagerPanel::OnBtnCreatePackage)
49 EVT_COMMAND(wxID_ANY, wxEVT_COMMAND_TOOL_CLICKED, wxCDMPackageManagerPanel::OnBtnCreatePackage)
50 EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMPackageManagerPanel::OnBtnEditCMakeLists)
51 EVT_COMMAND(wxID_ANY, wxEVT_COMMAND_TOOL_ENTER, wxCDMPackageManagerPanel::OnBtnEditCMakeLists)
52 EVT_CHECKBOX(ID_CHECK_INCLUDE_PACKAGE, wxCDMPackageManagerPanel::OnChBPackageChange)
55 wxCDMPackageManagerPanel::wxCDMPackageManagerPanel(
57 modelCDMProject* project,
59 const wxString& caption,
65 wxCDMPackageManagerPanel::Create(parent, project, id, caption, pos, size, style);
68 wxCDMPackageManagerPanel::~wxCDMPackageManagerPanel()
72 bool wxCDMPackageManagerPanel::Create(
74 modelCDMProject* project,
76 const wxString& caption,
82 wxPanel::Create(parent, id, pos, size, style);
83 this->project = project;
88 void wxCDMPackageManagerPanel::CreateControls()
90 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
93 wxHyperlinkCtrl* returnLnk = new wxHyperlinkCtrl(this, ID_BUTTON_PREV, crea::std2wx(this->project->GetName()), crea::std2wx(this->project->GetPath()), wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE);
94 returnLnk->SetWindowStyle(wxNO_BORDER);
95 returnLnk->SetToolTip(wxT("Return to the active project description."));
96 sizer->Add(returnLnk, 0, wxALIGN_CENTER | wxALL, 5);
99 wxBoxSizer* headerSizer = new wxBoxSizer(wxHORIZONTAL);
102 headerSizer->Add(new wxStaticBitmap(this, -1, wxBitmap(PkIcon64)),0, wxALIGN_CENTER, 0);
103 wxBoxSizer* textSizer = new wxBoxSizer(wxVERTICAL);
105 textSizer->Add(new wxStaticText(this, -1, _("Package Management")),0, wxALIGN_LEFT, 0);
107 headerSizer->Add(textSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
109 sizer->Add(headerSizer, 0, wxALIGN_CENTER);
112 wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("A&vailable Packages"));
113 propertiesBox->GetStaticBox()->SetToolTip(wxT("Select any of the available packages to see its details or modify them. Remember that black boxes are created inside packages, any of these packages is available."));
114 wxPanel* propertiesPanel = new wxPanel(this);
116 std::vector<modelCDMPackage*> packages = this->project->GetPackages();
117 wxFlexGridSizer* propertiesGridSizer = new wxFlexGridSizer(packages.size()+1, 3, 9, 5);
119 wxStaticText* ChBTitle = new wxStaticText(propertiesPanel, wxID_ANY, wxT("Include in\nCMake"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE_HORIZONTAL);
120 wxStaticText* LkTitle = new wxStaticText(propertiesPanel, wxID_ANY, wxT("Package Name"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE_HORIZONTAL);
121 wxStaticText* HlpTitle = new wxStaticText(propertiesPanel, wxID_ANY, wxT("Help"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE_HORIZONTAL);
123 propertiesGridSizer -> Add(ChBTitle, 0, wxEXPAND | wxALL, 5);
124 propertiesGridSizer -> Add(LkTitle, 0, wxEXPAND | wxALL, 5);
125 propertiesGridSizer -> Add(HlpTitle, 0, wxEXPAND | wxALL, 5);
127 for (int i = 0; i < (int)(packages.size()); i++)
129 //checkbox for cmake inclusion
130 wxCheckBox* pPackageChB = new wxCheckBox(propertiesPanel, ID_CHECK_INCLUDE_PACKAGE, wxT(""), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
131 pPackageChB->SetName(crea::std2wx(packages[i]->GetName()));
132 std::string tt = "if this box is checked the the " + packages[i]->GetName() + " package is included in the project compilation.";
133 pPackageChB->SetToolTip(crea::std2wx(tt));
134 pPackageChB->SetValue(this->project->IsPackageIncluded(packages[i]->GetName()));
135 propertiesGridSizer -> Add(pPackageChB, 0, wxEXPAND | wxALIGN_CENTER);
137 //link to package with description
138 wxHyperlinkCtrl* pPackagelk = new wxHyperlinkCtrl(propertiesPanel, ID_LINK_SELECT_PACKAGE, crea::std2wx(packages[i]->GetName().c_str()), crea::std2wx(packages[i]->GetName().c_str()), wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE);
139 pPackagelk->SetWindowStyle(wxALIGN_LEFT | wxNO_BORDER);
140 tt = "Name: " + packages[i]->GetName() + "\n";
141 tt += "Location: " + packages[i]->GetPath();
142 pPackagelk->SetToolTip(crea::std2wx(tt));
143 pPackagelk->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageManagerPanel::OnMouseEnter,NULL,this);
144 pPackagelk->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageManagerPanel::OnMouseExit,NULL,this);
145 propertiesGridSizer -> Add(pPackagelk, 0, wxEXPAND);
148 wxButton* pPackageHlp = new wxButton(propertiesPanel, wxID_ANY, wxT("?"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
149 propertiesGridSizer -> Add(pPackageHlp, 0, wxEXPAND | wxALIGN_CENTER);
152 propertiesGridSizer->AddGrowableCol(1,1);
154 propertiesPanel->SetSizer(propertiesGridSizer);
155 propertiesGridSizer->Fit(propertiesPanel);
158 propertiesBox->Add(propertiesPanel, 1, wxALL | wxEXPAND, 5);
160 sizer -> Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
163 wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions"));
164 wxPanel* actionsPanel = new wxPanel(this);
165 wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
168 wxFlexGridSizer* actionsGridSizer = new wxFlexGridSizer(1, 2, 9, 15);
170 wxButton* createPkgbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_PACKAGE, _T("A. Create Package"));
171 createPkgbt->SetToolTip(wxT("Create a new package for this project."));
172 actionsGridSizer->Add(createPkgbt, 1, wxALL | wxEXPAND, 5);
173 wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("B. Edit CMakeLists File"));
174 editCMakebt->SetToolTip(wxT("Edit the CMakeLists.txt file of this project."));
175 editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageManagerPanel::OnCMakeMouseEnter,NULL,this);
176 editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageManagerPanel::OnCMakeMouseExit,NULL,this);
177 actionsGridSizer->Add(editCMakebt, 1, wxALL | wxEXPAND, 5);
179 actionsGridSizer->AddGrowableCol(0,1);
180 actionsGridSizer->AddGrowableCol(1,1);
182 actionsPanelSizer->Add(actionsGridSizer, 1, wxEXPAND, 0);
183 actionsPanel->SetSizer(actionsPanelSizer);
184 actionsPanelSizer->Fit(actionsPanel);
185 actionsBox->Add(actionsPanel, 1, wxEXPAND);
186 sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 10);
190 sizer->SetSizeHints(this);
192 if (((wxCDMMainFrame*)this->GetParent())->isHelp())
194 wxCDMPackageManagerHelpDialog* helpDialog = new wxCDMPackageManagerHelpDialog(this->GetParent(), this, wxID_ANY);
195 helpDialog->Show(true);
199 modelCDMProject* wxCDMPackageManagerPanel::GetProject() const
201 return this->project;
204 void wxCDMPackageManagerPanel::OnBtnReturn(wxHyperlinkEvent& event)
206 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
207 newEvent->SetClientData(project);
209 wxPostEvent(this->GetParent(), *newEvent);
212 void wxCDMPackageManagerPanel::OnChBPackageChange(wxCommandEvent& event)
214 this->project->SetPackageInclude(
215 crea::wx2std(((wxCheckBox*)event.GetEventObject())->GetName()),
216 ((wxCheckBox*)event.GetEventObject())->GetValue()
220 void wxCDMPackageManagerPanel::OnLnkPackageSelect(wxHyperlinkEvent& event)
222 modelCDMPackage* thePackage = NULL;
223 std::vector<modelCDMPackage*> packages = this->project->GetPackages();
224 for (int i = 0; i < (int)(packages.size()); i++)
226 if(packages[i]->GetName() == crea::wx2std(event.GetURL()))
228 thePackage = packages[i];
233 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
234 newEvent->SetClientData(thePackage);
236 wxPostEvent(this->GetParent(), *newEvent);
238 wxCommandEvent* newEvent1 = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
239 newEvent1->SetClientData(thePackage);
241 wxPostEvent(this->GetParent(), *newEvent1);
245 void wxCDMPackageManagerPanel::OnBtnCreatePackage(wxCommandEvent& event)
249 wxCDMNewPackageDialog* dialog = new wxCDMNewPackageDialog(this);
251 userResponse = dialog->ShowModal();
253 if(userResponse == wxID_FORWARD)
255 modelCDMIProjectTreeNode* package = this->project->CreatePackage(
256 crea::wx2std(dialog->GetPackageName()),
258 crea::wx2std(dialog->GetPackageAuthor()),
259 crea::wx2std(dialog->GetPackageAuthorEmail()),
260 crea::wx2std(dialog->GetPackageDescription())
264 std::cout << "error creating package: " << *result << std::endl;
265 wxMessageBox(crea::std2wx(*result),_T("New Package - Error!"),wxOK | wxICON_ERROR);
269 wxMessageBox(crea::std2wx("Package successfully created."),_T("New Package - Success!"),wxOK | wxICON_INFORMATION);
271 //refreshing tree and description
272 //send event instead of calling parent to avoid crashing
274 ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
276 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
277 newEvent->SetClientData(package);
279 wxPostEvent(this->GetParent(), *newEvent);
286 void wxCDMPackageManagerPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
289 if(!this->project->OpenCMakeListsFile(result))
290 wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
292 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
294 if(this->project->GetCMakeLists() != NULL)
296 newEvent->SetClientData(this->project->GetCMakeLists());
298 wxPostEvent(this->GetParent(), *newEvent);
302 void wxCDMPackageManagerPanel::OnMouseEnter(wxMouseEvent& event)
304 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
305 std::string PkgName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
306 modelCDMPackage* thePackage = NULL;
307 std::vector<modelCDMPackage*> packages = this->project->GetPackages();
308 for (int i = 0; i < (int)(packages.size()); i++)
310 if(packages[i]->GetName() == PkgName)
312 thePackage = packages[i];
316 newEvent->SetClientData(thePackage);
318 wxPostEvent(this->GetParent(), *newEvent);
322 void wxCDMPackageManagerPanel::OnMouseExit(wxMouseEvent& event)
324 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
325 std::string PkgName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
326 modelCDMPackage* thePackage = NULL;
327 std::vector<modelCDMPackage*> packages = this->project->GetPackages();
328 project->GetPackages();
329 for (int i = 0; i < (int)(packages.size()); i++)
331 if(packages[i]->GetName() == PkgName)
333 thePackage = packages[i];
337 newEvent->SetClientData(thePackage);
339 wxPostEvent(this->GetParent(), *newEvent);
343 void wxCDMPackageManagerPanel::OnCMakeMouseEnter(wxMouseEvent& event)
345 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
347 if(this->project->GetCMakeLists() != NULL)
349 newEvent->SetClientData(this->project->GetCMakeLists());
351 wxPostEvent(this->GetParent(), *newEvent);
356 void wxCDMPackageManagerPanel::OnCMakeMouseExit(wxMouseEvent& event)
358 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
360 if(this->project->GetCMakeLists() != NULL)
362 newEvent->SetClientData(this->project->GetCMakeLists());
364 wxPostEvent(this->GetParent(), *newEvent);