1 // Created on: 1995-08-04
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1995-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
9 // under the terms of the GNU Lesser General Public 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 <TopOpeBRep_FacesFiller.ixx>
19 #include <TopOpeBRepTool_ShapeTool.hxx>
20 #include <TopOpeBRepTool_EXPORT.hxx>
21 #include <TopOpeBRepTool_makeTransition.hxx>
23 #include <TopOpeBRepDS_PointIterator.hxx>
24 #include <TopOpeBRepDS_define.hxx>
25 #include <TopOpeBRepDS_repvg.hxx> // LOIinfsup
26 #include <TopOpeBRepDS_EXPORT.hxx>
28 #include <TopOpeBRep_define.hxx>
30 #include <Precision.hxx>
33 #include <BRep_Tool.hxx>
34 #include <BRepAdaptor_Curve.hxx>
38 #define M_ON(st) (st == TopAbs_ON)
39 #define M_REVERSED(st) (st == TopAbs_REVERSED)
42 extern Standard_Boolean TopOpeBRepDS_GettraceDSF();
43 extern Standard_Boolean TopOpeBRepDS_GettraceSPSX(const Standard_Integer i1);
44 Standard_EXPORT void debarc(const Standard_Integer i);
45 Standard_EXPORT void debooarc(const Standard_Integer i);
48 Standard_EXPORT Handle(TopOpeBRepDS_Interference) MakeEPVInterference
49 (const TopOpeBRepDS_Transition& T, // transition
50 const Standard_Integer S, // curve/edge index
51 const Standard_Integer G, // point/vertex index
52 const Standard_Real P, // parameter of G on S
53 const TopOpeBRepDS_Kind GK,
54 const Standard_Boolean B); // G is a vertex (or not) of the interference master
55 Standard_EXPORT Handle(TopOpeBRepDS_Interference) MakeEPVInterference
56 (const TopOpeBRepDS_Transition& T, // transition
57 const Standard_Integer S, // curve/edge index
58 const Standard_Integer G, // point/vertex index
59 const Standard_Real P, // parameter of G on S
60 const TopOpeBRepDS_Kind GK, // POINT/VERTEX
61 const TopOpeBRepDS_Kind SK,
62 const Standard_Boolean B); // G is a vertex (or not) of the interference master
65 static Standard_Boolean FUN_INlos(const TopoDS_Shape& S, const TopTools_ListOfShape& loS)
67 TopTools_ListIteratorOfListOfShape it(loS);
68 for (; it.More(); it.Next())
69 if (it.Value().IsSame(S)) return Standard_True;
70 return Standard_False;
73 //=======================================================================
74 //function : GetEdgeTrans
75 //purpose : Computes E<Sind> transition on <F> at point <VP>
76 // Computes FORWARD or REVERSED transitions,
77 // returns transition UNKNOWN elsewhere.
78 //=======================================================================
79 TopOpeBRepDS_Transition TopOpeBRep_FacesFiller::GetEdgeTrans(const TopOpeBRep_VPointInter& VP,const TopOpeBRepDS_Kind PVKind,
80 const Standard_Integer PVIndex,const Standard_Integer ShapeIndex,const TopoDS_Face& F)
82 // VP is on couture <Ec> of rank <sind>
83 // on face <F> of rank <oosind>.
84 Standard_Integer OOShapeIndex = (ShapeIndex == 1) ? 2 : 1;
85 Standard_Integer vpsind = VP.ShapeIndex();
86 Standard_Boolean on2edges = (vpsind == 3);
87 Standard_Boolean isvalid = on2edges || (vpsind == ShapeIndex);
88 if (!isvalid) Standard_Failure::Raise("TopOpeBRep_FacesFiller::GetEdgeTrans");
90 const TopoDS_Edge& edge = TopoDS::Edge(VP.Edge(ShapeIndex));
91 Standard_Real paredge = VP.EdgeParameter(ShapeIndex);
95 Standard_Real OOparedge = 0.;
97 Standard_Boolean hasONedge = (VP.State(OOShapeIndex) == TopAbs_ON);
98 Standard_Boolean hasOOedge = (on2edges) ? Standard_True : hasONedge;
100 if (on2edges) OOparedge = VP.EdgeParameter(OOShapeIndex);
101 else OOparedge = VP.EdgeONParameter(OOShapeIndex);
103 if (on2edges) OOe = VP.Edge(OOShapeIndex);
104 else OOe = VP.EdgeON(OOShapeIndex);
105 OOedge = TopoDS::Edge(OOe);
107 gp_Pnt2d OOuv = VP.SurfaceParameters(OOShapeIndex);
109 Standard_Real par1,par2;
110 Standard_Integer SIedgeIndex = (myHDS->HasShape(edge)) ? myHDS->Shape(edge) : 0;
111 // if (SIedgeIndex != 0) FDS_getupperlower(myHDS,SIedgeIndex,paredge,par1,par2);
112 if (SIedgeIndex != 0) {
113 Standard_Boolean isonboundper;
114 FDS_LOIinfsup(myHDS->DS(),edge,paredge,PVKind,PVIndex,
115 myHDS->DS().ShapeInterferences(edge),par1,par2,isonboundper);
118 FUN_tool_bounds(edge,par1,par2);
120 TopOpeBRepDS_Transition T;
122 // <Tr> relative to 3d <OOface> matter,
123 // we take into account <Tr> / 2d <OOface> only if <edge> is normal to <OOface>
124 Standard_Real tola = Precision::Angular()*1.e+2; //dealing with tolerances
125 Standard_Boolean EtgF = FUN_tool_EtgF(paredge,edge,OOuv,F,tola);
126 Standard_Boolean rest = FUN_INlos(edge,myERL);
127 Standard_Boolean isse = myHDS->DS().IsSectionEdge(edge);
129 Standard_Boolean interf2d = EtgF && hasOOedge && rest;
131 Standard_Real factor = 1.e-4;
132 TopOpeBRepTool_makeTransition MKT;
133 Standard_Boolean ok = MKT.Initialize(edge,par1,par2,paredge, F,OOuv, factor);
135 Standard_Boolean isT2d = MKT.IsT2d();
136 interf2d = interf2d && isT2d;
137 if (interf2d) ok = MKT.SetRest(OOedge,OOparedge);
140 TopAbs_State stb,sta; ok = MKT.MkTonE(stb,sta);
142 T.Before(stb); T.After(sta);
146 //=======================================================================
147 //function : ProcessVPonclosingR
148 //purpose : SUPPLYING INTPATCH when <VP> is on closing arc.
149 //=======================================================================
150 void TopOpeBRep_FacesFiller::ProcessVPonclosingR(const TopOpeBRep_VPointInter& VP,
151 // const TopoDS_Shape& GFace,
152 const TopoDS_Shape& ,
153 const Standard_Integer ShapeIndex,
154 const TopOpeBRepDS_Transition& transEdge,const TopOpeBRepDS_Kind PVKind, const Standard_Integer PVIndex,
155 // const Standard_Boolean EPIfound,
156 const Standard_Boolean ,
157 // const Handle(TopOpeBRepDS_Interference)& IEPI)
158 const Handle(TopOpeBRepDS_Interference)& )
160 // Standard_Boolean isvertex = VP.IsVertex(ShapeIndex);
161 Standard_Boolean isvertex = (PVKind == TopOpeBRepDS_VERTEX);
162 Standard_Integer absindex = VP.ShapeIndex(); // 0,1,2,3
163 Standard_Boolean OOShapeIndex = (ShapeIndex == 1) ? 2 : 1;
164 Standard_Boolean on2edges = (absindex == 3);
165 Standard_Boolean hasONedge = (VP.State(OOShapeIndex) == TopAbs_ON);
166 Standard_Boolean hasOOedge = (on2edges) ? Standard_True : hasONedge;
168 TopoDS_Face Face = (*this).Face(ShapeIndex);
169 TopoDS_Face OOFace = (*this).Face(OOShapeIndex);
170 Standard_Integer iOOFace = myDS->Shape(OOFace);
171 if (iOOFace == 0) iOOFace = myDS->AddShape(OOFace,OOShapeIndex);
173 // current VPoint is on <edge>
175 Standard_Integer SIedgeIndex = 0;
177 const TopoDS_Edge& edge = TopoDS::Edge(VP.Edge(ShapeIndex));
178 if (!myDS->HasShape(edge)) myDS->AddShape(edge,ShapeIndex);
180 else SIedgeIndex = myDS->Shape(edge);
183 Standard_Real paredge = VP.EdgeParameter(ShapeIndex);
185 // dummy if !<hasOOedge>
186 Standard_Integer OOedgeIndex = 0;
190 if (on2edges) OOe = VP.Edge(OOShapeIndex);
191 else OOe = VP.EdgeON(OOShapeIndex);
192 OOedge = TopoDS::Edge(OOe);
193 if (myDS->HasShape(OOedge)) OOedgeIndex = myDS->Shape(OOedge);
194 else OOedgeIndex = myDS->AddShape(OOedge,OOShapeIndex);
198 Standard_Boolean traceDSF = TopOpeBRepDS_GettraceDSF();
199 Standard_Boolean trce = TopOpeBRepDS_GettraceSPSX(SIedgeIndex); if(trce) debarc(SIedgeIndex);
200 Standard_Boolean trcooe = TopOpeBRepDS_GettraceSPSX(OOedgeIndex); if(trcooe) debooarc(OOedgeIndex);
203 // ===================================================================
204 // --- Edge/(POINT,VERTEX) Interference (EPI) creation ---
205 // ===================================================================
207 // 1. <edge> enters or outers myF<OOShapeIndex> at <VP>,
208 // transition <transEdge> returned by IntPatch is valid (FORWARD/REVERSED).
209 // 2. <edge> is tangent to myF<OOShapeIndex> :
210 // transEdge should be INTERNAL/EXTERNAL.
212 Standard_Boolean Tunk = transEdge.IsUnknown();
214 if (!Tunk && traceDSF) cout<<"-> on closing : transAdd = "<<endl;
216 TopOpeBRepDS_Transition transAdd;
217 Standard_Boolean newtransEdge = Tunk;
218 if (newtransEdge) transAdd = GetEdgeTrans(VP,PVKind,PVIndex,ShapeIndex,OOFace);
219 else transAdd = transEdge;
221 // !!! if the compute of <transAdd> fails, we add transEdge.
222 // hasOOedge : <VP> is ON edge <edge> and ON <OOFace>
223 // !hasOOedge : <VP> is ON edge <edge> and IN <OOFace>
225 TopOpeBRepDS_Transition T = transAdd; T.Index(iOOFace);
226 Handle(TopOpeBRepDS_Interference) EPI = ::MakeEPVInterference
227 (T,iOOFace,PVIndex,paredge,PVKind,TopOpeBRepDS_FACE,isvertex);
228 myHDS->StoreInterference(EPI,edge);
231 TopOpeBRepDS_Transition T = transAdd; T.Index(iOOFace);
232 Handle(TopOpeBRepDS_Interference) EPI = ::MakeEPVInterference
233 (T,OOedgeIndex,PVIndex,paredge,PVKind,isvertex);
234 myHDS->StoreInterference(EPI,edge);
237 } // ProcessVPonclosingR