乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 40|回复: 2

[求助][ARX]如何根据鼠标在屏幕上面的移动轨迹画出它的相应CAD实体?

[复制链接]

4

主题

6

帖子

2

银币

初来乍到

Rank: 1

铜币
22
发表于 2006-2-28 00:13:00 | 显示全部楼层 |阅读模式
利用Arx进行二次开发的时候,如何根据鼠标在屏幕上面的移动轨迹画出它的相应CAD实体?请斑竹和各位高手赐教!谢谢!
回复

使用道具 举报

14

主题

43

帖子

3

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
99
发表于 2006-3-2 19:59:00 | 显示全部楼层
我试过了,这个可以。是转载别处的代码
//而且目前所有的参考书上对AcEdJig类的使用都是以拖动一个椭圆为例(作者都互相抄袭)
//因此我就想,把要生成的系列图形定义成一个自定义实体,不就可以使用AcEdJig了吗!
class  CMARectWindow : public AcDbEntity
{
public:
ACRX_DECLARE_MEMBERS(CMARectWindow);
CMARectWindow();
virtual ~CMARectWindow();
virtual Acad::ErrorStatus dwgOutFields(AcDbDwgFiler* pFiler) const;
virtual Acad::ErrorStatus dwgInFields(AcDbDwgFiler* pFiler);
virtual Adesk::Boolean worldDraw(AcGiWorldDraw* mode);
        //设置插入基点
Acad::ErrorStatus setStartPt(const AcGePoint3d startPt);
        //取得插入基点
AcGePoint3d startPt();

private:
        //成员变量,图形插入基点
        AcGePoint3d m_startPt;
};

///////////////CMARectWindow 类实现文件//////////////////

ACRX_DXF_DEFINE_MEMBERS(CMARectWindow, AcDbEntity,
                        AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,
                        AcDbProxyEntity::kNoOperation,
                        CMAWINDO_INFO, PGL_02);

CMARectWindow::CMARectWindow()
{
m_startPt.set(0.0, 0.0, 0.0);
}
CMARectWindow::~CMARectWindow()
{
// TODO: clean up.
}

Adesk::Boolean CMARectWindow::worldDraw(AcGiWorldDraw* mode)
{
assertReadEnabled();

AcGePoint3d pt;  //插入点
AcGePoint3d pt1, pt2, pt3, pt4;  //四个角点
AcGeVector3d vec;
AcGeVector3d normal(0.0, 0.0, 1.0);

//
pt = startPt();

//
vec.set(0, 50, 0);
pt1 = pt - vec;
pt4 = pt + vec;

vec.set(60, 0, 0);
pt2 = pt1 + vec;
pt3 = pt4 + vec;

AcGePoint3d pLineArray[5];
pLineArray[0] = pt1;
pLineArray[1] = pt2;
pLineArray[2] = pt3;
pLineArray[3] = pt4;
pLineArray[4] = pt1;

//设置颜色为红色
mode->subEntityTraits().setColor(1);
   
//绘制矩形
mode->geometry().polyline(5, pLineArray);

//绘制圆
mode->geometry().circle(pt, 30.0, normal);

return AcDbEntity::worldDraw(mode);

}
Acad::ErrorStatus CMARectWindow::dwgInFields(AcDbDwgFiler* pFiler)
{
assertWriteEnabled();

Acad::ErrorStatus es;
if ((es = AcDbEntity::dwgInFields(pFiler)) != Acad::eOk)
{
  return es;
}

pFiler->readItem(&m_startPt);

return pFiler->filerStatus();
}
Acad::ErrorStatus CMARectWindow::dwgOutFields(AcDbDwgFiler* pFiler) const
{
assertReadEnabled();

Acad::ErrorStatus es;
if ((es = AcDbEntity::dwgOutFields(pFiler)) != Acad::eOk)
{
  return es;
}

pFiler->writeItem(m_startPt);

return pFiler->filerStatus();
}


AcGePoint3d CMARectWindow::startPt()
{
assertReadEnabled();
return m_startPt;
}

Acad::ErrorStatus CMARectWindow::setStartPt(const AcGePoint3d startPt)
{
assertWriteEnabled();
m_startPt = startPt;
return Acad::eOk;
}

/////////////////////////////////////////////
/////////////////////////////////////////////
/////////////////////////////////////////////
////////////拖动函数/////////////////////////

class pglyxqLine : public AcEdJig
{
public:
    pglyxqLine();
    void doIt();
    virtual DragStatus sampler();
    virtual Adesk::Boolean update();
    virtual AcDbEntity* entity() const;
private:
    CMARectWindow *pRectWindow;
    AcGePoint3d ptm, movePt;
};

///////////////构造函数//////////////////////////////////////
pglyxqLine::pglyxqLine()
{
   //
   //
}

///////////////拖动图形/////////////////////////////////////
void
pglyxqLine::doIt()
{
    pRectWindow = new CMARectWindow;
    if(!pRectWindow)
    {
      acutPrintf("****CMARectWindow对象不存在****");
      return;
    }
    setDispPrompt("\n指定位置: ");
    AcEdJig:ragStatus stat = drag();
    append();
}

//////////////捕获定点设备并作出分析////////////////////////
AcEdJig:ragStatus
pglyxqLine::sampler()
{
    DragStatus stat;

    static AcGePoint3d tempPoint;
    stat = acquirePoint(movePt);
    if (tempPoint != movePt)
        tempPoint = movePt;
    else if (stat == AcEdJig::kNormal)
        return AcEdJig::kNoChange;
   
    return stat;
}

/////////更新数据///////并更新类成员变量的值/////////////////
Adesk::Boolean
pglyxqLine::update()
{
    ptm = movePt;
    pRectWindow->setStartPt(ptm);
    return Adesk::kTrue;
}

//////////////////更新实体///////////////////////////////////
AcDbEntity*
pglyxqLine::entity() const
{
    return pRectWindow;
}

////////////命令执行函数//////////////////////////////////////////////
void
create_tuxing()
{
   
    //初始化一个拖动派生类实体
    pglyxqLine *pJig = new pglyxqLine();
    //拖动实体
    pJig->doIt();
    delete pJig;
}
void
initApp()
{
    acedRegCmds->addCommand("PGL_YXQ", "PGLYXQ", "PGLYXQ", ACRX_CMD_MODAL, create_tuxing);
    //自定义类初始化函数
    CMARectWindow::rxInit();
    acrxBuildClassHierarchy();
}
void
unloadApp()
{
    acedRegCmds->removeGroup("PGL_YXQ");
    deleteAcRxClass(CMARectWindow::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;
}
回复

使用道具 举报

4

主题

6

帖子

2

银币

初来乍到

Rank: 1

铜币
22
发表于 2006-3-2 22:07:00 | 显示全部楼层
谢谢badboy518朋友的答案。正在认真学习中。。。
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-5-1 01:54 , Processed in 0.397540 second(s), 59 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表