示例#1
0
void
KnobGui::onSetKeyActionTriggered()
{
    QAction* action = qobject_cast<QAction*>( sender() );

    assert(action);
    int dim = action->data().toInt();
    KnobPtr knob = getKnob();

    assert( knob->getHolder()->getApp() );
    //get the current time on the global timeline
    SequenceTime time = knob->getHolder()->getApp()->getTimeLine()->currentFrame();
    AddKeysCommand::KeysToAddList toAdd;
    KnobGuiPtr thisShared = shared_from_this();
    for (int i = 0; i < knob->getDimension(); ++i) {
        if ( (dim == -1) || (i == dim) ) {
            std::list<boost::shared_ptr<CurveGui> > curves = getGui()->getCurveEditor()->findCurve(thisShared, i);
            for (std::list<boost::shared_ptr<CurveGui> >::iterator it = curves.begin(); it != curves.end(); ++it) {
                AddKeysCommand::KeyToAdd keyToAdd;
                KeyFrame kf;
                kf.setTime(time);
                Knob<int>* isInt = dynamic_cast<Knob<int>*>( knob.get() );
                Knob<bool>* isBool = dynamic_cast<Knob<bool>*>( knob.get() );
                AnimatingKnobStringHelper* isString = dynamic_cast<AnimatingKnobStringHelper*>( knob.get() );
                Knob<double>* isDouble = dynamic_cast<Knob<double>*>( knob.get() );

                if (isInt) {
                    kf.setValue( isInt->getValue(i) );
                } else if (isBool) {
                    kf.setValue( isBool->getValue(i) );
                } else if (isDouble) {
                    kf.setValue( isDouble->getValue(i) );
                } else if (isString) {
                    std::string v = isString->getValue(i);
                    double dv;
                    isString->stringToKeyFrameValue(time, ViewIdx(0), v, &dv);
                    kf.setValue(dv);
                }

                keyToAdd.keyframes.push_back(kf);
                keyToAdd.curveUI = *it;
                keyToAdd.knobUI = thisShared;
                keyToAdd.dimension = i;
                toAdd.push_back(keyToAdd);
            }
        }
    }
    pushUndoCommand( new AddKeysCommand(getGui()->getCurveEditor()->getCurveWidget(), toAdd) );
}
void
DSPasteKeysCommand::addOrRemoveKeyframe(bool add)
{
    for (std::list<boost::weak_ptr<DSKnob> >::const_iterator it = _dstKnobs.begin(); it != _dstKnobs.end(); ++it) {
        DSKnobPtr knobContext = it->lock();
        if (!knobContext) {
            continue;
        }
        for (std::size_t i = 0; i < _keys.size(); ++i) {

            int dim = knobContext->getDimension();
            KnobIPtr knob = knobContext->getInternalKnob();
            knob->beginChanges();

            double keyTime = _keys[i].key.getTime();
            double setTime = _pasteRelativeToRefTime ? keyTime - _keys[_refKeyindex].key.getTime() + _refTime : keyTime;

            if (add) {

                for (int j = 0; j < knob->getDimension(); ++j) {
                    if ( (dim == -1) || (j == dim) ) {
                        KeyFrame k = _keys[i].key;
                        k.setTime(setTime);

                        knob->setKeyFrame(k, ViewSpec::all(), j, eValueChangedReasonNatronGuiEdited);
                    }
                }
            } else {
                for (int j = 0; j < knob->getDimension(); ++j) {
                    if ( (dim == -1) || (j == dim) ) {
                        knob->deleteValueAtTime(eCurveChangeReasonDopeSheet, setTime, ViewSpec::all(), j, i == 0);
                    }
                }
            }
            
            knob->endChanges();
        }
    }


    _model->refreshSelectionBboxAndRedrawView();
} // DSPasteKeysCommand::addOrRemoveKeyframe
示例#3
0
	bool AnimationTrack::loadFromXML(TiXmlElement *xmlNodeTrack)
	{
		xmlNodeTrack->QueryStringAttribute("name",&m_name);			
		stringc dataType;
		xmlNodeTrack->QueryStringAttribute("dataType",&dataType);
		m_dataType = stringToDataType(dataType);
		
		TiXmlHandle hXmlNode(xmlNodeTrack);

		//load keyframes data
		TiXmlElement* xmlNodeTimes = hXmlNode.FirstChild( "times" ).Element();
		if(xmlNodeTimes!=0)
		{
			int kfNum = 0;

			//times
			const char* timesStr = xmlNodeTimes->GetText();
			if(timesStr!=0)
			{
				float *times=0;
				kfNum = StringUtil::splitOutFloats(times, timesStr);

				for(int i=0; i<kfNum; ++i)
				{
					KeyFrame* kf = createKeyFrame();
					if(kf!=0)
					{
						kf->setTime(times[i]);
						m_keyFrames.push_back(kf);
					}
				}

				delete times;
			}

			//at least has 1 kf
			if(kfNum>0)
			{
				//KF datas
				float *kfDatas=0;
				TiXmlElement* xmlNodeKFs = hXmlNode.FirstChild( "keyframes" ).Element();
				if(xmlNodeKFs!=0)
				{
					int valueNum = StringUtil::splitOutFloats(kfDatas, xmlNodeKFs->GetText());
					u32 dataElemNum = m_keyFrames[0]->getDataElementNum();
					FLT_ASSERT(dataElemNum>0 && valueNum/dataElemNum==kfNum);					
					
					for(int i=0; i<kfNum; ++i)
					{
						m_keyFrames[i]->loadValue(kfDatas, i);						
					}

					delete kfDatas;
				}

				//interp datas
				TiXmlElement* xmlNodeInterps = hXmlNode.FirstChild( "interps" ).Element();
				if(xmlNodeInterps!=0)
				{
					array_t<stringc> strs;
					strs = StringUtil::split(xmlNodeInterps->GetText(), ",", kfNum);
										
					FLT_ASSERT(strs.size()==kfNum);					

					for(int i=0; i<kfNum; ++i)
					{
						m_keyFrames[i]->setInterpTypeByString(strs[i]);						
					}					
				}
			}

			//create a computed frame, for interpolation
			m_computedFrame = createKeyFrame();
		}

		return true;
	}