0027772: Foundation Classes - define Standard_Boolean using C++ type "bool" instead...
[occt.git] / src / TopOpeBRep / TopOpeBRep_vprclo.cxx
CommitLineData
b311480e 1// Created on: 1995-08-04
2// Created by: Jean Yves LEBEY
3// Copyright (c) 1995-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
7fd59977 17
7fd59977 18#include <BRep_Tool.hxx>
19#include <BRepAdaptor_Curve.hxx>
42cf5bc1 20#include <gp_Pnt.hxx>
7fd59977 21#include <gp_Vec.hxx>
42cf5bc1 22#include <Precision.hxx>
23#include <TopExp.hxx>
24#include <TopoDS.hxx>
25#include <TopoDS_Face.hxx>
26#include <TopoDS_Shape.hxx>
27#include <TopOpeBRep_define.hxx>
28#include <TopOpeBRep_FacesFiller.hxx>
29#include <TopOpeBRep_FacesIntersector.hxx>
30#include <TopOpeBRep_FFDumper.hxx>
31#include <TopOpeBRep_LineInter.hxx>
32#include <TopOpeBRep_PointClassifier.hxx>
33#include <TopOpeBRep_VPointInter.hxx>
34#include <TopOpeBRep_VPointInterClassifier.hxx>
35#include <TopOpeBRep_VPointInterIterator.hxx>
36#include <TopOpeBRepDS_DataStructure.hxx>
37#include <TopOpeBRepDS_define.hxx>
38#include <TopOpeBRepDS_EXPORT.hxx>
39#include <TopOpeBRepDS_HDataStructure.hxx>
40#include <TopOpeBRepDS_Interference.hxx>
41#include <TopOpeBRepDS_Point.hxx>
42#include <TopOpeBRepDS_PointIterator.hxx>
43#include <TopOpeBRepDS_repvg.hxx>
44#include <TopOpeBRepDS_Transition.hxx>
45#include <TopOpeBRepTool_EXPORT.hxx>
46#include <TopOpeBRepTool_makeTransition.hxx>
47#include <TopOpeBRepTool_ShapeTool.hxx>
7fd59977 48
42cf5bc1 49// LOIinfsup
7fd59977 50#define M_ON(st) (st == TopAbs_ON)
51#define M_REVERSED(st) (st == TopAbs_REVERSED)
52
0797d9d3 53#ifdef OCCT_DEBUG
7fd59977 54Standard_EXPORT void debarc(const Standard_Integer i);
55Standard_EXPORT void debooarc(const Standard_Integer i);
56#endif
57
58Standard_EXPORT Handle(TopOpeBRepDS_Interference) MakeEPVInterference
59(const TopOpeBRepDS_Transition& T, // transition
60 const Standard_Integer S, // curve/edge index
61 const Standard_Integer G, // point/vertex index
62 const Standard_Real P, // parameter of G on S
63 const TopOpeBRepDS_Kind GK,
64 const Standard_Boolean B); // G is a vertex (or not) of the interference master
65Standard_EXPORT Handle(TopOpeBRepDS_Interference) MakeEPVInterference
66(const TopOpeBRepDS_Transition& T, // transition
67 const Standard_Integer S, // curve/edge index
68 const Standard_Integer G, // point/vertex index
69 const Standard_Real P, // parameter of G on S
70 const TopOpeBRepDS_Kind GK, // POINT/VERTEX
71 const TopOpeBRepDS_Kind SK,
72 const Standard_Boolean B); // G is a vertex (or not) of the interference master
73
74
75static Standard_Boolean FUN_INlos(const TopoDS_Shape& S, const TopTools_ListOfShape& loS)
76{
77 TopTools_ListIteratorOfListOfShape it(loS);
78 for (; it.More(); it.Next())
79 if (it.Value().IsSame(S)) return Standard_True;
80 return Standard_False;
81}
82
83//=======================================================================
84//function : GetEdgeTrans
85//purpose : Computes E<Sind> transition on <F> at point <VP>
86// Computes FORWARD or REVERSED transitions,
87// returns transition UNKNOWN elsewhere.
88//=======================================================================
89TopOpeBRepDS_Transition TopOpeBRep_FacesFiller::GetEdgeTrans(const TopOpeBRep_VPointInter& VP,const TopOpeBRepDS_Kind PVKind,
90 const Standard_Integer PVIndex,const Standard_Integer ShapeIndex,const TopoDS_Face& F)
91{
92 // VP is on couture <Ec> of rank <sind>
93 // on face <F> of rank <oosind>.
94 Standard_Integer OOShapeIndex = (ShapeIndex == 1) ? 2 : 1;
95 Standard_Integer vpsind = VP.ShapeIndex();
96 Standard_Boolean on2edges = (vpsind == 3);
97 Standard_Boolean isvalid = on2edges || (vpsind == ShapeIndex);
98 if (!isvalid) Standard_Failure::Raise("TopOpeBRep_FacesFiller::GetEdgeTrans");
99
100 const TopoDS_Edge& edge = TopoDS::Edge(VP.Edge(ShapeIndex));
101 Standard_Real paredge = VP.EdgeParameter(ShapeIndex);
102
103 TopoDS_Edge OOedge;
1d47d8d0 104
105 Standard_Real OOparedge = 0.;
106
7fd59977 107 Standard_Boolean hasONedge = (VP.State(OOShapeIndex) == TopAbs_ON);
108 Standard_Boolean hasOOedge = (on2edges) ? Standard_True : hasONedge;
109 if ( hasOOedge ) {
110 if (on2edges) OOparedge = VP.EdgeParameter(OOShapeIndex);
111 else OOparedge = VP.EdgeONParameter(OOShapeIndex);
112 TopoDS_Shape OOe;
113 if (on2edges) OOe = VP.Edge(OOShapeIndex);
114 else OOe = VP.EdgeON(OOShapeIndex);
115 OOedge = TopoDS::Edge(OOe);
116 }
117 gp_Pnt2d OOuv = VP.SurfaceParameters(OOShapeIndex);
118
119 Standard_Real par1,par2;
120 Standard_Integer SIedgeIndex = (myHDS->HasShape(edge)) ? myHDS->Shape(edge) : 0;
121// if (SIedgeIndex != 0) FDS_getupperlower(myHDS,SIedgeIndex,paredge,par1,par2);
122 if (SIedgeIndex != 0) {
123 Standard_Boolean isonboundper;
124 FDS_LOIinfsup(myHDS->DS(),edge,paredge,PVKind,PVIndex,
125 myHDS->DS().ShapeInterferences(edge),par1,par2,isonboundper);
126 }
127 else
128 FUN_tool_bounds(edge,par1,par2);
129
130 TopOpeBRepDS_Transition T;
131 // xpu : 16-01-98
132 // <Tr> relative to 3d <OOface> matter,
133 // we take into account <Tr> / 2d <OOface> only if <edge> is normal to <OOface>
134 Standard_Real tola = Precision::Angular()*1.e+2; //dealing with tolerances
135 Standard_Boolean EtgF = FUN_tool_EtgF(paredge,edge,OOuv,F,tola);
136 Standard_Boolean rest = FUN_INlos(edge,myERL);
137 Standard_Boolean isse = myHDS->DS().IsSectionEdge(edge);
138 rest = rest || isse;
139 Standard_Boolean interf2d = EtgF && hasOOedge && rest;
140
141 Standard_Real factor = 1.e-4;
142 TopOpeBRepTool_makeTransition MKT;
143 Standard_Boolean ok = MKT.Initialize(edge,par1,par2,paredge, F,OOuv, factor);
144 if (!ok) return T;
145 Standard_Boolean isT2d = MKT.IsT2d();
146 interf2d = interf2d && isT2d;
147 if (interf2d) ok = MKT.SetRest(OOedge,OOparedge);
148 if (!ok) return T;
149
150 TopAbs_State stb,sta; ok = MKT.MkTonE(stb,sta);
151 if (!ok) return T;
152 T.Before(stb); T.After(sta);
153 return T;
154}
155
156//=======================================================================
157//function : ProcessVPonclosingR
158//purpose : SUPPLYING INTPATCH when <VP> is on closing arc.
159//=======================================================================
160void TopOpeBRep_FacesFiller::ProcessVPonclosingR(const TopOpeBRep_VPointInter& VP,
161// const TopoDS_Shape& GFace,
162 const TopoDS_Shape& ,
163 const Standard_Integer ShapeIndex,
164 const TopOpeBRepDS_Transition& transEdge,const TopOpeBRepDS_Kind PVKind, const Standard_Integer PVIndex,
165// const Standard_Boolean EPIfound,
166 const Standard_Boolean ,
167// const Handle(TopOpeBRepDS_Interference)& IEPI)
168 const Handle(TopOpeBRepDS_Interference)& )
169{
170// Standard_Boolean isvertex = VP.IsVertex(ShapeIndex);
171 Standard_Boolean isvertex = (PVKind == TopOpeBRepDS_VERTEX);
172 Standard_Integer absindex = VP.ShapeIndex(); // 0,1,2,3
dde68833 173 Standard_Integer OOShapeIndex = (ShapeIndex == 1) ? 2 : 1;
7fd59977 174 Standard_Boolean on2edges = (absindex == 3);
175 Standard_Boolean hasONedge = (VP.State(OOShapeIndex) == TopAbs_ON);
176 Standard_Boolean hasOOedge = (on2edges) ? Standard_True : hasONedge;
177
178 TopoDS_Face Face = (*this).Face(ShapeIndex);
7fd59977 179 TopoDS_Face OOFace = (*this).Face(OOShapeIndex);
180 Standard_Integer iOOFace = myDS->Shape(OOFace);
181 if (iOOFace == 0) iOOFace = myDS->AddShape(OOFace,OOShapeIndex);
182
183 // current VPoint is on <edge>
7fd59977 184 const TopoDS_Edge& edge = TopoDS::Edge(VP.Edge(ShapeIndex));
96a95605 185 if (!myDS->HasShape(edge)) myDS->AddShape(edge,ShapeIndex);
6e6cd5d9 186
7fd59977 187 Standard_Real paredge = VP.EdgeParameter(ShapeIndex);
188
189 // dummy if !<hasOOedge>
190 Standard_Integer OOedgeIndex = 0;
7fd59977 191 TopoDS_Edge OOedge;
192 if ( hasOOedge ) {
193 TopoDS_Shape OOe;
194 if (on2edges) OOe = VP.Edge(OOShapeIndex);
195 else OOe = VP.EdgeON(OOShapeIndex);
196 OOedge = TopoDS::Edge(OOe);
7fd59977 197 if (myDS->HasShape(OOedge)) OOedgeIndex = myDS->Shape(OOedge);
198 else OOedgeIndex = myDS->AddShape(OOedge,OOShapeIndex);
199 }
200
7fd59977 201 // ===================================================================
202 // --- Edge/(POINT,VERTEX) Interference (EPI) creation ---
203 // ===================================================================
204
205 // 1. <edge> enters or outers myF<OOShapeIndex> at <VP>,
206 // transition <transEdge> returned by IntPatch is valid (FORWARD/REVERSED).
207 // 2. <edge> is tangent to myF<OOShapeIndex> :
208 // transEdge should be INTERNAL/EXTERNAL.
209
210 Standard_Boolean Tunk = transEdge.IsUnknown();
7fd59977 211 TopOpeBRepDS_Transition transAdd;
212 Standard_Boolean newtransEdge = Tunk;
213 if (newtransEdge) transAdd = GetEdgeTrans(VP,PVKind,PVIndex,ShapeIndex,OOFace);
214 else transAdd = transEdge;
215
216 // !!! if the compute of <transAdd> fails, we add transEdge.
217 // hasOOedge : <VP> is ON edge <edge> and ON <OOFace>
218 // !hasOOedge : <VP> is ON edge <edge> and IN <OOFace>
219 {
220 TopOpeBRepDS_Transition T = transAdd; T.Index(iOOFace);
221 Handle(TopOpeBRepDS_Interference) EPI = ::MakeEPVInterference
222 (T,iOOFace,PVIndex,paredge,PVKind,TopOpeBRepDS_FACE,isvertex);
223 myHDS->StoreInterference(EPI,edge);
224 }
225 if (hasOOedge) {
226 TopOpeBRepDS_Transition T = transAdd; T.Index(iOOFace);
227 Handle(TopOpeBRepDS_Interference) EPI = ::MakeEPVInterference
228 (T,OOedgeIndex,PVIndex,paredge,PVKind,isvertex);
229 myHDS->StoreInterference(EPI,edge);
230 }
231
232} // ProcessVPonclosingR