X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGEOMImpl%2FGEOMImpl_ShapeDriver.cxx;h=b3aa980abdf8c7f945beeddedd231efc30d29932;hb=728e6e5834d7de537e9fe79518aafa28ec8e63ed;hp=b2c57e879491014f2bf29bc787b988a62f014e4a;hpb=e2dcf4323c7d7c36e8e1a4fda4dd6cf86c99be81;p=modules%2Fgeom.git diff --git a/src/GEOMImpl/GEOMImpl_ShapeDriver.cxx b/src/GEOMImpl/GEOMImpl_ShapeDriver.cxx index b2c57e879..b3aa980ab 100644 --- a/src/GEOMImpl/GEOMImpl_ShapeDriver.cxx +++ b/src/GEOMImpl/GEOMImpl_ShapeDriver.cxx @@ -5,8 +5,13 @@ #include #include #include +#include + #include +// OCCT Includes +#include + #include #include #include @@ -18,7 +23,6 @@ #include #include #include -#include #include #include @@ -76,27 +80,53 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes(); unsigned int ind, nbshapes = aShapes->Length(); - // add edges + TopoDS_Wire aWire; + B.MakeWire(aWire); BRepBuilderAPI_MakeWire MW; + bool isMWDone = true; + + // add edges for (ind = 1; ind <= nbshapes; 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) - MW.Add(TopoDS::Edge(aShape_i)); - else if (aShape_i.ShapeType() == TopAbs_WIRE) - MW.Add(TopoDS::Wire(aShape_i)); - else + if (aShape_i.ShapeType() == TopAbs_EDGE) { + B.Add(aWire, TopoDS::Edge(aShape_i)); + MW.Add(TopoDS::Edge(aShape_i)); + } else if (aShape_i.ShapeType() == TopAbs_WIRE) { + B.Add(aWire, TopoDS::Wire(aShape_i)); + MW.Add(TopoDS::Wire(aShape_i)); + } else { Standard_TypeMismatch::Raise ("Shape for wire construction is neither an edge nor a wire"); + } + if (!MW.IsDone()) { + // check status after each edge/wire addition, because the final status + // can be OK even in case, when some edges/wires was not accepted. + isMWDone = false; + } } - if (!MW.IsDone()) { - Standard_ConstructionError::Raise("Wire construction failed"); + if (isMWDone) { + aShape = MW; + } else { + // 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 if (aFW->StatusReorder(ShapeExtend_DONE2)) { + Standard_ConstructionError::Raise("Wire construction failed: some gaps detected"); + } else { + } + aShape = aFW->WireAPIMake(); } - aShape = MW; } else if (aType == FACE_WIRE) { Handle(GEOM_Function) aRefBase = aCI.GetBase(); @@ -106,14 +136,22 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const ("Shape for face construction is null or not a wire"); } TopoDS_Wire W = TopoDS::Wire(aShapeBase); - BRepBuilderAPI_MakeFace MF (W, aCI.GetIsPlanar()); - if (!MF.IsDone()) { + //BRepBuilderAPI_MakeFace MF (W, aCI.GetIsPlanar()); + //if (!MF.IsDone()) { + // Standard_ConstructionError::Raise("Face construction failed"); + //} + //aShape = MF.Shape(); + GEOMImpl_Block6Explorer::MakeFace(W, aCI.GetIsPlanar(), aShape); + if (aShape.IsNull()) { Standard_ConstructionError::Raise("Face construction failed"); } - aShape = MF.Shape(); } else if (aType == FACE_WIRES) { Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes(); + int nbshapes = aShapes->Length(); + if (nbshapes < 1) { + Standard_ConstructionError::Raise("No wires given"); + } // first wire Handle(GEOM_Function) aRefWire = Handle(GEOM_Function)::DownCast(aShapes->Value(1)); @@ -124,53 +162,56 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const TopoDS_Wire W = TopoDS::Wire(aWire); // basic face - BRepBuilderAPI_MakeFace MF (W, aCI.GetIsPlanar()); - if (!MF.IsDone()) { + //BRepBuilderAPI_MakeFace MF (W, aCI.GetIsPlanar()); + //if (!MF.IsDone()) { + // Standard_ConstructionError::Raise("Face construction failed"); + //} + //TopoDS_Shape FFace = MF.Shape(); + TopoDS_Shape FFace; + GEOMImpl_Block6Explorer::MakeFace(W, aCI.GetIsPlanar(), FFace); + if (FFace.IsNull()) { Standard_ConstructionError::Raise("Face construction failed"); } - TopoDS_Shape FFace = MF.Shape(); - if (!FFace.IsNull()) { - unsigned int ind, nbshapes = aShapes->Length(); - if (nbshapes == 1) { - aShape = FFace; - - } else if (nbshapes >= 2) { - TopoDS_Compound C; - BRep_Builder aBuilder; - aBuilder.MakeCompound(C); - BRepAlgo_FaceRestrictor FR; - - TopAbs_Orientation OriF = FFace.Orientation(); - TopoDS_Shape aLocalS = FFace.Oriented(TopAbs_FORWARD); - FR.Init(TopoDS::Face(aLocalS), Standard_False, Standard_True); - - for (ind = 1; ind <= nbshapes; ind++) { - Handle(GEOM_Function) aRefWire_i = - Handle(GEOM_Function)::DownCast(aShapes->Value(ind)); - TopoDS_Shape aWire_i = aRefWire_i->GetValue(); - if (aWire_i.IsNull() || aWire_i.ShapeType() != TopAbs_WIRE) { - Standard_NullObject::Raise("Shape for face construction is null or not a wire"); - } - - FR.Add(TopoDS::Wire(aWire_i)); - } - - FR.Perform(); - - if (FR.IsDone()) { - int k = 0; - TopoDS_Shape aFace; - for (; FR.More(); FR.Next()) { - aFace = FR.Current().Oriented(OriF); - aBuilder.Add(C, aFace); - k++; - } - if (k == 1) { - aShape = aFace; - } else { - aShape = C; - } - } + + if (nbshapes == 1) { + aShape = FFace; + + } else { + TopoDS_Compound C; + BRep_Builder aBuilder; + aBuilder.MakeCompound(C); + BRepAlgo_FaceRestrictor FR; + + TopAbs_Orientation OriF = FFace.Orientation(); + TopoDS_Shape aLocalS = FFace.Oriented(TopAbs_FORWARD); + FR.Init(TopoDS::Face(aLocalS), Standard_False, Standard_True); + + for (int ind = 1; ind <= nbshapes; ind++) { + Handle(GEOM_Function) aRefWire_i = + Handle(GEOM_Function)::DownCast(aShapes->Value(ind)); + TopoDS_Shape aWire_i = aRefWire_i->GetValue(); + if (aWire_i.IsNull() || aWire_i.ShapeType() != TopAbs_WIRE) { + Standard_NullObject::Raise("Shape for face construction is null or not a wire"); + } + + FR.Add(TopoDS::Wire(aWire_i)); + } + + FR.Perform(); + + if (FR.IsDone()) { + int k = 0; + TopoDS_Shape aFace; + for (; FR.More(); FR.Next()) { + aFace = FR.Current().Oriented(OriF); + aBuilder.Add(C, aFace); + k++; + } + if (k == 1) { + aShape = aFace; + } else { + aShape = C; + } } } } else if (aType == SHELL_FACES) { @@ -277,7 +318,7 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const 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(); @@ -291,7 +332,7 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const tds.Orientation(TopAbs_FORWARD) ; aShape = tds; - } + } } if (aShape.IsNull()) return 0;