1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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>
29 #include <Bnd_Box.hxx>
30 #include <Bnd_HArray1OfBox.hxx>
31 #include <Bnd_BoundSortBox.hxx>
32 #include <BRepBndLib.hxx>
34 #include <TColStd_ListIteratorOfListOfInteger.hxx>
35 #include <TColStd_ListOfInteger.hxx>
38 #include <TopoDS_Shape.hxx>
39 #include <TopoDS_Face.hxx>
40 #include <TopoDS_Edge.hxx>
41 #include <TopoDS_Compound.hxx>
42 #include <TopoDS_Vertex.hxx>
44 #include <BRep_Builder.hxx>
48 #include <TopTools_IndexedMapOfShape.hxx>
49 #include <TopTools_ListOfShape.hxx>
50 #include <TopTools_ListIteratorOfListOfShape.hxx>
51 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
52 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
53 #include <TopTools_MapOfShape.hxx>
55 #include <GEOMAlgo_IndexedDataMapOfIntegerShape.hxx>
56 #include <GEOMAlgo_IndexedDataMapOfShapeBox.hxx>
57 #include <GEOMAlgo_PassKeyShape.hxx>
58 #include <GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape.hxx>
59 #include <GEOMAlgo_AlgoTools.hxx>
60 #include <GEOMAlgo_CoupleOfShapes.hxx>
61 #include <GEOMAlgo_ListOfCoupleOfShapes.hxx>
62 #include <GEOMAlgo_Gluer.hxx>
64 //=======================================================================
67 //=======================================================================
68 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 // Initialize the context
128 GEOMAlgo_ShapeAlgo::Perform();
155 //=======================================================================
156 //function : DetectVertices
158 //=======================================================================
159 void GEOMAlgo_GlueAnalyser::DetectVertices()
163 Standard_Integer j, i, aNbV, aIndex, aNbVSD;
164 TColStd_ListIteratorOfListOfInteger aIt;
165 Handle(Bnd_HArray1OfBox) aHAB;
166 Bnd_BoundSortBox aBSB;
167 TopoDS_Shape aSTmp, aVF;
169 TopTools_IndexedMapOfShape aMV, aMVProcessed;
170 TopTools_ListIteratorOfListOfShape aItS;
171 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItIm;
172 GEOMAlgo_IndexedDataMapOfIntegerShape aMIS;
173 GEOMAlgo_IndexedDataMapOfShapeBox aMSB;
175 TopExp::MapShapes(myShape, TopAbs_VERTEX, aMV);
178 myErrorStatus=2; // no vertices in source shape
182 aHAB=new Bnd_HArray1OfBox(1, aNbV);
184 for (i=1; i<=aNbV; ++i) {
185 const TopoDS_Shape& aV=aMV(i);
189 BRepBndLib::Add(aV, aBox);
190 aHAB->SetValue(i, aBox);
195 aBSB.Initialize(aHAB);
197 for (i=1; i<=aNbV; ++i) {
198 const TopoDS_Shape& aV=aMV(i);
200 if (aMVProcessed.Contains(aV)) {
204 const Bnd_Box& aBoxV=aMSB.FindFromKey(aV);
205 const TColStd_ListOfInteger& aLI=aBSB.Compare(aBoxV);
208 myErrorStatus=3; // it must not be
213 TopTools_ListOfShape aLVSD;
216 for (j=0; aIt.More(); aIt.Next(), ++j) {
218 const TopoDS_Shape& aVx=aMIS.FindFromKey(aIndex);
223 aMVProcessed.Add(aVx);
225 myImages.Bind(aVF, aLVSD);
228 aItIm.Initialize(myImages);
229 for (; aItIm.More(); aItIm.Next()) {
230 const TopoDS_Shape& aV=aItIm.Key();
231 const TopTools_ListOfShape& aLVSD=aItIm.Value();
233 aItS.Initialize(aLVSD);
234 for (; aItS.More(); aItS.Next()) {
235 const TopoDS_Shape& aVSD=aItS.Value();
236 if (!myOrigins.IsBound(aVSD)) {
237 myOrigins.Bind(aVSD, aV);
242 //=======================================================================
243 //function : DetectFaces
245 //=======================================================================
246 void GEOMAlgo_GlueAnalyser::DetectFaces()
248 DetectShapes(TopAbs_FACE);
250 //=======================================================================
251 //function : DetectEdges
253 //=======================================================================
254 void GEOMAlgo_GlueAnalyser::DetectEdges()
256 DetectShapes(TopAbs_EDGE);
258 //=======================================================================
259 //function : DetectShapes
261 //=======================================================================
262 void GEOMAlgo_GlueAnalyser::DetectShapes(const TopAbs_ShapeEnum aType)
266 Standard_Integer i, aNbF, aNbSDF, iErr;
267 TopoDS_Shape aNewShape;
268 TopTools_IndexedMapOfShape aMF;
269 TopTools_ListIteratorOfListOfShape aItS;
270 GEOMAlgo_PassKeyShape aPKF;
271 GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape aMPKLF;
273 TopExp::MapShapes(myShape, aType, aMF);
276 for (i=1; i<=aNbF; ++i) {
277 const TopoDS_Shape& aS=aMF(i);
280 if (aType==TopAbs_FACE) {
281 const TopoDS_Face& aF=TopoDS::Face(aS);
282 FacePassKey(aF, aPKF);
284 else if (aType==TopAbs_EDGE) {
285 const TopoDS_Edge& aE=TopoDS::Edge(aS);
286 EdgePassKey(aE, aPKF);
293 if (aMPKLF.Contains(aPKF)) {
294 TopTools_ListOfShape& aLSDF=aMPKLF.ChangeFromKey(aPKF);
298 TopTools_ListOfShape aLSDF;
301 aMPKLF.Add(aPKF, aLSDF);
304 // check geometric coincidence
305 if (myCheckGeometry) {
306 iErr=GEOMAlgo_AlgoTools::RefineSDShapes(aMPKLF, myTol, myContext); //XX
314 aNbF=aMPKLF.Extent();
315 for (i=1; i<=aNbF; ++i) {
316 const TopTools_ListOfShape& aLSDF=aMPKLF(i);
317 aNbSDF=aLSDF.Extent();
319 myErrorStatus=4; // it must not be
322 const TopoDS_Shape& aS1=aLSDF.First();
325 myImages.Bind(aNewShape, aLSDF);
327 aItS.Initialize(aLSDF);
328 for (; aItS.More(); aItS.Next()) {
329 const TopoDS_Shape& aFSD=aItS.Value();
330 if (!myOrigins.IsBound(aFSD)) {
331 myOrigins.Bind(aFSD, aNewShape);
336 //=======================================================================
337 //function : DetectSolids
339 //=======================================================================
340 void GEOMAlgo_GlueAnalyser::DetectSolids()
344 Standard_Integer i, aNbF, aNbS, aNbC, aNbX;
345 TopoDS_Compound aCmp;
347 TopTools_IndexedDataMapOfShapeListOfShape aMFS;
348 TopTools_IndexedMapOfShape aMx, aMS;
349 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItIm;
350 GEOMAlgo_CoupleOfShapes aCS;
352 GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape aMPKLS;
353 GEOMAlgo_PassKeyShape aPKSx;
355 aBB.MakeCompound(aCmp);
357 TopExp::MapShapesAndAncestors(myShape, TopAbs_FACE, TopAbs_SOLID, aMFS);
359 aItIm.Initialize(myImages);
360 for (; aItIm.More(); aItIm.Next()) {
361 const TopoDS_Shape& aIm=aItIm.Key();
362 if (aIm.ShapeType()!=TopAbs_FACE) {
366 const TopTools_ListOfShape& aLF=aItIm.Value();
372 TopoDS_Shape aSx[2], aFx[2];
376 for (i=0; i<2; ++i) {
377 if (!aMFS.Contains(aFx[i])) {
378 continue;// it must not be so
381 const TopTools_ListOfShape& aLS=aMFS.FindFromKey(aFx[i]);
389 if (aSx[0].IsNull() || aSx[1].IsNull()) {
393 //aPKSx.Clear();//qft
395 //aPKSx.SetIds(aSx[0], aSx[1]);
396 aPKSx.SetShapes(aSx[0], aSx[1]);
399 if (!aMPKLS.Contains(aPKSx)) {
400 TopTools_ListOfShape aLSx;
405 aMPKLS.Add(aPKSx, aLSx);
409 mySolidsToGlue.Clear();
410 mySolidsAlone.Clear();
413 aNbC=aMPKLS.Extent();
418 for (i=1; i<=aNbC; ++i) {
419 const TopTools_ListOfShape& aLSx=aMPKLS(i);
420 const TopoDS_Shape& aSx1=aLSx.First();
421 const TopoDS_Shape& aSx2=aLSx.Last();
424 mySolidsToGlue.Append(aCS);
426 if (!aMx.Contains(aSx1)) {
430 if (!aMx.Contains(aSx2)) {
437 // check alone solids
438 TopExp::MapShapes(myShape, TopAbs_SOLID, aMS);
441 for (i=1; i<=aNbX; ++i) {
442 const TopoDS_Shape& aSx=aMx(i);
443 if (!aMS.Contains(aSx)) {
444 mySolidsAlone.Append(aSx);
453 aItIm.Initialize(myImages);
454 for (; aItIm.More(); aItIm.Next()) {
455 const TopoDS_Shape& aV=aItIm.Key();
457 const TopTools_ListOfShape& aLVSD=aItIm.Value();
458 MakeVertex(aLVSD, aVnew);//ZZ
459 myImages.Bind(aVnew, aLVSD);
463 for (i=1; i<=aNbV; ++i) {
464 const TopoDS_Shape& aV=aMV(i);