ObjectARX, AutoCAD. Среда программирования библиотеки C++



         

Использование Реактора Базы данных - часть 2


// calls printObj() to print the information about

// the object that triggered the notification.

//

void printDbEvent(const AcDbObject* pObj, const char* pEvent)

{

acutPrintf(" Event: AcDbDatabaseReactor::%s ", pEvent);

printObj(pObj);

}

// Prints out the basic information about the object pointed

// to by pObj.

//

void printObj(const AcDbObject* pObj)

{

if (pObj == NULL) {

acutPrintf("(NULL)");

return;

}

AcDbHandle objHand;

char handbuf[17];

// Get the handle as a string.

//

pObj->getAcDbHandle(objHand);

objHand.getIntoAsciiBuffer(handbuf);

acutPrintf(

"\n (class==%s, handle==%s, id==%lx, db==%lx)",

pObj->isA()->name(), handbuf,

pObj->objectId().asOldId(), pObj->database());

}

// Adds a reactor to the database to monitor changes.

// This can be called multiple times without any ill

// effect because subsequent calls will be ignored.

//

void watchDb()

{

if (gpDbr == NULL) {

gpDbr = new AsdkDbReactor();

}

acdbHostApplicationServices()->workingDatabase()->addReactor(gpDbr);

acutPrintf(

" Added Database Reactor to "

"acdbHostApplicationServices()->workingDatabase().\n");

}

// Removes the database reactor.

//

void clearReactors()

{

if (acdbHostApplicationServices()->workingDatabase() != NULL) {

acdbHostApplicationServices()->workingDatabase()->removeReactor(gpDbr);

delete gpDbr;

gpDbr = NULL;

}

}

// ObjectARX entry point function

//

AcRx::AppRetCode

acrxEntryPoint(AcRx::AppMsgCode msg, void* appId)

{

switch (msg) {

case AcRx::kInitAppMsg:

acrxDynamicLinker->unlockApplication(appId);

acrxDynamicLinker->registerAppNotMDIAware(appId);

acedRegCmds->addCommand("ASDK_NOTIFY_TEST",

"ASDK_WATCH",

"WATCH",

ACRX_CMD_TRANSPARENT,

watchDb);

acedRegCmds->addCommand("ASDK_NOTIFY_TEST",

"ASDK_CLEAR",

"CLEAR",

ACRX_CMD_TRANSPARENT,

clearReactors);

break;

case AcRx::kUnloadAppMsg:

clearReactors();

acedRegCmds->removeGroup("ASDK_NOTIFY_TEST");

break;

}

return AcRx::kRetOK;

}




Содержание  Назад  Вперед