]> Creatis software - bbtk.git/blob - kernel/src/bbtkComplexBlackBoxDescriptor.h
=== MAJOR RELEASE ====
[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/18 12:59:15 $
7   Version:   $Revision: 1.5 $
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   typedef boost::shared_ptr<ComplexBlackBox> ComplexBlackBoxPointer;
42
43   //==========================================================================
44   class BBTK_EXPORT ComplexBlackBoxDescriptor : 
45     public bbtk::BlackBoxDescriptor
46   {
47     BBTK_OBJECT_INTERFACE(ComplexBlackBoxDescriptor);
48     typedef BlackBoxDescriptor Superclass;
49   public:
50     friend class ComplexBlackBox;
51
52     static Pointer New(const std::string& name); 
53     /// Sets the factory used 
54     void SetFactory(Factory::Pointer f) { mFactory = f; }
55     /// Gets the factory used
56     Factory::Pointer GetFactory() const { return mFactory.lock(); }
57
58     /// Releases the descriptor
59     //    void Release(bool release_package = true);
60
61     /// Gets the factory used (const)
62     //    const Factory* GetFactory() const { return mFactory; }
63
64     /// Creates an instance of name <name> of the ComplexBlackBox of which this is the descriptor 
65     virtual BlackBoxPointer NewBlackBox(const std::string& name);
66
67     /// Adds a black box to the complex box
68     /// Needs a factory set !
69     void Add ( const std::string& type,
70                const std::string& name
71                ); 
72
73     /// Removes a black box from the complex box
74     void Remove( const std::string& name, bool remove_connections = true);
75
76     /// Connects two black boxes of the complex box
77     /// Needs a factory set !
78      void Connect ( const std::string& from,
79                    const std::string& output,
80                    const std::string& to,
81                    const std::string& input
82                    ); 
83     /// Defines an input of the complex box
84     void DefineInput ( const std::string& name,
85                        const std::string& box,
86                        const std::string& input,
87                        const std::string& help);
88     /// Defines an output of the complex box
89     void DefineOutput ( const std::string& name,
90                        const std::string& box,
91                        const std::string& output,
92                        const std::string& help);
93  
94  
95     /// Sets the name of the script file from which it is defined
96     void SetScriptFileName(const std::string& n) { mScriptFileName = n; }
97     /// Gets the name of the script file from which it is defined
98     std::string GetScriptFileName() const { return mScriptFileName; }
99    
100     /// 
101     void AddToExecutionList( const std::string& box );
102
103     ComplexBlackBoxPointer GetPrototype() { return mPrototype; }
104     void PrintBlackBoxes(); 
105    
106     /// Prints help on the black box
107     void GetHelp(bool full=true) const;
108  
109     /// Writes html formatted help into the output file stream. 
110     /// detail and level are used for graphical representation of 
111     /// complex black boxes (see ComplexBlackBox::InsertHTMLGraph)
112     /// output_dir is the directory in which to write auxilliary files 
113     /// (.dot/.png/.cmap)
114     void InsertHtmlHelp ( std::ofstream& s, 
115                           int detail, int level,
116                           const std::string& output_dir = "",
117                           bool relative_link = false);
118
119     /// Generates a png image representing the pipeline graph of the 
120     /// complex box and writes html code to insert it 
121     /// into the output file stream. 
122     /// detail : 
123     /// level : depth of nested complex boxes graph development 
124     /// (0:only this box level 
125     /// output_dir is the directory in which to write the files 
126     /// (.dot/.png/.cmap)
127     void InsertHTMLGraph( std::ofstream& s, 
128                           int detail, int level, 
129                           const std::string& output_dir = "",
130                           bool relative_link = false );
131     
132
133    ///
134     virtual void Check(bool recursive=true) const;
135        
136
137
138   protected:
139     /// Default ctor with name is protected
140     ComplexBlackBoxDescriptor(const std::string& name); 
141
142   private:
143     /// The factory used
144     Factory::WeakPointer mFactory;
145     /// The complex box in which boxes and connections are stored
146     ComplexBlackBoxPointer mPrototype;
147     /// The name of the script file from which it was created
148     std::string mScriptFileName;
149     
150   };
151   // class ComplexBlackBoxDescriptor
152   //==========================================================================
153
154
155  
156 }
157 // namespace bbtk
158 #endif