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

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

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

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

<P>我试过了,这个可以。是转载别处的代码</P>
<P>//而且目前所有的参考书上对AcEdJig类的使用都是以拖动一个椭圆为例(作者都互相抄袭)<BR>//因此我就想,把要生成的系列图形定义成一个自定义实体,不就可以使用AcEdJig了吗!</P>
<P>class&nbsp; CMARectWindow : public AcDbEntity<BR>{<BR>public:</P>
<P>&nbsp;ACRX_DECLARE_MEMBERS(CMARectWindow);</P>
<P>&nbsp;CMARectWindow();<BR>&nbsp;virtual ~CMARectWindow();</P>
<P>&nbsp;virtual Acad::ErrorStatus dwgOutFields(AcDbDwgFiler* pFiler) const;<BR>&nbsp;virtual Acad::ErrorStatus dwgInFields(AcDbDwgFiler* pFiler);<BR>&nbsp;virtual Adesk::Boolean worldDraw(AcGiWorldDraw* mode);</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //设置插入基点<BR>&nbsp;Acad::ErrorStatus setStartPt(const AcGePoint3d startPt);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //取得插入基点<BR>&nbsp;AcGePoint3d startPt();</P>
<P><BR>private:</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //成员变量,图形插入基点<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AcGePoint3d m_startPt;<BR>};</P>
<P>&nbsp;</P>
<P>///////////////CMARectWindow 类实现文件//////////////////</P>
<P><BR>ACRX_DXF_DEFINE_MEMBERS(CMARectWindow, AcDbEntity,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AcDbProxyEntity::kNoOperation,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CMAWINDO_INFO, PGL_02);</P>
<P><BR>CMARectWindow::CMARectWindow()<BR>{</P>
<P>&nbsp;m_startPt.set(0.0, 0.0, 0.0);</P>
<P>}</P>
<P>CMARectWindow::~CMARectWindow()<BR>{<BR>&nbsp;// TODO: clean up.</P>
<P>}</P>
<P>&nbsp;</P>
<P>Adesk::Boolean CMARectWindow::worldDraw(AcGiWorldDraw* mode)<BR>{<BR>&nbsp;assertReadEnabled();<BR>&nbsp;<BR>&nbsp;AcGePoint3d pt;&nbsp; //插入点<BR>&nbsp;AcGePoint3d pt1, pt2, pt3, pt4;&nbsp; //四个角点<BR>&nbsp;AcGeVector3d vec;<BR>&nbsp;AcGeVector3d normal(0.0, 0.0, 1.0);<BR>&nbsp;<BR>&nbsp;//&nbsp;<BR>&nbsp;pt = startPt();<BR>&nbsp;<BR>&nbsp;//<BR>&nbsp;vec.set(0, 50, 0);<BR>&nbsp;pt1 = pt - vec;<BR>&nbsp;pt4 = pt + vec;<BR>&nbsp;<BR>&nbsp;vec.set(60, 0, 0);<BR>&nbsp;pt2 = pt1 + vec;<BR>&nbsp;pt3 = pt4 + vec;<BR>&nbsp;<BR>&nbsp;AcGePoint3d pLineArray;&nbsp;<BR>&nbsp;pLineArray = pt1;<BR>&nbsp;pLineArray = pt2;<BR>&nbsp;pLineArray = pt3;<BR>&nbsp;pLineArray = pt4;<BR>&nbsp;pLineArray = pt1;<BR>&nbsp;<BR>&nbsp;//设置颜色为红色<BR>&nbsp;mode-&gt;subEntityTraits().setColor(1);<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;//绘制矩形<BR>&nbsp;mode-&gt;geometry().polyline(5, pLineArray);<BR>&nbsp;<BR>&nbsp;//绘制圆<BR>&nbsp;mode-&gt;geometry().circle(pt, 30.0, normal);<BR>&nbsp;<BR>&nbsp;return AcDbEntity::worldDraw(mode);<BR>&nbsp;<BR>}</P>
<P>Acad::ErrorStatus CMARectWindow::dwgInFields(AcDbDwgFiler* pFiler)<BR>{<BR>&nbsp;assertWriteEnabled();<BR>&nbsp;<BR>&nbsp;Acad::ErrorStatus es;&nbsp;<BR>&nbsp;if ((es = AcDbEntity::dwgInFields(pFiler)) != Acad::eOk)<BR>&nbsp;{<BR>&nbsp;&nbsp;return es;<BR>&nbsp;}<BR>&nbsp;<BR>&nbsp;pFiler-&gt;readItem(&amp;m_startPt);<BR>&nbsp;<BR>&nbsp;return pFiler-&gt;filerStatus();<BR>}</P>
<P>Acad::ErrorStatus CMARectWindow::dwgOutFields(AcDbDwgFiler* pFiler) const<BR>{<BR>&nbsp;assertReadEnabled();<BR>&nbsp;<BR>&nbsp;Acad::ErrorStatus es;<BR>&nbsp;if ((es = AcDbEntity::dwgOutFields(pFiler)) != Acad::eOk) <BR>&nbsp;{<BR>&nbsp;&nbsp;return es;<BR>&nbsp;}<BR>&nbsp;<BR>&nbsp;pFiler-&gt;writeItem(m_startPt);<BR>&nbsp;<BR>&nbsp;return pFiler-&gt;filerStatus();<BR>}</P>
<P><BR>&nbsp;<BR>AcGePoint3d CMARectWindow::startPt()<BR>{</P>
<P>&nbsp;assertReadEnabled();<BR>&nbsp;return m_startPt;<BR>}</P>
<P><BR>Acad::ErrorStatus CMARectWindow::setStartPt(const AcGePoint3d startPt)<BR>{</P>
<P>&nbsp;assertWriteEnabled();<BR>&nbsp;m_startPt = startPt;<BR>&nbsp;return Acad::eOk;<BR>}</P>
<P>&nbsp;</P>
<P>/////////////////////////////////////////////<BR>/////////////////////////////////////////////<BR>/////////////////////////////////////////////<BR>////////////拖动函数/////////////////////////</P>
<P><BR>class pglyxqLine : public AcEdJig&nbsp;<BR>{<BR>public:<BR>&nbsp;&nbsp;&nbsp; pglyxqLine();<BR>&nbsp;&nbsp;&nbsp; void doIt();<BR>&nbsp;&nbsp;&nbsp; virtual DragStatus sampler();<BR>&nbsp;&nbsp;&nbsp; virtual Adesk::Boolean update();<BR>&nbsp;&nbsp;&nbsp; virtual AcDbEntity* entity() const;</P>
<P>private:<BR>&nbsp;&nbsp;&nbsp; CMARectWindow *pRectWindow;</P>
<P>&nbsp;&nbsp;&nbsp; AcGePoint3d ptm, movePt;<BR>};</P>
<P><BR>///////////////构造函数//////////////////////////////////////</P>
<P>pglyxqLine::pglyxqLine()<BR>{<BR>&nbsp;&nbsp; //<BR>&nbsp;&nbsp; //<BR>}</P>
<P><BR>///////////////拖动图形/////////////////////////////////////</P>
<P>void<BR>pglyxqLine::doIt()<BR>{<BR>&nbsp;&nbsp;&nbsp; pRectWindow = new CMARectWindow;<BR>&nbsp;&nbsp;&nbsp; if(!pRectWindow)<BR>&nbsp;&nbsp;&nbsp; { <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; acutPrintf("****CMARectWindow对象不存在****"); <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return;<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; setDispPrompt("\n指定位置: ");<BR>&nbsp;&nbsp;&nbsp; AcEdJig::DragStatus stat = drag();</P>
<P>&nbsp;&nbsp;&nbsp; append();<BR>}</P>
<P>&nbsp;</P>
<P>//////////////捕获定点设备并作出分析////////////////////////</P>
<P>AcEdJig::DragStatus<BR>pglyxqLine::sampler()<BR>{<BR>&nbsp;&nbsp;&nbsp; DragStatus stat;</P>
<P><BR>&nbsp;&nbsp;&nbsp; static AcGePoint3d tempPoint;</P>
<P>&nbsp;&nbsp;&nbsp; stat = acquirePoint(movePt);</P>
<P>&nbsp;&nbsp;&nbsp; if (tempPoint != movePt)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tempPoint = movePt;<BR>&nbsp;&nbsp;&nbsp; else if (stat == AcEdJig::kNormal)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return AcEdJig::kNoChange;<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; return stat;<BR>}</P>
<P>&nbsp;</P>
<P>/////////更新数据///////并更新类成员变量的值/////////////////</P>
<P>Adesk::Boolean<BR>pglyxqLine::update()<BR>{<BR>&nbsp;&nbsp;&nbsp; ptm = movePt;</P>
<P>&nbsp;&nbsp;&nbsp; pRectWindow-&gt;setStartPt(ptm); </P>
<P>&nbsp;&nbsp;&nbsp; return Adesk::kTrue;<BR>}</P>
<P>&nbsp;</P>
<P>//////////////////更新实体///////////////////////////////////</P>
<P>AcDbEntity*<BR>pglyxqLine::entity() const<BR>{<BR>&nbsp;&nbsp;&nbsp; return pRectWindow;<BR>}</P>
<P>&nbsp;</P>
<P>////////////命令执行函数//////////////////////////////////////////////</P>
<P>void<BR>create_tuxing()<BR>{<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; //初始化一个拖动派生类实体<BR>&nbsp;&nbsp;&nbsp; pglyxqLine *pJig = new pglyxqLine();<BR>&nbsp;&nbsp;&nbsp; //拖动实体<BR>&nbsp;&nbsp;&nbsp; pJig-&gt;doIt();</P>
<P>&nbsp;&nbsp;&nbsp; delete pJig;<BR>}</P>
<P>void<BR>initApp()<BR>{<BR>&nbsp;&nbsp;&nbsp; acedRegCmds-&gt;addCommand("PGL_YXQ", "PGLYXQ", "PGLYXQ", ACRX_CMD_MODAL, create_tuxing);</P>
<P>&nbsp;&nbsp;&nbsp; //自定义类初始化函数<BR>&nbsp;&nbsp;&nbsp; CMARectWindow::rxInit();<BR>&nbsp;&nbsp;&nbsp; acrxBuildClassHierarchy();</P>
<P>}</P>
<P>void<BR>unloadApp()<BR>{<BR>&nbsp;&nbsp;&nbsp; acedRegCmds-&gt;removeGroup("PGL_YXQ");</P>
<P>&nbsp;&nbsp;&nbsp; deleteAcRxClass(CMARectWindow::desc());<BR>}</P>
<P>&nbsp;</P>
<P><BR>extern "C" AcRx::AppRetCode<BR>acrxEntryPoint(AcRx::AppMsgCode msg, void* appId)<BR>{<BR>&nbsp;&nbsp;&nbsp; switch (msg) <BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; case AcRx::kInitAppMsg:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; acrxDynamicLinker-&gt;unlockApplication(appId);<BR>&nbsp;acrxDynamicLinker-&gt;registerAppMDIAware(appId);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; initApp();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<BR>&nbsp;&nbsp;&nbsp; case AcRx::kUnloadAppMsg:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unloadApp();<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; return AcRx::kRetOK;<BR>}</P>

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

谢谢<A name=1099><FONT color=#000066><B>badboy518</B></FONT></A>朋友的答案。正在认真学习中。。。

pglyxq 发表于 2006-3-2 22:10:00

pglyxq 发表于 2006-3-3 08:28:00

页: [1]
查看完整版本: [求助][ARX]如何根据鼠标在屏幕上面的移动轨迹画出它的相应CAD实体?