码迷,mamicode.com
首页 > 其他好文 > 详细

创建多段线

时间:2015-08-31 09:57:52      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:

1、创建一个工具类CTool。

Tool.h:

 

static ads_real GetWidth();
static int GetColorIndex();


Tool.cpp

 

 

ads_real CTool::GetWidth()
{
	ads_real width = 0;
	if(acedGetReal(_T("\n输入线宽:"), &width)==RTNORM)
	{
		return width;
	}
	else
	{
		return 0;
	}
}

int CTool::GetColorIndex()
{
	int colorIndex = 0;
	if(acedGetInt(_T("输入颜色索引值(0~256):"), &colorIndex) != RTNORM)
	{
		return 0;
	}

	while(colorIndex < 0 || colorIndex >256)
	{
		acedPrompt(_T("输入了错误的颜色索引值!"));
		if(acedGetInt(_T("输入颜色索引值(0~256)"), &colorIndex) != RTNORM)
		{
			return 0;
		}
	}

	return colorIndex;
}


2、添加命令AddPoly

 

实现代码如下:

 

static void qxzyAddPolyDynamicCommands_AddPoly(void)
	{
		// Add your code for command qxzyAddPolyDynamicCommands._AddPoly here
		int colorIndex = 0;
		ads_real width = 0;


		int index = 2;
		ads_point ptStart;

		if(acedGetPoint(NULL, _T("\n输入第一点:"), ptStart) != RTNORM)
			return;
		ads_point ptPrevious,ptCurrent;
		acdbPointSet(ptStart, ptPrevious);
		AcDbObjectId polyId;

		acedInitGet(NULL, _T("W C O"));
		int rc = acedGetPoint(ptPrevious,
			_T("\n输入下一点[宽度(W)/颜色(C)]<完成(O)>"), ptCurrent);
		while(rc == RTNORM || rc == RTKWORD)
		{
			if(rc == RTKWORD)
			{
				ACHAR kword[20];
				if(acedGetInput(kword)!=RTNORM)
					return;
				if(strcmp((LPSTR)(LPCTSTR)kword,"W")==0)
				{
					width = CTool::GetWidth();
				}
				else if(strcmp((LPSTR)(LPCTSTR)kword,"C")==0)
				{
					colorIndex = CTool::GetColorIndex();
				}
				else if(strcmp((LPSTR)(LPCTSTR)kword, "O")==0)
				{
					return;
				}
				else
				{
					acutPrintf(_T("\n无效的关键字"));
				}
			}
			else if(rc == RTNORM)
			{
				if(index == 2)
				{
					AcDbPolyline *pPoly= new AcDbPolyline(2);
					AcGePoint2d ptGe1,ptGe2;
					ptGe1[X]=ptPrevious[X];
					ptGe1[Y]=ptPrevious[Y];
					ptGe2[X]=ptCurrent[X];
					ptGe2[Y]=ptCurrent[Y];
					pPoly->addVertexAt(0, ptGe1);
					pPoly->addVertexAt(1, ptGe2);

					pPoly->setConstantWidth(width);
					pPoly->setColorIndex(colorIndex);

					AcDbBlockTable *pBlkTbl;
					acdbHostApplicationServices()->workingDatabase()
						->getSymbolTable(pBlkTbl, AcDb::kForRead);

					AcDbBlockTableRecord *pBlkTblRcd;
					pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd, AcDb::kForWrite);

					pBlkTblRcd->appendAcDbEntity(polyId, pPoly);

					pBlkTblRcd->close();
					pBlkTbl->close();
					pPoly->close();

				}
				else if(index>2)
				{
					AcDbPolyline *pPoly;
					acdbOpenObject(pPoly, polyId, AcDb::kForWrite);

					AcGePoint2d ptGe;
					ptGe[X]=ptCurrent[X];
					ptGe[Y]=ptCurrent[Y];

					pPoly->addVertexAt(index-1,ptGe);
					pPoly->setConstantWidth(width);
					pPoly->setColorIndex(colorIndex);

					pPoly->close();
				}
				index++;

				acdbPointSet(ptCurrent,ptPrevious);
			}

			acedInitGet(NULL, _T("W C O"));
			rc = acedGetPoint(ptPrevious,
				_T("\n输入下一点[宽度(W)/颜色(C)]<完成(O)>"), ptCurrent);
		}


	}

创建多段线

标签:

原文地址:http://www.cnblogs.com/xzh1993/p/4772295.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!