#include "stdafx.h" #include "KTSetting.h" #include "Resource.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif #define APP_DIMSTYLE _T("DimStyle") #define APP_TEXTSTYLE _T("TextStyle") #define APP_LAYER _T("Layer") #define APP_SEEDFILE _T("SEEDFILE") #define KEY_SEEDDWG _T("SeedDwg") #define KT_FILE_INIT _T("PipeInit.ini") #define DELETE_PTR delete KTSetting::KTSetting() { } KTSetting::~KTSetting() { } AcDbObjectId KTSetting::InitDimStyle(LPCTSTR pszDef, AcDbDatabase *pDb) { if (!pDb) pDb = acdbCurDwg(); if (pszDef == NULL) return AcDbObjectId::kNull; AcDbObjectId id = AcDbObjectId::kNull; CString sName; if (!KTSetting::GetDimStyleName(pszDef,sName)) { return id; } AcDbDimStyleTable* pDimTable = NULL; pDb->getDimStyleTable(pDimTable,AcDb::kForRead); if (pDimTable != NULL) { if (Acad::eOk == pDimTable->getAt(sName,id)) { pDimTable->close(); return id; } pDimTable->close(); } //初始化环境 KTSetting::InitFromSeed(pDb); //再次读取 pDimTable = NULL; pDb->getDimStyleTable(pDimTable,AcDb::kForRead); if (pDimTable != NULL) { if (Acad::eOk == pDimTable->getAt(sName,id)) { pDimTable->close(); return id; } pDimTable->close(); } return AcDbObjectId::kNull; } AcDbObjectId KTSetting::InitTextStyle(LPCTSTR pszDef, AcDbDatabase *pDb) { if (!pDb) pDb = acdbCurDwg(); if (pszDef == NULL || _tcslen(pszDef) <= 0) return AcDbObjectId::kNull; CString sName; if (!KTSetting::GetTextStyleName(pszDef, sName)) return AcDbObjectId::kNull; AcDbTextStyleTable* pStTable = NULL; pDb->getTextStyleTable(pStTable,AcDb::kForRead); if (NULL == pStTable) return AcDbObjectId::kNull; AcDbObjectId id; pStTable->getAt(sName, id); pStTable->close(); if (id.isNull()) { //初始化环境 KTSetting::InitFromSeed(pDb); pStTable = NULL; pDb->getTextStyleTable(pStTable, AcDb::kForRead); if (pStTable != NULL) { pStTable->getAt(sName,id); pStTable->close(); } } return id; } AcDbObjectId KTSetting::InitLayer(LPCTSTR pszDef,LPCTSTR pszSize/* = NULL*/,TCHAR chUnit/* = 'M'*/, AcDbDatabase *pDb) { if (!pDb) pDb = acdbCurDwg(); CAcModuleResourceOverride resOverride; if (pszDef == NULL) return AcDbObjectId::kNull; //1.没找到创建 CString sName,sNameFr; if (!KTSetting::GetLayerName(pszDef,sName,sNameFr)) { return AcDbObjectId::kNull; } //2.首先到数据库中找图层名 if (pszSize != NULL && chUnit != _T('\0')) { sName.Replace(_T("%d"),pszSize); sName.Replace(_T('U'),chUnit); } AcDbObjectId idLayer = AcDbObjectId::kNull; AcDbLayerTable* pTable = NULL; BOOL bFind = FALSE; pDb->getLayerTable(pTable,AcDb::kForRead); if (pTable != NULL) { if (Acad::eOk == pTable->getAt(sName,idLayer)) { bFind = TRUE; } pTable->close(); } if (bFind) return idLayer; //根据预签正体字,右侧对应为电子签名 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("sys\\"); sFullPath += KT_FILE_INIT; //3.否则创建图层,从配置文件[KTPSInit.dwg] CString sTip; TCHAR szInitFile[MAX_PATH]; _tcscpy(szInitFile,sFullPath); TCHAR szSeedFile[MAX_PATH]; ::GetPrivateProfileString(APP_SEEDFILE, KEY_SEEDDWG, _T(""), szSeedFile, MAX_PATH, szInitFile); if (RTNORM != acedFindFile(szSeedFile, szSeedFile)) { sTip = szInitFile; sTip.MakeLower(); sTip.Replace(_T(".ini"),_T(".dwg")); _tcscpy(szSeedFile,(LPCTSTR)sTip); //acutPrintf(_T("\n读取环境设置定义文件出错!请确认软件正确安装!")); //return AcDbObjectId::kNull; } //1.从seed dwg 读入设置 AcDbDatabase* pSrcDb = new AcDbDatabase(false); VERIFY(pSrcDb != NULL); pSrcDb->readDwgFile(szSeedFile); AcDbObjectId id; pDb->insert(id,_T("*U"),pSrcDb,true); DELETE_PTR(pSrcDb); //2.迭代LAYER,按MAP 重命名 pTable = NULL; pDb->getLayerTable(pTable,AcDb::kForWrite); if (pTable != NULL) { AcDbLayerTableRecord* pRec = NULL; AcDbLayerTableRecord* pNewLay = NULL; pTable->getAt(sName,pRec,AcDb::kForRead); if (pRec != NULL) { idLayer = pRec->objectId(); pRec->close(); } else { pTable->getAt(sNameFr,pRec,AcDb::kForRead); if (pRec != NULL) { pNewLay = new AcDbLayerTableRecord; pNewLay->copyFrom(pRec); pNewLay->setName(sName); pTable->add(idLayer,pNewLay); pNewLay->close(); pRec->close(); } } pTable->close(); } return idLayer; } AcDbObjectId KTSetting::InitLayer(LPCTSTR pszDef,bool bPoltable, AcDbDatabase *pDb) { if (!pDb) pDb = acdbCurDwg(); CAcModuleResourceOverride resOverride; if (pszDef == NULL) return AcDbObjectId::kNull; //1.没找到创建 CString sName,sNameFr; if (!KTSetting::GetLayerName(pszDef,sName,sNameFr)) { return AcDbObjectId::kNull; } AcDbObjectId idLayer = AcDbObjectId::kNull; AcDbLayerTable* pTable = NULL; BOOL bFind = FALSE; pDb->getLayerTable(pTable,AcDb::kForRead); if (pTable != NULL) { if (Acad::eOk == pTable->getAt(sName,idLayer)) { bFind = TRUE; } pTable->close(); } if (bFind) return idLayer; //读取设置是否显示 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("sys\\"); sFullPath += KT_FILE_INIT; //3.否则创建图层,从配置文件[KTPSInit.dwg] CString sTip; TCHAR szInitFile[MAX_PATH]; _tcscpy(szInitFile,sFullPath); //3.否则创建图层,从配置文件[KTPSInit.dwg] TCHAR szSeedFile[MAX_PATH]; ::GetPrivateProfileString(APP_SEEDFILE, KEY_SEEDDWG, _T(""), szSeedFile, MAX_PATH, szInitFile); if (RTNORM != acedFindFile(szSeedFile, szSeedFile)) { sTip = szInitFile; sTip.MakeLower(); sTip.Replace(_T(".ini"),_T(".dwg")); _tcscpy(szSeedFile,(LPCTSTR)sTip); //acutPrintf(_T("\n读取环境设置定义文件出错!请确认软件正确安装!")); //return AcDbObjectId::kNull; } //1.从seed dwg 读入设置 AcDbDatabase* pSrcDb = new AcDbDatabase(false); VERIFY(pSrcDb != NULL); pSrcDb->readDwgFile(szSeedFile); AcDbObjectId id; pDb->insert(id,_T("*U"),pSrcDb,true); DELETE_PTR(pSrcDb); //2.迭代LAYER,按MAP 重命名 pTable = NULL; pDb->getLayerTable(pTable,AcDb::kForWrite); if (pTable != NULL) { AcDbLayerTableRecord* pRec = NULL; AcDbLayerTableRecord* pNewLay = NULL; pTable->getAt(sName,pRec,AcDb::kForRead); if (pRec != NULL) { idLayer = pRec->objectId(); pRec->close(); } else { pTable->getAt(sNameFr,pRec,AcDb::kForRead); if (pRec != NULL) { pNewLay = new AcDbLayerTableRecord; pNewLay->copyFrom(pRec); pNewLay->setName(sName); pNewLay->setIsPlottable(bPoltable); pTable->add(idLayer,pNewLay); pNewLay->close(); pRec->close(); } } pTable->close(); } return idLayer; } int KTSetting::GetLayerColor(LPCTSTR pszDef) { if (pszDef == NULL) return 0; //1.没找到创建 CString sName,sNameFr; if (!KTSetting::GetLayerName(pszDef,sName,sNameFr)) { return 0; } int nColor = 0; AcDbObjectId idLayer = AcDbObjectId::kNull; AcDbLayerTable* pTable = NULL; BOOL bFind = FALSE; acdbCurDwg()->getLayerTable(pTable,AcDb::kForRead); if (pTable != NULL) { if (Acad::eOk == pTable->getAt(sName,idLayer)) { bFind = TRUE; } pTable->close(); } if (bFind) { AcDbLayerTableRecord* pLayRec = NULL; if ( Acad::eOk == acdbOpenObject((AcDbObject*&)pLayRec,idLayer,AcDb::kForRead)) { nColor = pLayRec->color().colorIndex(); pLayRec->close(); } return nColor; } //读取设置是否显示 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("sys\\"); sFullPath += KT_FILE_INIT; //3.否则创建图层,从配置文件[KTPSInit.dwg] CString sTip; TCHAR szInitFile[MAX_PATH]; _tcscpy(szInitFile,sFullPath); //3.否则创建图层,从配置文件[KTPSInit.dwg] TCHAR szSeedFile[MAX_PATH]; ::GetPrivateProfileString(APP_SEEDFILE, KEY_SEEDDWG, _T(""), szSeedFile, MAX_PATH, szInitFile); if (RTNORM != acedFindFile(szSeedFile, szSeedFile)) { sTip = szInitFile; sTip.MakeLower(); sTip.Replace(_T(".ini"),_T(".dwg")); _tcscpy(szSeedFile,(LPCTSTR)sTip); //acutPrintf(_T("\n读取环境设置定义文件出错!请确认软件正确安装!")); //return AcDbObjectId::kNull; } //1.从seed dwg 读入设置 AcDbDatabase* pSrcDb = new AcDbDatabase(false); VERIFY(pSrcDb != NULL); pSrcDb->readDwgFile(szSeedFile); AcDbObjectId id; acdbCurDwg()->insert(id,_T("*U"),pSrcDb,true); DELETE_PTR(pSrcDb); //2.迭代LAYER,按MAP 重命名 pTable = NULL; acdbCurDwg()->getLayerTable(pTable,AcDb::kForWrite); if (pTable != NULL) { AcDbLayerTableRecord* pRec = NULL; AcDbLayerTableRecord* pNewLay = NULL; pTable->getAt(sName,pRec,AcDb::kForRead); if (pRec != NULL) { nColor = pRec->color().colorIndex(); pRec->close(); } else { pTable->getAt(sNameFr,pRec,AcDb::kForRead); if (pRec != NULL) { nColor = pRec->color().colorIndex(); pRec->close(); } } pTable->close(); } return nColor; } AcDbObjectId KTSetting::InitLineStyle(LPCTSTR pszName, AcDbDatabase*pDb) { if (!pDb) pDb = acdbCurDwg(); AcDbObjectId idRec = AcDbObjectId::kNull; if (pszName == NULL) return idRec; pDb->loadLineTypeFile(pszName,_T("acadiso.lin")); AcDbLinetypeTable* pTable = NULL; pDb->getLinetypeTable(pTable,AcDb::kForRead); if (pTable != NULL) { pTable->getAt(pszName,idRec); pTable->close(); } return idRec; } static BOOL RenameSymbolTableRecs(CMapStringToString& mapName2Name,AcDbSymbolTable* pSymTable) { if (pSymTable != NULL) { AcDbSymbolTableIterator* pIt = NULL; pSymTable->newIterator(pIt); if (pIt != NULL) { AcDbVoidPtrArray arNewRecPtrs; for(pIt->start();!pIt->done();pIt->step()) { AcDbSymbolTableRecord* pRec = NULL; pIt->getRecord(pRec,AcDb::kForWrite); if (pRec != NULL) { TCHAR* pszName = NULL; pRec->getName(pszName); if (pszName != NULL) { CString sKey,sVal; for(POSITION ps = mapName2Name.GetStartPosition();ps != NULL;) { mapName2Name.GetNextAssoc(ps,sKey,sVal); if (sVal.CompareNoCase(pszName) == 0) { AcDbSymbolTableRecord* pRecNew = (AcDbSymbolTableRecord*)pRec->clone(); pRecNew->setName(sKey); arNewRecPtrs.append(pRecNew); } } acdbFree(pszName); } pRec->close(); } } DELETE_PTR(pIt); Acad::ErrorStatus es; pSymTable->upgradeOpen(); for (int i = 0;i < arNewRecPtrs.length();i++) { AcDbSymbolTableRecord* pRecNew = (AcDbSymbolTableRecord*)arNewRecPtrs.at(i); es = pSymTable->add(pRecNew); if (es == Acad::eOk) { pRecNew->close(); } else { delete pRecNew; } } pSymTable->downgradeOpen(); } } return TRUE; } BOOL KTSetting::InitFromSeed(AcDbDatabase *pDb) { if (!pDb) pDb = acdbCurDwg(); //读取设置是否显示 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("sys\\"); sFullPath += KT_FILE_INIT; //3.否则创建图层,从配置文件[KTPSInit.dwg] CString sTip; TCHAR szInitFile[MAX_PATH]; _tcscpy(szInitFile,sFullPath); TCHAR szSeedFile[MAX_PATH]; ::GetPrivateProfileString(APP_SEEDFILE, KEY_SEEDDWG, _T(""), szSeedFile, MAX_PATH, szInitFile); if (RTNORM != acedFindFile(szSeedFile, szSeedFile)) { sTip = szInitFile; sTip.MakeLower(); sTip.Replace(_T(".ini"),_T(".dwg")); _tcscpy(szSeedFile,(LPCTSTR)sTip); //acutPrintf(_T("\n读取环境设置定义文件出错!请确认软件正确安装!")); //return FALSE; } CMapStringToString mapDsName2Name,mapTsName2Name; CStdioFile file; if (file.Open(szInitFile,CFile::modeRead)) { CString sNewName,sOldName,sText; BOOL bReadDimStyle = FALSE,bReadTextStyle = FALSE; while(file.ReadString(sText)) { //Layer Map sText.TrimLeft(_T('[')); sText.TrimRight(_T(']')); if (sText.CompareNoCase(APP_LAYER) == 0) { while(file.ReadString(sText)) { sText.TrimLeft(_T('[')); sText.TrimRight(_T(']')); if (sText.CompareNoCase(APP_DIMSTYLE) == 0) { bReadDimStyle = TRUE; break; } } } //DimSt map if (bReadDimStyle) { while(file.ReadString(sText)) { sText.TrimLeft(_T('[')); sText.TrimRight(_T(']')); if (sText.CompareNoCase(APP_TEXTSTYLE) == 0) { bReadTextStyle = TRUE; break; } int nIndex1 = sText.Find('='); int nIndex2 = sText.Find(':'); if (nIndex1 != -1 && nIndex2 != -1) { sNewName = sText.Mid(nIndex1 + 1,nIndex2 - nIndex1 - 1); sOldName = sText.Mid(nIndex2 + 1); sNewName.TrimRight();sNewName.TrimLeft(); sOldName.TrimLeft();sOldName.TrimRight(); mapDsName2Name.SetAt(sNewName,sOldName); } } } //TextSt map if (bReadTextStyle) { while(file.ReadString(sText)) { int nIndex1 = sText.Find('='); int nIndex2 = sText.Find(':'); if (nIndex1 != -1 && nIndex2 != -1) { sNewName = sText.Mid(nIndex1 + 1,nIndex2 - nIndex1 - 1); sOldName = sText.Mid(nIndex2 + 1); sNewName.TrimRight();sNewName.TrimLeft(); sOldName.TrimLeft();sOldName.TrimRight(); mapTsName2Name.SetAt(sNewName,sOldName); } } } } file.Close(); //1.从seed dwg 读入设置 AcDbDatabase* pSrcDb = new AcDbDatabase(false); VERIFY(pSrcDb != NULL); pSrcDb->readDwgFile(szSeedFile); AcDbObjectId id; pDb->insert(id,_T("*U"),pSrcDb,true); DELETE_PTR(pSrcDb); //2.迭代txtsty 按MAP 重命名 AcDbSymbolTable* pSymTable = NULL; pDb->getTextStyleTable((AcDbTextStyleTable*&)pSymTable,AcDb::kForRead); if (pSymTable != NULL) { RenameSymbolTableRecs(mapTsName2Name,pSymTable); pSymTable->close(); } //3.迭代标注样式,按MAP 重命名 pSymTable = NULL; pDb->getDimStyleTable((AcDbDimStyleTable*&)pSymTable,AcDb::kForRead); if (pSymTable != NULL) { RenameSymbolTableRecs(mapDsName2Name,pSymTable); pSymTable->close(); } return TRUE; } return FALSE; } BOOL KTSetting::GetDimStyleName(LPCTSTR pszDef,CString& sName) { //读取设置是否显示 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("sys\\"); sFullPath += KT_FILE_INIT; //3.否则创建图层,从配置文件[KTPSInit.dwg] CString sTip; TCHAR szInitFile[MAX_PATH]; _tcscpy(szInitFile,sFullPath); sName = _T(""); CString sText; GetPrivateProfileString(APP_DIMSTYLE, pszDef, _T(""), sText.GetBuffer(MAX_PATH), MAX_PATH, szInitFile); sText.ReleaseBuffer(); int iFind = sText.Find(_T(':')); if (iFind < 0) { acutPrintf(_T("\n没有找到环境设置文件!请确认软件正确安装!")); return FALSE; } sName = sText.Left(iFind); sName.TrimLeft(); sName.TrimRight(); return !sName.IsEmpty(); } BOOL KTSetting::GetTextStyleName(LPCTSTR pszDef,CString& sName) { //读取设置是否显示 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("sys\\"); sFullPath += KT_FILE_INIT; //3.否则创建图层,从配置文件[KTPSInit.dwg] CString sTip; TCHAR szInitFile[MAX_PATH]; _tcscpy(szInitFile,sFullPath); sName = _T(""); CString sText; GetPrivateProfileString(APP_TEXTSTYLE, pszDef, _T(""), sText.GetBuffer(MAX_PATH), MAX_PATH, szInitFile); sText.ReleaseBuffer(); int iFind = sText.Find(_T(':')); if (iFind < 0) { acutPrintf(_T("\n没有找到环境设置文件!请确认软件正确安装!")); return FALSE; } sName = sText.Left(iFind); sName.TrimLeft(); sName.TrimRight(); return !sName.IsEmpty(); } BOOL KTSetting::GetLayerName(LPCTSTR pszDef,CString& sName,CString& sNameFr) { //读取设置是否显示 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("sys\\"); sFullPath += KT_FILE_INIT; //3.否则创建图层,从配置文件[KTPSInit.dwg] CString sTip; TCHAR szInitFile[MAX_PATH]; _tcscpy(szInitFile,sFullPath); sName = _T(""); CString sText; GetPrivateProfileString(APP_LAYER, pszDef, _T(""), sText.GetBuffer(MAX_PATH), MAX_PATH, szInitFile); sText.ReleaseBuffer(); int iFind = sText.Find(_T(':')); if (iFind < 0) { acutPrintf(_T("\n没有找到环境设置文件!请确认软件正确安装!")); return FALSE; } sName = sText.Left(iFind); sNameFr = sText.Mid(iFind + 1); sName.TrimLeft(); sName.TrimRight(); sNameFr.TrimLeft(); sNameFr.TrimRight(); return !sName.IsEmpty(); } BOOL KTSetting::GetLayerName(LPCTSTR pszDef,CString& sName) { CString sNameFr; return GetLayerName(pszDef, sName, sNameFr); } BOOL KTSetting::GetKTPsPath(CString& sPath) { TCHAR szPath[MAX_PATH]; DWORD dwRes = ::GetModuleFileName(_hdllInstance,szPath,MAX_PATH); if (dwRes <= 0) return FALSE; LPTSTR pszSub = _tcsrchr(szPath, _T('\\')); if (NULL == pszSub) return FALSE; pszSub[0] = 0; pszSub = _tcsrchr(szPath, _T('\\')); if (NULL == pszSub) return FALSE; pszSub[1] = 0; sPath = szPath; return TRUE; } bool KTSetting::FindESignRecord(AcDbDatabase* pDb,LPCTSTR pszName,AcDbObjectId& idRec) { if (pDb == NULL) return false; AcDbBlockTable* pTbl = NULL; if ( Acad::eOk == pDb->getBlockTable(pTbl,AcDb::kForRead) ) { if ( Acad::eOk == pTbl->getAt(pszName,idRec) ) { pTbl->close(); return true; } pTbl->close(); } return false; } bool KTSetting::LoadESignRecord(AcDbDatabase* pDb,LPCTSTR pszName,AcDbObjectId& idRec) { if (!pDb) pDb = acdbCurDwg(); CString sTempFile; 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("nodedwgs\\"); sTempFile.Format(_T("%s%s.dwg"),sFullPath,pszName); AcDbDatabase db(Adesk::kFalse); if (Acad::eOk == db.readDwgFile(sTempFile)) { db.setInsbase(AcGePoint3d::kOrigin); if ( Acad::eOk == pDb->insert(idRec,pszName,&db) ) { return true; } } return false; }