]> Creatis software - bbtk.git/blob - kernel/src/bbtkComplexBlackBoxDescriptor.h
*** empty log message ***
[bbtk.git] / kernel / src / bbtkComplexBlackBoxDescriptor.h
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbtkComplexBlackBoxDescriptor.h,v $
5   Language:  C++
6   Date:      $Date: 2008/04/09 11:16:57 $
7   Version:   $Revision: 1.4 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18
19 /**
20  *  \file 
21  *  \brief Class bbtk::ComplexBlackBoxDescriptor : describes a ComplexBlackBox (constituents, connections) and is able to create an instance of it.
22  */
23 /**
24  * \class bbtk::ComplexBlackBoxDescriptor
25  * \brief Describes a ComplexBlackBox (constituents, connections) and is able to create an instance of it.
26  */
27
28 #ifndef __bbtkComplexBlackBoxDescriptor_h__
29 #define __bbtkComplexBlackBoxDescriptor_h__
30
31 #include "bbtkBlackBoxDescriptor.h"
32 #include "bbtkComplexBlackBoxInputDescriptor.h"
33 #include "bbtkComplexBlackBoxOutputDescriptor.h"
34 #include "bbtkFactory.h"
35 #include <fstream>
36
37 namespace bbtk
38 {
39
40   class ComplexBlackBox;
41   
42   //==========================================================================
43   class BBTK_EXPORT ComplexBlackBoxDescriptor : public bbtk::BlackBoxDescriptor
44   {
45   public:
46     friend class ComplexBlackBox;
47     /// Default ctor with name 
48     ComplexBlackBoxDescriptor(const std::string& name); 
49   protected:
50    /// Default dtor
51     ~ComplexBlackBoxDescriptor();
52   public:
53     /// Sets the factory used 
54     void SetFactory(Factory* f) { mFactory = f; }
55     /// Gets the factory used
56     Factory* GetFactory() { return mFactory; }
57     /// Gets the factory used (const)
58     const Factory* GetFactory() const { return mFactory; }
59
60     /// Creates an instance of name <name> of the ComplexBlackBox of which this is the descriptor 
61     virtual BlackBox* CreateInstance(const std::string& name);
62
63     /// Adds a black box to the complex box
64     /// Needs a factory set !
65     void Add ( const std::string& type,
66                const std::string& name
67                ); 
68     /// Connects two black boxes of the complex box
69     /// Needs a factory set !
70      void Connect ( const std::string& from,
71                    const std::string& output,
72                    const std::string& to,
73                    const std::string& input
74                    ); 
75     /// Defines an input of the complex box
76     void DefineInput ( const std::string& name,
77                        const std::string& box,
78                        const std::string& input,
79                        const std::string& help);
80     /// Defines an output of the complex box
81     void DefineOutput ( const std::string& name,
82                        const std::string& box,
83                        const std::string& output,
84                        const std::string& help);
85  
86  
87     /// Sets the name of the script file from which it is defined
88     void SetScriptFileName(const std::string& n) { mScriptFileName = n; }
89     /// Gets the name of the script file from which it is defined
90     std::string GetScriptFileName() const { return mScriptFileName; }
91    
92     /// 
93     void AddToExecutionList( const std::string& box );
94
95     ComplexBlackBox* GetPrototype() { return mPrototype; }
96     void PrintBlackBoxes(); 
97    
98     /// Prints help on the black box
99     void GetHelp(bool full=true) const;
100  
101     /// Writes html formatted help into the output file stream. 
102     /// detail and level are used for graphical representation of 
103     /// complex black boxes (see ComplexBlackBox::InsertHTMLGraph)
104     /// output_dir is the directory in which to write auxilliary files 
105     /// (.dot/.png/.cmap)
106     void InsertHtmlHelp ( std::ofstream& s, 
107                           int detail, int level,
108                           const std::string& output_dir = "",
109                           bool relative_link = false);
110
111     /// Generates a png image representing the pipeline graph of the 
112     /// complex box and writes html code to insert it 
113     /// into the output file stream. 
114     /// detail : 
115     /// level : depth of nested complex boxes graph development 
116     /// (0:only this box level 
117     /// output_dir is the directory in which to write the files 
118     /// (.dot/.png/.cmap)
119     void InsertHTMLGraph( std::ofstream& s, 
120                           int detail, int level, 
121                           const std::string& output_dir = "",
122                           bool relative_link = false );
123     
124
125    ///
126     virtual void Check(bool recursive=true) const;
127
128   private:
129     /// Default ctor is private (must have name and factory)
130     ComplexBlackBoxDescriptor() {}
131     /// The factory used
132     Factory* mFactory;
133     /// The complex box in which boxes and connections are stored
134     ComplexBlackBox* mPrototype;
135     /// The name of the script file from which it was created
136     std::string mScriptFileName;
137     
138   };
139   // class ComplexBlackBoxDescriptor
140   //==========================================================================
141
142
143  
144 }
145 // namespace bbtk
146 #endif