1 /*=========================================================================
3 Module: $RCSfile: bbtkWxGUIPackageBrowser.cxx,v $
5 Date: $Date: 2008/10/17 08:18:15 $
6 Version: $Revision: 1.7 $
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
33 * \brief Short description in one line
35 * Long description which
36 * can span multiple lines
48 #ifdef _USE_WXWIDGETS_
50 #define CHECKBOXVIEW 1
52 #include "bbtkWxGUIPackageBrowser.h"
53 #include "ThirdParty/wx/treemultictrl/wxTreeMultiCtrl.h"
54 #include "bbtkInterpreter.h"
55 #include "bbtkBlackBoxInputDescriptor.h"
56 #include "bbtkBlackBoxOutputDescriptor.h"
57 #include "bbtkWxBlackBox.h"
59 #include <wx/statline.h>
64 //================================================================
65 WxGUIPackageBrowserBlackBox::
66 WxGUIPackageBrowserBlackBox(wxWindow* parent,
67 WxGUIPackageBrowser* browser,
68 BlackBoxDescriptor::Pointer descr) :
73 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
75 wxStaticText* s = new wxStaticText(this,-1,
76 std2wx(descr->GetDescription()));
77 sizer->Add(s,0,wxGROW);
78 s = new wxStaticText(this,-1,
79 std2wx(descr->GetAuthor()));
80 sizer->Add(s,0,wxGROW);
81 s = new wxStaticText(this,-1,
82 std2wx(descr->GetCategory()));
83 sizer->Add(s,0,wxGROW);
85 std::vector<std::vector<std::string> > user_defined;
86 std::vector<std::vector<std::string> > ubb_defined;
87 std::vector<std::vector<std::string> > wxbb_defined;
89 std::string titlecol("#BBBBFF");
90 std::string usercol("#FFFFFF");
91 std::string ubbcol("#DDFFFF");
92 std::string wxbbcol("#EEFFFF");
94 const BlackBoxDescriptor::InputDescriptorMapType& imap =
95 descr->GetInputDescriptorMap();
96 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
97 for ( in = imap.begin(); in != imap.end(); ++in )
99 // Skips system-defined inputs
100 std::string col(usercol);
102 if (in->second->GetCreatorTypeInfo() ==
103 typeid(AtomicBlackBoxDescriptor))
108 else if (in->second->GetCreatorTypeInfo() ==
109 typeid(WxBlackBoxDescriptor))
115 std::string name(in->second->GetName());
116 //Utilities::html_format(name);
118 std::string type("<");
119 type += in->second->GetTypeName();
121 //Utilities::html_format(type);
123 std::string descr(in->second->GetDescription());
124 //Utilities::html_format(descr);
126 std::vector<std::string> out;
129 out.push_back(descr);
131 if (iotype==0) user_defined.push_back(out);
132 else if (iotype==1) ubb_defined.push_back(out);
133 else if (iotype==2) wxbb_defined.push_back(out);
140 ( new wxStaticBox(this, wxID_ANY, _T("Inputs")), wxVERTICAL );
141 wxFlexGridSizer* grid = new wxFlexGridSizer(3);
143 wxTextAttr ionameattr(*wxRED,*wxBLACK);
144 wxTextAttr iotypeattr(*wxBLACK,*wxRED);
147 std::vector<std::vector<std::string> >::iterator hi;
148 for (hi=user_defined.begin();hi!=user_defined.end();++hi)
151 grid->Add( new wxStaticText(this,-1,std2wx((*hi)[0])));
152 grid->Add( new wxStaticText(this,-1,std2wx((*hi)[1])));
153 grid->Add( new wxStaticText(this,-1,std2wx((*hi)[2])));
154 // grid->SetCellValue( n, 0, std2wx((*hi)[0]) );
155 // grid->SetReadOnly( n, 0 );
157 // grid->Add( new wxStaticLine(this,-1));
158 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi)
160 grid->Add( new wxStaticText(this,-1,
162 grid->Add( new wxStaticText(this,-1,
164 grid->Add( new wxStaticText(this,-1,
167 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi)
169 grid->Add( new wxStaticText(this,-1,
171 grid->Add( new wxStaticText(this,-1,
173 grid->Add( new wxStaticText(this,-1,
177 inputs->Add(grid,0,wxGROW);
178 sizer->Add(inputs,0,wxGROW);
181 user_defined.clear();
183 wxbb_defined.clear();
184 const BlackBoxDescriptor::OutputDescriptorMapType& omap =
185 descr->GetOutputDescriptorMap();
186 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator out;
187 for ( out = omap.begin(); out != omap.end(); ++out )
189 // Skips system-defined inputs
190 std::string col(usercol);
192 if (out->second->GetCreatorTypeInfo() ==
193 typeid(AtomicBlackBoxDescriptor))
198 else if (out->second->GetCreatorTypeInfo() ==
199 typeid(WxBlackBoxDescriptor))
205 std::string name(out->second->GetName());
206 //Utilities::html_format(name);
208 std::string type("<");
209 type += out->second->GetTypeName();
211 //Utilities::html_format(type);
213 std::string descr(out->second->GetDescription());
214 //Utilities::html_format(descr);
216 std::vector<std::string> out;
219 out.push_back(descr);
221 if (iotype==0) user_defined.push_back(out);
222 else if (iotype==1) ubb_defined.push_back(out);
223 else if (iotype==2) wxbb_defined.push_back(out);
227 wxBoxSizer *outputs =
229 ( new wxStaticBox(this, wxID_ANY, _T("Outputs")), wxVERTICAL );
230 wxFlexGridSizer* ogrid = new wxFlexGridSizer(3);
234 for (hi=user_defined.begin();hi!=user_defined.end();++hi)
236 ogrid->Add( new wxStaticText(this,-1,
238 ogrid->Add( new wxStaticText(this,-1,
240 ogrid->Add( new wxStaticText(this,-1,
242 // grid->SetCellValue( n, 0, std2wx((*hi)[0]) );
243 // grid->SetReadOnly( n, 0 );
245 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi)
247 ogrid->Add( new wxStaticText(this,-1,
249 ogrid->Add( new wxStaticText(this,-1,
251 ogrid->Add( new wxStaticText(this,-1,
254 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi)
256 ogrid->Add( new wxStaticText(this,-1,
258 ogrid->Add( new wxStaticText(this,-1,
260 ogrid->Add( new wxStaticText(this,-1,
264 outputs->Add(ogrid,0,wxGROW);
265 sizer->Add(outputs,0,wxGROW);
272 //================================================================
275 //================================================================
276 WxGUIPackageBrowserBlackBox::~WxGUIPackageBrowserBlackBox()
279 //================================================================
282 //================================================================
283 WxGUIPackageBrowser::WxGUIPackageBrowser( wxWindow *parent,
284 WxGUIPackageBrowserUser* user )
285 : wxPanel(parent, -1),
290 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
291 mTree = new wxTreeMultiCtrl(this, -1);
293 mTree->SetBackgroundColour(*wxWHITE);
294 sizer->Add(mTree,1,wxGROW);
297 wxTreeMultiWindowInfo wndinfo(wxTMC_BG_ADJUST_CNT, 8, 0);
299 wxTreeMultiWindowInfo wndinfo(wxTMC_BG_ADJUST_ALL, 8, 0);
302 // make it a bit bigger
304 somefont = mTree->GetCaptionFont();
305 somefont.SetFamily(wxMODERN);
306 somefont.SetWeight(wxBOLD);
307 somefont.SetPointSize(somefont.GetPointSize()+1);
308 mTree->SetCaptionFont(somefont);
310 mTree->SetSpacingY(1);
311 // mTree->SetCheckboxView(true);
318 //================================================================
320 //================================================================
321 WxGUIPackageBrowser::~WxGUIPackageBrowser()
323 // std::cout << "del interpreter" << std::endl;
324 // if (mInterpreter) delete mInterpreter;
325 // std::cout << "ok" << std::endl;
327 //================================================================
329 //================================================================
330 void WxGUIPackageBrowser::IncludeAll()
332 if (!mInterpreter) mInterpreter = bbtk::Interpreter::New();
333 mInterpreter->SetCommandLine(true);
334 mInterpreter->InterpretLine("include *");
336 Factory::Pointer F = mInterpreter->GetExecuter()->GetFactory();
339 //================================================================
340 //================================================================
342 void WxGUIPackageBrowser::BuildFromFactory(Factory::Pointer F)
345 wxTreeMultiWindowInfo wndinfo(wxTMC_BG_ADJUST_CNT, 8, 0);
347 wxTreeMultiWindowInfo wndinfo(wxTMC_BG_ADJUST_ALL, 8, 0);
349 mTree->DeleteAllItems();
350 const Factory::PackageMapType& M = F->GetPackageMap();
351 Factory::PackageMapType::const_iterator i;
352 for (i=M.begin();i!=M.end();++i)
354 Package::Pointer P = i->second;
355 wxString packname = std2wx(P->GetName());
356 if (packname==_T("user")) continue;
357 wxTreeMultiItem pack = mTree->AddRoot(packname,packname);
359 wxString packinfo = std2wx(P->GetDescription());
360 packinfo += _T(" - by ")+ std2wx(P->GetAuthor());
361 packinfo += _T(" - v. ")+ std2wx(P->GetVersion());
362 mTree->AppendWindow(pack,
363 new wxStaticText(mTree,
365 Package::BlackBoxMapType::iterator j;
366 for (j=P->GetBlackBoxMap().begin();
367 j!=P->GetBlackBoxMap().end();
370 wxString boxname = std2wx(j->second->GetTypeName());
371 wxTreeMultiItem box = mTree->AppendNode(pack,boxname,boxname);
372 WxGUIPackageBrowserBlackBox* boxdescr
373 = new WxGUIPackageBrowserBlackBox(mTree,this,j->second);
374 mTree->AppendWindow(box, boxdescr, _T(""),
375 wndinfo, wxTMC_SPAN_WIDTH);
379 mTree->CollapseNodes(true);
382 wxTreeMultiItem item = mTree->FindItem(_T("Add"));
383 if(item.IsOk()) mTree->Exclude(item);
385 //================================================================
387 //================================================================
388 WxGUIPackageBrowserWindow::WxGUIPackageBrowserWindow( wxWindow *parent,
391 : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
395 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
397 mBrowser = new WxGUIPackageBrowser(this);
398 mBrowser->IncludeAll();
399 sizer->Add(mBrowser,1,wxGROW);
401 // WxGUICommand* com = new WxGUICommand(this,this);
407 // Creates the parent window of all bbtk windows as a child of this
408 Wx::CreateTopWindow(this);
409 // bbtkAddWxObserver(WxGUIConsole::OnWxSignal);
415 //================================================================
417 //================================================================
418 WxGUIPackageBrowserWindow::~WxGUIPackageBrowserWindow()
421 //================================================================
426 #endif //_USE_WXWIDGETS_