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