void KnobGuiChoice::updateGUI(int /*dimension*/) { ///we don't use setCurrentIndex because the signal emitted by combobox will call onCurrentIndexChanged and ///change the internal value of the knob again... ///The slot connected to onCurrentIndexChanged is reserved to catch user interaction with the combobox. ///This function is called in response to an internal change. KnobChoicePtr knob = _knob.lock(); std::string activeEntry = knob->getActiveEntryText_mt_safe(); if ( !activeEntry.empty() ) { bool activeIndexPresent = knob->isActiveEntryPresentInEntries(); if (!activeIndexPresent) { QString error = tr("The value set to this parameter no longer exist in the menu. Right click and press Refresh Menu to update the menu and then pick a new value."); setWarningValue( KnobGui::eKnobWarningChoiceMenuOutOfDate, GuiUtils::convertFromPlainText(error, Qt::WhiteSpaceNormal) ); } else { setWarningValue( KnobGui::eKnobWarningChoiceMenuOutOfDate, QString() ); } } if ( _comboBox->isCascading() || activeEntry.empty() ) { _comboBox->setCurrentIndex_no_emit( knob->getValue() ); } else { _comboBox->setCurrentText( QString::fromUtf8( activeEntry.c_str() ) ); } }
void KnobGuiChoice::onCurrentIndexChanged(int i) { KnobGuiPtr knobUI = getKnobGui(); knobUI->setWarningValue( KnobGui::eKnobWarningChoiceMenuOutOfDate, QString() ); KnobChoicePtr knob = _knob.lock(); if (!knob) { return; } knobUI->pushUndoCommand( new KnobUndoCommand<int>(knob, knob->getValue(DimIdx(0), getView()), i, DimIdx(0), getView())); }
void ViewerNodePrivate::toggleDownscaleLevel(int index) { assert(index > 0); KnobChoicePtr downscaleChoice = downscaleChoiceKnob.lock(); int curChoice_i = downscaleChoice->getValue(); if (curChoice_i != index) { downscaleChoice->setValue(index); } else { // Reset back to auto downscaleChoice->setValue(0); } }
FramesNeededMap OneViewNode::getFramesNeeded(double time, ViewIdx /*view*/) { FramesNeededMap ret; FrameRangesMap& rangeMap = ret[0]; KnobChoicePtr viewKnob = _imp->viewKnob.lock(); int view_i = viewKnob->getValue(); std::vector<RangeD>& ranges = rangeMap[ViewIdx(view_i)]; ranges.resize(1); ranges[0].min = ranges[0].max = time; return ret; }
bool OneViewNode::isIdentity(double time, const RenderScale & /*scale*/, const RectI & /*roi*/, ViewIdx /*view*/, double* inputTime, ViewIdx* inputView, int* inputNb) { KnobChoicePtr viewKnob = _imp->viewKnob.lock(); int view_i = viewKnob->getValue(); *inputView = ViewIdx(view_i); *inputNb = 0; *inputTime = time; return true; }
void KnobGuiChoice::onEntryAppended(const QString& entry, const QString& help) { KnobChoicePtr knob = _knob.lock(); if ( knob->getHostCanAddOptions() && ( ( knob->getName() == kNatronOfxParamOutputChannels) || ( knob->getName() == kOutputChannelsKnobName) ) ) { _comboBox->insertItem(_comboBox->count() - 1, entry, QIcon(), QKeySequence(), help); } else { _comboBox->addItem(entry, QIcon(), QKeySequence(), help); } int activeIndex = knob->getValue(); if (activeIndex >= 0) { _comboBox->setCurrentIndex_no_emit(activeIndex); } else { _comboBox->setCurrentText( QString::fromUtf8( knob->getActiveEntryText_mt_safe().c_str() ) ); } }
void KnobGuiChoice::onEntriesPopulated() { KnobChoicePtr knob = _knob.lock(); _comboBox->clear(); std::vector<std::string> entries = knob->getEntries_mt_safe(); const std::vector<std::string> help = knob->getEntriesHelp_mt_safe(); std::string activeEntry = knob->getActiveEntryText_mt_safe(); for (U32 i = 0; i < entries.size(); ++i) { std::string helpStr; if ( !help.empty() && !help[i].empty() ) { helpStr = help[i]; } _comboBox->addItem( QString::fromUtf8( entries[i].c_str() ), QIcon(), QKeySequence(), QString::fromUtf8( helpStr.c_str() ) ); } // the "New" menu is only added to known parameters (e.g. the choice of output channels) if ( knob->getHostCanAddOptions() && ( ( knob->getName() == kNatronOfxParamOutputChannels) || ( knob->getName() == kOutputChannelsKnobName) ) ) { _comboBox->addItemNew(); } ///we don't use setCurrentIndex because the signal emitted by combobox will call onCurrentIndexChanged and ///we don't want that to happen because the index actually didn't change. if ( _comboBox->isCascading() || activeEntry.empty() ) { _comboBox->setCurrentIndex_no_emit( knob->getValue() ); } else { _comboBox->setCurrentText_no_emit( QString::fromUtf8( activeEntry.c_str() ) ); } if ( !activeEntry.empty() ) { bool activeIndexPresent = knob->isActiveEntryPresentInEntries(); if (!activeIndexPresent) { QString error = tr("The value set to this parameter no longer exist in the menu. Right click and press Refresh Menu to update the menu and then pick a new value."); setWarningValue( KnobGui::eKnobWarningChoiceMenuOutOfDate, GuiUtils::convertFromPlainText(error, Qt::WhiteSpaceNormal) ); } else { setWarningValue( KnobGui::eKnobWarningChoiceMenuOutOfDate, QString() ); } } }
void KnobGuiChoice::updateGUI() { ///we don't use setCurrentIndex because the signal emitted by combobox will call onCurrentIndexChanged and ///change the internal value of the knob again... ///The slot connected to onCurrentIndexChanged is reserved to catch user interaction with the combobox. ///This function is called in response to an internal change. KnobChoicePtr knob = _knob.lock(); if (!knob) { return; } ChoiceOption activeEntry = knob->getCurrentEntry(); QString activeEntryLabel; if (!activeEntry.label.empty()) { activeEntryLabel = QString::fromUtf8(activeEntry.label.c_str()); } else { activeEntryLabel = QString::fromUtf8(activeEntry.id.c_str()); } if ( !activeEntry.id.empty() ) { bool activeIndexPresent = knob->isActiveEntryPresentInEntries(getView()); if (!activeIndexPresent) { QString error = tr("The value %1 no longer exists in the menu").arg(activeEntryLabel); getKnobGui()->setWarningValue( KnobGui::eKnobWarningChoiceMenuOutOfDate, NATRON_NAMESPACE::convertFromPlainText(error, NATRON_NAMESPACE::WhiteSpaceNormal) ); } else { getKnobGui()->setWarningValue( KnobGui::eKnobWarningChoiceMenuOutOfDate, QString() ); } } if ( _comboBox->isCascading() || activeEntry.id.empty() ) { _comboBox->setCurrentIndex( knob->getValue(), false ); } else { ensureUnknownChocieIsNotInternalPlaneID(activeEntryLabel); _comboBox->setCurrentIndexFromLabel( activeEntryLabel, false /*emitSignal*/ ); } }
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
void TrackerNodePrivate::exportTrackDataFromExportOptions() { //bool transformLink = _imp->exportLink.lock()->getValue(); KnobChoicePtr transformTypeKnob = transformType.lock(); assert(transformTypeKnob); int transformType_i = transformTypeKnob->getValue(); TrackerTransformNodeEnum transformType = (TrackerTransformNodeEnum)transformType_i; KnobChoicePtr motionTypeKnob = motionType.lock(); if (!motionTypeKnob) { return; } int motionType_i = motionTypeKnob->getValue(); TrackerMotionTypeEnum mt = (TrackerMotionTypeEnum)motionType_i; if (mt == eTrackerMotionTypeNone) { Dialogs::errorDialog( tr("Tracker Export").toStdString(), tr("Please select the export mode with the Motion Type parameter").toStdString() ); return; } bool linked = exportLink.lock()->getValue(); QString pluginID; switch (transformType) { case eTrackerTransformNodeCornerPin: pluginID = QString::fromUtf8(PLUGINID_OFX_CORNERPIN); break; case eTrackerTransformNodeTransform: pluginID = QString::fromUtf8(PLUGINID_OFX_TRANSFORM); break; } NodePtr thisNode = publicInterface->getNode(); AppInstancePtr app = thisNode->getApp(); CreateNodeArgsPtr args(CreateNodeArgs::create( pluginID.toStdString(), thisNode->getGroup() )); args->setProperty<bool>(kCreateNodeArgsPropAutoConnect, false); args->setProperty<bool>(kCreateNodeArgsPropSettingsOpened, false); NodePtr createdNode = app->createNode(args); if (!createdNode) { return; } // Move the new node double thisNodePos[2]; double thisNodeSize[2]; thisNode->getPosition(&thisNodePos[0], &thisNodePos[1]); thisNode->getSize(&thisNodeSize[0], &thisNodeSize[1]); createdNode->setPosition(thisNodePos[0] + thisNodeSize[0] * 2., thisNodePos[1]); TimeValue timeForFromPoints(referenceFrame.lock()->getValue()); switch (transformType) { case eTrackerTransformNodeCornerPin: { KnobDoublePtr cornerPinToPoints[4]; KnobDoublePtr cornerPinFromPoints[4]; for (unsigned int i = 0; i < 4; ++i) { cornerPinFromPoints[i] = getCornerPinPoint(createdNode, true, i); assert(cornerPinFromPoints[i]); for (int j = 0; j < cornerPinFromPoints[i]->getNDimensions(); ++j) { cornerPinFromPoints[i]->setValue(fromPoints[i].lock()->getValueAtTime(timeForFromPoints, DimIdx(j)), ViewSetSpec::all(), DimIdx(j)); } cornerPinToPoints[i] = getCornerPinPoint(createdNode, false, i); assert(cornerPinToPoints[i]); if (!linked) { cornerPinToPoints[i]->copyKnob( toPoints[i].lock() ); } else { bool ok = cornerPinToPoints[i]->linkTo(toPoints[i].lock()); (void)ok; assert(ok); } } { KnobIPtr knob = createdNode->getKnobByName(kCornerPinParamMatrix); if (knob) { KnobDoublePtr isType = toKnobDouble(knob); if (isType) { isType->copyKnob(cornerPinMatrix.lock() ); } } } break; } case eTrackerTransformNodeTransform: { KnobIPtr translateKnob = createdNode->getKnobByName(kTransformParamTranslate); if (translateKnob) { KnobDoublePtr isDbl = toKnobDouble(translateKnob); if (isDbl) { if (!linked) { isDbl->copyKnob(translate.lock() ); } else { ignore_result(isDbl->linkTo(translate.lock())); } } } KnobIPtr scaleKnob = createdNode->getKnobByName(kTransformParamScale); if (scaleKnob) { KnobDoublePtr isDbl = toKnobDouble(scaleKnob); if (isDbl) { if (!linked) { isDbl->copyKnob(scale.lock() ); } else { ignore_result(isDbl->linkTo(scale.lock())); } } } KnobIPtr rotateKnob = createdNode->getKnobByName(kTransformParamRotate); if (rotateKnob) { KnobDoublePtr isDbl = toKnobDouble(rotateKnob); if (isDbl) { if (!linked) { isDbl->copyKnob(rotate.lock()); } else { ignore_result(isDbl->linkTo(rotate.lock())); } } } KnobIPtr centerKnob = createdNode->getKnobByName(kTransformParamCenter); if (centerKnob) { KnobDoublePtr isDbl = toKnobDouble(centerKnob); if (isDbl) { isDbl->copyKnob( center.lock() ); } } break; } } // switch KnobIPtr cpInvertKnob = createdNode->getKnobByName(kTransformParamInvert); if (cpInvertKnob) { KnobBoolPtr isBool = toKnobBool(cpInvertKnob); if (isBool) { if (!linked) { isBool->copyKnob(invertTransform.lock()); } else { ignore_result(isBool->linkTo(invertTransform.lock())); } } } { KnobIPtr knob = createdNode->getKnobByName(kTransformParamMotionBlur); if (knob) { KnobDoublePtr isType = toKnobDouble(knob); if (isType) { isType->copyKnob(motionBlur.lock()); } } } { KnobIPtr knob = createdNode->getKnobByName(kTransformParamShutter); if (knob) { KnobDoublePtr isType = toKnobDouble(knob); if (isType) { isType->copyKnob(shutter.lock()); } } } { KnobIPtr knob = createdNode->getKnobByName(kTransformParamShutterOffset); if (knob) { KnobChoicePtr isType = toKnobChoice(knob); if (isType) { isType->copyKnob(shutterOffset.lock()); } } } { KnobIPtr knob = createdNode->getKnobByName(kTransformParamCustomShutterOffset); if (knob) { KnobDoublePtr isType = toKnobDouble(knob); if (isType) { isType->copyKnob(customShutterOffset.lock()); } } } } // exportTrackDataFromExportOptions
void TrackerNodePrivate::solveTransformParams() { setTransformOutOfDate(false); std::vector<TrackMarkerPtr> markers; knobsTable->getAllMarkers(&markers); if ( markers.empty() ) { return; } resetTransformParamsAnimation(); KnobChoicePtr motionTypeKnob = motionType.lock(); int motionType_i = motionTypeKnob->getValue(); TrackerMotionTypeEnum type = (TrackerMotionTypeEnum)motionType_i; TimeValue refTime(referenceFrame.lock()->getValue()); int jitterPer = 0; bool jitterAdd = false; switch (type) { case eTrackerMotionTypeNone: return; case eTrackerMotionTypeMatchMove: case eTrackerMotionTypeStabilize: break; case eTrackerMotionTypeAddJitter: case eTrackerMotionTypeRemoveJitter: { jitterPer = jitterPeriod.lock()->getValue(); jitterAdd = type == eTrackerMotionTypeAddJitter; break; } } setSolverParamsEnabled(false); std::set<TimeValue> keyframes; { for (std::size_t i = 0; i < markers.size(); ++i) { std::set<double> keys; markers[i]->getCenterKeyframes(&keys); for (std::set<double>::iterator it = keys.begin(); it != keys.end(); ++it) { keyframes.insert(TimeValue(*it)); } } } KnobChoicePtr transformTypeKnob = transformType.lock(); assert(transformTypeKnob); int transformType_i = transformTypeKnob->getValue(); TrackerTransformNodeEnum transformType = (TrackerTransformNodeEnum)transformType_i; NodePtr node = publicInterface->getNode(); invertTransform.lock()->setValue(type == eTrackerMotionTypeStabilize); KnobDoublePtr centerKnob = center.lock(); // Set the center at the reference frame Point centerValue = {0, 0}; int nSamplesAtRefTime = 0; for (std::size_t i = 0; i < markers.size(); ++i) { if ( !markers[i]->isEnabled(refTime) ) { continue; } KnobDoublePtr markerCenterKnob = markers[i]->getCenterKnob(); centerValue.x += markerCenterKnob->getValueAtTime(refTime); centerValue.y += markerCenterKnob->getValueAtTime(refTime, DimIdx(1)); ++nSamplesAtRefTime; } if (nSamplesAtRefTime) { centerValue.x /= nSamplesAtRefTime; centerValue.y /= nSamplesAtRefTime; { std::vector<double> values(2); values[0] = centerValue.x; values[1] = centerValue.y; centerKnob->setValueAcrossDimensions(values); } } bool robust; robust = robustModel.lock()->getValue(); KnobDoublePtr maxFittingErrorKnob = fittingErrorWarnIfAbove.lock(); const double maxFittingError = maxFittingErrorKnob->getValue(); node->getApp()->progressStart( node, tr("Solving for transform parameters...").toStdString(), std::string() ); lastSolveRequest.refTime = refTime; lastSolveRequest.jitterPeriod = jitterPer; lastSolveRequest.jitterAdd = jitterAdd; lastSolveRequest.allMarkers = markers; lastSolveRequest.keyframes = keyframes; lastSolveRequest.robustModel = robust; lastSolveRequest.maxFittingError = maxFittingError; switch (transformType) { case eTrackerTransformNodeTransform: computeTransformParamsFromTracks(); break; case eTrackerTransformNodeCornerPin: computeCornerParamsFromTracks(); break; } } // TrackerNodePrivate::solveTransformParams
DisplayChannelsEnum ViewerNode::getDisplayChannels(int index) const { KnobChoicePtr displayChoice = _imp->displayChannelsKnob[index].lock(); return (DisplayChannelsEnum)displayChoice->getValue(); }