输入上下文事件示例
以下示例创建一个简单的上下文反应器,用于响应各种输入上下文事件: #include <adslib.h>
#include <aced.h>
#include <dbmain.h>
#include <rxregsvc.h>
#include <acedinpt.h>
#include <acdocman.h>
// The input context reactor class.
//
class MyContextReactor : public AcEdInputContextReactor
{
public:
void
beginGetPoint(
const AcGePoint3d* pointIn,
const char* promptString,
int initGetFlags,
const char* pKeywords);
void
endGetPoint(
Acad::PromptStatus returnStatus,
const AcGePoint3d& pointOut,
const char*& pKeyword);
void
beginGetOrientation(
const AcGePoint3d* pointIn,
const char* promptString,
int initGetFlags,
const char* pKeywords);
void
endGetOrientation(
Acad::PromptStatus returnStatus,
double& angle,
const char*& pKeyword);
void
beginGetCorner(
const AcGePoint3d* firstCorner,
const char* promptString,
int initGetFlags,
const char* pKeywords);
void
endGetCorner(
Acad::PromptStatus returnStatus,
AcGePoint3d& secondCorner,
const char*& pKeyword);
void
beginSSGet(
const char* pPrompt,
int initGetFlags,
const char* pKeywords,
const char* pSSControls,
const AcArray<AcGePoint3d>& points,
const resbuf* entMask);
void
endSSGet(
Acad::PromptStatus returnStatus,
const AcArray<AcDbObjectId>& ss);
};
void
MyContextReactor::beginGetPoint(
const AcGePoint3d* pointIn,
const char* promptString,
int initGetFlags,
const char* pKeywords)
{
acutPrintf("beginGetPoint: pointIn = %.2f,%.2f,%.2f\n",
(*pointIn)[0], (*pointIn)[1], (*pointIn)[2]);
if (NULL != promptString)
acutPrintf("%s", promptString);
acutPrintf("initGetFlags: %d\n", initGetFlags);
if (NULL != pKeywords)
acutPrintf("Keywords: %s\n", pKeywords);
}
void
MyContextReactor::endGetPoint(
Acad::PromptStatus returnStatus,
const AcGePoint3d& pointOut,
const char*& pKeyword)
{
acutPrintf("endGetPoint: %d\n", returnStatus);
acutPrintf("%.2f,%.2f,%.2f\n", pointOut[0], pointOut[1],
pointOut[2]);
if (NULL != pKeyword)
acutPrintf("Keyword: %s\n", pKeyword);
}
void
MyContextReactor::beginGetOrientation(
const AcGePoint3d* pointIn,
const char* promptString,
int initGetFlags,
const char* pKeywords)
{
acutPrintf("beginGetOrientation: %.2f, %.2f, %.2f\n",
(*pointIn)[0], (*pointIn)[1], (*pointIn)[2]);
}
void
MyContextReactor::endGetOrientation(
Acad::PromptStatus returnStatus,
double& angle,
const char*& pKeyword)
{
acutPrintf("endGetOrientation: %.2f\n", angle);
}
void
MyContextReactor::beginGetCorner(
const AcGePoint3d* firstCorner,
const char* promptString,
int initGetFlags,
const char* pKeywords)
{
if (NULL != firstCorner)
{
acutPrintf(
"beginGetCorner: %.2f, %.2f, %.2f\n",
(*firstCorner)[0],
(*firstCorner)[1],
(*firstCorner)[2]);
}
}
void
MyContextReactor::endGetCorner(
Acad::PromptStatus returnStatus,
AcGePoint3d& secondCorner,
const char*& pKeyword)
{
acutPrintf("endGetCorner\n");
}
void
MyContextReactor::beginSSGet(
const char* pPrompt,
int initGetFlags,
const char* pKeywords,
const char* pSSControls,
const AcArray<AcGePoint3d>& points,
const resbuf* entMask)
{
acutPrintf("beginSSGet:%s\n", NULL != pPrompt ? pPrompt : "");
for (int i = 0; i < points.length(); i++)
acutPrintf("%d: %.2f, %.2f, %.2f\n", i, points[i][X],
points[i][Y], points[i][Z]);
}
void
MyContextReactor::endSSGet(
Acad::PromptStatus returnStatus,
const AcArray<AcDbObjectId>& ss)
{
acutPrintf("endSSGet\n");
for (int i = 0; i < ss.length(); i++)
acutPrintf("Entity %d: <%x>\n", i, ss[i].asOldId());
}
// My context reactor object
MyContextReactor my_icr;
extern "C" __declspec(dllexport) AcRx::AppRetCode
acrxEntryPoint(
AcRx::AppMsgCode msg,
void *p)
{
switch (msg)
{
case AcRx::kInitAppMsg:
acrxUnlockApplication(p);
acrxRegisterAppMDIAware(p);
break;
case AcRx::kLoadDwgMsg:
// Attach a context reactor to the current document.
//
curDoc()->inputPointManager()->
addInputContextReactor(&my_icr);
break;
case AcRx::kUnloadAppMsg:
// Warning! This sample attaches a context reactor,
// but it never detaches it. A real-life application
// will need to monitor to which document it attached
// the reactor, and will need to detach it.
//
break;
}
return AcRx::kRetOK;
}
父主题: |
|Archiver|CAD开发者社区
( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-10-29 07:02
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.