Skip to content
Permalink
Browse files

[Backport release-3_12] fix mesh calculator

  • Loading branch information
vcloarec authored and nyalldawson committed Apr 27, 2020
1 parent 0d0c3bc commit 1f2374f6d8514d9726fec23d9f325b2b6968f26c
@@ -736,7 +736,40 @@ Returns whether the faces are active for particular dataset
.. versionadded:: 3.6
%End

virtual bool persistDatasetGroup( const QString &path,
virtual bool persistDatasetGroup( const QString &path,
const QgsMeshDatasetGroupMetadata &meta,
const QVector<QgsMeshDataBlock> &datasetValues,
const QVector<QgsMeshDataBlock> &datasetActive,
const QVector<double> &times
) /Deprecated/;
%Docstring
Creates a new dataset group from a data and
persists it into a destination path

On success, the mesh's dataset group count is changed

:param path: destination path of the stored file in form DRIVER_NAME:path
:param meta: new group's metadata
:param datasetValues: scalar/vector values for all datasets and all faces/vertices in the group
:param datasetActive: active flag values for all datasets in the group. Empty array represents can be used
when all faces are active
:param times: times in hours for all datasets in the group

:return: ``True`` on failure, ``False`` on success

.. note::

Doesn't work if there is ":" in the path (e.g. Windows system)


.. versionadded:: 3.6

.. deprecated::
QGIS 3.12.3
%End

virtual bool persistDatasetGroup( const QString &outputFilePath,
const QString &outputDriver,
const QgsMeshDatasetGroupMetadata &meta,
const QVector<QgsMeshDataBlock> &datasetValues,
const QVector<QgsMeshDataBlock> &datasetActive,
@@ -748,7 +781,8 @@ persists it into a destination path

On success, the mesh's dataset group count is changed

:param path: destination path of the stored file in form DRIVER_NAME:path
:param outputFilePath: destination path of the stored file
:param outputDriver: output driver name
:param meta: new group's metadata
:param datasetValues: scalar/vector values for all datasets and all faces/vertices in the group
:param datasetActive: active flag values for all datasets in the group. Empty array represents can be used
@@ -757,7 +791,7 @@ On success, the mesh's dataset group count is changed

:return: ``True`` on failure, ``False`` on success

.. versionadded:: 3.6
.. versionadded:: 3.12.3
%End
};

@@ -235,7 +235,8 @@ QgsMeshCalculator::Result QgsMeshCalculator::processCalculation( QgsFeedback *fe

const QgsMeshDatasetGroupMetadata meta = outputGroup->groupMetadata();
bool err = mMeshLayer->dataProvider()->persistDatasetGroup(
mOutputDriver + ':' + mOutputFile,
mOutputFile,
mOutputDriver,
meta,
datasetValues,
datasetActive,
@@ -58,6 +58,27 @@ QgsMeshDataProvider::QgsMeshDataProvider( const QString &uri, const QgsDataProvi
{
}

bool QgsMeshDatasetSourceInterface::persistDatasetGroup(
const QString &path,
const QgsMeshDatasetGroupMetadata &meta,
const QVector<QgsMeshDataBlock> &datasetValues,
const QVector<QgsMeshDataBlock> &datasetActive,
const QVector<double> &times )
{
// Form DRIVER:filename
QString filename = path;
// ASCII dat supports face, edge and vertex datasets
QString driverName = QStringLiteral( "DAT" );
QStringList parts = path.split( ':' );
if ( parts.size() > 1 )
{
driverName = parts[0];
parts.removeFirst();
filename = parts.join( QString() );
}
return persistDatasetGroup( filename, driverName, meta, datasetValues, datasetActive, times );
}

QgsMeshDatasetValue::QgsMeshDatasetValue( double x, double y )
: mX( x ), mY( y )
{}
@@ -714,9 +714,37 @@ class CORE_EXPORT QgsMeshDatasetSourceInterface SIP_ABSTRACT
* \param times times in hours for all datasets in the group
* \returns TRUE on failure, FALSE on success
*
* \note Doesn't work if there is ":" in the path (e.g. Windows system)
*
* \since QGIS 3.6
* \deprecated QGIS 3.12.3
*/
Q_DECL_DEPRECATED virtual bool persistDatasetGroup( const QString &path,
const QgsMeshDatasetGroupMetadata &meta,
const QVector<QgsMeshDataBlock> &datasetValues,
const QVector<QgsMeshDataBlock> &datasetActive,
const QVector<double> &times
) SIP_DEPRECATED;

/**
* Creates a new dataset group from a data and
* persists it into a destination path
*
* On success, the mesh's dataset group count is changed
*
* \param outputFilePath destination path of the stored file
* \param outputDriver output driver name
* \param meta new group's metadata
* \param datasetValues scalar/vector values for all datasets and all faces/vertices in the group
* \param datasetActive active flag values for all datasets in the group. Empty array represents can be used
* when all faces are active
* \param times times in hours for all datasets in the group
* \returns TRUE on failure, FALSE on success
*
* \since QGIS 3.12.3
*/
virtual bool persistDatasetGroup( const QString &path,
virtual bool persistDatasetGroup( const QString &outputFilePath,
const QString &outputDriver,
const QgsMeshDatasetGroupMetadata &meta,
const QVector<QgsMeshDataBlock> &datasetValues,
const QVector<QgsMeshDataBlock> &datasetActive,
@@ -539,13 +539,15 @@ QgsMeshDataBlock QgsMeshMemoryDataset::areFacesActive( int faceIndex, int count
return ret;
}

bool QgsMeshMemoryDataProvider::persistDatasetGroup( const QString &path,
bool QgsMeshMemoryDataProvider::persistDatasetGroup( const QString &outputFilePath,
const QString &outputDriver,
const QgsMeshDatasetGroupMetadata &meta,
const QVector<QgsMeshDataBlock> &datasetValues,
const QVector<QgsMeshDataBlock> &datasetActive,
const QVector<double> &times )
{
Q_UNUSED( path )
Q_UNUSED( outputFilePath )
Q_UNUSED( outputDriver )
Q_UNUSED( meta )
Q_UNUSED( datasetValues )
Q_UNUSED( datasetActive )
@@ -151,7 +151,8 @@ class CORE_EXPORT QgsMeshMemoryDataProvider final: public QgsMeshDataProvider

bool isFaceActive( QgsMeshDatasetIndex index, int faceIndex ) const override;
QgsMeshDataBlock areFacesActive( QgsMeshDatasetIndex index, int faceIndex, int count ) const override;
bool persistDatasetGroup( const QString &path,
bool persistDatasetGroup( const QString &outputFilePath,
const QString &outputDriver,
const QgsMeshDatasetGroupMetadata &meta,
const QVector<QgsMeshDataBlock> &datasetValues,
const QVector<QgsMeshDataBlock> &datasetActive,
@@ -162,12 +162,14 @@ QgsRectangle QgsMdalProvider::extent() const
return ret;
}

bool QgsMdalProvider::persistDatasetGroup( const QString &path,
const QgsMeshDatasetGroupMetadata &meta,
const QVector<QgsMeshDataBlock> &datasetValues,
const QVector<QgsMeshDataBlock> &datasetActive,
const QVector<double> &times
)
bool QgsMdalProvider::persistDatasetGroup(
const QString &outputFilePath,
const QString &outputDriver,
const QgsMeshDatasetGroupMetadata &meta,
const QVector<QgsMeshDataBlock> &datasetValues,
const QVector<QgsMeshDataBlock> &datasetActive,
const QVector<double> &times
)
{
if ( !mMeshH )
return true;
@@ -190,22 +192,10 @@ bool QgsMdalProvider::persistDatasetGroup( const QString &path,
return true;
}

if ( path.isEmpty() )
if ( outputFilePath.isEmpty() )
return true;

// Form DRIVER:filename
QString filename = path;
// ASCII dat supports both face and vertex datasets
QString driverName = QStringLiteral( "DAT" );
QStringList parts = path.split( ':' );
if ( parts.size() > 1 )
{
driverName = parts[0];
parts.removeFirst();
filename = parts.join( QString() );
}

DriverH driver = MDAL_driverFromName( driverName.toStdString().c_str() );
DriverH driver = MDAL_driverFromName( outputDriver.toStdString().c_str() );
if ( !driver )
return true;

@@ -229,7 +219,7 @@ bool QgsMdalProvider::persistDatasetGroup( const QString &path,
location,
meta.isScalar(),
driver,
path.toStdString().c_str()
outputFilePath.toStdString().c_str()
);
if ( !g )
return true;
@@ -76,7 +76,8 @@ class QgsMdalProvider : public QgsMeshDataProvider
QgsMeshDataBlock areFacesActive( QgsMeshDatasetIndex index, int faceIndex, int count ) const override;
QgsRectangle extent() const override;

bool persistDatasetGroup( const QString &path,
bool persistDatasetGroup( const QString &outputFilePath,
const QString &outputDriver,
const QgsMeshDatasetGroupMetadata &meta,
const QVector<QgsMeshDataBlock> &datasetValues,
const QVector<QgsMeshDataBlock> &datasetActive,
@@ -48,6 +48,9 @@ class TestQgsMeshCalculator : public QObject
void calcWithVertexLayers();
void calcWithFaceLayers();
void calcWithMixedLayers();

void calcAndSave();

private:

QgsMeshLayer *mpMeshLayer = nullptr;
@@ -292,5 +295,26 @@ void TestQgsMeshCalculator::calcWithMixedLayers()
QCOMPARE( val.scalar(), 2.0 );
}

void TestQgsMeshCalculator::calcAndSave()
{
QgsRectangle extent( 1000.000, 1000.000, 3000.000, 3000.000 );

QString tempFilePath = QDir::tempPath() + '/' + "meshCalculatorResult.out";
QgsMeshCalculator rc( QStringLiteral( "\"VertexScalarDataset\" + \"FaceScalarDataset\"" ),
QStringLiteral( "BINARY_DAT" ),
"NewMixScalarDataset",
tempFilePath,
extent,
0,
3600,
mpMeshLayer
);

rc.processCalculation();

QFileInfo fileInfo( tempFilePath );
QVERIFY( fileInfo.exists() );
}

QGSTEST_MAIN( TestQgsMeshCalculator )
#include "testqgsmeshcalculator.moc"

0 comments on commit 1f2374f

Please sign in to comment.
You can’t perform that action at this time.