1 // File: NMTDS_ShapesDataStructure.cxx
2 // Created: Mon Dec 1 10:21:04 2003
3 // Author: Peter KURNEV
7 #include <NMTDS_ShapesDataStructure.ixx>
8 #include <TopoDS_Iterator.hxx>
9 #include <TopoDS_Shape.hxx>
10 #include <BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors.hxx>
11 #include <NMTDS_ListOfIndexedDataMapOfShapeAncestorsSuccessors.hxx>
12 #include <NMTDS_ListIteratorOfListOfIndexedDataMapOfShapeAncestorsSuccessors.hxx>
13 #include <BooleanOperations_ShapeAndInterferences.hxx>
14 #include <NMTDS_IndexRange.hxx>
16 //===========================================================================
17 //function : NMTDS_ShapesDataStructure::NMTDS_ShapesDataStructure
19 //===========================================================================
20 NMTDS_ShapesDataStructure::NMTDS_ShapesDataStructure()
22 BooleanOperations_ShapesDataStructure()
24 //===========================================================================
25 //function : SetCompositeShape
27 //===========================================================================
28 void NMTDS_ShapesDataStructure::SetCompositeShape(const TopoDS_Shape& aS)
32 //===========================================================================
33 //function : CompositeShape
35 //===========================================================================
36 const TopoDS_Shape& NMTDS_ShapesDataStructure::CompositeShape()const
38 return myCompositeShape;
40 //===========================================================================
43 //===========================================================================
44 const NMTDS_CArray1OfIndexRange& NMTDS_ShapesDataStructure::Ranges()const
48 //===========================================================================
51 //===========================================================================
52 void NMTDS_ShapesDataStructure::Init()
54 Standard_Integer i, j, aNbSx, aNbS, aShift, aNbRanges;
55 Standard_Integer iFirst, iLast;
56 NMTDS_ListOfIndexedDataMapOfShapeAncestorsSuccessors aLx;
57 NMTDS_ListIteratorOfListOfIndexedDataMapOfShapeAncestorsSuccessors aLit;
61 anIt.Initialize(myCompositeShape);
62 for (i=0; anIt.More(); anIt.Next(), ++i) {
63 const TopoDS_Shape& aSx=anIt.Value();
64 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors aIndDatMapShape;
65 FillIndexedMapOfShapesAncestorsAndSuccessors(aSx, aIndDatMapShape);
66 aNbSx=aIndDatMapShape.Extent();
68 aLx.Append(aIndDatMapShape);
74 for (i=1; aLit.More(); aLit.Next(), ++i) {
75 const BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aM=aLit.Value();
80 myRanges(i).SetFirst(iFirst);
81 myRanges(i).SetLast(iLast);
84 iFirst=myRanges(i-1).Last()+1;
86 myRanges(i).SetFirst(iFirst);
87 myRanges(i).SetLast(iLast);
90 myNumberOfShapesOfTheObject=aNbS;
91 myNumberOfShapesOfTheTool=aNbS;
94 // Allocate the whole Table
95 myListOfShapeAndInterferences = (BooleanOperations_PShapeAndInterferences)
96 Standard::Allocate(myLength*sizeof(BooleanOperations_ShapeAndInterferences));
102 aShift=myNumberOfShapesOfTheObject;
104 aLit.Initialize(aLx);
105 for (; aLit.More(); aLit.Next()) {
106 const BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aM=aLit.Value();
108 for (j=1; j<=aNbSx; ++j) {
109 const TopoDS_Shape& aSx=aM.FindKey(j);
110 const BooleanOperations_AncestorsSeqAndSuccessorsSeq& aASx=aM.FindFromIndex(j);
111 InsertShapeAndAncestorsSuccessors(aSx, aASx, aShift);
118 myShapeIndexMap.Clear();
120 aNbRanges=myRanges.Extent();
121 for (i=1; i<=aNbRanges; ++i){
122 BooleanOperations_IndexedDataMapOfShapeInteger aSIM;
124 const NMTDS_IndexRange& aR=myRanges(i);
127 for (j=iFirst; j<=iLast; ++j) {
128 const TopoDS_Shape& aS=GetShape(j);
131 myShapeIndexMap.Add(i, aSIM);
135 iLast=myNumberOfShapesOfTheObject+myNumberOfShapesOfTheTool;
136 myRefEdges.Resize(iLast);
138 for (i=1; i<=iLast; ++i) {
139 const TopoDS_Shape& aS=Shape(i);
141 if (aS.ShapeType()==TopAbs_EDGE) {
143 myRefEdges(i)=myNbEdges;
147 //===========================================================================
148 //function : ShapeRangeIndex
150 //===========================================================================
151 Standard_Integer NMTDS_ShapesDataStructure::ShapeRangeIndex(const Standard_Integer aId)const
153 Standard_Boolean bFound;
154 Standard_Integer i, aNbR, aIdx, aNbS, aZero=0;
156 aNbS=myNumberOfShapesOfTheObject+myNumberOfShapesOfTheTool;
159 if (aIdx > aNbS || aIdx < 1){
163 if (aIdx > myNumberOfShapesOfTheObject) {
164 aIdx-=myNumberOfShapesOfTheObject;
167 aNbR=myRanges.Extent();
168 for (i=1; i<=aNbR; ++i) {
169 const NMTDS_IndexRange& aRange=myRanges(i);
170 bFound=aRange.IsInRange(aIdx);
177 //===========================================================================
180 //===========================================================================
181 Standard_Integer NMTDS_ShapesDataStructure::Rank(const Standard_Integer aId)const
183 Standard_Boolean bFound;
184 Standard_Integer i, aNbR, aNbS, aZero=0;
186 aNbS=myNumberOfShapesOfTheObject;
188 if (aId > aNbS || aId < 1){
192 aNbR=myRanges.Extent();
193 for (i=1; i<=aNbR; ++i) {
194 const NMTDS_IndexRange& aRange=myRanges(i);
195 bFound=aRange.IsInRange(aId);
202 //===========================================================================
203 //function : ShapeIndex
205 //===========================================================================
206 Standard_Integer NMTDS_ShapesDataStructure::ShapeIndex(const TopoDS_Shape& aS,
207 const Standard_Integer aRank)const
209 Standard_Boolean bFound;
210 Standard_Integer aIndex=0;
212 bFound=myShapeIndexMap.Contains(aRank);
217 const BooleanOperations_IndexedDataMapOfShapeInteger& aSIM=myShapeIndexMap.FindFromKey(aRank);
219 bFound=aSIM.Contains(aS);
224 aIndex=aSIM.FindFromKey(aS);