Salome HOME
fix test on stream linear interpolation
[modules/hydro.git] / src / HYDROData / HYDROData_OperationsFactory.h
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #ifndef HYDROData_OperationsFactory_HeaderFile
20 #define HYDROData_OperationsFactory_HeaderFile
21
22 #include <HYDROData.h>
23 #include <HYDROData_Image.h>
24 #include <QMap>
25
26 class ImageComposer_Operator;
27 class HYDROData_Document;
28
29 /**\class HYDROData_OperationsFactory
30  *
31  * \brief This class provides the unified management of operations on images.
32  *
33  * Object is created as one global instance and allows to register and launch
34  * all registered operations in general way. To register a new operation just
35  * call REGISTER_HYDRO_OPERATION(operation_name) in some method implementation.
36  * This macro will call constructor of this operation (it must inherit
37  * ImageComposer_Operator) and factory will set up arguments and call this 
38  * operator by demand.
39  */
40
41 class HYDROData_OperationsFactory
42 {
43 public:
44
45   //! Returns the global factory
46   HYDRODATA_EXPORT static HYDROData_OperationsFactory* Factory();
47   
48   /**
49    * Registers the operator by the name, used by REGISTER_HYDRO_OPERATION macro
50    * \param theOperator new instance of the operator that will be used for
51    *                    processing of operation with such kind
52    */
53   HYDRODATA_EXPORT static void Register(
54     ImageComposer_Operator* theOperator);
55   
56   /**
57    * Creates a new Image object in the data structure by the operator data.
58    * \param theDoc document where it must be created
59    * \param theOperator base operator for this Image: will be used in "Update" to recompute the image
60    * \returns created object related to the data structure
61    */
62   HYDRODATA_EXPORT Handle(HYDROData_Image) CreateImage(
63     Handle(HYDROData_Document) theDoc, const ImageComposer_Operator* theOperator);
64
65   /**
66    * Returns the operator, initialized by the properties of theImage
67    * \param theImage data structures object, that contains all arguments 
68    *                 required for creation of operation
69    * \returns NULL if operator type is unknown
70    */
71   HYDRODATA_EXPORT ImageComposer_Operator* Operator(
72     Handle(HYDROData_Image) theImage) const;
73  
74
75   /**
76    * Returns the appropriate operator by the name
77    * \param theName name of the operator, equals to the operation_name constructor
78    * \returns NULL if operator with such name is not registered yet
79    */
80   HYDRODATA_EXPORT ImageComposer_Operator* Operator(const QString theName) const;
81
82 protected:
83
84   //! Not public constructor that creates only one, global instance of this factory.
85   HYDROData_OperationsFactory();  
86
87 private:
88   //! Map that stores all operators, isentified by strings
89   typedef QMap<QString, ImageComposer_Operator*> FactoryOperators;
90   
91   FactoryOperators myOps; ///< all operators stored by a factory
92 };
93
94 /**
95  * Macro that is used for registered operators, see C++ of this class to see
96  * example of hte registration.
97  */
98 #define REGISTER_HYDRO_OPERATION(operation_name) \
99   HYDROData_OperationsFactory::Factory()->Register(new operation_name);
100
101 #endif