Salome HOME
Get altitude from region implementation.
[modules/hydro.git] / src / HYDROData / HYDROData_OperationsFactory.cxx
1 #include<HYDROData_OperationsFactory.h>
2
3 #include<HYDROData_Document.h>
4 #include<HYDROData_Iterator.h>
5
6 #include<ImageComposer_ColorMaskOperator.h>
7 #include<ImageComposer_CropOperator.h>
8 #include<ImageComposer_CutOperator.h>
9 #include<ImageComposer_FuseOperator.h>
10
11 #include <typeinfo>
12
13 // global instance
14 HYDROData_OperationsFactory* FACTORY = 0;
15
16 HYDROData_OperationsFactory* HYDROData_OperationsFactory::Factory()
17 {
18   if (!FACTORY) {
19     FACTORY = new HYDROData_OperationsFactory;
20     // default operations
21     REGISTER_HYDRO_OPERATION(ImageComposer_ColorMaskOperator)
22     REGISTER_HYDRO_OPERATION(ImageComposer_CropOperator)
23     REGISTER_HYDRO_OPERATION(ImageComposer_CutOperator)
24     REGISTER_HYDRO_OPERATION(ImageComposer_FuseOperator)
25   }
26   return FACTORY;
27 }
28
29 void HYDROData_OperationsFactory::Register(
30   ImageComposer_Operator* theOperator)
31 {
32   if ( !theOperator )
33     return;
34
35   FACTORY->myOps[ theOperator->name() ] = theOperator;
36 }
37
38 HYDROData_OperationsFactory::HYDROData_OperationsFactory()
39 {
40 }
41
42 ImageComposer_Operator* HYDROData_OperationsFactory::Operator(
43   Handle(HYDROData_Image) theImage ) const
44 {
45   // retreive operator instance by name
46   ImageComposer_Operator* anOp = Operator( theImage->OperatorName() );
47   if ( !anOp )
48     return anOp;
49
50   // fill arguments of the operator from theImage
51   anOp->setBinArgs( theImage->Args() );
52
53   return anOp;
54 }
55
56 ImageComposer_Operator* HYDROData_OperationsFactory::Operator(const QString theName) const
57 {
58   return myOps.contains( theName ) ? myOps[ theName ] : NULL;
59 }
60
61 Handle(HYDROData_Image) HYDROData_OperationsFactory::CreateImage(
62   Handle(HYDROData_Document) theDoc, const ImageComposer_Operator* theOperator)
63 {
64   // create an object
65   Handle(HYDROData_Image) anImage = 
66     Handle(HYDROData_Image)::DownCast(theDoc->CreateObject(KIND_IMAGE));
67   // get data from operation
68   if (theOperator) {
69     anImage->SetOperatorName( theOperator->name() );
70     anImage->SetArgs( theOperator->getBinArgs() );
71   }
72   return anImage;
73 }