#include "stdafx.h" #include "basefunc.h" #include "distdrag.h" #include "tkcsdlg.h" #include "DockPane.h" #include "BlockDrag.h" extern CTkcsDlg *g_TkcsDlg; extern CString g_sLayerName; CDockPane *g_pDockPane = NULL; namespace BaseFuncs { void CAD_GetVarInt(CString sMode, int &nRet) { resbuf *pRb = acutBuildList(RTSHORT, 23, 0); acedGetVar(sMode, pRb); if (pRb==NULL) { acutRelRb(pRb); return; } nRet = pRb->resval.rint; acutRelRb(pRb); } void CAD_SetvarInt(CString sMode, int nRet) { resbuf *pNewRb = acutBuildList(RTSHORT, nRet, 0); acedSetVar(sMode, pNewRb); acutRelRb(pNewRb); } BOOL DeleteEnt(AcDbObjectId EntId) { AcDbEntity *pEnt = NULL; if (acdbOpenObject(pEnt, EntId, AcDb::kForWrite)==Acad::eOk) { Acad::ErrorStatus es = pEnt->erase(); pEnt->close(); pEnt = NULL; return TRUE; } return FALSE; } BOOL ClearAcadCmdLine() { HWND hAcadDocWnd = adsw_acadDocWnd(); if (hAcadDocWnd == NULL) return false; ::SendMessage(hAcadDocWnd, WM_CHAR, VK_ESCAPE, 0); ::SendMessage(hAcadDocWnd, WM_CHAR, VK_ESCAPE, 0); acedPostCommandPrompt(); return true; } BOOL AddEntToDb(AcDbEntity *pEnt, AcDbObjectId &EntId, AcDbObjectId OwerId) { AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase(); // AcDbBlockTable *pBlockTable=NULL; AcDbBlockTableRecord *pBlockTableRecord = NULL; // pDb->getSymbolTable(pBlockTable,AcDb::kForRead); if (OwerId==NULL) OwerId = pDb->currentSpaceId(); if (acdbOpenObject(pBlockTableRecord, OwerId, AcDb::kForWrite)!=Acad::eOk) { return FALSE; } Acad::ErrorStatus es = pBlockTableRecord->appendAcDbEntity(EntId, pEnt); pBlockTableRecord->close(); pEnt->close(); return TRUE; } void CAD_SendStringToExecute(CString szCommand, bool bAutoReturn /*=TRUE*/) { if (acedGetAcadDwgView()!=NULL) acedGetAcadDwgView()->SetFocus(); AcApDocument *pDoc = acDocManager->curDocument(); //取消当前命令 HWND hdoc = acedGetAcadTextCmdLine()->m_hWnd; szCommand.TrimRight(); szCommand += _T("\n"); acDocManager->sendStringToExecute(pDoc, szCommand); return; if (bAutoReturn) { ::SendMessage(hdoc, WM_CHAR, VK_RETURN, 0); } } void dist_ent_highlight(AcDbObjectId EntId) { AcDbEntity *pEnt = NULL; if (acdbOpenObject(pEnt, EntId, AcDb::kForRead)==Acad::eOk) { pEnt->highlight(); pEnt->close(); pEnt = NULL; } } void dist_ent_highlight(AcDbObjectIdArray EntIds) { for (int nLen = 0; nLenunhighlight(); pEnt->close(); pEnt = NULL; } } void dist_ent_unhighlight(AcDbObjectIdArray EntIds) { for (int nLen = 0; nLen=0) { int nLength = strFind.GetLength(); strZj = strFind.Left(nIndex); strFind = strFind.Right(nLength-nIndex-strFg.GetLength()); strFind.TrimLeft(); strFind.TrimRight(); nIndex = strFind.Find(strFg, 0); strZj.TrimLeft(); strZj.TrimRight(); strArr.Add(strZj); } strFind.TrimLeft(); strFind.TrimRight(); strArr.Add(strFind); } BOOL FindStringInArr(CStringArray &strArr, CString str, int &nIndex) { nIndex = -1; for (int nLen = 0; nLen=0||sFileName.Find(sExtLow, 0)>=0) { sFileName.TrimRight(sExtUp); sFileName.TrimRight(sExtLow); sFileNameArray.Add(sFileName); } } } void DrawD(AcDbObjectId &PlineId, BOOL bAutoClose) { AsdkCadPolylineJig *pJig = new AsdkCadPolylineJig(); pJig->doIt(); PlineId = pJig->m_objId; delete pJig; if (bAutoClose) { AcDbPolyline *pLine = NULL; if (acdbOpenObject(pLine, PlineId, AcDb::kForWrite)==Acad::eOk) { if (pLine->numVerts()<3) { pLine->erase(); PlineId = NULL; } else pLine->setClosed(Adesk::kTrue); pLine->close(); pLine = NULL; } } return; int nIndex = 0; AcGePoint3d ptEnd; AcGePoint3d ptStart; double dOldAnlge = 0; AcDbPolyline *pLine = NULL; if (acedGetPoint(NULL, _T("\n指定起点"), asDblArray(ptStart))!=RTNORM) return; acdbUcs2Wcs(asDblArray(ptStart), asDblArray(ptStart), FALSE); pLine = new AcDbPolyline(); ptEnd = ptStart; TCHAR kw[10]; //获得当前线宽; double dWidth = 0.0; pLine->addVertexAt(nIndex++, AcGePoint2d(ptStart.x, ptStart.y), 0); AddEntToDb(pLine, PlineId); acutPrintf(_T("\n当前线宽(0.0)")); CString sPromt; AcGePoint3d pt1; AcGePoint3d pt2; AcGeVector3d vt; double dDist = 0; double dWidth1 = 0; double dWidth2 = 0; AcGePoint3d ptNext; AcGePoint3d ptLast; double dBulge; int nOldMode = 0; //老的正交模式 int nORTHOode = 0; CAD_GetVarInt(_T("ORTHOMODE"), nOldMode); CAD_GetVarReal(_T("SNAPANG"), dOldAnlge); double dSnapAnlge = 0; while (1) { if (nIndex<3) { acedInitGet(0, _T("A H L O U W")); sPromt = _T("\n指定下一个点或 [圆弧(A)/半宽(H)/长度(L)/正交(O)/放弃(U)/宽度(W)]:"); } else { acedInitGet(0, _T("A C H L O U W")); sPromt = _T("\n指定下一个点或 [圆弧(A)/半宽(H)/长度(L)/正交(O)/放弃(U)/闭合(C)/宽度(W)]:"); } acdbWcs2Ucs(asDblArray(ptStart), asDblArray(ptStart), FALSE); switch (acedGetPoint(asDblArray(ptStart), sPromt, asDblArray(ptEnd))) { case RTCAN: DeleteEnt(PlineId); PlineId = NULL; return; case RTNORM: acdbUcs2Wcs(asDblArray(ptEnd), asDblArray(ptEnd), FALSE); // pLine->addVertexAt(nIndex++,AcGePoint2d(ptEnd.x,ptEnd.y)); if (acdbOpenObject(pLine, PlineId, AcDb::kForWrite)==Acad::eOk) { pLine->addVertexAt(nIndex++, AcGePoint2d(ptEnd.x, ptEnd.y)); pLine->setWidthsAt(nIndex-1, dWidth, dWidth); pLine->close(); pLine = NULL; } ptStart = ptEnd; break; case RTKWORD: acedGetInput(kw); switch (kw[0]) { case 'A': //圆狐 if (acedGetPoint(asDblArray(ptStart), _T("\n指定圆弧第一点"), asDblArray(ptNext))!=RTNORM) continue; if (acedGetPoint(asDblArray(ptNext), _T("\n指定圆弧第二点"), asDblArray(ptLast))!=RTNORM) continue; acdbUcs2Wcs(asDblArray(ptStart), asDblArray(ptStart), FALSE); acdbUcs2Wcs(asDblArray(ptNext), asDblArray(ptNext), FALSE); acdbUcs2Wcs(asDblArray(ptLast), asDblArray(ptLast), FALSE); GetBulge(ptStart, ptNext, ptLast, dBulge); if (acdbOpenObject(pLine, PlineId, AcDb::kForWrite)==Acad::eOk) { pLine->setBulgeAt(nIndex-1, dBulge); pLine->addVertexAt(nIndex++, AcGePoint2d(ptLast.x, ptLast.y)); pLine->close(); pLine = NULL; } ptStart = ptLast; break; case 'L': if (acedGetDist(asDblArray(ptStart), _T("\n指定直线的长度:"), &dDist)!=RTNORM) continue; if (nIndex<2) continue; if (acdbOpenObject(pLine, PlineId, AcDb::kForWrite)==Acad::eOk) { pLine->getPointAt(nIndex-1, pt2); pLine->getPointAt(nIndex-2, pt1); ptStart = pt2+(pt2-pt1).normal()*dDist; pLine->setPointAt(nIndex-1, AcGePoint2d(ptStart.x, ptStart.y)); pLine->close(); pLine = NULL; } break; case 'U': //回退 if (nIndex<2) continue; if (acdbOpenObject(pLine, PlineId, AcDb::kForWrite)==Acad::eOk) { pLine->removeVertexAt(nIndex-1); nIndex--; pLine->getPointAt(nIndex-1, ptStart); pLine->close(); pLine = NULL; } CAD_GetVarInt(_T("ORTHOMODE"), nORTHOode); if (nORTHOode==0) //关闭状态 { CAD_SetvarReal(_T("SNAPANG"), dOldAnlge); } else { if (GetPlAngle(PlineId, dSnapAnlge)) { CAD_SetvarReal(_T("SNAPANG"), dSnapAnlge); } } break; case 'W'://宽度 dWidth1 = dWidth2 = dWidth; sPromt.Format(_T("\n指定起点线宽(%0.2f):"), dWidth1); if (acedGetDist(asDblArray(ptStart), sPromt, &dWidth1)==RTCAN) { if (bAutoClose) ClosePline(PlineId); CAD_SetvarInt(_T("ORTHOMODE"), nORTHOode); CAD_SetvarReal(_T("SNAPANG"), dOldAnlge); return; } sPromt.Format(_T("\n指定终点线宽(%0.2f):"), dWidth2); if (acedGetDist(asDblArray(ptStart), sPromt, &dWidth2)==RTCAN) { if (bAutoClose) ClosePline(PlineId); CAD_SetvarInt(_T("ORTHOMODE"), nORTHOode); CAD_SetvarReal(_T("SNAPANG"), dOldAnlge); return; } if (acdbOpenObject(pLine, PlineId, AcDb::kForWrite)==Acad::eOk) { dWidth = dWidth2; pLine->setWidthsAt(nIndex-1, dWidth1, dWidth2); pLine->close(); pLine = NULL; } break; case 'H'://半宽 dWidth1 = dWidth2 = dWidth/2; sPromt.Format(_T("\n指定起点半宽(%0.2f):"), dWidth1); if (acedGetDist(asDblArray(ptStart), sPromt, &dWidth1)==RTCAN) { if (bAutoClose) ClosePline(PlineId); CAD_SetvarInt(_T("ORTHOMODE"), nORTHOode); CAD_SetvarReal(_T("SNAPANG"), dOldAnlge); return; } sPromt.Format(_T("\n指定终点半宽(%0.2f):"), dWidth2); if (acedGetDist(asDblArray(ptStart), sPromt, &dWidth2)==RTCAN) { if (bAutoClose) ClosePline(PlineId); CAD_SetvarInt(_T("ORTHOMODE"), nORTHOode); CAD_SetvarReal(_T("SNAPANG"), dOldAnlge); return; } dWidth1 *= 2; dWidth2 *= 2; if (acdbOpenObject(pLine, PlineId, AcDb::kForWrite)==Acad::eOk) { dWidth = dWidth2; pLine->setWidthsAt(nIndex-1, dWidth1, dWidth2); pLine->close(); pLine = NULL; } break; case 'C': //闭合 if (acdbOpenObject(pLine, PlineId, AcDb::kForWrite)==Acad::eOk) { pLine->setClosed(TRUE); pLine->close(); pLine = NULL; } CAD_SetvarInt(_T("ORTHOMODE"), nORTHOode); CAD_SetvarReal(_T("SNAPANG"), dOldAnlge); return; case 'O': //正交 CAD_GetVarInt(_T("ORTHOMODE"), nORTHOode); if (nORTHOode==1) //关闭状态 { CAD_SetvarReal(_T("SNAPANG"), dOldAnlge); } else { if (GetPlAngle(PlineId, dSnapAnlge)) { CAD_SetvarReal(_T("SNAPANG"), dSnapAnlge); } } CAD_SetvarInt(_T("ORTHOMODE"), (nORTHOode+1)%2); continue; default: break; } break; default: if (bAutoClose) { if (nIndex>2) ClosePline(PlineId); } CAD_SetvarReal(_T("SNAPANG"), dOldAnlge); CAD_SetvarInt(_T("ORTHOMODE"), nORTHOode); if (nIndex<2) { DeleteEnt(PlineId); PlineId = NULL; return; } return; } } CAD_SetvarReal(_T("SNAPANG"), dOldAnlge); CAD_SetvarInt(_T("ORTHOMODE"), nOldMode); } void GetBulge(AcGePoint3d pt1, AcGePoint3d pt2, AcGePoint3d pt3, double &dBulge) { AcGePoint3d ptCenter; AcGePoint3d ptJd; AcGePoint3d ptCenter1 = pt1+(pt2-pt1)/2; AcGePoint3d ptCenter2 = pt2+(pt3-pt2)/2; AcGeVector3d vt1 = pt2-pt1; AcGeVector3d vt2 = pt3-pt2; vt1 = vt1.normal(); vt2 = vt2.normal(); vt1 = vt1.rotateBy(PI/2, AcGeVector3d(0, 0, 1)); vt2 = vt2.rotateBy(PI/2, AcGeVector3d(0, 0, 1)); AcGePoint3d ptTo1 = ptCenter1+vt1*20; AcGePoint3d ptTo2 = ptCenter2+vt2*20; AcDbObjectId LineId; int nFx; AcDbPolyline *pLine = new AcDbPolyline; pLine->addVertexAt(0, AcGePoint2d(pt1.x, pt1.y)); pLine->addVertexAt(1, AcGePoint2d(pt2.x, pt2.y)); pLine->addVertexAt(2, AcGePoint2d(pt3.x, pt3.y)); pLine->setClosed(Adesk::kTrue); AddEntToDb(pLine, LineId); //判断是顺时针还是你时针小于0是顺 大于0是你 polyWindingNumber(LineId, nFx); DeleteEnt(LineId); acdbInters(asDblArray(ptCenter1), asDblArray(ptTo1), asDblArray(ptCenter2), asDblArray(ptTo2), 0, asDblArray(ptCenter)); //开始求bugle vt1 = pt1-ptCenter; vt2 = pt3-ptCenter; double dAngle; if (nFx<0) dAngle = vt1.angleTo(vt2, -AcGeVector3d::kZAxis); else dAngle = vt1.angleTo(vt2, AcGeVector3d::kZAxis); dBulge = fabs(tan(dAngle/4)); if (nFx<0) dBulge = -dBulge; } void CAD_GetVarReal(CString sMode, double &dReal) { resbuf *pRb = acutBuildList(RTREAL, 23.0, 0); acedGetVar(sMode, pRb); if (pRb==NULL) { acutRelRb(pRb); return; } dReal = pRb->resval.rint; acutRelRb(pRb); } void CAD_SetvarReal(CString sMode, double dReal) { resbuf *pNewRb = acutBuildList(RTREAL, dReal, 0); acedSetVar(sMode, pNewRb); acutRelRb(pNewRb); } BOOL GetPlAngle(AcDbObjectId PlId, double &dAngle) { AcDbPolyline *pLine = NULL; int nNumVert = 0; AcGePoint2d ptStart; AcGePoint2d ptEnd; AcGeVector2d vt; if (acdbOpenObject(pLine, PlId, AcDb::kForRead)!=Acad::eOk) return FALSE; nNumVert = pLine->numVerts(); if (nNumVert<2) { pLine->close(); pLine = NULL; return FALSE; } pLine->getPointAt(nNumVert-2, ptStart); pLine->getPointAt(nNumVert-1, ptEnd); pLine->close(); pLine = NULL; vt = ptEnd-ptStart; dAngle = vt.angle(); return TRUE; } void ClosePline(AcDbObjectId PlineId) { AcDbPolyline *pLine = NULL; if (acdbOpenObject(pLine, PlineId, AcDb::kForWrite)!=Acad::eOk) return; int nVerts = pLine->numVerts(); if (nVerts<3) { pLine->close(); pLine = NULL; return; } pLine->setClosed(Adesk::kTrue); pLine->close(); pLine = NULL; } Adesk::Boolean polyWindingNumber(AcDbObjectId polyId, int &winding) { // if (!pPoly->isClosed()) // { // return Adesk::kFalse; // } AcDbPolyline *pPoly = NULL; if (acdbOpenObject(pPoly, polyId, AcDb::kForRead)!=Acad::eOk) return Adesk::kFalse; BOOL bRet = polyWindingNumber(pPoly, winding); pPoly->close(); pPoly = NULL; return bRet; } Adesk::Boolean polyWindingNumber(AcDbPolyline *&pPoly, int &winding) { double turn = 0; int nSegs = pPoly->numVerts(); AcGeVector3dArray startTans(nSegs); AcGeVector3dArray endTans(nSegs); double TWOPI = 6.28318530718; double PIBYTWO = 1.570796326795; int i = 0; for (i = 0; i < nSegs; i++) { if (pPoly->segType(i) == AcDbPolyline::kArc) { AcGeCircArc2d arc; pPoly->getArcSegAt(i, arc); AcGeVector2d startTan; AcGeVector2d endTan; AcGeVector2dArray startDerivs; arc.evalPoint(arc.startAng(), 1, startDerivs); startTan = startDerivs[0]; AcGeVector2dArray endDerivs; arc.evalPoint(arc.endAng(), 1, endDerivs); endTan = endDerivs[0]; startTans.append(AcGeVector3d(startTan.x, startTan.y, 0.0)); endTans.append(AcGeVector3d(endTan.x, endTan.y, 0.0)); double ang = arc.endAng() - arc.startAng(); turn += arc.isClockWise() ? -ang : ang; } else if (pPoly->segType(i) == AcDbPolyline::kLine) { AcGeLineSeg2d line; pPoly->getLineSegAt(i, line); AcGeVector2d tan2d = line.endPoint() -line.startPoint(); AcGeVector3d tan = AcGeVector3d(tan2d.x, tan2d.y, 0.0); startTans.append(tan); endTans.append(tan); } } nSegs = startTans.length(); for (i = 0; i < nSegs; i++) { double angle = endTans[i].angleTo(startTans[(i + 1) % nSegs]); AcGeVector3d norm = endTans[i].crossProduct(startTans[(i + 1) % nSegs]); angle = norm.z > 0 ? angle : -angle; turn += angle; } turn = turn / TWOPI; double lower = floor(turn); double tol = 1e-6; if ((turn - lower) < tol) winding = (int)lower; else if (((lower + 1) - turn) < tol) winding = (int)(lower + 1); else return Adesk::kFalse; return Adesk::kTrue; } void SSToIds(ads_name ssName, AcDbObjectIdArray &EnIds) { AcDbObjectId EntId; ads_name EntName; Adesk::Int32 nLength = 0; acedSSLength(ssName, &nLength); for (int nLen = 0; nLenblockTableRecord(); pBlf->close(); pBlf = NULL; int nFind = -1; if (!RcdIds.find(RcdId, nFind)) { RcdIds.append(RcdId); TCHAR *name; AcDbBlockTableRecord *pRcd = NULL; acdbOpenObject(pRcd, RcdId, AcDb::kForRead); pRcd->getName(name); pRcd->close(); pRcd = NULL; strArr.Add(name); free(name); } } } BOOL dist_dwg_ReadDiction(CString &sXDList, CString sDicName, CString sRecName) { AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase(); AcDbDictionary *pNameObj = NULL; AcDbDictionary *pDict = NULL; pDb->getNamedObjectsDictionary(pNameObj, AcDb::kForRead); if (pNameObj->getAt(sDicName, (AcDbObject *&)pDict, AcDb::kForRead) != Acad::eOk) { pNameObj->close(); return FALSE; } pNameObj->close(); pNameObj = NULL; AcDbXrecord *pXrec = NULL; struct resbuf *pHead = NULL; if (pDict->getAt(sRecName, (AcDbObject *&)pXrec, AcDb::kForRead) != Acad::eOk) { pDict->close(); pDict = NULL; return FALSE; } pDict->close(); pDict = NULL; pXrec->rbChain(&pHead); struct resbuf *pRb = pHead; if (pRb->restype==AcDb::kDxfXdReal) sXDList.Format(_T("%0.1f"), pRb->resval.rreal); else if (pRb->restype==AcDb::kDxfText) sXDList = pRb->resval.rstring; else if (pRb->restype==AcDb::kDxfXdInteger16) sXDList.Format(pRb->resval.rint); pXrec->close(); pXrec = NULL; acutRelRb(pHead); pHead = NULL; return TRUE; } BOOL dist_dwg_WriteDiction(CString sXDList, CString sDicName, CString sRecName) { AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase(); AcDbDictionary *pNameObj = NULL; AcDbDictionary *pDict = NULL; pDb->getNamedObjectsDictionary(pNameObj, AcDb::kForWrite); if (pNameObj->getAt(sDicName, (AcDbObject *&)pDict, AcDb::kForWrite) != Acad::eOk) { pDict = new AcDbDictionary; AcDbObjectId DictId; if (pNameObj->setAt(sDicName, pDict, DictId)!=Acad::eOk) { pNameObj->close(); pNameObj = NULL; delete pDict; return FALSE; } } pNameObj->close(); pNameObj = NULL; AcDbXrecord *pXrec = NULL; struct resbuf *pHead = NULL; if (pDict->getAt(sRecName, (AcDbObject *&)pXrec, AcDb::kForWrite) != Acad::eOk) { pXrec = new AcDbXrecord; AcDbObjectId xrecObjId; if (pDict->setAt(sRecName, pXrec, xrecObjId)!=Acad::eOk) { pDict->close(); pDict = NULL; delete pXrec; return FALSE; } pHead = acutBuildList(AcDb::kDxfText, sXDList, 0); } else { pXrec->rbChain(&pHead); struct resbuf *pRb = pHead; pRb->resval.rstring = _tcsdup(sXDList); } pDict->close(); pDict = NULL; pXrec->setFromRbChain(*pHead); acutRelRb(pHead); pXrec->close(); pXrec = NULL; return TRUE; } BOOL GetColorIndex(CString sColor, unsigned long &nColor) { if (sColor==_T("红色")) nColor = 1; else if (sColor==_T("黄色")) nColor = 2; else if (sColor==_T("绿色")) nColor = 3; else if (sColor==_T("青色")) nColor = 4; else if (sColor==_T("蓝色")) nColor = 5; else if (sColor==_T("紫色")) nColor = 6; else if (sColor==_T("白色")) nColor = 7; else return FALSE; return TRUE; } void GetSoftPath(CString &sSoftPath) { sSoftPath = FilePath::GetRootDir() + _T("\\"); } // 得到软件的安装路径 void GetPathName(CString &sSoftPath) { sSoftPath = FilePath::GetRootDir() + _T("\\"); } void dist_blkrcd_insert(AcDbDatabase *pDb, AcDbObjectIdArray BlcokIds, AcDbDatabase *pOrgDb) { CString sCommand; AcDbObjectId RcdId; if (pOrgDb==NULL) pOrgDb = acdbHostApplicationServices()->workingDatabase(); acedSetStatusBarProgressMeter(_T("..处理中"), 0, BlcokIds.logicalLength()); for (int nLen = 0; nLenhasPreviewIcon(); pRcd->getPreviewIcon(previewIcon); pRcd->getName(name); BOOL bIsdepend = pRcd->isDependent(); pRcd->close(); strName = _tcsdup(name); free(name); //acutPrintf("\nblockname=%s",strName); AcDbObjectIdArray objIds; AcDbDatabase *pInsertDb = new AcDbDatabase; if (pOrgDb->wblock(pInsertDb, BlcokIds[nLen])==Acad::eOk) { // dist_db_delNoUseBlk(pInsertDb); Acad::ErrorStatus es; es = pDb->insert(RcdId, strName, pInsertDb); AcDbBlockTableRecord *pRcd = NULL; if (acdbOpenObject(pRcd, RcdId, AcDb::kForWrite)==Acad::eOk) { if (bHasPreviewIcon) pRcd->setPreviewIcon(previewIcon); pRcd->close(); pRcd = NULL; } } delete pInsertDb; } acedRestoreStatusBar(); } void dist_blkrcd_insert(CString strFilePath, AcDbObjectIdArray BlcokIds, AcDbDatabase *pOrgDb) { acDocManager->lockDocument(curDoc()); AcDbDatabase *pDb = new AcDbDatabase(Adesk::kFalse); #if ARX < 19 Acad::ErrorStatus es = pDb->readDwgFile(strFilePath, SH_DENYNO); #else Acad::ErrorStatus es = pDb->readDwgFile(strFilePath, AcDbDatabase::kForReadAndAllShare); #endif if (es!=Acad::eOk) { acDocManager->unlockDocument(curDoc()); return; } acDocManager->unlockDocument(curDoc()); dist_blkrcd_insert(pDb, BlcokIds, pOrgDb); AcDb::AcDbDwgVersion dwgVer = pDb->originalFileVersion(); es = pDb->saveAs(strFilePath, false, dwgVer); delete pDb; if (es != Acad::eOk) { acutPrintf(_T("\n保存失败。")); return; } } void dist_ent_getminmaxpt(AcDbObjectIdArray GroupIds, AcGePoint3d &ptMin, AcGePoint3d &ptMax) { for (int nLen = 0; nLenptMax.x) ptMax.x = pt2.x; if (pt2.y>ptMax.y) ptMax.y = pt2.y; } } } BOOL GetEntExt(AcDbEntity *pEnt, AcGePoint3d &ptMax, AcGePoint3d &ptMin) { AcDbExtents ex; AcGePoint3d ptOrg; AcDbExtents extLast; pEnt->getGeomExtents(ex); ptMax = ex.maxPoint(); ptMin = ex.minPoint(); return TRUE; } BOOL GetEntExt(AcDbObjectId EntId, AcGePoint3d &ptMax, AcGePoint3d &ptMin) { AcDbEntity *pEnt = NULL; if (acdbOpenObject(pEnt, EntId, AcDb::kForRead)!=Acad::eOk) return FALSE; BOOL bRet = GetEntExt(pEnt, ptMax, ptMin); pEnt->close(); pEnt = NULL; return bRet; } //将选择集转成实体 void dist_ss_ToIds(ads_name ssName, AcDbObjectIdArray &EnIds) { AcDbObjectId EntId; ads_name EntName; Adesk::Int32 nLength = 0; acedSSLength(ssName, &nLength); for (int nLen = 0; nLenbiSize + PaletteSize(lpbi), (LPBITMAPINFO)lpbi, DIB_RGB_COLORS); if (hpal) SelectPalette(hdc, hpalT, FALSE); ReleaseDC(NULL, hdc); GlobalUnlock(hdib); return hbm; } HANDLE readDibFromMemory(LPVOID pDibSrc) { LPBITMAPINFOHEADER pbmih = (LPBITMAPINFOHEADER)pDibSrc; DWORD totalSize = pbmih->biSize + pbmih->biSizeImage + (DWORD)PaletteSize(pbmih); HANDLE hdib = GlobalAlloc(GHND, totalSize); LPVOID pDibDst = GlobalLock(hdib); CopyMemory(pDibDst, pDibSrc, totalSize); GlobalUnlock(hdib); return hdib; } WORD PaletteSize(VOID FAR *pv) { LPBITMAPINFOHEADER lpbi; WORD NumColors; lpbi = (LPBITMAPINFOHEADER)pv; NumColors = DibNumColors(lpbi); return (WORD)(NumColors * sizeof(RGBQUAD)); } WORD DibNumColors(VOID FAR *pv) { INT bits; LPBITMAPINFOHEADER lpbi; lpbi = ((LPBITMAPINFOHEADER)pv); if (lpbi->biClrUsed != 0) return (WORD)lpbi->biClrUsed; bits = lpbi->biBitCount; switch (bits) { case 1: return 2; case 4: return 16; case 8: return 256; default: /* A 24 bitcount DIB has no color table */ return 0; } } void makeHatch3(CString sHatchName, AcDbObjectIdArray ExtIds, AcDbObjectIdArray DftIds, int nColor, double dAngle, double dScale) { AcDbHatch *pHatch = new AcDbHatch(); AcGeVector3d normal(0.0, 0.0, 1.0); pHatch->setNormal(normal); pHatch->setElevation(0.0); Acad::ErrorStatus es1 = pHatch->setPattern(AcDbHatch::kPreDefined, sHatchName); pHatch->setAssociative(Adesk::kTrue); pHatch->setColorIndex(nColor); pHatch->setPatternAngle(dAngle); pHatch->setPatternScale(dScale); AcDbObjectId hatchId; AcDbObjectIdArray dbObjIds; pHatch->appendLoop(AcDbHatch::kExternal, ExtIds); pHatch->appendLoop(AcDbHatch::kDefault, DftIds); pHatch->evaluateHatch(); pHatch->getAssocObjIds(dbObjIds); AddEntToDb(pHatch, hatchId); AcDbEntity *pEnt; int numObjs = dbObjIds.length(); Acad::ErrorStatus es; for (int i = 0; i < numObjs; i++) { es = acdbOpenAcDbEntity(pEnt, dbObjIds[i], AcDb::kForWrite); if (es == Acad::eOk) { pEnt->addPersistentReactor(hatchId); pEnt->close(); } } } BOOL GetAttdefByBlockIdNew(AcDbObjectId BlockId, CStringArray &strTags, CStringArray &strPromts, CStringArray &strContents) { // 如果我们在这里结束程序,我们将看到当前图形中source.dwg已经被作为图块插入.但是图块中没有source.dwg所定义的Attibute. 因此我们还要做工作.后面的事情就简单了. // acDocManagerPtr()->lockDocument(curDoc()); AcDbBlockTableRecord *pBlockDef; if (acdbOpenObject(pBlockDef, BlockId, AcDb::kForRead)!=Acad::eOk) return FALSE; AcDbBlockTableRecordIterator *pIterator; pBlockDef->newIterator(pIterator); AcGePoint3d basePoint; AcDbEntity *pEnt; AcDbAttributeDefinition *pAttdef; for (pIterator->start(); !pIterator->done(); pIterator->step())//将source.dwg中所有的Attibute进行遍历 { pIterator->getEntity(pEnt, AcDb::kForRead); pAttdef = AcDbAttributeDefinition::cast(pEnt); if (pAttdef != NULL && !pAttdef->isConstant()) { strTags.Add(pAttdef->tag()); strPromts.Add(pAttdef->prompt()); strContents.Add(pAttdef->textString()); } pEnt->close(); // use pEnt... pAttdef might be NULL } pBlockDef->close(); delete pIterator; if (strTags.GetSize()>0) return TRUE; else return FALSE; } BOOL GetBlockCommand(CString sDwgPath, CString sBlockName, CString &sCommand) { return FALSE; sCommand = ""; CString sDwgName = _T("命令名"); AcDbDictionary *pNameObj, *pDict; acDocManagerPtr()->lockDocument(curDoc()); AcDbDatabase *pDb = new AcDbDatabase(Adesk::kFalse); pDb->readDwgFile(sDwgPath); if (pDb->getNamedObjectsDictionary(pNameObj, AcDb::kForWrite)!=Acad::eOk) { delete pDb; acDocManagerPtr()->unlockDocument(curDoc()); return FALSE; } if (pNameObj->getAt(sDwgName, (AcDbObject *&)pDict, AcDb::kForRead)!=Acad::eOk) { pNameObj->close(); delete pDb; acDocManagerPtr()->unlockDocument(curDoc()); return FALSE; } pNameObj->close(); AcDbXrecord *pXrec; if (pDict->getAt(sBlockName, (AcDbObject *&)pXrec, AcDb::kForRead)!=Acad::eOk) { pDict->close(); delete pDb; acDocManagerPtr()->unlockDocument(curDoc()); return FALSE; } pDict->close(); struct resbuf *pRbList; pXrec->rbChain(&pRbList); pXrec->close(); sCommand = pRbList->resval.rstring; // acutRelRb(pRbList); acDocManagerPtr()->unlockDocument(curDoc()); delete pDb; sCommand.TrimLeft(); sCommand.TrimRight(); if (sCommand==_T("")) return FALSE; return TRUE; } BOOL GetColorIndex(CString sTextPath, CString sKey, int &nRcolor, int &nGcolor, int &nBcolor) { int nIndex = 0; CString sContent; CFile file; if (!file.Open(sTextPath, CFile::modeRead)) return FALSE; CArchive ar(&file, CArchive::load); while (ar.ReadString(sContent)) { if (sContent.Find(sKey)>=0) { CString sG; CString sR; CString sB; sContent = sContent.Right(sContent.GetLength()-sKey.GetLength()); sContent.TrimLeft(); sContent.TrimRight(); int nFind; nFind = sContent.Find(_T(',')); sR = sContent.Left(nFind); sContent = sContent.Right(sContent.GetLength()-nFind-1); nFind = sContent.Find(_T(',')); sG = sContent.Left(nFind); sContent = sContent.Right(sContent.GetLength()-nFind-1); sB = sContent; nRcolor = _ttoi(sR); nGcolor = _ttoi(sG); nBcolor = _ttoi(sB); return TRUE; } } return FALSE; } BOOL GetBlockId(CString sDwgFilePath, AcDbObjectId &BlockId) { acDocManagerPtr()->lockDocument(curDoc()); CString sFileName; sFileName = sDwgFilePath.Right(sDwgFilePath.GetLength()-sDwgFilePath.ReverseFind('\\')-1); // sFileName.TrimRight(".dwg"); // sFileName.TrimRight(".DWG"); AcDbDatabase *pNewDb = new AcDbDatabase(Adesk::kFalse); pNewDb->readDwgFile(sDwgFilePath); AcDbBlockTable *pBlkTable = NULL; acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pBlkTable, AcDb::kForWrite); if (pBlkTable->has(sFileName)) { pBlkTable->getAt(sFileName, BlockId); pBlkTable->close(); acDocManagerPtr()->unlockDocument(curDoc()); return TRUE; } pBlkTable->close(); acdbHostApplicationServices()->workingDatabase()->insert(BlockId, sFileName, pNewDb); delete pNewDb; acDocManagerPtr()->unlockDocument(curDoc()); return TRUE; } BOOL RenameBlock(AcDbDatabase *&pDb, CString sOldName, CString sNewName) { BOOL bRet = FALSE; acDocManagerPtr()->lockDocument(curDoc()); AcDbObjectId RcdId; AcDbBlockTableRecord *pRcd = NULL; AcDbBlockTable *pBlkTable; pDb->getBlockTable(pBlkTable, AcDb::kForRead); if (pBlkTable->has(sNewName)) { acutPrintf(_T("\n该块名已被使用")); pBlkTable->close(); pBlkTable = NULL; acDocManagerPtr()->unlockDocument(curDoc()); ClearAcadCmdLine(); return FALSE; } if (pBlkTable->getAt(sOldName, pRcd, AcDb::kForWrite)==Acad::eOk) { pRcd->setName(sNewName); pRcd->close(); pRcd = NULL; bRet = TRUE; } pBlkTable->close(); pBlkTable = NULL; acDocManagerPtr()->unlockDocument(curDoc()); return bRet; } BOOL RenameBlock(CString sDwgName, CString sOldName, CString sNewName) { BOOL bRet = FALSE; acDocManagerPtr()->lockDocument(curDoc()); Acad::ErrorStatus es; AcDbDatabase *pDb = new AcDbDatabase(Adesk::kFalse); #if ARX < 19 es = pDb->readDwgFile(sDwgName, SH_DENYNO); #else es = pDb->readDwgFile(sDwgName, AcDbDatabase::kForReadAndAllShare); #endif AcDbObjectId RcdId; AcDbBlockTableRecord *pRcd = NULL; AcDbBlockTable *pBlkTable; if ((es = pDb->getBlockTable(pBlkTable, AcDb::kForRead))!=Acad::eOk) { delete pDb; acDocManagerPtr()->unlockDocument(curDoc()); return FALSE; } if (pBlkTable->has(sNewName)) { acutPrintf(_T("\n该块名已被使用")); pBlkTable->close(); pBlkTable = NULL; delete pDb; acDocManagerPtr()->unlockDocument(curDoc()); return FALSE; } pBlkTable->getAt(sOldName, RcdId); pBlkTable->close(); pBlkTable = NULL; if (acdbOpenObject(pRcd, RcdId, AcDb::kForWrite)!=Acad::eOk) { delete pDb; acDocManagerPtr()->unlockDocument(curDoc()); return FALSE; } pRcd->setName(sNewName); pRcd->close(); pRcd = NULL; acDocManagerPtr()->unlockDocument(curDoc()); AcDb::AcDbDwgVersion dwgVer = pDb->originalFileVersion(); pDb->saveAs(sDwgName, false, dwgVer); delete pDb; return TRUE; } void InsertBlockRef1(AcDbObjectId BlockId, AcDbObjectId &BlockRefId, AcGePoint3d ptInsert, AcGeScale3d scale, double dAngle, BOOL bCreate) { if (BlockId==NULL) return; if (bCreate==TRUE) { AcDbBlockReference *pBref = new AcDbBlockReference(ptInsert, BlockId); pBref->setScaleFactors(scale); pBref->setRotation(dAngle); AddEntToDb(pBref, BlockRefId, NULL); } CStringArray strTags; CStringArray strPromts; CStringArray strContents; CStringArray strContentsNew; CString sPrompt; //判断是不是属性块 if (!GetAttdefByBlockIdNew(BlockId, strTags, strPromts, strContents)) return; int nLength = (int)strTags.GetSize(); int nLen = 0; for (nLen = 0; nLenclose(); pBlkRef = NULL; acutPrintf(_T("\n打开块表记录失败")); return; } AcDbBlockTableRecordIterator *pIterator; pBlockDef->newIterator(pIterator); AcGePoint3d basePoint; AcDbEntity *pEnt; AcDbAttributeDefinition *pAttdef; AcDbObjectIdArray attIds; for (pIterator->start(); !pIterator->done(); pIterator->step())//将source.dwg中所有的Attibute进行遍历 { pIterator->getEntity(pEnt, AcDb::kForRead); pAttdef = AcDbAttributeDefinition::cast(pEnt); if (pAttdef != NULL && !pAttdef->isConstant()) { AcDbAttribute *pAtt = new AcDbAttribute(); pAtt->setLayer(pAttdef->layer()); pAtt->setColorIndex(pAttdef->colorIndex()); pAtt->setColor(pAttdef->color()); pAtt->setTextStyle(pAttdef->textStyle()); pAtt->setPropertiesFrom(pAttdef); pAtt->setInvisible(pAttdef->isInvisible()); basePoint = pAttdef->position(); // basePoint += pBlkRef->position().asVector(); pAtt->setPosition(basePoint); pAtt->setHeight(pAttdef->height()); //pAtt->setRotation(pAttdef->rotation()+dAngle); pAtt->setTag(pAttdef->tag()); pAtt->setFieldLength(pAttdef->fieldLength()); pAtt->setTextString(strContentsNew[nLen++]); pAtt->setHorizontalMode(pAttdef->horizontalMode()); pAtt->setVerticalMode(pAttdef->verticalMode()); pAtt->setAlignmentPoint(pAttdef->alignmentPoint()); AcDbObjectId attId; pAtt->setAttributeFromBlock(pBlkRef->blockTransform()); // ScaleEnt(ptInsert,pAtt,scale); // RotateEnt1(ptInsert,pAtt,dAngle); pBlkRef->appendAttribute(attId, pAtt); pAtt->close(); attIds.append(attId); } pEnt->close(); } pBlockDef->close(); pBlkRef->close(); pBlkRef = NULL; delete pIterator; } void GetInIFolderAndIcon(CString sIniName, CStringArray &sFolderArr, CStringArray &sBigIconArr, CStringArray &sSmllIconArr) { CStringArray sIconArr; ACHAR sIconName[256]; ACHAR sDwgName[256]; CString sDefautStr; CString sAppName; int nIndex = sIniName.ReverseFind(_T('\\')); sAppName = sIniName.Right(sIniName.GetLength()-nIndex-1); GetPrivateProfileString(sAppName, _T("文件夹"), sDefautStr, sDwgName, 256, sIniName+_T(".ini")); JxString(sDwgName, sFolderArr); if (sFolderArr.GetSize()<1) return; GetPrivateProfileString(sAppName, _T("FOLDERICON"), sDefautStr, sIconName, 256, sIniName+_T(".ini")); JxString(sIconName, sIconArr); CString sBigIcon = sIconArr[0]; CString sSmallIcon = sIconArr[1]; for (int nLen = 0; nLen=0) { int nLength = strFind.GetLength(); strZj = strFind.Left(nIndex); strFind = strFind.Right(nLength-nIndex-1); nIndex = strFind.Find(_T(","), 0); strArr.Add(strZj); } strArr.Add(strFind); } BOOL GetJd(AcGePoint3d pt1, AcGePoint3d pt2, AcGeVector3d vt, AcGePoint3d ptOut, AcGePoint3d &ptJd) { AcGePoint3dArray ptJds; AcDbLine *pLine = new AcDbLine(pt1, pt2); AcDbLine *pLine1 = new AcDbLine(ptOut, ptOut+vt); pLine->intersectWith(pLine1, AcDb::kExtendBoth, ptJds); delete pLine; if (ptJds.logicalLength()!=1) return FALSE; ptJd = ptJds[0]; return TRUE; } void CAD_FlushAcadGraphicsQueue() { if (acdbHostApplicationServices()->workingDatabase() && actrTransactionManager) { actrTransactionManager->flushGraphics(); acedUpdateDisplay(); } } void MoveRecordToZ0(AcDbBlockTable* pBlockTable,CString& sBlockName) { //整体移动,最低为点0,0 AcDbBlockTableRecord* pRec = NULL; if ( Acad::eOk == pBlockTable->getAt(sBlockName,pRec,AcDb::kForRead) ) { AcDbBlockTableRecordIterator* pIt = NULL; pRec->newIterator(pIt); if (pIt != NULL) { AcGePoint3d ptMin; double dMinZ = 999999999.0; AcDbExtents extT; AcDbEntity* pEnt = NULL; for ( pIt->start();!pIt->done();pIt->step() ) { if ( Acad::eOk == pIt->getEntity(pEnt,AcDb::kForRead) ) { pEnt->getGeomExtents(extT); ptMin = extT.minPoint(); if (dMinZ > ptMin.z) { dMinZ = ptMin.z; } pEnt->close(); } } AcGeVector3d vtM(0,0,-dMinZ); AcGeMatrix3d xform; xform.setToTranslation(vtM); for ( pIt->start();!pIt->done();pIt->step() ) { if ( Acad::eOk == pIt->getEntity(pEnt,AcDb::kForWrite) ) { pEnt->transformBy(xform); pEnt->close(); } } delete pIt; } pRec->close(); } } BOOL InSertBlockFromDwgToCurDb(CString sDwgPath, CString sBlockName, AcDbObjectId &BlockId) { Acad::ErrorStatus es; AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase(); AcDbBlockTable *pBlockTable = NULL; if (pDb->getBlockTable(pBlockTable, AcDb::kForRead)!=Acad::eOk) return FALSE; if (pBlockTable->getAt(sBlockName, BlockId)==Acad::eOk) { //MoveRecordToZ0(pBlockTable,sBlockName); pBlockTable->close(); pBlockTable = NULL; return FALSE; } pBlockTable->close(); pBlockTable = NULL; acDocManagerPtr()->lockDocument(curDoc()); AcDbDatabase *pNewDb = new AcDbDatabase(Adesk::kFalse); pNewDb->readDwgFile(sDwgPath); AcDbObjectId RcdId; if (pNewDb->getBlockTable(pBlockTable, AcDb::kForRead)!=Acad::eOk) { delete pNewDb; acDocManagerPtr()->unlockDocument(curDoc()); return FALSE; } #if ARX > 24 if (pBlockTable->getAt(sBlockName, RcdId)!=Acad::eOk) #else if (pBlockTable->getAt(sBlockName, RcdId, AcDb::kForRead)!=Acad::eOk) #endif { pBlockTable->close(); pBlockTable = NULL; delete pNewDb; acDocManagerPtr()->unlockDocument(curDoc()); return FALSE; } MoveRecordToZ0(pBlockTable,sBlockName); pBlockTable->close(); pBlockTable = NULL; AcDbDatabase *pInsertDb = new AcDbDatabase; if ((es = pNewDb->wblock(pInsertDb, RcdId))!=Acad::eOk) { delete pInsertDb; delete pNewDb; acDocManagerPtr()->unlockDocument(curDoc()); return FALSE; } es = pDb->insert(BlockId, sBlockName, pInsertDb); delete pNewDb; delete pInsertDb; acDocManagerPtr()->unlockDocument(curDoc()); return TRUE; } void DrawBlockFun() { g_BlockId = NULL; AcGeVector3d g_vt = AcGeVector3d(0, 0, 0); g_dAngle = 0.0; BOOL bGet = FALSE; TCHAR cValue[256]; CString sDefautStr; CString strPathName; BaseFuncs::GetPathName(strPathName); strPathName += _T("\\tk\\Customer\\图库中心"); CString strSubPath = g_strInsertDwgPath; CString subPath(strSubPath), pathName(strPathName); subPath.MakeUpper(); pathName.MakeUpper(); if (subPath.Find(pathName, 0)>=0) subPath = subPath.Right(subPath.GetLength()-pathName.GetLength()); bGet = GetPrivateProfileString(subPath, g_strInsertBlockName, sDefautStr, cValue, 256, pathName+_T("\\dwglib.ini")); BaseFuncs::InSertBlockFromDwgToCurDb(g_strInsertDwgPath, g_strInsertBlockName, g_BlockId); if (g_BlockId==NULL) return; // AfxMessageBox("44"); CAcModuleResourceOverride res; Showtkcsdlg(TRUE); g_TkcsDlg->m_strAngle = "0.0"; g_TkcsDlg->m_strScaleX = "1.0"; g_TkcsDlg->m_strScaleY = "1.0"; g_TkcsDlg->m_strScaleZ = "1.0"; CStringArray strArr; BaseFuncs::JxString(cValue, _T(","), strArr); BOOL bAutoScale = FALSE; BOOL bAutoExplode = FALSE; BOOL bMM = FALSE; if (strArr.GetSize()==3) { bMM = _ttoi(strArr[0]); bAutoScale = _ttoi(strArr[1]); bAutoExplode = _ttoi(strArr[2]); } if (!bMM) //图块的原始单位是米 { if (BaseFuncs::IsMMUnitForDwg()) //毫米 { g_TkcsDlg->m_strScaleX.Format(_T("%0.4f"), 1000.0); g_TkcsDlg->m_strScaleY.Format(_T("%0.4f"), 1000.0); g_TkcsDlg->m_strScaleZ.Format(_T("%0.4f"), 1000.0); } } else { if (!BaseFuncs::IsMMUnitForDwg())//米 { g_TkcsDlg->m_strScaleX.Format(_T("%0.4f"), 0.001); g_TkcsDlg->m_strScaleY.Format(_T("%0.4f"), 0.001); g_TkcsDlg->m_strScaleZ.Format(_T("%0.4f"), 0.001); } } if (bAutoScale) { if (!BaseFuncs::IsMMUnitForDwg())//米 { g_TkcsDlg->m_strScaleX.Format(_T("%0.4f"), _ttof(g_TkcsDlg->m_strScaleX)); g_TkcsDlg->m_strScaleY.Format(_T("%0.4f"), _ttof(g_TkcsDlg->m_strScaleY)); g_TkcsDlg->m_strScaleZ.Format(_T("%0.4f"), _ttof(g_TkcsDlg->m_strScaleZ)); } else { g_TkcsDlg->m_strScaleX.Format(_T("%0.4f"), _ttof(g_TkcsDlg->m_strScaleX)/1000.0); g_TkcsDlg->m_strScaleY.Format(_T("%0.4f"), _ttof(g_TkcsDlg->m_strScaleY)/1000.0); g_TkcsDlg->m_strScaleZ.Format(_T("%0.4f"), _ttof(g_TkcsDlg->m_strScaleZ)/1000.0); } } g_TkcsDlg->m_strLengthX.Format(_T("%0.3f"), _ttof(g_TkcsDlg->m_strScaleX)*g_TkcsDlg->m_dUnitLengthX); g_TkcsDlg->m_strLengthY.Format(_T("%0.3f"), _ttof(g_TkcsDlg->m_strScaleY)*g_TkcsDlg->m_dUnitLengthY); g_TkcsDlg->m_strLengthZ.Format(_T("%0.3f"), _ttof(g_TkcsDlg->m_strScaleZ)*g_TkcsDlg->m_dUnitLengthZ); g_TkcsDlg->UpdateData(FALSE); //g_TkcsDlg->UpdateDataAll(); CLayer layer(_T("图库中心"), g_sLayerName); while (1) { acedGetAcadDwgView()->SetFocus(); BOOL bAppend = FALSE; AcEdBlockDrag *drag = new AcEdBlockDrag(g_BlockId, g_dBlockScale, g_dAngle, g_vt); drag->doIt(); bAppend = drag->m_bAppend; g_dAngle = drag->m_dAngle; g_dBlockScale = drag->m_dScale; g_vt = drag->m_vt; AcDbObjectId objId = drag->m_objId; delete drag; drag = NULL; if (!bAppend) break; if (bAutoExplode) { AcDbVoidPtrArray voidPtrArr; AcDbEntity *pEnt = NULL; if (acdbOpenObject(pEnt, objId, AcDb::kForRead)==Acad::eOk) { pEnt->explode(voidPtrArr); pEnt->close(); pEnt = NULL; } for (int nLen = 0; nLenShowControlBar(g_pDockPane, TRUE, FALSE); } BOOL GetLayerParam(CString sAppName, CString sLayerName, LayerParam &pm) { CStringArray strArr; CString sDefautStr; TCHAR sLayerParam[256]; CString sSoftPath; GetSoftPath(sSoftPath); GetPrivateProfileString(sAppName, sLayerName, sDefautStr, sLayerParam, 256, sSoftPath+_T("\\Sys\\LayerConfig.ini")); JxString(sLayerParam, strArr); if (strArr.GetSize()==8) { pm.sKey = sLayerName; pm.sLayerName = strArr[0]; pm.nColorIndex = _ttoi(strArr[1]); pm.strColor = strArr[1]; pm.dLineWidth = _ttof(strArr[2]); pm.sLineType = strArr[3]; pm.bClose = _ttoi(strArr[4]); pm.bFreeze = _ttoi(strArr[5]); pm.bvpdflt = _ttoi(strArr[6]); pm.bLock = _ttoi(strArr[7]); return TRUE; } return FALSE; } void CreateLineType(CString sLineTypeName, AcDbObjectId &LineTypeId) { CString sSoftPath; GetSoftPath(sSoftPath); sSoftPath += _T("Sys\\Customer.lin"); Acad::ErrorStatus es = acdbLoadLineTypeFile(sLineTypeName, sSoftPath, acdbHostApplicationServices()->workingDatabase()); AcDbLinetypeTable *pLineTpTable; AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase(); pDb->getLinetypeTable(pLineTpTable, AcDb::kForWrite); pLineTpTable->getAt(sLineTypeName, LineTypeId); pLineTpTable->close(); } void GetLineTypeId(CString sLineTypeName, AcDbObjectId &LineTypeId) { AcDbLinetypeTable *pLineTpTable; AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase(); pDb->getLinetypeTable(pLineTpTable, AcDb::kForRead); pLineTpTable->getAt(sLineTypeName, LineTypeId); pLineTpTable->close(); } AcDbObjectId CreateLayer(CString sAppName, CString sLayerName) { AcDbObjectId LineTypeId; LayerParam pm; AcDbObjectId LayerId; AcDbLayerTable *pLayerTbl; acdbHostApplicationServices()->workingDatabase() ->getSymbolTable(pLayerTbl, AcDb::kForWrite); if (GetLayerParam(sAppName, sLayerName, pm)) { sLayerName = pm.sLayerName; if (!pLayerTbl->has(sLayerName)) { AcDbLayerTableRecord *pLayerTblRcd = new AcDbLayerTableRecord; pLayerTblRcd->setName(sLayerName); pLayerTblRcd->setIsFrozen(pm.bFreeze ? true : false); pLayerTblRcd->setIsOff(pm.bClose ? true : false); pLayerTblRcd->setVPDFLT(pm.bvpdflt ? true : false); pLayerTblRcd->setIsLocked(pm.bLock ? true : false); GetLineTypeId(pm.sLineType, LineTypeId); if (LineTypeId==NULL) CreateLineType(pm.sLineType, LineTypeId); if (LineTypeId!=NULL) pLayerTblRcd->setLinetypeObjectId(LineTypeId); // pLayerTblRcd->setLineWeight(pm.dLineWidth); // pLayerTblRcd->setL AcCmColor color; color.setColorIndex(pm.nColorIndex); pLayerTblRcd->setColor(color); pLayerTbl->add(pLayerTblRcd); pLayerTblRcd->close(); } // pLayerTbl->close(); } pLayerTbl->getAt(sLayerName, LayerId); pLayerTbl->close(); return LayerId; } bool IsMMUnitForDwg() { struct resbuf rb; acedGetVar(_T("INSUNITS"), &rb); if (rb.resval.rint == AcDb::kUnitsMillimeters) return true; return false; } void OpenTkAndSelectByName(LPCTSTR pszFolder, LPCTSTR pszDwg) { // 首先打开库图 if (g_pDockPane == NULL) { AfxSetResourceHandle(_hdllInstance); g_pDockPane = new CDockPane; g_pDockPane->Create(acedGetAcadFrame(), _T("图库中心")); AfxSetResourceHandle(acedGetAcadResourceInstance()); g_pDockPane->EnableDocking(CBRS_ALIGN_ANY); g_pDockPane->m_DockDialog.m_pMyFrame->ShowExplainCtrl(); g_pDockPane->RestoreControlBar(); } else { acedGetAcadFrame()->ShowControlBar(g_pDockPane, TRUE, FALSE); } if (pszFolder && pszDwg) g_pDockPane->SetSltDwgFile(pszFolder, pszDwg); } void updateBlockIcon() { SHacedCommand(RTSTR, _T("blockIcon"), RTSTR, _T(""), 0); } } namespace BaseFuncs { CLayer::CLayer(CString sAppName, CString sLyaerName, BOOL bRet) { m_bRet = bRet; m_OldId = acdbHostApplicationServices()->workingDatabase()->clayer(); AcDbObjectId LayerId = CreateLayer(sAppName, sLyaerName); acdbHostApplicationServices()->workingDatabase()->setClayer(LayerId); AcDbLayerTableRecord *pRcd = NULL; if (acdbOpenObject(pRcd, LayerId, AcDb::kForWrite)==Acad::eOk) { pRcd->setIsOff(FALSE); pRcd->close(); pRcd = NULL; } } CLayer::~CLayer() { if (m_bRet) acdbHostApplicationServices()->workingDatabase()->setClayer(m_OldId); } }