0024510: Remove unused local variables
[occt.git] / src / TopOpeBRepBuild / TopOpeBRepBuild_Grid.cxx
CommitLineData
b311480e 1// Created on: 1996-03-07
2// Created by: Jean Yves LEBEY
3// Copyright (c) 1996-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//
973c2be1 8// This library is free software; you can redistribute it and / or modify it
9// under the terms of the GNU Lesser General Public 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.
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 <TopOpeBRepBuild_Builder.ixx>
18
19#include <TopExp.hxx>
20#include <TopoDS.hxx>
21#include <TopOpeBRepBuild_define.hxx>
22
23#ifdef DEB
1d0a9d4d 24extern Standard_Boolean TopOpeBRepBuild_GetcontextSPEON();
7fd59977 25#endif
26
27//=======================================================================
28//function : GToSplit
29//purpose :
30//=======================================================================
31Standard_Boolean TopOpeBRepBuild_Builder::GToSplit(const TopoDS_Shape& S,const TopAbs_State TB) const
32{
33 Standard_Boolean issplit = IsSplit(S,TB);
34 Standard_Boolean facshap = myDataStructure->HasShape(S) && (S.ShapeType() == TopAbs_FACE);
35 Standard_Boolean hasgeom = myDataStructure->HasGeometry(S);
36 Standard_Boolean hassame = myDataStructure->HasSameDomain(S);
37 Standard_Boolean tosplit = (!issplit) && (facshap || hasgeom || hassame);
38
39#ifdef DEB
40 Standard_Integer iS; Standard_Boolean tSPS = GtraceSPS(S,iS);
41 if (tSPS) {
42 cout<<"GToSplit ";GdumpSHA(S);cout<<" ";TopAbs::Print(TB,cout);
43 cout<<" "<<tosplit<<" : "<<"!issplit "<<(!issplit);
44 cout<<" && (facshap || hasgeom || hassame) ";
45 cout<<"("<<facshap<<" || "<<hasgeom<<" || "<<hassame<<")"<<endl;
46 cout.flush();
47 }
48#endif
49
50#ifdef DEB
51 if (TopOpeBRepBuild_GetcontextSPEON()) { //CONTEXT
52 tSPS = Standard_True; //CONTEXT
53 Standard_Boolean hasON = Standard_False; //CONTEXT
54 Standard_Boolean isE = (S.ShapeType() == TopAbs_EDGE); //CONTEXT
55 if (isE) { //CONTEXT
56 const TopoDS_Edge& E = TopoDS::Edge(S); //CONTEXT
57 Standard_Boolean issE = myDataStructure->DS().IsSectionEdge(E); //CONTEXT
58 if (issE) { //CONTEXT
59 Standard_Boolean issplitON = IsSplit(E,TopAbs_ON); //CONTEXT
60 if (issplitON) { //CONTEXT
61 Standard_Integer n = Splits(E,TopAbs_ON).Extent(); //CONTEXT
62 hasON = (n>0); //CONTEXT
63 } //CONTEXT
64 } //CONTEXT
65 } //CONTEXT
66 Standard_Boolean tosplitH = tosplit || hasON; //CONTEXT
67 if(tSPS){cout<<"GToSplit context SPEON";} //CONTEXT
68 if(tSPS){cout<<" "<<tosplitH<<" : "<<"tosplit "<<tosplit;} //CONTEXT
69 if(tSPS){cout<<" || hasON "<<hasON<<endl;} //CONTEXT
70 } //CONTEXT
71#endif
72
73 return tosplit;
74} // GToSplit
75
76
77//=======================================================================
78//function : GToMerge
79//purpose :
80//=======================================================================
81Standard_Boolean TopOpeBRepBuild_Builder::GToMerge(const TopoDS_Shape& S) const
82{
83 TopAbs_State TB = TopAbs_IN;
84
85 Standard_Boolean ismerged = IsMerged(S,TB);
86 Standard_Boolean hassame = myDataStructure->HasSameDomain(S);
87 Standard_Boolean tomerge = (!ismerged && hassame);
88
89#ifdef DEB
90 Standard_Integer iS; Standard_Boolean tSPS = GtraceSPS(S,iS);
91 if(tSPS){cout<<"GToMerge ";GdumpSHA(S);cout<<" ";TopAbs::Print(TB,cout);}
92 if(tSPS){cout<<" "<<tomerge<<" : !ismerged "<<(!ismerged)<<" && hassame "<<hassame<<endl;}
93#endif
94
95 return tomerge;
96} // GToMerge
97
98//=======================================================================
99//function : GTakeCommonOfSame
100//purpose :
101//=======================================================================
102Standard_Boolean TopOpeBRepBuild_Builder::GTakeCommonOfSame(const TopOpeBRepBuild_GTopo& G)
103{
104 TopAbs_State t1,t2; G.StatesON(t1,t2);
105 Standard_Boolean sam = Standard_False;
106 if (t1 == TopAbs_OUT && t2 == TopAbs_OUT) sam = Standard_True;
107 else if (t1 == TopAbs_OUT && t2 == TopAbs_IN ) sam = Standard_False;
108 else if (t1 == TopAbs_IN && t2 == TopAbs_OUT) sam = Standard_False;
109 else if (t1 == TopAbs_IN && t2 == TopAbs_IN ) sam = Standard_True;
110
111 return sam;
112}
113
114//=======================================================================
115//function : GTakeCommonOfDiff
116//purpose :
117//=======================================================================
118Standard_Boolean TopOpeBRepBuild_Builder::GTakeCommonOfDiff(const TopOpeBRepBuild_GTopo& G)
119{
120 TopAbs_State t1,t2; G.StatesON(t1,t2);
121 Standard_Boolean dif = Standard_False;
122 if (t1 == TopAbs_OUT && t2 == TopAbs_OUT) dif = Standard_False;
123 else if (t1 == TopAbs_OUT && t2 == TopAbs_IN ) dif = Standard_True;
124 else if (t1 == TopAbs_IN && t2 == TopAbs_OUT) dif = Standard_True;
125 else if (t1 == TopAbs_IN && t2 == TopAbs_IN ) dif = Standard_False;
126
127 return dif;
128}
129
130//=======================================================================
131//function : GFindSamDom
132//purpose : complete the lists L1,L2 with the shapes of the DS
133// having same domain
134//=======================================================================
135void TopOpeBRepBuild_Builder::GFindSamDom(const TopoDS_Shape& S,TopTools_ListOfShape& L1,TopTools_ListOfShape& L2) const
136{
137 L1.Clear(); L2.Clear();
138 L1.Append(S);
139 GFindSamDom(L1,L2);
140}
141
142//=======================================================================
143//function : GFindSamDom
144//purpose : complete the lists L1,L2 with the shapes of the DS
145// having same domain
146//=======================================================================
147void TopOpeBRepBuild_Builder::GFindSamDom(TopTools_ListOfShape& L1,TopTools_ListOfShape& L2) const
148{
149 Standard_Integer i;
150 Standard_Integer nl1 = L1.Extent(), nl2 = L2.Extent();
151
152 while ( nl1 > 0 || nl2 > 0 ) {
153
154 TopTools_ListIteratorOfListOfShape it1(L1);
155 for (i=1 ; i<=nl1; i++) {
156 const TopoDS_Shape& S1 = it1.Value();
157#ifdef DEB
158// Standard_Integer iS1 = myDataStructure->Shape(S1);
159#endif
160 TopTools_ListIteratorOfListOfShape itsd(myDataStructure->SameDomain(S1));
161 for (; itsd.More(); itsd.Next() ) {
162 const TopoDS_Shape& S2 = itsd.Value();
163#ifdef DEB
164// Standard_Integer iS2 = myDataStructure->Shape(S2);
165#endif
166 Standard_Boolean found = GContains(S2,L2);
167 if ( ! found ) {
168 L2.Prepend(S2);
169 nl2++;
170 }
171 }
172 it1.Next();
173 }
174 nl1 = 0;
175
176 TopTools_ListIteratorOfListOfShape it2(L2);
177 for (i=1 ; i<=nl2; i++) {
178 const TopoDS_Shape& S2 = it2.Value();
179#ifdef DEB
180// Standard_Integer iS2 = myDataStructure->Shape(S2);
181#endif
182 TopTools_ListIteratorOfListOfShape itsd(myDataStructure->SameDomain(S2));
183 for (; itsd.More(); itsd.Next() ) {
184 const TopoDS_Shape& S1 = itsd.Value();
185#ifdef DEB
186// Standard_Integer iS1 = myDataStructure->Shape(S1);
187#endif
188 Standard_Boolean found = GContains(S1,L1);
189 if ( ! found ) {
190 L1.Prepend(S1);
191 nl1++;
192 }
193 }
194 it2.Next();
195 }
196 nl2 = 0;
197
198 }
199
200}
201
202//=======================================================================
203//function : GFindSamDomSODO
204//purpose :
205//=======================================================================
206void TopOpeBRepBuild_Builder::GFindSamDomSODO(const TopoDS_Shape& S,TopTools_ListOfShape& LSO,TopTools_ListOfShape& LDO) const
207{
208 LSO.Clear();
209 LDO.Clear();
210 LSO.Append(S);
211 GFindSamDomSODO(LSO,LDO);
212}
213
214//=======================================================================
215//function : GFindSamDomSODO
216//purpose :
217//=======================================================================
218void TopOpeBRepBuild_Builder::GFindSamDomSODO(TopTools_ListOfShape& LSO,TopTools_ListOfShape& LDO) const
219{
220 TopTools_ListIteratorOfListOfShape it;
221 it.Initialize(LSO);
222 if ( ! it.More() ) return;
223 const TopoDS_Shape& sref = it.Value();
224#ifdef DEB
225// Standard_Integer iref = myDataStructure->SameDomainReference(sref);
226#endif
227 TopOpeBRepDS_Config oref = myDataStructure->SameDomainOrientation(sref);
228
229 GFindSamDom(LSO,LDO);
230
231#ifdef DEB
232 Standard_Integer iS; Standard_Boolean tSPS = GtraceSPS(sref,iS);
233 if(tSPS) {
234 TCollection_AsciiString ss("GFindSamDom result on ");
235 GdumpSHA(sref,(Standard_Address)ss.ToCString());cout<<endl;
236 GdumpSAMDOM(LSO, (char *) "L1 : ");
237 GdumpSAMDOM(LDO, (char *) "L2 : ");
238 }
239#endif
240
241 TopTools_ListOfShape LLSO,LLDO;
242
243 for (it.Initialize(LSO); it.More(); it.Next() ) {
244 const TopoDS_Shape& s = it.Value();
245 TopOpeBRepDS_Config o = myDataStructure->SameDomainOrientation(s);
246#ifdef DEB
247// Standard_Integer iS = myDataStructure->Shape(s);
248#endif
249 if ( o == oref && !GContains(s,LLSO) ) LLSO.Append(s);
250 else if ( o != oref && !GContains(s,LLDO) ) LLDO.Append(s);
251 }
252
253 for (it.Initialize(LDO); it.More(); it.Next() ) {
254 const TopoDS_Shape& s = it.Value();
255 TopOpeBRepDS_Config o = myDataStructure->SameDomainOrientation(s);
256#ifdef DEB
257// Standard_Integer iS = myDataStructure->Shape(s);
258#endif
259 if ( o == oref && !GContains(s,LLSO) ) LLSO.Append(s);
260 else if ( o != oref && !GContains(s,LLDO) ) LLDO.Append(s);
261 }
262
7fd59977 263 LSO = LLSO;
264 LDO = LLDO;
7fd59977 265}
266
267//=======================================================================
268//function : GMapShapes
269//purpose :
270//=======================================================================
271void TopOpeBRepBuild_Builder::GMapShapes(const TopoDS_Shape& S1,const TopoDS_Shape& S2)
272{
273 Standard_Boolean S1null = S1.IsNull();
274 Standard_Boolean S2null = S2.IsNull();
275 GClearMaps();
276 if ( ! S1null ) TopExp::MapShapes(S1,myMAP1);
277 if ( ! S2null ) TopExp::MapShapes(S2,myMAP2);
278}
279
280//=======================================================================
281//function : GClearMaps
282//purpose :
283//=======================================================================
284void TopOpeBRepBuild_Builder::GClearMaps()
285{
286 myMAP1.Clear();
287 myMAP2.Clear();
288}
289
290//=======================================================================
291//function : GFindSameRank
292//purpose :
293//=======================================================================
294void TopOpeBRepBuild_Builder::GFindSameRank
295(const TopTools_ListOfShape& L1,const Standard_Integer Rank,TopTools_ListOfShape& L2) const
296{
297 for ( TopTools_ListIteratorOfListOfShape it1(L1); it1.More(); it1.Next() ) {
298 const TopoDS_Shape& s = it1.Value();
299#ifdef DEB
300// Standard_Integer iS = myDataStructure->Shape(s);
301#endif
302 Standard_Integer r = GShapeRank(s);
303 if ( r == Rank && !GContains(s,L2) ) {
304 L2.Append(s);
305 }
306 }
307}
308
309//=======================================================================
310//function : GShapeRank
311//purpose :
312//=======================================================================
313Standard_Integer TopOpeBRepBuild_Builder::GShapeRank(const TopoDS_Shape& S) const
314{
315 Standard_Boolean isof1 = GIsShapeOf(S,1);
316 Standard_Boolean isof2 = GIsShapeOf(S,2);
317 Standard_Integer ancetre = (isof1 || isof2) ? ((isof1) ? 1 : 2) : 0;
318 return ancetre;
319}
320
321//=======================================================================
322//function : GIsShapeOf
323//purpose :
324//=======================================================================
325Standard_Boolean TopOpeBRepBuild_Builder::GIsShapeOf(const TopoDS_Shape& S,const Standard_Integer I) const
326{
327 if (S.IsNull()) return Standard_False;
328 Standard_Boolean b = Standard_False;
329 if (I == 1) b = myMAP1.Contains(S);
330 else if (I == 2) b = myMAP2.Contains(S);
331 return b;
332}
333
334//=======================================================================
335//function : GContains
336//purpose : returns True if S is in the list L.
337//=======================================================================
338Standard_Boolean TopOpeBRepBuild_Builder::GContains(const TopoDS_Shape& S,const TopTools_ListOfShape& L)
339{
340 for (TopTools_ListIteratorOfListOfShape it(L); it.More(); it.Next() ) {
341 const TopoDS_Shape& SL = it.Value();
342 Standard_Boolean issame = SL.IsSame(S);
343 if ( issame ) return Standard_True;
344 }
345 return Standard_False;
346}
347
348
349//=======================================================================
350//function : GCopyList
351//purpose :
352// copy des elements [i1..i2] de Lin dans Lou. 1er element de Lin = index 1
353//=======================================================================
354void TopOpeBRepBuild_Builder::GCopyList(const TopTools_ListOfShape& Lin,const Standard_Integer I1,const Standard_Integer I2,TopTools_ListOfShape& Lou)
355{
356 TopTools_ListIteratorOfListOfShape it(Lin);
357 Standard_Integer nadd = 0;
358 for ( Standard_Integer i = 1; it.More(); it.Next(),i++ ) {
359 const TopoDS_Shape& EL = it.Value();
360 if ( i >= I1 && i <= I2 ) {
361 Lou.Append(EL);
362 nadd++;
363 }
364 }
365}
366
367
368//=======================================================================
369//function : GCopyList
370//purpose :
371// copy de Lin dans Lou
372//=======================================================================
373void TopOpeBRepBuild_Builder::GCopyList(const TopTools_ListOfShape& Lin,TopTools_ListOfShape& Lou)
374{
375 const Standard_Integer I1 = 1;
376 const Standard_Integer I2 = Lin.Extent();
377 GCopyList(Lin,I1,I2,Lou);
378}