1 // Copyright (C) 2007-2014 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;
87 //modified by NIZNHY-PKV Tue Mar 13 13:38:28 2012f
89 //modified by NIZNHY-PKV Tue Mar 13 13:38:30 2012t
91 //modified by NIZNHY-PKV Tue Mar 13 12:26:50 2012f
92 //=======================================================================
93 //function : StickedShapes
95 //=======================================================================
96 const TopTools_IndexedDataMapOfShapeListOfShape&
97 GEOMAlgo_Gluer2::StickedShapes()
99 return myDetector.StickedShapes();
101 //modified by NIZNHY-PKV Tue Mar 13 12:26:54 2012t
102 //=======================================================================
103 //function : SetShapesToGlue
105 //=======================================================================
106 void GEOMAlgo_Gluer2::SetShapesToGlue(const TopTools_DataMapOfShapeListOfShape& aM)
110 //=======================================================================
111 //function : ShapesToGlue
113 //=======================================================================
114 const TopTools_DataMapOfShapeListOfShape& GEOMAlgo_Gluer2::ShapesToGlue()const
116 return myShapesToGlue;
118 //=======================================================================
119 //function : SetKeepNonSolids
121 //=======================================================================
122 void GEOMAlgo_Gluer2::SetKeepNonSolids(const Standard_Boolean aFlag)
124 myKeepNonSolids=aFlag;
126 //=======================================================================
127 //function : KeepNonSolids
129 //=======================================================================
130 Standard_Boolean GEOMAlgo_Gluer2::KeepNonSolids()const
132 return myKeepNonSolids;
134 //=======================================================================
135 //function : ShapesDetected
137 //=======================================================================
138 const TopTools_DataMapOfShapeListOfShape& GEOMAlgo_Gluer2::ShapesDetected()const
140 return myImagesDetected;
142 //=======================================================================
143 //function : ImagesToWork
145 //=======================================================================
146 const TopTools_DataMapOfShapeListOfShape& GEOMAlgo_Gluer2::ImagesToWork()const
148 return myImagesToWork;
150 //=======================================================================
153 //=======================================================================
154 void GEOMAlgo_Gluer2::Perform()
164 // Initialize the context
165 GEOMAlgo_GluerAlgo::Perform();
167 PerformShapesToWork();
171 if (myWarningStatus==1) {
227 BRepLib::SameParameter(myShape, myTolerance, Standard_True);
229 //=======================================================================
230 //function : CheckData
232 //=======================================================================
233 void GEOMAlgo_Gluer2::CheckData()
235 Standard_Integer aNbSG, i;
236 TopAbs_ShapeEnum aType, aTypeX;
237 TopTools_ListIteratorOfListOfShape aItLS;
238 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItDMSLS;
243 aNbSG=myShapesToGlue.Extent();
245 // Check myShapesToGlue
246 aItDMSLS.Initialize(myShapesToGlue);
247 for (; aItDMSLS.More(); aItDMSLS.Next()) {
248 //const TopoDS_Shape& aSkey=aItDMSLS.Key();
249 const TopTools_ListOfShape& aLSG=aItDMSLS.Value();
250 aItLS.Initialize(aLSG);
251 for (i=0; aItLS.More(); aItLS.Next(), ++i) {
252 const TopoDS_Shape& aSG=aItLS.Value();
253 aTypeX=aSG.ShapeType();
256 if (!(aType==TopAbs_VERTEX ||
257 aType==TopAbs_EDGE ||
258 aType==TopAbs_FACE)) {
259 myErrorStatus=21;// non-brep shapes
265 myErrorStatus=20;// non-homogeneous shapes
272 //=======================================================================
273 //function : FillEdges
275 //=======================================================================
276 void GEOMAlgo_Gluer2::FillEdges()
278 FillBRepShapes(TopAbs_EDGE);
280 //=======================================================================
281 //function : FillFaces
283 //=======================================================================
284 void GEOMAlgo_Gluer2::FillFaces()
286 FillBRepShapes(TopAbs_FACE);
288 //=======================================================================
289 //function : FillWires
291 //=======================================================================
292 void GEOMAlgo_Gluer2::FillWires()
294 FillContainers(TopAbs_WIRE);
296 //=======================================================================
297 //function : FillShells
299 //=======================================================================
300 void GEOMAlgo_Gluer2::FillShells()
302 FillContainers(TopAbs_SHELL);
304 //=======================================================================
305 //function : FillSolids
307 //=======================================================================
308 void GEOMAlgo_Gluer2::FillSolids()
310 FillContainers(TopAbs_SOLID);
312 //=======================================================================
313 //function : FillCompSolids
315 //=======================================================================
316 void GEOMAlgo_Gluer2::FillCompSolids()
318 FillContainers(TopAbs_COMPSOLID);
320 //=======================================================================
321 //function : FillVertices
323 //=======================================================================
324 void GEOMAlgo_Gluer2::FillVertices()
326 TopAbs_ShapeEnum aType;
328 TopTools_ListIteratorOfListOfShape aItLS;
329 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItDMSLS;
334 aItDMSLS.Initialize(myImagesToWork);
335 for (; aItDMSLS.More(); aItDMSLS.Next()) {
336 const TopoDS_Shape& aSkey=aItDMSLS.Key();
337 aType=aSkey.ShapeType();
338 if (aType!=TopAbs_VERTEX) {
342 const TopTools_ListOfShape& aLSD=aItDMSLS.Value();
344 GEOMAlgo_Gluer2::MakeVertex(aLSD, aVnew);
346 myImages.Bind(aVnew, aLSD);
348 aItLS.Initialize(aLSD);
349 for (; aItLS.More(); aItLS.Next()) {
350 const TopoDS_Shape& aV=aItLS.Value();
351 myOrigins.Bind(aV, aVnew);
355 //=======================================================================
356 //function : FillBRepShapes
358 //=======================================================================
359 void GEOMAlgo_Gluer2::FillBRepShapes(const TopAbs_ShapeEnum theType)
361 Standard_Boolean bHasImage, bIsToWork;
362 Standard_Integer i, aNbE;
363 TopoDS_Iterator aItS;
365 TopTools_IndexedMapOfShape aME;
366 TopTools_MapOfShape aMFence;
367 TopTools_ListIteratorOfListOfShape aItLS;
372 TopExp::MapShapes(myArgument, theType, aME);
375 for (i=1; i<=aNbE; ++i) {
376 const TopoDS_Shape& aE=aME(i);
378 if (!aMFence.Add(aE)) {
382 bIsToWork=myOriginsToWork.IsBound(aE);
383 bHasImage=HasImage(aE);
384 if (!bHasImage && !bIsToWork) {
388 MakeBRepShapes(aE, aEnew);
390 //myImages / myOrigins
392 const TopoDS_Shape& aSkey=myOriginsToWork.Find(aE);
393 const TopTools_ListOfShape& aLSD=myImagesToWork.Find(aSkey);
395 myImages.Bind(aEnew, aLSD);
397 aItLS.Initialize(aLSD);
398 for (; aItLS.More(); aItLS.Next()) {
399 const TopoDS_Shape& aEx=aItLS.Value();
400 myOrigins.Bind(aEx, aEnew);
406 TopTools_ListOfShape aLSD;
409 myImages.Bind(aEnew, aLSD);
410 myOrigins.Bind(aE, aEnew);
412 }//for (i=1; i<=aNbF; ++i) {
414 //=======================================================================
415 //function : FillContainers
417 //=======================================================================
418 void GEOMAlgo_Gluer2::FillContainers(const TopAbs_ShapeEnum aType)
420 Standard_Boolean bHasImage, bToReverse;
421 Standard_Integer i, aNbW;
422 TopoDS_Shape aWnew, aEnew;
423 TopoDS_Iterator aItS;
425 TopTools_IndexedMapOfShape aMW;
426 TopTools_MapOfShape aMFence;
431 TopExp::MapShapes(myArgument, aType, aMW);
434 for (i=1; i<=aNbW; ++i) {
435 const TopoDS_Shape& aW=aMW(i);
437 if (!aMFence.Add(aW)) {
441 bHasImage=HasImage(aW);
446 GEOMAlgo_AlgoTools::MakeContainer(aType, aWnew);
447 aWnew.Orientation(aW.Orientation());
450 for (; aItS.More(); aItS.Next()) {
451 const TopoDS_Shape& aE=aItS.Value();
452 if (myOrigins.IsBound(aE)) {
453 aEnew=myOrigins.Find(aE);
455 bToReverse=BOPTools_AlgoTools::IsSplitToReverse(aEnew, aE, myContext);
460 aBB.Add(aWnew, aEnew);
467 //myImages / myOrigins
468 TopTools_ListOfShape aLSD;
471 myImages.Bind(aWnew, aLSD);
472 myOrigins.Bind(aW, aWnew);
474 }//for (i=1; i<=aNbE; ++i) {
476 //=======================================================================
477 //function : FillCompounds
479 //=======================================================================
480 void GEOMAlgo_Gluer2::FillCompounds()
482 TopAbs_ShapeEnum aType;
483 TopoDS_Iterator aItC;
488 aItC.Initialize(myArgument);
489 for (; aItC.More(); aItC.Next()) {
490 const TopoDS_Shape& aCx=aItC.Value();
491 aType=aCx.ShapeType();
492 if (aType==TopAbs_COMPOUND) {
497 //=======================================================================
498 //function : FillCompound
500 //=======================================================================
501 void GEOMAlgo_Gluer2::FillCompound(const TopoDS_Shape& aC)
503 Standard_Boolean bHasImage;
504 TopAbs_ShapeEnum aType;
505 TopoDS_Shape aCnew, aCXnew;
506 TopoDS_Iterator aItC;
509 bHasImage=HasImage(aC);
514 GEOMAlgo_AlgoTools::MakeContainer(TopAbs_COMPOUND, aCnew);
517 for (; aItC.More(); aItC.Next()) {
518 const TopoDS_Shape& aCX=aItC.Value();
519 aType=aCX.ShapeType();
521 if (aType==TopAbs_COMPOUND) {
525 if (myOrigins.IsBound(aCX)) {
526 aCXnew=myOrigins.Find(aCX);
527 aCXnew.Orientation(aCX.Orientation());
528 aBB.Add(aCnew, aCXnew);
535 //myImages / myOrigins
536 TopTools_ListOfShape aLSD;
539 myImages.Bind(aCnew, aLSD);
540 myOrigins.Bind(aC, aCnew);
542 //=======================================================================
543 //function : HasImage
545 //=======================================================================
546 Standard_Boolean GEOMAlgo_Gluer2::HasImage(const TopoDS_Shape& aC)
548 Standard_Boolean bRet;
549 TopAbs_ShapeEnum aType;
550 TopoDS_Iterator aItC;
554 for (; aItC.More(); aItC.Next()) {
555 const TopoDS_Shape& aCx=aItC.Value();
556 aType=aCx.ShapeType();
558 if (aType==TopAbs_COMPOUND) {
565 bRet=myOrigins.IsBound(aCx);
572 bRet=myOrigins.IsBound(aC);
576 //=======================================================================
577 //function : BuildResult
579 //=======================================================================
580 void GEOMAlgo_Gluer2::BuildResult()
582 Standard_Boolean bHasImage;
583 TopoDS_Shape aCnew, aCXnew;
584 TopoDS_Iterator aItC;
590 aItC.Initialize(myArgument);
591 for (; aItC.More(); aItC.Next()) {
592 const TopoDS_Shape& aCx=aItC.Value();
593 bHasImage=HasImage(aCx);
604 GEOMAlgo_AlgoTools::MakeContainer(TopAbs_COMPOUND, aCnew);
606 aItC.Initialize(myArgument);
607 for (; aItC.More(); aItC.Next()) {
608 const TopoDS_Shape& aCX=aItC.Value();
609 if (myOrigins.IsBound(aCX)) {
610 aCXnew=myOrigins.Find(aCX);
611 aCXnew.Orientation(aCX.Orientation());
612 aBB.Add(aCnew, aCXnew);
619 if (!myKeepNonSolids) {
620 Standard_Integer i, aNb;
622 TopTools_IndexedMapOfShape aM;
624 GEOMAlgo_AlgoTools::MakeContainer(TopAbs_COMPOUND, aCnew1);
626 TopExp::MapShapes(aCnew, TopAbs_SOLID, aM);
629 for (i=1; i<=aNb; ++i) {
630 const TopoDS_Shape& aS=aM(i);
638 //--------------------------------------------------------
641 // 11 - GEOMAlgo_GlueDetector failed
642 // 13 - PerformImagesToWork failed
643 // 14 - PerformImagesToWork failed
646 // 1 - no shapes to glue
647 // 2 - sticked shapes are detected.
648 // The value of myTolerance is so large that
649 // subshapes of a shape becomes intefere
650 // (e.g. vertices of an edge).
652 // the result is can not be obtained