1 // Copyright (C) 2007-2021 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_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>
52 //=======================================================================
53 //function : GEOMAlgo_Gluer2
55 //=======================================================================
56 GEOMAlgo_Gluer2::GEOMAlgo_Gluer2()
59 GEOMAlgo_BuilderShape()
63 //=======================================================================
64 //function : ~GEOMAlgo_Gluer2
66 //=======================================================================
67 GEOMAlgo_Gluer2::~GEOMAlgo_Gluer2()
70 //=======================================================================
73 //=======================================================================
74 void GEOMAlgo_Gluer2::Clear()
79 GEOMAlgo_GluerAlgo::Clear();
81 myImagesDetected.Clear();
82 myOriginsDetected.Clear();
83 myShapesToGlue.Clear();
84 myImagesToWork.Clear();
85 myOriginsToWork.Clear();
86 myKeepNonSolids=Standard_False;
89 //=======================================================================
90 //function : StickedShapes
92 //=======================================================================
93 const TopTools_IndexedDataMapOfShapeListOfShape&
94 GEOMAlgo_Gluer2::StickedShapes()
96 return myDetector.StickedShapes();
98 //=======================================================================
99 //function : SetShapesToGlue
101 //=======================================================================
102 void GEOMAlgo_Gluer2::SetShapesToGlue
103 (const TopTools_DataMapOfShapeListOfShape& aM)
107 //=======================================================================
108 //function : ShapesToGlue
110 //=======================================================================
111 const TopTools_DataMapOfShapeListOfShape& GEOMAlgo_Gluer2::ShapesToGlue()const
113 return myShapesToGlue;
115 //=======================================================================
116 //function : SetKeepNonSolids
118 //=======================================================================
119 void GEOMAlgo_Gluer2::SetKeepNonSolids(const Standard_Boolean aFlag)
121 myKeepNonSolids=aFlag;
123 //=======================================================================
124 //function : KeepNonSolids
126 //=======================================================================
127 Standard_Boolean GEOMAlgo_Gluer2::KeepNonSolids()const
129 return myKeepNonSolids;
131 //=======================================================================
132 //function : ShapesDetected
134 //=======================================================================
135 const TopTools_DataMapOfShapeListOfShape& GEOMAlgo_Gluer2::ShapesDetected()const
137 return myImagesDetected;
139 //=======================================================================
140 //function : ImagesToWork
142 //=======================================================================
143 const TopTools_DataMapOfShapeListOfShape& GEOMAlgo_Gluer2::ImagesToWork()const
145 return myImagesToWork;
147 //=======================================================================
150 //=======================================================================
151 void GEOMAlgo_Gluer2::Perform()
161 // Initialize the context
162 GEOMAlgo_GluerAlgo::Perform();
164 PerformShapesToWork();
168 if (myWarningStatus==1) {
224 BRepLib::SameParameter(myShape, myTolerance, Standard_True);
226 //=======================================================================
227 //function : CheckData
229 //=======================================================================
230 void GEOMAlgo_Gluer2::CheckData()
232 Standard_Integer aNbSG, i;
233 TopAbs_ShapeEnum aType, aTypeX;
234 TopTools_ListIteratorOfListOfShape aItLS;
235 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItDMSLS;
240 aNbSG=myShapesToGlue.Extent();
243 // Check myShapesToGlue
244 aItDMSLS.Initialize(myShapesToGlue);
245 for (; aItDMSLS.More(); aItDMSLS.Next()) {
246 //const TopoDS_Shape& aSkey=aItDMSLS.Key();
247 const TopTools_ListOfShape& aLSG=aItDMSLS.Value();
248 aItLS.Initialize(aLSG);
249 for (i=0; aItLS.More(); aItLS.Next(), ++i) {
250 const TopoDS_Shape& aSG=aItLS.Value();
251 aTypeX=aSG.ShapeType();
254 if (!(aType==TopAbs_VERTEX ||
255 aType==TopAbs_EDGE ||
256 aType==TopAbs_FACE)) {
257 myErrorStatus=21;// non-brep shapes
263 myErrorStatus=20;// non-homogeneous shapes
270 //=======================================================================
271 //function : FillEdges
273 //=======================================================================
274 void GEOMAlgo_Gluer2::FillEdges()
276 FillBRepShapes(TopAbs_EDGE);
278 //=======================================================================
279 //function : FillFaces
281 //=======================================================================
282 void GEOMAlgo_Gluer2::FillFaces()
284 FillBRepShapes(TopAbs_FACE);
286 //=======================================================================
287 //function : FillWires
289 //=======================================================================
290 void GEOMAlgo_Gluer2::FillWires()
292 FillContainers(TopAbs_WIRE);
294 //=======================================================================
295 //function : FillShells
297 //=======================================================================
298 void GEOMAlgo_Gluer2::FillShells()
300 FillContainers(TopAbs_SHELL);
302 //=======================================================================
303 //function : FillSolids
305 //=======================================================================
306 void GEOMAlgo_Gluer2::FillSolids()
308 FillContainers(TopAbs_SOLID);
310 //=======================================================================
311 //function : FillCompSolids
313 //=======================================================================
314 void GEOMAlgo_Gluer2::FillCompSolids()
316 FillContainers(TopAbs_COMPSOLID);
318 //=======================================================================
319 //function : FillVertices
321 //=======================================================================
322 void GEOMAlgo_Gluer2::FillVertices()
324 TopAbs_ShapeEnum aType;
326 TopTools_ListIteratorOfListOfShape aItLS;
327 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItDMSLS;
332 aItDMSLS.Initialize(myImagesToWork);
333 for (; aItDMSLS.More(); aItDMSLS.Next()) {
334 const TopoDS_Shape& aSkey=aItDMSLS.Key();
335 aType=aSkey.ShapeType();
336 if (aType!=TopAbs_VERTEX) {
340 const TopTools_ListOfShape& aLSD=aItDMSLS.Value();
342 GEOMAlgo_Gluer2::MakeVertex(aLSD, aVnew);
344 myImages.Bind(aVnew, aLSD);
346 aItLS.Initialize(aLSD);
347 for (; aItLS.More(); aItLS.Next()) {
348 const TopoDS_Shape& aV=aItLS.Value();
349 myOrigins.Bind(aV, aVnew);
353 //=======================================================================
354 //function : FillBRepShapes
356 //=======================================================================
357 void GEOMAlgo_Gluer2::FillBRepShapes(const TopAbs_ShapeEnum theType)
359 Standard_Boolean bHasImage, bIsToWork;
360 Standard_Integer i, aNbE;
361 TopoDS_Iterator aItS;
363 TopTools_IndexedMapOfShape aME;
364 TopTools_MapOfShape aMFence;
365 TopTools_ListIteratorOfListOfShape aItLS;
370 TopExp::MapShapes(myArgument, theType, aME);
373 for (i=1; i<=aNbE; ++i) {
374 const TopoDS_Shape& aE=aME(i);
376 if (!aMFence.Add(aE)) {
380 bIsToWork=myOriginsToWork.IsBound(aE);
381 bHasImage=HasImage(aE);
382 if (!bHasImage && !bIsToWork) {
386 MakeBRepShapes(aE, aEnew);
388 //myImages / myOrigins
390 const TopoDS_Shape& aSkey=myOriginsToWork.Find(aE);
391 const TopTools_ListOfShape& aLSD=myImagesToWork.Find(aSkey);
393 myImages.Bind(aEnew, aLSD);
395 aItLS.Initialize(aLSD);
396 for (; aItLS.More(); aItLS.Next()) {
397 const TopoDS_Shape& aEx=aItLS.Value();
398 myOrigins.Bind(aEx, aEnew);
404 TopTools_ListOfShape aLSD;
407 myImages.Bind(aEnew, aLSD);
408 myOrigins.Bind(aE, aEnew);
410 }//for (i=1; i<=aNbF; ++i) {
412 //=======================================================================
413 //function : FillContainers
415 //=======================================================================
416 void GEOMAlgo_Gluer2::FillContainers(const TopAbs_ShapeEnum aType)
418 Standard_Boolean bHasImage, bToReverse;
419 Standard_Integer i, aNbW;
420 TopoDS_Shape aWnew, aEnew;
421 TopoDS_Iterator aItS;
423 TopTools_IndexedMapOfShape aMW;
424 TopTools_MapOfShape aMFence;
429 TopExp::MapShapes(myArgument, aType, aMW);
432 for (i=1; i<=aNbW; ++i) {
433 const TopoDS_Shape& aW=aMW(i);
435 if (!aMFence.Add(aW)) {
439 bHasImage=HasImage(aW);
444 GEOMAlgo_AlgoTools::MakeContainer(aType, aWnew);
445 aWnew.Orientation(aW.Orientation());
448 for (; aItS.More(); aItS.Next()) {
449 const TopoDS_Shape& aE=aItS.Value();
450 if (myOrigins.IsBound(aE)) {
451 aEnew=myOrigins.Find(aE);
453 bToReverse=BOPTools_AlgoTools::IsSplitToReverse(aEnew, aE, myContext);
458 aBB.Add(aWnew, aEnew);
465 //myImages / myOrigins
466 TopTools_ListOfShape aLSD;
469 myImages.Bind(aWnew, aLSD);
470 myOrigins.Bind(aW, aWnew);
472 }//for (i=1; i<=aNbE; ++i) {
474 //=======================================================================
475 //function : FillCompounds
477 //=======================================================================
478 void GEOMAlgo_Gluer2::FillCompounds()
480 TopAbs_ShapeEnum aType;
481 TopoDS_Iterator aItC;
486 aItC.Initialize(myArgument);
487 for (; aItC.More(); aItC.Next()) {
488 const TopoDS_Shape& aCx=aItC.Value();
489 aType=aCx.ShapeType();
490 if (aType==TopAbs_COMPOUND) {
495 //=======================================================================
496 //function : FillCompound
498 //=======================================================================
499 void GEOMAlgo_Gluer2::FillCompound(const TopoDS_Shape& aC)
501 Standard_Boolean bHasImage;
502 TopAbs_ShapeEnum aType;
503 TopoDS_Shape aCnew, aCXnew;
504 TopoDS_Iterator aItC;
507 bHasImage=HasImage(aC);
512 GEOMAlgo_AlgoTools::MakeContainer(TopAbs_COMPOUND, aCnew);
515 for (; aItC.More(); aItC.Next()) {
516 const TopoDS_Shape& aCX=aItC.Value();
517 aType=aCX.ShapeType();
519 if (aType==TopAbs_COMPOUND) {
523 if (myOrigins.IsBound(aCX)) {
524 aCXnew=myOrigins.Find(aCX);
525 aCXnew.Orientation(aCX.Orientation());
526 aBB.Add(aCnew, aCXnew);
533 //myImages / myOrigins
534 TopTools_ListOfShape aLSD;
537 myImages.Bind(aCnew, aLSD);
538 myOrigins.Bind(aC, aCnew);
540 //=======================================================================
541 //function : HasImage
543 //=======================================================================
544 Standard_Boolean GEOMAlgo_Gluer2::HasImage(const TopoDS_Shape& aC)
546 Standard_Boolean bRet;
547 TopAbs_ShapeEnum aType;
548 TopoDS_Iterator aItC;
552 for (; aItC.More(); aItC.Next()) {
553 const TopoDS_Shape& aCx=aItC.Value();
554 aType=aCx.ShapeType();
556 if (aType==TopAbs_COMPOUND) {
563 bRet=myOrigins.IsBound(aCx);
570 bRet=myOrigins.IsBound(aC);
574 //=======================================================================
575 //function : BuildResult
577 //=======================================================================
578 void GEOMAlgo_Gluer2::BuildResult()
580 Standard_Boolean bHasImage;
581 TopoDS_Shape aCnew, aCXnew;
582 TopoDS_Iterator aItC;
588 bHasImage=Standard_False;
589 aItC.Initialize(myArgument);
590 for (; aItC.More(); aItC.Next()) {
591 const TopoDS_Shape& aCx=aItC.Value();
592 bHasImage=HasImage(aCx);
603 GEOMAlgo_AlgoTools::MakeContainer(TopAbs_COMPOUND, aCnew);
605 aItC.Initialize(myArgument);
606 for (; aItC.More(); aItC.Next()) {
607 const TopoDS_Shape& aCX=aItC.Value();
608 if (myOrigins.IsBound(aCX)) {
609 aCXnew=myOrigins.Find(aCX);
610 aCXnew.Orientation(aCX.Orientation());
611 aBB.Add(aCnew, aCXnew);
618 if (!myKeepNonSolids) {
619 Standard_Integer i, aNb;
621 TopTools_IndexedMapOfShape aM;
623 GEOMAlgo_AlgoTools::MakeContainer(TopAbs_COMPOUND, aCnew1);
625 TopExp::MapShapes(aCnew, TopAbs_SOLID, aM);
628 for (i=1; i<=aNb; ++i) {
629 const TopoDS_Shape& aS=aM(i);
637 //--------------------------------------------------------
640 // 11 - GEOMAlgo_GlueDetector failed
641 // 13 - PerformImagesToWork failed
642 // 14 - PerformImagesToWork failed
645 // 1 - no shapes to glue
646 // 2 - sticked shapes are detected.
647 // The value of myTolerance is so large that
648 // subshapes of a shape becomes intefere
649 // (e.g. vertices of an edge).
651 // the result is can not be obtained