From: asl Date: Wed, 14 Oct 2015 11:46:36 +0000 (+0300) Subject: #669: merge algorithm for land cover X-Git-Tag: v1.5~121 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=eac15201a2a8fcce36c87e965f9c2953239f409f;p=modules%2Fhydro.git #669: merge algorithm for land cover --- diff --git a/src/HYDROData/HYDROData_LandCoverMap.cxx b/src/HYDROData/HYDROData_LandCoverMap.cxx index f384999d..02c73ba8 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.cxx +++ b/src/HYDROData/HYDROData_LandCoverMap.cxx @@ -25,6 +25,8 @@ #include #include #include +#include +#include #include #include #include @@ -215,8 +217,19 @@ bool HYDROData_LandCoverMap::Add( const Handle( HYDROData_Object )& theObject, c */ bool HYDROData_LandCoverMap::Add( const Handle( HYDROData_PolylineXY )& thePolyline, const QString& theType ) { - //TODO - return false; + if( thePolyline.IsNull() ) + return false; + + TopoDS_Shape aShape = thePolyline->GetShape(); + if( aShape.ShapeType()!=TopAbs_WIRE ) + return false; + + TopoDS_Wire aWire = TopoDS::Wire( aShape ); + if( !aWire.Closed() ) + return false; + + TopoDS_Face aFace = BRepBuilderAPI_MakeFace( aWire, Standard_True ).Face(); + return LocalPartition( aFace, theType ); } /** @@ -233,16 +246,26 @@ bool HYDROData_LandCoverMap::Remove( const TopoDS_Face& theFace ) /** Remove the given faces from land cover map - @param theFacesList the face list to be removed + @param theFacesToRemove the face list to be removed @return if the removing is successful */ -bool HYDROData_LandCoverMap::Remove( const TopTools_ListOfShape& theFacesList ) +bool HYDROData_LandCoverMap::Remove( const TopTools_ListOfShape& theFacesToRemove ) { - TopoDS_Compound aCompound = TopoDS::Compound( GetShape() ); - BRep_Builder aCompoundBuilder; - //TODO: aCompoundBuilder.Remove( aCompound, theFace ); - //TODO: update types - SetShape( aCompound ); + HYDROData_MapOfFaceToStricklerType aFacesToRemove, aNewFaces; + TopTools_ListIteratorOfListOfShape aFIt( theFacesToRemove ); + for( ; aFIt.More(); aFIt.Next() ) + { + TopoDS_Shape aShape = aFIt.Value(); + if( aShape.ShapeType()==TopAbs_FACE ) + aFacesToRemove.Add( TopoDS::Face( aShape ), "" ); + } + + Iterator anIt( *this ); + for( ; anIt.More(); anIt.Next() ) + if( !aFacesToRemove.Contains( anIt.Face() ) ) + aNewFaces.Add( anIt.Face(), anIt.StricklerType() ); + + StoreLandCovers( aNewFaces ); return true; } @@ -272,11 +295,18 @@ bool HYDROData_LandCoverMap::Merge( const TopTools_ListOfShape& theFaces, const Remove( theFaces ); // 2. to fuse the faces into the new face - // TODO - TopoDS_Face aMergedFace; + BRepAlgoAPI_Fuse aFuse; + aFuse.SetArguments( theFaces ); + aFuse.Build(); + if( !aFuse.IsDone() ) + return false; + + TopoDS_Shape aMergedShape = aFuse.Shape(); + if( aMergedShape.ShapeType()!=TopAbs_FACE ) + return false; // 3. to add the face into the map - return LocalPartition( aMergedFace, theType ); + return LocalPartition( TopoDS::Face( aMergedShape ), theType ); } /**