// AllDwgDlg.cpp : implementation file // #include "stdafx.h" #include "tapi.h" //#include "arxtools.h" #include "teldef.h" #include "AllDwgDlg.h" #include "dbsymutl.h" #include "TGAs.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif extern "C" HINSTANCE _hdllInstance; ///////////////////////////////////////////////////////////////////////////// // CAllDwgDlg dialog void DoTgDwgLibEx(CString csTKFileName) { CString csTKName = g_csDwbPath + csTKFileName+_T(".TK"); XString fullFile; if(!FindFile(csTKName, fullFile)) { Callme(_T("对不起,没有发现相关上华图库文件!")); return; } CAcModuleResourceOverride vTemp; CAllDwgDlg dlg(NULL, csTKFileName); int nDrawMode=DocGetDrawMode(); DocSetDrawMode(DRAW_2D); if(dlg.DoModal() != IDOK || dlg.m_csInsBlkName == _T("")){ DocSetDrawMode(nDrawMode); return; } DocSetDrawMode(nDrawMode); XPoint ptIns; ads_getpoint(NULL, _T("\n请点选插入点 <中心点>:"), ptIns); ptIns = Ucs2Wcs(ptIns); InsertBlock((const TCHAR*)dlg.m_csInsBlkName, asPnt3d(ptIns), 1, 1, 0, _T("0")); Entity ent; ent.GetLast(); SHads_command(RTSTR,_T("explode"),RTENAME, (TLong_ptr*)ent, RTNONE); return; } //LISP调用 例如:(ITgDwgLib "03d201") int InvokeTgDwgLib() { resbuf *rb=ads_getargs(); RBList rbArgs=rb; if(rb && rb->restype==RTSTR) { DoTgDwgLibEx(rb->resval.rstring); } ads_retnil(); return RTNORM; } //原理图集 void TgDwgLibEx() { DoTgDwgLibEx(_T("CIRCUIT")); } int GetLibIndex(XString xsRecord, XStringList lstLib) { int len = lstLib.Length(); int index = -1; for(int i=0;i -1) DwbLib.Copy(index, dwgPrefix); m_csTmpDwg = dwgPrefix; mPreviewCtrl.clearAll(); if(!mPreviewDb){ mPreviewDb = new AcDbDatabase(false,true); } else{ delete mPreviewDb; mPreviewDb = new AcDbDatabase(false,true); } #if ADS > 20 mPreviewDb->readDwgFile((const TCHAR*)m_csTmpDwg, AcDbDatabase::OpenMode::kForReadAndAllShare, false); #else mPreviewDb->readDwgFile((const TCHAR*)m_csTmpDwg, _SH_DENYNO, false); #endif // modify by cq 2017-01-05 支持CAD2017 UpdatePreview(); } void CAllDwgDlg::OnSelchangeListName() { int iSel = m_listName.GetCurSel(); m_listName.GetCurSel(); if(iSel < 0) return; Redraw(); OnButtonShow(); } void CAllDwgDlg::Redraw() { UpdateData(); CString csName, csItem, csRecord; int iSel = m_listName.GetCurSel(); m_listName.GetCurSel(); if(iSel < 0) return; m_listName.GetText(iSel, csItem); int len = m_lstAllDwg.Length(); for(int i=0;im_csDesName; if(csItem == csTmp){ csRecord = m_lstAllDwg[i]->m_csRecord; break; } } m_csCurRecord = csRecord; m_csText = csItem; UpdateData(FALSE); } void CAllDwgDlg::OnPaint() { CPaintDC dc(this); // device context for painting } //计算AcDbDatabase的外包围盒 void CAllDwgDlg::GetDwgdatabaseExt(XPoint &ptMax, XPoint &ptMin) { DList ssAllPipe; if(GetEntityFromDatabase(ssAllPipe, *mPreviewDb, _T("LINE,INSERT,TEXT"), 1, ACDB_MODEL_SPACE) != Acad::eOk) return; AcDbExtents extAll; int len = ssAllPipe.Length(); for(int i=0;igetGeomExtents(ext); extAll.addExt(ext); } OPENOBJ_END(); } ptMax = extAll.maxPoint(); ptMin = extAll.minPoint(); } void CAllDwgDlg::UpdatePreview() { mPreviewCtrl.init(true); { XPoint ptMax, ptMin; GetDwgdatabaseExt(ptMax, ptMin); XPoint ptCen; double nWidth(0),nHeight(0); XLine line(ptMax, ptMin); line.MidPoint(ptCen); nWidth = ads_distance(ptMax, ptMin); nHeight = nWidth; //double nHeight = line.GetLength(); AcGePoint3d target = ptCen;//(0.0,0.0,0.0); AcGePoint3d position(target); position.z += 1; AcGsView* pView = mPreviewCtrl.view(); pView->setView(position, target, AcGeVector3d(0.0, 1.0, 0.0), // upvector nWidth, nHeight); AcDbObjectId idMSpace = acdbSymUtil()->blockModelSpaceId(mPreviewDb); OPENOBJ_BEGIN(idMSpace, AcDb::kForRead, AcDbBlockTableRecord, pBlockTableRecord); if(pBlockTableRecord) mPreviewCtrl.view()->add(pBlockTableRecord, mPreviewCtrl.model()); OPENOBJ_END(); } mPreviewCtrl.Invalidate(); } BOOL CAllDwgDlg::DestroyWindow() { mPreviewCtrl.clearAll(); return CDialog::DestroyWindow(); } void CAllDwgDlg::OnSelchangeComboType() { UpdateData(); CString csType; m_comboType.GetLBText(m_iComSel, csType); CString csTKName = g_csDwbPath + m_csTKName + _T(".TK"); CodeBase db; XDbfTable *pTable = db.Open(csTKName); m_lstAllDwg.Reset(); m_listName.ResetContent(); if(!pTable) { CString csTmp; csTmp.Format(_T("%s文件只读或损坏!"), csTKName); AfxMessageBox(csTmp); // AfxMessageBox(_T("TK文件只读或损坏!")); return; } for(pTable->MoveFirst();!pTable->IsEOF();pTable->MoveNext()) { CString sKind, sItem, sDrawing; GET_FIELD(pTable, _T("kind"), sKind); GET_FIELD(pTable, _T("item"), sItem); GET_FIELD(pTable, _T("drawing"), sDrawing); if(sKind == csType && sDrawing != _T("")) { CBlockStruct *pData = new CBlockStruct(); pData->m_csTKName = csTKName; pData->m_csRecord = (const TCHAR*)sDrawing; pData->m_csDesName = (const TCHAR*)sItem; m_lstAllDwg.Append(pData); m_listName.AddString((const TCHAR*)sItem); } } }