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
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;
86 //=======================================================================
87 //function : SetShapesToGlue
89 //=======================================================================
90 void GEOMAlgo_Gluer2::SetShapesToGlue(const TopTools_DataMapOfShapeListOfShape& aM)
94 //=======================================================================
95 //function : ShapesToGlue
97 //=======================================================================
98 const TopTools_DataMapOfShapeListOfShape& GEOMAlgo_Gluer2::ShapesToGlue()const
100 return myShapesToGlue;
102 //=======================================================================
103 //function : SetKeepNonSolids
105 //=======================================================================
106 void GEOMAlgo_Gluer2::SetKeepNonSolids(const Standard_Boolean aFlag)
108 myKeepNonSolids=aFlag;
110 //=======================================================================
111 //function : KeepNonSolids
113 //=======================================================================
114 Standard_Boolean GEOMAlgo_Gluer2::KeepNonSolids()const
116 return myKeepNonSolids;
118 //=======================================================================
119 //function : ShapesDetected
121 //=======================================================================
122 const TopTools_DataMapOfShapeListOfShape& GEOMAlgo_Gluer2::ShapesDetected()const
124 return myImagesDetected;
126 //=======================================================================
127 //function : ImagesToWork
129 //=======================================================================
130 const TopTools_DataMapOfShapeListOfShape& GEOMAlgo_Gluer2::ImagesToWork()const
132 return myImagesToWork;
134 //=======================================================================
137 //=======================================================================
138 void GEOMAlgo_Gluer2::Perform()
148 PerformShapesToWork();
152 if (myWarningStatus==1) {// no shapes to glue
207 BRepLib::SameParameter(myShape, myTolerance, Standard_True);
209 //=======================================================================
210 //function : CheckData
212 //=======================================================================
213 void GEOMAlgo_Gluer2::CheckData()
215 Standard_Integer aNbSG, i;
216 TopAbs_ShapeEnum aType, aTypeX;
217 TopTools_ListIteratorOfListOfShape aItLS;
218 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItDMSLS;
223 aNbSG=myShapesToGlue.Extent();
225 // Check myShapesToGlue
226 aItDMSLS.Initialize(myShapesToGlue);
227 for (; aItDMSLS.More(); aItDMSLS.Next()) {
228 //const TopoDS_Shape& aSkey=aItDMSLS.Key();
229 const TopTools_ListOfShape& aLSG=aItDMSLS.Value();
230 aItLS.Initialize(aLSG);
231 for (i=0; aItLS.More(); aItLS.Next(), ++i) {
232 const TopoDS_Shape& aSG=aItLS.Value();
233 aTypeX=aSG.ShapeType();
236 if (!(aType==TopAbs_VERTEX ||
237 aType==TopAbs_EDGE ||
238 aType==TopAbs_FACE)) {
239 myErrorStatus=21;// non-brep shapes
245 myErrorStatus=20;// non-homogeneous shapes
252 //=======================================================================
253 //function : FillEdges
255 //=======================================================================
256 void GEOMAlgo_Gluer2::FillEdges()
258 FillBRepShapes(TopAbs_EDGE);
260 //=======================================================================
261 //function : FillFaces
263 //=======================================================================
264 void GEOMAlgo_Gluer2::FillFaces()
266 FillBRepShapes(TopAbs_FACE);
268 //=======================================================================
269 //function : FillWires
271 //=======================================================================
272 void GEOMAlgo_Gluer2::FillWires()
274 FillContainers(TopAbs_WIRE);
276 //=======================================================================
277 //function : FillShells
279 //=======================================================================
280 void GEOMAlgo_Gluer2::FillShells()
282 FillContainers(TopAbs_SHELL);
284 //=======================================================================
285 //function : FillSolids
287 //=======================================================================
288 void GEOMAlgo_Gluer2::FillSolids()
290 FillContainers(TopAbs_SOLID);
292 //=======================================================================
293 //function : FillCompSolids
295 //=======================================================================
296 void GEOMAlgo_Gluer2::FillCompSolids()
298 FillContainers(TopAbs_COMPSOLID);
300 //=======================================================================
301 //function : FillVertices
303 //=======================================================================
304 void GEOMAlgo_Gluer2::FillVertices()
306 TopAbs_ShapeEnum aType;
308 TopTools_ListIteratorOfListOfShape aItLS;
309 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItDMSLS;
314 aItDMSLS.Initialize(myImagesToWork);
315 for (; aItDMSLS.More(); aItDMSLS.Next()) {
316 const TopoDS_Shape& aSkey=aItDMSLS.Key();
317 aType=aSkey.ShapeType();
318 if (aType!=TopAbs_VERTEX) {
322 const TopTools_ListOfShape& aLSD=aItDMSLS.Value();
324 GEOMAlgo_Gluer2::MakeVertex(aLSD, aVnew);
326 myImages.Bind(aVnew, aLSD);
328 aItLS.Initialize(aLSD);
329 for (; aItLS.More(); aItLS.Next()) {
330 const TopoDS_Shape& aV=aItLS.Value();
331 myOrigins.Bind(aV, aVnew);
335 //=======================================================================
336 //function : FillBRepShapes
338 //=======================================================================
339 void GEOMAlgo_Gluer2::FillBRepShapes(const TopAbs_ShapeEnum theType)
341 Standard_Boolean bHasImage, bIsToWork;
342 Standard_Integer i, aNbE;
343 TopoDS_Iterator aItS;
345 TopTools_IndexedMapOfShape aME;
346 TopTools_MapOfShape aMFence;
347 TopTools_ListIteratorOfListOfShape aItLS;
352 TopExp::MapShapes(myArgument, theType, aME);
355 for (i=1; i<=aNbE; ++i) {
356 const TopoDS_Shape& aE=aME(i);
358 if (!aMFence.Add(aE)) {
362 bIsToWork=myOriginsToWork.IsBound(aE);
363 bHasImage=HasImage(aE);
364 if (!bHasImage && !bIsToWork) {
368 MakeBRepShapes(aE, aEnew);
370 //myImages / myOrigins
372 const TopoDS_Shape& aSkey=myOriginsToWork.Find(aE);
373 const TopTools_ListOfShape& aLSD=myImagesToWork.Find(aSkey);
375 myImages.Bind(aEnew, aLSD);
377 aItLS.Initialize(aLSD);
378 for (; aItLS.More(); aItLS.Next()) {
379 const TopoDS_Shape& aEx=aItLS.Value();
380 myOrigins.Bind(aEx, aEnew);
386 TopTools_ListOfShape aLSD;
389 myImages.Bind(aEnew, aLSD);
390 myOrigins.Bind(aE, aEnew);
392 }//for (i=1; i<=aNbF; ++i) {
394 //=======================================================================
395 //function : FillContainers
397 //=======================================================================
398 void GEOMAlgo_Gluer2::FillContainers(const TopAbs_ShapeEnum aType)
400 Standard_Boolean bHasImage, bToReverse;
401 Standard_Integer i, aNbW;
402 TopoDS_Shape aWnew, aEnew;
403 TopoDS_Iterator aItS;
405 TopTools_IndexedMapOfShape aMW;
406 TopTools_MapOfShape aMFence;
411 TopExp::MapShapes(myArgument, aType, aMW);
414 for (i=1; i<=aNbW; ++i) {
415 const TopoDS_Shape& aW=aMW(i);
417 if (!aMFence.Add(aW)) {
421 bHasImage=HasImage(aW);
426 GEOMAlgo_Tools3D::MakeContainer(aType, aWnew);
427 //modified by NIZNHY-PKV Tue May 10 13:46:30 2011f
428 aWnew.Orientation(aW.Orientation());
429 //modified by NIZNHY-PKV Tue May 10 13:46:32 2011t
432 for (; aItS.More(); aItS.Next()) {
433 const TopoDS_Shape& aE=aItS.Value();
434 if (myOrigins.IsBound(aE)) {
435 aEnew=myOrigins.Find(aE);
437 bToReverse=GEOMAlgo_Tools3D::IsSplitToReverse(aEnew, aE, myContext);
442 aBB.Add(aWnew, aEnew);
449 //modified by NIZNHY-PKV Tue May 10 13:46:19 2011f
450 //aWnew.Orientation(aW.Orientation());
451 //modified by NIZNHY-PKV Tue May 10 13:46:22 2011t
453 //myImages / myOrigins
454 TopTools_ListOfShape aLSD;
457 myImages.Bind(aWnew, aLSD);
458 myOrigins.Bind(aW, aWnew);
460 }//for (i=1; i<=aNbE; ++i) {
462 //=======================================================================
463 //function : FillCompounds
465 //=======================================================================
466 void GEOMAlgo_Gluer2::FillCompounds()
468 TopAbs_ShapeEnum aType;
469 TopoDS_Iterator aItC;
474 aItC.Initialize(myArgument);
475 for (; aItC.More(); aItC.Next()) {
476 const TopoDS_Shape& aCx=aItC.Value();
477 aType=aCx.ShapeType();
478 if (aType==TopAbs_COMPOUND) {
483 //=======================================================================
484 //function : FillCompound
486 //=======================================================================
487 void GEOMAlgo_Gluer2::FillCompound(const TopoDS_Shape& aC)
489 Standard_Boolean bHasImage;
490 TopAbs_ShapeEnum aType;
491 TopoDS_Shape aCnew, aCXnew;
492 TopoDS_Iterator aItC;
495 bHasImage=HasImage(aC);
500 GEOMAlgo_Tools3D::MakeContainer(TopAbs_COMPOUND, aCnew);
503 for (; aItC.More(); aItC.Next()) {
504 const TopoDS_Shape& aCX=aItC.Value();
505 aType=aCX.ShapeType();
507 if (aType==TopAbs_COMPOUND) {
511 if (myOrigins.IsBound(aCX)) {
512 aCXnew=myOrigins.Find(aCX);
513 aCXnew.Orientation(aCX.Orientation());
514 aBB.Add(aCnew, aCXnew);
521 //myImages / myOrigins
522 TopTools_ListOfShape aLSD;
525 myImages.Bind(aCnew, aLSD);
526 myOrigins.Bind(aC, aCnew);
528 //=======================================================================
529 //function : HasImage
531 //=======================================================================
532 Standard_Boolean GEOMAlgo_Gluer2::HasImage(const TopoDS_Shape& aC)
534 Standard_Boolean bRet;
535 TopAbs_ShapeEnum aType;
536 TopoDS_Iterator aItC;
540 for (; aItC.More(); aItC.Next()) {
541 const TopoDS_Shape& aCx=aItC.Value();
542 aType=aCx.ShapeType();
544 if (aType==TopAbs_COMPOUND) {
551 bRet=myOrigins.IsBound(aCx);
558 bRet=myOrigins.IsBound(aC);
562 //=======================================================================
563 //function : BuildResult
565 //=======================================================================
566 void GEOMAlgo_Gluer2::BuildResult()
568 Standard_Boolean bHasImage;
569 TopoDS_Shape aCnew, aCXnew;
570 TopoDS_Iterator aItC;
576 aItC.Initialize(myArgument);
577 for (; aItC.More(); aItC.Next()) {
578 const TopoDS_Shape& aCx=aItC.Value();
579 bHasImage=HasImage(aCx);
590 GEOMAlgo_Tools3D::MakeContainer(TopAbs_COMPOUND, aCnew);
592 aItC.Initialize(myArgument);
593 for (; aItC.More(); aItC.Next()) {
594 const TopoDS_Shape& aCX=aItC.Value();
595 if (myOrigins.IsBound(aCX)) {
596 aCXnew=myOrigins.Find(aCX);
597 aCXnew.Orientation(aCX.Orientation());
598 aBB.Add(aCnew, aCXnew);
605 if (!myKeepNonSolids) {
606 Standard_Integer i, aNb;
608 TopTools_IndexedMapOfShape aM;
610 GEOMAlgo_Tools3D::MakeContainer(TopAbs_COMPOUND, aCnew1);
612 TopExp::MapShapes(aCnew, TopAbs_SOLID, aM);
615 for (i=1; i<=aNb; ++i) {
616 const TopoDS_Shape& aS=aM(i);
624 //--------------------------------------------------------
627 // 11 - GEOMAlgo_GlueDetector failed
628 // 13 - PerformImagesToWork failed
629 // 14 - PerformImagesToWork failed
632 // 1 - no shapes to glue