]> Creatis software - bbtk.git/blob - kernel/src/bbtkComplexBlackBoxDescriptor.h
*** empty log message ***
[bbtk.git] / kernel / src / bbtkComplexBlackBoxDescriptor.h
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkComplexBlackBoxDescriptor.h,v $
4   Language:  C++
5   Date:      $Date: 2008/10/17 08:18:12 $
6   Version:   $Revision: 1.6 $
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
14 *  This software is governed by the CeCILL-B license under French law and 
15 *  abiding by the rules of distribution of free software. You can  use, 
16 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
17 *  license as circulated by CEA, CNRS and INRIA at the following URL 
18 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
19 *  or in the file LICENSE.txt.
20 *
21 *  As a counterpart to the access to the source code and  rights to copy,
22 *  modify and redistribute granted by the license, users are provided only
23 *  with a limited warranty  and the software's author,  the holder of the
24 *  economic rights,  and the successive licensors  have only  limited
25 *  liability. 
26 *
27 *  The fact that you are presently reading this means that you have had
28 *  knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */                                                                         
30
31
32 /**
33  *  \file 
34  *  \brief Class bbtk::ComplexBlackBoxDescriptor : describes a ComplexBlackBox (constituents, connections) and is able to create an instance of it.
35  */
36 /**
37  * \class bbtk::ComplexBlackBoxDescriptor
38  * \brief Describes a ComplexBlackBox (constituents, connections) and is able to create an instance of it.
39  */
40
41 #ifndef __bbtkComplexBlackBoxDescriptor_h__
42 #define __bbtkComplexBlackBoxDescriptor_h__
43
44 #include "bbtkBlackBoxDescriptor.h"
45 #include "bbtkComplexBlackBoxInputDescriptor.h"
46 #include "bbtkComplexBlackBoxOutputDescriptor.h"
47 #include "bbtkFactory.h"
48 #include <fstream>
49
50 namespace bbtk
51 {
52
53   class ComplexBlackBox;
54   typedef boost::shared_ptr<ComplexBlackBox> ComplexBlackBoxPointer;
55
56   //==========================================================================
57   class BBTK_EXPORT ComplexBlackBoxDescriptor : 
58     public bbtk::BlackBoxDescriptor
59   {
60     BBTK_OBJECT_INTERFACE(ComplexBlackBoxDescriptor);
61     typedef BlackBoxDescriptor Superclass;
62   public:
63     friend class ComplexBlackBox;
64
65     static Pointer New(const std::string& name); 
66     /// Sets the factory used 
67     void SetFactory(Factory::Pointer f) { mFactory = f; }
68     /// Gets the factory used
69     Factory::Pointer GetFactory() const { return mFactory.lock(); }
70
71     /// Releases the descriptor
72     //    void Release(bool release_package = true);
73
74     /// Gets the factory used (const)
75     //    const Factory* GetFactory() const { return mFactory; }
76
77     /// Creates an instance of name <name> of the ComplexBlackBox of which this is the descriptor 
78     virtual BlackBoxPointer NewBlackBox(const std::string& name);
79
80     /// Adds a black box to the complex box
81     /// Needs a factory set !
82     void Add ( const std::string& type,
83                const std::string& name
84                ); 
85
86     /// Removes a black box from the complex box
87     void Remove( const std::string& name, bool remove_connections = true);
88
89     /// Connects two black boxes of the complex box
90     /// Needs a factory set !
91      void Connect ( const std::string& from,
92                    const std::string& output,
93                    const std::string& to,
94                    const std::string& input
95                    ); 
96     /// Defines an input of the complex box
97     void DefineInput ( const std::string& name,
98                        const std::string& box,
99                        const std::string& input,
100                        const std::string& help);
101     /// Defines an output of the complex box
102     void DefineOutput ( const std::string& name,
103                        const std::string& box,
104                        const std::string& output,
105                        const std::string& help);
106  
107  
108     /// Sets the name of the script file from which it is defined
109     void SetScriptFileName(const std::string& n) { mScriptFileName = n; }
110     /// Gets the name of the script file from which it is defined
111     std::string GetScriptFileName() const { return mScriptFileName; }
112    
113     /// 
114     void AddToExecutionList( const std::string& box );
115
116     ComplexBlackBoxPointer GetPrototype() { return mPrototype; }
117     void PrintBlackBoxes(); 
118    
119     /// Prints help on the black box
120     void GetHelp(bool full=true) const;
121  
122     /// Writes html formatted help into the output file stream. 
123     /// detail and level are used for graphical representation of 
124     /// complex black boxes (see ComplexBlackBox::InsertHTMLGraph)
125     /// output_dir is the directory in which to write auxilliary files 
126     /// (.dot/.png/.cmap)
127     void InsertHtmlHelp ( std::ofstream& s, 
128                           int detail, int level,
129                           const std::string& output_dir = "",
130                           bool relative_link = false);
131
132     /// Generates a png image representing the pipeline graph of the 
133     /// complex box and writes html code to insert it 
134     /// into the output file stream. 
135     /// detail : 
136     /// level : depth of nested complex boxes graph development 
137     /// (0:only this box level 
138     /// output_dir is the directory in which to write the files 
139     /// (.dot/.png/.cmap)
140     void InsertHTMLGraph( std::ofstream& s, 
141                           int detail, int level, 
142                           const std::string& output_dir = "",
143                           bool relative_link = false );
144     
145
146    ///
147     virtual void Check(bool recursive=true) const;
148        
149
150
151   protected:
152     /// Default ctor with name is protected
153     ComplexBlackBoxDescriptor(const std::string& name); 
154
155   private:
156     /// The factory used
157     Factory::WeakPointer mFactory;
158     /// The complex box in which boxes and connections are stored
159     ComplexBlackBoxPointer mPrototype;
160     /// The name of the script file from which it was created
161     std::string mScriptFileName;
162     
163   };
164   // class ComplexBlackBoxDescriptor
165   //==========================================================================
166
167
168  
169 }
170 // namespace bbtk
171 #endif