0028643: Coding rules - eliminate GCC compiler warnings -Wmisleading-indentation
[occt.git] / src / TopOpeBRepDS / TopOpeBRepDS_connex.cxx
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
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <TopOpeBRepDS_connex.hxx>
18
19 #include <TopExp_Explorer.hxx>
20 #include <TopoDS.hxx>
21
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;
27
28 //modified by NIZNHY-PKV Sun Dec 15 17:41:43 2002 f
29 //=======================================================================
30 //function : FDSCNX_Close
31 //purpose  :
32 //=======================================================================
33 void FDSCNX_Close()
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
59 Standard_EXPORT const TopTools_ListOfShape& FDSCNX_EdgeConnexityShapeIndex(const TopoDS_Shape& E,const Handle(TopOpeBRepDS_HDataStructure)& HDS,const Standard_Integer SI)
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
76 Standard_EXPORT const TopTools_ListOfShape& FDSCNX_EdgeConnexitySameShape(const TopoDS_Shape& S,const Handle(TopOpeBRepDS_HDataStructure)& HDS)
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
94 Standard_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;
118     TopTools_DataMapOfShapeListOfShape& elf = (rf == 1) ? *GLOBAL_elf1 : *GLOBAL_elf2;
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;
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);
140     }
141   }
142   GLOBAL_FDSCNX_prepared = Standard_True;
143 }
144
145 Standard_EXPORT Standard_Boolean FDSCNX_HasConnexFace(const TopoDS_Shape& S,const Handle(TopOpeBRepDS_HDataStructure)& HDS)
146 {
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);
172   return has;
173 }
174
175 Standard_EXPORT void FDSCNX_FaceEdgeConnexFaces(const TopoDS_Shape& F,const TopoDS_Shape& E,const Handle(TopOpeBRepDS_HDataStructure)& HDS,TopTools_ListOfShape& LF)
176 {
177   LF.Clear();
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);
181   if (loe.IsEmpty())
182   {
183     return;
184   }
185   for (TopTools_ListIteratorOfListOfShape i(loe);i.More();i.Next())
186   {
187     const TopoDS_Shape& e = i.Value();
188 //             HDS->Shape(e);
189     Standard_Boolean b = e.IsSame(E);
190     if (b)
191     {
192       EofF=Standard_True;
193       break;
194     }
195   }
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   {
208     const TopoDS_Shape& f = it.Value();
209     Standard_Boolean b = f.IsSame(F);
210     if (!b)
211     {
212       LF.Append(f);
213     }
214   }
215 }
216
217 Standard_EXPORT void FDSCNX_DumpIndex(const Handle(TopOpeBRepDS_HDataStructure)& HDS,const Standard_Integer I)
218 {
219   if (HDS.IsNull())
220   {
221     return;
222   }
223
224   const TopOpeBRepDS_DataStructure& BDS = HDS->DS();
225   Standard_Integer ns=BDS.NbShapes();
226   if (I<1 || I>ns)
227   {
228     return;
229   }
230
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)
236   {
237     TopTools_ListIteratorOfListOfShape ils(ls);
238     if (!ils.More())
239     {
240       return;
241     }
242
243     for (; ils.More(); ils.Next())
244     {
245       cout<<BDS.Shape(ils.Value())<<" ";
246     }
247   }
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     {
258       const TopoDS_Shape& e=ils.Value();
259       TopTools_ListOfShape lf;FDSCNX_FaceEdgeConnexFaces(s,e,HDS,lf);
260       TopTools_ListIteratorOfListOfShape ilf(lf);
261       if (!ilf.More())
262       {
263         continue;
264       }
265       for (; ilf.More(); ilf.Next())
266       {
267         cout<<BDS.Shape(ilf.Value())<<" ";
268       }
269     }
270   }
271 }
272
273 Standard_EXPORT void FDSCNX_Dump(const Handle(TopOpeBRepDS_HDataStructure)& HDS,const Standard_Integer I)
274 {
275   if (HDS.IsNull())
276   {
277     return;
278   }
279
280   const TopOpeBRepDS_DataStructure& BDS = HDS->DS();
281   Standard_Integer ns=BDS.NbShapes();
282   if (I<1 || I>ns)
283   {
284     return;
285   }
286
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)
291   {
292     TopTools_ListIteratorOfListOfShape ils(ls);
293     if(!ils.More())
294     {
295       return;
296     }
297
298     cout<<"clear;";
299     for (; ils.More(); ils.Next())
300     {
301       cout<<"tsee f "<<BDS.Shape(ils.Value())<<";";
302     }
303     cout<<"tsee e "<<is<<";### edge "<<is<<" connexity"<<endl;
304   }
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     {
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);
317       if (!ilf.More())
318       {
319         continue;
320       }
321
322       cout<<"clear;";cout<<"tsee f "<<is<<";";
323       for (;ilf.More(); ilf.Next())
324       {
325         cout<<"tsee f "<<BDS.Shape(ilf.Value())<<";";
326       }
327       cout<<"tsee e "<<ie<<";### face "<<is<<" connexity"<<endl;
328     }
329   }
330 }
331
332 Standard_EXPORT void FDSCNX_Dump(const Handle(TopOpeBRepDS_HDataStructure)& HDS)
333 {
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   }
345 }