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 // Initialize the context
148 GEOMAlgo_GluerAlgo::Perform();
150 PerformShapesToWork();
154 if (myWarningStatus==1) {// no shapes to glue
209 BRepLib::SameParameter(myShape, myTolerance, Standard_True);
211 //=======================================================================
212 //function : CheckData
214 //=======================================================================
215 void GEOMAlgo_Gluer2::CheckData()
217 Standard_Integer aNbSG, i;
218 TopAbs_ShapeEnum aType, aTypeX;
219 TopTools_ListIteratorOfListOfShape aItLS;
220 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItDMSLS;
225 aNbSG=myShapesToGlue.Extent();
227 // Check myShapesToGlue
228 aItDMSLS.Initialize(myShapesToGlue);
229 for (; aItDMSLS.More(); aItDMSLS.Next()) {
230 //const TopoDS_Shape& aSkey=aItDMSLS.Key();
231 const TopTools_ListOfShape& aLSG=aItDMSLS.Value();
232 aItLS.Initialize(aLSG);
233 for (i=0; aItLS.More(); aItLS.Next(), ++i) {
234 const TopoDS_Shape& aSG=aItLS.Value();
235 aTypeX=aSG.ShapeType();
238 if (!(aType==TopAbs_VERTEX ||
239 aType==TopAbs_EDGE ||
240 aType==TopAbs_FACE)) {
241 myErrorStatus=21;// non-brep shapes
247 myErrorStatus=20;// non-homogeneous shapes
254 //=======================================================================
255 //function : FillEdges
257 //=======================================================================
258 void GEOMAlgo_Gluer2::FillEdges()
260 FillBRepShapes(TopAbs_EDGE);
262 //=======================================================================
263 //function : FillFaces
265 //=======================================================================
266 void GEOMAlgo_Gluer2::FillFaces()
268 FillBRepShapes(TopAbs_FACE);
270 //=======================================================================
271 //function : FillWires
273 //=======================================================================
274 void GEOMAlgo_Gluer2::FillWires()
276 FillContainers(TopAbs_WIRE);
278 //=======================================================================
279 //function : FillShells
281 //=======================================================================
282 void GEOMAlgo_Gluer2::FillShells()
284 FillContainers(TopAbs_SHELL);
286 //=======================================================================
287 //function : FillSolids
289 //=======================================================================
290 void GEOMAlgo_Gluer2::FillSolids()
292 FillContainers(TopAbs_SOLID);
294 //=======================================================================
295 //function : FillCompSolids
297 //=======================================================================
298 void GEOMAlgo_Gluer2::FillCompSolids()
300 FillContainers(TopAbs_COMPSOLID);
302 //=======================================================================
303 //function : FillVertices
305 //=======================================================================
306 void GEOMAlgo_Gluer2::FillVertices()
308 TopAbs_ShapeEnum aType;
310 TopTools_ListIteratorOfListOfShape aItLS;
311 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItDMSLS;
316 aItDMSLS.Initialize(myImagesToWork);
317 for (; aItDMSLS.More(); aItDMSLS.Next()) {
318 const TopoDS_Shape& aSkey=aItDMSLS.Key();
319 aType=aSkey.ShapeType();
320 if (aType!=TopAbs_VERTEX) {
324 const TopTools_ListOfShape& aLSD=aItDMSLS.Value();
326 GEOMAlgo_Gluer2::MakeVertex(aLSD, aVnew);
328 myImages.Bind(aVnew, aLSD);
330 aItLS.Initialize(aLSD);
331 for (; aItLS.More(); aItLS.Next()) {
332 const TopoDS_Shape& aV=aItLS.Value();
333 myOrigins.Bind(aV, aVnew);
337 //=======================================================================
338 //function : FillBRepShapes
340 //=======================================================================
341 void GEOMAlgo_Gluer2::FillBRepShapes(const TopAbs_ShapeEnum theType)
343 Standard_Boolean bHasImage, bIsToWork;
344 Standard_Integer i, aNbE;
345 TopoDS_Iterator aItS;
347 TopTools_IndexedMapOfShape aME;
348 TopTools_MapOfShape aMFence;
349 TopTools_ListIteratorOfListOfShape aItLS;
354 TopExp::MapShapes(myArgument, theType, aME);
357 for (i=1; i<=aNbE; ++i) {
358 const TopoDS_Shape& aE=aME(i);
360 if (!aMFence.Add(aE)) {
364 bIsToWork=myOriginsToWork.IsBound(aE);
365 bHasImage=HasImage(aE);
366 if (!bHasImage && !bIsToWork) {
370 MakeBRepShapes(aE, aEnew);
372 //myImages / myOrigins
374 const TopoDS_Shape& aSkey=myOriginsToWork.Find(aE);
375 const TopTools_ListOfShape& aLSD=myImagesToWork.Find(aSkey);
377 myImages.Bind(aEnew, aLSD);
379 aItLS.Initialize(aLSD);
380 for (; aItLS.More(); aItLS.Next()) {
381 const TopoDS_Shape& aEx=aItLS.Value();
382 myOrigins.Bind(aEx, aEnew);
388 TopTools_ListOfShape aLSD;
391 myImages.Bind(aEnew, aLSD);
392 myOrigins.Bind(aE, aEnew);
394 }//for (i=1; i<=aNbF; ++i) {
396 //=======================================================================
397 //function : FillContainers
399 //=======================================================================
400 void GEOMAlgo_Gluer2::FillContainers(const TopAbs_ShapeEnum aType)
402 Standard_Boolean bHasImage, bToReverse;
403 Standard_Integer i, aNbW;
404 TopoDS_Shape aWnew, aEnew;
405 TopoDS_Iterator aItS;
407 TopTools_IndexedMapOfShape aMW;
408 TopTools_MapOfShape aMFence;
413 TopExp::MapShapes(myArgument, aType, aMW);
416 for (i=1; i<=aNbW; ++i) {
417 const TopoDS_Shape& aW=aMW(i);
419 if (!aMFence.Add(aW)) {
423 bHasImage=HasImage(aW);
428 GEOMAlgo_Tools3D::MakeContainer(aType, aWnew);
429 //modified by NIZNHY-PKV Tue May 10 13:46:30 2011f
430 aWnew.Orientation(aW.Orientation());
431 //modified by NIZNHY-PKV Tue May 10 13:46:32 2011t
434 for (; aItS.More(); aItS.Next()) {
435 const TopoDS_Shape& aE=aItS.Value();
436 if (myOrigins.IsBound(aE)) {
437 aEnew=myOrigins.Find(aE);
439 bToReverse=GEOMAlgo_Tools3D::IsSplitToReverse(aEnew, aE, myContext);
444 aBB.Add(aWnew, aEnew);
451 //modified by NIZNHY-PKV Tue May 10 13:46:19 2011f
452 //aWnew.Orientation(aW.Orientation());
453 //modified by NIZNHY-PKV Tue May 10 13:46:22 2011t
455 //myImages / myOrigins
456 TopTools_ListOfShape aLSD;
459 myImages.Bind(aWnew, aLSD);
460 myOrigins.Bind(aW, aWnew);
462 }//for (i=1; i<=aNbE; ++i) {
464 //=======================================================================
465 //function : FillCompounds
467 //=======================================================================
468 void GEOMAlgo_Gluer2::FillCompounds()
470 TopAbs_ShapeEnum aType;
471 TopoDS_Iterator aItC;
476 aItC.Initialize(myArgument);
477 for (; aItC.More(); aItC.Next()) {
478 const TopoDS_Shape& aCx=aItC.Value();
479 aType=aCx.ShapeType();
480 if (aType==TopAbs_COMPOUND) {
485 //=======================================================================
486 //function : FillCompound
488 //=======================================================================
489 void GEOMAlgo_Gluer2::FillCompound(const TopoDS_Shape& aC)
491 Standard_Boolean bHasImage;
492 TopAbs_ShapeEnum aType;
493 TopoDS_Shape aCnew, aCXnew;
494 TopoDS_Iterator aItC;
497 bHasImage=HasImage(aC);
502 GEOMAlgo_Tools3D::MakeContainer(TopAbs_COMPOUND, aCnew);
505 for (; aItC.More(); aItC.Next()) {
506 const TopoDS_Shape& aCX=aItC.Value();
507 aType=aCX.ShapeType();
509 if (aType==TopAbs_COMPOUND) {
513 if (myOrigins.IsBound(aCX)) {
514 aCXnew=myOrigins.Find(aCX);
515 aCXnew.Orientation(aCX.Orientation());
516 aBB.Add(aCnew, aCXnew);
523 //myImages / myOrigins
524 TopTools_ListOfShape aLSD;
527 myImages.Bind(aCnew, aLSD);
528 myOrigins.Bind(aC, aCnew);
530 //=======================================================================
531 //function : HasImage
533 //=======================================================================
534 Standard_Boolean GEOMAlgo_Gluer2::HasImage(const TopoDS_Shape& aC)
536 Standard_Boolean bRet;
537 TopAbs_ShapeEnum aType;
538 TopoDS_Iterator aItC;
542 for (; aItC.More(); aItC.Next()) {
543 const TopoDS_Shape& aCx=aItC.Value();
544 aType=aCx.ShapeType();
546 if (aType==TopAbs_COMPOUND) {
553 bRet=myOrigins.IsBound(aCx);
560 bRet=myOrigins.IsBound(aC);
564 //=======================================================================
565 //function : BuildResult
567 //=======================================================================
568 void GEOMAlgo_Gluer2::BuildResult()
570 Standard_Boolean bHasImage;
571 TopoDS_Shape aCnew, aCXnew;
572 TopoDS_Iterator aItC;
578 aItC.Initialize(myArgument);
579 for (; aItC.More(); aItC.Next()) {
580 const TopoDS_Shape& aCx=aItC.Value();
581 bHasImage=HasImage(aCx);
592 GEOMAlgo_Tools3D::MakeContainer(TopAbs_COMPOUND, aCnew);
594 aItC.Initialize(myArgument);
595 for (; aItC.More(); aItC.Next()) {
596 const TopoDS_Shape& aCX=aItC.Value();
597 if (myOrigins.IsBound(aCX)) {
598 aCXnew=myOrigins.Find(aCX);
599 aCXnew.Orientation(aCX.Orientation());
600 aBB.Add(aCnew, aCXnew);
607 if (!myKeepNonSolids) {
608 Standard_Integer i, aNb;
610 TopTools_IndexedMapOfShape aM;
612 GEOMAlgo_Tools3D::MakeContainer(TopAbs_COMPOUND, aCnew1);
614 TopExp::MapShapes(aCnew, TopAbs_SOLID, aM);
617 for (i=1; i<=aNb; ++i) {
618 const TopoDS_Shape& aS=aM(i);
626 //--------------------------------------------------------
629 // 11 - GEOMAlgo_GlueDetector failed
630 // 13 - PerformImagesToWork failed
631 // 14 - PerformImagesToWork failed
634 // 1 - no shapes to glue