X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGEOMImpl%2FGEOMImpl_BlockDriver.cxx;h=d80125d3582d5042a62d1f4ef1f525728cec0e56;hb=3059f9d5521dd7c91c35c50afbd6beb18b8826fd;hp=880661f70c3b4b93f6da7792390354a8c29313a4;hpb=8fc906ac5adbcbd6e2ba22455a005bc622171509;p=modules%2Fgeom.git diff --git a/src/GEOMImpl/GEOMImpl_BlockDriver.cxx b/src/GEOMImpl/GEOMImpl_BlockDriver.cxx index 880661f70..d80125d35 100644 --- a/src/GEOMImpl/GEOMImpl_BlockDriver.cxx +++ b/src/GEOMImpl/GEOMImpl_BlockDriver.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2010 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 @@ -43,6 +44,7 @@ #include +#include #include #include #include @@ -82,6 +84,9 @@ #include +#include +#include + #include #include #include @@ -234,7 +239,14 @@ Standard_Integer GEOMImpl_BlockDriver::Execute(TFunction_Logbook& log) const ("Impossible to build a connected wire from the given edges"); } TopoDS_Wire aWire = *MW; - delete MW; + delete MW; + + // check the wire closure + TopoDS_Vertex aV1, aV2; + TopExp::Vertices(aWire, aV1, aV2); + if ( !aV1.IsNull() && !aV2.IsNull() && aV1.IsSame(aV2) ) + aWire.Closed( true ); + if (!aWire.Closed()) { Standard_ConstructionError::Raise ("Impossible to build a closed wire from the given edges"); @@ -263,16 +275,26 @@ Standard_Integer GEOMImpl_BlockDriver::Execute(TFunction_Logbook& log) const // create two edges, linking ends of the given edges TopoDS_Vertex V11, V12, V21, V22; - TopExp::Vertices(anEdge1, V11, V12, Standard_True); - TopExp::Vertices(anEdge2, V21, V22, Standard_True); + TopExp::Vertices(anEdge1, V11, V12, Standard_False); + TopExp::Vertices(anEdge2, V21, V22, Standard_False); if (V11.IsNull() || V12.IsNull() || V21.IsNull() || V22.IsNull()) { Standard_NullObject::Raise("Bad edge for face construction: vertex is not defined"); } - gp_Pnt P11 = BRep_Tool::Pnt(V11); - gp_Pnt P12 = BRep_Tool::Pnt(V12); - gp_Pnt P21 = BRep_Tool::Pnt(V21); - gp_Pnt P22 = BRep_Tool::Pnt(V22); + + BRepAdaptor_Curve C1 (anEdge1); + BRepAdaptor_Curve C2 (anEdge2); + gp_Pnt P11, P12, P21, P22; + + // Mantis issue 0020599: Creation of a quadrangle face from 2 edges: SIGSEGV + P11 = C1.Value(C1.FirstParameter()); + P12 = C1.Value(C1.LastParameter()); + P21 = C2.Value(C2.FirstParameter()); + P22 = C2.Value(C2.LastParameter()); + //gp_Pnt P11 = BRep_Tool::Pnt(V11); + //gp_Pnt P12 = BRep_Tool::Pnt(V12); + //gp_Pnt P21 = BRep_Tool::Pnt(V21); + //gp_Pnt P22 = BRep_Tool::Pnt(V22); if (P11.Distance(P21) < prec || P12.Distance(P22) < prec || P11.Distance(P22) < prec || P12.Distance(P21) < prec) { @@ -282,24 +304,70 @@ Standard_Integer GEOMImpl_BlockDriver::Execute(TFunction_Logbook& log) const Standard_Real per11 = P11.Distance(P21) + P12.Distance(P22); Standard_Real per12 = P11.Distance(P22) + P12.Distance(P21); + BRep_Builder BB; + TopoDS_Edge anEdge3; TopoDS_Edge anEdge4; + + // Mantis issue 0020599: Creation of a quadrangle face from 2 edges: SIGSEGV if (per11 < per12) { - anEdge3 = BRepBuilderAPI_MakeEdge(V11, V21); - anEdge4 = BRepBuilderAPI_MakeEdge(V12, V22); - } else { - anEdge3 = BRepBuilderAPI_MakeEdge(V11, V22); - anEdge4 = BRepBuilderAPI_MakeEdge(V12, V21); + Handle(Geom_Line) Line1 = GC_MakeLine(P11, P21).Value(); + Handle(Geom_Line) Line2 = GC_MakeLine(P12, P22).Value(); + + BB.MakeEdge(anEdge3, Line1, Precision::Confusion()); + BB.Range(anEdge3, 0., P11.Distance(P21)); + BB.Add(anEdge3, V11.Oriented(TopAbs_FORWARD)); + BB.Add(anEdge3, V21.Oriented(TopAbs_REVERSED)); + + BB.MakeEdge(anEdge4, Line2, Precision::Confusion()); + BB.Range(anEdge4, 0., P12.Distance(P22)); + BB.Add(anEdge4, V12.Oriented(TopAbs_FORWARD)); + BB.Add(anEdge4, V22.Oriented(TopAbs_REVERSED)); + } + else { + Handle(Geom_Line) Line1 = GC_MakeLine(P11, P22).Value(); + Handle(Geom_Line) Line2 = GC_MakeLine(P12, P21).Value(); + + BB.MakeEdge(anEdge3, Line1, Precision::Confusion()); + BB.Range(anEdge3, 0., P11.Distance(P22)); + BB.Add(anEdge3, V11.Oriented(TopAbs_FORWARD)); + BB.Add(anEdge3, V22.Oriented(TopAbs_REVERSED)); + + BB.MakeEdge(anEdge4, Line2, Precision::Confusion()); + BB.Range(anEdge4, 0., P12.Distance(P21)); + BB.Add(anEdge4, V12.Oriented(TopAbs_FORWARD)); + BB.Add(anEdge4, V21.Oriented(TopAbs_REVERSED)); } + //if (per11 < per12) { + // anEdge3 = BRepBuilderAPI_MakeEdge(V11, V21); + // anEdge4 = BRepBuilderAPI_MakeEdge(V12, V22); + //} else { + // anEdge3 = BRepBuilderAPI_MakeEdge(V11, V22); + // anEdge4 = BRepBuilderAPI_MakeEdge(V12, V21); + //} // build a wire - BRepBuilderAPI_MakeWire MW (anEdge1, anEdge3, anEdge2, anEdge4); - if (!MW.IsDone()) { + BRepBuilderAPI_MakeWire* MW; + MW = new BRepBuilderAPI_MakeWire(anEdge1, anEdge3, anEdge2, anEdge4); + if (!MW->IsDone()) { Standard_ConstructionError::Raise("Wire construction failed"); } + TopoDS_Wire aWire = *MW; + delete MW; + + TopoDS_Vertex aV1, aV2; + TopExp::Vertices(aWire, aV1, aV2); + if ( !aV1.IsNull() && !aV2.IsNull() && aV1.IsSame(aV2) ) + aWire.Closed( true ); + + if (!aWire.Closed()) { + Standard_ConstructionError::Raise + ("Impossible to build a closed wire from the given edges"); + } + // try to build face on the wire - GEOMImpl_Block6Explorer::MakeFace(MW, Standard_False, aShape); + GEOMImpl_Block6Explorer::MakeFace(aWire, Standard_False, aShape); if (aShape.IsNull()) { Standard_ConstructionError::Raise("Face construction failed"); } @@ -357,6 +425,7 @@ Standard_Integer GEOMImpl_BlockDriver::Execute(TFunction_Logbook& log) const } // try to build face on the wire + aMkPoly.Close(); GEOMImpl_Block6Explorer::MakeFace(aMkPoly, Standard_False, aShape); if (aShape.IsNull()) { Standard_ConstructionError::Raise("Face construction failed"); @@ -1013,7 +1082,8 @@ Standard_EXPORT Handle_Standard_Type& GEOMImpl_BlockDriver_Type_() //function : DownCast //purpose : //======================================================================= -const Handle(GEOMImpl_BlockDriver) Handle(GEOMImpl_BlockDriver)::DownCast(const Handle(Standard_Transient)& AnObject) +const Handle(GEOMImpl_BlockDriver) Handle(GEOMImpl_BlockDriver)::DownCast + (const Handle(Standard_Transient)& AnObject) { Handle(GEOMImpl_BlockDriver) _anOtherObject; @@ -1023,5 +1093,5 @@ const Handle(GEOMImpl_BlockDriver) Handle(GEOMImpl_BlockDriver)::DownCast(const } } - return _anOtherObject ; + return _anOtherObject; }