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

#include "StdAfx.h"

using namespace VWFC;
using namespace VWFC::Math;
using namespace VWFC::VWObjects;
using namespace VWFC::Tools;

VWObjectAttr::VWObjectAttr()
{
	fhObject		= NULL;
}

VWObjectAttr::VWObjectAttr(MCObjectHandle h)
{
	fhObject		= h;
}

VWObjectAttr::VWObjectAttr(const VWObjectAttr& src)
{
	this->operator = ( src );
}

VWObjectAttr::~VWObjectAttr()
{
}

VWObjectAttr& VWObjectAttr::operator=(const VWObjectAttr& src)
{
	fhObject	= src.fhObject;
	return *this;
}

void VWObjectAttr::ApplyToObject(MCObjectHandle h) const
{
	VWObjectAttr	destObjAttr( h );

	destObjAttr.SetPenForeColor( this->GetPenForeColor() );
	destObjAttr.SetPenBackColor( this->GetPenBackColor() );
	if ( this->GetPenColorByClass() ) {
		destObjAttr.SetPenColorByClass();
	}

	destObjAttr.SetPenPattern( this->GetPenPattern() );
	if ( this->GetPenPatternByClass() ) {
		destObjAttr.SetPenPatternByClass();
	}

	destObjAttr.SetFillForeColor( this->GetFillForeColor() );
	destObjAttr.SetFillBackColor( this->GetFillBackColor() );
	if ( this->GetFillColorByClass() ) {
		destObjAttr.SetFillColorByClass();
	}

	destObjAttr.SetFillPattern( this->GetFillPattern() );
	if ( this->GetFillPatternByClass() ) {
		destObjAttr.SetFillPatternByClass();
	}

	destObjAttr.SetLineWeightInMils( this->GetLineWeightInMils() );
	if ( this->GetLineWeightByClass() ) {
		destObjAttr.SetLineWeightByClass();
	}
}

void VWObjectAttr::SetPenNone()
{
	::GS_SetPenPat( gCBP, fhObject, 0 );
}

void VWObjectAttr::SetPenSolid()
{
	::GS_SetPenPat( gCBP, fhObject, 2 );
}

CRGBColor VWObjectAttr::GetPenForeColor() const
{
	ObjectColorType		color;
	::GS_GetColor( gCBP, fhObject, color );
	return CRGBColor( color.penFore );
}

CRGBColor VWObjectAttr::GetPenBackColor() const
{
	ObjectColorType		color;
	::GS_GetColor( gCBP, fhObject, color );
	return CRGBColor( color.penBack );
}

void VWObjectAttr::SetPenForeColor(const CRGBColor& clr)
{
	ObjectColorType		color;
	::GS_GetColor( gCBP, fhObject, color );
	color.penFore		= clr.GetColorIndex();
	::GS_SetColor( gCBP, fhObject, color );
}

void VWObjectAttr::SetPenBackColor(const CRGBColor& clr)
{
	ObjectColorType		color;
	::GS_GetColor( gCBP, fhObject, color );
	color.penBack		= clr.GetColorIndex();
	::GS_SetColor( gCBP, fhObject, color );
}

bool VWObjectAttr::GetPenColorByClass() const
{
	return ::GS_GetPColorsByClass( gCBP, fhObject ) ? true : false;
}

void VWObjectAttr::SetPenColorByClass()
{
	::GS_SetPColorsByClass( gCBP, fhObject );
}

VWPattern VWObjectAttr::GetPenPattern() const
{
	return VWPattern( ::GS_GetPenPat( gCBP, fhObject ) );
}

void VWObjectAttr::SetPenPattern(const VWPattern& pattern)
{
	::GS_SetPenPat( gCBP, fhObject, pattern );
}

bool VWObjectAttr::GetPenPatternByClass() const
{
	return ::GS_GetPPatByClass( gCBP, fhObject );
}

void VWObjectAttr::SetPenPatternByClass()
{
	::GS_SetPPatByClass( gCBP, fhObject );
}

void VWObjectAttr::SetFillNone()
{
	::GS_SetFillPat( gCBP, fhObject, 0 );
}

void VWObjectAttr::SetFillSolid()
{
	::GS_SetFillPat( gCBP, fhObject, 1 );
}

CRGBColor VWObjectAttr::GetFillForeColor() const
{
	ObjectColorType		color;
	::GS_GetColor( gCBP, fhObject, color );
	return CRGBColor( color.fillFore );
}

CRGBColor VWObjectAttr::GetFillBackColor() const
{
	ObjectColorType		color;
	::GS_GetColor( gCBP, fhObject, color );
	return CRGBColor( color.fillBack );
}

void VWObjectAttr::SetFillForeColor(const CRGBColor& clr)
{
	ObjectColorType		color;
	::GS_GetColor( gCBP, fhObject, color );
	color.fillFore		= clr.GetColorIndex();
	::GS_SetColor( gCBP, fhObject, color );
}

void VWObjectAttr::SetFillBackColor(const CRGBColor& clr)
{
	ObjectColorType		color;
	::GS_GetColor( gCBP, fhObject, color );
	color.fillBack		= clr.GetColorIndex();
	::GS_SetColor( gCBP, fhObject, color );
}

bool VWObjectAttr::GetFillColorByClass() const
{
	return ::GS_GetFColorsByClass( gCBP, fhObject );
}

void VWObjectAttr::SetFillColorByClass()
{
	GS_SetFColorsByClass( gCBP, fhObject );
}

VWPattern VWObjectAttr::GetFillPattern() const
{
	return VWPattern( ::GS_GetFillPat( gCBP, fhObject ) );
}

void VWObjectAttr::SetFillPattern(const VWPattern& pattern)
{
	::GS_SetFillPat( gCBP, fhObject, pattern );
}

bool VWObjectAttr::GetFillPatternByClass() const
{
	return ::GS_GetFPatByClass( gCBP, fhObject );
}

void VWObjectAttr::SetFillPatternByClass()
{
	::GS_SetFPatByClass( gCBP, fhObject );
}

short VWObjectAttr::GetLineWeightInMils() const
{
	return GS_GetLineWeight( gCBP, fhObject );
}

void VWObjectAttr::SetLineWeightInMils(short mils)
{
	::GS_SetLineWeight( gCBP, fhObject, mils );
}

bool VWObjectAttr::GetLineWeightByClass() const
{
	return ::GS_GetLWByClass( gCBP, fhObject );
}

void VWObjectAttr::SetLineWeightByClass()
{
	::GS_SetLWByClass( gCBP, fhObject );
}

MarkerType VWObjectAttr::GetMarker(short& size, short& angle, bool& start, bool& end) const
{
	MarkerType		style;
	Boolean			innerStart, innerEnd;
	::GS_GetMarker( gCBP, fhObject, style, size, angle, innerStart, innerEnd );
	start		= innerStart ? true : false;
	end			= innerEnd ? true : false;
	return style;
}

void VWObjectAttr::SetMarker(MarkerType marker,short size, short angle, bool start, bool end)
{
	::GS_SetMarker( gCBP, fhObject, marker, size, angle, start, end);
}

ArrowType VWObjectAttr::GetArrowHeads(bool& starting, bool& ending, short& sizeInPoints)
{
	ArrowType	style;
	Boolean			innerStart, innerEnd;
	::GS_GetArrowHeads( gCBP, fhObject, innerStart, innerEnd, style, sizeInPoints );
	starting		= innerStart ? true : false;
	ending			= innerEnd ? true : false;
	return style;
}

ArrowType VWObjectAttr::GetArrowHeads(bool& starting, bool& ending, double_gs& sizeInMilimeters)
{
	ArrowType		style;
	double_gs		sizeInInch;
	Boolean			innerStart, innerEnd;
	::GS_GetArrowHeadsN( gCBP, fhObject, innerStart, innerEnd, style, sizeInInch );

	starting				= innerStart ? true : false;
	ending					= innerEnd ? true : false;
	sizeInMilimeters		= sizeInInch * 25.4;
	return style;
}

void VWObjectAttr::SetArrowHeads(ArrowType type, bool starting, bool ending, short sizeInPoints)
{
	::GS_SetArrowHeads( gCBP, fhObject, starting, ending, type, sizeInPoints );
}

void VWObjectAttr::SetArrowHeads(ArrowType type, bool starting, bool ending, double_gs sizeInMilimeters)
{
	double_gs	sizeInInch	= sizeInMilimeters / 25.4;
	::GS_SetArrowHeadsN( gCBP, fhObject, starting, ending, type, sizeInInch );
}

bool VWObjectAttr::GetArrowByClass() const
{
	return ::GS_GetArrowByClass( gCBP, fhObject );
}

void VWObjectAttr::SetArrowByClass()
{
	::GS_SetArrowByClass( gCBP, fhObject );
}

VWPoint2D VWObjectAttr::GetFillOriginPoint() const
{
	WorldPt		pt;
	VERIFYN( kVStanev, ::GS_GetFillOriginPoint( gCBP, fhObject, pt ) );
	return pt;
}

void VWObjectAttr::SetFillOriginPoint(const VWPoint2D& pt)
{
	VERIFYN( kVStanev, ::GS_SetFillOriginPoint( gCBP, fhObject, pt ) );
}

VWPoint2D VWObjectAttr::GetFillIAxisEndPoint() const
{
	WorldPt	pt;
	VERIFYN( kVStanev, ::GS_GetFillIAxisEndPoint( gCBP, fhObject, pt ) );
	return pt;
}

void VWObjectAttr::SetFillIAxisEndPoint(const VWPoint2D& pt)
{
	VERIFYN( kVStanev, ::GS_SetFillIAxisEndPoint( gCBP, fhObject, pt ) );
}

VWPoint2D VWObjectAttr::GetFillJAxisEndPoint() const
{
	WorldPt	pt;
	VERIFYN( kVStanev, ::GS_GetFillJAxisEndPoint( gCBP, fhObject, pt ) );
	return pt;
}

void VWObjectAttr::SetFillJAxisEndPoint(const VWPoint2D& pt)
{
	VERIFYN( kVStanev, ::GS_SetFillJAxisEndPoint( gCBP, fhObject, pt ) );
}

void VWObjectAttr::GetFillPoints(VWPoint2D& originPoint, VWPoint2D& iAxisEndPoint, VWPoint2D& jAxisEndPoint)
{
	WorldPt			a, b, c;
	VERIFYN( kVStanev, ::GS_GetFillPoints( gCBP, fhObject, a, b, c ) );
	originPoint		= a;
	iAxisEndPoint	= b;
	jAxisEndPoint	= c;
}



