22#include "qgsmeshmemorydataprovider.h"
24QgsMeshCalcNode::QgsMeshCalcNode()
29QgsMeshCalcNode::QgsMeshCalcNode(
double number )
36QgsMeshCalcNode::QgsMeshCalcNode( Operator op, QgsMeshCalcNode *left, QgsMeshCalcNode *right )
44QgsMeshCalcNode::QgsMeshCalcNode( QgsMeshCalcNode *condition ,
45 QgsMeshCalcNode *left ,
46 QgsMeshCalcNode *right )
50 , mCondition( condition )
55QgsMeshCalcNode::QgsMeshCalcNode(
const QString &datasetGroupName )
56 : mType( tDatasetGroupRef )
57 , mDatasetGroupName( datasetGroupName )
59 if ( mDatasetGroupName.startsWith(
'"' ) && mDatasetGroupName.endsWith(
'"' ) )
60 mDatasetGroupName = mDatasetGroupName.mid( 1, mDatasetGroupName.size() - 2 );
63QgsMeshCalcNode::~QgsMeshCalcNode() =
default;
65QgsMeshCalcNode::Type QgsMeshCalcNode::type()
const
70void QgsMeshCalcNode::setLeft( QgsMeshCalcNode *left )
75void QgsMeshCalcNode::setRight( QgsMeshCalcNode *right )
77 mRight.reset( right );
80QStringList QgsMeshCalcNode::usedDatasetGroupNames()
const
84 if ( mType == tDatasetGroupRef )
86 res.append( mDatasetGroupName );
91 res += mLeft->usedDatasetGroupNames();
96 res += mRight->usedDatasetGroupNames();
101 res += mCondition->usedDatasetGroupNames();
107QStringList QgsMeshCalcNode::aggregatedUsedDatasetGroupNames()
const
113 case QgsMeshCalcNode::opPLUS:
114 case QgsMeshCalcNode::opMINUS:
115 case QgsMeshCalcNode::opMUL:
116 case QgsMeshCalcNode::opDIV:
117 case QgsMeshCalcNode::opPOW:
118 case QgsMeshCalcNode::opEQ:
119 case QgsMeshCalcNode::opNE:
120 case QgsMeshCalcNode::opGT:
121 case QgsMeshCalcNode::opLT:
122 case QgsMeshCalcNode::opGE:
123 case QgsMeshCalcNode::opLE:
124 case QgsMeshCalcNode::opAND:
125 case QgsMeshCalcNode::opOR:
126 case QgsMeshCalcNode::opNOT:
127 case QgsMeshCalcNode::opIF:
128 case QgsMeshCalcNode::opSIGN:
129 case QgsMeshCalcNode::opMIN:
130 case QgsMeshCalcNode::opMAX:
131 case QgsMeshCalcNode::opABS:
132 case QgsMeshCalcNode::opNONE:
135 res += mLeft->aggregatedUsedDatasetGroupNames();
140 res += mRight->aggregatedUsedDatasetGroupNames();
145 res += mCondition->aggregatedUsedDatasetGroupNames();
148 case QgsMeshCalcNode::opSUM_AGGR:
149 case QgsMeshCalcNode::opMAX_AGGR:
150 case QgsMeshCalcNode::opMIN_AGGR:
151 case QgsMeshCalcNode::opAVG_AGGR:
154 res += mLeft->usedDatasetGroupNames();
159 res += mRight->usedDatasetGroupNames();
164 res += mCondition->usedDatasetGroupNames();
172QStringList QgsMeshCalcNode::notAggregatedUsedDatasetGroupNames()
const
176 if ( mType == tDatasetGroupRef )
178 res.append( mDatasetGroupName );
183 case QgsMeshCalcNode::opPLUS:
184 case QgsMeshCalcNode::opMINUS:
185 case QgsMeshCalcNode::opMUL:
186 case QgsMeshCalcNode::opDIV:
187 case QgsMeshCalcNode::opPOW:
188 case QgsMeshCalcNode::opEQ:
189 case QgsMeshCalcNode::opNE:
190 case QgsMeshCalcNode::opGT:
191 case QgsMeshCalcNode::opLT:
192 case QgsMeshCalcNode::opGE:
193 case QgsMeshCalcNode::opLE:
194 case QgsMeshCalcNode::opAND:
195 case QgsMeshCalcNode::opOR:
196 case QgsMeshCalcNode::opNOT:
197 case QgsMeshCalcNode::opIF:
198 case QgsMeshCalcNode::opSIGN:
199 case QgsMeshCalcNode::opMIN:
200 case QgsMeshCalcNode::opMAX:
201 case QgsMeshCalcNode::opABS:
204 res += mLeft->notAggregatedUsedDatasetGroupNames();
209 res += mRight->notAggregatedUsedDatasetGroupNames();
214 res += mCondition->notAggregatedUsedDatasetGroupNames();
217 case QgsMeshCalcNode::opSUM_AGGR:
218 case QgsMeshCalcNode::opMAX_AGGR:
219 case QgsMeshCalcNode::opMIN_AGGR:
220 case QgsMeshCalcNode::opAVG_AGGR:
221 case QgsMeshCalcNode::opNONE:
230 if ( mType == tDatasetGroupRef )
232 dsu.copy( result, mDatasetGroupName, isAggregate );
235 else if ( mType == tOperator )
240 bool currentOperatorIsAggregate = mOperator == opSUM_AGGR ||
241 mOperator == opMAX_AGGR ||
242 mOperator == opMIN_AGGR ||
243 mOperator == opAVG_AGGR;
245 if ( !mLeft || !mLeft->calculate( dsu, leftDatasetGroup, isAggregate || currentOperatorIsAggregate ) )
249 if ( mRight && !mRight->calculate( dsu, rightDatasetGroup, isAggregate || currentOperatorIsAggregate ) )
259 if ( !mCondition->calculate( dsu, condition ) )
264 dsu.addIf( leftDatasetGroup, rightDatasetGroup, condition );
268 dsu.add( leftDatasetGroup, rightDatasetGroup );
271 dsu.subtract( leftDatasetGroup, rightDatasetGroup );
274 dsu.multiply( leftDatasetGroup, rightDatasetGroup );
277 dsu.divide( leftDatasetGroup, rightDatasetGroup );
280 dsu.power( leftDatasetGroup, rightDatasetGroup );
283 dsu.equal( leftDatasetGroup, rightDatasetGroup );
286 dsu.notEqual( leftDatasetGroup, rightDatasetGroup );
289 dsu.greaterThan( leftDatasetGroup, rightDatasetGroup );
292 dsu.lesserThan( leftDatasetGroup, rightDatasetGroup );
295 dsu.greaterEqual( leftDatasetGroup, rightDatasetGroup );
298 dsu.lesserEqual( leftDatasetGroup, rightDatasetGroup );
301 dsu.logicalAnd( leftDatasetGroup, rightDatasetGroup );
304 dsu.logicalOr( leftDatasetGroup, rightDatasetGroup );
307 dsu.logicalNot( leftDatasetGroup );
310 dsu.minimum( leftDatasetGroup, rightDatasetGroup );
313 dsu.maximum( leftDatasetGroup, rightDatasetGroup );
316 dsu.abs( leftDatasetGroup );
319 dsu.sumAggregated( leftDatasetGroup );
322 dsu.minimumAggregated( leftDatasetGroup );
325 dsu.maximumAggregated( leftDatasetGroup );
328 dsu.averageAggregated( leftDatasetGroup );
331 dsu.changeSign( leftDatasetGroup );
336 dsu.transferDatasets( result, leftDatasetGroup );
339 else if ( mType == tNumber )
341 dsu.number( result, mNumber );
344 else if ( mType == tNoData )
346 dsu.nodata( result );
354QgsMeshCalcNode *QgsMeshCalcNode::parseMeshCalcString(
const QString &str, QString &parserErrorMsg )
356 extern QgsMeshCalcNode *localParseMeshCalcString(
const QString & str, QString & parserErrorMsg );
357 return localParseMeshCalcString( str, parserErrorMsg );
360bool QgsMeshCalcNode::isNonTemporal()
const
362 if ( mType == tNoData || mType == tNumber )
365 if ( mType == tDatasetGroupRef )
370 case QgsMeshCalcNode::opIF:
371 return ( mLeft && mLeft->isNonTemporal() ) &&
372 ( mRight && mRight->isNonTemporal() &&
373 mCondition->isNonTemporal() );
375 case QgsMeshCalcNode::opPLUS:
376 case QgsMeshCalcNode::opMINUS:
377 case QgsMeshCalcNode::opMUL:
378 case QgsMeshCalcNode::opDIV:
379 case QgsMeshCalcNode::opPOW:
380 case QgsMeshCalcNode::opEQ:
381 case QgsMeshCalcNode::opNE:
382 case QgsMeshCalcNode::opGT:
383 case QgsMeshCalcNode::opLT:
384 case QgsMeshCalcNode::opGE:
385 case QgsMeshCalcNode::opLE:
386 case QgsMeshCalcNode::opAND:
387 case QgsMeshCalcNode::opOR:
388 case QgsMeshCalcNode::opNOT:
389 case QgsMeshCalcNode::opSIGN:
390 case QgsMeshCalcNode::opMIN:
391 case QgsMeshCalcNode::opMAX:
392 case QgsMeshCalcNode::opABS:
393 return ( mLeft && mLeft->isNonTemporal() ) &&
394 ( mRight && mRight->isNonTemporal() );
396 case QgsMeshCalcNode::opSUM_AGGR:
397 case QgsMeshCalcNode::opMAX_AGGR:
398 case QgsMeshCalcNode::opMIN_AGGR:
399 case QgsMeshCalcNode::opAVG_AGGR:
400 case QgsMeshCalcNode::opNONE:
Class that represents a dataset group stored in memory.