void EventMonitorEntry::replaceDependency(KstDataObjectPtr oldObject, KstDataObjectPtr newObject) { QString newExp = _event; // replace all occurences of outputVectors, outputScalars from oldObject for (KstVectorMap::ConstIterator j = oldObject->outputVectors().begin(); j != oldObject->outputVectors().end(); ++j) { const QString oldTag = j.value()->tagName(); const QString newTag = newObject->outputVectors()[j.key()]->tagName(); newExp = newExp.replace("[" + oldTag + "]", "[" + newTag + "]"); } for (KstScalarMap::ConstIterator j = oldObject->outputScalars().begin(); j != oldObject->outputScalars().end(); ++j) { const QString oldTag = j.value()->tagName(); const QString newTag = newObject->outputScalars()[j.key()]->tagName(); newExp = newExp.replace("[" + oldTag + "]", "[" + newTag + "]"); } // and dependencies on vector stats for (KstVectorMap::ConstIterator j = oldObject->outputVectors().begin(); j != oldObject->outputVectors().end(); ++j) { const QHash<QString, KstScalar*>& scalarMap(newObject->outputVectors()[j.key()]->scalars()); QHashIterator<QString, KstScalar*> scalarDictIter(j.value()->scalars()); while (scalarDictIter.hasNext()) { const QString oldTag = scalarDictIter.next().value()->tagName(); const QString newTag = scalarMap[scalarDictIter.key()]->tagName(); newExp = newExp.replace("[" + oldTag + "]", "[" + newTag + "]"); } } // and dependencies on matrix stats for (KstMatrixMap::ConstIterator j = oldObject->outputMatrices().begin(); j != oldObject->outputMatrices().end(); ++j) { const QHash<QString, KstScalar*>& scalarMap(newObject->outputMatrices()[j.key()]->scalars()); QHashIterator<QString, KstScalar*> scalarDictIter(j.value()->scalars()); while (scalarDictIter.hasNext()) { const QString oldTag = scalarDictIter.next().value()->tagName(); const QString newTag = scalarMap[scalarDictIter.key()]->tagName(); newExp = newExp.replace("[" + oldTag + "]", "[" + newTag + "]"); } } setEvent(newExp); setDirty(); // events have no _inputVectors }
bool EventMonitorEntry::uses(KstObjectPtr p) const { // check VectorsUsed in addition to _input*'s if (KstVectorPtr vect = kst_cast<KstVector>(p)) { for (KstVectorMap::ConstIterator j = _vectorsUsed.begin(); j != _vectorsUsed.end(); ++j) { if (j.value() == vect) { return true; } } } else if (KstDataObjectPtr obj = kst_cast<KstDataObject>(p) ) { // check all connections from this expression to p for (KstVectorMap::ConstIterator j = obj->outputVectors().begin(); j != obj->outputVectors().end(); ++j) { for (KstVectorMap::ConstIterator k = _vectorsUsed.begin(); k != _vectorsUsed.end(); ++k) { if (j.value() == k.value()) { return true; } } } } return KstDataObject::uses(p); }
KstObject::UpdateType EventMonitorEntry::update(int updateCounter) { Q_ASSERT(myLockStatus() == KstRWLock::WRITELOCKED); bool force = dirty(); setDirty(false); if (KstObject::checkUpdateCounter(updateCounter) && !force) { return lastUpdateResult(); } writeLockInputsAndOutputs(); if (!_pExpression) { reparse(); } KstVectorPtr xv = *_xVector; KstVectorPtr yv = *_yVector; int ns = 1; for (KstVectorMap::ConstIterator i = _vectorsUsed.begin(); i != _vectorsUsed.end(); ++i) { ns = qMax(ns, i.value()->length()); } double *rawValuesX = 0L; double *rawValuesY = 0L; if (xv && yv) { if (xv->resize(ns)) { rawValuesX = xv->value(); } if (yv->resize(ns)) { rawValuesY = yv->value(); } } Equation::Context ctx; ctx.sampleCount = ns; ctx.x = 0.0; if (needToEvaluate()) { if (_pExpression) { for (ctx.i = _numDone; ctx.i < ns; ++ctx.i) { const double value = _pExpression->value(&ctx); if (value != 0.0) { // The expression evaluates to true log(ctx.i); if (rawValuesX && rawValuesY) { rawValuesX[ctx.i] = ctx.i; rawValuesY[ctx.i] = 1.0; } } else { if (rawValuesX && rawValuesY) { rawValuesX[ctx.i] = ctx.i; rawValuesY[ctx.i] = 0.0; } } } _numDone = ns; logImmediately(); } } else { _numDone = ns; } if (xv) { xv->setDirty(); xv->update(updateCounter); } if (yv) { yv->setDirty(); yv->update(updateCounter); } unlockInputsAndOutputs(); return setLastUpdateResult(NO_CHANGE); }