From 95a58c6f6d03e925872ff59cea6ba65ddf6ec29f Mon Sep 17 00:00:00 2001 From: Paul RASCLE Date: Fri, 24 Jun 2016 20:11:04 +0200 Subject: [PATCH] polylines with several sections allowed for calculation case limit --- src/HYDROData/HYDROData_PolylineXY.cxx | 90 +++++++++++++++++--- src/HYDROData/HYDROData_PolylineXY.h | 6 ++ src/HYDROData/HYDROData_SplitToZonesTool.cxx | 8 +- src/HYDROGUI/HYDROGUI_CalculationOp.cxx | 10 +-- 4 files changed, 93 insertions(+), 21 deletions(-) diff --git a/src/HYDROData/HYDROData_PolylineXY.cxx b/src/HYDROData/HYDROData_PolylineXY.cxx index 4c223307..c36a6c7f 100644 --- a/src/HYDROData/HYDROData_PolylineXY.cxx +++ b/src/HYDROData/HYDROData_PolylineXY.cxx @@ -882,35 +882,99 @@ void HYDROData_PolylineXY::setEditable( const bool theIsEditable ) /** * Returns true if polyline is closed */ -bool HYDROData_PolylineXY::IsClosed( const bool theIsSimpleCheck ) const +bool HYDROData_PolylineXY::IsClosed(const bool theIsSimpleCheck) const { + //DEBTRACE("IsClosed " << theIsSimpleCheck << " " << GetName()); bool anIsClosed = false; TopoDS_Shape aShape = GetShape(); - if ( aShape.IsNull() ) + if (aShape.IsNull()) return anIsClosed; TopTools_SequenceOfShape aWires; - HYDROData_ShapesTool::ExploreShapeToShapes( aShape, TopAbs_WIRE, aWires ); + HYDROData_ShapesTool::ExploreShapeToShapes(aShape, TopAbs_WIRE, aWires); int aNbWires = aWires.Length(); - if ( theIsSimpleCheck ) - { - anIsClosed = aNbWires > 0; - for ( int i = 1; i <= aNbWires && anIsClosed; ++i ) + if (theIsSimpleCheck) { - const TopoDS_Shape& aWire = aWires.Value( i ); - anIsClosed = BRep_Tool::IsClosed( aWire ); + anIsClosed = aNbWires > 0; + for (int i = 1; i <= aNbWires && anIsClosed; ++i) + { + const TopoDS_Shape& aWire = aWires.Value(i); + anIsClosed = BRep_Tool::IsClosed(aWire); + } } - } else - { - anIsClosed = aNbWires == 1 && BRep_Tool::IsClosed( aWires.First() ); - } + { + if (aNbWires == 1) + anIsClosed = BRep_Tool::IsClosed(aWires.First()); + else + { + //DEBTRACE("aNbWires " << aNbWires); + Handle(TopTools_HSequenceOfShape) aSeqWires = new TopTools_HSequenceOfShape; + Handle(TopTools_HSequenceOfShape) aSeqEdges = new TopTools_HSequenceOfShape; + for (int i = 1; i <= aNbWires; ++i) + { + const TopoDS_Shape& aWire = aWires.Value(i); + TopExp_Explorer it2(aWire, TopAbs_EDGE); + for (; it2.More(); it2.Next()) + aSeqEdges->Append(it2.Current()); + } + if (aSeqEdges->Length() > 1) + { + //DEBTRACE(aSeqEdges->Length()); + ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdges, 1E-5, Standard_False, aSeqWires); + if (aSeqWires->Length() == 1) + { + //DEBTRACE(aSeqWires->Length()); + const TopoDS_Wire& aPolylineWire = TopoDS::Wire(aSeqWires->Value(1)); + anIsClosed = BRep_Tool::IsClosed(aPolylineWire); + } + } + } + } return anIsClosed; } +int HYDROData_PolylineXY::GetNbConnectedWires(Handle(TopTools_HSequenceOfShape)& aConnectedWires) const +{ + TopoDS_Shape aShape = GetShape(); + if (aShape.IsNull()) + return 0; + int aNbconnectedWires = 0; + TopTools_SequenceOfShape aWires; + HYDROData_ShapesTool::ExploreShapeToShapes(aShape, TopAbs_WIRE, aWires); + int aNbWires = aWires.Length(); + if (aNbWires == 1) + { + aNbconnectedWires = aNbWires; + aConnectedWires->Append(aWires.First()); + } + else + { + //DEBTRACE("aNbWires " << aNbWires); + Handle(TopTools_HSequenceOfShape) aSeqWires = new TopTools_HSequenceOfShape; + Handle(TopTools_HSequenceOfShape) aSeqEdges = new TopTools_HSequenceOfShape; + for (int i = 1; i <= aNbWires; ++i) + { + const TopoDS_Shape& aWire = aWires.Value(i); + TopExp_Explorer it2(aWire, TopAbs_EDGE); + for (; it2.More(); it2.Next()) + aSeqEdges->Append(it2.Current()); + } + if (aSeqEdges->Length() > 1) + { + //DEBTRACE(aSeqEdges->Length()); + ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdges, 1E-5, Standard_False, aSeqWires); + } + aConnectedWires = aSeqWires; + aNbconnectedWires = aConnectedWires->Length(); + DEBTRACE("aNbconnectedWires " << aNbconnectedWires); + } +return aNbconnectedWires; +} + double HYDROData_PolylineXY::GetDistance( const int theSectionIndex, const int thePointIndex ) const { diff --git a/src/HYDROData/HYDROData_PolylineXY.h b/src/HYDROData/HYDROData_PolylineXY.h index cbf5657b..d67f0ad5 100644 --- a/src/HYDROData/HYDROData_PolylineXY.h +++ b/src/HYDROData/HYDROData_PolylineXY.h @@ -20,6 +20,7 @@ #define HYDROData_PolylineXY_HeaderFile #include "HYDROData_IPolyline.h" +#include DEFINE_STANDARD_HANDLE(HYDROData_PolylineXY, HYDROData_IPolyline) @@ -151,6 +152,11 @@ public: */ HYDRODATA_EXPORT bool IsClosed( const bool theIsSimpleCheck = true ) const; + /** + * Returns connected wires and their number, by rebuild of the wires from the edges, looking for connections + */ + HYDRODATA_EXPORT int GetNbConnectedWires(Handle(TopTools_HSequenceOfShape)& aConnectedWires) const; + /** * Returns the distance between first and point with index thePointIndex * at the section with index theSectionIndex. -1 is returned if error is occurred. diff --git a/src/HYDROData/HYDROData_SplitToZonesTool.cxx b/src/HYDROData/HYDROData_SplitToZonesTool.cxx index f91732cd..bef3e9a2 100644 --- a/src/HYDROData/HYDROData_SplitToZonesTool.cxx +++ b/src/HYDROData/HYDROData_SplitToZonesTool.cxx @@ -347,8 +347,10 @@ HYDROData_SplitToZonesTool::SplitDataList Standard_Boolean hasLimits(Standard_False); QString aBndName; HYDROData_MapOfShape aBndView; - if (! thePolyline.IsNull()) { - const TopoDS_Wire aBndWire = TopoDS::Wire(thePolyline->GetShape()); + if (! thePolyline.IsNull()) { + Handle(TopTools_HSequenceOfShape) aConnectedWires = new TopTools_HSequenceOfShape; + int nbWires = thePolyline->GetNbConnectedWires(aConnectedWires); + const TopoDS_Wire aBndWire = TopoDS::Wire(aConnectedWires->Value(1)); if(!aBndWire.IsNull()) { TopoDS_Face limFace; if(buildLimFace(aBndWire, limFace)) { @@ -605,4 +607,4 @@ HYDROData_SplitToZonesTool::SplitDataList Handle(HYDROData_PolylineXY) aPolyline; return Split( theObjectList, aGeomGroups, aPolyline ); -} \ No newline at end of file +} diff --git a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx index b06fbb3b..0af2109b 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx @@ -110,18 +110,18 @@ void HYDROGUI_CalculationOp::startOperation() { aPolylineObj = Handle(HYDROData_PolylineXY)::DownCast( anIter.Current() ); - if ( !aPolylineObj.IsNull() && aPolylineObj->IsClosed() ) + if ( !aPolylineObj.IsNull() && aPolylineObj->IsClosed(false) ) { - // Check the polyline shape - TopoDS_Shape aPolylineShape = aPolylineObj->GetShape(); - if ( !aPolylineShape.IsNull() && aPolylineShape.ShapeType() == TopAbs_WIRE ) { +// // Check the polyline shape +// TopoDS_Shape aPolylineShape = aPolylineObj->GetShape(); +// if ( !aPolylineShape.IsNull() && aPolylineShape.ShapeType() == TopAbs_WIRE ) { aPolylineName = aPolylineObj->GetName(); if ( !aPolylineName.isEmpty() ) { aList.append( aPolylineName ); anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aPolylineObj ) ); } - } +// } } } aPanel->setPolylineNames( aList, anEntryList ); -- 2.39.2