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