#include "StdAfx.h" #include "jig.h" TDrawingIdxEdJig::TDrawingIdxEdJig(TDbSymbDrawingIndex *pIdx, CDimPipeSerialDlg *pDlg) { m_pDrawEnt = pIdx; m_pDlg = pDlg; m_pDlg2 = NULL; } TDrawingIdxEdJig::TDrawingIdxEdJig(TDbSymbDrawingIndex *pIdx, CDimSanitaryDlg *pDlg) { m_pDrawEnt = pIdx; m_pDlg2 = pDlg; m_pDlg = NULL; } TDrawingIdxEdJig::TDrawingIdxEdJig(TDbSymbDrawingIndex *pIdx) { m_pDrawEnt = pIdx; m_pDlg2 = NULL; m_pDlg = NULL; } AcEdJig::DragStatus TDrawingIdxEdJig::GetPoint(XPoint &pt) { if(!m_ptRef) return acquirePoint(pt); else return acquirePoint(pt, m_ptRef); } // 开始执行拖动 int TDrawingIdxEdJig::DoIt(int *keyIndex) { int nRet = TSymbEdJig::DoIt(keyIndex); return nRet; } // 更新实体数据 Adesk::Boolean TDrawingIdxEdJig::update() { Adesk::Boolean bRet=Adesk::kTrue; if(m_pDlg){ m_pDlg->UpdateData(); CString csTextStyle; if(m_pDlg->m_iStyle > -1) m_pDlg->m_comboStyle.GetLBText(m_pDlg->m_iStyle, csTextStyle); m_pDrawEnt->SetTextStyleId(InitTextStyle((const TCHAR*)csTextStyle)); m_pDrawEnt->SetIndexLabel((const TCHAR*)m_pDlg->m_csX); m_pDrawEnt->SetDrawingLabel((const TCHAR*)m_pDlg->m_csY); m_pDrawEnt->SetLineWidth(m_pDlg->m_nWidth); m_pDrawEnt->SetRadius(m_pDlg->m_nRadius); // 增加“出圈文字样式”和字高系数设置 cet 2013.3.14 add int nType = m_pDlg->GetTextType(); m_pDrawEnt->SetOldStyle(nType); if (nType == 0 || nType == 3) { double dTextHeight = m_pDlg->GetTextHeightCoefficient(); m_pDrawEnt->SetTextRatio(dTextHeight); } } else if(m_pDlg2){ m_pDlg2->UpdateData(); CString csTextStyle; if(m_pDlg2->m_iStyle > -1) m_pDlg2->m_comboStyle.GetLBText(m_pDlg2->m_iStyle, csTextStyle); m_pDrawEnt->SetTextStyleId(InitTextStyle((const TCHAR*)csTextStyle)); m_pDrawEnt->SetIndexLabel((const TCHAR*)m_pDlg2->m_csText); m_pDrawEnt->SetLineWidth(m_pDlg2->m_nWidth); m_pDrawEnt->SetRadius(m_pDlg2->m_nRadius); } m_pDrawEnt->SetCenter(m_ptResult); return bRet; } AcDbEntity* TDrawingIdxEdJig::entity() const { return (AcDbEntity *)m_pDrawEnt; } //*************************************************************************************************** // 管道坡度 //*************************************************************************************************** //90度~270度是反, 270~90度是正, 顺时针旋转, 90度和270度是正 BOOL IsLineReverse(double nLineRotate) { if(nLineRotate > PI * 2) nLineRotate -= PI*2; if(fabs(nLineRotate - PI/2) < 0.001 || fabs(nLineRotate - PI/2*3) < 0.001) return FALSE; if(nLineRotate > PI/2 && nLineRotate < PI/2*3) return TRUE; return FALSE; } TArrowEdJig::TArrowEdJig(TDbSymbArrow *pIdx, XPoint ptRef, XPoint ptStart, XPoint ptEnd, double dDimDist2Pipe) { m_pDrawEnt = pIdx; m_ptRef = ptRef; m_ptStart = ptStart; m_ptEnd = ptEnd; m_dDimDist2Pipe = dDimDist2Pipe; m_bFromStart = TRUE; SetArrow2TextDist(); } // zxl 2012.04.01 add 设定文字距离箭头距离 void TArrowEdJig::SetArrow2TextDist() { m_dDist = (m_pDrawEnt->GetTextHeight() + m_pDrawEnt->GetText2BaseRatio() * 2) * DocGetPScale(); } AcEdJig::DragStatus TArrowEdJig::GetPoint(XPoint &pt) { return acquirePoint(pt, m_ptRef); } // 开始执行拖动 int TArrowEdJig::DoIt(int *keyIndex) { int nRet = TSymbEdJig::DoIt(keyIndex); return nRet; } // 更新实体数据 Adesk::Boolean TArrowEdJig::update() { Adesk::Boolean bRet=Adesk::kTrue; AcGeVector3d vectTmp(m_ptResult.x - m_ptRef.x, m_ptResult.y - m_ptRef.y, 0); vectTmp.normalize(); AcGeVector3d vectBase(m_ptStart.x - m_ptEnd.x, m_ptStart.y - m_ptEnd.y, 0); vectBase.normalize(); double dAng = vectBase.angleTo(vectTmp, AcGeVector3d::kZAxis); double n = Radian2Angle(dAng); double nPipeAng = ads_angle(m_ptStart, m_ptEnd); if(fabs(nPipeAng - PI/2*3) < 0.0001) nPipeAng -= PI; XPoint ptStart, ptEnd, ptText; ptText = m_pDrawEnt->GetDefaultTextLocation(); BOOL flag = IsLineReverse(nPipeAng);//管线逆向绘制 if(flag){ if(dAng >= 0 && dAng < PI/2){ //第1象限 m_bFromStart = FALSE; ads_polar(m_ptStart, nPipeAng-PI/2, m_dDimDist2Pipe/2*DocGetPScale(), ptEnd); ads_polar(m_ptEnd, nPipeAng-PI/2, m_dDimDist2Pipe/2*DocGetPScale(), ptStart); } else if(dAng >= PI/2 && dAng < PI){ //第2象限 m_bFromStart = TRUE; ads_polar(m_ptStart, nPipeAng-PI/2, m_dDimDist2Pipe/2*DocGetPScale(), ptStart); ads_polar(m_ptEnd, nPipeAng-PI/2, m_dDimDist2Pipe/2*DocGetPScale(), ptEnd); } else if(dAng >= PI && dAng < PI/2*3){ //第3象限 //ads_polar(ptText, nPipeAng+PI/2, (g_nTwtDimHeight + 1)*DocGetPScale(), ptText); ads_polar(ptText, nPipeAng+PI/2, m_dDist, ptText); m_bFromStart = TRUE; ads_polar(m_ptStart, nPipeAng+PI/2, m_dDimDist2Pipe/2*DocGetPScale(), ptStart); ads_polar(m_ptEnd, nPipeAng+PI/2, m_dDimDist2Pipe/2*DocGetPScale(), ptEnd); } else if(dAng >= PI/2*3 && dAng < PI*2){//第4象限 //ads_polar(ptText, nPipeAng+PI/2, (g_nTwtDimHeight + 1)*DocGetPScale(), ptText); ads_polar(ptText, nPipeAng+PI/2, m_dDist, ptText); m_bFromStart = FALSE; ads_polar(m_ptStart, nPipeAng+PI/2, m_dDimDist2Pipe/2*DocGetPScale(), ptEnd); ads_polar(m_ptEnd, nPipeAng+PI/2, m_dDimDist2Pipe/2*DocGetPScale(), ptStart); } } else{//顺向绘制,象限与逆向绘制相反 if(dAng >= 0 && dAng < PI/2){ //第3象限 //ads_polar(ptText, nPipeAng-PI/2, (g_nTwtDimHeight + 1)*DocGetPScale(), ptText); ads_polar(ptText, nPipeAng-PI/2, m_dDist, ptText); m_bFromStart = FALSE; ads_polar(m_ptStart, nPipeAng-PI/2, m_dDimDist2Pipe/2*DocGetPScale(), ptEnd); ads_polar(m_ptEnd, nPipeAng-PI/2, m_dDimDist2Pipe/2*DocGetPScale(), ptStart); } else if(dAng >= PI/2 && dAng < PI){ //第4象限 //ads_polar(ptText, nPipeAng-PI/2, (g_nTwtDimHeight + 1)*DocGetPScale(), ptText); ads_polar(ptText, nPipeAng-PI/2, m_dDist, ptText); m_bFromStart = TRUE; ads_polar(m_ptStart, nPipeAng-PI/2, m_dDimDist2Pipe/2*DocGetPScale(), ptStart); ads_polar(m_ptEnd, nPipeAng-PI/2, m_dDimDist2Pipe/2*DocGetPScale(), ptEnd); } else if(dAng >= PI && dAng <= PI/2*3){ //第1象限 m_bFromStart = TRUE; ads_polar(m_ptStart, nPipeAng+PI/2, m_dDimDist2Pipe/2*DocGetPScale(), ptStart); ads_polar(m_ptEnd, nPipeAng+PI/2, m_dDimDist2Pipe/2*DocGetPScale(), ptEnd); } else if(dAng > PI/2*3 && dAng < PI*2){//第2象限 m_bFromStart = FALSE; ads_polar(m_ptStart, nPipeAng+PI/2, m_dDimDist2Pipe/2*DocGetPScale(), ptEnd); ads_polar(m_ptEnd, nPipeAng+PI/2, m_dDimDist2Pipe/2*DocGetPScale(), ptStart); } } m_pDrawEnt->SetTextLocation(ptText); XPoly2D poly; poly.AppendNode(ptStart); poly.AppendNode(ptEnd); m_pDrawEnt->SetPoly2D(poly); return bRet; } AcDbEntity* TArrowEdJig::entity() const { return (AcDbEntity *)m_pDrawEnt; } TMultPipeDimEdJig::TMultPipeDimEdJig(TDbPipeMultDim *pElev) { m_pDrawEnt=pElev; } AcEdJig::DragStatus TMultPipeDimEdJig::GetPoint(XPoint &pt) { return acquirePoint(pt); } // 开始执行拖动 int TMultPipeDimEdJig::DoIt(int *keyIndex) { m_ptResult = m_pDrawEnt->GetTurnPoint(); int nRet = TSymbEdJig::DoIt(keyIndex); return nRet; } #define WHV_ON 0x0 //原点 #define WHV_UP 0x2 //上 #define WHV_RIGHT 0x4 //右 int WhereOfVector2d(const XPoint& ptWho, const ads_real dRotation, const XPoint &ptQst) { int flag=0x0; ads_matrix mat1; ads_matrix mat2; ptWho.GetRotationMatrix( dRotation*-1, mat1 ); ptWho.GetMoveMatrix(XPoint(), mat2); XPoint ptTmp(ptQst); ptTmp.TransformBy( mat1 ); ptTmp.TransformBy( mat2 ); if (ptTmp == ptQst) { flag |= WHV_ON; } if (ptTmp.x > 0.0) { flag |= WHV_RIGHT; } if (ptTmp.y > 0.0) { flag |= WHV_UP; } return flag; } double GetLayoutRotate(double nRotateIn) { double nRotate(0); if(fabs(nRotateIn - PI) < 0.01 || nRotateIn > PI) nRotateIn = nRotateIn - PI; if(nRotateIn > 0 && (nRotateIn < PI/2 || fabs(nRotateIn - PI/2) < 0.01)) nRotate = nRotateIn - PI/2; else if(fabs(nRotateIn) < 0.001) nRotate = nRotateIn + PI/2; else if(nRotateIn < PI*2 && nRotateIn > PI*3/2) nRotate = nRotateIn + PI/2; else nRotate = nRotateIn - PI/2; return nRotate; } // 更新实体数据 Adesk::Boolean TMultPipeDimEdJig::update() { Adesk::Boolean bRet=Adesk::kTrue; XLine lnMin(m_ptLeftUp, m_ptRightUp); double dir = lnMin.Direction(); int flagLeftUp = WhereOfVector2d(m_ptLeftUp, dir, m_ptResult); int flagRightUp = WhereOfVector2d(m_ptRightUp, dir, m_ptResult); int flagLeftDown = WhereOfVector2d(m_ptLeftDown, dir, m_ptResult); if ((flagLeftUp&WHV_RIGHT) == WHV_RIGHT && (flagRightUp&WHV_RIGHT) != WHV_RIGHT) { XPoint ptTmp1,ptTmp2; m_ptResult.Project(&lnMin, ptTmp1); int flag = WhereOfVector2d(m_ptLeftUp, dir, m_ptLeftDown); if ((flag&WHV_UP) != WHV_UP && (flagLeftDown&WHV_UP) != WHV_UP) { ads_polar(ptTmp1, dir+PI/2, 0.5*DocGetPScale(), ptTmp2); } else if((flag&WHV_UP) != WHV_UP && (flagLeftDown&WHV_UP) == WHV_UP){ ads_polar(ptTmp1, dir-PI/2, m_ptLeftUp.Distance2d(m_ptLeftDown)+DocGetPScale(), ptTmp2); } else if((flag&WHV_UP) == WHV_UP && (flagLeftDown&WHV_UP) == WHV_UP){ ads_polar(ptTmp1, dir-PI/2, 0.5*DocGetPScale(), ptTmp2); } else if((flag&WHV_UP) == WHV_UP && (flagLeftDown&WHV_UP) != WHV_UP){ ads_polar(ptTmp1, dir+PI/2, m_ptLeftUp.Distance2d(m_ptLeftDown)+DocGetPScale(), ptTmp2); } ptTmp2.z = 0; m_ptResult.z = 0; DList lstPipe; m_pDrawEnt->GetPipes(lstPipe); if(lstPipe.Length() == 1) m_pDrawEnt->SetStartPoint(ptTmp1);//如果是单管引出标注,起点在管线上 else m_pDrawEnt->SetStartPoint(ptTmp2);//如果是多管引出标注,多1段小尾巴 m_pDrawEnt->SetTurnPoint(m_ptResult); } double nRotate = GetLayoutRotate(ads_angle(m_pDrawEnt->GetStartPoint(), m_pDrawEnt->GetTurnPoint())); m_pDrawEnt->SetLayoutRotation(nRotate); return bRet; } AcDbEntity* TMultPipeDimEdJig::entity() const { return (AcDbEntity *)m_pDrawEnt; } // 工具条升级标准 bool UpdateText2(CString &sCmd) { if (sCmd.Compare(_T("T88_")) == 0 || sCmd.Compare(_T("T98_")) == 0)// twt { sCmd = _T(""); } else if (sCmd.Compare(_T("T86_")) == 0 || sCmd.Compare(_T("T96_")) == 0) // tch { sCmd = _T(""); } else if (sCmd.Compare(_T("T83_")) == 0 || sCmd.Compare(_T("T93_")) == 0)// th { sCmd = _T(""); } else if (sCmd.Compare(_T("t88_")) == 0 || sCmd.Compare(_T("t98_")) == 0)// twt { sCmd = _T(""); } else if (sCmd.Compare(_T("t86_")) == 0 || sCmd.Compare(_T("t96_")) == 0) // tch { sCmd = _T(""); } else if (sCmd.Compare(_T("t83_")) == 0 || sCmd.Compare(_T("t93_")) == 0 )// th { sCmd = _T(""); } else { return false; } return true; } // 升级acad.pgp文件 void UpdateAcad2() { XString fullFile, fullFile2; if(!FindFile(_T("acad.pgp"), fullFile)) { AfxMessageBox(_T("acad.pgp文件错误!")); return; } FILE *pFile = fopen(_AS(fullFile), "r"); CString sOldText = fullFile.cs(); int n = sOldText.ReverseFind('\\'); CString sText = sOldText.Left(n + 1); fullFile2 = sText + _T("acadCopy.pgp"); FILE *pFileCopy = fopen(_AS(fullFile2), "w"); if(!pFile || !pFileCopy) { return; } while(!feof(pFile)) { char sBuf[256]=""; fgets(sBuf, 255, pFile); CString csTmp = sBuf; csTmp.TrimRight(); int iIndex = csTmp.Find(_T("_")); if(iIndex > 0) { iIndex++; CString sCmdLeft = csTmp.Left(iIndex); CString sCmdRight = csTmp.Right(csTmp.GetLength() - iIndex); CString sCmd = sCmdLeft.Right(4); UpdateText2(sCmd); sCmdLeft = sCmdLeft.Left(sCmdLeft.GetLength() - 4); csTmp = sCmdLeft + sCmd + sCmdRight; } csTmp +=_T("\n"); fputs(_AS(csTmp), pFileCopy); } fclose(pFile); fclose(pFileCopy); remove(_AS(fullFile)); rename(_AS(fullFile2), _AS(fullFile)); } #include"TGAs.h" // 升级tchdata.dbf文件 void UpdateTchData2() { CodeBase db; XString fullFile; if(!FindFile(_T("tchdata.dbf"), fullFile)) { AfxMessageBox(_T("tchdata.dbf文件错误!")); return; } XDbfTable *pTable = db.Open(fullFile); if(!pTable) { return; } CString sCmd, sCmdNew; for(pTable->MoveFirst();!pTable->IsEOF();pTable->MoveNext()) { GET_FIELD(pTable, _T("Engcmd"), sCmd); int nIndex = sCmd.Find(_T("_")); if(nIndex > 0) { nIndex++; CString sCmdLeft = sCmd.Left(nIndex); sCmdLeft.TrimLeft(); CString sCmdRight = sCmd.Right(sCmd.GetLength() - nIndex); if (!UpdateText2(sCmdLeft)) { continue; } sCmdNew = sCmdLeft + sCmdRight; SET_FIELD(pTable, _T("Engcmd"), (const TCHAR*)sCmdNew); } } } // 工具条升级2 void UpdateToolBarCmd() { UpdateTchData2(); UpdateAcad2(); AfxMessageBox(_T("工具条升级完成,需重启软件生效! ")); }