Salome HOME
The data model has been redesigned to new format.
[modules/hydro.git] / src / HYDROData / HYDROData_OperationsFactory.h
1 #ifndef HYDROData_OperationsFactory_HeaderFile
2 #define HYDROData_OperationsFactory_HeaderFile
3
4 #include <HYDROData.h>
5 #include <HYDROData_Image.h>
6 #include <QMap>
7
8 class ImageComposer_Operator;
9 class Handle_HYDROData_Document;
10
11 /**\class HYDROData_OperationsFactory
12  *
13  * \brief This class provides the unified management of operations on images.
14  *
15  * Object is created as one global instance and allows to register and launch
16  * all registered operations in general way. To register a new operation just
17  * call REGISTER_HYDRO_OPERATION(operation_name) in some method implementation.
18  * This macro will call constructor of this operation (it must inherit
19  * ImageComposer_Operator) and factory will set up arguments and call this 
20  * operator by demand.
21  */
22
23 class HYDROData_OperationsFactory
24 {
25 public:
26
27   //! Returns the global factory
28   HYDRODATA_EXPORT static HYDROData_OperationsFactory* Factory();
29   
30   /**
31    * Registers the operator by the name, used by REGISTER_HYDRO_OPERATION macro
32    * \param theOperator new instance of the operator that will be used for
33    *                    processing of operation with such kind
34    */
35   HYDRODATA_EXPORT static void Register(
36     ImageComposer_Operator* theOperator);
37   
38   /**
39    * Creates a new Image object in the data structure by the operator data.
40    * \param theDoc document where it must be created
41    * \param theOperator base operator for this Image: will be used in "Update" to recompute the image
42    * \returns created object related to the data structure
43    */
44   HYDRODATA_EXPORT Handle(HYDROData_Image) CreateImage(
45     Handle_HYDROData_Document theDoc, const ImageComposer_Operator* theOperator);
46
47   /**
48    * Returns the operator, initialized by the properties of theImage
49    * \param theImage data structures object, that contains all arguments 
50    *                 required for creation of operation
51    * \returns NULL if operator type is unknown
52    */
53   HYDRODATA_EXPORT ImageComposer_Operator* Operator(
54     Handle(HYDROData_Image) theImage) const;
55  
56
57   /**
58    * Returns the appropriate operator by the name
59    * \param theName name of the operator, equals to the operation_name constructor
60    * \returns NULL if operator with such name is not registered yet
61    */
62   HYDRODATA_EXPORT ImageComposer_Operator* Operator(const QString theName) const;
63
64 protected:
65
66   //! Not public constructor that creates only one, global instance of this factory.
67   HYDROData_OperationsFactory();  
68
69 private:
70   //! Map that stores all operators, isentified by strings
71   typedef QMap<QString, ImageComposer_Operator*> FactoryOperators;
72   
73   FactoryOperators myOps; ///< all operators stored by a factory
74 };
75
76 /**
77  * Macro that is used for registered operators, see C++ of this class to see
78  * example of hte registration.
79  */
80 #define REGISTER_HYDRO_OPERATION(operation_name) \
81   HYDROData_OperationsFactory::Factory()->Register(new operation_name);
82
83 #endif