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