1 /*=========================================================================
4 Module: $RCSfile: bbtkWxGUIPackageBrowser.cxx,v $
6 Date: $Date: 2008/04/24 13:56:34 $
7 Version: $Revision: 1.6 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*//**
18 * \brief Short description in one line
20 * Long description which
21 * can span multiple lines
33 #ifdef _USE_WXWIDGETS_
35 #define CHECKBOXVIEW 1
37 #include "bbtkWxGUIPackageBrowser.h"
38 #include "ThirdParty/wx/treemultictrl/wxTreeMultiCtrl.h"
39 #include "bbtkInterpreter.h"
40 #include "bbtkBlackBoxInputDescriptor.h"
41 #include "bbtkBlackBoxOutputDescriptor.h"
42 #include "bbtkWxBlackBox.h"
44 #include <wx/statline.h>
49 //================================================================
50 WxGUIPackageBrowserBlackBox::
51 WxGUIPackageBrowserBlackBox(wxWindow* parent,
52 WxGUIPackageBrowser* browser,
53 BlackBoxDescriptor::Pointer descr) :
58 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
60 wxStaticText* s = new wxStaticText(this,-1,
61 std2wx(descr->GetDescription()));
62 sizer->Add(s,0,wxGROW);
63 s = new wxStaticText(this,-1,
64 std2wx(descr->GetAuthor()));
65 sizer->Add(s,0,wxGROW);
66 s = new wxStaticText(this,-1,
67 std2wx(descr->GetCategory()));
68 sizer->Add(s,0,wxGROW);
70 std::vector<std::vector<std::string> > user_defined;
71 std::vector<std::vector<std::string> > ubb_defined;
72 std::vector<std::vector<std::string> > wxbb_defined;
74 std::string titlecol("#BBBBFF");
75 std::string usercol("#FFFFFF");
76 std::string ubbcol("#DDFFFF");
77 std::string wxbbcol("#EEFFFF");
79 const BlackBoxDescriptor::InputDescriptorMapType& imap =
80 descr->GetInputDescriptorMap();
81 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
82 for ( in = imap.begin(); in != imap.end(); ++in )
84 // Skips system-defined inputs
85 std::string col(usercol);
87 if (in->second->GetCreatorTypeInfo() ==
88 typeid(AtomicBlackBoxDescriptor))
93 else if (in->second->GetCreatorTypeInfo() ==
94 typeid(WxBlackBoxDescriptor))
100 std::string name(in->second->GetName());
101 //Utilities::html_format(name);
103 std::string type("<");
104 type += in->second->GetTypeName();
106 //Utilities::html_format(type);
108 std::string descr(in->second->GetDescription());
109 //Utilities::html_format(descr);
111 std::vector<std::string> out;
114 out.push_back(descr);
116 if (iotype==0) user_defined.push_back(out);
117 else if (iotype==1) ubb_defined.push_back(out);
118 else if (iotype==2) wxbb_defined.push_back(out);
125 ( new wxStaticBox(this, wxID_ANY, _T("Inputs")), wxVERTICAL );
126 wxFlexGridSizer* grid = new wxFlexGridSizer(3);
128 wxTextAttr ionameattr(*wxRED,*wxBLACK);
129 wxTextAttr iotypeattr(*wxBLACK,*wxRED);
132 std::vector<std::vector<std::string> >::iterator hi;
133 for (hi=user_defined.begin();hi!=user_defined.end();++hi)
136 grid->Add( new wxStaticText(this,-1,std2wx((*hi)[0])));
137 grid->Add( new wxStaticText(this,-1,std2wx((*hi)[1])));
138 grid->Add( new wxStaticText(this,-1,std2wx((*hi)[2])));
139 // grid->SetCellValue( n, 0, std2wx((*hi)[0]) );
140 // grid->SetReadOnly( n, 0 );
142 // grid->Add( new wxStaticLine(this,-1));
143 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi)
145 grid->Add( new wxStaticText(this,-1,
147 grid->Add( new wxStaticText(this,-1,
149 grid->Add( new wxStaticText(this,-1,
152 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi)
154 grid->Add( new wxStaticText(this,-1,
156 grid->Add( new wxStaticText(this,-1,
158 grid->Add( new wxStaticText(this,-1,
162 inputs->Add(grid,0,wxGROW);
163 sizer->Add(inputs,0,wxGROW);
166 user_defined.clear();
168 wxbb_defined.clear();
169 const BlackBoxDescriptor::OutputDescriptorMapType& omap =
170 descr->GetOutputDescriptorMap();
171 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator out;
172 for ( out = omap.begin(); out != omap.end(); ++out )
174 // Skips system-defined inputs
175 std::string col(usercol);
177 if (out->second->GetCreatorTypeInfo() ==
178 typeid(AtomicBlackBoxDescriptor))
183 else if (out->second->GetCreatorTypeInfo() ==
184 typeid(WxBlackBoxDescriptor))
190 std::string name(out->second->GetName());
191 //Utilities::html_format(name);
193 std::string type("<");
194 type += out->second->GetTypeName();
196 //Utilities::html_format(type);
198 std::string descr(out->second->GetDescription());
199 //Utilities::html_format(descr);
201 std::vector<std::string> out;
204 out.push_back(descr);
206 if (iotype==0) user_defined.push_back(out);
207 else if (iotype==1) ubb_defined.push_back(out);
208 else if (iotype==2) wxbb_defined.push_back(out);
212 wxBoxSizer *outputs =
214 ( new wxStaticBox(this, wxID_ANY, _T("Outputs")), wxVERTICAL );
215 wxFlexGridSizer* ogrid = new wxFlexGridSizer(3);
219 for (hi=user_defined.begin();hi!=user_defined.end();++hi)
221 ogrid->Add( new wxStaticText(this,-1,
223 ogrid->Add( new wxStaticText(this,-1,
225 ogrid->Add( new wxStaticText(this,-1,
227 // grid->SetCellValue( n, 0, std2wx((*hi)[0]) );
228 // grid->SetReadOnly( n, 0 );
230 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi)
232 ogrid->Add( new wxStaticText(this,-1,
234 ogrid->Add( new wxStaticText(this,-1,
236 ogrid->Add( new wxStaticText(this,-1,
239 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi)
241 ogrid->Add( new wxStaticText(this,-1,
243 ogrid->Add( new wxStaticText(this,-1,
245 ogrid->Add( new wxStaticText(this,-1,
249 outputs->Add(ogrid,0,wxGROW);
250 sizer->Add(outputs,0,wxGROW);
257 //================================================================
260 //================================================================
261 WxGUIPackageBrowserBlackBox::~WxGUIPackageBrowserBlackBox()
264 //================================================================
267 //================================================================
268 WxGUIPackageBrowser::WxGUIPackageBrowser( wxWindow *parent,
269 WxGUIPackageBrowserUser* user )
270 : wxPanel(parent, -1),
275 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
276 mTree = new wxTreeMultiCtrl(this, -1);
278 mTree->SetBackgroundColour(*wxWHITE);
279 sizer->Add(mTree,1,wxGROW);
282 wxTreeMultiWindowInfo wndinfo(wxTMC_BG_ADJUST_CNT, 8, 0);
284 wxTreeMultiWindowInfo wndinfo(wxTMC_BG_ADJUST_ALL, 8, 0);
287 // make it a bit bigger
289 somefont = mTree->GetCaptionFont();
290 somefont.SetFamily(wxMODERN);
291 somefont.SetWeight(wxBOLD);
292 somefont.SetPointSize(somefont.GetPointSize()+1);
293 mTree->SetCaptionFont(somefont);
295 mTree->SetSpacingY(1);
296 // mTree->SetCheckboxView(true);
303 //================================================================
305 //================================================================
306 WxGUIPackageBrowser::~WxGUIPackageBrowser()
308 // std::cout << "del interpreter" << std::endl;
309 // if (mInterpreter) delete mInterpreter;
310 // std::cout << "ok" << std::endl;
312 //================================================================
314 //================================================================
315 void WxGUIPackageBrowser::IncludeAll()
317 if (!mInterpreter) mInterpreter = bbtk::Interpreter::New();
318 mInterpreter->SetCommandLine(true);
319 mInterpreter->InterpretLine("include *");
321 Factory::Pointer F = mInterpreter->GetExecuter()->GetFactory();
324 //================================================================
325 //================================================================
327 void WxGUIPackageBrowser::BuildFromFactory(Factory::Pointer F)
330 wxTreeMultiWindowInfo wndinfo(wxTMC_BG_ADJUST_CNT, 8, 0);
332 wxTreeMultiWindowInfo wndinfo(wxTMC_BG_ADJUST_ALL, 8, 0);
334 mTree->DeleteAllItems();
335 const Factory::PackageMapType& M = F->GetPackageMap();
336 Factory::PackageMapType::const_iterator i;
337 for (i=M.begin();i!=M.end();++i)
339 Package::Pointer P = i->second;
340 wxString packname = std2wx(P->GetName());
341 if (packname==_T("user")) continue;
342 wxTreeMultiItem pack = mTree->AddRoot(packname,packname);
344 wxString packinfo = std2wx(P->GetDescription());
345 packinfo += _T(" - by ")+ std2wx(P->GetAuthor());
346 packinfo += _T(" - v. ")+ std2wx(P->GetVersion());
347 mTree->AppendWindow(pack,
348 new wxStaticText(mTree,
350 Package::BlackBoxMapType::iterator j;
351 for (j=P->GetBlackBoxMap().begin();
352 j!=P->GetBlackBoxMap().end();
355 wxString boxname = std2wx(j->second->GetTypeName());
356 wxTreeMultiItem box = mTree->AppendNode(pack,boxname,boxname);
357 WxGUIPackageBrowserBlackBox* boxdescr
358 = new WxGUIPackageBrowserBlackBox(mTree,this,j->second);
359 mTree->AppendWindow(box, boxdescr, _T(""),
360 wndinfo, wxTMC_SPAN_WIDTH);
364 mTree->CollapseNodes(true);
367 wxTreeMultiItem item = mTree->FindItem(_T("Add"));
368 if(item.IsOk()) mTree->Exclude(item);
370 //================================================================
372 //================================================================
373 WxGUIPackageBrowserWindow::WxGUIPackageBrowserWindow( wxWindow *parent,
376 : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
380 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
382 mBrowser = new WxGUIPackageBrowser(this);
383 mBrowser->IncludeAll();
384 sizer->Add(mBrowser,1,wxGROW);
386 // WxGUICommand* com = new WxGUICommand(this,this);
392 // Creates the parent window of all bbtk windows as a child of this
393 Wx::CreateTopWindow(this);
394 // bbtkAddWxObserver(WxGUIConsole::OnWxSignal);
400 //================================================================
402 //================================================================
403 WxGUIPackageBrowserWindow::~WxGUIPackageBrowserWindow()
406 //================================================================
411 #endif //_USE_WXWIDGETS_