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: GEOMAlgo_GlueDetector.cxx
24 // Created: Wed Dec 15 11:08:09 2004
25 // Author: Peter KURNEV
27 #include <GEOMAlgo_GlueAnalyser.hxx>
30 #include <TopoDS_Shape.hxx>
31 #include <TopoDS_Face.hxx>
32 #include <TopoDS_Edge.hxx>
33 #include <TopoDS_Compound.hxx>
35 #include <BRep_Builder.hxx>
39 #include <TopTools_IndexedMapOfShape.hxx>
40 #include <TopTools_ListOfShape.hxx>
41 #include <TopTools_ListIteratorOfListOfShape.hxx>
42 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
43 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
45 #include <GEOMAlgo_PassKeyShape.hxx>
46 #include <GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape.hxx>
47 #include <GEOMAlgo_Tools.hxx>
48 #include <GEOMAlgo_CoupleOfShapes.hxx>
49 #include <GEOMAlgo_ListOfCoupleOfShapes.hxx>
51 #include <GEOMAlgo_Gluer.hxx>
52 #include <Bnd_HArray1OfBox.hxx>
53 #include <Bnd_BoundSortBox.hxx>
54 #include <TopoDS_Vertex.hxx>
55 #include <GEOMAlgo_IndexedDataMapOfIntegerShape.hxx>
56 #include <GEOMAlgo_IndexedDataMapOfShapeBox.hxx>
57 #include <Bnd_Box.hxx>
58 #include <TColStd_ListOfInteger.hxx>
59 #include <TopTools_MapOfShape.hxx>
60 #include <TColStd_ListIteratorOfListOfInteger.hxx>
61 #include <BRepBndLib.hxx>
63 //=======================================================================
66 //=======================================================================
67 GEOMAlgo_GlueAnalyser::GEOMAlgo_GlueAnalyser()
71 //=======================================================================
74 //=======================================================================
75 GEOMAlgo_GlueAnalyser::~GEOMAlgo_GlueAnalyser()
77 //=======================================================================
78 //function : HasSolidsToGlue
80 //=======================================================================
81 Standard_Boolean GEOMAlgo_GlueAnalyser::HasSolidsToGlue()const
83 return !mySolidsToGlue.IsEmpty();
85 //=======================================================================
86 //function : HasSolidsAlone
88 //=======================================================================
89 Standard_Boolean GEOMAlgo_GlueAnalyser::HasSolidsAlone()const
91 return !mySolidsAlone.IsEmpty();
93 //=======================================================================
94 //function : SolidsToGlue
96 //=======================================================================
97 const GEOMAlgo_ListOfCoupleOfShapes& GEOMAlgo_GlueAnalyser::SolidsToGlue()const
99 return mySolidsToGlue;
101 //=======================================================================
102 //function : SolidsAlone
104 //=======================================================================
105 const TopTools_ListOfShape& GEOMAlgo_GlueAnalyser::SolidsAlone()const
107 return mySolidsAlone;
109 //=======================================================================
112 //=======================================================================
113 void GEOMAlgo_GlueAnalyser::Perform()
118 mySolidsToGlue.Clear();
119 mySolidsAlone.Clear();
126 // Initialize the context
127 GEOMAlgo_ShapeAlgo::Perform();
154 //=======================================================================
155 //function : DetectVertices
157 //=======================================================================
158 void GEOMAlgo_GlueAnalyser::DetectVertices()
162 Standard_Integer j, i, aNbV, aIndex, aNbVSD;
163 TColStd_ListIteratorOfListOfInteger aIt;
164 Handle(Bnd_HArray1OfBox) aHAB;
165 Bnd_BoundSortBox aBSB;
166 TopoDS_Shape aSTmp, aVF;
168 TopTools_IndexedMapOfShape aMV, aMVProcessed;
169 TopTools_ListIteratorOfListOfShape aItS;
170 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItIm;
171 GEOMAlgo_IndexedDataMapOfIntegerShape aMIS;
172 GEOMAlgo_IndexedDataMapOfShapeBox aMSB;
174 TopExp::MapShapes(myShape, TopAbs_VERTEX, aMV);
177 myErrorStatus=2; // no vertices in source shape
181 aHAB=new Bnd_HArray1OfBox(1, aNbV);
183 for (i=1; i<=aNbV; ++i) {
184 const TopoDS_Shape& aV=aMV(i);
188 BRepBndLib::Add(aV, aBox);
189 aHAB->SetValue(i, aBox);
194 aBSB.Initialize(aHAB);
196 for (i=1; i<=aNbV; ++i) {
197 const TopoDS_Shape& aV=aMV(i);
199 if (aMVProcessed.Contains(aV)) {
203 const Bnd_Box& aBoxV=aMSB.FindFromKey(aV);
204 const TColStd_ListOfInteger& aLI=aBSB.Compare(aBoxV);
207 myErrorStatus=3; // it must not be
212 TopTools_ListOfShape aLVSD;
215 for (j=0; aIt.More(); aIt.Next(), ++j) {
217 const TopoDS_Shape& aVx=aMIS.FindFromKey(aIndex);
222 aMVProcessed.Add(aVx);
224 myImages.Bind(aVF, aLVSD);
227 aItIm.Initialize(myImages);
228 for (; aItIm.More(); aItIm.Next()) {
229 const TopoDS_Shape& aV=aItIm.Key();
230 const TopTools_ListOfShape& aLVSD=aItIm.Value();
232 aItS.Initialize(aLVSD);
233 for (; aItS.More(); aItS.Next()) {
234 const TopoDS_Shape& aVSD=aItS.Value();
235 if (!myOrigins.IsBound(aVSD)) {
236 myOrigins.Bind(aVSD, aV);
241 //=======================================================================
242 //function : DetectFaces
244 //=======================================================================
245 void GEOMAlgo_GlueAnalyser::DetectFaces()
247 DetectShapes(TopAbs_FACE);
249 //=======================================================================
250 //function : DetectEdges
252 //=======================================================================
253 void GEOMAlgo_GlueAnalyser::DetectEdges()
255 DetectShapes(TopAbs_EDGE);
257 //=======================================================================
258 //function : DetectShapes
260 //=======================================================================
261 void GEOMAlgo_GlueAnalyser::DetectShapes(const TopAbs_ShapeEnum aType)
265 Standard_Integer i, aNbF, aNbSDF, iErr;
266 TopoDS_Shape aNewShape;
267 TopTools_IndexedMapOfShape aMF;
268 TopTools_ListIteratorOfListOfShape aItS;
269 GEOMAlgo_PassKeyShape aPKF;
270 GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape aMPKLF;
272 TopExp::MapShapes(myShape, aType, aMF);
275 for (i=1; i<=aNbF; ++i) {
276 const TopoDS_Shape& aS=aMF(i);
279 if (aType==TopAbs_FACE) {
280 const TopoDS_Face& aF=TopoDS::Face(aS);
281 FacePassKey(aF, aPKF);
283 else if (aType==TopAbs_EDGE) {
284 const TopoDS_Edge& aE=TopoDS::Edge(aS);
285 EdgePassKey(aE, aPKF);
292 if (aMPKLF.Contains(aPKF)) {
293 TopTools_ListOfShape& aLSDF=aMPKLF.ChangeFromKey(aPKF);
297 TopTools_ListOfShape aLSDF;
300 aMPKLF.Add(aPKF, aLSDF);
303 // check geometric coincidence
304 if (myCheckGeometry) {
305 iErr=GEOMAlgo_Tools::RefineSDShapes(aMPKLF, myTol, myContext); //XX
313 aNbF=aMPKLF.Extent();
314 for (i=1; i<=aNbF; ++i) {
315 const TopTools_ListOfShape& aLSDF=aMPKLF(i);
316 aNbSDF=aLSDF.Extent();
318 myErrorStatus=4; // it must not be
321 const TopoDS_Shape& aS1=aLSDF.First();
324 myImages.Bind(aNewShape, aLSDF);
326 aItS.Initialize(aLSDF);
327 for (; aItS.More(); aItS.Next()) {
328 const TopoDS_Shape& aFSD=aItS.Value();
329 if (!myOrigins.IsBound(aFSD)) {
330 myOrigins.Bind(aFSD, aNewShape);
335 //=======================================================================
336 //function : DetectSolids
338 //=======================================================================
339 void GEOMAlgo_GlueAnalyser::DetectSolids()
343 Standard_Integer i, aNbF, aNbS, aNbC, aNbX;
344 TopoDS_Compound aCmp;
346 TopTools_IndexedDataMapOfShapeListOfShape aMFS;
347 TopTools_IndexedMapOfShape aMx, aMS;
348 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItIm;
349 GEOMAlgo_CoupleOfShapes aCS;
351 GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape aMPKLS;
352 GEOMAlgo_PassKeyShape aPKSx;
354 aBB.MakeCompound(aCmp);
356 TopExp::MapShapesAndAncestors(myShape, TopAbs_FACE, TopAbs_SOLID, aMFS);
358 aItIm.Initialize(myImages);
359 for (; aItIm.More(); aItIm.Next()) {
360 const TopoDS_Shape& aIm=aItIm.Key();
361 if (aIm.ShapeType()!=TopAbs_FACE) {
365 const TopTools_ListOfShape& aLF=aItIm.Value();
371 TopoDS_Shape aSx[2], aFx[2];
375 for (i=0; i<2; ++i) {
376 if (!aMFS.Contains(aFx[i])) {
377 continue;// it must not be so
380 const TopTools_ListOfShape& aLS=aMFS.FindFromKey(aFx[i]);
388 if (aSx[0].IsNull() || aSx[1].IsNull()) {
392 //aPKSx.Clear();//qft
394 //aPKSx.SetIds(aSx[0], aSx[1]);
395 aPKSx.SetShapes(aSx[0], aSx[1]);
398 if (!aMPKLS.Contains(aPKSx)) {
399 TopTools_ListOfShape aLSx;
404 aMPKLS.Add(aPKSx, aLSx);
408 mySolidsToGlue.Clear();
409 mySolidsAlone.Clear();
412 aNbC=aMPKLS.Extent();
417 for (i=1; i<=aNbC; ++i) {
418 const TopTools_ListOfShape& aLSx=aMPKLS(i);
419 const TopoDS_Shape& aSx1=aLSx.First();
420 const TopoDS_Shape& aSx2=aLSx.Last();
423 mySolidsToGlue.Append(aCS);
425 if (!aMx.Contains(aSx1)) {
429 if (!aMx.Contains(aSx2)) {
436 // check alone solids
437 TopExp::MapShapes(myShape, TopAbs_SOLID, aMS);
440 for (i=1; i<=aNbX; ++i) {
441 const TopoDS_Shape& aSx=aMx(i);
442 if (!aMS.Contains(aSx)) {
443 mySolidsAlone.Append(aSx);
452 aItIm.Initialize(myImages);
453 for (; aItIm.More(); aItIm.Next()) {
454 const TopoDS_Shape& aV=aItIm.Key();
456 const TopTools_ListOfShape& aLVSD=aItIm.Value();
457 MakeVertex(aLVSD, aVnew);//ZZ
458 myImages.Bind(aVnew, aLVSD);
462 for (i=1; i<=aNbV; ++i) {
463 const TopoDS_Shape& aV=aMV(i);