📄 stdafx.cpp
字号:
// StdAfx.cpp : source file that includes just the standard includes
// StdAfx.pch will be the pre-compiled header
// StdAfx.obj will contain the pre-compiled type information
#include "StdAfx.h"
#include "StdArx.h"
#include "rxdebug.h"
// RX Includes
#include "acdb.h" // acdb definitions
#include "rxregsvc.h" // ARX linker
#include "dbapserv.h" // Host application services
#include "aced.h" // aced stuff
#include "adslib.h" // RXADS definitions
#include "acdocman.h" // MDI document manager
// 向AUTOCAD 数据库中添加实体对象的通用函数
AcDbObjectId AddEntityToDbs(AcDbEntity *pEntity)
{
acDocManager->lockDocument(acDocManager->curDocument(),AcAp::kWrite);
AcDbObjectId objId;
AcDbBlockTable *pBlockTable;
acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable,AcDb::kForRead);
AcDbBlockTableRecord *pSpaceRecord;
pBlockTable->getAt(ACDB_MODEL_SPACE, pSpaceRecord,AcDb::kForWrite);
pSpaceRecord->appendAcDbEntity(objId, pEntity);
pSpaceRecord->close();
pBlockTable->close();
pEntity->close();
acDocManager->unlockDocument(acDocManager->curDocument());
return objId;
}
AcDbObjectId makeline(AcGePoint3d& startPt,AcGePoint3d& endPt,int icolor,AcDb::LineWeight lw,char *LayerName, char *LineType)
{
AcDbLine *pLine = new AcDbLine(startPt, endPt);
if(icolor>=0)pLine->setColorIndex(icolor);
pLine->setLineWeight(lw);
AcDbLayerTableRecord *pLayerTableRecord;
AcDbObjectId LayerTabRecordId;
AcDbLayerTable *pLayerTable;
AcDbObjectId ltypeObjId;
acdbHostApplicationServices()->workingDatabase()->getLayerTable(pLayerTable,AcDb::kForWrite);
if(LayerName==NULL)
LayerName="XBMarker";
if(pLayerTable->getAt(LayerName,LayerTabRecordId) != Acad::eOk)
{
pLayerTableRecord=new AcDbLayerTableRecord;
pLayerTableRecord->setName(LayerName);
pLayerTable->getAt(LayerName,LayerTabRecordId);
pLayerTable->add(LayerTabRecordId,pLayerTableRecord);
pLayerTableRecord->close();
}
pLine->setLayer(LayerTabRecordId);
pLayerTable->close();
if(LineType!=NULL)
{
acdbHostApplicationServices()->workingDatabase()->
loadLineTypeFile(LineType,"acadiso.lin");//
pLine->setLinetype(LineType);
}
AcDbObjectId LId;
LId = AddEntityToDbs(pLine) ;
return LId;
}
AcDbObjectId makeline(AcGePoint3d& startPt,AcGePoint3d& endPt)
{
AcDbLine *pLine = new AcDbLine(startPt,endPt);
AcDbObjectId LId ;
LId=AddEntityToDbs(pLine) ;
return LId ;
}
// 绘文本
AcDbObjectId maketext(AcGePoint3d& pos, ACHAR* ctext,double ang,double texth ,int icolor,int mode,ACHAR * textStyle,char *cLayerName)
{
AcDbObjectId TId;
AcDbText *pText = new AcDbText;
AcDbTextStyleTable *pTextStyleTbl;
AcDbObjectId pTextStyleTblId;
acdbHostApplicationServices()->workingDatabase()->getTextStyleTable(pTextStyleTbl,AcDb::kForWrite);
if(pTextStyleTbl->getAt(textStyle,pTextStyleTblId)!= Acad::eOk)
{
AcDbTextStyleTableRecord *pTextStyleTblRcd=new AcDbTextStyleTableRecord;
pTextStyleTblRcd->setName(textStyle);
ACHAR TextStyleFile[256];
pTextStyleTblRcd->setFileName(TextStyleFile);
pTextStyleTblRcd->setBigFontFileName(TextStyleFile);
pTextStyleTblRcd->setFont(_T("standard.shx"),0,0,134,2); //rs9.shx
pTextStyleTblRcd->setFileName(textStyle);
pTextStyleTblRcd->setFont(textStyle,0,0,134,2);
pTextStyleTblRcd->setXScale(0.8);
pTextStyleTbl->add(pTextStyleTblRcd);
pTextStyleTblRcd->close();
pTextStyleTbl->getAt(textStyle,pTextStyleTblId);
}
pTextStyleTbl->close();
if (mode==1) // 左对齐
{ pText->setHorizontalMode(AcDb::kTextLeft); }
else if (mode==2) // 中对齐
{ pText->setHorizontalMode(AcDb::kTextCenter); }
else if (mode==3) // 中对齐
{ pText->setHorizontalMode(AcDb::kTextMid); }
else if (mode==5)
{
pText->setHorizontalMode(AcDb::kTextLeft);
pText->setVerticalMode(AcDb::kTextTop);
}
else // // 右对齐
{
pText->setHorizontalMode(AcDb::kTextRight); };
pText->setColorIndex(icolor);
if (mode==1) { pText->setPosition(pos); }
else { pText->setAlignmentPoint(pos); };
pText->setTextStyle(pTextStyleTblId);
pText->setRotation(ang);
pText->setHeight(texth);
pText->setWidthFactor(0.8);
pText->setTextString(ctext);
/*
//layer///////////////////////////////////////////////////////////////////
AcDbLayerTableRecord *pLayerTableRecord;
AcDbObjectId LayerTabRecordId;
AcDbLayerTable *pLayerTable;
AcDbObjectId ltypeObjId;
acdbHostApplicationServices()->workingDatabase()->getLayerTable(pLayerTable,AcDb::kForWrite);
ACHAR *LayerName;
LayerName=_T("XBMarker");
if(pLayerTable->getAt(LayerName,LayerTabRecordId) != Acad::eOk)
{
pLayerTableRecord=new AcDbLayerTableRecord;
pLayerTableRecord->setName(LayerName);
pLayerTable->getAt(LayerName,LayerTabRecordId);
pLayerTable->add(LayerTabRecordId,pLayerTableRecord);
pLayerTableRecord->close();
}
pText->setLayer(LayerTabRecordId);
pLayerTable->close();
//////////////////////////////////////////////////////////////////////////
*/
pText->setLayer(cLayerName);
TId= AddEntityToDbs(pText);
return TId;
}
double fwj(AcGePoint3d startPt,AcGePoint3d endPt)//与Y轴夹角
{
ads_point spt,ept;
spt[X]=startPt.x;
spt[Y]=startPt.y;
ept[X]=endPt.x;
ept[Y]=endPt.y;
double ang=ads_angle(spt,ept);//与X轴夹角
ang=2.5*PI-ang;
if(ang>2*PI)ang-=2*PI;
return ang;
}
//由里程组里程字串
char* LCchr(char *GH,double lc,int NLC,int mode)
{
long int zlc,gl;
double bm;
char ch1[100],ch[100];
bm=fabs(lc);
zlc=(long int)((fabs(lc)+0.0001)/1000.0);
bm=bm-zlc*1000.0;
if (fabs(bm-1000.0)<=pow(0.1,NLC)*0.5)
{
zlc+=1;
}
//gl 公里数
gl=zlc;
//将公里数转为字符
ads_rtos(gl,2,0,ch1);
if(gl!=0)
strcpy(ch,GH);
else
strcpy(ch,"");
if (lc<0 && gl>0)
strcat(ch,"-");
if (gl!=0)
strcat(ch,ch1);
bm=bm+1000.0;
ads_rtos(bm,2,NLC,ch1);
ch1[0] = '+';
if(gl == 0 && lc <0)
ch1[0] = '-';
strcat(ch,ch1);
return &ch[0];
}
AcDbEntity* selectEntity(AcDbObjectId& eId, AcDb::OpenMode openMode)
{
ads_name en;
ads_point pt;
int rc = ads_entsel("\nSelect an entity: ", en, pt);
if (rc != RTNORM)
{
ads_printf("Nothing selected.\n", rc);
return NULL;
}
Acad::ErrorStatus es = acdbGetObjectId(eId, en);
if (es != Acad::eOk)
{
ads_printf("Either acdbGetObjectId or ads_entsel failed: "
"Entity name <%lx,%lx>, error %d.\n", en[0], en[1], es);
return NULL;
}
AcDbEntity* entObj;
es = acdbOpenObject(entObj, eId, openMode);
if (es != Acad::eOk)
{
ads_printf("acdbOpenObject failed with error %d.\n", es);
return NULL;
}
return entObj;
}
int CCWTest(AcGePoint3d dStartPt,AcGePoint3d dEndPt,AcGePoint3d theTestPt)
{
double dResult;
double x1,x2,y1,y2;
x1 = dStartPt.x - theTestPt.x;
y1 = dStartPt.y - theTestPt.y;
x2 = dEndPt.x - theTestPt.x;
y2 = dEndPt.y - theTestPt.y;
dResult = x1*y2-x2*y1;
if (dResult>0.0)
return TURN_LEFT;
else
return TURN_RIGHT;
}
//创建新层 先监测是否该层已经存在,如果不存在则创建新层
bool createLayer(char * cLayerName)
{
AcDbLayerTable *pLayerTable=NULL;
acdbHostApplicationServices()->workingDatabase()->getLayerTable(pLayerTable,AcDb::kForWrite);
AcDbLayerTableIterator *pLayerItor=NULL;
pLayerTable->newIterator(pLayerItor);
AcDbLayerTableRecord *pLayerRec = NULL;
AcDbLayerTableRecord *pNewLayer = NULL;
char *pNameTemp;
int nLayerCount=0;
bool bFound = false;
//寻找层记录
for (;!pLayerItor->done();pLayerItor->step())
{
pLayerItor->getRecord(pLayerRec,AcDb::kForRead);
pLayerRec->getName(pNameTemp);
int nResult = strcmp(cLayerName,pNameTemp);
if (nResult==0)
bFound = true;
pLayerRec->close();
nLayerCount++;
}
if (!bFound)
{
pNewLayer = new AcDbLayerTableRecord;
pNewLayer->setName(cLayerName);
AcDbObjectId newLayerId;
pLayerTable->add(newLayerId,pNewLayer);
pNewLayer->close();
}
pLayerTable->close();
delete pLayerItor;
pLayerItor = NULL;
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -