1 /*=========================================================================
4 Module: $RCSfile: bbtkWxGUIPackageBrowser.cxx,v $
6 Date: $Date: 2008/03/31 13:18:04 $
7 Version: $Revision: 1.3 $
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::WxGUIPackageBrowserBlackBox(wxWindow* parent,
51 WxGUIPackageBrowser* browser,
52 BlackBoxDescriptor* descr) :
57 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
59 wxStaticText* s = new wxStaticText(this,-1,
60 std2wx(descr->GetDescription()));
61 sizer->Add(s,0,wxGROW);
62 s = new wxStaticText(this,-1,
63 std2wx(descr->GetAuthor()));
64 sizer->Add(s,0,wxGROW);
65 s = new wxStaticText(this,-1,
66 std2wx(descr->GetCategory()));
67 sizer->Add(s,0,wxGROW);
69 std::vector<std::vector<std::string> > user_defined;
70 std::vector<std::vector<std::string> > ubb_defined;
71 std::vector<std::vector<std::string> > wxbb_defined;
73 std::string titlecol("#BBBBFF");
74 std::string usercol("#FFFFFF");
75 std::string ubbcol("#DDFFFF");
76 std::string wxbbcol("#EEFFFF");
78 const BlackBoxDescriptor::InputDescriptorMapType& imap =
79 descr->GetInputDescriptorMap();
80 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
81 for ( in = imap.begin(); in != imap.end(); ++in )
83 // Skips system-defined inputs
84 std::string col(usercol);
86 if (in->second->GetCreatorTypeInfo() ==
87 typeid(AtomicBlackBoxDescriptor))
92 else if (in->second->GetCreatorTypeInfo() ==
93 typeid(WxBlackBoxDescriptor))
99 std::string name(in->second->GetName());
100 //Utilities::html_format(name);
102 std::string type("<");
103 type += in->second->GetTypeName();
105 //Utilities::html_format(type);
107 std::string descr(in->second->GetDescription());
108 //Utilities::html_format(descr);
110 std::vector<std::string> out;
113 out.push_back(descr);
115 "<TR><TD style='vertical-align: top;' bgcolor=\"" + col
116 +"\"><B><PRE> "+name+" </PRE></B></TD>"
117 + "<TD style='vertical-align: top;' bgcolor=\""+col
118 +"\"><I><PRE> "+type+" </PRE></I></TD>"
119 + "<TD style='vertical-align: top;' bgcolor=\""+col
120 +"\">"+descr+"</TD></TR>\n";
123 if (iotype==0) user_defined.push_back(out);
124 else if (iotype==1) ubb_defined.push_back(out);
125 else if (iotype==2) wxbb_defined.push_back(out);
132 ( new wxStaticBox(this, wxID_ANY, _T("Inputs")), wxVERTICAL );
133 wxFlexGridSizer* grid = new wxFlexGridSizer(3);
135 wxTextAttr ionameattr(*wxRED,*wxBLACK);
136 wxTextAttr iotypeattr(*wxBLACK,*wxRED);
139 std::vector<std::vector<std::string> >::iterator hi;
140 for (hi=user_defined.begin();hi!=user_defined.end();++hi)
143 wxTextCtrl* t = new wxTextCtrl(this,-1,_T("")
148 t->SetDefaultStyle(ionameattr);
149 t->AppendText( std2wx((*hi)[0]) );
152 t = new wxTextCtrl(this,-1,_T("")
157 t->SetDefaultStyle(iotypeattr);
158 t->AppendText( std2wx((*hi)[1]) );
162 grid->Add( new wxStaticText(this,-1,std2wx((*hi)[0])));
163 grid->Add( new wxStaticText(this,-1,std2wx((*hi)[1])));
164 grid->Add( new wxStaticText(this,-1,std2wx((*hi)[2])));
165 // grid->SetCellValue( n, 0, std2wx((*hi)[0]) );
166 // grid->SetReadOnly( n, 0 );
168 // grid->Add( new wxStaticLine(this,-1));
169 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi)
171 grid->Add( new wxStaticText(this,-1,
173 grid->Add( new wxStaticText(this,-1,
175 grid->Add( new wxStaticText(this,-1,
178 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi)
180 grid->Add( new wxStaticText(this,-1,
182 grid->Add( new wxStaticText(this,-1,
184 grid->Add( new wxStaticText(this,-1,
188 inputs->Add(grid,0,wxGROW);
189 sizer->Add(inputs,0,wxGROW);
192 user_defined.clear();
194 wxbb_defined.clear();
195 const BlackBoxDescriptor::OutputDescriptorMapType& omap =
196 descr->GetOutputDescriptorMap();
197 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator out;
198 for ( out = omap.begin(); out != omap.end(); ++out )
200 // Skips system-defined inputs
201 std::string col(usercol);
203 if (out->second->GetCreatorTypeInfo() ==
204 typeid(AtomicBlackBoxDescriptor))
209 else if (out->second->GetCreatorTypeInfo() ==
210 typeid(WxBlackBoxDescriptor))
216 std::string name(out->second->GetName());
217 //Utilities::html_format(name);
219 std::string type("<");
220 type += out->second->GetTypeName();
222 //Utilities::html_format(type);
224 std::string descr(out->second->GetDescription());
225 //Utilities::html_format(descr);
227 std::vector<std::string> out;
230 out.push_back(descr);
232 "<TR><TD style='vertical-align: top;' bgcolor=\"" + col
233 +"\"><B><PRE> "+name+" </PRE></B></TD>"
234 + "<TD style='vertical-align: top;' bgcolor=\""+col
235 +"\"><I><PRE> "+type+" </PRE></I></TD>"
236 + "<TD style='vertical-align: top;' bgcolor=\""+col
237 +"\">"+descr+"</TD></TR>\n";
240 if (iotype==0) user_defined.push_back(out);
241 else if (iotype==1) ubb_defined.push_back(out);
242 else if (iotype==2) wxbb_defined.push_back(out);
246 wxBoxSizer *outputs =
248 ( new wxStaticBox(this, wxID_ANY, _T("Outputs")), wxVERTICAL );
249 wxFlexGridSizer* ogrid = new wxFlexGridSizer(3);
253 for (hi=user_defined.begin();hi!=user_defined.end();++hi)
255 ogrid->Add( new wxStaticText(this,-1,
257 ogrid->Add( new wxStaticText(this,-1,
259 ogrid->Add( new wxStaticText(this,-1,
261 // grid->SetCellValue( n, 0, std2wx((*hi)[0]) );
262 // grid->SetReadOnly( n, 0 );
264 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi)
266 ogrid->Add( new wxStaticText(this,-1,
268 ogrid->Add( new wxStaticText(this,-1,
270 ogrid->Add( new wxStaticText(this,-1,
273 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi)
275 ogrid->Add( new wxStaticText(this,-1,
277 ogrid->Add( new wxStaticText(this,-1,
279 ogrid->Add( new wxStaticText(this,-1,
283 outputs->Add(ogrid,0,wxGROW);
284 sizer->Add(outputs,0,wxGROW);
291 //================================================================
294 //================================================================
295 WxGUIPackageBrowserBlackBox::~WxGUIPackageBrowserBlackBox()
298 //================================================================
301 //================================================================
302 WxGUIPackageBrowser::WxGUIPackageBrowser( wxWindow *parent,
303 WxGUIPackageBrowserUser* user )
304 : wxPanel(parent, -1),
309 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
310 mTree = new wxTreeMultiCtrl(this, -1);
312 mTree->SetBackgroundColour(*wxWHITE);
313 sizer->Add(mTree,1,wxGROW);
316 wxTreeMultiWindowInfo wndinfo(wxTMC_BG_ADJUST_CNT, 8, 0);
318 wxTreeMultiWindowInfo wndinfo(wxTMC_BG_ADJUST_ALL, 8, 0);
321 // make it a bit bigger
323 somefont = mTree->GetCaptionFont();
324 somefont.SetFamily(wxMODERN);
325 somefont.SetWeight(wxBOLD);
326 somefont.SetPointSize(somefont.GetPointSize()+1);
327 mTree->SetCaptionFont(somefont);
329 mTree->SetSpacingY(1);
330 // mTree->SetCheckboxView(true);
337 //================================================================
339 //================================================================
340 WxGUIPackageBrowser::~WxGUIPackageBrowser()
342 std::cout << "del interpreter" << std::endl;
343 if (mInterpreter) delete mInterpreter;
344 std::cout << "ok" << std::endl;
346 //================================================================
348 //================================================================
349 void WxGUIPackageBrowser::IncludeAll()
351 if (!mInterpreter) mInterpreter = new bbtk::Interpreter();
352 mInterpreter->SetCommandLine(true);
353 mInterpreter->InterpretLine("include *");
355 Factory* F = mInterpreter->GetExecuter()->GetFactory();
358 //================================================================
359 //================================================================
361 void WxGUIPackageBrowser::BuildFromFactory(Factory* F)
364 wxTreeMultiWindowInfo wndinfo(wxTMC_BG_ADJUST_CNT, 8, 0);
366 wxTreeMultiWindowInfo wndinfo(wxTMC_BG_ADJUST_ALL, 8, 0);
368 mTree->DeleteAllItems();
369 const Factory::PackageMapType& M = F->GetPackageMap();
370 Factory::PackageMapType::const_iterator i;
371 for (i=M.begin();i!=M.end();++i)
373 Package* P = i->second.mPackage;
374 wxString packname = std2wx(P->GetName());
375 if (packname==_T("user")) continue;
376 wxTreeMultiItem pack = mTree->AddRoot(packname,packname);
378 wxString packinfo = std2wx(P->GetDescription());
379 packinfo += _T(" - by ")+ std2wx(P->GetAuthor());
380 packinfo += _T(" - v. ")+ std2wx(P->GetVersion());
381 mTree->AppendWindow(pack,
382 new wxStaticText(mTree,
384 Package::BlackBoxMapType::iterator j;
385 for (j=P->GetBlackBoxMap().begin();
386 j!=P->GetBlackBoxMap().end();
389 wxString boxname = std2wx(j->second->GetTypeName());
390 wxTreeMultiItem box = mTree->AppendNode(pack,boxname,boxname);
391 WxGUIPackageBrowserBlackBox* boxdescr
392 = new WxGUIPackageBrowserBlackBox(mTree,this,j->second);
393 mTree->AppendWindow(box, boxdescr, _T(""),
394 wndinfo, wxTMC_SPAN_WIDTH);
398 mTree->CollapseNodes(true);
401 wxTreeMultiItem item = mTree->FindItem(_T("Add"));
402 if(item.IsOk()) mTree->Exclude(item);
404 //================================================================
406 //================================================================
407 WxGUIPackageBrowserWindow::WxGUIPackageBrowserWindow( wxWindow *parent,
410 : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
414 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
416 mBrowser = new WxGUIPackageBrowser(this);
417 mBrowser->IncludeAll();
418 sizer->Add(mBrowser,1,wxGROW);
420 // WxGUICommand* com = new WxGUICommand(this,this);
425 // Creates and sets the parent window of all bbtk windows
426 wxWindow* top = new wxPanel(this,-1);
429 Wx::SetTopWindow(top);
434 //================================================================
436 //================================================================
437 WxGUIPackageBrowserWindow::~WxGUIPackageBrowserWindow()
440 //================================================================
445 #endif //_USE_WXWIDGETS_