1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File: NMTDS_ShapesDataStructure.cxx
24 // Created: Mon Dec 1 10:21:04 2003
25 // Author: Peter KURNEV
28 #include <NMTDS_ShapesDataStructure.ixx>
29 #include <TopoDS_Iterator.hxx>
30 #include <TopoDS_Shape.hxx>
31 #include <BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors.hxx>
32 #include <NMTDS_ListOfIndexedDataMapOfShapeAncestorsSuccessors.hxx>
33 #include <NMTDS_ListIteratorOfListOfIndexedDataMapOfShapeAncestorsSuccessors.hxx>
34 #include <BooleanOperations_ShapeAndInterferences.hxx>
35 #include <NMTDS_IndexRange.hxx>
37 #include <BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors.hxx>
38 #include <BooleanOperations_AncestorsSeqAndSuccessorsSeq.hxx>
39 #include <TColStd_MapOfInteger.hxx>
40 #include <NMTDS_Tools.hxx>
44 void ComputeBoxExS(const Standard_Integer aIx,
45 const NMTDS_ShapesDataStructure* pDS,
48 void GetAllSuccessorsS(const Standard_Integer nS,
49 const NMTDS_ShapesDataStructure* myDS,
50 TColStd_IndexedMapOfInteger& aMA);
52 //===========================================================================
53 //function : NMTDS_ShapesDataStructure::NMTDS_ShapesDataStructure
55 //===========================================================================
56 NMTDS_ShapesDataStructure::NMTDS_ShapesDataStructure()
58 BooleanOperations_ShapesDataStructure()
60 //===========================================================================
61 //function : SetCompositeShape
63 //===========================================================================
64 void NMTDS_ShapesDataStructure::SetCompositeShape(const TopoDS_Shape& aS)
68 //===========================================================================
69 //function : CompositeShape
71 //===========================================================================
72 const TopoDS_Shape& NMTDS_ShapesDataStructure::CompositeShape()const
74 return myCompositeShape;
76 //===========================================================================
79 //===========================================================================
80 const NMTDS_CArray1OfIndexRange& NMTDS_ShapesDataStructure::Ranges()const
84 // Modified to Add new methods Thu Sep 14 14:35:18 2006
85 // Contribution of Samtech www.samcef.com BEGIN
86 //===========================================================================
89 //===========================================================================
90 void NMTDS_ShapesDataStructure::FillMap
91 (const TopoDS_Shape& aS,
92 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aMSA,
93 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aMS) const
95 Standard_Integer iX, i, j, aIndex, aNbSc, aNbS;
96 BooleanOperations_AncestorsSeqAndSuccessorsSeq aAS;
100 FillSubshapes(aS, aMSA, aMS);
103 for(i=1; i<=aNbS; ++i) {
104 TColStd_MapOfInteger aMFence;
106 const TopoDS_Shape& aSX=aMS.FindKey(i);
107 iX=aMSA.FindIndex(aSX);
108 const BooleanOperations_AncestorsSeqAndSuccessorsSeq& aAS1=aMSA(iX);
110 aNbSc=aAS1.NumberOfSuccessors();
111 for(j=1; j<=aNbSc; ++j) {
112 aIndex=aAS1.GetSuccessor(j);
113 if(aMFence.Add(aIndex)) {
114 BooleanOperations_AncestorsSeqAndSuccessorsSeq& aAS2=aMSA.ChangeFromIndex(aIndex);
115 aAS2.SetNewAncestor(iX);
120 //===========================================================================
121 //function : FillSubshapes
123 //===========================================================================
124 void NMTDS_ShapesDataStructure::FillSubshapes
125 (const TopoDS_Shape& aS,
126 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aMSA,
127 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aMS) const
129 Standard_Boolean bIsNewSubShape;
130 Standard_Integer aIndexSubShape, aIndex;
131 BooleanOperations_AncestorsSeqAndSuccessorsSeq aASx;
133 aIndex=aMSA.FindIndex(aS);
134 BooleanOperations_AncestorsSeqAndSuccessorsSeq& aAS=aMSA.ChangeFromIndex(aIndex);
136 TopoDS_Iterator anIt(aS, Standard_True);
137 for(; anIt.More(); anIt.Next()) {
138 const TopoDS_Shape& aSubShape = anIt.Value();
139 bIsNewSubShape = Standard_False;
140 if(!aMSA.Contains(aSubShape)) {
141 bIsNewSubShape=!bIsNewSubShape;
142 aIndexSubShape=aMSA.Add(aSubShape, aASx);
143 aMS.Add(aSubShape, aASx);
146 aIndexSubShape=aMSA.FindIndex(aSubShape);
148 aAS.SetNewSuccessor(aIndexSubShape);
149 aAS.SetNewOrientation(aSubShape.Orientation());
151 if(bIsNewSubShape && (aSubShape.ShapeType() != TopAbs_VERTEX)) {
152 FillSubshapes(aSubShape, aMSA, aMS);
156 // Contribution of Samtech www.samcef.com END
157 //===========================================================================
160 //===========================================================================
161 void NMTDS_ShapesDataStructure::Init()
163 Standard_Integer i, j, aNbSx, aNbS, aShift, aNbRanges;
164 Standard_Integer iFirst, iLast;
165 NMTDS_ListOfIndexedDataMapOfShapeAncestorsSuccessors aLx;
166 NMTDS_ListIteratorOfListOfIndexedDataMapOfShapeAncestorsSuccessors aLit;
167 TopoDS_Iterator anIt;
168 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors aMSA;
170 anIt.Initialize(myCompositeShape);
171 for (; anIt.More(); anIt.Next()) {
172 const TopoDS_Shape& aSx=anIt.Value();
173 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors aMS;
174 //modified by NIZNHY-PKV Tue Feb 27 17:05:47 2007f
175 //FillMap(aSx, aMSA, aMS);
178 if (!aMSA.Contains(aSx)) {
179 FillMap(aSx, aMSA, aMS);
182 //modified by NIZNHY-PKV Tue Feb 27 17:06:03 2007t
187 //modified by NIZNHY-PKV Tue Feb 27 17:10:07 2007f
189 //modified by NIZNHY-PKV Tue Feb 27 17:10:10 2007t
191 aLit.Initialize(aLx);
192 for (i=1; aLit.More(); aLit.Next(), ++i) {
193 // Modified Thu Sep 14 14:35:18 2006
194 // Contribution of Samtech www.samcef.com BEGIN
195 const BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aMSx=aLit.Value();
197 // Contribution of Samtech www.samcef.com END
201 myRanges(i).SetFirst(iFirst);
202 myRanges(i).SetLast(iLast);
205 iFirst=myRanges(i-1).Last()+1;
206 iLast=iFirst+aNbSx-1;
207 myRanges(i).SetFirst(iFirst);
208 myRanges(i).SetLast(iLast);
211 myNumberOfShapesOfTheObject=aNbS;
212 // Modified Thu Sep 14 14:35:18 2006
213 // Contribution of Samtech www.samcef.com BEGIN
214 //myNumberOfShapesOfTheTool=aNbS;
216 myNumberOfShapesOfTheTool=0;
218 // Contribution of Samtech www.samcef.com END
220 // Allocate the whole Table
221 myListOfShapeAndInterferences = (BooleanOperations_PShapeAndInterferences)
222 Standard::Allocate(myLength*sizeof(BooleanOperations_ShapeAndInterferences));
223 // Modified Thu Sep 14 14:35:18 2006
224 // Contribution of Samtech www.samcef.com BEGIN
229 //for (i=0; i<2; ++i) {
233 // for (j=1; j<=aNbS; ++j) {
234 // const TopoDS_Shape& aSx=aMSA.FindKey(j);
235 // const BooleanOperations_AncestorsSeqAndSuccessorsSeq& aASx=
236 // aMSA.FindFromIndex(j);
237 // InsertShapeAndAncestorsSuccessors(aSx, aASx, aShift);
242 for (j=1; j<=aNbS; ++j) {
243 const TopoDS_Shape& aSx=aMSA.FindKey(j);
244 const BooleanOperations_AncestorsSeqAndSuccessorsSeq& aASx=aMSA.FindFromIndex(j);
245 InsertShapeAndAncestorsSuccessors(aSx, aASx, aShift);
247 // Contribution of Samtech www.samcef.com END
250 myShapeIndexMap.Clear();
252 aNbRanges=myRanges.Extent();
253 for (i=1; i<=aNbRanges; ++i){
254 BooleanOperations_IndexedDataMapOfShapeInteger aSIM;
256 const NMTDS_IndexRange& aR=myRanges(i);
259 for (j=iFirst; j<=iLast; ++j) {
260 const TopoDS_Shape& aS=Shape(j);
263 myShapeIndexMap.Add(i, aSIM);
267 iLast=myNumberOfShapesOfTheObject+myNumberOfShapesOfTheTool;
268 myRefEdges.Resize(iLast);
270 for (i=1; i<=iLast; ++i) {
271 const TopoDS_Shape& aS=Shape(i);
273 if (aS.ShapeType()==TopAbs_EDGE) {
275 myRefEdges(i)=myNbEdges;
279 //===========================================================================
280 //function : ShapeRangeIndex
282 //===========================================================================
283 Standard_Integer NMTDS_ShapesDataStructure::ShapeRangeIndex(const Standard_Integer aId)const
285 Standard_Boolean bFound;
286 Standard_Integer i, aNbR, aIdx, aNbS, aZero=0;
288 aNbS=myNumberOfShapesOfTheObject+myNumberOfShapesOfTheTool;
291 if (aIdx > aNbS || aIdx < 1){
295 if (aIdx > myNumberOfShapesOfTheObject) {
296 aIdx-=myNumberOfShapesOfTheObject;
299 aNbR=myRanges.Extent();
300 for (i=1; i<=aNbR; ++i) {
301 const NMTDS_IndexRange& aRange=myRanges(i);
302 bFound=aRange.IsInRange(aIdx);
309 //===========================================================================
312 //===========================================================================
313 Standard_Integer NMTDS_ShapesDataStructure::Rank(const Standard_Integer aId)const
315 Standard_Boolean bFound;
316 Standard_Integer i, aNbR, aNbS, aZero=0;
318 aNbS=myNumberOfShapesOfTheObject;
320 if (aId > aNbS || aId < 1){
324 aNbR=myRanges.Extent();
325 for (i=1; i<=aNbR; ++i) {
326 const NMTDS_IndexRange& aRange=myRanges(i);
327 bFound=aRange.IsInRange(aId);
334 //===========================================================================
335 //function : ShapeIndex
337 //===========================================================================
338 Standard_Integer NMTDS_ShapesDataStructure::ShapeIndex(const TopoDS_Shape& aS,
339 const Standard_Integer aRank)const
341 Standard_Boolean bFound;
342 Standard_Integer aIndex=0;
344 bFound=myShapeIndexMap.Contains(aRank);
348 // Modified Thu Sep 14 14:35:18 2006
349 // Contribution of Samtech www.samcef.com BEGIN
351 //const BooleanOperations_IndexedDataMapOfShapeInteger& aSIM=
352 // myShapeIndexMap.FindFromKey(aRank);
354 //bFound=aSIM.Contains(aS);
359 //aIndex=aSIM.FindFromKey(aS);
361 Standard_Integer i, aNbRanks;
363 aNbRanks=myShapeIndexMap.Extent();
364 for (i=1; i<=aNbRanks; ++i){
365 const BooleanOperations_IndexedDataMapOfShapeInteger& aSIM=myShapeIndexMap.FindFromKey(i);
366 bFound=aSIM.Contains(aS);
368 aIndex=aSIM.FindFromKey(aS);
372 // Contribution of Samtech www.samcef.com END
376 //=======================================================================
377 //function : ComputeBoxEx
379 //=======================================================================
380 void NMTDS_ShapesDataStructure::ComputeBoxEx (const Standard_Integer aIx,
381 Bnd_Box& aBoxEx)const
383 ComputeBoxExS(aIx, this, aBoxEx);
385 //=======================================================================
386 //function : GetAllSuccessors
388 //=======================================================================
389 void NMTDS_ShapesDataStructure::GetAllSuccessors(const Standard_Integer nS,
390 TColStd_IndexedMapOfInteger& aMA)const
392 GetAllSuccessorsS(nS, this, aMA);
394 //=======================================================================
395 //function : GetAllSuccessorsS
397 //=======================================================================
398 void GetAllSuccessorsS(const Standard_Integer nS,
399 const NMTDS_ShapesDataStructure* myDS,
400 TColStd_IndexedMapOfInteger& aMA)
403 Standard_Integer i, nSx, aNbSuccessors, *pSuccessors;
404 Standard_Address xSuccessors;
406 const TopoDS_Shape& aS=myDS->Shape(nS);
408 if(NMTDS_Tools::HasBRep(aT)) {
411 if (aT==TopAbs_VERTEX) {
416 myDS->GetSuccessors(nS, xSuccessors, aNbSuccessors);
417 pSuccessors=(Standard_Integer*)xSuccessors;
418 for (i=0; i<aNbSuccessors; ++i) {
420 GetAllSuccessorsS(nSx, myDS, aMA);
423 //=======================================================================
424 // function: ComputeBoxExS
426 //=======================================================================
427 void ComputeBoxExS(const Standard_Integer aIx,
428 const NMTDS_ShapesDataStructure* pDS,
431 Standard_Integer i, aNbS, iS;
433 const Bnd_Box& aBox=pDS->GetBoundingBox(aIx);
436 aNbS=pDS->NumberOfSuccessors(aIx);
437 for (i=1; i<=aNbS; ++i) {
439 iS=pDS->GetSuccessor(aIx, i);
440 ComputeBoxExS(iS, pDS, aBoxS);