1 // Copyright (C) 2007-2012 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 // Author: Peter KURNEV
26 #include <NMTDS_ShapesDataStructure.hxx>
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 //===========================================================================
85 //===========================================================================
86 void NMTDS_ShapesDataStructure::FillMap
87 (const TopoDS_Shape& aS,
88 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aMSA,
89 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aMS) const
91 Standard_Integer iX, i, j, aIndex, aNbSc, aNbS;
92 BooleanOperations_AncestorsSeqAndSuccessorsSeq aAS;
96 FillSubshapes(aS, aMSA, aMS);
99 for(i=1; i<=aNbS; ++i) {
100 TColStd_MapOfInteger aMFence;
102 const TopoDS_Shape& aSX=aMS.FindKey(i);
103 iX=aMSA.FindIndex(aSX);
104 const BooleanOperations_AncestorsSeqAndSuccessorsSeq& aAS1=aMSA(iX);
106 aNbSc=aAS1.NumberOfSuccessors();
107 for(j=1; j<=aNbSc; ++j) {
108 aIndex=aAS1.GetSuccessor(j);
109 if(aMFence.Add(aIndex)) {
110 BooleanOperations_AncestorsSeqAndSuccessorsSeq& aAS2=aMSA.ChangeFromIndex(aIndex);
111 aAS2.SetNewAncestor(iX);
116 //===========================================================================
117 //function : FillSubshapes
119 //===========================================================================
120 void NMTDS_ShapesDataStructure::FillSubshapes
121 (const TopoDS_Shape& aS,
122 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aMSA,
123 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aMS) const
125 Standard_Boolean bIsNewSubShape;
126 Standard_Integer aIndexSubShape, aIndex;
127 BooleanOperations_AncestorsSeqAndSuccessorsSeq aASx;
129 aIndex=aMSA.FindIndex(aS);
130 BooleanOperations_AncestorsSeqAndSuccessorsSeq& aAS=aMSA.ChangeFromIndex(aIndex);
132 TopoDS_Iterator anIt(aS, Standard_True);
133 for(; anIt.More(); anIt.Next()) {
134 const TopoDS_Shape& aSubShape = anIt.Value();
135 bIsNewSubShape = Standard_False;
136 if(!aMSA.Contains(aSubShape)) {
137 bIsNewSubShape=!bIsNewSubShape;
138 aIndexSubShape=aMSA.Add(aSubShape, aASx);
139 aMS.Add(aSubShape, aASx);
142 aIndexSubShape=aMSA.FindIndex(aSubShape);
144 aAS.SetNewSuccessor(aIndexSubShape);
145 aAS.SetNewOrientation(aSubShape.Orientation());
147 if(bIsNewSubShape && (aSubShape.ShapeType() != TopAbs_VERTEX)) {
148 FillSubshapes(aSubShape, aMSA, aMS);
152 //===========================================================================
155 //===========================================================================
156 void NMTDS_ShapesDataStructure::Init()
158 Standard_Integer i, j, aNbSx, aNbS, aShift, aNbRanges;
159 Standard_Integer iFirst, iLast;
160 NMTDS_ListOfIndexedDataMapOfShapeAncestorsSuccessors aLx;
161 NMTDS_ListIteratorOfListOfIndexedDataMapOfShapeAncestorsSuccessors aLit;
162 TopoDS_Iterator anIt;
163 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors aMSA;
165 anIt.Initialize(myCompositeShape);
166 for (; anIt.More(); anIt.Next()) {
167 const TopoDS_Shape& aSx=anIt.Value();
168 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors aMS;
170 if (!aMSA.Contains(aSx)) {
171 FillMap(aSx, aMSA, aMS);
180 aLit.Initialize(aLx);
181 for (i=1; aLit.More(); aLit.Next(), ++i) {
182 const BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aMSx=aLit.Value();
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 myNumberOfShapesOfTheTool=0;
201 // Allocate the whole Table
202 myListOfShapeAndInterferences = (BooleanOperations_PShapeAndInterferences)
203 Standard::Allocate(myLength*sizeof(BooleanOperations_ShapeAndInterferences));
208 for (j=1; j<=aNbS; ++j) {
209 const TopoDS_Shape& aSx=aMSA.FindKey(j);
210 const BooleanOperations_AncestorsSeqAndSuccessorsSeq& aASx=aMSA.FindFromIndex(j);
211 InsertShapeAndAncestorsSuccessors(aSx, aASx, aShift);
214 myShapeIndexMap.Clear();
216 //modified by NIZNHY-PKV Mon Dec 12 09:01:53 2011f
217 aNbRanges=myRanges.Extent();
218 for (i=1; i<=aNbRanges; ++i){
219 const NMTDS_IndexRange& aR=myRanges(i);
222 for (j=iFirst; j<=iLast; ++j) {
223 const TopoDS_Shape& aS=Shape(j);
224 myShapeIndexMap.Bind(aS, j);
227 //modified by NIZNHY-PKV Mon Dec 12 09:02:00 2011t
230 iLast=myNumberOfShapesOfTheObject+myNumberOfShapesOfTheTool;
231 myRefEdges.Resize(iLast);
233 for (i=1; i<=iLast; ++i) {
234 const TopoDS_Shape& aS=Shape(i);
236 if (aS.ShapeType()==TopAbs_EDGE) {
238 myRefEdges(i)=myNbEdges;
242 //===========================================================================
243 //function : ShapeRangeIndex
245 //===========================================================================
246 Standard_Integer NMTDS_ShapesDataStructure::ShapeRangeIndex
247 (const Standard_Integer aId)const
249 Standard_Boolean bFound;
250 Standard_Integer i, aNbR, aIdx, aNbS, aZero=0;
252 aNbS=myNumberOfShapesOfTheObject+myNumberOfShapesOfTheTool;
255 if (aIdx > aNbS || aIdx < 1){
259 if (aIdx > myNumberOfShapesOfTheObject) {
260 aIdx-=myNumberOfShapesOfTheObject;
263 aNbR=myRanges.Extent();
264 for (i=1; i<=aNbR; ++i) {
265 const NMTDS_IndexRange& aRange=myRanges(i);
266 bFound=aRange.IsInRange(aIdx);
273 //===========================================================================
276 //===========================================================================
277 Standard_Integer NMTDS_ShapesDataStructure::Rank
278 (const Standard_Integer aId)const
280 Standard_Boolean bFound;
281 Standard_Integer i, aNbR, aNbS, aZero=0;
283 aNbS=myNumberOfShapesOfTheObject;
285 if (aId > aNbS || aId < 1){
289 aNbR=myRanges.Extent();
290 for (i=1; i<=aNbR; ++i) {
291 const NMTDS_IndexRange& aRange=myRanges(i);
292 bFound=aRange.IsInRange(aId);
299 //===========================================================================
300 //function : ShapeIndex
302 //===========================================================================
303 Standard_Integer NMTDS_ShapesDataStructure::ShapeIndex
304 (const TopoDS_Shape& aS,
305 const Standard_Integer aRank)const
307 Standard_Address pIndex;
308 Standard_Integer aIndex;
312 //modified by NIZNHY-PKV Mon Dec 12 09:02:48 2011f
313 pIndex=myShapeIndexMap.Find1(aS);
315 aIndex=*((Standard_Integer*)pIndex);
317 //modified by NIZNHY-PKV Mon Dec 12 09:02:54 2011t
321 //=======================================================================
322 //function : ComputeBoxEx
324 //=======================================================================
325 void NMTDS_ShapesDataStructure::ComputeBoxEx
326 (const Standard_Integer aIx,
327 Bnd_Box& aBoxEx)const
329 ComputeBoxExS(aIx, this, aBoxEx);
331 //=======================================================================
332 //function : GetAllSuccessors
334 //=======================================================================
335 void NMTDS_ShapesDataStructure::GetAllSuccessors
336 (const Standard_Integer nS,
337 TColStd_IndexedMapOfInteger& aMA)const
339 GetAllSuccessorsS(nS, this, aMA);
341 //=======================================================================
342 //function : GetAllSuccessorsS
344 //=======================================================================
345 void GetAllSuccessorsS(const Standard_Integer nS,
346 const NMTDS_ShapesDataStructure* myDS,
347 TColStd_IndexedMapOfInteger& aMA)
350 Standard_Integer i, nSx, aNbSuccessors, *pSuccessors;
351 Standard_Address xSuccessors;
353 const TopoDS_Shape& aS=myDS->Shape(nS);
355 if(NMTDS_Tools::HasBRep(aT)) {
358 if (aT==TopAbs_VERTEX) {
363 myDS->GetSuccessors(nS, xSuccessors, aNbSuccessors);
364 pSuccessors=(Standard_Integer*)xSuccessors;
365 for (i=0; i<aNbSuccessors; ++i) {
367 GetAllSuccessorsS(nSx, myDS, aMA);
370 //=======================================================================
371 // function: ComputeBoxExS
373 //=======================================================================
374 void ComputeBoxExS(const Standard_Integer aIx,
375 const NMTDS_ShapesDataStructure* pDS,
378 Standard_Integer i, aNbS, iS;
380 const Bnd_Box& aBox=pDS->GetBoundingBox(aIx);
383 aNbS=pDS->NumberOfSuccessors(aIx);
384 for (i=1; i<=aNbS; ++i) {
386 iS=pDS->GetSuccessor(aIx, i);
387 ComputeBoxExS(iS, pDS, aBoxS);