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 <TDataStd_Real.hxx>
49 #include <TopTools_IndexedMapOfShape.hxx>
50 #include <ShapeBuild_ReShape.hxx>
51 #include <ShapeFix_Shape.hxx>
56 #include <QTextStream>
58 const char TELEMAC_FORMAT = 'f';
59 const int TELEMAC_PRECISION = 3;
62 IMPLEMENT_STANDARD_HANDLE(HYDROData_LandCoverMap, HYDROData_Entity)
63 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_LandCoverMap, HYDROData_Entity)
67 @param theMap the land cover map to iterate through
69 HYDROData_LandCoverMap::Iterator::Iterator( const HYDROData_LandCoverMap& theMap )
74 HYDROData_LandCoverMap::Iterator::Iterator( const Handle( HYDROData_LandCoverMap )& theMap )
86 Initialize the iterator
87 @param theMap the land cover map to iterate through
89 void HYDROData_LandCoverMap::Iterator::Init( const HYDROData_LandCoverMap& theMap )
91 TopoDS_Shape aShape = theMap.GetShape();
95 myIterator = new TopoDS_Iterator( aShape );
97 theMap.myLab.FindChild( DataTag_Types ).FindAttribute( TDataStd_ExtStringArray::GetID(), myArray );
98 if( myArray.IsNull() )
101 myIndex = myArray->Lower();
107 HYDROData_LandCoverMap::Iterator::~Iterator()
113 Return the current 0-based index of the iterator
114 @return the current index
116 int HYDROData_LandCoverMap::Iterator::Index() const
118 if( myArray.IsNull() )
121 return myIndex - myArray->Lower();
125 Return if the iterator has more elements
126 @return if the iterator has more elements
128 bool HYDROData_LandCoverMap::Iterator::More() const
130 return !myArray.IsNull() && myIterator && myIterator->More();
134 Move iterator to the next element
136 void HYDROData_LandCoverMap::Iterator::Next()
146 Get the current land cover (face)
147 @return the land cover's face
149 TopoDS_Face HYDROData_LandCoverMap::Iterator::Face() const
152 return TopoDS::Face( myIterator->Value() );
154 return TopoDS_Face();
158 Get the current land cover's Strickler type
159 @return the land cover's Strickler type
161 QString HYDROData_LandCoverMap::Iterator::StricklerType() const
163 if( myArray.IsNull() || myIndex < myArray->Lower() || myIndex > myArray->Upper() )
166 return HYDROData_Tool::toQString( myArray->Value( myIndex ) );
170 Set the Strickler type for the current land cover
171 @param theType the Strickler type
173 void HYDROData_LandCoverMap::Iterator::SetStricklerType( const QString& theType )
175 if( myArray.IsNull() || myIndex < myArray->Lower() || myIndex > myArray->Upper() )
178 myArray->SetValue( myIndex, HYDROData_Tool::toExtString( theType ) );
184 HYDROData_LandCoverMap::HYDROData_LandCoverMap()
185 : HYDROData_Entity( Geom_No )
192 HYDROData_LandCoverMap::~HYDROData_LandCoverMap()
198 @return object's kind
200 const ObjectKind HYDROData_LandCoverMap::GetKind() const
202 return KIND_LAND_COVER_MAP;
205 int HYDROData_LandCoverMap::GetLCCount() const
207 Iterator anIt( *this );
209 for( ; anIt.More(); anIt.Next() )
214 bool HYDROData_LandCoverMap::IsEmpty() const
216 Iterator anIt( *this );
224 Load attributes from DBF File
227 HYDROData_LandCoverMap::DBFStatus HYDROData_LandCoverMap::ImportDBF( const QString& theDBFFileName,
228 const QString& theFieldName,
229 const QStringList& theDBFValues,
230 const QStringList& theStricklerTypes,
231 const QList<int>& theIndices )
233 if (theDBFValues.size() != theStricklerTypes.size())
234 return DBFStatus_DIFF_SIZE_ERROR;
235 HYDROData_ShapeFile aDBFImporter;
236 if (!aDBFImporter.DBF_OpenDBF(theDBFFileName))
237 return DBFStatus_OPEN_FILE_ERROR; //cant open file
239 QStringList FieldList = aDBFImporter.DBF_GetFieldList();
240 int FieldNameIndex = FieldList.indexOf(theFieldName);
241 if (FieldNameIndex == -1)
242 return DBFStatus_NO_SUCH_FIELD_ERROR; //no such field
244 std::vector<HYDROData_ShapeFile::DBF_AttrValue> theAttrV;
245 aDBFImporter.DBF_GetAttributeList(FieldNameIndex, theAttrV );
248 Iterator anIt( *this );
249 for( ; anIt.More(); anIt.Next() )
251 int CurIndex = anIt.Index();
252 HYDROData_ShapeFile::DBF_AttrValue AValue = theAttrV[theIndices[CurIndex]];
253 int StricklerTypesInd = theDBFValues.indexOf(QString(AValue.myStrVal));
254 if ( StricklerTypesInd != -1)
255 anIt.SetStricklerType(theStricklerTypes[StricklerTypesInd]);
262 return DBFStatus_NO_DBFVALUES_CORRESPONDENCE_WARNING;
266 Export attributes to DBF File
269 void HYDROData_LandCoverMap::ExportDBF( const QString& theDBFFileName,
270 const QString& theFieldName,
271 const QStringList& theDBFValues,
272 const QStringList& theStricklerTypes) const
274 if (theDBFValues.size() != theStricklerTypes.size())
276 HYDROData_ShapeFile anExporter;
277 std::vector<HYDROData_ShapeFile::DBF_AttrValue> theAttrV;
278 Iterator anIt( *this );
279 for( ; anIt.More(); anIt.Next() )
281 QString CurST = anIt.StricklerType();
282 HYDROData_ShapeFile::DBF_AttrValue aCurAttrV;
283 aCurAttrV.myIsNull = false;
284 int StricklerTypesInd = theStricklerTypes.indexOf(CurST);
285 if (StricklerTypesInd != -1)
287 aCurAttrV.myStrVal = theDBFValues[StricklerTypesInd];
288 aCurAttrV.myFieldType = HYDROData_ShapeFile::DBF_FieldType_String;
289 theAttrV.push_back(aCurAttrV);
292 aCurAttrV.myIsNull = true;
294 //use actual str value; not the raw value
295 anExporter.DBF_WriteFieldAndValues(theDBFFileName, theFieldName, HYDROData_ShapeFile::DBF_FieldType_String, theAttrV, false);
299 int HashCode( const gp_Pnt& thePoint, const Standard_Integer theUpper )
301 int aHashX = HashCode( thePoint.X(), theUpper );
302 int aHashY = HashCode( thePoint.Y(), theUpper );
303 return (aHashX^aHashY)%theUpper;
306 bool operator == ( const gp_Pnt& thePoint1, const gp_Pnt& thePoint2 )
308 return thePoint1.IsEqual( thePoint2, Precision::Confusion() );
311 bool EdgeDiscretization( const TopoDS_Edge& theEdge,
312 Standard_Real theDeflection,
313 NCollection_IndexedMap<gp_Pnt>& theVerticesMap,
314 QList<int>& theVerticesIds )
316 BRepAdaptor_Curve aCurve( theEdge );
317 GCPnts_QuasiUniformDeflection aDiscrete( aCurve, theDeflection );
318 if( !aDiscrete.IsDone() )
321 int n = aDiscrete.NbPoints();
322 for( int i=1; i<=n; i++ )
324 gp_Pnt aPnt = aDiscrete.Value( i );
326 if( theVerticesMap.Contains( aPnt ) )
327 anId = theVerticesMap.FindIndex( aPnt );
330 anId = theVerticesMap.Size();
331 theVerticesMap.Add( aPnt );
333 theVerticesIds.append( anId );
339 Export the land cover map for the solver (Telemac)
340 @param theFileName the name of file
341 @return if the export is successful
343 bool HYDROData_LandCoverMap::ExportTelemac( const QString& theFileName, Standard_Real theDeflection ) const
345 TopoDS_Shape aLandCoverMapShape = GetShape();
346 TopTools_ListOfShape aListOfFaces;
347 TopExp_Explorer anExp( aLandCoverMapShape, TopAbs_FACE );
348 for( ; anExp.More(); anExp.Next() )
349 aListOfFaces.Append( anExp.Current() );
351 TopoDS_Shape aShape = MergeFaces( aListOfFaces, false );
353 NCollection_IndexedMap<gp_Pnt> aVerticesMap;
354 NCollection_IndexedDataMap< TopoDS_Edge, QList<int> > anEdgesMap;
355 NCollection_IndexedDataMap< TopoDS_Face, QList<int> > aFacesMap;
357 // add into the map all edges existing in the shell
358 TopExp_Explorer anExp1( aShape, TopAbs_EDGE );
359 for( ; anExp1.More(); anExp1.Next() )
361 TopoDS_Edge anEdge = TopoDS::Edge( anExp1.Current() );
362 QList<int> aVerticesIdsList;
363 if( EdgeDiscretization( anEdge, theDeflection, aVerticesMap, aVerticesIdsList ) )
364 anEdgesMap.Add( anEdge, aVerticesIdsList );
367 // add into the map all faces existing in the shell and correspondence between face and edges ids
368 TopExp_Explorer anExp2( aShape, TopAbs_FACE );
369 for( ; anExp2.More(); anExp2.Next() )
371 TopoDS_Face aFace = TopoDS::Face( anExp2.Current() );
372 TopExp_Explorer anExp3( aFace, TopAbs_EDGE );
373 QList<int> anEdgesIdsList;
374 for( ; anExp3.More(); anExp3.Next() )
376 TopoDS_Edge anEdge = TopoDS::Edge( anExp3.Current() );
377 int anEdgeId = anEdgesMap.FindIndex( anEdge );
378 anEdgesIdsList.append( anEdgeId );
380 aFacesMap.Add( aFace, anEdgesIdsList );
383 QFile aFile( theFileName );
384 if( !aFile.open( QFile::WriteOnly | QFile::Text ) )
387 QTextStream aStream( &aFile );
388 aStream << "# nodes\n";
389 NCollection_IndexedMap<gp_Pnt>::Iterator anIt1( aVerticesMap );
390 for( ; anIt1.More(); anIt1.Next() )
392 gp_Pnt aPnt = anIt1.Value();
393 aStream << QString::number( aPnt.X(), TELEMAC_FORMAT, TELEMAC_PRECISION );
395 aStream << QString::number( aPnt.Y(), TELEMAC_FORMAT, TELEMAC_PRECISION );
397 aStream << QString::number( aPnt.Z(), TELEMAC_FORMAT, TELEMAC_PRECISION );
402 aStream << "# edges\n";
403 NCollection_IndexedDataMap< TopoDS_Edge, QList<int> >::Iterator anIt2( anEdgesMap );
404 for( ; anIt2.More(); anIt2.Next() )
406 QList<int> aVerticesIds = anIt2.Value();
407 foreach( int anId, aVerticesIds )
408 aStream << anId << " ";
413 aStream << "# faces\n";
414 NCollection_IndexedDataMap< TopoDS_Face, QList<int> >::Iterator anIt3( aFacesMap );
415 for( ; anIt3.More(); anIt3.Next() )
417 QList<int> anEdgesIds = anIt3.Value();
418 foreach( int anId, anEdgesIds )
419 aStream << anId << " ";
429 Add a new object as land cover
430 @param theObject the object to add as land cover
431 @param theType the Strickler type for the new land cover
432 @return if the addition is successful
434 bool HYDROData_LandCoverMap::Add( const Handle( HYDROData_Object )& theObject, const QString& theType )
436 if( theObject.IsNull() )
439 TopoDS_Shape aShape = theObject->GetTopShape();
440 if( aShape.ShapeType()!=TopAbs_FACE )
443 TopoDS_Face aFace = TopoDS::Face( aShape );
444 return LocalPartition( aFace, theType );
447 bool HYDROData_LandCoverMap::Add( const TopoDS_Wire& theWire, const QString& theType )
449 if( !theWire.Closed() )
452 TopoDS_Face aFace = BRepBuilderAPI_MakeFace( theWire, Standard_True ).Face();
453 return LocalPartition( aFace, theType );
457 Add a new polyline as land cover
458 @param thePolyline the polyline to add as land cover
459 @param theType the Strickler type for the new land cover
460 @return if the addition is successful
462 bool HYDROData_LandCoverMap::Add( const Handle( HYDROData_PolylineXY )& thePolyline, const QString& theType )
464 if( thePolyline.IsNull() )
467 TopoDS_Shape aShape = thePolyline->GetShape();
468 if( aShape.ShapeType()==TopAbs_WIRE )
469 return Add( TopoDS::Wire( aShape ), theType );
471 if( aShape.ShapeType()==TopAbs_COMPOUND )
473 TopExp_Explorer anExp( aShape, TopAbs_WIRE );
474 for( ; anExp.More(); anExp.Next() )
476 TopoDS_Wire aPart = TopoDS::Wire( anExp.Current() );
477 if( !Add( aPart, theType ) )
487 Remove the given face from land cover map
488 @param theFace the face to be removed
489 @return if the removing is successful
491 bool HYDROData_LandCoverMap::Remove( const TopoDS_Face& theFace )
493 TopTools_ListOfShape aList;
494 aList.Append( theFace );
495 return Remove( aList );
499 Remove the given faces from land cover map
500 @param theFacesToRemove the face list to be removed
501 @return if the removing is successful
503 bool HYDROData_LandCoverMap::Remove( const TopTools_ListOfShape& theFacesToRemove )
505 HYDROData_MapOfFaceToStricklerType aFacesToRemove, aNewFaces;
506 TopTools_ListIteratorOfListOfShape aFIt( theFacesToRemove );
507 for( ; aFIt.More(); aFIt.Next() )
509 TopoDS_Shape aShape = aFIt.Value();
510 if( aShape.ShapeType()==TopAbs_FACE )
511 aFacesToRemove.Add( TopoDS::Face( aShape ), "" );
514 Iterator anIt( *this );
515 for( ; anIt.More(); anIt.Next() )
516 if( !aFacesToRemove.Contains( anIt.Face() ) )
517 aNewFaces.Add( anIt.Face(), anIt.StricklerType() );
519 if ( aNewFaces.IsEmpty() )
522 StoreLandCovers( aNewFaces );
527 Split the land cover map by the given polyline
528 @param thePolyline the tool polyline to split the land cover map
529 @return if the removing is successful
531 bool HYDROData_LandCoverMap::Split( const Handle( HYDROData_PolylineXY )& thePolyline )
533 if( thePolyline.IsNull() )
536 TopoDS_Shape aShape = thePolyline->GetShape();
537 return Split( aShape );
542 Split the land cover map by the given polyline
543 @param theShape the tool polyline to split the land cover map
544 @return if the removing is successful
546 bool HYDROData_LandCoverMap::Split( const TopoDS_Shape& theShape )
548 return LocalPartition( theShape, "" );
553 Merge the given faces in the land cover
554 @param theFaces the faces to merge in the land cover map
555 @param theType the Strickler type for the merged land cover
556 @return if the merge is successful
558 bool HYDROData_LandCoverMap::Merge( const TopTools_ListOfShape& theFaces, const QString& theType )
560 // 1. to fuse the faces into the new face
561 TopoDS_Shape aMergedFace = MergeFaces( theFaces, true );
562 if( !aMergedFace.IsNull() && aMergedFace.ShapeType()==TopAbs_FACE )
564 // 2. to remove the merged faces from the current map
567 // 3. to add the face into the map
568 return LocalPartition( TopoDS::Face( aMergedFace ), theType );
574 Merge the given faces into the shell/face
575 @param theFaces the faces to merge
576 @param IsToUnify if the common edges should be removed (fused)
577 @param theTolerance the operation's tolerance
578 @return result shape (face or shell)
580 TopoDS_Shape HYDROData_LandCoverMap::MergeFaces( const TopTools_ListOfShape& theFaces,
581 bool IsToUnify, double theTolerance )
584 TopTools_ListIteratorOfListOfShape anIt;
585 BOPCol_ListOfShape aLC;
586 anIt.Initialize(theFaces);
587 for( ; anIt.More(); anIt.Next() )
589 if (anIt.Value().ShapeType() != TopAbs_FACE)
590 return TopoDS_Shape();
591 aLC.Append( anIt.Value() );
594 BOPAlgo_PaveFiller aPF;
595 aPF.SetArguments( aLC );
596 aPF.SetRunParallel( Standard_False );
597 aPF.SetFuzzyValue( theTolerance );
600 anError = aPF.ErrorStatus();
602 return TopoDS_Shape();
604 BOPAlgo_Builder anAlgo;
605 anIt.Initialize( theFaces );
606 for( ; anIt.More(); anIt.Next() )
607 anAlgo.AddArgument( anIt.Value() );
609 anAlgo.PerformWithFiller( aPF );
610 anError = anAlgo.ErrorStatus();
612 return TopoDS_Shape();
614 const TopoDS_Shape& aMergedShape = anAlgo.Shape();
616 BRep_Builder aBuilder;
618 aBuilder.MakeShell( aShell );
619 aShell.Closed( Standard_False );
620 TopExp_Explorer anExplorer( aMergedShape, TopAbs_FACE );
621 for( ; anExplorer.More(); anExplorer.Next() )
623 const TopoDS_Face& aFace = TopoDS::Face(anExplorer.Current());
626 if( aFace.ShapeType() == TopAbs_FACE )
628 aBuilder.Add( aShell, aFace );
629 aShell.Closed( Standard_False );
633 TopoDS_Shape aResult;
636 ShapeUpgrade_UnifySameDomain aUSD;
637 aUSD.Initialize( aShell );
639 aResult = aUSD.Shape();
644 anExplorer.Init( aResult, TopAbs_FACE );
646 TopoDS_Face anOneFace;
647 for( ; anExplorer.More(); anExplorer.Next(), n++ )
648 anOneFace = TopoDS::Face( anExplorer.Current() );
657 Change Strickler type for the list of faces to the given one
658 @param theFaces the faces to change type
659 @param theType the Strickler type for the given land cover(s)
660 @return if the change type operation is successful
662 bool HYDROData_LandCoverMap::ChangeType( const TopTools_ListOfShape& theFaces, const QString& theType )
664 HYDROData_MapOfFaceToStricklerType aFacesToChangeType;
665 TopTools_ListIteratorOfListOfShape aFIt( theFaces );
666 for( ; aFIt.More(); aFIt.Next() )
668 TopoDS_Shape aShape = aFIt.Value();
669 if( aShape.ShapeType()==TopAbs_FACE )
670 aFacesToChangeType.Add( TopoDS::Face( aShape ), "" );
674 Iterator anIt( *this );
675 for( ; anIt.More(); anIt.Next() )
676 if( aFacesToChangeType.Contains( anIt.Face() ) )
678 anIt.SetStricklerType( theType );
681 if ( aNbChanges != theFaces.Extent() )
688 Get the shape of the land cover map
690 TopoDS_Shape HYDROData_LandCoverMap::GetShape() const
692 return HYDROData_Entity::GetShape( DataTag_Shape );
696 Get Strickler type of the given land cover
697 @param theLandCover the land cover to get Strickler type of
698 @return name of Strickler type
700 QString HYDROData_LandCoverMap::StricklerType( const TopoDS_Face& theLandCover ) const
704 Iterator anIt( *this );
705 for( ; anIt.More(); anIt.Next() )
706 if( anIt.Face().IsEqual( theLandCover) )
708 aType = anIt.StricklerType();
716 Set the shape of the land cover map
717 @param theShape the new shape for the land cover map
719 void HYDROData_LandCoverMap::SetShape( const TopoDS_Shape& theShape )
721 HYDROData_Entity::SetShape( DataTag_Shape, theShape );
725 Perform the local partition algorithm on the land cover
726 @param theNewShape the new shape to add into the land cover
727 @param theNewType the new Strickler type for the new land cover
728 @return if the local partition is successful
730 bool HYDROData_LandCoverMap::LocalPartition( const TopoDS_Shape& theNewShape, const QString& theNewType )
732 if( theNewShape.IsNull() )
735 BOPCol_ListOfShape aShapesList;
736 BOPAlgo_PaveFiller aPaveFiller;
737 HYDROData_MapOfFaceToStricklerType aNewFaces;
739 // add faces to shapes list
740 Iterator anIt( *this );
741 for( ; anIt.More(); anIt.Next() )
742 aShapesList.Append( anIt.Face() );
743 aShapesList.Append( theNewShape );
745 if( aShapesList.Size()==1 && theNewShape.ShapeType()==TopAbs_FACE )
747 aNewFaces.Add( TopoDS::Face( theNewShape ), theNewType );
748 StoreLandCovers( aNewFaces );
752 // prepare pave filler
753 aPaveFiller.SetArguments( aShapesList );
754 aPaveFiller.Perform();
755 Standard_Integer anError = aPaveFiller.ErrorStatus();
759 // add faces to builder
760 BOPAlgo_Builder aBuilder;
762 for( ; anIt.More(); anIt.Next() )
763 aBuilder.AddArgument( anIt.Face() );
764 aBuilder.AddArgument( theNewShape );
766 // perform the partition with the pave filler
767 aBuilder.PerformWithFiller( aPaveFiller );
768 anError = aBuilder.ErrorStatus();
772 //std::cout << "History:" << std::endl;
773 // analysis of the history
774 // a. to fill map of shapes which come from the new face
775 NCollection_IndexedMap<int> aShapesFromNewFace;
776 //std::cout << "from NEW " << theNewShape << ":" << theNewType << std::endl;
777 TopTools_ListOfShape aModified = aBuilder.Modified( theNewShape );
778 TopTools_ListIteratorOfListOfShape aMIt( aModified );
779 for( ; aMIt.More(); aMIt.Next() )
781 //std::cout << " " << aMIt.Value() << std::endl;
782 int aKey = (int)(uintptr_t)aMIt.Value().TShape().operator->();
783 aShapesFromNewFace.Add( aKey );
786 // b. to fill map of parts except parts from new face
788 for( ; anIt.More(); anIt.Next() )
790 QString aSType = anIt.StricklerType();
791 //std::cout << "from " << anIt.Face() << ": " << anIt.StricklerType() << std::endl;
792 TopTools_ListOfShape aModified = aBuilder.Modified( anIt.Face() );
793 if( aModified.Extent() == 0 )
794 aModified.Append( anIt.Face() );
796 TopTools_ListIteratorOfListOfShape aMIt( aModified );
797 for( ; aMIt.More(); aMIt.Next() )
799 TopoDS_Shape aShape = aMIt.Value();
800 bool isFace = aShape.ShapeType()==TopAbs_FACE;
801 int aKey = (int)(uintptr_t)aShape.TShape().operator->();
802 bool isAlsoFromNew = aShapesFromNewFace.Contains( aKey );
803 //std::cout << " " << aShape << " " << isAlsoFromNew << std::endl;
804 if( isFace && !isAlsoFromNew )
805 aNewFaces.Add( TopoDS::Face( aShape ), aSType );
809 // c. add the new shape if it is face with its type
810 if( theNewShape.ShapeType()==TopAbs_FACE )
811 aNewFaces.Add( TopoDS::Face( theNewShape ), theNewType );
813 // convert map of shape to type to compound and list of types
814 StoreLandCovers( aNewFaces );
819 Replace the set of land covers in the land cover map
820 @param theMap the map of shape (face) to Strickler type (string)
822 void HYDROData_LandCoverMap::StoreLandCovers( const HYDROData_MapOfFaceToStricklerType& theMap )
824 TopTools_ListOfShape aListOfFaces;
826 int n = theMap.Size();
828 Handle( TDataStd_ExtStringArray ) aTypes =
829 TDataStd_ExtStringArray::Set( myLab.FindChild( DataTag_Types ), 0, n-1, Standard_True );
831 HYDROData_MapOfFaceToStricklerType::Iterator aNFIt( theMap );
832 for( int i=0; aNFIt.More(); aNFIt.Next(), i++ )
834 TopoDS_Face aFace = aNFIt.Key();
837 QString aType = aNFIt.Value();
838 aListOfFaces.Append(aFace);
839 aTypes->SetValue( i, HYDROData_Tool::toExtString( aType ) );
842 TopoDS_Shape aResult;
843 if( aListOfFaces.Extent() == 1 )
846 BRep_Builder aShellBuilder;
847 aShellBuilder.MakeShell( aShell );
848 aShell.Closed( Standard_False );
849 aShellBuilder.Add( aShell, aListOfFaces.First() );
852 else if( aListOfFaces.Extent() > 1 )
853 aResult = MergeFaces( aListOfFaces, false );
855 //remove internal edges
856 aResult = RemoveInternal(aResult);
861 Checks that object has 2D presentation. Reimlemented to retun true.
863 bool HYDROData_LandCoverMap::IsHas2dPrs() const
869 Find the land cover for the given point
870 @param thePoint the point laying in some land cover
871 @param theType the returned type
872 @return the found land cover's face
874 TopoDS_Face HYDROData_LandCoverMap::FindByPoint( const gp_Pnt2d& thePoint, QString& theType ) const
876 //TODO: some more optimal algorithm
877 Iterator anIt( *this );
878 for( ; anIt.More(); anIt.Next() )
879 if( HYDROData_Tool::ComputePointState( thePoint.XY(), anIt.Face() ) == TopAbs_IN )
881 theType = anIt.StricklerType();
886 return TopoDS_Face();
891 @param theTreatedObjects the map of treated objects
893 QStringList HYDROData_LandCoverMap::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
895 QStringList aResList = dumpObjectCreation( theTreatedObjects );
896 QString aName = GetObjPyName();
898 //Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
899 //setPythonReferenceObject( theTreatedObjects, aResList, aHydAxis, "SetHydraulicAxis" );
901 //HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
902 //for ( int i = 1, aNb = aSeqOfProfiles.Size(); i <= aNb; ++i )
904 //const Handle(HYDROData_Entity) aProfile = aSeqOfProfiles.Value( i );
905 //setPythonReferenceObject( theTreatedObjects, aResList, aProfile, "AddProfile" );
913 TopoDS_Shape HYDROData_LandCoverMap::RemoveInternal(const TopoDS_Shape& InSh)
915 //Shape must be topologically correct
916 TopExp_Explorer anExp(InSh, TopAbs_EDGE);
917 TopTools_ListOfShape anEdgesToRemove;
919 for(; anExp.More(); anExp.Next() )
921 TopoDS_Edge CurEdge = TopoDS::Edge(anExp.Current());
922 if (CurEdge.Orientation() == TopAbs_INTERNAL)
923 anEdgesToRemove.Append(CurEdge);
926 Handle_ShapeBuild_ReShape aReshape = new ShapeBuild_ReShape();
927 TopoDS_Shape OutSh = aReshape->Apply(InSh);
928 TopTools_ListIteratorOfListOfShape aIt(anEdgesToRemove);
929 for (; aIt.More(); aIt.Next())
930 aReshape->Remove(aIt.Value());
931 OutSh = aReshape->Apply(InSh);
933 Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
940 void HYDROData_LandCoverMap::SetTransparency( double theTransparency )
942 Handle(TDataStd_Real) anAttr;
943 TDF_Label aLabel = myLab.FindChild( DataTag_Transparency );
944 if( !aLabel.FindAttribute( TDataStd_Real::GetID(), anAttr ) )
945 aLabel.AddAttribute( anAttr = new TDataStd_Real() );
946 anAttr->Set( theTransparency );
949 double HYDROData_LandCoverMap::GetTransparency() const
951 Handle(TDataStd_Real) anAttr;
952 TDF_Label aLabel = myLab.FindChild( DataTag_Transparency );
953 if( !aLabel.FindAttribute( TDataStd_Real::GetID(), anAttr ) )
956 return anAttr->Get();