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>
38 #include <NMTDS_Tools.hxx>
42 void ComputeBoxExS(const Standard_Integer aIx,
43 const NMTDS_ShapesDataStructure* pDS,
46 void GetAllSuccessorsS(const Standard_Integer nS,
47 const NMTDS_ShapesDataStructure* myDS,
48 TColStd_IndexedMapOfInteger& aMA);
50 //===========================================================================
51 //function : NMTDS_ShapesDataStructure::NMTDS_ShapesDataStructure
53 //===========================================================================
54 NMTDS_ShapesDataStructure::NMTDS_ShapesDataStructure()
56 BooleanOperations_ShapesDataStructure()
58 //===========================================================================
59 //function : SetCompositeShape
61 //===========================================================================
62 void NMTDS_ShapesDataStructure::SetCompositeShape(const TopoDS_Shape& aS)
66 //===========================================================================
67 //function : CompositeShape
69 //===========================================================================
70 const TopoDS_Shape& NMTDS_ShapesDataStructure::CompositeShape()const
72 return myCompositeShape;
74 //===========================================================================
77 //===========================================================================
78 const NMTDS_CArray1OfIndexRange& NMTDS_ShapesDataStructure::Ranges()const
82 // Modified to Add new methods Thu Sep 14 14:35:18 2006
83 // Contribution of Samtech www.samcef.com BEGIN
84 //===========================================================================
87 //===========================================================================
88 void NMTDS_ShapesDataStructure::FillMap
89 (const TopoDS_Shape& aS,
90 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aMSA,
91 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aMS) const
93 Standard_Integer iX, i, j, aIndex, aNbSc, aNbS;
94 BooleanOperations_AncestorsSeqAndSuccessorsSeq aAS;
98 FillSubshapes(aS, aMSA, aMS);
101 for(i=1; i<=aNbS; ++i) {
102 TColStd_MapOfInteger aMFence;
104 const TopoDS_Shape& aSX=aMS.FindKey(i);
105 iX=aMSA.FindIndex(aSX);
106 const BooleanOperations_AncestorsSeqAndSuccessorsSeq& aAS1=aMSA(iX);
108 aNbSc=aAS1.NumberOfSuccessors();
109 for(j=1; j<=aNbSc; ++j) {
110 aIndex=aAS1.GetSuccessor(j);
111 if(aMFence.Add(aIndex)) {
112 BooleanOperations_AncestorsSeqAndSuccessorsSeq& aAS2=aMSA.ChangeFromIndex(aIndex);
113 aAS2.SetNewAncestor(iX);
118 //===========================================================================
119 //function : FillSubshapes
121 //===========================================================================
122 void NMTDS_ShapesDataStructure::FillSubshapes
123 (const TopoDS_Shape& aS,
124 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aMSA,
125 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aMS) const
127 Standard_Boolean bIsNewSubShape;
128 Standard_Integer aIndexSubShape, aIndex;
129 BooleanOperations_AncestorsSeqAndSuccessorsSeq aASx;
131 aIndex=aMSA.FindIndex(aS);
132 BooleanOperations_AncestorsSeqAndSuccessorsSeq& aAS=aMSA.ChangeFromIndex(aIndex);
134 TopoDS_Iterator anIt(aS, Standard_True);
135 for(; anIt.More(); anIt.Next()) {
136 const TopoDS_Shape& aSubShape = anIt.Value();
137 bIsNewSubShape = Standard_False;
138 if(!aMSA.Contains(aSubShape)) {
139 bIsNewSubShape=!bIsNewSubShape;
140 aIndexSubShape=aMSA.Add(aSubShape, aASx);
141 aMS.Add(aSubShape, aASx);
144 aIndexSubShape=aMSA.FindIndex(aSubShape);
146 aAS.SetNewSuccessor(aIndexSubShape);
147 aAS.SetNewOrientation(aSubShape.Orientation());
149 if(bIsNewSubShape && (aSubShape.ShapeType() != TopAbs_VERTEX)) {
150 FillSubshapes(aSubShape, aMSA, aMS);
154 // Contribution of Samtech www.samcef.com END
155 //===========================================================================
158 //===========================================================================
159 void NMTDS_ShapesDataStructure::Init()
161 Standard_Integer i, j, aNbSx, aNbS, aShift, aNbRanges;
162 Standard_Integer iFirst, iLast;
163 NMTDS_ListOfIndexedDataMapOfShapeAncestorsSuccessors aLx;
164 NMTDS_ListIteratorOfListOfIndexedDataMapOfShapeAncestorsSuccessors aLit;
165 TopoDS_Iterator anIt;
166 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors aMSA;
168 anIt.Initialize(myCompositeShape);
169 for (; anIt.More(); anIt.Next()) {
170 const TopoDS_Shape& aSx=anIt.Value();
171 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors aMS;
172 //modified by NIZNHY-PKV Tue Feb 27 17:05:47 2007f
173 //FillMap(aSx, aMSA, aMS);
176 if (!aMSA.Contains(aSx)) {
177 FillMap(aSx, aMSA, aMS);
180 //modified by NIZNHY-PKV Tue Feb 27 17:06:03 2007t
185 //modified by NIZNHY-PKV Tue Feb 27 17:10:07 2007f
187 //modified by NIZNHY-PKV Tue Feb 27 17:10:10 2007t
189 aLit.Initialize(aLx);
190 for (i=1; aLit.More(); aLit.Next(), ++i) {
191 // Modified Thu Sep 14 14:35:18 2006
192 // Contribution of Samtech www.samcef.com BEGIN
193 const BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aMSx=aLit.Value();
195 // Contribution of Samtech www.samcef.com END
199 myRanges(i).SetFirst(iFirst);
200 myRanges(i).SetLast(iLast);
203 iFirst=myRanges(i-1).Last()+1;
204 iLast=iFirst+aNbSx-1;
205 myRanges(i).SetFirst(iFirst);
206 myRanges(i).SetLast(iLast);
209 myNumberOfShapesOfTheObject=aNbS;
210 // Modified Thu Sep 14 14:35:18 2006
211 // Contribution of Samtech www.samcef.com BEGIN
212 //myNumberOfShapesOfTheTool=aNbS;
214 myNumberOfShapesOfTheTool=0;
216 // Contribution of Samtech www.samcef.com END
218 // Allocate the whole Table
219 myListOfShapeAndInterferences = (BooleanOperations_PShapeAndInterferences)
220 Standard::Allocate(myLength*sizeof(BooleanOperations_ShapeAndInterferences));
221 // Modified Thu Sep 14 14:35:18 2006
222 // Contribution of Samtech www.samcef.com BEGIN
227 //for (i=0; i<2; ++i) {
231 // for (j=1; j<=aNbS; ++j) {
232 // const TopoDS_Shape& aSx=aMSA.FindKey(j);
233 // const BooleanOperations_AncestorsSeqAndSuccessorsSeq& aASx=
234 // aMSA.FindFromIndex(j);
235 // InsertShapeAndAncestorsSuccessors(aSx, aASx, aShift);
240 for (j=1; j<=aNbS; ++j) {
241 const TopoDS_Shape& aSx=aMSA.FindKey(j);
242 const BooleanOperations_AncestorsSeqAndSuccessorsSeq& aASx=aMSA.FindFromIndex(j);
243 InsertShapeAndAncestorsSuccessors(aSx, aASx, aShift);
245 // Contribution of Samtech www.samcef.com END
248 myShapeIndexMap.Clear();
250 aNbRanges=myRanges.Extent();
251 for (i=1; i<=aNbRanges; ++i){
252 BooleanOperations_IndexedDataMapOfShapeInteger aSIM;
254 const NMTDS_IndexRange& aR=myRanges(i);
257 for (j=iFirst; j<=iLast; ++j) {
258 const TopoDS_Shape& aS=Shape(j);
261 myShapeIndexMap.Add(i, aSIM);
265 iLast=myNumberOfShapesOfTheObject+myNumberOfShapesOfTheTool;
266 myRefEdges.Resize(iLast);
268 for (i=1; i<=iLast; ++i) {
269 const TopoDS_Shape& aS=Shape(i);
271 if (aS.ShapeType()==TopAbs_EDGE) {
273 myRefEdges(i)=myNbEdges;
277 //===========================================================================
278 //function : ShapeRangeIndex
280 //===========================================================================
281 Standard_Integer NMTDS_ShapesDataStructure::ShapeRangeIndex(const Standard_Integer aId)const
283 Standard_Boolean bFound;
284 Standard_Integer i, aNbR, aIdx, aNbS, aZero=0;
286 aNbS=myNumberOfShapesOfTheObject+myNumberOfShapesOfTheTool;
289 if (aIdx > aNbS || aIdx < 1){
293 if (aIdx > myNumberOfShapesOfTheObject) {
294 aIdx-=myNumberOfShapesOfTheObject;
297 aNbR=myRanges.Extent();
298 for (i=1; i<=aNbR; ++i) {
299 const NMTDS_IndexRange& aRange=myRanges(i);
300 bFound=aRange.IsInRange(aIdx);
307 //===========================================================================
310 //===========================================================================
311 Standard_Integer NMTDS_ShapesDataStructure::Rank(const Standard_Integer aId)const
313 Standard_Boolean bFound;
314 Standard_Integer i, aNbR, aNbS, aZero=0;
316 aNbS=myNumberOfShapesOfTheObject;
318 if (aId > aNbS || aId < 1){
322 aNbR=myRanges.Extent();
323 for (i=1; i<=aNbR; ++i) {
324 const NMTDS_IndexRange& aRange=myRanges(i);
325 bFound=aRange.IsInRange(aId);
332 //===========================================================================
333 //function : ShapeIndex
335 //===========================================================================
336 Standard_Integer NMTDS_ShapesDataStructure::ShapeIndex(const TopoDS_Shape& aS,
337 const Standard_Integer aRank)const
339 Standard_Boolean bFound;
340 Standard_Integer aIndex=0;
342 bFound=myShapeIndexMap.Contains(aRank);
346 // Modified Thu Sep 14 14:35:18 2006
347 // Contribution of Samtech www.samcef.com BEGIN
349 //const BooleanOperations_IndexedDataMapOfShapeInteger& aSIM=
350 // myShapeIndexMap.FindFromKey(aRank);
352 //bFound=aSIM.Contains(aS);
357 //aIndex=aSIM.FindFromKey(aS);
359 Standard_Integer i, aNbRanks;
361 aNbRanks=myShapeIndexMap.Extent();
362 for (i=1; i<=aNbRanks; ++i){
363 const BooleanOperations_IndexedDataMapOfShapeInteger& aSIM=myShapeIndexMap.FindFromKey(i);
364 bFound=aSIM.Contains(aS);
366 aIndex=aSIM.FindFromKey(aS);
370 // Contribution of Samtech www.samcef.com END
374 //=======================================================================
375 //function : ComputeBoxEx
377 //=======================================================================
378 void NMTDS_ShapesDataStructure::ComputeBoxEx (const Standard_Integer aIx,
379 Bnd_Box& aBoxEx)const
381 ComputeBoxExS(aIx, this, aBoxEx);
383 //=======================================================================
384 //function : GetAllSuccessors
386 //=======================================================================
387 void NMTDS_ShapesDataStructure::GetAllSuccessors(const Standard_Integer nS,
388 TColStd_IndexedMapOfInteger& aMA)const
390 GetAllSuccessorsS(nS, this, aMA);
392 //=======================================================================
393 //function : GetAllSuccessorsS
395 //=======================================================================
396 void GetAllSuccessorsS(const Standard_Integer nS,
397 const NMTDS_ShapesDataStructure* myDS,
398 TColStd_IndexedMapOfInteger& aMA)
401 Standard_Integer i, nSx, aNbSuccessors, *pSuccessors;
402 Standard_Address xSuccessors;
404 const TopoDS_Shape& aS=myDS->Shape(nS);
406 if(NMTDS_Tools::HasBRep(aT)) {
409 if (aT==TopAbs_VERTEX) {
414 myDS->GetSuccessors(nS, xSuccessors, aNbSuccessors);
415 pSuccessors=(Standard_Integer*)xSuccessors;
416 for (i=0; i<aNbSuccessors; ++i) {
418 GetAllSuccessorsS(nSx, myDS, aMA);
421 //=======================================================================
422 // function: ComputeBoxExS
424 //=======================================================================
425 void ComputeBoxExS(const Standard_Integer aIx,
426 const NMTDS_ShapesDataStructure* pDS,
429 Standard_Integer i, aNbS, iS;
431 const Bnd_Box& aBox=pDS->GetBoundingBox(aIx);
434 aNbS=pDS->NumberOfSuccessors(aIx);
435 for (i=1; i<=aNbS; ++i) {
437 iS=pDS->GetSuccessor(aIx, i);
438 ComputeBoxExS(iS, pDS, aBoxS);