Salome HOME
remove trace
[modules/geom.git] / src / GEOMImpl / GEOMImpl_ShapeDriver.cxx
index 9f2ec8081ef91a66252bca747b44290ede986db2..0ec4b35e6addff5a35d9fe1cd1fa878c10ab5b6f 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2013  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
@@ -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 <GEOMImpl_ShapeDriver.hxx>
 
@@ -92,7 +93,7 @@
 //modified by NIZNHY-PKV Wed Dec 28 13:48:20 2011f
 //static
 //  void KeepEdgesOrder(const Handle(TopTools_HSequenceOfShape)& aEdges,
-//                   const Handle(TopTools_HSequenceOfShape)& aWires);
+//                    const Handle(TopTools_HSequenceOfShape)& aWires);
 //modified by NIZNHY-PKV Wed Dec 28 13:48:23 2011t
 
 //=======================================================================
@@ -133,66 +134,12 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
 
   if (aType == WIRE_EDGES) {
     Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
-    TopoDS_Wire aWire;
-    B.MakeWire(aWire);
-
-    // add edges
-    for (unsigned int ind = 1; ind <= aShapes->Length(); ind++) {
-      Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
-      TopoDS_Shape aShape_i = aRefShape->GetValue();
-      if (aShape_i.IsNull()) {
-        Standard_NullObject::Raise("Shape for wire construction is null");
-      }
-      if (aShape_i.ShapeType() == TopAbs_EDGE || aShape_i.ShapeType() == TopAbs_WIRE) {
-        TopExp_Explorer exp (aShape_i, TopAbs_EDGE);
-        for (; exp.More(); exp.Next())
-          B.Add(aWire, TopoDS::Edge(exp.Current()));
-      } else {
-        Standard_TypeMismatch::Raise
-          ("Shape for wire construction is neither an edge nor a wire");
-      }
-    }
-
-    // fix edges order
-    Handle(ShapeFix_Wire) aFW = new ShapeFix_Wire;
-    aFW->Load(aWire);
-    aFW->FixReorder();
-
-    if (aFW->StatusReorder(ShapeExtend_FAIL1)) {
-      Standard_ConstructionError::Raise("Wire construction failed: several loops detected");
-    } else if (aFW->StatusReorder(ShapeExtend_FAIL)) {
-      Standard_ConstructionError::Raise("Wire construction failed");
-    } else {
-    }
 
-    // IMP 0019766: Building a Wire from unconnected edges by introducing a tolerance
     Standard_Real aTolerance = aCI.GetTolerance();
     if (aTolerance < Precision::Confusion())
       aTolerance = Precision::Confusion();
 
-    aFW->ClosedWireMode() = Standard_False;
-    aFW->FixConnected(aTolerance);
-    if (aFW->StatusConnected(ShapeExtend_FAIL)) {
-      Standard_ConstructionError::Raise("Wire construction failed: cannot build connected wire");
-    }
-    // IMP 0019766
-    if (aFW->StatusConnected(ShapeExtend_DONE3)) {
-      // Confused with <prec> but not Analyzer.Precision(), set the same
-      aFW->FixGapsByRangesMode() = Standard_True;
-      if (aFW->FixGaps3d()) {
-        Handle(ShapeExtend_WireData) sbwd = aFW->WireData();
-        Handle(ShapeFix_Edge) aFe = new ShapeFix_Edge;
-        for (Standard_Integer iedge = 1; iedge <= sbwd->NbEdges(); iedge++) {
-          TopoDS_Edge aEdge = TopoDS::Edge(sbwd->Edge(iedge));
-          aFe->FixVertexTolerance(aEdge);
-          aFe->FixSameParameter(aEdge);
-        }
-      }
-      else if (aFW->StatusGaps3d(ShapeExtend_FAIL)) {
-        Standard_ConstructionError::Raise("Wire construction failed: cannot fix 3d gaps");
-      }
-    }
-      aShape = aFW->WireAPIMake();
+    aShape = MakeWireFromEdges(aShapes, aTolerance);
   }
   else if (aType == FACE_WIRE) {
     Handle(GEOM_Function) aRefBase = aCI.GetBase();
@@ -594,6 +541,10 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
   BRepCheck_Analyzer ana (aShape, false);
   if (!ana.IsValid()) {
     //Standard_ConstructionError::Raise("Algorithm have produced an invalid shape result");
+    // For Mantis issue 0021772: EDF 2336 GEOM: Non valid face created from two circles
+    Handle(ShapeFix_Shape) aSfs = new ShapeFix_Shape (aShape);
+    aSfs->Perform();
+    aShape = aSfs->Shape();
   }
 
   aFunction->SetValue(aShape);
@@ -606,6 +557,73 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
   return 1;
 }
 
+TopoDS_Wire GEOMImpl_ShapeDriver::MakeWireFromEdges(const Handle(TColStd_HSequenceOfTransient)& theEdgesFuncs,
+                                                    const Standard_Real theTolerance)
+{
+  BRep_Builder B;
+
+  TopoDS_Wire aWire;
+  B.MakeWire(aWire);
+
+  // add edges
+  for (unsigned int ind = 1; ind <= theEdgesFuncs->Length(); ind++) {
+    Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(theEdgesFuncs->Value(ind));
+    TopoDS_Shape aShape_i = aRefShape->GetValue();
+    if (aShape_i.IsNull()) {
+      Standard_NullObject::Raise("Shape for wire construction is null");
+    }
+    if (aShape_i.ShapeType() == TopAbs_EDGE || aShape_i.ShapeType() == TopAbs_WIRE) {
+      TopExp_Explorer exp (aShape_i, TopAbs_EDGE);
+      for (; exp.More(); exp.Next())
+        B.Add(aWire, TopoDS::Edge(exp.Current()));
+    } else {
+      Standard_TypeMismatch::Raise
+        ("Shape for wire construction is neither an edge nor a wire");
+    }
+  }
+
+  // fix edges order
+  Handle(ShapeFix_Wire) aFW = new ShapeFix_Wire;
+  aFW->Load(aWire);
+  aFW->FixReorder();
+
+  if (aFW->StatusReorder(ShapeExtend_FAIL1)) {
+    Standard_ConstructionError::Raise("Wire construction failed: several loops detected");
+  }
+  else if (aFW->StatusReorder(ShapeExtend_FAIL)) {
+    Standard_ConstructionError::Raise("Wire construction failed");
+  }
+  else {
+  }
+
+  // IMP 0019766: Building a Wire from unconnected edges by introducing a tolerance
+  aFW->ClosedWireMode() = Standard_False;
+  aFW->FixConnected(theTolerance);
+  if (aFW->StatusConnected(ShapeExtend_FAIL)) {
+    Standard_ConstructionError::Raise("Wire construction failed: cannot build connected wire");
+  }
+  // IMP 0019766
+  if (aFW->StatusConnected(ShapeExtend_DONE3)) {
+    // Confused with <prec> but not Analyzer.Precision(), set the same
+    aFW->FixGapsByRangesMode() = Standard_True;
+    if (aFW->FixGaps3d()) {
+      Handle(ShapeExtend_WireData) sbwd = aFW->WireData();
+      Handle(ShapeFix_Edge) aFe = new ShapeFix_Edge;
+      for (Standard_Integer iedge = 1; iedge <= sbwd->NbEdges(); iedge++) {
+        TopoDS_Edge aEdge = TopoDS::Edge(sbwd->Edge(iedge));
+        aFe->FixVertexTolerance(aEdge);
+        aFe->FixSameParameter(aEdge);
+      }
+    }
+    else if (aFW->StatusGaps3d(ShapeExtend_FAIL)) {
+      Standard_ConstructionError::Raise("Wire construction failed: cannot fix 3d gaps");
+    }
+  }
+  aWire = aFW->WireAPIMake();
+
+  return aWire;
+}
+
 TopoDS_Edge GEOMImpl_ShapeDriver::MakeEdgeFromWire(const TopoDS_Shape& aWire,
                                                    const Standard_Real LinTol,
                                                    const Standard_Real AngTol)
@@ -956,48 +974,88 @@ TopoDS_Edge GEOMImpl_ShapeDriver::MakeEdgeFromWire(const TopoDS_Shape& aWire,
     return ResEdge;
 }
 
-//=======================================================================
-//function :  GEOMImpl_ShapeDriver_Type_
-//purpose  :
-//=======================================================================
-Standard_EXPORT Handle_Standard_Type& GEOMImpl_ShapeDriver_Type_()
-{
-
-  static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
-  if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
-  static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
-  if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
-  static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
-  if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
-
-
-  static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
-  static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_ShapeDriver",
-                                                         sizeof(GEOMImpl_ShapeDriver),
-                                                         1,
-                                                         (Standard_Address)_Ancestors,
-                                                         (Standard_Address)NULL);
+//================================================================================
+/*!
+ * \brief Returns a name of creation operation and names and values of creation parameters
+ */
+//================================================================================
 
-  return _aType;
-}
-
-//=======================================================================
-//function : DownCast
-//purpose  :
-//=======================================================================
-const Handle(GEOMImpl_ShapeDriver) Handle(GEOMImpl_ShapeDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
+bool GEOMImpl_ShapeDriver::
+GetCreationInformation(std::string&             theOperationName,
+                       std::vector<GEOM_Param>& theParams)
 {
-  Handle(GEOMImpl_ShapeDriver) _anOtherObject;
-
-  if (!AnObject.IsNull()) {
-     if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_ShapeDriver))) {
-       _anOtherObject = Handle(GEOMImpl_ShapeDriver)((Handle(GEOMImpl_ShapeDriver)&)AnObject);
-     }
+  if (Label().IsNull()) return 0;
+  Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
+
+  GEOMImpl_IShapes aCI( function );
+  Standard_Integer aType = function->GetType();
+
+  switch ( aType ) {
+  case WIRE_EDGES:
+    theOperationName = "WIRE";
+    AddParam( theParams, "Wires/edges", aCI.GetShapes() );
+    AddParam( theParams, "Tolerance", aCI.GetTolerance() );
+    break;
+  case FACE_WIRE:
+    theOperationName = "FACE";
+    AddParam( theParams, "Wire/edge", aCI.GetBase() );
+    AddParam( theParams, "Is planar wanted", aCI.GetIsPlanar() );
+    break;
+  case FACE_WIRES:
+    theOperationName = "FACE";
+    AddParam( theParams, "Wires/edges", aCI.GetShapes() );
+    AddParam( theParams, "Is planar wanted", aCI.GetIsPlanar() );
+    break;
+  case SHELL_FACES:
+    theOperationName = "SHELL";
+    AddParam( theParams, "Objects", aCI.GetShapes() );
+    break;
+  case SOLID_SHELL:
+  case SOLID_SHELLS:
+    theOperationName = "SOLID";
+    AddParam( theParams, "Objects", aCI.GetShapes() );
+    break;
+  case COMPOUND_SHAPES:
+    theOperationName = "COMPOUND";
+    AddParam( theParams, "Objects", aCI.GetShapes() );
+    break;
+  case EDGE_WIRE:
+    theOperationName = "EDGE";
+    AddParam( theParams, "Wire", aCI.GetBase() );
+    AddParam( theParams, "Linear Tolerance", aCI.GetTolerance() );
+    AddParam( theParams, "Angular Tolerance", aCI.GetAngularTolerance() );
+    break;
+  case EDGE_CURVE_LENGTH:
+    theOperationName = "EDGE";
+    {
+      GEOMImpl_IVector aCI( function );
+      AddParam( theParams, "Edge", aCI.GetPoint1() );
+      AddParam( theParams, "Start point", aCI.GetPoint2() );
+      AddParam( theParams, "Length", aCI.GetParameter() );
+    }
+    break;
+  case SHAPES_ON_SHAPE:
+  {
+    theOperationName = "GetShapesOnShapeAsCompound";
+    Handle(TColStd_HSequenceOfTransient) shapes = aCI.GetShapes();
+    if ( !shapes.IsNull() && shapes->Length() > 0 )
+      AddParam( theParams, "Check shape", shapes->Value(1) );
+    if ( !shapes.IsNull() && shapes->Length() > 1 )
+      AddParam( theParams, "Shape", shapes->Value(2) );
+    AddParam( theParams, "Shape type", TopAbs_ShapeEnum( aCI.GetSubShapeType() ));
+    AddParam( theParams, "State", TopAbs_State((int) aCI.GetTolerance() ));
+    break;
+  }
+  default:
+    return false;
   }
 
-  return _anOtherObject;
+  return true;
 }
 
+IMPLEMENT_STANDARD_HANDLE (GEOMImpl_ShapeDriver,GEOM_BaseDriver);
+IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_ShapeDriver,GEOM_BaseDriver);
+
 //modified by NIZNHY-PKV Wed Dec 28 13:48:31 2011f
 #include <TopoDS_Iterator.hxx>
 #include <TopTools_HSequenceOfShape.hxx>
@@ -1013,7 +1071,7 @@ const Handle(GEOMImpl_ShapeDriver) Handle(GEOMImpl_ShapeDriver)::DownCast(const
 //=======================================================================
 /*
 void KeepEdgesOrder(const Handle(TopTools_HSequenceOfShape)& aEdges,
-                   const Handle(TopTools_HSequenceOfShape)& aWires)
+                    const Handle(TopTools_HSequenceOfShape)& aWires)
 {
   Standard_Integer aNbWires, aNbEdges;
   // 
@@ -1052,7 +1110,7 @@ void KeepEdgesOrder(const Handle(TopTools_HSequenceOfShape)& aEdges,
     for (j=1; j<=aNbEdges; ++j) {
       const TopoDS_Shape& aE=aEdges->Value(j);
       if (aMEx.Contains(aE)) {
-       aBB.Add(aWy, aE);
+        aBB.Add(aWy, aE);
       }
     }
     //