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 wxPanel::Create(parent, id, pos, size, style);
83 // this part makes the scrollbars show up
84 this->FitInside(); // ask the sizer about the needed size
85 this->SetScrollRate(5, 5);
87 this->blackBox = blackBox;
92 void wxCDMBlackBoxDescriptionPanel::CreateControls()
94 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
97 wxBoxSizer *linksSizer = new wxBoxSizer(wxHORIZONTAL);
98 std::vector<modelCDMIProjectTreeNode*> parents = this->blackBox->GetParents();
99 for (int i = 0; i < (int)(parents.size()); i++)
101 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);
102 returnLnk->SetWindowStyle(wxNO_BORDER);
103 returnLnk->SetToolTip(crea::std2wx("Return to " + parents[parents.size()-1-i]->GetName() + "."));
104 linksSizer->Add(returnLnk, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 5);
105 linksSizer->Add(new wxStaticText(this,wxID_ANY, wxT("/")), 0, wxALIGN_CENTER, 0);
108 linksSizer->Add(new wxStaticText(this, wxID_ANY, crea::std2wx(this->blackBox->GetName())), 0, wxALIGN_CENTER, 0);
110 sizer->Add(linksSizer, 0, wxALIGN_CENTER | wxALL, 5);
113 wxBoxSizer* headerSizer = new wxBoxSizer(wxHORIZONTAL);
116 headerSizer->Add(new wxStaticBitmap(this, -1, wxBitmap(BBIcon64)),0, wxALIGN_CENTER, 0);
117 wxBoxSizer* textSizer = new wxBoxSizer(wxVERTICAL);
119 textSizer->Add(new wxStaticText(this, -1, _("Black Box")),0, wxALIGN_LEFT, 0);
121 textSizer->Add(new wxStaticText(this, -1, crea::std2wx(this->blackBox->GetNameBlackBox())),0, wxALIGN_LEFT, 0);
122 headerSizer->Add(textSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
124 sizer->Add(headerSizer, 0, wxALIGN_CENTER);
126 //BlackBox Properties
127 wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Properties"));
128 wxPanel* propertiesPanel = new wxPanel(this);
129 wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL);
130 wxFlexGridSizer* propertiesGridSizer = new wxFlexGridSizer(4, 2, 9, 15);
132 wxStaticText *pAuthor = new wxStaticText(propertiesPanel, -1, wxT("Author"));
133 wxStaticText *pDescription = new wxStaticText(propertiesPanel, -1, wxT("Description"));
134 wxStaticText *pCategories = new wxStaticText(propertiesPanel, -1, wxT("Categories"));
137 wxBoxSizer* pAuthorsz = new wxBoxSizer(wxHORIZONTAL);
138 this->authortc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->blackBox->GetAuthors()));
139 wxButton* pAuthorbt = new wxButton(propertiesPanel, ID_BUTTON_SET_AUTHOR, wxT("Change"));
140 pAuthorbt->SetToolTip(wxT("Update the author/s of the package."));
141 pAuthorsz->Add(this->authortc, 1, wxALIGN_CENTER, 0);
142 pAuthorsz->Add(pAuthorbt, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 10);
145 wxBoxSizer* pDescriptionsz = new wxBoxSizer(wxHORIZONTAL);
146 this->descriptiontc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->blackBox->GetDescription()));
147 wxButton* pDescriptionbt = new wxButton(propertiesPanel, ID_BUTTON_SET_DESCRIPTION, wxT("Change"));
148 pDescriptionbt->SetToolTip(wxT("Update the description of the project."));
149 pDescriptionsz->Add(this->descriptiontc, 1, wxALIGN_CENTER, 1);
150 pDescriptionsz->Add(pDescriptionbt, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 10);
153 wxBoxSizer* pCategoriessz = new wxBoxSizer(wxHORIZONTAL);
154 this->categoriestc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->blackBox->GetCategories()));
155 wxButton* pCategoriesbt = new wxButton(propertiesPanel, ID_BUTTON_SET_CATEGORY, wxT("Change"));
156 pCategoriesbt->SetToolTip(wxT("Update the categories of the project."));
157 pCategoriessz->Add(this->categoriestc, 1, wxALIGN_CENTER, 0);
158 pCategoriessz->Add(pCategoriesbt, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 10);
160 propertiesGridSizer->Add(pAuthor, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
161 propertiesGridSizer->Add(pAuthorsz, 1, wxEXPAND);
162 propertiesGridSizer->Add(pDescription, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
163 propertiesGridSizer->Add(pDescriptionsz, 1, wxEXPAND);
164 propertiesGridSizer->Add(pCategories, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
165 propertiesGridSizer->Add(pCategoriessz, 1, wxEXPAND);
167 propertiesGridSizer->AddGrowableCol(1,1);
169 propertiesPanelSizer -> Add(propertiesGridSizer, 1, wxEXPAND | wxALL, 5);
170 propertiesPanel->SetSizer(propertiesPanelSizer);
171 propertiesPanelSizer->Fit(propertiesPanel);
172 propertiesBox->Add(propertiesPanel, 1, wxEXPAND, 5);
174 sizer->Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
178 wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions"));
179 wxPanel* actionsPanel = new wxPanel(this);
180 wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
182 wxFlexGridSizer* actionsGridSizer = new wxFlexGridSizer(2, 2, 9, 15);
184 wxButton* openHxxbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_HXX, _T("A. Open .h"));
185 openHxxbt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMBlackBoxDescriptionPanel::OnHxxMouseEnter,NULL,this);
186 openHxxbt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMBlackBoxDescriptionPanel::OnHxxMouseExit,NULL,this);
187 openHxxbt->SetToolTip(wxT("Open the .h file in the default text editor."));
188 actionsGridSizer->Add(openHxxbt, 1, wxALL | wxEXPAND, 5);
189 wxButton* openCxxbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_CXX, _T("B. Open .cxx"));
190 openCxxbt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMBlackBoxDescriptionPanel::OnCxxMouseEnter,NULL,this);
191 openCxxbt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMBlackBoxDescriptionPanel::OnCxxMouseExit,NULL,this);
192 openCxxbt->SetToolTip(wxT("Open the .cxx file in the default text editor."));
193 actionsGridSizer->Add(openCxxbt, 1, wxALL | wxEXPAND, 5);
194 wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("Open Source Folder"));
195 openFolderbt->SetToolTip(wxT("Open the source folder in the file explorer."));
196 actionsGridSizer->Add(openFolderbt, 1, wxALL | wxEXPAND, 5);
198 actionsGridSizer->AddGrowableCol(0,1);
199 actionsGridSizer->AddGrowableCol(1,1);
201 actionsPanelSizer->Add(actionsGridSizer, 1, wxEXPAND, 0);
202 actionsPanel->SetSizer(actionsPanelSizer);
203 actionsPanelSizer->Fit(actionsPanel);
204 actionsBox->Add(actionsPanel, 1, wxEXPAND);
205 sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 10);
209 sizer->SetSizeHints(this);
211 if (((wxCDMMainFrame*)this->GetParent())->isHelp())
213 wxCDMBlackBoxHelpDialog* helpDialog = new wxCDMBlackBoxHelpDialog(this->GetParent(), this->blackBox, wxID_ANY);
214 helpDialog->Show(true);
218 void wxCDMBlackBoxDescriptionPanel::OnBtnReturn(wxHyperlinkEvent& event)
220 std::vector<modelCDMIProjectTreeNode*> parents = this->blackBox->GetParents();
221 std::string parentURL = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
222 //std::cout << parentURL << std::endl;
223 for (int i = 0; i < (int)(parents.size()); i++)
225 if (parents[i]->GetPath() == parentURL)
227 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
228 newEvent->SetClientData(parents[i]);
230 wxPostEvent(this->GetParent(), *newEvent);
236 void wxCDMBlackBoxDescriptionPanel::OnBtnSetAuthor(wxCommandEvent& event)
238 //get author from user
239 wxTextEntryDialog* authDlg = new wxTextEntryDialog(
241 wxT("Enter the new authors name. Separate each author with a '/'."),
242 wxT("Change Black Box Author - creaDevManager"),
243 crea::std2wx(this->blackBox->GetAuthors()),
247 if (authDlg->ShowModal() == wxID_OK)
249 std::string authorsStr = crea::wx2std(authDlg->GetValue());
251 if(authorsStr.size() > 0)
254 if(!this->blackBox->SetAuthors(authorsStr, result))
255 wxMessageBox(crea::std2wx(*result),_T("Change Black Box Author - Error!"),wxOK | wxICON_ERROR);
259 this->authortc->SetLabel(crea::std2wx(this->blackBox->GetAuthors()));
260 this->authortc->GetParent()->GetSizer()->RecalcSizes();
265 void wxCDMBlackBoxDescriptionPanel::OnBtnSetDescription(wxCommandEvent& event)
267 //get author from user
268 wxTextEntryDialog* descDlg = new wxTextEntryDialog(
270 wxT("Edit the black box description."),
271 wxT("Change Black Box Description - creaDevManager"),
272 crea::std2wx(this->blackBox->GetDescription()),
273 wxTE_MULTILINE | wxOK | wxCANCEL
276 if (descDlg->ShowModal() == wxID_OK)
278 std::string descriptionStr = crea::wx2std(descDlg->GetValue());
280 if(descriptionStr.size() > 0)
283 if(!this->blackBox->SetDescription(descriptionStr, result))
284 wxMessageBox(crea::std2wx(*result),_T("Change Black Box Description - Error!"),wxOK | wxICON_ERROR);
286 this->descriptiontc->SetLabel(crea::std2wx(this->blackBox->GetDescription()));
287 this->descriptiontc->GetParent()->GetSizer()->RecalcSizes();
291 void wxCDMBlackBoxDescriptionPanel::OnBtnSetCategories(wxCommandEvent& event)
293 //get author from user
294 wxTextEntryDialog* catsDlg = new wxTextEntryDialog(
296 wxT("Edit the black box categories separated by '/'."),
297 wxT("Change Black Box Categories - creaDevManager"),
298 crea::std2wx(this->blackBox->GetCategories()),
299 wxTE_MULTILINE | wxOK | wxCANCEL
302 if (catsDlg->ShowModal() == wxID_OK)
304 std::string categoriesStr = crea::wx2std(catsDlg->GetValue());
306 if(categoriesStr.size() > 0)
309 if(!this->blackBox->SetCategories(categoriesStr, result))
310 wxMessageBox(crea::std2wx(*result),_T("Change Black Box Categories - Error!"),wxOK | wxICON_ERROR);
312 this->categoriestc->SetLabel(crea::std2wx(this->blackBox->GetCategories()));
313 this->categoriestc->GetParent()->GetSizer()->RecalcSizes();
317 void wxCDMBlackBoxDescriptionPanel::OnBtnOpenCxx(wxCommandEvent& event)
320 if(!this->blackBox->OpenCxx(result))
321 wxMessageBox(crea::std2wx(*result),_T("Open Source File - Error!"),wxOK | wxICON_ERROR);
323 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
325 if(this->blackBox->GetSourceFile() != NULL)
327 newEvent->SetClientData(this->blackBox->GetSourceFile());
329 wxPostEvent(this->GetParent(), *newEvent);
335 void wxCDMBlackBoxDescriptionPanel::OnBtnOpenHxx(wxCommandEvent& event)
338 if(!this->blackBox->OpenHxx(result))
339 wxMessageBox(crea::std2wx(*result),_T("Open Header File - Error!"),wxOK | wxICON_ERROR);
341 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
343 if(this->blackBox->GetHeaderFile() != NULL)
345 newEvent->SetClientData(this->blackBox->GetHeaderFile());
347 wxPostEvent(this->GetParent(), *newEvent);
353 void wxCDMBlackBoxDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
356 if(!this->blackBox->OpenInFileExplorer(result))
357 wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
360 void wxCDMBlackBoxDescriptionPanel::OnCxxMouseEnter(wxMouseEvent& event)
362 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
364 if(this->blackBox->GetSourceFile() != NULL)
366 newEvent->SetClientData(this->blackBox->GetSourceFile());
368 wxPostEvent(this->GetParent(), *newEvent);
373 void wxCDMBlackBoxDescriptionPanel::OnCxxMouseExit(wxMouseEvent& event)
375 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
377 if(this->blackBox->GetSourceFile() != NULL)
379 newEvent->SetClientData(this->blackBox->GetSourceFile());
381 wxPostEvent(this->GetParent(), *newEvent);
386 void wxCDMBlackBoxDescriptionPanel::OnHxxMouseEnter(wxMouseEvent& event)
388 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED);
390 if(this->blackBox->GetHeaderFile() != NULL)
392 newEvent->SetClientData(this->blackBox->GetHeaderFile());
394 wxPostEvent(this->GetParent(), *newEvent);
399 void wxCDMBlackBoxDescriptionPanel::OnHxxMouseExit(wxMouseEvent& event)
401 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LISTBOX_SELECTED);
403 if(this->blackBox->GetHeaderFile() != NULL)
405 newEvent->SetClientData(this->blackBox->GetHeaderFile());
407 wxPostEvent(this->GetParent(), *newEvent);