2 #include <Standard_Stream.hxx>
4 #include <GEOMImpl_PositionDriver.hxx>
5 #include <GEOMImpl_IPosition.hxx>
6 #include <GEOMImpl_Types.hxx>
7 #include <GEOM_Function.hxx>
9 #include <BRepBuilderAPI_Transform.hxx>
10 #include <BRep_Tool.hxx>
12 #include <TopoDS_Shape.hxx>
13 #include <TopoDS_Vertex.hxx>
17 #include <Geom_Plane.hxx>
18 #include <GProp_GProps.hxx>
19 #include <BRepGProp.hxx>
21 #include <Precision.hxx>
24 //=======================================================================
27 //=======================================================================
28 const Standard_GUID& GEOMImpl_PositionDriver::GetID()
30 static Standard_GUID aPositionDriver("FF1BBB69-5D14-4df2-980B-3A668264EA16");
31 return aPositionDriver;
35 //=======================================================================
36 //function : GEOMImpl_PositionDriver
38 //=======================================================================
39 GEOMImpl_PositionDriver::GEOMImpl_PositionDriver()
43 //=======================================================================
46 //=======================================================================
47 Standard_Integer GEOMImpl_PositionDriver::Execute(TFunction_Logbook& log) const
49 if (Label().IsNull()) return 0;
50 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
52 GEOMImpl_IPosition aCI (aFunction);
53 Standard_Integer aType = aFunction->GetType();
57 if (aType == POSITION_SHAPE || aType == POSITION_SHAPE_COPY) {
58 Handle(GEOM_Function) aRefShape = aCI.GetShape();
59 Handle(GEOM_Function) aRefStartLCS = aCI.GetStartLCS();
60 Handle(GEOM_Function) aRefEndLCS = aCI.GetEndLCS();
62 TopoDS_Shape aShapeBase = aRefShape->GetValue();
63 TopoDS_Shape aShapeStartLCS = aRefStartLCS->GetValue();
64 TopoDS_Shape aShapeEndLCS = aRefEndLCS->GetValue();
66 if (aShapeBase.IsNull() || aShapeStartLCS.IsNull() ||
67 aShapeEndLCS.IsNull() || aShapeEndLCS.ShapeType() != TopAbs_FACE)
71 gp_Ax3 aStartAx3, aDestAx3;
72 aStartAx3.Transform(aShapeStartLCS.Location().Transformation());
73 aDestAx3.Transform(aShapeEndLCS.Location().Transformation());
75 Handle(Geom_Surface) aGS2 = BRep_Tool::Surface( TopoDS::Face( aShapeEndLCS ) );
76 if (!aGS2.IsNull() && aGS2->IsKind( STANDARD_TYPE( Geom_Plane ) ) ) {
77 Handle(Geom_Plane) aGPlane2 = Handle(Geom_Plane)::DownCast( aGS2 );
78 gp_Pln aPln2 = aGPlane2->Pln();
79 aDestAx3 = aPln2.Position();
82 if(aShapeStartLCS.ShapeType() == TopAbs_FACE) {
83 Handle(Geom_Surface) aGS = BRep_Tool::Surface( TopoDS::Face( aShapeStartLCS ) );
84 if (!aGS.IsNull() && aGS->IsKind( STANDARD_TYPE( Geom_Plane ) ) ) {
85 Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast( aGS );
86 gp_Pln aPln = aGPlane->Pln();
87 aStartAx3 = aPln.Position();
89 aTrsf.SetDisplacement(aStartAx3, aDestAx3);
92 gp_Trsf aTrsf1, aTrsf2;
93 aTrsf1.SetDisplacement(aStartAx3, aDestAx3);
94 BRepBuilderAPI_Transform aBT (aShapeBase, aTrsf1, Standard_False);
95 TopoDS_Shape aNewShape = aBT.Shape();
98 if (aNewShape.ShapeType() == TopAbs_VERTEX) {
99 aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aNewShape));
102 GProp_GProps aSystem;
103 if (aNewShape.ShapeType() == TopAbs_EDGE || aNewShape.ShapeType() == TopAbs_WIRE)
104 BRepGProp::LinearProperties(aNewShape, aSystem);
105 else if (aNewShape.ShapeType() == TopAbs_FACE || aNewShape.ShapeType() == TopAbs_SHELL)
106 BRepGProp::SurfaceProperties(aNewShape, aSystem);
108 BRepGProp::VolumeProperties(aNewShape, aSystem);
110 aPnt = aSystem.CentreOfMass();
113 gp_Vec aVec(aPnt, aDestAx3.Location());
114 aTrsf2.SetTranslation(aVec);
115 aTrsf = aTrsf2 * aTrsf1;
118 BRepBuilderAPI_Transform aBRepTrsf (aShapeBase, aTrsf, Standard_False);
119 aShape = aBRepTrsf.Shape();
124 if (aShape.IsNull()) return 0;
126 aFunction->SetValue(aShape);
128 log.SetTouched(Label());
134 //=======================================================================
135 //function : GEOMImpl_PositionDriver_Type_
137 //=======================================================================
138 Standard_EXPORT Handle_Standard_Type& GEOMImpl_PositionDriver_Type_()
141 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
142 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
143 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
144 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
145 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
146 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
149 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
150 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_PositionDriver",
151 sizeof(GEOMImpl_PositionDriver),
153 (Standard_Address)_Ancestors,
154 (Standard_Address)NULL);
159 //=======================================================================
160 //function : DownCast
162 //=======================================================================
163 const Handle(GEOMImpl_PositionDriver) Handle(GEOMImpl_PositionDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
165 Handle(GEOMImpl_PositionDriver) _anOtherObject;
167 if (!AnObject.IsNull()) {
168 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_PositionDriver))) {
169 _anOtherObject = Handle(GEOMImpl_PositionDriver)((Handle(GEOMImpl_PositionDriver)&)AnObject);
173 return _anOtherObject ;