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