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;
}

原文地址:https://www.cnblogs.com/mjgw/p/12609685.html

时间: 2024-12-10 23:35:07

CAD ObjectARX扩展工具的源码(三)的相关文章

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

CAD ObjectARX扩展工具的源码(一)收藏的CAD扩展工具的源码: Acad::ErrorStatus CDrawFunction::getAllEntity(AcDbDatabase *pDb,AcDbObjectIdArray& IdArr,const AcArray& layerNameArr){Acad::ErrorStatus es=Acad::eOk;ASSERT(pDb);if(pDb==NULL)return Acad::eInalidInput;AcDbBlock

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

CAD ObjectARX扩展工具的源码(二)  //AcDbObjectId CDrawFunction::createtextAll(AcGePoint3d pt,char *text,AcDb::TextHorzMode hMode,AcDb::TextertMode Mode,double hight,double widthFactor,double rotation,int color,CString smallFontName,CString bigFontName,CString

可视化工具gephi源码探秘(二)---导入netbeans

在上篇<可视化工具gephi源码探秘(一)>中主要介绍了如何将gephi的源码导入myeclipse中遇到的一些问题,此篇接着上篇而来,主要讲解当下通过myeclipse导入gephi源码的可行性不高以及熟悉netbeans,并把原本基于netbeans平台开发的gephi源码导入进netbeans后启动正常运行的过程,其中有遇到的不少问题和相应的解决方法. 前日工作梗概(还是沿着想把源码导入myeclipse的思路): 经过从各大子模块的pom.xml中筛选出符合条件的jar包写入项目下的p

可视化工具gephi源码探秘(二)

在上篇<可视化工具gephi源码探秘(一)>中主要介绍了如何将gephi的源码导入myeclipse中遇到的一些问题,此篇接着上篇而来,主要讲解当下通过myeclipse导入gephi源码的可行性不高以及熟悉netbeans,并把原本基于netbeans平台开发的gephi源码导入进netbeans后启动正常运行的过程,其中有遇到的不少问题和相应的解决方法. 前日工作梗概(还是沿着想把源码导入myeclipse的思路): 经过从各大子模块的pom.xml中筛选出符合条件的jar包写入项目下的p

[软件测试]网站压测工具Webbench源码分析

一.我与webbench二三事 Webbench是一个在linux下使用的非常简单的网站压测工具.它使用fork()模拟多个客户端同时访问我们设定的URL,测试网站在压力下工作的性能.Webbench使用C语言编写,下面是其下载链接: http://home.tiscali.cz/~cz210552/webbench.html 说到这里,我赶脚非常有必要给这个网站局部一个截图,如下图: 第一次看到这张图片,着实吃了一精!居然是2004年最后一次更新,我和我的小伙伴们都惊呆了.不过既然现在大家还都

yii源码三 -- db

CDbConnection:path:/framework/db/CDbConnection.phpoverview:CDbConnection represents a connection to a database. 工作原理:CDbConnection works together with CDbCommand, CDbDataReader and CDbTransaction to provide data access to various DBMS.且基于PDO扩展. 首先用$c

用Diff和Patch工具维护源码

在Unix系统下,维护源码版本可以使用很多方法,其中最常用的当然是大名鼎鼎的CVS,但实际上,简单的版本维护工作并没有必要使用复杂的CVS等专门的版本维护工具,Unix标配中的diff和patch工具就完全可以完成代码的简单备份和升级工作. diff以"行"为单位比较两个文本文件(也可以是目录比较),并将不同之处以某种格式输出到标准输出上:patch可以读入这种输出,并按照一定指令使源文件(目录)按照目标文件(目录)更新.Linux内核源码就是按照这种方式保持更新的,我们在www.ke

Java学习-039-源码 jar 包的二次开发扩展实例(源码修改)

最近在使用已有的一些 jar 包时,发现有些 jar 包中的一些方法无法满足自己的一些需求,例如返回固定的格式,字符串处理等等,因而需要对原有 jar 文件中对应的 class 文件进行二次开发扩展,并重新打包文件,替换原有的 jar 文件,满足测试开发自身的需求. 下面以修改 eclipse 默认注释中的 ${date} 和 ${time} 对应的返回样式(如下图所示),进行实例说明. 整个二次开发的过程如下所示: 0.未修改之前,生成注释的日期.时间显示格式如下所示: 1.获取对应的 jar

一款生活辅助工具应用源码完整版

这个源码是一款生活辅助工具应用源码完整版,应用集 是一款生活辅助工具,主要有三大功能 (1)易闹钟:用户可以设定一个时间段以及响铃时间,设定个性铃声,设定响铃周期,可以当做早起闹钟,也可以当做备忘提醒: (2)易扫码:可以扫描二维码和条形码,点击之后可以跳转到地址详情: (3)易管理:SD卡管理工具,可以实现增删改移等功能 源码下载: http://code.662p.com/view/9596.html <ignore_js_op> 2_副本 - 副本.png (19.79 KB, 下载次数