1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.salome-platform.org/
21 #include <Standard_Stream.hxx>
23 #include <GEOMImpl_ScaleDriver.hxx>
24 #include <GEOMImpl_IScale.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOM_Function.hxx>
28 #include <BRepBuilderAPI_Transform.hxx>
29 #include <BRep_Tool.hxx>
31 #include <TopoDS_Shape.hxx>
32 #include <TopoDS_Vertex.hxx>
36 #include <Precision.hxx>
39 //=======================================================================
42 //=======================================================================
43 const Standard_GUID& GEOMImpl_ScaleDriver::GetID()
45 static Standard_GUID aScaleDriver("FF1BBB52-5D14-4df2-980B-3A668264EA16");
50 //=======================================================================
51 //function : GEOMImpl_ScaleDriver
53 //=======================================================================
54 GEOMImpl_ScaleDriver::GEOMImpl_ScaleDriver()
58 //=======================================================================
61 //=======================================================================
62 Standard_Integer GEOMImpl_ScaleDriver::Execute(TFunction_Logbook& log) const
64 if (Label().IsNull()) return 0;
65 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
67 GEOMImpl_IScale aCI (aFunction);
68 Standard_Integer aType = aFunction->GetType();
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;
80 gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
82 aTrsf.SetScale(aP, aCI.GetFactor());
83 BRepBuilderAPI_Transform aBRepTrsf (aShapeBase, aTrsf, Standard_False);
84 aShape = aBRepTrsf.Shape();
88 if (aShape.IsNull()) return 0;
90 aFunction->SetValue(aShape);
92 log.SetTouched(Label());
98 //=======================================================================
99 //function : GEOMImpl_ScaleDriver_Type_
101 //=======================================================================
102 Standard_EXPORT Handle_Standard_Type& GEOMImpl_ScaleDriver_Type_()
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);
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),
117 (Standard_Address)_Ancestors,
118 (Standard_Address)NULL);
123 //=======================================================================
124 //function : DownCast
126 //=======================================================================
127 const Handle(GEOMImpl_ScaleDriver) Handle(GEOMImpl_ScaleDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
129 Handle(GEOMImpl_ScaleDriver) _anOtherObject;
131 if (!AnObject.IsNull()) {
132 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_ScaleDriver))) {
133 _anOtherObject = Handle(GEOMImpl_ScaleDriver)((Handle(GEOMImpl_ScaleDriver)&)AnObject);
137 return _anOtherObject ;