📄 mydtm.cpp
字号:
// MyDTM.cpp : Initialization functions
#include "StdAfx.h"
#include "StdArx.h"
#include "resource.h"
#include <afxdllx.h>
#include <fstream.h>
#include <math.h>
#include "dbents.h" //三维点
#include "stdio.h"
//#include "dbsymtb.h"
//#include "dbmain.h"
#include "math.h"
#include "geassign.h"//二维点转三维点
#include "acutads.h"//长度 角度
#include "acutads.h"//acutprintf
// This command registers an ARX command.
void AddCommand(const char* cmdGroup, const char* cmdInt, const char* cmdLoc,
const int cmdFlags, const AcRxFunctionPtr cmdProc, const int idLocal = -1);
// NOTE: DO NOT edit the following lines.
//{{AFX_ARX_MSG
void InitApplication();
void UnloadApplication();
//}}AFX_ARX_MSG
// NOTE: DO NOT edit the following lines.
//{{AFX_ARX_ADDIN_FUNCS
//}}AFX_ARX_ADDIN_FUNCS
////////////////////////////////////////////////////////////////////////////
//
// Define the sole extension module object.
AC_IMPLEMENT_EXTENSION_MODULE(MyDTMDLL);
// Now you can use the CAcModuleRecourceOverride class in
// your application to switch to the correct resource instance.
// Please see the ObjectARX Documentation for more details
/////////////////////////////////////////////////////////////////////////////
// DLL Entry Point
extern "C"
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
{
if (dwReason == DLL_PROCESS_ATTACH)
{
// Extension DLL one time initialization
MyDTMDLL.AttachInstance(hInstance);
InitAcUiDLL();
} else if (dwReason == DLL_PROCESS_DETACH) {
// Terminate the library before destructors are called
MyDTMDLL.DetachInstance();
}
return TRUE; // ok
}
/////////////////////////////////////////////////////////////////////////////
// ObjectARX EntryPoint
extern "C" AcRx::AppRetCode
acrxEntryPoint(AcRx::AppMsgCode msg, void* pkt)
{
switch (msg) {
case AcRx::kInitAppMsg:
// Comment out the following line if your
// application should be locked into memory
acrxDynamicLinker->unlockApplication(pkt);
acrxDynamicLinker->registerAppMDIAware(pkt);
InitApplication();
break;
case AcRx::kUnloadAppMsg:
UnloadApplication();
break;
}
return AcRx::kRetOK;
}
/////////////////
//////////////
// Init this application. Register your
// commands, reactors...
void PINCRline();//绘制等高线
void PINCSet();//绘制方格网
void PINCCroute();//平面选线
void PINCBD();//等高线标注
void PINCRBZ();//线路中线标注
void InitApplication()
{
// NOTE: DO NOT edit the following lines.
//{{AFX_ARX_INIT
//}}AFX_ARX_INIT
// TODO: add your initialization functions
acedRegCmds->addCommand("MyDTM","PINCRline","PINCRline",ACRX_CMD_MODAL, PINCRline);
acedRegCmds->addCommand("MyDTM","PINCSet","PINCSet",ACRX_CMD_MODAL,PINCSet);
acedRegCmds->addCommand("MyDTM","PINCCroute","PINCCroute",ACRX_CMD_MODAL,PINCCroute);
acedRegCmds->addCommand("MyDTM","PINCBD","PINCBD",ACRX_CMD_MODAL,PINCBD);
acedRegCmds->addCommand("MyDTM","PINCRBZ","PINCRBZ",ACRX_CMD_MODAL,PINCRBZ);
}
// Unload this application. Unregister all objects
// registered in InitApplication.
void UnloadApplication()
{
// NOTE: DO NOT edit the following lines.
//{{AFX_ARX_EXIT
//}}AFX_ARX_EXIT
// TODO: clean up your application
acedRegCmds->removeGroup("MyDTM");
}
// This functions registers an ARX command.
// It can be used to read the localized command name
// from a string table stored in the resources.
void AddCommand(const char* cmdGroup, const char* cmdInt, const char* cmdLoc,
const int cmdFlags, const AcRxFunctionPtr cmdProc, const int idLocal)
{
char cmdLocRes[65];
// If idLocal is not -1, it's treated as an ID for
// a string stored in the resources.
if (idLocal != -1) {
HMODULE hModule = GetModuleHandle("0MyDTM.arx");
// Load strings from the string table and register the command.
::LoadString(hModule, idLocal, cmdLocRes, 64);
acedRegCmds->addCommand(cmdGroup, cmdInt, cmdLocRes, cmdFlags, cmdProc);
} else
// idLocal is -1, so the 'hard coded'
// localized function name is used.
acedRegCmds->addCommand(cmdGroup, cmdInt, cmdLoc, cmdFlags, cmdProc);
}
int aint[150000][2];
float fdou[150000][3];
char s[100];
#define Npt 5
ads_point pt[4];
void PINCRline()//读取等高线
{
int j;
int i=0;
ifstream MyFile("DZXTEM.DAT",ios::out);
while(!MyFile.eof())
{
MyFile>>aint[i][0]>>s>>fdou[i][0]>>fdou[i][1]>>fdou[i][2]>>aint[i][1];//把文件数据读到数组中
i++;
}
MyFile.close();
AcGePoint3d startpt,endpt;
AfxMessageBox("程序运行中...",MB_OK);
if(i>0)
{
for(j=0;j<i+1;j++)
{
AcDbLayerTable *pLayerTable;//创建一个新层
acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pLayerTable, AcDb::kForWrite);//打开层表,打开方式为只读
AcDbLayerTableRecord *pLayerTableRecord=new AcDbLayerTableRecord;//初始化层表记录对象
pLayerTableRecord->setName("RECD");//设定层表记录的名称
//层表记录的其他属性(例如颜色、线性等)若未设置都取缺省值
//如:颜色未White、线性为Continous等
//并将层表记录的Id保存到pLayerId作为函数的返回值
//将新建的层表记录添加到层表中
//AcDbObjectId pLayerId;
//pLayerTable->add(pLayerId,pLayerTableRecord);
pLayerTable->add(pLayerTableRecord);//将新建的层表记录添加到层表中
pLayerTable->close();//关闭层表
pLayerTableRecord->close();//层表记录对象
if( ((aint[j][1]==31)||(aint[j][1]==21))&&((aint[j+1][1]==32)||(aint[j+1][1]==22)) )
{
AcGePoint3d startpt(fdou[j][0],fdou[j][1],0);
AcGePoint3d endpt(fdou[j+1][0],fdou[j+1][1],0);
AcDbLine*pLine=new AcDbLine(startpt,endpt);//
if(aint[j][0]==12)
{
pLine->setColorIndex(5);//蓝色
}
else
{
pLine->setColorIndex(3);
}//绿色
AcDbBlockTable *pBlockTable;//创建块表
acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pBlockTable,AcDb::kForRead);
//打开模型空间块表段,获得当前块表记录,并关闭块表
AcDbBlockTableRecord *pBlockTableRecord;
pBlockTable->getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForWrite);
pBlockTable->close();
AcDbObjectId lineId;//创建对象ID
pBlockTableRecord->appendAcDbEntity(lineId,pLine);//向当前块表记录中添加直线对象
pBlockTableRecord->close();
//关闭块表记录及直线对象
pLine->setLayer("RECD");
pLine->close();
}
if( ((aint[j][1]==32)||(aint[j][1]==22))&&((aint[j+1][1]==32)||(aint[j+1][1]==22)) )
{
AcGePoint3d startpt(fdou[j][0],fdou[j][1],0);
AcGePoint3d endpt(fdou[j+1][0],fdou[j+1][1],0);
AcDbLine*pLine=new AcDbLine(startpt,endpt);//连线
if(aint[j][0]==12)
{
pLine->setColorIndex(5);//蓝色
}
else
{
pLine->setColorIndex(3);
}//绿色
AcDbBlockTable *pBlockTable;
acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pBlockTable,AcDb::kForRead);
AcDbBlockTableRecord *pBlockTableRecord;
pBlockTable->getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForWrite);
pBlockTable->close();
AcDbObjectId lineId;
pBlockTableRecord->appendAcDbEntity(lineId,pLine);
pBlockTableRecord->close();
pLine->setLayer("RECD");
pLine->close();
}
if( ((aint[j][1]==32)||(aint[j][1]==22))&&((aint[j+1][1]==33)||(aint[j+1][1]==23)) )
{
AcGePoint3d startpt(fdou[j][0],fdou[j][1],0);
AcGePoint3d endpt(fdou[j+1][0],fdou[j+1][1],0);
AcDbLine*pLine=new AcDbLine(startpt,endpt);
if(aint[j][0]==12)
{
pLine->setColorIndex(5);//蓝色
}
else
{
pLine->setColorIndex(3);
}//绿色
AcDbBlockTable *pBlockTable;
acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pBlockTable,AcDb::kForRead);
AcDbBlockTableRecord *pBlockTableRecord;
pBlockTable->getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForWrite);
pBlockTable->close();
AcDbObjectId lineId;
pBlockTableRecord->appendAcDbEntity(lineId,pLine);
pBlockTableRecord->close();
pLine->close();
}
else if(((aint[j][1]==33)||(aint[j][1]==23))&&((aint[j+1][1]==31)||(aint[j+1][1]==21)))
{
AcGePoint3d startpt(fdou[j+1][0],fdou[j+1][1],0);
AcGePoint3d endpt(fdou[j+2][0],fdou[j+2][1],0);
AcDbLine*pLine=new AcDbLine(startpt,endpt);
if(aint[j][0]==12)
{
pLine->setColorIndex(5);//蓝色
}
else
{
pLine->setColorIndex(3);
}//绿色
AcDbBlockTable *pBlockTable;
acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pBlockTable,AcDb::kForRead);
AcDbBlockTableRecord *pBlockTableRecord;
pBlockTable->getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForWrite);
pBlockTable->close();
AcDbObjectId lineId;
pBlockTableRecord->appendAcDbEntity(lineId,pLine);
pBlockTableRecord->close();
pLine->close();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -