xiaomuyi 发表于 2006-2-28 00:13:00

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

利用Arx进行二次开发的时候,如何根据鼠标在屏幕上面的移动轨迹画出它的相应CAD实体?请斑竹和各位高手赐教!谢谢!

badboy518 发表于 2006-3-2 19:59:00

我试过了,这个可以。是转载别处的代码
//而且目前所有的参考书上对AcEdJig类的使用都是以拖动一个椭圆为例(作者都互相抄袭)
//因此我就想,把要生成的系列图形定义成一个自定义实体,不就可以使用AcEdJig了吗!
classCMARectWindow : 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;
pLineArray = pt1;
pLineArray = pt2;
pLineArray = pt3;
pLineArray = pt4;
pLineArray = 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;
}

xiaomuyi 发表于 2006-3-2 22:07:00

谢谢badboy518朋友的答案。正在认真学习中。。。
页: [1]
查看完整版本: [求助][ARX]如何根据鼠标在屏幕上面的移动轨迹画出它的相应CAD实体?