Salome HOME
Typo-fix by Kunda
[modules/geom.git] / src / GEOMImpl / GEOMImpl_GlueDriver.cxx
index c0ace03080560e1a2fdc44b594686daba63267ab..d014f5503baa5cf5237d7d5a4a71f564f22ea7c4 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  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 "GEOMAlgo_CoupleOfShapes.hxx"
 #include "GEOMAlgo_ListOfCoupleOfShapes.hxx"
 
-#include <Basics_OCCTVersion.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>
@@ -120,7 +115,7 @@ TopoDS_Shape GEOMImpl_GlueDriver::GlueFacesWithWarnings (const TopoDS_Shape& the
       Standard_Failure::Raise(MSG_BAD_ARG_SHAPE);
       break;
     case 200:
-      Standard_Failure::Raise("Error occured during check of geometric coincidence");
+      Standard_Failure::Raise("Error occurred during check of geometric coincidence");
       break;
     default:
       {
@@ -239,7 +234,7 @@ TopoDS_Shape GEOMImpl_GlueDriver::GlueFaces (const TopoDS_Shape& theShape,
       Standard_Failure::Raise("Result shape is Null");
       break;
     case 200:
-      Standard_Failure::Raise("Error occured during check of geometric coincidence");
+      Standard_Failure::Raise("Error occurred during check of geometric coincidence");
       break;
     default:
       {
@@ -326,9 +321,11 @@ TopoDS_Shape GEOMImpl_GlueDriver::GlueFacesByList (const TopoDS_Shape& theShape,
 //function : GlueFaces
 //purpose  :
 //=======================================================================
-TopoDS_Shape GEOMImpl_GlueDriver::GlueFaces (const TopoDS_Shape& theShape,
-                                             const Standard_Real theTolerance,
-                                             const Standard_Boolean doKeepNonSolids)
+TopoDS_Shape GEOMImpl_GlueDriver::GlueFaces
+          (const TopoDS_Shape                       &theShape,
+           const Standard_Real                       theTolerance,
+           const Standard_Boolean                    doKeepNonSolids,
+                 TopTools_DataMapOfShapeListOfShape *pMapModif)
 {
   TopoDS_Shape aRes;
 
@@ -339,7 +336,7 @@ TopoDS_Shape GEOMImpl_GlueDriver::GlueFaces (const TopoDS_Shape& theShape,
   aGA.SetTolerance(theTolerance);
   aGA.SetKeepNonSolids(doKeepNonSolids);
 
-  // 2. Detect interferred shapes
+  // 2. Detect interfered shapes
   aGA.Detect();
 
   //Standard_Integer iWrnDetect = aGA.WarningStatus();
@@ -412,6 +409,26 @@ TopoDS_Shape GEOMImpl_GlueDriver::GlueFaces (const TopoDS_Shape& theShape,
   // 5. Result
   aRes = aGA.Shape();
 
+  if (pMapModif) {
+    // Fill the map of modified shapes.
+    TopTools_IndexedMapOfShape aMapSubShapes;
+
+    TopExp::MapShapes(theShape, aMapSubShapes);
+    pMapModif->Clear();
+
+    const Standard_Integer aNbShapes = aMapSubShapes.Extent();
+    Standard_Integer       i;
+
+    for (i = 1; i <= aNbShapes; ++i) {
+      const TopoDS_Shape         &aSubShape = aMapSubShapes.FindKey(i);
+      const TopTools_ListOfShape &aModif    = aGA.Modified(aSubShape);
+
+      if (!aModif.IsEmpty()) {
+        pMapModif->Bind(aSubShape, aModif);
+      }
+    }
+  }
+
   return aRes;
 }
 
@@ -423,8 +440,7 @@ TopoDS_Shape GEOMImpl_GlueDriver::GlueWithWarnings (const TopoDS_Shape& theShape
                                                     const Standard_Real theTolerance,
                                                     const TopAbs_ShapeEnum theShapeType,
                                                     const Standard_Boolean doKeepNonSolids,
-                                                    TCollection_AsciiString& theWarning,
-                                                    const TopTools_DataMapOfShapeShape& aCopyMap) const
+                                                    TCollection_AsciiString& theWarning) const
 {
   TopoDS_Shape aRes;
 
@@ -435,16 +451,14 @@ TopoDS_Shape GEOMImpl_GlueDriver::GlueWithWarnings (const TopoDS_Shape& theShape
   aGA.SetTolerance(theTolerance);
   aGA.SetKeepNonSolids(doKeepNonSolids);
 
-  // 2. Detect interferred shapes
+  // 2. Detect interfered shapes
   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();
@@ -554,18 +568,10 @@ TopoDS_Shape GEOMImpl_GlueDriver::GlueWithWarnings (const TopoDS_Shape& theShape
     TDF_Label anArgumentHistoryLabel =
       aFunction->GetArgumentHistoryEntry(anArgumentRefLabel, Standard_True);
 
-    TopTools_ListOfShape aModified;
     for (Standard_Integer ie = 1; ie <= nbArgumentEntities; ie++) {
       TopoDS_Shape anEntity = anArgumentIndices.FindKey(ie);
-      if (aCopyMap.IsBound(anEntity)) {
-        anEntity = aCopyMap.Find(anEntity);
-      }
-      aModified = aGA.Modified(anEntity);
+      const TopTools_ListOfShape& aModified = aGA.Modified(anEntity);
       Standard_Integer nbModified = aModified.Extent();
-      if (!nbModified && aResIndices.Contains(anEntity)) {
-        aModified.Append(anEntity);
-        nbModified = 1;
-      }
 
       if (nbModified > 0) {
         TDF_Label aWhatHistoryLabel = anArgumentHistoryLabel.FindChild(ie, Standard_True);
@@ -603,11 +609,10 @@ TopoDS_Shape GEOMImpl_GlueDriver::GlueByList (const TopoDS_Shape& theShape,
   aGA.SetTolerance(theTolerance);
   aGA.SetKeepNonSolids(doKeepNonSolids);
 
-  // 2. Detect interferred shapes
+  // 2. Detect interfered shapes
   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) {
     /*
@@ -633,7 +638,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();
@@ -733,7 +737,7 @@ TopoDS_Shape GEOMImpl_GlueDriver::GlueByList (const TopoDS_Shape& theShape,
 //function : Execute
 //purpose  :
 //=======================================================================
-Standard_Integer GEOMImpl_GlueDriver::Execute(TFunction_Logbook& log) const
+Standard_Integer GEOMImpl_GlueDriver::Execute(Handle(TFunction_Logbook)& log) const
 {
   if (Label().IsNull()) return 0;
   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
@@ -744,8 +748,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");
   }
@@ -754,35 +786,18 @@ 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);
-  //
-  // map sub-shapes
-  TopTools_IndexedMapOfShape aShapeBase_inds, aShapeCopy_inds;
-  TopTools_DataMapOfShapeShape aCopyMap;
-  Standard_Integer aNbInd, i;
-  //
-  TopExp::MapShapes(aShapeBase, aShapeBase_inds);
-  TopExp::MapShapes(aShapeCopy, aShapeCopy_inds);
-  //
-  aNbInd = aShapeBase_inds.Extent();
-  for (i = 1; i <= aNbInd; ++i) {
-    aCopyMap.Bind(aShapeBase_inds(i), aShapeCopy_inds(i));
-  }
-  //
   if (aType == GLUE_FACES) {
-    aShape = GlueWithWarnings(aShapeCopy, tol3d, TopAbs_FACE, aKeepNonSolids, aWrn, aCopyMap);
+    //aShape = GlueFacesWithWarnings(aShapeBase, tol3d, aKeepNonSolids, aWrn);
+    aShape = GlueWithWarnings(aShapeBase, tol3d, TopAbs_FACE, aKeepNonSolids, aWrn);
   }
   else if (aType == GLUE_EDGES) {
-    aShape = GlueWithWarnings(aShapeCopy, tol3d, TopAbs_EDGE, aKeepNonSolids, aWrn, aCopyMap);
+    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;
-
-    for (i = 1; i <= SF->Length(); i++) {
+    int i = 1;
+    for (; i <= SF->Length(); i++) {
       Handle(Standard_Transient) anItem = SF->Value(i);
       if (anItem.IsNull())
         continue;
@@ -792,14 +807,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;
@@ -807,14 +815,14 @@ 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;
 
   aFunction->SetValue(aShape);
 
-  log.SetTouched(Label());
+  log->SetTouched(Label());
 
   if (!aWrn.IsEmpty()) {
     Standard_Failure::Raise(aWrn.ToCString());
@@ -842,18 +850,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() );
@@ -861,7 +869,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;
@@ -872,5 +880,4 @@ GetCreationInformation(std::string&             theOperationName,
   return true;
 }
 
-IMPLEMENT_STANDARD_HANDLE (GEOMImpl_GlueDriver,GEOM_BaseDriver);
 IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_GlueDriver,GEOM_BaseDriver);