3 #include "GEOMImpl_PlaneDriver.hxx"
4 #include "GEOMImpl_IPlane.hxx"
5 #include "GEOMImpl_Types.hxx"
6 #include "GEOM_Function.hxx"
8 #include <BRepBuilderAPI_MakeFace.hxx>
9 #include <BRep_Tool.hxx>
13 #include <TopoDS_Shape.hxx>
14 #include <TopoDS_Edge.hxx>
15 #include <TopoDS_Vertex.hxx>
18 #include <GC_MakePlane.hxx>
19 #include <Geom_Surface.hxx>
21 #include <Precision.hxx>
26 #include <Standard_ConstructionError.hxx>
27 #include <Standard_TypeMismatch.hxx>
29 //=======================================================================
32 //=======================================================================
33 const Standard_GUID& GEOMImpl_PlaneDriver::GetID()
35 static Standard_GUID aPlaneDriver("FF1BBB05-5D14-4df2-980B-3A668264EA16");
40 //=======================================================================
41 //function : GEOMImpl_PlaneDriver
43 //=======================================================================
44 GEOMImpl_PlaneDriver::GEOMImpl_PlaneDriver()
48 //=======================================================================
51 //=======================================================================
52 Standard_Integer GEOMImpl_PlaneDriver::Execute(TFunction_Logbook& log) const
54 if (Label().IsNull()) return 0;
55 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
57 GEOMImpl_IPlane aPI (aFunction);
58 Standard_Integer aType = aFunction->GetType();
62 double aSize = aPI.GetSize() / 2.0;
63 if (aType == PLANE_PNT_VEC) {
64 Handle(GEOM_Function) aRefPnt = aPI.GetPoint();
65 Handle(GEOM_Function) aRefVec = aPI.GetVector();
66 TopoDS_Shape aShape1 = aRefPnt->GetValue();
67 TopoDS_Shape aShape2 = aRefVec->GetValue();
68 if (aShape1.ShapeType() != TopAbs_VERTEX ||
69 aShape2.ShapeType() != TopAbs_EDGE) return 0;
70 gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aShape1));
71 TopoDS_Edge anE = TopoDS::Edge(aShape2);
73 TopExp::Vertices(anE, V1, V2, Standard_True);
74 if (!V1.IsNull() && !V2.IsNull()) {
75 gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
77 aShape = BRepBuilderAPI_MakeFace(aPln, -aSize, +aSize, -aSize, +aSize).Shape();
79 } else if (aType == PLANE_THREE_PNT) {
80 Handle(GEOM_Function) aRefPnt1 = aPI.GetPoint1();
81 Handle(GEOM_Function) aRefPnt2 = aPI.GetPoint2();
82 Handle(GEOM_Function) aRefPnt3 = aPI.GetPoint3();
83 TopoDS_Shape aShape1 = aRefPnt1->GetValue();
84 TopoDS_Shape aShape2 = aRefPnt2->GetValue();
85 TopoDS_Shape aShape3 = aRefPnt3->GetValue();
86 if (aShape1.ShapeType() != TopAbs_VERTEX ||
87 aShape2.ShapeType() != TopAbs_VERTEX ||
88 aShape3.ShapeType() != TopAbs_VERTEX) return 0;
89 gp_Pnt aP1 = BRep_Tool::Pnt(TopoDS::Vertex(aShape1));
90 gp_Pnt aP2 = BRep_Tool::Pnt(TopoDS::Vertex(aShape2));
91 gp_Pnt aP3 = BRep_Tool::Pnt(TopoDS::Vertex(aShape3));
92 if (aP1.Distance(aP2) < gp::Resolution() ||
93 aP1.Distance(aP3) < gp::Resolution() ||
94 aP2.Distance(aP3) < gp::Resolution())
95 Standard_ConstructionError::Raise("Plane creation aborted: coincident points given");
96 if (gp_Vec(aP1, aP2).IsParallel(gp_Vec(aP1, aP3), Precision::Angular()))
97 Standard_ConstructionError::Raise("Plane creation aborted: points lay on one line");
98 GC_MakePlane aMakePlane (aP1, aP2, aP3);
99 aShape = BRepBuilderAPI_MakeFace(aMakePlane, -aSize, +aSize, -aSize, +aSize).Shape();
100 } else if (aType == PLANE_FACE) {
101 Handle(GEOM_Function) aRef = aPI.GetFace();
102 TopoDS_Shape aRefShape = aRef->GetValue();
103 if (aRefShape.ShapeType() != TopAbs_FACE) return 0;
104 Handle(Geom_Surface) aGS = BRep_Tool::Surface(TopoDS::Face(aRefShape));
105 if (!aGS->IsKind(STANDARD_TYPE(Geom_Plane))) {
106 Standard_TypeMismatch::Raise("Plane creation aborted: non-planar face given as argument");
108 aShape = BRepBuilderAPI_MakeFace(aGS, -aSize, +aSize, -aSize, +aSize).Shape();
112 if (aShape.IsNull()) return 0;
114 aFunction->SetValue(aShape);
116 log.SetTouched(Label());
122 //=======================================================================
123 //function : GEOMImpl_PlaneDriver_Type_
125 //=======================================================================
126 Standard_EXPORT Handle_Standard_Type& GEOMImpl_PlaneDriver_Type_()
129 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
130 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
131 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
132 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
133 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
134 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
137 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
138 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_PlaneDriver",
139 sizeof(GEOMImpl_PlaneDriver),
141 (Standard_Address)_Ancestors,
142 (Standard_Address)NULL);
147 //=======================================================================
148 //function : DownCast
150 //=======================================================================
151 const Handle(GEOMImpl_PlaneDriver) Handle(GEOMImpl_PlaneDriver)::DownCast
152 (const Handle(Standard_Transient)& AnObject)
154 Handle(GEOMImpl_PlaneDriver) _anOtherObject;
156 if (!AnObject.IsNull()) {
157 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_PlaneDriver))) {
158 _anOtherObject = Handle(GEOMImpl_PlaneDriver)((Handle(GEOMImpl_PlaneDriver)&)AnObject);
162 return _anOtherObject ;