返回介绍

从符号表中获得信息

发布于 2023-08-09 23:10:33 字数 9435 浏览 0 评论 0 收藏 0

至此,我们就读取到当前模型空间的所有符号表及字典,而对于如何取到具体的信息,我们在此实例的树形结构图的单击事件下进行读取,代码如下:

void CMxDatabaseDlg::OnTvnSelchangedDatabaseinfoTree(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
	*pResult = 0;

	CString strText; // 树节点的标签文本字符串   

					 // 获取当前选中节点的句柄   
	HTREEITEM hItem = m_DatabaseInfo.GetSelectedItem();
	strText = m_DatabaseInfo.GetItemText(hItem);
	GetObjectAndPring(strText);
}

void CMxDatabaseDlg::GetObjectAndPring(const CString sHandle)
{
	//在此处我们得到所需的一些信息
	McDbObjectPointer<McDbObject> spObject;
	{
		McDbObjectId mId;
		McDbHandle mHandle(GetHandleStr(sHandle));
		acdbHostApplicationServices()->workingDatabase()->getAcDbObjectId(mId, false, mHandle);
		spObject.open(mId, McDb::kForRead);
	}

	if (Mcad::eOk == spObject.openStatus())
	{
		CString sTemp;
		CString sType = spObject->isA()->name();
		sTemp.Format(_T("\n类型:%s\t组码名:%s\nID:%d"), spObject->isA()->name(), spObject->isA()->DXF0(), spObject->objectId().asOldId());
		Mx::mcutPrompt(sTemp);
		sTemp.Format(_T("\t句柄:%s"), GetHandleStr(sHandle));
		Mx::mcutPrompt(sTemp);

		//		MrxDbgUtils::putEntityInView(spObject->objectId(), 10);

		//符号表
		if (McDbSymbolTableRecord::cast(spObject))
		{
			auto pDisSymUtilInfo = [&](McDbSymbolTableRecord* pMcDbSymbolTable) {
				CString sName;
				pMcDbSymbolTable->getNameEx(sName);
				sTemp.Format(_T("\n符号记录表名:%s"), sName);
				Mx::mcutPrompt(sTemp);
			};

			const CString sMcDbLayerTableRecord(L"McDbLayerTableRecord");
			const CString sMcDbBlockTableRecord(L"McDbBlockTableRecord");
			const CString sMcDbTextStyleTableRecord(L"McDbTextStyleTableRecord");
			const CString sMcDbLinetypeTableRecord(L"McDbLinetypeTableRecord");
			const CString sMcDbDimStyleTableRecord(L"McDbDimStyleTableRecord");

			if (sMcDbLayerTableRecord == sType)
			{
				auto pEnt = McDbLayerTableRecord::cast(spObject);
				pDisSymUtilInfo(pEnt);
				sTemp.Format(_T("\n锁定状态:%s\t关闭状态:%s\n冻结状态:%s"), pEnt->isLocked() ? L"锁定" : L"未锁定",
					pEnt->isOff() ? L"关闭" : L"未关闭", pEnt->isFrozen() ? L"冻结" : L"未冻结");
				Mx::mcutPrompt(sTemp);
				auto mColor = pEnt->color();
				sTemp.Format(_T("\t颜色索引%d"), mColor.colorIndex());
				Mx::mcutPrompt(sTemp);
			}
			else if (sMcDbTextStyleTableRecord == sType)
			{
				auto pEnt = McDbTextStyleTableRecord::cast(spObject);
				pDisSymUtilInfo(pEnt);
				LPCTSTR lpFileName;
				pEnt->fileName(lpFileName);
				sTemp.Format(_T("\n竖向绘制:%s\t文字高度:%f\t缩放比例:%f\t倾斜弧度%f\t字体文件名:%s"), pEnt->isVertical() ? L"是" : L"否",
					pEnt->textSize(), pEnt->xScale(), pEnt->obliquingAngle(), lpFileName);
				Mx::mcutPrompt(sTemp);
				//...在此处介绍其他的信息
			}
			else if (sMcDbLinetypeTableRecord == sType)
			{
				auto pEnt = McDbLinetypeTableRecord::cast(spObject);
				pDisSymUtilInfo(pEnt);
				CString sCommentsEx;
				pEnt->commentsEx(sCommentsEx);
				sTemp.Format(_T("\n线型说明:%s"), sCommentsEx);
				Mx::mcutPrompt(sTemp);
				//...在此处介绍其他的信息
			}
			else if (sMcDbDimStyleTableRecord == sType)
			{
				auto pEnt = McDbDimStyleTableRecord::cast(spObject);
				pDisSymUtilInfo(pEnt);
				//...在此处介绍其他的信息
			}
			else if (sMcDbBlockTableRecord == sType)
			{
				auto pEnt = McDbBlockTableRecord::cast(spObject);
				pDisSymUtilInfo(pEnt);
				//...在此处介绍其他的信息
			}
			Mx::mcutPrompt(L"\n");
		}
		else if (auto spEnt = McDbEntity::cast(spObject))
		{
			auto pDisText = [&](McGePoint3d vPt, double dRotation, double dHeight, double dWidth, CString sText, CString sStyle) {
				const CString sTextInfoFormat(L"\n文字位置:X = %.3lf Y = %.3lf\n旋转弧度%f\t行高%f\t宽度比例%f\n文字内容:%s\n文字样式%s\n");
				sTemp.Format(sTextInfoFormat, vPt.x, vPt.y, dRotation,
					dHeight, dWidth, sText, sStyle);
				Mx::mcutPrompt(sTemp);
			};

			//基本实体
			sTemp.Format(_T("\n层名:%s\t颜色索引:%d"), spEnt->layer(), spEnt->colorIndex());
			Mx::mcutPrompt(sTemp);

			const CString sMcDbLine(L"McDbLine");
			const CString sMcDbPolyline(L"McDbPolyline");
			const CString sMcDbArc(L"McDbArc");
			const CString sMcDbCircle(L"McDbCircle");
			const CString sMcDbSpline(L"McDbSpline");
			const CString sMcDbEllipse(L"McDbEllipse");
			const CString sMcDbPoint(L"McDbPoint");
			const CString sMcDbBlockReference(L"McDbBlockReference");
			const CString sMcDbAttributeDefinition(L"McDbAttributeDefinition");
			const CString sMcDbText(L"McDbText");
			const CString sMcDbMText(L"McDbMText");
			const CString sMcDbHatch(L"McDbHatch");
			const CString sMcDbDimension(L"McDbDimension");

			if (sMcDbLine == sType)
			{
				auto pEnt = McDbLine::cast(spEnt);
				auto vPt1 = pEnt->startPoint();
				sTemp.Format(_T("\n起始点:X = %.3lf Y = %.3lf"), vPt1.x, vPt1.y);
				Mx::mcutPrompt(sTemp);
				auto vPt2 = pEnt->endPoint();
				sTemp.Format(_T("\n结束点:X = %.3lf Y = %.3lf"), vPt2.x, vPt2.y);
				Mx::mcutPrompt(sTemp);
				sTemp.Format(_T("\n增量:X = %.3lf 增量Y = %.3lf"), vPt2.x - vPt1.x, vPt2.y - vPt1.y);
				Mx::mcutPrompt(sTemp);
			}
			else if (sMcDbPoint == sType)
			{
				auto pEnt = McDbPoint::cast(spEnt);
				auto vPt = pEnt->position();
				sTemp.Format(_T("\n点:X = %.3lf Y = %.3lf"), vPt.x, vPt.y);
				Mx::mcutPrompt(sTemp);
			}
			else if (sMcDbPolyline == sType)
			{
				auto pEnt = McDbPolyline::cast(spEnt);
				sTemp.Format(_T("\n是否闭合%s"), pEnt->isClosed() ? L"闭合" : L"不闭合");
				Mx::mcutPrompt(sTemp);

				McGePoint2d vPt;
				for (UINT i(0); i < pEnt->numVerts(); i++)
				{
					pEnt->getPointAt(i, vPt);
					sTemp.Format(_T("\n点:X = %.3lf Y = %.3lf"), vPt.x, vPt.y);
					Mx::mcutPrompt(sTemp);
				}
			}
			else if (sMcDbText == sType)
			{
				auto pEnt = McDbText::cast(spEnt);
				pDisText(pEnt->position(), pEnt->rotation(), pEnt->height(),
					pEnt->widthFactor(), pEnt->textStringConst(), pEnt->textStyleEx());
			}
			else if (sMcDbMText == sType)
			{
				auto pEnt = McDbMText::cast(spEnt);
				pDisText(pEnt->location(), pEnt->rotation(),
					pEnt->textHeight(), pEnt->width(), pEnt->contents(), pEnt->textStyleEx());
			}
			else if (sMcDbCircle == sType)
			{
				auto pEnt = McDbCircle::cast(spEnt);
				auto vCenter = pEnt->center();
				sTemp.Format(_T("\n圆心:X = %.3lf Y = %.3lf"), vCenter.x, vCenter.y);
				Mx::mcutPrompt(sTemp);
				auto dRadius = pEnt->radius();
				sTemp.Format(_T("\n半径:%f"), dRadius);
				Mx::mcutPrompt(sTemp);
			}
			else if (sMcDbArc == sType)
			{
				auto pEnt = McDbArc::cast(spEnt);
				auto vCenter = pEnt->center();
				sTemp.Format(_T("\n圆心:X = %.3lf Y = %.3lf"), vCenter.x, vCenter.y);
				Mx::mcutPrompt(sTemp);
				auto dRadius = pEnt->radius();
				sTemp.Format(_T("\n半径:%f"), dRadius);
				Mx::mcutPrompt(sTemp);
				auto dstartAngle = pEnt->startAngle();
				sTemp.Format(_T("\n起始角度:%f"), dstartAngle);
				Mx::mcutPrompt(sTemp);
				auto dendAngle = pEnt->endAngle();
				sTemp.Format(_T("\n结束角度:%f"), dendAngle);
				Mx::mcutPrompt(sTemp);
			}
			else if (sMcDbEllipse == sType)
			{
				auto pEnt = McDbEllipse::cast(spEnt); //    
				auto vCenter = pEnt->center();
				sTemp.Format(_T("\n圆心:X = %.3lf Y = %.3lf"), vCenter.x, vCenter.y);
				Mx::mcutPrompt(sTemp);
				auto vMajorAxis = pEnt->majorAxis();
				sTemp.Format(_T("\n主轴向量:%f"), vMajorAxis.x, vMajorAxis.y);
				Mx::mcutPrompt(sTemp);
				auto vMinorAxis = pEnt->minorAxis();
				sTemp.Format(_T("\n副轴向量:%f"), vMinorAxis.x, vMinorAxis.y);
				Mx::mcutPrompt(sTemp);
				sTemp.Format(_T("\n副轴与主轴长度比值:%f"), pEnt->radiusRatio());
				Mx::mcutPrompt(sTemp);
				sTemp.Format(_T("\n开始角度:%f\t结束角度%f"), pEnt->startAngle(), pEnt->endAngle());
				Mx::mcutPrompt(sTemp);
			}
			else if (sMcDbBlockReference == sType)
			{
				auto pEnt = McDbBlockReference::cast(spEnt);
				auto sName = pEnt->appName();
				sTemp.Format(_T("\n块名:%s"), sName);
				Mx::mcutPrompt(sTemp);
				auto vPosition = pEnt->position();
				sTemp.Format(_T("\n插入位置:X = %.3lf Y = %.3lf"), vPosition.x, vPosition.y);
				Mx::mcutPrompt(sTemp);
				auto dScale = pEnt->scaleFactors();
				sTemp.Format(_T("\n缩放比例:%f"), dScale);
				Mx::mcutPrompt(sTemp);
				auto drotationAngle = pEnt->rotation();
				sTemp.Format(_T("\n旋转角度:%f"), drotationAngle);
				Mx::mcutPrompt(sTemp);
			}
			else if (sMcDbDimension == sType)
			{
				//标注类型
			}
			Mx::mcutPrompt(L"\n");
		}
		else
		{
			Mx::mcutPrompt(L"未说明的类型\n");
			Mx::mcutPrompt(L"\n");
		}
	}
}

对于获取实体信息,重点在于获取它的句柄或ID,我们可用通过选择及或构造选择集的方式去过滤,也可以使用与用户交互的方式去选择需要的实体,而获取ID之后,我们使用以下的方式去打开,即可获取它的全部相关信息,如得到它的类型、DXF组码名:

McDbObjectPointer<McDbObject> spObject;
{
    //...
    spObject.open(mId, McDb::kForRead);
}
  
if (Mcad::eOk == spObject.openStatus())
{
    CString sTemp;
    CString sType = spObject->isA()->name();
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文