1 /*=========================================================================
4 Module: $RCSfile: bbtkWxGUIPackageBrowser.cxx,v $
6 Date: $Date: 2008/04/24 10:11:28 $
7 Version: $Revision: 1.5 $
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 "<TR><TD style='vertical-align: top;' bgcolor=\"" + col
117 +"\"><B><PRE> "+name+" </PRE></B></TD>"
118 + "<TD style='vertical-align: top;' bgcolor=\""+col
119 +"\"><I><PRE> "+type+" </PRE></I></TD>"
120 + "<TD style='vertical-align: top;' bgcolor=\""+col
121 +"\">"+descr+"</TD></TR>\n";
124 if (iotype==0) user_defined.push_back(out);
125 else if (iotype==1) ubb_defined.push_back(out);
126 else if (iotype==2) wxbb_defined.push_back(out);
133 ( new wxStaticBox(this, wxID_ANY, _T("Inputs")), wxVERTICAL );
134 wxFlexGridSizer* grid = new wxFlexGridSizer(3);
136 wxTextAttr ionameattr(*wxRED,*wxBLACK);
137 wxTextAttr iotypeattr(*wxBLACK,*wxRED);
140 std::vector<std::vector<std::string> >::iterator hi;
141 for (hi=user_defined.begin();hi!=user_defined.end();++hi)
144 wxTextCtrl* t = new wxTextCtrl(this,-1,_T("")
149 t->SetDefaultStyle(ionameattr);
150 t->AppendText( std2wx((*hi)[0]) );
153 t = new wxTextCtrl(this,-1,_T("")
158 t->SetDefaultStyle(iotypeattr);
159 t->AppendText( std2wx((*hi)[1]) );
163 grid->Add( new wxStaticText(this,-1,std2wx((*hi)[0])));
164 grid->Add( new wxStaticText(this,-1,std2wx((*hi)[1])));
165 grid->Add( new wxStaticText(this,-1,std2wx((*hi)[2])));
166 // grid->SetCellValue( n, 0, std2wx((*hi)[0]) );
167 // grid->SetReadOnly( n, 0 );
169 // grid->Add( new wxStaticLine(this,-1));
170 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi)
172 grid->Add( new wxStaticText(this,-1,
174 grid->Add( new wxStaticText(this,-1,
176 grid->Add( new wxStaticText(this,-1,
179 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi)
181 grid->Add( new wxStaticText(this,-1,
183 grid->Add( new wxStaticText(this,-1,
185 grid->Add( new wxStaticText(this,-1,
189 inputs->Add(grid,0,wxGROW);
190 sizer->Add(inputs,0,wxGROW);
193 user_defined.clear();
195 wxbb_defined.clear();
196 const BlackBoxDescriptor::OutputDescriptorMapType& omap =
197 descr->GetOutputDescriptorMap();
198 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator out;
199 for ( out = omap.begin(); out != omap.end(); ++out )
201 // Skips system-defined inputs
202 std::string col(usercol);
204 if (out->second->GetCreatorTypeInfo() ==
205 typeid(AtomicBlackBoxDescriptor))
210 else if (out->second->GetCreatorTypeInfo() ==
211 typeid(WxBlackBoxDescriptor))
217 std::string name(out->second->GetName());
218 //Utilities::html_format(name);
220 std::string type("<");
221 type += out->second->GetTypeName();
223 //Utilities::html_format(type);
225 std::string descr(out->second->GetDescription());
226 //Utilities::html_format(descr);
228 std::vector<std::string> out;
231 out.push_back(descr);
233 "<TR><TD style='vertical-align: top;' bgcolor=\"" + col
234 +"\"><B><PRE> "+name+" </PRE></B></TD>"
235 + "<TD style='vertical-align: top;' bgcolor=\""+col
236 +"\"><I><PRE> "+type+" </PRE></I></TD>"
237 + "<TD style='vertical-align: top;' bgcolor=\""+col
238 +"\">"+descr+"</TD></TR>\n";
241 if (iotype==0) user_defined.push_back(out);
242 else if (iotype==1) ubb_defined.push_back(out);
243 else if (iotype==2) wxbb_defined.push_back(out);
247 wxBoxSizer *outputs =
249 ( new wxStaticBox(this, wxID_ANY, _T("Outputs")), wxVERTICAL );
250 wxFlexGridSizer* ogrid = new wxFlexGridSizer(3);
254 for (hi=user_defined.begin();hi!=user_defined.end();++hi)
256 ogrid->Add( new wxStaticText(this,-1,
258 ogrid->Add( new wxStaticText(this,-1,
260 ogrid->Add( new wxStaticText(this,-1,
262 // grid->SetCellValue( n, 0, std2wx((*hi)[0]) );
263 // grid->SetReadOnly( n, 0 );
265 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi)
267 ogrid->Add( new wxStaticText(this,-1,
269 ogrid->Add( new wxStaticText(this,-1,
271 ogrid->Add( new wxStaticText(this,-1,
274 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi)
276 ogrid->Add( new wxStaticText(this,-1,
278 ogrid->Add( new wxStaticText(this,-1,
280 ogrid->Add( new wxStaticText(this,-1,
284 outputs->Add(ogrid,0,wxGROW);
285 sizer->Add(outputs,0,wxGROW);
292 //================================================================
295 //================================================================
296 WxGUIPackageBrowserBlackBox::~WxGUIPackageBrowserBlackBox()
299 //================================================================
302 //================================================================
303 WxGUIPackageBrowser::WxGUIPackageBrowser( wxWindow *parent,
304 WxGUIPackageBrowserUser* user )
305 : wxPanel(parent, -1),
310 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
311 mTree = new wxTreeMultiCtrl(this, -1);
313 mTree->SetBackgroundColour(*wxWHITE);
314 sizer->Add(mTree,1,wxGROW);
317 wxTreeMultiWindowInfo wndinfo(wxTMC_BG_ADJUST_CNT, 8, 0);
319 wxTreeMultiWindowInfo wndinfo(wxTMC_BG_ADJUST_ALL, 8, 0);
322 // make it a bit bigger
324 somefont = mTree->GetCaptionFont();
325 somefont.SetFamily(wxMODERN);
326 somefont.SetWeight(wxBOLD);
327 somefont.SetPointSize(somefont.GetPointSize()+1);
328 mTree->SetCaptionFont(somefont);
330 mTree->SetSpacingY(1);
331 // mTree->SetCheckboxView(true);
338 //================================================================
340 //================================================================
341 WxGUIPackageBrowser::~WxGUIPackageBrowser()
343 // std::cout << "del interpreter" << std::endl;
344 // if (mInterpreter) delete mInterpreter;
345 // std::cout << "ok" << std::endl;
347 //================================================================
349 //================================================================
350 void WxGUIPackageBrowser::IncludeAll()
352 if (!mInterpreter) mInterpreter = bbtk::Interpreter::New();
353 mInterpreter->SetCommandLine(true);
354 mInterpreter->InterpretLine("include *");
356 Factory::Pointer F = mInterpreter->GetExecuter()->GetFactory();
359 //================================================================
360 //================================================================
362 void WxGUIPackageBrowser::BuildFromFactory(Factory::Pointer F)
365 wxTreeMultiWindowInfo wndinfo(wxTMC_BG_ADJUST_CNT, 8, 0);
367 wxTreeMultiWindowInfo wndinfo(wxTMC_BG_ADJUST_ALL, 8, 0);
369 mTree->DeleteAllItems();
370 const Factory::PackageMapType& M = F->GetPackageMap();
371 Factory::PackageMapType::const_iterator i;
372 for (i=M.begin();i!=M.end();++i)
374 Package::Pointer P = i->second;
375 wxString packname = std2wx(P->GetName());
376 if (packname==_T("user")) continue;
377 wxTreeMultiItem pack = mTree->AddRoot(packname,packname);
379 wxString packinfo = std2wx(P->GetDescription());
380 packinfo += _T(" - by ")+ std2wx(P->GetAuthor());
381 packinfo += _T(" - v. ")+ std2wx(P->GetVersion());
382 mTree->AppendWindow(pack,
383 new wxStaticText(mTree,
385 Package::BlackBoxMapType::iterator j;
386 for (j=P->GetBlackBoxMap().begin();
387 j!=P->GetBlackBoxMap().end();
390 wxString boxname = std2wx(j->second->GetTypeName());
391 wxTreeMultiItem box = mTree->AppendNode(pack,boxname,boxname);
392 WxGUIPackageBrowserBlackBox* boxdescr
393 = new WxGUIPackageBrowserBlackBox(mTree,this,j->second);
394 mTree->AppendWindow(box, boxdescr, _T(""),
395 wndinfo, wxTMC_SPAN_WIDTH);
399 mTree->CollapseNodes(true);
402 wxTreeMultiItem item = mTree->FindItem(_T("Add"));
403 if(item.IsOk()) mTree->Exclude(item);
405 //================================================================
407 //================================================================
408 WxGUIPackageBrowserWindow::WxGUIPackageBrowserWindow( wxWindow *parent,
411 : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
415 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
417 mBrowser = new WxGUIPackageBrowser(this);
418 mBrowser->IncludeAll();
419 sizer->Add(mBrowser,1,wxGROW);
421 // WxGUICommand* com = new WxGUICommand(this,this);
427 // Creates the parent window of all bbtk windows as a child of this
428 Wx::CreateTopWindow(this);
429 // bbtkAddWxObserver(WxGUIConsole::OnWxSignal);
435 //================================================================
437 //================================================================
438 WxGUIPackageBrowserWindow::~WxGUIPackageBrowserWindow()
441 //================================================================
446 #endif //_USE_WXWIDGETS_