0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / TopOpeBRepDS / TopOpeBRepDS_connex.cxx
CommitLineData
b311480e 1// Created on: 1997-11-25
2// Created by: Jean Yves LEBEY
3// Copyright (c) 1997-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 <TopOpeBRepDS_connex.hxx>
18
19#include <TopExp_Explorer.hxx>
20#include <TopoDS.hxx>
21
22static TopTools_DataMapOfShapeListOfShape *GLOBAL_elf1 = NULL; // NYI to CDLize as a tool of DS
23static TopTools_DataMapOfShapeListOfShape *GLOBAL_elf2 = NULL; // NYI to CDLize as a tool of DS
24static TopTools_DataMapOfShapeListOfShape *GLOBAL_fle = NULL; // NYI to CDLize as a tool of DS
25static TopTools_ListOfShape *GLOBAL_los = NULL; // NYI to CDLize as a tool of DS
26static Standard_Boolean GLOBAL_FDSCNX_prepared = Standard_False;
27
28//modified by NIZNHY-PKV Sun Dec 15 17:41:43 2002 f
29//=======================================================================
30//function : FDSCNX_Close
c48e2889 31//purpose :
7fd59977 32//=======================================================================
1d0a9d4d 33void FDSCNX_Close()
7fd59977 34{
35 if (GLOBAL_elf1) {
36 delete GLOBAL_elf1;
37 GLOBAL_elf1=NULL;
38 }
39 //
40 if (GLOBAL_elf2) {
41 delete GLOBAL_elf2;
42 GLOBAL_elf2=NULL;
43 }
44 //
45 if (GLOBAL_fle) {
46 delete GLOBAL_fle;
47 GLOBAL_fle=NULL;
48 }
49 //
50 if (GLOBAL_los) {
51 delete GLOBAL_los;
52 GLOBAL_los=NULL;
53 }
54 //
55 GLOBAL_FDSCNX_prepared = Standard_False;
56}
57//modified by NIZNHY-PKV Sun Dec 15 17:41:40 2002 t
58
c48e2889 59Standard_EXPORT const TopTools_ListOfShape& FDSCNX_EdgeConnexityShapeIndex(const TopoDS_Shape& E,const Handle(TopOpeBRepDS_HDataStructure)& HDS,const Standard_Integer SI)
7fd59977 60{
61 if (HDS.IsNull()) return *GLOBAL_los;
62 if (!GLOBAL_FDSCNX_prepared) return *GLOBAL_los;
63 if (SI != 1 && SI != 2) return *GLOBAL_los;
64 const TopOpeBRepDS_DataStructure& BDS = HDS->DS();
65 TopAbs_ShapeEnum t = E.ShapeType(); if (t != TopAbs_EDGE) return *GLOBAL_los;
66 Standard_Boolean has = FDSCNX_HasConnexFace(E,HDS); if (!has) return *GLOBAL_los;
67 Standard_Integer re = BDS.AncestorRank(E); if (re == 0) return *GLOBAL_los;
68 TopTools_DataMapOfShapeListOfShape* pelf = (SI == 1) ? GLOBAL_elf1 : GLOBAL_elf2;
69 TopTools_DataMapOfShapeListOfShape& elf = *pelf;
70 const TopTools_ListOfShape& lof = elf.Find(E);
71 return lof;
72}
73
74// S = edge --> liste de faces connexes par S
75// S = face --> liste d'edges E de S qui ont au moins une autre face connexe
c48e2889 76Standard_EXPORT const TopTools_ListOfShape& FDSCNX_EdgeConnexitySameShape(const TopoDS_Shape& S,const Handle(TopOpeBRepDS_HDataStructure)& HDS)
7fd59977 77{
78 TopAbs_ShapeEnum t = S.ShapeType();
79 if (t == TopAbs_EDGE) {
80 Standard_Integer si = HDS->DS().AncestorRank(S);
81 const TopTools_ListOfShape& lf = FDSCNX_EdgeConnexityShapeIndex(S,HDS,si);
82 return lf;
83 }
84 else if (t == TopAbs_FACE) {
85 TopTools_DataMapOfShapeListOfShape& fle = *GLOBAL_fle;
86 if (fle.IsBound(S)) {
87 const TopTools_ListOfShape& le = fle.Find(S);
88 return le;
89 }
90 }
91 return *GLOBAL_los;
92}
93
94Standard_EXPORT void FDSCNX_Prepare(const TopoDS_Shape& /*S1*/,
95 const TopoDS_Shape& /*S2*/,
96 const Handle(TopOpeBRepDS_HDataStructure)& HDS)
97{
98 if (HDS.IsNull()) {
99 GLOBAL_FDSCNX_prepared = Standard_False;
100 return;
101 }
102 const TopOpeBRepDS_DataStructure& BDS = HDS->DS();
103 if (GLOBAL_elf1 == NULL) GLOBAL_elf1 = (TopTools_DataMapOfShapeListOfShape*) new TopTools_DataMapOfShapeListOfShape();
104 if (GLOBAL_elf2 == NULL) GLOBAL_elf2 = (TopTools_DataMapOfShapeListOfShape*) new TopTools_DataMapOfShapeListOfShape();
105 if (GLOBAL_fle == NULL) GLOBAL_fle = (TopTools_DataMapOfShapeListOfShape*) new TopTools_DataMapOfShapeListOfShape();
106 if (GLOBAL_los == NULL) GLOBAL_los = (TopTools_ListOfShape*) new TopTools_ListOfShape();
107 GLOBAL_elf1->Clear();
108 GLOBAL_elf2->Clear();
109 GLOBAL_fle->Clear();
110 GLOBAL_los->Clear();
111
112 Standard_Integer i=0,n=BDS.NbShapes();
113 for (i=1;i<=n;i++) {
114 const TopoDS_Shape& f = BDS.Shape(i); if (f.ShapeType() != TopAbs_FACE) continue;
115 Standard_Integer rf = BDS.AncestorRank(f); if (rf == 0) continue;
116// BDS.Shape(f);
117 TopTools_DataMapOfShapeListOfShape& fle = *GLOBAL_fle;
c48e2889 118 TopTools_DataMapOfShapeListOfShape& elf = (rf == 1) ? *GLOBAL_elf1 : *GLOBAL_elf2;
7fd59977 119 TopExp_Explorer exe;
120 for (exe.Init(f,TopAbs_EDGE);exe.More();exe.Next()) {
121// for (TopExp_Explorer exe(f,TopAbs_EDGE);exe.More();exe.Next()) {
122 const TopoDS_Shape& e = exe.Current();
123// BDS.Shape(e);
124// Standard_Boolean se = BDS.IsSectionEdge(TopoDS::Edge(e)); if (!se) continue;
125 Standard_Boolean hs = BDS.HasShape(TopoDS::Edge(e)); if (!hs) continue;
c48e2889 126
127 TopTools_ListOfShape* aListFle = fle.ChangeSeek (f);
128 if (aListFle == NULL)
129 {
130 aListFle = fle.Bound (f, TopTools_ListOfShape());
131 }
132 aListFle->Append(e);
133
134 TopTools_ListOfShape* aListElf = elf.ChangeSeek (e);
135 if (aListElf == NULL)
136 {
137 aListElf = elf.Bound (e, TopTools_ListOfShape());
138 }
139 aListElf->Append(f);
7fd59977 140 }
141 }
142 GLOBAL_FDSCNX_prepared = Standard_True;
143}
144
c48e2889 145Standard_EXPORT Standard_Boolean FDSCNX_HasConnexFace(const TopoDS_Shape& S,const Handle(TopOpeBRepDS_HDataStructure)& HDS)
7fd59977 146{
c48e2889 147 if (HDS.IsNull())
148 {
149 return Standard_False;
150 }
151
152 const TopOpeBRepDS_DataStructure& BDS = HDS->DS();
153 const TopAbs_ShapeEnum t = S.ShapeType();
154 if (t != TopAbs_FACE
155 && t != TopAbs_EDGE)
156 {
157 return Standard_False;
158 }
159 const Standard_Integer rs = BDS.AncestorRank(S);
160 if (rs == 0)
161 {
162 return Standard_False;
163 }
164
165 TopTools_DataMapOfShapeListOfShape* pelf = (rs == 1) ? GLOBAL_elf1 : GLOBAL_elf2;
166 if (pelf == NULL)
167 {
168 return Standard_False;
169 }
170
171 Standard_Boolean has = (t == TopAbs_EDGE ? pelf : GLOBAL_fle)->IsBound(S);
7fd59977 172 return has;
173}
174
c48e2889 175Standard_EXPORT void FDSCNX_FaceEdgeConnexFaces(const TopoDS_Shape& F,const TopoDS_Shape& E,const Handle(TopOpeBRepDS_HDataStructure)& HDS,TopTools_ListOfShape& LF)
7fd59977 176{
177 LF.Clear();
7fd59977 178 // verifier que E est une arete de connexite de F
179 Standard_Boolean EofF = Standard_False;
c48e2889 180 const TopTools_ListOfShape& loe = FDSCNX_EdgeConnexitySameShape(F,HDS);
181 if (loe.IsEmpty())
182 {
183 return;
184 }
185 for (TopTools_ListIteratorOfListOfShape i(loe);i.More();i.Next())
186 {
7fd59977 187 const TopoDS_Shape& e = i.Value();
188// HDS->Shape(e);
189 Standard_Boolean b = e.IsSame(E);
c48e2889 190 if (b)
191 {
7fd59977 192 EofF=Standard_True;
193 break;
194 }
195 }
c48e2889 196 if (!EofF)
197 {
198 return;
199 }
200
201 const TopTools_ListOfShape& lof = FDSCNX_EdgeConnexitySameShape(E,HDS);
202 if (lof.IsEmpty())
203 {
204 return;
205 }
206 for (TopTools_ListIteratorOfListOfShape it(lof);it.More();it.Next())
207 {
7fd59977 208 const TopoDS_Shape& f = it.Value();
7fd59977 209 Standard_Boolean b = f.IsSame(F);
c48e2889 210 if (!b)
211 {
7fd59977 212 LF.Append(f);
213 }
214 }
215}
216
217Standard_EXPORT void FDSCNX_DumpIndex(const Handle(TopOpeBRepDS_HDataStructure)& HDS,const Standard_Integer I)
218{
c48e2889 219 if (HDS.IsNull())
220 {
221 return;
222 }
223
224 const TopOpeBRepDS_DataStructure& BDS = HDS->DS();
7fd59977 225 Standard_Integer ns=BDS.NbShapes();
c48e2889 226 if (I<1 || I>ns)
227 {
228 return;
229 }
230
7fd59977 231 Standard_Integer i=I;
232 const TopoDS_Shape& s=BDS.Shape(i);
7fd59977 233 TopAbs_ShapeEnum ts=s.ShapeType();
234 const TopTools_ListOfShape& ls=FDSCNX_EdgeConnexitySameShape(s,HDS);
c48e2889 235 if (ts == TopAbs_EDGE)
236 {
237 TopTools_ListIteratorOfListOfShape ils(ls);
238 if (!ils.More())
239 {
240 return;
241 }
242
243 for (; ils.More(); ils.Next())
244 {
04232180 245 std::cout<<BDS.Shape(ils.Value())<<" ";
c48e2889 246 }
7fd59977 247 }
c48e2889 248 else if (ts == TopAbs_FACE)
249 {
250 TopTools_ListIteratorOfListOfShape ils(ls);
251 if (!ils.More())
252 {
253 return;
254 }
255
256 for (; ils.More(); ils.Next())
257 {
7fd59977 258 const TopoDS_Shape& e=ils.Value();
7fd59977 259 TopTools_ListOfShape lf;FDSCNX_FaceEdgeConnexFaces(s,e,HDS,lf);
c48e2889 260 TopTools_ListIteratorOfListOfShape ilf(lf);
261 if (!ilf.More())
262 {
263 continue;
264 }
265 for (; ilf.More(); ilf.Next())
266 {
04232180 267 std::cout<<BDS.Shape(ilf.Value())<<" ";
c48e2889 268 }
7fd59977 269 }
270 }
271}
272
273Standard_EXPORT void FDSCNX_Dump(const Handle(TopOpeBRepDS_HDataStructure)& HDS,const Standard_Integer I)
274{
c48e2889 275 if (HDS.IsNull())
276 {
277 return;
278 }
279
280 const TopOpeBRepDS_DataStructure& BDS = HDS->DS();
7fd59977 281 Standard_Integer ns=BDS.NbShapes();
c48e2889 282 if (I<1 || I>ns)
283 {
284 return;
285 }
286
7fd59977 287 Standard_Integer i=I;
288 const TopoDS_Shape& s=BDS.Shape(i);Standard_Integer is=BDS.Shape(s);TopAbs_ShapeEnum ts=s.ShapeType();
289 const TopTools_ListOfShape& ls=FDSCNX_EdgeConnexitySameShape(s,HDS);
c48e2889 290 if (ts == TopAbs_EDGE)
291 {
292 TopTools_ListIteratorOfListOfShape ils(ls);
293 if(!ils.More())
294 {
295 return;
296 }
297
04232180 298 std::cout<<"clear;";
c48e2889 299 for (; ils.More(); ils.Next())
300 {
04232180 301 std::cout<<"tsee f "<<BDS.Shape(ils.Value())<<";";
c48e2889 302 }
04232180 303 std::cout<<"tsee e "<<is<<";### edge "<<is<<" connexity"<<std::endl;
7fd59977 304 }
c48e2889 305 else if (ts == TopAbs_FACE)
306 {
307 TopTools_ListIteratorOfListOfShape ils(ls);
308 if (!ils.More())
309 {
310 return;
311 }
312 for(;ils.More();ils.Next())
313 {
7fd59977 314 const TopoDS_Shape& e=ils.Value();Standard_Integer ie=BDS.Shape(e);
7fd59977 315 TopTools_ListOfShape lf;FDSCNX_FaceEdgeConnexFaces(s,e,HDS,lf);
c48e2889 316 TopTools_ListIteratorOfListOfShape ilf(lf);
317 if (!ilf.More())
318 {
319 continue;
320 }
321
04232180 322 std::cout<<"clear;";std::cout<<"tsee f "<<is<<";";
c48e2889 323 for (;ilf.More(); ilf.Next())
324 {
04232180 325 std::cout<<"tsee f "<<BDS.Shape(ilf.Value())<<";";
c48e2889 326 }
04232180 327 std::cout<<"tsee e "<<ie<<";### face "<<is<<" connexity"<<std::endl;
7fd59977 328 }
329 }
330}
331
332Standard_EXPORT void FDSCNX_Dump(const Handle(TopOpeBRepDS_HDataStructure)& HDS)
333{
c48e2889 334 if (HDS.IsNull())
335 {
336 return;
337 }
338
339 const TopOpeBRepDS_DataStructure& BDS = HDS->DS();
340 Standard_Integer ns=BDS.NbShapes();
341 for (Standard_Integer i = 1;i<=ns;i++)
342 {
343 FDSCNX_Dump(HDS,i);
344 }
7fd59977 345}