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 * wxCDMBlackBoxDescriptionPanel.cpp
31 * Created on: Nov 27, 2012
32 * Author: Daniel Felipe Gonzalez Obando
35 #include "wxCDMBlackBoxDescriptionPanel.h"
37 #include "wxCDMMainFrame.h"
39 #include "wxCDMBlackBoxHelpDialog.h"
41 #include "creaDevManagerIds.h"
42 #include "images/BBIcon64.xpm"
44 BEGIN_EVENT_TABLE(wxCDMBlackBoxDescriptionPanel, wxPanel)
45 EVT_HYPERLINK(ID_BUTTON_PREV, wxCDMBlackBoxDescriptionPanel::OnBtnReturn)
46 EVT_BUTTON(ID_BUTTON_SET_AUTHOR, wxCDMBlackBoxDescriptionPanel::OnBtnSetAuthor)
47 EVT_BUTTON(ID_BUTTON_SET_DESCRIPTION, wxCDMBlackBoxDescriptionPanel::OnBtnSetDescription)
48 EVT_BUTTON(ID_BUTTON_SET_CATEGORY, wxCDMBlackBoxDescriptionPanel::OnBtnSetCategories)
49 EVT_BUTTON(ID_BUTTON_OPEN_CXX, wxCDMBlackBoxDescriptionPanel::OnBtnOpenCxx)
50 EVT_BUTTON(ID_BUTTON_OPEN_HXX, wxCDMBlackBoxDescriptionPanel::OnBtnOpenHxx)
51 EVT_BUTTON(ID_BUTTON_OPEN_FOLDER, wxCDMBlackBoxDescriptionPanel::OnBtnOpenFolder)
54 wxCDMBlackBoxDescriptionPanel::wxCDMBlackBoxDescriptionPanel(
56 modelCDMBlackBox* blackBox,
58 const wxString& caption,
64 wxCDMBlackBoxDescriptionPanel::Create(parent, blackBox, id, caption, pos, size, style);
67 wxCDMBlackBoxDescriptionPanel::~wxCDMBlackBoxDescriptionPanel()
71 bool wxCDMBlackBoxDescriptionPanel::Create(
73 modelCDMBlackBox* blackBox,
75 const wxString& caption,
81 this->blackBox = blackBox;
82 wxPanel::Create(parent, id, pos, size, style);
84 // this part makes the scrollbars show up
85 this->FitInside(); // ask the sizer about the needed size
86 this->SetScrollRate(5, 5);
90 void wxCDMBlackBoxDescriptionPanel::CreateControls()
92 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
95 wxBoxSizer *linksSizer = new wxBoxSizer(wxHORIZONTAL);
96 std::vector<modelCDMIProjectTreeNode*> parents = this->blackBox->GetParents();
97 for (int i = 0; i < (int)(parents.size()); i++)
99 wxHyperlinkCtrl* returnLnk = new wxHyperlinkCtrl(this, ID_BUTTON_PREV, crea::std2wx(parents[parents.size()-1-i]->GetName()), crea::std2wx(parents[parents.size()-1-i]->GetPath()), wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE);
100 returnLnk->SetWindowStyle(wxNO_BORDER);
101 returnLnk->SetToolTip(crea::std2wx("Return to " + parents[parents.size()-1-i]->GetName() + "."));
102 linksSizer->Add(returnLnk, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 5);
103 linksSizer->Add(new wxStaticText(this,wxID_ANY, wxT("/")), 0, wxALIGN_CENTER, 0);
106 linksSizer->Add(new wxStaticText(this, wxID_ANY, crea::std2wx(this->blackBox->GetName())), 0, wxALIGN_CENTER, 0);
108 sizer->Add(linksSizer, 0, wxALIGN_CENTER | wxALL, 5);
111 wxBoxSizer* headerSizer = new wxBoxSizer(wxHORIZONTAL);
114 headerSizer->Add(new wxStaticBitmap(this, -1, wxBitmap(BBIcon64)),0, wxALIGN_CENTER, 0);
115 wxBoxSizer* textSizer = new wxBoxSizer(wxVERTICAL);
117 textSizer->Add(new wxStaticText(this, -1, _("Black Box")),0, wxALIGN_LEFT, 0);
119 textSizer->Add(new wxStaticText(this, -1, crea::std2wx(this->blackBox->GetNameBlackBox())),0, wxALIGN_LEFT, 0);
120 headerSizer->Add(textSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
122 sizer->Add(headerSizer, 0, wxALIGN_CENTER);
124 //BlackBox Properties
125 wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Properties"));
126 wxPanel* propertiesPanel = new wxPanel(this);
127 wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL);
128 wxFlexGridSizer* propertiesGridSizer = new wxFlexGridSizer(4, 2, 9, 15);
130 wxStaticText *pAuthor = new wxStaticText(propertiesPanel, -1, wxT("Author"));
131 wxStaticText *pDescription = new wxStaticText(propertiesPanel, -1, wxT("Description"));
132 wxStaticText *pCategories = new wxStaticText(propertiesPanel, -1, wxT("Categories"));
135 wxBoxSizer* pAuthorsz = new wxBoxSizer(wxHORIZONTAL);
136 this->authortc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->blackBox->GetAuthors()));
137 wxButton* pAuthorbt = new wxButton(propertiesPanel, ID_BUTTON_SET_AUTHOR, wxT("Change"));
138 pAuthorbt->SetToolTip(wxT("Update the author/s of the package."));
139 pAuthorsz->Add(this->authortc, 1, wxALIGN_CENTER, 0);
140 pAuthorsz->Add(pAuthorbt, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 10);
143 wxBoxSizer* pDescriptionsz = new wxBoxSizer(wxHORIZONTAL);
144 this->descriptiontc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->blackBox->GetDescription()));
145 wxButton* pDescriptionbt = new wxButton(propertiesPanel, ID_BUTTON_SET_DESCRIPTION, wxT("Change"));
146 pDescriptionbt->SetToolTip(wxT("Update the description of the project."));
147 pDescriptionsz->Add(this->descriptiontc, 1, wxALIGN_CENTER, 1);
148 pDescriptionsz->Add(pDescriptionbt, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 10);
151 wxBoxSizer* pCategoriessz = new wxBoxSizer(wxHORIZONTAL);
152 this->categoriestc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->blackBox->GetCategories()));
153 wxButton* pCategoriesbt = new wxButton(propertiesPanel, ID_BUTTON_SET_CATEGORY, wxT("Change"));
154 pCategoriesbt->SetToolTip(wxT("Update the categories of the project."));
155 pCategoriessz->Add(this->categoriestc, 1, wxALIGN_CENTER, 0);
156 pCategoriessz->Add(pCategoriesbt, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 10);
158 propertiesGridSizer->Add(pAuthor, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
159 propertiesGridSizer->Add(pAuthorsz, 1, wxEXPAND);
160 propertiesGridSizer->Add(pDescription, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
161 propertiesGridSizer->Add(pDescriptionsz, 1, wxEXPAND);
162 propertiesGridSizer->Add(pCategories, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
163 propertiesGridSizer->Add(pCategoriessz, 1, wxEXPAND);
165 propertiesGridSizer->AddGrowableCol(1,1);
167 propertiesPanelSizer -> Add(propertiesGridSizer, 1, wxEXPAND | wxALL, 5);
168 propertiesPanel->SetSizer(propertiesPanelSizer);
169 propertiesPanelSizer->Fit(propertiesPanel);
170 propertiesBox->Add(propertiesPanel, 1, wxEXPAND, 5);
172 sizer->Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
176 wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions"));
177 wxPanel* actionsPanel = new wxPanel(this);
178 wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
180 wxFlexGridSizer* actionsGridSizer = new wxFlexGridSizer(2, 2, 9, 15);
182 wxButton* openHxxbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_HXX, _T("A. Open .h"));
183 openHxxbt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMBlackBoxDescriptionPanel::OnHxxMouseEnter,NULL,this);
184 openHxxbt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMBlackBoxDescriptionPanel::OnHxxMouseExit,NULL,this);
185 openHxxbt->SetToolTip(wxT("Open the .h file in the default text editor."));
186 actionsGridSizer->Add(openHxxbt, 1, wxALL | wxEXPAND, 5);
187 wxButton* openCxxbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_CXX, _T("B. Open .cxx"));
188 openCxxbt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMBlackBoxDescriptionPanel::OnCxxMouseEnter,NULL,this);
189 openCxxbt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMBlackBoxDescriptionPanel::OnCxxMouseExit,NULL,this);
190 openCxxbt->SetToolTip(wxT("Open the .cxx file in the default text editor."));
191 actionsGridSizer->Add(openCxxbt, 1, wxALL | wxEXPAND, 5);
192 wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("Open Source Folder"));
193 openFolderbt->SetToolTip(wxT("Open the source folder in the file explorer."));
194 actionsGridSizer->Add(openFolderbt, 1, wxALL | wxEXPAND, 5);
196 actionsGridSizer->AddGrowableCol(0,1);
197 actionsGridSizer->AddGrowableCol(1,1);
199 actionsPanelSizer->Add(actionsGridSizer, 1, wxEXPAND, 0);
200 actionsPanel->SetSizer(actionsPanelSizer);
201 actionsPanelSizer->Fit(actionsPanel);
202 actionsBox->Add(actionsPanel, 1, wxEXPAND);
203 sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 10);
207 sizer->SetSizeHints(this);
209 if (((wxCDMMainFrame*)this->GetParent())->isHelp())
211 wxCDMBlackBoxHelpDialog* helpDialog = new wxCDMBlackBoxHelpDialog(this->GetParent(), this->blackBox, wxID_ANY);
212 helpDialog->Show(true);
216 void wxCDMBlackBoxDescriptionPanel::OnBtnReturn(wxHyperlinkEvent& event)
218 std::vector<modelCDMIProjectTreeNode*> parents = this->blackBox->GetParents();
219 std::string parentURL = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
220 //std::cout << parentURL << std::endl;
221 for (int i = 0; i < (int)(parents.size()); i++)
223 if (parents[i]->GetPath() == parentURL)
225 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
226 newEvent->SetClientData(parents[i]);
228 wxPostEvent(this->GetParent(), *newEvent);
234 void wxCDMBlackBoxDescriptionPanel::OnBtnSetAuthor(wxCommandEvent& event)
236 //get author from user
237 wxTextEntryDialog* authDlg = new wxTextEntryDialog(
239 wxT("Enter the new authors name. Separate each author with a '/'."),
240 wxT("Change Black Box Author - creaDevManager"),
241 crea::std2wx(this->blackBox->GetAuthors()),
245 if (authDlg->ShowModal() == wxID_OK)
247 std::string authorsStr = crea::wx2std(authDlg->GetValue());
249 if(authorsStr.size() > 0)
252 if(!this->blackBox->SetAuthors(authorsStr, result))
253 wxMessageBox(crea::std2wx(*result),_T("Change Black Box Author - Error!"),wxOK | wxICON_ERROR);
257 this->authortc->SetLabel(crea::std2wx(this->blackBox->GetAuthors()));
258 this->authortc->GetParent()->GetSizer()->RecalcSizes();
263 void wxCDMBlackBoxDescriptionPanel::OnBtnSetDescription(wxCommandEvent& event)
265 //get author from user
266 wxTextEntryDialog* descDlg = new wxTextEntryDialog(
268 wxT("Edit the black box description."),
269 wxT("Change Black Box Description - creaDevManager"),
270 crea::std2wx(this->blackBox->GetDescription()),
271 wxTE_MULTILINE | wxOK | wxCANCEL
274 if (descDlg->ShowModal() == wxID_OK)
276 std::string descriptionStr = crea::wx2std(descDlg->GetValue());
278 if(descriptionStr.size() > 0)
281 if(!this->blackBox->SetDescription(descriptionStr, result))
282 wxMessageBox(crea::std2wx(*result),_T("Change Black Box Description - Error!"),wxOK | wxICON_ERROR);
284 this->descriptiontc->SetLabel(crea::std2wx(this->blackBox->GetDescription()));
285 this->descriptiontc->GetParent()->GetSizer()->RecalcSizes();
289 void wxCDMBlackBoxDescriptionPanel::OnBtnSetCategories(wxCommandEvent& event)
291 //get author from user
292 wxTextEntryDialog* catsDlg = new wxTextEntryDialog(
294 wxT("Edit the black box categories separated by '/'."),
295 wxT("Change Black Box Categories - creaDevManager"),
296 crea::std2wx(this->blackBox->GetCategories()),
297 wxTE_MULTILINE | wxOK | wxCANCEL
300 if (catsDlg->ShowModal() == wxID_OK)
302 std::string categoriesStr = crea::wx2std(catsDlg->GetValue());
304 if(categoriesStr.size() > 0)
307 if(!this->blackBox->SetCategories(categoriesStr, result))
308 wxMessageBox(crea::std2wx(*result),_T("Change Black Box Categories - Error!"),wxOK | wxICON_ERROR);
310 this->categoriestc->SetLabel(crea::std2wx(this->blackBox->GetCategories()));
311 this->categoriestc->GetParent()->GetSizer()->RecalcSizes();
315 void wxCDMBlackBoxDescriptionPanel::OnBtnOpenCxx(wxCommandEvent& event)
318 if(!this->blackBox->OpenCxx(result))
319 wxMessageBox(crea::std2wx(*result),_T("Open Source File - Error!"),wxOK | wxICON_ERROR);
321 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
323 if(this->blackBox->GetSourceFile() != NULL)
325 newEvent->SetClientData(this->blackBox->GetSourceFile());
327 wxPostEvent(this->GetParent(), *newEvent);
333 void wxCDMBlackBoxDescriptionPanel::OnBtnOpenHxx(wxCommandEvent& event)
336 if(!this->blackBox->OpenHxx(result))
337 wxMessageBox(crea::std2wx(*result),_T("Open Header File - Error!"),wxOK | wxICON_ERROR);
339 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
341 if(this->blackBox->GetHeaderFile() != NULL)
343 newEvent->SetClientData(this->blackBox->GetHeaderFile());
345 wxPostEvent(this->GetParent(), *newEvent);
351 void wxCDMBlackBoxDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
354 if(!this->blackBox->OpenInFileExplorer(result))
355 wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
358 void wxCDMBlackBoxDescriptionPanel::OnCxxMouseEnter(wxMouseEvent& event)
360 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
362 if(this->blackBox->GetSourceFile() != NULL)
364 newEvent->SetClientData(this->blackBox->GetSourceFile());
366 wxPostEvent(this->GetParent(), *newEvent);
371 void wxCDMBlackBoxDescriptionPanel::OnCxxMouseExit(wxMouseEvent& event)
373 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
375 if(this->blackBox->GetSourceFile() != NULL)
377 newEvent->SetClientData(this->blackBox->GetSourceFile());
379 wxPostEvent(this->GetParent(), *newEvent);
384 void wxCDMBlackBoxDescriptionPanel::OnHxxMouseEnter(wxMouseEvent& event)
386 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
388 if(this->blackBox->GetHeaderFile() != NULL)
390 newEvent->SetClientData(this->blackBox->GetHeaderFile());
392 wxPostEvent(this->GetParent(), *newEvent);
397 void wxCDMBlackBoxDescriptionPanel::OnHxxMouseExit(wxMouseEvent& event)
399 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
401 if(this->blackBox->GetHeaderFile() != NULL)
403 newEvent->SetClientData(this->blackBox->GetHeaderFile());
405 wxPostEvent(this->GetParent(), *newEvent);