23 const QString &formulaString,
25 qint64 relativeStartTime,
26 qint64 relativeEndTime ):
28 , mFormula( formulaString )
30 , mStartTime( relativeStartTime )
31 , mEndTime( relativeEndTime )
38 mCalcNode.reset( QgsMeshCalcNode::parseMeshCalcString( mFormula, errMessage ) );
40 if ( !mCalcNode || !mLayer )
43 mDatasetGroupNameUsed = mCalcNode->usedDatasetGroupNames();
44 setDataType( QgsMeshCalcUtils::determineResultDataType( mLayer, mDatasetGroupNameUsed ) );
47 QMap<QString, int> usedDatasetGroupindexes;
49 for (
int i : indexes )
52 if ( mDatasetGroupNameUsed.contains( usedName ) )
53 usedDatasetGroupindexes[usedName] = i;
57 if ( !mCalcNode->isNonTemporal() )
60 const QList<int> &usedIndexes = usedDatasetGroupindexes.values();
61 for (
int groupIndex : usedIndexes )
69 for (
int i = 0; i < dsCount; i++ )
78 if ( times.isEmpty() )
81 mDatasetTimes = qgis::setToList( times );
82 std::sort( mDatasetTimes.begin(), mDatasetTimes.end() );
84 mDatasetMetaData = QVector<QgsMeshDatasetMetadata>( mDatasetTimes.count() );
88 while ( i < mDatasetTimes.count() )
90 mCurrentDatasetIndex = i;
91 if ( calculateDataset() )
94 mDatasetTimes.removeAt( i );
102 return mDatasetTimes.count();
107 if ( index < 0 || index >= mDatasetTimes.count() )
110 if ( index != mCurrentDatasetIndex )
112 mCurrentDatasetIndex = index;
116 return mCacheDataset.get();
121 if ( datasetIndex < 0 && datasetIndex >= mDatasetMetaData.count() )
124 return mDatasetMetaData.at( datasetIndex );
129 return mDatasetGroupNameUsed;
135 QDomElement elemDataset = doc.createElement( QStringLiteral(
"mesh-dataset" ) );
136 elemDataset.setAttribute( QStringLiteral(
"source-type" ), QStringLiteral(
"virtual" ) );
137 elemDataset.setAttribute( QStringLiteral(
"name" ),
name() );
138 elemDataset.setAttribute( QStringLiteral(
"formula" ), mFormula );
139 elemDataset.setAttribute( QStringLiteral(
"start-time" ), mStartTime );
140 elemDataset.setAttribute( QStringLiteral(
"end-time" ), mEndTime );
150 bool QgsMeshVirtualDatasetGroup::calculateDataset()
const
155 QgsMeshCalcUtils dsu( mLayer, mDatasetGroupNameUsed,
QgsInterval( mDatasetTimes[mCurrentDatasetIndex] / 1000.0 ) );
157 if ( !dsu.isValid() )
161 std::unique_ptr<QgsMeshMemoryDatasetGroup> outputGroup = qgis::make_unique<QgsMeshMemoryDatasetGroup> ( QString(), dsu.outputType() );
162 mCalcNode->calculate( dsu, *outputGroup );
164 if ( outputGroup->memoryDatasets.isEmpty() )
167 mCacheDataset = outputGroup->memoryDatasets[0];
168 if ( !mDatasetMetaData[mCurrentDatasetIndex].isValid() )
170 mCacheDataset->calculateMinMax();
171 mCacheDataset->time = mDatasetTimes[mCurrentDatasetIndex] / 3600.0 / 1000.0;
172 mDatasetMetaData[mCurrentDatasetIndex] = mCacheDataset->metadata();