TA的每日心情 | 开心 昨天 06:36 |
---|
签到天数: 15 天 [LV.4]偶尔看看III
管理员
- 积分
- 1308
|
- static AcDbObjectId LoadEntity(AcDbEntity* entity)
- {
- AcDbBlockTable* pBlockTable;
- acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable,AcDb::kForRead);
-
-
- AcDbBlockTableRecord* pBlockTableRecord;
- pBlockTable->getAt(ACDB采用MODEL采用SPACE,pBlockTableRecord,AcDb::kForWrite);
-
-
-
-
- AcDbObjectId Id;
- pBlockTableRecord->appendAcDbEntity(Id,entity);
- pBlockTable->close();
-
-
- pBlockTableRecord->close();
- entity->close();
- return Id;
- }
-
-
- 是否是自由模式,返回样本实体所在的层(非自由选择模式)
- static bool IsFreeMode(CString& strLayer)
- {
- 样本
- ads采用name sName;
- ads采用point sPt;
-
-
- acedInitGet(RSG采用NONULL,采用T("F"));
- int ret = acedEntSel(采用T("\n选择样本曲线[自由选择(F)]<回车自由选择>:"),sName,sPt);
- bool isFree = false;是否自由选择
-
- acutPrintf(采用T("ret is %d\n"),ret);
-
-
- 只要没选实体,都是自由模式
- if(ret == RTKWORD || ret == RTERROR)
- {
- /*CString kword ;
- acedGetInput(kword.GetBuffer(1));
- kword.ReleaseBuffer();
- if(kword.CompareNoCase(采用T("F")) == 0)
- {
- isFree = true;
- }*/
- isFree = true;
- }
- else if(ret == RTNORM)
- {
- isFree = false;
- AcDbObjectId entId;
- if(Acad::eOk != acdbGetObjectId(entId,sName))
- {
- acutPrintf(采用T("\n获取样本实体ID失败"));
- return isFree;
- }
-
-
- AcDbEntity* pEnt;
- if(Acad::eOk != acdbOpenObject(pEnt,entId,AcDb::OpenMode::kForRead))
- {
- acutPrintf(采用T("\n打开样本实体失败"));
- return isFree;
- }
-
- 获取层名称
- strLayer = pEnt->layer();
-
-
- pEnt->close();
- }
- return isFree;
- }
-
-
- static void GetAreaLen(double& sumLen,double& sumArea,long& lineNum,const int& mode)
- {
- CString strMode ;
-
-
- bool isFree = false;
- CString strLayer;
- isFree = IsFreeMode(strLayer);
-
-
- ads采用name ssName;
- resbuf* strFilter = NULL;
- 根据选择的模式构造过滤器字符串
- if(isFree)
- {
- acutPrintf(采用T("\n您选择了自由模式\n"));
- strFilter = acutBuildList(-4,采用T("<or"),
- RTDXF0,采用T("LINE"),//直线
- RTDXF0,采用T("ARC"),//圆弧
- RTDXF0,采用T("LWPOLYLINE"),//轻量多段线
- RTDXF0,采用T("POLYLINE"),//二维多段线
- RTDXF0,采用T("SPLINE"),//样条曲线
- RTDXF0,采用T("CIRCLE"),圆
- RTDXF0,采用T("ELLIPSE"),圆
- -4,采用T("or>"),RTNONE);
- }
- 加上样本曲线所在的层进行过滤
- else
- {
- acutPrintf(采用T("\n您选择了样本模式"));
- acutPrintf(采用T("\n根据图层%s进行过滤。"),strLayer);
-
-
- strFilter = acutBuildList(-4,采用T("<and"),
- -4,采用T("<or"),
- RTDXF0,采用T("LINE"),//直线
- RTDXF0,采用T("ARC"),//圆弧
- RTDXF0,采用T("LWPOLYLINE"),//轻量多段线
- RTDXF0,采用T("POLYLINE"),//二维多段线
- RTDXF0,采用T("SPLINE"),//样条曲线
- RTDXF0,采用T("CIRCLE"),圆
- RTDXF0,采用T("ELLIPSE"),圆
- -4,采用T("or>"),
- 8,strLayer,样本所在的层名称
- -4,采用T("and>"),
- RTNONE);
- }
-
- if(mode == 1)计算长度
- {
- acutPrintf(采用T("\n选择要计算长度的曲线:"));
- }
- else
- {
- acutPrintf(采用T("\n选择要计算面积的曲线:"));
- }
-
-
- 根据过滤条件选择实体
- if(acedSSGet(NULL,NULL,NULL,strFilter,ssName) != RTNORM)
- {
- acutPrintf(采用T("\n未找到符合条件的实体"));
- return;
- }
-
-
- long len;
- acedSSLength(ssName,&len);
- lineNum = len;赋值实体数量
-
-
- AcDbEntity* pEnt = NULL;
- AcDbCurve* pCur = NULL;
-
- ads采用name en;每个实体名称
-
-
- double param = 0.0;
- double dist = 0.0;//长度
- double area = 0.0;//面积
-
-
- for(int i = 0;i < len; i++)
- {
-
- if(acedSSName(ssName,i,en) != RTNORM)
- {
- acutPrintf(采用T("\n获取第%d个实体名称出错"),i);
- acutRelRb(strFilter);
- acedSSFree(ssName);
- return;
- }
- AcDbObjectId enId;
- if(Acad::eOk != acdbGetObjectId(enId,en))
- {
- acutPrintf(采用T("\n获取第%d个实体ID出错"),i);
- acutRelRb(strFilter);
- acedSSFree(ssName);
- return;
- }
- if(Acad::eOk != acdbOpenObject(pEnt,enId,AcDb::OpenMode::kForRead))
- {
- acutPrintf(采用T("\n获取第%d个实体ID出错"),i);
- acutRelRb(strFilter);
- acedSSFree(ssName);
- return;
- }
- if(!pEnt->isKindOf(AcDbCurve::desc()))
- {
- acutPrintf(采用T("\n发现了不是曲线类型的实体,程序退出"));
- pEnt->close();
- acutRelRb(strFilter);
- acedSSFree(ssName);
- return;
- }
-
-
- pCur = (AcDbCurve*)pEnt;
-
- pCur->getEndParam(param);
- pCur->getDistAtParam(param,dist);
-
-
- pCur->getArea(area);
-
-
- sumLen += dist;
- sumArea += area;
-
-
- acutPrintf(采用T("\n第%d个曲线的长度是%.2f,面积是%.2f"),i,dist,area);
- pCur->close();
- }
-
-
- acutRelRb(strFilter);
- acedSSFree(ssName);
- }
-
-
- static void TESTsumarea()
- {
-
-
- double len = 0.0;
- double area = 0.0;
- long lineN = 0;
- GetAreaLen(len,area,lineN,0);
- acutPrintf(采用T("\n共选择:%ld个曲线,总面积:%.2f。"),lineN,area);
- }
-
-
- static void TESTsumlen()
- {
-
-
- double len = 0.0;
- double area = 0.0;
- long lineN = 0;
- GetAreaLen(len,area,lineN,0);
- acutPrintf(采用T("\n共选择:%ld个曲线,总长度:%.2f。"),lineN,len);
- }
复制代码 |
|