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