]> Creatis software - bbtk.git/blob - kernel/doc/bbtkUsersGuide/bbtkUsersGuide.tex
8e539ee7f304ea7e427511a47dd5038a41b4b12a
[bbtk.git] / kernel / doc / bbtkUsersGuide / bbtkUsersGuide.tex
1 % ==========================================
2 \documentclass[11pt,final,a4paper]{article}
3 \input{config.tex}
4
5
6 \def\todo{\scriptsize\fbox{\bf TODO !!}\normalsize}
7 \def\x{\bm{x}}
8 \def\BBTK{{\xspace}The {\bf Black Box Toolkit} }
9 \def\bbtk{{\xspace}$\texttt{bbtk}$ }
10 \def\bbi{{\xspace}$\texttt{bbi}$ }
11 \def\bbStudio{{\xspace}$\texttt{bbStudio}$ }
12 \def\bbfy{{\xspace}$\texttt{bbfy}$ }
13 \def\bbdoc{{\xspace}$\texttt{bbdoc}$ }
14 \def\bbCreatePackage{{\xspace}$\texttt{bbCreatePackage}$ }
15
16 \def\bb{{\xspace}$\texttt{bb}$ }
17 %\def\bbp{{\xspace}$\texttt{bbp}$\xspace}
18
19 \def\cmake{{\xspace}$\texttt{cmake}$ }
20
21 \def\C{{\xspace}$\texttt{C}$ }
22 \def\CPP{{\xspace}$\texttt{C++}$ }
23
24 \def\xml{{\xspace}$\texttt{xml}$ }
25
26 \def\itk{{\xspace}$\texttt{itk}$ }
27 \def\vtk{{\xspace}$\texttt{vtk}$ }
28 \def\gdcm{{\xspace}$\texttt{gdcm}$ }
29 \def\gsmis{{\xspace}$\texttt{gsmis}$ }
30 \def\wx{{\xspace}$\texttt{wxWidgets}$ }
31
32 \def\lin{{\xspace}\textit{Linux} }
33 \def\win{{\xspace}\textit{Windows} }
34
35 % the same macros with no space at the end
36
37 \def\BBTKns{{\xspace}The {\bf Black Box Toolkit}}
38 \def\bbtkns{{\xspace}$\texttt{bbtk}$}
39 \def\bbins{{\xspace}$\texttt{bbi}$}
40 \def\bbfyns{{\xspace}$\texttt{bbfy}$}
41 \def\bbdocns{{\xspace}$\texttt{bbdoc}$}
42 \def\bbCreatePackagens{{\xspace}$\texttt{bbCreatePackage}$}
43
44 \def\bbns{{\xspace}$\texttt{bb}$}
45 %\def\bbp{{\xspace}$\texttt{bbp}$\xspace}
46
47 \def\cmakens{{\xspace}$\texttt{cmake}$}
48
49 \def\Cns{{\xspace}$\texttt{C}$}
50 \def\CPPns{{\xspace}$\texttt{C++}$}
51
52 \def\xmlns{{\xspace}$\texttt{xml}$}
53
54 \def\itkns{{\xspace}$\texttt{itk}$}
55 \def\vtkns{{\xspace}$\texttt{vtk}$}
56 \def\gdcmns{{\xspace}$\texttt{gdcm}$}
57 \def\gsmisns{{\xspace}$\texttt{gsmis}$}
58 \def\wxns{{\xspace}$\texttt{wxWidgets}$}
59
60 \def\linns{{\xspace}\textit{Linux}}
61 \def\winns{{\xspace}\textit{Windows}}
62
63
64
65
66 \begin{document}
67 \begin{center}
68
69 {\Large \BBTK}
70 \vspace{1cm}
71
72 {\Huge User's Guide}
73 \vspace{1cm}
74
75 \bbtk version 1.0
76 \vspace{0.5cm}
77
78
79 Last modified on : September 16, 2008 \\
80 Generated on : \today 
81 \vspace{0.5cm}
82
83 Laurent Guigues, Jean-Pierre Roux
84 \end{center}
85
86 % ==========================================
87 \tableofcontents
88 % ==========================================
89
90 \listoftables
91
92 \listoffigures
93
94
95
96 % ==========================================
97 %\section*{Abstract}
98 % ==========================================
99 \newpage
100 % ==========================================
101 \hrule
102 \section{What is {\bf bbtk} ?}
103 % ==========================================
104 \BBTK(\bbtkns) is a set of tools 
105 (\CPP libraries and executables) 
106 providing a \CPP framework for the definition 
107 of elementary processing \emph{units}, called {\bf black boxes}, 
108 and the definition and execution of processing \emph{chains} 
109 made up of these black boxes. \\
110 It's a part of the \texttt{Creatools suite} composed mainly of :
111 \begin{verbatim}
112  bbtk
113  creaContours
114  creaImageIO
115  creaLib
116  gdcm 
117 \end{verbatim}
118 which depend on the OpenSource libraries: 
119 \begin{verbatim}
120  itk
121  vtk
122  wxWidgets
123 \end{verbatim}
124
125 % ==========================================
126 \subsection{The black box philosophy}
127 % ==========================================
128
129 \href{http://www.answers.com/topic/black-box-theater}{The Answers Dictionary} defines a {\bf black box} as 
130 \emph{``A device or theoretical construct with known or specified performance characteristics 
131 but unknown or unspecified constituents and means of operation''} \\
132 \href{http://en.wikipedia.org/wiki/Black_box_\%28disambiguation\%29}{Wikipedia}
133 defines a {\bf black box} as 
134 \emph{``any component in a system in which only the input and output 
135 characteristics are of interest, without regard to its internal mechanism 
136 or structure''}. \\
137 We should merge theese definitions. : 
138 not only the inputs and outputs are of interest but also 
139 \emph{what the box does} !
140 Hence, I would say that a black box is any \emph{\bf documented} 
141 component of a system, letting the user know  
142 \emph{\bf what} the box is supposed to do and 
143 \emph{\bf how to use it}
144 but not \emph{\bf how it does it}. \\
145
146 \BBTK provides a systematic framework 
147 to encapsulate (or ``wrap'') any 
148 existing \texttt{C} or \CPP processing code into an object 
149 (a black box) having a {\bf generic symbolic interface}, where 
150
151 \begin{itemize}
152 \item{\bf generic} means that the interface is \emph{the same} 
153 for all boxes. Hence one does not need to know which particular 
154 method allows, say, to set a particular input or 
155 get a particular output of the box. 
156 One can use a black box in a purely abstract way. 
157 \item{\bf symbolic} means that a particular 
158 input or output is referenced by a 'name', that is by a symbol 
159 which identifies the input or output. 
160 It also means that symbolic information (text!) is 
161 attached to a box: description of the box, author, 
162 description of its inputs and outputs, etc.
163 \end{itemize}
164
165 (Actually, genericity is achieved because the interface is symbolic. 
166 We let you think about this\dots)
167
168 Of course, symbolic data attached to a box may be 
169 {\bf queried} : what are the inputs/outputs of the box ? 
170 what are their type ? their description ? etc.
171 This allows {\bf automatic documentation} of boxes. 
172
173 The abstract definition of black boxes is the most basic 
174 aspect of \BBTK architecture. 
175 Another key aspect is the groupement of black boxes into 
176 so called {\bf packages}, 
177 which are \emph{dynamic libraries} which can also 
178 be queried, in particular about the boxes they provide. 
179 The package structure then offers a mechanism which 
180 is like a \emph{'plug-in'} mechanism.
181 \BBTK provides the methods to load a package at run-time, 
182 and create instances of the boxes it contains. 
183
184 These two mechanisms (black boxes and packages) 
185 then gives the way to:
186
187 \begin{itemize}
188 \item The definition of an {\bf interpreted script language}, 
189 which allows to manipulate packages and boxes very easily in symbolic way. 
190 \BBTK provides one : \bbi (the Black Box Interpreter). 
191 \item {\bf Automatic documentation} of existing packages. 
192 \texttt{html} documentation of packages is proposed by 
193 \bbStudions.
194 \end{itemize}
195
196 Finally, these different components allow {\bf efficient} :
197
198 \begin{itemize}
199 \item {\bf capitalization and reuse} of existing processing units, 
200 including {\bf documentation} 
201 \item {\bf testing, prototyping} in a very simple script language
202 \item {\bf inter-operability} between atomic processings which 
203 have been written by different persons, using different libraries, etc. 
204 \end{itemize}
205
206 % ==========================================
207 \subsection{\bbtk components}
208 % ==========================================
209 \BBTK includes :
210 \begin{itemize}
211   \item A \CPP {\bf\emph{library}} - called \bbtk - which defines a framework 
212     (abstract classes) to develop black boxes and store them into 
213     dynamic libraries, called black box \emph{packages}.
214   \item Different {\bf\emph{black box packages}} :
215     \begin{itemize}
216       \item {\bf\emph{std}} : the 'standard' package including basic useful boxes.
217       \item {\bf\emph{wx}} : basic graphical interface elements (widgets : sliders, buttons, etc. based on the \texttt{wxWidgets} library).  
218       \item {\bf\emph{itk}} : the basic image processing package, based on the \itk library.
219       \item {\bf\emph{vtk}} : the basic images and surfaces processing and vizualization package, based on the \vtk library.
220       \item {\bf\emph{wxvtk}} : widget boxes based on the \vtk library (2D and 3D vizualization and
221       interaction).
222       %\item {\bf\emph{creaImageIO}} : Provides hight level widgets to read images, including DICOM.
223       \item {\bf\emph{toolsbbtk}} : Tools for bbtk administration and package development..      
224     \end{itemize}
225   \item A {\bf\emph{Developement environment}}, called \bbStudio, which provides
226     \begin{itemize}
227       \item An online {\bf\emph{script editor and interpretor}}
228       \item A powerfull html {\bf\emph{Help environment}},whith integrated :       
229         \begin{itemize}
230           \item Online documentation scaning
231           \item Retreiving boxes on various criterions
232           \item Checking Demo and examples
233         \end{itemize}
234       \end{itemize}
235       \item An standalone {\bf\emph{interpreter}}, called \bbins, which allows to 
236           load black box packages and to define and execute 
237           processing chains by connecting various black boxes.
238       \item {\bf\emph{Various Development Utilities}} :
239          \begin{itemize}
240             \item \bbfy generates the \CPP code of a black box from a 
241                description file written in \texttt{xml}.
242                 %\item \bbdoc generates the html documentation of a black box package 
243                 %(author, description, description of its black boxes : 
244                 %author, description, inputs, outputs, and so on).
245             \item \bbCreatePackage allows to create the basic file architecture 
246                to start the development of a new black box package.
247             \item \texttt{bbs2cpp} translates a \texttt{.bbs} script into a \CPP file.
248             \item \texttt{bbc} that               
249          \end{itemize}
250       \item A full {\bf\emph{documentation}} printable (pdf), browsable (html), queryable thru keywords.          
251 \end{itemize}
252 The general architecture of \BBTK 
253 is shown in figure \ref{bb-architecture}.
254
255 \begin{figure}[!ht]
256 \caption{\label{bb-architecture}\BBTK architecture}
257 \begin{center}
258 \includegraphics[width=0.6\textwidth]{bb-architecture.png}
259 \end{center}
260 \end{figure}
261
262 \newpage
263
264 % ==========================================
265 \section{Getting started with bbStudio}
266 % ==========================================
267
268 % ==========================================
269 % ==========================================
270 % ==========================================
271 % ==========================================
272 % ==========================================
273 % ==========================================
274
275 % ==========================================
276 \subsection{The interface}
277 % ==========================================
278
279
280 %\vspace{0.5cm}\hrule
281 %\section{The Development environment (bbStudio)}
282 %\label{bbStudio}
283
284 Just run it, typing in a console \bbStudio 
285 or clicking on its icon or its menu entry.
286 At start, \bbStudio opens with a very minimal 'How to use' in the middle. \\
287 Don't forget to read it : it will vanish at the first mouse click. \\
288 \begin{verbatim}
289 1) Click on the 'Demo' or 'Examples' link.
290 2) Select a Demo or an Example
291 3) Click on the [Source] link : the source file is loaded in bbStudio
292 4) Click on the 'Run button' (the down arrow at the bottom right
293    of the source file).
294 \end{verbatim}
295
296 You'll get something like in figure 
297 \ref{bbi-fig-bbStudio-gui-start}
298 (the exact appearance of \bbStudio is Operating System and \bbtk version dependent)
299
300 \newpage
301
302
303 \begin{figure}[!ht]
304 \caption{\label{bbi-fig-bbStudio-gui-start}The bbStudio Development environment interface at start time}
305 \begin{center}
306 \includegraphics[width=0.7\textwidth]{bbStudioMainPageStart.png}
307 \end{center}
308 \end{figure}
309
310
311 Feel free to resize any part you want.
312 Your preferences will be kept next time you run again \bbStudio. \\
313
314 Let's have a look at the resized window :
315
316 \begin{figure}[!ht]
317 \caption{\label{bbi-fig-bbStudio-gui}The bbStudio Development environment interface}
318 \begin{center}
319 \includegraphics[width=0.7\textwidth]{bbStudioMainPage.png}
320 \end{center}
321 \end{figure}
322
323 You can see four parts : \texttt{Files}, \texttt{Messages},
324  \texttt{Command}, \texttt{Help}.\\
325
326 The stuff is written using the Advanced User Interface library of wxWidgets,
327 whose 'docking manager' allows windows and toolbars to be floated/docked 
328 onto a frame.\\
329 Please don't use this feature at learning time (the snapshots of this document
330  wouldn't match with your screen ...)
331
332 \subsubsection{'Files' part}
333 \label{bbi-FilesPart}
334
335 It's the .bbs script editor.\\
336 If you load a file holding a script, it will be displayed here, and you'll be
337 able to modify it, to save it, to save-as it, to run it, using the
338 lower toolbar (see figure : \ref{lowertoolbar})
339
340 \begin{figure}[!ht]
341 \caption{\label{lowertoolbar}The lower tool bar}
342 \begin{center}
343 \includegraphics[width=0.7\textwidth]{lowertoolbar.png}
344 \end{center}
345 \end{figure}
346
347
348  \begin{itemize}
349    \item {\bf\emph{New file}} : Create a new file to hold a script
350    \item {\bf\emph{Open file}} : Open an already existing file holding a script 
351    \item {\bf\emph{Close file}} : Close a file holding a script
352    \item {\bf\emph{Save file}} : Save he current file (if modified)
353    \item {\bf\emph{Save file as}} : Save he current file under a different name
354    \item {\bf\emph{Run file}} : Execute the script you just loaded/modified/written
355    \item {\bf\emph{cursor position}} : column number : line number   
356  \end{itemize}
357
358
359 \subsubsection{'Messages' part}
360 \label{bbi-MessagesPart}
361
362 Two kinds of messages will be output here:\\
363 System messages : produced by the kernel, in case of a user mistyping, or an execution error\\
364 Script messages : produced by the \bbtk equivalent of \texttt{printf} 
365 or \texttt{std::cout} in user programs
366
367 \subsubsection{'Command' part}
368 \label{bbi-CommandPart}
369
370 This is where user will type his requirements.
371
372 \subsubsection{'Help Contents' part}
373 \label{bbi-HelpContentsPart}
374
375 The 'Help Contents' part of \bbStudio is used to browse the html help of \BBTK.
376 All the entries of the starting page are self-explanatory :
377  \begin{itemize}
378    \item {\bf\emph{Help Contents}}
379    \begin{itemize}
380      %\item {\bf\emph{Wiki}} : Direct link to the bbtk Wiki (intranet only, right now, www
381      %later).
382      \item {\bf\emph{Demo}} : Link to some 'sophisticated' demonstrations.
383      \item {\bf\emph{Examples}} : Link to some detailed 'How to use' examples
384    \end{itemize}
385    
386    \item {\bf\emph{Guides}}   
387    \begin{itemize}      
388      \item {\bf\emph{User's Guide}} : Step to step How-to for user who wants to create his own
389      application, just using already existing boxes.
390      \item {\bf\emph{Package Developper's Guide}} : Step to step How-to for user who wants to create his own
391      black boxes.
392      \item {\bf\emph{Developper's Guide}} : For bbtk kernel developpers. Sorry, not yet written.
393      \item {\bf\emph{Reference Manual}} : Sorry, not yet written.
394      \item {\bf\emph{Booklet}} : Vade mecum. Sorry, not yet written.    
395      \item {\bf\emph{Doxygen Documentation}} : Doxygen source browser.
396    \end{itemize}
397         
398    \item {\bf\emph{Boxes}} : Box retrieving on various criterions :
399    \begin{itemize} 
400     \item {\bf\emph{    \texttt{By name}}} (Alphabetical list), 
401     \item {\bf\emph{    \texttt{{By package}}}, 
402      \item {\bf\emph{   \texttt{{By category}}}.
403    \end{itemize} 
404    
405         A special hidden Box category, called \texttt{{Adaptors}} exists. \\ 
406         They are used internaly to perform type conversions. Thought there are not end user intended, an aware user may query them.     
407
408       
409  \end{itemize}
410
411
412 % ==========================================
413
414
415
416
417 % ==========================================
418 % ==========================================
419 % ==========================================
420 % ==========================================
421 % ==========================================
422
423
424
425
426 % ==========================================
427
428 \newpage
429
430 % ==============================================
431 \subsection{Running Demo and Examples}
432 % ==============================================
433
434 Run \bbStudio the way you need. \\
435 In the part 'Help contents' (See figure \ref{HelpContents}), select \texttt{Examples} link.
436
437 \begin{figure}[!ht]
438 \caption{\label{HelpContents}Help Contents}
439 \begin{center}
440 \includegraphics[width=0.7\textwidth]{HelpContents.png}
441 \end{center}
442 \end{figure}
443
444 \newpage
445
446 You will be asked to select a Box category (See figure \ref{BoxCategories}); \\ 
447 Select \texttt{example}.
448
449
450 \begin{figure}[!ht]
451 \caption{\label{BoxCategories}Box Categories}
452 \begin{center}
453 \includegraphics[width=0.7\textwidth]{BoxCategories.png}
454 \end{center}
455 \end{figure} 
456
457 You will be asked to choose a script (See figure \ref{example}).
458
459 \begin{figure}[!ht]
460 \caption{\label{example}example list}
461 \begin{center}
462 \includegraphics[width=0.7\textwidth]{example.png}
463 \end{center}
464 \end{figure}
465
466
467
468 Select \texttt{wx::exampleSlider} (See figure \ref{exampleSlider});
469  
470 \begin{figure}[!ht]
471 \caption{\label{exampleSlider}example 'exampleSlider'}
472 \begin{center}
473 \includegraphics[width=0.7\textwidth]{exampleSlider.png}
474 \end{center}
475 \end{figure}
476
477 You can see the graphical summary representation of the current script (the elementary boxes that compose it, and their
478 connections) \\
479 Click on \texttt{source}, and you'll be able to see the (very simple) script, 
480 in the 'Files' part, within the script editor (See figure \ref{exampleSliderSource});
481
482 \begin{figure}[!ht]
483 \caption{\label{exampleSliderSource}source code of 'exampleSlider'}
484 \begin{center}
485 \includegraphics[width=0.7\textwidth]{exampleSliderSource.png}
486 \end{center}
487 \end{figure}
488
489 Run it, using the lower toolbar  (see figure : \ref{lowertoolbar})
490
491 You'll get something like in figure \ref{execSliderSource}.
492
493 \begin{figure}[!ht]
494 \caption{\label{execSliderSource}execution of 'exampleSlider'}
495 \begin{center}
496 \includegraphics[width=0.7\textwidth]{execSliderSource.png}
497 \end{center}
498 \end{figure}
499
500 Feel free to move the slider, to check it actually works...
501
502 \newpage
503
504 Just a few words on what you saw :
505 \begin{itemize}
506 \item{in the File part} \\
507 The source code of the script
508 \begin{verbatim}
509    new Slider     slider
510      set slider.ReactiveOnTrack 1
511 \end{verbatim}
512 We create a \texttt{Slider} called \emph{slider}\\
513 We tell it to inform anybody that's interested in, that the cursor moved, each time it moved. \\
514 The standard behaviour is to inform, only when cursor is released.
515 \begin{verbatim}
516    new OutputText text
517 \end{verbatim}
518 We create a \texttt{OutputText} called \emph{text} 
519 (in which slider value will be displayed)
520
521 \begin{verbatim}
522 new LayoutLine layout
523 \end{verbatim}
524 We create a \texttt{LayoutLine} called \emph{layout},
525 a \emph{container} widget, designed to embed other wigets (say, a main window)
526 \begin{verbatim}
527 connect slider.Widget    layout.Widget1
528 connect text.Widget      layout.Widget2
529 \end{verbatim}
530 We embed \emph{slider} and \emph{text} into  \emph{layout}.
531 \begin{verbatim}
532 connect slider.BoxChange text.BoxExecute
533 connect slider.Out       text.In
534 \end{verbatim}
535 We tell  \emph{slider} to inform \emph{text} every time it's modified.\\
536 We tell  \emph{slider} to pass its output value (\texttt{Out} to \emph{text}  input value (\testtt{In})
537 \begin{verbatim}
538 exec layout
539 \end{verbatim}
540 We tell \emph{layout} to process itself (it will do it only if it's warned 
541 that one of its entries was modified since its (own) last processing.
542
543 \item{in the Help part}
544
545 You can see the graphical representation of the script, as in figure \ref{SmallGraph}.
546
547
548 \begin{figure}[!ht]
549 \caption{\label{SmallGraph}Graphical representation of a script}
550 \begin{center}
551 \includegraphics[width=0.7\textwidth]{SmallGraph.png}
552 \end{center}
553 \end{figure}
554
555 Both graphical pipe line (\emph{slider} and \emph{text} are embedded into \emph{layout})
556  and processing pipe line (\emph{slider} warns \emph{text} immedialtely when it's modified, \emph{slider} passed \emph{text} its new value).\\
557  Yes, we know : all the arrows (pipe line arrows and processing arrows) are blue; we are sorry about that...\\
558  
559  You could get a much more detailled graph, just clicking on the button \\ \texttt{graph (detailled)} in the toolbar of the \texttt{Command} part, like in
560  figure  \ref{LargeGraph}.
561  
562 \begin{figure}[!ht]
563 \caption{\label{LargeGraph}Detailled graphical representation of a script}
564 \begin{center}
565 \includegraphics[width=0.75\textwidth]{LargeGraph.png}
566 \end{center}
567 \end{figure} 
568
569 \end{itemize}
570 \newpage
571
572 % ==============================================
573 \subsection{Online Help}
574 % ==============================================
575
576 Various levels or help are suplied by \bbStudions.
577
578 % ==========================================
579 \subsubsection{Command line help}
580 % ==========================================
581
582
583 The 'working' area (the left one, as opposed to the 'help' area, on the right side) is composed of : 
584 one single line zone (Command), at the bottom in which you can enter your commands and 
585 a multiple line zone in which the Command interpreter prints out the result of your commands.
586 The upper part contains the script editor; we shall not use it right now, you may reduce it
587
588 Try typing in the \texttt{Command} area (in this manual, 
589 the commands entered by the user will be preceded by a prompt \textgreater) :
590 \begin{verbatim}
591 > help 
592 \end{verbatim}
593
594 you get the list of the commands of the interpreter :
595 \begin{verbatim}
596 Available commands :
597  author
598  category
599  config
600  connect
601  debug
602  define
603  delete
604  description
605  endefine
606  endpackage
607  exec
608  graph
609  help
610  include
611  index
612  input
613  kind
614  load
615  message
616  new
617  newgui
618  output
619  package
620  print
621  quit
622  reset
623  set
624  unload
625 \end{verbatim}
626
627 To get help on a particular command type \texttt{help <command-name>},
628 for example :
629 \begin{verbatim}
630 > help author
631 \end{verbatim}
632
633 gives :
634 \begin{verbatim}
635  usage : author <string>
636   Adds the string <string> to the author information of the black box being defined
637 \end{verbatim}
638
639 The \texttt{help} command has multiple usages. 
640 It is used to get help about almost anything in the interpretor!
641 Type \texttt{'help help'} to get help on the \texttt{help} command itself :
642 \begin{verbatim}
643 > help help
644  usage : 
645          (1) help 
646          (2) help <command name> 
647          (3) help packages [all]
648          (4) help <package name> [all]
649          (5) help <black box type> 
650          (6) help <black box name>
651   Effect :
652          (1) Lists all available commands;
653          (2) Prints help on a particular command; 
654          (3) Lists the packages loaded and their black boxes.
655              Add 'all' to list adaptors; 
656          (4) Prints short help on the black boxes of a package.
657              Add 'all' to include adaptors; 
658          (5) Prints full help on a black box type; 
659          (6) Prints information on the inputs, outputs and connectionns
660              of a black box instance.
661 \end{verbatim}
662
663 At start the interpretor does not know any black box. 
664 If you type \texttt{'help packages'}, which is 
665 the third form of the \texttt{help} command, you get :
666 \begin{verbatim}
667 > help packages
668 user
669   workspace
670 \end{verbatim}
671
672 which means that the interpretor only knows one package 
673 (library of black boxes) called \texttt{user}
674 and which contains a black box called \texttt{workspace}.
675 The \texttt{user} package is an internal package of the interpreter, 
676 which stores user-defined black box types. 
677 At start, it already contains 
678 one box, called \texttt{workspace}.
679 \texttt{workspace} is a special type of black box, 
680 called complex black box, whose purpose is 
681 to store other black boxes. 
682 Any black box you create in \bbStudio is stored 
683 in \texttt{workspace}  
684 (this will be explained in details in sections 
685 \ref{bbi-writing-scripts} and 
686 \ref{bbi-more-on-complex-black-boxes}). 
687
688 If you type \texttt{'help workspace'}, you get :
689 \begin{verbatim}
690 > help workspace
691  Complex Black Box <user::workspace>
692   User's workspace
693   By : bbtk
694   Category(s) : complex box;
695   * No inputs
696   * No outputs
697   * No boxes
698 \end{verbatim}
699
700 In the text displayed, 
701 the \texttt{user::} prepended to the name \texttt{workspace} 
702 means that the box \texttt{workspace} 
703 belongs to the \texttt{user} package. 
704 Then comes a description and three lines which 
705 tell that \texttt{workspace} does not have any input 
706 nor output nor boxes yet.
707
708 In order to let the interpreter know of some black boxes, 
709 you must load another package. 
710 The \texttt{std} package is the ``standard'' package, 
711 which contains basic useful black boxes. 
712
713 To load it, type :
714 \begin{verbatim}
715 > include std
716 \end{verbatim}
717
718 Then if you type :
719 \begin{verbatim}
720 > help packages
721 \end{verbatim}
722
723 you get something like :
724
725 \begin{verbatim}
726
727  std
728    ASCII                   : ascii codes sequence to string - string to ascii...
729    Add                     : Adds its inputs
730    ConcatStrings           : String concatenation
731    Configuration           : Gets configuration informations
732    Div                     : Divides its inputs
733    ExecBbiCommand          : Executes bbi commands
734    ExecSystemCommand       : Executes system (O.S.) commands
735    GetVectorCharElement    : Gets the i-th element from the input vector (std...
736      ...
737    MagicBox                : Takes *any kind* of data and copies it to its ou...
738    MakeFileName            : Makes a kosher file name
739    Mul                     : Multiplies its inputs
740    MultipleInputs          : This box has multiple Void inputs and one Void o...
741    StringRelay             : Just copies the value of its input to its output...
742    StringSelect            : Outputs the string set to the ith input Ini (In0...
743  user
744    workspace 
745 \end{verbatim}
746
747 Now the interpreter knows the package \texttt{std} and the black boxes it provides,
748 such as the \texttt{'Add'} box, the \texttt{'ConcatStrings'} box, and so on. Remark that the 
749 content of \texttt{std} may vary from one version to another 
750 as new black boxes might be added to it. 
751 If you type :  
752 \begin{verbatim}
753 > help Add
754 \end{verbatim}
755
756 You'll get a text help, in the 'Message' part :
757 \begin{verbatim}
758 Black Box <std::Add>S
759   Adds its inputs
760   By : laurent.guigues@creatis.insa-lyon.fr
761   Categories : atomic box;math;
762   * Inputs : 
763      'BoxExecute'     <bbtk::Void> [signal] : Any signal received by this input 
764                                               executes the box
765      'BoxProcessMode' <String>     []       : Sets the processing mode of the box 
766                                               (Pipeline | Always | Reactive)
767      'In1'            <Double>     []       : First number to add
768      'In2'            <Double>     []       : Second number to add
769   * Outputs : 
770      'BoxChange'      <bbtk::VoidS> [signal] : Signals modifications of the box
771      'Out'            <Double>     []       : Result
772 \end{verbatim}
773
774 More information about what is a 'box' will be given in the 'Scriptting' part of this manual.
775
776 % ==========================================
777 \subsubsection{Guides}
778 % ==========================================
779
780 An html version of all the guides is browsable in the \texttt{Help} part of \bbStudions.
781  \begin{itemize}      
782      \item {\bf\emph{User's Guide}} : Step to step How-to for user who wants to create his own
783      application, just using already existing boxes.
784      \item {\bf\emph{Package Developper's Guide}} : Step to step How-to for programmer who wants to create his own
785      black boxes/packages.
786      \item {\bf\emph{Developper's Guide}} : For bbtk kernel developpers only. (This one is probabely not very much
787      up-to-date, since we spend more time in developping than writing documentation that's not of user concern).
788      \item {\bf\emph{Reference Manual}} : Contains a exaustive description of all the features for all the commands.
789      \item {\bf\emph{Booklet}} : Vade mecum.     
790      \item {\bf\emph{Doxygen Documentation}} : Doxygen source browser.\\ Automatically generated from source file
791      headers. Should concern only the kernel developpers (i.e. : us).
792    \end{itemize}
793         
794
795    \end{itemize} 
796    
797 % ==========================================
798 \subsubsection{Boxes Help}
799 % ==========================================
800  Box retrieving on various criterions :
801    \begin{itemize} 
802     \item {\bf\emph{Alphabetical list}} \\ This is the 'zero-level' of retrieving.
803     \item {\bf\emph{List by package}} \\ Several packages are supplied with bbtk :
804     \begin{itemize}
805       \item {\bf\emph{std}} : the 'standard' package including basic useful boxes.
806       \item {\bf\emph{wx}} : basic graphical interface elements (widgets : sliders, buttons, etc. based on the \texttt{wxWidgets} library).  
807       \item {\bf\emph{itk}} : the basic image processing package, based on the \itk library.
808       \item {\bf\emph{vtk}} : the basic images and surfaces processing and vizualization package, based on the \vtk library.
809       \item {\bf\emph{wxvtk}} : widget boxes based on the \vtk library (2D and 3D vizualization and
810       interaction).
811       %\item {\bf\emph{creaImageIO}} : Provides hight level widgets to read images, including DICOM.
812       \item {\bf\emph{toolsbbtk}} : Tools for bbtk administration and package development, such as :
813          \begin{itemize}
814          \item{GUICreateBlackBox} For creating the XML or C++ code for a new black box 
815          \item{GUICreatePackage} For creating a new bbtk package file structure on disk (Graphical user interface for the shell script bbCreatePackage)
816          \item{MakePackageDoc} For creating the html documentation of a package. The doc is generated at the 'canonical' location. Works both for a build tree or an installed toolkit.  
817          \end{itemize}               
818     \end{itemize}
819     \item {\bf\emph{List by category}}.
820     
821     
822     A given box may belong to more than one \texttt{category}.\\
823     You have to consider categories like keywords to index black boxes.\\
824     Some of them are mutually exclusive.
825     A black box may be :
826     \begin {itemize}
827        \item{atomic box / complex box}\\
828        Whether it's written is C++ or it's an assembly of several black boxes (atomic or complex).\\
829        Any box is either atomic ou complex.
830        \item{example / demo / application}\\
831            Theese ones are always complex black boxes. 
832           \begin {itemize}
833              \item{example}\\
834              It's just a (simple) example on how to use a given feature.
835              \item{demo}\\
836              It can be a 'good looking' (a.k.a 'sexy') example on some sophisticated work.       
837              \item{application}\\
838              It's a Final application, end user intended (e.g. Subscale a huge volume, Crop a DICOM image, etc)  
839           \end {itemize}
840         \item{widget}\\
841         Piece of graphical interface (based on \texttt{wxWidgets})
842         \item{Dicom}\\
843         Dicom medical image related box.
844         \item{viewer}\\
845         \item{read/write}
846         \item{mesh}
847         \item{3D Object creator}
848         \item{math}
849         \item{misc}              
850     \end {itemize}
851   \end {itemize}
852 % ==============================================
853 \subsection{The Menu}
854 % ==============================================
855 TODO
856
857
858 % ==========================================
859 \section{bbs scripting}
860 % ==========================================
861
862 % ==========================================
863 \subsection{Using an already existing}
864 % ==========================================
865
866 % ==========================================
867 \subsection{Creating and executing black boxes}
868 % ==========================================
869
870 You'll get as well the same information in the 'Help' Part, in html format (see figure : \ref{HelpAdd}) :
871
872 \begin{figure}[!ht]
873 \caption{\label{HelpAdd}The html Help}
874 \begin{center}
875 \includegraphics[width=0.7\textwidth]{HelpAdd.png}
876 \end{center}
877 \end{figure}
878
879 Like previously, 
880 the \texttt{std::} prepended to the name \texttt{Add} 
881 means that the box \texttt{Add} 
882 belongs to the \texttt{std} package. 
883 Then comes a description 
884 (the one which was provided by the author of the box), 
885 the author(s) of the box (usually e-mail adress(es)) and 
886 the categories to which the box belongs. 
887 Finally comes the lists of inputs and outputs of the box.
888 For each input or output, \bbi provides 
889 its \emph{name} (between quotes, e.g. \texttt{'ProcessMode'}), 
890 its \emph{type} (between \texttt{<} and  \texttt{>}, e.g. \texttt{<Int>})
891 and a description.    
892 Remark that the box \texttt{Add} is not a 'complex' black box 
893 but an 'atomic' box, hence its help does not 
894 mention any information concerning possible internal boxes.
895
896 You can create an \emph{instance} of an \texttt{Add} box by 
897 the command \texttt{new} :
898 \begin{verbatim}
899 > new Add a
900 \end{verbatim}
901
902 The \texttt{'a'} at the end is the \emph{name} of the instance, 
903 which will be used to reference it later. 
904 It is important to distinguish a box \emph{type} 
905 and an \emph{instance} of a box type. 
906 The \texttt{Add} box of the package \texttt{std} is actually 
907 a \emph{box type} , like \texttt{int} is a data type 
908 in \texttt{C} langage. The \texttt{new} command allows to create 
909 an instance of a box type, exactly like \texttt{int i;} in 
910 a \texttt{C} code, it declares a variable of type \texttt{int} whose 
911 name is \texttt{i}. 
912 Of course, like in \texttt{C} Language, you can declare multiple boxes of the 
913 same type in \bbi. 
914
915 After the creation of the box \texttt{a}, type :
916 \begin{verbatim}
917 > help workspace
918 \end{verbatim}
919
920 you get :
921 \begin{verbatim}
922 Complex Black Box <user::workspace>
923  User's workspace
924  By : bbtk
925  Category(s) : complex box;
926  * No inputs
927  * No outputs
928  * Boxes : 
929     'a' <std::Add>
930 \end{verbatim}
931
932 which means that \bbi workspace now contains a black box named \texttt{a},
933 of type \texttt{std::Add}.
934
935 Now look back at the help on \texttt{Add} boxes : 
936 you can see that this type of box has two inputs, 
937 with name \texttt{In1} and \texttt{In2},
938 and an output, with name \texttt{Out}.
939
940 You can set the input \texttt{In1} 
941 of the \texttt{Add} box \texttt{a} to the value $1$ 
942 by the command :
943 \begin{verbatim}
944 > set a.In1 1 
945 \end{verbatim}
946
947 Similarly, setting the input \texttt{In2} of \texttt{a} to the value $2$
948 is done with :
949 \begin{verbatim}
950 > set a.In2 2
951 \end{verbatim}
952  
953 And you print the output \texttt{Out} of the box \texttt{a} with :
954 \begin{verbatim}
955 > print "result=$a.Out$"
956 result=3
957 \end{verbatim}
958
959 In the string passed to the \texttt{print} command, 
960 each substring enclosed between a couple of \$ is considered 
961 as the name of an output of a box. 
962 To process this special substrings, the interpretor :
963 \begin{enumerate}
964 \item Processes the box if needed (see below)
965 \item Converts the output of the box to a string if possible 
966 (see below)
967 \item Substitutes the result in the string to print
968 \item Postpones an implicit 'new line' character to the string
969 \end{enumerate}
970
971 %\paragraph
972
973 Box processing is needed if :
974
975 \begin{itemize}
976 \item either at least input has changed since last processing 
977 \item or the input \texttt{'BoxProcessMode'} of the box is set to 
978 \texttt{'Always'}, which forces box reprocessing. 
979 \end{itemize}
980
981 Note that all boxes have an input named \texttt{'BoxProcessMode'}.\\ 
982
983 Another way to process the box \texttt{a} is to issue the command :
984 \begin{verbatim}
985 > exec a
986 \end{verbatim}
987
988 however this command does not display anything (except if the 
989 box itself displays something in its processing).
990 It just processes the box if needed. 
991 This command is used to execute boxes that do not have any output,  
992 such as boxes that write something to a file or, display a 
993 graphical interface, and so on. \\
994
995 %To exit \bbi, type :
996 %\begin{verbatim}
997 %> quit
998 %Good bye !
999 %\end{verbatim}
1000
1001 % ==========================================
1002 \hrule
1003
1004 \paragraph{Summary}
1005 %\hrule
1006 \begin{itemize}
1007 \item The \texttt{include} command allows to load a package, and the complex black boxes that come with it..
1008 \item \texttt{help} gives help on :
1009 \begin{itemize} 
1010 \item Available commands if you just type \texttt{help}.
1011 \item A particular command if you type \texttt{help <command-name>}.
1012 \item All available packages and their boxes (without description) if you type \texttt{help packages}.
1013 \item A particular package and its boxes (with brief description) if you type \texttt{help <package-name>}.
1014 \item A particular black box type (with full description) if you type \texttt{help <box-type-name>}. In particular, \texttt{help workspace} displays information on the content of the \texttt{'workspace'} black box, which stores the boxes created by the user (by \texttt{new}).
1015 \end{itemize}
1016 %\item \texttt{list} displays the list of black box instances created so far (by \texttt{new}).
1017 \item \texttt{new} : creates an instance of a black box. 
1018 \item \texttt{set} : sets the value of an input of a black box. 
1019 \item Under any component of  \bbStudions, to reference the input called \texttt{i} 
1020 of a black box called \texttt{b} you must type \texttt{'b.i'}. 
1021 The same syntax holds for outputs.
1022 \item \texttt{print} : prints a string, substituting each substring of the form \$b.o\$ by the value of the output \texttt{o} of the black box \texttt{b}. Note that an
1023 implicit trailing 'new line character' is added at the final string.
1024 \item \texttt{exec} : runs, if needed, the process of a box. 
1025 %\item \texttt{quit} : quits \bbi.
1026 \end{itemize}
1027 \hrule
1028
1029 %\paragraph{Note :}
1030 %A more 'modern' way to proceed is to run \texttt{bbStudio}, drag and drop the  \texttt{Command} bookmark to the lower \texttt{Welcome to bbStudio!} bar.
1031 %Wou'll get something like in figure \ref{bbCommandPlusHelp} :
1032
1033 %\begin{figure}[!ht]
1034 %\caption{\label{bbCommandPlusHelp}
1035 %An other way to run the command interpreter}
1036 %\begin{center}
1037 %\includegraphics[width=0.5\textwidth]{bbCommandPlusHelp.png}
1038 %\end{center}
1039 %\end{figure}
1040
1041 % ==========================================
1042
1043 % ==========================================
1044 \subsubsection{Connecting black boxes}
1045 \label{bbi-connecting-black-boxes}
1046 % ==========================================
1047
1048 \BBTK allows to create 
1049 and execute processing chains, 
1050 also called \emph{pipelines}, 
1051 by connecting black boxes.
1052 This section explains how to do it with examples. 
1053 Read section \ref{bbi-more-on-pipeline-processing} to get 
1054 more information on pipeline processing.
1055
1056 First start \bbStudio and load the package \texttt{std}, typing :
1057 \begin{verbatim}
1058 > include std
1059 \end{verbatim}
1060 in the 'Command' part.
1061
1062 Assume you want to compute $1+2+3$. You can do it by 
1063 chaining two \texttt{Add} boxes, as shown in figure 
1064 \ref{bbi-fig-connecting-black-boxes-1}. 
1065
1066 \begin{figure}[!ht]
1067 \caption{\label{bbi-fig-connecting-black-boxes-1} A simple pipeline which adds 3 numbers}
1068 \begin{center}
1069 \includegraphics[width=0.5\textwidth]{1plus2plus3.png}
1070 \end{center}
1071 \end{figure}
1072
1073
1074 The \bbi instructions to create and execute this pipeline are :
1075 \begin{verbatim}
1076 > new Add a
1077 > new Add b
1078 > connect a.Out b.In1
1079 > set a.In1 1
1080 > set a.In2 2
1081 > set b.In2 3
1082 > print $b.Out$
1083 \end{verbatim}
1084
1085 You will see the (very expected) result :
1086 \begin{verbatim}
1087 6
1088 \end{verbatim}
1089
1090 The first three commands build the pipeline, 
1091 the next three set \texttt{a} and \texttt{b} black boxes inputs and the last one 
1092 prints \texttt{b} black boxe output (the pipeline is executed before printing, because the interpretor 'knows' the box  \texttt{b}, 
1093 whose output is requested, is not up to date.
1094  
1095 The command \texttt{'connect a.Out b.In1'} ``plugs'' the output 
1096 \texttt{Out} of the box \texttt{a} into the input \texttt{In1} of the 
1097 box \texttt{b}. 
1098 Once the boxes connected, the processing of the two boxes are chained :
1099 getting the output of \texttt{b} requires getting its inputs, 
1100 hence getting the output of \texttt{a} which is connected to it. 
1101 This pipeline mechanism can recurse into arbitrary long 
1102 chains of boxes (see \ref{bbi-more-on-pipeline-processing} 
1103 for details).
1104
1105
1106 Lets' consider an other, more image oriented, example :
1107
1108 \begin{verbatim}
1109 > include vtk
1110 > include wx
1111 > include itk
1112 > include wxvtk
1113
1114 > new FileSelector fileDialog
1115 > new ImageReader  reader 
1116 > new Slider       slider
1117 > new Viewer2D     viewer
1118
1119 > connect fileDialog.Out   reader.In 
1120 > connect reader.Out       viewer.In
1121 > connect slider.Out       viewer.Slice
1122 > connect slider.BoxChange viewer.BoxExecute
1123
1124 > exec viewer
1125 \end{verbatim}
1126
1127 Some explainations : the \texttt{include} instructions load the necessary packages. \\
1128
1129 \texttt{new FileSelector} will pop a File Selector, at run time, that will out the user chosen file name. \\
1130 \texttt{new Slider} will pop a Slider, at run time, that will out an integer, used later as a slice number.\\ 
1131 \texttt{new ImageReader} will read any itk readable file, whose name is passed as a std::string, and return a itk::ImagePointer.\\
1132 \texttt{new Viewer2D} display a plane, whose number id specified by an integer.\\
1133 \\
1134 \texttt{connect fileDialog.Out   reader.In} plugs the output of the File Selector (a std::string) to the input of the reader (a std::string, too).\\
1135 \texttt{connect reader.Out       viewer.In} plugs the output of the reader (an itk::ImagePointer) to the input of the Viewer (a vtkImageData *)\\
1136 \texttt{connect slider.Out       viewer.Slice} plugs the output of the slider (an int) to an other output (named Slide) of the viewer.\\
1137 \texttt{connect slider.BoxChange viewer.BoxExecute} says the viewer it must re process itself any time the slider is modified.\\
1138 \\
1139 \texttt{exec viewer} processes the viewer.
1140
1141
1142 This would correspond to the graph in figure \ref{bbi-simplegraph}
1143
1144
1145 \begin{figure}[!ht]
1146 \caption{\label{bbi-simplegraph}(Very) simple Graph of a (very) simple pipeline}
1147 \begin{center}
1148 \includegraphics[width=0.8\textwidth]{bbi-simplegraph.png}
1149 \end{center}
1150 \end{figure}
1151    
1152 Of course, to be able to connect two boxes, 
1153 the output and the input must be compatibles. 
1154 You can always connect an output to an input of the \emph{same} type, 
1155 but you can do more, thanks to particular (hidden) black boxes called {\bf adaptors}.
1156
1157 An adaptor is a black box which has at least one input, called \texttt{In}, 
1158 and at least one ouput called \texttt{Out} and whose role is to convert 
1159 a data of the type of \texttt{In} 
1160 into a data of the type of \texttt{Out} (other inputs or outputs may serve 
1161 to parameter the adaptor or retreive other usefull information).
1162
1163 Under \bbStudions, if you type :
1164 \begin{verbatim}
1165 > load std
1166 > help std all
1167 \end{verbatim}
1168 you get :
1169 \begin{verbatim}
1170  Package std v1.0.0 - laurent.guigues@creatis.insa-lyon.fr
1171  Basic useful black boxes
1172  Black boxes : 
1173       ...
1174    BoolToString        [DA]  : Converts a Bool (bool) into a string
1175    CastBoolToChar      [DA]  : Static cast from Bool (bool) to Char (signed c...
1176    CastBoolToDouble    [DA]  : Static cast from Bool (bool) to Double (double...
1177       ...
1178    CastBoolToUChar     [DA]  : Static cast from Bool (bool) to UChar (unsigne...
1179    CastBoolToUInt      [DA]  : Static cast from Bool (bool) to UInt (unsigned...
1180       ...
1181    CastUIntToBool      [DA]  : Static cast from UInt (unsigned int) to Bool (...
1182    CastUIntToChar      [DA]  : Static cast from UInt (unsigned int) to Char (...
1183    CastUIntToDouble    [DA]  : Static cast from UInt (unsigned int) to Double...
1184       ...      
1185
1186 \end{verbatim}
1187
1188 \texttt{[DA]}  stands for \emph{default adaptor}.
1189
1190 Once you have loaded the package \texttt{std}, you can 
1191 plug an output of type \texttt{char} into an input of type \texttt{double}. 
1192 When the interpreter encounters the \texttt{connect} command, 
1193 it looks for an adequate \emph{adaptor} in the  loaded packages. 
1194 In our case, as the package \texttt{std} provides the 
1195 \texttt{CastUCharToDouble} adaptor, the interpreter automatically creates an 
1196 instance of this adaptor and place it \emph{between} 
1197 the output and the input you want to connect 
1198 (however this adaptor is hidden to you, 
1199 it is embedded into the created connection and does not appear 
1200 as an existing black box). 
1201 When the pipeline is processed the 
1202 adaptor converts the output data into the required input type, 
1203 in a totally transparent way.
1204 In our example, the \texttt{CastUCharToDouble} adaptor 
1205 would simply cast the value of the \texttt{char} into a \texttt{double}, 
1206 however arbitrarily complex type conversion may be done.
1207
1208 %\begin{verbatim}
1209 %Question (for info-dev): 
1210 %if two adaptors with the same input and output types exist 
1211 %in two different packages, currenly loaded, 
1212 %which one is chosen by the interpreter at connection time?
1213 %A feature is missing to specify explicitely which one user wants to choose 
1214 %(use a namespace notation ?)
1215
1216 %-> Role of default adaptors
1217 %\end{verbatim}
1218
1219 Note that the \texttt{set} and \texttt{print} commands of interpreter 
1220 work with adaptors from \texttt{string} to the type of the input to set 
1221 or from the type of the output to print to \texttt{string}. 
1222 Hence in order to \texttt{set} or \texttt{print} values the adequate 
1223 adaptors must be available in the packages currently loaded. \\
1224
1225
1226 % ==========================================
1227 \hrule
1228 \paragraph{Summary}
1229 %\hrule
1230 \begin{itemize}
1231 \item The \texttt{connect} command allows to connect two black boxes
1232 \item You can connect two black boxes if (and only if) : 
1233 \begin{itemize}
1234 \item The output and the input are of the same type, or
1235 \item There is an adaptor black box in the packages loaded which 
1236 converts data of the output type into data of the input type
1237 \end{itemize}
1238 \item \texttt{help <package name>} does not display the adaptors of the package. To see them use : \texttt{help <package name> all}.
1239 including adaptors
1240 \end{itemize}
1241 \hrule
1242 % ==========================================
1243
1244 % ==========================================
1245 \subsubsection{Creating complex black boxes}
1246 \label{bbi-complex-black-boxes}
1247 % ==========================================
1248
1249 Remember the pipeline of figure 
1250 \ref{bbi-fig-connecting-black-boxes-1}, which 
1251 computed the sum of three doubles?
1252 You can consider it as a whole and define 
1253 a new black box type, which will be a \emph{complex black box}, 
1254 having three inputs and one output, 
1255 as shown in figure \ref{bbi-fig-complex-black-box-1}.
1256
1257 \begin{figure}[!ht]
1258 \caption{\label{bbi-fig-complex-black-box-1} Creating the complex black box \texttt{Add3}}
1259 \begin{center}
1260 \includegraphics[width=0.5\textwidth]{Add3.png}
1261 \end{center}
1262 \end{figure}
1263
1264 The \bbi commands to define this complex black box are 
1265 the following :
1266
1267 \begin{verbatim}
1268 > load std
1269 >
1270 > define Add3
1271 >
1272 > new Add a
1273 > new Add b
1274 > connect a.Out b.In1
1275 >
1276 > author "myself"
1277 > description "adds 3 doubles"
1278 > input x a.In1 "first double to add"
1279 > input y a.In2 "second double to add"
1280 > input z b.In2 "third double to add"
1281 > output result b.Out "output"
1282 >
1283 > endefine
1284 \end{verbatim}
1285
1286 Explainations :
1287
1288 As we will use \texttt{Add} boxes, we need to load the package \texttt{std}, which is done in first line.
1289
1290 The command \texttt{define} then starts the definition 
1291 of the complex box type, which will be called \texttt{Add3}. 
1292
1293 The next three lines define the pipeline, 
1294 exactly in the same way than outside a complex box definition. 
1295
1296 The commands \texttt{author}, \texttt{description}, \texttt{input} 
1297 and \texttt{output} are commands specific to complex boxes definition :
1298
1299 \texttt{author} and \texttt{description} are used for the documentation 
1300 of the new box. You can provide multiple \texttt{author} or 
1301 \texttt{description} commands, the arguments of the commands will 
1302 be concatenated to produce the final author and description strings.
1303
1304 \texttt{input} and \texttt{output} are used to define the inputs and outputs 
1305 of the new complex box. 
1306 Their syntax is the same : for each new input/output you need to say 
1307 to which internal input/output it corresponds and to provide 
1308 a help string documenting the input/output.
1309 In our example, we define that the box \texttt{Add3} has 
1310 three inputs : \texttt{x}, \texttt{y} and \texttt{z}. 
1311 The input \texttt{x} corresponds to the input \texttt{In1} of the 
1312 internal box \texttt{a}. 
1313 In the same way, the external input \texttt{y} 
1314 corresponds to the internal input \texttt{a.In2}, and 
1315 the external input \texttt{In3} to \texttt{b.In2}. 
1316 The only output of the new box is called \texttt{result}
1317 and corresponds to \texttt{b.Out}. 
1318 The figure \ref{bbi-fig-complex-black-box-1} 
1319 illustrates the external to internal 
1320 input/output correspondence.
1321
1322 Finally, the \texttt{endefine} command ends the definition of the 
1323 new box type.
1324
1325 After this definition, if you ask for help 
1326 on packages, you get :
1327 \begin{verbatim}
1328 > help packages
1329 std
1330   Add
1331   ...
1332 user
1333   Add3
1334   workspace
1335 \end{verbatim}
1336
1337 The \texttt{user} package now contains a new black box type, called 
1338 \texttt{Add3}. If you ask for help on this type of box, you get :
1339 \begin{verbatim}
1340 > help Add3
1341 Complex Black Box <user::Add3>
1342  adds 3 doubles
1343  By : myself
1344  * Inputs : 
1345     'x'      <double> : first double to add
1346     'y'      <double> : second double to add
1347     'z'      <double> : third double to add
1348  * Outputs : 
1349     'result' <double> : output
1350  * Boxes : 
1351     'a' <std::Add>
1352     'b' <std::Add>
1353 \end{verbatim}
1354
1355 and you can use it like any other box, for example type :
1356
1357 \begin{verbatim}
1358 > new Add3 a
1359 > set a.x 1
1360 > set a.y 2
1361 > set a.z 3
1362 > print $a.result$
1363 6
1364 \end{verbatim}
1365
1366
1367 As a side note, we can say that, for consistency reasons, it would have been better to name  
1368 \texttt{In1}, \texttt{In2} and \texttt{In3} the inputs of the black box \texttt{Add3}, 
1369 since all the 'natural entry' of a box is named \texttt{In}, or \texttt{In}\emph{x} if there are more than one  'natural
1370 entry'.
1371
1372 % ==========================================
1373 \hrule
1374 \paragraph{Summary}
1375 %\hrule
1376 \begin{itemize}
1377 \item The \texttt{define/endefine} commands allows to define complex black box types, i.e. types of black boxes made up of other black boxes. 
1378 Inside a \texttt{define/endefine} block :
1379 \begin{itemize}
1380 \item The \texttt{author} and \texttt{description} commands allow to document the new type of box
1381 \item The \texttt{input} and \texttt{output} commands allow to define the inputs and outputs of the new type of box, that is to which inputs and outputs 
1382 of internal boxes they correspond.  
1383 \end{itemize}
1384 \end{itemize}
1385 \hrule
1386 % ==========================================
1387
1388 % ==========================================
1389 \subsubsection{Writing scripts}
1390 \label{bbi-writing-scripts}
1391 % ==========================================
1392
1393 Once you have defined a new type of complex box, you 
1394 may like to reuse it. To do this, you can simply 
1395 write the \bbi commands defining the new box 
1396 into a text file and afterwards include that file in \bbi. 
1397 Doing this, you start writing \bbi scripts.
1398 The conventionnal (and mandatory) extension for such scripts is \texttt{bbs} 
1399 (black box script).
1400 For consistency reasons, you are requested to prepend \texttt{bb} to the name.
1401
1402 For example, the \texttt{Add3} complex box we previously worked on 
1403 can be defined in the \texttt{bbAdd3.bbs} file :
1404
1405 \begin{file}{bbAdd3.bbs}
1406 \begin{verbatim}
1407 # Defines the Add3 black box which adds 3 doubles 
1408 load std
1409
1410 define Add3
1411   # I am the author 
1412   author "myself"
1413   description "adds 3 doubles"
1414   # Pipeline creation
1415   new Add a
1416   new Add b
1417   connect a.Out b.In1
1418   # Inputs definition
1419   input x a.In1 "first double to add
1420   input y a.In2 "second double to add
1421   input z b.In2 "third double to add"
1422   # Output definition
1423   output result b.Out "output"
1424 endefine
1425 \end{verbatim}
1426 \end{file}
1427
1428 Lines starting with a \texttt{\#} character or a \texttt{\//\//} character are ignored, they 
1429 are considered as comments by the interpreter.
1430 To use this file in \bbStudions, click on the \texttt{include} button, and browse your filestore to find the file.
1431
1432 \begin{verbatim}
1433 > include bbAdd3.bbs
1434 > help Add3
1435 Complex Black Box <user::Add3>
1436  adds 3 doubles
1437  By : myself
1438  * Inputs : 
1439     'x'      <double> : first double to add
1440     'y'      <double> : second double to add
1441     'z'      <double> : third double to add
1442  * Outputs : 
1443     'result' <double> : output
1444  * Boxes : 
1445     'a' <std::Add>
1446     'b' <std::Add>
1447 >
1448 and so on ...
1449 \end{verbatim}
1450
1451 If the file has the \texttt{bbs} extension, you can ommit it and just type :
1452 \begin{verbatim}
1453 > include Add3
1454 \end{verbatim}
1455
1456 \subsubsection{Creating complex black boxes that use complex black boxes}
1457 \label{bbi-complex-complex-black-boxes}
1458
1459
1460 Of course, you can include script files in other script files, 
1461 like in the following example :
1462
1463 \begin{file}{bbAdd4.bbs}
1464 \begin{verbatim}
1465 # Defines the Add4 black box which adds 4 doubles 
1466 include Add3
1467
1468 define Add4
1469   author "myself"
1470   description "adds 4 doubles"
1471   new Add3 a
1472   new Add b
1473   connect a.Out b.In1
1474   input In1 a.In1 "first double to add
1475   input In2 a.In2 "second double to add
1476   input In3 a.In3 "third double to add"
1477   input In4 b.In2 "fourth double to add"
1478   output Out b.Out "output"
1479 endefine
1480 \end{verbatim}
1481 \end{file}
1482
1483
1484
1485 \subsubsection{Naming Conventions}
1486 \label{bbi-Naming Conventions}
1487
1488
1489 % ==========================================
1490 %\hrule
1491 %\paragraph{Naming Conventions}
1492 %\hrule
1493
1494 %\hrule
1495 % ==========================================
1496 \begin{itemize}
1497 \item
1498 File names : 
1499 For consistency reasons, you are requested to prepend \texttt{bb}, and postpone an extention \texttt{.bbs},
1500 to the names of the files that hold a \texttt{complex black box} definition.
1501
1502 For example, the \texttt{Add3} complex box we previously worked on 
1503 can be defined in the \texttt{bbAdd3.bbs} file.
1504 \item
1505 Search Paths :
1506 For consistency reasons, the names of dynamic libraries holding the packages must start by \texttt{libbb}.
1507 For instance, the package \texttt{wx} will be in the library \texttt{libbbwx.dll} (Windows) or \texttt{libbbwx.so}
1508 (Linux).
1509
1510
1511 \end{itemize}
1512 % ==========================================
1513 \hrule
1514
1515 \paragraph{Summary}
1516 %\hrule
1517 \begin{itemize}
1518 \item The \texttt{include} command tells the interpreter to include a script file.
1519 \item Lines starting with a \texttt{\#} or with a \texttt{\//\//} are considered as comments by the interpreter.
1520 \item Lines between a line starting with a \texttt{\//*} an a line starting with a \texttt{*\//} are considered as comments by the interpreter.
1521 \end{itemize}
1522
1523 \hrule
1524 % ==========================================
1525
1526 % ==========================================
1527 \subsubsection{Creating command line applications}
1528 \label{bbi-command-line-app}
1529 % ==========================================
1530
1531 Now that you know how to create complex black boxes 
1532 (with \texttt{define/endefine}), think 
1533 back to the \texttt{workspace} object. 
1534 Remember that it is also 
1535 a \texttt{complex black box}. 
1536 Actually, when you type interpreter commands 
1537 outside a \texttt{define/endefine} block, 
1538 you progressively define the \texttt{workspace} 
1539 complex black box.
1540 You can think of it like if at start the interpreter
1541 was issuing a command \texttt{'define workspace'} 
1542 and then letting you define the interior of the box 
1543 \texttt{workspace}.
1544
1545 Remember that the command \texttt{inputs} 
1546 allows to define an input of a complex box. 
1547 Now, if you use the command \texttt{input} 
1548 outside a \texttt{define/endefine} block then 
1549 it defines an input of the \texttt{workspace} box, 
1550 that is an input of the \emph{main program}. 
1551 This input will then be connected to the 
1552 parameters that the user passes to the command line.
1553
1554 For example, consider the script : 
1555
1556 \begin{file}{add.bbs}
1557 \begin{verbatim}
1558 load std
1559 new Add a
1560 input x a.In1 "first number to add"
1561 input y a.In2 "second number to add"
1562 print "x+y=$a.Out$"
1563 \end{verbatim}
1564 \end{file}
1565
1566 The third and fourth lines define two inputs \texttt{x} 
1567 and \texttt{y}. When you execute this script, 
1568 you can pass these two arguments on the command line, 
1569 like this :
1570
1571 \begin{verbatim}
1572 > bbi add x=1 y=1
1573 x+y=2
1574 \end{verbatim}
1575
1576 You can also invoke \bbi the option \texttt{-h}, 
1577 which gives help on the \texttt{workspace} box :
1578
1579 \begin{verbatim}
1580 > bbi add -h
1581  User's workspace
1582  By : bbi (internal)
1583  * Inputs : 
1584     'x' <double> : first number to add
1585     'y' <double> : second number to add
1586 \end{verbatim}
1587
1588 To get a better help, use the \texttt{description} 
1589 and \texttt{author} commands :
1590
1591 \begin{file}{add.bbs}
1592 \begin{verbatim}
1593 description "Adds two numbers"
1594 author "foo@bar.com"
1595 load std
1596 new Add a
1597 input x a.In1 "first number to add"
1598 input y a.In2 "second number to add"
1599 print "x+y=$a.Out$"
1600 \end{verbatim}
1601 \end{file}
1602
1603 Now if you ask for help on the \texttt{add} script, you get :
1604
1605 \begin{verbatim}
1606 > bbi add -h
1607  Adds two numbers
1608  By : foo@bar.com
1609  * Inputs : 
1610     'x' <double> : first number to add
1611     'y' <double> : second number to add
1612 \end{verbatim}
1613
1614 Rather than getting the inputs of a script 
1615 from the command line, you can ask \bbi to 
1616 prompt the user for the values, using the \texttt{-t}
1617 commutator :
1618
1619 \begin{verbatim}
1620 > bbi add -t
1621 x=[the program waits for user answer]2
1622 y=[the program waits for user answer]5
1623 x+y=7
1624 \end{verbatim}
1625
1626 \bbStudio is always compiled in graphical mode (with \wx), therefore
1627 you can also use the \texttt{-g} commutator. 
1628 \bbi then prompts the user in graphical mode, 
1629 displaying a dialog box for each input,
1630 like in fig. \ref{bb-input-dialog-box}.
1631
1632 \begin{figure}[!ht]
1633 \caption{\label{bb-input-dialog-box}Input dialog box}
1634 \begin{center}
1635 \includegraphics[width=0.6\textwidth]{enter-the-value-of-x.png}
1636 \end{center}
1637 \end{figure}
1638
1639 % ==========================================
1640 \hrule
1641 \paragraph{Summary}
1642 %\hrule
1643 \begin{itemize}
1644 \item The \texttt{input}, \texttt{description} and \texttt{author} commands,
1645 when they are used outside a \texttt{define/endefine} block allow 
1646 to define the inputs, description and author of the main program.
1647 \item Inputs of the main program can be passed on the command line 
1648 using the syntax \texttt{<input-name>=<value>}. 
1649 No white space is allowed, if the value or the input name 
1650 contains white spaces, enclose them 
1651 between double quotes, e.g. \texttt{"parameter with white spaces = gnu's not unix"}.
1652 \item The \texttt{-h} option of \bbi prints help on the main program.
1653 \item The \texttt{-t} option of \bbi orders the program to prompt for its inputs in text mode.
1654 \item The \texttt{-g} option of \bbi orders the program to prompt for its inputs in graphical mode.
1655 \end{itemize}
1656 \hrule
1657 % ==========================================
1658
1659 % ==========================================
1660 \subsubsection{Using graphical interface boxes (widget boxes)}
1661 \label{bbi-widget}
1662 % ==========================================
1663
1664 % ==========================================
1665 \subsubsection{Overwiew}
1666 \label{bbi-overview}
1667 % ==========================================
1668
1669 \bbStudio is always compiled in graphical mode 
1670 (option \texttt{BUILD\_bbi\_GRAPHICAL} of \cmakens, requires \wxns),
1671 then you can use special black boxes which are 
1672 graphical interface components (widgets). 
1673 Basic components are provided in the package \texttt{wx}, 
1674 such as buttons, sliders, file open/save dialogs, etc.
1675
1676 As first example, type the following commands in \bbi :
1677 \begin{verbatim}
1678 > load wx 
1679 > new InputText t
1680 > print $t.Out$\n
1681 \end{verbatim}
1682
1683 When you type \texttt{enter} after the last line, 
1684 a window pops up in which you can entrer a text.
1685 When you close the window, the text you entered is printed by 
1686 the \texttt{print} command.
1687
1688 Type \texttt{help wx}, you get something like :
1689 \begin{verbatim}
1690  Package wx v1.0.0- info-dev@creatis.insa-lyon.fr
1691  Basic graphical interface elements (sliders, buttons ...) based on wxWidgets
1692  Black boxes : 
1693    ColourSelector        : Colour Selector dialog (bbfication of wxColourSele...
1694    ColourSelectorButton  : A button which displays a colour picker dialog whe...
1695    CommandButton         : Button which executes bbi commands
1696    DirectorySelector     : Pops up a directory selection dialog (wxDirDialog)
1697    FileSelector          : Pops up a file selection dialog for reading or sav...
1698    InputText             : A zone in which the user can enter a text (wxTextC...
1699    LayoutLine            : LayoutLine widget (wxBoxSizer)
1700    LayoutSplit           : Widget which splits a window in two fixed size par...
1701    LayoutTab             : LayoutTab widget (wxNotebook)
1702    OutputText            : Text zone to be inserted into a window (wxStaticTe...
1703    RadioButton           : RadioButton group widget 0-9 entries
1704    Slider                : Slider widget (wxSlider)
1705 \end{verbatim}
1706
1707 You can reproduce the same experiment as above using a 
1708 \texttt{Slider} or a \texttt{FileDialog} rather than a \texttt{InputText}.
1709 See the files \texttt{test*.bbs} in the \texttt{scripts/test} directory.
1710
1711 There are two kinds of widgets : ``terminal'' widgets and ``container'' widgets.
1712 The \texttt{InputText}, \texttt{FileDialog} or \texttt{Slider} widgets 
1713 are ``terminal'' widgets. 
1714 ``container'' widgets are of another kind : they are designed to 
1715 contain other widgets in order to build larger dialog boxes. 
1716 For example, the \texttt{LayoutSplit} widget is a container which 
1717 ``splits'' horizontally a window into two parts, 
1718 each part including another widget. 
1719 The size of the two parts can be adjusted by the user thanks 
1720 to a ``handle''.
1721
1722 The script \texttt{scripts/test/testSplit.bbs} demonstrate its use. 
1723 Run it : it displays a window with two sliders. 
1724 Move the sliders and close the window. 
1725 The final positions of the sliders are printed out. 
1726 Now edit the file to see how this is done :
1727
1728 \begin{file}{scripts/test/testSplit.bbs}
1729 \begin{verbatim}
1730 load std
1731 load wx
1732
1733 new Slider s1
1734 new Slider s2
1735
1736 new LayoutSplit s
1737 connect  s1.Widget s.Widget1
1738 connect  s2.Widget s.Widget2
1739
1740 print s1=$s1.Out$\\n
1741 print s2=$s2.Out$\\n
1742 \end{verbatim}
1743 \end{file}
1744
1745 First, the two sliders \texttt{s1} and \texttt{s2} are created.
1746 A \texttt{LayoutSplit} box \texttt{s} is also created. 
1747 The \texttt{connect} commands then ``includes'' the sliders in the 
1748 split ``container''. 
1749 The input \texttt{Widget} is common to all widget boxes : 
1750 every widget can be inserted into another widget. 
1751 The outputs \texttt{Widget1},\texttt{Widget2}  are specific of \emph{container} 
1752 widgets 
1753 (in \bbi type \texttt{help Slider} : 
1754 you will see the output \texttt{Widget}; 
1755 type \texttt{help LayoutSplit} : 
1756 you will see the inputs \texttt{Widget1} and \texttt{Widget2} 
1757 and the output \texttt{Widget}). 
1758 When you connect the \texttt{Widget} output of a container 
1759 to the \texttt{Widget}i input of a widget, 
1760 you order to include the widget in the container.
1761 Of course, the order of connection is important. 
1762 In our case, the slider \texttt{s1} is included first, 
1763 then the slider \texttt{s2} : \texttt{s1} will be placed 
1764 on top of \texttt{s2} (the \texttt{LayoutSplit} box is 
1765 implemented that way, but this is arbitrary choice).
1766
1767 Right now, there are only \emph{three} container widgets in the \texttt{wx} package : 
1768 \begin{itemize} 
1769 \item {the \texttt{LayoutSplit} widget} we just described, the \texttt{LayoutLine} , and the \texttt{LayoutTab}
1770 widget. 
1771
1772 \item {the \texttt{LayoutLine} widget} can have multiple children and 
1773 divides its window into as much parts as children, 
1774 each part of equal size. 
1775 The orientation of the \texttt{LayoutSplit} or of the \texttt{LayoutLine}  can be changed by the input \texttt{Orientation}.
1776 See the example \texttt{test/testSizer.bbs}.
1777 With only those two containers you can already create 
1778 complex dialog boxes (of course containers can be nested, which leads to tree-like structures of widgets). 
1779 See the script \texttt{bbtk/share/bbtk/bbs/wx/appli/ExampleLayoutSplit.bbs} for an example.
1780
1781 \item {The \texttt{LayoutTab}  widget} is based on the \texttt{wxNotebook.}\\
1782 The label of each 'note book' is the name of the object it contains.
1783 \end{itemize}
1784
1785
1786 %=====> TODO \\
1787
1788
1789 %One word about a special widget in the package \texttt{wx} : 
1790 %the \texttt{Button}... to be continued.
1791
1792 % ==========================================
1793 \subsubsection{Deeper in the boxes}
1794 \label{bbi-deep-box}
1795 % ==========================================
1796
1797 Any widget box has two mandatory Inputs :
1798 \begin{itemize}
1799   \item {\bf\emph{BoxExecute}}     : Any signal received by this input executes the box
1800   \item {\bf\emph{BoxProcessMode}} : Sets the processing mode of the box :
1801   \begin{itemize}
1802     \item {\bf\emph{Pipeline}} : bbBackwardUpdate() calls Process() only if Status == MODIFIED \\
1803                                  The box executes itself only when an entry was changed (normal pipeline processing).
1804     \item {\bf\emph{Reactive}} : bbSetModifiedStatus() calls bbUpdate() \\
1805                                  Warning : Re-processed immediately when \emph{any entry} changed.\\
1806                                  To be more selective, better use \texttt{connect A.BoxChange \emph{currentBox}.BoxExecute}.    
1807     \item {\bf\emph{Always}}   : bbUpdate() always calls Process. \\
1808                                  Usefull for 'sources', that must be processed, even when no entry changed (e.g. : FileSelector, ColorSelector)\\
1809                                  This one is not end user intended (for Package developer only)
1810   \end{itemize}   
1811 \end{itemize}
1812
1813 Any widget box has five Inputs, that will be dealt with only if the box is not connected to the \emph{Widget}i of any \emph{Layout box} :  
1814 \begin{itemize}
1815   \item {\bf\emph{WinHeight}} : Height of the window 
1816   \item {\bf\emph{WinWidth}}  : Width of the window  
1817   \item {\bf\emph{WinTitle}}  : Title of the window
1818   \item {\bf\emph{WinClose}}  : Any received signal closes the window
1819   \item {\bf\emph{WinHide}}   : Any received signal hides the window
1820   \item {\bf\emph{WinDialog}} : When set to 'true', creates a \emph{dialog window}, that blocks the pipeline until it is closed (\emph{modal})   
1821 \end{itemize}
1822
1823
1824 Any \emph{Layout box} (i.e. \emph{LayoutLine}, \emph{LayoutSplit} or \emph{LayoutTab}) has at one or more mandatory Inputs :
1825 \begin{itemize}
1826   \item {\bf\emph{Widget}}\texttt{i} : e.g. a \emph{LayoutSplit} box (Widget which splits a window in two resizeable parts) 
1827        has two Input parameters \emph{Widget1} and \emph{Widget2}, used to embed the child windows.\\
1828        e.g. a  \emph{LayoutLine} divides the window in up to 9 (depending on the number of inputs \emph{Widget}i) fixed size parts.  
1829 \end{itemize} 
1830
1831
1832 Any widget box has two mandatory Outputs  :
1833
1834 \begin{itemize}
1835   \item {\bf\emph{Widget}} : that is the \texttt{wxWindow} itself. If it's not connected to the \texttt{Widget}\emph{i} of any \emph{Layout box}, it
1836      will popup. If it's connected to the \texttt{Widget}\texttt{\emph{i}} of any \texttt{Layout box}, it will be embedded in its parent window.
1837   \item {\bf\emph{Boxchange}}  : Signals any modification of the box. This output may be connect if necessary to the \emph{BoxExecute} entry of an other box,
1838    further within the execution pipeline.
1839 \end{itemize}    
1840
1841
1842
1843 % ==========================================
1844 \subsection{More on ...}
1845 \label{bbi-more-on}
1846 % ==========================================
1847
1848 % ==========================================
1849 \subsubsection{Black box packages}
1850 \label{bbi-more-on-packages}
1851 % ==========================================
1852 There are various others user-intended packages :
1853
1854 \begin{verbatim}
1855 ---> Were moved in a 'Reference Manual' ?\\
1856 ---> Any suggestion welcome!
1857 \end{verbatim}
1858
1859 \begin{itemize}
1860 \item{vtk} \\
1861 \item{itk} \\
1862 \item{...} \\
1863 \end{itemize}
1864 % ==========================================
1865 \subsubsection{Pipeline processing}
1866 \label{bbi-more-on-pipeline-processing}
1867 % ==========================================
1868 \begin{itemize}
1869 \item the ``control'' mechanism in bbi.
1870
1871 When a box is requested to update itself, it asks (recursively) each one of its inputs if it was modified.\\
1872 In normal pipe-line mode, it will be re-processed if at least one of its imputs was actually modified, as the output of a previous box.
1873
1874 (switch exec commands, e.g. Button)
1875 \item the role of ProcessMode to update widgets.
1876 \end{itemize}
1877 % ==========================================
1878 \subsubsection{Complex black boxes}
1879 \label{bbi-more-on-complex-black-boxes}
1880 Creation of complex widgets (containers, contained...)
1881
1882 You can include script files in other script files, 
1883 like in the following example :
1884
1885
1886 \begin{verbatim}
1887 # Defines the Add4 black box which adds 4 doubles 
1888 include Add3
1889 define Add4
1890   author "myself"
1891   description "adds 4 doubles"
1892   new Add3 a
1893   new Add b
1894   connect a.Out b.In1
1895   input In1 a.In1 "first double to add"
1896   input In2 a.In2 "second double to add"
1897   input In3 a.In3 "third double to add"
1898   input In4 b.In2 "fourth double to add"
1899   output Out b.Out "output"
1900 endefine
1901 \end{verbatim}
1902
1903 The inner boxes have they own entries (In1, In2, In3 for box a, In1, In2 for box b )\\
1904 Only the inputs In1, In2, In3 of box a and the input In2 of box b is of interest for the end user, but he dosn't want to have to
1905 care neither about the inner boxes name, nor about the names of their Inputs.\\
1906 The writer of the complex box has the ability to give these inputs a meaningfull name !
1907 \begin{verbatim}
1908   input In3 a.In3 "third double to add"
1909   input In4 b.In2 "fourth double to add"
1910 \end{verbatim}
1911
1912 %\subsubsection{Advanced issues}
1913 %\paragraph{Reducing the number of inputs of a box}
1914
1915 % ==========================================
1916 \subsubsection{Errors}
1917 \label{bbi-more-on-errors}
1918
1919 % ==========================================
1920 \subsubsection{Creating and using your own uninstalled version of bbStudio}
1921 \label{bbi-more-on-your_own_version}
1922
1923 Suppose you want to run your own uninstalled version (say : you downloaded and compiled the
1924 cvs version in order to use a recently commited patch, but you want to be able
1925 to still use the standard version).
1926  
1927 You have to :
1928 \begin{itemize} 
1929 \item cvs checkout the sources :
1930 \begin{verbatim}
1931 cvs checkout bbtk
1932 \end{verbatim}
1933 \item 
1934 create a build directory
1935 \begin{verbatim}
1936 mkdir buildBBTK
1937 \end{verbatim}
1938 \item cd in the build directory:
1939 \begin{verbatim}
1940 cd buildBBTK
1941 \end{verbatim}
1942 \item run ccmake.
1943 \begin{verbatim}
1944 ccmake ../bbtk
1945 \end{verbatim}
1946
1947 Don't forget to switch ON the flag \textttBBTK\_COMPILE\_DEBUG\_MESSAGE \\
1948 (see figure : \ref{bb-ccmake})
1949
1950 \begin{figure}[!ht]
1951 \caption{\label{bb-ccmake}\Running ccmake}
1952 \begin{center}
1953 \includegraphics[width=0.6\textwidth]{ccmake.png}
1954 \end{center}
1955 \end{figure}
1956
1957 \item As usual, type \texttt{c} untill there is no longer any area quoted with a * (or enlighted in red)\\
1958 Ask for generation (type \texttt{g} -once is always enough-)
1959
1960 \item Ask for compilation and link.
1961 \begin{verbatim}
1962 make
1963 \end{verbatim}
1964 For some strange reasons (?!?), you may be warned that an error occured while documentation generation.\\
1965 Take it easy, \texttt{make} again!\\
1966
1967 The dynamic libraries (\texttt{.dll} or \texttt{.so} and the executable programs will be created in the \testtt{bin}
1968 directory of the built tree.
1969
1970 \item choose to install or not your own version.
1971 \begin{verbatim}
1972 make install
1973 \end{verbatim}
1974 Linux users : Don't forget to \texttt{sudo} before.
1975 \end{itemize}
1976 % ==========================================
1977 \subsubsection{\bbtk configuration file and search pathes}
1978 \label{bbi-more-on-configuration}
1979
1980 At start, \bbi tries to open an \texttt{xml} 
1981 configuration file named \texttt{bbtk\_config.xml}. 
1982 The search order is 
1983 \begin{enumerate}
1984 \item The current directory
1985 \item The subdir \texttt{.bbtk} of the user's home directory. 
1986 \begin{itemize} 
1987 \item On \texttt{Unix}, the home directory is the
1988 one stored by the environnement variable \texttt{HOME}, 
1989 typically \texttt{/home/username}.
1990 \item On \texttt{Windows}, the home directory is 
1991 the user's profile directory stored by the environnement 
1992 variable \texttt{USERPROFILE}, 
1993 typically \texttt{C:\\...}.
1994 \end{itemize}
1995 \item If none of these two pathes contains the file then it creates 
1996 a new one in the \texttt{.bbtk} directory. 
1997 \end{enumerate}
1998
1999 Once created, you can edit the \texttt{bbtk\_config.xml} file located 
2000 in your \texttt{.bbtk} directory. It contains :
2001
2002 \begin{file}{bbtk\_config.xml}
2003 \begin{verbatim}
2004 <?xml version="1.0" encoding="iso-8859-1"?>
2005 <config>
2006    <description>  </description>
2007    <bbs_path>     </bbs_path>
2008    <package_path> 
2009       /usr/local/lib
2010    </package_path>
2011    <data_path> </data_path>
2012    <default_temp_dir>$</default_temp_dir>
2013 </config>
2014 \end{verbatim}
2015 \end{file}
2016
2017 You can add pathes to 
2018 \begin{itemize}
2019 \item A custom folder in which to search for \texttt{.bbs} scripts (\texttt{include} command of \bbi) by adding an \texttt{xml} tag : 
2020 \texttt{<bbs\_path>complete\_path\_to\_folder<\/bbs\_path>}.
2021 \item A custom folder in which to search for packages (\texttt{load} command of \bbi) by adding an \texttt{xml} tag : 
2022 \texttt{<package\_path>complete\_path\_to\_folder<\/package\_path>}.
2023 \end{itemize}
2024
2025
2026 \newpage
2027
2028 % ==========================================
2029 \subsection{Language reference}
2030 \label{bbi-reference}
2031 % ==========================================
2032
2033
2034 % ==========================================
2035 \subsubsection{pipeline creation and execution related commands}
2036 \label{bbi-reference-creation-execution}
2037 % ==========================================
2038
2039
2040 % ==========================================
2041 \begin{table}[!ht]
2042 \caption{\label{bbi-reference-box} \bbi pipeline creation and execution related commands.}
2043 \small
2044 \begin{tabular}{|lcm{6cm}|}
2045 \hline
2046 Command & Parameters & Effect \\ \hline
2047
2048 \texttt{new} & \texttt{<boxtype>} \texttt{<box-name>}& 
2049 Creates a box of type \texttt{boxtype} and name  
2050 \texttt{box-name}.\\ \hline
2051
2052 \texttt{delete} & \texttt{<box-name>} & 
2053 Destroys the box named \texttt{box-name}.\\ \hline 
2054
2055 \texttt{connect} & \texttt{<box1.output>} \texttt{<box2.input>} & 
2056 Connects the output 
2057 \texttt{output} of the box named \texttt{box1} 
2058 to the input \texttt{input} of the box named \texttt{box2} \\ \hline 
2059
2060 \texttt{set} & \texttt{<box.input>} \texttt{<value>} &
2061 Sets the input \texttt{input} of 
2062 the box named \texttt{box} to the value \texttt{value}.
2063 An \texttt{adaptor} must exist
2064 in the packages loaded which converts a \texttt{std::string} 
2065 to the type of the input \texttt{input}. \\ \hline 
2066
2067 \texttt{print} & \texttt{<string>} & 
2068 Prints the string after substituting each token of the form \texttt{\$box.output\$} by the adaptation to string of the value of the 
2069 output \texttt{output} of the box named \texttt{box}. 
2070 An \texttt{adaptor} must exist
2071 in the packages loaded which converts 
2072 the type of the output \texttt{output}
2073 to a \texttt{std::string}.
2074 \\ \hline 
2075
2076 \texttt{exec} & \texttt{<box-name>} & 
2077 Executes the box named \texttt{box-name}.
2078 If needed the boxes 
2079 connected to its inputs 
2080 are also processed recursively (pipeline processing).\\ \hline 
2081 \texttt{exec} & \texttt{freeze} & 
2082  Allows to block execution commands while keeping definition commands active.(This one is not for end user)\\ \hline 
2083 \texttt{exec} & \texttt{unfreeze} & 
2084  Turns back to 'normal' mode (This one is not for end user).\\ \hline 
2085 \end{tabular}
2086 \end{table}
2087 % ==========================================
2088
2089 \newpage
2090
2091 % ==========================================
2092 \subsubsection{Interpreter related commands}
2093 \label{bbi-reference-interpreter}
2094 % ==========================================
2095
2096 % ==========================================
2097 \begin{table}[!ht]
2098 \caption{\label{bbi-reference-interpreter}\bbi intepreter related commands.}
2099 \small
2100 \begin{tabular}{|lcm{6cm}|}
2101 \hline
2102 Command & Parameters & Effect \\ \hline
2103
2104 \texttt{author} &  \texttt{<author-name>} & 
2105 Adds the string \texttt{<author-name>} to the author information of the black box being defined \\ \hline 
2106
2107 \texttt{category} & \texttt{<category-name>} & 
2108   Adds the string \texttt{<category-name>} to the category information of the black box being defined \\ \hline 
2109
2110 \texttt{help} & - & 
2111 Prints help on available commands \\ \hline 
2112
2113 & \texttt{<command-name>} & 
2114 Prints help on the command \texttt{command-name} \\ \hline 
2115
2116 & \texttt{packages} & 
2117 Prints help on available packages and their box types 
2118 (without description)\\ \hline 
2119
2120 & \texttt{<package-name>} & 
2121 Prints help on the package \texttt{package-name} and its boxes 
2122 (with brief description). 
2123 The package must have been previously loaded \\ \hline 
2124
2125 & \texttt{<box-type>} & 
2126 Prints help (with full description) on the type of box 
2127 \texttt{box-type}. 
2128 The box type must belong to a package which has been previously loaded \\ \hline 
2129
2130 & \texttt{<debug-directive>} & 
2131 [expr|-C|-D] 
2132   Prints debug info on living bbtk objects containing the string \texttt{expr} (default expr=''). 
2133          \texttt{-C} checks the factory integrity.
2134          \texttt{-D} turns on objects debug info after main ends\\ \hline 
2135
2136 \texttt{include} & \texttt{<file-name>} & 
2137 Includes and executes the content of the file named \texttt{file-name} 
2138 exactly like if you were typing its content at the place were the 
2139 \texttt{include} command is. \\ \hline 
2140
2141 \texttt{load} & \texttt{<package-name>} & 
2142 Loads the package \texttt{package-name} (use it only if you know that you won't work with complex black boxes) \\ \hline 
2143
2144 \texttt{include} & \texttt{<package-name>} & 
2145 Loads the package \texttt{package-name} and includes all the complex black boxes that comes with it \\ \hline 
2146
2147 \texttt{kind} & \texttt{<box kind>} & 
2148 Specifies the \texttt{kind} of the complex black boxes you are describing \\ \hline 
2149
2150 \texttt{unload} & \texttt{<package-name>}& 
2151 Unloads the package \texttt{package-name}. 
2152 The package must have been previously loaded. 
2153 No box of a type defined in this package must still exist.\\ \hline 
2154
2155 \texttt{message} & \texttt{<category>} \texttt{<level>} & 
2156 Sets the level of verbosity of \bbi for the category of messages 
2157 \texttt{category} to \texttt{level}.\\ \hline 
2158 %See \ref{verbosity}. 
2159
2160 \texttt{config} & - & Displays the Configuration parameters\\ \hline 
2161
2162 \texttt{reset} & - & Deletes all boxes and unloads all packages so 
2163 that \bbi gets back to its initial state \\ \hline 
2164
2165 \texttt{quit} & - & Exits the interpreter (Don't use it under \bbStudions)\\ \hline 
2166
2167 \end{tabular}
2168 \end{table}
2169 % ==========================================
2170
2171
2172
2173 % ==========================================
2174 \subsubsection{complex black box definition related commands}
2175 \label{bbi-reference-black-box-definition}
2176 % ==========================================
2177
2178 % ==========================================
2179 \begin{table}[!ht]
2180 \caption{\label{bbi-reference-complex-box} \bbi complex black box definition related commands.}
2181 \small
2182 \begin{tabular}{|lcm{6cm}|}
2183 \hline
2184 Command & Parameters & Effect \\ \hline
2185
2186
2187 \texttt{define} & \texttt{<box-type>} & 
2188 Starts the definition of a complex black box of type  
2189 \texttt{box-type}\\ \hline 
2190
2191 \texttt{endefine} & - & 
2192 Ends the definition of a complex black box type\\ \hline 
2193
2194 \texttt{author} & \texttt{<string>} & 
2195 Sets the author(s) of the complex black box currently being defined \\ \hline 
2196
2197 \texttt{description} & \texttt{<string>} & 
2198 Sets the description of the complex black box currently being defined \\ \hline 
2199
2200 \texttt{input} & \texttt{<name>} \texttt{<box.input>} \texttt{<help>} & 
2201 Defines a new input for the current complex black box, 
2202 named \texttt{name}. 
2203 It is defined as corresponding to 
2204 the input \texttt{input} of the box \texttt{box}.
2205  
2206 \texttt{<help>} is the help string for the new input.
2207 The box \texttt{box} must already have been created in the complex box 
2208 and of course have an input named \texttt{input}.\\ \hline 
2209
2210 \texttt{output} & \texttt{<name>} \texttt{<box.output>} \texttt{<help>} & 
2211 Defines a new output for the current complex black box, 
2212 named \texttt{name}. 
2213 It is defined as corresponding to 
2214 the output \texttt{output} of the box \texttt{box}. 
2215 \texttt{<help>} is the help string for the new output.
2216 The box \texttt{box} must already have been created in the complex box and of course have an output named \texttt{output}. \\ \hline 
2217
2218
2219 \end{tabular}
2220 \end{table}
2221 % ==========================================
2222
2223 \newpage
2224
2225 % ==========================================
2226 \vspace{0.5cm}\hrule \\
2227 \section{The Package Browser}
2228 \label{Package_Browser}
2229 % ==========================================
2230
2231
2232 You can run it using the tool bar of the 'Command' part.
2233
2234 See figure \ref{Package_Browser}.
2235
2236 \begin{figure}[!ht]
2237 \caption{\label{Package_Browser}The Package Browser}
2238 \begin{center}
2239 \includegraphics[width=0.6\textwidth]{Package_Browser.png}
2240 \end{center}
2241 \end{figure}
2242
2243 It allows you to query informations about what you can find in the packages (boxes and applications), using several criterions
2244 (warning : it's case sensitive, i.e \texttt{Button} will give different results thn \texttt{button} ...)
2245 \begin {itemize}
2246 \item Pakages :\\
2247 All the boxes and applications held in a given package (e.g. \texttt{wxvtk}, \texttt{std}, ...)
2248 \item Name :\\
2249 You can query on a subpart of the name of a box or an application (e.g. \texttt{DICOM})
2250 \item Description :\\
2251 You can query on a substring of the description of a box or an application (e.g. \texttt{utton} : user wants to get all
2252 the\texttt{Button} as well as the \texttt{button} )
2253 \item Category :\\
2254 You can query on a sub part of the category name of a box or an application (e.g. \texttt{3D})
2255 \item Input Type :\\
2256 You can query all the boxes or applications that have at least one Input entry of the given type (e.g. \texttt{int})
2257 \item Output Type :\\
2258 You can query all the boxes or applications that have at least one Output entry of the given type (e.g. \texttt{int})
2259 \item Input Nature :\\
2260 You can query all the boxes or applications that have at least one Input entry of the given nature (e.g. \texttt{signal})
2261 \item Output Nature :\\
2262 You can query all the boxes or applications that have at least one Output entry of the given nature (e.g.
2263 \texttt{signal},\texttt{file name})
2264 \end {itemize}
2265
2266
2267 All these criterions are \emph{AND}ed while the query process.\\
2268 You can get the whole description of a given box or application clicking on its name.
2269
2270
2271 % ==========================================
2272 \vspace{0.5cm}\hrule \\
2273 \section{Using third party Package}
2274 \label{Third_Party_Package}
2275 % ==========================================
2276
2277 You will have to update the \emph{bbtk\_config.xml} file.\\
2278 To know where it is stored, just click on \texttt{Config} button of the \texttt{Command} part toolbar.
2279
2280 You'll get something like :
2281
2282 \begin{verbatim}
2283 =============
2284  Configuration
2285  =============
2286  bbtk_config.xml    : [/home/jpr/Creatis/bbtk/binLIN/bin/bbtk_config.xml]
2287  Documentation Path : [/home/jpr/Creatis/bbtk/binLIN/bin/../share/bbtk/doc]
2288  Data Path          : [/home/jpr/Creatis/bbtk/binLIN/bin/../share/bbtk/data]
2289  Temp Directory     : [/home/jpr/Creatis/bbtk/binLIN]
2290  File Separator     : [/]
2291  BBS Paths   
2292  --- [.]
2293  --- [/home/jpr/Creatis/bbtk/binLIN/bin/../share/bbtk/bbs]
2294  --- [/home/jpr/Creatis/bbtk/binLIN/share/bbtk/bbs]
2295  PACKAGE Paths : 
2296  --- [.]
2297  --- [/home/jpr/Creatis/bbtk/binLIN/bin]
2298  --- [/home/jpr/Creatis/bbtk/binLIN/bin/../lib]
2299  --- [/home/jpr/Creatis/bbtk/binLIN/bin]
2300  --- [/home/jpr/Creatis/bbtk/binLIN/bin\Debug]
2301  --- [/home/jpr/Creatis/bbtk/binLIN/bin\Release] 
2302 \end{verbatim}
2303
2304 (depending on who you are, and whether \texttt{bbStudio} is installed or not.)\\
2305
2306 Just use your favourite text editor to add :
2307 \begin{itemize}
2308 \item
2309  at the end of the \texttt{BBS Paths} part 
2310  the name of the directory that contains the \texttt{.bbs} scripts of the package you
2311 want to use,
2312 \item at the end of the \texttt{PACKAGE Paths} part
2313  the name of the directory that contains the dynamic libraries (\texttt{.dll} or \texttt{.so}) of the package
2314 \end{itemize}
2315
2316 If you want (and sure you will) to be able to use the Help tools as well on the features provided by this package, you must use the
2317 option \texttt{Generate index}  in the menu \texttt{Tools} of the \texttt{Files} part toolbar.  
2318 % ==========================================
2319 \vspace{0.5cm}\hrule \\
2320 \section{Using black boxes in \CPP programs}
2321 \label{cpp}
2322 % ==========================================
2323
2324 A very usefull feature is that you may use any black box within a \CPP program witout worrying about wxWigets main window.\\
2325
2326 Let's look a the following bbs script :
2327
2328 \begin{verbatim}
2329 # Load the packages
2330 load std
2331 load wx
2332
2333 # Create the Objects
2334 new Slider     slider
2335 new OutputText text
2336 new LayoutLine layout
2337
2338 # Graphical pipeline
2339 connect slider.Widget    layout.Widget1
2340 connect text.Widget      layout.Widget2
2341
2342 # Execution pipeline
2343 connect slider.BoxChange text.BoxExecute
2344 connect slider.Out       text.In
2345
2346 # Go!
2347 exec layout
2348 \end{verbatim}
2349
2350 User wants to create a slider and an output text, within a layoutline, and display the slider value in the output text.\\ 
2351 Think about the (little!) nightmare to code the same, in 'raw C++', using wxWidgets.\\
2352
2353 Using \bbtk you just 'convert' the script :
2354 \begin{verbatim}
2355
2356 #include <bbwxSlider.h>
2357 #include <bbwxOutputText.h>
2358 #include <bbtkFactory.h>
2359 #include <bbwxLayoutLine.h>
2360
2361 int main(int argv, char* argc[])
2362 {
2363       // we need to intanciate a bbtk::Factory to be aware of the adaptors
2364       bbtk::Factory::Pointer factory = bbtk::Factory::New();
2365       
2366       // Load the packages
2367       // ----------------  
2368       factory->LoadPackage("std");
2369       factory->LoadPackage("wx");
2370       
2371       // Create the Objects
2372       // ------------------      
2373       bbwx::Slider::Pointer     slider   = bbwx::Slider::New("slider");
2374       bbwx::OutputText::Pointer text     = bbwx::OutputText::New("text");
2375       bbwx::LayoutLine::Pointer layout   = bbwx::LayoutLine::New("layout");
2376       
2377       // Graphical pipeline
2378       bbtk::Connection::Pointer c1       = bbtk::Connection::New(slider,"Widget",
2379                                                            layout,"Widget1");
2380                                                            
2381       bbtk::Connection::Pointer c2       = bbtk::Connection::New(text,"Widget",
2382                                                            layout,"Widget2");
2383                                                                                                                                                                            
2384       // Execution pipeline
2385       // ------------------
2386       
2387       // We have to pass the 'factory', in order to call automatically an adaptor,
2388       // if necessary.
2389       bbtk::Connection::Pointer s2t      = bbtk::Connection::New(slider,"Out",
2390                                                             text,"In",
2391                                                             factory);      
2392        bbtk::Connection::Pointer c3       = bbtk::Connection::New(slider,"BoxChange",
2393                                                             text,"BoxExecute");      
2394       layout->bbSetInputWinDialog(true);
2395       
2396       // Go!
2397       // ---     
2398       layout->bbExecute();
2399
2400     }
2401   catch (bbtk::Exception e)
2402     {
2403       bbtk::MessageManager::SetMessageLevel("Error",1);
2404       e.Print();
2405     }
2406 }
2407 \end{verbatim}
2408
2409 %\bibliography{all}
2410
2411
2412
2413 %\section{Conclusion}
2414
2415
2416 \end{document}
2417