ObjectARX
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Custom Object to hold data structure

1 REPLY 1
Reply
Message 1 of 2
Anonymous
394 Views, 1 Reply

Custom Object to hold data structure

Hello Group,

I am trying to modify the delivered example
"...\editor\custobj_dg\custobj.cpp" by replacing the int value with a
struct. But I am not sure about the changes I made to the class and the
dwg/dxf In/Out Fields group of functions with regards to the
AcDbHardPointerId. Is this how it should be done?

Any help will be greatly appreciated.
TIA
Todd

==========================

typedef struct
{
char szUserName [256];
char szDate [16];
char szTime [16];
char szFileName [MAX_PATH];
int nMod;
unsigned int unRevNum;
} sUserData;

typedef struct
{
sUserData User[10];
} sUserList;

void createDictionary();
void iterateDictionary();
void initApp();
void unloadApp();
extern "C"
AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode, void*);

class AsdkMyClass : public AcDbObject
{
public:
ACRX_DECLARE_MEMBERS(AsdkMyClass);
AsdkMyClass() {};
AsdkMyClass(sUserList &list): mUserList(list) {};

Acad::ErrorStatus getData (sUserList&);
Acad::ErrorStatus setData (sUserList);

virtual Acad::ErrorStatus dwgInFields (AcDbDwgFiler*);
virtual Acad::ErrorStatus dwgOutFields(AcDbDwgFiler*)
const;
virtual Acad::ErrorStatus dxfInFields (AcDbDxfFiler*);
virtual Acad::ErrorStatus dxfOutFields(AcDbDxfFiler*)
const;
private:
sUserList mUserList;
AcDbHardOwnershipId mId;
};

ACRX_DXF_DEFINE_MEMBERS(AsdkMyClass, AcDbObject,
AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,
AcDbProxyObject::kDisableProxyWarning,
ASDKMYCLASS, SAMP2);

// Gets the user data list.
//
Acad::ErrorStatus
AsdkMyClass::getData(sUserList &list)
{
// Tells AutoCAD a read operation is taking place.
//
assertReadEnabled();
list = mUserList;
return Acad::eOk;
}

// Sets the user data list.
//
Acad::ErrorStatus
AsdkMyClass::setData(sUserList list)
{
// Triggers openedForModify notification.
//
assertWriteEnabled();
mUserList = list;
return Acad::eOk;
}


// Files data in from a DWG file.
//
Acad::ErrorStatus
AsdkMyClass::dwgInFields(AcDbDwgFiler* pFiler)
{
assertWriteEnabled();

AcDbObject::dwgInFields(pFiler);
// For wblock filing we wrote out our owner as a hard
// pointer ID so now we need to read it in to keep things
// in sync.
//
if (pFiler->filerType() == AcDb::kWblockCloneFiler) {
AcDbHardPointerId id;
pFiler->readItem(&id);
}
pFiler->readItem(&mId);
return pFiler->filerStatus();
}

// Files data out to a DWG file.
//
Acad::ErrorStatus
AsdkMyClass::dwgOutFields(AcDbDwgFiler* pFiler) const
{
assertReadEnabled();

AcDbObject::dwgOutFields(pFiler);
// Since objects of this class will be in the Named
// Objects Dictionary tree and may be hard referenced
// by some other object, to support wblock we need to
// file out our owner as a hard pointer ID so that it
// will be added to the list of objects to be wblocked.
//
if (pFiler->filerType() == AcDb::kWblockCloneFiler)
pFiler->writeHardPointerId((AcDbHardPointerId)ownerId());
pFiler->writeItem(mId);
return pFiler->filerStatus();
}

// Files data in from a DXF file.
//
Acad::ErrorStatus
AsdkMyClass::dxfInFields(AcDbDxfFiler* pFiler)
{
assertWriteEnabled();

Acad::ErrorStatus es;
if ((es = AcDbObject::dxfInFields(pFiler))
!= Acad::eOk)
{
return es;
}

// Check if we're at the right subclass getData marker.
//
if (!pFiler->atSubclassData("AsdkMyClass")) {
return Acad::eBadDxfSequence;
}

struct resbuf inbuf;
while (es == Acad::eOk) {
if ((es = pFiler->readItem(&inbuf)) == Acad::eOk) {
if (inbuf.restype == AcDb::kDxfHardPointerId) {
acdbGetObjectId(mId, inbuf.resval.rlname);
}
}
}
return pFiler->filerStatus();
}

// Files data out to a DXF file.
//
Acad::ErrorStatus
AsdkMyClass::dxfOutFields(AcDbDxfFiler* pFiler) const
{
assertReadEnabled();

AcDbObject::dxfOutFields(pFiler);
pFiler->writeItem(AcDb::kDxfSubclass, "AsdkMyClass");
pFiler->writeItem(AcDb::kDxfHardPointerId, mId);
return pFiler->filerStatus();
}

void
createDictionary()
{
AcDbDictionary *pNamedobj;
acdbHostApplicationServices()->workingDatabase()->
getNamedObjectsDictionary(pNamedobj, AcDb::kForWrite);

// Check to see if the dictionary we want to create is
// already present. If not, create it and add
// it to the named object dictionary.
//
AcDbDictionary *pDict;
if (pNamedobj->getAt("ASDK_DICT", (AcDbObject*&) pDict,
AcDb::kForWrite) == Acad::eKeyNotFound)
{
pDict = new AcDbDictionary;
AcDbObjectId DictId;
pNamedobj->setAt("ASDK_DICT", pDict, DictId);
}
pNamedobj->close();

if (pDict) {
// Create a new object to add to the new dictionary,
// add it, then close it.
//
sUserList list;

for ( int i = 0; i < 10; i++ )
{
sprintf ( list.User.szUserName, "My User Name%02d", i+1 );
sprintf ( list.User.szFileName, "My File Name%02d", i+1 );
sprintf ( list.User.szDate, "%02d/%02d/20%02d", i+1, i+1,
i+1 );
sprintf ( list.User.szTime, "%02d:%02d:%02d AM", i+1, i+1,
i+1 );
list.User.nMod = 0;
list.User.unRevNum = i;
}

AsdkMyClass *pObj1 = new AsdkMyClass(list);

AcDbObjectId rId1;
pDict->setAt("OBJ1", pObj1, rId1);

pObj1->close();
pDict->close();
}
}


// Opens the dictionary associated with the key ASDK_DICT
// and iterates through all its entries, printing out the
// integer data value in each entry.
//
void
iterateDictionary()
{
AcDbDictionary *pNamedobj;
acdbHostApplicationServices()->workingDatabase()
->getNamedObjectsDictionary(pNamedobj, AcDb::kForRead);

// Get a pointer to the ASDK_DICT dictionary.
//
AcDbDictionary *pDict;
pNamedobj->getAt("ASDK_DICT", (AcDbObject*&)pDict,
AcDb::kForRead);

pNamedobj->close();

// Get an iterator for the ASDK_DICT dictionary.
//
AcDbDictionaryIterator* pDictIter= pDict->newIterator();

AsdkMyClass *pMyCl;
sUserList list;
for (; !pDictIter->done(); pDictIter->next()) {

// Get the current record, open it for read, and
// print its data.
//
pDictIter->getObject((AcDbObject*&)pMyCl,
AcDb::kForRead);
pMyCl->getData(list);
pMyCl->close();
for ( int i = 0; i < 10; i++ )
{
acutPrintf("\nUser Name = %s", list.User.szUserName);
acutPrintf("\nFile Name = %s", list.User.szFileName);
acutPrintf("\nDate = %s", list.User.szDate);
acutPrintf("\nTime = %s", list.User.szTime);
acutPrintf("\nModified = %d", list.User.nMod);
acutPrintf("\nRevision = %u", list.User.unRevNum);
} }
delete pDictIter;
pDict->close();
}

// The initialization function called from the acrxEntryPoint() function
during the
// kInitAppMsg case is used to add commands
// to the command stack and to add classes to the ACRX class
// hierarchy.
//
void
initApp()
{
acedRegCmds->addCommand("ASDK_DICTIONARY_COMMANDS",
"ASDK_CREATE", "CREATE", ACRX_CMD_MODAL,
createDictionary);

acedRegCmds->addCommand("ASDK_DICTIONARY_COMMANDS",
"ASDK_ITERATE", "ITERATE", ACRX_CMD_MODAL,
iterateDictionary);

AsdkMyClass::rxInit();
acrxBuildClassHierarchy();
}


// The clean up function called from the acrxEntryPoint() function during
the
// kUnloadAppMsg case removes this application's
// command set from the command stack and removes this application's
// custom classes from the ACRX runtime class hierarchy.
//
void
unloadApp()
{
acedRegCmds->removeGroup("ASDK_DICTIONARY_COMMANDS");

// Remove the AsdkMyClass class from the ACRX runtime
// class hierarchy. If this is done while the database is
// still active, it should cause all objects of class
// AsdkMyClass to be turned into proxies.
//
deleteAcRxClass(AsdkMyClass::desc());
}


// ARX entry point
//
AcRx::AppRetCode
acrxEntryPoint(AcRx::AppMsgCode msg, void* appId)
{
switch (msg) {
case AcRx::kInitAppMsg:
acrxDynamicLinker->unlockApplication(appId);
acrxDynamicLinker->registerAppMDIAware(appId);
initApp();
break;
case AcRx::kUnloadAppMsg:
unloadApp();
}
return AcRx::kRetOK;
}
1 REPLY 1
Message 2 of 2
Anonymous
in reply to: Anonymous

Trying this again

The original post loss its formatting when viewing it on the Web, but it
looked Ok from the newsreader.
Sorry, and I apologize in advance if this second attempt also fails.
Thanks,
Todd

"Todd R. Jacobs" wrote in message
news:5105331@discussion.autodesk.com...
Hello Group,

I am trying to modify the delivered example
"...\editor\custobj_dg\custobj.cpp" by replacing the int value with a
struct. But I am not sure about the changes I made to the class and the
dwg/dxf In/Out Fields group of functions with regards to the
AcDbHardPointerId. Is this how it should be done?

Any help will be greatly appreciated.
TIA
Todd

[code]
typedef struct
{
char szUserName [256];
char szDate [16];
char szTime [16];
char szFileName [MAX_PATH];
int nMod;
unsigned int unRevNum;
} sUserData;

typedef struct
{
sUserData User[10];
} sUserList;

void createDictionary();
void iterateDictionary();
void initApp();
void unloadApp();
extern "C"
AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode, void*);

class AsdkMyClass : public AcDbObject
{
public:
ACRX_DECLARE_MEMBERS(AsdkMyClass);
AsdkMyClass() {};
AsdkMyClass(sUserList &list): mUserList(list) {};

Acad::ErrorStatus getData (sUserList&);
Acad::ErrorStatus setData (sUserList);

virtual Acad::ErrorStatus dwgInFields (AcDbDwgFiler*);
virtual Acad::ErrorStatus dwgOutFields(AcDbDwgFiler*)
const;
virtual Acad::ErrorStatus dxfInFields (AcDbDxfFiler*);
virtual Acad::ErrorStatus dxfOutFields(AcDbDxfFiler*)
const;
private:
sUserList mUserList;
AcDbHardOwnershipId mId;
};

ACRX_DXF_DEFINE_MEMBERS(AsdkMyClass, AcDbObject,
AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,
AcDbProxyObject::kDisableProxyWarning,
ASDKMYCLASS, SAMP2);

// Gets the user data list.
//
Acad::ErrorStatus
AsdkMyClass::getData(sUserList &list)
{
// Tells AutoCAD a read operation is taking place.
//
assertReadEnabled();
list = mUserList;
return Acad::eOk;
}

// Sets the user data list.
//
Acad::ErrorStatus
AsdkMyClass::setData(sUserList list)
{
// Triggers openedForModify notification.
//
assertWriteEnabled();
mUserList = list;
return Acad::eOk;
}


// Files data in from a DWG file.
//
Acad::ErrorStatus
AsdkMyClass::dwgInFields(AcDbDwgFiler* pFiler)
{
assertWriteEnabled();

AcDbObject::dwgInFields(pFiler);
// For wblock filing we wrote out our owner as a hard
// pointer ID so now we need to read it in to keep things
// in sync.
//
if (pFiler->filerType() == AcDb::kWblockCloneFiler) {
AcDbHardPointerId id;
pFiler->readItem(&id);
}
pFiler->readItem(&mId);
return pFiler->filerStatus();
}

// Files data out to a DWG file.
//
Acad::ErrorStatus
AsdkMyClass::dwgOutFields(AcDbDwgFiler* pFiler) const
{
assertReadEnabled();

AcDbObject::dwgOutFields(pFiler);
// Since objects of this class will be in the Named
// Objects Dictionary tree and may be hard referenced
// by some other object, to support wblock we need to
// file out our owner as a hard pointer ID so that it
// will be added to the list of objects to be wblocked.
//
if (pFiler->filerType() == AcDb::kWblockCloneFiler)
pFiler->writeHardPointerId((AcDbHardPointerId)ownerId());
pFiler->writeItem(mId);
return pFiler->filerStatus();
}

// Files data in from a DXF file.
//
Acad::ErrorStatus
AsdkMyClass::dxfInFields(AcDbDxfFiler* pFiler)
{
assertWriteEnabled();

Acad::ErrorStatus es;
if ((es = AcDbObject::dxfInFields(pFiler))
!= Acad::eOk)
{
return es;
}

// Check if we're at the right subclass getData marker.
//
if (!pFiler->atSubclassData("AsdkMyClass")) {
return Acad::eBadDxfSequence;
}

struct resbuf inbuf;
while (es == Acad::eOk) {
if ((es = pFiler->readItem(&inbuf)) == Acad::eOk) {
if (inbuf.restype == AcDb::kDxfHardPointerId) {
acdbGetObjectId(mId, inbuf.resval.rlname);
}
}
}
return pFiler->filerStatus();
}

// Files data out to a DXF file.
//
Acad::ErrorStatus
AsdkMyClass::dxfOutFields(AcDbDxfFiler* pFiler) const
{
assertReadEnabled();

AcDbObject::dxfOutFields(pFiler);
pFiler->writeItem(AcDb::kDxfSubclass, "AsdkMyClass");
pFiler->writeItem(AcDb::kDxfHardPointerId, mId);
return pFiler->filerStatus();
}

void
createDictionary()
{
AcDbDictionary *pNamedobj;
acdbHostApplicationServices()->workingDatabase()->
getNamedObjectsDictionary(pNamedobj, AcDb::kForWrite);

// Check to see if the dictionary we want to create is
// already present. If not, create it and add
// it to the named object dictionary.
//
AcDbDictionary *pDict;
if (pNamedobj->getAt("ASDK_DICT", (AcDbObject*&) pDict,
AcDb::kForWrite) == Acad::eKeyNotFound)
{
pDict = new AcDbDictionary;
AcDbObjectId DictId;
pNamedobj->setAt("ASDK_DICT", pDict, DictId);
}
pNamedobj->close();

if (pDict) {
// Create a new object to add to the new dictionary,
// add it, then close it.
//
sUserList list;

for ( int i = 0; i < 10; i++ )
{
sprintf ( list.User.szUserName, "My User Name%02d", i+1 );
sprintf ( list.User.szFileName, "My File Name%02d", i+1 );
sprintf ( list.User.szDate, "%02d/%02d/20%02d", i+1, i+1,
i+1 );
sprintf ( list.User.szTime, "%02d:%02d:%02d AM", i+1, i+1,
i+1 );
list.User.nMod = 0;
list.User.unRevNum = i;
}

AsdkMyClass *pObj1 = new AsdkMyClass(list);

AcDbObjectId rId1;
pDict->setAt("OBJ1", pObj1, rId1);

pObj1->close();
pDict->close();
}
}


// Opens the dictionary associated with the key ASDK_DICT
// and iterates through all its entries, printing out the
// integer data value in each entry.
//
void
iterateDictionary()
{
AcDbDictionary *pNamedobj;
acdbHostApplicationServices()->workingDatabase()
->getNamedObjectsDictionary(pNamedobj, AcDb::kForRead);

// Get a pointer to the ASDK_DICT dictionary.
//
AcDbDictionary *pDict;
pNamedobj->getAt("ASDK_DICT", (AcDbObject*&)pDict,
AcDb::kForRead);

pNamedobj->close();

// Get an iterator for the ASDK_DICT dictionary.
//
AcDbDictionaryIterator* pDictIter= pDict->newIterator();

AsdkMyClass *pMyCl;
sUserList list;
for (; !pDictIter->done(); pDictIter->next()) {

// Get the current record, open it for read, and
// print its data.
//
pDictIter->getObject((AcDbObject*&)pMyCl,
AcDb::kForRead);
pMyCl->getData(list);
pMyCl->close();
for ( int i = 0; i < 10; i++ )
{
acutPrintf("\nUser Name = %s", list.User.szUserName);
acutPrintf("\nFile Name = %s", list.User.szFileName);
acutPrintf("\nDate = %s", list.User.szDate);
acutPrintf("\nTime = %s", list.User.szTime);
acutPrintf("\nModified = %d", list.User.nMod);
acutPrintf("\nRevision = %u", list.User.unRevNum);
} }
delete pDictIter;
pDict->close();
}

// The initialization function called from the acrxEntryPoint() function
during the
// kInitAppMsg case is used to add commands
// to the command stack and to add classes to the ACRX class
// hierarchy.
//
void
initApp()
{
acedRegCmds->addCommand("ASDK_DICTIONARY_COMMANDS",
"ASDK_CREATE", "CREATE", ACRX_CMD_MODAL,
createDictionary);

acedRegCmds->addCommand("ASDK_DICTIONARY_COMMANDS",
"ASDK_ITERATE", "ITERATE", ACRX_CMD_MODAL,
iterateDictionary);

AsdkMyClass::rxInit();
acrxBuildClassHierarchy();
}


// The clean up function called from the acrxEntryPoint() function during
the
// kUnloadAppMsg case removes this application's
// command set from the command stack and removes this application's
// custom classes from the ACRX runtime class hierarchy.
//
void
unloadApp()
{
acedRegCmds->removeGroup("ASDK_DICTIONARY_COMMANDS");

// Remove the AsdkMyClass class from the ACRX runtime
// class hierarchy. If this is done while the database is
// still active, it should cause all objects of class
// AsdkMyClass to be turned into proxies.
//
deleteAcRxClass(AsdkMyClass::desc());
}


// ARX entry point
//
AcRx::AppRetCode
acrxEntryPoint(AcRx::AppMsgCode msg, void* appId)
{
switch (msg) {
case AcRx::kInitAppMsg:
acrxDynamicLinker->unlockApplication(appId);
acrxDynamicLinker->registerAppMDIAware(appId);
initApp();
break;
case AcRx::kUnloadAppMsg:
unloadApp();
}
return AcRx::kRetOK;
}
[/code]

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost