Salome HOME
Corrections of examples path after install with scbi
[modules/hydro.git] / src / HYDROData / HYDROData_OperationsFactory.cxx
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 #include<HYDROData_OperationsFactory.h>
20
21 #include<HYDROData_Document.h>
22 #include<HYDROData_Iterator.h>
23
24 #include<ImageComposer_ColorMaskOperator.h>
25 #include<ImageComposer_CropOperator.h>
26 #include<ImageComposer_CutOperator.h>
27 #include<ImageComposer_FuseOperator.h>
28
29 #include <typeinfo>
30
31 // global instance
32 HYDROData_OperationsFactory* FACTORY = 0;
33
34 HYDROData_OperationsFactory* HYDROData_OperationsFactory::Factory()
35 {
36   if (!FACTORY) {
37     FACTORY = new HYDROData_OperationsFactory;
38     // default operations
39     REGISTER_HYDRO_OPERATION(ImageComposer_ColorMaskOperator)
40     REGISTER_HYDRO_OPERATION(ImageComposer_CropOperator)
41     REGISTER_HYDRO_OPERATION(ImageComposer_CutOperator)
42     REGISTER_HYDRO_OPERATION(ImageComposer_FuseOperator)
43   }
44   return FACTORY;
45 }
46
47 void HYDROData_OperationsFactory::Register(
48   ImageComposer_Operator* theOperator)
49 {
50   if ( !theOperator )
51     return;
52
53   FACTORY->myOps[ theOperator->name() ] = theOperator;
54 }
55
56 HYDROData_OperationsFactory::HYDROData_OperationsFactory()
57 {
58 }
59
60 ImageComposer_Operator* HYDROData_OperationsFactory::Operator(
61   Handle(HYDROData_Image) theImage ) const
62 {
63   // retreive operator instance by name
64   ImageComposer_Operator* anOp = Operator( theImage->OperatorName() );
65   if ( !anOp )
66     return anOp;
67
68   // fill arguments of the operator from theImage
69   anOp->setBinArgs( theImage->Args() );
70
71   return anOp;
72 }
73
74 ImageComposer_Operator* HYDROData_OperationsFactory::Operator(const QString theName) const
75 {
76   return myOps.contains( theName ) ? myOps[ theName ] : NULL;
77 }
78
79 Handle(HYDROData_Image) HYDROData_OperationsFactory::CreateImage(
80   Handle(HYDROData_Document) theDoc, const ImageComposer_Operator* theOperator)
81 {
82   // create an object
83   Handle(HYDROData_Image) anImage = 
84     Handle(HYDROData_Image)::DownCast(theDoc->CreateObject(KIND_IMAGE));
85   // get data from operation
86   if (theOperator) {
87     anImage->SetOperatorName( theOperator->name() );
88     anImage->SetArgs( theOperator->getBinArgs() );
89   }
90   return anImage;
91 }