1 // Copyright (C) 2007-2011 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 // Author: Peter KURNEV
25 #include <NMTDS_ShapesDataStructure.ixx>
26 #include <TopoDS_Iterator.hxx>
27 #include <TopoDS_Shape.hxx>
28 #include <BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors.hxx>
29 #include <NMTDS_ListOfIndexedDataMapOfShapeAncestorsSuccessors.hxx>
30 #include <NMTDS_ListIteratorOfListOfIndexedDataMapOfShapeAncestorsSuccessors.hxx>
31 #include <BooleanOperations_ShapeAndInterferences.hxx>
32 #include <NMTDS_IndexRange.hxx>
34 #include <BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors.hxx>
35 #include <BooleanOperations_AncestorsSeqAndSuccessorsSeq.hxx>
36 #include <TColStd_MapOfInteger.hxx>
37 #include <NMTDS_Tools.hxx>
41 void ComputeBoxExS(const Standard_Integer aIx,
42 const NMTDS_ShapesDataStructure* pDS,
45 void GetAllSuccessorsS(const Standard_Integer nS,
46 const NMTDS_ShapesDataStructure* myDS,
47 TColStd_IndexedMapOfInteger& aMA);
49 //===========================================================================
50 //function : NMTDS_ShapesDataStructure::NMTDS_ShapesDataStructure
52 //===========================================================================
53 NMTDS_ShapesDataStructure::NMTDS_ShapesDataStructure()
55 BooleanOperations_ShapesDataStructure()
57 //===========================================================================
58 //function : SetCompositeShape
60 //===========================================================================
61 void NMTDS_ShapesDataStructure::SetCompositeShape(const TopoDS_Shape& aS)
65 //===========================================================================
66 //function : CompositeShape
68 //===========================================================================
69 const TopoDS_Shape& NMTDS_ShapesDataStructure::CompositeShape()const
71 return myCompositeShape;
73 //===========================================================================
76 //===========================================================================
77 const NMTDS_CArray1OfIndexRange& NMTDS_ShapesDataStructure::Ranges()const
81 //===========================================================================
84 //===========================================================================
85 void NMTDS_ShapesDataStructure::FillMap
86 (const TopoDS_Shape& aS,
87 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aMSA,
88 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aMS) const
90 Standard_Integer iX, i, j, aIndex, aNbSc, aNbS;
91 BooleanOperations_AncestorsSeqAndSuccessorsSeq aAS;
95 FillSubshapes(aS, aMSA, aMS);
98 for(i=1; i<=aNbS; ++i) {
99 TColStd_MapOfInteger aMFence;
101 const TopoDS_Shape& aSX=aMS.FindKey(i);
102 iX=aMSA.FindIndex(aSX);
103 const BooleanOperations_AncestorsSeqAndSuccessorsSeq& aAS1=aMSA(iX);
105 aNbSc=aAS1.NumberOfSuccessors();
106 for(j=1; j<=aNbSc; ++j) {
107 aIndex=aAS1.GetSuccessor(j);
108 if(aMFence.Add(aIndex)) {
109 BooleanOperations_AncestorsSeqAndSuccessorsSeq& aAS2=aMSA.ChangeFromIndex(aIndex);
110 aAS2.SetNewAncestor(iX);
115 //===========================================================================
116 //function : FillSubshapes
118 //===========================================================================
119 void NMTDS_ShapesDataStructure::FillSubshapes
120 (const TopoDS_Shape& aS,
121 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aMSA,
122 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aMS) const
124 Standard_Boolean bIsNewSubShape;
125 Standard_Integer aIndexSubShape, aIndex;
126 BooleanOperations_AncestorsSeqAndSuccessorsSeq aASx;
128 aIndex=aMSA.FindIndex(aS);
129 BooleanOperations_AncestorsSeqAndSuccessorsSeq& aAS=aMSA.ChangeFromIndex(aIndex);
131 TopoDS_Iterator anIt(aS, Standard_True);
132 for(; anIt.More(); anIt.Next()) {
133 const TopoDS_Shape& aSubShape = anIt.Value();
134 bIsNewSubShape = Standard_False;
135 if(!aMSA.Contains(aSubShape)) {
136 bIsNewSubShape=!bIsNewSubShape;
137 aIndexSubShape=aMSA.Add(aSubShape, aASx);
138 aMS.Add(aSubShape, aASx);
141 aIndexSubShape=aMSA.FindIndex(aSubShape);
143 aAS.SetNewSuccessor(aIndexSubShape);
144 aAS.SetNewOrientation(aSubShape.Orientation());
146 if(bIsNewSubShape && (aSubShape.ShapeType() != TopAbs_VERTEX)) {
147 FillSubshapes(aSubShape, aMSA, aMS);
151 //===========================================================================
154 //===========================================================================
155 void NMTDS_ShapesDataStructure::Init()
157 Standard_Integer i, j, aNbSx, aNbS, aShift, aNbRanges;
158 Standard_Integer iFirst, iLast;
159 NMTDS_ListOfIndexedDataMapOfShapeAncestorsSuccessors aLx;
160 NMTDS_ListIteratorOfListOfIndexedDataMapOfShapeAncestorsSuccessors aLit;
161 TopoDS_Iterator anIt;
162 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors aMSA;
164 anIt.Initialize(myCompositeShape);
165 for (; anIt.More(); anIt.Next()) {
166 const TopoDS_Shape& aSx=anIt.Value();
167 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors aMS;
169 if (!aMSA.Contains(aSx)) {
170 FillMap(aSx, aMSA, aMS);
179 aLit.Initialize(aLx);
180 for (i=1; aLit.More(); aLit.Next(), ++i) {
181 const BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aMSx=aLit.Value();
186 myRanges(i).SetFirst(iFirst);
187 myRanges(i).SetLast(iLast);
190 iFirst=myRanges(i-1).Last()+1;
191 iLast=iFirst+aNbSx-1;
192 myRanges(i).SetFirst(iFirst);
193 myRanges(i).SetLast(iLast);
196 myNumberOfShapesOfTheObject=aNbS;
197 myNumberOfShapesOfTheTool=0;
200 // Allocate the whole Table
201 myListOfShapeAndInterferences = (BooleanOperations_PShapeAndInterferences)
202 Standard::Allocate(myLength*sizeof(BooleanOperations_ShapeAndInterferences));
207 for (j=1; j<=aNbS; ++j) {
208 const TopoDS_Shape& aSx=aMSA.FindKey(j);
209 const BooleanOperations_AncestorsSeqAndSuccessorsSeq& aASx=aMSA.FindFromIndex(j);
210 InsertShapeAndAncestorsSuccessors(aSx, aASx, aShift);
213 myShapeIndexMap.Clear();
215 //modified by NIZNHY-PKV Mon Dec 12 09:01:53 2011f
216 aNbRanges=myRanges.Extent();
217 for (i=1; i<=aNbRanges; ++i){
218 const NMTDS_IndexRange& aR=myRanges(i);
221 for (j=iFirst; j<=iLast; ++j) {
222 const TopoDS_Shape& aS=Shape(j);
223 myShapeIndexMap.Bind(aS, j);
226 //modified by NIZNHY-PKV Mon Dec 12 09:02:00 2011t
229 iLast=myNumberOfShapesOfTheObject+myNumberOfShapesOfTheTool;
230 myRefEdges.Resize(iLast);
232 for (i=1; i<=iLast; ++i) {
233 const TopoDS_Shape& aS=Shape(i);
235 if (aS.ShapeType()==TopAbs_EDGE) {
237 myRefEdges(i)=myNbEdges;
241 //===========================================================================
242 //function : ShapeRangeIndex
244 //===========================================================================
245 Standard_Integer NMTDS_ShapesDataStructure::ShapeRangeIndex
246 (const Standard_Integer aId)const
248 Standard_Boolean bFound;
249 Standard_Integer i, aNbR, aIdx, aNbS, aZero=0;
251 aNbS=myNumberOfShapesOfTheObject+myNumberOfShapesOfTheTool;
254 if (aIdx > aNbS || aIdx < 1){
258 if (aIdx > myNumberOfShapesOfTheObject) {
259 aIdx-=myNumberOfShapesOfTheObject;
262 aNbR=myRanges.Extent();
263 for (i=1; i<=aNbR; ++i) {
264 const NMTDS_IndexRange& aRange=myRanges(i);
265 bFound=aRange.IsInRange(aIdx);
272 //===========================================================================
275 //===========================================================================
276 Standard_Integer NMTDS_ShapesDataStructure::Rank
277 (const Standard_Integer aId)const
279 Standard_Boolean bFound;
280 Standard_Integer i, aNbR, aNbS, aZero=0;
282 aNbS=myNumberOfShapesOfTheObject;
284 if (aId > aNbS || aId < 1){
288 aNbR=myRanges.Extent();
289 for (i=1; i<=aNbR; ++i) {
290 const NMTDS_IndexRange& aRange=myRanges(i);
291 bFound=aRange.IsInRange(aId);
298 //===========================================================================
299 //function : ShapeIndex
301 //===========================================================================
302 Standard_Integer NMTDS_ShapesDataStructure::ShapeIndex
303 (const TopoDS_Shape& aS,
304 const Standard_Integer aRank)const
306 Standard_Address pIndex;
307 Standard_Integer aIndex;
311 //modified by NIZNHY-PKV Mon Dec 12 09:02:48 2011f
312 pIndex=myShapeIndexMap.Find1(aS);
314 aIndex=*((Standard_Integer*)pIndex);
316 //modified by NIZNHY-PKV Mon Dec 12 09:02:54 2011t
320 //=======================================================================
321 //function : ComputeBoxEx
323 //=======================================================================
324 void NMTDS_ShapesDataStructure::ComputeBoxEx
325 (const Standard_Integer aIx,
326 Bnd_Box& aBoxEx)const
328 ComputeBoxExS(aIx, this, aBoxEx);
330 //=======================================================================
331 //function : GetAllSuccessors
333 //=======================================================================
334 void NMTDS_ShapesDataStructure::GetAllSuccessors
335 (const Standard_Integer nS,
336 TColStd_IndexedMapOfInteger& aMA)const
338 GetAllSuccessorsS(nS, this, aMA);
340 //=======================================================================
341 //function : GetAllSuccessorsS
343 //=======================================================================
344 void GetAllSuccessorsS(const Standard_Integer nS,
345 const NMTDS_ShapesDataStructure* myDS,
346 TColStd_IndexedMapOfInteger& aMA)
349 Standard_Integer i, nSx, aNbSuccessors, *pSuccessors;
350 Standard_Address xSuccessors;
352 const TopoDS_Shape& aS=myDS->Shape(nS);
354 if(NMTDS_Tools::HasBRep(aT)) {
357 if (aT==TopAbs_VERTEX) {
362 myDS->GetSuccessors(nS, xSuccessors, aNbSuccessors);
363 pSuccessors=(Standard_Integer*)xSuccessors;
364 for (i=0; i<aNbSuccessors; ++i) {
366 GetAllSuccessorsS(nSx, myDS, aMA);
369 //=======================================================================
370 // function: ComputeBoxExS
372 //=======================================================================
373 void ComputeBoxExS(const Standard_Integer aIx,
374 const NMTDS_ShapesDataStructure* pDS,
377 Standard_Integer i, aNbS, iS;
379 const Bnd_Box& aBox=pDS->GetBoundingBox(aIx);
382 aNbS=pDS->NumberOfSuccessors(aIx);
383 for (i=1; i<=aNbS; ++i) {
385 iS=pDS->GetSuccessor(aIx, i);
386 ComputeBoxExS(iS, pDS, aBoxS);