1 // Created on: 1995-08-04
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1995-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.
22 #include <TopOpeBRep_FacesFiller.ixx>
24 #include <TopOpeBRepTool_ShapeTool.hxx>
25 #include <TopOpeBRepTool_EXPORT.hxx>
26 #include <TopOpeBRepTool_makeTransition.hxx>
28 #include <TopOpeBRepDS_PointIterator.hxx>
29 #include <TopOpeBRepDS_define.hxx>
30 #include <TopOpeBRepDS_repvg.hxx> // LOIinfsup
31 #include <TopOpeBRepDS_EXPORT.hxx>
33 #include <TopOpeBRep_define.hxx>
35 #include <Precision.hxx>
38 #include <BRep_Tool.hxx>
39 #include <BRepAdaptor_Curve.hxx>
43 #define M_ON(st) (st == TopAbs_ON)
44 #define M_REVERSED(st) (st == TopAbs_REVERSED)
47 Standard_EXPORT Standard_Boolean TopOpeBRepDS_GettraceDSF();
48 Standard_EXPORT Standard_Boolean TopOpeBRepDS_GettraceSPSX(const Standard_Integer i1);
49 Standard_EXPORT void debarc(const Standard_Integer i);
50 Standard_EXPORT void debooarc(const Standard_Integer i);
53 Standard_EXPORT Handle(TopOpeBRepDS_Interference) MakeEPVInterference
54 (const TopOpeBRepDS_Transition& T, // transition
55 const Standard_Integer S, // curve/edge index
56 const Standard_Integer G, // point/vertex index
57 const Standard_Real P, // parameter of G on S
58 const TopOpeBRepDS_Kind GK,
59 const Standard_Boolean B); // G is a vertex (or not) of the interference master
60 Standard_EXPORT Handle(TopOpeBRepDS_Interference) MakeEPVInterference
61 (const TopOpeBRepDS_Transition& T, // transition
62 const Standard_Integer S, // curve/edge index
63 const Standard_Integer G, // point/vertex index
64 const Standard_Real P, // parameter of G on S
65 const TopOpeBRepDS_Kind GK, // POINT/VERTEX
66 const TopOpeBRepDS_Kind SK,
67 const Standard_Boolean B); // G is a vertex (or not) of the interference master
70 static Standard_Boolean FUN_INlos(const TopoDS_Shape& S, const TopTools_ListOfShape& loS)
72 TopTools_ListIteratorOfListOfShape it(loS);
73 for (; it.More(); it.Next())
74 if (it.Value().IsSame(S)) return Standard_True;
75 return Standard_False;
78 //=======================================================================
79 //function : GetEdgeTrans
80 //purpose : Computes E<Sind> transition on <F> at point <VP>
81 // Computes FORWARD or REVERSED transitions,
82 // returns transition UNKNOWN elsewhere.
83 //=======================================================================
84 TopOpeBRepDS_Transition TopOpeBRep_FacesFiller::GetEdgeTrans(const TopOpeBRep_VPointInter& VP,const TopOpeBRepDS_Kind PVKind,
85 const Standard_Integer PVIndex,const Standard_Integer ShapeIndex,const TopoDS_Face& F)
87 // VP is on couture <Ec> of rank <sind>
88 // on face <F> of rank <oosind>.
89 Standard_Integer OOShapeIndex = (ShapeIndex == 1) ? 2 : 1;
90 Standard_Integer vpsind = VP.ShapeIndex();
91 Standard_Boolean on2edges = (vpsind == 3);
92 Standard_Boolean isvalid = on2edges || (vpsind == ShapeIndex);
93 if (!isvalid) Standard_Failure::Raise("TopOpeBRep_FacesFiller::GetEdgeTrans");
95 const TopoDS_Edge& edge = TopoDS::Edge(VP.Edge(ShapeIndex));
96 Standard_Real paredge = VP.EdgeParameter(ShapeIndex);
100 Standard_Real OOparedge;
102 Standard_Real OOparedge=0;
104 Standard_Boolean hasONedge = (VP.State(OOShapeIndex) == TopAbs_ON);
105 Standard_Boolean hasOOedge = (on2edges) ? Standard_True : hasONedge;
107 if (on2edges) OOparedge = VP.EdgeParameter(OOShapeIndex);
108 else OOparedge = VP.EdgeONParameter(OOShapeIndex);
110 if (on2edges) OOe = VP.Edge(OOShapeIndex);
111 else OOe = VP.EdgeON(OOShapeIndex);
112 OOedge = TopoDS::Edge(OOe);
114 gp_Pnt2d OOuv = VP.SurfaceParameters(OOShapeIndex);
116 Standard_Real par1,par2;
117 Standard_Integer SIedgeIndex = (myHDS->HasShape(edge)) ? myHDS->Shape(edge) : 0;
118 // if (SIedgeIndex != 0) FDS_getupperlower(myHDS,SIedgeIndex,paredge,par1,par2);
119 if (SIedgeIndex != 0) {
120 Standard_Boolean isonboundper;
121 FDS_LOIinfsup(myHDS->DS(),edge,paredge,PVKind,PVIndex,
122 myHDS->DS().ShapeInterferences(edge),par1,par2,isonboundper);
125 FUN_tool_bounds(edge,par1,par2);
127 TopOpeBRepDS_Transition T;
129 // <Tr> relative to 3d <OOface> matter,
130 // we take into account <Tr> / 2d <OOface> only if <edge> is normal to <OOface>
131 Standard_Real tola = Precision::Angular()*1.e+2; //dealing with tolerances
132 Standard_Boolean EtgF = FUN_tool_EtgF(paredge,edge,OOuv,F,tola);
133 Standard_Boolean rest = FUN_INlos(edge,myERL);
134 Standard_Boolean isse = myHDS->DS().IsSectionEdge(edge);
136 Standard_Boolean interf2d = EtgF && hasOOedge && rest;
138 Standard_Real factor = 1.e-4;
139 TopOpeBRepTool_makeTransition MKT;
140 Standard_Boolean ok = MKT.Initialize(edge,par1,par2,paredge, F,OOuv, factor);
142 Standard_Boolean isT2d = MKT.IsT2d();
143 interf2d = interf2d && isT2d;
144 if (interf2d) ok = MKT.SetRest(OOedge,OOparedge);
147 TopAbs_State stb,sta; ok = MKT.MkTonE(stb,sta);
149 T.Before(stb); T.After(sta);
153 //=======================================================================
154 //function : ProcessVPonclosingR
155 //purpose : SUPPLYING INTPATCH when <VP> is on closing arc.
156 //=======================================================================
157 void TopOpeBRep_FacesFiller::ProcessVPonclosingR(const TopOpeBRep_VPointInter& VP,
158 // const TopoDS_Shape& GFace,
159 const TopoDS_Shape& ,
160 const Standard_Integer ShapeIndex,
161 const TopOpeBRepDS_Transition& transEdge,const TopOpeBRepDS_Kind PVKind, const Standard_Integer PVIndex,
162 // const Standard_Boolean EPIfound,
163 const Standard_Boolean ,
164 // const Handle(TopOpeBRepDS_Interference)& IEPI)
165 const Handle(TopOpeBRepDS_Interference)& )
167 // Standard_Boolean isvertex = VP.IsVertex(ShapeIndex);
168 Standard_Boolean isvertex = (PVKind == TopOpeBRepDS_VERTEX);
169 Standard_Integer absindex = VP.ShapeIndex(); // 0,1,2,3
170 Standard_Boolean OOShapeIndex = (ShapeIndex == 1) ? 2 : 1;
171 Standard_Boolean on2edges = (absindex == 3);
172 Standard_Boolean hasONedge = (VP.State(OOShapeIndex) == TopAbs_ON);
173 Standard_Boolean hasOOedge = (on2edges) ? Standard_True : hasONedge;
175 TopoDS_Face Face = (*this).Face(ShapeIndex);
176 TopoDS_Face OOFace = (*this).Face(OOShapeIndex);
177 Standard_Integer iOOFace = myDS->Shape(OOFace);
178 if (iOOFace == 0) iOOFace = myDS->AddShape(OOFace,OOShapeIndex);
180 // current VPoint is on <edge>
181 Standard_Integer SIedgeIndex = 0;
182 const TopoDS_Edge& edge = TopoDS::Edge(VP.Edge(ShapeIndex));
183 if (myDS->HasShape(edge)) SIedgeIndex = myDS->Shape(edge);
184 else myDS->AddShape(edge,ShapeIndex);
186 Standard_Real paredge = VP.EdgeParameter(ShapeIndex);
188 // dummy if !<hasOOedge>
189 Standard_Integer OOedgeIndex = 0;
190 Standard_Boolean OOclosing,OOisrest; OOclosing = OOisrest = Standard_False;
194 if (on2edges) OOe = VP.Edge(OOShapeIndex);
195 else OOe = VP.EdgeON(OOShapeIndex);
196 OOedge = TopoDS::Edge(OOe);
197 OOisrest = myDS->IsSectionEdge(OOedge);
198 OOclosing = TopOpeBRepTool_ShapeTool::Closed(OOedge,OOFace);
199 if (myDS->HasShape(OOedge)) OOedgeIndex = myDS->Shape(OOedge);
200 else OOedgeIndex = myDS->AddShape(OOedge,OOShapeIndex);
204 Standard_Boolean traceDSF = TopOpeBRepDS_GettraceDSF();
205 Standard_Boolean trce = TopOpeBRepDS_GettraceSPSX(SIedgeIndex); if(trce) debarc(SIedgeIndex);
206 Standard_Boolean trcooe = TopOpeBRepDS_GettraceSPSX(OOedgeIndex); if(trcooe) debooarc(OOedgeIndex);
209 // ===================================================================
210 // --- Edge/(POINT,VERTEX) Interference (EPI) creation ---
211 // ===================================================================
213 // 1. <edge> enters or outers myF<OOShapeIndex> at <VP>,
214 // transition <transEdge> returned by IntPatch is valid (FORWARD/REVERSED).
215 // 2. <edge> is tangent to myF<OOShapeIndex> :
216 // transEdge should be INTERNAL/EXTERNAL.
218 Standard_Boolean Tunk = transEdge.IsUnknown();
220 if (!Tunk && traceDSF) cout<<"-> on closing : transAdd = "<<endl;
222 TopOpeBRepDS_Transition transAdd;
223 Standard_Boolean newtransEdge = Tunk;
224 if (newtransEdge) transAdd = GetEdgeTrans(VP,PVKind,PVIndex,ShapeIndex,OOFace);
225 else transAdd = transEdge;
227 // !!! if the compute of <transAdd> fails, we add transEdge.
228 // hasOOedge : <VP> is ON edge <edge> and ON <OOFace>
229 // !hasOOedge : <VP> is ON edge <edge> and IN <OOFace>
231 TopOpeBRepDS_Transition T = transAdd; T.Index(iOOFace);
232 Handle(TopOpeBRepDS_Interference) EPI = ::MakeEPVInterference
233 (T,iOOFace,PVIndex,paredge,PVKind,TopOpeBRepDS_FACE,isvertex);
234 myHDS->StoreInterference(EPI,edge);
237 TopOpeBRepDS_Transition T = transAdd; T.Index(iOOFace);
238 Handle(TopOpeBRepDS_Interference) EPI = ::MakeEPVInterference
239 (T,OOedgeIndex,PVIndex,paredge,PVKind,isvertex);
240 myHDS->StoreInterference(EPI,edge);
243 } // ProcessVPonclosingR