- 积分
- 3918
- 明经币
- 个
- 注册时间
- 2006-10-7
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
绘制有向矩形,学习Jig的一个小例子,分享一下,高手见了勿喷。
 - class CLyFunJigDirectedRect :
- public AcEdJig
- {
- public:
- static void FunJigDirectedRect();//对外接口,注册命令LYDIRRECT
- protected:
- CLyFunJigDirectedRect(void);
- virtual ~CLyFunJigDirectedRect(void);
- virtual void FunDoit();//主流程
- virtual bool GetStPt();//拾取起点
- virtual bool JigFirst();//拾取第二点
- virtual bool JigSecond();//拾取第三点
- protected:
- //此函数将被drag函数调用以获得用户输入
- virtual AcEdJig::DragStatus sampler();
- //对需要在拖动过程中发生变化的实体进行修改
- virtual Adesk::Boolean update();
- //指定了Jig所操作的对象
- virtual AcDbEntity* entity() const;
- void InitPolyline();//初始化多段线
- double Hdist(const AcGePoint3d &pt1,const AcGePoint3d &pt2);
- protected:
- AcDbPolyline* m_pPolyline;//拖动的实体指针
- AcGePoint3d m_StPt;//起点
- AcGePoint3d m_PtJig;//拖动的点
- int m_Index;//操作的是那个点,2,3
- AcGeLine2d m_BaseLine;//方向线
- };
 - void CLyFunJigDirectedRect::FunJigDirectedRect()
- {
- CLyFunJigDirectedRect A;
- A.FunDoit ();
- }
- CLyFunJigDirectedRect::CLyFunJigDirectedRect(void)
- {
- m_pPolyline=nullptr;
- }
- CLyFunJigDirectedRect::~CLyFunJigDirectedRect(void)
- {
- if (m_pPolyline)
- {
- delete m_pPolyline;
- m_pPolyline=nullptr;
- }
- }
- void CLyFunJigDirectedRect::FunDoit()
- {
- if (!this->GetStPt ())
- {
- return;
- }
- this->InitPolyline ();
- if (!this->JigFirst ())
- {
- return;
- }
- this->JigSecond ();
- }
- bool CLyFunJigDirectedRect::GetStPt()
- {
- ads_point ptads;
- int retcode=acedGetPoint(nullptr,_T("\n请拾取起点:"),ptads);
- if (retcode!=RTNORM)
- {
- return false;
- }
- acdbUcs2Wcs(ptads,asDblArray(m_StPt),false);
- return true;
- }
- bool CLyFunJigDirectedRect::JigFirst()
- {
- m_Index=2;
- CString prompt=_T("\n指定第二点<退出>:");
- setDispPrompt(prompt);
- AcEdJig::DragStatus stat=drag ();
- // 拖动之后,根据需要自己的处理方式
- if (stat==kNormal)
- {
- m_BaseLine.set(AcGePoint2d(m_StPt.x,m_StPt.y),AcGePoint2d(m_PtJig.x,m_PtJig.y));
- return true;
- }
- return false;
- }
- bool CLyFunJigDirectedRect::JigSecond()
- {
- m_Index=3;
- CString prompt=_T("\n指定第三点<退出>:");
- setDispPrompt(prompt);
- AcEdJig::DragStatus stat=drag ();
- // 拖动之后,根据需要自己的处理方式
- if (stat==kNormal)
- {
- this->append ();
- m_pPolyline=nullptr;
- return true;
- }
- return false;
- }
- AcEdJig::DragStatus CLyFunJigDirectedRect::sampler()
- {
- DragStatus stat;
- setUserInputControls((UserInputControls)(AcEdJig::kDontEchoCancelForCtrlC));
- //|不回显取消
- static AcGePoint3d pointTemp;
- stat = acquirePoint(m_PtJig);
- if (m_Index==2)
- {
- if (Hdist(m_StPt,m_PtJig)<1E-12)
- {
- return AcEdJig::kNoChange;
- }
- }
- if (pointTemp != m_PtJig)
- pointTemp = m_PtJig;
- else if (stat == AcEdJig::kNormal)
- stat = AcEdJig::kNoChange;
- return stat;
- }
- Adesk::Boolean CLyFunJigDirectedRect::update()
- {
- if (m_Index==2)
- {
- m_PtJig.z=m_StPt.z;
- AcGeVector2d Vec(m_PtJig.x-m_StPt.x,m_PtJig.y-m_StPt.y);
- if (Vec.isZeroLength())
- {
- return Adesk::kFalse;
- }
- AcGeVector2d Vec2(Vec);
- Vec2 *=0.5;
- Vec2.rotateBy(atan (1.0)*2);
- AcGePoint2d pt0;
- m_pPolyline->getPointAt(0,pt0);
- m_pPolyline->setPointAt(1,pt0+Vec);
- m_pPolyline->setPointAt(2,pt0+Vec+Vec2);
- m_pPolyline->setPointAt(3,pt0+Vec2);
- }
- else
- {
- m_PtJig.z=m_StPt.z;
- AcGeVector2d VecSt=m_BaseLine.direction();
- VecSt.rotateBy(atan (1.0)*2);
- AcGeLine2d LinePer(AcGePoint2d(m_PtJig.x,m_PtJig.y),VecSt);
- AcGePoint2d ptper;
- LinePer.intersectWith(m_BaseLine,ptper);
- AcGeVector2d Vec2_3(m_PtJig.x-ptper.x,m_PtJig.y-ptper.y);
- AcGePoint2d pt0;
- m_pPolyline->getPointAt(0,pt0);
- m_pPolyline->setPointAt(1,ptper);
- m_pPolyline->setPointAt(2,ptper+Vec2_3);
- m_pPolyline->setPointAt(3,pt0+Vec2_3);
- }
- return Adesk::kTrue;
- }
- AcDbEntity* CLyFunJigDirectedRect::entity() const
- {
- return m_pPolyline;
- }
- void CLyFunJigDirectedRect::InitPolyline()
- {
- if (m_pPolyline)
- {
- delete m_pPolyline;
- }
- m_pPolyline=new AcDbPolyline;
- for (unsigned int i=0;i<4;i++)
- {
- m_pPolyline->addVertexAt(i,AcGePoint2d(m_StPt.x,m_StPt.y));
- }
- m_pPolyline->setElevation(m_StPt.z);
- m_pPolyline->setClosed(Adesk::kTrue);
- }
- double CLyFunJigDirectedRect::Hdist( const AcGePoint3d &pt1,const AcGePoint3d &pt2 )
- {
- return sqrt((pt1.x-pt2.x)*(pt1.x-pt2.x)+(pt1.y-pt2.y)*(pt1.y-pt2.y));
- }
|
评分
-
查看全部评分
|