#include "stdafx.h" #include "TDbWireDimNew.h" #include "dbtext.h" #include #include "TSysCoordinateTool.h" #include "dbxutil.h" #define SPEC_CHAR _T("@") const Adesk::UInt8 TDbWireDimNew::g_nVersion = 2; AcGePoint3d g_ptTextPos = AcGePoint3d::kOrigin; //T20标注样式0时文字的插入点 ACRX_DXF_DEFINE_MEMBERS(ATSWireDimNew, ATSSymbWithText, AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent, 1, ATS_WIREDIM2, "ATS_WIREDIM2图形无法解析, 请下载上华软件|网址: www.shanghuasoft.com"); IMPLEMENT_TENTBASE(TDbWireDimNew); TDbWireDimNew::TDbWireDimNew() { m_vtDir = AcGeVector3d::kXAxis; m_bShowLine = TRUE; m_bSample = FALSE; //是否是简标 m_dLineBaseLen = 0.0; //线最初长度 m_csWeakWireNum = _T(""); } TDbWireDimNew::~TDbWireDimNew() { } CString TDbWireDimNew::getWireText() { if (m_vecText.size() > 0) { CString csType; //导线型号 CString csRadius; //穿管直径 CString csMode; //配线方式 CString csPlace; //敷设部位 CString csArea; //导线规格 CString csNorm; CString csName; //回路编号 //解析得到想要的 ParseText(m_vecText[0],csType,csRadius,csMode,csPlace,csArea,csNorm,csName); return csName; } return _T(""); } Acad::ErrorStatus TDbWireDimNew::subGetClassID(CLSID* pClsid) const { return Acad::eOk; } //版本控制 Acad::ErrorStatus TDbWireDimNew::dwgInFieldsVer1 (AcDbDwgFiler* pFiler) { if (pFiler != NULL) { Adesk::Int16 nCount = 0; Adesk::Int16 nSample = 0; Adesk::Int16 nShowLine = 0; AcGePoint3d ptS; pFiler->readInt16(&nCount); //起点 m_arPtS.setLogicalLength(0); for (int i = 0; i < nCount; ++i) { pFiler->readItem(&ptS); m_arPtS.append(ptS); } pFiler->readItem(&m_ptTurn); pFiler->readItem(&m_vtDir); pFiler->readItem(&nSample); pFiler->readItem(&nShowLine); pFiler->readItem(&m_dLineBaseLen); m_dLineBaseLen /= GetPScale(); m_bSample = nSample; m_bShowLine = nShowLine; //文字 pFiler->readInt16(&nCount); AcDbSoftPointerId handle; TCHAR *lpText = NULL; m_vecIds.clear(); for (int j = 0; j < nCount; ++j) { pFiler->readSoftPointerId(&handle); m_vecIds.push_back(handle); //解决兼容问题 CString sText; GetNeedDimStr(handle,sText, m_csWeakWireNum);//modify by wx 2015-1-14 增加了弱电缆线的返回 m_vecText.push_back(sText); AcGeVector3d vtBottom; GetEntVector(handle,vtBottom); m_vecBottomVt.push_back(vtBottom); } } return Acad::eOk; } Acad::ErrorStatus TDbWireDimNew::dwgOutFieldsVer1(AcDbDwgFiler* pFiler) const { if (pFiler != NULL) { //写入起点个数 int nCount = m_arPtS.length(); pFiler->writeInt16(Adesk::Int16(nCount)); for (int i = 0; i < nCount; ++i) { pFiler->writeItem(m_arPtS[i]); } pFiler->writeItem(m_ptTurn); pFiler->writeItem(m_vtDir); pFiler->writeItem(Adesk::Int16(m_bSample)); pFiler->writeItem(Adesk::Int16(m_bShowLine)); pFiler->writeItem(m_dLineBaseLen*GetPScale()); //写入文字 nCount = (int)m_vecIds.size(); pFiler->writeInt16(Adesk::Int16(nCount)); AcDbSoftPointerId handle; for (int j = 0; j < nCount; ++j) { handle = m_vecIds[j]; pFiler->writeSoftPointerId(handle); } } return Acad::eOk; } Acad::ErrorStatus TDbWireDimNew::dwgInFieldsVer2 (AcDbDwgFiler* pFiler) { if (pFiler != NULL) { Adesk::Int16 nCount = 0; Adesk::Int16 nSample = 0; Adesk::Int16 nShowLine = 0; AcGePoint3d ptS; pFiler->readInt16(&nCount); //起点 m_arPtS.setLogicalLength(0); for (int i = 0; i < nCount; ++i) { pFiler->readItem(&ptS); m_arPtS.append(ptS); } pFiler->readItem(&m_ptTurn); pFiler->readItem(&m_vtDir); pFiler->readItem(&nSample); pFiler->readItem(&nShowLine); pFiler->readItem(&m_dLineBaseLen); m_dLineBaseLen /= GetPScale(); m_bSample = nSample; m_bShowLine = nShowLine; //文字 pFiler->readInt16(&nCount); AcDbSoftPointerId handle; TCHAR *lpText = NULL; m_vecText.clear(); m_vecBottomVt.clear(); AcGeVector3d vtBottom; for (int j = 0; j < nCount; ++j) { pFiler->readString(&lpText); m_vecText.push_back(lpText); acutDelString(lpText); pFiler->readVector3d(&vtBottom); m_vecBottomVt.push_back(vtBottom); } } return Acad::eOk; } Acad::ErrorStatus TDbWireDimNew::dwgOutFieldsVer2(AcDbDwgFiler* pFiler) const { if (pFiler != NULL) { //写入起点个数 int nCount = m_arPtS.length(); pFiler->writeInt16(Adesk::Int16(nCount)); for (int i = 0; i < nCount; ++i) { pFiler->writeItem(m_arPtS[i]); } pFiler->writeItem(m_ptTurn); pFiler->writeItem(m_vtDir); pFiler->writeItem(Adesk::Int16(m_bSample)); pFiler->writeItem(Adesk::Int16(m_bShowLine)); pFiler->writeItem(m_dLineBaseLen*GetPScale()); //写入文字 nCount = (int)m_vecText.size(); pFiler->writeInt16(Adesk::Int16(nCount)); AcDbSoftPointerId handle; CString sText; for (int j = 0; j < nCount; ++j) { sText = m_vecText[j]; pFiler->writeString((LPCTSTR)sText); if (m_vecBottomVt.size() > j) pFiler->writeVector3d(m_vecBottomVt[j]); } } return Acad::eOk; } Acad::ErrorStatus TDbWireDimNew::dwgInFields (AcDbDwgFiler* pFiler) { assertWriteEnabled(); Acad::ErrorStatus es = TDbSymbWithText::dwgInFields(pFiler); if(es != Acad::eOk) return es; Adesk::UInt8 nVer = 0; pFiler->readItem(&nVer); if(nVer>g_nVersion) {// Version is too new return Acad::eMakeMeProxy; } switch(nVer) { case 1: dwgInFieldsVer1(pFiler); break; case 2: dwgInFieldsVer2(pFiler); break; default: break; } return pFiler->filerStatus(); } Acad::ErrorStatus TDbWireDimNew::dwgOutFields(AcDbDwgFiler *pFiler) const { assertReadEnabled(); Acad::ErrorStatus es = TDbSymbWithText::dwgOutFields(pFiler); if(es != Acad::eOk) return es; pFiler->writeItem(g_nVersion); switch(g_nVersion) { case 1: dwgOutFieldsVer1(pFiler); break; case 2: dwgOutFieldsVer2(pFiler); break; default: break; } return pFiler->filerStatus(); } Acad::ErrorStatus TDbWireDimNew::dxfInFields (AcDbDxfFiler *pFiler) { assertWriteEnabled(); Acad::ErrorStatus es = TDbSymbWithText::dxfInFields(pFiler); if(es!=Acad::eOk) return pFiler->filerStatus(); if (!pFiler->atSubclassData(_T("TDbWireDimNew"))) { return Acad::eBadDxfSequence; } return pFiler->filerStatus(); } Acad::ErrorStatus TDbWireDimNew::dxfOutFields(AcDbDxfFiler *pFiler) const { assertReadEnabled(); Acad::ErrorStatus es=TDbSymbWithText::dxfOutFields(pFiler); assert(es == Acad::eOk); es = pFiler->writeItem(AcDb::kDxfSubclass,_T("TDbWireDimNew")); assert(es == Acad::eOk); return Acad::eOk; } Acad::ErrorStatus TDbWireDimNew::subGetGripPoints(AcGePoint3dArray& gripPoints, AcDbIntArray& osnapModes, AcDbIntArray& geomIds) const { BOOL bShowLine = GetShowObliqueLine(); if (!bShowLine) { gripPoints.append(m_arPtS[0]); gripPoints.append(m_ptTurn); return Acad::eOk; } for (int i = 0; i < m_arPtS.length(); ++i) gripPoints.append(m_arPtS[i]); gripPoints.append(m_ptTurn); AcGePoint3d ptEnd; ptEnd = m_ptTurn + m_vtDir * m_dLineBaseLen*GetPScale(); gripPoints.append(ptEnd); return Acad::eOk; } Acad::ErrorStatus TDbWireDimNew::subGetStretchPoints(AcGePoint3dArray & stretchPoints) const { AcGePoint3d ptEnd; for (int i = 0; i < m_arPtS.length(); ++i) stretchPoints.append(m_arPtS[i]); stretchPoints.append(m_ptTurn); ptEnd = m_ptTurn + m_vtDir * m_dLineBaseLen*GetPScale(); stretchPoints.append(ptEnd); return Acad::eOk; } Acad::ErrorStatus TDbWireDimNew::subMoveGripPointsAt(const AcDbIntArray& indices, const AcGeVector3d& offset) { assertWriteEnabled(); int nCount = m_arPtS.length(); if (indices.length() == 1) { if (nCount == indices[0]) { //axc add 2014-09-01 拖动转向可以依据情况进行变化 if(m_arPtS.length() == 0) return Acad::eNotImplementedYet; if (Wcs2Ucs(m_ptTurn).x > Wcs2Ucs(m_arPtS[0]).x) { if (Wcs2Ucs(m_ptTurn + offset).x < Wcs2Ucs(m_arPtS[0]).x) { m_vtDir *= -1; } } else { if (Wcs2Ucs(m_ptTurn + offset).x > Wcs2Ucs(m_arPtS[0]).x) { m_vtDir *= -1; } } //add end m_ptTurn += offset; } else if (nCount > indices[0]) { for (int i = 0; i < m_arPtS.length(); ++i) { m_arPtS[i] += offset; } } else if (nCount+1 == indices[0]) { // tsj modified 2010.5.21 m_vtDir.normalize(); AcGePoint3d ptE = m_ptTurn + m_dLineBaseLen*GetPScale() * m_vtDir; AcDbLine line(m_ptTurn,ptE); AcGePoint3d ptOnLine; ptE += offset; line.getClosestPointTo(ptE,ptOnLine,Adesk::kTrue); m_vtDir = ptOnLine - m_ptTurn; m_dLineBaseLen = m_vtDir.length()/GetPScale(); m_vtDir.normalize(); } } int iCount = indices.length(); if (indices.length() == 2) { if (nCount == indices[0]) { m_ptTurn += offset; m_vtDir.normalize(); AcGePoint3d ptE = m_ptTurn + m_dLineBaseLen*GetPScale() * m_vtDir; AcDbLine line(m_ptTurn,ptE); AcGePoint3d ptOnLine; ptE += offset; line.getClosestPointTo(ptE,ptOnLine,Adesk::kTrue); m_vtDir = ptOnLine - m_ptTurn; m_dLineBaseLen = m_vtDir.length()/GetPScale(); m_vtDir.normalize(); } else if (nCount > indices[0]) { for (int i = 0; i < m_arPtS.length(); ++i) { m_arPtS[i] += offset; } if (nCount == indices[1]) { m_ptTurn += offset; } if (nCount+1 == indices[1]) { m_vtDir.normalize(); AcGePoint3d ptE = m_ptTurn + m_dLineBaseLen*GetPScale() * m_vtDir; AcDbLine line(m_ptTurn,ptE); AcGePoint3d ptOnLine; ptE += offset; line.getClosestPointTo(ptE,ptOnLine,Adesk::kTrue); m_vtDir = ptOnLine - m_ptTurn; m_dLineBaseLen = m_vtDir.length()/GetPScale(); m_vtDir.normalize(); } } } if (indices.length() == 3) { for (int i = 0; i < m_arPtS.length(); ++i) { m_arPtS[i] += offset; } m_ptTurn += offset; } return Acad::eOk; } Acad::ErrorStatus TDbWireDimNew::subMoveStretchPointsAt(const AcDbIntArray& indices,const AcGeVector3d& offset) { return subMoveGripPointsAt(indices,offset); } //镜像会使用到 Acad::ErrorStatus TDbWireDimNew::subTransformBy(const AcGeMatrix3d& xform) { assertWriteEnabled(); TDbEntity::subTransformBy(xform); for (int i = 0; i < m_arPtS.length(); ++i) m_arPtS[i].transformBy(xform); m_ptTurn.transformBy(xform); // modify by sps 2013.6.3 取消文字方向转换 //m_vtDir.transformBy(xform); //bsl 2012.1.10 引脚线支持sc缩放 for (i = 0;i < m_vecBottomVt.size();++i) { m_vecBottomVt[i].transformBy(xform); } m_vtDir.transformBy(xform); return Acad::eOk; } void TDbWireDimNew::DrawSimpleDimWire(XExplodeDraw &dc) const { BOOL bShowOL = GetShowObliqueLine(); if (!bShowOL) { double dLeadLineLen = GetLeadLineLen(); if (m_arPtS.length() > 0 && (int)m_vecText.size() == m_arPtS.length()) { AcGePoint3d ptLineS; ptLineS = m_arPtS[0]; AcGeVector3d vtDir = m_ptTurn - m_arPtS[0]; vtDir.normalize(); vtDir *= dLeadLineLen/2*GetPScale(); ptLineS -= vtDir; AcDbPolyline pline; pline.addVertexAt(0, ptLineS.convert2d(AcGePlane::kXYPlane)); pline.addVertexAt(1, m_arPtS[0].convert2d(AcGePlane::kXYPlane)); pline.addVertexAt(2, m_ptTurn.convert2d(AcGePlane::kXYPlane)); pline.setColorIndex(colorIndex()); pline.setLayer(layerId()); dc.DrawEntity(pline); } } } Acad::ErrorStatus TDbWireDimNew::ExplodeOrDraw2d(XExplodeDraw &dc) const { // cet 2016.10.17 add 图层关闭时,实体不显示,不进行绘制(打印时,也不会绘制) AcDbLayerTableRecordPointer player(this->layerId(), AcDb::kForRead); if (player.openStatus() == Acad::eOk && player->isOff()) { return Acad::eOk; } //绘制标注线 if (m_bShowLine) ExplodeOrDraw2dLine(dc); //绘制标注文字 ExplodeOrDraw2dText(dc); return Acad::eOk; } //绘制标注线 Acad::ErrorStatus TDbWireDimNew::ExplodeOrDraw2dLine(XExplodeDraw &dc) const { //axc add 2014-07-02 T20回路编号新增简谱标注样式和是否固定转角角度 //是否简谱样式回路编号 BOOL bShowOL = GetShowObliqueLine(); if (!bShowOL) { DrawSimpleDimWire(dc); return Acad::eOk; } //绘制起点连线 AcDbPolyline pline; for (int i = 0; i < m_arPtS.length(); ++i) { pline.addVertexAt(i,m_arPtS[i].convert2d(AcGePlane::kXYPlane)); } // 2012/5/16 add by wzh 修正 导线与标注连接线 位置错误问题 // 1. 导线连线 2012/5/16 int nVertLen = m_arPtS.length(); pline.setColorIndex(colorIndex()); pline.setLayer(layerId()); if(nVertLen > 1)//sr add 2012-7-27 dc.DrawEntity(pline); // 2. 延伸线(导线末点-拐点) AcDbPolyline pline3; if (nVertLen >= 1) { pline3.addVertexAt(0, m_arPtS[0].convert2d(AcGePlane::kXYPlane)); pline3.addVertexAt(1, m_ptTurn.convert2d(AcGePlane::kXYPlane)); pline3.setColorIndex(colorIndex()); pline3.setLayer(layerId()); dc.DrawEntity(pline3); } // 2012/5/16 comment by wzh // pline.addVertexAt(pline.numVerts(),m_ptTurn.convert2d(AcGePlane::kXYPlane)); // pline.setColorIndex(colorIndex()); // pline.setLayer(layerId()); // dc.DrawEntity(pline); AcGeVector3d vtTemp = TSysCoordinateTool::GetCurrentViewWCSKXAxis(); if (m_vtDir.angleTo(vtTemp) > PI/2) { vtTemp *= -1; } //绘制拐点处线 AcDbPolyline pline2; //AcGePoint3d ptET = m_ptTurn + m_vtDir * m_dLineBaseLen*GetPScale(); vtTemp.rotateBy(m_nLayoutRotation, AcGeVector3d::kZAxis);//add by wx 2015-1-15 AcGePoint3d ptET = m_ptTurn + vtTemp * m_dLineBaseLen*GetPScale(); pline2.addVertexAt(0, m_ptTurn.convert2d(AcGePlane::kXYPlane)); pline2.addVertexAt(1, ptET.convert2d(AcGePlane::kXYPlane)); pline2.setColorIndex(colorIndex()); pline2.setLayer(layerId()); dc.DrawEntity(pline2); //绘制多个文字时的线 int nTextNum = GetTextCount(); if (nTextNum > 1) { AcGeVector3d vtVer = m_vtDir; if (m_vtDir.angleTo(AcGeVector3d::kXAxis) < PI/2) { vtVer.rotateBy(PI/2,AcGeVector3d::kZAxis); } else { vtVer.rotateBy(-PI/2,AcGeVector3d::kZAxis); } vtVer.normalize(); AcGePoint3d ptS = m_ptTurn; double dTVerLineHeight = 0.0; double dHeight = GetDimTextHeght(); for (int j = 0;j < nTextNum-1;++j) { AcDbPolyline pline3; dTVerLineHeight += dHeight; ptS += vtVer * dHeight; ptET += vtVer * dHeight; pline3.addVertexAt(0, ptS.convert2d(AcGePlane::kXYPlane)); pline3.addVertexAt(1, ptET.convert2d(AcGePlane::kXYPlane)); pline3.setColorIndex(colorIndex()); pline3.setLayer(layerId()); dc.DrawEntity(pline3); } ptET = m_ptTurn + vtVer * (dTVerLineHeight+dHeight); AcDbPolyline pline4; pline4.addVertexAt(0, m_ptTurn.convert2d(AcGePlane::kXYPlane)); pline4.addVertexAt(1, ptET.convert2d(AcGePlane::kXYPlane)); pline4.setColorIndex(colorIndex()); pline4.setLayer(layerId()); dc.DrawEntity(pline4); } // 2012/5/16 add by wzh 正交 //struct resbuf os; // acedGetVar(_T("orthomode"), &os); //底部斜线 AcGeVector3d vtBottom = AcGeVector3d::kYAxis; double dLeadLineLen = GetLeadLineLen(); if (dLeadLineLen == 0) dLeadLineLen = 1.75 * 2; if (m_arPtS.length() > 0 && (int)m_vecText.size() == m_arPtS.length()) { int nIndex = m_arPtS.length()-1; AcGeVector3d vtLine = m_arPtS[m_arPtS.length() - 1] - m_arPtS[0]; AcGeVector3d vtVer = TSysCoordinateTool::GetCurrentViewWCSKYAxis(); if (vtLine.angleTo(vtVer) > PI/2) nIndex = 0; AcGeVector3d vtT = m_ptTurn - m_arPtS[nIndex]; AcGePoint3d ptLineS,ptLineE; for (int l = 0; l < m_vecBottomVt.size(); ++l) { //通过实体得到向量 vtBottom = m_vecBottomVt[l]; // 2012/5/16 add by wzh 支持正交 // if ( vtT.angleTo(vtBottom) < PI/4 || vtT.angleTo(vtBottom) > PI*3/4 || os.resval.rint) // 2012/5/16 comment by wzh if ( vtT.angleTo(vtBottom) < PI/4 || vtT.angleTo(vtBottom) > PI*3/4) vtBottom.rotateBy(PI/2,TSysCoordinateTool::GetCurrentViewWCSKZAxis()); //vtBottom *= 1.75*GetPScale(); //SR 2010-3-9 修改 vtBottom *= dLeadLineLen/2*GetPScale(); //axc alter T20回路编号可以修改底部斜线的长度 ptLineS = m_arPtS[l]; ptLineE = m_arPtS[l]; ptLineS -= vtBottom; ptLineE += vtBottom; AcDbLine line(ptLineS,ptLineE); line.setColorIndex(colorIndex()); line.setLayer(layerId()); dc.DrawEntity(line); } } return Acad::eOk; } //绘制标注文字 Acad::ErrorStatus TDbWireDimNew::ExplodeOrDraw2dText(XExplodeDraw &dc) const { CString sText; AcGePoint3d ptT = m_ptTurn; AcGeVector3d vtVer = m_vtDir; BOOL bType = FALSE;//FALSE左下角,TRUE右下角 AcGeVector3d vtHor = TSysCoordinateTool::GetCurrentViewWCSKXAxis(); AcGeVector3d vtZ = TSysCoordinateTool::GetCurrentViewWCSKZAxis(); //modify by sps 布局下获取文字旋转角度(即ucs相对wcs旋转角度)错误 //double dRotate = Ucs2Wcs(0.0); double dRotate = AcGeVector3d::kXAxis.angleTo(TSysCoordinateTool::GetCurrentViewWCSKXAxis(), AcGeVector3d::kZAxis); if (m_bShowLine) { if (m_vtDir.angleTo(vtHor) < PI / 2) { bType = TRUE; vtVer.rotateBy(PI/2, vtZ); } else { vtVer.rotateBy(-PI/2, vtZ); vtHor *= -1; } vtHor.rotateBy(m_nLayoutRotation, AcGeVector3d::kZAxis);//add by wx ptT += vtHor * m_dLineBaseLen*GetPScale(); ptT -= vtHor * GetTextHeight()*GetPScale()/4; //add bsl 2011.6.27 //axc add 2014-07-01 电气T20调整文字插入位置 BOOL bOblique = GetShowObliqueLine(); if (!bOblique) { AcGeVector3d vtY = AcGeVector3d::kYAxis; ptT = m_ptTurn; ptT += vtHor *GetTextLen()*GetPScale()/2; ptT -= vtHor * GetTextHeight()*GetPScale()/2; double dPurnY = m_ptTurn.y; if (m_ptTurn.y < m_arPtS[0].y) { ptT -= vtY * GetTextHeight()*GetPScale(); } } //end } else { dRotate = m_vtDir.angleTo(vtHor, vtZ); dRotate = 2*PI - dRotate; if (dRotate >= 0 && dRotate <= PI/2) { vtVer.rotateBy(PI/2, vtZ); } else if (dRotate > PI/2 && dRotate <= 3*PI/2) { dRotate -= PI; vtVer.rotateBy(-PI/2, vtZ); } else //drote > 3*pi/2 && drote <= 2*pi { dRotate -= 2 * PI; vtVer.rotateBy(PI/2, vtZ); } } ptT += vtVer*GetPScale() / 2.0; for (UINT i = 0; i < m_vecText.size(); ++i) { sText = m_vecText[i]; CString sDimText = _T(""); DeCryptText(sText,sDimText); TDbText text; text.setPropertiesFrom(this); if (m_bShowLine) { if (bType) { text.SetAlignment(XExplodeDraw::kBottomRight); } else { text.SetAlignment(XExplodeDraw::kBottomLeft); } } else { text.SetAlignment(XExplodeDraw::kBottomCenter); } text.SetText((const TCHAR*)sDimText); AcDbObjectId id = this->GetTextStyleId(); text.SetStyleId(id); text.SetHeight(this->GetTextHeight()); text.SetRotation(dRotate); text.setColorIndex(GetTextColor()); text.SetLocation(XPoint(ptT)); ptT += vtVer*GetDimTextHeght(); TPushProperty vProp(&text, dc); if(dc.IsFullExplode()) text.ExplodeOrDraw2d(dc); else dc.DrawEntity(text); } return Acad::eOk; } //axc add 2015-05-13 支持导线标注实体 查找替换命令 // 返回发现的位置,同时posStart往前移动(以便继续找下一个使用), TextFindInfo g_TextFindInfo;//保存形如BV@15@SC@FC@2x2.5@0@WL1@信息 也就是未解密时的文字信息 TTextPosition TDbWireDimNew::FindSubText(const TCHAR *sSubText, TTextPosition &posStart, TTextRange *pRange) const { TTextPosition pos; if (!sSubText || !sSubText[0]) return pos; TTextPosition posNext = posStart; while (1) { TTextPosition posFind; //查找解密后文字的文字位置 TTextPosition posFind2,posNext2; //查找未解密文字时的文字位置 TTextRange Range2; //未加密时查找文字的外围框 int nCookies = posNext.m_nCookies; TDbText text; //解密后的标注文字 TDbText text2; //未解密时的标注文字 if (!GetText(nCookies, text,text2)) break; posFind = text.FindSubText(sSubText, posNext, pRange); if (!posFind) { posNext.m_nCookies++; posNext.m_nTextPos = 0; } else { posStart = posNext; if (!posStart) { posStart.m_nCookies++; posStart.m_nTextPos = 0; } posFind.m_nCookies = posNext.m_nCookies; pos = posFind; posFind2 = text2.FindSubText(sSubText, posNext2, &Range2); //保存未解密时找到的文字信息 g_TextFindInfo.sSubText = sSubText; //待查找的文字内容 g_TextFindInfo.nTextPos = posFind2.m_nTextPos; //待查找文字在未解密时文字的位置 break; } } return pos; } BOOL TDbWireDimNew::GetText(Adesk::UInt32 cookies, TDbText &text, TDbText &text2) const { if ((UINT)cookies >= m_vecText.size()) return FALSE; text.setPropertiesFrom(this); text.SetRotation(0); text.SetHeight(m_nTextHeight); text.SetStyleId(m_idTextStyle); BOOL bType = FALSE;//FALSE左下角,TRUE右下角 AcGeVector3d vtHor = TSysCoordinateTool::GetCurrentViewWCSKXAxis(); if (m_vtDir.angleTo(vtHor) < PI / 2) { bType = TRUE; } XPoint ptLoc; CString sText = m_vecText[cookies]; DeCryptText(sText,sText); ptLoc = GetTextPt(cookies); text.SetText(sText); XExplodeDraw::TextAlignment nAlign = XExplodeDraw::kBottomLeft; if (m_bShowLine) { if (bType) text.SetAlignment(XExplodeDraw::kBottomRight); else text.SetAlignment(XExplodeDraw::kBottomLeft); } else text.SetAlignment(XExplodeDraw::kBottomCenter); text.SetLocation(ptLoc); text2.copyFrom((TDbText*)& text); text2.SetText(m_vecText[cookies]); return TRUE; } XPoint TDbWireDimNew::GetTextPt(Adesk::UInt32 cookies,BOOL bUseLayout) const { AcGePoint3d ptT = m_ptTurn; AcGeVector3d vtVer = m_vtDir; AcGeVector3d vtHor = TSysCoordinateTool::GetCurrentViewWCSKXAxis(); AcGeVector3d vtZ = TSysCoordinateTool::GetCurrentViewWCSKZAxis(); double dRotate = AcGeVector3d::kXAxis.angleTo(TSysCoordinateTool::GetCurrentViewWCSKXAxis(), AcGeVector3d::kZAxis); if (m_bShowLine) { if (m_vtDir.angleTo(vtHor) < PI / 2) { vtVer.rotateBy(PI/2, vtZ); } else { vtVer.rotateBy(-PI/2, vtZ); vtHor *= -1; } vtHor.rotateBy(m_nLayoutRotation, AcGeVector3d::kZAxis); ptT += vtHor * m_dLineBaseLen*GetPScale(); ptT -= vtHor * GetTextHeight()*GetPScale()/4; BOOL bOblique = GetShowObliqueLine(); if (!bOblique) { AcGeVector3d vtY = AcGeVector3d::kYAxis; ptT = m_ptTurn; ptT += vtHor *GetTextLen()*GetPScale()/2; ptT -= vtHor * GetTextHeight()*GetPScale()/2; double dPurnY = m_ptTurn.y; if (m_ptTurn.y < m_arPtS[0].y) { ptT -= vtY * GetTextHeight()*GetPScale(); } } } else { dRotate = m_vtDir.angleTo(vtHor, vtZ); dRotate = 2*PI - dRotate; if (dRotate >= 0 && dRotate <= PI/2) { vtVer.rotateBy(PI/2, vtZ); } else if (dRotate > PI/2 && dRotate <= 3*PI/2) { dRotate -= PI; vtVer.rotateBy(-PI/2, vtZ); } else { dRotate -= 2 * PI; vtVer.rotateBy(PI/2, vtZ); } } ptT += vtVer*GetPScale() / 2.0; for (UINT i = 0; i < m_vecText.size(); ++i) { if ((UINT)cookies == i) break; ptT += vtVer*GetDimTextHeght(); } XPoint ptRet(ptT); return ptRet; } //设置文本内容时应该设置成未解密的形式 这样在文字显示 双击实体时显示的信息才是正确的 //未解密的形式应是BV@.....形式 void TDbWireDimNew::SetSubText(long i,CString sText) { m_vecText[i] = sText; } TTextPosition TDbWireDimNew::ReplaceSubText(const TTextPosition &posRep, const TCHAR *sRepText, TTextRange *pRange) { assertWriteEnabled(); TTextPosition posNext; TTextPosition posNext2,posRep2; //未解密时要被替换的文字内容 TTextRange Range2; //未解密时被替换的文字内容的外轮廓 int cookies = posRep.m_nCookies; if (cookies >= m_vecText.size()) { posNext.m_nCookies = posRep.m_nCookies + 1; posNext.m_nTextPos = 0; return posNext; } TDbText text; //解密后文字内容 TDbText text2; //未解密的文字内容 if (!sRepText || !GetText(cookies, text,text2)) return posNext; posRep2.m_nCookies = cookies; posRep2.m_nTextPos = g_TextFindInfo.nTextPos; posRep2.m_nBufLen = g_TextFindInfo.sSubText.GetLength(); posNext = text.ReplaceSubText(posRep, sRepText, pRange); posNext2 = text2.ReplaceSubText(posRep2,sRepText,&Range2); m_vecText[cookies] = text2.GetText(); if (!posNext) { posNext.m_nCookies = posRep.m_nCookies+1; posNext.m_nTextPos = 0; } return posNext; } //end //初始化起点和转折点 void TDbWireDimNew::SetInitDims(const AcGePoint3d &ptS,const AcGePoint3d &ptTurn,const AcGeVector3d &vtDir,BOOL bSample) { assertWriteEnabled(); m_ptS = ptS; m_ptTurn = ptTurn; m_vtDir = vtDir; m_vtDir = m_vtDir.orthoProject(AcGeVector3d::kYAxis); m_bSample = bSample; m_vtDir.normalize(); } //得到文字长度 double TDbWireDimNew::GetLineLen() const { return m_dLineBaseLen; } //得到文字高度 double TDbWireDimNew::GetDimTextHeght() const { double dHeight = this->GetTextHeight()*GetPScale(); dHeight = dHeight*(DocGetText2Base()+0.8); return dHeight; } //得到文字个数 int TDbWireDimNew::GetTextCount() const { int nCount = 3; nCount = (int)m_vecText.size(); return nCount; } void InitDbWireDimNew(BOOL bTrue) { if (bTrue) { TDbWireDimNew::rxInit(); TDbWireDimNew::InitMatchProtocol(TRUE); } else { TDbWireDimNew::InitMatchProtocol(FALSE); deleteAcRxClass(TDbWireDimNew::desc()); } } //添加需要标注的实体 void TDbWireDimNew::AddEnts(const AcDbSoftPointerId &id) { m_vecIds.push_back(id); //得到交点 GetInterPoints(id); //版本2改为存字符串 CString sDimText; //GetNeedDimStr(id,sDimText); modify by wx GetNeedShowDimStr(id,sDimText, m_csWeakWireNum);//2015-1-14 m_vecText.push_back(sDimText); AcGeVector3d vtBottom; GetEntVector(id,vtBottom); m_vecBottomVt.push_back(vtBottom); m_dLineBaseLen = this->GetTextLen(); } //更新导线文字 void TDbWireDimNew::RenewWireDimText(const std::vector &vecIds) { m_vecIds.clear(); m_vecText.clear(); for (UINT i = 0; i < vecIds.size(); ++i) { m_vecIds.push_back(vecIds[i]); CString sDimText; //GetNeedDimStr(vecIds[i],sDimText); modify by wx GetNeedShowDimStr(vecIds[i],sDimText, m_csWeakWireNum);//2015-1-14 m_vecText.push_back(sDimText); } } static CString GetXDataByName(const AcDbObjectId &id,const TCHAR*szName) { CString sXData; AcDbEntity *pEnt = NULL; if (acdbOpenAcDbEntity(pEnt,id,AcDb::kForRead) == Acad::eOk) { resbuf *pRb = pEnt->xData(szName); if (pRb != NULL) { CString csRet; if (pRb != NULL) { resbuf *pTemp = pRb; if (pTemp->rbnext != NULL) { pTemp = pTemp->rbnext; if (pTemp->restype == 1000) csRet = pTemp->resval.rstring; } } ads_relrb(pRb); sXData = csRet; } pEnt->close(); } return sXData; } static void SetXData(const AcDbObjectId &id,const TCHAR*szName,const TCHAR *szData,int nLength) { AcDbEntity *pEnt = NULL; CString sData = szData; if (acdbOpenAcDbEntity(pEnt,id,AcDb::kForWrite) == Acad::eOk) { resbuf *pRb = pEnt->xData(szName); if (pRb != NULL) { CString csRet; if (pRb != NULL) { resbuf *pTemp = pRb; if (pTemp->rbnext != NULL) { pTemp = pTemp->rbnext; if (pTemp->restype == 1000) { delete pTemp->resval.rstring; pTemp->resval.rstring = new TCHAR[nLength+1]; memset(pTemp->resval.rstring,0,nLength+1); _tcscpy(pTemp->resval.rstring,szData); } } } pEnt->setXData(pRb); ads_relrb(pRb); } pEnt->close(); } } //得到需要标注的文字 void TDbWireDimNew::GetNeedDimStr(const AcDbObjectId &id,CString &sDimText, CString &csWeakWireNum) const { CString csType = GetXDataByName(id, _T("ltype")); //导线型号 CString csRadius = GetXDataByName(id, _T("ldm")); //穿管直径 CString csMode = GetXDataByName(id, _T("lmeth")); //配线方式 CString csPlace = GetXDataByName(id, _T("linst")); //敷设部位 CString csArea = GetXDataByName(id, _T("lnoar")); //导线规格 CString csNorm = GetXDataByName(id, _T("lnorm")); CString csName = GetXDataByName(id, _T("linenum")); //回路编号 csWeakWireNum = GetXDataByName(id, _T("weakwirenum")); //add by wx 2015-1-14 弱电缆数 if(csName == _T("") && csType == _T("") && csArea == _T("") && csMode == _T("") && csPlace == _T("")){ return; } sDimText.Format(_T("%s@%s@%s@%s@%s@%s@%s@"),csType,csRadius,csMode,csPlace,csArea,csNorm,csName); } void TDbWireDimNew::GetNeedShowDimStr(const AcDbObjectId &id, CString &sDimShowText, CString &csWeakWireNum) const { CString csType = GetXDataByName(id, _T("ltype")); //导线型号 CString csRadius = GetXDataByName(id, _T("ldm")); //穿管直径 CString csMode = GetXDataByName(id, _T("lmeth")); //配线方式 CString csPlace = GetXDataByName(id, _T("linst")); //敷设部位 CString csArea = GetXDataByName(id, _T("lnoar")); //导线规格 CString csNorm = GetXDataByName(id, _T("lnorm")); CString csName = GetXDataByName(id, _T("linenum")); //回路编号 //add by wx 2015-1-14 弱电缆数 csWeakWireNum = GetXDataByName(id, _T("weakwirenum")); csType = csWeakWireNum + csType; //add end if(csName == _T("") && csType == _T("") && csArea == _T("") && csMode == _T("") && csPlace == _T("")){ return; } CRegProperty regProp(GetRegLocation(), _T("TElecConfig")); regProp.SetTopRootKey(HKEY_CURRENT_USER); int nSimple; regProp.GetValue(_T("DimWireSimple"), nSimple); if(nSimple) { csRadius = csMode = csPlace = csName = _T(""); csNorm = _T("0"); sDimShowText.Format(_T("%s@%s@%s@%s@%s@%s@%s@"),csType,csRadius,csMode,csPlace,csArea,csNorm,csName); } else sDimShowText.Format(_T("%s@%s@%s@%s@%s@%s@%s@"),csType,csRadius,csMode,csPlace,csArea,csNorm,csName); } //得到交点 void TDbWireDimNew::GetInterPoints(const AcDbObjectId &id) { AcGePoint3d ptS = m_ptS; if (m_ptS.isEqualTo(AcGePoint3d::kOrigin) == true) ptS = m_arPtS[0]; AcDbLine line(ptS,m_ptTurn); //AcDbLine line(m_arPtS[0],m_ptTurn);//版本2起点存在m_arPts AcDbEntity *pEnt = NULL; if (acdbOpenAcDbEntity(pEnt,id,AcDb::kForRead) == Acad::eOk) { line.intersectWith(pEnt,AcDb::kOnBothOperands,m_arPtS); pEnt->close(); } } //得到文字长度 double TDbWireDimNew::GetTextLen() const { double dLen = 0.0; double dLenTemp; CString sText; for (UINT i = 0;i < m_vecText.size();++i) { sText = m_vecText[i]; DeCryptText(sText,sText); TDbText text; text.setPropertiesFrom(this); text.SetText((const TCHAR*)sText); AcDbObjectId id = this->GetTextStyleId(); text.SetStyleId(id); text.SetLocation(m_ptTurn); text.SetHeight(this->GetTextHeight()); text.SetAlignment(XExplodeDraw::kMiddleCenter); AcDbExtents ext; text.getGeomExtents(ext); dLenTemp = fabs(ext.maxPoint().x - ext.minPoint().x)/GetPScale(); dLenTemp += GetTextHeight()/2; //add bsl 2011.6.27 CString sStyleName = GetSymbolName(id).cs(); struct resbuf* pRb = acutBuildList(RTDXF0, _T("TEXT"), 1, sText, 7, sStyleName, 40, GetTextHeight(), 41, GetPScale(), 0); ads_point adsPt1, adsPt2; int iRet = acedTextBox(pRb, adsPt1, adsPt2); acutRelRb(pRb); // 2012/7/13 comment by wzh 标注引线改短 //dLenTemp = fabs(adsPt2[X] - adsPt1[X])/GetPScale(); //dLenTemp += GetTextHeight()/2; if (dLenTemp > dLen) { dLen = dLenTemp; } } return dLen; } //标注的方向 void TDbWireDimNew::SetDirVec(const AcGeVector3d &vt) { assertWriteEnabled(); m_vtDir = vt; } //设置文字起点 void TDbWireDimNew::SetStartPt(const AcGePoint3d &ptS) { assertWriteEnabled(); if (m_arPtS.length() == 1) { m_arPtS[0] = ptS; }//BSL 2011-6-23 增加以上几行 m_ptS没有存储在图中 m_ptS = ptS; } //设置拐点 void TDbWireDimNew::SetTurnPt(const AcGePoint3d &ptTurn) { assertWriteEnabled(); m_ptTurn = ptTurn; } //得到标注的实体ID void TDbWireDimNew::GetDimEnts(std::vector &vecIds) { vecIds.erase(vecIds.begin(),vecIds.end()); //m_vecIds没有保存到图纸中去 当重新打开图纸时m_vecIds为0,应重新得到导线id if (m_vecIds.size() == 0) { AcGePoint3dArray arPts; GetStartPt(arPts); RBList rbMask = ads_buildlist(RTDXF0, _T("LWPOLYLINE,LINE,ARC"), 8, GetLayerNames(_T("导线")), NULL); XPoint ptSel1,ptSel2; AcGeVector3d vtDir = AcGeVector3d::kXAxis; vtDir.rotateBy(PI/4,AcGeVector3d::kZAxis); AcDbObjectId id; for (int i = 0; i < arPts.length(); ++i) { PickSet ssSel(SS_FREE); ptSel1 = arPts[i] + vtDir*1.5*DocGetPScale(); ptSel2 = arPts[i] - vtDir*1.5*DocGetPScale(); ssSel.Get(_T("C"),Wcs2Ucs(ptSel1), Wcs2Ucs(ptSel2),rbMask); if (ssSel.Length() > long(0)) { if (acdbGetObjectId(id,ssSel[long(0)]) == Acad::eOk) { vecIds.push_back(id); m_vecIds.push_back(id); } } } } else { for (UINT i = 0; i < m_vecIds.size(); ++i) vecIds.push_back(m_vecIds[i]); } } //得到实体方向向量 void TDbWireDimNew::GetEntVector(const AcDbObjectId &id,AcGeVector3d &vtDir) const { if (!id.isValid()) return; // 2012/5/7 add by wzh AcGeVector3d vtKYAxis = AcGeVector3d::kYAxis; vtDir = AcGeVector3d::kYAxis; vtDir.rotateBy(PI/4,AcGeVector3d::kZAxis); AcDbEntity *pEnt = NULL; AcGePoint3d ptS,ptE; if (acdbOpenAcDbEntity(pEnt,id,AcDb::kForRead) == Acad::eOk) { AcDbCurve *pCurve = AcDbCurve::cast(pEnt); pCurve->getStartPoint(ptS); pCurve->getEndPoint(ptE); vtDir = ptE - ptS; vtDir.normalize(); // 2012/5/7 add by wzh 支持平行导线中不同方向情况 if (vtKYAxis.isCodirectionalTo(vtDir) != Adesk::kTrue) { // 即 -Y轴 情况 vtDir *= -1; } // 2012/5/7 comment // if ((ptS.x - ptE.x)*(ptS.y - ptE.y) < 0) // vtDir.rotateBy(PI/2,AcGeVector3d::kZAxis); vtDir.rotateBy(PI/4,AcGeVector3d::kZAxis); pEnt->close(); } } //设置是否简标 void TDbWireDimNew::SetDimSample(BOOL bSample) { assertWriteEnabled(); m_bSample = bSample; } //判断是否简标 BOOL TDbWireDimNew::IsDimSample() { return m_bSample; } //更新线长 void TDbWireDimNew::RenewLinLen() { double dLen = GetTextLen(); /*if (m_dLineBaseLen < dLen || m_bSample) m_dLineBaseLen = dLen;*/ m_dLineBaseLen = dLen; } //将实体的顺序颠倒 void TDbWireDimNew::ReverseEntitys() { std::vector vecT(m_vecIds); m_vecIds.clear(); int nLen = (int)vecT.size(); for (int i = 0 ; i < nLen; ++i) { m_vecIds.push_back(vecT[nLen - i -1]); } std::vector vecT2(m_vecText); m_vecText.clear(); nLen = (int)vecT2.size(); for (int j = 0 ; j < nLen; ++j) { m_vecText.push_back(vecT2[nLen - j -1]); } } AcGePoint3d TDbWireDimNew::GetStartPt() { if (m_arPtS.length() == 1) { return m_arPtS[0]; }//BSL 2011-6-23 增加以上几行 m_ptS没有存储在图中 return m_ptS; } AcGePoint3d TDbWireDimNew::GetTurnPt() { return m_ptTurn; } void TDbWireDimNew::CopyPropertiesFrom(AcDbEntity *pSrcEntity, unsigned gMatchFlag) { assertWriteEnabled(); TDbSymbWithText::CopyPropertiesFrom(pSrcEntity, gMatchFlag); TDbWireDimNew *pDim = TDbWireDimNew::cast(pSrcEntity); if (pDim != NULL) { m_dLineBaseLen = pDim->GetLineLen(); } } AcGeVector3d TDbWireDimNew::GetDirVector() { return m_vtDir; } //设置是否显示线 void TDbWireDimNew::SetShowLine(BOOL bShow) { assertWriteEnabled(); m_bShowLine = bShow; } //设置是否显示底部斜线 void TDbWireDimNew::SetShowObliqueLine(BOOL bShow) { assertWriteEnabled(); TEntityFields& fields = Fields(); fields.SFD(_T("SHOWOBLIQUELINE"), bShow); } BOOL TDbWireDimNew::GetShowObliqueLine() const { assertReadEnabled(); BOOL bShow = TRUE; const TEntityFields& fields = GetFields(); fields.GFD(_T("SHOWOBLIQUELINE"), bShow); return bShow; } void TDbWireDimNew::SetLeadLineLen(double dLen) { assertWriteEnabled(); TEntityFields& fields = Fields(); fields.SFD(_T("LEADLINELEN"), dLen); } double TDbWireDimNew::GetLeadLineLen() const { assertReadEnabled(); double dLen = 0.0; const TEntityFields& fields = GetFields(); fields.GFD(_T("LEADLINELEN"), dLen); return dLen; } void TDbWireDimNew::GetStartPt(AcGePoint3dArray &arPts) { arPts = m_arPtS; } void TDbWireDimNew::SetStartPt(const AcGePoint3dArray& arPts) { //修改标注起始点 bsl 2011.6.27(支持多线标注房间复制) m_arPtS.setLogicalLength(0); m_arPtS = arPts; } //对文字加密 void TDbWireDimNew::EnCryptText(LPCTSTR lpSource,CString &sDestination) { ASSERT(lpSource); } //对文字解密 void TDbWireDimNew::DeCryptText(LPCTSTR lpSource,CString &sDestination) const { ASSERT(lpSource); CString csType; //导线型号 CString csRadius; //穿管直径 CString csMode; //配线方式 CString csPlace; //敷设部位 CString csArea; //导线规格 CString csNorm; CString csName; //回路编号 //解析得到想要的 ParseText(lpSource,csType,csRadius,csMode,csPlace,csArea,csNorm,csName); //if(csNorm == _T("0") && csType !=_T("")) if(csNorm == _T("0")) sDestination = csType; else if(csNorm == _T("1") && csType !=_T("")) sDestination = _T("ZR-") + csType; else if(csNorm == _T("2") && csType !=_T("")) sDestination = _T("NH-") + csType; if(sDestination != _T("")) sDestination += _T("-"); if (!m_bSample) { //mod liaoy 170725 统一方法 MergeText(sDestination,csArea,csMode,csRadius,csPlace); /* if(csArea!=_T("") && csMode !=_T("") && csRadius != _T("") && csPlace != _T("")) sDestination = sDestination + csArea + _T("-") + csMode + csRadius + _T("-") + csPlace; else if(csArea!=_T("") && csMode !=_T("") && csRadius != _T("") && csPlace == _T("")) sDestination = sDestination + csArea + _T("-") + csMode + csRadius; else if(csArea==_T("") && csMode !=_T("") && csRadius != _T("") && csPlace != _T("")) sDestination = sDestination + csMode + csRadius + _T("-") + csPlace; else if(csArea!=_T("") && csMode ==_T("") && csRadius == _T("") && csPlace == _T("")) sDestination = sDestination + csArea; else if(csArea!=_T("") && csMode ==_T("") && csRadius == _T("") && csPlace != _T("")) sDestination = sDestination + csArea + _T("-") + csPlace; else if(csArea!=_T("") && csMode !=_T("") && csRadius == _T("") && csPlace != _T("")) sDestination = sDestination + csArea + _T("-") + csMode + _T("-") + csPlace; else if(csArea ==_T("") && csMode !=_T("") && csRadius == _T("") && csPlace != _T("")) sDestination = sDestination + csMode + _T("-") + csPlace; else if(csArea ==_T("") && csMode !=_T("") && csRadius != _T("") && csPlace == _T("")) sDestination = sDestination + csMode + csRadius; //axc add 2014-09-05 解决当配线方式为空时,敷设部位和穿管直径不显示问题 else if (csArea!=_T("") && csMode ==_T("") && csPlace != _T("")) sDestination = sDestination + csArea + _T("-") + csPlace; */ //mod end if(csName != _T("")) sDestination = csName + _T("-") + sDestination; } else { sDestination = csName; } if (sDestination.IsEmpty() && !csName.IsEmpty()) sDestination = lpSource; } //拆分文字 void TDbWireDimNew::ParseText(LPCTSTR lpSource,CString &csType,CString &csRadius,CString &csMode, CString &csPlace,CString &csArea,CString &csNorm,CString &csName) const { CString sSource = lpSource; if (sSource.IsEmpty()) return; //解析字符串 int nFind = -1; nFind = sSource.Find(SPEC_CHAR); if (nFind != -1) { csType = sSource.Left(nFind); sSource = sSource.Mid(nFind + 1); } nFind = sSource.Find(SPEC_CHAR); if (nFind != -1) { csRadius = sSource.Left(nFind); sSource = sSource.Mid(nFind + 1); } nFind = sSource.Find(SPEC_CHAR); if (nFind != -1) { csMode = sSource.Left(nFind); sSource = sSource.Mid(nFind + 1); } nFind = sSource.Find(SPEC_CHAR); if (nFind != -1) { csPlace = sSource.Left(nFind); sSource = sSource.Mid(nFind + 1); } nFind = sSource.Find(SPEC_CHAR); if (nFind != -1) { csArea = sSource.Left(nFind); sSource = sSource.Mid(nFind + 1); } nFind = sSource.Find(SPEC_CHAR); if (nFind != -1) { csNorm = sSource.Left(nFind); sSource = sSource.Mid(nFind + 1); } nFind = sSource.Find(SPEC_CHAR); if (nFind != -1) { csName = sSource.Left(nFind); sSource = sSource.Mid(nFind + 1); } } //通过文字更新导线实体 void TDbWireDimNew::RenewWireByText(const std::vector &vecIds) { assertWriteEnabled(); if (vecIds.size() != m_vecText.size()) return; CString csType; //导线型号 CString csRadius; //穿管直径 CString csMode; //配线方式 CString csPlace; //敷设部位 CString csArea; //导线规格 CString csNorm; CString csName; //回路编号 for (UINT i = 0; i < m_vecText.size(); ++i) { ParseText(m_vecText[i],csType,csRadius,csMode,csPlace,csArea,csNorm,csName); //导线型号 //穿管直径 //配线方式 //敷设部位 //导线规格 //回路编号 //如果弱电缆数不为空,则导线型号csType = 弱电缆数csWeakWireNum + csType; //add liaoy 2015-10-16 CString csWeakLineNum; int nLen = csType.GetLength(); int nPos = 0; for (nPos = 0;nPos < nLen;nPos++) { TCHAR ch = csType[nPos]; if (ch >='0' && ch <='9') { continue; } else { break; } } csWeakLineNum = csType.Left(nPos); csType = csType.Right(nLen - nPos); SetXData(vecIds[i],_T("weakwirenum"),csWeakLineNum,csWeakLineNum.GetLength()); //add end SetXData(vecIds[i],_T("ltype"),csType,csType.GetLength()); SetXData(vecIds[i],_T("ldm"),csRadius,csRadius.GetLength()); SetXData(vecIds[i],_T("lmeth"),csMode,csMode.GetLength()); SetXData(vecIds[i],_T("linst"),csPlace,csPlace.GetLength()); SetXData(vecIds[i],_T("lnoar"),csArea,csArea.GetLength()); SetXData(vecIds[i],_T("lnorm"),csNorm,csNorm.GetLength()); SetXData(vecIds[i],_T("linenum"),csName,csName.GetLength()); } } //回路编号标注时才用 void TDbWireDimNew::SetWireName(LPCTSTR pszWireName) { if(m_vecIds.size() < 1 || !m_bSample) return; AcDbObjectId id = m_vecIds[0]; if (m_bSample != NULL) { m_vecText.clear(); CString csType = GetXDataByName(id, _T("ltype")); //导线型号 CString csRadius = GetXDataByName(id, _T("ldm")); //穿管直径 CString csMode = GetXDataByName(id, _T("lmeth")); //配线方式 CString csPlace = GetXDataByName(id, _T("linst")); //敷设部位 CString csArea = GetXDataByName(id, _T("lnoar")); //导线规格 CString csNorm = GetXDataByName(id, _T("lnorm")); CString csName = pszWireName; //回路编号 CString sDimText = _T(""); sDimText.Format(_T("%s@%s@%s@%s@%s@%s@%s@"),csType,csRadius,csMode,csPlace,csArea,csNorm,csName); m_vecText.push_back(sDimText); m_dLineBaseLen = this->GetTextLen(); } } CString TDbWireDimNew::GetWeakLineNum() { return m_csWeakWireNum; } void TDbWireDimNew::MergeText(CString& sMerge,const CString& csArea,const CString& csMode,const CString& csRadius,const CString& csPlace) { if (!csArea.IsEmpty()) sMerge += csArea; if (!csMode.IsEmpty()) sMerge += _T("-") + csMode + csRadius; if (!csPlace.IsEmpty()) sMerge += _T("-") + csPlace; }