void KstEquation::replaceDependency(KstVectorPtr oldVector, KstVectorPtr newVector) { QString oldTag = oldVector->tagName(); QString newTag = newVector->tagName(); // replace all occurences of oldTag with newTag QString newExp = _equation.replace("["+oldTag+"]", "["+newTag+"]"); // also replace all occurences of scalar stats for the oldVector QDictIterator<KstScalar> scalarDictIter(oldVector->scalars()); for (; scalarDictIter.current(); ++scalarDictIter) { QString oldTag = scalarDictIter.current()->tagName(); QString newTag = ((newVector->scalars())[scalarDictIter.currentKey()])->tagName(); newExp = newExp.replace("[" + oldTag + "]", "[" + newTag + "]"); } setEquation(newExp); // do the dependency replacements for _inputVectors, but don't call parent function as it // replaces _inputScalars for (KstVectorMap::Iterator j = _inputVectors.begin(); j != _inputVectors.end(); ++j) { if (j.data() == oldVector) { _inputVectors[j.key()] = newVector; } } }
Surface::Surface(const QString &equation, qreal a, QObject *parent) : QObject(parent), privateMemberLock(QReadWriteLock::Recursive) { construct(); setEquation(equation); setA(a); }
CalculatorWidget::CalculatorWidget(WContainerWidget* parent) : WContainerWidget(parent), mOperation("+"), mLHS(0), mRHS(0), mResult(0) { mDisplay = new CalculatorDisplay(this); addWidget(mDisplay); initNumberButtons(); mDecimal = new WPushButton(".", this); mDecimal->clicked().connect(std::bind([&] () { mDisplay->push('.'); })); addWidget(mDecimal); initOperationButtons(); mEquals = new WPushButton("=", this); mEquals->clicked().connect(std::bind([&] () { double val = mDisplay->getValue(); mDisplay->clear(); setEquation(val); mDisplay->setText(std::to_string(performOperation())); })); addWidget(mEquals); mClear = new WPushButton("Clear", this); mClear->clicked().connect(std::bind([&] () { mLHS = mRHS = 0.0; mResult = 0; mDisplay->clear(); })); addWidget(mClear); }
void KstEquation::replaceDependency(KstMatrixPtr oldMatrix, KstMatrixPtr newMatrix) { QString newExp = _equation; // also replace all occurences of scalar stats for the oldMatrix QDictIterator<KstScalar> scalarDictIter(oldMatrix->scalars()); for (; scalarDictIter.current(); ++scalarDictIter) { QString oldTag = scalarDictIter.current()->tagName(); QString newTag = ((newMatrix->scalars())[scalarDictIter.currentKey()])->tagName(); newExp = newExp.replace("[" + oldTag + "]", "[" + newTag + "]"); } setEquation(newExp); }
void KstEquation::replaceDependency(KstDataObjectPtr oldObject, KstDataObjectPtr newObject) { QString newExp = _equation; // replace all occurences of outputVectors, outputScalars from oldObject for (KstVectorMap::Iterator j = oldObject->outputVectors().begin(); j != oldObject->outputVectors().end(); ++j) { QString oldTag = j.data()->tagName(); QString newTag = ((newObject->outputVectors())[j.key()])->tagName(); newExp = newExp.replace("[" + oldTag + "]", "[" + newTag + "]"); } for (KstScalarMap::Iterator j = oldObject->outputScalars().begin(); j != oldObject->outputScalars().end(); ++j) { QString oldTag = j.data()->tagName(); QString newTag = ((newObject->outputScalars())[j.key()])->tagName(); newExp = newExp.replace("[" + oldTag + "]", "[" + newTag + "]"); } // and dependencies on matrix stats (there won't be matrices themselves in the expression) for (KstMatrixMap::Iterator j = oldObject->outputMatrices().begin(); j != oldObject->outputMatrices().end(); ++j) { QDictIterator<KstScalar> scalarDictIter(j.data()->scalars()); for (; scalarDictIter.current(); ++scalarDictIter) { QString oldTag = scalarDictIter.current()->tagName(); QString newTag = ((((newObject->outputMatrices())[j.key()])->scalars())[scalarDictIter.currentKey()])->tagName(); newExp = newExp.replace("[" + oldTag + "]", "[" + newTag + "]"); } } // only replace _inputVectors for (KstVectorMap::Iterator j = oldObject->outputVectors().begin(); j != oldObject->outputVectors().end(); ++j) { for (KstVectorMap::Iterator k = _inputVectors.begin(); k != _inputVectors.end(); ++k) { if (j.data().data() == k.data().data()) { // replace input with the output from newObject _inputVectors[k.key()] = (newObject->outputVectors())[j.key()]; } } // and dependencies on vector stats QDictIterator<KstScalar> scalarDictIter(j.data()->scalars()); for (; scalarDictIter.current(); ++scalarDictIter) { QString oldTag = scalarDictIter.current()->tagName(); QString newTag = ((((newObject->outputVectors())[j.key()])->scalars())[scalarDictIter.currentKey()])->tagName(); newExp = newExp.replace("[" + oldTag + "]", "[" + newTag + "]"); } } setEquation(newExp); }
void KstEquation::commonConstructor(const QString& in_tag, const QString& in_equation) { _ns = 2; _pe = 0L; _typeString = i18n("Equation"); _type = "Equation"; KstObject::setTagName(in_tag); KstVectorPtr yv = new KstVector(tagName()+"-sv" , 2); KST::addVectorToList(yv); _yVector = _outputVectors.insert(OUTVECTOR, yv); yv->setProvider(this); _isValid = false; _numNew = _numShifted = 0; setEquation(in_equation); }
void KstEquation::commonConstructor(const QString& in_tag, const QString& in_equation) { _ns = 2; _pe = 0L; _typeString = i18n("Equation"); _type = "Equation"; KstObject::setTagName(KstObjectTag::fromString(in_tag)); KstVectorPtr xv = new KstVector(KstObjectTag("xsv", tag()), 2, this); _xOutVector = _outputVectors.insert(XOUTVECTOR, xv); KstVectorPtr yv = new KstVector(KstObjectTag("sv", tag()), 2, this); _yOutVector = _outputVectors.insert(YOUTVECTOR, yv); _isValid = false; _numNew = _numShifted = 0; setEquation(in_equation); }
void CalculatorWidget::initOperationButtons() { mOperations[0] = new OperationButton("+", this); mOperations[1] = new OperationButton("-", this); mOperations[2] = new OperationButton("*", this); mOperations[3] = new OperationButton("/", this); for(int i = 0; i < opCount; ++i){ addWidget(mOperations[i]); mOperations[i]->clicked().connect(std::bind([=] (std::string op) { /* save operation in mOperation member variable */ mOperation = op; /* retrieve value from mDisplay before we clear it for next number */ double val = mDisplay->getValue(); setEquation(val); mDisplay->clear(); }, mOperations[i]->getOperation())); } }
// Assignment operator void Transformer::operator=(const Transformer& source) { // Set equation from old expression setEquation(source.text_); enabled_ = source.enabled_; }
void CEquSystem::setEquation(CEquation *pEquFrom, const CEquation *pEquTo) { const auto pVar = pEquTo->firstVariable(); setEquation(pEquFrom, *(equIndx() + pVar->equIdx())); }
CVariableMapping *CEquSystem::solveExtraEquations() { static int hhh; ++hhh; CVariableMapping *pVarValue = NULL; // Loop over all constructed equations auto iMax = equNumb(); size_t i = 0; while (i < iMax) { CEquation *pEquation = equation(i); if (pEquation->numbVar() != 1) { i++; continue; } // We found trivial equation const auto pVariable = pEquation->firstVariable(); const auto varValue = pEquation->rightPart(); if (!pVarValue) pVarValue = new CVariableMapping(iMax - i); pVarValue->addMapping(pVariable->varIndex(), varValue); // Get next equation with the current variable // (we need to do it BEFORE releasing this variable) auto pVariableNext = pVariable->sameVarNextEqu(); // Release current equation and copy last equation of the system to the current slot pEquation->releaseEquation(); if (i < --iMax) setEquation(equation(iMax), i); CVariable *pVariableTmp, *pVarTmp, *pTmp; while (pVariableNext != pVariable) { pVariableNext = (pVariableTmp = pVariableNext)->sameVarNextEqu(); CEquation *pCurrEquation = equation(pVariableTmp); if (pCurrEquation->rightPart() < varValue) { delete pVarValue; return NULL; // no solution } auto *pVarNext = pVariableTmp->nextVarSameEqu(); if (pCurrEquation->rightPart() == varValue) { // The values of all remaining variables of current equation are 0's while (pVarNext != pVariableTmp) { pVarNext = (pVarTmp = pVarNext)->nextVarSameEqu(); // Map variable with it's value 0 pVarValue->addMapping(pVarTmp->varIndex(), 0); // ... and remove this variable from remaining equations auto *pNxt = pVarTmp->sameVarNextEqu(); while (pNxt != pVarTmp) { pNxt = (pTmp = pNxt)->sameVarNextEqu(); pTmp->prevVarSameEqu()->linkVariable(pTmp->nextVarSameEqu()); delete pTmp; } delete pVarTmp; } // Current equation already solved and we need to delete it and move the last equation to its place setEquation(equation(--iMax), pCurrEquation); } else { if (pVarNext == pVariableTmp) { delete pVarValue; return NULL; // Only one variable in this equation } // Adjust right part pCurrEquation->adjustRightPart(varValue); // Remove variable pVariableTmp->prevVarSameEqu()->linkVariable(pVarNext); delete pVariableTmp; } } } setEquNumb(iMax); return pVarValue; }