公差标注模块说明
一、数据结构及公差类定义
1、公差属性信息的数据结构:
classAttInfo
{
public:
char* pInfoTag;//信息标识
char* pDisplay;//说明信息
};
2、定义公差算法的类型:
enumTolCalType
{
TolCalType1 = 1,
TolCalType2 = 2,
TolCalType3 = 3,
TolCalType4 = 4
};
3、从AcDbMText派生公差标注需要的公差类,添加以下数据信息:
AcDbHardPointerIdm_RefObjectID;//和公差关联的圆的对象ID
AttInfom_attribute[10];//公差关联的的属性信息
TolCalTypem_CalType;//公差算法类型
longm_nAttCount;//公差所关联的属性组数目,最大为10
doubledDim;// 公差关联的圆/直径
doubledUp;//根据直径计算的公差上标
doubledLow;// 根据直径计算的公差下标
doubledSize;//字体尺寸
重载和添加公差类的函数,具体如下:
//设置公差关联的圆
Acad::ErrorStatussetRefCircle(constAcDbObjectId& tsId);
//设置公差关联的属性
Acad::ErrorStatussetAttribute(intnIndex,AttInfoatt);
//获取公差关联的属性
Acad::ErrorStatusgetAttribute(intnIndex,AttInfo &att);
//设置公差的标注位置
Acad::ErrorStatussetPosition(constAcGePoint3d& cen);
//获取文字的大小
doublegetTextSize()const;
//设置文字的大小
voidsetTextSize(doubledTxtSize);
//根据圆的直径和公差算法计算公差的上下限
Acad::ErrorStatusgetDimData();
//设置公差算法类型
voidsetCalType(TolCalTypetype);
二、命令实现
创建新的arx工程,添加新的命令,公差操作分为2部分,
公差创建:
<code begin>
CGDCsDbTolerance *pTol =NULL;
AcDbObjectIdtsId;
if ((pTol=newCGDCsDbTolerance)==NULL){
acutPrintf("\nOut of Memory.");
return;
}
AcDbObjectIdpEntId;
ads_nameen;
ads_pointpt;
//获取要标注的圆
if (acedEntSel("\n选择要标注公差的圆: ", en, pt)
!= RTNORM)
{
acutPrintf("没有选择对象\n");
return;
}
ads_pointptIn;
if (acedGetPoint(pt,"选择标注位置",ptIn)!= RTNORM)
{
acutPrintf("没有选择标注位置\n");
return;
}
acdbGetObjectId(pEntId, en);
pTol->setRefCircle(pEntId);
pTol->setPosition(AcGePoint3d(ptIn[0],ptIn[1],0.0));
pTol->setCalType(TolCalType1 );//设置公差计算类型
///设置公差数据
doubledR,dU,dL;
dR = pTol->getTolDim();
dU = pTol->getTolUp();
dL = pTol->getTolLow();
CStringstr;
str.Format("%.4f",dR);
char *p=str.GetBuffer(str.GetLength());
pTol->setDimChar(p);
if (dU>=0) {
str.Format("+%f",dU);
}
else{
str.Format("%f",dU);
}
p=str.GetBuffer(str.GetLength());
pTol->setUpChar(p);
if (dL>=0) {
str.Format("+%f",dL);
}
else{
str.Format("%f",dL);
}
p=str.GetBuffer(str.GetLength());
pTol->setLowChar(p);
//设置附加属性
pTol->setAttCount(3);//设置附加属性的数目
AttInfoattNew;
attNew.pDisplay = "说明";
attNew.pInfoTag = "E";
pTol->setAttribute(0,attNew);//设置附加属性
attNew.pDisplay = "说明";
attNew.pInfoTag = "EP";
pTol->setAttribute(1,attNew);
attNew.pDisplay = "说明";
attNew.pInfoTag = "OP";
pTol->setAttribute(2,attNew);
//保存到数据库中
postToDb(pTol);
pTol->close();
<code end>
公差属性获取:
<code begin>
//获取属性数据
if (acedEntSel("\n选择一个公差: ", en, pt) != RTNORM)
{
acutPrintf("Nothing Selected\n");
return;
}
acdbGetObjectId(pEntId, en);
AcDbEntity *ent = NULL;
acdbOpenAcDbEntity(ent, pEntId,AcDb::kForRead);
if (ent->isKindOf(CGDCsDbTolerance::desc()))
{
CGDCsDbTolerance* pTol1 = (CGDCsDbTolerance*)ent;
AttInfoattOut;
pTol1->getAttribute(0,attOut);
acutPrintf("属性:%s,%s\n,",attOut.pInfoTag,attOut.pDisplay);
pTol1->getAttribute(1,attOut);
acutPrintf("属性:%s,%s\n,",attOut.pInfoTag,attOut.pDisplay);
pTol1->getAttribute(2,attOut);
acutPrintf("属性:%s,%s\n,",attOut.pInfoTag,attOut.pDisplay);
}
else
{
acutPrintf("不是公差对象\n");
}
<code end>