📄 readxdatacommands.cpp
字号:
//
// ObjectARX defined commands, created by [2005-10-19], ,
#include "dbxrecrd.h "
#include "StdAfx.h"
#include "StdArx.h"
#include "resource.h"
#include "dbpl.h "//getclose getarea...
#include <rxregsvc.h>
#include <acutmem.h>
#include <dbsymtb.h>//->close ->objectID
#include "dbidar.h "//array
#include <string.h>
#include "dbents.h "
char *cLayer1 ="0";//请指定层!!
int qsc[20];//建筑起始层
int pscale=1;//比例系数
int cmax[20];
int Lnum[20];//楼的数目小于20
int t;//判断楼号
double allarea;//总面积存放
//double area1=0.00;//每个实体面积
char*data, *data1,*data2,*data3,*num;//对象属性//楼号//建筑起始层//建筑始终层//层数
static char* datacaption[8]={"居住","商业","办公","阳台","车库","阁楼","配套","其他"};
CString appName="xlgis";
int nn=1;//关联楼号动态数
double j[20][100],s[20][100],b[20][100],y[20][100],c[20][100],g[20][100],p[20][100],q[20][100];
//存储面积数组{"居住","商业","办公","阳台","车库","阁楼","配套","其他"};//楼<20,层<100
void On2d(double nx,double ny,int num,int ntt);//x坐标,y坐标,自定义houseID,比例系数
AcDbObjectId AddEntityToDbs(int i,AcDbEntity* pEnt);
Acad::ErrorStatus
getselectpolyarea(const char* szLayerName);//筛选出poly并计算面积
bool readxdata(AcDbPolyline* ppline);
bool FloorNum(int zl,double areax,char * datasx);
bool IsIntStr(CString str);
bool louhao(int houseID,int housenum, double area2,char * datasx);//判断housenum是否与之前的楼号相同
void coordinate(double n,AcGePoint3d pt,int nt);//调用填充表格
void txtcaption(double mx,double my,char CScaption[512],double ndb);
void numtable(int n,AcGePoint3d pt,int nt);
//应用程序名/对象ID/对象属性/楼号/建筑起始层/始终层/层数
//-----------------------------------------------------------------------------
// This is command 'READX, by [2005-10-19], ,
void xlgisntupReadx()
{
#ifdef OARXWIZDEBUG
acutPrintf ("\nOARXWIZDEBUG - xlgisntupReadx() called.");
#endif // OARXWIZDEBUG
getselectpolyarea("建筑功能");
// TODO: Implement the command
}
Acad::ErrorStatus
getselectpolyarea(const char* szLayerName)
{
Acad::ErrorStatus es = Acad::eOk;
AcDbLayerTable *pLayerTable = NULL;
es = acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pLayerTable, AcDb::kForRead);
if (es != Acad::eOk) return es;
AcDbLayerTableRecord *pLayerTableRecord = NULL;
es = pLayerTable->getAt(szLayerName, pLayerTableRecord,
AcDb::kForRead); // 判断是否存在层名szLayerName
if (es != Acad::eOk)
{
pLayerTable->close();
acutPrintf("\n'%s'层不存在!", szLayerName);
return es;
}
AcDbObjectId layerId=pLayerTableRecord->objectId();
pLayerTableRecord->close();
pLayerTable->close();
acdbHostApplicationServices()->workingDatabase()->setClayer(layerId);
// 得到模型空间的块表记录,并遍历它得到所需要的实体
AcDbBlockTable *pBlockTable = NULL;
es = acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pBlockTable, AcDb::kForRead);
if (es != Acad::eOk) {
acutPrintf("\n以读方式打开块表操作失败!");
return es;
}
AcDbBlockTableRecord *pBlockTableRecord = NULL;
es = pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,
AcDb::kForRead);
if (es != Acad::eOk) {
pBlockTable->close();
acutPrintf("\n以读方式打开块表记录操作失败!");
return es;
}
pBlockTable->close();
AcDbBlockTableRecordIterator *pBlockIterator = NULL;
pBlockTableRecord->newIterator(pBlockIterator);
AcDbBlockTableRecordIterator *pBlkTblRcdItr; //生成块表记录的迭代器
pBlockTableRecord->newIterator(pBlkTblRcdItr);
AcDbEntity *pEnt; //遍历法获得并打印每一个实体的类名
int n=0,m=0,x=0,NoPl=0;
allarea=0;
for (pBlkTblRcdItr->start(); !pBlkTblRcdItr->done(); pBlkTblRcdItr->step())
{
n=n++;
pBlkTblRcdItr->getEntity(pEnt, AcDb::kForRead);
acutPrintf("\npEnt is: %s\n", (pEnt->isA())->name());
////////////////////////////////
char *cLayer = pEnt->layer();
if (strcmp(cLayer, cLayer1) == 0) {
if (pEnt->isKindOf(AcDbPolyline::desc()))
{
acutPrintf("\n存在AcDbPolyline!");
AcDbPolyline *pPLine;
pPLine=AcDbPolyline::cast(pEnt);
double area1=0.00;//每个实体面积
pPLine->getArea(area1);
if(pPLine->isClosed()!=0) //筛选闭合
{
//acutPrintf("\n该不确定pline线的面积为: '%.3f'平方米", area1);
if(readxdata(pPLine)==0)//读取XData
{
char* sx=data;
CString str1=data1;
if (data1!=NULL)//判断data1是否为楼号(int型)IsIntStr(str1)==0
{
m=m++;
int num2=atoi(data1);//转换为int楼号
if(louhao(n,num2,area1,data)==0)
acedAlert("succeed!");
}
else
acutPrintf("XData有误!");
}
pPLine->close();
pEnt->close();
}
else
{
pPLine->close();
pEnt->close();
x=x++;//非闭合pline线
}
}
else
{
// pEnt->highlight();
// pEnt->setColorIndex(1);//
pEnt->close();
NoPl=NoPl++;//非pline线
}
}
}
acutPrintf("\nn='%d'!", nn);
pBlockTableRecord->close();
delete pBlkTblRcdItr; //删除块表记录迭代器及数据库指针
//选择表格左上角的标注点/层数 cs
ads_point point,pont;
int ret = acedGetPoint(NULL,"请选择表格左上角的标注点:",point);
acutPrintf("\n你选的点坐标为 x = %.3f y = %.3f",point[0],point[1]);
acutPrintf("\nLnum[1]='%d'!",Lnum[1]);
acutPrintf("\nLnum[2]='%d'!",Lnum[2]);
acutPrintf("\nLnum[3]='%d'!",Lnum[3]);
acutPrintf("\nLnum[4]='%d'!",Lnum[4]);
pont[1]=point[1];
On2d( point[0], point[1],1,pscale);//x坐标,y坐标,自定义houseID,比例系数
for(int node=2;node<nn+1;node++)
{ //ads_point pont;
pont[0]=point[0];
pont[1]=pont[1]-(cmax[node-1]+7)*4;
On2d( pont[0], pont[1],node,pscale);//x坐标,y坐标,自定义houseID,比例系数
acutPrintf("sdjh");
}
acutPrintf("\n有'%d'个非闭合pline线存在!",x);
acutPrintf("\n有'%d'个非pline线存在!",NoPl);
acutPrintf("\n有'%d'个对象存在!",n);
acutPrintf("\n有'%d'个Xdata匹配成功闭合pline线存在!",m);
for(int jj=1;jj<20;jj++)
{
for(int gg=1;gg<100;gg++)
{
j[jj][gg]=s[jj][gg]=b[jj][gg]=y[jj][gg]=c[jj][gg]=g[jj][gg]=p[jj][gg]=q[jj][gg]=0;
}
}
return Acad::eOk;
}
bool louhao(int houseID,int housenum,double area2,char * datasx)
{ //判断楼号是否与之前的一样//houseID并非自定义楼号而是为了判断是否是第一次赋值
if (houseID==1)
{
Lnum[1]=housenum;
FloorNum(1,area2,datasx);//Lnum[t]);//楼号
acutPrintf("\n初始化houseID'%d'!", houseID);
return 0;
}
else
{
int ttt;
for(ttt=1;ttt<nn+1;ttt++)
{
if(housenum==Lnum[ttt])//判断housenum是否与之前的楼号相同
{
FloorNum(ttt,area2,datasx);//Lnum[t]);//楼号/面积/属性
acutPrintf("\nLnum[ttt]='%d'!",Lnum[ttt]);
return 0;
}
}
if(ttt==nn+1)
{
nn=nn++;
Lnum[nn]=housenum;//存放楼号
FloorNum(houseID,area2,datasx);
acutPrintf("\n(houseID++)='%d'!", houseID);
acutPrintf("\n(nn++)='%d'!", nn);
return 0;
}
}
return 0;
}
bool IsIntStr(CString str)//判断data1是否为楼号(int型)
{
for (int i = 0; i < strlen(str); i ++ )
{
int ch = str[i];
if ( ch < '0' || ch > '9' )
return 1;
}
return 0;
}
bool FloorNum(int zl,double areax,char * datasx)//传入自定义楼号/面积
{
cmax[zl]=atoi(data3);//得到:建筑始终层
int cs=atoi(num);//层数
qsc[zl]=atoi(data2);//建筑起始层
if (qsc[zl]<0||qsc[zl]>1)
{
if (cs>0)
{
cmax[zl]=cmax[zl]-qsc[zl];//将负层转化到自定义的实际楼层中!
cs=cs-qsc[zl];
}
else{
cmax[zl]=cmax[zl]-qsc[zl];//将负层转化到自定义的实际楼层中!
cs=cs-qsc[zl]+1; //将层数转化为自定义的楼层数!
}
}
for(int i=1;i<9;i++) //确定属性
{
if(strcmp(datasx,datacaption[i-1])==0)
{
CString attribute=data;
switch (i)
{
case 1:
j[zl][cs]=j[zl][cs]+areax;//第zl号楼的cs层的“居住”面积
break;
case 2:
s[zl][cs]=s[zl][cs]+areax;
break;
case 3:
b[zl][cs]=b[zl][cs]+areax;
break;
case 4:
y[zl][cs]=y[zl][cs]+areax;
break;
case 5://'车库':
c[zl][cs]=c[zl][cs]+areax;
break;
case 6://'阁楼':
g[zl][cs]=g[zl][cs]+areax;
break;
case 7://'配套':
p[zl][cs]=p[zl][cs]+areax;
break;
case 8://'其他':
q[zl][cs]=q[zl][cs]+areax;
break;
}
return 0;
}
}
return 1;
}
bool readxdata(AcDbPolyline* ppline)
{ // 获取指定对象的扩展实体数据
char appName1[40];//应用程序名
strcpy(appName1,appName);
struct resbuf *pRb;
if(pRb = ppline->xData(appName1))
{
// acedAlert("appName匹配成功!");
if(pRb!=NULL)
{
pRb=pRb->rbnext;
int n=1;
for(;pRb!=NULL;pRb=pRb->rbnext)
{
if(pRb->restype==1000)
{
switch (n)
{
case 1: data=pRb->resval.rstring;break; //得到:对象属性
case 2: data1=pRb->resval.rstring;break;//得到:楼号
case 3: data2=pRb->resval.rstring;break;//得到:建筑起始层
case 4: data3=pRb->resval.rstring;break;//得到:建筑始终层
case 5: num=pRb->resval.rstring;break;//得到:层数
}
n++;
}
}
}
else{
acutPrintf("\n该闭合pline扩展数据为空!");
acutRelRb(pRb);
return 1;
}
}
else
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -