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