]> SALOME platform Git repositories - modules/geom.git/blobdiff - src/GEOMImpl/GEOMImpl_ShapeDriver.cxx
Salome HOME
Merge branch 'master' into V7_5_BR
[modules/geom.git] / src / GEOMImpl / GEOMImpl_ShapeDriver.cxx
index 96f0bb6c69673b70da933c6c208e96d666c832fc..914158002cfd653ff08c18fbece0c48a10eb446c 100644 (file)
@@ -44,6 +44,7 @@
 #include <BRepBuilderAPI_Sewing.hxx>
 #include <BRepBuilderAPI_MakeWire.hxx>
 #include <BRepBuilderAPI_MakeEdge.hxx>
+#include <BRepBuilderAPI_MakeSolid.hxx>
 #include <BRepCheck.hxx>
 #include <BRepCheck_Analyzer.hxx>
 #include <BRepCheck_Shell.hxx>
@@ -133,10 +134,13 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
 
   TopoDS_Shape aShape;
   TCollection_AsciiString aWarning;
+  TopAbs_ShapeEnum anExpectedType = TopAbs_SHAPE;
 
   BRep_Builder B;
 
   if (aType == WIRE_EDGES) {
+    anExpectedType = TopAbs_WIRE;
+
     Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
 
     Standard_Real aTolerance = aCI.GetTolerance();
@@ -146,6 +150,8 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
     aShape = MakeWireFromEdges(aShapes, aTolerance);
   }
   else if (aType == FACE_WIRE) {
+    anExpectedType = TopAbs_FACE;
+
     Handle(GEOM_Function) aRefBase = aCI.GetBase();
     TopoDS_Shape aShapeBase = aRefBase->GetValue();
     if (aShapeBase.IsNull()) Standard_NullObject::Raise("Argument Shape is null");
@@ -179,6 +185,8 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
     }
   }
   else if (aType == FACE_WIRES) {
+    anExpectedType = TopAbs_FACE;
+
     // Try to build a face from a set of wires and edges
     int ind;
 
@@ -295,6 +303,8 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
     }
   }
   else if (aType == SHELL_FACES) {
+    anExpectedType = TopAbs_SHELL;
+
     Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
     unsigned int ind, nbshapes = aShapes->Length();
 
@@ -350,40 +360,14 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
       }
     }
 
-  }
-  else if (aType == SOLID_SHELL) {
-    Handle(GEOM_Function) aRefShell = aCI.GetBase();
-    TopoDS_Shape aShapeShell = aRefShell->GetValue();
-    if (!aShapeShell.IsNull() && aShapeShell.ShapeType() == TopAbs_COMPOUND) {
-      TopoDS_Iterator It (aShapeShell, Standard_True, Standard_True);
-      if (It.More()) aShapeShell = It.Value();
-    }
-    if (aShapeShell.IsNull() || aShapeShell.ShapeType() != TopAbs_SHELL) {
-      Standard_NullObject::Raise("Shape for solid construction is null or not a shell");
-    }
-
-    BRepCheck_Shell chkShell(TopoDS::Shell(aShapeShell));
-    if (chkShell.Closed() == BRepCheck_NotClosed) return 0;
-
-    TopoDS_Solid Sol;
-    B.MakeSolid(Sol);
-    B.Add(Sol, aShapeShell);
-    BRepClass3d_SolidClassifier SC (Sol);
-    SC.PerformInfinitePoint(Precision::Confusion());
-    if (SC.State() == TopAbs_IN) {
-      B.MakeSolid(Sol);
-      B.Add(Sol, aShapeShell.Reversed());
-    }
-
-    aShape = Sol;
-
   }
   else if (aType == SOLID_SHELLS) {
+    anExpectedType = TopAbs_SOLID;
+
     Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
     unsigned int ind, nbshapes = aShapes->Length();
     Standard_Integer ish = 0;
-    TopoDS_Solid Sol;
-    B.MakeSolid(Sol);
+    BRepBuilderAPI_MakeSolid aMkSolid;
 
     // add shapes
     for (ind = 1; ind <= nbshapes; ind++) {
@@ -397,11 +381,13 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
         if (It.More()) aShapeShell = It.Value();
       }
       if (aShapeShell.ShapeType() == TopAbs_SHELL) {
-        B.Add(Sol, aShapeShell);
+        aMkSolid.Add(TopoDS::Shell(aShapeShell));
         ish++;
       }
     }
-    if (ish == 0) return 0;
+    if (ish == 0 || !aMkSolid.IsDone()) return 0;
+
+    TopoDS_Solid Sol = aMkSolid.Solid();
     BRepClass3d_SolidClassifier SC (Sol);
     SC.PerformInfinitePoint(Precision::Confusion());
     if (SC.State() == TopAbs_IN)
@@ -410,6 +396,8 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
       aShape = Sol;
   }
   else if (aType == COMPOUND_SHAPES) {
+    anExpectedType = TopAbs_COMPOUND;
+
     Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
     unsigned int ind, nbshapes = aShapes->Length();
 
@@ -428,31 +416,9 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
     aShape = C;
 
   }
-  /*
-  else if (aType == REVERSE_ORIENTATION) {
-    Handle(GEOM_Function) aRefShape = aCI.GetBase();
-    TopoDS_Shape aShape_i = aRefShape->GetValue();
-    if (aShape_i.IsNull()) {
-       Standard_NullObject::Raise("Shape for reverse is null");
-    }
-
-    BRepBuilderAPI_Copy Copy(aShape_i);
-    if( Copy.IsDone() ) {
-      TopoDS_Shape tds = Copy.Shape();
-      if( tds.IsNull() ) {
-        Standard_ConstructionError::Raise("Orientation aborted : Can not reverse the shape");
-      }
-
-      if( tds.Orientation() == TopAbs_FORWARD)
-        tds.Orientation(TopAbs_REVERSED);
-      else
-        tds.Orientation(TopAbs_FORWARD);
-
-      aShape = tds;
-    }
-  }
-  */
   else if (aType == EDGE_WIRE) {
+    anExpectedType = TopAbs_EDGE;
+
     Handle(GEOM_Function) aRefBase = aCI.GetBase();
     TopoDS_Shape aWire = aRefBase->GetValue();
     Standard_Real LinTol = aCI.GetTolerance();
@@ -462,6 +428,8 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
     aShape = MakeEdgeFromWire(aWire, LinTol, AngTol);
   }
   else if (aType == EDGE_CURVE_LENGTH) {
+    anExpectedType = TopAbs_EDGE;
+
     GEOMImpl_IVector aVI (aFunction);
 
     // RefCurve
@@ -577,6 +545,13 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
     aShape = aSfs->Shape();
   }
 
+  // Check if the result shape type is compatible with the expected.
+  const TopAbs_ShapeEnum aShType = aShape.ShapeType();
+
+  if (anExpectedType != TopAbs_SHAPE && anExpectedType != aShType) {
+    Standard_ConstructionError::Raise("Result type check failed");
+  }
+
   aFunction->SetValue(aShape);
 
   log.SetTouched(Label());
@@ -1074,7 +1049,7 @@ TopoDS_Shape GEOMImpl_ShapeDriver::MakeIsoline
                              const double       theParameter) const
 {
   TopoDS_Shape          aResult;
-  GEOMUtils_Hatcher     aHatcher(theFace);
+  GEOMUtils::Hatcher    aHatcher(theFace);
   const GeomAbs_IsoType aType = (IsUIso ? GeomAbs_IsoU : GeomAbs_IsoV);
 
   aHatcher.Init(aType, theParameter);
@@ -1193,7 +1168,6 @@ GetCreationInformation(std::string&             theOperationName,
     theOperationName = "SHELL";
     AddParam( theParams, "Objects", aCI.GetShapes() );
     break;
-  case SOLID_SHELL:
   case SOLID_SHELLS:
     theOperationName = "SOLID";
     AddParam( theParams, "Objects", aCI.GetShapes() );