384 lines
15 KiB
C++
384 lines
15 KiB
C++
#pragma once
|
||
#include "AecDbSymbWithText.h"
|
||
#include "ObjInfoUnit.h"
|
||
#include "GePoly2D.h"
|
||
|
||
class AecXDbText;
|
||
class AecXDbSymbIndexPointer : public AecXDbSymbWithText
|
||
{
|
||
public:
|
||
ACRX_DECLARE_MEMBERS(AecXDbSymbIndexPointer);
|
||
|
||
private:
|
||
const static Adesk::UInt8 g_nVersion;
|
||
|
||
public:
|
||
// sg add 090217,文字对齐方式
|
||
enum TSymbIPTextAlign { kAtStart = 1, kAtMiddle = 2, kAtEnd = 3, };
|
||
|
||
protected:
|
||
Adesk::UInt8 m_nFlag; // 0--指向; 1--剖切
|
||
|
||
ADSGePoint3d m_ptStart, m_ptTurn; // g1点和g2点
|
||
double m_nRadius; // 索引号半径,图纸尺寸
|
||
double m_nTextBaseLen; // 图纸单位, 可以为负数
|
||
double m_nSourceExtent; // 指向,详图区域的直径;剖切,剖视方向
|
||
|
||
// 文字参数
|
||
TCString m_sText1; // 文字说明1
|
||
TCString m_sText2; // 文字说明2
|
||
TCString m_sIndexLabel; // 索引编号
|
||
TCString m_sDrawingLabel; // 图号
|
||
|
||
// TArch7
|
||
PtrList<TCString> m_lstIndex;
|
||
PtrList<TCString> m_lstLabel;
|
||
|
||
// TArch8,预留给8.0的BETA2版本
|
||
double m_dText2BaseRatio; // 文字距基线系数,sg add 081112
|
||
TSymbIPTextAlign m_nTextAlign; // 文字对齐方式,sg add 090217
|
||
// 引线的角度,注:圆上任意点指向圆心的方向,与X轴正向夹角
|
||
double m_dLineAngle;
|
||
// 8.5使用它来存储多段剖切线,m_poly中的点代表剖切线的起点,Bulge代表引出线的相对长度
|
||
GePoly2D m_polyCutLine;
|
||
// lgh modify 101227 这个数据被使用来表示索引延长线的长度 (g4 - g5)
|
||
double m_dTextBaseLen2; // 规范6.22图4中,索引符号左侧文字线长,可以为负数
|
||
TCString m_szText3; // 索引图名符号左侧文字内容
|
||
|
||
public:
|
||
AecXDbSymbIndexPointer();
|
||
~AecXDbSymbIndexPointer();
|
||
|
||
public:
|
||
virtual BOOL IsValid() const;
|
||
virtual void CopyPropertiesFrom(AcDbEntity *pSrcEntity, unsigned gMatchFlag);
|
||
|
||
//virtual Acad::ErrorStatus subGetClassID(CLSID* pClsid) const;
|
||
virtual Acad::ErrorStatus dwgInFields(AcDbDwgFiler*);
|
||
virtual Acad::ErrorStatus dwgOutFields(AcDbDwgFiler*) const;
|
||
virtual Acad::ErrorStatus dxfInFields(AcDbDxfFiler*);
|
||
virtual Acad::ErrorStatus dxfOutFields(AcDbDxfFiler*) const;
|
||
virtual Acad::ErrorStatus subGetGripPoints(AcGePoint3dArray& gripPoints,
|
||
AcDbIntArray& osnapModes,
|
||
AcDbIntArray& geomIds) const;
|
||
virtual Acad::ErrorStatus subGetGripPoints(AcDbGripDataPtrArray& grips,
|
||
const double curViewUnitSize,
|
||
const int gripSize,
|
||
const AcGeVector3d& curViewDir,
|
||
const int bitflags) const;
|
||
|
||
virtual Acad::ErrorStatus subGetStretchPoints(AcGePoint3dArray & stretchPoints) const;
|
||
virtual Acad::ErrorStatus subTransformBy(const AcGeMatrix3d& xform);
|
||
virtual Acad::ErrorStatus subMoveGripPointsAt(const AcDbIntArray& indices,
|
||
const AcGeVector3d& offset);
|
||
virtual Acad::ErrorStatus subMoveStretchPointsAt(const AcDbIntArray& indices,
|
||
const AcGeVector3d& offset);
|
||
|
||
public:
|
||
// drived from TDbEntity
|
||
//virtual Acad::ErrorStatus DownGradeSave(int nDrawMode, AcDbVoidPtrArray &entSet,
|
||
// BOOL *bErase);
|
||
virtual Acad::ErrorStatus Draw2d(AcGiDraw &dc) const;
|
||
|
||
virtual void GetTips(PtrList<ObjInfoUnit> &) const; // 取动态属性显示数据
|
||
virtual Acad::ErrorStatus GetGripText(int i, CString &cs) const;
|
||
|
||
virtual int ConvertText(TConvertTextPtr ptr, void *pData = NULL);
|
||
// 返回发现的位置,同时posStart往前移动(以便继续找下一个使用),
|
||
virtual TextPosition FindSubText(const TCHAR *sSubText,
|
||
TextPosition &posStart, TextRange *pRange = NULL) const;
|
||
// 返回下一次查找的开始位置
|
||
virtual TextPosition ReplaceSubText(const TextPosition &posRep,
|
||
const TCHAR *sRepText, TextRange *pRange = NULL);
|
||
|
||
virtual long GetSubTextNum()const { return 4 + GetAppendIndexNum() * 2; }
|
||
virtual void SetSubText(long i, CString sText);
|
||
virtual SubText* HitTestText(ADSGePoint3d pt)const;
|
||
virtual SubText* GetSubText(long iText)const;
|
||
virtual long GetNextSubTextIndex(long i, bool bVert, bool bPre)const; // ok
|
||
|
||
virtual const TCHAR *GetDefaultLayer() const;
|
||
|
||
// sg add 090323
|
||
virtual int GetCtrlToggleIndex()const { return 6; }
|
||
|
||
// sg add 110211,支持统一标高
|
||
virtual bool UnifyElevation(double dElevation = 0.0);
|
||
|
||
public: // Helper Method
|
||
// 返回值为绝对值
|
||
double GetMinTextBaseLen(BOOL bAsPaperUnit = TRUE) const;
|
||
double GetDefaultTextBaseLen(BOOL bAsPaperUnit = TRUE) const;
|
||
|
||
public: // Properties
|
||
const TCHAR *GetText1() const;
|
||
void SetText1(const TCHAR *pszText);
|
||
const TCHAR *GetText2() const;
|
||
void SetText2(const TCHAR *pszText);
|
||
|
||
const TCHAR *GetIndexLabel() const;
|
||
void SetIndexLabel(const TCHAR *pszText);
|
||
const TCHAR *GetDrawingLabel() const;
|
||
void SetDrawingLabel(const TCHAR *pszText);
|
||
|
||
ADSGePoint3d GetStartPoint() const;
|
||
void SetStartPoint(ADSGePoint3d pt);
|
||
ADSGePoint3d GetTurnPoint() const;
|
||
void SetTurnPoint(ADSGePoint3d pt);
|
||
|
||
double GetTextBaseLen(BOOL bAsPaperUnit = TRUE) const;
|
||
void SetTextBaseLen(double nVal, BOOL bAsPaperUnit = TRUE);
|
||
|
||
double GetRadius(BOOL bAsPaperUnit = TRUE) const;
|
||
void SetRadius(double val, BOOL bAsPaperUnit = TRUE);
|
||
|
||
double GetSourceExtent() const; // Use Model Unit
|
||
void SetSourceExtent(double val); // Use Model Unit
|
||
|
||
BOOL IsIndexPointer() const;
|
||
void SetIndexPointer(BOOL bTrue);
|
||
|
||
// sg add 081112,bRealDist用来控制,返回“实际距离”(自动乘字高)或“系数”
|
||
double GetText2BaseRatio(BOOL bAsPaperUnit = TRUE, BOOL bRealDist = TRUE) const;
|
||
void SetText2BaseRatio(double dVal, BOOL bAsPaperUnit = TRUE);
|
||
|
||
// sg add 090217,预留给8.0的BETA2版本
|
||
TSymbIPTextAlign GetTextAlign() const;
|
||
void SetTextAlign(TSymbIPTextAlign align);
|
||
|
||
double GetLineAngle() const;
|
||
void SetLineAngle(double dVal);
|
||
|
||
void GetPoly2D(GePoly2D &poly) const;
|
||
void SetPoly2D(const GePoly2D &poly);
|
||
|
||
double GetTextBaseLen2() const;
|
||
void SetTextBaseLen2(double dVal);
|
||
|
||
const TCHAR *GetText3() const;
|
||
void SetText3(const TCHAR *pszText);
|
||
|
||
// sg add 090410,支持文字控制大小的比例,间接设置TDbSymbDrawingIndex,动态数据
|
||
double GetTextRatio(BOOL bDraw = FALSE) const;
|
||
void SetTextRatio(double dVal);
|
||
|
||
// sg add 090723,支持使用新、旧圆圈文字样式,动态数据
|
||
void SetOldStyle(int nOldStyle);
|
||
int GetOldStyle() const;
|
||
BOOL IsOldStyle() const; // 是否保留旧的样式
|
||
|
||
public:
|
||
// lgh add.
|
||
// 8.5的修改使用扩展数据添加以下几个属性:
|
||
// 文字样式(标注的)
|
||
// 标志延长线数据 -->使用预留数据
|
||
// 多加一段引出线(点) (gAdd)
|
||
// 多段剖切线
|
||
typedef CArray<int, int&> AryInt;
|
||
typedef CArray<ADSGePoint3d, ADSGePoint3d&> AryXPoint;
|
||
typedef CArray<GeLine, GeLine&> AryXLine;
|
||
typedef AryXPoint AryXVector;
|
||
|
||
// 8.5新增扩展数据的读写以及操作函数
|
||
// 标注文字样式的读写
|
||
void SetDimTextStyle(const AcDbObjectId &id);
|
||
AcDbObjectId GetDimTextStyle() const;
|
||
|
||
// 引出线的点(gAdd)对应顺序如下:
|
||
void SetAddedPoint(const ADSGePoint3d &ptAdded);
|
||
bool GetAddedPoint(ADSGePoint3d &ptAdded) const;
|
||
void ClearAddedPoint();
|
||
bool HasAddedPoint() const;
|
||
|
||
// 多段剖切线相关读写
|
||
// 第一根剖切线仍旧按照原先的格式
|
||
// 新添加的剖切线使用下面函数添加.
|
||
// 剖切线:起点,长度, 起点,长度....
|
||
// 剖切线的起点记录的是在引线上的点,
|
||
// 因此在绘制的时候,根据剖切线的方向做相应的偏移。改变剖切方向,这些点不需要改变。
|
||
// 返回剖切线的个数。(不包括第一段剖切线)
|
||
int GetCutLineNum() const;
|
||
// 重新设置动态数据中的剖切线,不会修正第一段剖切线,内部会针对剖切线排序
|
||
void SetCutLine(AryXLine &arCutLines);
|
||
// 获得所有的剖切线,包括第一段
|
||
int GetCutLineAll(AryXLine &arCutLines) const;
|
||
// 清空剖切线
|
||
void ClearCutLine();
|
||
|
||
// 标注位置:标注在原文字基线上,还是在延长线上
|
||
// nFlag: 0,基线上;1,延长线上
|
||
void SetDimPos(int nFlag);
|
||
int GetDimPos() const;
|
||
|
||
// 设置和读取标注文字宽度
|
||
void SetTextWidthUp(double d, BOOL bAsPaperUnit = TRUE);
|
||
double GetTextWidthUp(BOOL bAsPaperUnit = TRUE) const;
|
||
void SetTextWidthDown(double d, BOOL bAsPaperUnit = TRUE);
|
||
double GetTextWidthDown(BOOL bAsPaperUnit = TRUE) const;
|
||
// 获取实际文字的宽度,多行文字直接取宽度,单行文字计算宽度,返回。
|
||
double GetTextRelWidth(bool bUp, BOOL bAsPaperUnit = TRUE) const;
|
||
// 上标或者下标是否单行
|
||
bool IsSingleLineText(bool bUp) const;
|
||
|
||
// 检测是否有延长线 (g4 - g5)
|
||
bool HasExtendLine() const;
|
||
// 见索引标注夹点示意图
|
||
ADSGePoint3d GetG5Point() const;
|
||
|
||
public: // Properties
|
||
ADSGePoint3d GetIndexCenter() const;
|
||
ADSGePoint3d GetIndexCenter(long i)const;
|
||
ADSGePoint3d GetTextBasePoint() const;
|
||
ADSGePoint3d GetTextEndPoint() const;
|
||
|
||
long GetAppendIndexNum()const {//ok
|
||
assertReadEnabled();
|
||
return m_lstLabel.Length();
|
||
}
|
||
void SetAppendIndexNum(long num);
|
||
|
||
public:// 属性读取辅助函数
|
||
// 设置延长线长度
|
||
void SetExtendLineLen(double dVal, bool bPaperUnit = TRUE);
|
||
double GetExtendLineLen(bool bAsPaperUnit = TRUE);
|
||
// 文字线单位向量,
|
||
Vector3D GetTextLineUnitVec() const;
|
||
// 第一段引线的单位向量
|
||
Vector3D GetFirstLineUnitVec() const;
|
||
// 获取第一段引线
|
||
GeLine GetFirstLine() const;
|
||
// 获取绘制标注文字的线段,可能在延长线上,或者在原文字基线上。
|
||
GeLine GetTextLine() const;
|
||
// 向量单位化
|
||
static Vector3D UnitVec(Vector3D &vec);
|
||
// 剖切线绘制偏移(剖切线距离引线)
|
||
Vector3D CutLineOffset() const;
|
||
|
||
// 获取默认值
|
||
static double GetDefaultExtendLineLen();
|
||
static double GetDefaultCutLineLen();
|
||
|
||
// 计算单行文字的长度,
|
||
// sText,文字; styleId:文字样式; dHei:字高; iWider:多计算几个字符的宽度(原始长度太小)
|
||
static double CalcTextLen(const CString &sText, const AcDbObjectId &styleId, double dHei, int iWider);
|
||
|
||
public: // 夹点类型,参见索引示意图
|
||
enum {
|
||
eG1 = 0,
|
||
eGAdd,
|
||
eG2,
|
||
eG3,
|
||
eG4,
|
||
eG5,
|
||
eGArea, // 剖切范围
|
||
eGTextWid1, // 上标文字页宽
|
||
eGTextWid2, // 下标文字页宽
|
||
eGPointNum, // 记录夹点的个数
|
||
eGCutFir, // 第一个剖切点(用来改变剖切方向)
|
||
eGCutStart, // 剖切线起点 (不包括第一个剖切线的起点)
|
||
eGCutEnd, // 剖切线终点
|
||
};
|
||
|
||
protected:
|
||
struct SGrip
|
||
{
|
||
int nType; // eG***;
|
||
int nIndeces; // 夹点索引,CAD subMove***,或者subStretch**中传入的数据
|
||
bool bCheck; // 是否被选中
|
||
bool bProcessed; // 是否被处理过。
|
||
};
|
||
|
||
typedef CArray<SGrip, SGrip&> AryGrip;
|
||
// 夹点提取附加信息
|
||
struct SGripAdditional
|
||
{
|
||
// 对应从SubMove***中传来的索引的类型
|
||
AryInt arGripType; // 剖切点类型数组,对应剖切点
|
||
int nCutStart; // 剖切点起始
|
||
int nCutEnd; // 剖切点终止 [nCutStart, nCutEnd)
|
||
AryGrip arGripStruct; // 类型和indeces在初始时写入,并且设置bProcessed,根据indices填写bCheck标记,
|
||
ADSGePoint3d ptUpTextMin;
|
||
ADSGePoint3d ptUpTextMax;
|
||
ADSGePoint3d ptDownTextMin;
|
||
ADSGePoint3d ptDownTextMax;
|
||
|
||
// 填充arGripStruct是否Check的标记
|
||
void FillCheckProp(const AcDbIntArray &arIndicesSrc);
|
||
void SetChecked(int nType, bool bCheck);
|
||
// 查找某类型对应的夹点是否被选中
|
||
bool FindCheck(int nType) const;
|
||
// 查找某索引对应的夹点是否被选中
|
||
bool FindCutCheckBoth(int nIndec) const;
|
||
// 查找某索引nIndec对应的是第几个CutLine
|
||
int GetCutLineIndex(int nIndec) const;
|
||
bool IsCut(int nIndec) const;
|
||
};
|
||
|
||
protected: // 文字标注绘制相关函数
|
||
// 是否绘制上部标注
|
||
bool NeedDrawUpText() const;
|
||
// 是否绘制下部标注
|
||
bool NeedDrawDownText() const;
|
||
// 文字标注相关函数
|
||
void GetTextAttribute(const GeLine &textLine, ADSGePoint3d &ptAlignUp, ADSGePoint3d &ptAlignDown) const;
|
||
// 获取文字的实际左下和右上点(旋转之后的)
|
||
bool GetUpTextExtent(ADSGePoint3d &ptMin, ADSGePoint3d &ptMax) const;
|
||
bool GetDownTextExtent(ADSGePoint3d &ptMin, ADSGePoint3d &ptMax) const;
|
||
|
||
// 计算标注文字位置
|
||
void CalcUpTextPostion(const GeLine &textLine, double nDirRot, double nText2Base,
|
||
ADSGePoint3d &ptPos, AcGiDraw::TextAlignment &alginment) const;
|
||
void CalcDownTextPostion(const GeLine &textLine, double nDirRot, double nText2Base,
|
||
ADSGePoint3d &ptAlignDown, AcGiDraw::TextAlignment &alginment) const;
|
||
// 设置构造并且设置文字属性
|
||
AecXDbText* ConstructDimText(const GeLine &textLine, bool bUp) const;
|
||
|
||
protected: // 夹点操作函数
|
||
// 三个内联函数,分别用来添加,夹点,提示信息,以及类型。
|
||
void AddGripPoint(AcGePoint3dArray *pArGripPoints, const ADSGePoint3d &gripPoint) const;
|
||
void AddGripTip(CStringArray *pArTips, LPCTSTR szTips) const;
|
||
void AddSGripType(AecXDbSymbIndexPointer::SGripAdditional *pSga, int nType, int nIndex) const;
|
||
|
||
// 调节剖切线终点,处于引线内部,可能会调整点的顺序。
|
||
// nKeepType:剖切线的调整方式:0:保持剖切线的长度,1:保持剖切线起点位置不变(改变长度)
|
||
void KeepCutLineAssistLine(const GeLine &lineAssist, ADSGePoint3d &ptCutStart, ADSGePoint3d &ptCutEnd, int nKeepType);
|
||
// 构造夹点信息
|
||
// pArTips:提示信息数组
|
||
// pArGripPoints:夹点数组
|
||
// pSga:夹点信息结构体。
|
||
// bGrip:夹点操作还是拉伸操作(所构造的夹点不同)
|
||
void BuildGrip(CStringArray *pArTips, AcGePoint3dArray *pArGripPoints, SGripAdditional *pSga, bool bGrip = true) const;
|
||
// 移动夹点或者拉伸点。
|
||
void MoveGripOrStretchPoints(const SGripAdditional &sgaFull,
|
||
const AcGeVector3d& offset,
|
||
bool bGrip = true,
|
||
int nCutSplit = 0);
|
||
|
||
protected: // 用来对cutLine排序函数
|
||
static int CutLineCmp(const void *p1, const void *p2);
|
||
// 按照lineAssist的方向,根据lines中线段的起点,对lines中的线段排序,并且调节lines中与线段lineAssist方向不同的线段
|
||
static void SortCutLine(const GeLine &lineAssist, AryXLine &lines);
|
||
// 向量放缩
|
||
static Vector3D ScaleVec(double dScale, const Vector3D &vec);
|
||
|
||
// 获取MText属性:
|
||
// sText, 显示的字符串
|
||
// idStyle :字体样式ID
|
||
// dHei, dWid, 高和宽
|
||
// ptMin:输出,文字左下坐标
|
||
// ptMax:输出,文字右上坐标
|
||
// pMisValue:文字显示的位置跟实际输入的位置会产生一个偏移(SetPosition的位置跟实际显示的位置)精确控制需要使用这个数据
|
||
void MTextExtents(const CString &sText, const AcDbObjectId &idStyle, double dHei, double dWid,
|
||
ADSGePoint3d &ptMin, ADSGePoint3d &ptMax, double *pMisValue = NULL) const;
|
||
// 文字绘制位置偏移
|
||
void SingleTextUpMis(const CString &sText, const AcDbObjectId &idStyle, double dHei, double *pMisValue = NULL) const;
|
||
void SingleTextDownMis(const CString &sText, const AcDbObjectId &idStyle, double dHei, double *pMisValue = NULL) const;
|
||
|
||
protected:
|
||
BOOL GetText(Adesk::UInt32 cookies, AecXDbText &text) const;
|
||
|
||
//void DownGradeSaveText(XExplodeStream &dc);
|
||
};
|
||
|
||
|