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/ or email : webmaster.salome@opencascade.com
21 #include <Standard_Stream.hxx>
23 #include <GEOMImpl_PositionDriver.hxx>
24 #include <GEOMImpl_IPosition.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 <Geom_Plane.hxx>
37 #include <GProp_GProps.hxx>
38 #include <BRepGProp.hxx>
40 #include <Precision.hxx>
43 //=======================================================================
46 //=======================================================================
47 const Standard_GUID& GEOMImpl_PositionDriver::GetID()
49 static Standard_GUID aPositionDriver("FF1BBB69-5D14-4df2-980B-3A668264EA16");
50 return aPositionDriver;
54 //=======================================================================
55 //function : GEOMImpl_PositionDriver
57 //=======================================================================
58 GEOMImpl_PositionDriver::GEOMImpl_PositionDriver()
62 //=======================================================================
65 //=======================================================================
66 Standard_Integer GEOMImpl_PositionDriver::Execute(TFunction_Logbook& log) const
68 if (Label().IsNull()) return 0;
69 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
71 GEOMImpl_IPosition aCI (aFunction);
72 Standard_Integer aType = aFunction->GetType();
76 if (aType == POSITION_SHAPE || aType == POSITION_SHAPE_COPY) {
77 Handle(GEOM_Function) aRefShape = aCI.GetShape();
78 Handle(GEOM_Function) aRefStartLCS = aCI.GetStartLCS();
79 Handle(GEOM_Function) aRefEndLCS = aCI.GetEndLCS();
81 TopoDS_Shape aShapeBase = aRefShape->GetValue();
82 TopoDS_Shape aShapeStartLCS = aRefStartLCS->GetValue();
83 TopoDS_Shape aShapeEndLCS = aRefEndLCS->GetValue();
85 if (aShapeBase.IsNull() || aShapeStartLCS.IsNull() ||
86 aShapeEndLCS.IsNull() || aShapeEndLCS.ShapeType() != TopAbs_FACE)
90 gp_Ax3 aStartAx3, aDestAx3;
91 aStartAx3.Transform(aShapeStartLCS.Location().Transformation());
92 aDestAx3.Transform(aShapeEndLCS.Location().Transformation());
94 Handle(Geom_Surface) aGS2 = BRep_Tool::Surface( TopoDS::Face( aShapeEndLCS ) );
95 if (!aGS2.IsNull() && aGS2->IsKind( STANDARD_TYPE( Geom_Plane ) ) ) {
96 Handle(Geom_Plane) aGPlane2 = Handle(Geom_Plane)::DownCast( aGS2 );
97 gp_Pln aPln2 = aGPlane2->Pln();
98 aDestAx3 = aPln2.Position();
101 if(aShapeStartLCS.ShapeType() == TopAbs_FACE) {
102 Handle(Geom_Surface) aGS = BRep_Tool::Surface( TopoDS::Face( aShapeStartLCS ) );
103 if (!aGS.IsNull() && aGS->IsKind( STANDARD_TYPE( Geom_Plane ) ) ) {
104 Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast( aGS );
105 gp_Pln aPln = aGPlane->Pln();
106 aStartAx3 = aPln.Position();
108 aTrsf.SetDisplacement(aStartAx3, aDestAx3);
111 gp_Trsf aTrsf1, aTrsf2;
112 aTrsf1.SetDisplacement(aStartAx3, aDestAx3);
113 BRepBuilderAPI_Transform aBT (aShapeBase, aTrsf1, Standard_False);
114 TopoDS_Shape aNewShape = aBT.Shape();
117 if (aNewShape.ShapeType() == TopAbs_VERTEX) {
118 aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aNewShape));
121 GProp_GProps aSystem;
122 if (aNewShape.ShapeType() == TopAbs_EDGE || aNewShape.ShapeType() == TopAbs_WIRE)
123 BRepGProp::LinearProperties(aNewShape, aSystem);
124 else if (aNewShape.ShapeType() == TopAbs_FACE || aNewShape.ShapeType() == TopAbs_SHELL)
125 BRepGProp::SurfaceProperties(aNewShape, aSystem);
127 BRepGProp::VolumeProperties(aNewShape, aSystem);
129 aPnt = aSystem.CentreOfMass();
132 gp_Vec aVec(aPnt, aDestAx3.Location());
133 aTrsf2.SetTranslation(aVec);
134 aTrsf = aTrsf2 * aTrsf1;
137 BRepBuilderAPI_Transform aBRepTrsf (aShapeBase, aTrsf, Standard_False);
138 aShape = aBRepTrsf.Shape();
143 if (aShape.IsNull()) return 0;
145 aFunction->SetValue(aShape);
147 log.SetTouched(Label());
153 //=======================================================================
154 //function : GEOMImpl_PositionDriver_Type_
156 //=======================================================================
157 Standard_EXPORT Handle_Standard_Type& GEOMImpl_PositionDriver_Type_()
160 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
161 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
162 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
163 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
164 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
165 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
168 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
169 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_PositionDriver",
170 sizeof(GEOMImpl_PositionDriver),
172 (Standard_Address)_Ancestors,
173 (Standard_Address)NULL);
178 //=======================================================================
179 //function : DownCast
181 //=======================================================================
182 const Handle(GEOMImpl_PositionDriver) Handle(GEOMImpl_PositionDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
184 Handle(GEOMImpl_PositionDriver) _anOtherObject;
186 if (!AnObject.IsNull()) {
187 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_PositionDriver))) {
188 _anOtherObject = Handle(GEOMImpl_PositionDriver)((Handle(GEOMImpl_PositionDriver)&)AnObject);
192 return _anOtherObject ;