STDMETHODIMP CComPolygon::get_TextStyleName(BSTR * pVal)
{
	CHECKOUTPARAM(pVal);
    try
    {
        Acad::ErrorStatus es;
        AcAxObjectRefPtr<AsdkPoly> pPoly(&m_objRef,AcDb::kForRead,Adesk::kTrue);
	    if((es=pPoly.openStatus()) != Acad::eOk)
            throw es;
        AcDbTextStyleTableRecordPointer pTextStyleRecord(pPoly->styleId(),AcDb::kForRead);
        if((es=pTextStyleRecord.openStatus()) != Acad::eOk)
            throw es;
        const TCHAR* pName;
        if ((es=pTextStyleRecord->getName(pName))!=Acad::eOk)
            throw es;

        USES_CONVERSION;
        *pVal = ::SysAllocString(CT2W(pName));
    }
    catch(const Acad::ErrorStatus)
    {
        return Error(L"Failed to open object.",IID_IComPolygon,E_FAIL);
    }
    catch(const HRESULT hr)
    {
        return Error(L"Invalid argument.",IID_IComPolygon,hr);
    }
	return S_OK;
}
//-----------------------------------------------------------------------------
//- IPerPropertyDisplay
STDMETHODIMP CPieSectorExploded::GetCustomPropertyCtrl (VARIANT varId, LCID lcid, BSTR *pProgId) {
	CHECKOUTPARAM( pProgId ) ;
	//- We want a Boolean edit
	LPOLESTR lpOleStr ;
	::ProgIDFromCLSID (CLSID_AcPePropertyEditorBool, &lpOleStr) ;
	*pProgId =::SysAllocString (lpOleStr) ;
	return (S_OK) ;
}
//This is used to get the value for an element in a group.
//The element is identified by the dwCookie parameter
STDMETHODIMP CComPolygon::GetElementValue(
	/* [in] */ DISPID dispID,
	/* [in] */ DWORD dwCookie,
	/* [out] */ VARIANT * pVarOut)
{
    CHECKOUTPARAM(pVarOut);
    if (dispID >= DISPID_NORMAL && dispID <= DISPID_STARTPOINT)
    {
        try
        {
            if (dwCookie>2)
                throw Acad::eInvalidInput;
            Acad::ErrorStatus es;
            AcAxObjectRefPtr<AsdkPoly> pPoly(&m_objRef,AcDb::kForRead,Adesk::kTrue);
	        if((es=pPoly.openStatus()) != Acad::eOk)
                throw es;

            AcAxPoint3d pt;
			Adesk::Boolean bAsVector=Adesk::kFalse;
			if (dispID == DISPID_NORMAL)
            {
                pt = pPoly->normal();
                //translate from wcs to ucs
                acdbWcs2Ucs(asDblArray(pt),asDblArray(pt),Adesk::kTrue);
                ::VariantCopy(pVarOut,&CComVariant(pt[dwCookie]));
            } else {
                AcAxPoint2d pt2d;
			    switch (dispID)
			    {
			    case DISPID_CENTER:
				    pt2d = pPoly->center();
				    break;
			    case DISPID_STARTPOINT:
				    pt2d = pPoly->startPoint();
				    break;
			    default:
				    throw Acad::eInvalidInput;
			    }
                pt.set(pt2d.x,pt2d.y,pPoly->elevation());
                //translate from wcs to ucs
                acdbEcs2Ucs(asDblArray(pt),asDblArray(pt),asDblArray(pPoly->normal()),Adesk::kFalse);
                ::VariantCopy(pVarOut,&CComVariant(pt[dwCookie]));
            }
        }
        catch(const Acad::ErrorStatus)
        {
            return Error(L"Failed to open object",IID_IComPolygon,E_FAIL);
        }
        catch(const HRESULT hr)
        {
            return Error(L"Invalid argument.",IID_IComPolygon,hr);
        }
    }
	return S_OK;
}
STDMETHODIMP CComPolygon::get_NumSides(long * pVal)
{
	CHECKOUTPARAM(pVal);
    try
    {
        Acad::ErrorStatus es;
        AcAxObjectRefPtr<AsdkPoly> pPoly(&m_objRef,AcDb::kForRead,Adesk::kTrue);
	    if((es=pPoly.openStatus()) != Acad::eOk)
            throw es;
        
        *pVal = pPoly->numSides();
    }
    catch(const Acad::ErrorStatus)
    {
        return Error(L"Failed to open object",IID_IComPolygon,E_FAIL);
    }
	return S_OK;
}
STDMETHODIMP CComPolygon::get_TextString(BSTR * pVal)
{
    CHECKOUTPARAM(pVal);
    try
    {
        Acad::ErrorStatus es;
        AcAxObjectRefPtr<AsdkPoly> pPoly(&m_objRef,AcDb::kForRead,Adesk::kTrue);
	    if((es=pPoly.openStatus()) != Acad::eOk)
            throw es;
        
        USES_CONVERSION;
        *pVal = SysAllocString(CT2W(pPoly->name()));
    }
    catch(const Acad::ErrorStatus)
    {
        return Error(L"Failed to open object",IID_IComPolygon,E_FAIL);
    }
	return S_OK;
}
STDMETHODIMP CComPolygon::get_Elevation(double *pVal)
{
	CHECKOUTPARAM(pVal);
    try
    {
        Acad::ErrorStatus es;
        AcAxObjectRefPtr<AsdkPoly> pPoly(&m_objRef,AcDb::kForRead,Adesk::kTrue);
	    if((es=pPoly.openStatus()) != Acad::eOk)
            throw es;
        *pVal = pPoly->elevation();
    }
    catch(const Acad::ErrorStatus)
    {
        return Error(L"Failed to open object.",IID_IComPolygon,E_FAIL);
    }
    catch(const HRESULT hr)
    {
        return Error(L"Invalid argument.",IID_IComPolygon,hr);
    }
	return S_OK;
}
STDMETHODIMP CComPolygon::get_StartPoint(VARIANT * pVal)
{
	CHECKOUTPARAM(pVal);
    try
    {
        Acad::ErrorStatus es;
        AcAxObjectRefPtr<AsdkPoly> pPoly(&m_objRef,AcDb::kForRead,Adesk::kTrue);
	    if((es=pPoly.openStatus()) != Acad::eOk)
            throw es;
        AcAxPoint2d pt = pPoly->startPoint();
        pt.setVariant(pVal);
    }
    catch(const Acad::ErrorStatus)
    {
        return Error(L"Failed to open object.",IID_IComPolygon,E_FAIL);
    }
    catch(const HRESULT hr)
    {
        return Error(L"Invalid argument.",IID_IComPolygon,hr);
    }
	return S_OK;
}
//-----------------------------------------------------------------------------
STDMETHODIMP CPieSectorExploded::GetCurrentValueData (IUnknown *pUnk, VARIANT *pVarData) {
	CHECKOUTPARAMVAL( pUnk, E_INVALIDARG ) ;
	CHECKOUTPARAM( pVarData ) ;

	::VariantInit (pVarData) ;
	V_VT(pVarData) =VT_BOOL ;
	V_BOOL(pVarData) =VARIANT_FALSE ;

	CComQIPtr<IAcadPie> pPie (pUnk) ;
	CComPtr<IAcadPieSectors> pSectors ;
	pPie->get_Sectors (&pSectors) ;
	long nb =0 ;
	pSectors->get_Count (&nb) ;
	if ( nb == 0 )
		return (S_OK) ;

	ULONG index =CPieSectorsSpin::GetCounterSpinPosition () ;
	CComPtr<IUnknown> pUnk2 ;
	pSectors->get_Item (CComVariant ((long)index), &pUnk2) ;
	CComQIPtr<IAcadPieSector> pSector (pUnk2) ;
	pSector->get_Exploded (&V_BOOL(pVarData)) ;
	return (S_OK) ;
}
//-----------------------------------------------------------------------------
STDMETHODIMP CPieSectorExploded::GetCurrentValueType (VARTYPE *pVarType) {
	CHECKOUTPARAM( pVarType ) ;
	//- Boolean
	*pVarType =VT_BOOL ;
	return (S_OK) ;
}
//-----------------------------------------------------------------------------
STDMETHODIMP CPieSectorExploded::GetCurrentValueName (BSTR *pBstrName) {
	CHECKOUTPARAM( pBstrName ) ;
	*pBstrName =::SysAllocString (L"Exploded") ;
	return (S_OK) ;
}
//-----------------------------------------------------------------------------
STDMETHODIMP CPieSectorExploded::GetDescription (BSTR *pBstrName) {
	CHECKOUTPARAM( pBstrName ) ;
	*pBstrName =::SysAllocString (L"Exploded") ;
	return (S_OK) ;
}
//-----------------------------------------------------------------------------
STDMETHODIMP CPieSectorExploded::IsPropertyReadOnly (BOOL *pbReadOnly) {
	CHECKOUTPARAM( pbReadOnly ) ;
	*pbReadOnly =FALSE ;
	return (S_OK) ;
}
//-----------------------------------------------------------------------------
STDMETHODIMP CPieSectorExploded::IsPropertyEnabled (IUnknown *pUnk, BOOL *pbEnabled) {
	CHECKOUTPARAMVAL( pUnk, E_INVALIDARG ) ;
	CHECKOUTPARAM( pbEnabled ) ;
	*pbEnabled =TRUE ;
	return (S_OK) ;
}
//-----------------------------------------------------------------------------
//- IDynamicProperty
STDMETHODIMP CPieSectorExploded::GetGUID (GUID *pPropGUID) {
	CHECKOUTPARAM( pPropGUID ) ;
	memcpy (pPropGUID, &CLSID_PieSectorExploded, sizeof (GUID)) ;
	return (S_OK) ;
}
//-----------------------------------------------------------------------------
STDMETHODIMP CPieSectorExploded::Connect (IDynamicPropertyNotify2 *pSink) {
	CHECKOUTPARAM( pSink ) ;
	m_pNotify =pSink ;
	m_pNotify->AddRef () ;
	return (S_OK) ;
}