Salome HOME
Fix for bug 0019870(Import/Export should show current directory).
[modules/geom.git] / src / GEOMImpl / GEOMImpl_GlueDriver.cxx
index 0c08d662797410e9111ff96e4f4f20b43b449fcf..ec18620ffdb16e1d45b213e626408cfc37312d28 100644 (file)
@@ -1,13 +1,37 @@
-
-using namespace std;
-#include "GEOMImpl_GlueDriver.hxx"
-#include "GEOMImpl_IGlue.hxx"
-#include "GEOMImpl_Types.hxx"
-
-#include "GEOM_Object.hxx"
-#include "GEOM_Function.hxx"
-
-#include "GEOMAlgo_Gluer.hxx"
+// Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// 
+// 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.
+// 
+// This library is distributed in the hope that it will be useful 
+// but WITHOUT ANY WARRANTY; without even the implied warranty of 
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public  
+// License along with this library; if not, write to the Free Software 
+// 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 <GEOMImpl_GlueDriver.hxx>
+#include <GEOMImpl_IGlue.hxx>
+#include <GEOMImpl_Types.hxx>
+
+#include <GEOM_Object.hxx>
+#include <GEOM_Function.hxx>
+
+#include <GEOMAlgo_Gluer.hxx>
+#include "GEOMAlgo_Gluer1.hxx"
+#include "GEOMAlgo_ListIteratorOfListOfCoupleOfShapes.hxx"
+#include "GEOMAlgo_CoupleOfShapes.hxx"
+#include "GEOMAlgo_ListOfCoupleOfShapes.hxx"
 
 #include "utilities.h"
 
@@ -49,6 +73,7 @@ const Standard_GUID& GEOMImpl_GlueDriver::GetID()
 //=======================================================================
 TopoDS_Shape GEOMImpl_GlueDriver::GlueFacesWithWarnings (const TopoDS_Shape& theShape,
                                                          const Standard_Real theTolerance,
+                                                         const Standard_Boolean doKeepNonSolids,
                                                          TCollection_AsciiString& theWarning) const
 {
   Standard_Integer iErr, iWrn;
@@ -58,6 +83,7 @@ TopoDS_Shape GEOMImpl_GlueDriver::GlueFacesWithWarnings (const TopoDS_Shape& the
   aGluer.SetShape(theShape);
   aGluer.SetTolerance(theTolerance);
   aGluer.SetCheckGeometry(Standard_True);
+  aGluer.SetKeepNonSolids(doKeepNonSolids);
 
   aGluer.Perform();
 
@@ -167,12 +193,14 @@ TopoDS_Shape GEOMImpl_GlueDriver::GlueFacesWithWarnings (const TopoDS_Shape& the
   return aRes;
 }
 
+
 //=======================================================================
 //function : GlueFaces
 //purpose  :
 //=======================================================================
 TopoDS_Shape GEOMImpl_GlueDriver::GlueFaces (const TopoDS_Shape& theShape,
-                                             const Standard_Real theTolerance)
+                                             const Standard_Real theTolerance,
+                                             const Standard_Boolean doKeepNonSolids)
 {
   Standard_Integer iErr, iWrn;
   TopoDS_Shape aRes;
@@ -181,6 +209,7 @@ TopoDS_Shape GEOMImpl_GlueDriver::GlueFaces (const TopoDS_Shape& theShape,
   aGluer.SetShape(theShape);
   aGluer.SetTolerance(theTolerance);
   aGluer.SetCheckGeometry(Standard_True);
+  aGluer.SetKeepNonSolids(doKeepNonSolids);
 
   aGluer.Perform();
 
@@ -229,6 +258,58 @@ TopoDS_Shape GEOMImpl_GlueDriver::GlueFaces (const TopoDS_Shape& theShape,
   return aRes;
 }
 
+
+//=======================================================================
+//function : GlueFacesByList
+//purpose  :
+//=======================================================================
+TopoDS_Shape GEOMImpl_GlueDriver::GlueFacesByList (const TopoDS_Shape& theShape,
+                                                  const Standard_Real theTolerance,
+                                                   const Standard_Boolean doKeepNonSolids,
+                                                  const TopTools_MapOfShape& aFaces)
+{
+  TopoDS_Shape aRes;
+
+  GEOMAlgo_Gluer1 aGluer;
+  GEOMAlgo_ListIteratorOfListOfCoupleOfShapes aItCS;
+  GEOMAlgo_CoupleOfShapes aCS;
+  GEOMAlgo_ListOfCoupleOfShapes aLCS;
+
+  aGluer.SetShape(theShape);
+  aGluer.SetTolerance(theTolerance);
+  aGluer.SetKeepNonSolids(doKeepNonSolids);
+  aGluer.Perform();
+  Standard_Integer iErr = aGluer.ErrorStatus();
+  if (iErr) return aRes;
+
+  TopTools_ListOfShape listShape;
+  const GEOMAlgo_ListOfCoupleOfShapes& aLCSG = aGluer.GluedFaces();
+  // Access to faces
+  aItCS.Initialize(aLCSG);
+  for (; aItCS.More(); aItCS.Next()) {
+    const GEOMAlgo_CoupleOfShapes& aCSG = aItCS.Value();
+    const TopoDS_Shape& aF1 = aCSG.Shape1();
+    const TopoDS_Shape& aF2 = aCSG.Shape2();
+    if( aFaces.Contains(aF1) || aFaces.Contains(aF2) )
+      continue;
+    aCS.SetShapes(aF1,aF2);
+    aLCS.Append(aCS);
+  }
+
+  //cout<<"aLCS.Extent() = "<<aLCS.Extent()<<endl;
+  if(aLCS.Extent()>0) {
+    aGluer.SetFacesToUnglue(aLCS);
+    aGluer.UnglueFaces();
+    iErr = aGluer.ErrorStatus();
+    if (iErr) return aRes;
+  }
+
+  aRes = aGluer.Result();
+
+  return aRes;
+}
+
+
 //=======================================================================
 //function : Execute
 //purpose  :
@@ -244,16 +325,37 @@ 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();
+  if (aShapeBase.IsNull()) {
+    Standard_NullObject::Raise("Shape for gluing is null");
+  }
+
+  Standard_Real tol3d = aCI.GetTolerance();
+
+  Standard_Boolean aKeepNonSolids = aCI.GetKeepNonSolids();
+
   if (aType == GLUE_FACES) {
-    Handle(GEOM_Function) aRefBase = aCI.GetBase();
-    TopoDS_Shape aShapeBase = aRefBase->GetValue();
-    if (aShapeBase.IsNull()) {
-      Standard_NullObject::Raise("Shape for gluing is null");
+    aShape = GlueFacesWithWarnings(aShapeBase, tol3d, aKeepNonSolids, aWrn);
+  }
+  else { // aType == GLUE_FACES_BY_LIST
+    Handle(TColStd_HSequenceOfTransient) SF = aCI.GetFaces();
+    TopTools_MapOfShape aFaces;
+    int i=1;
+    for( ; i <= SF->Length(); i++) {
+      Handle(Standard_Transient) anItem = SF->Value(i);
+      if(anItem.IsNull())
+       continue;
+      Handle(GEOM_Function) aRefSh = Handle(GEOM_Function)::DownCast(anItem);
+      if(aRefSh.IsNull())
+       continue;
+      TopoDS_Shape aFace = aRefSh->GetValue();
+      if(aFace.IsNull())
+       continue;
+      if(!aFaces.Contains(aFace))
+       aFaces.Add(aFace);
     }
-
-    Standard_Real tol3d = aCI.GetTolerance();
-    aShape = GlueFacesWithWarnings(aShapeBase, tol3d, aWrn);
-  } else {
+    aShape = GlueFacesByList(aShapeBase, tol3d, aKeepNonSolids, aFaces);
   }
 
   if (aShape.IsNull()) return 0;