1 // Copyright (C) 2007-2012 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
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 <GEOMAlgo_GlueDetector.hxx>
48 #include <GEOMAlgo_Tools3D.hxx>
50 //=======================================================================
51 //function : GEOMAlgo_Gluer2
53 //=======================================================================
54 GEOMAlgo_Gluer2::GEOMAlgo_Gluer2()
57 GEOMAlgo_BuilderShape()
61 //=======================================================================
62 //function : ~GEOMAlgo_Gluer2
64 //=======================================================================
65 GEOMAlgo_Gluer2::~GEOMAlgo_Gluer2()
68 //=======================================================================
71 //=======================================================================
72 void GEOMAlgo_Gluer2::Clear()
77 GEOMAlgo_GluerAlgo::Clear();
79 myImagesDetected.Clear();
80 myOriginsDetected.Clear();
81 myShapesToGlue.Clear();
82 myImagesToWork.Clear();
83 myOriginsToWork.Clear();
84 myKeepNonSolids=Standard_False;
85 //modified by NIZNHY-PKV Tue Mar 13 13:38:28 2012f
87 //modified by NIZNHY-PKV Tue Mar 13 13:38:30 2012t
89 //modified by NIZNHY-PKV Tue Mar 13 12:26:50 2012f
90 //=======================================================================
91 //function : StickedShapes
93 //=======================================================================
94 const TopTools_IndexedDataMapOfShapeListOfShape&
95 GEOMAlgo_Gluer2::StickedShapes()
97 return myDetector.StickedShapes();
99 //modified by NIZNHY-PKV Tue Mar 13 12:26:54 2012t
100 //=======================================================================
101 //function : SetShapesToGlue
103 //=======================================================================
104 void GEOMAlgo_Gluer2::SetShapesToGlue(const TopTools_DataMapOfShapeListOfShape& aM)
108 //=======================================================================
109 //function : ShapesToGlue
111 //=======================================================================
112 const TopTools_DataMapOfShapeListOfShape& GEOMAlgo_Gluer2::ShapesToGlue()const
114 return myShapesToGlue;
116 //=======================================================================
117 //function : SetKeepNonSolids
119 //=======================================================================
120 void GEOMAlgo_Gluer2::SetKeepNonSolids(const Standard_Boolean aFlag)
122 myKeepNonSolids=aFlag;
124 //=======================================================================
125 //function : KeepNonSolids
127 //=======================================================================
128 Standard_Boolean GEOMAlgo_Gluer2::KeepNonSolids()const
130 return myKeepNonSolids;
132 //=======================================================================
133 //function : ShapesDetected
135 //=======================================================================
136 const TopTools_DataMapOfShapeListOfShape& GEOMAlgo_Gluer2::ShapesDetected()const
138 return myImagesDetected;
140 //=======================================================================
141 //function : ImagesToWork
143 //=======================================================================
144 const TopTools_DataMapOfShapeListOfShape& GEOMAlgo_Gluer2::ImagesToWork()const
146 return myImagesToWork;
148 //=======================================================================
151 //=======================================================================
152 void GEOMAlgo_Gluer2::Perform()
162 // Initialize the context
163 GEOMAlgo_GluerAlgo::Perform();
165 PerformShapesToWork();
169 if (myWarningStatus==1) {
225 BRepLib::SameParameter(myShape, myTolerance, Standard_True);
227 //=======================================================================
228 //function : CheckData
230 //=======================================================================
231 void GEOMAlgo_Gluer2::CheckData()
233 Standard_Integer aNbSG, i;
234 TopAbs_ShapeEnum aType, aTypeX;
235 TopTools_ListIteratorOfListOfShape aItLS;
236 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItDMSLS;
241 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_Tools3D::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=GEOMAlgo_Tools3D::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_Tools3D::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 aItC.Initialize(myArgument);
589 for (; aItC.More(); aItC.Next()) {
590 const TopoDS_Shape& aCx=aItC.Value();
591 bHasImage=HasImage(aCx);
602 GEOMAlgo_Tools3D::MakeContainer(TopAbs_COMPOUND, aCnew);
604 aItC.Initialize(myArgument);
605 for (; aItC.More(); aItC.Next()) {
606 const TopoDS_Shape& aCX=aItC.Value();
607 if (myOrigins.IsBound(aCX)) {
608 aCXnew=myOrigins.Find(aCX);
609 aCXnew.Orientation(aCX.Orientation());
610 aBB.Add(aCnew, aCXnew);
617 if (!myKeepNonSolids) {
618 Standard_Integer i, aNb;
620 TopTools_IndexedMapOfShape aM;
622 GEOMAlgo_Tools3D::MakeContainer(TopAbs_COMPOUND, aCnew1);
624 TopExp::MapShapes(aCnew, TopAbs_SOLID, aM);
627 for (i=1; i<=aNb; ++i) {
628 const TopoDS_Shape& aS=aM(i);
636 //--------------------------------------------------------
639 // 11 - GEOMAlgo_GlueDetector failed
640 // 13 - PerformImagesToWork failed
641 // 14 - PerformImagesToWork failed
644 // 1 - no shapes to glue
645 // 2 - sticked shapes are detected.
646 // The value of myTolerance is so large that
647 // subshapes of a shape becomes intefere
648 // (e.g. vertices of an edge).
650 // the result is can not be obtained