|
|
#pragma once
|
|
|
|
|
|
#include <memory>
|
|
|
#include "Xy.h"
|
|
|
|
|
|
namespace StyleManager
|
|
|
{
|
|
|
/**
|
|
|
* @class CStyleLibraryItem
|
|
|
* @brief 表示样式库中的一个项目。
|
|
|
*
|
|
|
* 此类表示样式库中的一个项目。它管理项目的名称、相关数据和修改状态。
|
|
|
*/
|
|
|
class AFX_EXT_CLASS CStyleLibraryItem
|
|
|
{
|
|
|
public:
|
|
|
/**
|
|
|
* @brief 默认构造函数。
|
|
|
*/
|
|
|
CStyleLibraryItem();
|
|
|
|
|
|
/**
|
|
|
* @brief 析构函数。
|
|
|
*/
|
|
|
virtual ~CStyleLibraryItem();
|
|
|
|
|
|
/**
|
|
|
* 获取 pXy 指针
|
|
|
*
|
|
|
* \return
|
|
|
*/
|
|
|
std::shared_ptr<CXy> GetXy() const;
|
|
|
|
|
|
/**
|
|
|
* 列出所有样式
|
|
|
*
|
|
|
* \return 样式名称集合
|
|
|
*/
|
|
|
std::vector<CString> ListStyle();
|
|
|
|
|
|
/**
|
|
|
* 查找样式,其实就是图层
|
|
|
* *
|
|
|
* \param styleName 样式名
|
|
|
* \return 图层对象
|
|
|
*/
|
|
|
CLayer* FindStyle(const CString& styleName) const;
|
|
|
|
|
|
/**
|
|
|
* 重命名样式
|
|
|
*
|
|
|
* \param oldName 旧名称
|
|
|
* \param newName 新名称
|
|
|
*/
|
|
|
void RenameStyle(const CString& oldName, const CString& newName);
|
|
|
|
|
|
/**
|
|
|
* @brief 获取项目的名称。
|
|
|
*
|
|
|
* @return 项目名称的常量引用。
|
|
|
*/
|
|
|
const CString& GetItemName(void) const;
|
|
|
|
|
|
/**
|
|
|
* 获取样式组名称
|
|
|
*
|
|
|
* \return 实际返回的是带不路径和后缀名的文件名
|
|
|
*/
|
|
|
const CString GetGroupName(void) const;
|
|
|
|
|
|
/**
|
|
|
* @brief 设置项目的名称。
|
|
|
*/
|
|
|
void SetItemName(const CString& name);
|
|
|
|
|
|
/**
|
|
|
* @brief 读取与项目相关的数据。
|
|
|
*
|
|
|
* @return 读取操作成功/失败
|
|
|
*/
|
|
|
bool Read(void);
|
|
|
|
|
|
/**
|
|
|
* @brief 写入与项目相关的数据。
|
|
|
*/
|
|
|
void Write(void);
|
|
|
|
|
|
/**
|
|
|
* 渲染样式到 HDC 中
|
|
|
*
|
|
|
* \param style 样式名称
|
|
|
* \param hdc 图像句柄
|
|
|
* \param width 宽度
|
|
|
* \param height 高度
|
|
|
*/
|
|
|
bool RenderStyle(const CString &style, HDC hdc, int width, int height) const;
|
|
|
|
|
|
void RenderXy(HDC hdc, int width, int height) const;
|
|
|
|
|
|
/**
|
|
|
* @brief 清除项目的相关数据。
|
|
|
*/
|
|
|
void ClearXy();
|
|
|
private:
|
|
|
/**
|
|
|
* @brief 设置项目的相关数据。
|
|
|
*
|
|
|
* @param pxy 指向相关数据的指针。
|
|
|
*/
|
|
|
void SetXy(std::shared_ptr<CXy> pxy);
|
|
|
|
|
|
std::vector<CLayer*> GetAllLayers() const;
|
|
|
|
|
|
void SaveLayersState() const;
|
|
|
|
|
|
void RestoreLayersState() const;
|
|
|
|
|
|
void HideOtherLayer(CLayer* pTargetLayer) const;
|
|
|
|
|
|
std::shared_ptr<CXy> m_pXy; ///< 指向相关数据的指针
|
|
|
CString m_strFileName; ///< 项目的文件名
|
|
|
bool m_bModified; ///< 表示项目是否已被修改
|
|
|
mutable std::map<CLayer*, BYTE> m_storedState;
|
|
|
};
|
|
|
|
|
|
|
|
|
class AFX_EXT_CLASS CStyleLibraryManager
|
|
|
{
|
|
|
public:
|
|
|
CStyleLibraryManager();
|
|
|
virtual ~CStyleLibraryManager();
|
|
|
|
|
|
/*
|
|
|
* 初始化样式库
|
|
|
* \param strNewPath 样式库路径
|
|
|
* \param bNotJudgeSamePath 不加载相同路径,可以用来避免重复初始化
|
|
|
*/
|
|
|
bool InitLib(const CString& strNewPath, bool bNotJudgeSamePath);
|
|
|
|
|
|
/**
|
|
|
* 列出所有分组
|
|
|
*
|
|
|
* \return
|
|
|
*/
|
|
|
std::vector<CString> ListGroup() const;
|
|
|
|
|
|
/**
|
|
|
* 列出所有 Items
|
|
|
*
|
|
|
* \return
|
|
|
*/
|
|
|
std::vector<std::shared_ptr<CStyleLibraryItem>> ListGroupItems() const;
|
|
|
|
|
|
/**
|
|
|
* 创建新的分组
|
|
|
*
|
|
|
* \param strNewFile 组名
|
|
|
*/
|
|
|
void AddNewGroup(const CString &strNewFile);
|
|
|
|
|
|
/**
|
|
|
* 移除所有分组
|
|
|
*/
|
|
|
void RemoveAll(void);
|
|
|
|
|
|
/**
|
|
|
* 移除指定分组
|
|
|
*
|
|
|
* \param strNewFile
|
|
|
*/
|
|
|
void RemoveGroup(const CString& strNewFile);
|
|
|
|
|
|
/**
|
|
|
* 重命名某个分组
|
|
|
*
|
|
|
* \param oldFile 旧名称
|
|
|
* \param newFile 新名称
|
|
|
* \return
|
|
|
*/
|
|
|
bool RenameGroup(const CString& oldFile, const CString& newFile);
|
|
|
|
|
|
/**
|
|
|
* 查找样式分组
|
|
|
*
|
|
|
* \param strLibName 组名称
|
|
|
* \return
|
|
|
*/
|
|
|
std::shared_ptr<CStyleLibraryItem> Find(const CString& strGroup) const;
|
|
|
|
|
|
/** @brief 查找组strGroup中名称为strName的符号 */
|
|
|
CLayer *FindStyle(const CString& strGroup, const CString& strName) const;
|
|
|
CHowToViewCurve* GetHowToViewCurve(const CString& strGroup, const CString& strName);
|
|
|
CHowToViewPoint* GetHowToViewPoint(const CString& strGroup, const CString& strName);
|
|
|
/**
|
|
|
* 根据名称查找样式
|
|
|
*
|
|
|
* \param strName 样式名
|
|
|
* \return
|
|
|
*/
|
|
|
CLayer* FindStyle(const CString& strName);
|
|
|
|
|
|
/**
|
|
|
* 重命名样式
|
|
|
*
|
|
|
* \param strGroup 样式分组
|
|
|
* \param oldName 旧样式名称
|
|
|
* \param newName 新样式名称
|
|
|
*/
|
|
|
void RenameStyle(const CString& strGroup, const CString& oldName, const CString& newName);
|
|
|
|
|
|
/**
|
|
|
* 保存所有样式
|
|
|
*
|
|
|
* \return
|
|
|
*/
|
|
|
bool SaveAll();
|
|
|
|
|
|
/**
|
|
|
* 应用样式到另一图件的其它图层
|
|
|
*
|
|
|
* \param group 样式分组
|
|
|
* \param style 样式名
|
|
|
* \param targetXy 目标图件
|
|
|
* \param targetLayerName 目标图层名
|
|
|
* \return 如果指定样式不存在(组不存在或该组没有该样式),或者目标图层不存在,返回 false,否则返回 true
|
|
|
*/
|
|
|
bool ApplyStyleTo(const CString& group, const CString& style, CXy* targetXy, const CString& targetLayerName);
|
|
|
|
|
|
/**
|
|
|
* 获取样式的类型, 0, 不存在, 1-线样式,2-点样式, 3-点和线样式都有.
|
|
|
**/
|
|
|
int GetStyleType(const CString& group, const CString& style);
|
|
|
/**
|
|
|
* 渲染样式到 HDC 中
|
|
|
*
|
|
|
* \param group 分组名称
|
|
|
* \param style 样式名称
|
|
|
* \param hdc 图像句柄
|
|
|
* \param width 宽度
|
|
|
* \param height 高度
|
|
|
*/
|
|
|
bool RenderStyle(const CString& group, const CString& style, HDC hdc, int width, int height) const;
|
|
|
private:
|
|
|
bool IsSameStyleLibraryPath(const CString& path) const;
|
|
|
void CopyHowtoViewCurve(const CLayer *pSourceLayer, CLayer* pTargetLayer) const;
|
|
|
void CopyHowtoViewPoint(const CLayer *pSourceLayer, CLayer* pTargetLayer) const;
|
|
|
void CopyHowtoViewMarkTo(CXy *pSourceXy, CHowToViewCurve *pHowToViewCurve, CHowToViewPoint* pHowToViewPoint, CXy* pTargetXy) const;
|
|
|
void CopyMarkTo(CXy *pSourceXy, CXy* pTargetXy, const CString& symbolName) const;
|
|
|
|
|
|
std::list<std::shared_ptr<CStyleLibraryItem>> m_libXy; ///< 符号库里面的文件XY链表
|
|
|
CString m_strPath;
|
|
|
};
|
|
|
}
|
|
|
|
|
|
extern "C" AFX_EXT_API StyleManager::CStyleLibraryManager & WINAPI AfxGetStyleLibMgr(); |