1 // Copyright (C) 2007-2008 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
27 #include <GEOMAlgo_GlueAnalyser.ixx>
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>
50 #include <GEOMAlgo_Gluer.hxx>
51 #include <Bnd_HArray1OfBox.hxx>
52 #include <Bnd_BoundSortBox.hxx>
53 #include <TopoDS_Vertex.hxx>
54 #include <GEOMAlgo_IndexedDataMapOfIntegerShape.hxx>
55 #include <GEOMAlgo_IndexedDataMapOfShapeBox.hxx>
56 #include <Bnd_Box.hxx>
57 #include <TColStd_ListOfInteger.hxx>
58 #include <TopTools_MapOfShape.hxx>
59 #include <TColStd_ListIteratorOfListOfInteger.hxx>
60 #include <BRepBndLib.hxx>
62 //=======================================================================
65 //=======================================================================
66 GEOMAlgo_GlueAnalyser::GEOMAlgo_GlueAnalyser()
70 //=======================================================================
73 //=======================================================================
74 GEOMAlgo_GlueAnalyser::~GEOMAlgo_GlueAnalyser()
76 //=======================================================================
77 //function : HasSolidsToGlue
79 //=======================================================================
80 Standard_Boolean GEOMAlgo_GlueAnalyser::HasSolidsToGlue()const
82 return !mySolidsToGlue.IsEmpty();
84 //=======================================================================
85 //function : HasSolidsAlone
87 //=======================================================================
88 Standard_Boolean GEOMAlgo_GlueAnalyser::HasSolidsAlone()const
90 return !mySolidsAlone.IsEmpty();
92 //=======================================================================
93 //function : SolidsToGlue
95 //=======================================================================
96 const GEOMAlgo_ListOfCoupleOfShapes& GEOMAlgo_GlueAnalyser::SolidsToGlue()const
98 return mySolidsToGlue;
100 //=======================================================================
101 //function : SolidsAlone
103 //=======================================================================
104 const TopTools_ListOfShape& GEOMAlgo_GlueAnalyser::SolidsAlone()const
106 return mySolidsAlone;
108 //=======================================================================
111 //=======================================================================
112 void GEOMAlgo_GlueAnalyser::Perform()
117 mySolidsToGlue.Clear();
118 mySolidsAlone.Clear();
150 //=======================================================================
151 //function : DetectVertices
153 //=======================================================================
154 void GEOMAlgo_GlueAnalyser::DetectVertices()
158 Standard_Integer j, i, aNbV, aIndex, aNbVSD;
159 TColStd_ListIteratorOfListOfInteger aIt;
160 Handle(Bnd_HArray1OfBox) aHAB;
161 Bnd_BoundSortBox aBSB;
162 TopoDS_Shape aSTmp, aVF;
164 TopTools_IndexedMapOfShape aMV, aMVProcessed;
165 TopTools_ListIteratorOfListOfShape aItS;
166 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItIm;
167 GEOMAlgo_IndexedDataMapOfIntegerShape aMIS;
168 GEOMAlgo_IndexedDataMapOfShapeBox aMSB;
170 TopExp::MapShapes(myShape, TopAbs_VERTEX, aMV);
173 myErrorStatus=2; // no vertices in source shape
177 aHAB=new Bnd_HArray1OfBox(1, aNbV);
179 for (i=1; i<=aNbV; ++i) {
180 const TopoDS_Shape& aV=aMV(i);
184 BRepBndLib::Add(aV, aBox);
185 aHAB->SetValue(i, aBox);
190 aBSB.Initialize(aHAB);
192 for (i=1; i<=aNbV; ++i) {
193 const TopoDS_Shape& aV=aMV(i);
195 if (aMVProcessed.Contains(aV)) {
199 const Bnd_Box& aBoxV=aMSB.FindFromKey(aV);
200 const TColStd_ListOfInteger& aLI=aBSB.Compare(aBoxV);
203 myErrorStatus=3; // it must not be
208 TopTools_ListOfShape aLVSD;
211 for (j=0; aIt.More(); aIt.Next(), ++j) {
213 const TopoDS_Shape& aVx=aMIS.FindFromKey(aIndex);
218 aMVProcessed.Add(aVx);
220 myImages.Bind(aVF, aLVSD);
223 aItIm.Initialize(myImages);
224 for (; aItIm.More(); aItIm.Next()) {
225 const TopoDS_Shape& aV=aItIm.Key();
226 const TopTools_ListOfShape& aLVSD=aItIm.Value();
228 aItS.Initialize(aLVSD);
229 for (; aItS.More(); aItS.Next()) {
230 const TopoDS_Shape& aVSD=aItS.Value();
231 if (!myOrigins.IsBound(aVSD)) {
232 myOrigins.Bind(aVSD, aV);
237 //=======================================================================
238 //function : DetectFaces
240 //=======================================================================
241 void GEOMAlgo_GlueAnalyser::DetectFaces()
243 DetectShapes(TopAbs_FACE);
245 //=======================================================================
246 //function : DetectEdges
248 //=======================================================================
249 void GEOMAlgo_GlueAnalyser::DetectEdges()
251 DetectShapes(TopAbs_EDGE);
253 //=======================================================================
254 //function : DetectShapes
256 //=======================================================================
257 void GEOMAlgo_GlueAnalyser::DetectShapes(const TopAbs_ShapeEnum aType)
261 Standard_Integer i, aNbF, aNbSDF, iErr;
262 TopoDS_Shape aNewShape;
263 TopTools_IndexedMapOfShape aMF;
264 TopTools_ListIteratorOfListOfShape aItS;
265 GEOMAlgo_PassKeyShape aPKF;
266 GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape aMPKLF;
268 TopExp::MapShapes(myShape, aType, aMF);
271 for (i=1; i<=aNbF; ++i) {
272 const TopoDS_Shape& aS=aMF(i);
275 if (aType==TopAbs_FACE) {
276 const TopoDS_Face& aF=TopoDS::Face(aS);
277 FacePassKey(aF, aPKF);
279 else if (aType==TopAbs_EDGE) {
280 const TopoDS_Edge& aE=TopoDS::Edge(aS);
281 EdgePassKey(aE, aPKF);
288 if (aMPKLF.Contains(aPKF)) {
289 TopTools_ListOfShape& aLSDF=aMPKLF.ChangeFromKey(aPKF);
293 TopTools_ListOfShape aLSDF;
296 aMPKLF.Add(aPKF, aLSDF);
299 // check geometric coincidence
300 if (myCheckGeometry) {
301 iErr=GEOMAlgo_Tools::RefineSDShapes(aMPKLF, myTol, myContext); //XX
309 aNbF=aMPKLF.Extent();
310 for (i=1; i<=aNbF; ++i) {
311 const TopTools_ListOfShape& aLSDF=aMPKLF(i);
312 aNbSDF=aLSDF.Extent();
314 myErrorStatus=4; // it must not be
317 const TopoDS_Shape& aS1=aLSDF.First();
320 myImages.Bind(aNewShape, aLSDF);
322 aItS.Initialize(aLSDF);
323 for (; aItS.More(); aItS.Next()) {
324 const TopoDS_Shape& aFSD=aItS.Value();
325 if (!myOrigins.IsBound(aFSD)) {
326 myOrigins.Bind(aFSD, aNewShape);
331 //=======================================================================
332 //function : DetectSolids
334 //=======================================================================
335 void GEOMAlgo_GlueAnalyser::DetectSolids()
339 Standard_Integer i, aNbF, aNbS, aNbC, aNbX;
340 TopoDS_Compound aCmp;
342 TopTools_IndexedDataMapOfShapeListOfShape aMFS;
343 TopTools_IndexedMapOfShape aMx, aMS;
344 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItIm;
345 GEOMAlgo_CoupleOfShapes aCS;
347 GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape aMPKLS;
348 GEOMAlgo_PassKeyShape aPKSx;
350 aBB.MakeCompound(aCmp);
352 TopExp::MapShapesAndAncestors(myShape, TopAbs_FACE, TopAbs_SOLID, aMFS);
354 aItIm.Initialize(myImages);
355 for (; aItIm.More(); aItIm.Next()) {
356 const TopoDS_Shape& aIm=aItIm.Key();
357 if (aIm.ShapeType()!=TopAbs_FACE) {
361 const TopTools_ListOfShape& aLF=aItIm.Value();
367 TopoDS_Shape aSx[2], aFx[2];
371 for (i=0; i<2; ++i) {
372 if (!aMFS.Contains(aFx[i])) {
373 continue;// it must not be so
376 const TopTools_ListOfShape& aLS=aMFS.FindFromKey(aFx[i]);
384 if (aSx[0].IsNull() || aSx[1].IsNull()) {
388 //aPKSx.Clear();//qft
390 //aPKSx.SetIds(aSx[0], aSx[1]);
391 aPKSx.SetShapes(aSx[0], aSx[1]);
394 if (!aMPKLS.Contains(aPKSx)) {
395 TopTools_ListOfShape aLSx;
400 aMPKLS.Add(aPKSx, aLSx);
404 mySolidsToGlue.Clear();
405 mySolidsAlone.Clear();
408 aNbC=aMPKLS.Extent();
413 for (i=1; i<=aNbC; ++i) {
414 const TopTools_ListOfShape& aLSx=aMPKLS(i);
415 const TopoDS_Shape& aSx1=aLSx.First();
416 const TopoDS_Shape& aSx2=aLSx.Last();
419 mySolidsToGlue.Append(aCS);
421 if (!aMx.Contains(aSx1)) {
425 if (!aMx.Contains(aSx2)) {
432 // check alone solids
433 TopExp::MapShapes(myShape, TopAbs_SOLID, aMS);
436 for (i=1; i<=aNbX; ++i) {
437 const TopoDS_Shape& aSx=aMx(i);
438 if (!aMS.Contains(aSx)) {
439 mySolidsAlone.Append(aSx);
448 aItIm.Initialize(myImages);
449 for (; aItIm.More(); aItIm.Next()) {
450 const TopoDS_Shape& aV=aItIm.Key();
452 const TopTools_ListOfShape& aLVSD=aItIm.Value();
453 MakeVertex(aLVSD, aVnew);//ZZ
454 myImages.Bind(aVnew, aLVSD);
458 for (i=1; i<=aNbV; ++i) {
459 const TopoDS_Shape& aV=aMV(i);