寫AcEdJig類的一點心得

很不幸的,今天被老大訓導了,但也因爲學到不少東西:

AcGePoint3d (AcGePoint2d )轉換 ads_point 用:asDblArray函數。

ads_point 轉換AcGePoint2d  用asPnt2d(const double &pnt) 或aspnt3d

acdbUcs2Wcs(ptAds, asDblArray(m_ptStart) ,false), 是表示在CAD中的轉換成常用座標系WCS 進行轉換

 

使用AcDbPolyline類時,必須用到的函數有:

 

m_pEntity->setNormal(AcGeVector3d::kZAxis);

m_pEntity->setElevation(0.0);

 

 

 

轉換成實體所在平面的點:

先定義平面:AcGePlane plane(AcGePoint3d::kOrigin + m_pEntity->normal() * m_pEntity->elevation(), m_pEntity->normal());

AcGePoint2d pt1(m_ptStart.convert2d(plane)), pt2(m_ptEnd.convert2d(plane));

 

 

 

AcGeVector2d vt1(pt2 - pt1);

vt1.normalize();

AcGeVector2d vt2(vt1);

 

vt2.rotateBy(PI / 2.0);

 

 

向量vt1 與 向量vt2 互相垂直

 

用向量求點更簡單(示例):

 

還有一點是:變量第一個字母用小寫,函數用大寫

 

AcEdJIg的入門用法:

定義一個新類,從AcEdJig中繼函

 

重載AcEdJig三個函數 (必須重載):

AcEdJig::sampler(), which acquires a geometric value (an angle, a distance, or a point),得到一個角度,距離,或點 AcEdJig::update(), which analyzes the geometric value and stores it or updates the entity,更新實體數據 AcEdJig::entity(), which returns a pointer to the entity to be regenerated

 

sampler 函數示例:這裏面儘量不要計算更新的數據

 

 

update函數:計算更新的數據

 

entity ()返回最終的實體指針;

 

再定義一個實現函數 。

AcAxDocLock docLock(acdbHostApplicationServices()->workingDatabase()->blockTableId());

 

其中drag 回調的是sampler (),update函數。

 

注意,應養成一個習慣,在做判斷語句時,應該常量應前,變量在後,這樣,不至於少使比較符而出錯。

如: if (AcEdJig::kNormal == statusDrag)

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章