1 // Created on: 1997-11-25
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1997-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 under
9 // the terms of the GNU Lesser General Public License 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 <TopOpeBRepDS_connex.hxx>
19 #include <TopExp_Explorer.hxx>
22 static TopTools_DataMapOfShapeListOfShape *GLOBAL_elf1 = NULL; // NYI to CDLize as a tool of DS
23 static TopTools_DataMapOfShapeListOfShape *GLOBAL_elf2 = NULL; // NYI to CDLize as a tool of DS
24 static TopTools_DataMapOfShapeListOfShape *GLOBAL_fle = NULL; // NYI to CDLize as a tool of DS
25 static TopTools_ListOfShape *GLOBAL_los = NULL; // NYI to CDLize as a tool of DS
26 static Standard_Boolean GLOBAL_FDSCNX_prepared = Standard_False;
28 //modified by NIZNHY-PKV Sun Dec 15 17:41:43 2002 f
29 //=======================================================================
30 //function : FDSCNX_Close
32 //=======================================================================
55 GLOBAL_FDSCNX_prepared = Standard_False;
57 //modified by NIZNHY-PKV Sun Dec 15 17:41:40 2002 t
59 Standard_EXPORT const TopTools_ListOfShape& FDSCNX_EdgeConnexityShapeIndex(const TopoDS_Shape& E,const Handle(TopOpeBRepDS_HDataStructure)& HDS,const Standard_Integer SI)
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);
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
76 Standard_EXPORT const TopTools_ListOfShape& FDSCNX_EdgeConnexitySameShape(const TopoDS_Shape& S,const Handle(TopOpeBRepDS_HDataStructure)& HDS)
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);
84 else if (t == TopAbs_FACE) {
85 TopTools_DataMapOfShapeListOfShape& fle = *GLOBAL_fle;
87 const TopTools_ListOfShape& le = fle.Find(S);
94 Standard_EXPORT void FDSCNX_Prepare(const TopoDS_Shape& /*S1*/,
95 const TopoDS_Shape& /*S2*/,
96 const Handle(TopOpeBRepDS_HDataStructure)& HDS)
99 GLOBAL_FDSCNX_prepared = Standard_False;
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();
112 Standard_Integer i=0,n=BDS.NbShapes();
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;
117 TopTools_DataMapOfShapeListOfShape& fle = *GLOBAL_fle;
118 TopTools_DataMapOfShapeListOfShape& elf = (rf == 1) ? *GLOBAL_elf1 : *GLOBAL_elf2;
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();
124 // Standard_Boolean se = BDS.IsSectionEdge(TopoDS::Edge(e)); if (!se) continue;
125 Standard_Boolean hs = BDS.HasShape(TopoDS::Edge(e)); if (!hs) continue;
127 TopTools_ListOfShape* aListFle = fle.ChangeSeek (f);
128 if (aListFle == NULL)
130 aListFle = fle.Bound (f, TopTools_ListOfShape());
134 TopTools_ListOfShape* aListElf = elf.ChangeSeek (e);
135 if (aListElf == NULL)
137 aListElf = elf.Bound (e, TopTools_ListOfShape());
142 GLOBAL_FDSCNX_prepared = Standard_True;
145 Standard_EXPORT Standard_Boolean FDSCNX_HasConnexFace(const TopoDS_Shape& S,const Handle(TopOpeBRepDS_HDataStructure)& HDS)
149 return Standard_False;
152 const TopOpeBRepDS_DataStructure& BDS = HDS->DS();
153 const TopAbs_ShapeEnum t = S.ShapeType();
157 return Standard_False;
159 const Standard_Integer rs = BDS.AncestorRank(S);
162 return Standard_False;
165 TopTools_DataMapOfShapeListOfShape* pelf = (rs == 1) ? GLOBAL_elf1 : GLOBAL_elf2;
168 return Standard_False;
171 Standard_Boolean has = (t == TopAbs_EDGE ? pelf : GLOBAL_fle)->IsBound(S);
175 Standard_EXPORT void FDSCNX_FaceEdgeConnexFaces(const TopoDS_Shape& F,const TopoDS_Shape& E,const Handle(TopOpeBRepDS_HDataStructure)& HDS,TopTools_ListOfShape& LF)
178 // verifier que E est une arete de connexite de F
179 Standard_Boolean EofF = Standard_False;
180 const TopTools_ListOfShape& loe = FDSCNX_EdgeConnexitySameShape(F,HDS);
185 for (TopTools_ListIteratorOfListOfShape i(loe);i.More();i.Next())
187 const TopoDS_Shape& e = i.Value();
189 Standard_Boolean b = e.IsSame(E);
201 const TopTools_ListOfShape& lof = FDSCNX_EdgeConnexitySameShape(E,HDS);
206 for (TopTools_ListIteratorOfListOfShape it(lof);it.More();it.Next())
208 const TopoDS_Shape& f = it.Value();
209 Standard_Boolean b = f.IsSame(F);
217 Standard_EXPORT void FDSCNX_DumpIndex(const Handle(TopOpeBRepDS_HDataStructure)& HDS,const Standard_Integer I)
224 const TopOpeBRepDS_DataStructure& BDS = HDS->DS();
225 Standard_Integer ns=BDS.NbShapes();
231 Standard_Integer i=I;
232 const TopoDS_Shape& s=BDS.Shape(i);
233 TopAbs_ShapeEnum ts=s.ShapeType();
234 const TopTools_ListOfShape& ls=FDSCNX_EdgeConnexitySameShape(s,HDS);
235 if (ts == TopAbs_EDGE)
237 TopTools_ListIteratorOfListOfShape ils(ls);
243 for (; ils.More(); ils.Next())
245 std::cout<<BDS.Shape(ils.Value())<<" ";
248 else if (ts == TopAbs_FACE)
250 TopTools_ListIteratorOfListOfShape ils(ls);
256 for (; ils.More(); ils.Next())
258 const TopoDS_Shape& e=ils.Value();
259 TopTools_ListOfShape lf;FDSCNX_FaceEdgeConnexFaces(s,e,HDS,lf);
260 TopTools_ListIteratorOfListOfShape ilf(lf);
265 for (; ilf.More(); ilf.Next())
267 std::cout<<BDS.Shape(ilf.Value())<<" ";
273 Standard_EXPORT void FDSCNX_Dump(const Handle(TopOpeBRepDS_HDataStructure)& HDS,const Standard_Integer I)
280 const TopOpeBRepDS_DataStructure& BDS = HDS->DS();
281 Standard_Integer ns=BDS.NbShapes();
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);
290 if (ts == TopAbs_EDGE)
292 TopTools_ListIteratorOfListOfShape ils(ls);
299 for (; ils.More(); ils.Next())
301 std::cout<<"tsee f "<<BDS.Shape(ils.Value())<<";";
303 std::cout<<"tsee e "<<is<<";### edge "<<is<<" connexity"<<std::endl;
305 else if (ts == TopAbs_FACE)
307 TopTools_ListIteratorOfListOfShape ils(ls);
312 for(;ils.More();ils.Next())
314 const TopoDS_Shape& e=ils.Value();Standard_Integer ie=BDS.Shape(e);
315 TopTools_ListOfShape lf;FDSCNX_FaceEdgeConnexFaces(s,e,HDS,lf);
316 TopTools_ListIteratorOfListOfShape ilf(lf);
322 std::cout<<"clear;";std::cout<<"tsee f "<<is<<";";
323 for (;ilf.More(); ilf.Next())
325 std::cout<<"tsee f "<<BDS.Shape(ilf.Value())<<";";
327 std::cout<<"tsee e "<<ie<<";### face "<<is<<" connexity"<<std::endl;
332 Standard_EXPORT void FDSCNX_Dump(const Handle(TopOpeBRepDS_HDataStructure)& HDS)
339 const TopOpeBRepDS_DataStructure& BDS = HDS->DS();
340 Standard_Integer ns=BDS.NbShapes();
341 for (Standard_Integer i = 1;i<=ns;i++)