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_Gluer2.cxx
23 // Author: Peter KURNEV
25 #include <GEOMAlgo_Gluer2.hxx>
27 #include <TopAbs_ShapeEnum.hxx>
29 #include <TopoDS_Compound.hxx>
30 #include <TopoDS_Iterator.hxx>
31 #include <TopoDS_Shape.hxx>
32 #include <TopoDS_Vertex.hxx>
34 #include <BRep_Builder.hxx>
36 #include <BRepLib.hxx>
38 #include <TopTools_MapOfShape.hxx>
39 #include <TopTools_MapIteratorOfMapOfShape.hxx>
40 #include <TopTools_DataMapOfShapeShape.hxx>
41 #include <TopTools_ListOfShape.hxx>
42 #include <TopTools_ListIteratorOfListOfShape.hxx>
43 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
44 #include <TopTools_IndexedMapOfShape.hxx>
46 #include <GEOMAlgo_GlueDetector.hxx>
47 #include <GEOMAlgo_Tools3D.hxx>
49 //=======================================================================
50 //function : GEOMAlgo_Gluer2
52 //=======================================================================
53 GEOMAlgo_Gluer2::GEOMAlgo_Gluer2()
56 GEOMAlgo_BuilderShape()
60 //=======================================================================
61 //function : ~GEOMAlgo_Gluer2
63 //=======================================================================
64 GEOMAlgo_Gluer2::~GEOMAlgo_Gluer2()
67 //=======================================================================
70 //=======================================================================
71 void GEOMAlgo_Gluer2::Clear()
76 GEOMAlgo_GluerAlgo::Clear();
78 myImagesDetected.Clear();
79 myOriginsDetected.Clear();
80 myShapesToGlue.Clear();
81 myImagesToWork.Clear();
82 myOriginsToWork.Clear();
83 myKeepNonSolids=Standard_False;
84 //modified by NIZNHY-PKV Tue Mar 13 13:38:28 2012f
86 //modified by NIZNHY-PKV Tue Mar 13 13:38:30 2012t
88 //modified by NIZNHY-PKV Tue Mar 13 12:26:50 2012f
89 //=======================================================================
90 //function : StickedShapes
92 //=======================================================================
93 const TopTools_IndexedDataMapOfShapeListOfShape&
94 GEOMAlgo_Gluer2::StickedShapes()
96 return myDetector.StickedShapes();
98 //modified by NIZNHY-PKV Tue Mar 13 12:26:54 2012t
99 //=======================================================================
100 //function : SetShapesToGlue
102 //=======================================================================
103 void GEOMAlgo_Gluer2::SetShapesToGlue(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();
242 // Check myShapesToGlue
243 aItDMSLS.Initialize(myShapesToGlue);
244 for (; aItDMSLS.More(); aItDMSLS.Next()) {
245 //const TopoDS_Shape& aSkey=aItDMSLS.Key();
246 const TopTools_ListOfShape& aLSG=aItDMSLS.Value();
247 aItLS.Initialize(aLSG);
248 for (i=0; aItLS.More(); aItLS.Next(), ++i) {
249 const TopoDS_Shape& aSG=aItLS.Value();
250 aTypeX=aSG.ShapeType();
253 if (!(aType==TopAbs_VERTEX ||
254 aType==TopAbs_EDGE ||
255 aType==TopAbs_FACE)) {
256 myErrorStatus=21;// non-brep shapes
262 myErrorStatus=20;// non-homogeneous shapes
269 //=======================================================================
270 //function : FillEdges
272 //=======================================================================
273 void GEOMAlgo_Gluer2::FillEdges()
275 FillBRepShapes(TopAbs_EDGE);
277 //=======================================================================
278 //function : FillFaces
280 //=======================================================================
281 void GEOMAlgo_Gluer2::FillFaces()
283 FillBRepShapes(TopAbs_FACE);
285 //=======================================================================
286 //function : FillWires
288 //=======================================================================
289 void GEOMAlgo_Gluer2::FillWires()
291 FillContainers(TopAbs_WIRE);
293 //=======================================================================
294 //function : FillShells
296 //=======================================================================
297 void GEOMAlgo_Gluer2::FillShells()
299 FillContainers(TopAbs_SHELL);
301 //=======================================================================
302 //function : FillSolids
304 //=======================================================================
305 void GEOMAlgo_Gluer2::FillSolids()
307 FillContainers(TopAbs_SOLID);
309 //=======================================================================
310 //function : FillCompSolids
312 //=======================================================================
313 void GEOMAlgo_Gluer2::FillCompSolids()
315 FillContainers(TopAbs_COMPSOLID);
317 //=======================================================================
318 //function : FillVertices
320 //=======================================================================
321 void GEOMAlgo_Gluer2::FillVertices()
323 TopAbs_ShapeEnum aType;
325 TopTools_ListIteratorOfListOfShape aItLS;
326 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItDMSLS;
331 aItDMSLS.Initialize(myImagesToWork);
332 for (; aItDMSLS.More(); aItDMSLS.Next()) {
333 const TopoDS_Shape& aSkey=aItDMSLS.Key();
334 aType=aSkey.ShapeType();
335 if (aType!=TopAbs_VERTEX) {
339 const TopTools_ListOfShape& aLSD=aItDMSLS.Value();
341 GEOMAlgo_Gluer2::MakeVertex(aLSD, aVnew);
343 myImages.Bind(aVnew, aLSD);
345 aItLS.Initialize(aLSD);
346 for (; aItLS.More(); aItLS.Next()) {
347 const TopoDS_Shape& aV=aItLS.Value();
348 myOrigins.Bind(aV, aVnew);
352 //=======================================================================
353 //function : FillBRepShapes
355 //=======================================================================
356 void GEOMAlgo_Gluer2::FillBRepShapes(const TopAbs_ShapeEnum theType)
358 Standard_Boolean bHasImage, bIsToWork;
359 Standard_Integer i, aNbE;
360 TopoDS_Iterator aItS;
362 TopTools_IndexedMapOfShape aME;
363 TopTools_MapOfShape aMFence;
364 TopTools_ListIteratorOfListOfShape aItLS;
369 TopExp::MapShapes(myArgument, theType, aME);
372 for (i=1; i<=aNbE; ++i) {
373 const TopoDS_Shape& aE=aME(i);
375 if (!aMFence.Add(aE)) {
379 bIsToWork=myOriginsToWork.IsBound(aE);
380 bHasImage=HasImage(aE);
381 if (!bHasImage && !bIsToWork) {
385 MakeBRepShapes(aE, aEnew);
387 //myImages / myOrigins
389 const TopoDS_Shape& aSkey=myOriginsToWork.Find(aE);
390 const TopTools_ListOfShape& aLSD=myImagesToWork.Find(aSkey);
392 myImages.Bind(aEnew, aLSD);
394 aItLS.Initialize(aLSD);
395 for (; aItLS.More(); aItLS.Next()) {
396 const TopoDS_Shape& aEx=aItLS.Value();
397 myOrigins.Bind(aEx, aEnew);
403 TopTools_ListOfShape aLSD;
406 myImages.Bind(aEnew, aLSD);
407 myOrigins.Bind(aE, aEnew);
409 }//for (i=1; i<=aNbF; ++i) {
411 //=======================================================================
412 //function : FillContainers
414 //=======================================================================
415 void GEOMAlgo_Gluer2::FillContainers(const TopAbs_ShapeEnum aType)
417 Standard_Boolean bHasImage, bToReverse;
418 Standard_Integer i, aNbW;
419 TopoDS_Shape aWnew, aEnew;
420 TopoDS_Iterator aItS;
422 TopTools_IndexedMapOfShape aMW;
423 TopTools_MapOfShape aMFence;
428 TopExp::MapShapes(myArgument, aType, aMW);
431 for (i=1; i<=aNbW; ++i) {
432 const TopoDS_Shape& aW=aMW(i);
434 if (!aMFence.Add(aW)) {
438 bHasImage=HasImage(aW);
443 GEOMAlgo_Tools3D::MakeContainer(aType, aWnew);
444 aWnew.Orientation(aW.Orientation());
447 for (; aItS.More(); aItS.Next()) {
448 const TopoDS_Shape& aE=aItS.Value();
449 if (myOrigins.IsBound(aE)) {
450 aEnew=myOrigins.Find(aE);
452 bToReverse=GEOMAlgo_Tools3D::IsSplitToReverse(aEnew, aE, myContext);
457 aBB.Add(aWnew, aEnew);
464 //myImages / myOrigins
465 TopTools_ListOfShape aLSD;
468 myImages.Bind(aWnew, aLSD);
469 myOrigins.Bind(aW, aWnew);
471 }//for (i=1; i<=aNbE; ++i) {
473 //=======================================================================
474 //function : FillCompounds
476 //=======================================================================
477 void GEOMAlgo_Gluer2::FillCompounds()
479 TopAbs_ShapeEnum aType;
480 TopoDS_Iterator aItC;
485 aItC.Initialize(myArgument);
486 for (; aItC.More(); aItC.Next()) {
487 const TopoDS_Shape& aCx=aItC.Value();
488 aType=aCx.ShapeType();
489 if (aType==TopAbs_COMPOUND) {
494 //=======================================================================
495 //function : FillCompound
497 //=======================================================================
498 void GEOMAlgo_Gluer2::FillCompound(const TopoDS_Shape& aC)
500 Standard_Boolean bHasImage;
501 TopAbs_ShapeEnum aType;
502 TopoDS_Shape aCnew, aCXnew;
503 TopoDS_Iterator aItC;
506 bHasImage=HasImage(aC);
511 GEOMAlgo_Tools3D::MakeContainer(TopAbs_COMPOUND, aCnew);
514 for (; aItC.More(); aItC.Next()) {
515 const TopoDS_Shape& aCX=aItC.Value();
516 aType=aCX.ShapeType();
518 if (aType==TopAbs_COMPOUND) {
522 if (myOrigins.IsBound(aCX)) {
523 aCXnew=myOrigins.Find(aCX);
524 aCXnew.Orientation(aCX.Orientation());
525 aBB.Add(aCnew, aCXnew);
532 //myImages / myOrigins
533 TopTools_ListOfShape aLSD;
536 myImages.Bind(aCnew, aLSD);
537 myOrigins.Bind(aC, aCnew);
539 //=======================================================================
540 //function : HasImage
542 //=======================================================================
543 Standard_Boolean GEOMAlgo_Gluer2::HasImage(const TopoDS_Shape& aC)
545 Standard_Boolean bRet;
546 TopAbs_ShapeEnum aType;
547 TopoDS_Iterator aItC;
551 for (; aItC.More(); aItC.Next()) {
552 const TopoDS_Shape& aCx=aItC.Value();
553 aType=aCx.ShapeType();
555 if (aType==TopAbs_COMPOUND) {
562 bRet=myOrigins.IsBound(aCx);
569 bRet=myOrigins.IsBound(aC);
573 //=======================================================================
574 //function : BuildResult
576 //=======================================================================
577 void GEOMAlgo_Gluer2::BuildResult()
579 Standard_Boolean bHasImage;
580 TopoDS_Shape aCnew, aCXnew;
581 TopoDS_Iterator aItC;
587 aItC.Initialize(myArgument);
588 for (; aItC.More(); aItC.Next()) {
589 const TopoDS_Shape& aCx=aItC.Value();
590 bHasImage=HasImage(aCx);
601 GEOMAlgo_Tools3D::MakeContainer(TopAbs_COMPOUND, aCnew);
603 aItC.Initialize(myArgument);
604 for (; aItC.More(); aItC.Next()) {
605 const TopoDS_Shape& aCX=aItC.Value();
606 if (myOrigins.IsBound(aCX)) {
607 aCXnew=myOrigins.Find(aCX);
608 aCXnew.Orientation(aCX.Orientation());
609 aBB.Add(aCnew, aCXnew);
616 if (!myKeepNonSolids) {
617 Standard_Integer i, aNb;
619 TopTools_IndexedMapOfShape aM;
621 GEOMAlgo_Tools3D::MakeContainer(TopAbs_COMPOUND, aCnew1);
623 TopExp::MapShapes(aCnew, TopAbs_SOLID, aM);
626 for (i=1; i<=aNb; ++i) {
627 const TopoDS_Shape& aS=aM(i);
635 //--------------------------------------------------------
638 // 11 - GEOMAlgo_GlueDetector failed
639 // 13 - PerformImagesToWork failed
640 // 14 - PerformImagesToWork failed
643 // 1 - no shapes to glue
644 // 2 - sticked shapes are detected.
645 // The value of myTolerance is so large that
646 // subshapes of a shape becomes intefere
647 // (e.g. vertices of an edge).
649 // the result is can not be obtained