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 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Module: $RCSfile: bbtkWxGUIPackageBrowser.cxx,v $
32 Date: $Date: 2012/11/16 08:49:01 $
33 Version: $Revision: 1.8 $
34 =========================================================================*/
40 * \brief Short description in one line
42 * Long description which
43 * can span multiple lines
55 #ifdef _USE_WXWIDGETS_
57 #define CHECKBOXVIEW 1
59 #include "bbtkWxGUIPackageBrowser.h"
60 #include "ThirdParty/wx/treemultictrl/wxTreeMultiCtrl.h"
61 #include "bbtkInterpreter.h"
62 #include "bbtkBlackBoxInputDescriptor.h"
63 #include "bbtkBlackBoxOutputDescriptor.h"
64 #include "bbtkWxBlackBox.h"
66 #include <wx/statline.h>
71 //================================================================
72 WxGUIPackageBrowserBlackBox::
73 WxGUIPackageBrowserBlackBox(wxWindow* parent,
74 WxGUIPackageBrowser* browser,
75 BlackBoxDescriptor::Pointer descr) :
80 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
82 wxStaticText* s = new wxStaticText(this,-1,
83 std2wx(descr->GetDescription()));
84 sizer->Add(s,0,wxGROW);
85 s = new wxStaticText(this,-1,
86 std2wx(descr->GetAuthor()));
87 sizer->Add(s,0,wxGROW);
88 s = new wxStaticText(this,-1,
89 std2wx(descr->GetCategory()));
90 sizer->Add(s,0,wxGROW);
92 std::vector<std::vector<std::string> > user_defined;
93 std::vector<std::vector<std::string> > ubb_defined;
94 std::vector<std::vector<std::string> > wxbb_defined;
96 std::string titlecol("#BBBBFF");
97 std::string usercol("#FFFFFF");
98 std::string ubbcol("#DDFFFF");
99 std::string wxbbcol("#EEFFFF");
101 const BlackBoxDescriptor::InputDescriptorMapType& imap =
102 descr->GetInputDescriptorMap();
103 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
104 for ( in = imap.begin(); in != imap.end(); ++in )
106 // Skips system-defined inputs
107 std::string col(usercol);
109 if (in->second->GetCreatorTypeInfo() ==
110 typeid(AtomicBlackBoxDescriptor))
115 else if (in->second->GetCreatorTypeInfo() ==
116 typeid(WxBlackBoxDescriptor))
122 std::string name(in->second->GetName());
123 //Utilities::html_format(name);
125 std::string type("<");
126 type += in->second->GetTypeName();
128 //Utilities::html_format(type);
130 std::string descr(in->second->GetDescription());
131 //Utilities::html_format(descr);
133 std::vector<std::string> out;
136 out.push_back(descr);
138 if (iotype==0) user_defined.push_back(out);
139 else if (iotype==1) ubb_defined.push_back(out);
140 else if (iotype==2) wxbb_defined.push_back(out);
147 ( new wxStaticBox(this, wxID_ANY, _T("Inputs")), wxVERTICAL );
148 wxFlexGridSizer* grid = new wxFlexGridSizer(3);
150 wxTextAttr ionameattr(*wxRED,*wxBLACK);
151 wxTextAttr iotypeattr(*wxBLACK,*wxRED);
154 std::vector<std::vector<std::string> >::iterator hi;
155 for (hi=user_defined.begin();hi!=user_defined.end();++hi)
158 grid->Add( new wxStaticText(this,-1,std2wx((*hi)[0])));
159 grid->Add( new wxStaticText(this,-1,std2wx((*hi)[1])));
160 grid->Add( new wxStaticText(this,-1,std2wx((*hi)[2])));
161 // grid->SetCellValue( n, 0, std2wx((*hi)[0]) );
162 // grid->SetReadOnly( n, 0 );
164 // grid->Add( new wxStaticLine(this,-1));
165 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi)
167 grid->Add( new wxStaticText(this,-1,
169 grid->Add( new wxStaticText(this,-1,
171 grid->Add( new wxStaticText(this,-1,
174 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi)
176 grid->Add( new wxStaticText(this,-1,
178 grid->Add( new wxStaticText(this,-1,
180 grid->Add( new wxStaticText(this,-1,
184 inputs->Add(grid,0,wxGROW);
185 sizer->Add(inputs,0,wxGROW);
188 user_defined.clear();
190 wxbb_defined.clear();
191 const BlackBoxDescriptor::OutputDescriptorMapType& omap =
192 descr->GetOutputDescriptorMap();
193 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator out;
194 for ( out = omap.begin(); out != omap.end(); ++out )
196 // Skips system-defined inputs
197 std::string col(usercol);
199 if (out->second->GetCreatorTypeInfo() ==
200 typeid(AtomicBlackBoxDescriptor))
205 else if (out->second->GetCreatorTypeInfo() ==
206 typeid(WxBlackBoxDescriptor))
212 std::string name(out->second->GetName());
213 //Utilities::html_format(name);
215 std::string type("<");
216 type += out->second->GetTypeName();
218 //Utilities::html_format(type);
220 std::string descr(out->second->GetDescription());
221 //Utilities::html_format(descr);
223 std::vector<std::string> out;
226 out.push_back(descr);
228 if (iotype==0) user_defined.push_back(out);
229 else if (iotype==1) ubb_defined.push_back(out);
230 else if (iotype==2) wxbb_defined.push_back(out);
234 wxBoxSizer *outputs =
236 ( new wxStaticBox(this, wxID_ANY, _T("Outputs")), wxVERTICAL );
237 wxFlexGridSizer* ogrid = new wxFlexGridSizer(3);
241 for (hi=user_defined.begin();hi!=user_defined.end();++hi)
243 ogrid->Add( new wxStaticText(this,-1,
245 ogrid->Add( new wxStaticText(this,-1,
247 ogrid->Add( new wxStaticText(this,-1,
249 // grid->SetCellValue( n, 0, std2wx((*hi)[0]) );
250 // grid->SetReadOnly( n, 0 );
252 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi)
254 ogrid->Add( new wxStaticText(this,-1,
256 ogrid->Add( new wxStaticText(this,-1,
258 ogrid->Add( new wxStaticText(this,-1,
261 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi)
263 ogrid->Add( new wxStaticText(this,-1,
265 ogrid->Add( new wxStaticText(this,-1,
267 ogrid->Add( new wxStaticText(this,-1,
271 outputs->Add(ogrid,0,wxGROW);
272 sizer->Add(outputs,0,wxGROW);
279 //================================================================
282 //================================================================
283 WxGUIPackageBrowserBlackBox::~WxGUIPackageBrowserBlackBox()
286 //================================================================
289 //================================================================
290 WxGUIPackageBrowser::WxGUIPackageBrowser( wxWindow *parent,
291 WxGUIPackageBrowserUser* user )
292 : wxPanel(parent, -1),
297 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
298 mTree = new wxTreeMultiCtrl(this, -1);
300 mTree->SetBackgroundColour(*wxWHITE);
301 sizer->Add(mTree,1,wxGROW);
304 wxTreeMultiWindowInfo wndinfo(wxTMC_BG_ADJUST_CNT, 8, 0);
306 wxTreeMultiWindowInfo wndinfo(wxTMC_BG_ADJUST_ALL, 8, 0);
309 // make it a bit bigger
311 somefont = mTree->GetCaptionFont();
312 somefont.SetFamily(wxMODERN);
313 somefont.SetWeight(wxBOLD);
314 somefont.SetPointSize(somefont.GetPointSize()+1);
315 mTree->SetCaptionFont(somefont);
317 mTree->SetSpacingY(1);
318 // mTree->SetCheckboxView(true);
325 //================================================================
327 //================================================================
328 WxGUIPackageBrowser::~WxGUIPackageBrowser()
330 // std::cout << "del interpreter" << std::endl;
331 // if (mInterpreter) delete mInterpreter;
332 // std::cout << "ok" << std::endl;
334 //================================================================
336 //================================================================
337 void WxGUIPackageBrowser::IncludeAll()
339 if (!mInterpreter) mInterpreter = bbtk::Interpreter::New();
340 mInterpreter->SetCommandLine(true);
341 mInterpreter->InterpretLine("include *");
343 Factory::Pointer F = mInterpreter->GetExecuter()->GetFactory();
346 //================================================================
347 //================================================================
349 void WxGUIPackageBrowser::BuildFromFactory(Factory::Pointer F)
352 wxTreeMultiWindowInfo wndinfo(wxTMC_BG_ADJUST_CNT, 8, 0);
354 wxTreeMultiWindowInfo wndinfo(wxTMC_BG_ADJUST_ALL, 8, 0);
356 mTree->DeleteAllItems();
357 const Factory::PackageMapType& M = F->GetPackageMap();
358 Factory::PackageMapType::const_iterator i;
359 for (i=M.begin();i!=M.end();++i)
361 Package::Pointer P = i->second;
362 wxString packname = std2wx(P->GetName());
363 if (packname==_T("user")) continue;
364 wxTreeMultiItem pack = mTree->AddRoot(packname,packname);
366 wxString packinfo = std2wx(P->GetDescription());
367 packinfo += _T(" - by ")+ std2wx(P->GetAuthor());
368 packinfo += _T(" - v. ")+ std2wx(P->GetVersion());
369 mTree->AppendWindow(pack,
370 new wxStaticText(mTree,
372 Package::BlackBoxMapType::iterator j;
373 for (j=P->GetBlackBoxMap().begin();
374 j!=P->GetBlackBoxMap().end();
377 wxString boxname = std2wx(j->second->GetTypeName());
378 wxTreeMultiItem box = mTree->AppendNode(pack,boxname,boxname);
379 WxGUIPackageBrowserBlackBox* boxdescr
380 = new WxGUIPackageBrowserBlackBox(mTree,this,j->second);
381 mTree->AppendWindow(box, boxdescr, _T(""),
382 wndinfo, wxTMC_SPAN_WIDTH);
386 mTree->CollapseNodes(true);
389 wxTreeMultiItem item = mTree->FindItem(_T("Add"));
390 if(item.IsOk()) mTree->Exclude(item);
392 //================================================================
394 //================================================================
395 WxGUIPackageBrowserWindow::WxGUIPackageBrowserWindow( wxWindow *parent,
398 : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
402 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
404 mBrowser = new WxGUIPackageBrowser(this);
405 mBrowser->IncludeAll();
406 sizer->Add(mBrowser,1,wxGROW);
408 // WxGUICommand* com = new WxGUICommand(this,this);
414 // Creates the parent window of all bbtk windows as a child of this
415 Wx::CreateTopWindow(this);
416 // bbtkAddWxObserver(WxGUIConsole::OnWxSignal);
422 //================================================================
424 //================================================================
425 WxGUIPackageBrowserWindow::~WxGUIPackageBrowserWindow()
428 //================================================================
433 #endif //_USE_WXWIDGETS_