zoukankan      html  css  js  c++  java
  • ObjectARX JIG简单示意,实现正交例子

     

     

     

    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] ={
    		"
    Pick point",
    		"
    Pick 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正交效果

  • 相关阅读:
    动态规划之解决01背包问题 【转载】
    暴力搜索解0-1背包问题 【转载】
    回溯法之地图着色
    贪心算法之最小生成树
    贪心算法之最短路径
    HMM隐马尔科夫模型
    变分贝叶斯
    Leetcode好的微博
    HMM隐马尔科夫模型浅析
    向量的协方差矩阵浅析
  • 原文地址:https://www.cnblogs.com/edata/p/12865630.html
Copyright © 2011-2022 走看看