From: mzn Date: Mon, 22 Jun 2015 11:15:42 +0000 (+0300) Subject: refs #567: HYDROData_LandCover::buildShape() method returns the error message now. X-Git-Tag: v1.4.2~35^2~7 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=7db42f76ecf6f5409a591f2b64882e8f0d9dcdd5;p=modules%2Fhydro.git refs #567: HYDROData_LandCover::buildShape() method returns the error message now. --- diff --git a/src/HYDROData/HYDROData_LandCover.cxx b/src/HYDROData/HYDROData_LandCover.cxx index b588c1fa..815bc3b5 100644 --- a/src/HYDROData/HYDROData_LandCover.cxx +++ b/src/HYDROData/HYDROData_LandCover.cxx @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -120,7 +121,8 @@ void HYDROData_LandCover::Update() removeShape(); - TopoDS_Shape aResShape = buildShape(); + TCollection_AsciiString anErrorMsg; + TopoDS_Shape aResShape = buildShape( GetPolylines(), anErrorMsg ); setShape( aResShape ); } @@ -196,42 +198,62 @@ void HYDROData_LandCover::removeShape() } } -TopoDS_Shape HYDROData_LandCover::buildShape() const +TopoDS_Shape HYDROData_LandCover::buildShape( const HYDROData_SequenceOfObjects& thePolylines, + TCollection_AsciiString& theErrorMsg ) { + theErrorMsg.Clear(); TopoDS_Shape aResShape; BRepBuilderAPI_MakeWire aMakeWire; TopTools_ListOfShape aClosedWires; - HYDROData_SequenceOfObjects aRefPolylines = GetPolylines(); - for ( int i = 1, n = aRefPolylines.Length(); i <= n; ++i ) { + int aNbPolylines = thePolylines.Length(); + for ( int i = 1; i <= aNbPolylines; ++i ) { Handle(HYDROData_PolylineXY) aPolyline = - Handle(HYDROData_PolylineXY)::DownCast( aRefPolylines.Value( i ) ); + Handle(HYDROData_PolylineXY)::DownCast( thePolylines.Value( i ) ); if ( aPolyline.IsNull() ) { continue; } TopoDS_Shape aPolyShape = aPolyline->GetShape(); - if ( aPolyShape.IsNull() || aPolyShape.ShapeType() != TopAbs_WIRE ) { + if ( aPolyShape.IsNull() ) { continue; } - const TopoDS_Wire& aPolylineWire = TopoDS::Wire( aPolyShape ); - if ( aPolylineWire.IsNull() ) { - continue; + // Extract polyline wire(s) + TopTools_ListOfShape aPolylineWires; + + if ( aPolyShape.ShapeType() == TopAbs_WIRE ) { + const TopoDS_Wire& aPolylineWire = TopoDS::Wire( aPolyShape ); + if ( !aPolylineWire.IsNull() ) { + aPolylineWires.Append( aPolylineWire ); + } + } else if ( aPolyShape.ShapeType() == TopAbs_COMPOUND ) { + TopExp_Explorer anExp( aPolyShape, TopAbs_WIRE ); + for (; anExp.More(); anExp.Next() ) { + if(!anExp.Current().IsNull()) { + const TopoDS_Wire& aWire = TopoDS::Wire( anExp.Current() ); + aPolylineWires.Append( aWire ); + } + } } - - if ( aPolylineWire.Closed() ) { - aClosedWires.Append( aPolylineWire ); - } else { - aMakeWire.Add( aPolylineWire ); - aMakeWire.Build(); - if ( aMakeWire.IsDone() ) { - if ( aMakeWire.Wire().Closed() ) { - aClosedWires.Append( aMakeWire.Wire() ); - aMakeWire = BRepBuilderAPI_MakeWire(); + + TopTools_ListIteratorOfListOfShape anIt( aPolylineWires ); + for ( ; anIt.More(); anIt.Next() ) { + TopoDS_Wire& aWire = TopoDS::Wire( anIt.Value() ); + + if ( aWire.Closed() ) { + aClosedWires.Append( aWire ); + } else { + aMakeWire.Add( aWire ); + aMakeWire.Build(); + if ( aMakeWire.IsDone() ) { + if ( aMakeWire.Wire().Closed() ) { + aClosedWires.Append( aMakeWire.Wire() ); + aMakeWire = BRepBuilderAPI_MakeWire(); + } } } } @@ -260,6 +282,10 @@ TopoDS_Shape HYDROData_LandCover::buildShape() const } aResShape = aCompound; + } else if ( aNbPolylines > 0 ) { + TCollection_AsciiString aSourceName = aNbPolylines > 1 ? "polylines" : "polyline"; + theErrorMsg = "Can't build closed contour on the given "; + theErrorMsg += aSourceName; } ///< \TODO to be reimplemented diff --git a/src/HYDROData/HYDROData_LandCover.h b/src/HYDROData/HYDROData_LandCover.h index 3bba4a9e..398d6cdd 100644 --- a/src/HYDROData/HYDROData_LandCover.h +++ b/src/HYDROData/HYDROData_LandCover.h @@ -126,6 +126,12 @@ public: */ HYDRODATA_EXPORT static QColor DefaultBorderColor(); + /** + * Build the shape presentation of the land cover. + */ + HYDRODATA_EXPORT static TopoDS_Shape buildShape( const HYDROData_SequenceOfObjects& thePolylines, + TCollection_AsciiString& theErrorMsg ); + protected: /** * Sets the shape presentation of the land cover. @@ -136,11 +142,6 @@ protected: * Removes the shape from data label of the land cover object. */ HYDRODATA_EXPORT virtual void removeShape(); - - /** - * Build the shape presentation of the land cover. - */ - HYDRODATA_EXPORT virtual TopoDS_Shape buildShape() const; }; #endif diff --git a/src/HYDROGUI/HYDROGUI_LandCoverOp.cxx b/src/HYDROGUI/HYDROGUI_LandCoverOp.cxx index 5240b42d..00b32548 100644 --- a/src/HYDROGUI/HYDROGUI_LandCoverOp.cxx +++ b/src/HYDROGUI/HYDROGUI_LandCoverOp.cxx @@ -189,17 +189,25 @@ bool HYDROGUI_LandCoverOp::processApply( int& theUpdateFlags, } } + if ( aZonePolylines.IsEmpty() ) + { + theErrorMsg = tr( "POLYLINES_NOT_DEFINED" ); + return false; + } + QString aSelectedStricklerType = aPanel->getSelectedAdditionalParamName(); - // TODO: Generate TopoDS_Shape based on the set of polylines, implement generateTopShape data model method - /* - if ( HYDROData_LandCover::generateTopShape( aZonePolylines ).IsNull() ) + TCollection_AsciiString anError; + if ( HYDROData_LandCover::buildShape( aZonePolylines, anError ).IsNull() ) { - theErrorMsg = tr( "ZONE_OBJECT_CANNOT_BE_CREATED" ); + if ( !anError.IsEmpty() ) { + theErrorMsg = HYDROGUI_Tool::ToQString( anError ); + } else { + theErrorMsg = tr( "LAND_COVER_OBJECT_CANNOT_BE_CREATED" ); + } return false; } - */ - + Handle(HYDROData_LandCover) aZoneObj = myIsEdit ? myEditedObject : Handle(HYDROData_LandCover)::DownCast( doc()->CreateObject( KIND_LAND_COVER ) ); diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index c464bb86..c8eb087d 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -2370,7 +2370,7 @@ file cannot be correctly imported for an Obstacle definition. AXIS_NOT_DEFINED - Hydraulic axis is not defiled. + Hydraulic axis is not defined. PROFILES_NOT_DEFINED @@ -2599,6 +2599,14 @@ Polyline should consist from one not closed curve. CONFIRM_LAND_COVER_RECALCULATION Land cover object already exists and will be recalculated after polylines list modification. Do you confirm the recalculation? + + POLYLINES_NOT_DEFINED + At least 1 polyline should be defined. + + + LAND_COVER_OBJECT_CANNOT_BE_CREATED + Land Cover object can not be created +