예제 #1
0
static ValueChangedReturnCodeEnum setOldValueForDimView(const KnobIntBasePtr& isInt,
                                                        const KnobBoolBasePtr& isBool,
                                                        const KnobDoubleBasePtr& isDouble,
                                                        const KnobStringBasePtr& isString,
                                                        ValueChangedReasonEnum reason,
                                                        bool setKeyFrame,
                                                        double time,
                                                        bool hasChanged,
                                                        ValueChangedReturnCodeEnum retCode,
                                                        DimIdx dim,
                                                        ViewIdx view_i,
                                                        const PerDimViewVariantMap& oldValues)
{
    ValueChangedReturnCodeEnum ret = eValueChangedReturnCodeNothingChanged;
    DimensionViewPair key = {dim, view_i};
    PerDimViewVariantMap::const_iterator foundDimView = oldValues.find(key);
    if (foundDimView == oldValues.end()) {
        return ret;
    }

    const Variant& v = foundDimView->second;
    if (setKeyFrame && retCode != eValueChangedReturnCodeKeyframeAdded) {
        if (isInt) {
            ret = isInt->setValueAtTime(time, v.toInt(), view_i, dim, reason, 0, hasChanged);
        } else if (isBool) {
            ret = isBool->setValueAtTime(time, v.toBool(), view_i, dim, reason, 0, hasChanged);
        } else if (isDouble) {
            ret = isDouble->setValueAtTime(time, v.toDouble(), view_i, dim, reason, 0, hasChanged);
        } else if (isString) {
            ret = isString->setValueAtTime(time, v.toString().toStdString(), view_i, dim, reason, 0, hasChanged);
        }
    } else {
        if (isInt) {
            ret = isInt->setValue(v.toInt(), view_i, dim, reason, 0, hasChanged);
        } else if (isBool) {
            ret = isBool->setValue(v.toBool(), view_i, dim, reason, 0, hasChanged);
        } else if (isDouble) {
            ret = isDouble->setValue(v.toDouble(), view_i, dim, reason, 0, hasChanged);
        } else if (isString) {
            ret = isString->setValue(v.toString().toStdString(), view_i, dim, reason, 0, hasChanged);
        }
    }
    return ret;
}
예제 #2
0
void
MultipleKnobEditsUndoCommand::redo()
{
    // The first time, everything is handled within setValue/setValueAtTime already
    if (!firstRedoCalled) {
        firstRedoCalled = true;
        return;
    }

    assert( !knobs.empty() );
    KnobHolderPtr holder = knobs.begin()->first.lock()->getHolder();

    // Make sure we get a single evaluation
    if (holder) {
        holder->beginChanges();
    }

    for (ParamsMap::iterator it = knobs.begin(); it != knobs.end(); ++it) {

        KnobIPtr knob = it->first.lock();
        if (!knob) {
            continue;
        }

        if (it->second.empty()) {
            continue;
        }

        // All knobs must belong to the same node!
        assert(knob->getHolder() == holder);

        KnobIntBasePtr isInt = toKnobIntBase(knob);
        KnobBoolBasePtr isBool = toKnobBoolBase(knob);
        KnobDoubleBasePtr isDouble = toKnobDoubleBase(knob);
        KnobStringBasePtr isString = toKnobStringBase(knob);

        bool hasChanged = false;

        std::list<ValueToSet>::iterator next = it->second.begin();
        ++next;

        if (it->second.size() > 1) {
            // block knobChanged handler for this knob until the last change so we don't clutter the main-thread with useless action calls
            knob->blockValueChanges();
        }
        for (std::list<ValueToSet>::iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) {
            if (next == it->second.end() && it->second.size() > 1) {
                // Re-enable knobChanged for the last change on this knob
                knob->unblockValueChanges();
            }
            if (it2->setKeyFrame) {
                if (isInt) {
                    it2->setValueRetCode = isInt->setValueAtTime(it2->time, it2->newValue.toInt(), it2->view, it2->dimension, it2->reason, 0, hasChanged);
                } else if (isBool) {
                    it2->setValueRetCode = isBool->setValueAtTime(it2->time, it2->newValue.toBool(), it2->view, it2->dimension, it2->reason, 0, hasChanged);
                } else if (isDouble) {
                    it2->setValueRetCode = isDouble->setValueAtTime(it2->time, it2->newValue.toDouble(), it2->view, it2->dimension, it2->reason, 0, hasChanged);
                } else if (isString) {
                    it2->setValueRetCode = isString->setValueAtTime(it2->time, it2->newValue.toString().toStdString(), it2->view, it2->dimension, it2->reason, 0, hasChanged);
                } else {
                    assert(false);
                }
            } else {
                if (isInt) {
                    it2->setValueRetCode = isInt->setValue(it2->newValue.toInt(), it2->view, it2->dimension, it2->reason, 0, hasChanged);
                } else if (isBool) {
                    it2->setValueRetCode = isBool->setValue(it2->newValue.toBool(), it2->view, it2->dimension, it2->reason, 0, hasChanged);
                } else if (isDouble) {
                    it2->setValueRetCode = isDouble->setValue(it2->newValue.toDouble(), it2->view, it2->dimension, it2->reason, 0, hasChanged);
                } else if (isString) {
                    it2->setValueRetCode = isString->setValue(it2->newValue.toString().toStdString(), it2->view, it2->dimension, it2->reason, 0, hasChanged);
                } else {
                    assert(false);
                }
            }
            hasChanged |= it2->setValueRetCode != eValueChangedReturnCodeNothingChanged;

            if (next != it->second.end()) {
                ++next;
            }

        }
    }

    if (holder) {
        holder->endChanges();
    }

} // redo