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 gp_Dir axis = GS.Cone().Axis().Direction();
128 Standard_Real vf = GS.FirstVParameter();
129 Standard_Boolean onvf = Abs(p2d.Y()-vf)<toluv;
131 Standard_Real x = p2d.X(); Standard_Real y = p2d.Y();
132 //NYIXPU : devrait plutot etre fait sur les faces & TopOpeBRepTool_TOOL::minDUV...
135 S->D1(x,y,p,d1u,d1v);
140 if (ST == GeomAbs_Sphere) {
141 // Standard_Real deuxpi = 2*M_PI;
142 Standard_Real pisur2 = M_PI*.5;
143 Standard_Real u = p2d.X(),v = p2d.Y();
144 // Standard_Boolean u0 =(Abs(u) < toluv);
145 // Standard_Boolean u2pi=(Abs(u-deuxpi) < toluv);
146 // Standard_Boolean apex = u0 || u2pi;
147 Standard_Boolean vpisur2 = (Abs(v-pisur2) < toluv);
148 Standard_Boolean vmoinspisur2 = (Abs(v+pisur2) < toluv);
149 Standard_Boolean apex = vpisur2 || vmoinspisur2;
151 gp_Pnt center = GS.Sphere().Location();
152 gp_Pnt value = GS.Value(u,v);
153 gp_Vec ng(center,value);
159 std::cout<<"FUN_tool_nggeomF NYI"<<std::endl;
161 return gp_Dir(0,0,1);
166 gp_Dir ngS(udir^vdir);
170 // ----------------------------------------------------------------------
171 Standard_EXPORT Standard_Boolean FUN_tool_line(const Handle(Geom_Curve)& C3d)
173 Handle(Geom_Curve) C = TopOpeBRepTool_ShapeTool::BASISCURVE(C3d);
174 GeomAdaptor_Curve GC(C);
175 Standard_Boolean line = (GC.GetType() == GeomAbs_Line);
179 // ----------------------------------------------------------------------
180 Standard_EXPORT Standard_Boolean FUN_quadCT(const GeomAbs_CurveType& CT)
182 Standard_Boolean isquad = Standard_False;
183 if (CT == GeomAbs_Line) isquad = Standard_True;
184 if (CT == GeomAbs_Circle) isquad = Standard_True;
185 if (CT == GeomAbs_Ellipse) isquad = Standard_True;
186 if (CT == GeomAbs_Hyperbola) isquad = Standard_True;
187 if (CT == GeomAbs_Parabola) isquad = Standard_True;
191 // ----------------------------------------------------------------------
192 Standard_EXPORT Standard_Boolean FUN_tool_quad(const Handle(Geom_Curve)& C3d)
194 Handle(Geom_Curve) C = TopOpeBRepTool_ShapeTool::BASISCURVE(C3d);
195 if (C.IsNull()) return Standard_False;
196 GeomAdaptor_Curve GC(C);
197 GeomAbs_CurveType CT = GC.GetType();
198 Standard_Boolean quad = FUN_quadCT(CT);
202 // ----------------------------------------------------------------------
203 Standard_EXPORT Standard_Boolean FUN_tool_quad(const Handle(Geom2d_Curve)& pc)
205 Handle(Geom2d_Curve) pcb = BASISCURVE2D(pc); // NYI TopOpeBRepTool_ShapeTool
206 if (pcb.IsNull()) return Standard_False;
207 Geom2dAdaptor_Curve GC2d(pcb);
208 GeomAbs_CurveType typ = GC2d.GetType();
209 Standard_Boolean isquad = Standard_False;
210 if (typ == GeomAbs_Line) isquad = Standard_True;
211 if (typ == GeomAbs_Circle) isquad = Standard_True;
212 if (typ == GeomAbs_Ellipse) isquad = Standard_True;
213 if (typ == GeomAbs_Hyperbola) isquad = Standard_True;
214 if (typ == GeomAbs_Parabola) isquad = Standard_True;
217 // ----------------------------------------------------------------------
218 Standard_EXPORT Standard_Boolean FUN_tool_line(const Handle(Geom2d_Curve)& pc)
220 Handle(Geom2d_Curve) pcb = BASISCURVE2D(pc); // NYI TopOpeBRepTool_ShapeTool
221 if (pcb.IsNull()) return Standard_False;
222 Geom2dAdaptor_Curve GC2d(pcb);
223 GeomAbs_CurveType typ = GC2d.GetType();
225 if (typ == GeomAbs_Line) return Standard_True;
227 return Standard_False ;
231 // ----------------------------------------------------------------------
232 Standard_EXPORT Standard_Boolean FUN_tool_quad(const Handle(Geom_Surface)& S)
234 if (S.IsNull()) return Standard_False;
235 GeomAdaptor_Surface GAS(S);
236 GeomAbs_SurfaceType typ = GAS.GetType();
237 Standard_Boolean isquad = Standard_False;
238 if (typ == GeomAbs_Plane) isquad = Standard_True;
239 if (typ == GeomAbs_Cylinder) isquad = Standard_True;
240 if (typ == GeomAbs_Cone) isquad = Standard_True;
241 if (typ == GeomAbs_Sphere) isquad = Standard_True;
242 if (typ == GeomAbs_Torus) isquad = Standard_True;
247 // ----------------------------------------------------------------------
248 Standard_EXPORT Standard_Boolean FUN_tool_closed(const Handle(Geom_Surface)& S,
249 Standard_Boolean& uclosed,Standard_Real& uperiod,
250 Standard_Boolean& vclosed,Standard_Real& vperiod)
252 uperiod = vperiod = 0.;
253 if (S.IsNull()) return Standard_False;
254 uclosed = S->IsUClosed(); if (uclosed) uclosed = S->IsUPeriodic(); //xpu261098 (BUC60382)
255 if (uclosed) uperiod = S->UPeriod();
256 vclosed = S->IsVClosed(); if (vclosed) vclosed = S->IsVPeriodic();
257 if (vclosed) vperiod = S->VPeriod();
258 Standard_Boolean closed = uclosed || vclosed;
262 // ----------------------------------------------------------------------
263 Standard_EXPORT void FUN_tool_UpdateBnd2d(Bnd_Box2d& B2d,const Bnd_Box2d& newB2d)
265 // B2d.SetVoid(); -> DOESN'T EMPTY THE BOX