1 // Created on: 1998-10-06
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <TopOpeBRepTool_GEOMETRY.hxx>
19 #include <Geom2d_Curve.hxx>
20 #include <Geom2d_Line.hxx>
21 #include <Geom_Curve.hxx>
22 #include <Geom_Surface.hxx>
23 #include <Geom2dAdaptor_Curve.hxx>
24 #include <GeomAdaptor_Curve.hxx>
25 #include <GeomAdaptor_Surface.hxx>
27 #include <gp_Cone.hxx>
28 #include <gp_Sphere.hxx>
29 #include <Geom2d_OffsetCurve.hxx>
30 #include <Geom2d_TrimmedCurve.hxx>
31 #include <TopOpeBRepTool_ShapeTool.hxx>
32 #include <Precision.hxx>
34 // ----------------------------------------------------------------------
35 Standard_EXPORT Handle(Geom2d_Curve) BASISCURVE2D(const Handle(Geom2d_Curve)& C)
37 Handle(Standard_Type) T = C->DynamicType();
38 if ( T == STANDARD_TYPE(Geom2d_OffsetCurve) )
39 return ::BASISCURVE2D(Handle(Geom2d_OffsetCurve)::DownCast(C)->BasisCurve());
40 else if ( T == STANDARD_TYPE(Geom2d_TrimmedCurve) )
41 return ::BASISCURVE2D(Handle(Geom2d_TrimmedCurve)::DownCast(C)->BasisCurve());
45 /*// ----------------------------------------------------------------------
46 Standard_EXPORT Standard_Boolean FUN_tool_IsUViso(const Handle(Geom2d_Curve)& PC,
47 Standard_Boolean& isoU,Standard_Boolean& isoV,
48 gp_Dir2d& d2d,gp_Pnt2d& o2d)
50 isoU = isoV = Standard_False;
51 if (PC.IsNull()) return Standard_False;
52 Handle(Geom2d_Curve) LLL = BASISCURVE2D(PC);
53 Handle(Standard_Type) T2 = LLL->DynamicType();
54 Standard_Boolean isline2d = (T2 == STANDARD_TYPE(Geom2d_Line));
55 if (!isline2d) return Standard_False;
57 Handle(Geom2d_Line) L = Handle(Geom2d_Line)::DownCast(LLL);
59 isoU = (Abs(d2d.X()) < Precision::Parametric(Precision::Confusion()));
60 isoV = (Abs(d2d.Y()) < Precision::Parametric(Precision::Confusion()));
61 Standard_Boolean isoUV = isoU || isoV;
62 if (!isoUV) return Standard_False;
68 // ----------------------------------------------------------------------
69 Standard_EXPORT gp_Dir FUN_tool_dirC(const Standard_Real par,const Handle(Geom_Curve)& C)
71 gp_Pnt p; gp_Vec tgE; C->D1(par,p,tgE);
76 // ----------------------------------------------------------------------
77 Standard_EXPORT Standard_Boolean FUN_tool_onapex(const gp_Pnt2d& p2d,const Handle(Geom_Surface)& S)
79 Standard_Boolean isapex = Standard_False;
80 GeomAdaptor_Surface GS(S);
81 Standard_Real tol = Precision::Confusion();
82 GeomAbs_SurfaceType ST = GS.GetType();
83 Standard_Real toluv = 1.e-8;
84 if (ST == GeomAbs_Cone) {
85 gp_Cone co = GS.Cone();
86 gp_Pnt apex = co.Apex();
87 gp_Pnt pnt = GS.Value(p2d.X(),p2d.Y());
88 Standard_Real dist = pnt.Distance(apex);
89 isapex = (dist < tol);
91 if (ST == GeomAbs_Sphere) {
92 Standard_Real pisur2 = M_PI*.5;
93 Standard_Real v = p2d.Y();
94 Standard_Boolean vpisur2 = (Abs(v-pisur2) < toluv);
95 Standard_Boolean vmoinspisur2 = (Abs(v+pisur2) < toluv);
96 isapex = vpisur2 || vmoinspisur2;
101 // ----------------------------------------------------------------------
102 Standard_EXPORT gp_Dir FUN_tool_ngS(const gp_Pnt2d& p2d,const Handle(Geom_Surface)& S)
104 // ###############################
105 // nyi : all geometries are direct
106 // ###############################
107 gp_Pnt p; gp_Vec d1u,d1v;
108 S->D1(p2d.X(),p2d.Y(),p,d1u,d1v);
110 Standard_Real du = d1u.Magnitude();
111 Standard_Real dv = d1v.Magnitude();
112 Standard_Real tol = Precision::Confusion();
113 Standard_Boolean kpart = (du < tol) || (dv < tol);
115 GeomAdaptor_Surface GS(S);
116 GeomAbs_SurfaceType ST = GS.GetType();
117 Standard_Real toluv = 1.e-8;
118 if (ST == GeomAbs_Cone) {
119 Standard_Boolean nullx = (Abs(p2d.X()) < toluv);
120 Standard_Boolean apex = nullx && (Abs(p2d.Y()) < toluv);
122 const gp_Dir& axis = GS.Cone().Axis().Direction();
123 gp_Vec ng(axis); ng.Reverse();
127 Standard_Real vf = GS.FirstVParameter();
128 Standard_Boolean onvf = Abs(p2d.Y()-vf)<toluv;
130 Standard_Real x = p2d.X(); Standard_Real y = p2d.Y();
131 //NYIXPU : devrait plutot etre fait sur les faces & TopOpeBRepTool_TOOL::minDUV...
134 S->D1(x,y,p,d1u,d1v);
139 if (ST == GeomAbs_Sphere) {
140 // Standard_Real deuxpi = 2*M_PI;
141 Standard_Real pisur2 = M_PI*.5;
142 Standard_Real u = p2d.X(),v = p2d.Y();
143 // Standard_Boolean u0 =(Abs(u) < toluv);
144 // Standard_Boolean u2pi=(Abs(u-deuxpi) < toluv);
145 // Standard_Boolean apex = u0 || u2pi;
146 Standard_Boolean vpisur2 = (Abs(v-pisur2) < toluv);
147 Standard_Boolean vmoinspisur2 = (Abs(v+pisur2) < toluv);
148 Standard_Boolean apex = vpisur2 || vmoinspisur2;
150 gp_Pnt center = GS.Sphere().Location();
151 gp_Pnt value = GS.Value(u,v);
152 gp_Vec ng(center,value);
157 #ifdef TOPOPEBREPTOOL_DEB
158 cout<<"FUN_tool_nggeomF NYI"<<endl;
160 return gp_Dir(0,0,1);
165 gp_Dir ngS(udir^vdir);
169 // ----------------------------------------------------------------------
170 Standard_EXPORT Standard_Boolean FUN_tool_line(const Handle(Geom_Curve)& C3d)
172 Handle(Geom_Curve) C = TopOpeBRepTool_ShapeTool::BASISCURVE(C3d);
173 GeomAdaptor_Curve GC(C);
174 Standard_Boolean line = (GC.GetType() == GeomAbs_Line);
178 // ----------------------------------------------------------------------
179 Standard_EXPORT Standard_Boolean FUN_quadCT(const GeomAbs_CurveType& CT)
181 Standard_Boolean isquad = Standard_False;
182 if (CT == GeomAbs_Line) isquad = Standard_True;
183 if (CT == GeomAbs_Circle) isquad = Standard_True;
184 if (CT == GeomAbs_Ellipse) isquad = Standard_True;
185 if (CT == GeomAbs_Hyperbola) isquad = Standard_True;
186 if (CT == GeomAbs_Parabola) isquad = Standard_True;
190 // ----------------------------------------------------------------------
191 Standard_EXPORT Standard_Boolean FUN_tool_quad(const Handle(Geom_Curve)& C3d)
193 Handle(Geom_Curve) C = TopOpeBRepTool_ShapeTool::BASISCURVE(C3d);
194 if (C.IsNull()) return Standard_False;
195 GeomAdaptor_Curve GC(C);
196 GeomAbs_CurveType CT = GC.GetType();
197 Standard_Boolean quad = FUN_quadCT(CT);
201 // ----------------------------------------------------------------------
202 Standard_EXPORT Standard_Boolean FUN_tool_quad(const Handle(Geom2d_Curve)& pc)
204 Handle(Geom2d_Curve) pcb = BASISCURVE2D(pc); // NYI TopOpeBRepTool_ShapeTool
205 if (pcb.IsNull()) return Standard_False;
206 Geom2dAdaptor_Curve GC2d(pcb);
207 GeomAbs_CurveType typ = GC2d.GetType();
208 Standard_Boolean isquad = Standard_False;
209 if (typ == GeomAbs_Line) isquad = Standard_True;
210 if (typ == GeomAbs_Circle) isquad = Standard_True;
211 if (typ == GeomAbs_Ellipse) isquad = Standard_True;
212 if (typ == GeomAbs_Hyperbola) isquad = Standard_True;
213 if (typ == GeomAbs_Parabola) isquad = Standard_True;
216 // ----------------------------------------------------------------------
217 Standard_EXPORT Standard_Boolean FUN_tool_line(const Handle(Geom2d_Curve)& pc)
219 Handle(Geom2d_Curve) pcb = BASISCURVE2D(pc); // NYI TopOpeBRepTool_ShapeTool
220 if (pcb.IsNull()) return Standard_False;
221 Geom2dAdaptor_Curve GC2d(pcb);
222 GeomAbs_CurveType typ = GC2d.GetType();
224 if (typ == GeomAbs_Line) return Standard_True;
226 return Standard_False ;
230 // ----------------------------------------------------------------------
231 Standard_EXPORT Standard_Boolean FUN_tool_quad(const Handle(Geom_Surface)& S)
233 if (S.IsNull()) return Standard_False;
234 GeomAdaptor_Surface GAS(S);
235 GeomAbs_SurfaceType typ = GAS.GetType();
236 Standard_Boolean isquad = Standard_False;
237 if (typ == GeomAbs_Plane) isquad = Standard_True;
238 if (typ == GeomAbs_Cylinder) isquad = Standard_True;
239 if (typ == GeomAbs_Cone) isquad = Standard_True;
240 if (typ == GeomAbs_Sphere) isquad = Standard_True;
241 if (typ == GeomAbs_Torus) isquad = Standard_True;
246 // ----------------------------------------------------------------------
247 Standard_EXPORT Standard_Boolean FUN_tool_closed(const Handle(Geom_Surface)& S,
248 Standard_Boolean& uclosed,Standard_Real& uperiod,
249 Standard_Boolean& vclosed,Standard_Real& vperiod)
251 uperiod = vperiod = 0.;
252 if (S.IsNull()) return Standard_False;
253 uclosed = S->IsUClosed(); if (uclosed) uclosed = S->IsUPeriodic(); //xpu261098 (BUC60382)
254 if (uclosed) uperiod = S->UPeriod();
255 vclosed = S->IsVClosed(); if (vclosed) vclosed = S->IsVPeriodic();
256 if (vclosed) vperiod = S->VPeriod();
257 Standard_Boolean closed = uclosed || vclosed;
261 // ----------------------------------------------------------------------
262 Standard_EXPORT void FUN_tool_UpdateBnd2d(Bnd_Box2d& B2d,const Bnd_Box2d& newB2d)
264 // B2d.SetVoid(); -> DOESN'T EMPTY THE BOX