Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vcloarec committed Aug 30, 2022
1 parent e3e53b3 commit 0d70559
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 27 deletions.
26 changes: 16 additions & 10 deletions src/core/GIS/private/reosmesh_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "reosparameter.h"
#include "reosencodedelement.h"
#include "reosmapextent.h"
#include "reostopographycollection.h"

ReosMeshFrame_p::ReosMeshFrame_p( const QString &crs, QObject *parent ): ReosMesh( parent )
{
Expand All @@ -36,11 +37,11 @@ ReosMeshFrame_p::ReosMeshFrame_p( const QString &crs, QObject *parent ): ReosMes
qgisCrs.createFromWkt( crs );
mMeshLayer->setCrs( qgisCrs );
meshProvider()->overrideCrs( qgisCrs );

mMeshLayer->updateTriangularMesh();
init();
}

ReosMeshFrame_p::ReosMeshFrame_p( const QString &dataPath )
ReosMeshFrame_p::ReosMeshFrame_p( const QString &dataPath, const QString &destinationCrs )
{
mMeshLayer.reset( new QgsMeshLayer( "path", "", QStringLiteral( "ReosMesh" ) ) );

Expand All @@ -50,7 +51,11 @@ ReosMeshFrame_p::ReosMeshFrame_p( const QString &dataPath )
meshProvider()->loadMeshFrame( dir.filePath( QStringLiteral( "meshFrame.nc" ) ), QStringLiteral( "Ugrid" ) );
mMeshLayer->setCrs( meshProvider()->crs() );
mMeshLayer->reload();
}
QgsCoordinateReferenceSystem qgisDestinationCrs;
qgisDestinationCrs.createFromWkt( destinationCrs );
QgsCoordinateTransform transform( meshProvider()->crs(), qgisDestinationCrs, QgsProject::instance() );
mMeshLayer->updateTriangularMesh( transform );
};

init();
}
Expand Down Expand Up @@ -297,7 +302,7 @@ QPointF ReosMeshFrame_p::vertexPosition( int vertexIndex, const QString &destina
return mMeshLayer->nativeMesh()->vertices.at( vertexIndex ).toQPointF();

QgsCoordinateReferenceSystem crs;
crs.fromWkt( destinationCrs );
crs.createFromWkt( destinationCrs );
QgsCoordinateTransform transform( mMeshLayer->crs(), crs, QgsProject::instance() );
QgsPointXY vert = mMeshLayer->nativeMesh()->vertices.at( vertexIndex );
if ( transform.isValid() )
Expand Down Expand Up @@ -358,7 +363,7 @@ void ReosMeshFrame_p::updateWireFrameSettings()
QPointF ReosMeshFrame_p::tolayerCoordinates( const ReosSpatialPosition &position ) const
{
QgsCoordinateReferenceSystem sourceCrs;
sourceCrs.fromWkt( position.crs() );
sourceCrs.createFromWkt( position.crs() );

const QgsCoordinateTransform transform( sourceCrs, mMeshLayer->crs(), QgsProject::instance() );
QgsPointXY ret;
Expand Down Expand Up @@ -859,12 +864,13 @@ class ApplyTopopraphyProcess : public ReosProcess
ApplyTopopraphyProcess( ReosTopographyCollection *topographyCollection, ReosMeshDataProvider_p *meshProvider )
: mTopographyCollection( topographyCollection )
, mProvider( meshProvider )
{
{}


}
void start()
{
mProvider->applyTopographyOnVertices( mTopographyCollection, this );
mIsSuccessful = true;
}

private:
Expand All @@ -877,13 +883,13 @@ ReosProcess *ReosMeshFrame_p::applyTopographyOnVertices( ReosTopographyCollectio
if ( mMeshLayer->isEditable() )
stopFrameEditing( true );


std::unique_ptr<ReosProcess> process( new ApplyTopopraphyProcess( topographyCollection, meshProvider() ) );

connect( process.get(), &ReosProcess::finished, this, [this]
connect( process.get(), &ReosProcess::finished, this, [this, topographyCollection]
{
mMeshLayer->reload();

QgsCoordinateTransform tranform( mMeshLayer->crs(), QgsCoordinateReferenceSystem::fromWkt( topographyCollection->gisEngine()->crs() ), QgsProject::instance()->transformContext() );
mMeshLayer->updateTriangularMesh( tranform );
if ( mZVerticesDatasetGroup )
mZVerticesDatasetGroup->setStatisticObsolete();

Expand Down
4 changes: 2 additions & 2 deletions src/core/GIS/private/reosmesh_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ReosMeshFrame_p : public ReosMesh
{
public:
ReosMeshFrame_p( const QString &crs, QObject *parent );
ReosMeshFrame_p( const QString &dataPath );
ReosMeshFrame_p( const QString &dataPath, const QString &destinationCrs );

bool isValid() const override;
int vertexCount() const override;
Expand All @@ -56,7 +56,7 @@ class ReosMeshFrame_p : public ReosMesh
void generateMesh( const ReosMeshFrameData &data ) override;
QString crs() const override;
QObject *data() const override;
ReosProcess *applyTopographyOnVertices( ReosTopographyCollection *topographyCollection ) override;
ReosProcess *applyTopographyOnVertices(ReosTopographyCollection *topographyCollection ) override;
double datasetScalarValueAt( const QString &datasetId, const QPointF &pos ) const override;
void datasetGroupMinimumMaximum( const QString &datasetId, double &min, double &max ) const override;
void save( const QString &dataPath ) override;
Expand Down
8 changes: 4 additions & 4 deletions src/core/GIS/private/reospolylinesstructure_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ ReosGeometryStructure_p::ReosGeometryStructure_p( const QString &type, const QS
QgsPointXY ReosGeometryStructure_p::toLayerCoordinates( const ReosSpatialPosition &position ) const
{
QgsCoordinateReferenceSystem crs;
crs.fromWkt( position.crs() );
crs.createFromWkt( position.crs() );

QgsCoordinateTransform transform( crs, mVectorLayer->crs(), QgsProject::instance() );

Expand All @@ -57,15 +57,15 @@ QgsPointXY ReosGeometryStructure_p::transformCoordinates( const QPointF &positio
const QgsCoordinateTransform ReosGeometryStructure_p::toLayerTransform( const QString &crs ) const
{
QgsCoordinateReferenceSystem qgsCrs;
qgsCrs.fromWkt( crs );
qgsCrs.createFromWkt( crs );

return QgsCoordinateTransform( qgsCrs, mVectorLayer->crs(), QgsProject::instance() );
}

const QgsCoordinateTransform ReosGeometryStructure_p::toDestinationTransform( const QString &destinationCrs ) const
{
QgsCoordinateReferenceSystem qgsCrs;
qgsCrs.fromWkt( destinationCrs );
qgsCrs.createFromWkt( destinationCrs );

return QgsCoordinateTransform( mVectorLayer->crs(), qgsCrs, QgsProject::instance() );
}
Expand Down Expand Up @@ -1936,7 +1936,7 @@ bool ReosPolylineStructureVectorLayer::isOnBoundary( ReosGeometryStructureVertex
double ReosPolylineStructureVectorLayer::tolerance( const QString &wktCrs ) const
{
QgsCoordinateReferenceSystem destCrs;
destCrs.fromWkt( wktCrs );
destCrs.createFromWkt( wktCrs );

QgsUnitTypes::DistanceUnit destUnit = destCrs.mapUnits();
QgsUnitTypes::DistanceUnit layerUnit = mVectorLayer->crs().mapUnits();
Expand Down
4 changes: 2 additions & 2 deletions src/core/GIS/reosmesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ ReosMesh *ReosMesh::createMeshFrame( const QString &crs, QObject *parent )
return new ReosMeshFrame_p( crs, parent );
}

ReosMesh *ReosMesh::createMeshFrameFromFile( const QString &dataPath )
ReosMesh *ReosMesh::createMeshFrameFromFile( const QString &dataPath, const QString &destinationCrs )
{
return new ReosMeshFrame_p( dataPath );
return new ReosMeshFrame_p( dataPath, destinationCrs );
}


Expand Down
5 changes: 3 additions & 2 deletions src/core/GIS/reosmesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
#include <QSet>

#include "reoscore.h"
#include "reosgisengine.h"
#include "reosrenderedobject.h"
#include "reosencodedelement.h"

class ReosMeshGenerator;
class ReosMeshFrameData;
class ReosDigitalElevationModel;
class ReosMap;
class ReosTopographyCollection;
class ReosParameterDouble;
class ReosParameterInteger;
Expand All @@ -37,6 +37,7 @@ class ReosParameterArea;
class ReosHydraulicSimulationResults;
class ReosSpatialPosition;
class ReosMeshDatasetSource;
class ReosGisEngine;


class ReosMeshQualityChecker : public ReosProcess
Expand Down Expand Up @@ -110,7 +111,7 @@ class REOSCORE_EXPORT ReosMesh: public ReosRenderedObject
//! Creates a new void mesh in memory
static ReosMesh *createMeshFrame( const QString &crs = QString(), QObject *parent = nullptr );

static ReosMesh *createMeshFrameFromFile( const QString &dataPath );
static ReosMesh *createMeshFrameFromFile( const QString &dataPath, const QString &destinationCrs );

//! Returns whether the mesh is valid
virtual bool isValid() const = 0;
Expand Down
5 changes: 5 additions & 0 deletions src/core/GIS/reostopographycollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ ReosTopographyCollection::ReosTopographyCollection( const ReosEncodedElement &el
}
}

ReosGisEngine *ReosTopographyCollection::gisEngine() const
{
return mGisEngine;
}

ReosParameterBoolean *ReosTopographyCollection::autoApply() const
{
return mAutoApply;
Expand Down
4 changes: 3 additions & 1 deletion src/core/GIS/reostopographycollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ class REOSCORE_EXPORT ReosTopographyCollection : public ReosDataObject

ReosParameterBoolean *autoApply() const;

protected:
ReosGisEngine *gisEngine() const;

protected:
explicit ReosTopographyCollection( ReosGisEngine *gisEngine, QObject *parent = nullptr );
explicit ReosTopographyCollection( const ReosEncodedElement &element, ReosGisEngine *gisEngine, QObject *parent = nullptr );

Expand Down
2 changes: 1 addition & 1 deletion src/core/data/reosdataobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class REOSCORE_EXPORT ReosDataObject: public QObject
void deregisterUpstreamData( ReosDataObject *data );
void setActualized() const;

//! Return true whether the data need to be calculated ot updated
//! Return true whether the data need to be calculated or updated
bool isObsolete() const;

protected slots:
Expand Down
8 changes: 8 additions & 0 deletions src/core/hydraulicNetwork/reoshydraulicnetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,14 @@ ReosHydraulicNetwork *ReosHydraulicNetworkContext::network() const
return mNetwork;
}

QString ReosHydraulicNetworkContext::crs() const
{
if ( mNetwork->gisEngine() )
return mNetwork->gisEngine()->crs();

return QString();
}

QString ReosHydraulicNetworkContext::projectPath() const
{
return mProjectPath;
Expand Down
2 changes: 2 additions & 0 deletions src/core/hydraulicNetwork/reoshydraulicnetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ class REOSCORE_EXPORT ReosHydraulicNetworkContext
ReosWatershedModule *watershedModule() const;
ReosHydraulicNetwork *network() const;

QString crs() const;

QString projectPath() const;
QString projectName() const;

Expand Down
7 changes: 6 additions & 1 deletion src/core/hydraulicNetwork/reoshydraulicstructure2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ ReosHydraulicStructure2D::ReosHydraulicStructure2D(
else
mMeshResolutionController = new ReosMeshResolutionController( this );

mMesh.reset( ReosMesh::createMeshFrameFromFile( structureDirectory().path() ) );
mMesh.reset( ReosMesh::createMeshFrameFromFile( structureDirectory().path(), context.crs() ) );
init();

mMesh->setQualityMeshParameter( encodedElement.getEncodedData( QStringLiteral( "mesh-quality-parameters" ) ) );
Expand Down Expand Up @@ -412,6 +412,11 @@ QString ReosHydraulicStructure2D::terrainMeshDatasetId() const
return mMesh->verticesElevationDatasetId();
}

double ReosHydraulicStructure2D::terrainElevationAt( const QPointF &position )
{
return mMesh->datasetScalarValueAt( terrainMeshDatasetId(), position );
}

void ReosHydraulicStructure2D::activateResultDatasetGroup( const QString &id )
{
mMesh->activateDataset( id );
Expand Down
5 changes: 4 additions & 1 deletion src/core/hydraulicNetwork/reoshydraulicstructure2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ class REOSCORE_EXPORT ReosHydraulicStructure2D : public ReosHydraulicNetworkElem
//! Returns the id of the terrain dataset
QString terrainMeshDatasetId() const;

//! Returns the elevation of the terran at \a position in map coordinates
double terrainElevationAt( const QPointF &position );

//! Deactivates any activated scalar dataset
void deactivateMeshScalar();

Expand Down Expand Up @@ -215,7 +218,7 @@ class REOSCORE_EXPORT ReosHydraulicStructure2D : public ReosHydraulicNetworkElem

void exportResultAsMesh( const QString &fileName ) const;

void exportResultAsMeshInGisProject(const QString &fileName , bool keepLayers);
void exportResultAsMeshInGisProject( const QString &fileName, bool keepLayers );

public slots:
void updateCalculationContext( const ReosCalculationContext &context ) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ QString ReosHydraulicSimulationResults::groupName( int groupIndex ) const
return tr( "Velocity" );
break;
}

return QString();
}

bool ReosHydraulicSimulationResults::groupIsScalar( int groupIndex ) const
Expand Down
6 changes: 3 additions & 3 deletions src/core/utils/reosgeometryutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ QPolygonF ReosGeometryUtils::polygonCutByPolygons( const QPolygonF &polygon1, co
QPolygonF ReosGeometryUtils::polygonUnion( const QPolygonF &polygon1, const QPolygonF &polygon2 )
{
QgsGeometry geom1( createQgsPolygon( polygon1 ) );
QgsGeometry geom2( createQgsPolygon( polygon2 ) );
const QgsGeometry geom2( createQgsPolygon( polygon2 ) );

QPolygonF ret = geom1.combine( geom2 ).asQPolygonF();

Expand All @@ -192,7 +192,7 @@ QPolygonF ReosGeometryUtils::polygonUnion( const QPolygonF &polygon1, const QPol

int ReosGeometryUtils::closestSegment( const QPointF &point, const QPolygonF &polyline )
{
QgsGeometry poly( createQgsPolyline( polyline ) );
const QgsGeometry poly( createQgsPolyline( polyline ) );

QgsPointXY returnPoint;
int secondIndex;
Expand All @@ -203,7 +203,7 @@ int ReosGeometryUtils::closestSegment( const QPointF &point, const QPolygonF &po

double ReosGeometryUtils::projectedPointDistanceFromBegining( const QPointF &point, const QPolygonF &polyline )
{
QgsGeometry polyGeom = QgsGeometry::fromQPolygonF( polyline );
const QgsGeometry polyGeom = QgsGeometry::fromQPolygonF( polyline );
return polyGeom.lineLocatePoint( QgsGeometry::fromQPointF( point ) );
}

Expand Down

0 comments on commit 0d70559

Please sign in to comment.