1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include <HYDROData_LandCoverMap.h>
20 #include <HYDROData_Object.h>
21 #include <HYDROData_PolylineXY.h>
22 #include <HYDROData_Tool.h>
23 #include <HYDROData_ShapeFile.h>
25 #include <BOPAlgo_BOP.hxx>
26 #include <BOPAlgo_Builder.hxx>
27 #include <BOPAlgo_PaveFiller.hxx>
28 #include <BOPCol_ListOfShape.hxx>
29 #include <BRep_Builder.hxx>
30 #include <BRepAdaptor_Curve.hxx>
31 #include <BRepAlgoAPI_Fuse.hxx>
32 #include <BRepBuilderAPI_MakeFace.hxx>
33 #include <GCPnts_QuasiUniformDeflection.hxx>
35 #include <TopoDS_Compound.hxx>
36 #include <TopoDS_Edge.hxx>
37 #include <TopoDS_Face.hxx>
38 #include <TopoDS_Iterator.hxx>
39 #include <TopoDS_Shell.hxx>
40 #include <TopExp_Explorer.hxx>
41 #include <TopTools_ListIteratorOfListOfShape.hxx>
42 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
43 #include <BOPAlgo_PaveFiller.hxx>
44 #include <BRepTools.hxx>
45 #include <TopExp_Explorer.hxx>
46 #include <ShapeUpgrade_UnifySameDomain.hxx>
48 #include <TopTools_IndexedMapOfShape.hxx>
49 #include <ShapeBuild_ReShape.hxx>
50 #include <ShapeFix_Shape.hxx>
51 #include <BRepCheck_Shell.hxx>
52 #include <BRepCheck_ListOfStatus.hxx>
57 #include <QTextStream>
59 const char TELEMAC_FORMAT = 'f';
60 const int TELEMAC_PRECISION = 3;
63 IMPLEMENT_STANDARD_HANDLE(HYDROData_LandCoverMap, HYDROData_Entity)
64 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_LandCoverMap, HYDROData_Entity)
68 @param theMap the land cover map to iterate through
70 HYDROData_LandCoverMap::Explorer::Explorer( const HYDROData_LandCoverMap& theMap )
75 HYDROData_LandCoverMap::Explorer::Explorer( const Handle( HYDROData_LandCoverMap )& theMap )
87 Initialize the iterator
88 @param theMap the land cover map to iterate through
90 void HYDROData_LandCoverMap::Explorer::Init( const HYDROData_LandCoverMap& theMap )
92 TopoDS_Shape aShape = theMap.GetShape();
97 myExplorer = new TopExp_Explorer();
98 myExplorer->Init( aShape, TopAbs_FACE );
101 theMap.myLab.FindChild( DataTag_Types ).FindAttribute( TDataStd_ExtStringArray::GetID(), myArray );
102 if( myArray.IsNull() )
105 myIndex = myArray->Lower();
111 HYDROData_LandCoverMap::Explorer::~Explorer()
117 Return the current 0-based index of the iterator
118 @return the current index
120 int HYDROData_LandCoverMap::Explorer::Index() const
122 if( myArray.IsNull() )
125 return myIndex - myArray->Lower();
129 Return if the iterator has more elements
130 @return if the iterator has more elements
132 bool HYDROData_LandCoverMap::Explorer::More() const
134 return !myArray.IsNull() && myExplorer && myExplorer->More();
138 Move iterator to the next element
140 void HYDROData_LandCoverMap::Explorer::Next()
150 Get the current land cover (face)
151 @return the land cover's face
153 TopoDS_Face HYDROData_LandCoverMap::Explorer::Face() const
156 return TopoDS::Face( myExplorer->Current() );
158 return TopoDS_Face();
162 Get the current land cover's Strickler type
163 @return the land cover's Strickler type
165 QString HYDROData_LandCoverMap::Explorer::StricklerType() const
167 if( myArray.IsNull() || myIndex < myArray->Lower() || myIndex > myArray->Upper() )
170 return HYDROData_Tool::toQString( myArray->Value( myIndex ) );
174 Set the Strickler type for the current land cover
175 @param theType the Strickler type
177 void HYDROData_LandCoverMap::Explorer::SetStricklerType( const QString& theType )
179 if( myArray.IsNull() || myIndex < myArray->Lower() || myIndex > myArray->Upper() )
182 myArray->SetValue( myIndex, HYDROData_Tool::toExtString( theType ) );
188 HYDROData_LandCoverMap::HYDROData_LandCoverMap()
189 : HYDROData_Entity( Geom_No )
196 HYDROData_LandCoverMap::~HYDROData_LandCoverMap()
202 @return object's kind
204 const ObjectKind HYDROData_LandCoverMap::GetKind() const
206 return KIND_LAND_COVER_MAP;
209 int HYDROData_LandCoverMap::GetLCCount() const
211 Explorer anIt( *this );
213 for( ; anIt.More(); anIt.Next() )
218 bool HYDROData_LandCoverMap::IsEmpty() const
220 Explorer anIt( *this );
228 Load attributes from DBF File
231 HYDROData_LandCoverMap::DBFStatus HYDROData_LandCoverMap::ImportDBF( const QString& theDBFFileName,
232 const QString& theFieldName,
233 const QStringList& theDBFValues,
234 const QStringList& theStricklerTypes,
235 const QList<int>& theIndices )
237 if (theDBFValues.size() != theStricklerTypes.size())
238 return DBFStatus_DIFF_SIZE_ERROR;
239 HYDROData_ShapeFile aDBFImporter;
240 if (!aDBFImporter.DBF_OpenDBF(theDBFFileName))
241 return DBFStatus_OPEN_FILE_ERROR; //cant open file
243 QStringList FieldList = aDBFImporter.DBF_GetFieldList();
244 int FieldNameIndex = FieldList.indexOf(theFieldName);
245 if (FieldNameIndex == -1)
246 return DBFStatus_NO_SUCH_FIELD_ERROR; //no such field
248 std::vector<HYDROData_ShapeFile::DBF_AttrValue> theAttrV;
249 aDBFImporter.DBF_GetAttributeList(FieldNameIndex, theAttrV );
252 Explorer anIt( *this );
253 for( ; anIt.More(); anIt.Next() )
255 int CurIndex = anIt.Index();
256 HYDROData_ShapeFile::DBF_AttrValue AValue = theAttrV[theIndices[CurIndex]];
257 int StricklerTypesInd = theDBFValues.indexOf(QString(AValue.myStrVal));
258 if ( StricklerTypesInd != -1)
259 anIt.SetStricklerType(theStricklerTypes[StricklerTypesInd]);
266 return DBFStatus_NO_DBFVALUES_CORRESPONDENCE_WARNING;
270 Export attributes to DBF File
273 void HYDROData_LandCoverMap::ExportDBF( const QString& theDBFFileName,
274 const QString& theFieldName,
275 const QStringList& theDBFValues,
276 const QStringList& theStricklerTypes) const
278 if (theDBFValues.size() != theStricklerTypes.size())
280 HYDROData_ShapeFile anExporter;
281 std::vector<HYDROData_ShapeFile::DBF_AttrValue> theAttrV;
282 Explorer anIt( *this );
283 for( ; anIt.More(); anIt.Next() )
285 QString CurST = anIt.StricklerType();
286 HYDROData_ShapeFile::DBF_AttrValue aCurAttrV;
287 aCurAttrV.myIsNull = false;
288 int StricklerTypesInd = theStricklerTypes.indexOf(CurST);
289 if (StricklerTypesInd != -1)
291 aCurAttrV.myStrVal = theDBFValues[StricklerTypesInd];
292 aCurAttrV.myFieldType = HYDROData_ShapeFile::DBF_FieldType_String;
293 theAttrV.push_back(aCurAttrV);
296 aCurAttrV.myIsNull = true;
298 //use actual str value; not the raw value
299 anExporter.DBF_WriteFieldAndValues(theDBFFileName, theFieldName, HYDROData_ShapeFile::DBF_FieldType_String, theAttrV, false);
303 int HashCode( const gp_Pnt& thePoint, const Standard_Integer theUpper )
305 int aHashX = HashCode( thePoint.X(), theUpper );
306 int aHashY = HashCode( thePoint.Y(), theUpper );
307 return (aHashX^aHashY)%theUpper;
310 bool operator == ( const gp_Pnt& thePoint1, const gp_Pnt& thePoint2 )
312 return thePoint1.IsEqual( thePoint2, Precision::Confusion() );
315 bool EdgeDiscretization( const TopoDS_Edge& theEdge,
316 Standard_Real theDeflection,
317 NCollection_IndexedMap<gp_Pnt>& theVerticesMap,
318 QList<int>& theVerticesIds )
320 BRepAdaptor_Curve aCurve( theEdge );
321 GCPnts_QuasiUniformDeflection aDiscrete( aCurve, theDeflection );
322 if( !aDiscrete.IsDone() )
325 int n = aDiscrete.NbPoints();
326 for( int i=1; i<=n; i++ )
328 gp_Pnt aPnt = aDiscrete.Value( i );
330 if( theVerticesMap.Contains( aPnt ) )
331 anId = theVerticesMap.FindIndex( aPnt );
334 anId = theVerticesMap.Size();
335 theVerticesMap.Add( aPnt );
337 theVerticesIds.append( anId );
343 Export the land cover map for the solver (Telemac)
344 @param theFileName the name of file
345 @return if the export is successful
347 bool HYDROData_LandCoverMap::ExportTelemac( const QString& theFileName, Standard_Real theDeflection ) const
349 TopoDS_Shape aLandCoverMapShape = GetShape();
350 TopTools_ListOfShape aListOfFaces;
351 TopExp_Explorer anExp( aLandCoverMapShape, TopAbs_FACE );
352 for( ; anExp.More(); anExp.Next() )
353 aListOfFaces.Append( anExp.Current() );
355 TopoDS_Shape aShape = MergeFaces( aListOfFaces, false );
357 NCollection_IndexedMap<gp_Pnt> aVerticesMap;
358 NCollection_IndexedDataMap< TopoDS_Edge, QList<int> > anEdgesMap;
359 NCollection_IndexedDataMap< TopoDS_Face, QList<int> > aFacesMap;
361 // add into the map all edges existing in the shell
362 TopExp_Explorer anExp1( aShape, TopAbs_EDGE );
363 for( ; anExp1.More(); anExp1.Next() )
365 TopoDS_Edge anEdge = TopoDS::Edge( anExp1.Current() );
366 QList<int> aVerticesIdsList;
367 if( EdgeDiscretization( anEdge, theDeflection, aVerticesMap, aVerticesIdsList ) )
368 anEdgesMap.Add( anEdge, aVerticesIdsList );
371 // add into the map all faces existing in the shell and correspondence between face and edges ids
372 TopExp_Explorer anExp2( aShape, TopAbs_FACE );
373 for( ; anExp2.More(); anExp2.Next() )
375 TopoDS_Face aFace = TopoDS::Face( anExp2.Current() );
376 TopExp_Explorer anExp3( aFace, TopAbs_EDGE );
377 QList<int> anEdgesIdsList;
378 for( ; anExp3.More(); anExp3.Next() )
380 TopoDS_Edge anEdge = TopoDS::Edge( anExp3.Current() );
381 int anEdgeId = anEdgesMap.FindIndex( anEdge );
382 anEdgesIdsList.append( anEdgeId );
384 aFacesMap.Add( aFace, anEdgesIdsList );
387 QFile aFile( theFileName );
388 if( !aFile.open( QFile::WriteOnly | QFile::Text ) )
391 QTextStream aStream( &aFile );
392 aStream << "# nodes\n";
393 NCollection_IndexedMap<gp_Pnt>::Iterator anIt1( aVerticesMap );
394 for( ; anIt1.More(); anIt1.Next() )
396 gp_Pnt aPnt = anIt1.Value();
397 aStream << QString::number( aPnt.X(), TELEMAC_FORMAT, TELEMAC_PRECISION );
399 aStream << QString::number( aPnt.Y(), TELEMAC_FORMAT, TELEMAC_PRECISION );
401 aStream << QString::number( aPnt.Z(), TELEMAC_FORMAT, TELEMAC_PRECISION );
406 aStream << "# edges\n";
407 NCollection_IndexedDataMap< TopoDS_Edge, QList<int> >::Iterator anIt2( anEdgesMap );
408 for( ; anIt2.More(); anIt2.Next() )
410 QList<int> aVerticesIds = anIt2.Value();
411 foreach( int anId, aVerticesIds )
412 aStream << anId << " ";
417 aStream << "# faces\n";
418 NCollection_IndexedDataMap< TopoDS_Face, QList<int> >::Iterator anIt3( aFacesMap );
419 for( ; anIt3.More(); anIt3.Next() )
421 QList<int> anEdgesIds = anIt3.Value();
422 foreach( int anId, anEdgesIds )
423 aStream << anId << " ";
433 Add a new object as land cover
434 @param theObject the object to add as land cover
435 @param theType the Strickler type for the new land cover
436 @return if the addition is successful
438 bool HYDROData_LandCoverMap::Add( const Handle( HYDROData_Object )& theObject, const QString& theType )
440 if( theObject.IsNull() )
443 TopoDS_Shape aShape = theObject->GetTopShape();
444 if( aShape.ShapeType()!=TopAbs_FACE )
447 TopoDS_Face aFace = TopoDS::Face( aShape );
448 return LocalPartition( aFace, theType );
451 bool HYDROData_LandCoverMap::Add( const TopoDS_Wire& theWire, const QString& theType )
453 if( !theWire.Closed() )
456 TopoDS_Face aFace = BRepBuilderAPI_MakeFace( theWire, Standard_True ).Face();
457 return LocalPartition( aFace, theType );
461 Add a new polyline as land cover
462 @param thePolyline the polyline to add as land cover
463 @param theType the Strickler type for the new land cover
464 @return if the addition is successful
466 bool HYDROData_LandCoverMap::Add( const Handle( HYDROData_PolylineXY )& thePolyline, const QString& theType )
468 if( thePolyline.IsNull() )
471 TopoDS_Shape aShape = thePolyline->GetShape();
472 if( aShape.ShapeType()==TopAbs_WIRE )
473 return Add( TopoDS::Wire( aShape ), theType );
475 if( aShape.ShapeType()==TopAbs_COMPOUND )
477 TopExp_Explorer anExp( aShape, TopAbs_WIRE );
478 for( ; anExp.More(); anExp.Next() )
480 TopoDS_Wire aPart = TopoDS::Wire( anExp.Current() );
481 if( !Add( aPart, theType ) )
491 Remove the given face from land cover map
492 @param theFace the face to be removed
493 @return if the removing is successful
495 bool HYDROData_LandCoverMap::Remove( const TopoDS_Face& theFace )
497 TopTools_ListOfShape aList;
498 aList.Append( theFace );
499 return Remove( aList );
503 Remove the given faces from land cover map
504 @param theFacesToRemove the face list to be removed
505 @return if the removing is successful
507 bool HYDROData_LandCoverMap::Remove( const TopTools_ListOfShape& theFacesToRemove )
509 HYDROData_MapOfFaceToStricklerType aFacesToRemove, aNewFaces;
510 TopTools_ListIteratorOfListOfShape aFIt( theFacesToRemove );
511 for( ; aFIt.More(); aFIt.Next() )
513 TopoDS_Shape aShape = aFIt.Value();
514 if( aShape.ShapeType()==TopAbs_FACE )
515 aFacesToRemove.Add( TopoDS::Face( aShape ), "" );
518 Explorer anIt( *this );
519 for( ; anIt.More(); anIt.Next() )
520 if( !aFacesToRemove.Contains( anIt.Face() ) )
521 aNewFaces.Add( anIt.Face(), anIt.StricklerType() );
523 if ( aNewFaces.IsEmpty() )
526 StoreLandCovers( aNewFaces );
531 Split the land cover map by the given polyline
532 @param thePolyline the tool polyline to split the land cover map
533 @return if the removing is successful
535 bool HYDROData_LandCoverMap::Split( const Handle( HYDROData_PolylineXY )& thePolyline )
537 if( thePolyline.IsNull() )
540 TopoDS_Shape aShape = thePolyline->GetShape();
541 return Split( aShape );
546 Split the land cover map by the given polyline
547 @param theShape the tool polyline to split the land cover map
548 @return if the removing is successful
550 bool HYDROData_LandCoverMap::Split( const TopoDS_Shape& theShape )
552 return LocalPartition( theShape, "" );
557 Merge the given faces in the land cover
558 @param theFaces the faces to merge in the land cover map
559 @param theType the Strickler type for the merged land cover
560 @return if the merge is successful
562 bool HYDROData_LandCoverMap::Merge( const TopTools_ListOfShape& theFaces, const QString& theType )
564 // 1. to fuse the faces into the new face
565 TopoDS_Shape aMergedFace = MergeFaces( theFaces, true );
566 if( !aMergedFace.IsNull() && aMergedFace.ShapeType()==TopAbs_FACE )
568 // 2. to remove the merged faces from the current map
571 // 3. to add the face into the map
572 return LocalPartition( TopoDS::Face( aMergedFace ), theType );
578 Merge the given faces into the shell/face
579 @param theFaces the faces to merge
580 @param IsToUnify if the common edges should be removed (fused)
581 @param theTolerance the operation's tolerance
582 @return result shape (face or shell)
584 TopoDS_Shape HYDROData_LandCoverMap::MergeFaces( const TopTools_ListOfShape& theFaces,
585 bool IsToUnify, double theTolerance )
588 TopTools_ListIteratorOfListOfShape anIt;
589 BOPCol_ListOfShape aLC;
590 anIt.Initialize(theFaces);
591 for( ; anIt.More(); anIt.Next() )
593 if (anIt.Value().ShapeType() != TopAbs_FACE)
594 return TopoDS_Shape();
595 aLC.Append( anIt.Value() );
598 BOPAlgo_PaveFiller aPF;
599 aPF.SetArguments( aLC );
600 aPF.SetRunParallel( Standard_False );
601 aPF.SetFuzzyValue( theTolerance );
604 anError = aPF.ErrorStatus();
606 return TopoDS_Shape();
608 BOPAlgo_Builder anAlgo;
609 anIt.Initialize( theFaces );
610 for( ; anIt.More(); anIt.Next() )
611 anAlgo.AddArgument( anIt.Value() );
613 anAlgo.PerformWithFiller( aPF );
614 anError = anAlgo.ErrorStatus();
616 return TopoDS_Shape();
618 const TopoDS_Shape& aMergedShape = anAlgo.Shape();
620 BRep_Builder aBuilder;
622 aBuilder.MakeShell( aShell );
623 aShell.Closed( Standard_False );
624 TopExp_Explorer anExplorer( aMergedShape, TopAbs_FACE );
625 for( ; anExplorer.More(); anExplorer.Next() )
627 const TopoDS_Face& aFace = TopoDS::Face(anExplorer.Current());
630 if( aFace.ShapeType() == TopAbs_FACE )
632 aBuilder.Add( aShell, aFace );
633 aShell.Closed( Standard_False );
637 TopoDS_Shape aResult;
640 ShapeUpgrade_UnifySameDomain aUSD;
641 aUSD.Initialize( aShell );
643 aResult = aUSD.Shape();
648 anExplorer.Init( aResult, TopAbs_FACE );
650 TopoDS_Face anOneFace;
651 for( ; anExplorer.More(); anExplorer.Next(), n++ )
652 anOneFace = TopoDS::Face( anExplorer.Current() );
656 else if (aResult.ShapeType() == TopAbs_SHELL)
658 BRepCheck_Shell aBCS(TopoDS::Shell(aResult));
659 if (aBCS.Status().First() != BRepCheck_NoError)
661 ShapeFix_Shell aFixer;
662 aFixer.FixFaceOrientation(TopoDS::Shell(aResult), 1);
663 aResult = aFixer.Shape();
671 Change Strickler type for the list of faces to the given one
672 @param theFaces the faces to change type
673 @param theType the Strickler type for the given land cover(s)
674 @return if the change type operation is successful
676 bool HYDROData_LandCoverMap::ChangeType( const TopTools_ListOfShape& theFaces, const QString& theType )
678 HYDROData_MapOfFaceToStricklerType aFacesToChangeType;
679 TopTools_ListIteratorOfListOfShape aFIt( theFaces );
680 for( ; aFIt.More(); aFIt.Next() )
682 TopoDS_Shape aShape = aFIt.Value();
683 if( aShape.ShapeType()==TopAbs_FACE )
684 aFacesToChangeType.Add( TopoDS::Face( aShape ), "" );
688 Explorer anIt( *this );
689 for( ; anIt.More(); anIt.Next() )
690 if( aFacesToChangeType.Contains( anIt.Face() ) )
692 anIt.SetStricklerType( theType );
695 if ( aNbChanges != theFaces.Extent() )
702 Get the shape of the land cover map
704 TopoDS_Shape HYDROData_LandCoverMap::GetShape() const
706 return HYDROData_Entity::GetShape( DataTag_Shape );
710 Get Strickler type of the given land cover
711 @param theLandCover the land cover to get Strickler type of
712 @return name of Strickler type
714 QString HYDROData_LandCoverMap::StricklerType( const TopoDS_Face& theLandCover ) const
718 Explorer anIt( *this );
719 for( ; anIt.More(); anIt.Next() )
720 if( anIt.Face().IsEqual( theLandCover) )
722 aType = anIt.StricklerType();
730 Set the shape of the land cover map
731 @param theShape the new shape for the land cover map
733 void HYDROData_LandCoverMap::SetShape( const TopoDS_Shape& theShape )
735 HYDROData_Entity::SetShape( DataTag_Shape, theShape );
739 Perform the local partition algorithm on the land cover
740 @param theNewShape the new shape to add into the land cover
741 @param theNewType the new Strickler type for the new land cover
742 @return if the local partition is successful
744 bool HYDROData_LandCoverMap::LocalPartition( const TopoDS_Shape& theNewShape, const QString& theNewType )
746 if( theNewShape.IsNull() )
749 BOPCol_ListOfShape aShapesList;
750 BOPAlgo_PaveFiller aPaveFiller;
751 HYDROData_MapOfFaceToStricklerType aNewFaces;
753 // add faces to shapes list
754 Explorer anIt( *this );
755 for( ; anIt.More(); anIt.Next() )
756 aShapesList.Append( anIt.Face() );
757 aShapesList.Append( theNewShape );
759 if( aShapesList.Size()==1 && theNewShape.ShapeType()==TopAbs_FACE )
761 aNewFaces.Add( TopoDS::Face( theNewShape ), theNewType );
762 StoreLandCovers( aNewFaces );
766 // prepare pave filler
767 aPaveFiller.SetArguments( aShapesList );
768 aPaveFiller.Perform();
769 Standard_Integer anError = aPaveFiller.ErrorStatus();
773 // add faces to builder
774 BOPAlgo_Builder aBuilder;
776 for( ; anIt.More(); anIt.Next() )
777 aBuilder.AddArgument( anIt.Face() );
778 aBuilder.AddArgument( theNewShape );
780 // perform the partition with the pave filler
781 aBuilder.PerformWithFiller( aPaveFiller );
782 anError = aBuilder.ErrorStatus();
786 //std::cout << "History:" << std::endl;
787 // analysis of the history
788 // a. to fill map of shapes which come from the new face
789 NCollection_IndexedMap<int> aShapesFromNewFace;
790 //std::cout << "from NEW " << theNewShape << ":" << theNewType << std::endl;
791 TopTools_ListOfShape aModified = aBuilder.Modified( theNewShape );
792 TopTools_ListIteratorOfListOfShape aMIt( aModified );
793 for( ; aMIt.More(); aMIt.Next() )
795 //std::cout << " " << aMIt.Value() << std::endl;
796 int aKey = (int)(uintptr_t)aMIt.Value().TShape().operator->();
797 aShapesFromNewFace.Add( aKey );
800 // b. to fill map of parts except parts from new face
802 for( ; anIt.More(); anIt.Next() )
804 QString aSType = anIt.StricklerType();
805 //std::cout << "from " << anIt.Face() << ": " << anIt.StricklerType() << std::endl;
806 TopTools_ListOfShape aModified = aBuilder.Modified( anIt.Face() );
807 if( aModified.Extent() == 0 )
808 aModified.Append( anIt.Face() );
810 TopTools_ListIteratorOfListOfShape aMIt( aModified );
811 for( ; aMIt.More(); aMIt.Next() )
813 TopoDS_Shape aShape = aMIt.Value();
814 bool isFace = aShape.ShapeType()==TopAbs_FACE;
815 int aKey = (int)(uintptr_t)aShape.TShape().operator->();
816 bool isAlsoFromNew = aShapesFromNewFace.Contains( aKey );
817 //std::cout << " " << aShape << " " << isAlsoFromNew << std::endl;
818 if( isFace && !isAlsoFromNew )
819 aNewFaces.Add( TopoDS::Face( aShape ), aSType );
823 // c. add the new shape if it is face with its type
824 if( theNewShape.ShapeType()==TopAbs_FACE )
825 aNewFaces.Add( TopoDS::Face( theNewShape ), theNewType );
827 // convert map of shape to type to compound and list of types
828 StoreLandCovers( aNewFaces );
833 Replace the set of land covers in the land cover map
834 @param theMap the map of shape (face) to Strickler type (string)
836 void HYDROData_LandCoverMap::StoreLandCovers( const HYDROData_MapOfFaceToStricklerType& theMap )
838 TopTools_ListOfShape aListOfFaces;
840 int n = theMap.Size();
842 Handle( TDataStd_ExtStringArray ) aTypes =
843 TDataStd_ExtStringArray::Set( myLab.FindChild( DataTag_Types ), 0, n-1, Standard_True );
845 HYDROData_MapOfFaceToStricklerType::Iterator aNFIt( theMap );
846 for( int i=0; aNFIt.More(); aNFIt.Next(), i++ )
848 TopoDS_Face aFace = aNFIt.Key();
851 QString aType = aNFIt.Value();
852 aListOfFaces.Append(aFace);
853 aTypes->SetValue( i, HYDROData_Tool::toExtString( aType ) );
856 TopoDS_Shape aResult;
857 if( aListOfFaces.Extent() == 1 )
859 /*TopoDS_Shell aShell;
860 BRep_Builder aShellBuilder;
861 aShellBuilder.MakeShell( aShell );
862 aShell.Closed( Standard_False );
863 aShellBuilder.Add( aShell, aListOfFaces.First() );*/
864 aResult = aListOfFaces.First(); //aShell;
866 else if( aListOfFaces.Extent() > 1 )
867 aResult = MergeFaces( aListOfFaces, false );
869 //remove internal edges
870 aResult = RemoveInternal(aResult);
875 Find the land cover for the given point
876 @param thePoint the point laying in some land cover
877 @param theType the returned type
878 @return the found land cover's face
880 TopoDS_Face HYDROData_LandCoverMap::FindByPoint( const gp_Pnt2d& thePoint, QString& theType ) const
882 //TODO: some more optimal algorithm
883 Explorer anIt( *this );
884 for( ; anIt.More(); anIt.Next() )
885 if( HYDROData_Tool::ComputePointState( thePoint.XY(), anIt.Face() ) == TopAbs_IN )
887 theType = anIt.StricklerType();
892 return TopoDS_Face();
897 @param theTreatedObjects the map of treated objects
899 QStringList HYDROData_LandCoverMap::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
901 QStringList aResList = dumpObjectCreation( theTreatedObjects );
902 QString aName = GetObjPyName();
904 //Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
905 //setPythonReferenceObject( theTreatedObjects, aResList, aHydAxis, "SetHydraulicAxis" );
907 //HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
908 //for ( int i = 1, aNb = aSeqOfProfiles.Size(); i <= aNb; ++i )
910 //const Handle(HYDROData_Entity) aProfile = aSeqOfProfiles.Value( i );
911 //setPythonReferenceObject( theTreatedObjects, aResList, aProfile, "AddProfile" );
919 TopoDS_Shape HYDROData_LandCoverMap::RemoveInternal(const TopoDS_Shape& InSh)
921 //Shape must be topologically correct
922 TopExp_Explorer anExp(InSh, TopAbs_EDGE);
923 TopTools_ListOfShape anEdgesToRemove;
925 for(; anExp.More(); anExp.Next() )
927 TopoDS_Edge CurEdge = TopoDS::Edge(anExp.Current());
928 if (CurEdge.Orientation() == TopAbs_INTERNAL)
929 anEdgesToRemove.Append(CurEdge);
932 Handle_ShapeBuild_ReShape aReshape = new ShapeBuild_ReShape();
933 TopoDS_Shape OutSh = aReshape->Apply(InSh);
934 TopTools_ListIteratorOfListOfShape aIt(anEdgesToRemove);
935 for (; aIt.More(); aIt.Next())
936 aReshape->Remove(aIt.Value());
937 OutSh = aReshape->Apply(InSh);
939 Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;