예제 #1
0
void
makeABlock()
{
     // Create and name a new block table record.
     //
     AcDbBlockTableRecord *pBlockTableRec
         = new AcDbBlockTableRecord();
     pBlockTableRec->setName("ASDK-NO-ATTR");

     // Get the block table.
     //
     AcDbBlockTable *pBlockTable = NULL;
     acdbHostApplicationServices()->workingDatabase()
        ->getSymbolTable(pBlockTable, AcDb::kForWrite);

     // Add the new block table record to the block table.
     //
     AcDbObjectId blockTableRecordId;
     pBlockTable->add(blockTableRecordId, pBlockTableRec);
     pBlockTable->close();

     // Create and add a line entity to the component's
     // block record.
     //
     AcDbLine *pLine = new AcDbLine();
     AcDbObjectId lineId;

     pLine->setStartPoint(AcGePoint3d(3, 3, 0));
     pLine->setEndPoint(AcGePoint3d(6, 6, 0));
     pLine->setColorIndex(3);

     pBlockTableRec->appendAcDbEntity(lineId, pLine);
     pLine->close();
     pBlockTableRec->close();
}
예제 #2
0
void CMyDlg::UpdateListCtr()
{
	acDocManager->lockDocument(curDoc());
	int nCount = m_ListCtr.GetItemCount();
	acutPrintf("%d\n", nCount);
	long lId;
	CString str;
	AcDbObjectId LineId;
	AcDbEntity *pEnt = NULL;
	AcDbLine *pLine = NULL;
	Acad::ErrorStatus es;
	
	if (nCount > 0)
	{
			for (int i = 0; i < nCount; ++i)
			{
				str = m_ListCtr.GetItemText(i, 0);
				lId = atol(str);
				LineId.setFromOldId(lId);
				//获得指针
				es = acdbOpenAcDbEntity(pEnt, LineId, AcDb::kForWrite);

				//检查是否被删除
				pLine = AcDbLine::cast(pEnt);
				if (es == Acad::eWasErased)
				{
					m_ListCtr.DeleteItem(i);
					--m_lLineCnt;
					--i;
					--m_Row;
				} 
				//检查颜色
				else if (es == Acad::eOk)
				{
					if (pLine)
					{
						str = m_ListCtr.GetItemText(i, 1);
						Adesk::UInt16 usColor = (Adesk::UInt16)atoi(str);
						if (pLine->colorIndex() != usColor)
						{
							char *buf = (char*)malloc(20);
							itoa((int)pLine->colorIndex(), buf, 10);
							m_ListCtr.SetItemText(i, 1, buf);
							free(buf);
						}
						pLine->close();
					}
				}						
			}
	}
	
	UpdateData(FALSE);
	acDocManager->unlockDocument(curDoc());
}
void createBlock()
{
	AcDbBlockTableRecord* pBTR = new AcDbBlockTableRecord();
	pBTR->setName(DYNBLKSAMP_BLOCKNAME);
	AcDbSymbolTable* pBT = NULL;
	acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBT, AcDb::kForWrite);
	pBT->add(pBTR);
	pBT->close();	
	
	
	AcGePoint3d pt1(0.0, 0.0, 0.0);
	AcGePoint3d pt2(2.0, 0.0, 0.0);
	AcDbLine* pLine = new AcDbLine(pt1, pt2);
	pBTR->appendAcDbEntity(pLine);
	pLine->close();

	pt1 = pt2;
	pt2.y = 2.0;
	pLine = new AcDbLine(pt1, pt2);
	pBTR->appendAcDbEntity(pLine);
	pLine->close();

	pt1 = pt2;
	pt2.x = 0.0;
	pLine = new AcDbLine(pt1, pt2);
	pBTR->appendAcDbEntity(pLine);
	pLine->close();

	pt1 = pt2;
	pt2.y = 0.0;
	pLine = new AcDbLine(pt1, pt2);
	pBTR->appendAcDbEntity(pLine);
	pLine->close();
	
	pBTR->close();
}
예제 #4
0
AcDbObjectId Additional_Class::Draw_Line(AcGePoint3d stPoint, AcGePoint3d enPoint)
{
	AcDbLine *pLineTemp = new AcDbLine();
	pLineTemp->setStartPoint(stPoint);
	pLineTemp->setEndPoint(enPoint);
	AcDbBlockTable *pBlockTable = NULL;
	acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable, AcDb::kForRead);
	//this->Open_BlockTable(pBlockTable, NREADMODE);
	AcDbBlockTableRecord *pBlockTableRecord = NULL;
	pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite);
	//acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable, AcDb::kForRead);
	//this->Open_ModelTableRecord(pBlockTableRecord, pBlockTable, NWRITEMODE);
	AcDbObjectId TempLineID;
	pBlockTableRecord->appendAcDbEntity(TempLineID, pLineTemp);
	pLineTemp->close();
	pBlockTable->close();
	pBlockTableRecord->close();
	return TempLineID;
}
예제 #5
0
void Additional_Class::Change_Line(AcDbObjectId LineID, AcGePoint3d ptStart, AcGePoint3d ptEnd )
{
	AcDbEntity *pEnt_Temp;
	if (acdbOpenAcDbEntity(pEnt_Temp, LineID, AcDb::kForWrite)!= Acad::eOk)
	{
		acutPrintf(_T("\nOPEN ENETITY ERROR"));
		return;
	}
	if (!pEnt_Temp->isKindOf(AcDbLine::desc()))
	{
		acutPrintf(_T("\nENTITY IS NOT LINE"));
		return;
	}
	AcDbLine *pLineChange;
	pLineChange = AcDbLine::cast(pEnt_Temp);
	AcGePoint3d pLineE;
	pLineChange->setStartPoint(ptStart);
	pLineChange->setEndPoint(ptEnd);
	pEnt_Temp->close();
	pLineChange->close();
	return;
}
예제 #6
0
void CMyDlg::OnDelLine() 
{
	// TODO: Add your control notification handler code here
	int nItem;
	long lId;
	CString str;
	AcDbObjectId LineId;
	AcDbEntity *pEnt = NULL;
	AcDbLine *pLine = NULL;
	Acad::ErrorStatus es;

	acDocManager->lockDocument(curDoc());
	//在列表中删除选定行
	while(m_ListCtr.GetNextItem(-1, (LVNI_ALL | LVNI_SELECTED)) != -1)
	{
		nItem = m_ListCtr.GetNextItem(-1, (LVNI_ALL | LVNI_SELECTED));
		str = m_ListCtr.GetItemText(nItem, 0);
		//acutPrintf("%s\n", str);
		lId = atol(str);
		LineId.setFromOldId(lId);
		//获得指针
		es = acdbOpenAcDbEntity(pEnt, LineId, AcDb::kForWrite);
		//在模型空间删除相应实体
		pLine = AcDbLine::cast(pEnt);
		if (pLine)
		{
			pLine->erase();
			pLine->close();
			m_ListCtr.DeleteItem(nItem);
			--m_Row;
		}	
	}
	UpdateData(FALSE);
	
	acDocManager->unlockDocument(curDoc());	
}
예제 #7
0
void CMyDlg::OnCreateLine() 
{	
	// TODO: Add your control notification handler code here
	acDocManager->lockDocument(curDoc());

	int i;
	int m, n;

	char *buf = (char*)malloc(20);
	
	AcDbObjectId LineId;
	AcDbLine *pLine = NULL;
	//块表
	AcDbBlockTable *pTb = NULL;
	//块表记录
	AcDbBlockTableRecord *pTbr = NULL;
	//层表
	AcDbLayerTable *pLyr = NULL;
	//层表记录
	AcDbLayerTableRecord* pLyrr = NULL;
	//图形数据库
	AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase();
	
	Acad::ErrorStatus es;
	
	CListCtrl *pListCtr = (CListCtrl *)GetDlgItem( IDC_LIST1 );
	
	//设置随机数种子
	srand(time(NULL));
	
	//更新数据
	UpdateData(TRUE);

	m_VecSize += m_Edit5;
	m_xVec.resize(m_VecSize);
	m_yVec.resize(m_VecSize);

	//acutPrintf("%d\n", m_Edit1);
	
	es = pDb->getLayerTable(pLyr, AcDb::kForWrite);	//以写的方式打开层表
	es = pDb->getBlockTable(pTb, AcDb::kForRead);	//以读的方式打开块表
	es = pTb->getAt(ACDB_MODEL_SPACE, pTbr, AcDb::kForWrite);//以写的方式打开块表记录
	
	//创建图层GalLineTest
	if (!pLyr->has("GalLineTest"))
	{
		pLyrr = new AcDbLayerTableRecord;	//创建层记录
		pLyrr->setName("GalLineTest");		//设置名字
		//pLyrr->setColor(color);			//设置颜色
		//pLyrr->setLineWeight(lnWt);		//设置线宽
		
		if (Acad::eOk != pLyr->add(pLyrr))	//添加该层记录到层表
		{
			//添加失败
			delete pLyrr;		//释放内存
			pLyr->close();		//关闭层表
		}
		//关闭层表记录
		pLyrr->close();
	}
	//关闭层表
	pLyr->close();
	
	//生成点坐标
	for (i = 0; i < m_Edit5; ++i)
	{
		if ((m_Edit2 != 0) && (m_Edit4 != 0))
		{
			m_xVec[i] = rand() % m_Edit2 + m_Edit1;
			m_yVec[i] = rand() % m_Edit4 + m_Edit3;
		}
		else
		{
			m_xVec[i] = 0;
			m_yVec[i] = 0;
		}
	}
	
	//遍历点坐标
	for (m = 0; m < m_Edit5; ++m)
	{
		for (n = (m+1); n < m_Edit5; ++n)
		{
			if ((m_xVec[m] != m_xVec[n]) && (m_yVec[m] != m_yVec[n]))
			{
				AcGePoint3d ptStart(m_xVec[m], m_yVec[m], 0);
				AcGePoint3d ptEnd(m_xVec[n], m_yVec[n], 0);
				pLine = new AcDbLine(ptStart, ptEnd);
				//pLine->setColor();
				pLine->setLayer("GalLineTest");
				//创建线段
				es = pTbr->appendAcDbEntity(LineId, pLine);
				if (Acad::eOk == es)
				{
					++m_lLineCnt;
				}
				//acutPrintf("%d\n", LineId);
				sprintf(buf, "%d", LineId);			
				m_ListCtr.InsertItem(m_Row, buf);
				
				buf = itoa(pLine->colorIndex(), buf, 10);
				m_ListCtr.SetItemText(m_Row, 1, buf);
				
				buf = itoa(LineLength(m_xVec[m], m_yVec[m],
									m_xVec[n], m_yVec[n]), buf, 10);
				m_ListCtr.SetItemText(m_Row, 2, buf);
				
				++m_Row;
				pLine->close();	//关闭实体
			}
		}
	}
	pTbr->close();	//关闭块表记录
	pTb->close();	//关闭块表

	acDocManager->unlockDocument(curDoc());
	free(buf);
}