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_BUTTON(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)
54 wxCDMPackageManagerPanel::wxCDMPackageManagerPanel(
56 modelCDMProject* project,
58 const wxString& caption,
64 wxCDMPackageManagerPanel::Create(parent, project, id, caption, pos, size, style);
67 wxCDMPackageManagerPanel::~wxCDMPackageManagerPanel()
71 bool wxCDMPackageManagerPanel::Create(
73 modelCDMProject* project,
75 const wxString& caption,
81 wxPanel::Create(parent, id, pos, size, style);
82 this->project = project;
87 void wxCDMPackageManagerPanel::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);
97 sizer->Add(new wxStaticText(this, -1, _("Package Management")),0, wxALIGN_CENTER, 0);
100 sizer->Add(new wxStaticBitmap(this, -1, wxBitmap(PkIcon64)),0, wxALIGN_CENTER, 0);
103 wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("A&vailable Packages"));
104 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."));
105 wxPanel* propertiesPanel = new wxPanel(this);
106 wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL);
108 std::vector<modelCDMPackage*> packages = this->project->GetPackages();
109 for (int i = 0; i < packages.size(); i++)
111 wxHyperlinkCtrl* pPackagelk = new wxHyperlinkCtrl(propertiesPanel,ID_LINK_SELECT_PACKAGE, crea::std2wx(packages[i]->GetName().c_str()), crea::std2wx(packages[i]->GetName().c_str()));
112 std::string tt = "Author: " + packages[i]->GetAuthors() + "\nDescription: " + packages[i]->GetDescription();
113 pPackagelk->SetToolTip(crea::std2wx(tt));
114 propertiesPanelSizer -> Add(pPackagelk, 0, wxALIGN_LEFT | wxALL, 5);
115 pPackagelk->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageManagerPanel::OnMouseEnter,NULL,this);
116 pPackagelk->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageManagerPanel::OnMouseExit,NULL,this);
119 propertiesPanel->SetSizer(propertiesPanelSizer);
120 propertiesPanelSizer->Fit(propertiesPanel);
121 propertiesBox->Add(propertiesPanel, 0, wxALL, 5);
123 sizer -> Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
126 wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions"));
127 wxPanel* actionsPanel = new wxPanel(this);
128 wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
130 wxButton* createPkgbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_PACKAGE, _T("Create Package"));
131 createPkgbt->SetToolTip(wxT("Create a new package for this project."));
132 actionsPanelSizer->Add(createPkgbt, 0, wxALL, 5);
133 wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists File"));
134 editCMakebt->SetToolTip(wxT("Edit the CMakeLists.txt file of this project."));
135 editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageManagerPanel::OnCMakeMouseEnter,NULL,this);
136 editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageManagerPanel::OnCMakeMouseExit,NULL,this);
137 actionsPanelSizer->Add(editCMakebt, 0, wxALL, 5);
139 actionsPanel->SetSizer(actionsPanelSizer);
140 actionsPanelSizer->Fit(actionsPanel);
141 actionsBox->Add(actionsPanel, 0, wxEXPAND);
142 sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 10);
146 sizer->SetSizeHints(this);
148 if (((wxCDMMainFrame*)this->GetParent())->isHelp())
150 wxCDMPackageManagerHelpDialog* helpDialog = new wxCDMPackageManagerHelpDialog(this->GetParent(), this, wxID_ANY);
151 helpDialog->Show(true);
155 modelCDMProject* wxCDMPackageManagerPanel::GetProject() const
157 return this->project;
160 void wxCDMPackageManagerPanel::OnBtnReturn(wxCommandEvent& event)
162 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
163 newEvent->SetInt(project->GetId());
165 wxPostEvent(this->GetParent(), *newEvent);
168 void wxCDMPackageManagerPanel::OnLnkPackageSelect(wxHyperlinkEvent& event)
171 std::vector<modelCDMPackage*> packages = this->project->GetPackages();
172 for (int i = 0; i < packages.size(); i++)
174 if(packages[i]->GetName() == crea::wx2std(event.GetURL()))
176 packageId = packages[i]->GetId();
181 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
182 newEvent->SetInt(packageId);
184 wxPostEvent(this->GetParent(), *newEvent);
186 wxCommandEvent* newEvent1 = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
187 newEvent1->SetInt(packageId);
189 wxPostEvent(this->GetParent(), *newEvent1);
193 void wxCDMPackageManagerPanel::OnBtnCreatePackage(wxCommandEvent& event)
197 wxCDMNewPackageDialog* dialog = new wxCDMNewPackageDialog(this);
199 userResponse = dialog->ShowModal();
201 if(userResponse == wxID_FORWARD)
203 modelCDMIProjectTreeNode* package = this->project->CreatePackage(
204 crea::wx2std(dialog->GetPackageName()),
206 crea::wx2std(dialog->GetPackageAuthor()),
207 crea::wx2std(dialog->GetPackageAuthorEmail()),
208 crea::wx2std(dialog->GetPackageDescription())
212 std::cout << "error creating package: " << *result << std::endl;
213 wxMessageBox(crea::std2wx(*result),_T("New Package - Error!"),wxOK | wxICON_ERROR);
217 wxMessageBox(crea::std2wx("Package successfully created."),_T("New Package - Success!"),wxOK | wxICON_INFORMATION);
219 //refreshing tree and description
220 //send event instead of calling parent to avoid crashing
222 ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
224 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
225 newEvent->SetInt(package->GetId());
227 wxPostEvent(this->GetParent(), *newEvent);
234 void wxCDMPackageManagerPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
237 if(!this->project->OpenCMakeListsFile(result))
238 wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
240 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
242 if(this->project->GetCMakeLists() != NULL)
244 int CMId = this->project->GetCMakeLists()->GetId();
245 newEvent->SetInt(CMId);
247 wxPostEvent(this->GetParent(), *newEvent);
251 void wxCDMPackageManagerPanel::OnMouseEnter(wxMouseEvent& event)
253 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
254 std::string PkgName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
256 std::vector<modelCDMPackage*> packages = this->project->GetPackages();
257 for (int i = 0; i < packages.size(); i++)
259 if(packages[i]->GetName() == PkgName)
261 pkgId = packages[i]->GetId();
265 newEvent->SetInt(pkgId);
267 wxPostEvent(this->GetParent(), *newEvent);
271 void wxCDMPackageManagerPanel::OnMouseExit(wxMouseEvent& event)
273 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
274 std::string PkgName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
276 std::vector<modelCDMPackage*> packages = this->project->GetPackages();
277 project->GetPackages();
278 for (int i = 0; i < packages.size(); i++)
280 if(packages[i]->GetName() == PkgName)
282 pkgId = packages[i]->GetId();
286 newEvent->SetInt(pkgId);
288 wxPostEvent(this->GetParent(), *newEvent);
292 void wxCDMPackageManagerPanel::OnCMakeMouseEnter(wxMouseEvent& event)
294 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
296 if(this->project->GetCMakeLists() != NULL)
298 int CMId = this->project->GetCMakeLists()->GetId();
299 newEvent->SetInt(CMId);
301 wxPostEvent(this->GetParent(), *newEvent);
306 void wxCDMPackageManagerPanel::OnCMakeMouseExit(wxMouseEvent& event)
308 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
310 if(this->project->GetCMakeLists() != NULL)
312 int CMId = this->project->GetCMakeLists()->GetId();
313 newEvent->SetInt(CMId);
315 wxPostEvent(this->GetParent(), *newEvent);