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