]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMImpl/GEOMImpl_ScaleDriver.cxx
Salome HOME
Copyrights update
[modules/geom.git] / src / GEOMImpl / GEOMImpl_ScaleDriver.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/
19 //
20
21 #include <Standard_Stream.hxx>
22
23 #include <GEOMImpl_ScaleDriver.hxx>
24 #include <GEOMImpl_IScale.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOM_Function.hxx>
27
28 #include <BRepBuilderAPI_Transform.hxx>
29 #include <BRep_Tool.hxx>
30 #include <TopoDS.hxx>
31 #include <TopoDS_Shape.hxx>
32 #include <TopoDS_Vertex.hxx>
33 #include <TopAbs.hxx>
34 #include <TopExp.hxx>
35
36 #include <Precision.hxx>
37 #include <gp_Pnt.hxx>
38
39 //=======================================================================
40 //function : GetID
41 //purpose  :
42 //======================================================================= 
43 const Standard_GUID& GEOMImpl_ScaleDriver::GetID()
44 {
45   static Standard_GUID aScaleDriver("FF1BBB52-5D14-4df2-980B-3A668264EA16");
46   return aScaleDriver; 
47 }
48
49
50 //=======================================================================
51 //function : GEOMImpl_ScaleDriver
52 //purpose  : 
53 //=======================================================================
54 GEOMImpl_ScaleDriver::GEOMImpl_ScaleDriver() 
55 {
56 }
57
58 //=======================================================================
59 //function : Execute
60 //purpose  :
61 //======================================================================= 
62 Standard_Integer GEOMImpl_ScaleDriver::Execute(TFunction_Logbook& log) const
63 {
64   if (Label().IsNull()) return 0;    
65   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
66
67   GEOMImpl_IScale aCI (aFunction);
68   Standard_Integer aType = aFunction->GetType();
69
70   TopoDS_Shape aShape;
71
72   if (aType == SCALE_SHAPE || aType == SCALE_SHAPE_COPY) {
73     Handle(GEOM_Function) aRefShape = aCI.GetShape();
74     Handle(GEOM_Function) aRefPoint = aCI.GetPoint();
75     TopoDS_Shape aShapeBase = aRefShape->GetValue();
76     TopoDS_Shape aShapePnt  = aRefPoint->GetValue();
77     if (aShapeBase.IsNull() || aShapePnt.IsNull()) return 0;
78     if (aShapePnt.ShapeType() != TopAbs_VERTEX) return 0;
79
80     gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
81     gp_Trsf aTrsf;
82     aTrsf.SetScale(aP, aCI.GetFactor());
83     BRepBuilderAPI_Transform aBRepTrsf (aShapeBase, aTrsf, Standard_False);
84     aShape = aBRepTrsf.Shape();
85   } else {
86   }
87
88   if (aShape.IsNull()) return 0;
89
90   aFunction->SetValue(aShape);
91
92   log.SetTouched(Label()); 
93
94   return 1;    
95 }
96
97
98 //=======================================================================
99 //function :  GEOMImpl_ScaleDriver_Type_
100 //purpose  :
101 //======================================================================= 
102 Standard_EXPORT Handle_Standard_Type& GEOMImpl_ScaleDriver_Type_()
103 {
104
105   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
106   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
107   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
108   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared); 
109   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
110   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
111  
112
113   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
114   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_ScaleDriver",
115                                                          sizeof(GEOMImpl_ScaleDriver),
116                                                          1,
117                                                          (Standard_Address)_Ancestors,
118                                                          (Standard_Address)NULL);
119
120   return _aType;
121 }
122
123 //=======================================================================
124 //function : DownCast
125 //purpose  :
126 //======================================================================= 
127 const Handle(GEOMImpl_ScaleDriver) Handle(GEOMImpl_ScaleDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
128 {
129   Handle(GEOMImpl_ScaleDriver) _anOtherObject;
130
131   if (!AnObject.IsNull()) {
132      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_ScaleDriver))) {
133        _anOtherObject = Handle(GEOMImpl_ScaleDriver)((Handle(GEOMImpl_ScaleDriver)&)AnObject);
134      }
135   }
136
137   return _anOtherObject ;
138 }