|
我自己开发了一个公路类,3条直线,可是绘制的图形无法保存,请高手指点!//类的头文件.h
#ifndef __ROADCLASS__H__
#define __ROADCLASS__H__
#include "dbents.h"
class Road
{
private:
AcGePoint3d g3Sp,g3Ep;//公路的起点和终点
double dBlg;//公路的突起值
double dWRd;//公路的宽度
int iClrRd;//公路颜色
AcDbObjectId idMiddle,idLift,idRight;//三条中线的id
public:
Road();
Road(AcGePoint3d g3StartPt,AcGePoint3d g3EndPt,
int iRoadColor,
double dBulge,double dWidthRoad);
~Road();
void drawRoad();
}; //自定义类结束
#endif
//类的实现文件.cpp
#include "stdafx.h"
#include "croadclass.h"
#include "dbproxy.h"
/*************************************************************/
/*** fast_changEntityColor 2k1 ***/
/*************************************************************/
/*** 功能描述:改变实体的颜色 ***/
/*************************************************************/
/*** 入口参数:AcDbEntity * x_pEntity ***/
/*** int x_color ***/
/*** 返回值: void ***/
/*** ***/
/*** ***/
/*************************************************************/
/*** Programmed by Wang Zhiqin, 2001.08.01 ***/
/*************************************************************/
void fast_changEntityColor(AcDbEntity * x_pEntity,int x_color)
{
AcCmColor color;
color.setColorIndex(x_color);
x_pEntity->setColor(color);
}
/*************************************************************/
/*** fast_Entity_addToDb arx2000 ***/
/*************************************************************/
/*** 功能描述:把新创建的实体加入数据库 ***/
/*************************************************************/
/*** 入口参数:AcDbLine * pEntity, AcDbObjectId& id ***/
/*** 返回值: 0: 失败;1:成功; ***/
/*** int ***/
/*** ***/
/*************************************************************/
/*** Programmed by wzq, 2001.06.01 ***/
/*************************************************************/
int fast_Entity_addToDb (AcDbEntity * pEntity,AcDbObjectId& id)
{
AcDbDatabase *pEntityDb;
AcDbBlockTable *pBlockTable;
AcDbBlockTableRecord *pBlockTableRecord;
// AcDbObjectId lineId;
// pEntityDb = acdbCurDwg(); //ObjectARX14的形式
pEntityDb = acdbHostApplicationServices()->workingDatabase();//ObjectARX2000的形式
// Get the model space Block Table Record
if(pEntityDb->getBlockTable(pBlockTable, AcDb::kForRead)!=Acad::eOk)
{
return 0;
}
if(pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,
AcDb::kForWrite)!=Acad::eOk)
{
pBlockTable->close();
return 0;
}
pBlockTable->close();
if(pBlockTableRecord->appendAcDbEntity(id, pEntity)!=Acad::eOk)
{
pBlockTableRecord->close();
return 0;
}
pBlockTableRecord->close();
pEntity->close();
return 1;
}
/*
EDITION:2K
FUNCTION:fast_draw_2dpolyline
PARAMETER:起点集,突起值集
USE:绘制AcDb2dPolyline线,并加入到数据库;
RETURN:0:失败;1:成功;
AUTHOR:WANGQIN
*/
int fast_draw_2dpolyline(AcGePoint3dArray pts,
AcGeDoubleArray blgs,
int color,
double lw,
AcDbObjectId& id)
{
int ra;
AcDb2dPolyline * p2dpl=new AcDb2dPolyline(AcDb::k2dSimplePoly,pts,
0,Adesk::kFalse,lw,lw,&blgs);
fast_changEntityColor(p2dpl,color);
ra=fast_Entity_addToDb(p2dpl,id);
//p2dpl->close();
return ra;
}
Road::Road()
{
g3Sp.set(0.0,0.0,0.0);
g3Ep.set(300.0,0.0,0.0);
dBlg=0.0;
dWRd=32.0;
iClrRd=3;
idMiddle=0;
idLift=0;
idRight=0;
}
Road::Road(AcGePoint3d g3StartPt,AcGePoint3d g3EndPt,
int iRoadColor,
double dBulge,double dWidthRoad)
{
acutPrintf("\n执行构造函数2");
g3Sp=g3StartPt;
g3Ep=g3EndPt;
dBlg=dBulge;
dWRd=dWidthRoad;
iClrRd=iRoadColor;
idMiddle=0;
idLift=0;
idRight=0;
}
Road::~Road()
{
acutPrintf("\n执行析构函数");
}
void Road::drawRoad()
{
int iRz;
AcGeVector3d v3S2E=(g3Ep-g3Sp).normalize();//起点指向终点的单位矢量
AcGePoint3d g3SpLift,g3EpLift,g3SpRight,g3EpRight;//左边线和右边线的起点和终点
AcGePoint3dArray pts;
AcGeDoubleArray dBlgs;
//绘制中线
pts.append(g3Sp);
pts.append(g3Ep);
dBlgs.append(dBlg);
dBlgs.append(0);
iRz=fast_draw_2dpolyline(pts,dBlgs,iClrRd,0,idMiddle);
if(iRz==0)
{
return ;
}
pts.setLogicalLength(0);
dBlgs.setLogicalLength(0);
AcGeVector3d v3Tem1=v3S2E,v3Tem2=v3S2E;
//绘制边线1
g3SpLift=g3Sp+v3Tem1.perpVector()*dWRd;
g3EpLift=g3Ep+v3Tem1.perpVector()*dWRd;
pts.append(g3SpLift);
pts.append(g3EpLift);
dBlgs.append(dBlg);
dBlgs.append(0);
iRz=fast_draw_2dpolyline(pts,dBlgs,iClrRd,0,idLift);
if(iRz==0)
{
return ;
}
pts.setLogicalLength(0);
dBlgs.setLogicalLength(0);
//绘制边线2
g3SpRight=g3Sp-v3Tem2.perpVector()*dWRd;
g3EpRight=g3Ep-v3Tem2.perpVector()*dWRd;
pts.append(g3SpRight);
pts.append(g3EpRight);
dBlgs.append(dBlg);
dBlgs.append(0);
iRz=fast_draw_2dpolyline(pts,dBlgs,iClrRd,0,idLift);
if(iRz==0)
{
return ;
}
} |
|