当前位置: 代码迷 >> 综合 >> ObjectARX JIG简单示意,实现正交例子
  详细解决方案

ObjectARX JIG简单示意,实现正交例子

热度:44   发布时间:2023-12-23 22:23:30.0

 

 

 

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]) ;// 设置循环退出标志为falsebool quit =false ;//- Lets now do the input// drag开始拖动,会执行sampler采样函数,根据采样返回值判断处理方式// 采样后会执行update更新采样后的点.可以实现图形坐标点变化status =drag () ;if ( status != kNormal ) {//- If it's a keywordswitch ( 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 somethingbreak ;}} else {//如果返回的是kNormal,表示可以添加实体,设置标志.appendOk =true ;}//- If to finishif ( 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 doswitch ( 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 doswitch ( 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 midpointAcGePoint3d dimPoint =m_originPoint + ((m_lastPoint - m_originPoint) / 2.0) ;//- Then the offsetdim->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 requiredif ( getDynDimensionRequired (m_inputNumber) )dimData->setDimInvisible (false) ;elsedimData->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 constAcDbDimData *dimDataNC =const_cast<AcDbDimData *>(pDimData) ;int inputNumber =-1 ;//- Find the dim data being passed so we can determine the input numberif ( mDimData.find (dimDataNC, inputNumber) ) {//- Now get the dimensionAcDbDimension *pDim =(AcDbDimension *)dimDataNC->dimension () ;//- Check it's the type of dimension we wantAcDbAlignedDimension *pAlnDim =AcDbAlignedDimension::cast (pDim) ;//- If okif ( pAlnDim ) {//- Extract the dimensions as they are nowAcGePoint3d 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 pointpAlnDim->setXLine2Point (dimEndNew) ;//- Now update the jig data to reflect the dynamic dimension inputmInputPoints [mCurrentInputLevel] =dimEndNew ;}}*/return (es) ;
}//-----------------------------------------------------------------------------
//- Various helper functions
//- Dynamic dimdata update function
Adesk::Boolean CMyLineJig::updateDimData () {//- Check the dim data store for validityif ( mDimData.length () <= 0 )return (true) ;/* SAMPLE CODE ://- Extract the individual dimDataAcDbDimData *dimData =mDimData [m_inputNumber] ;//- Now get the dimensionAcDbDimension *pDim =(AcDbDimension *)dimData->dimension () ;//- Check it's the type of dimension we wantAcDbAlignedDimension *pAlnDim =AcDbAlignedDimension::cast (pDim) ;//- If okif ( pAlnDim ) {//- Check to see if it is requiredif ( getDynDimensionRequired (m_inputNumber) )dimData->setDimInvisible (false) ;elsedimData->setDimInvisible (true) ;pAlnDim->setXLine1Point (m_originPoint) ;pAlnDim->setXLine2Point (m_lastPoint) ;//- Get the dimPoint, first the midpointAcGePoint3d dimPoint =m_originPoint + ((m_lastPoint - m_originPoint) / 2.0) ;//- Then the offsetpAlnDim->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 inputif ( status == AcEdJig::kNormal ) {//- If there is no differenceif ( newPnt.isEqualTo (mInputPoints [mCurrentInputLevel]) )return (AcEdJig::kNoChange) ;//- Otherwise update the pointmInputPoints [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 inputif ( status == AcEdJig::kNormal ) {//- If there is no differenceif ( newPnt.isEqualTo (mInputPoints [mCurrentInputLevel]) )return (AcEdJig::kNoChange) ;//- Otherwise update the pointmInputPoints [mCurrentInputLevel] =newPnt ;}return (status) ;
} 
 

调用代码

 

JIG正交效果