+ if( theNewShape.IsNull() )
+ return false;
+
+ BOPCol_ListOfShape aShapesList;
+ BOPAlgo_PaveFiller aPaveFiller;
+ HYDROData_MapOfFaceToStricklerType aNewFaces;
+
+ // add faces to shapes list
+ Iterator anIt( *this );
+ for( ; anIt.More(); anIt.Next() )
+ aShapesList.Append( anIt.Face() );
+ aShapesList.Append( theNewShape );
+
+ if( aShapesList.Size()==1 && theNewShape.ShapeType()==TopAbs_FACE )
+ {
+ aNewFaces.Add( TopoDS::Face( theNewShape ), theNewType );
+ StoreLandCovers( aNewFaces );
+ return true;
+ }
+
+ // 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
+ // a. to fill map of shapes which come from the new face
+ NCollection_IndexedMap<TopoDS_Shape> aShapesFromNewFace;
+ //std::cout << "new: " << theNewShape << " " << theNewType << std::endl;
+ TopTools_ListOfShape aModified = aBuilder.Modified( theNewShape );
+ TopTools_ListIteratorOfListOfShape aMIt( aModified );
+ for( ; aMIt.More(); aMIt.Next() )
+ {
+ //std::cout << " " << aMIt.Value() << std::endl;
+ aShapesFromNewFace.Add( aMIt.Value() );
+ }
+
+ // b. to fill map of parts except parts from new face
+ anIt.Init( *this );
+ for( ; anIt.More(); anIt.Next() )
+ {
+ QString aSType = anIt.StricklerType();
+ //std::cout << anIt.Face() << " " << anIt.StricklerType() << std::endl;
+ TopTools_ListOfShape aModified = aBuilder.Modified( anIt.Face() );
+ TopTools_ListIteratorOfListOfShape aMIt( aModified );
+ for( ; aMIt.More(); aMIt.Next() )
+ {
+ TopoDS_Shape aShape = aMIt.Value();
+ bool isFace = aShape.ShapeType()==TopAbs_FACE;
+ bool isAlsoFromNew = aShapesFromNewFace.Contains( aShape );
+ //std::cout << " " << aShape << " " << isAlsoFromNew << std::endl;
+ if( isFace && !isAlsoFromNew )
+ aNewFaces.Add( TopoDS::Face( aShape ), aSType );
+ }
+ }
+
+ // c. add the new shape if it is face with its type
+ if( theNewShape.ShapeType()==TopAbs_FACE )
+ aNewFaces.Add( TopoDS::Face( theNewShape ), theNewType );
+
+ // convert map of shape to type to compound and list of types
+ StoreLandCovers( aNewFaces );
+ return true;
+}
+
+/**
+ Replace the set of land covers in the land cover map
+ @param theMap the map of shape (face) to Strickler type (string)
+*/
+void HYDROData_LandCoverMap::StoreLandCovers( const HYDROData_MapOfFaceToStricklerType& theMap )
+{
+ TopoDS_Shell aShell;
+ BRep_Builder aShellBuilder;
+ aShellBuilder.MakeShell( aShell );
+ aShell.Closed( Standard_False );
+ TopTools_ListOfShape aListOfFaces;
+
+ int n = theMap.Size();
+ Handle( TDataStd_ExtStringArray ) aTypes =
+ TDataStd_ExtStringArray::Set( myLab.FindChild( DataTag_Types ), 0, n-1, Standard_True );
+ HYDROData_MapOfFaceToStricklerType::Iterator aNFIt( theMap );
+ for( int i=0; aNFIt.More(); aNFIt.Next(), i++ )
+ {
+ TopoDS_Face aFace = aNFIt.Key();
+ if (aFace.IsNull())
+ continue;
+ QString aType = aNFIt.Value();
+ aShellBuilder.Add( aShell, aFace );
+ aListOfFaces.Append(aFace);
+ aTypes->SetValue( i, HYDROData_Tool::toExtString( aType ) );
+ }
+ TopoDS_Shape aMF = MergeFaces(aListOfFaces, false);
+
+ SetShape( aListOfFaces.Extent() < 2 ? aShell : MergeFaces(aListOfFaces, false));
+}
+
+/**
+ Find the land cover for the given point
+ @param thePoint the point laying in some land cover
+ @param theType the returned type
+ @return the found land cover's face
+*/
+TopoDS_Face HYDROData_LandCoverMap::FindByPoint( const gp_Pnt2d& thePoint, QString& theType ) const
+{
+ //TODO: some more optimal algorithm
+ Iterator anIt( *this );
+ for( ; anIt.More(); anIt.Next() )
+ if( HYDROData_Tool::ComputePointState( thePoint.XY(), anIt.Face() ) == TopAbs_IN )
+ {
+ theType = anIt.StricklerType();
+ return anIt.Face();
+ }
+
+ theType = "";
+ return TopoDS_Face();
+}
+
+/**
+ Dump to Python
+ @param theTreatedObjects the map of treated objects
+*/
+QStringList HYDROData_LandCoverMap::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
+{
+ QStringList aResList = dumpObjectCreation( theTreatedObjects );
+ QString aName = GetObjPyName();
+
+ //Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
+ //setPythonReferenceObject( theTreatedObjects, aResList, aHydAxis, "SetHydraulicAxis" );
+
+ //HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
+ //for ( int i = 1, aNb = aSeqOfProfiles.Size(); i <= aNb; ++i )
+ //{
+ //const Handle(HYDROData_Entity) aProfile = aSeqOfProfiles.Value( i );
+ //setPythonReferenceObject( theTreatedObjects, aResList, aProfile, "AddProfile" );
+ //}
+