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>
28 #include <TColStd_MapOfInteger.hxx>
30 #include <TopoDS_Iterator.hxx>
31 #include <TopoDS_Shape.hxx>
33 #include <BooleanOperations_ShapeAndInterferences.hxx>
34 #include <BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors.hxx>
35 #include <BooleanOperations_AncestorsSeqAndSuccessorsSeq.hxx>
37 #include <NMTDS_ListOfIndexedDataMapOfShapeAncestorsSuccessors.hxx>
38 #include <NMTDS_ListIteratorOfListOfIndexedDataMapOfShapeAncestorsSuccessors.hxx>
39 #include <NMTDS_IndexRange.hxx>
41 //===========================================================================
42 //function : NMTDS_ShapesDataStructure::NMTDS_ShapesDataStructure
44 //===========================================================================
45 NMTDS_ShapesDataStructure::NMTDS_ShapesDataStructure()
47 BooleanOperations_ShapesDataStructure()
49 //===========================================================================
50 //function : SetCompositeShape
52 //===========================================================================
53 void NMTDS_ShapesDataStructure::SetCompositeShape(const TopoDS_Shape& aS)
57 //===========================================================================
58 //function : CompositeShape
60 //===========================================================================
61 const TopoDS_Shape& NMTDS_ShapesDataStructure::CompositeShape()const
63 return myCompositeShape;
65 //===========================================================================
68 //===========================================================================
69 const NMTDS_CArray1OfIndexRange& NMTDS_ShapesDataStructure::Ranges()const
73 // Modified to Add new methods Thu Sep 14 14:35:18 2006
74 // Contribution of Samtech www.samcef.com BEGIN
75 //===========================================================================
78 //===========================================================================
79 void NMTDS_ShapesDataStructure::FillMap
80 (const TopoDS_Shape& aS,
81 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aMSA,
82 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aMS) const
84 Standard_Integer iX, i, j, aIndex, aNbSc, aNbS;
85 BooleanOperations_AncestorsSeqAndSuccessorsSeq aAS;
89 FillSubshapes(aS, aMSA, aMS);
92 for(i=1; i<=aNbS; ++i) {
93 TColStd_MapOfInteger aMFence;
95 const TopoDS_Shape& aSX=aMS.FindKey(i);
96 iX=aMSA.FindIndex(aSX);
97 const BooleanOperations_AncestorsSeqAndSuccessorsSeq& aAS1=aMSA(iX);
99 aNbSc=aAS1.NumberOfSuccessors();
100 for(j=1; j<=aNbSc; ++j) {
101 aIndex=aAS1.GetSuccessor(j);
102 if(aMFence.Add(aIndex)) {
103 BooleanOperations_AncestorsSeqAndSuccessorsSeq& aAS2=aMSA.ChangeFromIndex(aIndex);
104 aAS2.SetNewAncestor(iX);
109 //===========================================================================
110 //function : FillSubshapes
112 //===========================================================================
113 void NMTDS_ShapesDataStructure::FillSubshapes
114 (const TopoDS_Shape& aS,
115 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aMSA,
116 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aMS) const
118 Standard_Boolean bIsNewSubShape;
119 Standard_Integer aIndexSubShape, aIndex;
120 BooleanOperations_AncestorsSeqAndSuccessorsSeq aASx;
122 aIndex=aMSA.FindIndex(aS);
123 BooleanOperations_AncestorsSeqAndSuccessorsSeq& aAS=aMSA.ChangeFromIndex(aIndex);
125 TopoDS_Iterator anIt(aS, Standard_True);
126 for(; anIt.More(); anIt.Next()) {
127 const TopoDS_Shape& aSubShape = anIt.Value();
128 bIsNewSubShape = Standard_False;
129 if(!aMSA.Contains(aSubShape)) {
130 bIsNewSubShape=!bIsNewSubShape;
131 aIndexSubShape=aMSA.Add(aSubShape, aASx);
132 aMS.Add(aSubShape, aASx);
135 aIndexSubShape=aMSA.FindIndex(aSubShape);
137 aAS.SetNewSuccessor(aIndexSubShape);
138 aAS.SetNewOrientation(aSubShape.Orientation());
140 if(bIsNewSubShape && (aSubShape.ShapeType() != TopAbs_VERTEX)) {
141 FillSubshapes(aSubShape, aMSA, aMS);
145 // Contribution of Samtech www.samcef.com END
146 //===========================================================================
149 //===========================================================================
150 void NMTDS_ShapesDataStructure::Init()
152 Standard_Integer i, j, aNbSx, aNbS, aShift, aNbRanges;
153 Standard_Integer iFirst, iLast;
154 NMTDS_ListOfIndexedDataMapOfShapeAncestorsSuccessors aLx;
155 NMTDS_ListIteratorOfListOfIndexedDataMapOfShapeAncestorsSuccessors aLit;
156 TopoDS_Iterator anIt;
157 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors aMSA;
159 anIt.Initialize(myCompositeShape);
160 for (; anIt.More(); anIt.Next()) {
161 const TopoDS_Shape& aSx=anIt.Value();
162 BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors aMS;
163 //modified by NIZNHY-PKV Tue Feb 27 17:05:47 2007f
164 //FillMap(aSx, aMSA, aMS);
167 if (!aMSA.Contains(aSx)) {
168 FillMap(aSx, aMSA, aMS);
171 //modified by NIZNHY-PKV Tue Feb 27 17:06:03 2007t
177 //modified by NIZNHY-PKV Tue Feb 27 17:10:07 2007f
179 //modified by NIZNHY-PKV Tue Feb 27 17:10:10 2007t
181 aLit.Initialize(aLx);
182 for (i=1; aLit.More(); aLit.Next(), ++i) {
183 // Modified Thu Sep 14 14:35:18 2006
184 // Contribution of Samtech www.samcef.com BEGIN
185 const BooleanOperations_IndexedDataMapOfShapeAncestorsSuccessors& aMSx=aLit.Value();
187 // Contribution of Samtech www.samcef.com END
191 myRanges(i).SetFirst(iFirst);
192 myRanges(i).SetLast(iLast);
195 iFirst=myRanges(i-1).Last()+1;
196 iLast=iFirst+aNbSx-1;
197 myRanges(i).SetFirst(iFirst);
198 myRanges(i).SetLast(iLast);
201 myNumberOfShapesOfTheObject=aNbS;
202 // Modified Thu Sep 14 14:35:18 2006
203 // Contribution of Samtech www.samcef.com BEGIN
204 //myNumberOfShapesOfTheTool=aNbS;
206 myNumberOfShapesOfTheTool=0;
208 // Contribution of Samtech www.samcef.com END
210 // Allocate the whole Table
211 myListOfShapeAndInterferences = (BooleanOperations_PShapeAndInterferences)
212 Standard::Allocate(myLength*sizeof(BooleanOperations_ShapeAndInterferences));
213 // Modified Thu Sep 14 14:35:18 2006
214 // Contribution of Samtech www.samcef.com BEGIN
218 //for (i=0; i<2; ++i) {
222 // for (j=1; j<=aNbS; ++j) {
223 // const TopoDS_Shape& aSx=aMSA.FindKey(j);
224 // const BooleanOperations_AncestorsSeqAndSuccessorsSeq& aASx=
225 // aMSA.FindFromIndex(j);
226 // InsertShapeAndAncestorsSuccessors(aSx, aASx, aShift);
231 for (j=1; j<=aNbS; ++j) {
232 const TopoDS_Shape& aSx=aMSA.FindKey(j);
233 const BooleanOperations_AncestorsSeqAndSuccessorsSeq& aASx=aMSA.FindFromIndex(j);
234 InsertShapeAndAncestorsSuccessors(aSx, aASx, aShift);
236 // Contribution of Samtech www.samcef.com END
239 myShapeIndexMap.Clear();
241 aNbRanges=myRanges.Extent();
242 for (i=1; i<=aNbRanges; ++i){
243 BooleanOperations_IndexedDataMapOfShapeInteger aSIM;
245 const NMTDS_IndexRange& aR=myRanges(i);
248 for (j=iFirst; j<=iLast; ++j) {
249 const TopoDS_Shape& aS=Shape(j);
252 myShapeIndexMap.Add(i, aSIM);
256 iLast=myNumberOfShapesOfTheObject+myNumberOfShapesOfTheTool;
257 myRefEdges.Resize(iLast);
259 for (i=1; i<=iLast; ++i) {
260 const TopoDS_Shape& aS=Shape(i);
262 if (aS.ShapeType()==TopAbs_EDGE) {
264 myRefEdges(i)=myNbEdges;
268 //===========================================================================
269 //function : ShapeRangeIndex
271 //===========================================================================
272 Standard_Integer NMTDS_ShapesDataStructure::ShapeRangeIndex(const Standard_Integer aId)const
274 Standard_Boolean bFound;
275 Standard_Integer i, aNbR, aIdx, aNbS, aZero=0;
277 aNbS=myNumberOfShapesOfTheObject+myNumberOfShapesOfTheTool;
280 if (aIdx > aNbS || aIdx < 1){
284 if (aIdx > myNumberOfShapesOfTheObject) {
285 aIdx-=myNumberOfShapesOfTheObject;
288 aNbR=myRanges.Extent();
289 for (i=1; i<=aNbR; ++i) {
290 const NMTDS_IndexRange& aRange=myRanges(i);
291 bFound=aRange.IsInRange(aIdx);
298 //===========================================================================
301 //===========================================================================
302 Standard_Integer NMTDS_ShapesDataStructure::Rank(const Standard_Integer aId)const
304 Standard_Boolean bFound;
305 Standard_Integer i, aNbR, aNbS, aZero=0;
307 aNbS=myNumberOfShapesOfTheObject;
309 if (aId > aNbS || aId < 1){
313 aNbR=myRanges.Extent();
314 for (i=1; i<=aNbR; ++i) {
315 const NMTDS_IndexRange& aRange=myRanges(i);
316 bFound=aRange.IsInRange(aId);
323 //===========================================================================
324 //function : ShapeIndex
326 //===========================================================================
327 Standard_Integer NMTDS_ShapesDataStructure::ShapeIndex(const TopoDS_Shape& aS,
328 const Standard_Integer aRank)const
330 Standard_Boolean bFound;
331 Standard_Integer aIndex=0;
333 bFound=myShapeIndexMap.Contains(aRank);
337 // Modified Thu Sep 14 14:35:18 2006
338 // Contribution of Samtech www.samcef.com BEGIN
340 //const BooleanOperations_IndexedDataMapOfShapeInteger& aSIM=
341 // myShapeIndexMap.FindFromKey(aRank);
343 //bFound=aSIM.Contains(aS);
348 //aIndex=aSIM.FindFromKey(aS);
350 Standard_Integer i, aNbRanks;
352 aNbRanks=myShapeIndexMap.Extent();
353 for (i=1; i<=aNbRanks; ++i){
354 const BooleanOperations_IndexedDataMapOfShapeInteger& aSIM=myShapeIndexMap.FindFromKey(i);
355 bFound=aSIM.Contains(aS);
357 aIndex=aSIM.FindFromKey(aS);
361 // Contribution of Samtech www.samcef.com END