Files
envi-code/SourceCode/Code2026/tg_shs/shs_annotate/FindAndReplaceUtil.h
T

170 lines
6.3 KiB
C++
Raw Normal View History

2026-10-04 00:04:20 +08:00
#ifndef _FINDANDREPLACE_H_
2026-09-28 15:28:50 +08:00
#define _FINDANDREPLACE_H_
#include "StdAfx.h"
//////////////////////////////////////////////////////////////////////////
2026-10-04 00:04:20 +08:00
// Zyu add on 101019,抽象类,定义不同类型对象对应的查找替换方法
2026-09-28 15:28:50 +08:00
class CFAREntity
{
public:
CFAREntity();
virtual ~CFAREntity();
2026-10-04 00:04:20 +08:00
// 搜索文字
2026-09-28 15:28:50 +08:00
virtual TTextPosition FindText(AcDbEntity *pEnt, const TCHAR *sSubText, TTextPosition &posStart, TTextRange *pRange) = 0;
2026-10-04 00:04:20 +08:00
// 替换文字
2026-09-28 15:28:50 +08:00
virtual TTextPosition ReplaceText(AcDbEntity *pEnt, TTextPosition posFind, const TCHAR *szRepText) = 0;
};
//////////////////////////////////////////////////////////////////////////
2026-10-04 00:04:20 +08:00
// 上华对象的查找替换类
2026-09-28 15:28:50 +08:00
class CFARTDbEntity : CFAREntity
{
public:
2026-10-04 00:04:20 +08:00
// 搜索文字
2026-09-28 15:28:50 +08:00
virtual TTextPosition FindText(AcDbEntity *pEnt, const TCHAR *sSubText, TTextPosition &posStart, TTextRange *pRange);
2026-10-04 00:04:20 +08:00
// 替换文字
2026-09-28 15:28:50 +08:00
virtual TTextPosition ReplaceText(AcDbEntity *pEnt, TTextPosition posFind, const TCHAR *szRepText);
};
//////////////////////////////////////////////////////////////////////////
2026-10-04 00:04:20 +08:00
// 块参照的查找替换类
2026-09-28 15:28:50 +08:00
class CFARInsert : CFAREntity
{
public:
CFARInsert();
2026-10-04 00:04:20 +08:00
// 查找文字
2026-09-28 15:28:50 +08:00
virtual TTextPosition FindText(AcDbEntity *pEnt, const TCHAR *sSubText, TTextPosition &posStart, TTextRange *pRange);
2026-10-04 00:04:20 +08:00
// 替换文字
2026-09-28 15:28:50 +08:00
virtual TTextPosition ReplaceText(AcDbEntity *pEnt, TTextPosition posFind, const TCHAR *szRepText);
2026-10-04 00:04:20 +08:00
// 设置实体数组
2026-09-28 15:28:50 +08:00
void SetEntityIds(const AcDbObjectIdArray& arObjId);
2026-10-04 00:04:20 +08:00
// 得到实体数组
2026-09-28 15:28:50 +08:00
const AcDbObjectIdArray& GetEntityIds() const;
2026-10-04 00:04:20 +08:00
// 设置搜索选项
2026-09-28 15:28:50 +08:00
void SetFindInsertOption(BOOL bFindAttrib, BOOL bFindContent, BOOL bFindXref, BOOL bNoHidden);
2026-10-04 00:04:20 +08:00
// 重新开始搜索
2026-09-28 15:28:50 +08:00
void ResetFind();
protected:
2026-10-04 00:04:20 +08:00
// 根据给出的矩阵关系,转换指示文本范围的线框位置
2026-09-28 15:28:50 +08:00
void TransformRange(TTextRange *& pRange, const AcGeMatrix3d &matrix) const;
2026-10-04 00:04:20 +08:00
// 得到块参照的所有属性ID
2026-09-28 15:28:50 +08:00
void GetAttribIds(AcDbBlockReference *pRef);
2026-10-04 00:04:20 +08:00
// 得到块表记录中所有属性定义的ID
2026-09-28 15:28:50 +08:00
void GetAttribDefIds(AcDbBlockTableRecord *pBlkRec);
2026-10-04 00:04:20 +08:00
// 调整迭代器指针,指向m_arObjId中的第一个id代表的实体
2026-09-28 15:28:50 +08:00
bool SeekBlockRecIter(AcDbBlockTableRecordIterator *pIter);
2026-10-04 00:04:20 +08:00
// 判断实体是否满足搜索选项要求,不满足返回false
2026-09-28 15:28:50 +08:00
bool ContinueFind(AcDbEntity *pEnt, bool bIsXref) const;
2026-10-04 00:04:20 +08:00
// 清空id数组
2026-09-28 15:28:50 +08:00
void ClearObjIdArray(AcDbObjectIdArray &arObjId);
private:
2026-10-04 00:04:20 +08:00
AcDbObjectIdArray m_arObjId; // 记录打开实体的顺序
AcDbObjectIdArray m_arAttribId; // 块参照的所有属性ID
AcDbObjectIdArray m_arAttribDefId; // 块表记录的所有属性定义的ID
2026-09-28 15:28:50 +08:00
2026-10-04 00:04:20 +08:00
BOOL m_bFindAttrib; // 搜索块属性
BOOL m_bFindContent; // 搜索块内容
BOOL m_bFindXref; // 搜索外部参照
BOOL m_bNoHidden; // 忽略不可见块属性
2026-09-28 15:28:50 +08:00
};
//////////////////////////////////////////////////////////////////////////
2026-10-04 00:04:20 +08:00
// 块属性的查找替换类
2026-09-28 15:28:50 +08:00
class CFARInsertAttrib : CFAREntity
{
public:
CFARInsertAttrib();
virtual TTextPosition FindText(AcDbEntity *pEnt, const TCHAR *sSubText, TTextPosition &posStart, TTextRange *pRange);
virtual TTextPosition ReplaceText(AcDbEntity *pEnt, TTextPosition posFind, const TCHAR *szRepText);
2026-10-04 00:04:20 +08:00
// 设置忽略隐藏项
2026-09-28 15:28:50 +08:00
void SetNoHidden(BOOL bNoHidden);
private:
2026-10-04 00:04:20 +08:00
BOOL m_bNoHidden; // 忽略不可见块属性
2026-09-28 15:28:50 +08:00
};
//////////////////////////////////////////////////////////////////////////
2026-10-04 00:04:20 +08:00
// 单行文字的查找替换类
2026-09-28 15:28:50 +08:00
class CFARText : CFAREntity
{
public:
virtual TTextPosition FindText(AcDbEntity *pEnt, const TCHAR *sSubText, TTextPosition &posStart, TTextRange *pRange);
virtual TTextPosition ReplaceText(AcDbEntity *pEnt, TTextPosition posFind, const TCHAR *szRepText);
2026-10-04 00:04:20 +08:00
// 得到单行文字内的字符串
2026-09-28 15:28:50 +08:00
virtual bool GetEntityStrings(AcDbEntity *pEnt, CStringArray &arString);
};
//////////////////////////////////////////////////////////////////////////
2026-10-04 00:04:20 +08:00
// 多行文字的查找替换类
2026-09-28 15:28:50 +08:00
class CFARMText : CFAREntity
{
public:
virtual TTextPosition FindText(AcDbEntity *pEnt, const TCHAR *sSubText, TTextPosition &posStart, TTextRange *pRange);
virtual TTextPosition ReplaceText(AcDbEntity *pEnt, TTextPosition posFind, const TCHAR *szRepText);
2026-10-04 00:04:20 +08:00
// 得到多行文字内的字符串
2026-09-28 15:28:50 +08:00
bool GetEntityStrings(AcDbEntity *pEnt, CStringArray &arString);
};
//////////////////////////////////////////////////////////////////////////
2026-10-04 00:04:20 +08:00
// 标注的查找替换类
2026-09-28 15:28:50 +08:00
class CFARDimension : CFAREntity
{
public:
virtual TTextPosition FindText(AcDbEntity *pEnt, const TCHAR *sSubText, TTextPosition &posStart, TTextRange *pRange);
virtual TTextPosition ReplaceText(AcDbEntity *pEnt, TTextPosition posFind, const TCHAR *szRepText);
};
//////////////////////////////////////////////////////////////////////////
2026-10-04 00:04:20 +08:00
typedef CMap<CString, LPCTSTR, bool, bool> CMapLayer; // 图层名称和是否关闭或者冻结的关系映射类
// 查找替换工具集
2026-09-28 15:28:50 +08:00
class CFARUtil
{
public:
2026-10-04 00:04:20 +08:00
// 查找文字
2026-09-28 15:28:50 +08:00
TTextPosition FindEntText(TEntitySet ent, const TCHAR *sSubText, TTextPosition &posStart, TTextRange *pRange);
TTextPosition FindEntText(AcDbEntity *pEnt, const TCHAR *sSubText, TTextPosition &posStart, TTextRange *pRange);
2026-10-04 00:04:20 +08:00
// 替换文字
2026-09-28 15:28:50 +08:00
TTextPosition ReplaceEntText(TEntitySet ent, TTextPosition posFind, const TCHAR *szRepText);
TTextPosition ReplaceEntText(AcDbEntity *pEnt, TTextPosition posFind, const TCHAR *szRepText);
2026-10-04 00:04:20 +08:00
// id数组的Set/Get函数
2026-09-28 15:28:50 +08:00
void SetEntityIds(const AcDbObjectIdArray &arObjId);
const AcDbObjectIdArray& GetEntityIds() const;
2026-10-04 00:04:20 +08:00
// 设置查找选项
2026-09-28 15:28:50 +08:00
void SetFindOption(BOOL bFindAttrib, BOOL bFindContent, BOOL bFindXref, BOOL bNoHidden);
2026-10-04 00:04:20 +08:00
// 重新开始搜索
2026-09-28 15:28:50 +08:00
void ResetFind();
protected:
2026-10-04 00:04:20 +08:00
// 判断实体是否是在关闭或者隐藏层上
2026-09-28 15:28:50 +08:00
bool IsHiddenEntity(AcDbEntity *&pEnt);
2026-10-04 00:04:20 +08:00
// 判断id对应的层是否是关闭或者隐藏层
2026-09-28 15:28:50 +08:00
bool IsHiddenLayer(const AcDbObjectId &objIdLayer) const;
private:
2026-10-04 00:04:20 +08:00
CFARTDbEntity m_TDbEntity; // 上华对象的查找替换方法
CFARInsertAttrib m_InsertAttrib; // 块属性的查找替换方法
CFARInsert m_Insert; // 块参照/外部参照的查找替换方法
CFARText m_Text; // 单行文字的查找替换方法
CFARMText m_MText; // 多行文字的查找替换方法
CFARDimension m_Dimension; // 标注的查找替换方法
2026-09-28 15:28:50 +08:00
2026-10-04 00:04:20 +08:00
BOOL m_bNoHidden; // 标记是否忽略隐藏项
CMapLayer m_mapLayer; // 记录图层的隐藏信息
2026-09-28 15:28:50 +08:00
};
//////////////////////////////////////////////////////////////////////////
#endif