#include "stdafx.h" #include "ZHSBLibDlg.h" #include "coretools.h" #include "KTModelLayoutXData.h" #include "dbvisualstyle.h" #include "KTCadUtility.h" #ifndef ZH_SB_BIM_REC #define ZH_SB_BIM_REC _T("ZH_SB_BIM_REC") #endif #ifndef ZH_SB_BLK_NAME #define ZH_SB_BLK_NAME _T("ZH_SB_BLK_NAME") #endif #ifndef ZH_SB_BLK_EXT #define ZH_SB_BLK_EXT _T("ZH_SB_BLK_EXT") #endif #ifndef ZH_SB_FLAG #define ZH_SB_FLAG _T("ZH_SB_FLAG") #endif #ifndef ZH_SB_NAME #define ZH_SB_NAME _T("ZH_SB_NAME") #endif #ifndef ZH_SB_REF_FIELD #define ZH_SB_REF_FIELD _T("ZH_SB_REF_FIELD") #endif namespace { bool SaveBitmapToFile(CBitmap *bitmap, AcDbBlockTableRecord::PreviewIcon &icon) { CString sPath(FilePath::getSystemTemporaryFolder() + _T("\\a_b_cc__.bmp")); CImage img; img.Attach(*bitmap); HRESULT hr = img.Save(sPath); img.Detach(); if (!FAILED(hr) && _taccess(sPath, 0x0) == 0x0) { CFile fi; if (fi.Open(sPath, CFile::modeRead)) { icon.setLogicalLength(fi.GetLength()); fi.Read(icon.asArrayPtr(), fi.GetLength()); } } return !icon.isEmpty(); } HBITMAP PreviewIcon2Bitmap(const AcDbBlockTableRecord::PreviewIcon &icon) { CString sPath(FilePath::getSystemTemporaryFolder() + _T("\\a_v_v.bmp")); CFile file(sPath, CFile::modeReadWrite | CFile::modeCreate); if (file.m_hFile) { file.Write((void *)icon.asArrayPtr(), icon.length()); file.Close(); return (HBITMAP)::LoadImage(0, sPath, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); } return NULL; } void ScreenCopy(const AcGePoint3d &wptTL, const AcGePoint3d &wptBR, AcDbBlockTableRecord::PreviewIcon &icon) { CView *pView = acedGetAcadDwgView(); if (!pView) return; CDC *pDc = pView->GetDC(); if (!pDc) return; CRect rect; if (wptTL == wptBR) pView->GetClientRect(rect); else rect.SetRect(CKTCadUtility::Wcs2Pixel(wptTL), CKTCadUtility::Wcs2Pixel(wptBR)); CBitmap bitmap; bitmap.CreateCompatibleBitmap(pDc, rect.Width(), rect.Height()); CDC memDc; memDc.CreateCompatibleDC(pDc); CBitmap *pOldBitmap = memDc.SelectObject(&bitmap); memDc.BitBlt(0 , 0 , rect.Width() , rect.Height() , pDc , rect.left , rect.top , SRCCOPY); CMemFile file; SaveBitmapToFile(&bitmap, icon); memDc.SelectObject(pOldBitmap); memDc.DeleteDC(); ::ReleaseDC(pView->GetSafeHwnd(), pDc->GetSafeHdc()); } void SetViewportDir(const AcGeVector3d &dir , const AcGePoint3d &ptMax , const AcGePoint3d &ptMin) { AcGePlane plan(AcGePoint3d::kOrigin, dir); AcGePoint2d pt1 = ptMin.convert2d(plan); AcGePoint2d pt2 = ptMax.convert2d(plan); AcGePoint2d pt(CoreTools::MidPt(pt1, pt2)); AcDbViewTableRecord VTR; VTR.setViewDirection(dir); VTR.setCenterPoint(pt); VTR.setWidth(abs(pt1.x - pt2.x)); VTR.setHeight(abs(pt1.y - pt2.y)); acedSetCurrentView(&VTR, NULL); } void SetVistualStyle(LPCTSTR pszVSName) { if (!pszVSName) return; AcDbObjectId idVs(AcDbObjectId::kNull); AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase(); if (!pDb) return; AcDbDictionary *pVsD = NULL; if (pDb->getVisualStyleDictionary(pVsD, AcDb::kForRead) != Acad::eOk) return; AcDbVisualStyle *pVs(NULL); if (Acad::eOk == pVsD->getAt(pszVSName, (AcDbObject *&)pVs, AcDb::kForRead)) { idVs = pVs->objectId(); pVs->close(); } pVsD->close(); if (idVs.isValid()) acdbSetViewportVisualStyle(idVs); } std::shared_ptr getZhSbFileFromDb(CUIISQLiteServer &db, const int &fid) { CString sPath(FilePath::getSystemTemporaryFolder() + _T("\\temp_$_$_.dwg")); if (_taccess(sPath, 0x0) == 0x0) ::DeleteFile(sPath); CString sSQL(_T("")); sSQL.Format(_T("select package from dwg_package where ID='%d'"), fid); if (db.GetSelBlob(sSQL, sPath)) { AcDbDatabase *p(new AcDbDatabase(false)); if (p->readDwgFile(sPath, AcDbDatabase::kTryForReadShare) == Acad::eOk) return std::shared_ptr(p); else DELETE_PTR(p); } return std::shared_ptr(); } bool readXDataFromZhSbFile(AcDbDatabase *pDb, AecDbObjXDataMap &xData) { if (!pDb) return false; return KTModelLayoutXData::ReadModelNameObjXData(ZH_SB_BIM_REC, xData, pDb) == FALSE ? false : true; } bool writeXDataFromZhSbFile(AcDbDatabase *pDb, AecDbObjXDataMap &xData) { if (!pDb) return false; if (KTModelLayoutXData::WriteModelNameObjXData(ZH_SB_BIM_REC, xData, pDb)) #if ARX==18 return pDb->saveAs(pDb->originalFileName(), true, AcDb::kDHL_CURRENT) == Acad::eOk; #else return pDb->saveAs(pDb->originalFileName(), true, AcDb::kDHL_1027) == Acad::eOk; #endif return false; } bool updateDwgPackage(CUIISQLiteServer &db, const int &fid, LPCTSTR pszPath) { if (!pszPath) return false; CString sql(_T("")); sql.Format(_T("update dwg_package set package=? where id='%d'"), fid); return db.UpdateBlob(sql, pszPath) == 0 ? false : true; } bool addBimRecToZhSbFile(CUIISQLiteServer &db, const int &fid, const SH_BIM_REC &rec) { std::shared_ptr pDb = getZhSbFileFromDb(db, fid); AecDbObjXDataMap xDataMap; if (!readXDataFromZhSbFile(pDb.get(), xDataMap)) return false; xDataMap.SetAt(rec.first, rec.second); if (!writeXDataFromZhSbFile(pDb.get(), xDataMap)) return false; return updateDwgPackage(db, fid, pDb->originalFileName()); } bool delBimRecToZhSbFile(CUIISQLiteServer &db, const int &fid, LPCTSTR sKey) { std::shared_ptr pDb = getZhSbFileFromDb(db, fid); AecDbObjXDataMap xDataMap; if (!readXDataFromZhSbFile(pDb.get(), xDataMap)) return false; xDataMap.RemoveAt(sKey); if (!writeXDataFromZhSbFile(pDb.get(), xDataMap)) return false; return updateDwgPackage(db, fid, pDb->originalFileName()); } CString getZhSbNameFromDb(CUIISQLiteServer &db, const int &fid) { CString sSQL(_T("")); sSQL.Format(_T("SELECT dwg_folder.[Folder], dwg_class.[Class], dwg_package.[Name]") _T(" FROM") _T(" dwg_class INNER JOIN dwg_folder") _T(" ON dwg_folder.[ID] = dwg_class.[IDFolder]") _T(" INNER JOIN dwg_package") _T(" ON dwg_package.[IDClass] = dwg_class.[ID]") _T(" WHERE dwg_package.[ID] = '%d'"), fid); std::vector> v; db.GetSelDataEx(sSQL, v); if (v.empty()) return _T(""); if (v[0].size() < 2) return _T(""); CString ss(_T("")); ss.Format(_T("%s\\%s\\%s"), v[0][0], v[0][1], v[0][2]); ss.Replace(_T('\\'), _T('-')); return ss; } bool getBimsFromZhSbFile(AcDbDatabase *pDb, SH_BIM_BLOCK &bims) { if (!pDb) return false; AecDbObjXDataMap xDataMap; readXDataFromZhSbFile(pDb, xDataMap); CString s; AecDbObjXDataMap::CIt it(xDataMap.Begin()); for (; it != xDataMap.End(); ++it) { if (xDataMap.GetAt(it->first, s)) bims.push_back(std::make_pair(it->first, s)); } return !bims.empty(); } bool getBimsFromZhSbId(CUIISQLiteServer &db, const int &fid, SH_BIM_BLOCK &bims) { std::shared_ptr pDb = getZhSbFileFromDb(db, fid); return getBimsFromZhSbFile(pDb.get(), bims); } void insertZHSB(CUIISQLiteServer &db, const int &fid) { CString sBlkName = getZhSbNameFromDb(db, fid); if (sBlkName.IsEmpty()) return; AcDbDatabase *pCurDb = acdbHostApplicationServices()->workingDatabase(); if (!pCurDb) return; std::shared_ptr pDb = getZhSbFileFromDb(db, fid); if (!pDb) return; CString sFlag(_T("_Z_")); AcDbObjectId blkId; AcDbBlockTableRecordPointer pCurRcd(sBlkName, pCurDb, AcDb::kForRead); if (pCurRcd.openStatus() != Acad::eOk) { // 不存在,插入 AecDbObjXDataMap xPipeInit; // 如果当前图纸没有初始设置 if (!KTModelLayoutXData::ReadModelXData(KT_PIPEINIT, xPipeInit)) { // 从 pDb 中读取,写入当前数据库 if (KTModelLayoutXData::ReadModelXData(KT_PIPEINIT, xPipeInit, pDb.get())) KTModelLayoutXData::WriteModelXData(KT_PIPEINIT, xPipeInit); } AcDbBlockTableRecordPointer pNewRcd(ZH_SB_BLK_NAME, pDb.get(), AcDb::kForRead); if (pNewRcd.openStatus() != Acad::eOk) return; Adesk::Int16 nVal = acdbCurDwg()->useri4(); acdbCurDwg()->setUseri4(KEY_NOPROTECT); AcGePoint3d pt = pNewRcd->origin(); AcDbDatabase *pTempDb(NULL); if (pDb->wblock(pTempDb, pNewRcd->id()) == Acad::eOk) { if (pCurDb->insert(blkId, sBlkName, pTempDb) == Acad::eOk) { AecDbObjXDataMap xdata; xdata.SetAt(sFlag, pt.z); xdata.Write(blkId, sFlag); } } DELETE_PTR(pTempDb); acdbCurDwg()->setUseri4(nVal); } else { // 已经存在 blkId = pCurRcd->id(); pCurRcd->close(); } if (!blkId.isValid()) return; ads_real dElev(.0); { AecDbObjXDataMap xdata; if (xdata.Read(blkId, sFlag)) xdata.GetAt(sFlag, dElev); CString sPrompts; sPrompts.Format(_T("\n输入高程<%.2fmm>:"), dElev); acedGetDist(NULL, sPrompts, &dElev); } ads_point adsPtIns; if (acedGetPoint(NULL, _T("\n选择插入点:"), adsPtIns) != RTNORM) return; AcGePoint3d ptIns(asPnt3d(adsPtIns)); CoreTools::UCS2WCS(ptIns, ptIns); ptIns.z = dElev; // 做块 AcDbBlockReference *pRef(new AcDbBlockReference(ptIns, blkId)); CString sZHSBName = sBlkName.Right(sBlkName.GetLength() - 1 - sBlkName.ReverseFind(_T('-'))); SH_BIM_BLOCK bims; getBimsFromZhSbFile(pDb.get(), bims); CoreTools::setBimDatas(pRef, bims); CoreTools::setBimData(pRef, KEY_NAME, sZHSBName); // 为块打上“组合设备”的标记 AecDbObjXDataMap map; map.SetAt(ZH_SB_FLAG, TRUE); map.SetAt(ZH_SB_NAME, sZHSBName); map.Write(pRef, ZH_SB_REF_FIELD); CoreTools::AddToModelSpace(pRef); } } BEGIN_MESSAGE_MAP(CZHSBLibDlg, CModelLibDlgBase) END_MESSAGE_MAP() CZHSBLibDlg::CZHSBLibDlg(LPCTSTR pszDir , LPCTSTR pszFile) : CModelLibDlgBase(_T("组合设备"), pszDir, pszFile) , m_sTablePrefix(_T("dwg")) , m_sFileSuffix(_T(".zhequ")) , m_sRootName(_T("组合设备")) { } BOOL CZHSBLibDlg::OnInitDialog() { CModelLibDlgBase::OnInitDialog(); CWnd *pWnd = GetDlgItem(IDC_INSERT); if (pWnd) pWnd->SetWindowText(_T("插入")); return TRUE; } bool CZHSBLibDlg::initSqliteDB() { if (!m_sqlDB.InitADOServer(FilePath::GetSysDir() + _T("\\shzhsb.db"))) { AfxMessageBox(_T("打开数据库Aec3DMep.db失败!")); EndDialog(-1); return true; } return false; } void CZHSBLibDlg::refreshLocalFileList(HTREEITEM hItem) { helper_refreshLocalFileList(hItem, m_sTablePrefix); } void CZHSBLibDlg::refreshBimPropertyList(int idx) { if (idx == -1) return; int fid = m_ctrlLocalFileList.GetItemData(idx); m_ctrlBimPropertyList.DeleteAllItems(); int nRow(0); SH_BIM_BLOCK blk; getBimsFromZhSbId(m_sqlDB, fid, blk); for (size_t i(0); i < blk.size(); ++i) { SH_BIM_REC &rec(blk[i]); nRow = m_ctrlBimPropertyList.InsertItem(nRow, rec.first); m_ctrlBimPropertyList.SetItemText(nRow, 1, rec.second); ++nRow; } } void CZHSBLibDlg::LbnSelchangeFileList() { std::vector v; getSelectedFiles(v); if (v.size() > 1) return; AcAxDocLock lock; int idx = m_ctrlLocalFileList.GetCurSel(); refreshBimPropertyList(idx); m_iSelectFileID = m_ctrlLocalFileList.GetItemData(idx); CStatic *pPic = (CStatic *)GetDlgItem(IDC_PREVIEW_PIC); if (!pPic) return; std::shared_ptr pDb = getZhSbFileFromDb(m_sqlDB, m_iSelectFileID); if (!pDb) return; AcDbBlockTableRecordPointer pRcd(ZH_SB_BLK_NAME, pDb.get(), AcDb::kForRead); if (pRcd.openStatus() != Acad::eOk) return; AcDbBlockTableRecord::PreviewIcon icon; pRcd->getPreviewIcon(icon); if (icon.isEmpty()) return; if (m_hBitmap) ::DeleteObject(m_hBitmap); m_hBitmap = PreviewIcon2Bitmap(icon); if (!m_hBitmap) return; CImage img; img.Attach(m_hBitmap); CRect rect; pPic->GetWindowRect(rect); CPoint ptTL(rect.TopLeft()); ScreenToClient(&ptTL); // 得到绘制区域的左上角点的对话框客户端坐标 int controlWidth(rect.Width()), controlHeight(rect.Height()); int imgWidth(img.GetWidth()), imgHeight(img.GetHeight()); CDC *pDc = GetDC(); // 绘制在对话框上 CDC memDc; memDc.CreateCompatibleDC(pDc); CBitmap bmp; bmp.CreateCompatibleBitmap(pDc, controlWidth, controlHeight); CBitmap *pOldbmp = memDc.SelectObject(&bmp); memDc.FillSolidRect(&rect, pDc->GetBkColor()); img.Draw(memDc.m_hDC, 0, 0, controlWidth, controlHeight, 0, 0, imgWidth, imgHeight); pDc->BitBlt(ptTL.x, ptTL.y, controlWidth, controlHeight, &memDc, 0, 0, SRCCOPY); memDc.SelectObject(pOldbmp); ReleaseDC(pDc); return; } void CZHSBLibDlg::LbnDblClkFileList() { if (m_bSearch) { helper_CurrentSelectFilePosition(); } else { BnClickedInsert(); } } void CZHSBLibDlg::initPreviewCtrl() { // 不需要CAD View 预览 // 直接使用 pictrue 控件 // 无需操作,占位 } void CZHSBLibDlg::initLocalDirTree() { helper_initLocalDirTree(m_sRootName, m_sTablePrefix); } void CZHSBLibDlg::initServerDirTree() { } void CZHSBLibDlg::BnClickedDirAdd() { helper_ClickedLocalDirAdd(m_sTablePrefix); } void CZHSBLibDlg::BnClickedDirRename() { helper_ClickedLocalDirRename(m_sTablePrefix); } void CZHSBLibDlg::BnClickedDirDel() { helper_ClickedLocalDirDel(m_sTablePrefix); } void CZHSBLibDlg::BnClickedDirOut() { helper_ClickedLocalDirOut(m_sTablePrefix, m_sFileSuffix); } void CZHSBLibDlg::BnClickedDirIn() { std::vector filetypes(1, CString(_T("*")) + m_sFileSuffix); helper_ClickedLocalDirIn(m_sTablePrefix, filetypes); } void CZHSBLibDlg::BnClickedFileIn() { CString s(_T("")); s.Format(_T("上华%s文件(*%s)|*%s||"), m_sRootName, m_sFileSuffix, m_sFileSuffix); helper_ClickedFileIn(s); } void CZHSBLibDlg::BnClickedFileNew() { AcAxDocLock lock; HTREEITEM hItem = m_ctrlLocalDirTree.GetSelectedItem(); if (!hItem) { AfxMessageBox(_T("请选中一个目录!")); return; } if (!isClassItem(hItem)) { AfxMessageBox(_T("不能在根目录或一级目录下保存文件,请选择一个二级目录!")); return; } ads_name ssName; AcDbObjectId RcdId; AcDbObjectIdArray ids; AcDbIdMapping idmap; Acad::ErrorStatus es; //SetVistualStyle(_T("Shaded"));// 提前渲染 ShowWindow(SW_HIDE); do { if (acedSSGet(NULL, NULL, NULL, NULL, ssName) != RTNORM) break; AcDbObjectId EntId; ads_name EntName; Adesk::Int32 nLength = 0; acedSSLength(ssName, &nLength); filterX3dPartEntity(ssName, ids); acedSSFree(ssName); if (ids.isEmpty()) break; AcDbExtents ext, extAll; for (int nLen = 0; nLen < ids.length(); nLen++) { AcDbEntityPointer ptr(ids[nLen], AcDb::kForRead); if (ptr.openStatus() == Acad::eOk) { if (ptr->getGeomExtents(ext) == Acad::eOk) extAll.addExt(ext); } } AcGePoint3d ptBlk = CoreTools::MidPt(extAll.maxPoint(), extAll.minPoint()); CString sBlockName(ZH_SB_BLK_NAME), sEquName(_T("组合设备1")); if (!CoreTools::getNameByDialog(_T("输入组合设备名称"), _T("组合设备名称"), sEquName)) break; if (sEquName.IsEmpty()) break; if (!CoreTools::checkFileName(sEquName)) { AfxMessageBox(_T("请检查设备名称,不能出现“ \\/:*?\"<>| ”。")); break; } if (helper_hasSameFileName(sEquName)) { AfxMessageBox(_T("存在相同的文件名称!")); break; } if (!getAlignPoint(ptBlk)) break; int idxClass = m_ctrlLocalDirTree.GetItemData(hItem); SetViewportDir(AcGeVector3d(-1., -1., 1), extAll.maxPoint(), extAll.minPoint()); AcDbDatabase *_pDb = new AcDbDatabase(Adesk::kTrue, Adesk::kTrue); std::shared_ptr pDb(_pDb); // 得到当前文件中的 设置 AecDbObjXDataMap xPipeInit; if (KTModelLayoutXData::ReadModelXData(KT_PIPEINIT, xPipeInit)) KTModelLayoutXData::WriteModelXData(KT_PIPEINIT, xPipeInit, pDb.get()); AecDbObjXDataMap xDataMap; KTModelLayoutXData::WriteModelNameObjXData(ZH_SB_BIM_REC, xDataMap, pDb.get()); xDataMap.SetAt(_T("maxpt"), extAll.maxPoint()); xDataMap.SetAt(_T("minpt"), extAll.minPoint()); KTModelLayoutXData::WriteModelNameObjXData(ZH_SB_BLK_EXT, xDataMap, pDb.get()); AcDbBlockTableRecord *pRcd = new AcDbBlockTableRecord; pRcd->setOrigin(ptBlk); pRcd->setName(sBlockName); AcDbBlockTable *pTbl(NULL); pDb->getBlockTable(pTbl, AcDb::kForWrite); if (!pTbl) { DELETE_PTR(pRcd); break; } pTbl->add(RcdId, pRcd); pTbl->close(); AcDbBlockTableRecord::PreviewIcon icon; ScreenCopy(AcGePoint3d::kOrigin, AcGePoint3d::kOrigin, icon); if (!icon.isEmpty()) pRcd->setPreviewIcon(icon); pRcd->close(); Adesk::Int16 nVal = acdbCurDwg()->useri4(); acdbCurDwg()->setUseri4(KEY_NOPROTECT); es = acdbHostApplicationServices()->workingDatabase()->wblockCloneObjects(ids , RcdId , idmap , AcDb::kDrcReplace); acdbCurDwg()->setUseri4(nVal); CString sPath(FilePath::getSystemTemporaryFolder() + _T("\\") + sEquName + m_sFileSuffix); if (_taccess(sPath, 0x0) == 0x0) ::DeleteFile(sPath); #if ARX==18 es = pDb->saveAs(sPath, false, AcDb::kDHL_CURRENT); #else es = pDb->saveAs(sPath, false, AcDb::kDHL_1027); #endif if (es!=Acad::eOk) acutPrintf(_T("\n保存失败")); helper_putEquFileToDb(m_sqlDB, sPath, idxClass); refreshLocalFileList(hItem); } while (false); ShowWindow(SW_SHOW); } void CZHSBLibDlg::BnClickedFileCopy() { helper_ClickedFileCopy(m_sRootName, m_sTablePrefix); } void CZHSBLibDlg::BnClickedFileRename() { helper_ClickedFileRename(m_sTablePrefix); } void CZHSBLibDlg::BnClickedFileDel() { helper_ClickedFileDel(m_sTablePrefix); } void CZHSBLibDlg::BnClickedFileOut() { HTREEITEM hRoot = m_ctrlLocalDirTree.GetSelectedItem(); if (!hRoot) { AfxMessageBox(_T("请选中一个目录!")); return; } std::vector files; getSelectedFiles(files); if (files.empty()) { AfxMessageBox(_T("请至少选择一个文件!")); return; } CString sPath(_T("")); if (!CModelLibDlgBase::helper_selectPath(_T("请选择文件要保存的目录"), sPath)) return; CString sName(_T("")), sFile(_T("")); int fileId(-1); for (size_t i = 0; i < files.size(); ++i) { fileId = m_ctrlLocalFileList.GetItemData(files[i]); m_ctrlLocalFileList.GetText(files[i], sName); sName = CModelLibDlgBase::helper_checkFileName(sName); sFile = sPath + sName; std::shared_ptr ptr = getZhSbFileFromDb(m_sqlDB, fileId); if (!ptr) return; sFile += _T(".zhequ"); int j(1); while (j < 100) { if (_taccess(sFile, 0x0) == 0x0) sFile.Format(_T("%s%s(%d).zhequ") , sPath , sName , j++); else break; } #if ARX==18 ptr->saveAs(sFile, false, AcDb::kDHL_CURRENT); #else ptr->saveAs(sFile, false, AcDb::kDHL_1027); #endif } AfxMessageBox(_T("文件导出完毕。")); } void CZHSBLibDlg::BnClickedBimAdd() { int idx = m_ctrlLocalFileList.GetCurSel(); if (idx == -1) { AfxMessageBox(_T("请选中一个文件!")); return; } int equId = m_ctrlLocalFileList.GetItemData(idx); CString sKey(_T("")), sValue(_T("")); while (CoreTools::getBimDataByDlg(true, sKey, sValue)) { LVFINDINFO info; info.flags = LVFI_PARTIAL | LVFI_STRING; info.psz = sKey; int nIndex; nIndex = m_ctrlBimPropertyList.FindItem(&info); if (nIndex != -1) { AfxMessageBox(_T("已经存在相同的属性!")); return; } if (addBimRecToZhSbFile(m_sqlDB, equId, std::make_pair(sKey, sValue))) { idx = m_ctrlBimPropertyList.InsertItem(m_ctrlBimPropertyList.GetItemCount() + 1, sKey); m_ctrlBimPropertyList.SetItemText(idx, 1, sValue); m_ctrlBimPropertyList.Invalidate(); } } } void CZHSBLibDlg::BnClickedBimModi() { int idx = m_ctrlLocalFileList.GetCurSel(); if (idx == -1) { AfxMessageBox(_T("请选中一个文件!")); return; } int equId = m_ctrlLocalFileList.GetItemData(idx); idx = m_ctrlBimPropertyList.GetSelectionMark(); if (idx == -1) { AfxMessageBox(_T("请选中一行数据!")); return; } int bimId = m_ctrlBimPropertyList.GetItemData(idx); if (AfxMessageBox(_T("是否修改?此操作不可逆!"), MB_YESNO) != IDYES) return; CString sKey(m_ctrlBimPropertyList.GetItemText(idx, 0)), sValue(m_ctrlBimPropertyList.GetItemText(idx, 1)); if (!CoreTools::getBimDataByDlg(false, sKey, sValue)) return; if (addBimRecToZhSbFile(m_sqlDB, equId, std::make_pair(sKey, sValue))) { m_ctrlBimPropertyList.SetItemText(idx, 1, sValue); m_ctrlBimPropertyList.Invalidate(); } } void CZHSBLibDlg::BnClickedBimDel() { int fileIdx = m_ctrlLocalFileList.GetCurSel(); if (fileIdx == -1) { AfxMessageBox(_T("请选中一个文件!")); return; } int equId = m_ctrlLocalFileList.GetItemData(fileIdx); int bimIdx = m_ctrlBimPropertyList.GetSelectionMark(); if (bimIdx == -1) { AfxMessageBox(_T("请选中一行数据!")); return; } int bimId = m_ctrlBimPropertyList.GetItemData(bimIdx); if (AfxMessageBox(_T("是否删除?此操作不可逆!"), MB_YESNO) != IDYES) return; if (delBimRecToZhSbFile(m_sqlDB, equId, m_ctrlBimPropertyList.GetItemText(bimIdx, 0))) { m_ctrlBimPropertyList.DeleteItem(bimIdx); m_ctrlBimPropertyList.Invalidate(); } } void CZHSBLibDlg::BnClickedOk() { CDialog::OnOK(); } void CZHSBLibDlg::BnClickedInsert() { if (m_iSelectFileID != -1) { SetVistualStyle(_T("2dWireframe")); ShowWindow(SW_HIDE); insertZHSB(m_sqlDB, m_iSelectFileID); ShowWindow(SW_SHOW); } } void CZHSBLibDlg::TvnSelchangedLocalDirTree(NMHDR *pNMHDR, LRESULT *pResult) { LPNMTREEVIEW pNMTreeView = reinterpret_cast(pNMHDR); if (!pNMTreeView->itemNew.hItem) return; refreshLocalFileList(pNMTreeView->itemNew.hItem); m_iSelectFileID = -1; *pResult = 0; } void CZHSBLibDlg::EnChangeSearch() { helper_EnChangeSearch(m_sTablePrefix); } void CZHSBLibDlg::CheckSearch() { CModelLibDlgBase::CheckSearch(); helper_ShowWindow(IDC_FILE_NEW, this, !m_bSearch); } void CZHSBLibDlg::UpdateThumbnail() { AcAxDocLock lock; HTREEITEM hRoot = m_ctrlLocalDirTree.GetSelectedItem(); if (!hRoot) { AfxMessageBox(_T("请选中一个目录!")); return; } std::vector files; getSelectedFiles(files); if (files.size() != 1) { AfxMessageBox(_T("请选择一个文件!")); return; } int fileId = m_ctrlLocalFileList.GetItemData(files[0]); std::shared_ptr pDb = getZhSbFileFromDb(m_sqlDB, fileId); if (!pDb) return; AcDbBlockTableRecordPointer pRcd(ZH_SB_BLK_NAME, pDb.get(), AcDb::kForWrite); if (pRcd.openStatus() != Acad::eOk) return; do { ShowWindow(SW_HIDE); ads_point _pt1, _pt2; if (acedGetPoint(NULL, _T("\n选择预览图的左上角"), _pt1) != RTNORM) break; if (acedGetPoint(_pt1, _T("\n选择预览图的右下角"), _pt2) != RTNORM) break; AcGePoint3d pt1(asPnt3d(_pt1)), pt2(asPnt3d(_pt2)); CoreTools::UCS2WCS(pt1, pt1); CoreTools::UCS2WCS(pt2, pt2); AcDbExtents ext; ext.addPoint(pt1); ext.addPoint(pt2); AcGePoint3d ptMax(ext.maxPoint()), ptMin(ext.minPoint()); pt1.x = ptMin.x; pt1.y = ptMax.y; pt2.x = ptMax.x; pt2.y = ptMin.y; AcDbBlockTableRecord::PreviewIcon icon; ScreenCopy(pt1, pt2, icon); if (icon.isEmpty()) break; pRcd->setPreviewIcon(icon); pRcd->close(); #if ARX==18 pDb->saveAs(pDb->originalFileName(), true, AcDb::kDHL_CURRENT); #else pDb->saveAs(pDb->originalFileName(), true, AcDb::kDHL_1027); #endif updateDwgPackage(m_sqlDB, fileId, pDb->originalFileName()); } while (false); ShowWindow(SW_SHOW); OnLbnSelchangeFileList(); } void CZHSBLibDlg::PopMenuForLocalDirTree(const CPoint &pt) { helper_PopMenuForLocalDirTree(pt); } void CZHSBLibDlg::PopMenuForServerDirTree(const CPoint &pt) { } void CZHSBLibDlg::PopMenuForLocalFileList(const CPoint &pt) { CMenu menu; menu.CreatePopupMenu(); std::vector v; getSelectedFiles(v); if (m_bSearch) { menu.AppendMenu(MF_BYCOMMAND | MF_STRING | MF_ENABLED, ID_EQU_LIB_FILE_ANCHOR, _T("定位文件(&W)")); } else { menu.AppendMenu(MF_BYCOMMAND | MF_STRING | MF_ENABLED, ID_EQU_LIB_FILE_NEW, _T("新建设备(&N)")); menu.AppendMenu(MF_BYCOMMAND | MF_STRING | MF_ENABLED, ID_EQU_LIB_FILE_IN, _T("导入文件(&I)")); if (!v.empty()) { menu.AppendMenu(MF_BYCOMMAND | MF_STRING | MF_ENABLED, ID_EQU_LIB_FILE_OUT, _T("导出文件(&O)")); menu.AppendMenu(MF_BYCOMMAND | MF_STRING | MF_ENABLED, ID_EQU_LIB_FILE_COPY, _T("复制文件(&C)")); if (v.size() == 1) { menu.AppendMenu(MF_BYCOMMAND | MF_STRING | MF_ENABLED, ID_EQU_LIB_FILE_RENAME, _T("文件改名(&M)")); menu.AppendMenu(MF_BYCOMMAND | MF_STRING | MF_ENABLED, ID_EQU_LIB_FILE_THUMBNAIL, _T("更新预览(&P)")); } menu.AppendMenu(MF_BYCOMMAND | MF_STRING | MF_ENABLED, ID_EQU_LIB_FILE_DEL, _T("删除文件(&D)")); } } int nID = menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD , pt.x , pt.y, &m_ctrlLocalFileList); switch (nID) { case ID_EQU_LIB_FILE_THUMBNAIL: return UpdateThumbnail(); case ID_EQU_LIB_FILE_NEW: OnBnClickedFileNew(); break; case ID_EQU_LIB_FILE_IN: OnBnClickedFileIn(); break; case ID_EQU_LIB_FILE_OUT: return OnBnClickedFileOut(); case ID_EQU_LIB_FILE_DEL: OnBnClickedFileDel(); break; case ID_EQU_LIB_FILE_COPY: OnBnClickedFileCopy(); break; case ID_EQU_LIB_FILE_RENAME: OnBnClickedFileRename(); break; case ID_EQU_LIB_FILE_ANCHOR: return helper_CurrentSelectFilePosition(); default: break; } } void CZHSBLibDlg::zhsbgl() { static CZHSBLibDlg *pDlg(NULL); if (pDlg && pDlg->GetSafeHwnd()) { pDlg->DestroyWindow(); DELETE_PTR(pDlg); } CAcModuleResourceOverride myResources; pDlg = new CZHSBLibDlg(); pDlg->Create(CZHSBLibDlg::IDD, acedGetAcadFrame()); pDlg->CenterWindow(); pDlg->ShowWindow(SW_SHOW); } void CZHSBLibDlg::copyAec3dMep2shzhsb(LPCTSTR pszFrom, LPCTSTR pszTo) { //CString sFrom(FilePath::GetSysDir() + _T("\\aec3dmep.db")); //CString sTo(FilePath::GetSysDir() + _T("\\shzhsb.db")); if (!pszFrom || !pszTo) return; CModelLibDlgBase::helper_CopyTable(pszFrom, pszTo, _T("DWG_Class"), _T("DWG_Class")); CModelLibDlgBase::helper_CopyTable(pszFrom, pszTo, _T("DWG_Folder"), _T("DWG_Folder")); CModelLibDlgBase::helper_CopyTable(pszFrom, pszTo, _T("DWG_Package"), _T("DWG_Package")); }