1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.salome-platform.org/
20 // File: NMTDS_ShapesDataStructure.cxx
21 // Created: Mon Dec 1 10:21:04 2003
22 // Author: Peter KURNEV
26 #include <NMTDS_ShapesDataStructure.ixx>
27 #include <TopoDS_Iterator.hxx>
28 #include <TopoDS_Shape.hxx>
29 #include <BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors.hxx>
30 #include <NMTDS_ListOfIndexedDataMapOfShapeAncestorsSuccessors.hxx>
31 #include <NMTDS_ListIteratorOfListOfIndexedDataMapOfShapeAncestorsSuccessors.hxx>
32 #include <BooleanOperations_ShapeAndInterferences.hxx>
33 #include <NMTDS_IndexRange.hxx>
35 //===========================================================================
36 //function : NMTDS_ShapesDataStructure::NMTDS_ShapesDataStructure
38 //===========================================================================
39 NMTDS_ShapesDataStructure::NMTDS_ShapesDataStructure()
41 BooleanOperations_ShapesDataStructure()
43 //printf(" NMTDS_ShapesDataStructure CREATE:%x\n", (int)this);
45 //modified by NIZNHY-PKV Wed Feb 2 11:45:04 2005f
46 //===========================================================================
49 //===========================================================================
50 NMTDS_ShapesDataStructure::~NMTDS_ShapesDataStructure()
52 //printf(" NMTDS_ShapesDataStructure DELETE:%x\n", (int)this);
54 //modified by NIZNHY-PKV Wed Feb 2 11:45:06 2005t
55 //===========================================================================
56 //function : SetCompositeShape
58 //===========================================================================
59 void NMTDS_ShapesDataStructure::SetCompositeShape(const TopoDS_Shape& aS)
63 //===========================================================================
64 //function : CompositeShape
66 //===========================================================================
67 const TopoDS_Shape& NMTDS_ShapesDataStructure::CompositeShape()const
69 return myCompositeShape;
71 //===========================================================================
74 //===========================================================================
75 const NMTDS_CArray1OfIndexRange& NMTDS_ShapesDataStructure::Ranges()const
79 //===========================================================================
82 //===========================================================================
83 void NMTDS_ShapesDataStructure::Init()
85 Standard_Integer i, j, aNbSx, aNbS, aShift, aNbRanges;
86 Standard_Integer iFirst, iLast;
87 NMTDS_ListOfIndexedDataMapOfShapeAncestorsSuccessors aLx;
88 NMTDS_ListIteratorOfListOfIndexedDataMapOfShapeAncestorsSuccessors aLit;
92 anIt.Initialize(myCompositeShape);
93 for (i=0; anIt.More(); anIt.Next(), ++i) {
94 const TopoDS_Shape& aSx=anIt.Value();
95 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors aIndDatMapShape;
96 FillIndexedMapOfShapesAncestorsAndSuccessors(aSx, aIndDatMapShape);
97 aNbSx=aIndDatMapShape.Extent();
99 aLx.Append(aIndDatMapShape);
104 aLit.Initialize(aLx);
105 for (i=1; aLit.More(); aLit.Next(), ++i) {
106 const BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aM=aLit.Value();
111 myRanges(i).SetFirst(iFirst);
112 myRanges(i).SetLast(iLast);
115 iFirst=myRanges(i-1).Last()+1;
116 iLast=iFirst+aNbSx-1;
117 myRanges(i).SetFirst(iFirst);
118 myRanges(i).SetLast(iLast);
121 myNumberOfShapesOfTheObject=aNbS;
122 myNumberOfShapesOfTheTool=aNbS;
125 // Allocate the whole Table
126 myListOfShapeAndInterferences = (BooleanOperations_PShapeAndInterferences)
127 Standard::Allocate(myLength*sizeof(BooleanOperations_ShapeAndInterferences));
130 for (i=0; i<2; ++i) {
133 aShift=myNumberOfShapesOfTheObject;
135 aLit.Initialize(aLx);
136 for (; aLit.More(); aLit.Next()) {
137 const BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aM=aLit.Value();
139 for (j=1; j<=aNbSx; ++j) {
140 const TopoDS_Shape& aSx=aM.FindKey(j);
141 const BooleanOperations_AncestorsSeqAndSuccessorsSeq& aASx=aM.FindFromIndex(j);
142 InsertShapeAndAncestorsSuccessors(aSx, aASx, aShift);
149 myShapeIndexMap.Clear();
151 aNbRanges=myRanges.Extent();
152 for (i=1; i<=aNbRanges; ++i){
153 BooleanOperations_IndexedDataMapOfShapeInteger aSIM;
155 const NMTDS_IndexRange& aR=myRanges(i);
158 for (j=iFirst; j<=iLast; ++j) {
159 const TopoDS_Shape& aS=GetShape(j);
162 myShapeIndexMap.Add(i, aSIM);
166 iLast=myNumberOfShapesOfTheObject+myNumberOfShapesOfTheTool;
167 myRefEdges.Resize(iLast);
169 for (i=1; i<=iLast; ++i) {
170 const TopoDS_Shape& aS=Shape(i);
172 if (aS.ShapeType()==TopAbs_EDGE) {
174 myRefEdges(i)=myNbEdges;
178 //===========================================================================
179 //function : ShapeRangeIndex
181 //===========================================================================
182 Standard_Integer NMTDS_ShapesDataStructure::ShapeRangeIndex(const Standard_Integer aId)const
184 Standard_Boolean bFound;
185 Standard_Integer i, aNbR, aIdx, aNbS, aZero=0;
187 aNbS=myNumberOfShapesOfTheObject+myNumberOfShapesOfTheTool;
190 if (aIdx > aNbS || aIdx < 1){
194 if (aIdx > myNumberOfShapesOfTheObject) {
195 aIdx-=myNumberOfShapesOfTheObject;
198 aNbR=myRanges.Extent();
199 for (i=1; i<=aNbR; ++i) {
200 const NMTDS_IndexRange& aRange=myRanges(i);
201 bFound=aRange.IsInRange(aIdx);
208 //===========================================================================
211 //===========================================================================
212 Standard_Integer NMTDS_ShapesDataStructure::Rank(const Standard_Integer aId)const
214 Standard_Boolean bFound;
215 Standard_Integer i, aNbR, aNbS, aZero=0;
217 aNbS=myNumberOfShapesOfTheObject;
219 if (aId > aNbS || aId < 1){
223 aNbR=myRanges.Extent();
224 for (i=1; i<=aNbR; ++i) {
225 const NMTDS_IndexRange& aRange=myRanges(i);
226 bFound=aRange.IsInRange(aId);
233 //===========================================================================
234 //function : ShapeIndex
236 //===========================================================================
237 Standard_Integer NMTDS_ShapesDataStructure::ShapeIndex(const TopoDS_Shape& aS,
238 const Standard_Integer aRank)const
240 Standard_Boolean bFound;
241 Standard_Integer aIndex=0;
243 bFound=myShapeIndexMap.Contains(aRank);
248 const BooleanOperations_IndexedDataMapOfShapeInteger& aSIM=myShapeIndexMap.FindFromKey(aRank);
250 bFound=aSIM.Contains(aS);
255 aIndex=aSIM.FindFromKey(aS);