/////////////////////////////////////////////////////////////////////
// MyEnumType ///////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
void makeMyEnumTypeTemplateProperties(
class AcRxMemberCollectionBuilder & collectionBuilder, void*);
template<>
int MyEnumTypeTemplate<MyEnum>::subToString(
const void *instance, ACHAR *buffer, size_t sizeInACHARs,
AcRxValueType::StringFormat format) const
{
const ACHAR* formatString = L"%d";
MyEnum & value = *(MyEnum*)instance;
if (buffer==NULL)
return _scwprintf(formatString,value);
return swprintf_s(buffer,sizeInACHARs,formatString,value);
}
template<>
bool MyEnumTypeTemplate<MyEnum>::subEqualTo(
const void *a, const void* b) const
{
MyEnum & v1 = *(MyEnum*)a;
MyEnum & v2 = *(MyEnum*)b;
return v1==v2;
}
template<>
struct AcRxValueType::Desc< MyEnum >
{
__declspec(dllexport) static const AcRxValueType& value() throw();
static void del();
};
MyEnumTypeTemplate<MyEnum>* s_pMyEnumTypeTemplate = NULL;
const AcRxValueType& AcRxValueType::Desc< MyEnum >::value() throw()
{
if (s_pMyEnumTypeTemplate==NULL)
{
s_pMyEnumTypeTemplate = new MyEnumTypeTemplate<MyEnum>(
L"MyEnumProperties",&makeMyEnumTypeTemplateProperties);
AcRxEnumTag* pTag;
pTag = new AcRxEnumTag (L"One", (int)0);
s_pMyEnumTypeTemplate->append(*pTag);
pTag = new AcRxEnumTag (L"Two", (int)1);
s_pMyEnumTypeTemplate->append(*pTag);
pTag = new AcRxEnumTag (L"Three", (int)2);
s_pMyEnumTypeTemplate->append(*pTag);
pTag = new AcRxEnumTag (L"Four", (int)3);
s_pMyEnumTypeTemplate->append(*pTag);
}
return *s_pMyEnumTypeTemplate;
};
// This should be called when the value type is not needed anymore
// Best call it when the module gets unloaded (On_kUnloadAppMsg)
void AcRxValueType::Desc< MyEnum >::del()
{
if (s_pMyEnumTypeTemplate)
{
const ACHAR * name = s_pMyEnumTypeTemplate->name();
if (acrxSysRegistry())
acrxClassDictionary->remove(s_pMyEnumTypeTemplate->name());
s_pMyEnumTypeTemplate = NULL;
}
};
void makeMyEnumTypeTemplateProperties(
class AcRxMemberCollectionBuilder & collectionBuilder, void*)
{
}
/////////////////////////////////////////////////////////////////////
// MyListProperty ///////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
const ACHAR * MyListProperty::kCategoryName = _T("My Category");
AcRxCategory * MyListProperty::category = NULL;
MyListProperty::MyListProperty() :
AcRxProperty(_T("My List Property"),
AcRxValueType::Desc< MyEnum >::value())
{
if (category == NULL)
{
AcRxCategory * parent = AcRxCategory::rootCategory();
category = parent->findDescendant(kCategoryName);
if (category == NULL)
category = new AcRxCategory(kCategoryName, parent);
}
// OPM = Object Property Manager / Property Palette
// Add the Placement attribute to set under which category in
// the OPM the property will be shown
attributes().add(new AcRxUiPlacementAttribute(kCategoryName, 0));
// Add this attribute so that AutoCAD will automatically create
// the COM wrapper for this property, i.e. it will be visible
// in OPM
attributes().add(new AcRxGenerateDynamicPropertiesAttribute());
}
MyListProperty::~MyListProperty()
{
}
/// <summary>
/// This is called by the system to get the property value for
/// a specific object
/// </summary>
Acad::ErrorStatus MyListProperty::subGetValue(
const AcRxObject* pO, AcRxValue& value) const
{
AcDbEntity * ent = AcDbEntity::cast(pO);
if (ent == NULL)
return Acad::eNotThatKindOfClass;
// Get the value from the custom entity
// or wherever we stored the value
AEN1MyCircle * pMyCircle = AEN1MyCircle::cast(pO);
value = AcRxValue(static_cast<MyEnum>(pMyCircle->m_myEnum));
return Acad::eOk;
}
/// <summary>
/// This is called by the system to retrieve the property value for
/// a specific object
/// </summary>
Acad::ErrorStatus MyListProperty::subSetValue(
AcRxObject* pO, const AcRxValue& value) const
{
AcDbEntity * ent = AcDbEntity::cast(pO);
if (ent == NULL)
return Acad::eNotThatKindOfClass;
const MyEnum * val = rxvalue_cast<MyEnum>(&value);
if (val == NULL)
return Acad::eInvalidInput;
// Set the property of the custom entity
// or store it wherever we want to
AEN1MyCircle * pMyCircle = AEN1MyCircle::cast(pO);
pMyCircle->m_myEnum = *val;
return Acad::eOk;
}
/// <summary>
/// This is called to create an instance of our class
/// </summary>
AcRxObject * MyListProperty::makeMyListProperty()
{
return new MyListProperty();
}