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

#include "StdAfx.h"

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

VWClass::VWClass(InternalIndex index)
{
	fClassIndex				= index;
	Boolean		bValidClass	= ::GS_ValidClass( gCBP, fClassIndex );
	VWFC_ASSERT( bValidClass );
	if ( ! bValidClass )
		THROW_VWFC_EXCEPTION( VWBadObjectTypeException, 0, "invalid class internal index passed" );
}

VWClass::VWClass(const TXString& name)
{
	fClassIndex				= 0;
	VWFC_ASSERT( name.GetLength() < sizeof(InternalName) );
	if ( name.GetLength() < sizeof(InternalName) ) {
		InternalName className;
		name.CopyInto( className );

		fClassIndex				= ::GS_AddClass( gCBP, className );
	}

	Boolean		bValidClass	= ::GS_ValidClass( gCBP, fClassIndex );
	VWFC_ASSERT( bValidClass );
	if ( ! bValidClass )
		THROW_VWFC_EXCEPTION( VWCannotCreateObjectException, 0, "class cannot be created" );
}

VWClass::~VWClass()
{
}

VWClass::operator InternalIndex() const
{
	return fClassIndex;
}

VWClassAttr VWClass::GetClassAttribs() const
{
	VERIFYN( kVStanev, ::GS_ValidClass( gCBP, fClassIndex ) );
	return VWClassAttr( fClassIndex );
}

void VWClass::SetThisClassAsDefault() const
{
	VERIFYN( kVStanev, ::GS_ValidClass( gCBP, fClassIndex ) );
	::GS_SetDefaultClass( gCBP, fClassIndex );
}

bool VWClass::IsValidClass() const
{
	return ::GS_ValidClass( gCBP, fClassIndex );
}

TXString VWClass::GetClassName() const
{
	VERIFYN( kVStanev, ::GS_ValidClass( gCBP, fClassIndex ) );
	InternalName className;
	::GS_ClassIDToName( gCBP, fClassIndex, className );
	return className;
}

void VWClass::DeleteThisClass()
{
	VERIFYN( kVStanev, ::GS_ValidClass( gCBP, fClassIndex ) );
	InternalName className;
	::GS_ClassIDToName( gCBP, fClassIndex, className );
	::GS_DeleteClass( gCBP, className );
}

EClassVisibility VWClass::IsClassVisible() const
{
	VERIFYN( kVStanev, ::GS_ValidClass( gCBP, fClassIndex ) );
	return (EClassVisibility) ::GS_GetClVisibility( gCBP, fClassIndex );
}

void VWClass::SetClassVisible(EClassVisibility visibility)
{
	VERIFYN( kVStanev, ::GS_ValidClass( gCBP, fClassIndex ) );
	::GS_SetClVisibility( gCBP, fClassIndex, (short) visibility );
}

bool VWClass::GetUseGraphics() const
{
	VERIFYN( kVStanev, ::GS_ValidClass( gCBP, fClassIndex ) );
	return ::GS_GetClUseGraphic( gCBP, fClassIndex );
}

void VWClass::SetUseGraphics(bool use)
{
	VERIFYN( kVStanev, ::GS_ValidClass( gCBP, fClassIndex ) );
	::GS_SetClUseGraphic( gCBP, fClassIndex, use );
}

bool VWClass::IsValidClassName(const TXString& name)
{
	InternalIndex	index				= 0;
	VWFC_ASSERT( name.GetLength() < sizeof(InternalName) );
	if ( name.GetLength() < sizeof(InternalName) ) {
		InternalName className;
		name.CopyInto( className );

		index				= ::GS_ClassNameToID( gCBP, className );
	}

	return ::GS_ValidClass( gCBP, index );
}

bool VWClass::IsValidClassIndex(InternalIndex index)
{
	return ::GS_ValidClass( gCBP, index );
}

InternalIndex VWClass::GetClassIDByName(const TXString& name)
{
	InternalIndex	index				= 0;
	VWFC_ASSERT( name.GetLength() < sizeof(InternalName) );
	if ( name.GetLength() < sizeof(InternalName) ) {
		InternalName className;
		name.CopyInto( className );

		index				= ::GS_ClassNameToID( gCBP, className );
	}
	return index;
}

InternalIndex VWClass::GetMaxClassIndex()
{
	return ::GS_MaxClassID( gCBP );
}

InternalIndex VWClass::AddGuidesClass()
{
	return ::GS_AddGuidesClass( gCBP );
}

InternalIndex VWClass::GetDimensionClassIndex()
{
	return ::GS_GetDimensionClassID( gCBP );
}

InternalIndex VWClass::GetNoneClassIndex()
{
	return ::GS_GetNoneClassID( gCBP );
}

InternalIndex VWClass::GetDefaultClass()
{
	return ::GS_GetDefaultClass( gCBP );
}

EClassOptions VWClass::GetProgramVar_ClassOptions()
{
	short	value;
	VERIFYN( kVStanev, ::GS_GetProgramVariable( gCBP, varClassOptions, & value ) );
	return (EClassOptions) value;
}