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