Salome HOME
155b9b8435dffef25387eaa2c50f202835411d48
[modules/geom.git] / NMTTools_IteratorOfCoupleOfShape.cxx
1 // File:        NMTTools_IteratorOfCoupleOfShape.cxx
2 // Created:     Thu Dec  4 17:00:03 2003
3 // Author:      Peter KURNEV
4 //              <pkv@irinox>
5
6
7 #include <NMTTools_IteratorOfCoupleOfShape.ixx>
8 #include <Standard_NoSuchObject.hxx>
9 #include <NMTDS_ShapesDataStructure.hxx>
10 #include <BOPTools_CoupleOfInteger.hxx>
11 #include <NMTDS_CArray1OfIndexRange.hxx>
12 #include <BooleanOperations_ShapesDataStructure.hxx>
13
14 //=======================================================================
15 // function: 
16 // purpose: 
17 //=======================================================================
18   NMTTools_IteratorOfCoupleOfShape::NMTTools_IteratorOfCoupleOfShape()
19 :
20   BOPTools_IteratorOfCoupleOfShape()
21 {
22   myIndex1=0;
23   myIndex2=0;
24   myWithSubShapeFlag=Standard_False;
25 }
26 //=======================================================================
27 // function: SetDS
28 // purpose: 
29 //=======================================================================
30   void NMTTools_IteratorOfCoupleOfShape::SetDS(const NMTDS_PShapesDataStructure& PDS)
31 {
32   myPNMTPS=PDS;
33   SetDataStructure(myPNMTPS);
34 }
35 //=======================================================================
36 // function: Initialize
37 // purpose: 
38 //=======================================================================
39   void NMTTools_IteratorOfCoupleOfShape::Initialize(const TopAbs_ShapeEnum Type1,
40                                                     const TopAbs_ShapeEnum Type2)
41 {
42   if(myPDS==NULL) {
43     Standard_NoSuchObject::Raise("NMTTools_IteratorOfCoupleOfShape::Initialize: myPDS==NULL");
44   }
45   //
46   myType1 = Type1;
47   myType2 = Type2;
48   myCurrentIndex1 = -1;
49   myCurrentIndex2 = -1;
50   //
51   myFirstLowerIndex=1;
52   myFirstUpperIndex=myPNMTPS->NumberOfShapesOfTheObject();
53   mySecondLowerIndex=myFirstUpperIndex+1;
54   mySecondUpperIndex=myFirstUpperIndex+myPNMTPS->NumberOfShapesOfTheTool();
55   //
56   Standard_Integer n1, n2, aIR1, aIR2;//, aN1, aN2, aNS;
57   //
58   const NMTDS_CArray1OfIndexRange& aRanges=myPNMTPS->Ranges();
59   //
60   //aNS=myPNMTPS->NumberOfShapesOfTheObject(); 
61   myIndex1=0;
62   myIndex2=0;
63   myWithSubShapeFlag=Standard_False;
64   //
65   myListOfCouple.Clear();
66   myMap.Clear();
67   //
68   NextP();
69   for (; MoreP(); NextP()) {
70     CurrentP(n1, n2);
71     //
72     aIR1=myPNMTPS->ShapeRangeIndex(n1);
73     aIR2=myPNMTPS->ShapeRangeIndex(n2);
74     if (aIR1==aIR2){
75       continue;
76     }
77     //
78     BOPTools_CoupleOfInteger aCouple(n1, n2);
79     myListOfCouple.Append(aCouple);
80     //
81     /*
82     aN1=(n1>aNS)? n1-aNS : n1;
83     aN2=(n2>aNS)? n2-aNS : n2;
84     BOPTools_CoupleOfInteger aCoupleX(aN1, aN2);
85     myMap.Add(aCoupleX);
86     */
87   }
88   myIterator.Initialize(myListOfCouple);
89
90 //=======================================================================
91 // function: Current
92 // purpose: 
93 //=======================================================================
94   void NMTTools_IteratorOfCoupleOfShape::Current(Standard_Integer& aIndex1,
95                                                  Standard_Integer& aIndex2,
96                                                  Standard_Boolean& aWithSubShape) const
97 {
98   aIndex1=myIndex1;
99   aIndex2=myIndex2;
100   aWithSubShape=myWithSubShapeFlag;
101 }
102 //=======================================================================
103 // function: More
104 // purpose: 
105 //=======================================================================
106   Standard_Boolean NMTTools_IteratorOfCoupleOfShape::More()const
107 {
108   Standard_Boolean  bMore, bWithSubShape;
109   Standard_Integer n1, n2, aNS, aN1, aN2;
110   BOPTools_CoupleOfInteger aCoupleX;
111   NMTTools_IteratorOfCoupleOfShape* pIt=(NMTTools_IteratorOfCoupleOfShape*)this;
112   //
113   aNS=myPNMTPS->NumberOfShapesOfTheObject();
114   pIt->myIndex1=0;
115   pIt->myIndex2=0;
116   pIt->myWithSubShapeFlag=Standard_False;
117   //
118   while (1) {
119     bMore=myIterator.More();
120     if (!bMore) {
121       break;
122     }
123     //
124     BOPTools_IteratorOfCoupleOfShape::Current(n1, n2, bWithSubShape);
125     aN1=(n1>aNS)? n1-aNS : n1;
126     aN2=(n2>aNS)? n2-aNS : n2;
127     aCoupleX.SetCouple(aN1, aN2);
128     if (!myMap.Contains(aCoupleX)) {
129       pIt->myMap.Add(aCoupleX);
130       //
131       pIt->myIndex1=aN1;
132       pIt->myIndex2=aN2;
133       pIt->myWithSubShapeFlag=bWithSubShape;
134       break;
135     }
136     //
137     pIt->Next();
138   }
139   return bMore;
140