Integration of OCCT 6.5.0 from SVN
[occt.git] / src / TopOpeBRepDS / TopOpeBRepDS_TOOL.cxx
CommitLineData
7fd59977 1// File: TopOpeBRepDS_TOOL.cxx
2// Created: Mon Jan 25 14:33:44 1999
3// Author: Xuan PHAM PHU
4// <xpu@poulopox.paris1.matra-dtv.fr>
5
6
7#include <TopoDS.hxx>
8#include <TopExp_Explorer.hxx>
9#include <BRep_Tool.hxx>
10#include <TopOpeBRepTool_EXPORT.hxx>
11#include <TopOpeBRepTool_TOOL.hxx>
12#include <TopOpeBRepDS.hxx>
13#include <TopOpeBRepDS_TOOL.ixx>
14#include <TopOpeBRepDS_define.hxx>
15#include <TopOpeBRepDS_ProcessInterferencesTool.hxx>
16#include <TopOpeBRepDS_ListOfShapeOn1State.hxx>
17#include <TopOpeBRepDS_DataMapOfShapeListOfShapeOn1State.hxx>
18
19static void FUN_Raise()
20{
21#ifdef DEB
22 cout<<"****************************** TopOpeBRepDS_TOOL"<<endl;
23#endif
24}
25
26#define M_REVERSED(O) (O == TopAbs_REVERSED)
27
28static void FDS_sortGb(const Handle(TopOpeBRepDS_HDataStructure)& HDS,const TopOpeBRepDS_ListOfInterference& LI, TopOpeBRepDS_ListOfInterference& LIGb0,TopOpeBRepDS_ListOfInterference& LIGb1,TopOpeBRepDS_ListOfInterference& LIGbsd)
29{
30 const TopOpeBRepDS_DataStructure& BDS = HDS->DS();
31 LIGb0.Clear(); LIGb1.Clear(); LIGbsd.Clear();
32 TopOpeBRepDS_ListIteratorOfListOfInterference it(LI);
33 for (; it.More(); it.Next()){
34 const Handle(TopOpeBRepDS_Interference)& I = it.Value();
35 Handle(TopOpeBRepDS_ShapeShapeInterference) SSI = Handle(TopOpeBRepDS_ShapeShapeInterference)::DownCast(I);
36 if (SSI.IsNull()) {LIGb0.Append(I);continue;}
37
38 Standard_Boolean gb1 = SSI->GBound();
39 Standard_Integer G = I->Geometry();
40 Standard_Boolean hsd = HDS->HasSameDomain(BDS.Shape(G));
41 if (hsd) {LIGbsd.Append(I);continue;}
42
43 if (gb1) LIGb1.Append(I);
44 else LIGb0.Append(I);
45 }//it(LI)
46}
47
48//=======================================================================
49//function : EShareG
50//purpose :
51//=======================================================================
52
53#define FORWARD (1)
54#define REVERSED (2)
55#define INTERNAL (3)
56#define EXTERNAL (4)
57#define CLOSING (5)
58Standard_Integer TopOpeBRepDS_TOOL::EShareG(const Handle(TopOpeBRepDS_HDataStructure)& HDS,const TopoDS_Edge& E,TopTools_ListOfShape& lEsd)
59{
60 lEsd.Clear();
61 Standard_Boolean dgE = BRep_Tool::Degenerated(E);
62 if (dgE) {
63 Standard_Boolean hsd = HDS->HasSameDomain(E);
64 if (!hsd) return 0;
65 TopTools_ListIteratorOfListOfShape itsd(HDS->SameDomain(E));
66 for (; itsd.More(); itsd.Next()) lEsd.Append(itsd.Value());
67 return lEsd.Extent();
68 }
69
70 const TopOpeBRepDS_DataStructure& BDS = HDS->DS();
71 const TopOpeBRepDS_ListOfInterference& LI = BDS.ShapeInterferences(E);
72 TopOpeBRepDS_ListOfInterference LII; FDS_copy(LI,LII);
73 TopOpeBRepDS_ListOfInterference L1d; Standard_Integer n1d = FUN_selectTRASHAinterference(LII,TopAbs_EDGE,L1d);
74 if (n1d == 0) return 0;
75
76 TopTools_MapOfShape mapesd;
77 TopOpeBRepDS_ListOfInterference l1gb0,l1gb1,l1gbsd; FDS_sortGb(HDS,L1d,l1gb0,l1gb1,l1gbsd);
78#ifdef DEB
79// Standard_Integer ngb0 = l1gb0.Extent();
80// Standard_Integer ngb1 = l1gb1.Extent();
81// Standard_Integer ngbsd = l1gbsd.Extent();
82#endif
83
84 TopOpeBRepDS_ListIteratorOfListOfInterference it0(l1gb0);
85 for (; it0.More(); it0.Next()) mapesd.Add(BDS.Shape(it0.Value()->Support()));
86
87 TopOpeBRepDS_ListIteratorOfListOfInterference it1(l1gb1);
88 for (; it1.More(); it1.Next()) mapesd.Add(BDS.Shape(it1.Value()->Support()));
89
90 TopOpeBRepDS_ListIteratorOfListOfInterference itsd(l1gbsd);
91 for (; itsd.More(); itsd.Next()) {
92 const Handle(TopOpeBRepDS_Interference)& I = itsd.Value();
93 const TopoDS_Edge& Esd = TopoDS::Edge(BDS.Shape(I->Support()));
94 Standard_Boolean isb = mapesd.Contains(Esd);
95 if (isb) continue;
96
97 Standard_Integer G = I->Geometry();
98 const TopoDS_Vertex& vG = TopoDS::Vertex(BDS.Shape(G));
99 TopoDS_Vertex vsd; Standard_Boolean ok = FUN_ds_getoov(vG,BDS,vsd);
100 if (!ok) {FUN_Raise(); continue;}
101 Standard_Boolean Gb1 = Handle(TopOpeBRepDS_ShapeShapeInterference)::DownCast(I)->GBound();
102 TopoDS_Vertex vE = Gb1 ? vG : vsd;
103 TopoDS_Vertex vEsd = Gb1 ? vsd : vG;
104
105 Standard_Integer ovE; gp_Vec tgE;
106 ok = TopOpeBRepTool_TOOL::TgINSIDE(vE,E,tgE,ovE);
107 if (!ok) continue;
108 Standard_Integer ovEsd; gp_Vec tgEsd;
109 ok = TopOpeBRepTool_TOOL::TgINSIDE(vEsd,Esd,tgEsd,ovEsd);
110 if (!ok) continue;
111 Standard_Boolean inE = (ovE == CLOSING)||(ovE == INTERNAL);
112 Standard_Boolean inEsd = (ovEsd == CLOSING)||(ovEsd == INTERNAL);
113 if (inE || inEsd) {mapesd.Add(Esd); continue;}
114 Standard_Real dot = gp_Dir(tgE).Dot(gp_Dir(tgEsd));
115 if (dot > 0.) mapesd.Add(Esd);
116 }
117 TopTools_MapIteratorOfMapOfShape itm(mapesd);
118 for (; itm.More(); itm.Next()) lEsd.Append(itm.Key());
119 return (lEsd.Extent());
120}
121
122
123
124//=======================================================================
125//function : ShareG
126//purpose :
127//=======================================================================
128
129Standard_Boolean TopOpeBRepDS_TOOL::ShareG(const Handle(TopOpeBRepDS_HDataStructure)& HDS, const Standard_Integer i1, const Standard_Integer i2)
130{
131 const TopoDS_Shape& s1 = HDS->Shape(i1);
132 const TopoDS_Shape& s2 = HDS->Shape(i2);
133
134 Standard_Boolean hsd1 = HDS->HasSameDomain(s1);
135 if (!hsd1) return Standard_False;
136 TopTools_ListIteratorOfListOfShape it1(HDS->SameDomain(s1));
137 for (; it1.More(); it1.Next()){
138 Standard_Boolean same = it1.Value().IsSame(s2);
139 if (!same) continue;
140 return Standard_True;
141 }
142 return Standard_False;
143}
144
145
146
147//=======================================================================
148//function : GetEsd
149//purpose :
150//=======================================================================
151
152Standard_Boolean TopOpeBRepDS_TOOL::GetEsd(const Handle(TopOpeBRepDS_HDataStructure)& HDS,
153 const TopoDS_Shape& S, const Standard_Integer ie, Standard_Integer& iesd)
154{
155 // recall : method ::SameDomain(s) returns an iterator on the list of shapes
156 // sdm to s (ie actually sharing geometric domain with s)
157 iesd = 0;
158 TopTools_MapOfShape mesdS;
159 TopExp_Explorer ex(S, TopAbs_EDGE);
160 for (; ex.More(); ex.Next()){
161 const TopoDS_Shape& e = ex.Current();
162 Standard_Boolean hs = HDS->HasShape(e);
163 if (!hs) continue;
164 Standard_Boolean hsd = HDS->HasSameDomain(e);
165 if (!hsd) continue;
166 mesdS.Add(e);
167// TopTools_ListIteratorOfListOfShape itt(HDS->SameDomain(e));
168// for (; itt.More(); itt.Next()) mesdS.Add(itt.Value());
169 }
170
171 TopTools_ListIteratorOfListOfShape it(HDS->SameDomain(HDS->Shape(ie)));
172 for (; it.More(); it.Next()){
173 const TopoDS_Shape& esd = it.Value();
174 Standard_Boolean isb = mesdS.Contains(esd);
175 if (!isb) continue;
176 iesd = HDS->Shape(esd);
177 return Standard_True;
178 }
179 return Standard_False;
180}
181
182//=======================================================================
183//function : ShareSplitON
184//purpose :
185//=======================================================================
186
187Standard_Boolean TopOpeBRepDS_TOOL::ShareSplitON(const Handle(TopOpeBRepDS_HDataStructure)& HDS,
188 const TopOpeBRepDS_DataMapOfShapeListOfShapeOn1State& MEspON,
189 const Standard_Integer i1, const Standard_Integer i2, TopoDS_Shape& spON)
190{
191 spON.Nullify();
192 Standard_Boolean shareg = TopOpeBRepDS_TOOL::ShareG(HDS,i1,i2);
193 if (!shareg) return Standard_False;
194
195 const TopoDS_Shape& s1 = HDS->Shape(i1);
196 const TopoDS_Shape& s2 = HDS->Shape(i2);
197
198 const TopOpeBRepDS_ListOfShapeOn1State& los1 = MEspON.Find(s1);
199 Standard_Boolean issp = los1.IsSplit();
200 if (!issp) return Standard_False;
201 const TopTools_ListOfShape& lsp1 = los1.ListOnState();
202 Standard_Integer nsp1 = lsp1.Extent();
203 if (nsp1 == 0) return Standard_False;
204 TopTools_MapOfShape mesp1; // map of splits on of <s1>
205 TopTools_ListIteratorOfListOfShape it(lsp1);
206 for (; it.More(); it.Next()) mesp1.Add(it.Value());
207
208 const TopOpeBRepDS_ListOfShapeOn1State& los2 = MEspON.Find(s2);
209 Standard_Boolean issp2 = los2.IsSplit();
210 if (!issp2) return Standard_False;
211 const TopTools_ListOfShape& lsp2 = los2.ListOnState();
212 Standard_Integer nsp2 = lsp2.Extent();
213 if (nsp2 == 0) return Standard_False;
214
215 it.Initialize(lsp2);
216 for (; it.More(); it.Next()) {
217 const TopoDS_Shape& esp = it.Value();
218 Standard_Boolean isb = mesp1.Contains(esp);
219 if (!isb) continue;
220 spON = esp; return Standard_True;
221 }
222 return Standard_False;
223}
224
225
226
227//=======================================================================
228//function : GetConfig
229//purpose : returns relative geometric config
230//=======================================================================
231#define SAMEORIENTED (1)
232#define DIFFORIENTED (2)
233Standard_Boolean TopOpeBRepDS_TOOL::GetConfig(const Handle(TopOpeBRepDS_HDataStructure)& HDS,
234 const TopOpeBRepDS_DataMapOfShapeListOfShapeOn1State& MEspON,
235 const Standard_Integer ie,const Standard_Integer iesd,
236 Standard_Integer& config)
237{
238 config = 0;
239 Standard_Boolean shareg = TopOpeBRepDS_TOOL::ShareG(HDS,ie,iesd);
240 if (!shareg) return Standard_False;
241
242 const TopoDS_Edge& e = TopoDS::Edge(HDS->Shape(ie)); TopAbs_Orientation oe = e.Orientation();
243 const TopoDS_Edge& esd = TopoDS::Edge(HDS->Shape(iesd)); TopAbs_Orientation oesd = esd.Orientation();
244 TopOpeBRepDS_Config conf = HDS->SameDomainOrientation(e); Standard_Boolean unsh = (conf == TopOpeBRepDS_UNSHGEOMETRY);
245 TopOpeBRepDS_Config confsd = HDS->SameDomainOrientation(esd); Standard_Boolean unshsd = (confsd == TopOpeBRepDS_UNSHGEOMETRY);
246 if (!unsh && !unshsd) {
247 Standard_Boolean sameori = (conf == confsd);
248 if (M_REVERSED(oe)) sameori = !sameori;
249 if (M_REVERSED(oesd)) sameori = !sameori;
250 config = sameori ? SAMEORIENTED : DIFFORIENTED;
251 return Standard_True;
252 }
253
254 TopoDS_Shape eON; shareg = TopOpeBRepDS_TOOL::ShareSplitON(HDS,MEspON,ie,iesd,eON);
255 if (!shareg) return Standard_False;
256
257 Standard_Real f,l; FUN_tool_bounds(TopoDS::Edge(eON),f,l);
258 Standard_Real x = 0.45678; Standard_Real parON = (1-x)*f+x*l;
259 Standard_Real tole = BRep_Tool::Tolerance(TopoDS::Edge(e));
260 Standard_Real pare; Standard_Boolean ok = FUN_tool_parE(TopoDS::Edge(eON),parON, e,pare, tole);
261 if (!ok) return Standard_False;
262 Standard_Real tolesd = BRep_Tool::Tolerance(TopoDS::Edge(esd));
263 Standard_Real paresd; ok = FUN_tool_parE(TopoDS::Edge(eON),parON, esd,paresd, tolesd);
264 if (!ok) return Standard_False;
265 Standard_Boolean so; ok = FUN_tool_curvesSO(e,pare,esd,paresd,so);
266 if (!ok) return Standard_False;
267 config = (so)? SAMEORIENTED : DIFFORIENTED;
268 return Standard_True;
269}
270