bool UnFbx::FFbxImporter::ImportCurveToAnimSequence(class UAnimSequence * TargetSequence, const FString& CurveName, const FbxAnimCurve* FbxCurve, int32 CurveFlags,const FbxTimeSpan AnimTimeSpan, const float ValueScale/*=1.f*/) const
{
	if (TargetSequence && FbxCurve)
	{
		FName Name = *CurveName;
		USkeleton* Skeleton = TargetSequence->GetSkeleton();
		FSmartNameMapping* NameMapping = Skeleton->SmartNames.GetContainer(USkeleton::AnimCurveMappingName);

		// Add or retrieve curve
		USkeleton::AnimCurveUID Uid;
		if (!NameMapping->Exists(Name))
		{
			// mark skeleton dirty
			Skeleton->Modify();
		}

		NameMapping->AddOrFindName(Name, Uid);

		FFloatCurve * CurveToImport = static_cast<FFloatCurve *>(TargetSequence->RawCurveData.GetCurveData(Uid, FRawCurveTracks::FloatType));
		if(CurveToImport==NULL)
		{
			if(TargetSequence->RawCurveData.AddCurveData(Uid, CurveFlags))
			{
				CurveToImport = static_cast<FFloatCurve *> (TargetSequence->RawCurveData.GetCurveData(Uid, FRawCurveTracks::FloatType));
			}
			else
			{
				// this should not happen, we already checked before adding
				ensureMsgf(0, TEXT("FBX Import: Critical error: no memory?"));
			}
		}
		else
		{
			CurveToImport->FloatCurve.Reset();
		}

		return ImportCurve(FbxCurve, CurveToImport, AnimTimeSpan, ValueScale);
	}

	return false;
}
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent)
{
    setupUi(this);
    m_pTimerMainWindow = new QTimer(this);
    m_pTimerMainWindow->setInterval(100);
    m_pTimerMainWindow->start();

    connect(ComboAngUnits, SIGNAL(currentIndexChanged(int)), this, SLOT(AngleUnitsChanged())) ;

    connect(ComboPeriodMode, SIGNAL(currentIndexChanged(int)), this, SLOT(PeriodModeChanged())) ;

    connect(ComboInterpolMode, SIGNAL(currentIndexChanged(int)), this, SLOT(InterpolMethodChanged())) ;

    connect(CommandPeriod, SIGNAL(pressed()), this, SLOT(PeriodTextChanged())) ;

    connect(CommandSamples, SIGNAL(pressed()), this, SLOT(SamplesTextChanged())) ;

    connect(CommandThighLeng, SIGNAL(pressed()), this, SLOT(ThighLenTextChanged())) ;

    connect(CommandLowerLegLeng, SIGNAL(pressed()) ,this, SLOT(LegLenTextChanged())) ;

    connect(CommandDelay, SIGNAL(pressed()), this, SLOT(DelayTextChanged())) ;

    connect(ButtonAdamsSim, SIGNAL(clicked()), this, SLOT(RunAdamsSim()));


    /*-----------------------------------------------------------------------------------------------
                                Hip Objects Creation and Initialization
      -----------------------------------------------------------------------------------------------*/

    vector <double> vHipTimeVals, vHipAngVals;

    pHipLeft = new CompleteJointPlot;
    MainHLayoutLHip->addWidget(pHipLeft);

    pHipRight = new CompleteJointPlot;
    MainHLayoutRHip->addWidget(pHipRight);

    vHipTimeVals.push_back(0.12);    // Getting Time values into vector
    vHipTimeVals.push_back(0.75);
    vHipTimeVals.push_back(1.47);
    vHipTimeVals.push_back(1.98);
    vHipTimeVals.push_back(2.55);
    vHipTimeVals.push_back(2.91);

    vHipAngVals.push_back(0.371755131000000);  // Getting Angle Values into Vector
    vHipAngVals.push_back(0.0279252680000000);
    vHipAngVals.push_back(-0.336848546000000);
    vHipAngVals.push_back(0.0191986220000000);
    vHipAngVals.push_back(0.425860337000000);
    vHipAngVals.push_back(0.359537826000000);

    pHipLeft->SetDelay(1.5);
    pHipLeft->SetTitle("Left Hip");
    pHipLeft->SetMarkersStatus(MarkersUnchanged);
    pHipLeft->ImportMarkers (vHipTimeVals,vHipAngVals);
    pHipLeft->ShowMarkers(Qt::red);
    pHipLeft->PlotCurve();

    pHipRight->SetDelay(0);
    pHipRight->SetTitle("Right Hip");
    pHipRight->SetMarkersStatus(MarkersUnchanged);
    pHipRight->ImportMarkers (  vHipTimeVals , vHipAngVals );
    pHipRight->ShowMarkers(Qt::red);
    pHipRight->PlotCurve();

    /*-----------------------------------------------------------------------------------------------
                               Knee Objects Creation and Initialization
      -----------------------------------------------------------------------------------------------*/

    vector <double> vKneeTimeVals, vKneeAngVals;

    pKneeLeft = new CompleteJointPlot;
    MainHLayoutLKnee->addWidget(pKneeLeft);

    pKneeRight = new CompleteJointPlot;
    MainHLayoutRKnee->addWidget(pKneeRight);

    vKneeTimeVals.push_back(0.15);    // Getting Time values into vector
    vKneeTimeVals.push_back(0.39);
    vKneeTimeVals.push_back(0.78);
    vKneeTimeVals.push_back(1.17);
    vKneeTimeVals.push_back(1.65);
    vKneeTimeVals.push_back(2.16);

    vKneeAngVals.push_back(-0.169296937);  // Getting Angle Values into Vector
    vKneeAngVals.push_back(-0.307177948000000);
    vKneeAngVals.push_back(-0.151843645000000);
    vKneeAngVals.push_back(-0.0331612560000000);
    vKneeAngVals.push_back(-0.3036872900000);
    vKneeAngVals.push_back(-0.996583003000000);


    pKneeLeft->SetDelay(1.5);
    pKneeLeft->SetTitle("Left Knee");
    pKneeLeft->SetMarkersStatus(MarkersUnchanged);
    pKneeLeft->ImportMarkers ( vKneeTimeVals , vKneeAngVals );
    pKneeLeft->ShowMarkers(Qt::red);
    pKneeLeft->PlotCurve();

    pKneeRight->SetDelay(0);
    pKneeRight->SetTitle("Right Knee");
    pKneeRight->SetMarkersStatus(MarkersUnchanged);
    pKneeRight->ImportMarkers ( vKneeTimeVals , vKneeAngVals);
    pKneeRight->ShowMarkers(Qt::red);
    pKneeRight->PlotCurve();

    connect(pHipLeft, SIGNAL(InterpolationCompleted()), this, SLOT(GetValuesInterpol())) ;
    connect(pHipRight, SIGNAL(InterpolationCompleted()), this, SLOT(GetValuesInterpol())) ;
    connect(pKneeLeft, SIGNAL(InterpolationCompleted()), this, SLOT(GetValuesInterpol())) ;
    connect(pKneeRight, SIGNAL(InterpolationCompleted()), this, SLOT(GetValuesInterpol())) ;

    connect(pHipLeft, SIGNAL(ImportCurve()), this, SLOT(ImportValsCurve())) ;
    connect(pHipRight, SIGNAL(ImportCurve()), this, SLOT(ImportValsCurve())) ;
    connect(pKneeLeft, SIGNAL(ImportCurve()), this, SLOT(ImportValsCurve())) ;
    connect(pKneeRight, SIGNAL(ImportCurve()), this, SLOT(ImportValsCurve())) ;

    /*-----------------------------------------------------------------------------------------------
                                    Creating End Effector Objects and initialization
     -----------------------------------------------------------------------------------------------*/

    pEndEffectRight = new CompleteEndEffectPlot;
    MWinHLayoutREndEffect->addWidget(pEndEffectRight);

    pEndEffectLeft = new CompleteEndEffectPlot;
    MWinHLayoutLEndEffect->addWidget(pEndEffectLeft);

    pEndEffectLeft->SetMarkersNumber(vHipTimeVals.size(), vKneeTimeVals.size());
    pEndEffectRight->SetMarkersNumber(vHipTimeVals.size(), vKneeTimeVals.size());
    EndEffectorPlot(pEndEffectRight, pHipRight, pKneeRight);
    EndEffectorPlot(pEndEffectLeft, pHipLeft, pKneeLeft);

    /*-----------------------------------------------------------------------------------------------
                                    Creating RobotLinks Object
     -----------------------------------------------------------------------------------------------*/
    pRobotMain = new CompleteRobotLinks;
    MainHLayoutSimulation->addWidget(pRobotMain);

    pRobotMain->SetThighLength(50);
    pRobotMain->SetLegLength(60);
    pRobotMain->SetStepValue(0.0);
    pRobotMain->SetPeriod(lineEditPeriod->text().toDouble());
    pRobotMain->SetDelay(lineEditDelay->text().toDouble());
    pRobotMain->SetScalingFactorAngle(1);
    pRobotMain->SetSamples(lineEditSamples->text().toInt());
    pRobotMain->SetSamplesCounter(0);
    pRobotMain->SetTimerInterval();
    ChangeSimulation();

    /*-----------------------------------------------------------------------------------------------
                                   Pointer to Robot Objects Creation
     -----------------------------------------------------------------------------------------------*/

    ppRobotObjects = new CompleteJointPlot*[4];

    ppRobotObjects[1] = pHipLeft;
    ppRobotObjects[3] = pKneeLeft;
    ppRobotObjects[0] = pHipRight;
    ppRobotObjects[2] = pKneeRight;
}