1 // Copyright (C) 2007-2010 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
28 #include <GEOMAlgo_GlueAnalyser.ixx>
31 #include <TopoDS_Shape.hxx>
32 #include <TopoDS_Face.hxx>
33 #include <TopoDS_Edge.hxx>
34 #include <TopoDS_Compound.hxx>
36 #include <BRep_Builder.hxx>
40 #include <TopTools_IndexedMapOfShape.hxx>
41 #include <TopTools_ListOfShape.hxx>
42 #include <TopTools_ListIteratorOfListOfShape.hxx>
43 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
44 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
46 #include <GEOMAlgo_PassKeyShape.hxx>
47 #include <GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape.hxx>
48 #include <GEOMAlgo_Tools.hxx>
49 #include <GEOMAlgo_CoupleOfShapes.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();
151 //=======================================================================
152 //function : DetectVertices
154 //=======================================================================
155 void GEOMAlgo_GlueAnalyser::DetectVertices()
159 Standard_Integer j, i, aNbV, aIndex, aNbVSD;
160 TColStd_ListIteratorOfListOfInteger aIt;
161 Handle(Bnd_HArray1OfBox) aHAB;
162 Bnd_BoundSortBox aBSB;
163 TopoDS_Shape aSTmp, aVF;
165 TopTools_IndexedMapOfShape aMV, aMVProcessed;
166 TopTools_ListIteratorOfListOfShape aItS;
167 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItIm;
168 GEOMAlgo_IndexedDataMapOfIntegerShape aMIS;
169 GEOMAlgo_IndexedDataMapOfShapeBox aMSB;
171 TopExp::MapShapes(myShape, TopAbs_VERTEX, aMV);
174 myErrorStatus=2; // no vertices in source shape
178 aHAB=new Bnd_HArray1OfBox(1, aNbV);
180 for (i=1; i<=aNbV; ++i) {
181 const TopoDS_Shape& aV=aMV(i);
185 BRepBndLib::Add(aV, aBox);
186 aHAB->SetValue(i, aBox);
191 aBSB.Initialize(aHAB);
193 for (i=1; i<=aNbV; ++i) {
194 const TopoDS_Shape& aV=aMV(i);
196 if (aMVProcessed.Contains(aV)) {
200 const Bnd_Box& aBoxV=aMSB.FindFromKey(aV);
201 const TColStd_ListOfInteger& aLI=aBSB.Compare(aBoxV);
204 myErrorStatus=3; // it must not be
209 TopTools_ListOfShape aLVSD;
212 for (j=0; aIt.More(); aIt.Next(), ++j) {
214 const TopoDS_Shape& aVx=aMIS.FindFromKey(aIndex);
219 aMVProcessed.Add(aVx);
221 myImages.Bind(aVF, aLVSD);
224 aItIm.Initialize(myImages);
225 for (; aItIm.More(); aItIm.Next()) {
226 const TopoDS_Shape& aV=aItIm.Key();
227 const TopTools_ListOfShape& aLVSD=aItIm.Value();
229 aItS.Initialize(aLVSD);
230 for (; aItS.More(); aItS.Next()) {
231 const TopoDS_Shape& aVSD=aItS.Value();
232 if (!myOrigins.IsBound(aVSD)) {
233 myOrigins.Bind(aVSD, aV);
238 //=======================================================================
239 //function : DetectFaces
241 //=======================================================================
242 void GEOMAlgo_GlueAnalyser::DetectFaces()
244 DetectShapes(TopAbs_FACE);
246 //=======================================================================
247 //function : DetectEdges
249 //=======================================================================
250 void GEOMAlgo_GlueAnalyser::DetectEdges()
252 DetectShapes(TopAbs_EDGE);
254 //=======================================================================
255 //function : DetectShapes
257 //=======================================================================
258 void GEOMAlgo_GlueAnalyser::DetectShapes(const TopAbs_ShapeEnum aType)
262 Standard_Integer i, aNbF, aNbSDF, iErr;
263 TopoDS_Shape aNewShape;
264 TopTools_IndexedMapOfShape aMF;
265 TopTools_ListIteratorOfListOfShape aItS;
266 GEOMAlgo_PassKeyShape aPKF;
267 GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape aMPKLF;
269 TopExp::MapShapes(myShape, aType, aMF);
272 for (i=1; i<=aNbF; ++i) {
273 const TopoDS_Shape& aS=aMF(i);
276 if (aType==TopAbs_FACE) {
277 const TopoDS_Face& aF=TopoDS::Face(aS);
278 FacePassKey(aF, aPKF);
280 else if (aType==TopAbs_EDGE) {
281 const TopoDS_Edge& aE=TopoDS::Edge(aS);
282 EdgePassKey(aE, aPKF);
289 if (aMPKLF.Contains(aPKF)) {
290 TopTools_ListOfShape& aLSDF=aMPKLF.ChangeFromKey(aPKF);
294 TopTools_ListOfShape aLSDF;
297 aMPKLF.Add(aPKF, aLSDF);
300 // check geometric coincidence
301 if (myCheckGeometry) {
302 iErr=GEOMAlgo_Tools::RefineSDShapes(aMPKLF, myTol, myContext); //XX
310 aNbF=aMPKLF.Extent();
311 for (i=1; i<=aNbF; ++i) {
312 const TopTools_ListOfShape& aLSDF=aMPKLF(i);
313 aNbSDF=aLSDF.Extent();
315 myErrorStatus=4; // it must not be
318 const TopoDS_Shape& aS1=aLSDF.First();
321 myImages.Bind(aNewShape, aLSDF);
323 aItS.Initialize(aLSDF);
324 for (; aItS.More(); aItS.Next()) {
325 const TopoDS_Shape& aFSD=aItS.Value();
326 if (!myOrigins.IsBound(aFSD)) {
327 myOrigins.Bind(aFSD, aNewShape);
332 //=======================================================================
333 //function : DetectSolids
335 //=======================================================================
336 void GEOMAlgo_GlueAnalyser::DetectSolids()
340 Standard_Integer i, aNbF, aNbS, aNbC, aNbX;
341 TopoDS_Compound aCmp;
343 TopTools_IndexedDataMapOfShapeListOfShape aMFS;
344 TopTools_IndexedMapOfShape aMx, aMS;
345 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItIm;
346 GEOMAlgo_CoupleOfShapes aCS;
348 GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape aMPKLS;
349 GEOMAlgo_PassKeyShape aPKSx;
351 aBB.MakeCompound(aCmp);
353 TopExp::MapShapesAndAncestors(myShape, TopAbs_FACE, TopAbs_SOLID, aMFS);
355 aItIm.Initialize(myImages);
356 for (; aItIm.More(); aItIm.Next()) {
357 const TopoDS_Shape& aIm=aItIm.Key();
358 if (aIm.ShapeType()!=TopAbs_FACE) {
362 const TopTools_ListOfShape& aLF=aItIm.Value();
368 TopoDS_Shape aSx[2], aFx[2];
372 for (i=0; i<2; ++i) {
373 if (!aMFS.Contains(aFx[i])) {
374 continue;// it must not be so
377 const TopTools_ListOfShape& aLS=aMFS.FindFromKey(aFx[i]);
385 if (aSx[0].IsNull() || aSx[1].IsNull()) {
389 //aPKSx.Clear();//qft
391 //aPKSx.SetIds(aSx[0], aSx[1]);
392 aPKSx.SetShapes(aSx[0], aSx[1]);
395 if (!aMPKLS.Contains(aPKSx)) {
396 TopTools_ListOfShape aLSx;
401 aMPKLS.Add(aPKSx, aLSx);
405 mySolidsToGlue.Clear();
406 mySolidsAlone.Clear();
409 aNbC=aMPKLS.Extent();
414 for (i=1; i<=aNbC; ++i) {
415 const TopTools_ListOfShape& aLSx=aMPKLS(i);
416 const TopoDS_Shape& aSx1=aLSx.First();
417 const TopoDS_Shape& aSx2=aLSx.Last();
420 mySolidsToGlue.Append(aCS);
422 if (!aMx.Contains(aSx1)) {
426 if (!aMx.Contains(aSx2)) {
433 // check alone solids
434 TopExp::MapShapes(myShape, TopAbs_SOLID, aMS);
437 for (i=1; i<=aNbX; ++i) {
438 const TopoDS_Shape& aSx=aMx(i);
439 if (!aMS.Contains(aSx)) {
440 mySolidsAlone.Append(aSx);
449 aItIm.Initialize(myImages);
450 for (; aItIm.More(); aItIm.Next()) {
451 const TopoDS_Shape& aV=aItIm.Key();
453 const TopTools_ListOfShape& aLVSD=aItIm.Value();
454 MakeVertex(aLVSD, aVnew);//ZZ
455 myImages.Bind(aVnew, aLVSD);
459 for (i=1; i<=aNbV; ++i) {
460 const TopoDS_Shape& aV=aMV(i);