



jigcpp主要修改





附上jigcpp文件
// (C) Copyright 2005-2007 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
//-----------------------------------------------------------------------------
#include "StdAfx.h"
#include "MyLineJig.h"
//-----------------------------------------------------------------------------
CMyLineJig::CMyLineJig () : AcEdJig (),
mCurrentInputLevel(0), mpEntity(NULL)
{
}
CMyLineJig::~CMyLineJig () {
}
//-----------------------------------------------------------------------------
AcEdJig::DragStatus CMyLineJig::startJig (AcDbLine *pEntity) {
//- Store the new entity pointer
// 將jig復制給成員變量,接管實體指針
mpEntity =pEntity ;
//- Setup each input prompt
// 定義JIG選擇點的時候的提示字符數組
AcString inputPrompts [2] ={
"\nPick point",
"\nPick point"
} ;
//- Setup kwords for each input
// 定義JIG的關鍵字數組
AcString kwords [2] ={
"",
""
} ;
// 設置添加標志,如果JIG完成會添加實體到當前圖形數據庫
bool appendOk =true ;
AcEdJig::DragStatus status =AcEdJig::kNull ;
//- Loop the number of inputs
// 開始循環JIG,這里循環2次
for ( mCurrentInputLevel =0 ; mCurrentInputLevel < 2 ; mCurrentInputLevel++ ) {
//- Add a new input point to the list of input points
// 初始化輸入點數組
mInputPoints.append (AcGePoint3d ()) ;
//- Set the input prompt
// 設置JIG提示字符
setDispPrompt (inputPrompts [mCurrentInputLevel]) ;
//- Setup the keywords required
// 設置關鍵字
setKeywordList (kwords [mCurrentInputLevel]) ;
// 設置循環退出標志為false
bool quit =false ;
//- Lets now do the input
// drag開始拖動,會執行sampler采樣函數,根據采樣返回值判斷處理方式
// 采樣后會執行update更新采樣后的點.可以實現圖形坐標點變化
status =drag () ;
if ( status != kNormal ) {
//- If it's a keyword
switch ( status ) {
case kCancel:
case kNull:
quit =true ;
break ;
case kKW1:
case kKW2:
case kKW3:
case kKW4:
case kKW5:
case kKW6:
case kKW7:
case kKW8:
case kKW9:
//- Do something
break ;
}
} else {
//如果返回的是kNormal,表示可以添加實體,設置標志.
appendOk =true ;
}
//- If to finish
if ( quit )
break ;
}
//循環結束
//- If the input went well
// 如果appendOk為true,就執行添加對象到數據庫
if ( appendOk )
//- Append to the database
// 直接添加對象到當前圖形數據庫
append () ;
else
//- Clean up
//如果JIG不成功,則刪除實體
delete mpEntity ;
//最后返回拖動狀態碼
return (status) ;
}
//-----------------------------------------------------------------------------
//- Input sampler
AcEdJig::DragStatus CMyLineJig::sampler () {
//- Setup the user input controls for each input
// 用戶輸入控制數組,一般無需設置,具體的可以去看相關文檔
AcEdJig::UserInputControls userInputControls [2] ={
/*AcEdJig::UserInputControls::*/(AcEdJig::UserInputControls)0,
/*AcEdJig::UserInputControls::*/(AcEdJig::UserInputControls)0
} ;
//- Setup the cursor type for each input
// 光標狀態數組,控制光標顯示效果
AcEdJig::CursorType cursorType [2] ={
/*AcEdJig::CursorType::*/(AcEdJig::CursorType)0,
/*AcEdJig::CursorType::*/(AcEdJig::CursorType)0
} ;
//- Setup the user input controls for each sample
//設置輸入控制和光標狀態
setUserInputControls (userInputControls [mCurrentInputLevel]) ;
setSpecialCursorType (cursorType [mCurrentInputLevel]) ;
AcEdJig::DragStatus status =AcEdJig::kCancel ;
//- Check the current input number to see which input to do
switch ( mCurrentInputLevel+1 ) {
case 1:
// TODO : get an input here
//開始第一點
status =GetStartPoint () ;
break ;
case 2:
// TODO : get an input here
//開始第二點
status =GetNextPoint () ;
break ;
default:
break ;
}
return (status) ;
}
//-----------------------------------------------------------------------------
//- Jigged entity update
Adesk::Boolean CMyLineJig::update () {
//- Check the current input number to see which update to do
switch ( mCurrentInputLevel+1 ) {
case 1:
// TODO : update your entity for this input
//mpEntity->setCenter (mInputPoints [mCurrentInputLevel]) ;
// mCurrentInputLevel=1 開始更新實體的狀態,
// 這里需要更新起點和終點,如果只更新起點,會和默認的終點0,0形成一條直線,不符合JIG的直觀感覺
// 更新起點和終就形成長度為0的直線,感覺是一個點.
mpEntity->setStartPoint(mInputPoints[mCurrentInputLevel]);
mpEntity->setEndPoint(mInputPoints[mCurrentInputLevel]);
break ;
case 2:
// TODO : update your entity for this input
// mCurrentInputLevel=2 這里更新終點
// mpEntity->setCenter (mInputPoints [mCurrentInputLevel]) ;
mpEntity->setEndPoint(mInputPoints[mCurrentInputLevel]);
break ;
default:
break ;
}
return (updateDimData ()) ;
}
//-----------------------------------------------------------------------------
//- Jigged entity pointer return
AcDbEntity *CMyLineJig::entity () const {
return ((AcDbEntity *)mpEntity) ;
}
//-----------------------------------------------------------------------------
//- Dynamic dimension data setup
AcDbDimDataPtrArray *CMyLineJig::dimData (const double dimScale) {
/* SAMPLE CODE:
AcDbAlignedDimension *dim =new AcDbAlignedDimension () ;
dim->setDatabaseDefaults () ;
dim->setNormal (AcGeVector3d::kZAxis) ;
dim->setElevation (0.0) ;
dim->setHorizontalRotation (0.0) ;
dim->setXLine1Point (m_originPoint) ;
dim->setXLine2Point (m_lastPoint) ;
//- Get the dimPoint, first the midpoint
AcGePoint3d dimPoint =m_originPoint + ((m_lastPoint - m_originPoint) / 2.0) ;
//- Then the offset
dim->setDimLinePoint (dimPoint) ;
dim->setDimtad (1) ;
AcDbDimData *dimData = new AcDbDimData (dim) ;
//AppData *appData =new AppData (1, dimScale) ;
//dimData.setAppData (appData) ;
dimData->setDimFocal (true) ;
dimData->setDimHideIfValueIsZero (true) ;
//- Check to see if it is required
if ( getDynDimensionRequired (m_inputNumber) )
dimData->setDimInvisible (false) ;
else
dimData->setDimInvisible (true) ;
//- Make sure it is editable TODO:
dimData->setDimEditable (true) ;
mDimData.append (dimData) ;
return (&mDimData) ;
*/
return (NULL) ;
}
//-----------------------------------------------------------------------------
//- Dynamic dimension data update
Acad::ErrorStatus CMyLineJig::setDimValue (const AcDbDimData *pDimData, const double dimValue) {
Acad::ErrorStatus es =Acad::eOk ;
/* SAMPLE CODE:
//- Convert the const pointer to non const
AcDbDimData *dimDataNC =const_cast<AcDbDimData *>(pDimData) ;
int inputNumber =-1 ;
//- Find the dim data being passed so we can determine the input number
if ( mDimData.find (dimDataNC, inputNumber) ) {
//- Now get the dimension
AcDbDimension *pDim =(AcDbDimension *)dimDataNC->dimension () ;
//- Check it's the type of dimension we want
AcDbAlignedDimension *pAlnDim =AcDbAlignedDimension::cast (pDim) ;
//- If ok
if ( pAlnDim ) {
//- Extract the dimensions as they are now
AcGePoint3d dimStart =pAlnDim->xLine1Point () ;
AcGePoint3d dimEnd =pAlnDim->xLine2Point () ;
//- Lets get the new point entered by the user
AcGePoint3d dimEndNew =dimStart + (dimEnd - dimStart).normalize () * dimValue ;
//- Finally set the end dim point
pAlnDim->setXLine2Point (dimEndNew) ;
//- Now update the jig data to reflect the dynamic dimension input
mInputPoints [mCurrentInputLevel] =dimEndNew ;
}
}*/
return (es) ;
}
//-----------------------------------------------------------------------------
//- Various helper functions
//- Dynamic dimdata update function
Adesk::Boolean CMyLineJig::updateDimData () {
//- Check the dim data store for validity
if ( mDimData.length () <= 0 )
return (true) ;
/* SAMPLE CODE :
//- Extract the individual dimData
AcDbDimData *dimData =mDimData [m_inputNumber] ;
//- Now get the dimension
AcDbDimension *pDim =(AcDbDimension *)dimData->dimension () ;
//- Check it's the type of dimension we want
AcDbAlignedDimension *pAlnDim =AcDbAlignedDimension::cast (pDim) ;
//- If ok
if ( pAlnDim ) {
//- Check to see if it is required
if ( getDynDimensionRequired (m_inputNumber) )
dimData->setDimInvisible (false) ;
else
dimData->setDimInvisible (true) ;
pAlnDim->setXLine1Point (m_originPoint) ;
pAlnDim->setXLine2Point (m_lastPoint) ;
//- Get the dimPoint, first the midpoint
AcGePoint3d dimPoint =m_originPoint + ((m_lastPoint - m_originPoint) / 2.0) ;
//- Then the offset
pAlnDim->setDimLinePoint (dimPoint) ;
} */
return (true) ;
}
//-----------------------------------------------------------------------------
//- Std input to get a point with no rubber band
AcEdJig::DragStatus CMyLineJig::GetStartPoint () {
AcGePoint3d newPnt ;
//- Get the point
AcEdJig::DragStatus status =acquirePoint (newPnt) ;
//- If valid input
if ( status == AcEdJig::kNormal ) {
//- If there is no difference
if ( newPnt.isEqualTo (mInputPoints [mCurrentInputLevel]) )
return (AcEdJig::kNoChange) ;
//- Otherwise update the point
mInputPoints [mCurrentInputLevel] =newPnt ;
}
return (status) ;
}
//-----------------------------------------------------------------------------
//- Std input to get a point with rubber band from point
AcEdJig::DragStatus CMyLineJig::GetNextPoint () {
// 這里的向導算是有點問題,我們需要實現JIG的正交效果,而mCurrentInputLevel在執行到這里的時候
// mCurrentInputLevel已經是第二個的索引值了,我們需要的是上一個點的索引值修改為-1
// 否則oldPnt是第二點,不會出現正交的效果,
//AcGePoint3d oldPnt =mInputPoints [mCurrentInputLevel] ;
AcGePoint3d oldPnt = mInputPoints[mCurrentInputLevel-1];
AcGePoint3d newPnt ;
//- Get the point
AcEdJig::DragStatus status =acquirePoint (newPnt, oldPnt) ;
//- If valid input
if ( status == AcEdJig::kNormal ) {
//- If there is no difference
if ( newPnt.isEqualTo (mInputPoints [mCurrentInputLevel]) )
return (AcEdJig::kNoChange) ;
//- Otherwise update the point
mInputPoints [mCurrentInputLevel] =newPnt ;
}
return (status) ;
}
調用代碼


JIG正交效果

