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)
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 wxHyperlinkCtrl* returnLnk = new wxHyperlinkCtrl(this, ID_BUTTON_PREV, crea::std2wx(this->project->GetName()), crea::std2wx(this->project->GetPath()));
93 returnLnk->SetToolTip(wxT("Return to the active project description."));
94 sizer->Add(returnLnk, 0, wxALIGN_CENTER | wxALL, 5);
97 wxBoxSizer* headerSizer = new wxBoxSizer(wxHORIZONTAL);
100 headerSizer->Add(new wxStaticBitmap(this, -1, wxBitmap(PkIcon64)),0, wxALIGN_CENTER, 0);
101 wxBoxSizer* textSizer = new wxBoxSizer(wxVERTICAL);
103 textSizer->Add(new wxStaticText(this, -1, _("Package Management")),0, wxALIGN_LEFT, 0);
105 headerSizer->Add(textSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
107 sizer->Add(headerSizer, 0, wxALIGN_CENTER);
110 wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("A&vailable Packages"));
111 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."));
112 wxPanel* propertiesPanel = new wxPanel(this);
113 wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL);
115 std::vector<modelCDMPackage*> packages = this->project->GetPackages();
116 for (int i = 0; i < packages.size(); i++)
118 wxHyperlinkCtrl* pPackagelk = new wxHyperlinkCtrl(propertiesPanel,ID_LINK_SELECT_PACKAGE, crea::std2wx(packages[i]->GetName().c_str()), crea::std2wx(packages[i]->GetName().c_str()));
119 pPackagelk->SetWindowStyle(wxALIGN_LEFT);
120 std::string tt = "Author: " + packages[i]->GetAuthors() + "\nDescription: " + packages[i]->GetDescription();
121 pPackagelk->SetToolTip(crea::std2wx(tt));
122 propertiesPanelSizer -> Add(pPackagelk, 0, wxEXPAND | wxALL, 5);
123 pPackagelk->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageManagerPanel::OnMouseEnter,NULL,this);
124 pPackagelk->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageManagerPanel::OnMouseExit,NULL,this);
127 propertiesPanel->SetSizer(propertiesPanelSizer);
128 propertiesPanelSizer->Fit(propertiesPanel);
129 propertiesBox->Add(propertiesPanel, 1, wxALL | wxEXPAND, 5);
131 sizer -> Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
134 wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions"));
135 wxPanel* actionsPanel = new wxPanel(this);
136 wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
139 wxFlexGridSizer* actionsGridSizer = new wxFlexGridSizer(1, 2, 9, 15);
141 wxButton* createPkgbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_PACKAGE, _T("A. Create Package"));
142 createPkgbt->SetToolTip(wxT("Create a new package for this project."));
143 actionsGridSizer->Add(createPkgbt, 1, wxALL | wxEXPAND, 5);
144 wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("B. Edit CMakeLists File"));
145 editCMakebt->SetToolTip(wxT("Edit the CMakeLists.txt file of this project."));
146 editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageManagerPanel::OnCMakeMouseEnter,NULL,this);
147 editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageManagerPanel::OnCMakeMouseExit,NULL,this);
148 actionsGridSizer->Add(editCMakebt, 1, wxALL | wxEXPAND, 5);
150 actionsGridSizer->AddGrowableCol(0,1);
151 actionsGridSizer->AddGrowableCol(1,1);
153 actionsPanelSizer->Add(actionsGridSizer, 1, wxEXPAND, 0);
154 actionsPanel->SetSizer(actionsPanelSizer);
155 actionsPanelSizer->Fit(actionsPanel);
156 actionsBox->Add(actionsPanel, 1, wxEXPAND);
157 sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 10);
161 sizer->SetSizeHints(this);
163 if (((wxCDMMainFrame*)this->GetParent())->isHelp())
165 wxCDMPackageManagerHelpDialog* helpDialog = new wxCDMPackageManagerHelpDialog(this->GetParent(), this, wxID_ANY);
166 helpDialog->Show(true);
170 modelCDMProject* wxCDMPackageManagerPanel::GetProject() const
172 return this->project;
175 void wxCDMPackageManagerPanel::OnBtnReturn(wxHyperlinkEvent& event)
177 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
178 newEvent->SetInt(project->GetId());
180 wxPostEvent(this->GetParent(), *newEvent);
183 void wxCDMPackageManagerPanel::OnLnkPackageSelect(wxHyperlinkEvent& event)
186 std::vector<modelCDMPackage*> packages = this->project->GetPackages();
187 for (int i = 0; i < packages.size(); i++)
189 if(packages[i]->GetName() == crea::wx2std(event.GetURL()))
191 packageId = packages[i]->GetId();
196 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
197 newEvent->SetInt(packageId);
199 wxPostEvent(this->GetParent(), *newEvent);
201 wxCommandEvent* newEvent1 = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
202 newEvent1->SetInt(packageId);
204 wxPostEvent(this->GetParent(), *newEvent1);
208 void wxCDMPackageManagerPanel::OnBtnCreatePackage(wxCommandEvent& event)
212 wxCDMNewPackageDialog* dialog = new wxCDMNewPackageDialog(this);
214 userResponse = dialog->ShowModal();
216 if(userResponse == wxID_FORWARD)
218 modelCDMIProjectTreeNode* package = this->project->CreatePackage(
219 crea::wx2std(dialog->GetPackageName()),
221 crea::wx2std(dialog->GetPackageAuthor()),
222 crea::wx2std(dialog->GetPackageAuthorEmail()),
223 crea::wx2std(dialog->GetPackageDescription())
227 std::cout << "error creating package: " << *result << std::endl;
228 wxMessageBox(crea::std2wx(*result),_T("New Package - Error!"),wxOK | wxICON_ERROR);
232 wxMessageBox(crea::std2wx("Package successfully created."),_T("New Package - Success!"),wxOK | wxICON_INFORMATION);
234 //refreshing tree and description
235 //send event instead of calling parent to avoid crashing
237 ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
239 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
240 newEvent->SetInt(package->GetId());
242 wxPostEvent(this->GetParent(), *newEvent);
249 void wxCDMPackageManagerPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
252 if(!this->project->OpenCMakeListsFile(result))
253 wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
255 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
257 if(this->project->GetCMakeLists() != NULL)
259 int CMId = this->project->GetCMakeLists()->GetId();
260 newEvent->SetInt(CMId);
262 wxPostEvent(this->GetParent(), *newEvent);
266 void wxCDMPackageManagerPanel::OnMouseEnter(wxMouseEvent& event)
268 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
269 std::string PkgName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
271 std::vector<modelCDMPackage*> packages = this->project->GetPackages();
272 for (int i = 0; i < packages.size(); i++)
274 if(packages[i]->GetName() == PkgName)
276 pkgId = packages[i]->GetId();
280 newEvent->SetInt(pkgId);
282 wxPostEvent(this->GetParent(), *newEvent);
286 void wxCDMPackageManagerPanel::OnMouseExit(wxMouseEvent& event)
288 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
289 std::string PkgName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
291 std::vector<modelCDMPackage*> packages = this->project->GetPackages();
292 project->GetPackages();
293 for (int i = 0; i < packages.size(); i++)
295 if(packages[i]->GetName() == PkgName)
297 pkgId = packages[i]->GetId();
301 newEvent->SetInt(pkgId);
303 wxPostEvent(this->GetParent(), *newEvent);
307 void wxCDMPackageManagerPanel::OnCMakeMouseEnter(wxMouseEvent& event)
309 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
311 if(this->project->GetCMakeLists() != NULL)
313 int CMId = this->project->GetCMakeLists()->GetId();
314 newEvent->SetInt(CMId);
316 wxPostEvent(this->GetParent(), *newEvent);
321 void wxCDMPackageManagerPanel::OnCMakeMouseExit(wxMouseEvent& event)
323 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
325 if(this->project->GetCMakeLists() != NULL)
327 int CMId = this->project->GetCMakeLists()->GetId();
328 newEvent->SetInt(CMId);
330 wxPostEvent(this->GetParent(), *newEvent);