Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/geom.git] / src / NMTTools / NMTTools_IteratorOfCoupleOfShape.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 // File:        NMTTools_IteratorOfCoupleOfShape.cxx
21 // Created:     Thu Dec  4 17:00:03 2003
22 // Author:      Peter KURNEV
23 //              <pkv@irinox>
24
25
26 #include <NMTTools_IteratorOfCoupleOfShape.ixx>
27 #include <Standard_NoSuchObject.hxx>
28 #include <NMTDS_ShapesDataStructure.hxx>
29 #include <BOPTools_CoupleOfInteger.hxx>
30 #include <NMTDS_CArray1OfIndexRange.hxx>
31 #include <BooleanOperations_ShapesDataStructure.hxx>
32
33 //=======================================================================
34 // function: 
35 // purpose: 
36 //=======================================================================
37   NMTTools_IteratorOfCoupleOfShape::NMTTools_IteratorOfCoupleOfShape()
38 :
39   BOPTools_IteratorOfCoupleOfShape()
40 {
41   myIndex1=0;
42   myIndex2=0;
43   myWithSubShapeFlag=Standard_False;
44 }
45 //=======================================================================
46 // function: SetDS
47 // purpose: 
48 //=======================================================================
49   void NMTTools_IteratorOfCoupleOfShape::SetDS(const NMTDS_PShapesDataStructure& PDS)
50 {
51   myPNMTPS=PDS;
52   SetDataStructure(myPNMTPS);
53 }
54 //=======================================================================
55 // function: Initialize
56 // purpose: 
57 //=======================================================================
58   void NMTTools_IteratorOfCoupleOfShape::Initialize(const TopAbs_ShapeEnum Type1,
59                                                     const TopAbs_ShapeEnum Type2)
60 {
61   if(myPDS==NULL) {
62     Standard_NoSuchObject::Raise("NMTTools_IteratorOfCoupleOfShape::Initialize: myPDS==NULL");
63   }
64   //
65   myType1 = Type1;
66   myType2 = Type2;
67   myCurrentIndex1 = -1;
68   myCurrentIndex2 = -1;
69   //
70   myFirstLowerIndex=1;
71   myFirstUpperIndex=myPNMTPS->NumberOfShapesOfTheObject();
72   mySecondLowerIndex=myFirstUpperIndex+1;
73   mySecondUpperIndex=myFirstUpperIndex+myPNMTPS->NumberOfShapesOfTheTool();
74   //
75   Standard_Integer n1, n2, aIR1, aIR2;//, aN1, aN2, aNS;
76   //
77   const NMTDS_CArray1OfIndexRange& aRanges=myPNMTPS->Ranges();
78   //
79   //aNS=myPNMTPS->NumberOfShapesOfTheObject(); 
80   myIndex1=0;
81   myIndex2=0;
82   myWithSubShapeFlag=Standard_False;
83   //
84   myListOfCouple.Clear();
85   myMap.Clear();
86   //
87   NextP();
88   for (; MoreP(); NextP()) {
89     CurrentP(n1, n2);
90     //
91     aIR1=myPNMTPS->ShapeRangeIndex(n1);
92     aIR2=myPNMTPS->ShapeRangeIndex(n2);
93     if (aIR1==aIR2){
94       continue;
95     }
96     //
97     BOPTools_CoupleOfInteger aCouple(n1, n2);
98     myListOfCouple.Append(aCouple);
99     //
100     /*
101     aN1=(n1>aNS)? n1-aNS : n1;
102     aN2=(n2>aNS)? n2-aNS : n2;
103     BOPTools_CoupleOfInteger aCoupleX(aN1, aN2);
104     myMap.Add(aCoupleX);
105     */
106   }
107   myIterator.Initialize(myListOfCouple);
108
109 //=======================================================================
110 // function: Current
111 // purpose: 
112 //=======================================================================
113   void NMTTools_IteratorOfCoupleOfShape::Current(Standard_Integer& aIndex1,
114                                                  Standard_Integer& aIndex2,
115                                                  Standard_Boolean& aWithSubShape) const
116 {
117   aIndex1=myIndex1;
118   aIndex2=myIndex2;
119   aWithSubShape=myWithSubShapeFlag;
120 }
121 //=======================================================================
122 // function: More
123 // purpose: 
124 //=======================================================================
125   Standard_Boolean NMTTools_IteratorOfCoupleOfShape::More()const
126 {
127   Standard_Boolean  bMore, bWithSubShape;
128   Standard_Integer n1, n2, aNS, aN1, aN2;
129   BOPTools_CoupleOfInteger aCoupleX;
130   NMTTools_IteratorOfCoupleOfShape* pIt=(NMTTools_IteratorOfCoupleOfShape*)this;
131   //
132   aNS=myPNMTPS->NumberOfShapesOfTheObject();
133   pIt->myIndex1=0;
134   pIt->myIndex2=0;
135   pIt->myWithSubShapeFlag=Standard_False;
136   //
137   while (1) {
138     bMore=myIterator.More();
139     if (!bMore) {
140       break;
141     }
142     //
143     BOPTools_IteratorOfCoupleOfShape::Current(n1, n2, bWithSubShape);
144     aN1=(n1>aNS)? n1-aNS : n1;
145     aN2=(n2>aNS)? n2-aNS : n2;
146     aCoupleX.SetCouple(aN1, aN2);
147     if (!myMap.Contains(aCoupleX)) {
148       pIt->myMap.Add(aCoupleX);
149       //
150       pIt->myIndex1=aN1;
151       pIt->myIndex2=aN2;
152       pIt->myWithSubShapeFlag=bWithSubShape;
153       break;
154     }
155     //
156     pIt->Next();
157   }
158   return bMore;
159