Salome HOME
initial ver.
[modules/hydro.git] / src / HYDROData / HYDROData_LandCoverMap.cxx
index 5c1f9e39ae0bea42a7ae559d4ee391b370d975f7..c801780fd80cbb46cdd3d5aa249cecebac203bf1 100644 (file)
@@ -121,6 +121,15 @@ HYDROData_LandCoverMap::~HYDROData_LandCoverMap()
 {
 }
 
+/**
+  Get object's kind
+  @return object's kind
+*/
+const ObjectKind HYDROData_LandCoverMap::GetKind() const
+{
+  return KIND_LAND_COVER_MAP;
+}
+
 /**
   Import the land cover map from QGIS
   @param theFileName the name of file
@@ -245,7 +254,66 @@ void HYDROData_LandCoverMap::SetShape( const TopoDS_Shape& theShape )
 */
 bool HYDROData_LandCoverMap::LocalPartition( const TopoDS_Shape& theNewShape, const QString& theNewType )
 {
-  //TODO
+  BOPCol_ListOfShape aShapesList;
+  BOPAlgo_PaveFiller aPaveFiller;
+
+  // add faces to shapes list
+  Iterator anIt( *this );
+  for( ; anIt.More(); anIt.Next() )
+    aShapesList.Append( anIt.Face() );
+  aShapesList.Append( theNewShape );
+
+  // prepare pave filler
+  aPaveFiller.SetArguments( aShapesList );
+  aPaveFiller.Perform();
+  Standard_Integer anError = aPaveFiller.ErrorStatus();
+  if( anError )
+    return false;
+
+  // add faces to builder
+  BOPAlgo_Builder aBuilder;
+  anIt.Init( *this );
+  for( ; anIt.More(); anIt.Next() )
+    aBuilder.AddArgument( anIt.Face() );
+  aBuilder.AddArgument( theNewShape );
+
+  // perform the partition with the pave filler
+  aBuilder.PerformWithFiller( aPaveFiller );
+  anError = aBuilder.ErrorStatus();
+  if( anError )
+    return false;
+
+  // analysis of the history
+  BOPCol_DataMapOfShapeListOfShape aSplits = aBuilder.Splits();
+
+  //     a. fill map of shape => type for initial faces
+  HYDROData_MapOfShapeToStricklerType anOldFaces;
+  anIt.Init( *this );
+  for( ; anIt.More(); anIt.Next() )
+    anOldFaces.Add( anIt.Face(), anIt.StricklerType() );
+
+  //     b. fill map of shape => type for split faces without the new face
+  HYDROData_MapOfShapeToStricklerType aNewFaces;
+  BOPCol_DataMapOfShapeListOfShape::Iterator aSplitIt( aSplits );
+  for( ; aSplitIt.More(); aSplitIt.Next() )
+  {
+    TopoDS_Shape anInitial = aSplitIt.Key();
+    if( anInitial==theNewShape )
+      continue;
+    QString aType = anOldFaces.FindFromKey( anInitial );
+    BOPCol_ListOfShape aSplitFaces = aSplitIt.Value();
+    BOPCol_ListOfShape::Iterator aSFIt( aSplitFaces );
+    for( ; aSFIt.More(); aSFIt.Next() )
+      aNewFaces.Add( aSFIt.Value(), aType );
+  }
+
+  //     c. add the new shape if it is face with its type
+  if( theNewShape.ShapeType()==TopAbs_FACE )
+    aNewFaces.Add( theNewShape, theNewType );
+  
+  // convert map of shape to type to compound and list of types
+  StoreLandCovers( aNewFaces );
+  return true;
 }
 
 /**