1 // Copyright (C) 2007-2008 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
22 // File: NMTDS_ShapesDataStructure.cxx
23 // Created: Mon Dec 1 10:21:04 2003
24 // Author: Peter KURNEV
27 #include <NMTDS_ShapesDataStructure.ixx>
28 #include <TopoDS_Iterator.hxx>
29 #include <TopoDS_Shape.hxx>
30 #include <BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors.hxx>
31 #include <NMTDS_ListOfIndexedDataMapOfShapeAncestorsSuccessors.hxx>
32 #include <NMTDS_ListIteratorOfListOfIndexedDataMapOfShapeAncestorsSuccessors.hxx>
33 #include <BooleanOperations_ShapeAndInterferences.hxx>
34 #include <NMTDS_IndexRange.hxx>
36 #include <BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors.hxx>
37 #include <BooleanOperations_AncestorsSeqAndSuccessorsSeq.hxx>
38 #include <TColStd_MapOfInteger.hxx>
39 #include <NMTDS_Tools.hxx>
43 void ComputeBoxExS(const Standard_Integer aIx,
44 const NMTDS_ShapesDataStructure* pDS,
47 void GetAllSuccessorsS(const Standard_Integer nS,
48 const NMTDS_ShapesDataStructure* myDS,
49 TColStd_IndexedMapOfInteger& aMA);
51 //===========================================================================
52 //function : NMTDS_ShapesDataStructure::NMTDS_ShapesDataStructure
54 //===========================================================================
55 NMTDS_ShapesDataStructure::NMTDS_ShapesDataStructure()
57 BooleanOperations_ShapesDataStructure()
59 //===========================================================================
60 //function : SetCompositeShape
62 //===========================================================================
63 void NMTDS_ShapesDataStructure::SetCompositeShape(const TopoDS_Shape& aS)
67 //===========================================================================
68 //function : CompositeShape
70 //===========================================================================
71 const TopoDS_Shape& NMTDS_ShapesDataStructure::CompositeShape()const
73 return myCompositeShape;
75 //===========================================================================
78 //===========================================================================
79 const NMTDS_CArray1OfIndexRange& NMTDS_ShapesDataStructure::Ranges()const
83 // Modified to Add new methods Thu Sep 14 14:35:18 2006
84 // Contribution of Samtech www.samcef.com BEGIN
85 //===========================================================================
88 //===========================================================================
89 void NMTDS_ShapesDataStructure::FillMap
90 (const TopoDS_Shape& aS,
91 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aMSA,
92 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aMS) const
94 Standard_Integer iX, i, j, aIndex, aNbSc, aNbS;
95 BooleanOperations_AncestorsSeqAndSuccessorsSeq aAS;
99 FillSubshapes(aS, aMSA, aMS);
102 for(i=1; i<=aNbS; ++i) {
103 TColStd_MapOfInteger aMFence;
105 const TopoDS_Shape& aSX=aMS.FindKey(i);
106 iX=aMSA.FindIndex(aSX);
107 const BooleanOperations_AncestorsSeqAndSuccessorsSeq& aAS1=aMSA(iX);
109 aNbSc=aAS1.NumberOfSuccessors();
110 for(j=1; j<=aNbSc; ++j) {
111 aIndex=aAS1.GetSuccessor(j);
112 if(aMFence.Add(aIndex)) {
113 BooleanOperations_AncestorsSeqAndSuccessorsSeq& aAS2=aMSA.ChangeFromIndex(aIndex);
114 aAS2.SetNewAncestor(iX);
119 //===========================================================================
120 //function : FillSubshapes
122 //===========================================================================
123 void NMTDS_ShapesDataStructure::FillSubshapes
124 (const TopoDS_Shape& aS,
125 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aMSA,
126 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aMS) const
128 Standard_Boolean bIsNewSubShape;
129 Standard_Integer aIndexSubShape, aIndex;
130 BooleanOperations_AncestorsSeqAndSuccessorsSeq aASx;
132 aIndex=aMSA.FindIndex(aS);
133 BooleanOperations_AncestorsSeqAndSuccessorsSeq& aAS=aMSA.ChangeFromIndex(aIndex);
135 TopoDS_Iterator anIt(aS, Standard_True);
136 for(; anIt.More(); anIt.Next()) {
137 const TopoDS_Shape& aSubShape = anIt.Value();
138 bIsNewSubShape = Standard_False;
139 if(!aMSA.Contains(aSubShape)) {
140 bIsNewSubShape=!bIsNewSubShape;
141 aIndexSubShape=aMSA.Add(aSubShape, aASx);
142 aMS.Add(aSubShape, aASx);
145 aIndexSubShape=aMSA.FindIndex(aSubShape);
147 aAS.SetNewSuccessor(aIndexSubShape);
148 aAS.SetNewOrientation(aSubShape.Orientation());
150 if(bIsNewSubShape && (aSubShape.ShapeType() != TopAbs_VERTEX)) {
151 FillSubshapes(aSubShape, aMSA, aMS);
155 // Contribution of Samtech www.samcef.com END
156 //===========================================================================
159 //===========================================================================
160 void NMTDS_ShapesDataStructure::Init()
162 Standard_Integer i, j, aNbSx, aNbS, aShift, aNbRanges;
163 Standard_Integer iFirst, iLast;
164 NMTDS_ListOfIndexedDataMapOfShapeAncestorsSuccessors aLx;
165 NMTDS_ListIteratorOfListOfIndexedDataMapOfShapeAncestorsSuccessors aLit;
166 TopoDS_Iterator anIt;
167 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors aMSA;
169 anIt.Initialize(myCompositeShape);
170 for (; anIt.More(); anIt.Next()) {
171 const TopoDS_Shape& aSx=anIt.Value();
172 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors aMS;
173 //modified by NIZNHY-PKV Tue Feb 27 17:05:47 2007f
174 //FillMap(aSx, aMSA, aMS);
177 if (!aMSA.Contains(aSx)) {
178 FillMap(aSx, aMSA, aMS);
181 //modified by NIZNHY-PKV Tue Feb 27 17:06:03 2007t
186 //modified by NIZNHY-PKV Tue Feb 27 17:10:07 2007f
188 //modified by NIZNHY-PKV Tue Feb 27 17:10:10 2007t
190 aLit.Initialize(aLx);
191 for (i=1; aLit.More(); aLit.Next(), ++i) {
192 // Modified Thu Sep 14 14:35:18 2006
193 // Contribution of Samtech www.samcef.com BEGIN
194 const BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aMSx=aLit.Value();
196 // Contribution of Samtech www.samcef.com END
200 myRanges(i).SetFirst(iFirst);
201 myRanges(i).SetLast(iLast);
204 iFirst=myRanges(i-1).Last()+1;
205 iLast=iFirst+aNbSx-1;
206 myRanges(i).SetFirst(iFirst);
207 myRanges(i).SetLast(iLast);
210 myNumberOfShapesOfTheObject=aNbS;
211 // Modified Thu Sep 14 14:35:18 2006
212 // Contribution of Samtech www.samcef.com BEGIN
213 //myNumberOfShapesOfTheTool=aNbS;
215 myNumberOfShapesOfTheTool=0;
217 // Contribution of Samtech www.samcef.com END
219 // Allocate the whole Table
220 myListOfShapeAndInterferences = (BooleanOperations_PShapeAndInterferences)
221 Standard::Allocate(myLength*sizeof(BooleanOperations_ShapeAndInterferences));
222 // Modified Thu Sep 14 14:35:18 2006
223 // Contribution of Samtech www.samcef.com BEGIN
228 //for (i=0; i<2; ++i) {
232 // for (j=1; j<=aNbS; ++j) {
233 // const TopoDS_Shape& aSx=aMSA.FindKey(j);
234 // const BooleanOperations_AncestorsSeqAndSuccessorsSeq& aASx=
235 // aMSA.FindFromIndex(j);
236 // InsertShapeAndAncestorsSuccessors(aSx, aASx, aShift);
241 for (j=1; j<=aNbS; ++j) {
242 const TopoDS_Shape& aSx=aMSA.FindKey(j);
243 const BooleanOperations_AncestorsSeqAndSuccessorsSeq& aASx=aMSA.FindFromIndex(j);
244 InsertShapeAndAncestorsSuccessors(aSx, aASx, aShift);
246 // Contribution of Samtech www.samcef.com END
249 myShapeIndexMap.Clear();
251 aNbRanges=myRanges.Extent();
252 for (i=1; i<=aNbRanges; ++i){
253 BooleanOperations_IndexedDataMapOfShapeInteger aSIM;
255 const NMTDS_IndexRange& aR=myRanges(i);
258 for (j=iFirst; j<=iLast; ++j) {
259 const TopoDS_Shape& aS=Shape(j);
262 myShapeIndexMap.Add(i, aSIM);
266 iLast=myNumberOfShapesOfTheObject+myNumberOfShapesOfTheTool;
267 myRefEdges.Resize(iLast);
269 for (i=1; i<=iLast; ++i) {
270 const TopoDS_Shape& aS=Shape(i);
272 if (aS.ShapeType()==TopAbs_EDGE) {
274 myRefEdges(i)=myNbEdges;
278 //===========================================================================
279 //function : ShapeRangeIndex
281 //===========================================================================
282 Standard_Integer NMTDS_ShapesDataStructure::ShapeRangeIndex(const Standard_Integer aId)const
284 Standard_Boolean bFound;
285 Standard_Integer i, aNbR, aIdx, aNbS, aZero=0;
287 aNbS=myNumberOfShapesOfTheObject+myNumberOfShapesOfTheTool;
290 if (aIdx > aNbS || aIdx < 1){
294 if (aIdx > myNumberOfShapesOfTheObject) {
295 aIdx-=myNumberOfShapesOfTheObject;
298 aNbR=myRanges.Extent();
299 for (i=1; i<=aNbR; ++i) {
300 const NMTDS_IndexRange& aRange=myRanges(i);
301 bFound=aRange.IsInRange(aIdx);
308 //===========================================================================
311 //===========================================================================
312 Standard_Integer NMTDS_ShapesDataStructure::Rank(const Standard_Integer aId)const
314 Standard_Boolean bFound;
315 Standard_Integer i, aNbR, aNbS, aZero=0;
317 aNbS=myNumberOfShapesOfTheObject;
319 if (aId > aNbS || aId < 1){
323 aNbR=myRanges.Extent();
324 for (i=1; i<=aNbR; ++i) {
325 const NMTDS_IndexRange& aRange=myRanges(i);
326 bFound=aRange.IsInRange(aId);
333 //===========================================================================
334 //function : ShapeIndex
336 //===========================================================================
337 Standard_Integer NMTDS_ShapesDataStructure::ShapeIndex(const TopoDS_Shape& aS,
338 const Standard_Integer aRank)const
340 Standard_Boolean bFound;
341 Standard_Integer aIndex=0;
343 bFound=myShapeIndexMap.Contains(aRank);
347 // Modified Thu Sep 14 14:35:18 2006
348 // Contribution of Samtech www.samcef.com BEGIN
350 //const BooleanOperations_IndexedDataMapOfShapeInteger& aSIM=
351 // myShapeIndexMap.FindFromKey(aRank);
353 //bFound=aSIM.Contains(aS);
358 //aIndex=aSIM.FindFromKey(aS);
360 Standard_Integer i, aNbRanks;
362 aNbRanks=myShapeIndexMap.Extent();
363 for (i=1; i<=aNbRanks; ++i){
364 const BooleanOperations_IndexedDataMapOfShapeInteger& aSIM=myShapeIndexMap.FindFromKey(i);
365 bFound=aSIM.Contains(aS);
367 aIndex=aSIM.FindFromKey(aS);
371 // Contribution of Samtech www.samcef.com END
375 //=======================================================================
376 //function : ComputeBoxEx
378 //=======================================================================
379 void NMTDS_ShapesDataStructure::ComputeBoxEx (const Standard_Integer aIx,
380 Bnd_Box& aBoxEx)const
382 ComputeBoxExS(aIx, this, aBoxEx);
384 //=======================================================================
385 //function : GetAllSuccessors
387 //=======================================================================
388 void NMTDS_ShapesDataStructure::GetAllSuccessors(const Standard_Integer nS,
389 TColStd_IndexedMapOfInteger& aMA)const
391 GetAllSuccessorsS(nS, this, aMA);
393 //=======================================================================
394 //function : GetAllSuccessorsS
396 //=======================================================================
397 void GetAllSuccessorsS(const Standard_Integer nS,
398 const NMTDS_ShapesDataStructure* myDS,
399 TColStd_IndexedMapOfInteger& aMA)
402 Standard_Integer i, nSx, aNbSuccessors, *pSuccessors;
403 Standard_Address xSuccessors;
405 const TopoDS_Shape& aS=myDS->Shape(nS);
407 if(NMTDS_Tools::HasBRep(aT)) {
410 if (aT==TopAbs_VERTEX) {
415 myDS->GetSuccessors(nS, xSuccessors, aNbSuccessors);
416 pSuccessors=(Standard_Integer*)xSuccessors;
417 for (i=0; i<aNbSuccessors; ++i) {
419 GetAllSuccessorsS(nSx, myDS, aMA);
422 //=======================================================================
423 // function: ComputeBoxExS
425 //=======================================================================
426 void ComputeBoxExS(const Standard_Integer aIx,
427 const NMTDS_ShapesDataStructure* pDS,
430 Standard_Integer i, aNbS, iS;
432 const Bnd_Box& aBox=pDS->GetBoundingBox(aIx);
435 aNbS=pDS->NumberOfSuccessors(aIx);
436 for (i=1; i<=aNbS; ++i) {
438 iS=pDS->GetSuccessor(aIx, i);
439 ComputeBoxExS(iS, pDS, aBoxS);