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