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()), wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE);
93 returnLnk->SetWindowStyle(wxNO_BORDER);
94 returnLnk->SetToolTip(wxT("Return to the active project description."));
95 sizer->Add(returnLnk, 0, wxALIGN_CENTER | wxALL, 5);
98 wxBoxSizer* headerSizer = new wxBoxSizer(wxHORIZONTAL);
101 headerSizer->Add(new wxStaticBitmap(this, -1, wxBitmap(PkIcon64)),0, wxALIGN_CENTER, 0);
102 wxBoxSizer* textSizer = new wxBoxSizer(wxVERTICAL);
104 textSizer->Add(new wxStaticText(this, -1, _("Package Management")),0, wxALIGN_LEFT, 0);
106 headerSizer->Add(textSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
108 sizer->Add(headerSizer, 0, wxALIGN_CENTER);
111 wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("A&vailable Packages"));
112 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."));
113 wxPanel* propertiesPanel = new wxPanel(this);
114 wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL);
116 std::vector<modelCDMPackage*> packages = this->project->GetPackages();
117 for (int i = 0; i < (int)(packages.size()); i++)
119 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);
120 pPackagelk->SetWindowStyle(wxALIGN_LEFT | wxNO_BORDER);
121 std::string tt = "Author: " + packages[i]->GetAuthors() + "\nDescription: " + packages[i]->GetDescription();
122 pPackagelk->SetToolTip(crea::std2wx(tt));
123 propertiesPanelSizer -> Add(pPackagelk, 0, wxEXPAND | wxALL, 5);
124 pPackagelk->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageManagerPanel::OnMouseEnter,NULL,this);
125 pPackagelk->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageManagerPanel::OnMouseExit,NULL,this);
128 propertiesPanel->SetSizer(propertiesPanelSizer);
129 propertiesPanelSizer->Fit(propertiesPanel);
130 propertiesBox->Add(propertiesPanel, 1, wxALL | wxEXPAND, 5);
132 sizer -> Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
135 wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions"));
136 wxPanel* actionsPanel = new wxPanel(this);
137 wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
140 wxFlexGridSizer* actionsGridSizer = new wxFlexGridSizer(1, 2, 9, 15);
142 wxButton* createPkgbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_PACKAGE, _T("A. Create Package"));
143 createPkgbt->SetToolTip(wxT("Create a new package for this project."));
144 actionsGridSizer->Add(createPkgbt, 1, wxALL | wxEXPAND, 5);
145 wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("B. Edit CMakeLists File"));
146 editCMakebt->SetToolTip(wxT("Edit the CMakeLists.txt file of this project."));
147 editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageManagerPanel::OnCMakeMouseEnter,NULL,this);
148 editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageManagerPanel::OnCMakeMouseExit,NULL,this);
149 actionsGridSizer->Add(editCMakebt, 1, wxALL | wxEXPAND, 5);
151 actionsGridSizer->AddGrowableCol(0,1);
152 actionsGridSizer->AddGrowableCol(1,1);
154 actionsPanelSizer->Add(actionsGridSizer, 1, wxEXPAND, 0);
155 actionsPanel->SetSizer(actionsPanelSizer);
156 actionsPanelSizer->Fit(actionsPanel);
157 actionsBox->Add(actionsPanel, 1, wxEXPAND);
158 sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 10);
162 sizer->SetSizeHints(this);
164 if (((wxCDMMainFrame*)this->GetParent())->isHelp())
166 wxCDMPackageManagerHelpDialog* helpDialog = new wxCDMPackageManagerHelpDialog(this->GetParent(), this, wxID_ANY);
167 helpDialog->Show(true);
171 modelCDMProject* wxCDMPackageManagerPanel::GetProject() const
173 return this->project;
176 void wxCDMPackageManagerPanel::OnBtnReturn(wxHyperlinkEvent& event)
178 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
179 newEvent->SetClientData(project);
181 wxPostEvent(this->GetParent(), *newEvent);
184 void wxCDMPackageManagerPanel::OnLnkPackageSelect(wxHyperlinkEvent& event)
186 modelCDMPackage* thePackage = NULL;
187 std::vector<modelCDMPackage*> packages = this->project->GetPackages();
188 for (int i = 0; i < (int)(packages.size()); i++)
190 if(packages[i]->GetName() == crea::wx2std(event.GetURL()))
192 thePackage = packages[i];
197 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
198 newEvent->SetClientData(thePackage);
200 wxPostEvent(this->GetParent(), *newEvent);
202 wxCommandEvent* newEvent1 = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
203 newEvent1->SetClientData(thePackage);
205 wxPostEvent(this->GetParent(), *newEvent1);
209 void wxCDMPackageManagerPanel::OnBtnCreatePackage(wxCommandEvent& event)
213 wxCDMNewPackageDialog* dialog = new wxCDMNewPackageDialog(this);
215 userResponse = dialog->ShowModal();
217 if(userResponse == wxID_FORWARD)
219 modelCDMIProjectTreeNode* package = this->project->CreatePackage(
220 crea::wx2std(dialog->GetPackageName()),
222 crea::wx2std(dialog->GetPackageAuthor()),
223 crea::wx2std(dialog->GetPackageAuthorEmail()),
224 crea::wx2std(dialog->GetPackageDescription())
228 std::cout << "error creating package: " << *result << std::endl;
229 wxMessageBox(crea::std2wx(*result),_T("New Package - Error!"),wxOK | wxICON_ERROR);
233 wxMessageBox(crea::std2wx("Package successfully created."),_T("New Package - Success!"),wxOK | wxICON_INFORMATION);
235 //refreshing tree and description
236 //send event instead of calling parent to avoid crashing
238 ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
240 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
241 newEvent->SetClientData(package);
243 wxPostEvent(this->GetParent(), *newEvent);
250 void wxCDMPackageManagerPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
253 if(!this->project->OpenCMakeListsFile(result))
254 wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
256 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
258 if(this->project->GetCMakeLists() != NULL)
260 newEvent->SetClientData(this->project->GetCMakeLists());
262 wxPostEvent(this->GetParent(), *newEvent);
266 void wxCDMPackageManagerPanel::OnMouseEnter(wxMouseEvent& event)
268 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
269 std::string PkgName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
270 modelCDMPackage* thePackage = NULL;
271 std::vector<modelCDMPackage*> packages = this->project->GetPackages();
272 for (int i = 0; i < (int)(packages.size()); i++)
274 if(packages[i]->GetName() == PkgName)
276 thePackage = packages[i];
280 newEvent->SetClientData(thePackage);
282 wxPostEvent(this->GetParent(), *newEvent);
286 void wxCDMPackageManagerPanel::OnMouseExit(wxMouseEvent& event)
288 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
289 std::string PkgName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
290 modelCDMPackage* thePackage = NULL;
291 std::vector<modelCDMPackage*> packages = this->project->GetPackages();
292 project->GetPackages();
293 for (int i = 0; i < (int)(packages.size()); i++)
295 if(packages[i]->GetName() == PkgName)
297 thePackage = packages[i];
301 newEvent->SetClientData(thePackage);
303 wxPostEvent(this->GetParent(), *newEvent);
307 void wxCDMPackageManagerPanel::OnCMakeMouseEnter(wxMouseEvent& event)
309 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
311 if(this->project->GetCMakeLists() != NULL)
313 newEvent->SetClientData(this->project->GetCMakeLists());
315 wxPostEvent(this->GetParent(), *newEvent);
320 void wxCDMPackageManagerPanel::OnCMakeMouseExit(wxMouseEvent& event)
322 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
324 if(this->project->GetCMakeLists() != NULL)
326 newEvent->SetClientData(this->project->GetCMakeLists());
328 wxPostEvent(this->GetParent(), *newEvent);