CAD ObjectARX扩展工具的源码(三)

2024-02-29 06:48

本文主要是介绍CAD ObjectARX扩展工具的源码(三),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

CAD ObjectARX扩展工具的源码(三)
//得到文本边界
oid CDrawFunction::getTextBoundary(AcDbObjectId objectId,double offset,AcDbObjectId &textBoundaryId)
{
AcDbExtents Ext;
AcDbEntity *pEnt;
acdbOpenObject(pEnt,objectId,AcDb::kForWrite);
if(pEnt->isKindOf(AcDbText::desc()))
{
AcDbText *pText=AcDbText::cast(pEnt);
AcGePoint3d basePoint;
basePoint=pText->position();
double rotateAngle=pText->rotation();
pText->setRotation(0);
pText->getGeomExtents(Ext);
AcGePoint3d minPt,maxPt;
minPt=Ext.minPoint();
maxPt=Ext.maxPoint();
AcGePoint3dArray pointArray;
AcGePoint3d point1,point2,point3,point4;
point1.x=minPt.x-offset;point1.y=minPt.y-offset;point1.z=0;
pointArray.append(point1);
point2.x=maxPt.x+offset;point2.y=minPt.y-offset;point2.z=0;
pointArray.append(point2);
point3.x=maxPt.x+offset;point3.y=maxPt.y+offset;point3.z=0;
pointArray.append(point3);
point4.x=minPt.x-offset;point4.y=maxPt.y+offset;point4.z=0;
pointArray.append(point4);
DrawPolyline(textBoundaryId,pointArray,1,0,TRUE,"0","CONTINUOUS");
AcGeMatrix3d matrix;
AcGeector3d axis;
ident_init(matrix);
axis.set(0,0,1);
matrix=matrix.rotation(rotateAngle,axis,basePoint); //旋转矩阵
AcDbEntity *BounEnt;
acdbOpenObject(BounEnt,textBoundaryId,AcDb::kForWrite);
BounEnt->transformBy(matrix);
BounEnt->close();
pText->setRotation(rotateAngle);
}
else if(pEnt->isKindOf(AcDbMText::desc()))
{
AcDbMText *pMtext=AcDbMText::cast(pEnt);
AcGePoint3d basePoint;
basePoint=pMtext->location();
double rotateAngle=pMtext->rotation();
pMtext->setRotation(0);
AcGePoint3dArray pointArray;
double width=pMtext->actualWidth();
double height=pMtext->actualHeight();
AcGePoint3d point1,point2,point3,point4;
point1.x=basePoint.x-offset;point1.y=basePoint.y+offset;point1.z=0;
pointArray.append(point1);
point2.x=basePoint.x+width+offset;point2.y=basePoint.y+offset;point2.z=0;
pointArray.append(point2);
point3.x=basePoint.x+width+offset;point3.y=basePoint.y-height-offset;point3.z=0;
pointArray.append(point3);
point4.x=basePoint.x-offset;point4.y=basePoint.y-height-offset;point4.z=0;
pointArray.append(point4);
DrawPolyline(textBoundaryId,pointArray,1,0,TRUE,"0","CONTINUOUS");
AcGeMatrix3d matrix;
AcGeector3d axis;
ident_init(matrix);
axis.set(0,0,1);
matrix=matrix.rotation(rotateAngle,axis,basePoint); //旋转矩阵
AcDbEntity *BounEnt;
acdbOpenObject(BounEnt,textBoundaryId,AcDb::kForWrite);
BounEnt->transformBy(matrix);
BounEnt->close();
pMtext->setRotation(rotateAngle);
}
pEnt->close();
return;
}


AcDbObjectId CDrawFunction::createNewLayer(CString LayerName)
{
AcDbLayerTable *LayerTable;
acdbHostApplicationSerices()->workingDatabase()->getSymbolTable(LayerTable,AcDb::kForWrite);
AcDbObjectId LayerId;
if(!LayerTable->has(LayerName))
{
AcDbLayerTableRecord *LayerTableRecord=new AcDbLayerTableRecord;
LayerTableRecord->setName(LayerName);
LayerTable->add(LayerId,LayerTableRecord);
LayerTableRecord->close();
}
else
{
LayerTable->getAt(LayerName,LayerId,FALSE);
}
LayerTable->close();
return LayerId;
}

bool CDrawFunction::insertBlock(AcDbObjectId &newEntId,CString BlockName,double fwj,AcGePoint3d basePoint,double scalex,
CString Text1,CString Text2,CString Text3,
int text1color,int text2color,int text3color,
double text1height,double text2height,double text3height,
double text1scator,double text2scator,double text3scator,
CString littleFont,CString bigFont,CString layerName,double dx,double dy) //每块可有三个属性定义
{
AcDbObjectId blockId;
double x,y;
x=basePoint[X];
y=basePoint[Y];
bool a=AcDbSymbolUtilities::hasBlock(BlockName.GetBuffer(BlockName.GetLength()),acdbHostApplicationSerices()->workingDatabase());
if(!a)return FALSE;
AcDbSymbolUtilities::getBlockId(blockId,BlockName.GetBuffer(BlockName.GetLength()),acdbHostApplicationSerices()->workingDatabase());
AcDbBlockReference *pBlkRef = new AcDbBlockReference;
// pBlkRef->treatAsAcDbBlockRefForExplode();///
pBlkRef->setBlockTableRecord(blockId);
pBlkRef->setLayer(layerName);//设置层/
struct resbuf to, from;
from.restype = RTSHORT;
from.resal.rint = 1; // UCS
to.restype = RTSHORT;
to.resal.rint = 0; // WCS
AcGeector3d normal(0, 0, 1);
acedTrans(&(normal.x), &from, &to, Adesk::kTrue,&(normal.x));
AcGeScale3d scale(scalex,scalex,scalex);
pBlkRef->setScaleFactors(scale);
AcGePoint3d insertPoint;
insertPoint=basePoint;
pBlkRef->setPosition(basePoint);
pBlkRef->setRotation(fwj);
pBlkRef->setNormal(normal);
pBlkRef->setColorIndex(text1color);//按文本颜色设置改变颜色
pBlkRef->setLayer(layerName);
AcDbBlockTable *pBlockTable;
acdbHostApplicationSerices()->workingDatabase()->getBlockTable(pBlockTable,AcDb::kForWrite);
AcDbBlockTableRecord *pBlockTableRecord;
pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,AcDb::kForWrite);
pBlockTableRecord->appendAcDbEntity(newEntId, pBlkRef);
pBlockTable->close();
pBlockTableRecord->close();

acdbOpenObject(pBlockTableRecord, blockId, AcDb::kForRead);
AcDbBlockTableRecordIterator *pIterator;
pBlockTableRecord->newIterator(pIterator);
AcDbEntity *pEnt;
AcDbAttributeDefinition *pAttdef;
for (pIterator->start(); !pIterator->done();pIterator->step())
{
pIterator->getEntity(pEnt, AcDb::kForWrite);
//pEnt->setColorIndex(text1color);//按文本颜色设置改变颜色
//pEnt->setLayer(layerName);//设置层
if(pEnt->isKindOf(AcDbAttributeDefinition::desc()))
{
pAttdef = AcDbAttributeDefinition::cast(pEnt);
if (pAttdef != NULL && !pAttdef->isConstant())
{
AcDbAttribute *pAtt = new AcDbAttribute();
pAtt->setPropertiesFrom(pAttdef);
pAtt->setInisible(pAttdef->isInisible());
AcGePoint3d alignpoint;
alignpoint=pAttdef->alignmentPoint();
alignpoint+=pBlkRef->position().asector();
AcDbObjectId TextStyleId;
TextStyleId=createTextStyle(littleFont,bigFont,"xianlu");
pAtt->setTextStyle(TextStyleId);
pAtt->setHeight(pAttdef->height());
pAtt->setTag("Tag");
pAtt->setFieldLength(25);
pAtt->setLayer(layerName);
char *pStr = pAttdef->tag();
pAtt->setTag(pStr);
free(pStr);
pAtt->setFieldLength(pAttdef->fieldLength());
if(strcmp(pAtt->tag(),"标注1")==0)
{
AcGePoint3d gg(dx/scalex,0,0);
alignpoint=alignpoint+gg.asector();
AcGeector3d et(0,0,1);
alignpoint=alignpoint.scaleBy(scalex,insertPoint);
alignpoint=alignpoint.rotateBy(fwj,et,insertPoint);
pAtt->setTextString(Text1.GetBuffer(Text2.GetLength()));
pAtt->setRotation(PI/2+fwj);
pAtt->setHorizontalMode(AcDb::kTextCenter);
pAtt->seterticalMode(AcDb::kTextBottom);
pAtt->setAlignmentPoint(alignpoint);
pAtt->setColorIndex(text1color);
pAtt->setHeight(text1height*scalex);
pAtt->setWidthFactor(text1scator);
}
if(strcmp(pAtt->tag(),"标注2")==0)
{
AcGePoint3d gg(dx/scalex,0,0);
alignpoint=alignpoint-gg.asector();
AcGeector3d et(0,0,1);
alignpoint=alignpoint.scaleBy(scalex,insertPoint);
alignpoint=alignpoint.rotateBy(fwj,et,insertPoint);
pAtt->setTextString(Text2.GetBuffer(Text2.GetLength()));
pAtt->setRotation(PI/2+fwj);
pAtt->setHorizontalMode(AcDb::kTextCenter);
pAtt->seterticalMode(AcDb::kTextBottom);
pAtt->setAlignmentPoint(alignpoint);
pAtt->setColorIndex(text2color);
pAtt->setHeight(text2height*scalex);
pAtt->setWidthFactor(text2scator);
}
if(strcmp(pAtt->tag(),"标注3")==0)
{
AcGePoint3d gg(0,dy/scalex,0);
alignpoint=alignpoint+gg.asector();
AcGeector3d et(0,0,1);
alignpoint=alignpoint.scaleBy(scalex,insertPoint);
alignpoint=alignpoint.rotateBy(fwj,et,insertPoint);
pAtt->setTextString(Text3.GetBuffer(Text3.GetLength()));
pAtt->setRotation(fwj);
pAtt->setHorizontalMode(AcDb::kTextCenter);
pAtt->seterticalMode(AcDb::kTextBottom);
pAtt->setAlignmentPoint(alignpoint);
pAtt->setColorIndex(text3color);
pAtt->setHeight(text3height*scalex);
pAtt->setWidthFactor(text3scator);
}
AcDbObjectId attId;
pBlkRef->appendAttribute(attId, pAtt);
pAtt->close();
}
}
// pEnt->setColorIndex(text1color);//按文本颜色设置改变颜色
pEnt->close();
}
delete pIterator;
pBlockTableRecord->close();
pBlkRef->close();
return TRUE;
}


//遍历多义线顶点坐标
Acad::ErrorStatus CDrawFunction::IteratorPolyline(AcDbObjectId polylineID,AcGePoint3dArray& pointArray)
{
Acad::ErrorStatus es=Acad::eOk;
AcDbObject* pObject=NULL;
AcDbPolyline *pline=NULL;
if((es=acdbOpenObject(pObject,polylineID,AcDb::kForRead))!=Acad::eOk)
return es;
if(!pObject->isKindOf(AcDbPolyline::desc()))
{
pObject->close();
return Acad::eInalidInput;
}
pline=AcDbPolyline::cast(pObject);
int num=pline->numerts();
for (int i=0; i< num; i++)
{
AcGePoint3d temPt;
if((es=pline->getPointAt(i, temPt))!=Acad::eOk)
{
pObject->close();
return Acad::eInalidInput;
}
pointArray.append(temPt);
}
pObject->close();
return es;
}


Acad::ErrorStatus CDrawFunction::createGroup(CString groupname,AcDbObjectIdArray IdArray)
{
Acad::ErrorStatus es=Acad::eOk;
AcDbDictionary *pGroupDict=NULL;
AcDbGroup *pGroup=NULL;
if((es=acdbHostApplicationSerices()->workingDatabase()->getGroupDictionary(pGroupDict,AcDb::kForWrite))!=Acad::eOk)
{
return es;
}
AcDbObjectId groupId;
es=pGroupDict->getAt(groupname,groupId);
if(es==Acad::eInalidKey)
{
acutPrintf("/n输入的词典名无效!");
pGroupDict->close();
return es;
}
else if(es==Acad::eKeyNotFound)
{
pGroup=new AcDbGroup("GroupDiscription");
if((es=pGroupDict->setAt(groupname,pGroup,groupId))!=Acad::eOk)
{
pGroup->close();pGroupDict->close();return es;
}
}
else if(es==Acad::eOk )
{
if((es=acdbOpenObject(pGroup,groupId,AcDb::kForWrite))!=Acad::eOk)
{
pGroupDict->close();return es;
}
}
for(int i=0;i pGroup->append(IdArray[i]);
pGroup->setSelectable(FALSE);
pGroupDict->close();
pGroup->close();
return es;
}

double CDrawFunction::getTextLength(AcDbObjectId textId)
{
Acad::ErrorStatus es=Acad::eOk;
AcDbEntity *pEnt=NULL;
if((es=acdbOpenObject(pEnt,textId,AcDb::kForRead))!=Acad::eOk)
return -1;
AcDbExtents Ext;
pEnt->getGeomExtents(Ext);
pEnt->close();
AcGePoint3d minPt,maxPt;
minPt=Ext.minPoint();
maxPt=Ext.maxPoint();
return acutDistance(asDblArray(minPt),asDblArray(maxPt));
}



oid CDrawFunction::highlightEdge(const AcDbObjectId& objId,const int marker)
{
char dummy[133];
AcDbEntity *pEnt;
acdbOpenObject(pEnt,objId,AcDb::kForRead);
AcGePoint3d pickpnt;
AcGeMatrix3d xform;
int numIds;
AcDbFullSubentPath *subentIds;
pEnt->getSubentPathsAtGsMarker(AcDb::kEdgeSubentType,marker,pickpnt,xform,numIds,subentIds);
if(numIds>0)
{
pEnt->highlight(subentIds[0]);
ads_getstring(0,"/npressto continue...",dummy);
pEnt->unhighlight(subentIds[0]);

}
delete []subentIds;
pEnt->close();
}


Acad::ErrorStatus CDrawFunction::readXrecord(CString dictName,CString xrecordName,CString &message)
{
AcDbDictionary *pDict=NULL;
pDict=openDictionaryForRead(dictName,acdbHostApplicationSerices()->workingDatabase());
if(pDict)
{
AcDbXrecord *pXrec;
pDict->getAt(xrecordName, (AcDbObject*&) pXrec,AcDb::kForRead);
pDict->close();
struct resbuf *pRbList;
pXrec->rbChain(&pRbList);
pXrec->close();
message=pRbList->resal.rstring;
acutRelRb(pRbList);
return Acad::eOk;
}
else
{
return Acad::eInalidInput;
}
}


//
//
//
AcDbDictionary* CDrawFunction::openDictionaryForWrite(LPCTSTR dictName,
bool createIfNotFound,AcDbDictionary* parentDict)
{
ASSERT(dictName != NULL);
ASSERT(parentDict != NULL);
ASSERT(parentDict->isWriteEnabled());
AcDbDictionary* dict = NULL;
AcDbObject* obj;
Acad::ErrorStatus es;
es = parentDict->getAt(dictName, obj, AcDb::kForWrite);
if (es == Acad::eOk)
{
dict = AcDbDictionary::cast(obj);
}
else if (es == Acad::eKeyNotFound)
{
if (createIfNotFound)
{
dict = new AcDbDictionary;
AcDbObjectId dictId;
es = parentDict->setAt(dictName, dict, dictId);
if (es != Acad::eOk)
{
delete dict;dict = NULL;
}
}
}
return dict;
}

这篇关于CAD ObjectARX扩展工具的源码(三)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/757909

相关文章

基于Go语言实现一个压测工具

《基于Go语言实现一个压测工具》这篇文章主要为大家详细介绍了基于Go语言实现一个简单的压测工具,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录整体架构通用数据处理模块Http请求响应数据处理Curl参数解析处理客户端模块Http客户端处理Grpc客户端处理Websocket客户端

Go中sync.Once源码的深度讲解

《Go中sync.Once源码的深度讲解》sync.Once是Go语言标准库中的一个同步原语,用于确保某个操作只执行一次,本文将从源码出发为大家详细介绍一下sync.Once的具体使用,x希望对大家有... 目录概念简单示例源码解读总结概念sync.Once是Go语言标准库中的一个同步原语,用于确保某个操

java图像识别工具类(ImageRecognitionUtils)使用实例详解

《java图像识别工具类(ImageRecognitionUtils)使用实例详解》:本文主要介绍如何在Java中使用OpenCV进行图像识别,包括图像加载、预处理、分类、人脸检测和特征提取等步骤... 目录前言1. 图像识别的背景与作用2. 设计目标3. 项目依赖4. 设计与实现 ImageRecogni

基于Python开发电脑定时关机工具

《基于Python开发电脑定时关机工具》这篇文章主要为大家详细介绍了如何基于Python开发一个电脑定时关机工具,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1. 简介2. 运行效果3. 相关源码1. 简介这个程序就像一个“忠实的管家”,帮你按时关掉电脑,而且全程不需要你多做

基于C#实现PDF文件合并工具

《基于C#实现PDF文件合并工具》这篇文章主要为大家详细介绍了如何基于C#实现一个简单的PDF文件合并工具,文中的示例代码简洁易懂,有需要的小伙伴可以跟随小编一起学习一下... 界面主要用于发票PDF文件的合并。经常出差要报销的很有用。代码using System;using System.Col

redis-cli命令行工具的使用小结

《redis-cli命令行工具的使用小结》redis-cli是Redis的命令行客户端,支持多种参数用于连接、操作和管理Redis数据库,本文给大家介绍redis-cli命令行工具的使用小结,感兴趣的... 目录基本连接参数基本连接方式连接远程服务器带密码连接操作与格式参数-r参数重复执行命令-i参数指定命

Python pyinstaller实现图形化打包工具

《Pythonpyinstaller实现图形化打包工具》:本文主要介绍一个使用PythonPYQT5制作的关于pyinstaller打包工具,代替传统的cmd黑窗口模式打包页面,实现更快捷方便的... 目录1.简介2.运行效果3.相关源码1.简介一个使用python PYQT5制作的关于pyinstall

Java汇编源码如何查看环境搭建

《Java汇编源码如何查看环境搭建》:本文主要介绍如何在IntelliJIDEA开发环境中搭建字节码和汇编环境,以便更好地进行代码调优和JVM学习,首先,介绍了如何配置IntelliJIDEA以方... 目录一、简介二、在IDEA开发环境中搭建汇编环境2.1 在IDEA中搭建字节码查看环境2.1.1 搭建步

使用Python制作一个PDF批量加密工具

《使用Python制作一个PDF批量加密工具》PDF批量加密‌是一种保护PDF文件安全性的方法,通过为多个PDF文件设置相同的密码,防止未经授权的用户访问这些文件,下面我们来看看如何使用Python制... 目录1.简介2.运行效果3.相关源码1.简介一个python写的PDF批量加密工具。PDF批量加密

使用Java编写一个文件批量重命名工具

《使用Java编写一个文件批量重命名工具》这篇文章主要为大家详细介绍了如何使用Java编写一个文件批量重命名工具,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录背景处理1. 文件夹检查与遍历2. 批量重命名3. 输出配置代码片段完整代码背景在开发移动应用时,UI设计通常会提供不