Salome HOME
Code alignment.
[modules/hydro.git] / src / HYDROOperations / HYDROOperations_Factory.h
1 #ifndef HYDROOperations_Factory_HeaderFile
2 #define HYDROOperations_Factory_HeaderFile
3
4 #include <HYDROOperations.h>
5 #include <HYDROData_Image.h>
6 #include <QMap>
7
8 class ImageComposer_Operator;
9 class Handle_HYDROData_Document;
10
11 /**\class HYDROOperations_Factory
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 HYDROOperations_Factory
24 {
25 public:
26
27   //! Returns the global factory
28   HYDROOPERATIONS_EXPORT static HYDROOperations_Factory* 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   HYDROOPERATIONS_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   HYDROOPERATIONS_EXPORT Handle(HYDROData_Image) CreateImage(
45     Handle_HYDROData_Document theDoc, const ImageComposer_Operator* theOperator);
46
47   /**
48    * Updates an Image object in the data structure. If it is changed, 
49    * sets "MustBeUpdated" flag to other depended images.
50    * \param theDoc document of this image (needed to update other images flags)
51    * \param theImage the updated image
52    */
53   HYDROOPERATIONS_EXPORT void UpdateImage(
54     Handle_HYDROData_Document theDoc, Handle(HYDROData_Image) theImage);
55
56   /**
57    * Returns the operator, initialized by the properties of theImage
58    * \param theImage data structures object, that contains all arguments 
59    *                 required for creation of operation
60    * \returns NULL if operator type is unknown
61    */
62   HYDROOPERATIONS_EXPORT ImageComposer_Operator* Operator(
63     Handle(HYDROData_Image) theImage) const;
64  
65
66 protected:
67
68   //! Not public constructor that creates only one, global instance of this factory.
69   HYDROOperations_Factory();
70
71   /**
72    * Returns the appropriate operator by the name
73    * \param theName name of the operator, equals to the operation_name constructor
74    * \returns NULL if operator with such name is not registered yet
75    */
76   ImageComposer_Operator* Operator(const QString theName) const;
77   
78   /**
79    * Enables "MustBeUpdated" flag for Images that are depended on "MustBeUpdated" images.
80    * \param theDoc document where this operation is performed
81    */
82   void SetMustBeUpdatedImages(Handle_HYDROData_Document theDoc) const;
83
84 private:
85   //! Map that stores all operators, isentified by strings
86   typedef QMap<QString, ImageComposer_Operator*> FactoryOperators;
87   
88   FactoryOperators myOps; ///< all operators stored by a factory
89 };
90
91 /**
92  * Macro that is used for registered operators, see C++ of this class to see
93  * example of hte registration.
94  */
95 #define REGISTER_HYDRO_OPERATION(operation_name) \
96   HYDROOperations_Factory::Factory()->Register(new operation_name);
97
98 #endif