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.hxx>
29 #include <TopoDS_Shape.hxx>
30 #include <TopoDS_Face.hxx>
31 #include <TopoDS_Edge.hxx>
32 #include <TopoDS_Compound.hxx>
34 #include <BRep_Builder.hxx>
38 #include <TopTools_IndexedMapOfShape.hxx>
39 #include <TopTools_ListOfShape.hxx>
40 #include <TopTools_ListIteratorOfListOfShape.hxx>
41 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
42 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
44 #include <GEOMAlgo_PassKeyShape.hxx>
45 #include <GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape.hxx>
46 #include <GEOMAlgo_Tools.hxx>
47 #include <GEOMAlgo_CoupleOfShapes.hxx>
48 #include <GEOMAlgo_ListOfCoupleOfShapes.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();
125 // Initialize the context
126 GEOMAlgo_ShapeAlgo::Perform();
153 //=======================================================================
154 //function : DetectVertices
156 //=======================================================================
157 void GEOMAlgo_GlueAnalyser::DetectVertices()
161 Standard_Integer j, i, aNbV, aIndex, aNbVSD;
162 TColStd_ListIteratorOfListOfInteger aIt;
163 Handle(Bnd_HArray1OfBox) aHAB;
164 Bnd_BoundSortBox aBSB;
165 TopoDS_Shape aSTmp, aVF;
167 TopTools_IndexedMapOfShape aMV, aMVProcessed;
168 TopTools_ListIteratorOfListOfShape aItS;
169 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItIm;
170 GEOMAlgo_IndexedDataMapOfIntegerShape aMIS;
171 GEOMAlgo_IndexedDataMapOfShapeBox aMSB;
173 TopExp::MapShapes(myShape, TopAbs_VERTEX, aMV);
176 myErrorStatus=2; // no vertices in source shape
180 aHAB=new Bnd_HArray1OfBox(1, aNbV);
182 for (i=1; i<=aNbV; ++i) {
183 const TopoDS_Shape& aV=aMV(i);
187 BRepBndLib::Add(aV, aBox);
188 aHAB->SetValue(i, aBox);
193 aBSB.Initialize(aHAB);
195 for (i=1; i<=aNbV; ++i) {
196 const TopoDS_Shape& aV=aMV(i);
198 if (aMVProcessed.Contains(aV)) {
202 const Bnd_Box& aBoxV=aMSB.FindFromKey(aV);
203 const TColStd_ListOfInteger& aLI=aBSB.Compare(aBoxV);
206 myErrorStatus=3; // it must not be
211 TopTools_ListOfShape aLVSD;
214 for (j=0; aIt.More(); aIt.Next(), ++j) {
216 const TopoDS_Shape& aVx=aMIS.FindFromKey(aIndex);
221 aMVProcessed.Add(aVx);
223 myImages.Bind(aVF, aLVSD);
226 aItIm.Initialize(myImages);
227 for (; aItIm.More(); aItIm.Next()) {
228 const TopoDS_Shape& aV=aItIm.Key();
229 const TopTools_ListOfShape& aLVSD=aItIm.Value();
231 aItS.Initialize(aLVSD);
232 for (; aItS.More(); aItS.Next()) {
233 const TopoDS_Shape& aVSD=aItS.Value();
234 if (!myOrigins.IsBound(aVSD)) {
235 myOrigins.Bind(aVSD, aV);
240 //=======================================================================
241 //function : DetectFaces
243 //=======================================================================
244 void GEOMAlgo_GlueAnalyser::DetectFaces()
246 DetectShapes(TopAbs_FACE);
248 //=======================================================================
249 //function : DetectEdges
251 //=======================================================================
252 void GEOMAlgo_GlueAnalyser::DetectEdges()
254 DetectShapes(TopAbs_EDGE);
256 //=======================================================================
257 //function : DetectShapes
259 //=======================================================================
260 void GEOMAlgo_GlueAnalyser::DetectShapes(const TopAbs_ShapeEnum aType)
264 Standard_Integer i, aNbF, aNbSDF, iErr;
265 TopoDS_Shape aNewShape;
266 TopTools_IndexedMapOfShape aMF;
267 TopTools_ListIteratorOfListOfShape aItS;
268 GEOMAlgo_PassKeyShape aPKF;
269 GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape aMPKLF;
271 TopExp::MapShapes(myShape, aType, aMF);
274 for (i=1; i<=aNbF; ++i) {
275 const TopoDS_Shape& aS=aMF(i);
278 if (aType==TopAbs_FACE) {
279 const TopoDS_Face& aF=TopoDS::Face(aS);
280 FacePassKey(aF, aPKF);
282 else if (aType==TopAbs_EDGE) {
283 const TopoDS_Edge& aE=TopoDS::Edge(aS);
284 EdgePassKey(aE, aPKF);
291 if (aMPKLF.Contains(aPKF)) {
292 TopTools_ListOfShape& aLSDF=aMPKLF.ChangeFromKey(aPKF);
296 TopTools_ListOfShape aLSDF;
299 aMPKLF.Add(aPKF, aLSDF);
302 // check geometric coincidence
303 if (myCheckGeometry) {
304 iErr=GEOMAlgo_Tools::RefineSDShapes(aMPKLF, myTol, myContext); //XX
312 aNbF=aMPKLF.Extent();
313 for (i=1; i<=aNbF; ++i) {
314 const TopTools_ListOfShape& aLSDF=aMPKLF(i);
315 aNbSDF=aLSDF.Extent();
317 myErrorStatus=4; // it must not be
320 const TopoDS_Shape& aS1=aLSDF.First();
323 myImages.Bind(aNewShape, aLSDF);
325 aItS.Initialize(aLSDF);
326 for (; aItS.More(); aItS.Next()) {
327 const TopoDS_Shape& aFSD=aItS.Value();
328 if (!myOrigins.IsBound(aFSD)) {
329 myOrigins.Bind(aFSD, aNewShape);
334 //=======================================================================
335 //function : DetectSolids
337 //=======================================================================
338 void GEOMAlgo_GlueAnalyser::DetectSolids()
342 Standard_Integer i, aNbF, aNbS, aNbC, aNbX;
343 TopoDS_Compound aCmp;
345 TopTools_IndexedDataMapOfShapeListOfShape aMFS;
346 TopTools_IndexedMapOfShape aMx, aMS;
347 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItIm;
348 GEOMAlgo_CoupleOfShapes aCS;
350 GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape aMPKLS;
351 GEOMAlgo_PassKeyShape aPKSx;
353 aBB.MakeCompound(aCmp);
355 TopExp::MapShapesAndAncestors(myShape, TopAbs_FACE, TopAbs_SOLID, aMFS);
357 aItIm.Initialize(myImages);
358 for (; aItIm.More(); aItIm.Next()) {
359 const TopoDS_Shape& aIm=aItIm.Key();
360 if (aIm.ShapeType()!=TopAbs_FACE) {
364 const TopTools_ListOfShape& aLF=aItIm.Value();
370 TopoDS_Shape aSx[2], aFx[2];
374 for (i=0; i<2; ++i) {
375 if (!aMFS.Contains(aFx[i])) {
376 continue;// it must not be so
379 const TopTools_ListOfShape& aLS=aMFS.FindFromKey(aFx[i]);
387 if (aSx[0].IsNull() || aSx[1].IsNull()) {
391 //aPKSx.Clear();//qft
393 //aPKSx.SetIds(aSx[0], aSx[1]);
394 aPKSx.SetShapes(aSx[0], aSx[1]);
397 if (!aMPKLS.Contains(aPKSx)) {
398 TopTools_ListOfShape aLSx;
403 aMPKLS.Add(aPKSx, aLSx);
407 mySolidsToGlue.Clear();
408 mySolidsAlone.Clear();
411 aNbC=aMPKLS.Extent();
416 for (i=1; i<=aNbC; ++i) {
417 const TopTools_ListOfShape& aLSx=aMPKLS(i);
418 const TopoDS_Shape& aSx1=aLSx.First();
419 const TopoDS_Shape& aSx2=aLSx.Last();
422 mySolidsToGlue.Append(aCS);
424 if (!aMx.Contains(aSx1)) {
428 if (!aMx.Contains(aSx2)) {
435 // check alone solids
436 TopExp::MapShapes(myShape, TopAbs_SOLID, aMS);
439 for (i=1; i<=aNbX; ++i) {
440 const TopoDS_Shape& aSx=aMx(i);
441 if (!aMS.Contains(aSx)) {
442 mySolidsAlone.Append(aSx);
451 aItIm.Initialize(myImages);
452 for (; aItIm.More(); aItIm.Next()) {
453 const TopoDS_Shape& aV=aItIm.Key();
455 const TopTools_ListOfShape& aLVSD=aItIm.Value();
456 MakeVertex(aLVSD, aVnew);//ZZ
457 myImages.Bind(aVnew, aLVSD);
461 for (i=1; i<=aNbV; ++i) {
462 const TopoDS_Shape& aV=aMV(i);