971 lines
23 KiB
C++
971 lines
23 KiB
C++
#include "StdAfx.h"
|
||
#include "StdArx.h"
|
||
#include "acedxref.h"
|
||
#include "KTCadUtility.h"
|
||
#include "KTCadTempOverrides.h"
|
||
|
||
#ifndef _ttof
|
||
#define _ttof(pszVal) _tcstod((pszVal), NULL)
|
||
#endif
|
||
|
||
int SplitDirSegments(LPCTSTR pszFullDir,CStringArray& arFields)
|
||
{
|
||
//_T("e:\\mydwgdir\\mydwgdir\\sample\\");
|
||
CString sText = pszFullDir;
|
||
sText.TrimLeft();
|
||
sText.TrimRight();
|
||
|
||
CString sTemp;
|
||
for (int i = 0;i < sText.GetLength();i++)
|
||
{
|
||
if (sText.GetAt(i) == _T('\\') )
|
||
{
|
||
arFields.Add(sTemp);
|
||
sTemp = _T("");
|
||
}
|
||
else
|
||
{
|
||
sTemp += sText.GetAt(i);
|
||
if (i == sText.GetLength() - 1)
|
||
{
|
||
arFields.Add(sTemp);
|
||
}
|
||
}
|
||
}
|
||
return arFields.GetSize();
|
||
}
|
||
|
||
DWORD CreateFolder(LPCTSTR pszFullDir)
|
||
{
|
||
//create comp info global data
|
||
PSECURITY_DESCRIPTOR pSec = (PSECURITY_DESCRIPTOR)::LocalAlloc(LMEM_FIXED, SECURITY_DESCRIPTOR_MIN_LENGTH);
|
||
if(pSec == NULL)
|
||
{
|
||
return GetLastError();
|
||
}
|
||
|
||
if(!::InitializeSecurityDescriptor(pSec, SECURITY_DESCRIPTOR_REVISION))
|
||
{
|
||
LocalFree(pSec);
|
||
return GetLastError();
|
||
}
|
||
|
||
if(!::SetSecurityDescriptorDacl(pSec, TRUE, NULL, TRUE))
|
||
{
|
||
LocalFree(pSec);
|
||
return GetLastError();
|
||
}
|
||
|
||
SECURITY_ATTRIBUTES attr;
|
||
attr.bInheritHandle = FALSE;
|
||
attr.lpSecurityDescriptor = pSec;
|
||
attr.nLength = sizeof(SECURITY_ATTRIBUTES);
|
||
|
||
CStringArray arFields;
|
||
SplitDirSegments(pszFullDir,arFields);
|
||
|
||
CString sDir,sFullDir;
|
||
for(int i = 0;i < arFields.GetSize();i++)
|
||
{
|
||
sDir = arFields.GetAt(i);
|
||
sFullDir += sDir;
|
||
sFullDir += _T("\\");
|
||
|
||
if (i > 0)
|
||
{
|
||
CreateDirectory(sFullDir,&attr);
|
||
}
|
||
}
|
||
LocalFree(pSec);
|
||
return 0;
|
||
}
|
||
|
||
/*
|
||
(defun c:dxload()
|
||
|
||
(setq po (getpoint "拾取一点插入地形,右键退出:"))
|
||
(while (not (null po))
|
||
(setq x (car po))
|
||
;(princ x)
|
||
(setq y (car (cdr po)))
|
||
;(princ y)
|
||
(calth500 y x)
|
||
(setq strmapname500 (strcat "//hzgis/dwg_zx$/500/" strmapname ".dwg"))
|
||
(calth1000 y x)
|
||
(setq strmapname1000 (strcat "//hzgis/dwg$/1000/" strmapname ".dwg"))
|
||
;(if (findfile strmapname500) (command "xref" "" strmapname500 "0,0,0" "" "" "") (progn (princ "\n对不起,500地形图库中没有该幅地形图\n.") (princ)))
|
||
;(if (findfile strmapname1000) (command "xref" "" strmapname1000 "0,0,0" "" "" "") (progn (princ "\n对不起,1000地形图库中没有该幅地形图\n.")(princ)) )
|
||
|
||
(if (findfile strmapname1000) (command "xref" "" strmapname1000 "0,0,0" "" "" "") (progn (if (findfile strmapname500) (command "xref" "" strmapname500 "0,0,0" "" "" "") (progn (princ "\n对不起,500地形图库中没有该幅地形图\n.")(princ)) )(princ "\n对不起,1000地形图库中没有该幅地形图\n.") (princ)))
|
||
|
||
|
||
(setq po (getpoint "拾取一点插入地形,右键退出:"))
|
||
)
|
||
(princ)
|
||
)
|
||
*/
|
||
|
||
extern Acad::ErrorStatus AddToModelSpace(AcDbEntity* pEnt,AcDbDatabase* pDb,bool bClose);
|
||
|
||
void calth500(double fx,double fy,CString& strmapname)
|
||
{
|
||
//; calculate the first letter of the sheetID
|
||
int iState1 = 0;
|
||
if (fy > 80000 && fx > 80000)
|
||
iState1 = 1;
|
||
if (fx > 80000 && fy < 80000)
|
||
iState1 = 4;
|
||
if (fy < 80000 && fx < 80000)
|
||
iState1 = 3;
|
||
if (fx < 80000 && fy > 80000)
|
||
iState1 = 2;
|
||
|
||
strmapname.Format(_T("%d"),iState1);//象限
|
||
|
||
// 象限-xnynABCD
|
||
//calculate the second and third letter of the sheetID
|
||
int iState2 = (int)(fabs( (fx - 80000) / 1000 ) );//
|
||
int iState3 = (int)(fabs( (fy - 80000) / 800 ) );//
|
||
|
||
CString sTemp = _T("");
|
||
if ( (iState2 + 1) < 10)//0--9
|
||
{
|
||
strmapname += _T("0");
|
||
sTemp.Format(_T("%d"),iState2+1);
|
||
strmapname += sTemp;
|
||
//08
|
||
}
|
||
else
|
||
{
|
||
sTemp.Format(_T("%d"),iState2+1);
|
||
strmapname += sTemp;
|
||
//10
|
||
}
|
||
|
||
if ( (iState3 + 1) < 10)
|
||
{
|
||
strmapname += _T("0");
|
||
sTemp.Format(_T("%d"),iState3+1);
|
||
strmapname += sTemp;
|
||
}
|
||
else
|
||
{
|
||
sTemp.Format(_T("%d"),iState3+1);
|
||
strmapname += sTemp;
|
||
}
|
||
|
||
//lower left point within the 1:2000
|
||
double fxstart = iState2 * 1000;
|
||
double fystart = iState3 * 800;
|
||
|
||
//the offset within 1:2000
|
||
double fxoffset = fabs(80000 - fx) - fxstart;
|
||
double fyoffset = fabs(80000 - fy) - fystart;
|
||
|
||
if (iState1 == 2 || iState1 == 3 )
|
||
fxoffset -= 800;
|
||
|
||
if (iState1 == 3 || iState1 == 4)
|
||
fyoffset -= 1000;
|
||
|
||
//the forth letter with of sheetID
|
||
iState2 = (int)(fabs(fxoffset / 200));
|
||
iState3 = (int)(fabs(fyoffset / 250));
|
||
|
||
int iState4 = (iState2 * 4 - 13) + iState3;
|
||
if (iState4 > 9)
|
||
{
|
||
sTemp.Format(_T("%d"),iState4);
|
||
strmapname += sTemp;
|
||
}
|
||
else
|
||
{
|
||
strmapname += _T("0");
|
||
sTemp.Format(_T("%d"),abs(iState4));
|
||
strmapname += sTemp;
|
||
}
|
||
|
||
if (strmapname.GetAt(0) == _T('2'))
|
||
{
|
||
strmapname.SetAt(0,_T('4'));
|
||
return;
|
||
}
|
||
|
||
if (strmapname.GetAt(0) == _T('4'))
|
||
{
|
||
strmapname.SetAt(0,_T('2'));
|
||
return;
|
||
}
|
||
}
|
||
|
||
void calth1000(double fx,double fy,CString& strmapname)
|
||
{
|
||
//; calculate the first letter of the sheetID
|
||
int iState1 = 0;
|
||
if (fy > 80000 && fx > 80000)
|
||
iState1 = 1;
|
||
if (fx > 80000 && fy < 80000)
|
||
iState1 = 4;
|
||
if (fy < 80000 && fx < 80000)
|
||
iState1 = 3;
|
||
if (fx < 80000 && fy > 80000)
|
||
iState1 = 2;
|
||
|
||
strmapname.Format(_T("%d"),iState1);
|
||
|
||
// 象限-xnynABCD
|
||
//calculate the second and third letter of the sheetID
|
||
int iState2 = (int)(fabs( (fx - 80000) / 1000 ));//
|
||
int iState3 = (int)(fabs( (fy - 80000) / 800));//
|
||
|
||
CString sTemp = _T("");
|
||
if ( (iState2 + 1) < 10)//0--8
|
||
{
|
||
strmapname += _T("0");
|
||
sTemp.Format(_T("%d"),iState2+1);
|
||
strmapname += sTemp;
|
||
//08
|
||
}
|
||
else
|
||
{
|
||
sTemp.Format(_T("%d"),iState2+1);
|
||
strmapname += sTemp;
|
||
//10
|
||
}
|
||
|
||
if ( (iState3 + 1) < 10)//0--8
|
||
{
|
||
strmapname += _T("0");
|
||
sTemp.Format(_T("%d"),iState3+1);
|
||
strmapname += sTemp;
|
||
}
|
||
else
|
||
{
|
||
sTemp.Format(_T("%d"),iState3+1);
|
||
strmapname += sTemp;
|
||
}
|
||
|
||
//; lower left point within the 1:2000
|
||
double fxstart = iState2 * 1000;
|
||
double fystart = iState3 * 800;
|
||
|
||
double fxoffset = fabs(fx - 80000) - fxstart;
|
||
double fyoffset = fabs(fy - 80000) - fystart;
|
||
|
||
if (iState1 == 2 || iState1 == 3)
|
||
fxoffset -= 1000;
|
||
|
||
if (iState1 == 3 || iState1 == 4)
|
||
fyoffset -= 800;
|
||
|
||
|
||
//; the offset within 1:2000
|
||
iState2 = (int)(fabs(fyoffset / 400));
|
||
iState3 = (int)(fabs(fxoffset / 500));
|
||
|
||
CString iState4 = _T("");//A?
|
||
if (iState2 == 0 && iState3 == 0)
|
||
iState4 = _T("C");
|
||
if (iState2 == 1 && iState3 == 0)
|
||
iState4 = _T("A");
|
||
if (iState2 == 0 && iState3 == 1)
|
||
iState4 = _T("D");
|
||
if (iState2 == 1 && iState3 == 1)
|
||
iState4 = _T("B");
|
||
|
||
strmapname += iState4;
|
||
|
||
if (strmapname.GetAt(0) == _T('2'))
|
||
{
|
||
strmapname.SetAt(0,_T('4'));
|
||
return;
|
||
}
|
||
|
||
if (strmapname.GetAt(0) == _T('4'))
|
||
{
|
||
strmapname.SetAt(0,_T('2'));
|
||
return;
|
||
}
|
||
}
|
||
|
||
void EraseBlockRecord(CString& _strmapname1000)
|
||
{
|
||
AcDbDatabase* pDb = acdbCurDwg();
|
||
|
||
AcDbBlockTable* pTbl = NULL;
|
||
if (Acad::eOk == pDb->getBlockTable(pTbl,AcDb::kForRead))
|
||
{
|
||
AcDbBlockTableRecord* pRec = NULL;
|
||
if (Acad::eOk == pTbl->getAt(_strmapname1000,pRec,AcDb::kForWrite))
|
||
{
|
||
if (!pRec->isFromExternalReference())
|
||
{
|
||
AcDbObjectIdArray arIds;
|
||
pRec->getBlockReferenceIds(arIds);
|
||
|
||
AcDbEntity* pEnt = NULL;
|
||
for (int ii = 0;ii < arIds.length();ii++)
|
||
{
|
||
if (Acad::eOk == acdbOpenAcDbEntity(pEnt,arIds.at(ii),AcDb::kForWrite))
|
||
{
|
||
pEnt->erase();
|
||
pEnt->close();
|
||
}
|
||
}
|
||
pRec->erase();
|
||
}
|
||
pRec->close();
|
||
}
|
||
pTbl->close();
|
||
}
|
||
}
|
||
|
||
void KTDxload()
|
||
{
|
||
//文件复制到 Dwghelp/1000下
|
||
TCHAR szfileName[MAX_PATH],szFullPath[MAX_PATH];
|
||
GetModuleFileName(_hdllInstance,szfileName,MAX_PATH);
|
||
|
||
TCHAR drive[_MAX_DRIVE] = _T(""),
|
||
dir[_MAX_DIR] = _T(""),
|
||
fname[_MAX_FNAME] = _T(""),
|
||
ext[_MAX_EXT] = _T("");
|
||
|
||
//e:\,program files\autodesk\,myarx,exe
|
||
_tsplitpath(szfileName, drive, dir, fname, ext);
|
||
_tcscpy(szFullPath, drive);
|
||
_tcscat(szFullPath, dir);
|
||
|
||
CString sFullPath = szFullPath;
|
||
sFullPath.TrimRight(_T('\\'));
|
||
|
||
//上一级目录
|
||
int nPos = sFullPath.ReverseFind(_T('\\'));
|
||
CString sPath = sFullPath.Mid(0,nPos + 1);
|
||
|
||
sFullPath = sPath + _T("1000\\");
|
||
//CreateFolder(sFullPath);
|
||
|
||
CString sLicenseIni = sPath + _T("sys\\product.ini");
|
||
TCHAR szGisPath[MAX_PATH];
|
||
_tcscpy(szGisPath,_T("//hzgis/dwg$/1000/"));
|
||
::GetPrivateProfileString(_T("GIS"), _T("PATH"), _T(""), szGisPath, MAX_PATH, sLicenseIni);
|
||
CString sGisPath = szGisPath;
|
||
|
||
ads_point pt1,pt;
|
||
while(true)
|
||
{
|
||
int nRes = acedGetPoint(NULL,_T("\n拾取一点插入地形,右键退出:"),pt1);
|
||
if (nRes != RTNORM)
|
||
{
|
||
return;
|
||
}
|
||
//pt[X] = 79250;
|
||
//pt[Y] = 80200;
|
||
|
||
//测试
|
||
/*CString sName = _T("hzgis\\dwg_zx$\\500\\123.dwg");
|
||
TCHAR szFile[MAX_PATH];
|
||
memset(szFile,0,MAX_PATH);
|
||
|
||
nRes = acedFindFile(sName,szFile);
|
||
acutPrintf(_T("\n%d : %s"),nRes,szFile);
|
||
*/
|
||
|
||
acdbUcs2Wcs(pt1,pt,false);
|
||
|
||
double dX = pt[X];
|
||
double dY = pt[Y];
|
||
|
||
CString strmapname;
|
||
calth500(dX,dY,strmapname);
|
||
//strmapname = _T("demo");//测试
|
||
CString strmapname500,_strmapname500;
|
||
|
||
_strmapname500 = strmapname;
|
||
strmapname500.Format(_T("//hzgis/dwg_zx$/500/%s.dwg"),strmapname);
|
||
|
||
strmapname = _T("");
|
||
calth1000(dX,dY,strmapname);
|
||
//strmapname = _T("demo");//测试
|
||
CString strmapname1000,_strmapname1000;
|
||
_strmapname1000 = strmapname;
|
||
//strmapname1000.Format(_T("//hzgis/dwg$/1000/%s.dwg"),strmapname);
|
||
|
||
if (sGisPath.Find(_T("//hzgis")) != -1)
|
||
{
|
||
sGisPath.TrimRight(_T('/'));
|
||
strmapname1000.Format(_T("%s/%s.dwg"),sGisPath,strmapname);
|
||
}
|
||
else
|
||
{
|
||
sGisPath.TrimRight(_T('\\'));
|
||
strmapname1000.Format(_T("%s\\%s.dwg"),sGisPath,strmapname);
|
||
}
|
||
|
||
//TCHAR szDwgFile500[MAX_PATH];
|
||
//TCHAR szDwgFile1000[MAX_PATH];
|
||
|
||
//根据相对路径找文件
|
||
//int nRes1 = acedFindFile(strmapname500,szDwgFile500);
|
||
//int nRes2 = acedFindFile(strmapname1000,szDwgFile1000);
|
||
//if (nRes2 == RTNORM)
|
||
{
|
||
//完整路径的文件
|
||
//strmapname500 = szDwgFile500;
|
||
//strmapname1000 = szDwgFile1000;
|
||
|
||
//LISP
|
||
/*(if (findfile strmapname1000)
|
||
(command "xref" "" strmapname1000 "0,0,0" "" "" "")
|
||
(progn (if (findfile strmapname500)
|
||
(command "xref" "" strmapname500 "0,0,0" "" "" "")
|
||
(progn (princ "\n对不起,500地形图库中没有该幅地形图\n.")
|
||
(princ)) )(princ "\n对不起,1000地形图库中没有该幅地形图\n.") (princ)))*/
|
||
|
||
CString sCmd;
|
||
Acad::ErrorStatus es = Acad::eNotImplementedYet;
|
||
//if (nRes2 == RTNORM)
|
||
{
|
||
AcGeScale3d scale(1.0,1.0,1.0);
|
||
|
||
//判断对方图默认为米单位
|
||
AcDb::UnitsValue nOther = kUnitsMeters;
|
||
|
||
AcDbDatabase db(Adesk::kFalse);
|
||
if (Acad::eOk == (es = db.readDwgFile(strmapname1000)))
|
||
{
|
||
nOther = db.insunits();
|
||
}
|
||
else
|
||
{
|
||
acutPrintf(_T("\n错误:%d 不能访问文件 %s "),es,strmapname1000);
|
||
|
||
CFileFind find;
|
||
if (!find.FindFile(strmapname1000))
|
||
{
|
||
acutPrintf(_T("\n错误:没有找到文件 %s "),strmapname1000);
|
||
}
|
||
else
|
||
{
|
||
acutPrintf(_T("\n找到文件 %s "),strmapname1000);
|
||
}
|
||
continue;;
|
||
}
|
||
|
||
struct resbuf rb;
|
||
acedGetVar(_T("INSUNITS"),&rb);
|
||
|
||
//提示,如果当前地形图单位不是米,分米,厘米,毫米,无单位,给与提示
|
||
if (rb.resval.rint != AcDb::kUnitsMillimeters &&
|
||
rb.resval.rint != AcDb::kUnitsCentimeters &&
|
||
rb.resval.rint != AcDb::kUnitsUndefined)
|
||
{
|
||
AfxMessageBox(_T("当前图形单位不是米单位!不能插入地形图!\n请运行主菜单: 格式/单位 调整为米单位!"));
|
||
break;
|
||
}
|
||
|
||
if (nOther != rb.resval.rint)
|
||
{
|
||
if (rb.resval.rint == AcDb::kUnitsMeters) //当前图是米制
|
||
{
|
||
if (nOther == AcDb::kUnitsMillimeters)//毫米
|
||
{
|
||
//对方毫米
|
||
scale.set(1000.0,1000.0,1000.0);
|
||
}
|
||
else if (nOther == AcDb::kUnitsCentimeters)//厘米单位
|
||
{
|
||
//对方厘米
|
||
scale.set(100.0,100.0,100.0);
|
||
}
|
||
else if (nOther == AcDb::kUnitsDecimeters)//分米单位
|
||
{
|
||
//分米
|
||
scale.set(10.0,10.0,10.0);
|
||
}
|
||
else if (nOther == AcDb::kUnitsUndefined)
|
||
{
|
||
//对方无单位
|
||
scale.set(1000.0,1000.0,1000.0);
|
||
}
|
||
else if (nOther == AcDb::kUnitsMeters)
|
||
{
|
||
//对方米
|
||
scale.set(1.0,1.0,1.0);
|
||
}
|
||
}
|
||
else if(rb.resval.rint == AcDb::kUnitsMillimeters)//当前是毫米
|
||
{
|
||
if (nOther == AcDb::kUnitsMillimeters)//毫米
|
||
{
|
||
//对方毫米
|
||
scale.set(1.0,1.0,1.0);
|
||
}
|
||
else if (nOther == AcDb::kUnitsCentimeters)//厘米单位
|
||
{
|
||
//对方厘米
|
||
scale.set(0.1,0.1,0.1);
|
||
}
|
||
else if (nOther == AcDb::kUnitsDecimeters)//分米单位
|
||
{
|
||
//对方分米
|
||
scale.set(0.01,0.01,0.01);
|
||
}
|
||
else if (nOther == AcDb::kUnitsUndefined)
|
||
{
|
||
//对方无单位,按毫米
|
||
scale.set(1.0,1.0,1.0);
|
||
}
|
||
else if (nOther == AcDb::kUnitsMeters)
|
||
{
|
||
//对方米
|
||
scale.set(0.001,0.001,0.001);
|
||
}
|
||
}
|
||
else if(rb.resval.rint == AcDb::kUnitsCentimeters)//当前是厘米单位
|
||
{
|
||
if (nOther == AcDb::kUnitsMillimeters)//毫米
|
||
{
|
||
//对方毫米
|
||
scale.set(10.0,10.0,10.0);
|
||
}
|
||
else if (nOther == AcDb::kUnitsCentimeters)//厘米单位
|
||
{
|
||
//对方毫米
|
||
scale.set(1.0,1.0,1.0);
|
||
}
|
||
else if (nOther == AcDb::kUnitsDecimeters)//分米单位
|
||
{
|
||
//对方分米
|
||
scale.set(0.1,0.1,0.1);
|
||
}
|
||
else if (nOther == AcDb::kUnitsUndefined)//无单位
|
||
{
|
||
//对方无单位
|
||
scale.set(10.0,10.0,10.0);
|
||
}
|
||
else if (nOther == AcDb::kUnitsMeters)
|
||
{
|
||
//对方米
|
||
scale.set(0.01,0.01,0.01);
|
||
}
|
||
}
|
||
else if(rb.resval.rint == AcDb::kUnitsCentimeters)//当前是分米单位
|
||
{
|
||
if (nOther == AcDb::kUnitsMillimeters)//毫米
|
||
{
|
||
//对方毫米
|
||
scale.set(100.0,100.0,100.0);
|
||
}
|
||
else if (nOther == AcDb::kUnitsCentimeters)//厘米单位
|
||
{
|
||
//对方毫米
|
||
scale.set(10.0,10.0,10.0);
|
||
}
|
||
else if (nOther == AcDb::kUnitsDecimeters)//分米单位
|
||
{
|
||
//对方毫米
|
||
scale.set(1.0,1.0,1.0);
|
||
}
|
||
else if (nOther == AcDb::kUnitsUndefined)
|
||
{
|
||
//对方无单位,按毫米
|
||
scale.set(100.0,100.0,100.0);
|
||
}
|
||
else if (nOther == AcDb::kUnitsMeters)
|
||
{
|
||
//对方米
|
||
scale.set(0.1,0.1,0.1);
|
||
}
|
||
}
|
||
else if(rb.resval.rint == AcDb::kUnitsUndefined)//当前图无单位
|
||
{
|
||
if (nOther == AcDb::kUnitsMillimeters)//毫米
|
||
{
|
||
//对方毫米
|
||
scale.set(1.0,1.0,1.0);
|
||
}
|
||
else if (nOther == AcDb::kUnitsCentimeters)//厘米单位
|
||
{
|
||
//对方毫米
|
||
scale.set(0.1,0.1,0.1);
|
||
}
|
||
else if (nOther == AcDb::kUnitsDecimeters)//分米单位
|
||
{
|
||
//对方分米
|
||
scale.set(0.01,0.01,0.01);
|
||
}
|
||
else if (nOther == AcDb::kUnitsUndefined)
|
||
{
|
||
//对方无单位,按毫米
|
||
scale.set(1.0,1.0,1.0);
|
||
}
|
||
else if (nOther == AcDb::kUnitsMeters)
|
||
{
|
||
//对方米
|
||
scale.set(0.001,0.001,0.001);
|
||
}
|
||
}
|
||
}
|
||
|
||
//去除非参照的块定义,和删除对应的Ref
|
||
EraseBlockRecord(_strmapname1000);
|
||
|
||
AcDbObjectId idRec1,idRec2;
|
||
es = acedXrefAttach(strmapname1000,_strmapname1000,&idRec1,NULL,NULL,&scale);
|
||
if (es == Acad::eFileAccessErr)
|
||
{
|
||
acutPrintf(_T("\n错误:%d 不能访问文件 %s "),es,strmapname1000);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
void KTdfdel()
|
||
{
|
||
//文件复制到 Dwghelp/1000下
|
||
TCHAR szfileName[MAX_PATH],szFullPath[MAX_PATH];
|
||
GetModuleFileName(_hdllInstance,szfileName,MAX_PATH);
|
||
|
||
TCHAR drive[_MAX_DRIVE] = _T(""),
|
||
dir[_MAX_DIR] = _T(""),
|
||
fname[_MAX_FNAME] = _T(""),
|
||
ext[_MAX_EXT] = _T("");
|
||
|
||
//e:\,program files\autodesk\,myarx,exe
|
||
_tsplitpath(szfileName, drive, dir, fname, ext);
|
||
_tcscpy(szFullPath, drive);
|
||
_tcscat(szFullPath, dir);
|
||
|
||
CString sFullPath = szFullPath;
|
||
sFullPath.TrimRight(_T('\\'));
|
||
|
||
//上一级目录
|
||
int nPos = sFullPath.ReverseFind(_T('\\'));
|
||
CString sPath = sFullPath.Mid(0,nPos + 1);
|
||
|
||
sFullPath = sPath + _T("1000\\");
|
||
CreateFolder(sFullPath);
|
||
|
||
CString sLicenseIni = sPath + _T("sys\\product.ini");
|
||
TCHAR szGisPath[MAX_PATH];
|
||
_tcscpy(szGisPath,_T("//hzgis/dwg$/1000/"));
|
||
::GetPrivateProfileString(_T("GIS"), _T("PATH"), _T(""), szGisPath, MAX_PATH, sLicenseIni);
|
||
CString sGisPath = szGisPath;
|
||
|
||
ads_point pt1,pt;
|
||
while(true)
|
||
{
|
||
int nRes = acedGetPoint(NULL,_T("\n拾取一点卸载地形,右键退出:"),pt1);
|
||
if (nRes != RTNORM)
|
||
{
|
||
return;
|
||
}
|
||
|
||
acdbUcs2Wcs(pt1,pt,false);
|
||
|
||
double dX = pt[X];
|
||
double dY = pt[Y];
|
||
|
||
CString strmapname;
|
||
calth500(dX,dY,strmapname);
|
||
//strmapname = _T("demo");//测试
|
||
CString strmapname500,_strmapname500;
|
||
|
||
_strmapname500 = strmapname;
|
||
strmapname500.Format(_T("hzgis\\dwg_zx$\\500\\%s.dwg"),strmapname);
|
||
|
||
calth1000(dX,dY,strmapname);
|
||
//strmapname = _T("demo");//测试
|
||
CString strmapname1000,_strmapname1000;
|
||
|
||
_strmapname1000 = strmapname;
|
||
|
||
if (sGisPath.Find(_T("//hzgis")) != -1)
|
||
{
|
||
sGisPath.TrimRight(_T('/'));
|
||
strmapname1000.Format(_T("%s/%s.dwg"),sGisPath,strmapname);
|
||
}
|
||
else
|
||
{
|
||
sGisPath.TrimRight(_T('\\'));
|
||
strmapname1000.Format(_T("%s\\%s.dwg"),sGisPath,strmapname);
|
||
}
|
||
|
||
//TCHAR szDwgFile500[MAX_PATH];
|
||
//TCHAR szDwgFile1000[MAX_PATH];
|
||
//int nRes1 = acedFindFile(strmapname500,szDwgFile500);
|
||
//int nRes2 = acedFindFile(strmapname1000,szDwgFile1000);
|
||
//if (nRes1 == RTNORM && nRes2 == RTNORM)
|
||
{
|
||
//strmapname500 = szDwgFile500;
|
||
//strmapname1000 = szDwgFile1000;
|
||
//if (nRes2 == RTNORM)
|
||
{
|
||
//LISP
|
||
/*(if (findfile strmapname1000)
|
||
(command "xref" "d" mpname1000)
|
||
(progn (if (findfile strmapname500)
|
||
(command "xref" "d" mpname500) (princ))))*/
|
||
|
||
//acedPostCommand(_T("filedia\n0\n"));
|
||
|
||
//CString sCmd;
|
||
//(command "xref" "d" mpname1000)
|
||
//sCmd.Format(_T("-xref\nd\n%s\n"),_strmapname1000);
|
||
//acedPostCommand(sCmd);
|
||
|
||
acedXrefDetach(_strmapname1000);
|
||
//if (nRes1 == RTNORM)
|
||
{
|
||
//sCmd.Format(_T("-xref\nd\n%s\n"),_strmapname500);
|
||
//acedPostCommand(sCmd);
|
||
//acedXrefDetach(_strmapname500);
|
||
}
|
||
//acedPostCommand(_T("filedia\n1\n"));
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
//(RTOS number [mode [precision] ] )
|
||
double rtos(double dn,int nm,int np)
|
||
{
|
||
//nm 2,3
|
||
struct resbuf rbu;
|
||
acedGetVar(_T("LUPREC"),&rbu);
|
||
|
||
if (np != 0)
|
||
rbu.resval.rint = np;
|
||
|
||
//%.nf
|
||
CString sUn,sTmp;
|
||
sUn.Format(_T(".%df"),rbu.resval.rint);
|
||
sUn.Insert(0,_T('%'));
|
||
|
||
sTmp.Format(sUn,dn);
|
||
return _ttof(sTmp);
|
||
}
|
||
|
||
void FormatTo9Numbstr(double dx,CString& sX)
|
||
{
|
||
sX.Format(_T("%.3f"),dx);
|
||
}
|
||
|
||
void KTzbload()
|
||
{
|
||
double dScale = 1.0;
|
||
ads_point pt1;
|
||
|
||
int nRes = acedGetPoint(NULL,_T("请选择要标注的点::"),pt1);
|
||
if (nRes != RTNORM)
|
||
{
|
||
return;
|
||
}
|
||
CKTTempSetSysVar var(_T("osnap"),0);
|
||
|
||
ads_point pt2;
|
||
nRes = acedGetPoint(pt1,_T("请选择标注方向:"),pt2);
|
||
if (nRes != RTNORM)
|
||
{
|
||
return;
|
||
}
|
||
|
||
CString sX,sY;
|
||
FormatTo9Numbstr(pt1[X],sX);
|
||
FormatTo9Numbstr(pt1[Y],sY);
|
||
|
||
AcDbObjectId idSt = CKTCadUtility::InitTextStyle(_T("romand"));
|
||
|
||
AcGeVector3d vt1(1,1,0),vt2(-1,1,0),vt3(-1,-1,0),vt4(1,-1,0);
|
||
AcGeVector3d vtDir,vtText;
|
||
vtDir = asPnt3d(pt2) - asPnt3d(pt1);
|
||
|
||
if (vtDir.x > 1.e-10 && vtDir.y > 1.e-10)//I
|
||
{
|
||
vtDir = vt1;
|
||
vtText = AcGeVector3d::kXAxis;
|
||
}
|
||
else if (vtDir.x < 1.e-10 && vtDir.y > 1.e-10)//II
|
||
{
|
||
vtDir = vt2;
|
||
vtText = -AcGeVector3d::kXAxis;
|
||
}
|
||
else if (vtDir.x < 1.e-10 && vtDir.y < 1.e-10)//III
|
||
{
|
||
vtDir = vt3;
|
||
vtText = -AcGeVector3d::kXAxis;
|
||
}
|
||
else if (vtDir.x > 1.e-10 && vtDir.y < 1.e-10)//IV
|
||
{
|
||
vtDir = vt4;
|
||
vtText = AcGeVector3d::kXAxis;
|
||
}
|
||
|
||
AcDbCircle* pCir = new AcDbCircle;
|
||
pCir->setCenter(asPnt3d(pt1));
|
||
pCir->setRadius(2.0 * dScale);
|
||
pCir->setNormal(AcGeVector3d::kZAxis);
|
||
AddToModelSpace(pCir,acdbCurDwg(),true);
|
||
|
||
vtDir.normalize();
|
||
vtDir *= 17.0 * dScale;
|
||
|
||
//杭州要求 XY数值调换
|
||
CString sTemp;
|
||
sTemp = sX;
|
||
sX = sY;
|
||
sY = sTemp;
|
||
|
||
sX.Insert(0,_T("X="));
|
||
sY.Insert(0,_T("Y="));
|
||
|
||
AcGiTextStyle style;
|
||
fromAcDbTextStyle(style,idSt);
|
||
style.setTextSize(5.0 * dScale);
|
||
style.setXScale(1.0);
|
||
AcGePoint2d ptMin,ptMax;
|
||
style.extentsBox(sX,Adesk::kFalse,sX.GetLength(),Adesk::kTrue,ptMin,ptMax);
|
||
double dLen1 = ptMax.x - ptMin.x;
|
||
|
||
style.extentsBox(sX,Adesk::kFalse,sY.GetLength(),Adesk::kTrue,ptMin,ptMax);
|
||
double dLen2 = ptMax.x - ptMin.x;
|
||
double dLen = __max(dLen1,dLen2) + 2 * dScale;//文字的起点水平距离
|
||
|
||
AcGePoint3d ptGe[3];
|
||
ptGe[0] = asPnt3d(pt1);
|
||
ptGe[1] = asPnt3d(pt1) + vtDir;
|
||
ptGe[2] = ptGe[1] + vtText * dLen;
|
||
|
||
vtText.normalize();
|
||
AcGePoint3d ptText[2];
|
||
|
||
if (vtText.isCodirectionalTo(AcGeVector3d::kXAxis))
|
||
{
|
||
ptText[0] = ptGe[1];
|
||
ptText[0] += vtText * 2 * dScale;
|
||
ptText[0] += AcGeVector3d::kYAxis * 2 * dScale;
|
||
|
||
ptText[1] = ptGe[1];
|
||
ptText[1] += vtText * 2 * dScale;
|
||
ptText[1] -= AcGeVector3d::kYAxis * 7 * dScale;//文字高度5
|
||
}
|
||
else
|
||
{
|
||
ptText[0] = ptGe[2];
|
||
ptText[0] += AcGeVector3d::kYAxis * 2 * dScale;
|
||
|
||
ptText[1] = ptGe[2];
|
||
ptText[1] -= AcGeVector3d::kYAxis * 7 * dScale;//文字高度5
|
||
}
|
||
|
||
AcDbPolyline* pPl = new AcDbPolyline;
|
||
for (int i = 0;i < 3;i++)
|
||
{
|
||
pPl->addVertexAt(i,ptGe[i].convert2d(AcGePlane::kXYPlane));
|
||
}
|
||
AddToModelSpace(pPl,acdbCurDwg(),true);
|
||
|
||
AcDbText* pText = new AcDbText;
|
||
pText->setTextStyle(idSt);
|
||
pText->setTextString(sX);
|
||
pText->setPosition(ptText[0]);
|
||
pText->setHeight(5.0 * dScale);
|
||
pText->setWidthFactor(1.0);
|
||
AddToModelSpace(pText,acdbCurDwg(),true);
|
||
|
||
pText = new AcDbText;
|
||
pText->setTextStyle(idSt);
|
||
pText->setTextString(sY);
|
||
pText->setPosition(ptText[1]);
|
||
pText->setHeight(5.0 * dScale);
|
||
pText->setWidthFactor(1.0);
|
||
AddToModelSpace(pText,acdbCurDwg(),true);
|
||
}
|
||
|
||
void KTthload()
|
||
{
|
||
double dScale = 1.0;
|
||
ads_point pt1,pt;
|
||
|
||
int nRes = acedGetPoint(NULL,_T("拾取一点插入图号,右键退出:"),pt1);
|
||
if (nRes != RTNORM)
|
||
{
|
||
return;
|
||
}
|
||
|
||
acdbUcs2Wcs(pt1,pt,false);
|
||
|
||
double dx = pt[X];
|
||
double dy = pt[Y];
|
||
|
||
CString strmapname;
|
||
calth1000(dx,dy,strmapname);
|
||
|
||
struct resbuf rbu;
|
||
acedGetVar(_T("LUPREC"),&rbu);
|
||
|
||
CString sUn,sTmp;
|
||
sUn.Format(_T(".%df"),rbu.resval.rint);
|
||
sUn.Insert(0,_T('%'));
|
||
sTmp = sUn + _T(",") + sUn;
|
||
|
||
CString spi1;
|
||
spi1.Format(sTmp,dx,dy);
|
||
|
||
AcDbObjectId idSt = CKTCadUtility::InitTextStyle(_T("romand"));
|
||
|
||
//sTmp.Format(_T("text\ns\nromand\n%s\n10\n\n%s\n"),spi1,strmapname);
|
||
//acedPostCommand(sTmp);
|
||
|
||
int nPos = spi1.Find(_T(','));
|
||
dx = _ttof(spi1.Mid(0,nPos));
|
||
dy = _ttof(spi1.Mid(nPos + 1));
|
||
pt[X] = dx;
|
||
pt[Y] = dy;
|
||
pt[Z] = 0.0;
|
||
|
||
ads_point pt2;
|
||
acdbUcs2Wcs(pt,pt2,false);
|
||
|
||
AcDbText* pText = new AcDbText;
|
||
pText->setTextStyle(idSt);
|
||
pText->setTextString(strmapname);
|
||
pText->setHeight(10.0 * dScale);
|
||
pText->setWidthFactor(1.0);
|
||
pText->setPosition(asPnt3d(pt2));
|
||
AddToModelSpace(pText,acdbCurDwg(),true);
|
||
|
||
AcGiTextStyle style;
|
||
fromAcDbTextStyle(style,idSt);
|
||
style.setTextSize(10.0 * dScale);
|
||
style.setXScale(1.0);
|
||
|
||
AcGePoint2d ptMin,ptMax;
|
||
style.extentsBox(strmapname,Adesk::kFalse,strmapname.GetLength(),Adesk::kTrue,ptMin,ptMax);
|
||
|
||
double dDist = (ptMax.x - ptMin.x + 2); //加上0.25个字符宽度
|
||
|
||
AcGePoint2d ptGe[2];
|
||
ptGe[0] = asPnt2d(pt2);
|
||
ptGe[1] = ptGe[0];
|
||
ptGe[1].x += dDist;
|
||
|
||
ptGe[0].y -= 2.0;
|
||
ptGe[1].y -= 2.0;
|
||
|
||
AcDbPolyline* pPl = new AcDbPolyline;
|
||
pPl->addVertexAt(0,ptGe[0]);
|
||
pPl->addVertexAt(1,ptGe[1]);
|
||
pPl->setColorIndex(3);
|
||
pPl->setConstantWidth(0.7);
|
||
AddToModelSpace(pPl,acdbCurDwg(),true);
|
||
}
|
||
|
||
//三维地形
|
||
void EW_SWDXCmdFnc()
|
||
{
|
||
|
||
} |