Test for 0022778: Bug in BRepMesh
[occt.git] / src / BooleanOperations / BooleanOperations_ShapesDataStructure.cxx
1 // Created on: 2000-08-10
2 // Created by: Vincent DELOS
3 // Copyright (c) 2000-2012 OPEN CASCADE SAS
4 //
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
9 //
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 //
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
19
20
21
22 #include <BooleanOperations_ShapesDataStructure.ixx>
23
24 #include <stdio.h>
25 #include <stdlib.h>
26
27 #include <gp_Pnt.hxx>
28 #include <Bnd_Box.hxx>
29 #include <TopoDS.hxx>
30 #include <TopoDS_Shape.hxx>
31 #include <TopoDS_TShape.hxx>
32 #include <TopoDS_TVertex.hxx>
33 #include <TopoDS_TEdge.hxx>
34 #include <TopoDS_TWire.hxx>
35 #include <TopoDS_TFace.hxx>
36 #include <TopoDS_TShell.hxx>
37 #include <TopoDS_TSolid.hxx>
38 #include <TopoDS_Iterator.hxx>
39 #include <TopoDS_TCompound.hxx>
40 #include <TopoDS_TCompSolid.hxx>
41 #include <BRep_Tool.hxx>
42 #include <BRepBndLib.hxx>
43 #include <BRepTools_ShapeSet.hxx>
44 #include <TopExp.hxx>
45 #include <TopExp_Explorer.hxx>
46 #include <TopTools_ShapeSet.hxx>
47 #include <TopTools_IndexedMapOfShape.hxx>
48 #include <TopTools_IndexedMapOfOrientedShape.hxx>
49
50 #include <BooleanOperations_OnceExplorer.hxx>
51 #include <BooleanOperations_AncestorsAndSuccessors.hxx>
52 #include <BooleanOperations_AncestorsSeqAndSuccessorsSeq.hxx>
53 #include <BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors.hxx>
54
55 #include <TColStd_SequenceOfInteger.hxx>
56
57 #include <Bnd_Box.hxx>
58 #include <TColStd_MapOfInteger.hxx>
59 #include <BOPTColStd_Dump.hxx>
60
61
62 #ifdef WNT
63 #pragma warning ( disable : 4291 )
64 #endif
65
66 static
67   void Message(const Standard_Integer i);
68
69 const static Standard_Integer AddedValue=20;
70
71 //===========================================================================
72 //function : BooleanOperations_ShapesDataStructure
73 //purpose  : creator
74 //===========================================================================
75   BooleanOperations_ShapesDataStructure::BooleanOperations_ShapesDataStructure():
76   myListOfShapeAndInterferences(NULL),
77   myNumberOfShapesOfTheObject(0),
78   myNumberOfShapesOfTheTool(0),
79   myNumberOfInsertedShapes(0),
80   myLength(0),
81   myNbEdges(0)
82 {
83   //printf("-BOPDS_ShapesDataStructure CREATE:%x\n", (int)this);
84 }
85 //===========================================================================
86 //function : BooleanOperations_ShapesDataStructure
87 //purpose  : creator
88 //===========================================================================
89   BooleanOperations_ShapesDataStructure::BooleanOperations_ShapesDataStructure(const TopoDS_Shape& Object,
90                                                                                const TopoDS_Shape& Tool)
91 :
92   myListOfShapeAndInterferences(NULL),
93   myNumberOfShapesOfTheObject(0),
94   myNumberOfShapesOfTheTool(0),
95   myNumberOfInsertedShapes(0),
96   myLength(0),
97   myObject(Object),
98   myTool(Tool),
99   myNbEdges(0)
100 {
101   //printf(" BOPDS_ShapesDataStructure CREATE:%x\n", (int)this);
102   Standard_Integer i, Average;//, aNbShapes;
103   BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors IndDatMapTool;
104   BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors IndDatMapObject;
105
106   FillIndexedMapOfShapesAncestorsAndSuccessors(Object,IndDatMapObject);
107   FillIndexedMapOfShapesAncestorsAndSuccessors(Tool,IndDatMapTool);
108   myNumberOfShapesOfTheObject = IndDatMapObject.Extent();
109   myNumberOfShapesOfTheTool = IndDatMapTool.Extent();
110   Average = (myNumberOfShapesOfTheTool+myNumberOfShapesOfTheObject)/2;
111   myLength = myNumberOfShapesOfTheTool+myNumberOfShapesOfTheObject+Average;
112   /////
113   myListOfShapeAndInterferences = (BooleanOperations_PShapeAndInterferences)
114     Standard::Allocate(myLength*sizeof(BooleanOperations_ShapeAndInterferences));
115   //
116   // Inserting the shapes into the DS 
117   // Object
118   for (i=1; i<=myNumberOfShapesOfTheObject; i++){
119     const BooleanOperations_AncestorsSeqAndSuccessorsSeq& theAncestorsSeqAndSuccessorsSeq =
120       IndDatMapObject.FindFromIndex(i);
121     const TopoDS_Shape& theShape = IndDatMapObject.FindKey(i);
122     InsertShapeAndAncestorsSuccessors(theShape, theAncestorsSeqAndSuccessorsSeq, 0);
123   }
124   // Tool
125   for (i=1;i<=myNumberOfShapesOfTheTool;i++){
126     const BooleanOperations_AncestorsSeqAndSuccessorsSeq& theAncestorsSeqAndSuccessorsSeq =
127       IndDatMapTool.FindFromIndex(i);
128     const TopoDS_Shape& theShape = IndDatMapTool.FindKey(i);
129     InsertShapeAndAncestorsSuccessors(theShape,theAncestorsSeqAndSuccessorsSeq,myNumberOfShapesOfTheObject);
130   }
131   //
132   // Fill the myShapeIndexMapObj
133   for (i=1; i<=myNumberOfShapesOfTheObject; ++i){
134     const TopoDS_Shape& aS=GetShape(i);
135     myShapeIndexMapObj.Add(aS, i);
136   }
137   //
138   //
139   // Fill the myShapeIndexMapObj
140   Standard_Integer iFirst, iLast;
141   //
142   ToolRange (iFirst, iLast);  
143   for (i=iFirst; i<=iLast; ++i){
144     const TopoDS_Shape& aS=GetShape(i);
145     myShapeIndexMapTool.Add(aS, i);
146   }
147   //
148   iLast=myNumberOfShapesOfTheObject+myNumberOfShapesOfTheTool;
149   //
150   // Fill myRefEdges
151   myRefEdges.Resize(iLast);
152
153   for (i=1; i<=iLast; ++i) {
154     const TopoDS_Shape& aS=Shape(i);
155     myRefEdges(i)=0;
156     if (aS.ShapeType()==TopAbs_EDGE) {
157       myNbEdges++;
158       myRefEdges(i)=myNbEdges;
159     }
160   }
161 }
162 //modified by NIZNHY-PKV Wed Feb  2 11:34:07 2005f
163 //===========================================================================
164 //function : ~
165 //purpose  : 
166 //===========================================================================
167   BooleanOperations_ShapesDataStructure::~BooleanOperations_ShapesDataStructure()
168 {
169   //printf(" BOPDS_ShapesDataStructure DELETE:%x\n", (int)this);
170   Destroy();
171 }
172 //modified by NIZNHY-PKV Wed Feb  2 11:34:12 2005t
173 //===========================================================================
174 //function : BooleanOperations_ShapesDataStructure
175 //purpose  : destructor
176 //===========================================================================
177   void BooleanOperations_ShapesDataStructure::Destroy()
178 {
179   Standard_Integer i;
180
181   for (i=0;i<myNumberOfInsertedShapes;i++) {
182     myListOfShapeAndInterferences[i].~BooleanOperations_ShapeAndInterferences();
183   }
184   
185   //modified by NIZNHY-PKV Wed Feb  2 12:31:28 2005f
186   //printf(" ~     :%x, now:%x\n", 
187         // (int)this, 
188         // (int)myListOfShapeAndInterferences);
189   //modified by NIZNHY-PKV Wed Feb  2 12:31:31 2005t
190   //
191   Standard::Free((Standard_Address&)myListOfShapeAndInterferences);
192 }
193 //===========================================================================
194 //function : ShapeIndexMap
195 //purpose  : 
196 //===========================================================================
197   const BooleanOperations_IndexedDataMapOfShapeInteger& 
198     BooleanOperations_ShapesDataStructure::ShapeIndexMap(const Standard_Integer iRank)const
199 {
200   if (iRank == 1)
201     return myShapeIndexMapObj;
202   else 
203     return myShapeIndexMapTool;
204 }
205 //===========================================================================
206 //function : ShapeIndex
207 //purpose  : 
208 //===========================================================================
209   Standard_Integer BooleanOperations_ShapesDataStructure::ShapeIndex(const TopoDS_Shape& aS,
210                                                                      const Standard_Integer iRank) const
211 {
212   Standard_Integer anIndex=0;
213   const BooleanOperations_IndexedDataMapOfShapeInteger& aMap=ShapeIndexMap(iRank);
214   if (aMap.Contains(aS)) {
215     anIndex=aMap.FindFromKey(aS);
216     return anIndex;
217   }
218   return anIndex;
219 }
220
221 //===========================================================================
222 //function : FillIndexedMapOfShapesAncestorsAndSuccessors
223 //purpose  : 
224 //===========================================================================
225   void BooleanOperations_ShapesDataStructure::FillIndexedMapOfShapesAncestorsAndSuccessors
226   (const TopoDS_Shape& Sha,
227    BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& IndDatMap) const
228 {
229   Standard_Integer TotalNumberOfShapes = 1;
230   BooleanOperations_AncestorsSeqAndSuccessorsSeq theAncestorAndSuccessor;
231   IndDatMap.Add(Sha,theAncestorAndSuccessor);
232   this->FindSubshapes(Sha,TotalNumberOfShapes,IndDatMap);
233   //
234   Standard_Integer aNumberOfShapes = IndDatMap.Extent();
235   for(Standard_Integer i=1; i <= aNumberOfShapes; i++) {
236     const BooleanOperations_AncestorsSeqAndSuccessorsSeq& anAncestorAndSuccessorSeq1=IndDatMap(i);
237     TColStd_MapOfInteger aMapOfIndices;
238     for(Standard_Integer j = 1; j <= anAncestorAndSuccessorSeq1.NumberOfSuccessors(); j++) {
239       Standard_Integer aShapeIndex = anAncestorAndSuccessorSeq1.GetSuccessor(j);
240       if(aMapOfIndices.Add(aShapeIndex)) {
241         BooleanOperations_AncestorsSeqAndSuccessorsSeq& anAncestorAndSuccessorSeq2 = 
242           IndDatMap.ChangeFromIndex(aShapeIndex);
243         anAncestorAndSuccessorSeq2.SetNewAncestor(i);
244       }
245     }
246   }
247 }
248 //===========================================================================
249 //function : FindSubshapes
250 //purpose  : 
251 //===========================================================================
252   void BooleanOperations_ShapesDataStructure::FindSubshapes
253   (const TopoDS_Shape& Sha,
254    Standard_Integer& TotalNumberOfShapes,
255    BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& IndDatMap) const
256 {
257 // 
258   TopoDS_Iterator anIt(Sha, Standard_True);//Standard_False);
259   Standard_Integer anIndexOfShape = IndDatMap.FindIndex(Sha);
260   BooleanOperations_AncestorsSeqAndSuccessorsSeq& AncSucOfShape=IndDatMap.ChangeFromIndex(anIndexOfShape);
261   for(; anIt.More(); anIt.Next()) {
262     const TopoDS_Shape& aSubShape = anIt.Value();
263     Standard_Integer aSubShapeIndex = 0;
264     Standard_Boolean isNewSubShape = Standard_False;
265     if(!IndDatMap.Contains(aSubShape)) {
266       isNewSubShape = Standard_True;
267       BooleanOperations_AncestorsSeqAndSuccessorsSeq anAncestorAndSuccessorSeq;
268       aSubShapeIndex = IndDatMap.Add(aSubShape, anAncestorAndSuccessorSeq);
269     }
270     else {
271       aSubShapeIndex = IndDatMap.FindIndex(aSubShape);
272     }
273     AncSucOfShape.SetNewSuccessor(aSubShapeIndex);
274     AncSucOfShape.SetNewOrientation(aSubShape.Orientation());
275     //
276     if(isNewSubShape && (aSubShape.ShapeType() != TopAbs_VERTEX)) {
277       FindSubshapes(aSubShape, TotalNumberOfShapes, IndDatMap);
278     }
279   }
280   TotalNumberOfShapes = IndDatMap.Extent();
281 }
282 //===========================================================================
283 //function : ReInit
284 //purpose  : 
285 //===========================================================================
286   void BooleanOperations_ShapesDataStructure::ReInit() 
287 {
288   Standard_Integer i,NewLength;
289   BooleanOperations_PShapeAndInterferences NewListOfShapeAndInterferences;
290
291   NewLength = AddedValue + myLength;
292   NewListOfShapeAndInterferences = (BooleanOperations_PShapeAndInterferences)
293     Standard::Allocate(NewLength*sizeof(BooleanOperations_ShapeAndInterferences));
294   
295   //modified by NIZNHY-PKV Wed Feb  2 12:16:51 2005f
296   //printf(" ReInit:%x, was:%x, now:%x\n", 
297         // (int)this, 
298         // (int)myListOfShapeAndInterferences,
299         // (int)NewListOfShapeAndInterferences);
300   //modified by NIZNHY-PKV Wed Feb  2 12:16:55 2005t
301   
302   for (i=0;i<myNumberOfInsertedShapes;i++)    {
303     new (&NewListOfShapeAndInterferences[i])
304       BooleanOperations_ShapeAndInterferences(myListOfShapeAndInterferences[i]);
305     myListOfShapeAndInterferences[i].myShape.Nullify();
306   }
307
308   if (myLength>0) {
309     Standard::Free((Standard_Address&) myListOfShapeAndInterferences);
310   }
311
312   myLength = NewLength;
313   myListOfShapeAndInterferences = NewListOfShapeAndInterferences;
314 }
315 //===========================================================================
316 //function : InsertShapeAndAncestorsSuccessors
317 //purpose  : 
318 //===========================================================================
319 void BooleanOperations_ShapesDataStructure::InsertShapeAndAncestorsSuccessors
320   (const TopoDS_Shape& S,
321    const BooleanOperations_AncestorsSeqAndSuccessorsSeq& AncSuc,
322    const Standard_Integer shift)
323 {
324   if ((myNumberOfInsertedShapes<0)||(myNumberOfInsertedShapes>myLength)) {
325     Message(1);
326   }
327   //
328   Bnd_Box B;
329   //
330   if (myNumberOfInsertedShapes==myLength) {
331     ReInit();
332   }
333   
334   new (&(myListOfShapeAndInterferences[myNumberOfInsertedShapes].myShape)) TopoDS_Shape(S);
335   // Compute and insert the bounding box of <myShape>.
336   if (!S.IsNull()) {
337     BRepBndLib::Add(S,B);
338   }
339   new (&(myListOfShapeAndInterferences[myNumberOfInsertedShapes].myBoundingBox)) 
340     Bnd_Box(B);
341   new (&(myListOfShapeAndInterferences[myNumberOfInsertedShapes].myAncestorsAndSuccessors)) 
342     BooleanOperations_AncestorsAndSuccessors(AncSuc,shift);
343
344   myListOfShapeAndInterferences[myNumberOfInsertedShapes].myState = BooleanOperations_UNKNOWN;
345   myNumberOfInsertedShapes++;
346 }
347
348 //===========================================================================
349 //function : GetShape
350 //purpose  : 
351 //===========================================================================
352   const TopoDS_Shape& BooleanOperations_ShapesDataStructure::GetShape(const Standard_Integer index) const
353 {
354   if ((index<1)||(index>myNumberOfInsertedShapes))    {
355     Message(1);
356   }
357   return myListOfShapeAndInterferences[index-1].GetShape();
358 }
359 //===========================================================================
360 //function : Shape
361 //purpose  : 
362 //===========================================================================
363   const TopoDS_Shape& BooleanOperations_ShapesDataStructure::Shape(const Standard_Integer index) const
364 {
365   return GetShape(index);
366 }
367 //===========================================================================
368 //function : GetShapeType
369 //purpose  : 
370 //===========================================================================
371   TopAbs_ShapeEnum BooleanOperations_ShapesDataStructure::GetShapeType(const Standard_Integer index) const
372 {
373   if ((index<1)||(index>myNumberOfInsertedShapes))    {
374     Message(1);
375   }
376   return myListOfShapeAndInterferences[index-1].GetShapeType();
377 }
378 //===========================================================================
379 //function : GetBoundingBox
380 //purpose  : 
381 //===========================================================================
382   const Bnd_Box& BooleanOperations_ShapesDataStructure::GetBoundingBox(const Standard_Integer index) const
383 {
384   if ((index<1)||(index>myNumberOfInsertedShapes))    {
385     Message(1);
386   }
387   return myListOfShapeAndInterferences[index-1].GetBoundingBox();
388 }
389 //===========================================================================
390 //function : GetState
391 //purpose  : 
392 //===========================================================================
393   BooleanOperations_StateOfShape BooleanOperations_ShapesDataStructure::GetState(const Standard_Integer index) const
394 {
395   if ((index<1)||(index>myNumberOfInsertedShapes))    {
396     Message(1);
397   }
398   return myListOfShapeAndInterferences[index-1].GetState();
399 }
400 //===========================================================================
401 //function : SetState
402 //purpose  : 
403 //===========================================================================
404   void BooleanOperations_ShapesDataStructure::SetState(const Standard_Integer index,
405                                                        const BooleanOperations_StateOfShape theState) 
406 {
407   if ((index<1)||(index>myNumberOfInsertedShapes)) {
408     Message(1);
409   }
410   myListOfShapeAndInterferences[index-1].SetState(theState);
411 }
412
413 //===========================================================================
414 //function : NumberOfAncestors
415 //purpose  : 
416 //===========================================================================
417   Standard_Integer 
418     BooleanOperations_ShapesDataStructure::NumberOfAncestors(const Standard_Integer index) const
419 {
420   if ((index<1)||(index>myNumberOfInsertedShapes))  {
421     Message(1);
422   }
423   return myListOfShapeAndInterferences[index-1].NumberOfAncestors();
424 }
425 //===========================================================================
426 //function : NumberOfSuccessors
427 //purpose  : 
428 //===========================================================================
429   Standard_Integer 
430     BooleanOperations_ShapesDataStructure::NumberOfSuccessors(const Standard_Integer index) const
431 {
432   if ((index<1)||(index>myNumberOfInsertedShapes))    {
433     Message(1);
434   }
435   return myListOfShapeAndInterferences[index-1].NumberOfSuccessors();
436 }
437 //===========================================================================
438 //function : GetAncestor
439 //purpose  : 
440 //===========================================================================
441  Standard_Integer 
442   BooleanOperations_ShapesDataStructure::GetAncestor(const Standard_Integer index,
443                                                        const Standard_Integer ancestorNumber) const
444 {
445   if ((index<1)||
446       (index>myNumberOfInsertedShapes)||
447       (ancestorNumber<1)||
448       (ancestorNumber>NumberOfAncestors(index))) {
449     Message(1);
450   }
451   return myListOfShapeAndInterferences[index-1].GetAncestor(ancestorNumber);
452 }
453 //===========================================================================
454 //function : GetSuccessor
455 //purpose  : 
456 //===========================================================================
457   Standard_Integer 
458     BooleanOperations_ShapesDataStructure::GetSuccessor(const Standard_Integer index,
459                                                         const Standard_Integer successorNumber) const
460 {
461   if ((index<1)||(index>myNumberOfInsertedShapes)||(successorNumber<1)||(successorNumber>NumberOfSuccessors(index)))    {
462     Message(1);
463   }
464   if (GetShapeType(index) == TopAbs_VERTEX)  {
465     Message(2);
466   }
467   return myListOfShapeAndInterferences[index-1].GetSuccessor(successorNumber);
468 }
469 //===========================================================================
470 //function : GetAncestors
471 //purpose  : returns the array of ancestors
472 //===========================================================================
473  void 
474    BooleanOperations_ShapesDataStructure::GetAncestors(const Standard_Integer index,
475                                                         Standard_Address& theArrayOfAncestors,
476                                                         Standard_Integer& ancestorsNumber) const
477 {
478   if ((index<1)||(index>myNumberOfInsertedShapes))    {
479     Message(1);
480   }
481   myListOfShapeAndInterferences[index-1].GetAncestors(theArrayOfAncestors,ancestorsNumber);
482 }
483
484  
485 //===========================================================================
486 //function : GetSuccessors
487 //purpose  : returns the array of successors
488 //===========================================================================
489   void 
490     BooleanOperations_ShapesDataStructure::GetSuccessors(const Standard_Integer index,
491                                                          Standard_Address& theArrayOfSuccessors,
492                                                          Standard_Integer& successorsNumber) const
493 {
494   if ((index<1)||(index>myNumberOfInsertedShapes))  {
495     Message(1);
496   }
497   if (GetShapeType(index) == TopAbs_VERTEX) {
498     Message(2);
499   }
500   myListOfShapeAndInterferences[index-1].GetSuccessors(theArrayOfSuccessors,successorsNumber);
501 }
502
503 //
504 //===========================================================================
505 //function : NumberOfShapesOfTheObject
506 //purpose  : 
507 //===========================================================================
508   Standard_Integer BooleanOperations_ShapesDataStructure::NumberOfShapesOfTheObject()const
509 {
510   return myNumberOfShapesOfTheObject;
511 }
512 //===========================================================================
513 //function : NumberOfShapesOfTheTool
514 //purpose  : 
515 //===========================================================================
516   Standard_Integer BooleanOperations_ShapesDataStructure::NumberOfShapesOfTheTool()const
517 {
518   return myNumberOfShapesOfTheTool;
519 }
520
521 //
522
523 //===========================================================================
524 //function : NumberOfInsertedShapes
525 //purpose  : 
526 //===========================================================================
527   Standard_Integer BooleanOperations_ShapesDataStructure::NumberOfInsertedShapes()const
528 {
529   return myNumberOfInsertedShapes;
530 }
531 //===========================================================================
532 //function : NumberOfNewShapes
533 //purpose  : 
534 //===========================================================================
535   Standard_Integer BooleanOperations_ShapesDataStructure::NumberOfNewShapes()const
536 {
537   Standard_Integer aNb;
538
539   aNb=NumberOfSourceShapes();
540   aNb=myNumberOfInsertedShapes-aNb;
541   return aNb;
542 }
543
544 //===========================================================================
545 //function : NumberOfSourceShapes
546 //purpose  : 
547 //===========================================================================
548   Standard_Integer BooleanOperations_ShapesDataStructure::NumberOfSourceShapes()const
549 {
550   Standard_Integer aNb;
551   aNb=myNumberOfShapesOfTheTool+myNumberOfShapesOfTheObject;
552   return aNb;
553 }
554
555 //===========================================================================
556 //function : IsNewShape
557 //purpose  : 
558 //===========================================================================
559   Standard_Boolean 
560     BooleanOperations_ShapesDataStructure::IsNewShape(const Standard_Integer anIndex)const
561 {
562   Standard_Boolean aFlag;
563   aFlag=anIndex>NumberOfSourceShapes();
564   return aFlag;
565 }
566
567
568 //===========================================================================
569 //function : Line
570 //purpose  : 
571 //===========================================================================
572   const  BooleanOperations_ShapeAndInterferences& 
573     BooleanOperations_ShapesDataStructure::Line(const Standard_Integer index) const
574 {
575   if ((index<1)||(index>myNumberOfInsertedShapes)) {
576     Message(1);
577   }
578   return myListOfShapeAndInterferences[index-1];
579 }
580 //===========================================================================
581 //function : Object
582 //purpose  : 
583 //===========================================================================
584   const TopoDS_Shape& BooleanOperations_ShapesDataStructure::Object()const 
585 {
586   return myObject;
587 }
588 //===========================================================================
589 //function : Tool
590 //purpose  : 
591 //===========================================================================
592   const TopoDS_Shape& BooleanOperations_ShapesDataStructure::Tool()const 
593 {
594   return myTool;
595 }
596 //===========================================================================
597 //function : ObjectRange
598 //purpose  : 
599 //===========================================================================
600   void BooleanOperations_ShapesDataStructure::ObjectRange(Standard_Integer& iFirst,
601                                                           Standard_Integer& iLast)const 
602 {
603   iFirst=1;
604   iLast=NumberOfShapesOfTheObject();
605 }
606
607 //===========================================================================
608 //function : ToolRange
609 //purpose  : 
610 //===========================================================================
611   void BooleanOperations_ShapesDataStructure::ToolRange(Standard_Integer& iFirst,
612                                                         Standard_Integer& iLast)const 
613 {
614   iFirst=NumberOfShapesOfTheObject()+1;
615   iLast=NumberOfShapesOfTheObject()+NumberOfShapesOfTheTool();
616 }
617 //===========================================================================
618 //function : Rank
619 //purpose  : 
620 //===========================================================================
621   Standard_Integer BooleanOperations_ShapesDataStructure::Rank(const Standard_Integer nS)const
622                                                         
623 {
624   if (IsNewShape(nS)) {
625     return 3;
626   }
627   
628   Standard_Integer iFirst, iLast;
629   
630   ObjectRange(iFirst, iLast);
631   if (nS >= iFirst && nS <= iLast){
632     return 1;
633   }
634   
635   ToolRange(iFirst, iLast);
636   if (nS >= iFirst && nS <= iLast){
637     return 2;
638   }
639   return 0; // ?
640 }
641
642 //===========================================================================
643 //function : RefEdge
644 //purpose  : 
645 //===========================================================================
646   Standard_Integer 
647     BooleanOperations_ShapesDataStructure::RefEdge(const Standard_Integer anIndex)const
648 {
649   Standard_Integer iRefEdge;
650   iRefEdge=myRefEdges(anIndex);
651   return iRefEdge;
652 }
653
654 //===========================================================================
655 //function : NbEdges
656 //purpose  : 
657 //===========================================================================
658   Standard_Integer BooleanOperations_ShapesDataStructure::NbEdges()const 
659 {
660   return myNbEdges;
661 }
662
663
664 //===========================================================================
665 //function : Message
666 //purpose  : 
667 //===========================================================================
668 void Message(const Standard_Integer i)
669 {
670   char buf[256];
671   sprintf(buf, " BooleanOperations_ShapesDataStructure:: ");
672   BOPTColStd_Dump::PrintMessage(buf);
673
674   switch (i) {
675   case 1:
676     sprintf (buf, "index is out of range\n");
677     break;
678   case 2:
679     sprintf (buf, "incorrect Type\n");
680     break;
681   default: 
682     sprintf(buf, "undefined message\n");
683     break;
684   }
685   BOPTColStd_Dump::PrintMessage(buf);
686   Standard_DomainError::Raise("Message");
687 }
688
689 //===========================================================================
690 //function : Dump
691 //purpose  : 
692 //===========================================================================
693   void BooleanOperations_ShapesDataStructure::Dump(Standard_OStream& S) const
694 {
695   
696   Standard_Integer i,j;
697   TopAbs_ShapeEnum T;
698   //ZZ gp_Pnt thePoint;
699   BooleanOperations_StateOfShape St;
700
701   S<<endl<<"BooleanOperations_ShapesDataStructure::Dump()"<<endl;
702   S<<endl<<"myLength                    = "<<myLength;
703   S<<endl<<"myNumberOfInsertedShapes    = "<<myNumberOfInsertedShapes;
704   S<<endl<<"myNumberOfShapesOfTheTool   = "<<myNumberOfShapesOfTheTool;
705   S<<endl<<"myNumberOfShapesOfTheObject = "<<myNumberOfShapesOfTheObject<<endl;
706
707   for (i=1;i<=myNumberOfInsertedShapes;i++)
708     {
709       S << "---";
710       if (i < 10)   cout<< " ";
711       if (i < 100)  cout<< " ";
712       if (i < 1000) cout<< " ";
713       cout << i << " --- ";
714       T = GetShape(i).ShapeType();
715       switch(T)
716         {
717         case TopAbs_VERTEX :
718           S << "VERTEX   ";
719           break;
720           
721         case TopAbs_EDGE :
722           S << "EDGE     ";
723           break;
724           
725         case TopAbs_WIRE :
726           S << "WIRE     ";
727           break;
728           
729         case TopAbs_FACE :
730           S << "FACE     ";
731           break;
732           
733         case TopAbs_SHELL :
734           S << "SHELL    ";
735           break;
736           
737         case TopAbs_SOLID :
738           S << "SOLID    ";
739           break;
740           
741         case TopAbs_COMPSOLID :
742           S << "COMPSOLID";
743           break;
744           
745         case TopAbs_COMPOUND :
746           S << "COMPOUND ";
747           break;
748           
749         case TopAbs_SHAPE :
750           S << "SHAPE";
751           break;
752         }
753       St = GetState(i);
754       switch(St)
755         {
756         case BooleanOperations_IN :
757           S << "IN          ";
758           break;
759           
760         case BooleanOperations_OUT :
761           S << "OUT         ";
762           break;
763           
764         case BooleanOperations_UNKNOWN :
765           S << "UNKNOWN     ";
766           break;
767           
768         case BooleanOperations_ON :
769           S << "ON          ";
770           break;
771           
772         case BooleanOperations_INOROUT :
773           S << "INOROUT     ";
774           break;
775           
776         case BooleanOperations_INTERSECTED :
777           S << "INTERSECTED ";
778           break;
779
780         }
781       
782       Standard_Real a,b,c,d,e,f;
783       GetBoundingBox(i).Get(a,b,c,d,e,f);
784       S << " @ " << a << " " << b << " " << c << " " << d << " " << e << " " << f << " @ " ;
785       
786       S << " Ancestors :" ;
787       for (j=1;j<=NumberOfAncestors(i);j++)
788         S << " " << GetAncestor(i,j);
789       S << " Successors :" ;
790       for (j=1;j<=NumberOfSuccessors(i);j++)
791         S << " " << GetSuccessor(i,j);
792       /*
793       S << " INTERF = " ;
794       for (j=1;j<=NumberOfInterferences(i);j++)
795         S << " " << GetIntersectedShape(i,j) << " " << GetIntersectionResult(i,j) << " #";
796       */
797       S  << endl;
798     }
799   S  << endl;
800 }
801
802
803 //===========================================================================
804 //function : LightDump
805 //purpose  : 
806 //===========================================================================
807   void BooleanOperations_ShapesDataStructure::LightDump(Standard_OStream& S) const
808 {
809   Standard_Real a,b,c,d,e,f;
810   Standard_Integer i;
811   TopAbs_ShapeEnum T;
812
813   S<<endl<<"BooleanOperations_ShapesDataStructure::Dump()"<<endl;
814   S<<endl<<"myLength                    = "<<myLength;
815   S<<endl<<"myNumberOfInsertedShapes    = "<<myNumberOfInsertedShapes;
816   S<<endl<<"myNumberOfShapesOfTheTool   = "<<myNumberOfShapesOfTheTool;
817   S<<endl<<"myNumberOfShapesOfTheObject = "<<myNumberOfShapesOfTheObject<<endl;
818
819   for (i=1;i<=myNumberOfInsertedShapes;i++)
820     {
821       S << "---";
822       if (i < 10)   cout<< " ";
823       if (i < 100)  cout<< " ";
824       if (i < 1000) cout<< " ";
825       cout << i << " --- ";
826       T = GetShape(i).ShapeType();
827       switch(T)
828         {
829         case TopAbs_VERTEX :
830           S << "VERTEX   ";
831           break;
832           
833         case TopAbs_EDGE :
834           S << "EDGE     ";
835           break;
836           
837         case TopAbs_WIRE :
838           S << "WIRE     ";
839           break;
840           
841         case TopAbs_FACE :
842           S << "FACE     ";
843           break;
844           
845         case TopAbs_SHELL :
846           S << "SHELL    ";
847           break;
848           
849         case TopAbs_SOLID :
850           S << "SOLID    ";
851           break;
852           
853         case TopAbs_COMPSOLID :
854           S << "COMPSOLID";
855           break;
856           
857         case TopAbs_COMPOUND :
858           S << "COMPOUND ";
859           break;
860           
861         case TopAbs_SHAPE :
862           S << "SHAPE";
863           break;
864         }
865       GetBoundingBox(i).Get(a,b,c,d,e,f);
866       S << " @ " << a << " " << b << " " << c << " " << d << " " << e << " " << f << endl;
867     }
868   S  << endl;
869 }
870 //===========================================================================
871 //function : GetOrientation
872 //purpose  : 
873 //===========================================================================
874   TopAbs_Orientation 
875     BooleanOperations_ShapesDataStructure::GetOrientation(const Standard_Integer index,
876                                                           const Standard_Integer successorNumber) const
877 {
878   if ((index<1)||(index>myNumberOfInsertedShapes)||(successorNumber<1)||(successorNumber>NumberOfSuccessors(index)))  {
879     Message(1);
880   }
881   if (GetShapeType(index) == TopAbs_VERTEX)   {
882     Message(2);
883   }
884   return myListOfShapeAndInterferences[index-1].GetOrientation(successorNumber);
885 }
886 //===========================================================================
887 //function : GetOrientations
888 //purpose  : returns the array of orientations
889 //===========================================================================
890  void 
891    BooleanOperations_ShapesDataStructure::GetOrientations(const Standard_Integer index,
892                                                            Standard_Address& theArrayOfOrientations,
893                                                            Standard_Integer& orientationsNumber) const
894 {
895   if ((index<1)||(index>myNumberOfInsertedShapes))    {
896     Message(1);
897   }
898   if (GetShapeType(index) == TopAbs_VERTEX)  {
899     Message(2);
900   }
901   myListOfShapeAndInterferences[index-1].GetOrientations(theArrayOfOrientations,orientationsNumber);
902 }
903 //modified by NIZNHY-PKV Wed Feb  2 14:44:08 2005f
904 /*
905 #ifdef WNT
906 #pragma warning ( default : 4291 )
907 #endif
908 */
909 /*
910 //===========================================================================
911 //function : InsertInterference
912 //purpose  : 
913 //===========================================================================
914   void BooleanOperations_ShapesDataStructure::InsertInterference(const Standard_Integer index,
915                                                                  const BooleanOperations_InterferenceResult&)// IR) 
916 {
917   if ((index<1)||(index>myNumberOfInsertedShapes))    {
918     Message(1);
919   }
920 //modified by NIZNHY-PKV Wed Feb  2 13:02:32 2005ft
921 //  myListOfShapeAndInterferences[index-1].SetInterference(IR);
922 }
923 //===========================================================================
924 //function : GetInterference
925 //purpose  : 
926 //===========================================================================
927   const BooleanOperations_InterferenceResult& 
928     BooleanOperations_ShapesDataStructure::GetInterference(const Standard_Integer index,
929                                                            const Standard_Integer interfNumber) const
930 {
931   
932   if ((index<1)||(index>myNumberOfInsertedShapes))    {
933     Message(1);
934   }
935   //modified by NIZNHY-PKV Wed Feb  2 13:04:12 2005f
936   //return myListOfShapeAndInterferences[index-1].GetInterference(interfNumber);
937   
938   static BooleanOperations_InterferenceResult aIR;
939   return aIR;
940   //modified by NIZNHY-PKV Wed Feb  2 13:04:22 2005t
941 }
942  
943 //===========================================================================
944 //function : GetIntersectedShape
945 //purpose  : 
946 //===========================================================================
947   Standard_Integer 
948     BooleanOperations_ShapesDataStructure::GetIntersectedShape(const Standard_Integer index,
949                                                                const Standard_Integer interfNumber) const
950 {
951   if ((index<1)||(index>myNumberOfInsertedShapes))    {
952     Message(1);
953   }
954   //modified by NIZNHY-PKV Wed Feb  2 13:04:39 2005f
955   //return myListOfShapeAndInterferences[index-1].GetIntersectedShape(interfNumber);
956   return 0;
957   //modified by NIZNHY-PKV Wed Feb  2 13:04:45 2005t
958 }
959 //===========================================================================
960 //function : GetIntersectionResult
961 //purpose  : 
962 //===========================================================================
963   Standard_Integer 
964     BooleanOperations_ShapesDataStructure::GetIntersectionResult (const Standard_Integer index,
965                                                                   const Standard_Integer interfNumber) const
966 {
967   if ((index<1)||(index>myNumberOfInsertedShapes))    {
968     Message(1);
969   }
970   //modified by NIZNHY-PKV Wed Feb  2 13:05:36 2005f
971   //return myListOfShapeAndInterferences[index-1].GetIntersectionResult(interfNumber);
972   return 0;
973   //modified by NIZNHY-PKV Wed Feb  2 13:04:45 2005t
974 }
975 //===========================================================================
976 //function : NumberOfInterferences
977 //purpose  : 
978 //===========================================================================
979  Standard_Integer 
980     BooleanOperations_ShapesDataStructure::NumberOfInterferences(const Standard_Integer index) const
981 {
982   if ((index<1)||(index>myNumberOfInsertedShapes))    {
983     Message(1);
984   }
985   //modified by NIZNHY-PKV Wed Feb  2 13:06:43 2005f
986   //return myListOfShapeAndInterferences[index-1].NumberOfInterferences();
987   return 0;
988   //modified by NIZNHY-PKV Wed Feb  2 13:04:45 2005t
989 }
990
991 */
992 //modified by NIZNHY-PKV Wed Feb  2 14:44:11 2005t