void
RemoveItemsCommand::redo()
{
    KnobItemsTablePtr model = _items.begin()->item->getModel();

    KnobTableItemPtr nextItem;
    {
        KnobTableItemPtr item = _items.back().item;
        assert(item);
        int index = item->getIndexInParent();
        std::vector<KnobTableItemPtr> topLevel = model->getTopLevelItems();
        if (!topLevel.empty()) {
            if (index + 1 < (int)topLevel.size()) {
                nextItem = topLevel[index + 1];
            } else {
                if (topLevel[0] != item) {
                    nextItem = topLevel[0];
                }
            }
        }
    }

    model->beginEditSelection();
    model->clearSelection(eTableChangeReasonInternal);
    for (std::list<ItemToRemove>::const_iterator it = _items.begin(); it != _items.end(); ++it) {
        model->removeItem(it->item, eTableChangeReasonInternal);
    }
    if (nextItem) {
        model->addToSelection(nextItem, eTableChangeReasonInternal);
    }
    model->endEditSelection(eTableChangeReasonInternal);
    model->getNode()->getApp()->triggerAutoSave();
}
void
AddItemsCommand::redo()
{

    KnobItemsTablePtr model = _items.front().item->getModel();

    model->beginEditSelection();
    model->clearSelection(eTableChangeReasonInternal);


    for (std::list<ItemToAdd>::const_iterator it = _items.begin(); it != _items.end(); ++it) {
        bool skipInsert = false;
        if (_isFirstRedo) {
            // The item may already be at the correct position in the parent, check it
            if (!it->parentItem) {
                if (model->getTopLevelItem(it->indexInParent) == it->item) {
                    skipInsert = true;
                }
            } else {
                if (it->parentItem->getChild(it->indexInParent) == it->item) {
                    skipInsert = true;
                }
            }
        }
        if (!skipInsert) {
            model->insertItem(it->indexInParent, it->item, it->parentItem, eTableChangeReasonInternal);
        }
        model->addToSelection(it->item, eTableChangeReasonInternal);
    }

    model->endEditSelection(eTableChangeReasonInternal);
    model->getNode()->getApp()->triggerAutoSave();
    _isFirstRedo = false;
}
void
AddItemsCommand::undo()
{
    KnobItemsTablePtr model = _items.front().item->getModel();

    model->beginEditSelection();
    for (std::list<ItemToAdd>::const_iterator it = _items.begin(); it != _items.end(); ++it) {
        model->removeItem(it->item, eTableChangeReasonInternal);
    }
    model->endEditSelection(eTableChangeReasonInternal);
    model->getNode()->getApp()->triggerAutoSave();
}
void
RemoveItemsCommand::undo()
{
    KnobItemsTablePtr model = _items.begin()->item->getModel();
    model->beginEditSelection();
    model->clearSelection(eTableChangeReasonInternal);
    for (std::list<ItemToRemove>::const_iterator it = _items.begin(); it != _items.end(); ++it) {
        int prevIndex = -1;
        KnobTableItemPtr prevItem = it->prevItem.lock();
        if (prevItem) {
            prevIndex = prevItem->getIndexInParent();
        }
        if (prevIndex != -1) {
            model->insertItem(prevIndex, it->item, it->item->getParent(), eTableChangeReasonInternal);
        } else {
            model->addItem(it->item, it->item->getParent(), eTableChangeReasonInternal);
        }
        model->addToSelection(it->item, eTableChangeReasonInternal);
    }
    model->endEditSelection(eTableChangeReasonInternal);
    model->getNode()->getApp()->triggerAutoSave();
}
Beispiel #5
0
void
TrackMarker::resetCenter()
{
    KnobItemsTablePtr model = getModel();
    if (!model) {
        return;
    }
    RectD rod;
    NodePtr input = model->getNode()->getInput(0);
    if (!input) {
        Format f;
        getApp()->getProject()->getProjectDefaultFormat(&f);
        rod = f.toCanonicalFormat();
    } else {
        TimeValue time(input->getApp()->getTimeLine()->currentFrame());
        RenderScale scale(1.);
        RectD rod;
        {
            GetRegionOfDefinitionResultsPtr results;
            ActionRetCodeEnum stat = input->getEffectInstance()->getRegionOfDefinition_public(time, scale, ViewIdx(0), &results);
            if (!isFailureRetCode(stat)) {
                rod = results->getRoD();
            }
        }
        Point center;
        center.x = 0;
        center.y = 0;
        center.x = (rod.x1 + rod.x2) / 2.;
        center.y = (rod.y1 + rod.y2) / 2.;


        KnobDoublePtr centerKnob = getCenterKnob();
        centerKnob->setValue(center.x, ViewSetSpec::all(), DimIdx(0));
        centerKnob->setValue(center.y, ViewSetSpec::all(), DimIdx(1));
    }
}
Beispiel #6
0
void
TrackMarkerPM::initializeKnobs()
{
    TrackMarker::initializeKnobs();
    NodePtr thisNode = getModel()->getNode();
    NodePtr node;
    {
        CreateNodeArgsPtr args(CreateNodeArgs::create( PLUGINID_OFX_TRACKERPM, NodeCollectionPtr() ));
        args->setProperty<bool>(kCreateNodeArgsPropVolatile, true);
        args->setProperty<bool>(kCreateNodeArgsPropNoNodeGUI, true);
        args->setProperty<std::string>(kCreateNodeArgsPropNodeInitialName, "TrackerPMNode");

        node = getApp()->createNode(args);
        if (!node) {
            throw std::runtime_error("Couldn't create plug-in " PLUGINID_OFX_TRACKERPM);
        }
        if (thisNode) {
            NodePtr inputNode = thisNode->getInput(0);
            if (inputNode) {
                node->connectInput(inputNode, 0);
            }
        }
        trackerNode = node;
    }

    KnobItemsTablePtr model = getModel();
    EffectInstancePtr effect;
    if (model) {
        effect = model->getNode()->getEffectInstance();
    }

    trackPrevButton = getNodeKnob<KnobButton>(node, kTrackerPMParamTrackingPrevious);
    trackNextButton = getNodeKnob<KnobButton>(node, kTrackerPMParamTrackingNext);
    KnobDoublePtr center = getNodeKnob<KnobDouble>(node, kTrackerPMParamTrackingCenterPoint);
    centerKnob = center;

    // Slave the center knob and unslave when tracking
    if ( !center->linkTo(getCenterKnob()) ) {
        throw std::runtime_error("Could not link center");
    }

    KnobDoublePtr offset = getNodeKnob<KnobDouble>(node, kTrackerPMParamTrackingOffset);

    // Slave the offset knob
    if ( !offset->linkTo( getOffsetKnob() ) ) {
        throw std::runtime_error("Could not link offset");
    }

    offsetKnob = offset;

    // Ref frame is set for each
    refFrameKnob = getNodeKnob<KnobInt>(node, kTrackerPMParamTrackingReferenceFrame);

    // Enable reference frame
    KnobBoolPtr enableRefFrameKnob = getNodeKnob<KnobBool>(node, kTrackerPMParamTrackingEnableReferenceFrame);
    enableRefFrameKnob->setValue(true);

    KnobChoicePtr scoreType = getNodeKnob<KnobChoice>(node, kTrackerPMParamScore);
    if (effect) {
#ifdef kTrackerParamPatternMatchingScoreType
        KnobIPtr modelKnob = effect->getKnobByName(kTrackerParamPatternMatchingScoreType);
        if (modelKnob) {
            if ( !scoreType->linkTo(modelKnob) ) {
                throw std::runtime_error("Could not link scoreType");
            }
        }
#endif
    }

    scoreTypeKnob = scoreType;

    KnobDoublePtr correlationScore = getNodeKnob<KnobDouble>(node, kTrackerPMParamTrackingCorrelationScore);
    correlationScoreKnob = correlationScore;

    KnobDoublePtr patternBtmLeft = getNodeKnob<KnobDouble>(node, kTrackerPMParamTrackingPatternBoxBtmLeft);
    patternBtmLeftKnob = patternBtmLeft;

    // Slave the search window and pattern of the node to the parameters of the marker
    (void)patternBtmLeft->linkTo(getPatternBtmLeftKnob());

    KnobDoublePtr patternTopRight = getNodeKnob<KnobDouble>(node, kTrackerPMParamTrackingPatternBoxTopRight);
    patternTopRightKnob = patternTopRight;
    (void)patternTopRight->linkTo(getPatternTopRightKnob());

    KnobDoublePtr searchWindowBtmLeft = getNodeKnob<KnobDouble>(node, kTrackerPMParamTrackingSearchBoxBtmLeft);
    searchWindowBtmLeftKnob = searchWindowBtmLeft;
    (void)searchWindowBtmLeft->linkTo(getSearchWindowBottomLeftKnob());

    KnobDoublePtr searchWindowTopRight = getNodeKnob<KnobDouble>(node, kTrackerPMParamTrackingSearchBoxTopRight);
    searchWindowTopRightKnob = searchWindowTopRight;
    (void)searchWindowTopRight->linkTo(getSearchWindowTopRightKnob());

} // TrackMarkerPM::initializeKnobs
Beispiel #7
0
void
TrackMarker::initializeKnobs()
{
    KnobItemsTablePtr model = getModel();
    EffectInstancePtr effect;
    if (model) {
        effect = model->getNode()->getEffectInstance();
    }
    KnobIntPtr defPatternSizeKnob, defSearchSizeKnob;
    KnobChoicePtr defMotionModelKnob;
    defPatternSizeKnob = toKnobInt(effect->getKnobByName(kTrackerUIParamDefaultMarkerPatternWinSize));
    defSearchSizeKnob = toKnobInt(effect->getKnobByName(kTrackerUIParamDefaultMarkerSearchWinSize));
    defMotionModelKnob = toKnobChoice(effect->getKnobByName(kTrackerUIParamDefaultMotionModel));

    double patternHalfSize = defPatternSizeKnob ? defPatternSizeKnob->getValue() / 2. : 21;
    double searchHalfSize = defSearchSizeKnob ? defSearchSizeKnob->getValue() / 2. : 71;

    int defMotionModel_i = defMotionModelKnob ? defMotionModelKnob->getValue() : 0;

    KnobDoublePtr swbbtmLeft = createKnob<KnobDouble>(kTrackerParamSearchWndBtmLeft, 2);

    swbbtmLeft->setLabel(tr(kTrackerParamSearchWndBtmLeftLabel));
    swbbtmLeft->setDefaultValue(-searchHalfSize, DimIdx(0));
    swbbtmLeft->setDefaultValue(-searchHalfSize, DimIdx(1));
    swbbtmLeft->setHintToolTip( tr(kTrackerParamSearchWndBtmLeftHint) );
    _imp->searchWindowBtmLeft = swbbtmLeft;

    KnobDoublePtr swbtRight = createKnob<KnobDouble>(kTrackerParamSearchWndTopRight, 2);
    swbtRight->setLabel(tr(kTrackerParamSearchWndTopRightLabel));
    swbtRight->setDefaultValue(searchHalfSize, DimIdx(0));
    swbtRight->setDefaultValue(searchHalfSize, DimIdx(1));
    swbtRight->setHintToolTip( tr(kTrackerParamSearchWndTopRightHint) );
    _imp->searchWindowTopRight = swbtRight;


    KnobDoublePtr ptLeft = createKnob<KnobDouble>(kTrackerParamPatternTopLeft, 2);
    ptLeft->setLabel(tr(kTrackerParamPatternTopLeftLabel));
    ptLeft->setDefaultValue(-patternHalfSize, DimIdx(0));
    ptLeft->setDefaultValue(patternHalfSize, DimIdx(1));
    ptLeft->setHintToolTip( tr(kTrackerParamPatternTopLeftHint) );
    _imp->patternTopLeft = ptLeft;

    KnobDoublePtr ptRight = createKnob<KnobDouble>(kTrackerParamPatternTopRight, 2);
    ptRight->setLabel(tr(kTrackerParamPatternTopRightLabel));
    ptRight->setDefaultValue(patternHalfSize, DimIdx(0));
    ptRight->setDefaultValue(patternHalfSize, DimIdx(1));
    ptRight->setHintToolTip( tr(kTrackerParamPatternTopRightHint) );
    _imp->patternTopRight = ptRight;

    KnobDoublePtr pBRight = createKnob<KnobDouble>(kTrackerParamPatternBtmRight, 2);
    pBRight->setLabel(tr(kTrackerParamPatternBtmRightLabel));
    pBRight->setDefaultValue(patternHalfSize, DimIdx(0));
    pBRight->setDefaultValue(-patternHalfSize, DimIdx(1));
    pBRight->setHintToolTip( tr(kTrackerParamPatternBtmRightHint) );
    _imp->patternBtmRight = pBRight;

    KnobDoublePtr pBLeft = createKnob<KnobDouble>(kTrackerParamPatternBtmLeft, 2);
    pBLeft->setLabel(tr(kTrackerParamPatternBtmLeftLabel));
    pBLeft->setDefaultValue(-patternHalfSize, DimIdx(0));
    pBLeft->setDefaultValue(-patternHalfSize, DimIdx(1));
    pBLeft->setHintToolTip( tr(kTrackerParamPatternBtmLeftHint) );
    _imp->patternBtmLeft = pBLeft;

    KnobDoublePtr centerKnob = createKnob<KnobDouble>(kTrackerParamCenter, 2);
    centerKnob->setLabel(tr(kTrackerParamCenterLabel));
    centerKnob->setHintToolTip( tr(kTrackerParamCenterHint) );
    _imp->center = centerKnob;

    KnobDoublePtr offsetKnob = createKnob<KnobDouble>(kTrackerParamOffset, 2);
    offsetKnob->setLabel(tr(kTrackerParamOffsetLabel));
    offsetKnob->setHintToolTip( tr(kTrackerParamOffsetHint) );
    _imp->offset = offsetKnob;

#ifdef NATRON_TRACK_MARKER_USE_WEIGHT
    KnobDoublePtr weightKnob = createKnob<KnobDouble>(kTrackerParamTrackWeight, 1);
    weightKnob->setLabel(tr(kTrackerParamTrackWeightLabel));
    weightKnob->setHintToolTip( tr(kTrackerParamTrackWeightHint) );
    weightKnob->setDefaultValue(1.);
    weightKnob->setAnimationEnabled(false);
    weightKnob->setRange(0., 1.);
    _imp->weight = weightKnob;
#endif

    KnobChoicePtr mmodelKnob = createKnob<KnobChoice>(kTrackerParamMotionModel, 1);
    mmodelKnob->setHintToolTip( tr(kTrackerParamMotionModelHint) );
    mmodelKnob->setLabel(tr(kTrackerParamMotionModelLabel));
    {
        std::vector<ChoiceOption> choices, helps;
        std::map<int, std::string> icons;
        TrackerNodePrivate::getMotionModelsAndHelps(true, &choices, &icons);
        mmodelKnob->populateChoices(choices);
        mmodelKnob->setIcons(icons);
    }

    mmodelKnob->setDefaultValue(defMotionModel_i);
    _imp->motionModel = mmodelKnob;

    KnobDoublePtr errKnob = createKnob<KnobDouble>(kTrackerParamError, 1);
    errKnob->setLabel(tr(kTrackerParamErrorLabel));
    _imp->error = errKnob;

    KnobBoolPtr enableKnob = createKnob<KnobBool>(kTrackerParamEnabled, 1);
    enableKnob->setLabel(tr(kTrackerParamEnabledLabel));
    enableKnob->setHintToolTip( tr(kTrackerParamEnabledHint) );
    enableKnob->setAnimationEnabled(true);
    enableKnob->setDefaultValue(true);
    _imp->enabled = enableKnob;

    addColumn(kKnobTableItemColumnLabel, DimIdx(0));
    addColumn(kTrackerParamEnabled, DimIdx(0));
    addColumn(kTrackerParamMotionModel, DimIdx(0));
    addColumn(kTrackerParamCenter, DimIdx(0));
    addColumn(kTrackerParamCenter, DimIdx(1));
    addColumn(kTrackerParamOffset, DimIdx(0));
    addColumn(kTrackerParamOffset, DimIdx(1));
    addColumn(kTrackerParamError, DimIdx(0));

} // TrackMarker::initializeKnobs