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 "creaDevManagerIds.h"
41 #include "images/PkIcon64.xpm"
43 BEGIN_EVENT_TABLE(wxCDMPackageManagerPanel, wxPanel)
44 EVT_BUTTON(ID_BUTTON_PREV, wxCDMPackageManagerPanel::OnBtnReturn)
45 EVT_HYPERLINK(ID_LINK_SELECT_PACKAGE, wxCDMPackageManagerPanel::OnLnkPackageSelect)
46 EVT_BUTTON(ID_BUTTON_CREATE_PACKAGE, wxCDMPackageManagerPanel::OnBtnCreatePackage)
47 EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMPackageManagerPanel::OnBtnEditCMakeLists)
50 wxCDMPackageManagerPanel::wxCDMPackageManagerPanel(
52 modelCDMProject* project,
54 const wxString& caption,
60 wxCDMPackageManagerPanel::Create(parent, project, id, caption, pos, size, style);
63 wxCDMPackageManagerPanel::~wxCDMPackageManagerPanel()
67 bool wxCDMPackageManagerPanel::Create(
69 modelCDMProject* project,
71 const wxString& caption,
77 wxPanel::Create(parent, id, pos, size, style);
78 this->project = project;
83 void wxCDMPackageManagerPanel::CreateControls()
85 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
88 wxButton* returnbt = new wxButton(this, ID_BUTTON_PREV, wxT("Return to project"));
89 returnbt->SetToolTip(wxT("Return to the active project description."));
90 sizer->Add(returnbt, 0, wxALIGN_CENTER | wxALL, 5);
93 sizer->Add(new wxStaticText(this, -1, _("Package Management")),0, wxALIGN_CENTER, 0);
96 sizer->Add(new wxStaticBitmap(this, -1, wxBitmap(PkIcon64)),0, wxALIGN_CENTER, 0);
99 wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("A&vailable Packages"));
100 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."));
101 wxPanel* propertiesPanel = new wxPanel(this);
102 wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL);
104 std::vector<modelCDMPackage*> packages = this->project->GetPackages();
105 for (int i = 0; i < packages.size(); i++)
107 wxHyperlinkCtrl* pPackagelk = new wxHyperlinkCtrl(propertiesPanel,ID_LINK_SELECT_PACKAGE, crea::std2wx(packages[i]->GetName().c_str()), crea::std2wx(packages[i]->GetName().c_str()));
108 std::string tt = "Author: " + packages[i]->GetAuthors() + "\nDescription: " + packages[i]->GetDescription();
109 pPackagelk->SetToolTip(crea::std2wx(tt));
110 propertiesPanelSizer -> Add(pPackagelk, 0, wxALIGN_LEFT | wxALL, 5);
113 propertiesPanel->SetSizer(propertiesPanelSizer);
114 propertiesPanelSizer->Fit(propertiesPanel);
115 propertiesBox->Add(propertiesPanel, 0, wxALL, 5);
117 sizer -> Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
120 wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions"));
121 wxPanel* actionsPanel = new wxPanel(this);
122 wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
124 wxButton* createPkgbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_PACKAGE, _T("Create Package"));
125 createPkgbt->SetToolTip(wxT("Create a new package for this project."));
126 actionsPanelSizer->Add(createPkgbt, 0, wxALL, 5);
127 wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists File"));
128 editCMakebt->SetToolTip(wxT("Edit the CMakeLists.txt file of this project."));
129 actionsPanelSizer->Add(editCMakebt, 0, wxALL, 5);
131 actionsPanel->SetSizer(actionsPanelSizer);
132 actionsPanelSizer->Fit(actionsPanel);
133 actionsBox->Add(actionsPanel, 0, wxEXPAND);
134 sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 10);
138 sizer->SetSizeHints(this);
141 void wxCDMPackageManagerPanel::OnBtnReturn(wxCommandEvent& event)
143 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
144 newEvent->SetInt(project->GetId());
146 wxPostEvent(this->GetParent(), *newEvent);
149 void wxCDMPackageManagerPanel::OnLnkPackageSelect(wxHyperlinkEvent& event)
152 std::vector<modelCDMPackage*> packages = this->project->GetPackages();
153 for (int i = 0; i < packages.size(); i++)
155 if(packages[i]->GetName() == crea::wx2std(event.GetURL()))
157 packageId = packages[i]->GetId();
162 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
163 newEvent->SetInt(packageId);
165 wxPostEvent(this->GetParent(), *newEvent);
169 void wxCDMPackageManagerPanel::OnBtnCreatePackage(wxCommandEvent& event)
173 wxCDMNewPackageDialog* dialog = new wxCDMNewPackageDialog(this);
175 userResponse = dialog->ShowModal();
177 if(userResponse == wxID_FORWARD)
179 modelCDMIProjectTreeNode* package = this->project->CreatePackage(
180 crea::wx2std(dialog->GetPackageName()),
182 crea::wx2std(dialog->GetPackageAuthor()),
183 crea::wx2std(dialog->GetPackageAuthorEmail()),
184 crea::wx2std(dialog->GetPackageDescription())
188 std::cout << "error creating package: " << *result << std::endl;
189 wxMessageBox(crea::std2wx(*result),_T("New Package - Error!"),wxOK | wxICON_ERROR);
193 wxMessageBox(crea::std2wx("Package successfully created."),_T("New Package - Success!"),wxOK | wxICON_INFORMATION);
195 //refreshing tree and description
196 //send event instead of calling parent to avoid crashing
198 ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
200 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
201 newEvent->SetInt(package->GetId());
203 wxPostEvent(this->GetParent(), *newEvent);
210 void wxCDMPackageManagerPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
212 //TODO: implement method
213 std::cerr << "Event OnBtnCreatePackage not implemented" << std::endl;