]> Creatis software - bbtk.git/blob - kernel/src/bbtkComplexBlackBoxDescriptor.h
27dcd4dd89ebb8c399fbfef8f4ef7de10a89b149
[bbtk.git] / kernel / src / bbtkComplexBlackBoxDescriptor.h
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbtkComplexBlackBoxDescriptor.h,v $
5   Language:  C++
6   Date:      $Date: 2008/03/07 10:21:30 $
7   Version:   $Revision: 1.2 $
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
47     /// Default ctor with name 
48     ComplexBlackBoxDescriptor(const std::string& name); 
49     /// Default dtor
50     ~ComplexBlackBoxDescriptor();
51
52     /// Sets the factory used 
53     void SetFactory(Factory* f) { mFactory = f; }
54     /// Gets the factory used
55     Factory* GetFactory() { return mFactory; }
56     /// Gets the factory used (const)
57     const Factory* GetFactory() const { return mFactory; }
58
59     /// Creates an instance of name <name> of the ComplexBlackBox of which this is the descriptor 
60     virtual BlackBox* CreateInstance(const std::string& name);
61
62     /// Adds a black box to the complex box
63     /// Needs a factory set !
64     void Add ( const std::string& type,
65                const std::string& name
66                ); 
67     /// Connects two black boxes of the complex box
68     /// Needs a factory set !
69      void Connect ( const std::string& from,
70                    const std::string& output,
71                    const std::string& to,
72                    const std::string& input
73                    ); 
74     /// Defines an input of the complex box
75     void DefineInput ( const std::string& name,
76                        const std::string& box,
77                        const std::string& input,
78                        const std::string& help);
79     /// Defines an output of the complex box
80     void DefineOutput ( const std::string& name,
81                        const std::string& box,
82                        const std::string& output,
83                        const std::string& help);
84  
85     /// Sets the name of the script file from which it is defined
86     void SetScriptFileName(const std::string& n) { mScriptFileName = n; }
87     /// Gets the name of the script file from which it is defined
88     std::string GetScriptFileName() const { return mScriptFileName; }
89    
90     /// 
91     void AddToExecutionList( const std::string& box );
92
93     ComplexBlackBox* GetPrototype() { return mPrototype; }
94     void PrintBlackBoxes(); 
95    
96     /// Prints help on the black box
97     void GetHelp(bool full=true) const;
98  
99     /// Writes html formatted help into the output file stream. 
100     /// detail and level are used for graphical representation of 
101     /// complex black boxes (see ComplexBlackBox::InsertHTMLGraph)
102     /// output_dir is the directory in which to write auxilliary files 
103     /// (.dot/.png/.cmap)
104     void InsertHtmlHelp ( std::ofstream& s, 
105                           int detail, int level,
106                           const std::string& output_dir = "",
107                           bool relative_link = false);
108
109     /// Generates a png image representing the pipeline graph of the 
110     /// complex box and writes html code to insert it 
111     /// into the output file stream. 
112     /// detail : 
113     /// level : depth of nested complex boxes graph development 
114     /// (0:only this box level 
115     /// output_dir is the directory in which to write the files 
116     /// (.dot/.png/.cmap)
117     void InsertHTMLGraph( std::ofstream& s, 
118                           int detail, int level, 
119                           const std::string& output_dir = "",
120                           bool relative_link = false );
121     
122
123
124   private:
125     /// Default ctor is private (must have name and factory)
126     ComplexBlackBoxDescriptor() {}
127     /// The factory used
128     Factory* mFactory;
129     /// The complex box in which boxes and connections are stored
130     ComplexBlackBox* mPrototype;
131     /// The name of the script file from which it was created
132     std::string mScriptFileName;
133     
134   };
135   // class ComplexBlackBoxDescriptor
136   //==========================================================================
137
138
139  
140 }
141 // namespace bbtk
142 #endif