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