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;
126 TopTools_ListOfShape thelist, thelist1;
127 if (!fle.IsBound(f)) fle.Bind(f, thelist); fle.ChangeFind(f).Append(e);
128 if (!elf.IsBound(e)) elf.Bind(e, thelist1); elf.ChangeFind(e).Append(f);
131 GLOBAL_FDSCNX_prepared = Standard_True;
134 Standard_EXPORT Standard_Boolean FDSCNX_HasConnexFace(const TopoDS_Shape& S,const Handle(TopOpeBRepDS_HDataStructure)& HDS)
136 if (HDS.IsNull()) return Standard_False; const TopOpeBRepDS_DataStructure& BDS = HDS->DS();
137 const TopAbs_ShapeEnum t = S.ShapeType(); if (t != TopAbs_FACE && t != TopAbs_EDGE) return Standard_False;
138 const Standard_Integer rs = BDS.AncestorRank(S); if (rs == 0) return Standard_False;
139 TopTools_DataMapOfShapeListOfShape* pelf = (rs == 1) ? GLOBAL_elf1 : GLOBAL_elf2; if (pelf == NULL) return Standard_False;
140 TopTools_DataMapOfShapeListOfShape& fle = *GLOBAL_fle;
141 TopTools_DataMapOfShapeListOfShape& elf = *pelf;
142 Standard_Boolean has = Standard_False;
143 if (t == TopAbs_EDGE) has = elf.IsBound(S);
144 else if (t == TopAbs_FACE) has = fle.IsBound(S);
148 Standard_EXPORT void FDSCNX_FaceEdgeConnexFaces(const TopoDS_Shape& F,const TopoDS_Shape& E,const Handle(TopOpeBRepDS_HDataStructure)& HDS,TopTools_ListOfShape& LF)
152 // Standard_Integer Fi =
156 // Standard_Integer Ei =
160 // verifier que E est une arete de connexite de F
161 Standard_Boolean EofF = Standard_False;
162 const TopTools_ListOfShape& loe = FDSCNX_EdgeConnexitySameShape(F,HDS); if (loe.IsEmpty()) return;
163 for (TopTools_ListIteratorOfListOfShape i(loe);i.More();i.Next()) {
164 const TopoDS_Shape& e = i.Value();
166 Standard_Boolean b = e.IsSame(E);
174 const TopTools_ListOfShape& lof = FDSCNX_EdgeConnexitySameShape(E,HDS); if (lof.IsEmpty()) return;
175 for (TopTools_ListIteratorOfListOfShape it(lof);it.More();it.Next()) {
176 const TopoDS_Shape& f = it.Value();
178 // Standard_Integer fi =
181 Standard_Boolean b = f.IsSame(F);
188 Standard_EXPORT void FDSCNX_DumpIndex(const Handle(TopOpeBRepDS_HDataStructure)& HDS,const Standard_Integer I)
190 if (HDS.IsNull()) return; const TopOpeBRepDS_DataStructure& BDS = HDS->DS();
191 Standard_Integer ns=BDS.NbShapes();
192 if (I<1 || I>ns) return;
193 Standard_Integer i=I;
194 const TopoDS_Shape& s=BDS.Shape(i);
196 // Standard_Integer is=
199 TopAbs_ShapeEnum ts=s.ShapeType();
200 const TopTools_ListOfShape& ls=FDSCNX_EdgeConnexitySameShape(s,HDS);
201 if (ts == TopAbs_EDGE) {
202 TopTools_ListIteratorOfListOfShape ils(ls);if(!ils.More())return;
203 for(;ils.More();ils.Next())cout<<BDS.Shape(ils.Value())<<" ";
205 else if (ts == TopAbs_FACE) {
206 TopTools_ListIteratorOfListOfShape ils(ls);if(!ils.More())return;
207 for(;ils.More();ils.Next()) {
208 const TopoDS_Shape& e=ils.Value();
210 // Standard_Integer ie=BDS.Shape(e);
211 // TopAbs_ShapeEnum te=e.ShapeType();
213 TopTools_ListOfShape lf;FDSCNX_FaceEdgeConnexFaces(s,e,HDS,lf);
214 TopTools_ListIteratorOfListOfShape ilf(lf);if(!ilf.More())continue;
215 for(;ilf.More();ilf.Next())cout<<BDS.Shape(ilf.Value())<<" ";
220 Standard_EXPORT void FDSCNX_Dump(const Handle(TopOpeBRepDS_HDataStructure)& HDS,const Standard_Integer I)
222 if (HDS.IsNull()) return; const TopOpeBRepDS_DataStructure& BDS = HDS->DS();
223 Standard_Integer ns=BDS.NbShapes();
224 if (I<1 || I>ns) return;
225 Standard_Integer i=I;
226 const TopoDS_Shape& s=BDS.Shape(i);Standard_Integer is=BDS.Shape(s);TopAbs_ShapeEnum ts=s.ShapeType();
227 const TopTools_ListOfShape& ls=FDSCNX_EdgeConnexitySameShape(s,HDS);
228 if (ts == TopAbs_EDGE) {
229 TopTools_ListIteratorOfListOfShape ils(ls);if(!ils.More())return;
231 for(;ils.More();ils.Next())cout<<"tsee f "<<BDS.Shape(ils.Value())<<";";
232 cout<<"tsee e "<<is<<";### edge "<<is<<" connexity"<<endl;
234 else if (ts == TopAbs_FACE) {
235 TopTools_ListIteratorOfListOfShape ils(ls);if(!ils.More())return;
236 for(;ils.More();ils.Next()) {
237 const TopoDS_Shape& e=ils.Value();Standard_Integer ie=BDS.Shape(e);
239 // TopAbs_ShapeEnum te=e.ShapeType();
241 TopTools_ListOfShape lf;FDSCNX_FaceEdgeConnexFaces(s,e,HDS,lf);
242 TopTools_ListIteratorOfListOfShape ilf(lf);if(!ilf.More())continue;
243 cout<<"clear;";cout<<"tsee f "<<is<<";";
244 for(;ilf.More();ilf.Next())cout<<"tsee f "<<BDS.Shape(ilf.Value())<<";";
245 cout<<"tsee e "<<ie<<";### face "<<is<<" connexity"<<endl;
250 Standard_EXPORT void FDSCNX_Dump(const Handle(TopOpeBRepDS_HDataStructure)& HDS)
252 if (HDS.IsNull()) return; const TopOpeBRepDS_DataStructure& BDS = HDS->DS();
253 Standard_Integer i=1,ns=BDS.NbShapes();
254 for (i=1;i<=ns;i++) FDSCNX_Dump(HDS,i);