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;
85 //=======================================================================
86 //function : SetShapesToGlue
88 //=======================================================================
89 void GEOMAlgo_Gluer2::SetShapesToGlue(const TopTools_DataMapOfShapeListOfShape& aM)
93 //=======================================================================
94 //function : ShapesToGlue
96 //=======================================================================
97 const TopTools_DataMapOfShapeListOfShape& GEOMAlgo_Gluer2::ShapesToGlue()const
99 return myShapesToGlue;
101 //=======================================================================
102 //function : SetKeepNonSolids
104 //=======================================================================
105 void GEOMAlgo_Gluer2::SetKeepNonSolids(const Standard_Boolean aFlag)
107 myKeepNonSolids=aFlag;
109 //=======================================================================
110 //function : KeepNonSolids
112 //=======================================================================
113 Standard_Boolean GEOMAlgo_Gluer2::KeepNonSolids()const
115 return myKeepNonSolids;
117 //=======================================================================
118 //function : ShapesDetected
120 //=======================================================================
121 const TopTools_DataMapOfShapeListOfShape& GEOMAlgo_Gluer2::ShapesDetected()const
123 return myImagesDetected;
125 //=======================================================================
126 //function : ImagesToWork
128 //=======================================================================
129 const TopTools_DataMapOfShapeListOfShape& GEOMAlgo_Gluer2::ImagesToWork()const
131 return myImagesToWork;
133 //=======================================================================
136 //=======================================================================
137 void GEOMAlgo_Gluer2::Perform()
147 PerformShapesToWork();
151 if (myWarningStatus==1) {// no shapes to glue
206 BRepLib::SameParameter(myShape, myTolerance, Standard_True);
208 //=======================================================================
209 //function : CheckData
211 //=======================================================================
212 void GEOMAlgo_Gluer2::CheckData()
214 Standard_Integer aNbSG, i;
215 TopAbs_ShapeEnum aType, aTypeX;
216 TopTools_ListIteratorOfListOfShape aItLS;
217 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItDMSLS;
222 aNbSG=myShapesToGlue.Extent();
224 // Check myShapesToGlue
225 aItDMSLS.Initialize(myShapesToGlue);
226 for (; aItDMSLS.More(); aItDMSLS.Next()) {
227 //const TopoDS_Shape& aSkey=aItDMSLS.Key();
228 const TopTools_ListOfShape& aLSG=aItDMSLS.Value();
229 aItLS.Initialize(aLSG);
230 for (i=0; aItLS.More(); aItLS.Next(), ++i) {
231 const TopoDS_Shape& aSG=aItLS.Value();
232 aTypeX=aSG.ShapeType();
235 if (!(aType==TopAbs_VERTEX ||
236 aType==TopAbs_EDGE ||
237 aType==TopAbs_FACE)) {
238 myErrorStatus=21;// non-brep shapes
244 myErrorStatus=20;// non-homogeneous shapes
251 //=======================================================================
252 //function : FillEdges
254 //=======================================================================
255 void GEOMAlgo_Gluer2::FillEdges()
257 FillBRepShapes(TopAbs_EDGE);
259 //=======================================================================
260 //function : FillFaces
262 //=======================================================================
263 void GEOMAlgo_Gluer2::FillFaces()
265 FillBRepShapes(TopAbs_FACE);
267 //=======================================================================
268 //function : FillWires
270 //=======================================================================
271 void GEOMAlgo_Gluer2::FillWires()
273 FillContainers(TopAbs_WIRE);
275 //=======================================================================
276 //function : FillShells
278 //=======================================================================
279 void GEOMAlgo_Gluer2::FillShells()
281 FillContainers(TopAbs_SHELL);
283 //=======================================================================
284 //function : FillSolids
286 //=======================================================================
287 void GEOMAlgo_Gluer2::FillSolids()
289 FillContainers(TopAbs_SOLID);
291 //=======================================================================
292 //function : FillCompSolids
294 //=======================================================================
295 void GEOMAlgo_Gluer2::FillCompSolids()
297 FillContainers(TopAbs_COMPSOLID);
299 //=======================================================================
300 //function : FillVertices
302 //=======================================================================
303 void GEOMAlgo_Gluer2::FillVertices()
305 TopAbs_ShapeEnum aType;
307 TopTools_ListIteratorOfListOfShape aItLS;
308 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItDMSLS;
313 aItDMSLS.Initialize(myImagesToWork);
314 for (; aItDMSLS.More(); aItDMSLS.Next()) {
315 const TopoDS_Shape& aSkey=aItDMSLS.Key();
316 aType=aSkey.ShapeType();
317 if (aType!=TopAbs_VERTEX) {
321 const TopTools_ListOfShape& aLSD=aItDMSLS.Value();
323 GEOMAlgo_Gluer2::MakeVertex(aLSD, aVnew);
325 myImages.Bind(aVnew, aLSD);
327 aItLS.Initialize(aLSD);
328 for (; aItLS.More(); aItLS.Next()) {
329 const TopoDS_Shape& aV=aItLS.Value();
330 myOrigins.Bind(aV, aVnew);
334 //=======================================================================
335 //function : FillBRepShapes
337 //=======================================================================
338 void GEOMAlgo_Gluer2::FillBRepShapes(const TopAbs_ShapeEnum theType)
340 Standard_Boolean bHasImage, bIsToWork;
341 Standard_Integer i, aNbE;
342 TopoDS_Iterator aItS;
344 TopTools_IndexedMapOfShape aME;
345 TopTools_MapOfShape aMFence;
346 TopTools_ListIteratorOfListOfShape aItLS;
351 TopExp::MapShapes(myArgument, theType, aME);
354 for (i=1; i<=aNbE; ++i) {
355 const TopoDS_Shape& aE=aME(i);
357 if (!aMFence.Add(aE)) {
361 bIsToWork=myOriginsToWork.IsBound(aE);
362 bHasImage=HasImage(aE);
363 if (!bHasImage && !bIsToWork) {
367 MakeBRepShapes(aE, aEnew);
369 //myImages / myOrigins
371 const TopoDS_Shape& aSkey=myOriginsToWork.Find(aE);
372 const TopTools_ListOfShape& aLSD=myImagesToWork.Find(aSkey);
374 myImages.Bind(aEnew, aLSD);
376 aItLS.Initialize(aLSD);
377 for (; aItLS.More(); aItLS.Next()) {
378 const TopoDS_Shape& aEx=aItLS.Value();
379 myOrigins.Bind(aEx, aEnew);
385 TopTools_ListOfShape aLSD;
388 myImages.Bind(aEnew, aLSD);
389 myOrigins.Bind(aE, aEnew);
391 }//for (i=1; i<=aNbF; ++i) {
393 //=======================================================================
394 //function : FillContainers
396 //=======================================================================
397 void GEOMAlgo_Gluer2::FillContainers(const TopAbs_ShapeEnum aType)
399 Standard_Boolean bHasImage, bToReverse;
400 Standard_Integer i, aNbW;
401 TopoDS_Shape aWnew, aEnew;
402 TopoDS_Iterator aItS;
404 TopTools_IndexedMapOfShape aMW;
405 TopTools_MapOfShape aMFence;
410 TopExp::MapShapes(myArgument, aType, aMW);
413 for (i=1; i<=aNbW; ++i) {
414 const TopoDS_Shape& aW=aMW(i);
416 if (!aMFence.Add(aW)) {
420 bHasImage=HasImage(aW);
425 GEOMAlgo_Tools3D::MakeContainer(aType, aWnew);
426 //modified by NIZNHY-PKV Tue May 10 13:46:30 2011f
427 aWnew.Orientation(aW.Orientation());
428 //modified by NIZNHY-PKV Tue May 10 13:46:32 2011t
431 for (; aItS.More(); aItS.Next()) {
432 const TopoDS_Shape& aE=aItS.Value();
433 if (myOrigins.IsBound(aE)) {
434 aEnew=myOrigins.Find(aE);
436 bToReverse=GEOMAlgo_Tools3D::IsSplitToReverse(aEnew, aE, myContext);
441 aBB.Add(aWnew, aEnew);
448 //modified by NIZNHY-PKV Tue May 10 13:46:19 2011f
449 //aWnew.Orientation(aW.Orientation());
450 //modified by NIZNHY-PKV Tue May 10 13:46:22 2011t
452 //myImages / myOrigins
453 TopTools_ListOfShape aLSD;
456 myImages.Bind(aWnew, aLSD);
457 myOrigins.Bind(aW, aWnew);
459 }//for (i=1; i<=aNbE; ++i) {
461 //=======================================================================
462 //function : FillCompounds
464 //=======================================================================
465 void GEOMAlgo_Gluer2::FillCompounds()
467 TopAbs_ShapeEnum aType;
468 TopoDS_Iterator aItC;
473 aItC.Initialize(myArgument);
474 for (; aItC.More(); aItC.Next()) {
475 const TopoDS_Shape& aCx=aItC.Value();
476 aType=aCx.ShapeType();
477 if (aType==TopAbs_COMPOUND) {
482 //=======================================================================
483 //function : FillCompound
485 //=======================================================================
486 void GEOMAlgo_Gluer2::FillCompound(const TopoDS_Shape& aC)
488 Standard_Boolean bHasImage;
489 TopAbs_ShapeEnum aType;
490 TopoDS_Shape aCnew, aCXnew;
491 TopoDS_Iterator aItC;
494 bHasImage=HasImage(aC);
499 GEOMAlgo_Tools3D::MakeContainer(TopAbs_COMPOUND, aCnew);
502 for (; aItC.More(); aItC.Next()) {
503 const TopoDS_Shape& aCX=aItC.Value();
504 aType=aCX.ShapeType();
506 if (aType==TopAbs_COMPOUND) {
510 if (myOrigins.IsBound(aCX)) {
511 aCXnew=myOrigins.Find(aCX);
512 aCXnew.Orientation(aCX.Orientation());
513 aBB.Add(aCnew, aCXnew);
520 //myImages / myOrigins
521 TopTools_ListOfShape aLSD;
524 myImages.Bind(aCnew, aLSD);
525 myOrigins.Bind(aC, aCnew);
527 //=======================================================================
528 //function : HasImage
530 //=======================================================================
531 Standard_Boolean GEOMAlgo_Gluer2::HasImage(const TopoDS_Shape& aC)
533 Standard_Boolean bRet;
534 TopAbs_ShapeEnum aType;
535 TopoDS_Iterator aItC;
539 for (; aItC.More(); aItC.Next()) {
540 const TopoDS_Shape& aCx=aItC.Value();
541 aType=aCx.ShapeType();
543 if (aType==TopAbs_COMPOUND) {
550 bRet=myOrigins.IsBound(aCx);
557 bRet=myOrigins.IsBound(aC);
561 //=======================================================================
562 //function : BuildResult
564 //=======================================================================
565 void GEOMAlgo_Gluer2::BuildResult()
567 Standard_Boolean bHasImage;
568 TopoDS_Shape aCnew, aCXnew;
569 TopoDS_Iterator aItC;
575 aItC.Initialize(myArgument);
576 for (; aItC.More(); aItC.Next()) {
577 const TopoDS_Shape& aCx=aItC.Value();
578 bHasImage=HasImage(aCx);
589 GEOMAlgo_Tools3D::MakeContainer(TopAbs_COMPOUND, aCnew);
591 aItC.Initialize(myArgument);
592 for (; aItC.More(); aItC.Next()) {
593 const TopoDS_Shape& aCX=aItC.Value();
594 if (myOrigins.IsBound(aCX)) {
595 aCXnew=myOrigins.Find(aCX);
596 aCXnew.Orientation(aCX.Orientation());
597 aBB.Add(aCnew, aCXnew);
604 if (!myKeepNonSolids) {
605 Standard_Integer i, aNb;
607 TopTools_IndexedMapOfShape aM;
609 GEOMAlgo_Tools3D::MakeContainer(TopAbs_COMPOUND, aCnew1);
611 TopExp::MapShapes(aCnew, TopAbs_SOLID, aM);
614 for (i=1; i<=aNb; ++i) {
615 const TopoDS_Shape& aS=aM(i);
623 //--------------------------------------------------------
626 // 11 - GEOMAlgo_GlueDetector failed
627 // 13 - PerformImagesToWork failed
628 // 14 - PerformImagesToWork failed
631 // 1 - no shapes to glue