You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
AppFlow/FITK_Interface/FITKInterfaceGeometry/FITKAbsGeoCommand.h

428 lines
14 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/**
*
* @file FITKAbsGeoCommand.h
* @brief 几何命令创建基类
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-07-12
*
*/
#ifndef _FITKABS_GEO_COMMAND_H___
#define _FITKABS_GEO_COMMAND_H___
#include "FITKInterfaceGeometryAPI.h"
#include "FITKGeoEnum.h"
#include "FITK_Kernel/FITKCore/FITKAbstractNDataObject.h"
#include "FITK_Kernel/FITKCore/FITKVarientParams.h"
#include "FITK_Interface/FITKInterfaceModel/FITKModelEnum.h"
#include "FITK_Interface/FITKInterfaceGeometry/FITKAbsGeoShapeAgent.h"
#include "FITK_Interface/FITKInterfaceGeometry/FITKVirtualTopoManager.h"
#include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h"
#include "FITK_Kernel/FITKAppFramework/FITKSignalTransfer.h"
#include "FITK_Kernel/FITKCore/FITKAbstractDataManager.hpp"
namespace Interface
{
class FITKGeoCommandManager;
/**
* @brief 虚拓扑形状.
* @author YanZhiHui (chanyuantiandao@126.com)
* @date 2024-08-22
*/
class VirtualShape {
public:
/**
* @brief 命令CommandID.
* @author YanZhiHui (chanyuantiandao@126.com)
* @date 2024-08-22
*/
int CmdId{ 0 };
/**
* @brief 虚拓扑ID.
* @author YanZhiHui (chanyuantiandao@126.com)
* @date 2024-08-22
*/
int VirtualTopoId{ 0 };
/**
* @brief 是否为空形状.
* @author YanZhiHui (chanyuantiandao@126.com)
* @date 2024-08-22
*/
bool isNull() const { return CmdId <= 0 || VirtualTopoId <= 0; }
/**
* @brief 重置形状,置空(isNull() == true).
* @author YanZhiHui (chanyuantiandao@126.com)
* @date 2024-08-22
*/
void reset() { CmdId = 0; VirtualTopoId = 0; }
/**
* @brief 重载运算符.
* @author YanZhiHui (chanyuantiandao@126.com)
* @date 2024-08-22
*/
bool operator==(const VirtualShape& other) {
return (CmdId == other.CmdId) && (VirtualTopoId == other.VirtualTopoId);
}
friend bool operator==(const VirtualShape& shape1, const VirtualShape& shape2);
};
inline bool operator==(const VirtualShape& shape1, const VirtualShape& shape2) {
return (shape1.CmdId == shape2.CmdId) && (shape1.VirtualTopoId == shape2.VirtualTopoId);
}
/**
* @brief 几何命令抽象类
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-07-12
*/
class FITKInterfaceGeometryAPI FITKAbsGeoCommand : public Core::FITKAbstractNDataObject,
public Core::FITKVarientParams
{
Q_OBJECT
FITKCLASS(Interface, FITKAbsGeoCommand);
public:
/**
* @brief Construct a new FITKAbsGeoCommand object
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-07-12
*/
explicit FITKAbsGeoCommand();
/**
* @brief Destroy the FITKAbsGeoCommand object
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-07-12
*/
virtual ~FITKAbsGeoCommand() = 0;
/**
* @brief 获取几何命令类型
* @return FITKGeoEnum::FITKGeometryComType
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-07-12
*/
virtual FITKGeoEnum::FITKGeometryComType getGeometryCommandType() = 0;
/**
* @brief 更新模型
* @return true
* @return false
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-07-12
*/
virtual bool update() = 0;
/**
* @brief 执行撤销逻辑。(非必须)[虚函数]
* @return 是否执行成功。
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-09-06
*/
virtual bool undo();
/**
* @brief 执行重做逻辑。(非必须)[虚函数]
* @return 是否执行成功。
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-09-06
*/
virtual bool redo();
/**
* @brief 设置命令状态。
* @param status状态枚举
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-09-06
*/
void setCommandStatus(FITKGeoEnum::FITKGeoStatus status);
/**
* @brief 获取命令状态。
* @return 状态枚举
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-09-06
*/
FITKGeoEnum::FITKGeoStatus getCommandStatus();
/**
* @brief 获取形状代理器
* @return FITKAbsGeoShapeAgent
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-07-30
*/
FITKAbsGeoShapeAgent* getShapeAgent();
/**
* @brief 获取shape.
* @param type 拓扑类型
* @param id 虚拓扑ID
* @return shape
* @author YanZhiHui (chanyuantiandao@126.com)
* @date 2024-08-20
*/
template<typename T>
T* getShapeT(Interface::FITKGeoEnum::VTopoShapeType type, int id) {
auto shapeAgent = getShapeAgent();
if (shapeAgent == nullptr) return nullptr;
auto manager = shapeAgent->getVirtualTopoManager();
if (manager == nullptr) return nullptr;
auto shapeManager = manager->getShapeVirtualTopoManager(type);
if (shapeManager == nullptr) return nullptr;
auto virShape = shapeManager->getDataByID(id);
if (virShape == nullptr) return nullptr;
return virShape->getShapeT<T>();
}
/**
* @brief 获取shape.
* @param id 虚拓扑ID
* @return shape
* @author YanZhiHui (chanyuantiandao@126.com)
* @date 2024-08-20
*/
template<typename T>
T* getShapeT(int id) {
auto shapeAgent = getShapeAgent();
if (shapeAgent == nullptr) return nullptr;
auto manager = shapeAgent->getVirtualTopoManager();
if (manager == nullptr) return nullptr;
for (int type = static_cast<int>(FITKGeoEnum::VTopoShapeType::VSPoint); type < static_cast<int>(FITKGeoEnum::VTopoShapeType::VSAssembly); ++type) {
auto shapeManager = manager->getShapeVirtualTopoManager(static_cast<FITKGeoEnum::VTopoShapeType>(type));
if (shapeManager == nullptr) continue;
auto virShape = shapeManager->getDataByID(id);
if (virShape == nullptr) continue;
return virShape->getShapeT<T>();
}
return nullptr;
}
/**
* @brief 获取虚拓扑管理器。
* @return ShapeAgent中的虚拓扑管理器
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-08-20
*/
FITKVirtualTopoManager* getVirtualTopoManager();
template<class T>
/**
* @brief 获取形状代理器
* @return FITKAbsGeoShapeAgent
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-07-30
*/
T* getTShapeAgent()
{
return dynamic_cast<T*>(_shapeAgent);
}
/**
* @brief 打印信息到控制台.
* @param type 信息类型 1-normal 2-warning 3-error 4-info
* @param msg 信息内容
* @author YanZhiHui (chanyuantiandao@126.com)
* @date 2024-08-28
*/
void printLog(QString msg, int type = 1)
{
AppFrame::FITKSignalTransfer* sigTrans = FITKAPP->getSignalTransfer();
if (sigTrans)
{
sigTrans->outputMessageSig(type, msg);
}
}
/**
* @brief 开启或关闭引用数据计数。
* @param flag开启或关闭。
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-09-07
*/
void enableReferenceList(bool flag);
/**
* @brief 过去引用数据计数状态。
* @return 开启或关闭。
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-09-07
*/
bool getEnableReferenceList();
/**
* @brief 获取被引用计数。
* @return 被引用次数
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-09-07
*/
int getReferenceCount();
/**
* @brief 添加一次引用计数。
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-09-07
*/
void addOneReference();
/**
* @brief 移除一次引用计数。
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-09-07
*/
void removeOneReference();
/**
* @brief 添加引用的命令ID。
* @param id命令ID
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-09-07
*/
void addReferenceCmdID(int id);
/**
* @brief 添加引用的命令对象。
* @param cmd命令对象
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-09-07
*/
void addReferenceCmdObj(FITKAbsGeoCommand* cmd, bool isSet = false);
/**
* @brief 移除引用的命令ID。
* @param id命令ID
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-09-07
*/
void removeReferenceCmdID(int id);
/**
* @brief 移除引用的命令对象。
* @param cmd命令对象
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-09-07
*/
void removeReferenceCmdObj(FITKAbsGeoCommand* cmd);
/**
* @brief 清空引用命令。[虚函数]
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-09-07
*/
virtual void clearReference();
/**
* @brief 获取当前命令所引用的命令数量。
* @return 引用命令列表长度
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-09-07
*/
int getReferenceCmdCount();
/**
* @brief 根据索引获取当前命令引用的命令。
* @param index命令索引
* @return 引用命令对象
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-09-07
*/
FITKAbsGeoCommand* getReferenceCmdByIndex(int index);
/**
* @brief 获取数据的界面有效性:指是否为当前实际需要显示在模型树的数据。
* @return 是否需要显示在模型树
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-09-07
*/
bool getDataValidInGUI();
/**
* @brief 保存被编辑命令数据ID。
* @param id被编辑命令数据ID
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-09-07
*/
void setModifiedCmdID(int id);
/**
* @brief 获取被编辑命令数据ID。
* @return 被编辑命令数据ID
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-09-07
*/
int getModifiedCmdID();
/**
* @brief 是否为编辑类型命令。
* @param 是否为编辑类型
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-09-07
*/
bool hasModifiedCommand();
protected:
/**
* @brief 几何形状代理器
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-07-30
*/
FITKAbsGeoShapeAgent* _shapeAgent{};
/**
* @brief 命令状态。
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-09-06
*/
FITKGeoEnum::FITKGeoStatus m_status = FITKGeoEnum::FGSNormal;
/**
* @brief 引用的命令列表。
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-09-07
*/
FITKGeoCommandManager* m_referenceCmdList{ nullptr };
/**
* @brief 命令被引用次数。
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-09-07
*/
int m_referenceCount = 0;
/**
* @brief 编辑的命令数据ID。
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-09-07
*/
int m_modifiedCmdId = -1;
/**
* @brief 是否启用引用计数。
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-09-07
*/
bool m_enableRefer = true;
};
/**
* @brief 几何命令容器。
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-09-06
*/
class FITKInterfaceGeometryAPI FITKGeoCommandManager : public Core::FITKAbstractDataManager<FITKAbsGeoCommand>
{
public:
/**
* @brief 构造函数。
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-09-06
*/
explicit FITKGeoCommandManager() = default;
/**
* @brief 析构函数。
* @author ChengHaotian (yeguangbaozi@foxmail.com)
* @date 2024-09-06
*/
virtual ~FITKGeoCommandManager() = default;
};
}
#endif