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/ or email : webmaster.salome@opencascade.com
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 #include <BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors.hxx>
36 #include <BooleanOperations_AncestorsSeqAndSuccessorsSeq.hxx>
37 #include <TColStd_MapOfInteger.hxx>
39 //===========================================================================
40 //function : NMTDS_ShapesDataStructure::NMTDS_ShapesDataStructure
42 //===========================================================================
43 NMTDS_ShapesDataStructure::NMTDS_ShapesDataStructure()
45 BooleanOperations_ShapesDataStructure()
47 //===========================================================================
48 //function : SetCompositeShape
50 //===========================================================================
51 void NMTDS_ShapesDataStructure::SetCompositeShape(const TopoDS_Shape& aS)
55 //===========================================================================
56 //function : CompositeShape
58 //===========================================================================
59 const TopoDS_Shape& NMTDS_ShapesDataStructure::CompositeShape()const
61 return myCompositeShape;
63 //===========================================================================
66 //===========================================================================
67 const NMTDS_CArray1OfIndexRange& NMTDS_ShapesDataStructure::Ranges()const
71 // Modified to Add new methods Thu Sep 14 14:35:18 2006
72 // Contribution of Samtech www.samcef.com BEGIN
73 //===========================================================================
76 //===========================================================================
77 void NMTDS_ShapesDataStructure::FillMap
78 (const TopoDS_Shape& aS,
79 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aMSA,
80 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aMS) const
82 Standard_Integer iX, i, j, aIndex, aNbSc, aNbS;
83 BooleanOperations_AncestorsSeqAndSuccessorsSeq aAS;
87 FillSubshapes(aS, aMSA, aMS);
90 for(i=1; i<=aNbS; ++i) {
91 TColStd_MapOfInteger aMFence;
93 const TopoDS_Shape& aSX=aMS.FindKey(i);
94 iX=aMSA.FindIndex(aSX);
95 const BooleanOperations_AncestorsSeqAndSuccessorsSeq& aAS1=aMSA(iX);
97 aNbSc=aAS1.NumberOfSuccessors();
98 for(j=1; j<=aNbSc; ++j) {
99 aIndex=aAS1.GetSuccessor(j);
100 if(aMFence.Add(aIndex)) {
101 BooleanOperations_AncestorsSeqAndSuccessorsSeq& aAS2=aMSA.ChangeFromIndex(aIndex);
102 aAS2.SetNewAncestor(iX);
107 //===========================================================================
108 //function : FillSubshapes
110 //===========================================================================
111 void NMTDS_ShapesDataStructure::FillSubshapes
112 (const TopoDS_Shape& aS,
113 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aMSA,
114 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aMS) const
116 Standard_Boolean bIsNewSubShape;
117 Standard_Integer aIndexSubShape, aIndex;
118 BooleanOperations_AncestorsSeqAndSuccessorsSeq aASx;
120 aIndex=aMSA.FindIndex(aS);
121 BooleanOperations_AncestorsSeqAndSuccessorsSeq& aAS=aMSA.ChangeFromIndex(aIndex);
123 TopoDS_Iterator anIt(aS, Standard_True);
124 for(; anIt.More(); anIt.Next()) {
125 const TopoDS_Shape& aSubShape = anIt.Value();
126 bIsNewSubShape = Standard_False;
127 if(!aMSA.Contains(aSubShape)) {
128 bIsNewSubShape=!bIsNewSubShape;
129 aIndexSubShape=aMSA.Add(aSubShape, aASx);
130 aMS.Add(aSubShape, aASx);
133 aIndexSubShape=aMSA.FindIndex(aSubShape);
135 aAS.SetNewSuccessor(aIndexSubShape);
136 aAS.SetNewOrientation(aSubShape.Orientation());
138 if(bIsNewSubShape && (aSubShape.ShapeType() != TopAbs_VERTEX)) {
139 FillSubshapes(aSubShape, aMSA, aMS);
143 // Contribution of Samtech www.samcef.com END
144 //===========================================================================
147 //===========================================================================
148 void NMTDS_ShapesDataStructure::Init()
150 Standard_Integer i, j, aNbSx, aNbS, aShift, aNbRanges;
151 Standard_Integer iFirst, iLast;
152 NMTDS_ListOfIndexedDataMapOfShapeAncestorsSuccessors aLx;
153 NMTDS_ListIteratorOfListOfIndexedDataMapOfShapeAncestorsSuccessors aLit;
154 TopoDS_Iterator anIt;
155 // Modified Thu Sep 14 14:35:18 2006
156 // Contribution of Samtech www.samcef.com BEGIN
157 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors aMSA;
158 // Contribution of Samtech www.samcef.com END
160 anIt.Initialize(myCompositeShape);
161 for (i=0; anIt.More(); anIt.Next(), ++i) {
162 // Modified Thu Sep 14 14:35:18 2006
163 // Contribution of Samtech www.samcef.com BEGIN
164 const TopoDS_Shape& aSx=anIt.Value();
165 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors aMS;
166 FillMap(aSx, aMSA, aMS);
168 // Contribution of Samtech www.samcef.com END
170 // Modified Thu Sep 14 14:35:18 2006
171 // Contribution of Samtech www.samcef.com BEGIN
173 // Contribution of Samtech www.samcef.com END
177 aLit.Initialize(aLx);
178 for (i=1; aLit.More(); aLit.Next(), ++i) {
179 // Modified Thu Sep 14 14:35:18 2006
180 // Contribution of Samtech www.samcef.com BEGIN
181 const BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aMSx=aLit.Value();
183 // Contribution of Samtech www.samcef.com END
187 myRanges(i).SetFirst(iFirst);
188 myRanges(i).SetLast(iLast);
191 iFirst=myRanges(i-1).Last()+1;
192 iLast=iFirst+aNbSx-1;
193 myRanges(i).SetFirst(iFirst);
194 myRanges(i).SetLast(iLast);
197 myNumberOfShapesOfTheObject=aNbS;
198 // Modified Thu Sep 14 14:35:18 2006
199 // Contribution of Samtech www.samcef.com BEGIN
200 //myNumberOfShapesOfTheTool=aNbS;
202 myNumberOfShapesOfTheTool=0;
204 // Contribution of Samtech www.samcef.com END
206 // Allocate the whole Table
207 myListOfShapeAndInterferences = (BooleanOperations_PShapeAndInterferences)
208 Standard::Allocate(myLength*sizeof(BooleanOperations_ShapeAndInterferences));
209 // Modified Thu Sep 14 14:35:18 2006
210 // Contribution of Samtech www.samcef.com BEGIN
213 //modified by NIZNHY-PKV Tue May 16 11:47:28 2006f
216 //for (i=0; i<2; ++i) {
220 // for (j=1; j<=aNbS; ++j) {
221 // const TopoDS_Shape& aSx=aMSA.FindKey(j);
222 // const BooleanOperations_AncestorsSeqAndSuccessorsSeq& aASx=
223 // aMSA.FindFromIndex(j);
224 // InsertShapeAndAncestorsSuccessors(aSx, aASx, aShift);
229 for (j=1; j<=aNbS; ++j) {
230 const TopoDS_Shape& aSx=aMSA.FindKey(j);
231 const BooleanOperations_AncestorsSeqAndSuccessorsSeq& aASx=aMSA.FindFromIndex(j);
232 InsertShapeAndAncestorsSuccessors(aSx, aASx, aShift);
234 // Contribution of Samtech www.samcef.com END
237 myShapeIndexMap.Clear();
239 aNbRanges=myRanges.Extent();
240 for (i=1; i<=aNbRanges; ++i){
241 BooleanOperations_IndexedDataMapOfShapeInteger aSIM;
243 const NMTDS_IndexRange& aR=myRanges(i);
246 for (j=iFirst; j<=iLast; ++j) {
247 const TopoDS_Shape& aS=Shape(j);
250 myShapeIndexMap.Add(i, aSIM);
254 iLast=myNumberOfShapesOfTheObject+myNumberOfShapesOfTheTool;
255 myRefEdges.Resize(iLast);
257 for (i=1; i<=iLast; ++i) {
258 const TopoDS_Shape& aS=Shape(i);
260 if (aS.ShapeType()==TopAbs_EDGE) {
262 myRefEdges(i)=myNbEdges;
266 //===========================================================================
267 //function : ShapeRangeIndex
269 //===========================================================================
270 Standard_Integer NMTDS_ShapesDataStructure::ShapeRangeIndex(const Standard_Integer aId)const
272 Standard_Boolean bFound;
273 Standard_Integer i, aNbR, aIdx, aNbS, aZero=0;
275 aNbS=myNumberOfShapesOfTheObject+myNumberOfShapesOfTheTool;
278 if (aIdx > aNbS || aIdx < 1){
282 if (aIdx > myNumberOfShapesOfTheObject) {
283 aIdx-=myNumberOfShapesOfTheObject;
286 aNbR=myRanges.Extent();
287 for (i=1; i<=aNbR; ++i) {
288 const NMTDS_IndexRange& aRange=myRanges(i);
289 bFound=aRange.IsInRange(aIdx);
296 //===========================================================================
299 //===========================================================================
300 Standard_Integer NMTDS_ShapesDataStructure::Rank(const Standard_Integer aId)const
302 Standard_Boolean bFound;
303 Standard_Integer i, aNbR, aNbS, aZero=0;
305 aNbS=myNumberOfShapesOfTheObject;
307 if (aId > aNbS || aId < 1){
311 aNbR=myRanges.Extent();
312 for (i=1; i<=aNbR; ++i) {
313 const NMTDS_IndexRange& aRange=myRanges(i);
314 bFound=aRange.IsInRange(aId);
321 //===========================================================================
322 //function : ShapeIndex
324 //===========================================================================
325 Standard_Integer NMTDS_ShapesDataStructure::ShapeIndex(const TopoDS_Shape& aS,
326 const Standard_Integer aRank)const
328 Standard_Boolean bFound;
329 Standard_Integer aIndex=0;
331 bFound=myShapeIndexMap.Contains(aRank);
335 // Modified Thu Sep 14 14:35:18 2006
336 // Contribution of Samtech www.samcef.com BEGIN
338 //const BooleanOperations_IndexedDataMapOfShapeInteger& aSIM=
339 // myShapeIndexMap.FindFromKey(aRank);
341 //bFound=aSIM.Contains(aS);
346 //aIndex=aSIM.FindFromKey(aS);
348 Standard_Integer i, aNbRanks;
350 aNbRanks=myShapeIndexMap.Extent();
351 for (i=1; i<=aNbRanks; ++i){
352 const BooleanOperations_IndexedDataMapOfShapeInteger& aSIM=myShapeIndexMap.FindFromKey(i);
353 bFound=aSIM.Contains(aS);
355 aIndex=aSIM.FindFromKey(aS);
359 // Contribution of Samtech www.samcef.com END