b75f66fdb902e4ba1eb41b46e50ebdd2e5d15c44
[occt.git] / src / TopOpeBRepDS / TopOpeBRepDS_HDataStructure.cxx
1 // Created on: 1993-06-17
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22 #include <TopOpeBRepDS_HDataStructure.ixx>
23
24 #include <TopOpeBRepDS_EdgeInterferenceTool.hxx>
25 #include <BRep_Tool.hxx>
26 #include <TopoDS.hxx>
27 #include <TopoDS_Edge.hxx>
28 #include <TopExp_Explorer.hxx>
29 #include <TopTools_ListOfShape.hxx>
30 #include <TopOpeBRepDS_SurfaceCurveInterference.hxx>
31 #include <TopOpeBRepDS_Transition.hxx>
32 #include <TopAbs_ShapeEnum.hxx>
33 #include <TopOpeBRepDS.hxx>
34 #include <TopOpeBRepDS_Interference.hxx>
35 #include <TopOpeBRepDS_ListOfInterference.hxx>
36 #include <TopOpeBRepDS_ListIteratorOfListOfInterference.hxx>
37 #include <TopOpeBRepDS_Check.hxx>
38 #include <TopOpeBRepTool_ShapeExplorer.hxx>
39 #include <TopOpeBRepDS_Filter.hxx>
40 #include <TopOpeBRepDS_Reducer.hxx>
41 #include <TopOpeBRepDS_Dumper.hxx>
42 #include <Standard_ProgramError.hxx>
43 #include <TopOpeBRepDS_define.hxx>
44
45 #ifdef DEB
46 Standard_IMPORT Standard_Boolean TopOpeBRepDS_GettraceISTO();
47 Standard_IMPORT Standard_Boolean TopOpeBRepDS_GettraceEDSF(); 
48 Standard_IMPORT Standard_Boolean TopOpeBRepDS_GettraceDSF(); 
49 Standard_IMPORT Standard_Boolean TopOpeBRepDS_GettraceDSFD(); 
50 Standard_IMPORT Standard_Boolean TopOpeBRepDS_GettraceDEGEN(); 
51 Standard_IMPORT Standard_Boolean TopOpeBRepDS_GettracePCI();
52 Standard_IMPORT Standard_Boolean TopOpeBRepDS_GettracePI();
53 Standard_IMPORT Standard_Boolean TopOpeBRepDS_GettracePEI();
54 Standard_IMPORT Standard_Boolean TopOpeBRepDS_GettracePI();
55 Standard_IMPORT Standard_Boolean TopOpeBRepDS_GettraceSPSX(const Standard_Integer);
56
57 static Standard_Boolean traceSTORE()
58 {
59   Standard_Boolean trc = Standard_False;
60   trc = trc || TopOpeBRepDS_GettraceEDSF();
61   trc = trc || TopOpeBRepDS_GettraceDSF();
62   trc = trc || TopOpeBRepDS_GettraceDEGEN();
63   trc = trc || TopOpeBRepDS_GettraceISTO();
64   return trc;
65 }
66 #endif
67
68 static void FUN_HDS_data(const Handle(TopOpeBRepDS_Interference)& I,
69                          TopOpeBRepDS_Kind& GT1,Standard_Integer& G1,
70                          TopOpeBRepDS_Kind& ST1,Standard_Integer& S1)
71 {       
72   if (I.IsNull()) return;
73   GT1 = I->GeometryType(); G1 = I->Geometry();
74   ST1 = I->SupportType();  S1 = I->Support(); 
75 }
76
77
78 Standard_EXPORT Standard_Boolean FUN_HDS_FACESINTERFER
79 (const TopoDS_Shape& F1, const TopoDS_Shape& F2,
80  const Handle(TopOpeBRepDS_HDataStructure)& HDS)
81 {
82   Standard_Boolean yainterf = Standard_False;
83   const TopOpeBRepDS_DataStructure& DS = HDS->DS();
84   Standard_Boolean ya = DS.HasShape(F1);
85   if ( !ya ) return Standard_False;
86
87 //                         DS.Shape(F1);
88   Standard_Integer iF2 = DS.Shape(F2);
89
90   const TopOpeBRepDS_ListOfInterference& L1 = DS.ShapeInterferences(F1);
91   TopOpeBRepDS_ListIteratorOfListOfInterference itL1(L1);
92   for (;itL1.More(); itL1.Next()) {
93     const Handle(TopOpeBRepDS_Interference)& I = itL1.Value();
94     TopOpeBRepDS_Kind GT,ST;Standard_Integer G,S;
95     FUN_HDS_data(I,GT,G,ST,S);
96     // interference face1/edge/face2
97     Standard_Boolean fef = Standard_True;
98     fef = fef && (GT==TopOpeBRepDS_EDGE);
99     fef = fef && (ST==TopOpeBRepDS_FACE);
100     fef = fef && (S==iF2);
101     if (fef) {
102       yainterf = Standard_True;
103       break;
104     }
105   }
106   return yainterf;
107 }
108
109
110 //=======================================================================
111 //function : TopOpeBRepDS_HDataStructure
112 //purpose  : 
113 //=======================================================================
114 TopOpeBRepDS_HDataStructure::TopOpeBRepDS_HDataStructure()
115 {
116 }
117
118 //=======================================================================
119 //function : AddAncestors
120 //purpose  : 
121 //=======================================================================
122 void TopOpeBRepDS_HDataStructure::AddAncestors
123 (const TopoDS_Shape& S)
124 {
125   AddAncestors(S,TopAbs_WIRE,TopAbs_EDGE);
126   AddAncestors(S,TopAbs_FACE,TopAbs_WIRE);
127   AddAncestors(S,TopAbs_SHELL,TopAbs_FACE);
128   AddAncestors(S,TopAbs_SOLID,TopAbs_SHELL);
129 }
130
131 //=======================================================================
132 //function : AddAncestors
133 //purpose  : 
134 //=======================================================================
135 void TopOpeBRepDS_HDataStructure::AddAncestors
136 (const TopoDS_Shape& S,
137  const TopAbs_ShapeEnum T1,const TopAbs_ShapeEnum T2)
138 {
139   TopOpeBRepDS_DataStructure& BDS = ChangeDS();
140   Standard_Integer rankS = myDS.AncestorRank(S);
141   // find the shapes of type T1 containing HasShape() of type T2
142   for (TopOpeBRepTool_ShapeExplorer eT1(S,T1); eT1.More(); eT1.Next()) {
143     const TopoDS_Shape& ST1 = eT1.Current();
144     for (TopOpeBRepTool_ShapeExplorer eT2(ST1,T2); eT2.More(); eT2.Next()) {
145       const TopoDS_Shape& ST2 = eT2.Current();
146       if (BDS.HasShape(ST2)) {
147         BDS.AddShape(ST1,rankS);
148         break;
149       }
150     }
151   }
152 }
153
154 //=======================================================================
155 //function : ChkIntg
156 //purpose  : Check Integrity
157 //=======================================================================
158 void TopOpeBRepDS_HDataStructure::ChkIntg()
159 {
160   // Check the integrity of the DS
161   Handle(TopOpeBRepDS_Check) chk = new TopOpeBRepDS_Check(this);
162   chk->ChkIntg();
163 //  chk->PrintIntg(cout);
164 }
165
166 //=======================================================================
167 //function : DS
168 //purpose  : 
169 //=======================================================================
170 const TopOpeBRepDS_DataStructure&  TopOpeBRepDS_HDataStructure::DS()const 
171 {
172   return myDS;
173 }
174
175 //=======================================================================
176 //function : ChangeDS
177 //purpose  : 
178 //=======================================================================
179 TopOpeBRepDS_DataStructure&  TopOpeBRepDS_HDataStructure::ChangeDS()
180 {
181   return myDS;
182 }
183
184 //=======================================================================
185 //function : NbSurfaces
186 //purpose  : 
187 //=======================================================================
188 Standard_Integer  TopOpeBRepDS_HDataStructure::NbSurfaces()const 
189 {
190   return myDS.NbSurfaces();
191 }
192
193 //=======================================================================
194 //function : NbCurves
195 //purpose  : 
196 //=======================================================================
197 Standard_Integer  TopOpeBRepDS_HDataStructure::NbCurves()const 
198 {
199   return myDS.NbCurves();
200 }
201
202 //=======================================================================
203 //function : NbPoints
204 //purpose  : 
205 //=======================================================================
206 Standard_Integer  TopOpeBRepDS_HDataStructure::NbPoints()const 
207 {
208   return myDS.NbPoints();
209 }
210
211 //=======================================================================
212 //function : Surface
213 //purpose  : 
214 //=======================================================================
215 const TopOpeBRepDS_Surface&  TopOpeBRepDS_HDataStructure::Surface
216 (const Standard_Integer I)const 
217 {
218   return myDS.Surface(I);
219 }
220
221 //=======================================================================
222 //function : SurfaceCurves
223 //purpose  : 
224 //=======================================================================
225 TopOpeBRepDS_CurveIterator  TopOpeBRepDS_HDataStructure::SurfaceCurves
226 (const Standard_Integer I)const 
227 {
228   const TopOpeBRepDS_ListOfInterference& L = myDS.SurfaceInterferences(I);
229   return TopOpeBRepDS_CurveIterator(L);
230 }
231
232 //=======================================================================
233 //function : Curve
234 //purpose  : 
235 //=======================================================================
236 const TopOpeBRepDS_Curve&  TopOpeBRepDS_HDataStructure::Curve
237 (const Standard_Integer I)const
238 {
239   return myDS.Curve(I);
240 }
241
242 //=======================================================================
243 //function : ChangeCurve
244 //purpose  : 
245 //=======================================================================
246 TopOpeBRepDS_Curve&  TopOpeBRepDS_HDataStructure::ChangeCurve
247 (const Standard_Integer I)
248 {
249   return myDS.ChangeCurve(I);
250 }
251
252 //=======================================================================
253 //function : CurvePoints
254 //purpose  : 
255 //=======================================================================
256 TopOpeBRepDS_PointIterator  TopOpeBRepDS_HDataStructure::CurvePoints
257 (const Standard_Integer I)const 
258 {
259   const TopOpeBRepDS_ListOfInterference& L = myDS.CurveInterferences(I);
260   return TopOpeBRepDS_PointIterator(L);
261 }
262
263 //=======================================================================
264 //function : Point
265 //purpose  : 
266 //=======================================================================
267 const TopOpeBRepDS_Point&  TopOpeBRepDS_HDataStructure::Point
268 (const Standard_Integer I)const 
269 {
270   return myDS.Point(I);
271 }
272
273 //=======================================================================
274 //function : HasGeometry
275 //purpose  : 
276 //=======================================================================
277 Standard_Boolean  TopOpeBRepDS_HDataStructure::HasGeometry
278 (const TopoDS_Shape& S)const 
279 {
280   Standard_Boolean b = myDS.HasGeometry(S);
281   return b;
282 }
283
284 //=======================================================================
285 //function : HasShape
286 //purpose  : 
287 //=======================================================================
288 Standard_Boolean  TopOpeBRepDS_HDataStructure::HasShape
289 (const TopoDS_Shape& S,const Standard_Boolean FindKeep) const 
290 {
291   Standard_Boolean b = myDS.HasShape(S, FindKeep);
292   return b;
293 }
294
295 //=======================================================================
296 //function : HasSameDomain
297 //purpose  : 
298 //=======================================================================
299 Standard_Boolean  TopOpeBRepDS_HDataStructure::HasSameDomain
300 (const TopoDS_Shape& S,const Standard_Boolean FindKeep)const 
301 {
302   if ( ! HasShape(S, FindKeep) ) return Standard_False;
303   const TopTools_ListOfShape& l = myDS.ShapeSameDomain(S);
304   Standard_Boolean res = ! l.IsEmpty();
305   return res;
306 }
307
308 //=======================================================================
309 //function : SameDomain
310 //purpose  : 
311 //=======================================================================
312 TopTools_ListIteratorOfListOfShape TopOpeBRepDS_HDataStructure::SameDomain
313 (const TopoDS_Shape& S)const 
314 {
315   const TopTools_ListOfShape& L = myDS.ShapeSameDomain(S);
316   return TopTools_ListIteratorOfListOfShape(L);
317 }
318
319 //=======================================================================
320 //function : SameDomainOrientation
321 //purpose  : 
322 //=======================================================================
323 TopOpeBRepDS_Config  TopOpeBRepDS_HDataStructure::SameDomainOrientation
324 (const TopoDS_Shape& S)const 
325 {
326   if ( ! HasShape(S) ) return TopOpeBRepDS_UNSHGEOMETRY;
327   return myDS.SameDomainOri(S);
328 }
329
330 //=======================================================================
331 //function : SameDomainReference
332 //purpose  : 
333 //=======================================================================
334 Standard_Integer TopOpeBRepDS_HDataStructure::SameDomainReference
335 (const TopoDS_Shape& S)const 
336 {
337   if ( ! HasShape(S) ) return 0;
338   return myDS.SameDomainRef(S);
339 }
340
341 //=======================================================================
342 //function : NbShapes
343 //purpose  : 
344 //=======================================================================
345 Standard_Integer  TopOpeBRepDS_HDataStructure::NbShapes()const 
346 {
347   return myDS.NbShapes();
348 }
349
350 //=======================================================================
351 //function : Shape
352 //purpose  : 
353 //=======================================================================
354 const TopoDS_Shape&  TopOpeBRepDS_HDataStructure::Shape
355 (const Standard_Integer I,const Standard_Boolean FindKeep) const 
356 {
357   return myDS.Shape(I, FindKeep);
358 }
359
360 //=======================================================================
361 //function : Shape
362 //purpose  : 
363 //=======================================================================
364 Standard_Integer TopOpeBRepDS_HDataStructure::Shape
365 (const TopoDS_Shape& S,const Standard_Boolean FindKeep)const
366 {
367   return myDS.Shape(S, FindKeep);
368 }
369
370 //=======================================================================
371 //function : SolidSurfaces
372 //purpose  : 
373 //=======================================================================
374 TopOpeBRepDS_SurfaceIterator  TopOpeBRepDS_HDataStructure::SolidSurfaces
375 (const TopoDS_Shape& S) const 
376 {
377   const TopOpeBRepDS_ListOfInterference& L = myDS.ShapeInterferences(S);
378   return TopOpeBRepDS_SurfaceIterator(L);
379 }
380
381 //=======================================================================
382 //function : SolidSurfaces
383 //purpose  : 
384 //=======================================================================
385 TopOpeBRepDS_SurfaceIterator  TopOpeBRepDS_HDataStructure::SolidSurfaces
386 (const Standard_Integer I)const 
387 {
388   const TopOpeBRepDS_ListOfInterference& L = myDS.ShapeInterferences(I);
389   return TopOpeBRepDS_SurfaceIterator(L);
390 }
391
392 //=======================================================================
393 //function : FaceCurves
394 //purpose  : 
395 //=======================================================================
396 TopOpeBRepDS_CurveIterator  TopOpeBRepDS_HDataStructure::FaceCurves
397 (const TopoDS_Shape& F)const 
398 {
399   const TopOpeBRepDS_ListOfInterference& L = myDS.ShapeInterferences(F);
400   return TopOpeBRepDS_CurveIterator(L);
401 }
402
403 //=======================================================================
404 //function : FaceCurves
405 //purpose  : 
406 //=======================================================================
407 TopOpeBRepDS_CurveIterator  TopOpeBRepDS_HDataStructure::FaceCurves
408 (const Standard_Integer I)const 
409 {
410   const TopOpeBRepDS_ListOfInterference& L = myDS.ShapeInterferences(I);
411   return TopOpeBRepDS_CurveIterator(L);
412 }
413
414 //=======================================================================
415 //function : EdgePoints
416 //purpose  : 
417 //=======================================================================
418 TopOpeBRepDS_PointIterator  TopOpeBRepDS_HDataStructure::EdgePoints
419 (const TopoDS_Shape& E)const 
420 {
421   const TopOpeBRepDS_ListOfInterference& L = myDS.ShapeInterferences(E);
422   return TopOpeBRepDS_PointIterator(L);
423 }
424
425 //=======================================================================
426 //function : MakeCurve
427 //purpose  : 
428 //=======================================================================
429 Standard_Integer TopOpeBRepDS_HDataStructure::MakeCurve
430 (const TopOpeBRepDS_Curve& curC,TopOpeBRepDS_Curve& newC)
431 {
432   // SCI1, SCI2 = new surface/curve interf. build from 
433   // the surface/curve interf. of the curve curC
434   const Handle(TopOpeBRepDS_Interference)& I1 = curC.GetSCI1();
435   const Handle(TopOpeBRepDS_Interference)& I2 = curC.GetSCI2();
436   Handle(TopOpeBRepDS_SurfaceCurveInterference) SCI1,SCI2; 
437   if ( ! I1.IsNull() ) SCI1 = new TopOpeBRepDS_SurfaceCurveInterference(I1);
438   if ( ! I2.IsNull() ) SCI2 = new TopOpeBRepDS_SurfaceCurveInterference(I2);
439
440   const TopoDS_Shape& S1 = curC.Shape1();
441   const TopoDS_Shape& S2 = curC.Shape2();
442
443   // add the new SCIs in the lists of SCIs connected to the shapes
444   if ( ! SCI1.IsNull() ) myDS.AddShapeInterference(S1,SCI1);
445   if ( ! SCI2.IsNull() ) myDS.AddShapeInterference(S2,SCI2);
446
447   // the shapes of the new curve are the shapes of curve curC
448   newC.SetShapes(S1,S2);
449
450   // set surface/curve interferences of the new curve
451   newC.SetSCI(SCI1,SCI2);
452
453   // newC is a daughter of curC
454   newC.ChangeMother(curC.DSIndex());
455
456   // add the new curve in the DS
457   Standard_Integer inewC = myDS.AddCurve(newC);
458
459   // the geometry of the new surface/curve interf. is new curve inewC
460   if ( ! SCI1.IsNull() ) SCI1->Geometry(inewC);
461   if ( ! SCI2.IsNull() ) SCI2->Geometry(inewC);
462
463   return inewC;
464 }
465
466 //=======================================================================
467 //function : RemoveCurve
468 //purpose  : 
469 //=======================================================================
470 void TopOpeBRepDS_HDataStructure::RemoveCurve(const Standard_Integer icurC)
471 {
472   myDS.RemoveCurve(icurC);
473 }
474
475 //=======================================================================
476 //function : NbGeometry
477 //purpose  : 
478 //=======================================================================
479 Standard_Integer TopOpeBRepDS_HDataStructure::NbGeometry
480   (const TopOpeBRepDS_Kind K) const
481 {
482   if ( ! TopOpeBRepDS::IsGeometry(K)) return 0;
483
484   Standard_Integer n = 0;
485   switch(K) {
486   case TopOpeBRepDS_POINT : n = NbPoints(); break;
487   case TopOpeBRepDS_CURVE : n = NbCurves(); break;
488   case TopOpeBRepDS_SURFACE : n = NbSurfaces(); break;
489   default : n = 0; break;
490   }                     
491   return n;
492 }
493
494 //=======================================================================
495 //function : NbTopology
496 //purpose  : 
497 //=======================================================================
498 Standard_Integer TopOpeBRepDS_HDataStructure::NbTopology() const
499 {
500   Standard_Integer n = myDS.NbShapes();
501   return n;
502 }
503
504 //=======================================================================
505 //function : NbTopology
506 //purpose  : 
507 //=======================================================================
508 Standard_Integer TopOpeBRepDS_HDataStructure::NbTopology
509 (const TopOpeBRepDS_Kind K) const
510 {
511   if ( ! TopOpeBRepDS::IsTopology(K) ) return 0;
512   Standard_Integer res = 0;
513   const Standard_Boolean FindKeep = Standard_False;
514
515   TopAbs_ShapeEnum S = TopOpeBRepDS::KindToShape(K);
516   for (Standard_Integer i = 1; i <= NbTopology(); i++ )
517     if(myDS.KeepShape(i, FindKeep))
518       if (myDS.Shape(i, FindKeep).ShapeType() == S) res++;
519   return res;
520 }
521
522 //=======================================================================
523 //function : EdgesSameParameter
524 //purpose  : 
525 //=======================================================================
526
527 Standard_Boolean TopOpeBRepDS_HDataStructure::EdgesSameParameter() const
528 {
529   Standard_Integer i,n = myDS.NbShapes();
530   for (i = 1 ; i <= n; i++) {
531     const TopoDS_Shape& s = myDS.Shape(i);
532     if ( s.ShapeType() == TopAbs_EDGE ) {
533       const TopoDS_Edge& e = TopoDS::Edge(s);
534       if ( ! BRep_Tool::SameParameter(e) ) {
535         return Standard_False;
536       }
537     }
538   }
539   return Standard_True;
540 }
541
542 #include <TColStd_HArray1OfBoolean.hxx>
543 #include <TColStd_Array1OfBoolean.hxx>
544
545 Standard_EXPORT void FUN_TopOpeBRepDS_SortOnParameter
546 (const TopOpeBRepDS_ListOfInterference& List,
547  TopOpeBRepDS_ListOfInterference& SList)
548 {
549   // NYI : sort a list of Items, giving a sorting FUNCTION is impossible
550   // NYI : --> foobar method complexity n2.
551
552   Standard_Integer iIntf=0,nIntf = List.Extent();
553   if (nIntf == 0) return;
554
555   Handle(TColStd_HArray1OfBoolean) HT;
556   HT = new TColStd_HArray1OfBoolean(1,nIntf,Standard_False);
557   TColStd_Array1OfBoolean& T = HT->ChangeArray1();
558
559   Handle(TopOpeBRepDS_Interference) Intf;
560  
561   for (Standard_Integer i = 1; i <= nIntf; i++) { 
562     Standard_Real parmin = RealLast();
563     TopOpeBRepDS_PointIterator it(List);
564     for (Standard_Integer itest = 1; it.More(); it.Next(),itest++) {
565       if ( ! T(itest) ) {
566         Standard_Real par = it.Parameter();
567         if (par < parmin) {
568           parmin = par;
569           Intf = it.Value();
570           iIntf = itest;
571         }
572       }
573     }
574     SList.Append(Intf);
575     T(iIntf) = Standard_True;
576   }
577 }
578
579 //=======================================================================
580 //function : SortOnParameter
581 //purpose  : 
582 //=======================================================================
583 void TopOpeBRepDS_HDataStructure::SortOnParameter
584 (const TopOpeBRepDS_ListOfInterference& List,
585  TopOpeBRepDS_ListOfInterference& SList) const 
586 {
587   // NYI : sort a list of Items, giving a sorting FUNCTION is impossible
588   // NYI : --> foobar method complexity n2.
589
590   ::FUN_TopOpeBRepDS_SortOnParameter(List,SList);
591
592   // tete = interf FORWARD :
593   // modifier TopOpeBRepBuild_ParametrizedVertexSet ::SortParametrizedVertex()
594   Standard_Boolean found = Standard_False;
595   TopOpeBRepDS_ListIteratorOfListOfInterference it(SList);
596   TopOpeBRepDS_ListOfInterference L1,L2;
597
598   for (; it.More(); it.Next() ) {
599     Handle(TopOpeBRepDS_Interference) I = it.Value();
600     if ( ! found) {
601       TopAbs_Orientation o = I->Transition().Orientation(TopAbs_IN);
602       if (o == TopAbs_FORWARD) {
603         found = Standard_True;
604         L1.Append(I);
605       }
606       else L2.Append(I);
607     }
608     else L1.Append(I);
609   }
610
611   SList.Clear();
612   SList.Append(L1);
613   SList.Append(L2);
614 }
615
616 //=======================================================================
617 //function : SortOnParameter
618 //purpose  : 
619 //=======================================================================
620 void TopOpeBRepDS_HDataStructure::SortOnParameter
621 (TopOpeBRepDS_ListOfInterference& List) const 
622 {
623   TopOpeBRepDS_PointIterator it(List);
624   if (it.More()) {
625     TopOpeBRepDS_ListOfInterference SList;
626     SortOnParameter(List,SList);
627     List.Assign(SList);
628   }
629 }
630
631 //=======================================================================
632 //function : MinMaxOnParameter
633 //purpose  : 
634 //=======================================================================
635 void TopOpeBRepDS_HDataStructure::MinMaxOnParameter
636 (const TopOpeBRepDS_ListOfInterference& List,
637  Standard_Real& parmin,Standard_Real& parmax) const 
638 {
639   if ( ! List.IsEmpty() ) {
640     Standard_Real parline;
641     parmin = RealLast(); parmax = RealFirst();
642     TopOpeBRepDS_PointIterator it(List);
643     for ( ; it.More(); it.Next()) {
644       parline = it.Parameter();
645       parmin = Min(parmin,parline); 
646       parmax = Max(parmax,parline);
647     } 
648   }
649 }
650
651 //-----------------------------------------------------------------------
652 // Search, among a list of interferences accessed by the iterator <IT>,
653 // a geometry whose 3D point is identical yo the 3D point of a DS point <PDS>.
654 // return True if such an interference has been found, False else.
655 // if True, iterator <IT> points (by the Value() method) on the first 
656 // interference accessing an identical 3D point.
657 //-----------------------------------------------------------------------
658 //=======================================================================
659 //function : ScanInterfList
660 //purpose  : 
661 //=======================================================================
662 Standard_Boolean TopOpeBRepDS_HDataStructure::ScanInterfList
663 (TopOpeBRepDS_ListIteratorOfListOfInterference& IT,
664  const TopOpeBRepDS_Point& PDS) const
665 {
666   for ( ; IT.More(); IT.Next() ) {
667     TopOpeBRepDS_Kind GT = IT.Value()->GeometryType();
668     Standard_Integer  G  = IT.Value()->Geometry();
669     if ( GT == TopOpeBRepDS_POINT ) {
670       const TopOpeBRepDS_Point& OOPDS = myDS.Point(G);
671       Standard_Boolean iseq = PDS.IsEqual(OOPDS);
672       if (iseq) return iseq;
673     }
674     else if ( GT == TopOpeBRepDS_VERTEX ) {
675       TopOpeBRepDS_Point OOPDS(myDS.Shape(G));
676       Standard_Boolean iseq = PDS.IsEqual(OOPDS);
677       if (iseq) return iseq;
678     }
679   }
680   return Standard_False;
681 }
682
683 //=======================================================================
684 //function : GetGeometry
685 //purpose  : 
686 //=======================================================================
687
688 Standard_Boolean TopOpeBRepDS_HDataStructure::GetGeometry
689 (TopOpeBRepDS_ListIteratorOfListOfInterference& IT,
690  const TopOpeBRepDS_Point&                      PDS,
691  Standard_Integer&                              G,
692  TopOpeBRepDS_Kind&                             K) const 
693 {
694   Standard_Boolean found = ScanInterfList(IT,PDS);
695   if (found) {
696     G  = IT.Value()->Geometry();
697     K  = IT.Value()->GeometryType();
698   }
699   return found;
700 }
701
702 #ifdef DEB
703 Standard_IMPORT Standard_Boolean TopOpeBRepDS_GettraceSTRANGE();
704 Standard_IMPORT Standard_Boolean TopOpeBRepDS_GettraceSPSX(const Standard_Integer);
705 static Standard_Boolean TRC(const Standard_Integer SIX) {
706   Standard_Boolean b1 = TopOpeBRepDS_GettraceSTRANGE();
707   Standard_Boolean b2 = TopOpeBRepDS_GettraceSPSX(SIX);
708   return (b1 || b2);
709 }
710 void debstore(const Standard_Integer /*i*/) {}
711 #endif
712
713 //=======================================================================
714 //function : StoreInterference
715 //purpose  : Append an interference I to a list of interference LI
716 //           Append I to the interf. list connected to I Geometry()
717 //=======================================================================
718 void TopOpeBRepDS_HDataStructure::StoreInterference
719 (const Handle(TopOpeBRepDS_Interference)& I,TopOpeBRepDS_ListOfInterference& LI,
720 #ifdef DEB
721  const TCollection_AsciiString& str)
722 #else
723  const TCollection_AsciiString& )
724 #endif
725 {
726 #ifdef DEB
727   const TopOpeBRepDS_Transition& T = I->Transition();
728
729   TopAbs_ShapeEnum sb = T.ShapeBefore();
730   Standard_Integer ib = T.IndexBefore();
731   Standard_Boolean bok = Standard_True;
732   if (ib != 0) {
733     TopAbs_ShapeEnum sbds = myDS.Shape(ib).ShapeType();
734     bok = (sbds == sb);
735   }
736
737   TopAbs_ShapeEnum sa = T.ShapeAfter();
738   Standard_Integer ia = T.IndexAfter();
739   Standard_Boolean aok = Standard_True;
740   if (ia != 0) {
741     TopAbs_ShapeEnum sads = myDS.Shape(ia).ShapeType();
742     aok = (sads == sa);
743   }
744
745   TopOpeBRepDS_Kind ks = I->SupportType();
746   TopAbs_ShapeEnum ss = TopOpeBRepDS::KindToShape(ks);
747   Standard_Integer is = I->Support();
748   Standard_Boolean sok = Standard_True;
749   if ((is != 0) && (ks >= TopOpeBRepDS_EDGE)) {
750     TopAbs_ShapeEnum ssds = myDS.Shape(is).ShapeType();
751     sok = (ssds == ss);
752   }
753   
754   if (!aok) { 
755     if (TRC(ia)) cout<<"HDSstore ia,ib  is "<<ia<<","<<ib<<"  "<<is<<endl;
756     debstore(ia);
757   }
758   if (!bok ) {
759     if (TRC(ib)) cout<<"HDSstore ia,ib  is "<<ia<<","<<ib<<"  "<<is<<endl;
760     debstore(ib);
761   }
762   if (!sok ) {
763     if (TRC(is)) cout<<"HDSstore ia,ib  is "<<ia<<","<<ib<<"  "<<is<<endl;
764     debstore(is);
765   }
766 #endif
767
768   // append I to list LI
769   LI.Append(I);
770
771   Standard_Boolean appendtoG = Standard_False;
772   Standard_Integer G = I->Geometry();
773
774   // append I to list of interference connected to G = I->Geometry()
775   switch (I->GeometryType()) {
776
777   case TopOpeBRepDS_SOLID : case TopOpeBRepDS_FACE : 
778   case TopOpeBRepDS_EDGE : case TopOpeBRepDS_VERTEX :
779 //    appendtoG = Standard_True;
780 //    myDS.ChangeShapeInterferences(G).Append(I);
781     break;
782     
783   case TopOpeBRepDS_SURFACE :
784     appendtoG = Standard_True;
785     myDS.ChangeSurfaceInterferences(G).Append(I);
786     break;
787     
788   case TopOpeBRepDS_CURVE :
789     appendtoG = Standard_True;
790     myDS.ChangeCurveInterferences(G).Append(I);
791     break;
792     
793   case TopOpeBRepDS_POINT :
794 //    appendtoG = Standard_True;
795 //    myDS.ChangePointInterferences(G).Append(I);
796     break;
797   default:
798     break;
799   }
800
801 #ifdef DEB
802   Standard_Boolean trc = ::traceSTORE();
803   if (trc) {
804     cout<<str<<"append "; I->Dump(cout);
805     if (appendtoG) cout<<" and to G"<<G<<" list";
806     cout<<endl;
807   }
808 #endif
809 }
810
811 //=======================================================================
812 //function : StoreInterference
813 //purpose  : 
814 //=======================================================================
815 void TopOpeBRepDS_HDataStructure::StoreInterference
816 (const Handle(TopOpeBRepDS_Interference)& I,const TopoDS_Shape& S,
817 #ifdef DEB
818  const TCollection_AsciiString& str)
819 #else
820  const TCollection_AsciiString& )
821 #endif
822 {
823   Standard_Boolean h = myDS.HasShape(S);
824   if ( !h ) {
825     Standard_ProgramError::Raise("StoreInterference on shape out of DS");
826     return;
827   }
828
829 #ifdef DEB
830   Standard_Boolean trc = ::traceSTORE();
831   TopOpeBRepDS_Kind ks = TopOpeBRepDS::ShapeToKind(S.ShapeType());
832   Standard_Integer is = myDS.Shape(S);
833   if (trc) TopOpeBRepDS::Print(ks,is,cout,str," : ");
834 #endif
835
836   StoreInterference(I,myDS.ChangeShapeInterferences(S));
837 }
838
839 //=======================================================================
840 //function : StoreInterference
841 //purpose  : 
842 //=======================================================================
843
844 void TopOpeBRepDS_HDataStructure::StoreInterference
845 (const Handle(TopOpeBRepDS_Interference)& I,
846  const Standard_Integer IS,
847 #ifdef DEB
848  const TCollection_AsciiString& str)
849 #else
850  const TCollection_AsciiString& )
851 #endif
852 {
853   Standard_Integer n = myDS.NbShapes();
854   if ( IS < 1 || IS > n ) {
855     Standard_ProgramError::Raise("StoreInterference on index out of DS");
856     return;
857   }
858
859 #ifdef DEB
860   Standard_Boolean trc = ::traceSTORE();
861   const TopoDS_Shape& S = Shape(IS);
862   TopOpeBRepDS_Kind ks = TopOpeBRepDS::ShapeToKind(S.ShapeType());
863   if (trc) TopOpeBRepDS::Print(ks,IS,cout,str," : ");
864 #endif
865   
866   StoreInterference(I,myDS.ChangeShapeInterferences(IS));
867 }
868
869 //=======================================================================
870 //function : StoreInterference
871 //purpose  : 
872 //=======================================================================
873 void TopOpeBRepDS_HDataStructure::StoreInterferences
874 (const TopOpeBRepDS_ListOfInterference& LI,const Standard_Integer IS
875 // ,const TCollection_AsciiString& str)
876  ,const TCollection_AsciiString& )
877 {
878   TopOpeBRepDS_ListOfInterference& lids = myDS.ChangeShapeInterferences(IS);
879   TopOpeBRepDS_ListIteratorOfListOfInterference it(LI);
880   for (; it.More(); it.Next()){
881     const Handle(TopOpeBRepDS_Interference)& I = it.Value();
882     StoreInterference(I,lids);
883   }
884 }
885
886 //=======================================================================
887 //function : StoreInterferences
888 //purpose  : 
889 //=======================================================================
890 void TopOpeBRepDS_HDataStructure::StoreInterferences
891 (const TopOpeBRepDS_ListOfInterference& LI,const TopoDS_Shape& S
892 // ,const TCollection_AsciiString& str)
893  ,const TCollection_AsciiString& )
894 {
895   TopOpeBRepDS_ListOfInterference& lids = myDS.ChangeShapeInterferences(S);
896   TopOpeBRepDS_ListIteratorOfListOfInterference it(LI);
897   for (; it.More(); it.Next()){
898     const Handle(TopOpeBRepDS_Interference)& I = it.Value();
899     StoreInterference(I,lids);
900   }
901 }
902
903 //=======================================================================
904 //function : ClearStoreInterferences
905 //purpose  : 
906 //=======================================================================
907 void TopOpeBRepDS_HDataStructure::ClearStoreInterferences
908 (const TopOpeBRepDS_ListOfInterference& LI,const Standard_Integer IS
909 // ,const TCollection_AsciiString& str)
910  ,const TCollection_AsciiString& )
911 {
912   TopOpeBRepDS_ListOfInterference& lids = myDS.ChangeShapeInterferences(IS);
913   lids.Clear();
914   TopOpeBRepDS_ListIteratorOfListOfInterference it(LI);
915   for (; it.More(); it.Next()){
916     const Handle(TopOpeBRepDS_Interference)& I = it.Value();
917     StoreInterference(I,lids);
918   }
919 }
920
921 //=======================================================================
922 //function : ClearStoreInterferences
923 //purpose  : 
924 //=======================================================================
925 void TopOpeBRepDS_HDataStructure::ClearStoreInterferences
926 (const TopOpeBRepDS_ListOfInterference& LI,const TopoDS_Shape& S
927 // ,const TCollection_AsciiString& str)
928  ,const TCollection_AsciiString& )
929 {
930   TopOpeBRepDS_ListOfInterference& lids = myDS.ChangeShapeInterferences(S);
931   lids.Clear();
932   TopOpeBRepDS_ListIteratorOfListOfInterference it(LI);
933   for (; it.More(); it.Next()){
934     const Handle(TopOpeBRepDS_Interference)& I = it.Value();
935     StoreInterference(I,lids);
936   }
937 }