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>
52 #include <BRepCheck_Shell.hxx>
53 #include <BRepCheck_ListOfStatus.hxx>
58 #include <QTextStream>
60 const char TELEMAC_FORMAT = 'f';
61 const int TELEMAC_PRECISION = 3;
64 IMPLEMENT_STANDARD_HANDLE(HYDROData_LandCoverMap, HYDROData_Entity)
65 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_LandCoverMap, HYDROData_Entity)
69 @param theMap the land cover map to iterate through
71 HYDROData_LandCoverMap::Explorer::Explorer( const HYDROData_LandCoverMap& theMap )
76 HYDROData_LandCoverMap::Explorer::Explorer( const Handle( HYDROData_LandCoverMap )& theMap )
88 Initialize the iterator
89 @param theMap the land cover map to iterate through
91 void HYDROData_LandCoverMap::Explorer::Init( const HYDROData_LandCoverMap& theMap )
93 TopoDS_Shape aShape = theMap.GetShape();
98 myExplorer = new TopExp_Explorer();
99 myExplorer->Init( aShape, TopAbs_FACE );
102 theMap.myLab.FindChild( DataTag_Types ).FindAttribute( TDataStd_ExtStringArray::GetID(), myArray );
103 if( myArray.IsNull() )
106 myIndex = myArray->Lower();
112 HYDROData_LandCoverMap::Explorer::~Explorer()
118 Return the current 0-based index of the iterator
119 @return the current index
121 int HYDROData_LandCoverMap::Explorer::Index() const
123 if( myArray.IsNull() )
126 return myIndex - myArray->Lower();
130 Return if the iterator has more elements
131 @return if the iterator has more elements
133 bool HYDROData_LandCoverMap::Explorer::More() const
135 return !myArray.IsNull() && myExplorer && myExplorer->More();
139 Move iterator to the next element
141 void HYDROData_LandCoverMap::Explorer::Next()
151 Get the current land cover (face)
152 @return the land cover's face
154 TopoDS_Face HYDROData_LandCoverMap::Explorer::Face() const
157 return TopoDS::Face( myExplorer->Current() );
159 return TopoDS_Face();
163 Get the current land cover's Strickler type
164 @return the land cover's Strickler type
166 QString HYDROData_LandCoverMap::Explorer::StricklerType() const
168 if( myArray.IsNull() || myIndex < myArray->Lower() || myIndex > myArray->Upper() )
171 return HYDROData_Tool::toQString( myArray->Value( myIndex ) );
175 Set the Strickler type for the current land cover
176 @param theType the Strickler type
178 void HYDROData_LandCoverMap::Explorer::SetStricklerType( const QString& theType )
180 if( myArray.IsNull() || myIndex < myArray->Lower() || myIndex > myArray->Upper() )
183 myArray->SetValue( myIndex, HYDROData_Tool::toExtString( theType ) );
189 HYDROData_LandCoverMap::HYDROData_LandCoverMap()
190 : HYDROData_Entity( Geom_No )
197 HYDROData_LandCoverMap::~HYDROData_LandCoverMap()
203 @return object's kind
205 const ObjectKind HYDROData_LandCoverMap::GetKind() const
207 return KIND_LAND_COVER_MAP;
210 int HYDROData_LandCoverMap::GetLCCount() const
212 Explorer anIt( *this );
214 for( ; anIt.More(); anIt.Next() )
219 bool HYDROData_LandCoverMap::IsEmpty() const
221 Explorer anIt( *this );
229 Load attributes from DBF File
232 HYDROData_LandCoverMap::DBFStatus HYDROData_LandCoverMap::ImportDBF( const QString& theDBFFileName,
233 const QString& theFieldName,
234 const QStringList& theDBFValues,
235 const QStringList& theStricklerTypes,
236 const QList<int>& theIndices )
238 if (theDBFValues.size() != theStricklerTypes.size())
239 return DBFStatus_DIFF_SIZE_ERROR;
240 HYDROData_ShapeFile aDBFImporter;
241 if (!aDBFImporter.DBF_OpenDBF(theDBFFileName))
242 return DBFStatus_OPEN_FILE_ERROR; //cant open file
244 QStringList FieldList = aDBFImporter.DBF_GetFieldList();
245 int FieldNameIndex = FieldList.indexOf(theFieldName);
246 if (FieldNameIndex == -1)
247 return DBFStatus_NO_SUCH_FIELD_ERROR; //no such field
249 std::vector<HYDROData_ShapeFile::DBF_AttrValue> theAttrV;
250 aDBFImporter.DBF_GetAttributeList(FieldNameIndex, theAttrV );
253 Explorer anIt( *this );
254 for( ; anIt.More(); anIt.Next() )
256 int CurIndex = anIt.Index();
257 HYDROData_ShapeFile::DBF_AttrValue AValue = theAttrV[theIndices[CurIndex]];
258 int StricklerTypesInd = theDBFValues.indexOf(QString(AValue.myStrVal));
259 if ( StricklerTypesInd != -1)
260 anIt.SetStricklerType(theStricklerTypes[StricklerTypesInd]);
267 return DBFStatus_NO_DBFVALUES_CORRESPONDENCE_WARNING;
271 Export attributes to DBF File
274 void HYDROData_LandCoverMap::ExportDBF( const QString& theDBFFileName,
275 const QString& theFieldName,
276 const QStringList& theDBFValues,
277 const QStringList& theStricklerTypes) const
279 if (theDBFValues.size() != theStricklerTypes.size())
281 HYDROData_ShapeFile anExporter;
282 std::vector<HYDROData_ShapeFile::DBF_AttrValue> theAttrV;
283 Explorer anIt( *this );
284 for( ; anIt.More(); anIt.Next() )
286 QString CurST = anIt.StricklerType();
287 HYDROData_ShapeFile::DBF_AttrValue aCurAttrV;
288 aCurAttrV.myIsNull = false;
289 int StricklerTypesInd = theStricklerTypes.indexOf(CurST);
290 if (StricklerTypesInd != -1)
292 aCurAttrV.myStrVal = theDBFValues[StricklerTypesInd];
293 aCurAttrV.myFieldType = HYDROData_ShapeFile::DBF_FieldType_String;
294 theAttrV.push_back(aCurAttrV);
297 aCurAttrV.myIsNull = true;
299 //use actual str value; not the raw value
300 anExporter.DBF_WriteFieldAndValues(theDBFFileName, theFieldName, HYDROData_ShapeFile::DBF_FieldType_String, theAttrV, false);
304 int HashCode( const gp_Pnt& thePoint, const Standard_Integer theUpper )
306 int aHashX = HashCode( thePoint.X(), theUpper );
307 int aHashY = HashCode( thePoint.Y(), theUpper );
308 return (aHashX^aHashY)%theUpper;
311 bool operator == ( const gp_Pnt& thePoint1, const gp_Pnt& thePoint2 )
313 return thePoint1.IsEqual( thePoint2, Precision::Confusion() );
316 bool EdgeDiscretization( const TopoDS_Edge& theEdge,
317 Standard_Real theDeflection,
318 NCollection_IndexedMap<gp_Pnt>& theVerticesMap,
319 QList<int>& theVerticesIds )
321 BRepAdaptor_Curve aCurve( theEdge );
322 GCPnts_QuasiUniformDeflection aDiscrete( aCurve, theDeflection );
323 if( !aDiscrete.IsDone() )
326 int n = aDiscrete.NbPoints();
327 for( int i=1; i<=n; i++ )
329 gp_Pnt aPnt = aDiscrete.Value( i );
331 if( theVerticesMap.Contains( aPnt ) )
332 anId = theVerticesMap.FindIndex( aPnt );
335 anId = theVerticesMap.Size();
336 theVerticesMap.Add( aPnt );
338 theVerticesIds.append( anId );
344 Export the land cover map for the solver (Telemac)
345 @param theFileName the name of file
346 @return if the export is successful
348 bool HYDROData_LandCoverMap::ExportTelemac( const QString& theFileName, Standard_Real theDeflection ) const
350 TopoDS_Shape aLandCoverMapShape = GetShape();
351 TopTools_ListOfShape aListOfFaces;
352 Explorer anIt( *this );
353 QMap<Handle(TopoDS_TShape), QString> aTypesMap;
354 for( ; anIt.More(); anIt.Next() )
356 aListOfFaces.Append( anIt.Face() );
357 aTypesMap.insert( anIt.Face().TShape(), anIt.StricklerType() );
360 TopoDS_Shape aShape = MergeFaces( aListOfFaces, false );
362 NCollection_IndexedMap<gp_Pnt> aVerticesMap;
363 NCollection_IndexedDataMap< TopoDS_Edge, QList<int> > anEdgesMap;
364 typedef QPair< QString, QList<int> > FaceData;
365 NCollection_IndexedDataMap< TopoDS_Face, FaceData > aFacesMap;
367 // add into the map all edges existing in the shell
368 TopExp_Explorer anExp1( aShape, TopAbs_EDGE );
369 for( ; anExp1.More(); anExp1.Next() )
371 TopoDS_Edge anEdge = TopoDS::Edge( anExp1.Current() );
372 QList<int> aVerticesIdsList;
373 if( EdgeDiscretization( anEdge, theDeflection, aVerticesMap, aVerticesIdsList ) )
374 anEdgesMap.Add( anEdge, aVerticesIdsList );
377 // add into the map all faces existing in the shell and correspondence between face and edges ids
378 TopExp_Explorer anExp2( aShape, TopAbs_FACE );
379 for( ; anExp2.More(); anExp2.Next() )
381 TopoDS_Face aFace = TopoDS::Face( anExp2.Current() );
382 TopExp_Explorer anExp3( aFace, TopAbs_EDGE );
383 QList<int> anEdgesIdsList;
384 for( ; anExp3.More(); anExp3.Next() )
386 TopoDS_Edge anEdge = TopoDS::Edge( anExp3.Current() );
387 int anEdgeId = anEdgesMap.FindIndex( anEdge );
388 anEdgesIdsList.append( anEdgeId );
392 aData.first = aTypesMap[aFace.TShape()];
393 aData.second = anEdgesIdsList;
394 aFacesMap.Add( aFace, aData );
397 QFile aFile( theFileName );
398 if( !aFile.open( QFile::WriteOnly | QFile::Text ) )
401 QTextStream aStream( &aFile );
402 aStream << "# nodes\n";
403 NCollection_IndexedMap<gp_Pnt>::Iterator anIt1( aVerticesMap );
404 for( ; anIt1.More(); anIt1.Next() )
406 gp_Pnt aPnt = anIt1.Value();
407 aStream << QString::number( aPnt.X(), TELEMAC_FORMAT, TELEMAC_PRECISION );
409 aStream << QString::number( aPnt.Y(), TELEMAC_FORMAT, TELEMAC_PRECISION );
411 aStream << QString::number( aPnt.Z(), TELEMAC_FORMAT, TELEMAC_PRECISION );
416 aStream << "# edges\n";
417 NCollection_IndexedDataMap< TopoDS_Edge, QList<int> >::Iterator anIt2( anEdgesMap );
418 for( ; anIt2.More(); anIt2.Next() )
420 QList<int> aVerticesIds = anIt2.Value();
421 foreach( int anId, aVerticesIds )
422 aStream << anId << " ";
427 aStream << "# faces\n";
428 NCollection_IndexedDataMap< TopoDS_Face, FaceData >::Iterator anIt3( aFacesMap );
429 for( ; anIt3.More(); anIt3.Next() )
431 QString aType = anIt3.Value().first;
432 QList<int> anEdgesIds = anIt3.Value().second;
433 aStream << "\"" << aType << "\" ";
434 foreach( int anId, anEdgesIds )
435 aStream << anId << " ";
445 Add a new object as land cover
446 @param theObject the object to add as land cover
447 @param theType the Strickler type for the new land cover
448 @return if the addition is successful
450 bool HYDROData_LandCoverMap::Add( const Handle( HYDROData_Object )& theObject, const QString& theType )
452 if( theObject.IsNull() )
455 TopoDS_Shape aShape = theObject->GetTopShape();
456 if( aShape.ShapeType()!=TopAbs_FACE )
459 TopoDS_Face aFace = TopoDS::Face( aShape );
460 return LocalPartition( aFace, theType );
463 bool HYDROData_LandCoverMap::Add( const TopoDS_Wire& theWire, const QString& theType )
465 if( !theWire.Closed() )
468 TopoDS_Face aFace = BRepBuilderAPI_MakeFace( theWire, Standard_True ).Face();
469 return LocalPartition( aFace, theType );
473 Add a new polyline as land cover
474 @param thePolyline the polyline to add as land cover
475 @param theType the Strickler type for the new land cover
476 @return if the addition is successful
478 bool HYDROData_LandCoverMap::Add( const Handle( HYDROData_PolylineXY )& thePolyline, const QString& theType )
480 if( thePolyline.IsNull() )
483 TopoDS_Shape aShape = thePolyline->GetShape();
484 if( aShape.ShapeType()==TopAbs_WIRE )
485 return Add( TopoDS::Wire( aShape ), theType );
487 if( aShape.ShapeType()==TopAbs_COMPOUND )
489 TopExp_Explorer anExp( aShape, TopAbs_WIRE );
490 for( ; anExp.More(); anExp.Next() )
492 TopoDS_Wire aPart = TopoDS::Wire( anExp.Current() );
493 if( !Add( aPart, theType ) )
503 Remove the given face from land cover map
504 @param theFace the face to be removed
505 @return if the removing is successful
507 bool HYDROData_LandCoverMap::Remove( const TopoDS_Face& theFace )
509 TopTools_ListOfShape aList;
510 aList.Append( theFace );
511 return Remove( aList );
515 Remove the given faces from land cover map
516 @param theFacesToRemove the face list to be removed
517 @return if the removing is successful
519 bool HYDROData_LandCoverMap::Remove( const TopTools_ListOfShape& theFacesToRemove )
521 HYDROData_MapOfFaceToStricklerType aFacesToRemove, aNewFaces;
522 TopTools_ListIteratorOfListOfShape aFIt( theFacesToRemove );
523 for( ; aFIt.More(); aFIt.Next() )
525 TopoDS_Shape aShape = aFIt.Value();
526 if( aShape.ShapeType()==TopAbs_FACE )
527 aFacesToRemove.Add( TopoDS::Face( aShape ), "" );
530 Explorer anIt( *this );
531 for( ; anIt.More(); anIt.Next() )
532 if( !aFacesToRemove.Contains( anIt.Face() ) )
533 aNewFaces.Add( anIt.Face(), anIt.StricklerType() );
535 if ( aNewFaces.IsEmpty() )
538 StoreLandCovers( aNewFaces );
543 Split the land cover map by the given polyline
544 @param thePolyline the tool polyline to split the land cover map
545 @return if the removing is successful
547 bool HYDROData_LandCoverMap::Split( const Handle( HYDROData_PolylineXY )& thePolyline )
549 if( thePolyline.IsNull() )
552 TopoDS_Shape aShape = thePolyline->GetShape();
553 return Split( aShape );
558 Split the land cover map by the given polyline
559 @param theShape the tool polyline to split the land cover map
560 @return if the removing is successful
562 bool HYDROData_LandCoverMap::Split( const TopoDS_Shape& theShape )
564 return LocalPartition( theShape, "" );
569 Merge the given faces in the land cover
570 @param theFaces the faces to merge in the land cover map
571 @param theType the Strickler type for the merged land cover
572 @return if the merge is successful
574 bool HYDROData_LandCoverMap::Merge( const TopTools_ListOfShape& theFaces, const QString& theType )
576 // 1. to fuse the faces into the new face
577 TopoDS_Shape aMergedFace = MergeFaces( theFaces, true );
578 if( !aMergedFace.IsNull() && aMergedFace.ShapeType()==TopAbs_FACE )
580 // 2. to remove the merged faces from the current map
583 // 3. to add the face into the map
584 return LocalPartition( TopoDS::Face( aMergedFace ), theType );
590 Merge the given faces into the shell/face
591 @param theFaces the faces to merge
592 @param IsToUnify if the common edges should be removed (fused)
593 @param theTolerance the operation's tolerance
594 @return result shape (face or shell)
596 TopoDS_Shape HYDROData_LandCoverMap::MergeFaces( const TopTools_ListOfShape& theFaces,
597 bool IsToUnify, double theTolerance )
600 TopTools_ListIteratorOfListOfShape anIt;
601 BOPCol_ListOfShape aLC;
602 anIt.Initialize(theFaces);
603 for( ; anIt.More(); anIt.Next() )
605 if (anIt.Value().ShapeType() != TopAbs_FACE)
606 return TopoDS_Shape();
607 aLC.Append( anIt.Value() );
610 BOPAlgo_PaveFiller aPF;
611 aPF.SetArguments( aLC );
612 aPF.SetRunParallel( Standard_False );
613 aPF.SetFuzzyValue( theTolerance );
616 anError = aPF.ErrorStatus();
618 return TopoDS_Shape();
620 BOPAlgo_Builder anAlgo;
621 anIt.Initialize( theFaces );
622 for( ; anIt.More(); anIt.Next() )
623 anAlgo.AddArgument( anIt.Value() );
625 anAlgo.PerformWithFiller( aPF );
626 anError = anAlgo.ErrorStatus();
628 return TopoDS_Shape();
630 const TopoDS_Shape& aMergedShape = anAlgo.Shape();
632 BRep_Builder aBuilder;
634 aBuilder.MakeShell( aShell );
635 aShell.Closed( Standard_False );
636 TopExp_Explorer anExplorer( aMergedShape, TopAbs_FACE );
637 for( ; anExplorer.More(); anExplorer.Next() )
639 const TopoDS_Face& aFace = TopoDS::Face(anExplorer.Current());
642 if( aFace.ShapeType() == TopAbs_FACE )
644 aBuilder.Add( aShell, aFace );
645 aShell.Closed( Standard_False );
649 TopoDS_Shape aResult;
652 ShapeUpgrade_UnifySameDomain aUSD;
653 aUSD.Initialize( aShell );
655 aResult = aUSD.Shape();
660 anExplorer.Init( aResult, TopAbs_FACE );
662 TopoDS_Face anOneFace;
663 for( ; anExplorer.More(); anExplorer.Next(), n++ )
664 anOneFace = TopoDS::Face( anExplorer.Current() );
668 else if (aResult.ShapeType() == TopAbs_SHELL)
670 BRepCheck_Shell aBCS(TopoDS::Shell(aResult));
671 if (aBCS.Status().First() != BRepCheck_NoError)
673 ShapeFix_Shell aFixer;
674 aFixer.FixFaceOrientation(TopoDS::Shell(aResult), 1);
675 aResult = aFixer.Shape();
683 Change Strickler type for the list of faces to the given one
684 @param theFaces the faces to change type
685 @param theType the Strickler type for the given land cover(s)
686 @return if the change type operation is successful
688 bool HYDROData_LandCoverMap::ChangeType( const TopTools_ListOfShape& theFaces, const QString& theType )
690 HYDROData_MapOfFaceToStricklerType aFacesToChangeType;
691 TopTools_ListIteratorOfListOfShape aFIt( theFaces );
692 for( ; aFIt.More(); aFIt.Next() )
694 TopoDS_Shape aShape = aFIt.Value();
695 if( aShape.ShapeType()==TopAbs_FACE )
696 aFacesToChangeType.Add( TopoDS::Face( aShape ), "" );
700 Explorer anIt( *this );
701 for( ; anIt.More(); anIt.Next() )
702 if( aFacesToChangeType.Contains( anIt.Face() ) )
704 anIt.SetStricklerType( theType );
707 if ( aNbChanges != theFaces.Extent() )
714 Get the shape of the land cover map
716 TopoDS_Shape HYDROData_LandCoverMap::GetShape() const
718 return HYDROData_Entity::GetShape( DataTag_Shape );
722 Get Strickler type of the given land cover
723 @param theLandCover the land cover to get Strickler type of
724 @return name of Strickler type
726 QString HYDROData_LandCoverMap::StricklerType( const TopoDS_Face& theLandCover ) const
730 Explorer anIt( *this );
731 for( ; anIt.More(); anIt.Next() )
732 if( anIt.Face().IsEqual( theLandCover) )
734 aType = anIt.StricklerType();
742 Set the shape of the land cover map
743 @param theShape the new shape for the land cover map
745 void HYDROData_LandCoverMap::SetShape( const TopoDS_Shape& theShape )
747 HYDROData_Entity::SetShape( DataTag_Shape, theShape );
751 Perform the local partition algorithm on the land cover
752 @param theNewShape the new shape to add into the land cover
753 @param theNewType the new Strickler type for the new land cover
754 @return if the local partition is successful
756 bool HYDROData_LandCoverMap::LocalPartition( const TopoDS_Shape& theNewShape, const QString& theNewType )
758 if( theNewShape.IsNull() )
761 BOPCol_ListOfShape aShapesList;
762 BOPAlgo_PaveFiller aPaveFiller;
763 HYDROData_MapOfFaceToStricklerType aNewFaces;
765 // add faces to shapes list
766 Explorer anIt( *this );
767 for( ; anIt.More(); anIt.Next() )
768 aShapesList.Append( anIt.Face() );
769 aShapesList.Append( theNewShape );
771 if( aShapesList.Size()==1 && theNewShape.ShapeType()==TopAbs_FACE )
773 aNewFaces.Add( TopoDS::Face( theNewShape ), theNewType );
774 StoreLandCovers( aNewFaces );
778 // prepare pave filler
779 aPaveFiller.SetArguments( aShapesList );
780 aPaveFiller.Perform();
781 Standard_Integer anError = aPaveFiller.ErrorStatus();
785 // add faces to builder
786 BOPAlgo_Builder aBuilder;
788 for( ; anIt.More(); anIt.Next() )
789 aBuilder.AddArgument( anIt.Face() );
790 aBuilder.AddArgument( theNewShape );
792 // perform the partition with the pave filler
793 aBuilder.PerformWithFiller( aPaveFiller );
794 anError = aBuilder.ErrorStatus();
798 //std::cout << "History:" << std::endl;
799 // analysis of the history
800 // a. to fill map of shapes which come from the new face
801 NCollection_IndexedMap<int> aShapesFromNewFace;
802 //std::cout << "from NEW " << theNewShape << ":" << theNewType << std::endl;
803 TopTools_ListOfShape aModified = aBuilder.Modified( theNewShape );
804 TopTools_ListIteratorOfListOfShape aMIt( aModified );
805 for( ; aMIt.More(); aMIt.Next() )
807 //std::cout << " " << aMIt.Value() << std::endl;
808 int aKey = (int)(uintptr_t)aMIt.Value().TShape().operator->();
809 aShapesFromNewFace.Add( aKey );
812 // b. to fill map of parts except parts from new face
814 for( ; anIt.More(); anIt.Next() )
816 QString aSType = anIt.StricklerType();
817 //std::cout << "from " << anIt.Face() << ": " << anIt.StricklerType() << std::endl;
818 TopTools_ListOfShape aModified = aBuilder.Modified( anIt.Face() );
819 if( aModified.Extent() == 0 )
820 aModified.Append( anIt.Face() );
822 TopTools_ListIteratorOfListOfShape aMIt( aModified );
823 for( ; aMIt.More(); aMIt.Next() )
825 TopoDS_Shape aShape = aMIt.Value();
826 bool isFace = aShape.ShapeType()==TopAbs_FACE;
827 int aKey = (int)(uintptr_t)aShape.TShape().operator->();
828 bool isAlsoFromNew = aShapesFromNewFace.Contains( aKey );
829 //std::cout << " " << aShape << " " << isAlsoFromNew << std::endl;
830 if( isFace && !isAlsoFromNew )
831 aNewFaces.Add( TopoDS::Face( aShape ), aSType );
835 // c. add the new shape if it is face with its type
836 if( theNewShape.ShapeType()==TopAbs_FACE )
837 aNewFaces.Add( TopoDS::Face( theNewShape ), theNewType );
839 // convert map of shape to type to compound and list of types
840 StoreLandCovers( aNewFaces );
845 Replace the set of land covers in the land cover map
846 @param theMap the map of shape (face) to Strickler type (string)
848 void HYDROData_LandCoverMap::StoreLandCovers( const HYDROData_MapOfFaceToStricklerType& theMap )
850 TopTools_ListOfShape aListOfFaces;
852 int n = theMap.Size();
854 Handle( TDataStd_ExtStringArray ) aTypes =
855 TDataStd_ExtStringArray::Set( myLab.FindChild( DataTag_Types ), 0, n-1, Standard_True );
857 HYDROData_MapOfFaceToStricklerType::Iterator aNFIt( theMap );
858 for( int i=0; aNFIt.More(); aNFIt.Next(), i++ )
860 TopoDS_Face aFace = aNFIt.Key();
863 QString aType = aNFIt.Value();
864 aListOfFaces.Append(aFace);
865 aTypes->SetValue( i, HYDROData_Tool::toExtString( aType ) );
868 TopoDS_Shape aResult;
869 if( aListOfFaces.Extent() == 1 )
870 aResult = aListOfFaces.First();
871 else if( aListOfFaces.Extent() > 1 )
872 aResult = MergeFaces( aListOfFaces, false );
874 //remove internal edges
875 aResult = RemoveInternal(aResult);
880 Checks that object has 2D presentation. Reimlemented to retun true.
882 bool HYDROData_LandCoverMap::IsHas2dPrs() const
888 Find the land cover for the given point
889 @param thePoint the point laying in some land cover
890 @param theType the returned type
891 @return the found land cover's face
893 TopoDS_Face HYDROData_LandCoverMap::FindByPoint( const gp_Pnt2d& thePoint, QString& theType ) const
895 //TODO: some more optimal algorithm
896 Explorer anIt( *this );
897 for( ; anIt.More(); anIt.Next() )
898 if( HYDROData_Tool::ComputePointState( thePoint.XY(), anIt.Face() ) == TopAbs_IN )
900 theType = anIt.StricklerType();
905 return TopoDS_Face();
910 @param theTreatedObjects the map of treated objects
912 QStringList HYDROData_LandCoverMap::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
914 QStringList aResList = dumpObjectCreation( theTreatedObjects );
915 QString aName = GetObjPyName();
917 //Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
918 //setPythonReferenceObject( theTreatedObjects, aResList, aHydAxis, "SetHydraulicAxis" );
920 //HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
921 //for ( int i = 1, aNb = aSeqOfProfiles.Size(); i <= aNb; ++i )
923 //const Handle(HYDROData_Entity) aProfile = aSeqOfProfiles.Value( i );
924 //setPythonReferenceObject( theTreatedObjects, aResList, aProfile, "AddProfile" );
932 TopoDS_Shape HYDROData_LandCoverMap::RemoveInternal(const TopoDS_Shape& InSh)
934 //Shape must be topologically correct
935 TopExp_Explorer anExp(InSh, TopAbs_EDGE);
936 TopTools_ListOfShape anEdgesToRemove;
938 for(; anExp.More(); anExp.Next() )
940 TopoDS_Edge CurEdge = TopoDS::Edge(anExp.Current());
941 if (CurEdge.Orientation() == TopAbs_INTERNAL)
942 anEdgesToRemove.Append(CurEdge);
945 Handle_ShapeBuild_ReShape aReshape = new ShapeBuild_ReShape();
946 TopoDS_Shape OutSh = aReshape->Apply(InSh);
947 TopTools_ListIteratorOfListOfShape aIt(anEdgesToRemove);
948 for (; aIt.More(); aIt.Next())
949 aReshape->Remove(aIt.Value());
950 OutSh = aReshape->Apply(InSh);
952 Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
959 void HYDROData_LandCoverMap::SetTransparency( double theTransparency )
961 Handle(TDataStd_Real) anAttr;
962 TDF_Label aLabel = myLab.FindChild( DataTag_Transparency );
963 if( !aLabel.FindAttribute( TDataStd_Real::GetID(), anAttr ) )
964 aLabel.AddAttribute( anAttr = new TDataStd_Real() );
965 anAttr->Set( theTransparency );
968 double HYDROData_LandCoverMap::GetTransparency() const
970 Handle(TDataStd_Real) anAttr;
971 TDF_Label aLabel = myLab.FindChild( DataTag_Transparency );
972 if( !aLabel.FindAttribute( TDataStd_Real::GetID(), anAttr ) )
975 return anAttr->Get();