2 #include <Standard_Stream.hxx>
4 #include <GEOMImpl_PlaneDriver.hxx>
5 #include <GEOMImpl_IPlane.hxx>
6 #include <GEOMImpl_Types.hxx>
7 #include <GEOM_Function.hxx>
9 #include <BRepBuilderAPI_MakeFace.hxx>
10 #include <BRep_Tool.hxx>
14 #include <TopoDS_Shape.hxx>
15 #include <TopoDS_Edge.hxx>
16 #include <TopoDS_Vertex.hxx>
19 #include <GC_MakePlane.hxx>
20 #include <Geom_Surface.hxx>
22 #include <Precision.hxx>
27 #include <Standard_ConstructionError.hxx>
28 #include <Standard_TypeMismatch.hxx>
30 //=======================================================================
33 //=======================================================================
34 const Standard_GUID& GEOMImpl_PlaneDriver::GetID()
36 static Standard_GUID aPlaneDriver("FF1BBB05-5D14-4df2-980B-3A668264EA16");
41 //=======================================================================
42 //function : GEOMImpl_PlaneDriver
44 //=======================================================================
45 GEOMImpl_PlaneDriver::GEOMImpl_PlaneDriver()
49 //=======================================================================
52 //=======================================================================
53 Standard_Integer GEOMImpl_PlaneDriver::Execute(TFunction_Logbook& log) const
55 if (Label().IsNull()) return 0;
56 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
58 GEOMImpl_IPlane aPI (aFunction);
59 Standard_Integer aType = aFunction->GetType();
63 double aSize = aPI.GetSize() / 2.0;
64 if (aType == PLANE_PNT_VEC) {
65 Handle(GEOM_Function) aRefPnt = aPI.GetPoint();
66 Handle(GEOM_Function) aRefVec = aPI.GetVector();
67 TopoDS_Shape aShape1 = aRefPnt->GetValue();
68 TopoDS_Shape aShape2 = aRefVec->GetValue();
69 if (aShape1.ShapeType() != TopAbs_VERTEX ||
70 aShape2.ShapeType() != TopAbs_EDGE) return 0;
71 gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aShape1));
72 TopoDS_Edge anE = TopoDS::Edge(aShape2);
74 TopExp::Vertices(anE, V1, V2, Standard_True);
75 if (!V1.IsNull() && !V2.IsNull()) {
76 gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
78 aShape = BRepBuilderAPI_MakeFace(aPln, -aSize, +aSize, -aSize, +aSize).Shape();
80 } else if (aType == PLANE_THREE_PNT) {
81 Handle(GEOM_Function) aRefPnt1 = aPI.GetPoint1();
82 Handle(GEOM_Function) aRefPnt2 = aPI.GetPoint2();
83 Handle(GEOM_Function) aRefPnt3 = aPI.GetPoint3();
84 TopoDS_Shape aShape1 = aRefPnt1->GetValue();
85 TopoDS_Shape aShape2 = aRefPnt2->GetValue();
86 TopoDS_Shape aShape3 = aRefPnt3->GetValue();
87 if (aShape1.ShapeType() != TopAbs_VERTEX ||
88 aShape2.ShapeType() != TopAbs_VERTEX ||
89 aShape3.ShapeType() != TopAbs_VERTEX) return 0;
90 gp_Pnt aP1 = BRep_Tool::Pnt(TopoDS::Vertex(aShape1));
91 gp_Pnt aP2 = BRep_Tool::Pnt(TopoDS::Vertex(aShape2));
92 gp_Pnt aP3 = BRep_Tool::Pnt(TopoDS::Vertex(aShape3));
93 if (aP1.Distance(aP2) < gp::Resolution() ||
94 aP1.Distance(aP3) < gp::Resolution() ||
95 aP2.Distance(aP3) < gp::Resolution())
96 Standard_ConstructionError::Raise("Plane creation aborted: coincident points given");
97 if (gp_Vec(aP1, aP2).IsParallel(gp_Vec(aP1, aP3), Precision::Angular()))
98 Standard_ConstructionError::Raise("Plane creation aborted: points lay on one line");
99 GC_MakePlane aMakePlane (aP1, aP2, aP3);
100 aShape = BRepBuilderAPI_MakeFace(aMakePlane, -aSize, +aSize, -aSize, +aSize).Shape();
101 } else if (aType == PLANE_FACE) {
102 Handle(GEOM_Function) aRef = aPI.GetFace();
103 TopoDS_Shape aRefShape = aRef->GetValue();
104 if (aRefShape.ShapeType() != TopAbs_FACE) return 0;
105 Handle(Geom_Surface) aGS = BRep_Tool::Surface(TopoDS::Face(aRefShape));
106 if (!aGS->IsKind(STANDARD_TYPE(Geom_Plane))) {
107 Standard_TypeMismatch::Raise("Plane creation aborted: non-planar face given as argument");
109 aShape = BRepBuilderAPI_MakeFace(aGS, -aSize, +aSize, -aSize, +aSize).Shape();
113 if (aShape.IsNull()) return 0;
115 aFunction->SetValue(aShape);
117 log.SetTouched(Label());
123 //=======================================================================
124 //function : GEOMImpl_PlaneDriver_Type_
126 //=======================================================================
127 Standard_EXPORT Handle_Standard_Type& GEOMImpl_PlaneDriver_Type_()
130 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
131 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
132 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
133 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
134 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
135 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
138 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
139 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_PlaneDriver",
140 sizeof(GEOMImpl_PlaneDriver),
142 (Standard_Address)_Ancestors,
143 (Standard_Address)NULL);
148 //=======================================================================
149 //function : DownCast
151 //=======================================================================
152 const Handle(GEOMImpl_PlaneDriver) Handle(GEOMImpl_PlaneDriver)::DownCast
153 (const Handle(Standard_Transient)& AnObject)
155 Handle(GEOMImpl_PlaneDriver) _anOtherObject;
157 if (!AnObject.IsNull()) {
158 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_PlaneDriver))) {
159 _anOtherObject = Handle(GEOMImpl_PlaneDriver)((Handle(GEOMImpl_PlaneDriver)&)AnObject);
163 return _anOtherObject ;