for (int i = 0; i < ellipseCount; i++, j += 0.1) {
scale. setToScaling(j, pEllipse->center());
scale. entry[2][2] = 1.0; // Z scaling == 1
// getTransformed copy uses this->clone() to create
// a new object, which the ent pointer is assigned
// to point to. Therefore, ent should NOT point to an
// existing entity or there will be a memory leak!
//
// Since this->clone() is used, the AsdkEllipse class
// must override this member function to
// be sure that an AsdkEllipse is created instead
// of just an AcDbEllipse.
//
AsdkEllipse *pNextEllipse;
((AsdkEllipse*)ellipses[0])->getTransformedCopy(
scale, (AcDbEntity*&)pNextEllipse);
ellipses. append(pNextEllipse);
}
AcDbBlockTable *pBlockTable;
acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pBlockTable, AcDb::kForRead);
AcDbBlockTableRecord *pBlockTableRecord;
pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,
AcDb::kForWrite);
pBlockTable->close();
AcDbObjectIdArray ellipseIds;
AcDbObjectId tempId;
for (i = 0; i < ellipses. length(); i++) {
pBlockTableRecord->appendAcDbEntity(tempId,
(AsdkEllipse*)ellipses[i]);
ellipseIds. append(tempId);
}
pBlockTableRecord->close();
// Set up the hard pointers and close the ellipses.
//
for (i = 0; i < ellipses. length(); i++) {
// Add in all the IDs.
//
((AsdkEllipse*)ellipses[i])
->setEllipseIds(ellipseIds);
// Now remove the object ID of the "*this" ellipse
// so it doesn’t reference itself.
//
((AsdkEllipse*)ellipses[i])->removeId(
((AsdkEllipse*)ellipses[i])->objectId());
((AsdkEllipse*)ellipses[i])->close();
}
}
void
initApp()
{
acedRegCmds->addCommand("ASDK_ELLIPSES",
"ASDK_ELLIPSES", "ELLIPSES",
ACRX_CMD_MODAL, createEllipses);
AsdkEllipse::rxInit();
acrxBuildClassHierarchy();
}
void
unloadApp()
{
acedRegCmds->removeGroup("ASDK_ELLIPSES");
// Remove the AsdkEllipse class from the ACRX runtime
// class hierarchy. If this is done while the database is
// still active, it should cause all objects of class
// AsdkEllipse to be turned into proxies.
//
deleteAcRxClass(AsdkEllipse::desc());
}
extern "C" 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;
}
Пример Заказного Объектного Класса
Следующие разделы показывают заголовку и исходным файлам для класса пользователя, AsdkMyClass, который получен из AcDbObject. Этот класс сохраняет одиночное целочисленное значение, которое может быть установлено и делать запрос с его setData () и getData() функции. Это также осуществляет dwgInFields(), dwgOutFields(), dxfInFields(), и dxfOutFields () функции для записи в файл. Это записано в и читать от файла, так что его исходный файл использует макрокоманду ACRX_DXF_DEFINE_MEMBERS.
Файл Заголовка
Следующий код показывает объявлению класса для нового класса AsdkMyClass полученный из AcDbObject.
class AsdkMyClass : public AcDbObject
//
// This class demonstrates custom objects.
//
// To keep it simple, this class has a single integer data
// member. Get and set functions are provided for this
// data member.
//
{
public:
ACRX_DECLARE_MEMBERS(AsdkMyClass);
AsdkMyClass(): mIntval(0) {};
AsdkMyClass(const Adesk::Int16& val): mIntval(val) {};
Acad::ErrorStatus getData (Adesk::Int16&);
Acad::ErrorStatus setData (Adesk::Int16);
virtual Acad::ErrorStatus dwgInFields (AcDbDwgFiler*);
virtual Acad::ErrorStatus dwgOutFields(AcDbDwgFiler*)
const;
virtual Acad::ErrorStatus dxfInFields (AcDbDxfFiler*);
virtual Acad::ErrorStatus dxfOutFields(AcDbDxfFiler*)
const;
private:
Adesk::Int16 mIntval;
};
Файл реализации
Следующий код показывает выполнению для нового класса AsdkMyClass:
ACRX_DXF_DEFINE_MEMBERS(AsdkMyClass, AcDbObject,
AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent, 0,
ASDKMYCLASS, SAMP2);
// Gets the value of the integer data member.
//
Acad::ErrorStatus
AsdkMyClass::getData(Adesk::Int16& val)
{
// Tells AutoCAD a read operation is taking place.
//
assertReadEnabled();
val = mIntval;
return Acad::eOk;
}
// Sets the value of the integer data member.
//
Acad::ErrorStatus
AsdkMyClass::setData(Adesk::Int16 val)
{
// Triggers openedForModify notification.
//
assertWriteEnabled();
mIntval = val;
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(&mIntval);
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(mIntval);
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::kDxfInt16) {
mIntval = inbuf. resval. rint;
}
}
}
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::kDxfInt16, mIntval);
return pFiler->filerStatus();
}
// This function creates two objects of class AsdkMyClass.
// It fills them in with the integers 1 and 2, and then adds
// them to the dictionary associated with the key ASDK_DICT.
// If this dictionary doesn’t exist, it is created and added
// to the named object dictionary.
//
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 new objects to add to the new dictionary,
// add them, then close them.
//
AsdkMyClass *pObj1 = new AsdkMyClass(1);
AsdkMyClass *pObj2 = new AsdkMyClass(2);
AcDbObjectId rId1, rId2;
pDict->setAt("OBJ1", pObj1, rId1);
pDict->setAt("OBJ2", pObj2, rId2);
pObj1->close();
pObj2->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;
Adesk::Int16 val;
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(val);
pMyCl->close();
acutPrintf("\nintval is: %d", val);
}
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 cleanup 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
|
Из за большого объема этот материал размещен на нескольких страницах:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |


