1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include <Standard_Stream.hxx>
24 #include <GEOMImpl_PointDriver.hxx>
25 #include <GEOMImpl_IPoint.hxx>
26 #include <GEOMImpl_Types.hxx>
27 #include <GEOM_Function.hxx>
29 #include <BRep_Tool.hxx>
30 #include <BRepBuilderAPI_MakeVertex.hxx>
31 #include <BRepExtrema_DistShapeShape.hxx>
32 #include <Precision.hxx>
35 #include <TopoDS_Edge.hxx>
36 #include <TopoDS_Shape.hxx>
37 #include <TopoDS_Vertex.hxx>
39 #include <Geom_Curve.hxx>
40 #include <Geom_Surface.hxx>
42 #include <TopoDS_Face.hxx>
43 #include <ShapeAnalysis.hxx>
46 //=======================================================================
49 //=======================================================================
50 const Standard_GUID& GEOMImpl_PointDriver::GetID()
52 static Standard_GUID aPointDriver("FF1BBB02-5D14-4df2-980B-3A668264EA16");
57 //=======================================================================
58 //function : GEOMImpl_PointDriver
60 //=======================================================================
61 GEOMImpl_PointDriver::GEOMImpl_PointDriver()
66 //=======================================================================
69 //=======================================================================
70 Standard_Integer GEOMImpl_PointDriver::Execute(TFunction_Logbook& log) const
72 if (Label().IsNull()) return 0;
73 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
75 GEOMImpl_IPoint aPI (aFunction);
76 Standard_Integer aType = aFunction->GetType();
80 if (aType == POINT_XYZ) {
81 aPnt = gp_Pnt(aPI.GetX(), aPI.GetY(), aPI.GetZ());
84 else if (aType == POINT_XYZ_REF) {
86 Handle(GEOM_Function) aRefPoint = aPI.GetRef();
87 TopoDS_Shape aRefShape = aRefPoint->GetValue();
88 if (aRefShape.ShapeType() != TopAbs_VERTEX) {
89 Standard_TypeMismatch::Raise
90 ("Point creation aborted : referenced shape is not a vertex");
92 gp_Pnt P = BRep_Tool::Pnt(TopoDS::Vertex(aRefShape));
93 aPnt = gp_Pnt(P.X() + aPI.GetX(), P.Y() + aPI.GetY(), P.Z() + aPI.GetZ());
96 else if (aType == POINT_CURVE_PAR) {
97 Handle(GEOM_Function) aRefCurve = aPI.GetCurve();
98 TopoDS_Shape aRefShape = aRefCurve->GetValue();
99 if (aRefShape.ShapeType() != TopAbs_EDGE) {
100 Standard_TypeMismatch::Raise
101 ("Point On Curve creation aborted : curve shape is not an edge");
103 Standard_Real aFP, aLP, aP;
104 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(aRefShape), aFP, aLP);
105 aP = aFP + (aLP - aFP) * aPI.GetParameter();
106 aPnt = aCurve->Value(aP);
108 else if (aType == POINT_SURFACE_PAR) {
109 Handle(GEOM_Function) aRefCurve = aPI.GetSurface();
110 TopoDS_Shape aRefShape = aRefCurve->GetValue();
111 if (aRefShape.ShapeType() != TopAbs_FACE) {
112 Standard_TypeMismatch::Raise
113 ("Point On Surface creation aborted : surface shape is not a face");
115 TopoDS_Face F = TopoDS::Face(aRefShape);
116 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F);
117 Standard_Real U1,U2,V1,V2;
118 //aSurf->Bounds(U1,U2,V1,V2);
119 ShapeAnalysis::GetFaceUVBounds(F,U1,U2,V1,V2);
120 Standard_Real U = U1 + (U2-U1) * aPI.GetParameter();
121 Standard_Real V = V1 + (V2-V1) * aPI.GetParameter2();
122 aPnt = aSurf->Value(U,V);
124 else if (aType == POINT_LINES_INTERSECTION) {
125 Handle(GEOM_Function) aRef1 = aPI.GetLine1();
126 Handle(GEOM_Function) aRef2 = aPI.GetLine2();
128 TopoDS_Shape aRefShape1 = aRef1->GetValue();
129 TopoDS_Shape aRefShape2 = aRef2->GetValue();
131 if (aRefShape1.ShapeType() != TopAbs_EDGE || aRefShape2.ShapeType() != TopAbs_EDGE ) {
132 Standard_TypeMismatch::Raise
133 ("Creation Point On Lines Intersection Aborted : Line shape is not an edge");
135 //Calculate Lines Intersection Point
136 BRepExtrema_DistShapeShape dst (aRefShape1, aRefShape2);
140 for (int i = 1; i <= dst.NbSolution(); i++) {
141 P1 = dst.PointOnShape1(i);
142 P2 = dst.PointOnShape2(i);
143 Standard_Real Dist = P1.Distance(P2);
144 if ( Dist <= Precision::Confusion() )
147 Standard_TypeMismatch::Raise ("Lines not have an Intersection Point");
155 BRepBuilderAPI_MakeVertex mkVertex (aPnt);
156 TopoDS_Shape aShape = mkVertex.Shape();
157 aShape.Infinite(Standard_True);
158 aFunction->SetValue(aShape);
160 log.SetTouched(Label());
166 //=======================================================================
167 //function : GEOMImpl_PointDriver_Type_
169 //=======================================================================
170 Standard_EXPORT Handle_Standard_Type& GEOMImpl_PointDriver_Type_()
173 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
174 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
175 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
176 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
177 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
178 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
181 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
182 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_PointDriver",
183 sizeof(GEOMImpl_PointDriver),
185 (Standard_Address)_Ancestors,
186 (Standard_Address)NULL);
191 //=======================================================================
192 //function : DownCast
194 //=======================================================================
196 const Handle(GEOMImpl_PointDriver) Handle(GEOMImpl_PointDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
198 Handle(GEOMImpl_PointDriver) _anOtherObject;
200 if (!AnObject.IsNull()) {
201 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_PointDriver))) {
202 _anOtherObject = Handle(GEOMImpl_PointDriver)((Handle(GEOMImpl_PointDriver)&)AnObject);
206 return _anOtherObject ;