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 //printf(" NMTDS_ShapesDataStructure CREATE:%x\n", (int)this);
26 //modified by NIZNHY-PKV Wed Feb 2 11:45:04 2005f
27 //===========================================================================
30 //===========================================================================
31 NMTDS_ShapesDataStructure::~NMTDS_ShapesDataStructure()
33 //printf(" NMTDS_ShapesDataStructure DELETE:%x\n", (int)this);
35 //modified by NIZNHY-PKV Wed Feb 2 11:45:06 2005t
36 //===========================================================================
37 //function : SetCompositeShape
39 //===========================================================================
40 void NMTDS_ShapesDataStructure::SetCompositeShape(const TopoDS_Shape& aS)
44 //===========================================================================
45 //function : CompositeShape
47 //===========================================================================
48 const TopoDS_Shape& NMTDS_ShapesDataStructure::CompositeShape()const
50 return myCompositeShape;
52 //===========================================================================
55 //===========================================================================
56 const NMTDS_CArray1OfIndexRange& NMTDS_ShapesDataStructure::Ranges()const
60 //===========================================================================
63 //===========================================================================
64 void NMTDS_ShapesDataStructure::Init()
66 Standard_Integer i, j, aNbSx, aNbS, aShift, aNbRanges;
67 Standard_Integer iFirst, iLast;
68 NMTDS_ListOfIndexedDataMapOfShapeAncestorsSuccessors aLx;
69 NMTDS_ListIteratorOfListOfIndexedDataMapOfShapeAncestorsSuccessors aLit;
73 anIt.Initialize(myCompositeShape);
74 for (i=0; anIt.More(); anIt.Next(), ++i) {
75 const TopoDS_Shape& aSx=anIt.Value();
76 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors aIndDatMapShape;
77 FillIndexedMapOfShapesAncestorsAndSuccessors(aSx, aIndDatMapShape);
78 aNbSx=aIndDatMapShape.Extent();
80 aLx.Append(aIndDatMapShape);
86 for (i=1; aLit.More(); aLit.Next(), ++i) {
87 const BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aM=aLit.Value();
92 myRanges(i).SetFirst(iFirst);
93 myRanges(i).SetLast(iLast);
96 iFirst=myRanges(i-1).Last()+1;
98 myRanges(i).SetFirst(iFirst);
99 myRanges(i).SetLast(iLast);
102 myNumberOfShapesOfTheObject=aNbS;
103 myNumberOfShapesOfTheTool=aNbS;
106 // Allocate the whole Table
107 myListOfShapeAndInterferences = (BooleanOperations_PShapeAndInterferences)
108 Standard::Allocate(myLength*sizeof(BooleanOperations_ShapeAndInterferences));
111 for (i=0; i<2; ++i) {
114 aShift=myNumberOfShapesOfTheObject;
116 aLit.Initialize(aLx);
117 for (; aLit.More(); aLit.Next()) {
118 const BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aM=aLit.Value();
120 for (j=1; j<=aNbSx; ++j) {
121 const TopoDS_Shape& aSx=aM.FindKey(j);
122 const BooleanOperations_AncestorsSeqAndSuccessorsSeq& aASx=aM.FindFromIndex(j);
123 InsertShapeAndAncestorsSuccessors(aSx, aASx, aShift);
130 myShapeIndexMap.Clear();
132 aNbRanges=myRanges.Extent();
133 for (i=1; i<=aNbRanges; ++i){
134 BooleanOperations_IndexedDataMapOfShapeInteger aSIM;
136 const NMTDS_IndexRange& aR=myRanges(i);
139 for (j=iFirst; j<=iLast; ++j) {
140 const TopoDS_Shape& aS=GetShape(j);
143 myShapeIndexMap.Add(i, aSIM);
147 iLast=myNumberOfShapesOfTheObject+myNumberOfShapesOfTheTool;
148 myRefEdges.Resize(iLast);
150 for (i=1; i<=iLast; ++i) {
151 const TopoDS_Shape& aS=Shape(i);
153 if (aS.ShapeType()==TopAbs_EDGE) {
155 myRefEdges(i)=myNbEdges;
159 //===========================================================================
160 //function : ShapeRangeIndex
162 //===========================================================================
163 Standard_Integer NMTDS_ShapesDataStructure::ShapeRangeIndex(const Standard_Integer aId)const
165 Standard_Boolean bFound;
166 Standard_Integer i, aNbR, aIdx, aNbS, aZero=0;
168 aNbS=myNumberOfShapesOfTheObject+myNumberOfShapesOfTheTool;
171 if (aIdx > aNbS || aIdx < 1){
175 if (aIdx > myNumberOfShapesOfTheObject) {
176 aIdx-=myNumberOfShapesOfTheObject;
179 aNbR=myRanges.Extent();
180 for (i=1; i<=aNbR; ++i) {
181 const NMTDS_IndexRange& aRange=myRanges(i);
182 bFound=aRange.IsInRange(aIdx);
189 //===========================================================================
192 //===========================================================================
193 Standard_Integer NMTDS_ShapesDataStructure::Rank(const Standard_Integer aId)const
195 Standard_Boolean bFound;
196 Standard_Integer i, aNbR, aNbS, aZero=0;
198 aNbS=myNumberOfShapesOfTheObject;
200 if (aId > aNbS || aId < 1){
204 aNbR=myRanges.Extent();
205 for (i=1; i<=aNbR; ++i) {
206 const NMTDS_IndexRange& aRange=myRanges(i);
207 bFound=aRange.IsInRange(aId);
214 //===========================================================================
215 //function : ShapeIndex
217 //===========================================================================
218 Standard_Integer NMTDS_ShapesDataStructure::ShapeIndex(const TopoDS_Shape& aS,
219 const Standard_Integer aRank)const
221 Standard_Boolean bFound;
222 Standard_Integer aIndex=0;
224 bFound=myShapeIndexMap.Contains(aRank);
229 const BooleanOperations_IndexedDataMapOfShapeInteger& aSIM=myShapeIndexMap.FindFromKey(aRank);
231 bFound=aSIM.Contains(aS);
236 aIndex=aSIM.FindFromKey(aS);