工程方格网坐标标注

来源:互联网 发布:徐老师淘宝店号是多少 编辑:程序博客网 时间:2024/05/01 07:58

    近日在做一条公路带状图勘察测绘过程中,设计单位要求提供带状图200米间隔方格网坐标注记,考虑到要求内容简单,技术难度不大,决定用ARX练练手,实现第一个ARX程序的愿望。源程序如下:

#include "StdAfx.h"
#include "StdAfx.h"
#include <cmath>
#include "dbpl.h"
#include "dbents.h"
#include "dbsymtb.h"
#include "dbmtext.h"
#include "stdio.h"
//using namespace std;

const long double r90=3.1415926/2;
static AcDbObjectId CreateText1(const AcGePoint3d& ptInsert,
                                const char* text,AcDbObjectId style=AcDbObjectId::kNull,
                                double height=5,double rotation=0);//水平多行文字创建
static AcDbObjectId CreateText2(const AcGePoint3d& ptInsert,
                                const char* text,AcDbObjectId style=AcDbObjectId::kNull,
                                double height=5,double rotation=r90);// 垂直多行文字创建


AcDbObjectId PostToModelSpace(AcDbEntity* pEnt)
{
    AcDbBlockTable* pBlockTable;
    acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable,AcDb::kForRead);
    AcDbBlockTableRecord* pBlockTableRecord;
    pBlockTable->getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForWrite);
    AcDbObjectId entId;
    pBlockTableRecord->appendAcDbEntity(entId,pEnt);
    pBlockTable->close();
    pBlockTableRecord->close();
    pEnt->close();

    return entId;
}
AcDbObjectId CreateText1(const AcGePoint3d& ptInsert,
                        const char* text,AcDbObjectId style,
                        double height,double rotation)
{
    AcDbText* pText=new AcDbText(ptInsert,text,style,height,rotation);
    return PostToModelSpace(pText);
}
AcDbObjectId CreateText2(const AcGePoint3d& ptInsert,
                        const char* text,AcDbObjectId style,
                        double height,double rotation)
{
    AcDbText* pText=new AcDbText(ptInsert,text,style,height,rotation);
    return PostToModelSpace(pText);
}

void ckylldzzb()
{
    ads_point GetSp,GetEp;//输入边界坐标
    AcGePoint3d StarPo,EndPo;//注记坐标起止
    AcGePoint3d Tzbx,Tzby;
    AcDbObjectId polyId;
    if(acedGetPoint(NULL,"/n输入起点:",GetSp)!=RTNORM)
        return;
    acedGetCorner(GetSp,"/n输入对角点:",GetEp);
    AcGePoint3d ptGe1;
    ptGe1[X]=(ceil(GetSp[X]/200))*200;
    ptGe1[Y]=(ceil(GetSp[Y]/200))*200;
    ptGe1[Z]=0;
    //ptGe2[X]=(ceil(GetEp[X]/200))*200;
    //ptGe2[Y]=(ceil(GetEp[Y]/200))*200;
    for(ptGe1[X];ptGe1[X]<GetEp[X];ptGe1[X]+=200)
    {
        for(ptGe1[Y];ptGe1[Y]<GetEp[Y];ptGe1[Y]+=200)
        {
            StarPo[X]=ptGe1[X];
            StarPo[Y]=ptGe1[Y]+20;
            //StarPo[Z]=0;
            EndPo[X]=ptGe1[X];
            EndPo[Y]=ptGe1[Y]-20;
            Tzbx[X]=ptGe1[X]+5;
            Tzbx[Y]=ptGe1[Y];
            Tzby[X]=ptGe1[X]+5;
            Tzby[Y]=ptGe1[Y]+5;
            char zbX[10],zbY[10];
            sprintf(zbX,"%.0f",ptGe1[X]);
            sprintf(zbY,"%.0f",ptGe1[Y]);
            char xx[11]={'N'};
            char yy[11]={'E'};
            for(int i=1;i<11;i++)
            {
                xx[i]=zbX[i-1];
                yy[i]=zbY[i-1];
            }
            CreateText1(Tzbx,yy);
            CreateText2(Tzby,xx);
            AcDbLine *line1=new AcDbLine(StarPo,EndPo);
            polyId=PostToModelSpace(line1);
            StarPo[X]=ptGe1[X]-20;
            StarPo[Y]=ptGe1[Y];
            EndPo[X]=ptGe1[X]+20;
            EndPo[Y]=ptGe1[Y];
            AcDbLine *line2=new AcDbLine(StarPo,EndPo);
            polyId=PostToModelSpace(line2);
        }
        ptGe1[Y]=(ceil(GetSp[Y]/200))*200;
    }
}

//END

介于初学arx,本程序还有许多不尽人意的地方,只能实现对角线所构成的长方形内的整座标注记。程序还在进一步更新中......