]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
#669: merge algorithm for land cover
authorasl <asl@opencascade.com>
Wed, 14 Oct 2015 11:46:36 +0000 (14:46 +0300)
committerasl <asl@opencascade.com>
Wed, 14 Oct 2015 11:46:36 +0000 (14:46 +0300)
src/HYDROData/HYDROData_LandCoverMap.cxx

index f384999d11989ae221cc289c50543da1c91bb8d3..02c73ba80cb2fd315c7340c545074bf153ecf11a 100644 (file)
@@ -25,6 +25,8 @@
 #include <BOPAlgo_PaveFiller.hxx>
 #include <BOPCol_ListOfShape.hxx>
 #include <BRep_Builder.hxx>
+#include <BRepAlgoAPI_Fuse.hxx>
+#include <BRepBuilderAPI_MakeFace.hxx>
 #include <NCollection_IndexedMap.hxx>
 #include <TNaming_Builder.hxx>
 #include <TNaming_NamedShape.hxx>
@@ -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 );
 }
 
 /**