3 #include "GEOMImpl_PositionDriver.hxx"
4 #include "GEOMImpl_IPosition.hxx"
5 #include "GEOMImpl_Types.hxx"
6 #include "GEOM_Function.hxx"
8 #include <BRepBuilderAPI_Transform.hxx>
9 #include <BRep_Tool.hxx>
11 #include <TopoDS_Shape.hxx>
12 #include <TopoDS_Vertex.hxx>
16 #include <Geom_Plane.hxx>
17 #include <GProp_GProps.hxx>
18 #include <BRepGProp.hxx>
20 #include <Precision.hxx>
23 //=======================================================================
26 //=======================================================================
27 const Standard_GUID& GEOMImpl_PositionDriver::GetID()
29 static Standard_GUID aPositionDriver("FF1BBB69-5D14-4df2-980B-3A668264EA16");
30 return aPositionDriver;
34 //=======================================================================
35 //function : GEOMImpl_PositionDriver
37 //=======================================================================
38 GEOMImpl_PositionDriver::GEOMImpl_PositionDriver()
42 //=======================================================================
45 //=======================================================================
46 Standard_Integer GEOMImpl_PositionDriver::Execute(TFunction_Logbook& log) const
48 if (Label().IsNull()) return 0;
49 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
51 GEOMImpl_IPosition aCI (aFunction);
52 Standard_Integer aType = aFunction->GetType();
56 if (aType == POSITION_SHAPE || aType == POSITION_SHAPE_COPY) {
57 Handle(GEOM_Function) aRefShape = aCI.GetShape();
58 Handle(GEOM_Function) aRefStartLCS = aCI.GetStartLCS();
59 Handle(GEOM_Function) aRefEndLCS = aCI.GetEndLCS();
61 TopoDS_Shape aShapeBase = aRefShape->GetValue();
62 TopoDS_Shape aShapeStartLCS = aRefStartLCS->GetValue();
63 TopoDS_Shape aShapeEndLCS = aRefEndLCS->GetValue();
65 if (aShapeBase.IsNull() || aShapeStartLCS.IsNull() ||
66 aShapeEndLCS.IsNull() || aShapeEndLCS.ShapeType() != TopAbs_FACE)
70 gp_Ax3 aStartAx3, aDestAx3;
71 aStartAx3.Transform(aShapeStartLCS.Location().Transformation());
72 aDestAx3.Transform(aShapeEndLCS.Location().Transformation());
74 Handle(Geom_Surface) aGS2 = BRep_Tool::Surface( TopoDS::Face( aShapeEndLCS ) );
75 if (!aGS2.IsNull() && aGS2->IsKind( STANDARD_TYPE( Geom_Plane ) ) ) {
76 Handle(Geom_Plane) aGPlane2 = Handle(Geom_Plane)::DownCast( aGS2 );
77 gp_Pln aPln2 = aGPlane2->Pln();
78 aDestAx3 = aPln2.Position();
81 if(aShapeStartLCS.ShapeType() == TopAbs_FACE) {
82 Handle(Geom_Surface) aGS = BRep_Tool::Surface( TopoDS::Face( aShapeStartLCS ) );
83 if (!aGS.IsNull() && aGS->IsKind( STANDARD_TYPE( Geom_Plane ) ) ) {
84 Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast( aGS );
85 gp_Pln aPln = aGPlane->Pln();
86 aStartAx3 = aPln.Position();
88 aTrsf.SetDisplacement(aStartAx3, aDestAx3);
91 gp_Trsf aTrsf1, aTrsf2;
92 aTrsf1.SetDisplacement(aStartAx3, aDestAx3);
93 BRepBuilderAPI_Transform aBT (aShapeBase, aTrsf1, Standard_False);
94 TopoDS_Shape aNewShape = aBT.Shape();
97 if (aNewShape.ShapeType() == TopAbs_VERTEX) {
98 aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aNewShape));
101 GProp_GProps aSystem;
102 if (aNewShape.ShapeType() == TopAbs_EDGE || aNewShape.ShapeType() == TopAbs_WIRE)
103 BRepGProp::LinearProperties(aNewShape, aSystem);
104 else if (aNewShape.ShapeType() == TopAbs_FACE || aNewShape.ShapeType() == TopAbs_SHELL)
105 BRepGProp::SurfaceProperties(aNewShape, aSystem);
107 BRepGProp::VolumeProperties(aNewShape, aSystem);
109 aPnt = aSystem.CentreOfMass();
112 gp_Vec aVec(aPnt, aDestAx3.Location());
113 aTrsf2.SetTranslation(aVec);
114 aTrsf = aTrsf2 * aTrsf1;
117 BRepBuilderAPI_Transform aBRepTrsf (aShapeBase, aTrsf, Standard_False);
118 aShape = aBRepTrsf.Shape();
123 if (aShape.IsNull()) return 0;
125 aFunction->SetValue(aShape);
127 log.SetTouched(Label());
133 //=======================================================================
134 //function : GEOMImpl_PositionDriver_Type_
136 //=======================================================================
137 Standard_EXPORT Handle_Standard_Type& GEOMImpl_PositionDriver_Type_()
140 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
141 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
142 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
143 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
144 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
145 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
148 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
149 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_PositionDriver",
150 sizeof(GEOMImpl_PositionDriver),
152 (Standard_Address)_Ancestors,
153 (Standard_Address)NULL);
158 //=======================================================================
159 //function : DownCast
161 //=======================================================================
162 const Handle(GEOMImpl_PositionDriver) Handle(GEOMImpl_PositionDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
164 Handle(GEOMImpl_PositionDriver) _anOtherObject;
166 if (!AnObject.IsNull()) {
167 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_PositionDriver))) {
168 _anOtherObject = Handle(GEOMImpl_PositionDriver)((Handle(GEOMImpl_PositionDriver)&)AnObject);
172 return _anOtherObject ;