#include "stdafx.h" #include "AecDbMText.h" #include "AecDbSymbIndexPointer.h" #include "globalFunc.h" #include "AecDbSymbDrawingIndex.h" #include "PushProperty.h" #include "DimOptionData.h" const Adesk::UInt8 AecXDbSymbIndexPointer::g_nVersion = 3; // sg modify 081112 ACRX_DXF_DEFINE_MEMBERS(AecXDbSymbIndexPointer, AecXDbSymbWithText, AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent, 1, AEC_SUOYINFUHAO, "AEC_SUOYINFUHAO|缺乏上华解释器, 请下载上华软件|网址: www.shanghuasoft.com"); static Vector3D vecForSortCutLine; AecXDbSymbIndexPointer::AecXDbSymbIndexPointer() { // m_nRadius = 5.0; // 从高级选项中读取默认值 m_nRadius = g_DimOption::instance().g_dIndexPointerDia * 0.5; m_nTextHeight = 3.5; m_nTextBaseLen = 15.0; m_nFlag = 0; m_nSourceExtent = 0.0; m_dText2BaseRatio = -1000; // 使用GlobalFunc::DocGetText2BaseRatio,sg add 081112 m_nTextAlign = kAtEnd; // sg add 090217 m_dLineAngle = 0; m_dTextBaseLen2 = 0; } AecXDbSymbIndexPointer::~AecXDbSymbIndexPointer() { } BOOL AecXDbSymbIndexPointer::IsValid() const { //BOOL bRet = AecXDbSymbWithText::IsValid(); //if (!bRet) // return bRet; if (m_lstIndex.Length() != m_lstLabel.Length()) return FALSE; BOOL bRet = (m_nRadius > 0.0); return bRet; } //Acad::ErrorStatus //AecXDbSymbIndexPointer::subGetClassID(CLSID* pClsid) const //{ // *pClsid = CLSID_ComSymbIndex; // return Acad::eOk; //} const TCHAR* AecXDbSymbIndexPointer::GetDefaultLayer()const { extern TCHAR* LAY_INDEX_DIM; return LAY_INDEX_DIM; } // 提供对格式刷的支持 void AecXDbSymbIndexPointer::CopyPropertiesFrom(AcDbEntity *pSrcEntity, unsigned gMatchFlag) { AssertWriteEnabled(); AecXDbSymbWithText::CopyPropertiesFrom(pSrcEntity, gMatchFlag); AecXDbSymbIndexPointer *pSrc = AecXDbSymbIndexPointer::cast(pSrcEntity); if (pSrc != NULL) { m_nFlag = pSrc->m_nFlag; // 控制标记 m_nRadius = pSrc->m_nRadius; // 半径 m_nTextAlign = pSrc->m_nTextAlign; // sg add 090402,文字相对基线的对齐方式 } } // 从DWG读入数据: Acad::ErrorStatus AecXDbSymbIndexPointer::dwgInFields(AcDbDwgFiler* pFiler) { AssertWriteEnabled(); Acad::ErrorStatus es = AecXDbSymbWithText::dwgInFields(pFiler); if (es != Acad::eOk) return es; Adesk::UInt8 nVer; pFiler->readItem(&nVer); if (nVer > g_nVersion) {// Version is too new return Acad::eMakeMeProxy; } pFiler->readItem(&m_nFlag); pFiler->readItem((AcGePoint2d *)&m_ptStart); pFiler->readItem((AcGePoint2d *)&m_ptTurn); pFiler->readItem(&m_nRadius); pFiler->readItem(&m_nTextBaseLen); pFiler->readItem(&m_nSourceExtent); GlobalFunc::ReadString(pFiler, m_sIndexLabel); GlobalFunc::ReadString(pFiler, m_sDrawingLabel); GlobalFunc::ReadString(pFiler, m_sText1); GlobalFunc::ReadString(pFiler, m_sText2); if (nVer > 1) { m_lstLabel.Reset(); Adesk::UInt8 num; pFiler->readItem(&num); for (long i = 0; i < num; i++) { m_lstLabel.Append(new TCString); GlobalFunc::ReadString(pFiler, *m_lstLabel.Tail()); } m_lstIndex.Reset(); pFiler->readItem(&num); for (i = 0; i < num; i++) { m_lstIndex.Append(new TCString); GlobalFunc::ReadString(pFiler, *m_lstIndex.Tail()); } } if (nVer > 2) // sg add 081112,sg modify 090217,8.0版本为3 { pFiler->readItem(&m_dText2BaseRatio); pFiler->readItem(&m_dLineAngle); Adesk::UInt8 nTemp; pFiler->readItem(&nTemp); m_nTextAlign = (TSymbIPTextAlign)nTemp; m_polyCutLine.Reset(); GlobalFunc::ReadPoly2D(pFiler, m_polyCutLine); pFiler->readItem(&m_dTextBaseLen2); GlobalFunc::ReadString(pFiler, m_szText3); } else { m_dText2BaseRatio = -1000; m_nTextAlign = kAtEnd; m_dLineAngle = 0; m_polyCutLine.Reset(); m_dTextBaseLen2 = 0; m_szText3 = _T(""); } return pFiler->filerStatus(); } Acad::ErrorStatus AecXDbSymbIndexPointer::dwgOutFields(AcDbDwgFiler* pFiler) const { assertReadEnabled(); Acad::ErrorStatus es = AecXDbSymbWithText::dwgOutFields(pFiler); if (es != Acad::eOk) return es; pFiler->writeItem(g_nVersion); pFiler->writeItem(m_nFlag); pFiler->writeItem((const AcGePoint2d &)m_ptStart); pFiler->writeItem((const AcGePoint2d &)m_ptTurn); pFiler->writeItem(m_nRadius); pFiler->writeItem(m_nTextBaseLen); pFiler->writeItem(m_nSourceExtent); pFiler->writeString(m_sIndexLabel); pFiler->writeString(m_sDrawingLabel); pFiler->writeString(m_sText1); pFiler->writeString(m_sText2); pFiler->writeItem((Adesk::UInt8)m_lstLabel.Length()); for (long i = 0; i < m_lstLabel.Length(); i++) pFiler->writeString(m_lstLabel[i]); pFiler->writeItem((Adesk::UInt8)m_lstIndex.Length()); for (i = 0; i < m_lstIndex.Length(); i++) pFiler->writeString(m_lstIndex[i]); pFiler->writeItem(m_dText2BaseRatio); pFiler->writeItem(m_dLineAngle); pFiler->writeItem((Adesk::UInt8)m_nTextAlign); GlobalFunc::WritePoly2D(pFiler, m_polyCutLine); pFiler->writeItem(m_dTextBaseLen2); pFiler->writeString(m_szText3); return pFiler->filerStatus(); } Acad::ErrorStatus AecXDbSymbIndexPointer::dxfInFields(AcDbDxfFiler* pFiler) { return AecXDbSymbWithText::dxfInFields(pFiler); } Acad::ErrorStatus AecXDbSymbIndexPointer::dxfOutFields(AcDbDxfFiler* pFiler) const { return AecXDbSymbWithText::dxfOutFields(pFiler); } // ----------------------------------------------------------------------- // Active when being rotated, scaled, moved, etc. // Scale is disabled here Acad::ErrorStatus AecXDbSymbIndexPointer::subTransformBy(const AcGeMatrix3d& xform) { AssertWriteEnabled(); AecXDbSymbWithText::subTransformBy(xform); ads_matrix mat; GlobalFunc::AsAdsMatrix(xform, mat); ADSGePoint3d ptTextBase = GetTextBasePoint(); m_ptStart.TransformBy(mat); m_ptTurn.TransformBy(mat); ptTextBase.TransformBy(mat); if (HasAddedPoint()) { ADSGePoint3d ptAdded; GetAddedPoint(ptAdded); ptAdded.TransformBy(mat); SetAddedPoint(ptAdded); } Vector3D vt = ptTextBase - m_ptTurn; Vector3D vtBase(cos(m_nLayoutRotation), sin(m_nLayoutRotation)); // m_nTextBaseLen = (vt&vtBase)/GetPScale(); using namespace GlobalFunc; double dTmp = (vt & vtBase); // sg modify 090317,只取符号,不改变大小 int nSign = 1; if (fabs(dTmp) < 1.0E-5) // sg modify 090505,垂直的情况 { if (m_nTextBaseLen < -1.0E-5) // 一般情况下不改变符号 nSign = -1; if (GlobalFunc::IsMirrorMatrix(xform)) // 镜像时,通常要改变符号 nSign *= -1; } else if (dTmp < -1.0E-5) nSign = -1; m_nTextBaseLen = nSign * fabs(m_nTextBaseLen); if (xform.isUniScaledOrtho()) { double dScale = xform.scale(); m_nRadius *= xform.scale(); // m_nTextBaseLen *= xform.scale(); // sg modify 090317,只改变大小,不考虑符号 m_nTextBaseLen *= fabs(xform.scale()); if (m_nFlag == 0) // 指向索引 m_nSourceExtent *= xform.scale(); m_dTextBaseLen2 *= fabs(xform.scale()); } // lgh add 20101222 // 剖切线改变,保持长度,起点同步改变 // 取得所有剖切线,剖切线的起点随着变换矩阵变换,变换之后,保持剖切线的长度(随8.2逻辑) if (!IsIndexPointer()) { AryXLine arCutLine; GetCutLineAll(arCutLine); bool bNeg = m_nSourceExtent < 0.0; Vector3D vecFirstLine = GetFirstLineUnitVec(); arCutLine.RemoveAt(0); for (int i = 0; i < (int)arCutLine.GetSize(); i++) { double dLen = arCutLine[i].GetLength(); ADSGePoint3d ptStart = arCutLine[i].StartPoint(); ADSGePoint3d ptEnd; ptStart.TransformBy(mat); ptEnd = ptStart + ScaleVec(dLen, vecFirstLine); arCutLine[i].SetPoints(ptStart, ptEnd); } if (arCutLine.GetSize() > 0) SetCutLine(arCutLine); } return Acad::eOk; } // 取得夹点说明 Acad::ErrorStatus AecXDbSymbIndexPointer::GetGripText(int idx, CString &cs) const { Acad::ErrorStatus es = Acad::eOk; // if (idx == 0) // cs = _T("拉伸文字基线"); // else if (idx == 1) //// cs = _T("移动引线位置(Ctrl-固定标号)"); //// cs = GetCtrlToggle()?_T("移动引线位置(Ctrl-固定标号)"):_T("移动引线位置(Ctrl-不固定标号)"); // // sg modify 090605,默认为固定标号的情况 // cs = GetCtrlToggle()?_T("移动引线位置(Ctrl-不固定标号)"):_T("移动引线位置(Ctrl-固定标号)"); // else if (idx == 2) // cs = _T("移动标注点"); // else if (idx == 3) // { // if (m_nFlag == 0) // { // if (m_nSourceExtent < g_Option::instance()._DIST_SNAP) // cs = _T("改变索引个数"); // else // cs = _T("移动目标范围"); // } // else // cs = _T("改变剖视方向"); // } // else if (idx == 4) // cs = _T("改变索引个数"); // else if (idx == 5) // cs = _T("改变剖切长度"); CStringArray tips; BuildGrip(&tips, NULL, NULL); if (idx < tips.GetSize()) cs = tips[idx]; return es; } // Overriden functions for edit Acad::ErrorStatus AecXDbSymbIndexPointer::subGetGripPoints(AcGePoint3dArray& gripPoints, AcDbIntArray& osnapModes, AcDbIntArray& geomIds) const { // 试图在const 成员函数中修改成员变量的值 assertReadEnabled(); //ADSGePoint3d ptTextBase = GetTextBasePoint(); //gripPoints.append(ptTextBase); //gripPoints.append(m_ptTurn); //gripPoints.append(m_ptStart); //if (m_nFlag == 0) // 指向索引 //{ // if (m_nSourceExtent > g_Option::instance()._DIST_SNAP) // { // GeCircle cir(m_ptStart, m_nSourceExtent/2.0); // ADSGePoint3d ptTemp[2]; // if (!GeLine(m_ptStart, m_ptTurn, LS_FINITE).Intersection(&cir, ptTemp[0], ptTemp[1])) // ptTemp[0] = m_ptStart; // gripPoints.append(ptTemp[0]); // } //} //else // 剖切索引 //{ // double nDist = 1.5; // double nOffset = m_nSourceExtent<0.0?-nDist:nDist; // GeLine lnOffset = GeLine(m_ptStart, m_ptTurn).Offset(nOffset*GetPScale()); // gripPoints.append(lnOffset.StartPoint()); //} // //gripPoints.append(GetTextEndPoint().AsAcGePoint3d()); //if (m_nFlag != 0) // 剖切索引 //{ // ADSGePoint3d ptTemp; // double nDist = 1.5; // double nOffset = m_nSourceExtent<0.0?-nDist:nDist; // GeLine lnOffset = GeLine(m_ptStart, m_ptTurn).Offset(nOffset*GetPScale()); // ads_polar(lnOffset.StartPoint(), lnOffset.Direction(), fabs(m_nSourceExtent)*GetPScale(),ptTemp); // gripPoints.append(ptTemp.AsAcGePoint3d()); //} // lgh modify 101227 // 8.5的功能下,夹点数目较多,并且夹点会出现动态变化 // 使用这种方式设置夹点,每个夹点动态的绑定为一个枚举类型上,在夹点操作时,不需要在总是考虑各种情况下的夹点序号 BuildGrip(NULL, &gripPoints, NULL); return Acad::eOk; } Acad::ErrorStatus AecXDbSymbIndexPointer::subGetGripPoints(AcDbGripDataPtrArray & grips, const double curViewUnitSize, const int gripSize, const AcGeVector3d & curViewDir, const int bitflags) const { return Acad::eNotImplementedYet; } // stretch points is diffrent from grep points, with no midpoint included Acad::ErrorStatus AecXDbSymbIndexPointer::subGetStretchPoints(AcGePoint3dArray & stretchPoints) const { assertReadEnabled(); //ADSGePoint3d ptTextBase = GetTextBasePoint(); //stretchPoints.append(ptTextBase); //stretchPoints.append(m_ptTurn); //stretchPoints.append(m_ptStart); // //if (m_nFlag == 0) //{ // if (m_nSourceExtent > g_Option::instance()._DIST_SNAP) // { // GeCircle cir(m_ptStart, m_nSourceExtent/2.0); // ADSGePoint3d ptTemp[2]; // if (!GeLine(m_ptStart, m_ptTurn, LS_FINITE).Intersection(&cir, ptTemp[0], ptTemp[1])) // ptTemp[0] = m_ptStart; // stretchPoints.append(ptTemp[0]); // } //} //else //{ // double nDist = 1.5; // double nOffset = m_nSourceExtent<0.0?-nDist:nDist; // GeLine lnOffset = GeLine(m_ptStart, m_ptTurn).Offset(nOffset*GetPScale()); // stretchPoints.append(lnOffset.StartPoint()); //} BuildGrip(NULL, &stretchPoints, NULL, false); return Acad::eOk; } void AecXDbSymbIndexPointer::SetAppendIndexNum(long num) { AssertWriteEnabled(); while (m_lstLabel.Length() < num) { if (m_lstLabel.Length() > 0) m_lstLabel.Append(new TCString(*m_lstLabel.Tail())); else m_lstLabel.Append(new TCString(m_sDrawingLabel)); } while (m_lstLabel.Length() > num) m_lstLabel.Remove(m_lstLabel.Length() - 1); while (m_lstIndex.Length() < num) { if (m_lstIndex.Length() > 0) m_lstIndex.Append(new TCString(*m_lstIndex.Tail())); else m_lstIndex.Append(new TCString(m_sIndexLabel)); } while (m_lstIndex.Length() > num) m_lstIndex.Remove(m_lstIndex.Length() - 1); } // 功能: 夹点操作 Acad::ErrorStatus AecXDbSymbIndexPointer::subMoveGripPointsAt(const AcDbIntArray& indices, const AcGeVector3d& offset) { AssertWriteEnabled(); // BOOL bSkip0 = FALSE; // if (indices.contains(0) && indices.contains(1)) // bSkip0 = TRUE; // // ADSGePoint3d vtOffset(offset[0], offset[1]); // for (int i = 0; i < indices.length(); i++) // { // int idx = indices[i]; // if (idx == 0) // 拉伸文字基线 // { // if (!bSkip0) // { // Vector3D vt(1.0, 0.0); // vt.Rotate(GetLayoutRotation()); // add by whl on 050725 // double nVal = (vtOffset&vt); // m_nTextBaseLen += nVal/GetPScale(); // } // } // else if (idx == 1) // 移动引线位置(Ctrl-(不)固定标号) // { // ADSGePoint3d ptTextBase = GetTextBasePoint(); // // sg modify 090323,由于高版本下,一直按CTRL会自动复制,改用按一次,切换一次的方式 //// if (IsKeyPressed(VK_CONTROL)) // if (!bSkip0 && GetCtrlToggle()) // 固定 // { // // sg modify 090324,m_ptTurn点沿布局转角方向移动 // Vector3D vecOffset = vtOffset, // vtBase(cos(m_nLayoutRotation), sin(m_nLayoutRotation)); // double dOffset = (vecOffset&vtBase); // ads_polar(m_ptTurn, m_nLayoutRotation, dOffset, m_ptTurn); //// m_ptTurn.x += vtOffset.x; // // double nDist = ptTextBase.Distance2d(m_ptTurn); //// GeLine ln(GetStartPoint(), m_ptTurn); //// int nSide = ln.OnWhichSide(ptTextBase); //// if (nSide == OFFSET_LEFT) //// nDist = -nDist; // // // sg modify 090324,原算法有问题,符号在m_ptStart下时,符号不会固定 // double dDirRot = ads_angle(ptTextBase, m_ptTurn); // dDirRot = Wcs2Layout(dDirRot); // if (dDirRotPI*1.5) // 符号在m_ptTurn点左侧 // nDist *= -1; // SetTextBaseLen(nDist, FALSE); // } // else // 不固定 // m_ptTurn += vtOffset; // } // else if (idx == 2) // 移动标注点 // m_ptStart += vtOffset; // else if (idx == 3) // { // if (m_nFlag==0 && m_nSourceExtent= 4); // ADSGePoint3d ptVert = pts[3]; // ptVert += vtOffset; // if (m_nFlag == 0) // 移动目标范围 // m_nSourceExtent = ptVert.Distance2d(m_ptStart)*2.0; // else // 改变剖视方向 // { // GeLine ln(m_ptStart, m_ptTurn); // int nSide = ln.OnWhichSide(ptVert); // if (nSide == OFFSET_LEFT) // m_nSourceExtent = - fabs(m_nSourceExtent); // else // m_nSourceExtent = fabs(m_nSourceExtent); // } // } // } // else if (idx == 4) // 改变索引个数 // { // ADSGePoint3d ptNew = GetTextEndPoint() + offset; //// long num=ptNew.Distance2d(GetTextBasePoint())/(m_nRadius*2*GetPScale()); // // sg modify 081225,解决编译中的WARNING // double dTmpNum = // ptNew.Distance2d(GetTextBasePoint())/(m_nRadius*2*GetPScale()); // long num = (long)dTmpNum; // SetAppendIndexNum(num); // } // else if (idx == 5) // 改变剖切长度 // { // ADSGePoint3d ptTemp, ptEnd; // double nDist = 1.5; // double nOffset = m_nSourceExtent<0.0?-nDist:nDist; // GeLine lnOffset = GeLine(m_ptStart, m_ptTurn).Offset(nOffset*GetPScale()); // ads_polar(lnOffset.StartPoint(), lnOffset.Direction(), fabs(m_nSourceExtent)*GetPScale(),ptTemp); // GeLine line(lnOffset.StartPoint(), ptTemp); // ptTemp = ptTemp + offset; // ptTemp.Project(&line, ptEnd); // double dist = ptEnd.Distance2d(lnOffset.StartPoint()); // if (dist > 1) // { // if (m_nSourceExtent > 0) // m_nSourceExtent = dist/GetPScale(); // else // m_nSourceExtent = -dist/GetPScale(); // } // } // } // lgh modify 101227 // sumMove***的调用机制约束,每次在调用该函数的时候,该类中的数据都是初始数据。 // 构造夹点类型信息数组:每次都会重新读取夹点的数据 SGripAdditional sga; BuildGrip(NULL, NULL, &sga); sga.FillCheckProp(indices); int nCutSplit = 0; bool bStartCheck = sga.FindCheck(eG1); bool bEndCheck = sga.FindCheck(HasAddedPoint() ? eGAdd : eG2); if (!bStartCheck && bEndCheck) { // 选中了转折点,剖切线保持跟起点距离保持不变 nCutSplit = (int)((sga.nCutEnd - sga.nCutStart) * 0.5) - 1; } else nCutSplit = 0; MoveGripOrStretchPoints(sga, offset, true, nCutSplit); return Acad::eOk; } // 功能: 夹点操作 Acad::ErrorStatus AecXDbSymbIndexPointer::subMoveStretchPointsAt( const AcDbIntArray& indices, const AcGeVector3d& offset) { AssertWriteEnabled(); // // sg add 090219,指向索引符号,圆圈范围发生变化的问题 // DualList indices1; // for (long i=0; i 1) { iText -= 2; AecXDbSymbDrawingIndex index; index.SetPScale(GetPScale()); index.setPropertiesFrom(this); double dTextRatio = GetTextRatio(); index.SetTextRatio(dTextRatio); // 设置“文字字高系数” int nOldStyle = GetOldStyle(); // sg add 090723,增加是否使用旧圆圈文字样式 index.SetOldStyle(nOldStyle); index.SetCenter(GetIndexCenter(iText / 2)); index.SetLineWidth(0.0); index.SetRadius(m_nRadius); if ((iText / 2) == 0) { index.SetDrawingLabel(m_sDrawingLabel); index.SetIndexLabel(m_sIndexLabel); } else { index.SetDrawingLabel(m_lstLabel[iText / 2 - 1]); index.SetIndexLabel(m_lstIndex[iText / 2 - 1]); } index.SetTextStyleId(m_idTextStyle); SubText *pSubText = index.GetSubText(iText % 2); if (pSubText != NULL) { pSubText->SetObjectId(objectId()); pSubText->SetIndex(iText + 2); } return pSubText; } else return AecXDbSymbWithText::GetSubText(iText); } SubText* AecXDbSymbIndexPointer::HitTestText(ADSGePoint3d pt)const { SubText *pSubText = NULL; for (long i = 0; i < GetAppendIndexNum() + 1; i++) { AecXDbSymbDrawingIndex index; index.SetPScale(GetPScale()); index.setPropertiesFrom(this); double dTextRatio = GetTextRatio(); index.SetTextRatio(dTextRatio); // 设置“文字字高系数” int nOldStyle = GetOldStyle(); // sg add 090723,增加是否使用旧圆圈文字样式 index.SetOldStyle(nOldStyle); index.SetCenter(GetIndexCenter(i)); index.SetLineWidth(0.0); index.SetRadius(m_nRadius); if (i == 0) { index.SetDrawingLabel(m_sDrawingLabel); index.SetIndexLabel(m_sIndexLabel); } else { index.SetDrawingLabel(m_lstLabel[i - 1]); index.SetIndexLabel(m_lstIndex[i - 1]); } index.SetTextStyleId(m_idTextStyle); pSubText = index.HitTestText(pt); if (pSubText != NULL) { pSubText->SetIndex(pSubText->GetIndex() + i * 2 + 2); pSubText->SetObjectId(objectId()); return pSubText; } } return AecXDbSymbWithText::HitTestText(pt); } void AecXDbSymbIndexPointer::SetSubText(long i, CString sText) { AssertWriteEnabled(); if (i == 0) SetText1(sText); else if (i == 1) SetText2(sText); else { if (i == 2) SetIndexLabel(sText); else if (i == 3) SetDrawingLabel(sText); else { if ((i % 2) == 0) *m_lstIndex[(i - 4) / 2] = sText; else *m_lstLabel[(i - 4) / 2] = sText; } } } long AecXDbSymbIndexPointer::GetNextSubTextIndex(long i, bool bVert, bool bPre)const//ok { long num = GetSubTextNum(); long iStart = i; do { if (bPre) i = (i - 1 + num) % num; else i = (i + 1) % num; SubText *pSubText = GetSubText(i); if (pSubText != NULL) { delete pSubText; break; } } while (iStart != i); return i; } Acad::ErrorStatus AecXDbSymbIndexPointer::Draw2d(AcGiDraw &dc) const { assertReadEnabled(); GlobalFunc::_LoadConfig(); if (Has2DBuffer() && !m_bInJig) { dc.SetColor(colorIndex()); dc.SetLayer(layerId()); BaseEx::_Draw2DBuffers(dc, true); return Acad::eOk; } if (!IsValid()) return Acad::eInvalidInput; int a = 0; if (!m_bInJig) int a = 0; // 1、圈内索引!,以及附加圈内索引... AecXDbSymbDrawingIndex index; index.SetPScale(GetPScale()); index.setPropertiesFrom(this); index.SetCenter(GetIndexCenter()); index.SetLineWidth(0.0); index.SetRadius(m_nRadius); index.SetIndexLabel(m_sIndexLabel); // 线上 index.SetDrawingLabel(m_sDrawingLabel); // 线下 index.SetTextStyleId(m_idTextStyle); index.SetTextColor(m_colorText); // sg add 090608,将文字和标注放在同一层,文字的颜色为白色 // sg add 090410,增加文字字高系数的设置,注:全部索引图名,使用1个设置 double dTextRatio = GetTextRatio(); index.SetTextRatio(dTextRatio); // 设置“文字字高系数” int nOldStyle = GetOldStyle(); // sg add 090723,增加是否使用旧圆圈文字样式 index.SetOldStyle(nOldStyle); //index.setLayer(dc.GetLayerId()); //index.setColorIndex(dc.GetColor()); //if (dc.IsFullExplode()) // index.ExplodeOrDraw2d(dc); //else // dc.DrawEntity(index); // 绘制第一个索引图名符号 DrawBaseEx(dc, index); for (long i = 0; i < GetAppendIndexNum(); i++) { AecXDbSymbDrawingIndex index; index.SetPScale(GetPScale()); index.setPropertiesFrom(this); index.SetCenter(GetIndexCenter(i + 1)); index.SetLineWidth(0.0); index.SetRadius(m_nRadius); index.SetIndexLabel(m_lstIndex[i]); // 线上 index.SetDrawingLabel(m_lstLabel[i]); // 线下 index.SetTextStyleId(m_idTextStyle); index.SetTextRatio(dTextRatio); // sg add 090410,设置“文字字高系数” index.SetTextColor(m_colorText); // sg add 090608,将文字和标注放在同一层,文字的颜色为白色 index.SetOldStyle(nOldStyle); // sg add 090723,增加是否使用旧圆圈文字样式 //if (dc.IsFullExplode()) // index.ExplodeOrDraw2d(dc); //else // dc.DrawEntity(index); // 绘制多个索引图名符号 DrawBaseEx(dc, index); } // 2、绘制引出线段1,引出线段2(原文字基线),延长线 // lgh modified 20101208 // 8.5版本增加以下需求: // 1、带延长线的索引符号-- // 2、标注文字和圈内索引文字可以采用不同的文字样式-- // 3、剖切索引允许用户绘制三段或者两端 // 4、支持多个剖切线 ADSGePoint3d ptTail = GetTextBasePoint(); //dc << GeLine(m_ptTurn, ptTail); // 绘制文字基线 DrawLine(dc, m_ptTurn, ptTail); if (HasAddedPoint()) { ADSGePoint3d ptAdded; GetAddedPoint(ptAdded); //dc << GeLine(ptAdded, m_ptTurn); DrawLine(dc, ptAdded, m_ptTurn); } // 3、lgh add,延长线的绘制 if (HasExtendLine()) { //dc << GeLine(GetTextEndPoint(), GetG5Point()); DrawLine(dc, GetTextEndPoint(), GetG5Point()); } GeLine textLine = GetTextLine(); if (NeedDrawUpText()) // 上标文字 { AecXDbText *pText = ConstructDimText(textLine, true); pText->SetPScale(GetPScale()); pText->setPropertiesFrom(this); //if (dc.IsExportTch4()) // sg modify 090608 //{ // // sg add 120313,分解出来的文字的图层和颜色要随“高级选项”中的设置来处理 // if (g_nSymbTextT3Layer == 1 && !!m_idTextLayer) // pText->setLayer(m_idTextLayer); // 文字层 // else // pText->setColorIndex(m_colorText); // 文字和标注放在同一层,文字的颜色为白色 //} //else pText->setColorIndex(m_colorText); // sg add 090608,将文字和标注放在同一层,文字的颜色为白色 } PushProperty vProp(pText, dc); //if (dc.IsFullExplode()) // pText->ExplodeOrDraw2d(dc); // 绘制线上文字 //else // dc.DrawEntity(*pText); DrawBaseEx(dc, *pText); delete pText; pText = NULL; } if (NeedDrawDownText()) // 下标文字 { AecXDbText *pText = ConstructDimText(textLine, false); pText->SetPScale(GetPScale()); pText->setPropertiesFrom(this); //if (dc.IsExportTch4()) // sg modify 090608 //{ // // sg add 120313,分解出来的文字的图层和颜色要随“高级选项”中的设置来处理 // if (g_nSymbTextT3Layer == 1 && !!m_idTextLayer) // pText->setLayer(m_idTextLayer); // 文字层 // else // pText->setColorIndex(m_colorText); // 文字和标注放在同一层,文字的颜色为白色 //} //else pText->setColorIndex(m_colorText); // sg add 090608,将文字和标注放在同一层,文字的颜色为白色 } PushProperty vProp(pText, dc); //if (dc.IsFullExplode()) // pText->ExplodeOrDraw2d(dc); // 绘制线上文字 //else //dc.DrawEntity(*pText); DrawBaseEx(dc, *pText); delete pText; } // 5、第一段,引线(并且绘制了剖切线) ADSGePoint3d ptFirstEnd; if (!GetAddedPoint(ptFirstEnd)) ptFirstEnd = m_ptTurn; if (m_nFlag == 1) // 剖切 { // modify by lgh 20101208,8.5 允许绘制三段引出线 // GeLine lnLeader(m_ptStart, m_ptTurn); GeLine lnLeader(m_ptStart, ptFirstEnd); //dc << lnLeader; DrawLine(dc, m_ptStart, ptFirstEnd); AryXLine arCutLine; GetCutLineAll(arCutLine); Vector3D vecPlump = CutLineOffset(); for (int i = 0; i < (int)arCutLine.GetSize(); i++) { AcDbPolyline pLine; pLine.setPropertiesFrom(this); pLine.addVertexAt(0, arCutLine[i].StartPoint() + vecPlump); pLine.addVertexAt(1, arCutLine[i].EndPoint() + vecPlump); pLine.setConstantWidth(0.5 * GetPScale()); //dc.Polyline(pLine); DrawPline(dc, pLine); } } else // 指向 { GeCircle cir(m_ptStart, m_nSourceExtent / 2.0); //dc << cir; //AcDbCircle *pCir = new AcDbCircle(cir.GetCenterPt(), AcGeVector3d::kZAxis, cir.GetRadius()); //pCir->setColorIndex(dc.GetColor()); //pCir->setLayer(dc.GetLayerId()); //dc.DrawEntity(*pCir); //_Add2DBuffer(pCir); DrawCircle(dc, cir); ADSGePoint3d ptTemp[2]; if (!GeLine(m_ptStart, ptFirstEnd, LS_FINITE).Intersection(&cir, ptTemp[0], ptTemp[1])) ptTemp[0] = m_ptStart; //dc << GeLine(ptTemp[0], ptFirstEnd); DrawLine(dc, ptTemp[0], ptFirstEnd); } return Acad::eOk; } int AecXDbSymbIndexPointer::ConvertText(TConvertTextPtr ptr, void *pData) { AssertWriteEnabled(); TCString sText; int nRet = ptr(m_sText1, sText, pData); if (nRet == RTNORM) { m_sText1 = sText; } int nRet1 = ptr(m_sText2, sText, pData); if (nRet1 == RTNORM) { m_sText2 = sText; } else if (nRet1 == RTERROR) nRet = nRet1; nRet1 = ptr(m_sIndexLabel, sText, pData); if (nRet1 == RTNORM) { m_sIndexLabel = sText; } else if (nRet1 == RTERROR) nRet = nRet1; nRet1 = ptr(m_sDrawingLabel, sText, pData); if (nRet1 == RTNORM) { m_sDrawingLabel = sText; } else if (nRet1 == RTERROR) nRet = nRet1; return nRet; } BOOL AecXDbSymbIndexPointer::GetText(Adesk::UInt32 cookies, AecXDbText &text) const { int nLength = GetAppendIndexNum(); // sg add 090609,支持圆圈文字查找替换 nLength = (nLength + 1) * 2; if (!!m_sText1) nLength++; if (!!m_sText2) nLength++; // if (cookies >= 2) // sg modify 090609 if ((int)cookies >= nLength) return FALSE; // 写文字 AcDb::TextHorzMode hMode; ADSGePoint3d ptTail = GetTextBasePoint(), ptTextAlign = ptTail; // double nText2Base = DocGetText2Base()*GetPScale(); double nText2Base = GetText2BaseRatio(FALSE, TRUE); // sg modify 081112,距基线系数 double nDirRot = ads_angle(ptTail, m_ptTurn); nDirRot = Wcs2Layout(nDirRot); if (nDirRotPI * 1.5) { // sg add 090402,解决文字相对基线对齐方式的问题 if (m_nTextAlign == kAtStart) // 起端对齐 { ads_polar(m_ptTurn, m_nLayoutRotation + PI, nText2Base, ptTextAlign); hMode = AcDb::kTextRight; } else if (m_nTextAlign == kAtMiddle) // 居中对齐 { Midpoint(m_ptTurn, ptTail, ptTextAlign); hMode = AcDb::kTextCenter; } else // 末端对齐 { ads_polar(ADSGePoint3d(ptTextAlign), m_nLayoutRotation, nText2Base, ptTextAlign); hMode = AcDb::kTextLeft; } } else { // sg modify 090402,解决文字相对基线对齐方式的问题 if (m_nTextAlign == kAtStart) // 起端对齐 { ads_polar(m_ptTurn, m_nLayoutRotation, nText2Base, ptTextAlign); hMode = AcDb::kTextLeft; } else if (m_nTextAlign == kAtMiddle) // 居中对齐 { Midpoint(m_ptTurn, ptTail, ptTextAlign); hMode = AcDb::kTextCenter; } else // 末端对齐 { ads_polar(ADSGePoint3d(ptTextAlign), m_nLayoutRotation + PI, nText2Base, ptTextAlign); hMode = AcDb::kTextRight; } } text.setPropertiesFrom(this); text.SetHeight(GetTextHeight()); if (cookies == 0) { if (!!m_sText1) // m_sText1 { text.SetStyleId(GetDimTextStyle()); text.SetText(m_sText1); text.SetAlignment(GlobalFunc::GetTextAlignment(hMode, AcDb::kTextBottom)); text.SetLocation(ptTextAlign + ADSGePoint3d(0.0, nText2Base)); } else if (!!m_sText2) // m_sText2 { text.SetStyleId(GetDimTextStyle()); text.SetText(m_sText2); text.SetAlignment(GlobalFunc::GetTextAlignment(hMode, AcDb::kTextTop)); text.SetLocation(ptTextAlign - ADSGePoint3d(0.0, nText2Base)); } else // m_sIndexLabel { text.SetStyleId(m_idTextStyle); AecXDbSymbDrawingIndex index; index.SetPScale(GetPScale()); index.setPropertiesFrom(this); index.SetCenter(GetIndexCenter()); index.SetLineWidth(0.0); index.SetRadius(m_nRadius); index.SetIndexLabel(m_sIndexLabel); // 线上 index.SetDrawingLabel(m_sDrawingLabel); // 线下 index.SetTextStyleId(m_idTextStyle); index.SetTextRatio(GetTextRatio()); // 设置“文字字高系数” int nOldStyle = GetOldStyle(); // sg add 090723,增加是否使用旧圆圈文字样式 index.SetOldStyle(nOldStyle); return index.GetText(0, text); } } else if (cookies == 1) { if (!!m_sText1 && !!m_sText2) // m_sText2 { text.SetStyleId(GetDimTextStyle()); text.SetText(m_sText2); text.SetAlignment(GlobalFunc::GetTextAlignment(hMode, AcDb::kTextTop)); text.SetLocation(ptTextAlign - ADSGePoint3d(0.0, nText2Base)); } else if (!!m_sText1 || !!m_sText2) // m_sIndexLabel { AecXDbSymbDrawingIndex index; index.SetPScale(GetPScale()); index.setPropertiesFrom(this); index.SetCenter(GetIndexCenter()); index.SetLineWidth(0.0); index.SetRadius(m_nRadius); index.SetIndexLabel(m_sIndexLabel); // 线上 index.SetDrawingLabel(m_sDrawingLabel); // 线下 index.SetTextStyleId(m_idTextStyle); index.SetTextRatio(GetTextRatio()); // 设置“文字字高系数” int nOldStyle = GetOldStyle(); // sg add 090723,增加是否使用旧圆圈文字样式 index.SetOldStyle(nOldStyle); return index.GetText(0, text); } else // m_sDrawingLabel { text.SetStyleId(m_idTextStyle); AecXDbSymbDrawingIndex index; index.SetPScale(GetPScale()); index.setPropertiesFrom(this); index.SetCenter(GetIndexCenter()); index.SetLineWidth(0.0); index.SetRadius(m_nRadius); index.SetIndexLabel(m_sIndexLabel); // 线上 index.SetDrawingLabel(m_sDrawingLabel); // 线下 index.SetTextStyleId(m_idTextStyle); index.SetTextRatio(GetTextRatio()); // 设置“文字字高系数” int nOldStyle = GetOldStyle(); // sg add 090723,增加是否使用旧圆圈文字样式 index.SetOldStyle(nOldStyle); return index.GetText(1, text); } } else { text.SetStyleId(m_idTextStyle); int nTmp = cookies; if (!!m_sText1) nTmp -= 1; if (!!m_sText2) nTmp -= 1; int nRemainder = nTmp % 2, // 余数 nQuotient = nTmp / 2; // 商 if (nQuotient > 0) { nQuotient--; AecXDbSymbDrawingIndex index; index.SetPScale(GetPScale()); index.setPropertiesFrom(this); index.SetCenter(GetIndexCenter(nQuotient + 1)); index.SetLineWidth(0.0); index.SetRadius(m_nRadius); index.SetIndexLabel(m_lstIndex[nQuotient]); // 线上 index.SetDrawingLabel(m_lstLabel[nQuotient]); // 线下 index.SetTextStyleId(m_idTextStyle); index.SetTextRatio(GetTextRatio()); // 设置“文字字高系数” int nOldStyle = GetOldStyle(); // sg add 090723,增加是否使用旧圆圈文字样式 index.SetOldStyle(nOldStyle); return index.GetText(nRemainder, text); } else { AecXDbSymbDrawingIndex index; index.SetPScale(GetPScale()); index.setPropertiesFrom(this); index.SetCenter(GetIndexCenter()); index.SetLineWidth(0.0); index.SetRadius(m_nRadius); index.SetIndexLabel(m_sIndexLabel); // 线上 index.SetDrawingLabel(m_sDrawingLabel); // 线下 index.SetTextStyleId(m_idTextStyle); index.SetTextRatio(GetTextRatio()); // 设置“文字字高系数” int nOldStyle = GetOldStyle(); // sg add 090723,增加是否使用旧圆圈文字样式 index.SetOldStyle(nOldStyle); return index.GetText(nRemainder, text); } } return TRUE; } // 返回发现的位置,同时posStart往前移动(以便继续找下一个使用), TextPosition AecXDbSymbIndexPointer::FindSubText(const TCHAR *sSubText, TextPosition &posStart, TextRange *pRange) const { TextPosition pos; if (!sSubText || !sSubText[0]) return pos; // 文字基线,考虑了延长线的情况 GeLine textLine = GetTextLine(); TextPosition posNext = posStart; while (1) { TextPosition posFind; int nCookies = posNext.m_nCookies; // sg modify 110211,兼顾单行、多行文字 if (nCookies == 0) // 线上文字 { if (!!m_sText1) // m_sText1 { AecXDbText *pText = ConstructDimText(textLine, true); posFind = pText->FindSubText(sSubText, posNext, pRange); delete pText; pText = NULL; } else if (!!m_sText2) // m_sText2 { AecXDbText *pText = ConstructDimText(textLine, false); posFind = pText->FindSubText(sSubText, posNext, pRange); delete pText; pText = NULL; } else // 圆圈文字 { AecXDbText text; if (!GetText(posNext.m_nCookies, text)) break; posFind = text.FindSubText(sSubText, posNext, pRange); } } else if (nCookies == 1) { if (!!m_sText1 && !!m_sText2) // m_sText2 { AecXDbText *pText = ConstructDimText(textLine, false); posFind = pText->FindSubText(sSubText, posNext, pRange); delete pText; pText = NULL; } else { AecXDbText text; if (!GetText(posNext.m_nCookies, text)) break; posFind = text.FindSubText(sSubText, posNext, pRange); } } else // 圆圈文字 { AecXDbText text; if (!GetText(posNext.m_nCookies, text)) 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; break; } } return pos; } // 返回下一次查找的开始位置 // sg modify 090609,支持圆圈文字查找替换 TextPosition AecXDbSymbIndexPointer::ReplaceSubText(const TextPosition &posRep, const TCHAR *sRepText, TextRange *pRange) { AssertWriteEnabled(); // 文字基线,考虑了延长线的情况 GeLine textLine = GetTextLine(); TextPosition posNext; int cookies = posRep.m_nCookies; if (cookies == 0) { if (!!m_sText1) // m_sText1 { AecXDbText *pText = ConstructDimText(textLine, true); posNext = pText->ReplaceSubText(posRep, sRepText, pRange); SetText1(pText->GetText()); delete pText; pText = NULL; } else if (!!m_sText2) // m_sText2 { AecXDbText *pText = ConstructDimText(textLine, false); posNext = pText->ReplaceSubText(posRep, sRepText, pRange); SetText2(pText->GetText()); delete pText; pText = NULL; } else // 圆圈文字 { AecXDbText text; if (!GetText(posRep.m_nCookies, text)) return posNext; posNext = text.ReplaceSubText(posRep, sRepText, pRange); SetIndexLabel(text.GetText()); } } else if (cookies == 1) // m_sText2 { if (!!m_sText1 && !!m_sText2) { AecXDbText *pText = ConstructDimText(textLine, false); posNext = pText->ReplaceSubText(posRep, sRepText, pRange); SetText2(pText->GetText()); delete pText; pText = NULL; } else if (!!m_sText1 || !!m_sText2) // m_sIndexLabel { AecXDbText text; if (!GetText(posRep.m_nCookies, text)) return posNext; posNext = text.ReplaceSubText(posRep, sRepText, pRange); SetIndexLabel(text.GetText()); } else // m_sDrawingLabel { AecXDbText text; if (!GetText(posRep.m_nCookies, text)) return posNext; posNext = text.ReplaceSubText(posRep, sRepText, pRange); SetDrawingLabel(text.GetText()); } } else // 圆圈文字 { AecXDbText text; if (!GetText(posRep.m_nCookies, text)) return posNext; posNext = text.ReplaceSubText(posRep, sRepText, pRange); if (!!m_sText1) cookies -= 1; if (!!m_sText2) cookies -= 1; int nRemainder = cookies % 2, // 余数 nQuotient = cookies / 2; // 商 if (nQuotient > 0) { nQuotient--; if (nRemainder == 0) // m_lstIndex *m_lstIndex[nQuotient] = text.GetText(); else // m_lstLabel *m_lstLabel[nQuotient] = text.GetText(); } else { if (nRemainder == 0) // m_sIndexLabel SetIndexLabel(text.GetText()); else // m_sDrawingLabel SetDrawingLabel(text.GetText()); } } if (!posNext) { posNext.m_nCookies = posRep.m_nCookies + 1; posNext.m_nTextPos = 0; } return posNext; } /* * * * * * * * * * 取 动 态 属 性 显 示 数 据 的 函 数 * * * * * * * * * */ void AecXDbSymbIndexPointer::GetTips(PtrList &lstInfo) const { lstInfo.Append(new ObjInfoUnit(_T("对象类型"), m_nFlag ? _T("剖切索引") : _T("指向索引"))); lstInfo.Append(new ObjInfoUnit(_T("被索引图编号"), m_sDrawingLabel)); lstInfo.Append(new ObjInfoUnit(_T("文字说明1"), m_sText1)); lstInfo.Append(new ObjInfoUnit(_T("文字说明2"), m_sText2)); lstInfo.Append(new ObjInfoUnit(_T("索引编号"), m_sIndexLabel)); TCString sTextStyle = GlobalFunc::GetSymbolName(m_idTextStyle); lstInfo.Append(new ObjInfoUnit(_T("文字样式"), sTextStyle)); } double AecXDbSymbIndexPointer::GetMinTextBaseLen(BOOL bAsPaperUnit) const // 最小文字长度 { if (!m_sText1 && !m_sText2) return 0.0; AecXDbText text; text.SetPScale(GetPScale()); text.setPropertiesFrom(this); text.SetHeight(m_nTextHeight); text.SetStyleId(m_idTextStyle); double nVal = 0.0; if (!!m_sText1) { text.SetText(m_sText1); ADSGePoint3d ptExt = text.GetExtents(); nVal = max(nVal, ptExt.x + 3.0 * GetPScale()); } if (!!m_sText2) { text.SetText(m_sText2); ADSGePoint3d ptExt = text.GetExtents(); nVal = max(nVal, ptExt.x + 3.0 * GetPScale()); } if (bAsPaperUnit) nVal /= GetPScale(); return nVal; } // 默认文字基线长 double AecXDbSymbIndexPointer::GetDefaultTextBaseLen(BOOL bAsPaperUnit) const { double nVal = 6.0; if (!bAsPaperUnit) nVal *= GetPScale(); return max(nVal, GetMinTextBaseLen(bAsPaperUnit)); } ADSGePoint3d AecXDbSymbIndexPointer::GetIndexCenter() const { ADSGePoint3d pt; ADSGePoint3d ptBase = GetTextBasePoint(); ads_polar(ptBase, m_nLayoutRotation + (m_nTextBaseLen < 0.0 ? PI : 0.0), GetRadius(FALSE), pt); return pt; } ADSGePoint3d AecXDbSymbIndexPointer::GetTextBasePoint() const { ADSGePoint3d pt; ads_polar(m_ptTurn, m_nLayoutRotation, GetTextBaseLen(FALSE), pt); return pt; } ADSGePoint3d AecXDbSymbIndexPointer::GetIndexCenter(long i) const { ADSGePoint3d pt; ADSGePoint3d ptBase = GetTextBasePoint(); ads_polar(ptBase, m_nLayoutRotation + (m_nTextBaseLen < 0.0 ? PI : 0.0), GetRadius(FALSE) * (i * 2 + 1), pt); return pt; } ADSGePoint3d AecXDbSymbIndexPointer::GetTextEndPoint() const { ADSGePoint3d pt; ADSGePoint3d ptBase = GetTextBasePoint(); ads_polar(ptBase, m_nLayoutRotation + (m_nTextBaseLen < 0.0 ? PI : 0.0), (GetAppendIndexNum() + 1) * 2 * m_nRadius * GetPScale(), pt); return pt; } // Properties void AecXDbSymbIndexPointer::SetText1(const TCHAR *pszText) { AssertWriteEnabled(); m_sText1 = pszText; } const TCHAR* AecXDbSymbIndexPointer::GetText1() const { return (const TCHAR *)m_sText1; } void AecXDbSymbIndexPointer::SetText2(const TCHAR *pszText) { AssertWriteEnabled(); m_sText2 = pszText; } const TCHAR* AecXDbSymbIndexPointer::GetText2() const { return (const TCHAR *)m_sText2; } void AecXDbSymbIndexPointer::SetDrawingLabel(const TCHAR *pszText) { AssertWriteEnabled(); m_sDrawingLabel = pszText; } const TCHAR* AecXDbSymbIndexPointer::GetDrawingLabel() const { return (const TCHAR *)m_sDrawingLabel; } void AecXDbSymbIndexPointer::SetIndexLabel(const TCHAR *pszText) { AssertWriteEnabled(); m_sIndexLabel = pszText; } const TCHAR* AecXDbSymbIndexPointer::GetIndexLabel() const { return (const TCHAR *)m_sIndexLabel; } void AecXDbSymbIndexPointer::SetStartPoint(ADSGePoint3d pt) { AssertWriteEnabled(); m_ptStart = pt; } ADSGePoint3d AecXDbSymbIndexPointer::GetStartPoint() const { return m_ptStart; } void AecXDbSymbIndexPointer::SetTurnPoint(ADSGePoint3d pt) { AssertWriteEnabled(); m_ptTurn = pt; } ADSGePoint3d AecXDbSymbIndexPointer::GetTurnPoint() const { return m_ptTurn; } void AecXDbSymbIndexPointer::SetTextBaseLen(double val, BOOL bAsPaperUnit) { AssertWriteEnabled(); m_nTextBaseLen = val; if (!bAsPaperUnit) m_nTextBaseLen /= GetPScale(); } double AecXDbSymbIndexPointer::GetTextBaseLen(BOOL bAsPaperUnit) const { double nVal = m_nTextBaseLen; if (!bAsPaperUnit) nVal *= GetPScale(); return nVal; } void AecXDbSymbIndexPointer::SetRadius(double val, BOOL bAsPaperUnit) { AssertWriteEnabled(); m_nRadius = val; if (!bAsPaperUnit) m_nRadius /= GetPScale(); } double AecXDbSymbIndexPointer::GetRadius(BOOL bAsPaperUnit) const { double val = m_nRadius; if (!bAsPaperUnit) val *= GetPScale(); return val; } void AecXDbSymbIndexPointer::SetSourceExtent(double val) { AssertWriteEnabled(); m_nSourceExtent = val; } double AecXDbSymbIndexPointer::GetSourceExtent() const { return m_nSourceExtent; } void AecXDbSymbIndexPointer::SetIndexPointer(BOOL bTrue) { AssertWriteEnabled(); m_nFlag = !bTrue; } BOOL AecXDbSymbIndexPointer::IsIndexPointer() const { return (m_nFlag == 0); } // sg add 081112,文字距离基线系数 double AecXDbSymbIndexPointer::GetText2BaseRatio(BOOL bAsPaperUnit, BOOL bRealDist) const { double dVal = m_dText2BaseRatio; // 系数 if (fabs(dVal + 1000) < 1.0E-5) dVal = GlobalFunc::DocGetText2BaseRatio(); // 使用全局变量GlobalFunc::DocGetText2BaseRatio的值 if (bRealDist) dVal *= m_nTextHeight; // 将“系数”转为“实际值” if (!bAsPaperUnit) // 处理出图比例 dVal *= GetPScale(); return dVal; } void AecXDbSymbIndexPointer::SetText2BaseRatio(double dVal, BOOL bAsPaperUnit) { AssertWriteEnabled(); m_dText2BaseRatio = dVal; // 系数 if (!bAsPaperUnit) m_dText2BaseRatio /= GetPScale(); } // sg add 090217,8.0的BETA2起使用 void AecXDbSymbIndexPointer::SetTextAlign(TSymbIPTextAlign align) { AssertWriteEnabled(); m_nTextAlign = align; } AecXDbSymbIndexPointer::TSymbIPTextAlign AecXDbSymbIndexPointer::GetTextAlign() const { return m_nTextAlign; } void AecXDbSymbIndexPointer::SetLineAngle(double dVal) { AssertWriteEnabled(); m_dLineAngle = dVal; } double AecXDbSymbIndexPointer::GetLineAngle() const { return m_dLineAngle; } void AecXDbSymbIndexPointer::SetPoly2D(const GePoly2D &poly) { AssertWriteEnabled(); m_polyCutLine = poly; } void AecXDbSymbIndexPointer::GetPoly2D(GePoly2D &poly) const { poly = m_polyCutLine; } double AecXDbSymbIndexPointer::GetTextBaseLen2() const { return m_dTextBaseLen2; } void AecXDbSymbIndexPointer::SetTextBaseLen2(double dVal) { AssertWriteEnabled(); m_dTextBaseLen2 = dVal; } const TCHAR* AecXDbSymbIndexPointer::GetText3() const { return m_szText3; } void AecXDbSymbIndexPointer::SetText3(const TCHAR *pszText) { AssertWriteEnabled(); m_szText3 = pszText; } // sg add 090410,支持文字控制大小的比例,间接设置AecXDbSymbDrawingIndex,动态数据 double AecXDbSymbIndexPointer::GetTextRatio(BOOL bDraw) const { assertReadEnabled(); double dVal = 0; const EntityFields &fd = GetFields(); fd.GFD(_T("文字字高系数"), dVal); if (bDraw) { if (fabs(dVal) < 1.0E-3) { dVal = GlobalFunc::DocGetDITextRatio(); } } return dVal; } void AecXDbSymbIndexPointer::SetTextRatio(double dVal) { AssertWriteEnabled(); EntityFields &fd = Fields(); fd.SFD(_T("文字字高系数"), dVal); } // sg add 090723,支持使用新、旧圆圈文字样式,动态数据 void AecXDbSymbIndexPointer::SetOldStyle(int nOldStyle) { AssertWriteEnabled(); Adesk::UInt8 nValue = nOldStyle; EntityFields &fd = Fields(); fd.SFD(_T("旧圆圈文字样式"), nValue); } int AecXDbSymbIndexPointer::GetOldStyle() const { assertReadEnabled(); Adesk::UInt8 nVal = 2; const EntityFields &fd = GetFields(); fd.GFD(_T("旧圆圈文字样式"), nVal); return nVal; } BOOL AecXDbSymbIndexPointer::IsOldStyle() const // 是否保留旧的样式 { int nVal = GetOldStyle(); if (nVal == 2) { nVal = GlobalFunc::DocGetDrawingIndexStyle(); } return nVal; } // sg add 110211,支持统一标高 bool AecXDbSymbIndexPointer::UnifyElevation(double dElevation) { AssertWriteEnabled(); m_ptStart.z = dElevation; m_ptTurn.z = dElevation; int nLength = m_polyCutLine.Length(); if (nLength > 0) { m_polyCutLine.SetElevation(0); } if (HasAddedPoint()) { ADSGePoint3d ptTmp; GetAddedPoint(ptTmp); SetAddedPoint(ptTmp); } return true; } // 以扩展数据的形式添加新的属性,保持与8.0系列的版本兼容 #define S_DIMTEXT _T("标注文字样式ID") #define S_ADDED_POINT _T("引出点") #define S_DIMPOS _T("标注位置点") #define S_UPDIMWID _T("上部标注宽度") #define S_DOWNDIMWID _T("下部标注宽度") ////////////////////////////////////////////////////////////////////////// // 8.5新增扩展数据的读写以及操作函数 // 标注文字样式的读写 void AecXDbSymbIndexPointer::SetDimTextStyle(const AcDbObjectId &id) { AssertWriteEnabled(); AcDbHardPointerId idHard = id; Fields().SFD(S_DIMTEXT, idHard); } AcDbObjectId AecXDbSymbIndexPointer::GetDimTextStyle() const { assertReadEnabled(); AcDbHardPointerId idHard; if (!GetFields().GFD(S_DIMTEXT, idHard)) { idHard = m_idTextStyle; } return idHard; } void AecXDbSymbIndexPointer::SetAddedPoint(const ADSGePoint3d &ptAdded) { AssertWriteEnabled(); Fields().SFD(S_ADDED_POINT, ptAdded.AsAcGePoint3d()); } bool AecXDbSymbIndexPointer::GetAddedPoint(ADSGePoint3d &ptAdded) const { assertReadEnabled(); AcGePoint3d ptAddDump; bool bret = GetFields().GFD(S_ADDED_POINT, ptAddDump); if (bret) ptAdded = ptAddDump; return bret; } void AecXDbSymbIndexPointer::ClearAddedPoint() { AssertWriteEnabled(); EntityFields &fields = Fields(); long index = fields.Find(S_ADDED_POINT); if (index >= 0) fields.Del(index); } bool AecXDbSymbIndexPointer::HasAddedPoint() const { assertReadEnabled(); AcGePoint3d ptAddDump; return GetFields().GFD(S_ADDED_POINT, ptAddDump); } int AecXDbSymbIndexPointer::GetCutLineNum() const { int i = (int)m_polyCutLine.Length(); return i; } // 重新设置动态数据中的剖切线 void AecXDbSymbIndexPointer::SetCutLine(AryXLine &arCutLines) { AssertWriteEnabled(); ClearCutLine(); // 需要先清空原先的 SortCutLine(GetFirstLine(), arCutLines); // 排序 EntityFields &fields = Fields(); for (int i = 0; i < (int)arCutLines.GetSize(); i++) { // 保存的值是一个起点和一个长度 double dLen = arCutLines[i].GetLength(); m_polyCutLine.AppendBugle(dLen / GetPScale()); m_polyCutLine.Append(new ADSGePoint3d(arCutLines[i].GetStartPoint())); } } // 获得所有的剖切线 int AecXDbSymbIndexPointer::GetCutLineAll(AryXLine &arCutLines) const { assertReadEnabled(); GeLine lineLeader = GetFirstLine(); Vector3D vecLine = lineLeader.Direction3d(); double dScale = GetPScale(); GeLine ll(lineLeader.GetStartPoint(), lineLeader.GetStartPoint() + ScaleVec(fabs(m_nSourceExtent) * dScale, vecLine)); arCutLines.Add(ll); int nAppendCutLineNum = GetCutLineNum(); for (int i = 0; i < nAppendCutLineNum; i++) { AcGePoint3d pt1, pt2; pt1 = (m_polyCutLine.GetAt(i)).AsAcGePoint3d(); double dLen = m_polyCutLine.GetBulge(i); GeLine dd(ADSGePoint3d(pt1), ADSGePoint3d(pt1) + ScaleVec(fabs(dLen) * GetPScale(), vecLine)); arCutLines.Add(dd); } return (int)arCutLines.GetSize(); } void AecXDbSymbIndexPointer::ClearCutLine() { AssertWriteEnabled(); while (GetCutLineNum() > 0) // 需要先清空原先的 { m_polyCutLine.RemoveNode(0); } } void AecXDbSymbIndexPointer::SetDimPos(int nFlag) { AssertWriteEnabled(); Fields().SFD(S_DIMPOS, (Adesk::Int8)nFlag); } int AecXDbSymbIndexPointer::GetDimPos() const { assertReadEnabled(); Adesk::Int8 iFlag = 0; GetFields().GFD(S_DIMPOS, iFlag); return (int)iFlag; } void AecXDbSymbIndexPointer::SetTextWidthUp(double d, BOOL bAsPaperUnit) { AssertWriteEnabled(); if (!bAsPaperUnit) d /= GetPScale(); Fields().SFD(S_UPDIMWID, d); } double AecXDbSymbIndexPointer::GetTextWidthUp(BOOL bAsPaperUnit) const { assertReadEnabled(); double d = 0.0; GetFields().GFD(S_UPDIMWID, d); return bAsPaperUnit ? d : d * GetPScale(); } void AecXDbSymbIndexPointer::SetTextWidthDown(double d, BOOL bAsPaperUnit) { AssertWriteEnabled(); if (!bAsPaperUnit) d /= GetPScale(); Fields().SFD(S_DOWNDIMWID, d); } double AecXDbSymbIndexPointer::GetTextWidthDown(BOOL bAsPaperUnit) const { assertReadEnabled(); double d = 0.0; GetFields().GFD(S_DOWNDIMWID, d); return bAsPaperUnit ? d : d * GetPScale(); } double AecXDbSymbIndexPointer::GetTextRelWidth(bool bUp, BOOL bAsPaperUnit) const { if (IsSingleLineText(bUp)) { CString strText = bUp ? (LPCTSTR)m_sText1 : (LPCTSTR)m_sText2; double dWid = CalcTextLen(strText, GetDimTextStyle(), GetTextHeight(), 0); // 计算 return bAsPaperUnit ? dWid : dWid / GetPScale(); } else { return (bUp ? GetTextWidthUp(bAsPaperUnit) : GetTextWidthDown(bAsPaperUnit)); } } bool AecXDbSymbIndexPointer::IsSingleLineText(bool bUp) const { return fabs(bUp ? GetTextWidthUp() : GetTextWidthDown()) < 1e-6; } bool AecXDbSymbIndexPointer::HasExtendLine() const { return (fabs(m_dTextBaseLen2) > 1e-6); } // 见索引标注夹点示意图 ADSGePoint3d AecXDbSymbIndexPointer::GetG5Point() const { ADSGePoint3d pt; ADSGePoint3d ptBase = GetTextBasePoint(); ads_polar(ptBase, m_nLayoutRotation + (m_nTextBaseLen < 0.0 ? PI : 0.0), (GetAppendIndexNum() + 1) * 2 * m_nRadius * GetPScale() + fabs(m_dTextBaseLen2 * GetPScale()), pt); return pt; } ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// // 属性读取辅助函数 // 设置延长线长度 void AecXDbSymbIndexPointer::SetExtendLineLen(double dVal, bool bAsPaperUnit) { AssertWriteEnabled(); m_dTextBaseLen2 = dVal; if (!bAsPaperUnit) m_dTextBaseLen2 /= GetPScale(); } double AecXDbSymbIndexPointer::GetExtendLineLen(bool bAsPaperUnit) { return bAsPaperUnit ? m_dTextBaseLen2 : m_dTextBaseLen2 * GetPScale(); } Vector3D AecXDbSymbIndexPointer::GetTextLineUnitVec() const { Vector3D v(GetTextBasePoint() - GetTurnPoint()); return UnitVec(v); } Vector3D AecXDbSymbIndexPointer::GetFirstLineUnitVec() const { GeLine firstLine = GetFirstLine(); Vector3D v(firstLine.Direction3d()); return UnitVec(v); } // 获取第一段引线() GeLine AecXDbSymbIndexPointer::GetFirstLine() const { ADSGePoint3d ptAdded; if (GetAddedPoint(ptAdded)) return GeLine(GetStartPoint(), ptAdded); else return GeLine(GetStartPoint(), GetTurnPoint()); } GeLine AecXDbSymbIndexPointer::GetTextLine() const { GeLine textLine; if (GetDimPos() == 0) { // 文字标注在引出线段2上 textLine.SetPoints(m_ptTurn, GetTextBasePoint()); } else { // 文字标注在延长线上 textLine.SetPoints(GetTextEndPoint(), GetG5Point()); } return textLine; } Vector3D AecXDbSymbIndexPointer::UnitVec(Vector3D &vec) { if (vec == Vector3D(0.0, 0.0, 0.0)) return Vector3D(1.0, 0.0, 0.0); double dLen = vec.Length(); vec.Scale(1.0 / dLen); return vec; } Vector3D AecXDbSymbIndexPointer::CutLineOffset() const { double nOffset = (m_nSourceExtent < 0.0 ? -1.5 : 1.5) * GetPScale(); Vector3D vecFirstLine = GetFirstLine().Direction3d(); Vector3D vecPlump(vecFirstLine.y, -vecFirstLine.x, vecFirstLine.z); vecPlump.Scale(nOffset); return vecPlump; } // 获取默认值 double AecXDbSymbIndexPointer::GetDefaultExtendLineLen() { return g_DimOption::instance().g_dIndexPointerBaseLen; } double AecXDbSymbIndexPointer::GetDefaultCutLineLen() { return g_DimOption::instance().g_dSectionBaseLen; } ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// // 夹点操作函数 inline void AecXDbSymbIndexPointer::AddGripPoint(AcGePoint3dArray *pArGripPoints, const ADSGePoint3d &gripPoint) const { if (pArGripPoints != NULL) pArGripPoints->append(gripPoint.AsAcGePoint3d()); } inline void AecXDbSymbIndexPointer::AddGripTip(CStringArray *pArTips, LPCTSTR szTips) const { if (pArTips != NULL) pArTips->Add(szTips); } inline void AecXDbSymbIndexPointer::AddSGripType(AecXDbSymbIndexPointer::SGripAdditional *pSga, int nType, int nIndex) const { if (pSga != NULL) { pSga->arGripType.Add(nType); SGrip sg; sg.bCheck = false; sg.nIndeces = nIndex; sg.nType = nType; sg.bProcessed = false; pSga->arGripStruct.Add(sg); } } void AecXDbSymbIndexPointer::KeepCutLineAssistLine(const GeLine &lineAssist, ADSGePoint3d &ptCutStart, ADSGePoint3d &ptCutEnd, int nKeepType) { Vector3D vecLine = GeLine(ptCutStart, ptCutEnd).Direction3d(); using namespace GlobalFunc; if ((vecLine & lineAssist.Direction3d()) < 0.0) { ADSGePoint3d ptTemp = ptCutEnd; ptCutEnd = ptCutStart; ptCutStart = ptTemp; } { AcGePoint3d ptEnd = ptCutEnd.AsAcGePoint3d(); AcGeLineSeg3d geFirstLine(lineAssist.StartPoint().AsAcGePoint3d(), lineAssist.EndPoint().AsAcGePoint3d()); AcGePoint3d ptClose = geFirstLine.closestPointTo(ptCutEnd); if (ADSGePoint3d(ptClose) == lineAssist.EndPoint()) { // 移动这个剖切线 if (nKeepType == 0) { // 保持这个剖切线的长度 Vector3D vecOut = lineAssist.EndPoint() - ptCutEnd; ptCutStart = (ptCutStart + vecOut); ptCutEnd = (ptCutEnd + vecOut); } else { ptCutEnd = lineAssist.EndPoint(); } } } } // 夹点信息构造,把每个夹点的序号indece跟枚举类型做动态绑定,在拉伸,夹点操作,以及夹点提示信息的设置上变的简单 void AecXDbSymbIndexPointer::BuildGrip(CStringArray *pArTips, AcGePoint3dArray *pArGripPoints, SGripAdditional *pSga, bool bGrip) const { // 用来记录剖切点的编号 (起-终) int iIndex = 0; ADSGePoint3d ptTextBase = GetTextBasePoint(); // 原文字线终点 AddGripPoint(pArGripPoints, ptTextBase); AddGripTip(pArTips, _T("拉伸文字基线")); AddSGripType(pSga, eG3, iIndex++); // 转折点,原文字线起点 AddGripPoint(pArGripPoints, m_ptTurn); AddGripTip(pArTips, GetCtrlToggle() ? _T("移动引线位置(Ctrl-不固定标号)") : _T("移动引线位置(Ctrl-固定标号)")); AddSGripType(pSga, eG2, iIndex++); // 索引起点 AddGripPoint(pArGripPoints, m_ptStart); AddGripTip(pArTips, _T("移动标注点")); AddSGripType(pSga, eG1, iIndex++); // 改变索引范围 if ((m_nFlag == 0) && (m_nSourceExtent > g_Option::instance()._DIST_SNAP)) { if (bGrip) { // 拉伸模式下,这个点不用选择 if (pArGripPoints != NULL) { GeCircle cir(m_ptStart, m_nSourceExtent / 2.0); ADSGePoint3d ptTemp[2]; if (!GeLine(m_ptStart, m_ptTurn, LS_FINITE).Intersection(&cir, ptTemp[0], ptTemp[1])) ptTemp[0] = m_ptStart; AddGripPoint(pArGripPoints, ptTemp[0]); } AddGripTip(pArTips, _T("移动目标范围")); AddSGripType(pSga, eGArea, iIndex++); } } // 添加剖切点: // 剖切点在添加,放在保持连续,和顺序 // 剖切点的编号中间不能夹杂其他夹点,剖切点应该保持 起点-终点的顺序 if (m_nFlag == 1) { AryXLine arXLine; GetCutLineAll(arXLine); Vector3D vecPlump = CutLineOffset(); for (int i = 0; i < (int)arXLine.GetSize(); i++) { if (i == 0) { if (pSga != NULL) pSga->nCutStart = iIndex; AddGripPoint(pArGripPoints, arXLine[i].StartPoint() + vecPlump); AddGripTip(pArTips, _T("改变剖视方向")); AddSGripType(pSga, eGCutFir, iIndex++); AddGripPoint(pArGripPoints, arXLine[i].EndPoint() + vecPlump); AddGripTip(pArTips, _T("改变剖切长度")); AddSGripType(pSga, eGCutEnd, iIndex++); continue; } AddGripPoint(pArGripPoints, arXLine[i].StartPoint() + vecPlump); AddGripTip(pArTips, !GetCtrlToggle() ? _T("改变剖切位置(Ctrl-增加剖切线)") : _T("增加剖切线(Ctrl-改变剖切位置)")); AddSGripType(pSga, eGCutStart, iIndex++); AddGripPoint(pArGripPoints, arXLine[i].EndPoint() + vecPlump); AddGripTip(pArTips, _T("改变剖切长度")); AddSGripType(pSga, eGCutEnd, iIndex++); } if (pSga != NULL) pSga->nCutEnd = iIndex; } // end add 剖切点 // 新增加的夹点类型: // 剖切线第一段引线的终点(gAdd) if (!IsIndexPointer()) { ADSGePoint3d ptAdd; if (GetAddedPoint(ptAdd)) { AddGripPoint(pArGripPoints, ptAdd); AddGripTip(pArTips, _T("移动引线位置")); AddSGripType(pSga, eGAdd, iIndex++); } } { // 改变索引个数夹点 // 在没有延长线的时候,需要提示可以切换绘制延长线,如果已经有了延长线,则不提示绘制延长线。 LPCTSTR szToggle = _T("改变索引个数(Ctrl-绘制延长线)"); // LPCTSTR szNotToggle = _T("绘制延长线(Ctrl-改变索引个数)"); LPCTSTR szChangeOnly = _T("改变索引个数"); CString sTips; bool bStretchUse = true; if (HasExtendLine()) { sTips = szChangeOnly; } else { sTips = !GetCtrlToggle() ? szToggle : szNotToggle; bStretchUse = false; } if ((bGrip) || (!bGrip && bStretchUse)) {// 夹点模式下,或者拉伸模式下并且已经存在延长线 AddGripPoint(pArGripPoints, GetTextEndPoint().AsAcGePoint3d()); AddGripTip(pArTips, sTips); AddSGripType(pSga, eG4, iIndex++); } } // eG5 if (HasExtendLine()) { AddGripPoint(pArGripPoints, GetG5Point()); AddGripTip(pArTips, _T("改变延长线长度")); AddSGripType(pSga, eG5, iIndex++); } // 修改文字页宽 if (bGrip) { ADSGePoint3d ptMin, ptMax; if (NeedDrawUpText()) { GetUpTextExtent(ptMin, ptMax); if (pArGripPoints != NULL) { AddGripPoint(pArGripPoints, ptMax); } AddGripTip(pArTips, _T("修改文字1页宽")); AddSGripType(pSga, eGTextWid1, iIndex++); if (pSga != NULL) { pSga->ptUpTextMin = ptMin; pSga->ptUpTextMax = ptMax; } } if (NeedDrawDownText()) { GetDownTextExtent(ptMin, ptMax); AddGripPoint(pArGripPoints, ptMax); AddGripTip(pArTips, _T("修改文字2页宽")); AddSGripType(pSga, eGTextWid2, iIndex++); if (pSga != NULL) { pSga->ptDownTextMin = ptMin; pSga->ptDownTextMax = ptMax; } } } } // 夹点移动操作,或者拉伸操作 void AecXDbSymbIndexPointer::MoveGripOrStretchPoints(const SGripAdditional &sgaFull, const AcGeVector3d& offset, bool bGrip, int nCutSplit) { // sumMove***的调用机制约束,每次在调用该函数的时候,该类中的数据都是初始数据。 // 构造夹点类型信息数组:每次都会重新读取夹点的数据 const SGripAdditional &sga = sgaFull; // 原始剖切线, 新添加的剖切线 AryXLine arCutLineOri, arCutLineAdded; GeLine firstLineOri; // 原始第一段引线,用来调整剖切线 // AryXVector arCutVec; // 剖切线起点和终点的偏移 // 0:起点和终点都没有动,1,起点在动,2,终点动,3起点和终点都动 enum { NO_MOVE, START_MOVE, END_MOVE, ALL_MOVE }; AryInt arCutMove; GetCutLineAll(arCutLineOri); firstLineOri = GetFirstLine(); if (!IsIndexPointer()) { arCutMove.SetSize(arCutLineOri.GetSize()); memset(arCutMove.GetData(), 0, arCutMove.GetSize() * sizeof(int)); } #define EXTENT_DRAG (sga.FindCheck(eG3) && sga.FindCheck(eG4) && HasExtendLine() && !sga.FindCheck(eG5)) using namespace GlobalFunc; ADSGePoint3d vtOffset(offset[0], offset[1]); for (int i = 0; i < (int)sga.arGripStruct.GetSize(); i++) { if (!sga.arGripStruct[i].bCheck) continue; switch (sga.arGripStruct[i].nType) { case eG1: // 起点 { m_ptStart += vtOffset; break; } case eGAdd: // 三段引线的附加夹点 { ADSGePoint3d ptAdd; GetAddedPoint(ptAdd); ptAdd += vtOffset; SetAddedPoint(ptAdd); break; } case eG2: // 移动转折点, m_ptTurn; { ADSGePoint3d ptTextBase = GetTextBasePoint(); bool bCheckMany = sga.FindCheck(eG3) || sga.FindCheck(eG4) || sga.FindCheck(eG5); if (EXTENT_DRAG) { // 引出线拉长模式 Vector3D vecText = GetTextLineUnitVec(); ADSGePoint3d ptG4 = GetTextEndPoint(); ADSGePoint3d ptG5 = GetG5Point(); vecText.Scale(vtOffset & vecText); m_ptTurn += vecText; ptG4 += vecText; SetExtendLineLen(ptG4.Distance2d(ptG5) / GetPScale()); } // else if (!bCheckMany && GetCtrlToggle() && bGrip) // 固定 else if (!bCheckMany && GetCtrlToggle()) // 固定 { // sg modify 090324,m_ptTurn点沿布局转角方向移动 Vector3D vecOffset = vtOffset, vtBase(cos(m_nLayoutRotation), sin(m_nLayoutRotation)); double dOffset = (vecOffset & vtBase); ads_polar(m_ptTurn, m_nLayoutRotation, dOffset, m_ptTurn); double nDist = ptTextBase.Distance2d(m_ptTurn); double dDirRot = ads_angle(ptTextBase, m_ptTurn); dDirRot = Wcs2Layout(dDirRot); if (dDirRotPI * 1.5) // 符号在m_ptTurn点左侧 nDist *= -1; SetTextBaseLen(nDist, FALSE); } else // 不固定 m_ptTurn += vtOffset; break; } case eG3: // 拉伸文字基线 { if (!sga.FindCheck(eG2)) { Vector3D vt(1.0, 0.0); vt.Rotate(GetLayoutRotation()); // add by whl on 050725 double nVal = (vtOffset & vt); m_nTextBaseLen += nVal / GetPScale(); } break; } case eG4: { if (sga.FindCheck(eG2) || sga.FindCheck(eG3) || !bGrip) break; if (HasExtendLine() || !GetCtrlToggle()) { // 添加索引个数 ADSGePoint3d ptNew = GetTextEndPoint() + offset; double dTmpNum = ptNew.Distance2d(GetTextBasePoint()) / (m_nRadius * 2 * GetPScale()); long num = (long)dTmpNum; SetAppendIndexNum(num); } else { // 添加延长线 double dVal = vtOffset & (GetTextLineUnitVec()); SetExtendLineLen(dVal / GetPScale()); } break; } case eG5: // 拉伸延长线 { if (sga.FindCheck(eG2) || sga.FindCheck(eG3) || sga.FindCheck(eG4)) break; double dVal = vtOffset & (GetTextLineUnitVec()); SetExtendLineLen(fabs(m_dTextBaseLen2) + dVal / GetPScale()); break; } case eGCutFir: // 第一个剖切线的起点,改变剖切线的方向,不改变剖切点。对应的arCutLine中的数据也不会被修改 { if (!bGrip) break; GeLine ln = firstLineOri; ASSERT(!arCutLineOri.IsEmpty()); ADSGePoint3d ptVert = arCutLineOri[0].StartPoint(); ptVert += vtOffset; int nSide = ln.OnWhichSide(ptVert); if (nSide == OFFSET_LEFT) m_nSourceExtent = -fabs(m_nSourceExtent); else m_nSourceExtent = fabs(m_nSourceExtent); ASSERT(!arCutMove.IsEmpty()); if (sga.FindCutCheckBoth(sga.arGripStruct[i].nIndeces)) arCutMove[0] = ALL_MOVE; else arCutMove[0] = START_MOVE; break; } case eGCutStart: // 剖切线起点 { Vector3D vecFirstLine = firstLineOri.Direction3d(); Vector3D vecCut = ScaleVec((vecFirstLine & vtOffset), vecFirstLine); int nIndex = sga.GetCutLineIndex(sga.arGripStruct[i].nIndeces); // 剖切线在剖切数组中的编号 const GeLine &cutLine = arCutLineOri[nIndex]; if (!GetCtrlToggle() || !bGrip) { // 改变位置,默认操作,移动剖切线 // 什么也不做。 if (sga.FindCutCheckBoth(sga.arGripStruct[i].nIndeces)) arCutMove[nIndex] = ALL_MOVE; else arCutMove[nIndex] = START_MOVE; } else { // 复制CutLine,Ctrl切换; GeLine cutLineNew = cutLine; cutLineNew.m_startPoint += vecCut; cutLineNew.m_endPoint += vecCut; arCutLineAdded.Add(cutLineNew); } break; } case eGCutEnd: // 剖切线终点 { // 如果起点被选中,则这段剖切线执行移动操作。该点不需要再移动 if (sga.FindCutCheckBoth(sga.arGripStruct[i].nIndeces)) break; Vector3D vecFirstLineUnit = firstLineOri.Direction3d(); // Vector3D vecCut = ScaleVec((vecFirstLineUnit&vtOffset), vecFirstLineUnit); int nIndex = sga.GetCutLineIndex(sga.arGripStruct[i].nIndeces); if (sga.FindCutCheckBoth(sga.arGripStruct[i].nIndeces)) arCutMove[nIndex] = ALL_MOVE; else arCutMove[nIndex] = END_MOVE; break; } case eGArea: // 移动目标范围,指向索引的圆圈范围 { // 拉伸模式下不改变索引范围的大小 if (!bGrip) break; Vector3D vecFirstLineUnit = firstLineOri.Direction3d(); ADSGePoint3d ptVert = (m_ptStart + ScaleVec(m_nSourceExtent * 0.5, vecFirstLineUnit)); ptVert += vtOffset; if (m_nFlag == 0) // 移动目标范围 m_nSourceExtent = ptVert.Distance2d(m_ptStart) * 2.0; break; } case eGTextWid1: // 文字夹点 { Vector3D vecTextLine = GetTextLineUnitVec(); // 文字线的单位向量 Vector3D vecText = ScaleVec((vecTextLine & vtOffset), vecTextLine); ADSGePoint3d ptMax = (sga.ptUpTextMax + vecText); AcGeLine3d textLine(AcGePoint3d(0, 0, 0), vecTextLine.AsAcGePoint3d()); AcGePoint3d gePtMax = textLine.closestPointTo(ptMax.AsAcGePoint3d()); AcGePoint3d gePtMin = textLine.closestPointTo(sga.ptUpTextMin.AsAcGePoint3d()); double dLen = gePtMax.distanceTo(gePtMin); if (fabs(dLen) > 1e-6) SetTextWidthUp(dLen / GetPScale()); break; } case eGTextWid2: { Vector3D vecTextLine = GetTextLineUnitVec(); // 文字线的单位向量 Vector3D vecText = ScaleVec((vecTextLine & vtOffset), vecTextLine); ADSGePoint3d ptMax = (sga.ptDownTextMax + vecText); AcGeLine3d textLine(AcGePoint3d(0, 0, 0), vecTextLine.AsAcGePoint3d()); AcGePoint3d gePtMax = textLine.closestPointTo(ptMax.AsAcGePoint3d()); AcGePoint3d gePtMin = textLine.closestPointTo(sga.ptDownTextMin.AsAcGePoint3d()); double dLen = gePtMax.distanceTo(gePtMin); if (fabs(dLen) > 1e-6) SetTextWidthDown(dLen / GetPScale()); break; } } // end Switch (type..) } // end for (;;) // 调整剖切线: if (!IsIndexPointer()) { // 起点靠近和终点靠近的分界 [0, nNearStart] + (nNearStart, cutEnd] int nNearStart = nCutSplit; GeLine firstLine = GetFirstLine(); // 移动后的第一段引线,所有的cutLine要往这段线上靠。 AryXLine arCutLine; Vector3D vecFirstOri = firstLineOri.Direction3d(); // 原始引线切向量 Vector3D vecFirst = firstLine.Direction3d(); Vector3D vecOffset = ScaleVec((vtOffset & vecFirstOri), vecFirstOri);// 引线方向偏移向量 int i = 0; // 剖切线引线是否在移动 bool bFirstLineMoved = sga.FindCheck(eG1) || sga.FindCheck(HasAddedPoint() ? eGAdd : eG2); arCutLine.SetSize(arCutLineOri.GetSize()); //1、先重新计算所有的剖切线坐标 for (i = 0; i < (int)arCutLineOri.GetSize(); i++) { ADSGePoint3d ptStart = arCutLineOri[i].StartPoint(); ADSGePoint3d ptEnd = arCutLineOri[i].EndPoint(); // 改变方式: enum { POS_CHANGE = 0, LEN_CHANGE, NO_CHANGE }; int nChange = NO_CHANGE; if (i == 0) { if (arCutMove[i] == END_MOVE) nChange = LEN_CHANGE; else nChange = NO_CHANGE; } else { if ((arCutMove[i] == START_MOVE || arCutMove[i] == ALL_MOVE) && !bFirstLineMoved) nChange = POS_CHANGE; else if (arCutMove[i] == END_MOVE) nChange = LEN_CHANGE; else nChange = NO_CHANGE; } // 得到一个相对位置: if (nChange == POS_CHANGE) { ptStart += vecOffset; ptEnd += vecOffset; ADSGePoint3d ptKeepOri, ptKeep; if (i <= nNearStart) { // 保持相对起点位置不变 ptKeepOri = firstLineOri.StartPoint(); ptKeep = firstLine.StartPoint(); } else { // 相对终点保持距离不变 ptKeepOri = firstLineOri.EndPoint(); ptKeep = firstLine.EndPoint(); } double dDisS = ((ptStart - ptKeepOri) & vecFirstOri); double dDisE = ((ptEnd - ptKeepOri) & vecFirstOri); ptStart = ptKeep + ScaleVec(dDisS, vecFirst); ptEnd = ptKeep + ScaleVec(dDisE, vecFirst); KeepCutLineAssistLine(firstLine, ptStart, ptEnd, 0); } else if (nChange == LEN_CHANGE) { // 长度改变,位置不变,保持剖线起点到引线起点的位置不变 ptEnd += vecOffset; // 相对于原始线 ADSGePoint3d ptKeepOri, ptKeep; ptKeepOri = firstLineOri.StartPoint(); ptKeep = firstLine.StartPoint(); double dDisS = ((ptStart - ptKeepOri) & vecFirstOri); double dDisE = ((ptEnd - ptKeepOri) & vecFirstOri); ptStart = ptKeep + ScaleVec(dDisS, vecFirst); ptEnd = ptKeep + ScaleVec(dDisE, vecFirst); KeepCutLineAssistLine(firstLine, ptStart, ptEnd, 1); } else {// 相对于原始线的距离和长度都不变 ADSGePoint3d ptKeepOri, ptKeep; if (i <= nNearStart) { // 保持相对起点位置不变 ptKeepOri = firstLineOri.StartPoint(); ptKeep = firstLine.StartPoint(); } else { // 相对终点保持距离不变 ptKeepOri = firstLineOri.EndPoint(); ptKeep = firstLine.EndPoint(); } double dDisS = ((ptStart - ptKeepOri) & vecFirstOri); double dDisE = ((ptEnd - ptKeepOri) & vecFirstOri); ptStart = ptKeep + ScaleVec(dDisS, vecFirst); ptEnd = ptKeep + ScaleVec(dDisE, vecFirst); // KeepCutLineAssistLine(firstLine, ptStart, ptEnd, 1); } arCutLine[i].SetPoints(ptStart, ptEnd); } // 2、把新加的引出线添加进来 for (i = 0; i < (int)arCutLineAdded.GetSize(); i++) { ADSGePoint3d ptStart = arCutLineAdded[i].StartPoint(); ADSGePoint3d ptEnd = arCutLineAdded[i].EndPoint(); double dDisS = (ptStart - firstLineOri.EndPoint()) & vecFirstOri; double dDisE = (ptEnd - firstLineOri.EndPoint()) & vecFirstOri; ptStart = firstLine.EndPoint() + ScaleVec(dDisS, vecFirst); ptEnd = firstLine.EndPoint() + ScaleVec(dDisE, vecFirst); // 转到了新的引线上 KeepCutLineAssistLine(firstLine, ptStart, ptEnd, 0); GeLine l(ptStart, ptEnd); arCutLine.Add(l); } //3、按照起点对这些剖切线排序,并且重新整理按照firstLine的方向调整起点和终点 SortCutLine(firstLine, arCutLine); // 4、超出引线终点的剖切线,按照按照剖切长度平移过来。 //for (i = 0; i < (int)arCutLine.GetSize(); i++) //{ // AcGePoint3d ptStart = arCutLine[i].StartPoint().AsAcGePoint3d(); // AcGeLineSeg3d geFirstLine(firstLine.StartPoint().AsAcGePoint3d(), firstLine.EndPoint().AsAcGePoint3d()); // AcGePoint3d ptClose = geFirstLine.closestPointTo(ptStart); // if (ADSGePoint3d(ptClose) == firstLine.EndPoint()) // { // 移动这个剖切线 // ADSGePoint3d vecOut = firstLine.EndPoint() - arCutLine[i].StartPoint(); // arCutLine[i].SetPoints(arCutLine[i].StartPoint() + vecOut, arCutLine[i].EndPoint() + vecOut); // } //} //5、超出第一段剖切线起点的剖切线,应该取其中长度最大的一个保留为第一个剖切线,其他的删除 double dMaxLen = -1.0; for (i = 0; i < (int)arCutLine.GetSize(); i++) { bool bRem = false; // 剖切线起点-引线起点 得到向量 和引线方向向量叉积, < 0的为超出起点的剖切线 double dDot = ((arCutLine[i].StartPoint() - firstLine.StartPoint()) & vecFirst); if (dDot < 1e-6) { double dLen = arCutLine[i].GetLength(); if (dLen > dMaxLen) { dMaxLen = dLen; } arCutLine.RemoveAt(i--); bRem = true; } if (!bRem) { double dDot1 = ((arCutLine[i].StartPoint() - firstLine.EndPoint()) & vecFirst); if (dDot1 > 1e-6) { arCutLine.RemoveAt(i--); } else { double dDot2 = ((arCutLine[i].EndPoint() - firstLine.EndPoint()) & vecFirst); if (dDot2 > 1e-6) { arCutLine[i].EndPoint() = firstLine.EndPoint(); } } } } if (dMaxLen > 0.0) { bool bNegCut = m_nSourceExtent < 0.0 ? true : false; m_nSourceExtent = dMaxLen / GetPScale(); // 第一段引出线必须存在。 if (bNegCut) m_nSourceExtent = -m_nSourceExtent; } //6、起点重合的剖切线保留长度较大的 for (i = 1; i < (int)arCutLine.GetSize(); i++) { if (arCutLine[i].StartPoint() == arCutLine[i - 1].StartPoint()) { if (arCutLine[i].GetLength() > arCutLine[i - 1].GetLength()) { arCutLine.RemoveAt(--i); } else { arCutLine.RemoveAt(i--); } } } //7、距离较短的删除 for (i = 0; i < (int)arCutLine.GetSize(); i++) { if (arCutLine[i].GetLength() < 0.01) arCutLine.RemoveAt(i--); } // 8、写入剖切点,如果arCutLine长度为0,则会清空原先的cutLine。因此写入是必须的。 SetCutLine(arCutLine); } } ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// // 文字标注绘制相关函数 bool AecXDbSymbIndexPointer::NeedDrawUpText() const { return (!!m_sText1 || g_Option::instance().g_bExplodeSubText); } bool AecXDbSymbIndexPointer::NeedDrawDownText() const { return (!!m_sText2 || g_Option::instance().g_bExplodeSubText); } void AecXDbSymbIndexPointer::GetTextAttribute(const GeLine &textLine, ADSGePoint3d &ptAlignUp, ADSGePoint3d &ptAlignDown) const { ADSGePoint3d ptTextStart = textLine.StartPoint(); ADSGePoint3d ptTextEnd = textLine.EndPoint(); double nDirRot = ads_angle(ptTextEnd, ptTextStart); nDirRot = Wcs2Layout(nDirRot); // double nText2Base = DocGetText2Base() * GetPScale(); // sg modify 081112,距基线系数 double nText2Base = GetText2BaseRatio(FALSE, TRUE); ADSGePoint3d ptUpMin, ptUpMax, ptDownMin, ptDownMax; double dUpMis = 0.0, dDownMis = 0.0; MTextExtents((LPCTSTR)m_sText1, GetDimTextStyle(), GetTextHeight(), GetTextWidthUp(), ptUpMin, ptUpMax, &dUpMis); MTextExtents((LPCTSTR)m_sText2, GetDimTextStyle(), GetTextHeight(), GetTextWidthDown(), ptDownMin, ptDownMax, &dDownMis); double dUpLen = ptUpMax.x - ptUpMin.x, dUpHei = ptUpMax.y - ptUpMin.y; double dDownLen = ptDownMax.x - ptDownMin.x, dDownHei = ptDownMax.y - ptDownMin.y; // 下面的代码逻辑很简单 // 分别考虑了文字线向右,和向左两种方向下,文字排列在文字线的起点,中点,终点,共六种情况。 // 分别计算了多行文字的位置点(SetLocation(...))应该如何获取。 if (nDirRotPI * 1.5) { // sg add 090402,解决文字相对基线对齐方式的问题 if (m_nTextAlign == kAtStart) // 起端对齐 { ptAlignUp = ptTextStart; ads_polar(ptAlignUp, m_nLayoutRotation + PI, nText2Base + dUpLen, ptAlignUp); ads_polar(ptAlignUp, m_nLayoutRotation + PI * 0.5, nText2Base + dUpHei + dUpMis, ptAlignUp); ptAlignDown = ptTextStart; ads_polar(ptAlignDown, m_nLayoutRotation + PI, nText2Base + dDownLen, ptAlignDown); ads_polar(ptAlignDown, m_nLayoutRotation - PI * 0.5, nText2Base - dDownMis, ptAlignDown); } else if (m_nTextAlign == kAtMiddle) // 居中对齐 { ADSGePoint3d ptMid; Midpoint(ptTextStart, ptTextEnd, ptMid); ptAlignUp = ptMid; ads_polar(ptAlignUp, m_nLayoutRotation + PI, dUpLen * 0.5, ptAlignUp); ads_polar(ptAlignUp, m_nLayoutRotation + PI * 0.5, nText2Base + dUpHei + dUpMis, ptAlignUp); ptAlignDown = ptMid; ads_polar(ptAlignDown, m_nLayoutRotation + PI, dDownLen * 0.5, ptAlignDown); ads_polar(ptAlignDown, m_nLayoutRotation - PI * 0.5, nText2Base - dDownMis, ptAlignDown); } else // 末端对齐 { ptAlignUp = ptTextEnd; ads_polar(ptAlignUp, m_nLayoutRotation, nText2Base, ptAlignUp); ads_polar(ptAlignUp, m_nLayoutRotation + PI * 0.5, nText2Base + dUpHei + dUpMis, ptAlignUp); ptAlignDown = ptTextEnd; ads_polar(ptAlignDown, m_nLayoutRotation, nText2Base, ptAlignDown); ads_polar(ptAlignDown, m_nLayoutRotation - PI * 0.5, nText2Base - dDownMis, ptAlignDown); } } else { // sg modify 090402,解决文字相对基线对齐方式的问题 if (m_nTextAlign == kAtStart) // 起端对齐 { ptAlignUp = ptTextStart; ads_polar(ptAlignUp, m_nLayoutRotation, nText2Base, ptAlignUp); ads_polar(ptAlignUp, m_nLayoutRotation + PI * 0.5, nText2Base + dUpHei + dUpMis, ptAlignUp); ptAlignDown = ptTextStart; ads_polar(ptAlignDown, m_nLayoutRotation, nText2Base, ptAlignDown); ads_polar(ptAlignDown, m_nLayoutRotation - PI * 0.5, nText2Base - dDownMis, ptAlignDown); } else if (m_nTextAlign == kAtMiddle) // 居中对齐 { ADSGePoint3d ptMid; Midpoint(ptTextStart, ptTextEnd, ptMid); ptAlignUp = ptMid; ads_polar(ptAlignUp, m_nLayoutRotation + PI, dUpLen * 0.5, ptAlignUp); ads_polar(ptAlignUp, m_nLayoutRotation + PI * 0.5, nText2Base + dUpHei + dUpMis, ptAlignUp); ptAlignDown = ptMid; ads_polar(ptAlignDown, m_nLayoutRotation + PI, dDownLen * 0.5, ptAlignDown); ads_polar(ptAlignDown, m_nLayoutRotation - PI * 0.5, nText2Base - dDownMis, ptAlignDown); } else // 末端对齐 { ptAlignUp = ptTextEnd; ads_polar(ptAlignUp, m_nLayoutRotation + PI, nText2Base + dUpLen, ptAlignUp); ads_polar(ptAlignUp, m_nLayoutRotation + PI * 0.5, nText2Base + dUpHei + dUpMis, ptAlignUp); ptAlignDown = ptTextEnd; ads_polar(ptAlignDown, m_nLayoutRotation + PI, nText2Base + dDownLen, ptAlignDown); ads_polar(ptAlignDown, m_nLayoutRotation - PI * 0.5, nText2Base - dDownMis, ptAlignDown); } } } bool AecXDbSymbIndexPointer::GetUpTextExtent(ADSGePoint3d &ptMin, ADSGePoint3d &ptMax) const { if (!NeedDrawUpText()) return false; AecXDbText *pText = ConstructDimText(GetTextLine(), true); pText->SetPScale(GetPScale()); if (IsSingleLineText(true)) { pText->SetLayoutRotation(0.0); pText->GetExtents2d(ptMin, ptMax); ADSGePoint3d ptText = pText->GetLocation(); Vector3D vecCross = (ptMax - ptText); vecCross.Rotate(m_nLayoutRotation); ptMax = ptText + vecCross; vecCross = (ptMin - ptText); vecCross.Rotate(m_nLayoutRotation); ptMin = (ptText + vecCross); } else { // 多行文本 pText->SetLayoutRotation(0.0); pText->GetExtents2d(ptMin, ptMax); ADSGePoint3d ptLeftTop(ptMin.x, ptMax.y); Vector3D vecCross = (ptMax - ptLeftTop); vecCross.Rotate(m_nLayoutRotation); vecCross = UnitVec(vecCross); ptMax = ptLeftTop + ScaleVec(GetTextWidthUp() * GetPScale(), vecCross); vecCross = (ptMin - ptLeftTop); vecCross.Rotate(m_nLayoutRotation); ptMin = (ptLeftTop + vecCross); } return true; } bool AecXDbSymbIndexPointer::GetDownTextExtent(ADSGePoint3d &ptMin, ADSGePoint3d &ptMax) const { if (!NeedDrawDownText()) return false; AecXDbText *pText = ConstructDimText(GetTextLine(), false); pText->SetPScale(GetPScale()); if (IsSingleLineText(false)) { pText->SetLayoutRotation(0.0); pText->GetExtents2d(ptMin, ptMax); ADSGePoint3d ptText = pText->GetLocation(); Vector3D vecCross = (ptMax - ptText); vecCross.Rotate(m_nLayoutRotation); ptMax = ptText + vecCross; vecCross = (ptMin - ptText); vecCross.Rotate(m_nLayoutRotation); ptMin = (ptText + vecCross); } else { // 多行文本 pText->SetLayoutRotation(0.0); pText->GetExtents2d(ptMin, ptMax); ADSGePoint3d ptLeftTop(ptMin.x, ptMax.y); Vector3D vecCross = (ptMax - ptLeftTop); vecCross.Rotate(m_nLayoutRotation); vecCross = UnitVec(vecCross); ptMax = ptLeftTop + ScaleVec(GetTextWidthDown() * GetPScale(), vecCross); vecCross = (ptMin - ptLeftTop); vecCross.Rotate(m_nLayoutRotation); ptMin = (ptLeftTop + vecCross); } delete pText; return true; } void AecXDbSymbIndexPointer::CalcUpTextPostion(const GeLine &textLine, double nDirRot, double nText2Base, ADSGePoint3d &ptAlignUp, AcGiDraw::TextAlignment &alginment) const { ASSERT(NeedDrawUpText()); // 下面的代码逻辑很简单 // 分别考虑了文字线向右,和向左两种方向下,文字排列在文字线的起点,中点,终点,共六种情况。 if (!IsSingleLineText(true)) { alginment = AcGiDraw::kLeft; // 靠左排列,定位点是左上角点(多行文字的定位点都在左上角) const ADSGePoint3d &ptTextStart = textLine.StartPoint(); const ADSGePoint3d &ptTextEnd = textLine.EndPoint(); ADSGePoint3d ptUpMin, ptUpMax; double dUpMis = 0.0; MTextExtents((LPCTSTR)m_sText1, GetDimTextStyle(), GetTextHeight(), GetTextWidthUp(), ptUpMin, ptUpMax, &dUpMis); double dUpLen = ptUpMax.x - ptUpMin.x, dUpHei = ptUpMax.y - ptUpMin.y; if (nDirRotPI * 1.5) { // sg add 090402,解决文字相对基线对齐方式的问题 if (m_nTextAlign == kAtStart) // 起端对齐 { ptAlignUp = ptTextStart; ads_polar(ptAlignUp, m_nLayoutRotation + PI, nText2Base + dUpLen, ptAlignUp); } else if (m_nTextAlign == kAtMiddle) // 居中对齐 { textLine.MidPoint(ptAlignUp); ads_polar(ptAlignUp, m_nLayoutRotation + PI, dUpLen * 0.5, ptAlignUp); } else // 末端对齐 { ptAlignUp = ptTextEnd; ads_polar(ptAlignUp, m_nLayoutRotation, nText2Base, ptAlignUp); } } else { // sg modify 090402,解决文字相对基线对齐方式的问题 if (m_nTextAlign == kAtStart) // 起端对齐 { ptAlignUp = ptTextStart; ads_polar(ptAlignUp, m_nLayoutRotation, nText2Base, ptAlignUp); } else if (m_nTextAlign == kAtMiddle) // 居中对齐 { textLine.MidPoint(ptAlignUp); ads_polar(ptAlignUp, m_nLayoutRotation + PI, dUpLen * 0.5, ptAlignUp); } else // 末端对齐 { ptAlignUp = ptTextEnd; ads_polar(ptAlignUp, m_nLayoutRotation + PI, nText2Base + dUpLen, ptAlignUp); } } // 统一向上 ads_polar(ptAlignUp, m_nLayoutRotation + PI * 0.5, nText2Base + dUpHei + dUpMis, ptAlignUp); } else { if (nDirRotPI * 1.5) { // sg add 090402,解决文字相对基线对齐方式的问题 if (m_nTextAlign == kAtStart) // 起端对齐 { alginment = AcGiDraw::kBottomRight; ptAlignUp = textLine.StartPoint(); ads_polar(ptAlignUp, m_nLayoutRotation, -nText2Base, ptAlignUp); } else if (m_nTextAlign == kAtMiddle) // 居中对齐 { alginment = AcGiDraw::kBottomCenter; textLine.MidPoint(ptAlignUp); // ads_polar(ptAlignUp, m_nLayoutRotation, -nText2Base, ptAlignUp); } else // 末端对齐 { alginment = AcGiDraw::kBottomLeft; ptAlignUp = textLine.EndPoint(); ads_polar(ptAlignUp, m_nLayoutRotation, nText2Base, ptAlignUp); } } else { // sg modify 090402,解决文字相对基线对齐方式的问题 if (m_nTextAlign == kAtStart) // 起端对齐 { alginment = AcGiDraw::kBottomLeft; ptAlignUp = textLine.StartPoint(); ads_polar(ptAlignUp, m_nLayoutRotation, nText2Base, ptAlignUp); } else if (m_nTextAlign == kAtMiddle) // 居中对齐 { alginment = AcGiDraw::kBottomCenter; textLine.MidPoint(ptAlignUp); } else // 末端对齐 { alginment = AcGiDraw::kBottomRight; ptAlignUp = textLine.EndPoint(); ads_polar(ptAlignUp, m_nLayoutRotation, -nText2Base, ptAlignUp); } } // 采用Bottom对齐,这几个点都要向上移动 nText2Base位移 double dMis = 0; SingleTextUpMis(LPCTSTR(m_sText1), GetDimTextStyle(), GetTextHeight(), &dMis); ads_polar(ptAlignUp, m_nLayoutRotation + PI * 0.5, nText2Base - dMis, ptAlignUp); // Y方向精确定位 } } void AecXDbSymbIndexPointer::CalcDownTextPostion(const GeLine &textLine, double nDirRot, double nText2Base, ADSGePoint3d &ptAlignDown, AcGiDraw::TextAlignment &alginment) const { ASSERT(NeedDrawDownText()); // 下面的代码逻辑很简单 // 分别考虑了文字线向右,和向左两种方向下,文字排列在文字线的起点,中点,终点,共六种情况。 if (!IsSingleLineText(false)) { ADSGePoint3d ptDownMin, ptDownMax; double dDownMis = 0.0; MTextExtents((LPCTSTR)m_sText2, GetDimTextStyle(), GetTextHeight(), GetTextWidthDown(), ptDownMin, ptDownMax, &dDownMis); double dDownLen = ptDownMax.x - ptDownMin.x, dDownHei = ptDownMax.y - ptDownMin.y; alginment = AcGiDraw::kLeft; if (nDirRotPI * 1.5) { // sg add 090402,解决文字相对基线对齐方式的问题 if (m_nTextAlign == kAtStart) // 起端对齐 { ptAlignDown = textLine.StartPoint(); ads_polar(ptAlignDown, m_nLayoutRotation + PI, nText2Base + dDownLen, ptAlignDown); } else if (m_nTextAlign == kAtMiddle) // 居中对齐 { textLine.MidPoint(ptAlignDown); ads_polar(ptAlignDown, m_nLayoutRotation + PI, dDownLen * 0.5, ptAlignDown); } else // 末端对齐 { ptAlignDown = textLine.EndPoint(); ads_polar(ptAlignDown, m_nLayoutRotation, nText2Base, ptAlignDown); } } else { // sg modify 090402,解决文字相对基线对齐方式的问题 if (m_nTextAlign == kAtStart) // 起端对齐 { ptAlignDown = textLine.StartPoint(); ads_polar(ptAlignDown, m_nLayoutRotation, nText2Base, ptAlignDown); } else if (m_nTextAlign == kAtMiddle) // 居中对齐 { textLine.MidPoint(ptAlignDown); ads_polar(ptAlignDown, m_nLayoutRotation + PI, dDownLen * 0.5, ptAlignDown); } else // 末端对齐 { ptAlignDown = textLine.EndPoint(); ads_polar(ptAlignDown, m_nLayoutRotation + PI, nText2Base + dDownLen, ptAlignDown); } } // 统一向下 ads_polar(ptAlignDown, m_nLayoutRotation - PI * 0.5, nText2Base - dDownMis, ptAlignDown); } else { // 单行文字 if (nDirRotPI * 1.5) { // sg add 090402,解决文字相对基线对齐方式的问题 if (m_nTextAlign == kAtStart) // 起端对齐 { alginment = AcGiDraw::kTopRight; ptAlignDown = textLine.StartPoint(); ads_polar(ptAlignDown, m_nLayoutRotation, -nText2Base, ptAlignDown); } else if (m_nTextAlign == kAtMiddle) // 居中对齐 { alginment = AcGiDraw::kTopCenter; textLine.MidPoint(ptAlignDown); } else // 末端对齐 { alginment = AcGiDraw::kTopLeft; ptAlignDown = textLine.EndPoint(); ads_polar(ptAlignDown, m_nLayoutRotation, nText2Base, ptAlignDown); } } else { // sg modify 090402,解决文字相对基线对齐方式的问题 if (m_nTextAlign == kAtStart) // 起端对齐 { alginment = AcGiDraw::kTopLeft; ptAlignDown = textLine.StartPoint(); ads_polar(ptAlignDown, m_nLayoutRotation, nText2Base, ptAlignDown); } else if (m_nTextAlign == kAtMiddle) // 居中对齐 { alginment = AcGiDraw::kTopCenter; textLine.MidPoint(ptAlignDown); } else // 末端对齐 { alginment = AcGiDraw::kTopRight; ptAlignDown = textLine.EndPoint(); ads_polar(ptAlignDown, m_nLayoutRotation, -nText2Base, ptAlignDown); } } double dMis = 0; SingleTextDownMis((LPCTSTR)m_sText2, GetDimTextStyle(), GetTextHeight(), &dMis); ads_polar(ptAlignDown, m_nLayoutRotation - PI * 0.5, nText2Base + dMis, ptAlignDown); } } AecXDbText* AecXDbSymbIndexPointer::ConstructDimText(const GeLine &textLine, bool bUp) const { ASSERT(NeedDrawUpText()); AecXDbText *pText = NULL; if (IsSingleLineText(bUp)) { pText = new AecXDbText(); } else { pText = new AecXDbMText(); } pText->SetPScale(GetPScale()); ADSGePoint3d ptPos; AcGiDraw::TextAlignment ali; double nDirRot = ads_angle(textLine.EndPoint(), textLine.StartPoint()); nDirRot = Wcs2Layout(nDirRot); double nText2Base = GetText2BaseRatio(FALSE, TRUE); if (bUp) CalcUpTextPostion(textLine, nDirRot, nText2Base, ptPos, ali); else CalcDownTextPostion(textLine, nDirRot, nText2Base, ptPos, ali); pText->SetHeight(GetTextHeight()); pText->SetStyleId(GetDimTextStyle()); // modify by lgh 20101208. 标注使用独立的样式(8.5) pText->SetText(bUp ? m_sText1 : m_sText2); pText->SetAlignment(ali); pText->SetLocation(ptPos); pText->SetLayoutRotation(m_nLayoutRotation); if (pText->isKindOf(AecXDbMText::desc())) { // 多行 ASSERT(!IsSingleLineText(bUp)); AecXDbMText *pMText = (AecXDbMText*)pText; pMText->SetPageWidth(bUp ? GetTextWidthUp() : GetTextWidthDown()); } return pText; } ////////////////////////////////////////////////////////////////////////// int AecXDbSymbIndexPointer::CutLineCmp(const void *p1, const void *p2) { using namespace GlobalFunc; const GeLine *pLine1 = (const GeLine*)p1; const GeLine *pLine2 = (const GeLine*)p2; Vector3D vec = pLine2->StartPoint() - pLine1->StartPoint(); if (vec == Vector3D(0.0, 0.0, 0.0)) return 0; ads_real dDot = (vec & vecForSortCutLine); if (fabs(dDot) < 1e-6) return 0; else if (dDot > 0) return -1; else return 1; } void AecXDbSymbIndexPointer::SortCutLine(const GeLine &lineAssist, AryXLine &lines) { using namespace GlobalFunc; int index = 0; Vector3D vecLineAssist = lineAssist.Direction3d(); if (vecLineAssist == Vector3D(0.0, 0.0, 0.0)) { vecLineAssist = Vector3D(1.0, 0.0, 0.0); } // 调节lines中线段的方向 for (index = 0; index < (int)lines.GetSize(); index++) { Vector3D vecLine = lines[index].Direction3d(); if ((vecLine & vecLineAssist) < 0.0) lines[index].Reverse(); } // 排序 vecForSortCutLine = vecLineAssist; GeLine *pLines = lines.GetData(); qsort(pLines, lines.GetSize(), sizeof(GeLine), AecXDbSymbIndexPointer::CutLineCmp); } Vector3D AecXDbSymbIndexPointer::ScaleVec(double dScale, const Vector3D &vec) { return Vector3D(vec.x * dScale, vec.y * dScale, vec.z * dScale); } void AecXDbSymbIndexPointer::MTextExtents(const CString &sText, const AcDbObjectId &idStyle, double dHei, double dWid, ADSGePoint3d &ptMin, ADSGePoint3d &ptMax, double *pMisValue) const { AecXDbMText mText; mText.SetText(sText); mText.SetHeight(dHei * GetPScale(), FALSE); mText.SetStyleId(idStyle); mText.SetAlignment(AcGiDraw::kLeft); // 设置哪个都是一样的。 mText.SetRotation(0.0); mText.SetLocation(ADSGePoint3d(0, 0, 0)); mText.SetPageWidth(dWid * GetPScale(), FALSE); ADSGePoint3d ext = mText.GetExtents(); mText.GetExtents2d(ptMin, ptMax); // sg add 110729,批量转旧时,无法得到文字外包围框,整体的高度用:行高*行数+间距*(行高-1),整体的宽度用:页宽 if (ptMin == ADSGePoint3d() && ptMax == ADSGePoint3d()) { ptMax = mText.GetExtents(); return; // 这种情况下,相当于最小点(0,0),pMisValue就不需要使用了 } if (pMisValue != NULL) { *pMisValue = fabs(ptMax.y); } } // 单行文字显示误差 void AecXDbSymbIndexPointer::SingleTextUpMis(const CString &sText, const AcDbObjectId &idStyle, double dHei, double *pMisValue) const { if (pMisValue != NULL) { AecXDbText mText; mText.SetPScale(GetPScale()); mText.SetText(sText); mText.SetHeight(dHei * GetPScale(), FALSE); mText.SetStyleId(idStyle); mText.SetAlignment(AcGiDraw::kBottomLeft); mText.SetRotation(0.0); mText.SetLocation(ADSGePoint3d(0, 0, 0)); ADSGePoint3d ext = mText.GetExtents(); ADSGePoint3d ptMin, ptMax; mText.GetExtents2d(ptMin, ptMax); *pMisValue = (.0); } } void AecXDbSymbIndexPointer::SingleTextDownMis(const CString &sText, const AcDbObjectId &idStyle, double dHei, double *pMisValue) const { if (pMisValue != NULL) { AecXDbText mText; mText.SetPScale(GetPScale()); mText.SetText(sText); mText.SetHeight(dHei * GetPScale(), FALSE); mText.SetStyleId(idStyle); mText.SetAlignment(AcGiDraw::kTopRight); mText.SetRotation(0.0); mText.SetLocation(ADSGePoint3d(0, 0, 0)); ADSGePoint3d ext = mText.GetExtents(); ADSGePoint3d ptMin, ptMax; mText.GetExtents2d(ptMin, ptMax); *pMisValue = (.0); } } double AecXDbSymbIndexPointer::CalcTextLen(const CString &sText, const AcDbObjectId &styleId, double dHei, int iWider) { if (sText.IsEmpty()) return 0.0; CString sDump = sText; while (iWider-- > 0) { sDump += _T("1"); } AecXDbText text; text.SetHeight(dHei); text.SetStyleId(styleId); text.SetText(sDump); text.SetAlignment(AcGiDraw::kBottomLeft); text.SetLocation(ADSGePoint3d()); ADSGePoint3d ptMin, ptMax; text.GetExtents2d(ptMin, ptMax); return (ptMax.x - ptMin.x); } ////////////////////////////////////////////////////////////////////////// // AecXDbSymbIndexPointer::SGripAdditional的成员函数 // 填充arGripStruct是否Check的标记 void AecXDbSymbIndexPointer::SGripAdditional::FillCheckProp(const AcDbIntArray &arIndicesSrc) { for (int i = 0; i < (int)arIndicesSrc.length(); i++) { for (int j = 0; j < (int)arGripStruct.GetSize(); j++) { if (arGripStruct[j].nIndeces == arIndicesSrc[i]) { arGripStruct[j].bCheck = true; break; } } } } void AecXDbSymbIndexPointer::SGripAdditional::SetChecked(int nType, bool bCheck) { for (int i = 0; i < (int)arGripStruct.GetSize(); i++) { if (arGripStruct[i].nType == nType) { arGripStruct[i].bCheck = bCheck; return; } } } // 查找某类型对应的夹点是否被选中 bool AecXDbSymbIndexPointer::SGripAdditional::FindCheck(int nType) const { for (int j = 0; j < (int)arGripStruct.GetSize(); j++) { if (arGripStruct[j].nType == nType) { return arGripStruct[j].bCheck; } } return false; } // 查找某索引对应的夹点是否被选中 bool AecXDbSymbIndexPointer::SGripAdditional::FindCutCheckBoth(int nIndec) const { for (int j = 0; j < (int)arGripStruct.GetSize(); j++) { if (arGripStruct[j].nIndeces == nIndec) { switch (arGripStruct[j].nType) { case eGCutFir: case eGCutStart: return arGripStruct[j + 1].bCheck; case eGCutEnd: return arGripStruct[j - 1].bCheck; default: return false; } } } return false; } // 查找某索引nIndec对应的是第几个CutLine int AecXDbSymbIndexPointer::SGripAdditional::GetCutLineIndex(int nIndec) const { int iIndex = -1; for (int j = 0; j < (int)arGripStruct.GetSize(); j++) { if (arGripStruct[j].nIndeces == nIndec) { switch (arGripStruct[j].nType) { case eGCutFir: case eGCutStart: iIndex = j; break; case eGCutEnd: iIndex = j - 1; break; default: return -1; } break; } } if (iIndex != -1) { return (int)((iIndex - nCutStart) * 0.5); } else return -1; } bool AecXDbSymbIndexPointer::SGripAdditional::IsCut(int nIndec) const { return (nIndec >= nCutStart && nIndec < nCutEnd); }