|
|
|
|
#include "FITKAbsGeoCommand.h"
|
|
|
|
|
#include "FITKAbsGeoShapeAgent.h"
|
|
|
|
|
|
|
|
|
|
// Global data
|
|
|
|
|
#include "FITK_Kernel/FITKCore/FITKDataRepo.h"
|
|
|
|
|
|
|
|
|
|
namespace Interface
|
|
|
|
|
{
|
|
|
|
|
FITKAbsGeoCommand::FITKAbsGeoCommand()
|
|
|
|
|
{
|
|
|
|
|
// 创建引用命令管理器。
|
|
|
|
|
m_referenceCmdList = new FITKGeoCommandManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FITKAbsGeoCommand::~FITKAbsGeoCommand()
|
|
|
|
|
{
|
|
|
|
|
if (_shapeAgent != nullptr) delete _shapeAgent;
|
|
|
|
|
|
|
|
|
|
// 析构引用数据管理器。(不析构管理数据对象)
|
|
|
|
|
if (m_referenceCmdList)
|
|
|
|
|
{
|
|
|
|
|
// 遍历所有引用移除。
|
|
|
|
|
int nRef = m_referenceCmdList->getDataCount();
|
|
|
|
|
for (int i = nRef - 1; i >= 0; i--)
|
|
|
|
|
{
|
|
|
|
|
FITKAbsGeoCommand* cmd = m_referenceCmdList->getDataByIndex(i);
|
|
|
|
|
if (!cmd)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 不减少引用对象引用计数并移出列表。
|
|
|
|
|
m_referenceCmdList->removeDataObjWithoutRelease(cmd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delete m_referenceCmdList;
|
|
|
|
|
m_referenceCmdList = nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FITKGeoEnum::FITKGeometryComType FITKAbsGeoCommand::getGeometryCommandType()
|
|
|
|
|
{
|
|
|
|
|
//抽象类,错误值
|
|
|
|
|
return FITKGeoEnum::FGTNone;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FITKAbsGeoCommand::update()
|
|
|
|
|
{
|
|
|
|
|
//错误值
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FITKAbsGeoCommand::undo()
|
|
|
|
|
{
|
|
|
|
|
// 执行撤销逻辑,将引用数据计数暂时屏蔽。
|
|
|
|
|
if (!m_referenceCmdList)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 遍历所有引用。
|
|
|
|
|
enableReferenceList(false);
|
|
|
|
|
|
|
|
|
|
// 撤销编辑。
|
|
|
|
|
FITKAbsGeoCommand* cmdMod = FITKDATAREPO->getTDataByID<FITKAbsGeoCommand>(m_modifiedCmdId);
|
|
|
|
|
if (cmdMod)
|
|
|
|
|
{
|
|
|
|
|
cmdMod->setCommandStatus(FITKGeoEnum::FITKGeoStatus::FGSNormal);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FITKAbsGeoCommand::redo()
|
|
|
|
|
{
|
|
|
|
|
// 执行重做逻辑,将引用数据计数恢复。
|
|
|
|
|
if (!m_referenceCmdList)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 遍历所有引用。
|
|
|
|
|
enableReferenceList(true);
|
|
|
|
|
|
|
|
|
|
// 重做编辑。
|
|
|
|
|
FITKAbsGeoCommand* cmdMod = FITKDATAREPO->getTDataByID<FITKAbsGeoCommand>(m_modifiedCmdId);
|
|
|
|
|
if (cmdMod)
|
|
|
|
|
{
|
|
|
|
|
cmdMod->setCommandStatus(FITKGeoEnum::FITKGeoStatus::FGSModified);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FITKAbsGeoCommand::setCommandStatus(FITKGeoEnum::FITKGeoStatus status)
|
|
|
|
|
{
|
|
|
|
|
// 获取命令状态。
|
|
|
|
|
m_status = status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FITKGeoEnum::FITKGeoStatus FITKAbsGeoCommand::getCommandStatus()
|
|
|
|
|
{
|
|
|
|
|
return m_status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Interface::FITKAbsGeoShapeAgent* FITKAbsGeoCommand::getShapeAgent()
|
|
|
|
|
{
|
|
|
|
|
return _shapeAgent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Interface::FITKVirtualTopoManager* FITKAbsGeoCommand::getVirtualTopoManager()
|
|
|
|
|
{
|
|
|
|
|
if (!_shapeAgent)
|
|
|
|
|
{
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _shapeAgent->getVirtualTopoManager();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FITKAbsGeoCommand::enableReferenceList(bool flag)
|
|
|
|
|
{
|
|
|
|
|
if (flag && !m_enableRefer)
|
|
|
|
|
{
|
|
|
|
|
int nRef = m_referenceCmdList->getDataCount();
|
|
|
|
|
for (int i = nRef - 1; i >= 0; i--)
|
|
|
|
|
{
|
|
|
|
|
FITKAbsGeoCommand* cmd = m_referenceCmdList->getDataByIndex(i);
|
|
|
|
|
if (!cmd)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 增加引用对象引用计数。
|
|
|
|
|
cmd->m_referenceCount++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (!flag && m_enableRefer)
|
|
|
|
|
{
|
|
|
|
|
int nRef = m_referenceCmdList->getDataCount();
|
|
|
|
|
for (int i = nRef - 1; i >= 0; i--)
|
|
|
|
|
{
|
|
|
|
|
FITKAbsGeoCommand* cmd = m_referenceCmdList->getDataByIndex(i);
|
|
|
|
|
if (!cmd)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 增加引用对象引用计数。
|
|
|
|
|
cmd->m_referenceCount--;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 保存状态。
|
|
|
|
|
m_enableRefer = flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FITKAbsGeoCommand::getEnableReferenceList()
|
|
|
|
|
{
|
|
|
|
|
return m_enableRefer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int FITKAbsGeoCommand::getReferenceCount()
|
|
|
|
|
{
|
|
|
|
|
// 返回被引用计数。
|
|
|
|
|
return m_referenceCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FITKAbsGeoCommand::addOneReference()
|
|
|
|
|
{
|
|
|
|
|
m_referenceCount++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FITKAbsGeoCommand::removeOneReference()
|
|
|
|
|
{
|
|
|
|
|
if (m_referenceCount > 0)
|
|
|
|
|
{
|
|
|
|
|
m_referenceCount--;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FITKAbsGeoCommand::addReferenceCmdID(int id)
|
|
|
|
|
{
|
|
|
|
|
// 获取需要添加引用的命令数据对象。
|
|
|
|
|
FITKAbsGeoCommand* cmd = FITKDATAREPO->getTDataByID<FITKAbsGeoCommand>(id);
|
|
|
|
|
addReferenceCmdObj(cmd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FITKAbsGeoCommand::addReferenceCmdObj(FITKAbsGeoCommand* cmd, bool isSet)
|
|
|
|
|
{
|
|
|
|
|
if (!cmd || !m_referenceCmdList)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 判断数据是否已被引用。
|
|
|
|
|
bool contains = m_referenceCmdList->isContains(cmd);
|
|
|
|
|
if (contains)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 将添加的被引用对象引用计数加1。
|
|
|
|
|
if (!isSet)//不是工程读取设置的则执行以下逻辑
|
|
|
|
|
cmd->m_referenceCount++;
|
|
|
|
|
|
|
|
|
|
// 存储引用对象。
|
|
|
|
|
m_referenceCmdList->appendDataObj(cmd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FITKAbsGeoCommand::removeReferenceCmdID(int id)
|
|
|
|
|
{
|
|
|
|
|
// 获取需要移除引用的命令数据对象。
|
|
|
|
|
FITKAbsGeoCommand* cmd = FITKDATAREPO->getTDataByID<FITKAbsGeoCommand>(id);
|
|
|
|
|
removeReferenceCmdObj(cmd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FITKAbsGeoCommand::removeReferenceCmdObj(FITKAbsGeoCommand* cmd)
|
|
|
|
|
{
|
|
|
|
|
if (!cmd || !m_referenceCmdList)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 判断数据是否被引用。
|
|
|
|
|
bool contains = m_referenceCmdList->isContains(cmd);
|
|
|
|
|
if (!contains)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 将移除的被引用对象引用计数减1。
|
|
|
|
|
cmd->m_referenceCount--;
|
|
|
|
|
|
|
|
|
|
// 移除引用对象。
|
|
|
|
|
m_referenceCmdList->removeDataObjWithoutRelease(cmd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FITKAbsGeoCommand::clearReference()
|
|
|
|
|
{
|
|
|
|
|
if (!m_referenceCmdList)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 遍历所有引用移除。
|
|
|
|
|
int nRef = m_referenceCmdList->getDataCount();
|
|
|
|
|
for (int i = nRef - 1; i >= 0; i--)
|
|
|
|
|
{
|
|
|
|
|
FITKAbsGeoCommand* cmd = m_referenceCmdList->getDataByIndex(i);
|
|
|
|
|
if (!cmd)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 减少引用对象引用计数并移出列表。
|
|
|
|
|
cmd->m_referenceCount--;
|
|
|
|
|
m_referenceCmdList->removeDataObjWithoutRelease(cmd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int FITKAbsGeoCommand::getReferenceCmdCount()
|
|
|
|
|
{
|
|
|
|
|
if (!m_referenceCmdList)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取引用命令列表长度。
|
|
|
|
|
return m_referenceCmdList->getDataCount();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FITKAbsGeoCommand* FITKAbsGeoCommand::getReferenceCmdByIndex(int index)
|
|
|
|
|
{
|
|
|
|
|
if (!m_referenceCmdList)
|
|
|
|
|
{
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 返回第i条命令。
|
|
|
|
|
return m_referenceCmdList->getDataByIndex(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FITKAbsGeoCommand::getDataValidInGUI()
|
|
|
|
|
{
|
|
|
|
|
// 被移除、被修改或者删除命令无需显示。
|
|
|
|
|
if (this->getCommandStatus() == Interface::FITKGeoEnum::FITKGeoStatus::FGSDeleted ||
|
|
|
|
|
this->getCommandStatus() == Interface::FITKGeoEnum::FITKGeoStatus::FGSModified ||
|
|
|
|
|
this->getGeometryCommandType() == Interface::FITKGeoEnum::FITKGeometryComType::FGTDelete)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FITKAbsGeoCommand::setModifiedCmdID(int id)
|
|
|
|
|
{
|
|
|
|
|
// 检查数据ID并保存。
|
|
|
|
|
FITKAbsGeoCommand* cmd = FITKDATAREPO->getTDataByID<FITKAbsGeoCommand>(id);
|
|
|
|
|
if (cmd)
|
|
|
|
|
{
|
|
|
|
|
m_modifiedCmdId = id;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int FITKAbsGeoCommand::getModifiedCmdID()
|
|
|
|
|
{
|
|
|
|
|
FITKAbsGeoCommand* cmd = FITKDATAREPO->getTDataByID<FITKAbsGeoCommand>(m_modifiedCmdId);
|
|
|
|
|
if (!cmd)
|
|
|
|
|
{
|
|
|
|
|
m_modifiedCmdId = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return m_modifiedCmdId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FITKAbsGeoCommand::hasModifiedCommand()
|
|
|
|
|
{
|
|
|
|
|
// 被编辑命令不为空则为编辑命令。
|
|
|
|
|
FITKAbsGeoCommand* cmd = FITKDATAREPO->getTDataByID<FITKAbsGeoCommand>(m_modifiedCmdId);
|
|
|
|
|
return cmd != nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|