//
//	Copyright © 2008 Nemetschek North America 
//	All Rights Reserved.
//
// Created by Vladislav Stanev

#include "StdAfx.h"
//#include "VWNURBSCurve.h"

using namespace VWFC::Math;

VWNURBSCurve::VWNURBSCurve()
{
	fNURBSCurveID	= 0;
	fStartParam		= 0;
	fEndParam		= 1;
	fp				= NULL;
	::GS_VWQueryInterface( IID_ParasolidKernel, & fp );
}

VWNURBSCurve::VWNURBSCurve(int curveID)
{
	fp				= NULL;
	fNURBSCurveID	= 0;
	fStartParam		= 0;
	fEndParam		= 1;

	::GS_VWQueryInterface( IID_ParasolidKernel, & fp );

	PK_LOGICAL_t isEntity = PK_LOGICAL_false;
	VERIFYN(kBiplab, !PK_ENTITY_is(curveID, &isEntity));

	if (isEntity == PK_LOGICAL_true) {
		fNURBSCurveID	= curveID;
		PK_INTERVAL_t interval;
		VERIFYN(kBiplab, !PK_CURVE_ask_interval(fNURBSCurveID, &interval));
		fStartParam = interval.value[0];
		fEndParam = interval.value[1];
	}
}

VWNURBSCurve::VWNURBSCurve(const VWNURBSCurve& src)
{
	fp				= NULL;
	fNURBSCurveID	= 0;
	fStartParam		= 0;
	fEndParam		= 1;

	::GS_VWQueryInterface( IID_ParasolidKernel, & fp );

	PK_LOGICAL_t isEntity = PK_LOGICAL_false;
	VERIFYN(kBiplab, !PK_ENTITY_is(src.fNURBSCurveID, &isEntity));

	if (isEntity == PK_LOGICAL_true) {
		fNURBSCurveID	= src.fNURBSCurveID;
		PK_INTERVAL_t interval;
		VERIFYN(kBiplab, !PK_CURVE_ask_interval(fNURBSCurveID, &interval));
		fStartParam = interval.value[0];
		fEndParam = interval.value[1];
	}
}

VWNURBSCurve::~VWNURBSCurve()
{
	if ( fp ) {
		fp->Release();
		fp	= NULL;
	}
}

VWNURBSCurve& VWNURBSCurve::operator=(const VWNURBSCurve& src)
{
	fNURBSCurveID	= src.fNURBSCurveID;
	PK_INTERVAL_t interval;
	VERIFYN(kBiplab, !PK_CURVE_ask_interval(fNURBSCurveID, &interval));
	fStartParam = interval.value[0];
	fEndParam = interval.value[1];
	return *this;
}

void VWNURBSCurve::SetStartParameter(double startParam)
{
	if (fp) {
		if (fNURBSCurveID != PK_ENTITY_null) {
			PK_INTERVAL_t interval;
			VERIFYN(kBiplab, !PK_CURVE_ask_interval(fNURBSCurveID, &interval));
			if (MathUtils::GEish(startParam, interval.value[0], 1E-6))
				fStartParam = startParam;
		}
	}
}

void VWNURBSCurve::SetEndParameter(double endParam)
{
	if (fp) {
		if (fNURBSCurveID != PK_ENTITY_null) {
			PK_INTERVAL_t interval;
			VERIFYN(kBiplab, !PK_CURVE_ask_interval(fNURBSCurveID, &interval));
			if (MathUtils::GEish(endParam, interval.value[1], 1E-6))
				fEndParam = endParam;
		}
	}
}

double VWNURBSCurve::GetStartParameter()
{
	return fStartParam;
}

double VWNURBSCurve::GetEndParameter()
{
	return fEndParam;
}

int VWNURBSCurve::GetVWNURBSCurveID()
{
	return fNURBSCurveID;
}