+
+void Dump( const QString& theName, const QStringList& theList, QStringList& theLines )
+{
+ theLines.append( QString( "%1 = QStringList()" ).arg( theName ) );
+ foreach( QString anItem, theList )
+ theLines.append( QString( "%1.append( u\"%2\" )" ).arg( theName ).arg( anItem ) );
+}
+
+/**
+ Dump to Python
+ @param theTreatedObjects the map of treated objects
+*/
+QStringList HYDROData_LandCoverMap::DumpToPython( const QString& thePyScriptPath,
+ MapOfTreatedObjects& theTreatedObjects ) const
+{
+ QStringList aResList = dumpObjectCreation( theTreatedObjects );
+ QString aName = GetObjPyName();
+
+ QString aShpFileName = thePyScriptPath;
+ aShpFileName.replace( ".py", ".shp" );
+ QString aDbfFileName = thePyScriptPath;
+ aDbfFileName.replace( ".py", ".dbf" );
+
+ ExportSHP( aShpFileName, true, 0.1 );
+
+ QString anAttr = "CODE_06"; //TODO: some custom choice
+ QStringList anAttrValues, aTypes;
+ HYDROData_Document::Document( myLab )->CollectQGISValues( anAttr, anAttrValues, aTypes );
+ ExportDBF( aDbfFileName, anAttr, anAttrValues, aTypes );
+
+ aResList << QString( "%1.ImportSHP( '%2' )" ).
+ arg( aName ).arg( QFileInfo( aShpFileName ).fileName() );
+
+ Dump( "attr_values", anAttrValues, aResList );
+ Dump( "types", aTypes, aResList );
+ aResList << QString( "%1.ImportDBF( '%2', '%3', attr_values, types )" ).
+ arg( aName ).arg( QFileInfo( aDbfFileName ).fileName() ).arg( anAttr );
+
+ return aResList;
+}
+
+void HYDROData_LandCoverMap::RemoveInternal(TopoDS_Shape& ShToRebuild, NCollection_IndexedDataMap<TopoDS_Face, TopoDS_Face>* aF2FReplace)
+{
+ //DEBTRACE("RemoveInternal");
+ //Shape must be topologically correct
+ TopExp_Explorer anExpF(ShToRebuild, TopAbs_FACE);
+ //
+ for(; anExpF.More(); anExpF.Next() )
+ {
+ TopoDS_Face CurFace = TopoDS::Face(anExpF.Current());
+ //
+ TopExp_Explorer anExp(CurFace, TopAbs_EDGE);
+ TopTools_ListOfShape anEdgesToRemove;
+ //
+ for(; anExp.More(); anExp.Next() )
+ {
+ TopoDS_Edge CurEdge = TopoDS::Edge(anExp.Current());
+ if (CurEdge.Orientation() == TopAbs_INTERNAL)
+ anEdgesToRemove.Append(CurEdge);
+ }
+ //
+ if (!anEdgesToRemove.IsEmpty())
+ {
+ Handle_ShapeBuild_ReShape aReshape = new ShapeBuild_ReShape();
+ TopoDS_Shape OutF = aReshape->Apply(CurFace);
+ TopTools_ListIteratorOfListOfShape aIt(anEdgesToRemove);
+ for (; aIt.More(); aIt.Next())
+ aReshape->Remove(aIt.Value());
+ OutF = aReshape->Apply(CurFace);
+
+ Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
+ sfs->Init(OutF);
+ sfs->Perform();
+ OutF = sfs->Shape();
+ aF2FReplace->Add(CurFace, TopoDS::Face(OutF));
+ }
+ }
+ //
+ Handle_ShapeBuild_ReShape anExtReshape = new ShapeBuild_ReShape();
+ for (int i = 1; i <= aF2FReplace->Extent(); i++)
+ {
+ TopoDS_Face aFK = aF2FReplace->FindKey(i);
+ TopoDS_Face aFV = aF2FReplace->FindFromIndex(i);
+ anExtReshape->Replace(aFK, aFV);
+ ShToRebuild = anExtReshape->Apply(ShToRebuild);
+ }
+// for (int i = 1; i <= aF2FReplace->Extent(); i++)
+// {
+// DEBTRACE("aF2FReplace key,value " << aF2FReplace->FindKey(i) << " " << aF2FReplace->FindFromIndex(i));
+// }
+
+}
+
+void HYDROData_LandCoverMap::SetTransparency( double theTransparency )
+{
+ SetDouble( DataTag_Transparency, theTransparency );
+}
+
+double HYDROData_LandCoverMap::GetTransparency() const
+{
+ return GetDouble( DataTag_Transparency, 0.5 );
+}
+
+bool HYDROData_LandCoverMap::ImportSHP( const QString& theSHPFileName,
+ const QList<int>& theIndices )
+{
+ HYDROData_ShapeFile anImporter;
+ QStringList aPolyList;
+ TopTools_SequenceOfShape aFaces;
+ int aSHapeType = -1;
+ int Stat = anImporter.ImportPolygons(HYDROData_Document::Document(1), theSHPFileName, aPolyList, aFaces, aSHapeType);
+ //
+ if (Stat != 1)
+ return false;
+ //
+ HYDROData_MapOfFaceToStricklerType aMapFace2ST;
+ int maxInd = *std::max_element(theIndices.begin(), theIndices.end());
+ if (maxInd > aPolyList.length())
+ return false;
+ //
+ if (theIndices.empty())
+ {
+ //import all shapes
+ for ( int i = 1; i <=aFaces.Length(); i++ )
+ {
+ TopoDS_Shape aShape = aFaces(i);
+ if ( aShape.IsNull() )
+ continue;
+ aMapFace2ST.Add( TopoDS::Face( aShape ), "" );
+ }
+ }
+ else
+ {
+ //import given indices
+ foreach ( int Ind, theIndices )
+ {
+ TopoDS_Shape aShape = aFaces(Ind + 1);
+ if ( aShape.IsNull() )
+ continue;
+ aMapFace2ST.Add( TopoDS::Face( aShape ), "" );
+ }
+ }
+ //
+ StoreLandCovers(aMapFace2ST);
+ return true;
+}
+
+bool HYDROData_LandCoverMap::ExportSHP( const QString& theSHPFileName, bool bUseDiscr, double theDefl) const
+{
+ HYDROData_ShapeFile anExporter;
+ QStringList aList;
+ anExporter.Export(HYDROData_Document::Document(1), theSHPFileName, this, aList, bUseDiscr, theDefl );
+ if (aList.empty())
+ return true;
+ else
+ return false;
+}
+
+bool HYDROData_LandCoverMap::CheckLinear()
+{
+ TopoDS_Shape InpShape = GetShape();
+ TopExp_Explorer anEdgeEx(InpShape, TopAbs_EDGE);
+ for (; anEdgeEx.More(); anEdgeEx.Next())
+ {
+ TopoDS_Edge E = TopoDS::Edge(anEdgeEx.Current());
+ double aFP, aLP;
+ Handle_Geom_Curve aCur = BRep_Tool::Curve(E, aFP, aLP);
+ Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast(aCur);
+ if (aLine.IsNull())
+ {
+ Handle(Geom_TrimmedCurve) aTC = Handle(Geom_TrimmedCurve)::DownCast(aCur);
+ if (!aTC.IsNull())
+ {
+ Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast(aTC->BasisCurve());
+ if (aLine.IsNull())
+ return false;
+ }
+ else
+ return false;
+ }
+ }
+ return true;
+}
+
+void HYDROData_LandCoverMap::UpdateLocalCS( double theDx, double theDy )
+{
+ TopoDS_Shape aShape = GetShape();
+ TopoDS_Shape aLocatedShape = HYDROData_ShapesTool::Translated( aShape, theDx, theDy, 0 );
+ SetShape( aLocatedShape );
+}
+
+void HYDROData_LandCoverMap::ClassifyPoints( const std::vector<gp_XY>& thePoints, std::vector<std::set <QString> >& theTypes ) const
+{
+ HYDROData_LCM_FaceClassifier FC(this);
+ FC.Classify(thePoints, theTypes, NULL);
+}
+
+void HYDROData_LandCoverMap::ClassifyPoints( const std::vector<gp_XY>& thePoints,
+ Handle(HYDROData_StricklerTable) theTable,
+ std::vector<double>& theCoeffs, double DefValue, bool UseMax ) const
+{
+ std::vector<std::set <QString> > Types;
+ HYDROData_LCM_FaceClassifier FC(this);
+ FC.Classify(thePoints, Types, NULL);
+ theCoeffs.resize(thePoints.size());
+ for (size_t i = 0; i < Types.size(); i++)
+ {
+ const std::set<QString>& SStr = Types[i];
+ if (SStr.empty())
+ theCoeffs[i] = DefValue;
+ else
+ {
+ std::set<QString>::const_iterator it;
+ std::vector<double> C1(SStr.size());
+ for (it = SStr.begin(); it != SStr.end(); ++it)
+ C1.push_back(theTable->Get( *it, DefValue ));
+ double Val;
+ if (UseMax)
+ Val = *(std::max_element(std::begin(C1), std::end(C1)));
+ else
+ Val = *(std::min_element(std::begin(C1), std::end(C1)));
+ theCoeffs[i] = Val;
+ }
+ }
+}