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: GEOMAlgo_GlueDetector.cxx
23 // Created: Wed Dec 15 11:08:09 2004
24 // Author: Peter KURNEV
26 #include <GEOMAlgo_GlueAnalyser.ixx>
28 #include <GEOMAlgo_PassKeyShape.hxx>
29 #include <GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape.hxx>
30 #include <GEOMAlgo_Tools.hxx>
31 #include <GEOMAlgo_CoupleOfShapes.hxx>
32 #include <GEOMAlgo_Gluer.hxx>
33 #include <GEOMAlgo_IndexedDataMapOfIntegerShape.hxx>
34 #include <GEOMAlgo_IndexedDataMapOfShapeBox.hxx>
36 #include <Basics_OCCTVersion.hxx>
39 #include <TopoDS_Shape.hxx>
40 #include <TopoDS_Face.hxx>
41 #include <TopoDS_Edge.hxx>
42 #include <TopoDS_Compound.hxx>
43 #include <TopoDS_Vertex.hxx>
45 #include <BRep_Builder.hxx>
49 #include <TopTools_MapOfShape.hxx>
50 #include <TopTools_IndexedMapOfShape.hxx>
51 #include <TopTools_ListOfShape.hxx>
52 #include <TopTools_ListIteratorOfListOfShape.hxx>
53 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
54 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
56 #include <Bnd_HArray1OfBox.hxx>
57 #include <Bnd_BoundSortBox.hxx>
58 #include <Bnd_Box.hxx>
60 #include <BRepBndLib.hxx>
62 #include <TColStd_ListOfInteger.hxx>
63 #include <TColStd_ListIteratorOfListOfInteger.hxx>
65 //=======================================================================
68 //=======================================================================
69 GEOMAlgo_GlueAnalyser::GEOMAlgo_GlueAnalyser()
72 //=======================================================================
75 //=======================================================================
76 GEOMAlgo_GlueAnalyser::~GEOMAlgo_GlueAnalyser()
78 //=======================================================================
79 //function : HasSolidsToGlue
81 //=======================================================================
82 Standard_Boolean GEOMAlgo_GlueAnalyser::HasSolidsToGlue()const
84 return !mySolidsToGlue.IsEmpty();
86 //=======================================================================
87 //function : HasSolidsAlone
89 //=======================================================================
90 Standard_Boolean GEOMAlgo_GlueAnalyser::HasSolidsAlone()const
92 return !mySolidsAlone.IsEmpty();
94 //=======================================================================
95 //function : SolidsToGlue
97 //=======================================================================
98 const GEOMAlgo_ListOfCoupleOfShapes& GEOMAlgo_GlueAnalyser::SolidsToGlue()const
100 return mySolidsToGlue;
102 //=======================================================================
103 //function : SolidsAlone
105 //=======================================================================
106 const TopTools_ListOfShape& GEOMAlgo_GlueAnalyser::SolidsAlone()const
108 return mySolidsAlone;
110 //=======================================================================
113 //=======================================================================
114 void GEOMAlgo_GlueAnalyser::Perform()
119 mySolidsToGlue.Clear();
120 mySolidsAlone.Clear();
127 #if OCC_VERSION_LARGE > 0x06050200
128 // Initialize the context
129 GEOMAlgo_ShapeAlgo::Perform();
157 //=======================================================================
158 //function : DetectVertices
160 //=======================================================================
161 void GEOMAlgo_GlueAnalyser::DetectVertices()
165 Standard_Integer j, i, aNbV, aIndex, aNbVSD;
166 TColStd_ListIteratorOfListOfInteger aIt;
167 Handle(Bnd_HArray1OfBox) aHAB;
168 Bnd_BoundSortBox aBSB;
169 TopoDS_Shape aSTmp, aVF;
171 TopTools_IndexedMapOfShape aMV, aMVProcessed;
172 TopTools_ListIteratorOfListOfShape aItS;
173 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItIm;
174 GEOMAlgo_IndexedDataMapOfIntegerShape aMIS;
175 GEOMAlgo_IndexedDataMapOfShapeBox aMSB;
177 TopExp::MapShapes(myShape, TopAbs_VERTEX, aMV);
180 myErrorStatus=2; // no vertices in source shape
184 aHAB=new Bnd_HArray1OfBox(1, aNbV);
186 for (i=1; i<=aNbV; ++i) {
187 const TopoDS_Shape& aV=aMV(i);
191 BRepBndLib::Add(aV, aBox);
192 aHAB->SetValue(i, aBox);
197 aBSB.Initialize(aHAB);
199 for (i=1; i<=aNbV; ++i) {
200 const TopoDS_Shape& aV=aMV(i);
202 if (aMVProcessed.Contains(aV)) {
206 const Bnd_Box& aBoxV=aMSB.FindFromKey(aV);
207 const TColStd_ListOfInteger& aLI=aBSB.Compare(aBoxV);
210 myErrorStatus=3; // it must not be
215 TopTools_ListOfShape aLVSD;
218 for (j=0; aIt.More(); aIt.Next(), ++j) {
220 const TopoDS_Shape& aVx=aMIS.FindFromKey(aIndex);
225 aMVProcessed.Add(aVx);
227 myImages.Bind(aVF, aLVSD);
230 aItIm.Initialize(myImages);
231 for (; aItIm.More(); aItIm.Next()) {
232 const TopoDS_Shape& aV=aItIm.Key();
233 const TopTools_ListOfShape& aLVSD=aItIm.Value();
235 aItS.Initialize(aLVSD);
236 for (; aItS.More(); aItS.Next()) {
237 const TopoDS_Shape& aVSD=aItS.Value();
238 if (!myOrigins.IsBound(aVSD)) {
239 myOrigins.Bind(aVSD, aV);
244 //=======================================================================
245 //function : DetectFaces
247 //=======================================================================
248 void GEOMAlgo_GlueAnalyser::DetectFaces()
250 DetectShapes(TopAbs_FACE);
252 //=======================================================================
253 //function : DetectEdges
255 //=======================================================================
256 void GEOMAlgo_GlueAnalyser::DetectEdges()
258 DetectShapes(TopAbs_EDGE);
260 //=======================================================================
261 //function : DetectShapes
263 //=======================================================================
264 void GEOMAlgo_GlueAnalyser::DetectShapes(const TopAbs_ShapeEnum aType)
268 Standard_Integer i, aNbF, aNbSDF, iErr;
269 TopoDS_Shape aNewShape;
270 TopTools_IndexedMapOfShape aMF;
271 TopTools_ListIteratorOfListOfShape aItS;
272 GEOMAlgo_PassKeyShape aPKF;
273 GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape aMPKLF;
275 TopExp::MapShapes(myShape, aType, aMF);
278 for (i=1; i<=aNbF; ++i) {
279 const TopoDS_Shape& aS=aMF(i);
282 if (aType==TopAbs_FACE) {
283 const TopoDS_Face& aF=TopoDS::Face(aS);
284 FacePassKey(aF, aPKF);
286 else if (aType==TopAbs_EDGE) {
287 const TopoDS_Edge& aE=TopoDS::Edge(aS);
288 EdgePassKey(aE, aPKF);
295 if (aMPKLF.Contains(aPKF)) {
296 TopTools_ListOfShape& aLSDF=aMPKLF.ChangeFromKey(aPKF);
300 TopTools_ListOfShape aLSDF;
303 aMPKLF.Add(aPKF, aLSDF);
306 // check geometric coincidence
307 if (myCheckGeometry) {
308 iErr=GEOMAlgo_Tools::RefineSDShapes(aMPKLF, myTol, myContext); //XX
316 aNbF=aMPKLF.Extent();
317 for (i=1; i<=aNbF; ++i) {
318 const TopTools_ListOfShape& aLSDF=aMPKLF(i);
319 aNbSDF=aLSDF.Extent();
321 myErrorStatus=4; // it must not be
324 const TopoDS_Shape& aS1=aLSDF.First();
327 myImages.Bind(aNewShape, aLSDF);
329 aItS.Initialize(aLSDF);
330 for (; aItS.More(); aItS.Next()) {
331 const TopoDS_Shape& aFSD=aItS.Value();
332 if (!myOrigins.IsBound(aFSD)) {
333 myOrigins.Bind(aFSD, aNewShape);
338 //=======================================================================
339 //function : DetectSolids
341 //=======================================================================
342 void GEOMAlgo_GlueAnalyser::DetectSolids()
346 Standard_Integer i, aNbF, aNbS, aNbC, aNbX;
347 TopoDS_Compound aCmp;
349 TopTools_IndexedDataMapOfShapeListOfShape aMFS;
350 TopTools_IndexedMapOfShape aMx, aMS;
351 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItIm;
352 GEOMAlgo_CoupleOfShapes aCS;
354 GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape aMPKLS;
355 GEOMAlgo_PassKeyShape aPKSx;
357 aBB.MakeCompound(aCmp);
359 TopExp::MapShapesAndAncestors(myShape, TopAbs_FACE, TopAbs_SOLID, aMFS);
361 aItIm.Initialize(myImages);
362 for (; aItIm.More(); aItIm.Next()) {
363 const TopoDS_Shape& aIm=aItIm.Key();
364 if (aIm.ShapeType()!=TopAbs_FACE) {
368 const TopTools_ListOfShape& aLF=aItIm.Value();
374 TopoDS_Shape aSx[2], aFx[2];
378 for (i=0; i<2; ++i) {
379 if (!aMFS.Contains(aFx[i])) {
380 continue;// it must not be so
383 const TopTools_ListOfShape& aLS=aMFS.FindFromKey(aFx[i]);
391 if (aSx[0].IsNull() || aSx[1].IsNull()) {
395 //aPKSx.Clear();//qft
397 //aPKSx.SetIds(aSx[0], aSx[1]);
398 aPKSx.SetShapes(aSx[0], aSx[1]);
401 if (!aMPKLS.Contains(aPKSx)) {
402 TopTools_ListOfShape aLSx;
407 aMPKLS.Add(aPKSx, aLSx);
411 mySolidsToGlue.Clear();
412 mySolidsAlone.Clear();
415 aNbC=aMPKLS.Extent();
420 for (i=1; i<=aNbC; ++i) {
421 const TopTools_ListOfShape& aLSx=aMPKLS(i);
422 const TopoDS_Shape& aSx1=aLSx.First();
423 const TopoDS_Shape& aSx2=aLSx.Last();
426 mySolidsToGlue.Append(aCS);
428 if (!aMx.Contains(aSx1)) {
432 if (!aMx.Contains(aSx2)) {
439 // check alone solids
440 TopExp::MapShapes(myShape, TopAbs_SOLID, aMS);
443 for (i=1; i<=aNbX; ++i) {
444 const TopoDS_Shape& aSx=aMx(i);
445 if (!aMS.Contains(aSx)) {
446 mySolidsAlone.Append(aSx);
455 aItIm.Initialize(myImages);
456 for (; aItIm.More(); aItIm.Next()) {
457 const TopoDS_Shape& aV=aItIm.Key();
459 const TopTools_ListOfShape& aLVSD=aItIm.Value();
460 MakeVertex(aLVSD, aVnew);//ZZ
461 myImages.Bind(aVnew, aLVSD);
465 for (i=1; i<=aNbV; ++i) {
466 const TopoDS_Shape& aV=aMV(i);