1 // Created on: 1998-11-20
2 // Created by: Xuan PHAM PHU
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
24 #include <gp_Dir2d.hxx>
26 #include <gp_Pnt2d.hxx>
27 #include <BRep_Tool.hxx>
28 #include <TopOpeBRepTool_define.hxx>
29 #include <TopOpeBRepTool_EXPORT.hxx>
30 #include <TopOpeBRepTool_TOOL.hxx>
32 #define M_FORWARD(ori) (ori == TopAbs_FORWARD)
33 #define M_REVERSED(ori) (ori == TopAbs_REVERSED)
34 #define M_INTERNAL(ori) (ori == TopAbs_INTERNAL)
35 #define M_EXTERNAL(ori) (ori == TopAbs_EXTERNAL)
37 // ----------------------------------------------------------------------
39 // ----------------------------------------------------------------------
41 // ----------------------------------------------------------------------
42 Standard_EXPORT gp_Dir FUN_tool_nCinsideS(const gp_Dir& tgC,const gp_Dir& ngS)
44 // Give us a curve C on suface S,<parOnC>,a parameter
45 // Purpose : compute normal vector to C,tangent to S at
46 // given point,oriented INSIDE S
47 // <tgC> : geometric tangent at point of <parOnC>
48 // <ngS> : geometric normal at point of <parOnC>
52 // ----------------------------------------------------------------------
53 Standard_EXPORT gp_Dir2d FUN_tool_nC2dINSIDES(const gp_Dir2d& tgC2d)
55 // ------------------------------------------------------------
56 // Give us an edge E of 2d rep. on a face F C2d.
57 // E is oriented FORWARD in F,then the matter described by
58 // the restriction of E on the surface of F is on the left.
59 // Give us UV on S,<ngS> is the normal to S at point given by UV
60 // <tgC2d> is the tangent to C2d at point UV,
61 // (X,Y,Z) describes a RONd with :
62 // X = (tgC2d,0),Y = (xx,0),Z =(0,0,1)
63 // ------------------------------------------------------------
66 X = gp_Dir(tgC2d.X(),tgC2d.Y(),0.);
68 gp_Dir2d xx(Y.X(),Y.Y());
72 // ----------------------------------------------------------------------
73 //Standard_EXPORT gp_Vec FUN_tool_getgeomxx(const TopoDS_Face& Fi,
74 Standard_EXPORT gp_Vec FUN_tool_getgeomxx(const TopoDS_Face& ,
75 const TopoDS_Edge& Ei,
76 const Standard_Real parEi,
79 // <Ei> is an edge of <Fi>,
80 // computing XX a vector normal to <ngFi>,
81 // oriented IN the face <Fi>.
82 // (<ngFi> normal geometric to <Fi> at point of parameter
83 // <parEi> on edge <Ei>)
84 // <XX> is oriented inside 2d <F> if <E> is FORWARD in <F>
86 gp_Vec tgEi; Standard_Boolean ok = TopOpeBRepTool_TOOL::TggeomE(parEi,Ei,tgEi);
87 if (!ok) return gp_Vec(0.,0.,0.); //NYIRAISE
88 gp_Dir XX = FUN_tool_nCinsideS(tgEi,ngFi);
92 // ----------------------------------------------------------------------
93 Standard_EXPORT gp_Vec FUN_tool_getgeomxx(const TopoDS_Face& Fi,const TopoDS_Edge& Ei,
94 const Standard_Real parOnEi)
97 gp_Pnt2d uvi; Standard_Boolean ok = FUN_tool_paronEF(Ei,parOnEi,Fi,uvi);
98 if (!ok) return xx; // nyiRaise
99 gp_Vec ngFi = FUN_tool_nggeomF(uvi,Fi);
100 xx = FUN_tool_getgeomxx(Fi,Ei,parOnEi,ngFi);
104 // ----------------------------------------------------------------------
105 Standard_EXPORT Standard_Boolean FUN_tool_getxx(const TopoDS_Face& Fi,const TopoDS_Edge& Ei,
106 const Standard_Real parEi,const gp_Dir& ngFi,
109 gp_Vec xx = FUN_tool_getgeomxx(Fi,Ei,parEi,ngFi);
110 if (xx.Magnitude() < gp::Resolution()) return Standard_False;
112 TopAbs_Orientation oriEinF; Standard_Boolean ok = FUN_tool_orientEinFFORWARD(Ei,Fi,oriEinF);
113 if (!ok) return Standard_False;
114 if (M_REVERSED(oriEinF)) XX.Reverse();
115 return Standard_True;
118 // ----------------------------------------------------------------------
119 Standard_EXPORT Standard_Boolean FUN_tool_getxx(const TopoDS_Face& Fi,const TopoDS_Edge& Ei, const Standard_Real parEi,
122 Standard_Real tolFi = BRep_Tool::Tolerance(Fi)*1.e2; // nyitol
123 gp_Pnt2d uv; Standard_Boolean ok = FUN_tool_parF(Ei,parEi,Fi,uv,tolFi);
124 if (!ok) return Standard_False;
125 gp_Vec ng = FUN_tool_nggeomF(uv,Fi);
126 ok = FUN_tool_getxx(Fi,Ei,parEi,ng,XX);
130 // ----------------------------------------------------------------------
131 Standard_EXPORT Standard_Boolean FUN_tool_getdxx(const TopoDS_Face& F,
132 const TopoDS_Edge& E,
133 // const Standard_Real parE,
134 const Standard_Real ,
137 // points between uvparE and uvparE+dxx are IN F2d
139 dxx = gp_Vec2d(0.,0.);
140 TopAbs_Orientation oEinFF; Standard_Boolean ok = FUN_tool_orientEinFFORWARD(E,F,oEinFF);
141 if (!ok) return Standard_False;
142 if (M_INTERNAL(oEinFF) || M_EXTERNAL(oEinFF)) return Standard_False;
144 Standard_Boolean isoU,isoV; gp_Dir2d d2d; gp_Pnt2d o2d;
145 Standard_Boolean iso = TopOpeBRepTool_TOOL::UVISO(E,F,isoU,isoV,d2d,o2d);
146 if (!iso) return Standard_False;
147 Standard_Real u1,u2,v1,v2; ok = FUN_tool_isobounds(F,u1,u2,v1,v2);
148 if (!ok) return Standard_False;
150 Standard_Real xpar = isoU ? o2d.X() : o2d.Y();
151 Standard_Real xinf = isoU ? u1 : v1;
152 Standard_Real xsup = isoU ? u2 : v2;
154 ok = ::FUN_nearestISO(F,xpar,isoU,xinf,xsup);
155 if (!ok) return Standard_False;
157 Standard_Real ypar = isoU? d2d.Y() : d2d.X();
158 Standard_Boolean matterAFTERxpar = Standard_False;
159 if (isoU) matterAFTERxpar = (ypar < 0.);
160 if (isoV) matterAFTERxpar = (ypar > 0.);
161 if (oEinFF == TopAbs_REVERSED) matterAFTERxpar = !matterAFTERxpar;
163 Standard_Real dx = 0.;
164 if (matterAFTERxpar) dx = xsup-xpar;
167 if (isoU) dxx = gp_Vec2d(dx,0.);
168 if (isoV) dxx = gp_Vec2d(0.,dx);
169 return Standard_True;