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

#include "StdAfx.h"
//#include "VWSymbolObj.h"

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

VWSymbolObj::VWSymbolObj(const TXString& symDefName, const VWPoint2D& location, double dRotDeg)
{
	InternalName intSymbolDefName;
	symDefName.CopyInto( intSymbolDefName );

	fhObject	= ::GS_PlaceSymbolByNameN( gCBP, intSymbolDefName, location, dRotDeg );
	VWFC_ASSERT( fhObject );
	if ( fhObject == NULL )
		THROW_VWFC_EXCEPTION( VWCannotCreateObjectException, 0, "cannot create symbol object" );
}

VWSymbolObj::VWSymbolObj(const VWSymbolDefObj& dymDef, const VWPoint2D& location, double dRotDeg)
{
	fhObject	= ::GS_PlaceSymbolN( gCBP, (MCObjectHandle) dymDef, location, dRotDeg );
	VWFC_ASSERT( fhObject );
	if ( fhObject == NULL )
		THROW_VWFC_EXCEPTION( VWCannotCreateObjectException, 0, "cannot create symbol object" );
}

VWSymbolObj::VWSymbolObj(MCObjectHandle hSymbolDef, const VWPoint2D& location, double dRotDeg)
{
	fhObject	= ::GS_PlaceSymbolN( gCBP, hSymbolDef, location, dRotDeg );
	VWFC_ASSERT( fhObject );
	if ( fhObject == NULL )
		THROW_VWFC_EXCEPTION( VWCannotCreateObjectException, 0, "cannot create symbol object" );
}

VWSymbolObj::VWSymbolObj(MCObjectHandle hSymbol)
{
	VWFC_ASSERT( VWSymbolObj::IsSymbolObject( hSymbol ) );
	if ( ! VWSymbolObj::IsSymbolObject( hSymbol ) )
		THROW_VWFC_EXCEPTION( VWBadObjectTypeException, 0, "bad handle type when creating" );
	fhObject	= hSymbol;
	VWFC_ASSERT( fhObject );
}

VWSymbolObj::VWSymbolObj(const VWSymbolObj& src)
{
	fhObject	= src.fhObject;
	VWFC_ASSERT( fhObject );
}

VWSymbolObj::~VWSymbolObj()
{
}

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

bool VWSymbolObj::IsSymbolObject(MCObjectHandle hObj)
{
	short	type	= ::GS_GetObjectType( gCBP, hObj );
	return type == kSymbolNode;
}

MCObjectHandle VWSymbolObj::GetSymbolDef() const
{
	return ::GS_GetDefinition( gCBP, fhObject );
}