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