Salome HOME
0022746: [EDF] Improvement of Glue Faces and Glue Edges operations
[modules/geom.git] / src / GEOMImpl / GEOMImpl_GlueDriver.cxx
index 2571347c5d2eb3904ecc775af02c29046bff072e..4b3dfba96fa486ed5fb90e6d74d3f9d8ffea2253 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -6,7 +6,7 @@
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -18,6 +18,7 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
 
 #include <Standard_Stream.hxx>
 
 
 #include "utilities.h"
 
+#include <BRep_Builder.hxx>
+#include <ShapeFix_Shape.hxx>
 #include <TDataStd_IntegerArray.hxx>
-#include <TNaming_CopyShape.hxx>
-
 #include <TopExp.hxx>
-#include <TopoDS_Shape.hxx>
 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
 #include <TopTools_IndexedMapOfShape.hxx>
-#include <TopTools_ListOfShape.hxx>
 #include <TopTools_ListIteratorOfListOfShape.hxx>
-
-#include <TColStd_IndexedDataMapOfTransientTransient.hxx>
-
-#include <ShapeFix_Shape.hxx>
+#include <TopTools_ListOfShape.hxx>
+#include <TopoDS_Shape.hxx>
 
 #include <Standard_NullObject.hxx>
 #include <Standard_Failure.hxx>
@@ -438,12 +435,10 @@ TopoDS_Shape GEOMImpl_GlueDriver::GlueWithWarnings (const TopoDS_Shape& theShape
   aGA.Detect();
 
   //modified by NIZNHY-PKV Tue Mar 13 14:07:12 2012f
-#if OCC_VERSION_LARGE > 0x06050200
   Standard_Integer iWrnDetect = aGA.WarningStatus();
   if (iWrnDetect == 2) {
     Standard_Failure::Raise("GLUE_ERROR_STICKED_SHAPES");
   }
-#endif
   //modified by NIZNHY-PKV Tue Mar 13 14:07:14 2012t
 
   Standard_Integer iErr = aGA.ErrorStatus();
@@ -598,7 +593,6 @@ TopoDS_Shape GEOMImpl_GlueDriver::GlueByList (const TopoDS_Shape& theShape,
   aGA.Detect();
 
   //modified by NIZNHY-PKV Tue Mar 13 14:07:12 2012f
-#if OCC_VERSION_LARGE > 0x06050200
   Standard_Integer iWrnDetect = aGA.WarningStatus();
   if (iWrnDetect == 2) {
     /*
@@ -624,7 +618,6 @@ TopoDS_Shape GEOMImpl_GlueDriver::GlueByList (const TopoDS_Shape& theShape,
     */
     Standard_Failure::Raise("GLUE_ERROR_STICKED_SHAPES");
   }
-#endif
   //modified by NIZNHY-PKV Tue Mar 13 14:07:14 2012t
 
   Standard_Integer iErr = aGA.ErrorStatus();
@@ -735,8 +728,36 @@ Standard_Integer GEOMImpl_GlueDriver::Execute(TFunction_Logbook& log) const
   TopoDS_Shape aShape;
   TCollection_AsciiString aWrn;
 
-  Handle(GEOM_Function) aRefBase = aCI.GetBase();
-  TopoDS_Shape aShapeBase = aRefBase->GetValue();
+  TopoDS_Shape aShapeBase;
+  Handle(TColStd_HSequenceOfTransient) aRefBases = aCI.GetBase();
+  if ( aRefBases && !aRefBases->IsEmpty() )
+  {
+    if ( aRefBases->Length() == 1 )
+    {
+      Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aRefBases->Value(1));
+      if ( !aRefShape.IsNull() )
+        aShapeBase = aRefShape->GetValue();
+    }
+    else
+    {
+      TopoDS_Compound compound;
+      BRep_Builder builder;
+      builder.MakeCompound( compound );
+      int ind = 1;
+      for ( ; ind <= aRefBases->Length(); ind++)
+      {
+        Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aRefBases->Value(ind));
+        if ( aRefShape.IsNull() ) break;
+        TopoDS_Shape aShape = aRefShape->GetValue();
+        if (aShape.IsNull()) break;
+        builder.Add( compound, aShape );
+      }
+      if ( ind > aRefBases->Length() )
+        aShapeBase = compound;
+      else
+        aShapeBase.Nullify();
+    }
+  }
   if (aShapeBase.IsNull()) {
     Standard_NullObject::Raise("Shape for gluing is null");
   }
@@ -745,29 +766,17 @@ Standard_Integer GEOMImpl_GlueDriver::Execute(TFunction_Logbook& log) const
 
   Standard_Boolean aKeepNonSolids = aCI.GetKeepNonSolids();
 
-  // Copy initial shape to prevent its modification by gluing algorithm
-  TopoDS_Shape aShapeCopy;
-  TColStd_IndexedDataMapOfTransientTransient aMapTShapes;
-  TNaming_CopyShape::CopyTool(aShapeBase, aMapTShapes, aShapeCopy);
-
   if (aType == GLUE_FACES) {
     //aShape = GlueFacesWithWarnings(aShapeBase, tol3d, aKeepNonSolids, aWrn);
-    aShape = GlueWithWarnings(aShapeCopy, tol3d, TopAbs_FACE, aKeepNonSolids, aWrn);
+    aShape = GlueWithWarnings(aShapeBase, tol3d, TopAbs_FACE, aKeepNonSolids, aWrn);
   }
   else if (aType == GLUE_EDGES) {
-    aShape = GlueWithWarnings(aShapeCopy, tol3d, TopAbs_EDGE, aKeepNonSolids, aWrn);
+    aShape = GlueWithWarnings(aShapeBase, tol3d, TopAbs_EDGE, aKeepNonSolids, aWrn);
   }
   else if (aType == GLUE_FACES_BY_LIST || aType == GLUE_EDGES_BY_LIST) {
     Handle(TColStd_HSequenceOfTransient) SF = aCI.GetFaces();
     TopTools_MapOfShape aFaces;
     int i = 1;
-
-    // map sub-shapes to select faces from aShapeCopy
-    TopTools_IndexedMapOfShape aShapeBase_inds;
-    TopTools_IndexedMapOfShape aShapeCopy_inds;
-    TopExp::MapShapes(aShapeBase, aShapeBase_inds);
-    TopExp::MapShapes(aShapeCopy, aShapeCopy_inds);
-
     for (; i <= SF->Length(); i++) {
       Handle(Standard_Transient) anItem = SF->Value(i);
       if (anItem.IsNull())
@@ -778,14 +787,7 @@ Standard_Integer GEOMImpl_GlueDriver::Execute(TFunction_Logbook& log) const
       TopoDS_Shape aFace = aRefSh->GetValue();
       if (aFace.IsNull())
         continue;
-
-      // get copy of face to correspond to aShapeCopy
-      if (aShapeBase_inds.Contains(aFace)) {
-        int ind = aShapeBase_inds.FindIndex(aFace);
-        aFace = aShapeCopy_inds.FindKey(ind);
-
-        aFaces.Add(aFace);
-      }
+      aFaces.Add(aFace);
     }
 
     Standard_Boolean aGlueAllEdges = Standard_False;
@@ -793,7 +795,7 @@ Standard_Integer GEOMImpl_GlueDriver::Execute(TFunction_Logbook& log) const
       aGlueAllEdges = aCI.GetGlueAllEdges();
 
     //aShape = GlueFacesByList(aShapeBase, tol3d, aKeepNonSolids, aFaces);
-    aShape = GlueByList(aShapeCopy, tol3d, aKeepNonSolids, aFaces, aGlueAllEdges);
+    aShape = GlueByList(aShapeBase, tol3d, aKeepNonSolids, aFaces, aGlueAllEdges);
   }
 
   if (aShape.IsNull()) return 0;
@@ -828,18 +830,18 @@ GetCreationInformation(std::string&             theOperationName,
   switch ( aType ) {
   case GLUE_FACES:
     theOperationName = "GLUE_FACES";
-    AddParam( theParams, "Selected shape", aCI.GetBase() );
+    AddParam( theParams, "Selected shapes", aCI.GetBase() );
     AddParam( theParams, "Tolerance", aCI.GetTolerance() );
     AddParam( theParams, "To keep non solids", aCI.GetKeepNonSolids() );
     break;
   case GLUE_EDGES:
     theOperationName = "GLUE_EDGES";
-    AddParam( theParams, "Selected shape", aCI.GetBase() );
+    AddParam( theParams, "Selected shapes", aCI.GetBase() );
     AddParam( theParams, "Tolerance", aCI.GetTolerance() );
     break;
   case GLUE_FACES_BY_LIST:
     theOperationName = "GLUE_FACES";
-    AddParam( theParams, "Selected shape", aCI.GetBase() );
+    AddParam( theParams, "Selected shapes", aCI.GetBase() );
     AddParam( theParams, "Tolerance", aCI.GetTolerance() );
     AddParam( theParams, "Faces", aCI.GetFaces() );
     AddParam( theParams, "To keep non solids", aCI.GetKeepNonSolids() );
@@ -847,7 +849,7 @@ GetCreationInformation(std::string&             theOperationName,
     break;
   case GLUE_EDGES_BY_LIST:
     theOperationName = "GLUE_EDGES";
-    AddParam( theParams, "Selected shape", aCI.GetBase() );
+    AddParam( theParams, "Selected shapes", aCI.GetBase() );
     AddParam( theParams, "Tolerance", aCI.GetTolerance() );
     AddParam( theParams, "Edges", aCI.GetFaces() );
     break;