1 // Copyright (C) 2007-2023 CEA, EDF, 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_Gluer2.cxx
24 // Author: Peter KURNEV
26 #include <GEOMAlgo_Gluer2.hxx>
28 #include <TopAbs_ShapeEnum.hxx>
30 #include <TopoDS_Compound.hxx>
31 #include <TopoDS_Iterator.hxx>
32 #include <TopoDS_Shape.hxx>
33 #include <TopoDS_Vertex.hxx>
35 #include <BRep_Builder.hxx>
37 #include <BRepLib.hxx>
39 #include <TopTools_MapOfShape.hxx>
40 #include <TopTools_MapIteratorOfMapOfShape.hxx>
41 #include <TopTools_DataMapOfShapeShape.hxx>
42 #include <TopTools_ListOfShape.hxx>
43 #include <TopTools_ListIteratorOfListOfShape.hxx>
44 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
45 #include <TopTools_IndexedMapOfShape.hxx>
47 #include <BOPTools_AlgoTools.hxx>
49 #include <GEOMAlgo_GlueDetector.hxx>
50 #include <GEOMAlgo_AlgoTools.hxx>
53 //=======================================================================
54 //function : GEOMAlgo_Gluer2
56 //=======================================================================
57 GEOMAlgo_Gluer2::GEOMAlgo_Gluer2()
59 ,GEOMAlgo_BuilderShape()
64 //=======================================================================
65 //function : ~GEOMAlgo_Gluer2
67 //=======================================================================
68 GEOMAlgo_Gluer2::~GEOMAlgo_Gluer2()
72 //=======================================================================
75 //=======================================================================
76 void GEOMAlgo_Gluer2::Clear()
81 GEOMAlgo_GluerAlgo::Clear();
83 myImagesDetected.Clear();
84 myOriginsDetected.Clear();
85 myShapesToGlue.Clear();
86 myImagesToWork.Clear();
87 myOriginsToWork.Clear();
88 myKeepNonSolids=Standard_False;
92 //=======================================================================
93 //function : StickedShapes
95 //=======================================================================
96 const TopTools_IndexedDataMapOfShapeListOfShape& GEOMAlgo_Gluer2::StickedShapes()
98 return myDetector.StickedShapes();
101 //=======================================================================
102 //function : SetShapesToGlue
104 //=======================================================================
105 void GEOMAlgo_Gluer2::SetShapesToGlue(const TopTools_DataMapOfShapeListOfShape& aM)
110 //=======================================================================
111 //function : ShapesToGlue
113 //=======================================================================
114 const TopTools_DataMapOfShapeListOfShape& GEOMAlgo_Gluer2::ShapesToGlue() const
116 return myShapesToGlue;
119 //=======================================================================
120 //function : SetKeepNonSolids
122 //=======================================================================
123 void GEOMAlgo_Gluer2::SetKeepNonSolids(const Standard_Boolean aFlag)
125 myKeepNonSolids=aFlag;
128 //=======================================================================
129 //function : KeepNonSolids
131 //=======================================================================
132 Standard_Boolean GEOMAlgo_Gluer2::KeepNonSolids()const
134 return myKeepNonSolids;
137 //=======================================================================
138 //function : ShapesDetected
140 //=======================================================================
141 const TopTools_DataMapOfShapeListOfShape& GEOMAlgo_Gluer2::ShapesDetected() const
143 return myImagesDetected;
146 //=======================================================================
147 //function : ImagesToWork
149 //=======================================================================
150 const TopTools_DataMapOfShapeListOfShape& GEOMAlgo_Gluer2::ImagesToWork() const
152 return myImagesToWork;
155 //=======================================================================
158 //=======================================================================
159 void GEOMAlgo_Gluer2::Perform()
169 // Initialize the context
170 GEOMAlgo_GluerAlgo::Perform();
172 PerformShapesToWork();
176 if (myWarningStatus==1) {
232 BRepLib::SameParameter(myShape, myTolerance, Standard_True);
235 //=======================================================================
236 //function : CheckData
238 //=======================================================================
239 void GEOMAlgo_Gluer2::CheckData()
241 Standard_Integer aNbSG, i;
242 TopAbs_ShapeEnum aType, aTypeX;
243 TopTools_ListIteratorOfListOfShape aItLS;
244 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItDMSLS;
249 aNbSG=myShapesToGlue.Extent();
252 // Check myShapesToGlue
253 aItDMSLS.Initialize(myShapesToGlue);
254 for (; aItDMSLS.More(); aItDMSLS.Next()) {
255 const TopTools_ListOfShape& aLSG=aItDMSLS.Value();
256 aItLS.Initialize(aLSG);
257 for (i=0; aItLS.More(); aItLS.Next(), ++i) {
258 const TopoDS_Shape& aSG=aItLS.Value();
259 aTypeX=aSG.ShapeType();
262 if (!(aType==TopAbs_VERTEX ||
263 aType==TopAbs_EDGE ||
264 aType==TopAbs_FACE)) {
265 myErrorStatus=21;// non-brep shapes
271 myErrorStatus=20;// non-homogeneous shapes
279 //=======================================================================
280 //function : FillEdges
282 //=======================================================================
283 void GEOMAlgo_Gluer2::FillEdges()
285 FillBRepShapes(TopAbs_EDGE);
288 //=======================================================================
289 //function : FillFaces
291 //=======================================================================
292 void GEOMAlgo_Gluer2::FillFaces()
294 FillBRepShapes(TopAbs_FACE);
297 //=======================================================================
298 //function : FillWires
300 //=======================================================================
301 void GEOMAlgo_Gluer2::FillWires()
303 FillContainers(TopAbs_WIRE);
306 //=======================================================================
307 //function : FillShells
309 //=======================================================================
310 void GEOMAlgo_Gluer2::FillShells()
312 FillContainers(TopAbs_SHELL);
315 //=======================================================================
316 //function : FillSolids
318 //=======================================================================
319 void GEOMAlgo_Gluer2::FillSolids()
321 FillContainers(TopAbs_SOLID);
324 //=======================================================================
325 //function : FillCompSolids
327 //=======================================================================
328 void GEOMAlgo_Gluer2::FillCompSolids()
330 FillContainers(TopAbs_COMPSOLID);
333 //=======================================================================
334 //function : FillVertices
336 //=======================================================================
337 void GEOMAlgo_Gluer2::FillVertices()
339 TopAbs_ShapeEnum aType;
341 TopTools_ListIteratorOfListOfShape aItLS;
342 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItDMSLS;
347 aItDMSLS.Initialize(myImagesToWork);
348 for (; aItDMSLS.More(); aItDMSLS.Next()) {
349 const TopoDS_Shape& aSkey=aItDMSLS.Key();
350 aType=aSkey.ShapeType();
351 if (aType!=TopAbs_VERTEX) {
355 const TopTools_ListOfShape& aLSD=aItDMSLS.Value();
357 GEOMAlgo_Gluer2::MakeVertex(aLSD, aVnew);
359 myImages.Bind(aVnew, aLSD);
361 aItLS.Initialize(aLSD);
362 for (; aItLS.More(); aItLS.Next()) {
363 const TopoDS_Shape& aV=aItLS.Value();
364 myOrigins.Bind(aV, aVnew);
369 //=======================================================================
370 //function : FillBRepShapes
372 //=======================================================================
373 void GEOMAlgo_Gluer2::FillBRepShapes(const TopAbs_ShapeEnum theType)
375 Standard_Boolean bHasImage, bIsToWork;
376 Standard_Integer i, aNbE;
377 TopoDS_Iterator aItS;
379 TopTools_IndexedMapOfShape aME;
380 TopTools_MapOfShape aMFence;
381 TopTools_ListIteratorOfListOfShape aItLS;
386 TopExp::MapShapes(myArgument, theType, aME);
389 for (i=1; i<=aNbE; ++i) {
390 const TopoDS_Shape& aE=aME(i);
392 if (!aMFence.Add(aE)) {
396 bIsToWork=myOriginsToWork.IsBound(aE);
397 bHasImage=HasImage(aE);
398 if (!bHasImage && !bIsToWork) {
402 MakeBRepShapes(aE, aEnew);
404 //myImages / myOrigins
406 const TopoDS_Shape& aSkey=myOriginsToWork.Find(aE);
407 const TopTools_ListOfShape& aLSD=myImagesToWork.Find(aSkey);
409 myImages.Bind(aEnew, aLSD);
411 aItLS.Initialize(aLSD);
412 for (; aItLS.More(); aItLS.Next()) {
413 const TopoDS_Shape& aEx=aItLS.Value();
414 myOrigins.Bind(aEx, aEnew);
420 TopTools_ListOfShape aLSD;
423 myImages.Bind(aEnew, aLSD);
424 myOrigins.Bind(aE, aEnew);
426 }//for (i=1; i<=aNbF; ++i) {
429 //=======================================================================
430 //function : FillContainers
432 //=======================================================================
433 void GEOMAlgo_Gluer2::FillContainers(const TopAbs_ShapeEnum aType)
435 Standard_Boolean bHasImage, bToReverse;
436 Standard_Integer i, aNbW;
437 TopoDS_Shape aWnew, aEnew;
438 TopoDS_Iterator aItS;
440 TopTools_IndexedMapOfShape aMW;
441 TopTools_MapOfShape aMFence;
446 TopExp::MapShapes(myArgument, aType, aMW);
449 for (i=1; i<=aNbW; ++i) {
450 const TopoDS_Shape& aW=aMW(i);
452 if (!aMFence.Add(aW)) {
456 bHasImage=HasImage(aW);
461 GEOMAlgo_AlgoTools::MakeContainer(aType, aWnew);
462 aWnew.Orientation(aW.Orientation());
465 for (; aItS.More(); aItS.Next()) {
466 const TopoDS_Shape& aE=aItS.Value();
467 if (myOrigins.IsBound(aE)) {
468 aEnew=myOrigins.Find(aE);
470 bToReverse=BOPTools_AlgoTools::IsSplitToReverse(aEnew, aE, myContext);
475 aBB.Add(aWnew, aEnew);
482 //myImages / myOrigins
483 TopTools_ListOfShape aLSD;
486 myImages.Bind(aWnew, aLSD);
487 myOrigins.Bind(aW, aWnew);
489 }//for (i=1; i<=aNbE; ++i) {
492 //=======================================================================
493 //function : FillCompounds
495 //=======================================================================
496 void GEOMAlgo_Gluer2::FillCompounds()
498 TopAbs_ShapeEnum aType;
499 TopoDS_Iterator aItC;
504 aItC.Initialize(myArgument);
505 for (; aItC.More(); aItC.Next()) {
506 const TopoDS_Shape& aCx=aItC.Value();
507 aType=aCx.ShapeType();
508 if (aType==TopAbs_COMPOUND) {
514 //=======================================================================
515 //function : FillCompound
517 //=======================================================================
518 void GEOMAlgo_Gluer2::FillCompound(const TopoDS_Shape& aC)
520 Standard_Boolean bHasImage;
521 TopAbs_ShapeEnum aType;
522 TopoDS_Shape aCnew, aCXnew;
523 TopoDS_Iterator aItC;
526 bHasImage=HasImage(aC);
531 GEOMAlgo_AlgoTools::MakeContainer(TopAbs_COMPOUND, aCnew);
534 for (; aItC.More(); aItC.Next()) {
535 const TopoDS_Shape& aCX=aItC.Value();
536 aType=aCX.ShapeType();
538 if (aType==TopAbs_COMPOUND) {
542 if (myOrigins.IsBound(aCX)) {
543 aCXnew=myOrigins.Find(aCX);
544 aCXnew.Orientation(aCX.Orientation());
545 aBB.Add(aCnew, aCXnew);
552 //myImages / myOrigins
553 TopTools_ListOfShape aLSD;
556 myImages.Bind(aCnew, aLSD);
557 myOrigins.Bind(aC, aCnew);
560 //=======================================================================
561 //function : HasImage
563 //=======================================================================
564 Standard_Boolean GEOMAlgo_Gluer2::HasImage(const TopoDS_Shape& aC)
566 Standard_Boolean bRet;
567 TopAbs_ShapeEnum aType;
568 TopoDS_Iterator aItC;
572 for (; aItC.More(); aItC.Next()) {
573 const TopoDS_Shape& aCx=aItC.Value();
574 aType=aCx.ShapeType();
576 if (aType==TopAbs_COMPOUND) {
583 bRet=myOrigins.IsBound(aCx);
590 bRet=myOrigins.IsBound(aC);
595 //=======================================================================
596 //function : BuildResult
598 //=======================================================================
599 void GEOMAlgo_Gluer2::BuildResult()
601 Standard_Boolean bHasImage;
602 TopoDS_Shape aCnew, aCXnew;
603 TopoDS_Iterator aItC;
609 bHasImage=Standard_False;
610 aItC.Initialize(myArgument);
611 for (; aItC.More(); aItC.Next()) {
612 const TopoDS_Shape& aCx=aItC.Value();
613 bHasImage=HasImage(aCx);
624 GEOMAlgo_AlgoTools::MakeContainer(TopAbs_COMPOUND, aCnew);
626 aItC.Initialize(myArgument);
627 for (; aItC.More(); aItC.Next()) {
628 const TopoDS_Shape& aCX=aItC.Value();
629 if (myOrigins.IsBound(aCX)) {
630 aCXnew=myOrigins.Find(aCX);
631 aCXnew.Orientation(aCX.Orientation());
632 aBB.Add(aCnew, aCXnew);
639 if (!myKeepNonSolids) {
640 Standard_Integer i, aNb;
642 TopTools_IndexedMapOfShape aM;
644 GEOMAlgo_AlgoTools::MakeContainer(TopAbs_COMPOUND, aCnew1);
646 TopExp::MapShapes(aCnew, TopAbs_SOLID, aM);
649 for (i=1; i<=aNb; ++i) {
650 const TopoDS_Shape& aS=aM(i);
658 //--------------------------------------------------------
661 // 11 - GEOMAlgo_GlueDetector failed
662 // 13 - PerformImagesToWork failed
663 // 14 - PerformImagesToWork failed
666 // 1 - no shapes to glue
667 // 2 - sticked shapes are detected.
668 // The value of myTolerance is so large that
669 // subshapes of a shape start to interfere
670 // (e.g. vertices of an edge).
671 // In that case, the result can not be obtained