exam10b.cpp
#include "string.h" #include "stdlib.h" #include "aced.h" #include "dbents.h" #include "dbsymtb.h" #include "dbapserv.h" #include "adslib.h"
void assocLines(); void addToModelSpace(AcDbObjectId&,AcDbEntity *); void initApp(void); void unloadApp(void); extern "C" AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode,void *);
class MyObjectNotify:public AcDbObject { public: ACRX_DECLARE_MEMBERS(MyObjectNotify); MyObjectNotify(){}; void eLinkage(AcDbObjectId i,double f=1.0) { mId=i; mFactor=f; }; void modified(const AcDbObject *); Acad::ErrorStatus dwgInFields(AcDbDwgFiler *); Acad::ErrorStatus dwgOutFields(AcDbDwgFiler *)const ; Acad::ErrorStatus dxfInFields(AcDbDxfFiler *); Acad::ErrorStatus dxfOutFields(AcDbDxfFiler *) const; private: AcDbObjectId mId; double mFactor; };
ACRX_DXF_DEFINE_MEMBERS(MyObjectNotify,AcDbObject, AcDb::kDHL_CURRENT,AcDb::kMReleaseCurrent, 0,MYOBJECTMODIFY,exam10b);
void MyObjectNotify::modified(const AcDbObject *pObj) { AcDbLine *pLine=AcDbLine::cast(pObj); if(!pLine) { const char * str=pObj->isA()->name(); acutPrintf("This is a %s.\n",str); acutPrintf("i only work with lines,sorry.\n"); return; } acutPrintf("\nReactor attached to %lx calling %lx.\n", pLine->objectId(),mId); AcDbLine *pLine2; if(acdbOpenObject((AcDbObject *&)pLine2,mId, AcDb::kForWrite)==Acad::eOk) { AcGePoint3d p=pLine->startPoint(); AcGePoint3d q=pLine->endPoint(); AcGeVector3d v=q-p; double len=v.length();
p=pLine2->startPoint(); q=pLine2->endPoint(); v=q-p; v=len*mFactor *v.normal(); pLine2->setEndPoint(p+v); pLine2->close(); } }
Acad::ErrorStatus MyObjectNotify::dwgInFields(AcDbDwgFiler * filer) { assertWriteEnabled(); AcDbObject::dwgInFields(filer); filer->readItem(&mFactor); filer->readItem((AcDbSoftPointerId *) &mId); return filer->filerStatus(); }
Acad::ErrorStatus MyObjectNotify::dwgOutFields(AcDbDwgFiler * filer) const { assertReadEnabled(); AcDbObject::dwgOutFields(filer); filer->writeItem(mFactor); filer->writeItem((AcDbSoftPointerId *) &mId); return filer->filerStatus(); }
Acad::ErrorStatus MyObjectNotify::dxfInFields(AcDbDxfFiler * filer) { assertReadEnabled(); Acad::ErrorStatus es; if((es=AcDbObject::dxfInFields(filer))!=Acad::eOk) { return es; }
if(!filer->atSubclassData("MyObjectNotify")) { return Acad::eBadDxfSequence; }
struct resbuf rbIn; while(es==Acad::eOk) { if((es=filer->readItem(&rbIn))==Acad::eOk) { if(rbIn.restype==AcDb::kDxfReal) { mFactor=rbIn.resval.rreal; } else if(rbIn.restype==AcDb::kDxfSoftPointerId) { acdbGetObjectId(mId,rbIn.resval.rlname); } else { return (filer->pushBackItem()); } } } return filer->filerStatus(); }
Acad::ErrorStatus MyObjectNotify::dxfOutFields(AcDbDxfFiler * filer) const { assertReadEnabled(); AcDbObject::dxfOutFields(filer); filer->writeItem(AcDb::kDxfSubclass, "MyObjectNotify"); filer->writeItem(AcDb::kDxfReal,mFactor); filer->writeItem(AcDb::kDxfSoftPointerId,mId); return filer->filerStatus(); }
void assocLines() { AcDbDatabase *pDb=acdbHostApplicationServices()->workingDatabase(); AcDbObjectId aId,bId; AcDbLine *pLineA=new AcDbLine; pLineA->setDatabaseDefaults(pDb); pLineA->setStartPoint(AcGePoint3d(1,1,0)); pLineA->setEndPoint(AcGePoint3d(2,1,0)); addToModelSpace(aId,pLineA); ads_printf("Line A is %lx from 1,1 to 2,1j.\n", pLineA->objectId()); AcDbLine *pLineB=new AcDbLine; pLineB->setDatabaseDefaults(pDb); pLineB->setStartPoint(AcGePoint3d(1,2,0)); pLineB->setEndPoint(AcGePoint3d(2,2,0)); addToModelSpace(bId,pLineB); ads_printf("Line B is %lx from 1,2 to 2,2.\n", pLineB->objectId());
AcDbDictionary *pNamedObj; AcDbDictionary *pNameList; pDb->getNamedObjectsDictionary(pNamedObj, AcDb::kForWrite); if(pNamedObj->getAt("ASDK_DICT", (AcDbObject * &) pNameList,AcDb::kForWrite) ==Acad::eKeyNotFound) { pNameList=new AcDbDictionary; AcDbObjectId DictId; pNamedObj->setAt("ASDK_DICT",pNameList,DictId); } pNamedObj->close(); MyObjectNotify *pObj=new MyObjectNotify(); pObj->eLinkage(bId); AcDbObjectId objId; if((pNameList->getAt("object_to_notify_A",objId)) ==Acad::eKeyNotFound) { pNameList->setAt("object_to_notify_A",pObj,objId); pObj->close(); } else { delete pObj; ads_printf("object_to_notify_A already existes\n"); } pLineA->addPersistentReactor(objId); pLineA->close(); pObj=new MyObjectNotify(); pObj->eLinkage(aId); if((pNameList->getAt("object_to_notify_B",objId)) ==Acad::eKeyNotFound) { pNameList->setAt("object_to_notify_B",pObj,objId); pObj->close(); } else { delete pObj; ads_printf("object_to_notify_b already existes\n"); } pNameList->close();
pLineB->addPersistentReactor(objId); pLineB->close(); }
void addToModelSpace(AcDbObjectId &objId,AcDbEntity * pEntity) { AcDbBlockTable *pBlockTable; AcDbBlockTableRecord *pSpaceRecord; acdbHostApplicationServices()->workingDatabase() ->getSymbolTable(pBlockTable,AcDb::kForRead); pBlockTable->getAt(ACDB_MODEL_SPACE,pSpaceRecord, AcDb::kForWrite); pBlockTable->close(); pSpaceRecord->appendAcDbEntity(objId,pEntity); pSpaceRecord->close(); return; }
void initApp() { acedRegCmds->addCommand("EXAM10b", "ALINES", "ALINES", ACRX_CMD_MODAL, assocLines); MyObjectNotify::rxInit(); acrxBuildClassHierarchy(); }
void unloadApp() { acedRegCmds->removeGroup("EXAM10B"); deleteAcRxClass(MyObjectNotify::desc()); }
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; } |