CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ObjectARX 开发指南

输入上下文事件示例

2022-12-31 16:33| 发布者: admin| 查看: 322| 评论: 0|来自: AutoCAD

下面的示例创建一个简单的上下文反应器,用于响应各种输入上下文事件:

#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;
}

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-5-19 13:51

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部