logplus/ModuleConsole/command/src/CopyModuleCmd.cpp
2026-01-16 17:18:41 +08:00

122 lines
3.1 KiB
C++

/*
* CopyModuleCmd.cpp
*
* Created on: 2012-10-9
* Author: liujunxia
*/
#include "CopyModuleCmd.h"
#include "ModuleGraphicsItem.h"
#include "ModuleInformation.h"
#include "ModuleConnectGraphicsItem.h"
#include "PaiWorkflowDataModel.h"
#include "PluginManager.h"
#include "WorkflowPlugin.h"
#include "GlobalWorkflowItems.h"
using namespace pai::graphics2d;
using namespace pai::workflow;
namespace pai
{
namespace graphics2d
{
CopyModuleCmd::CopyModuleCmd(pai::objectmodel::PaiWorkflowDataModel *pWorkflow, QList<QGraphicsItem*> list,
QUndoCommand *parent)
:QUndoCommand(parent)
{
m_pWorkflow = pWorkflow;
m_list = list;
}
CopyModuleCmd::~CopyModuleCmd()
{
}
void CopyModuleCmd::undo()
{
}
void CopyModuleCmd::redo()
{
copyGraphicItems();
}
void CopyModuleCmd::copyGraphicItems()
{
if(m_list.count() == 0)
return;
QList<QGraphicsItem*> oldModuleItem; // original module items ID
oldModuleItem.clear();
m_pCopyItems.clear();
foreach(QGraphicsItem* pItem, m_list )
{
if( pItem == NULL ) continue;
if(pItem->type() == ModuleGraphicsItem::Type)
{
ModuleGraphicsItem* pModule = static_cast<ModuleGraphicsItem*>(pItem);
CModuleInformation* pInfo = pModule->GetModule();
CModuleInformation* pInf = new CModuleInformation(*pInfo);
PaiModuleStyle* pStyle = m_pWorkflow->GetModuleStyle(pInfo->GetStepID());
PaiModuleStyle* pSty = new PaiModuleStyle();
pSty->Copy(*pStyle);
ModuleGraphicsItem* pMod = new ModuleGraphicsItem(pInf,pSty,true);
if( pMod != NULL )
{
m_pCopyItems << (QGraphicsItem*)pMod;
oldModuleItem<<pItem;
}
}
}
int existFlg = 0;
foreach(QGraphicsItem* pItem, m_list )
{
if( pItem->type() == ModuleConnectGraphicsItem::Type )
{
ModuleConnectGraphicsItem *pConnectLine = static_cast<ModuleConnectGraphicsItem*>(pItem);
ModuleGraphicsItem* pStartItem = pConnectLine->GetStartItem();
existFlg = 0;
for(int i=0;i<oldModuleItem.count();i++)
{
if( pStartItem == oldModuleItem.at(i) )
{
pStartItem = static_cast<ModuleGraphicsItem*> (m_pCopyItems.at(i));
existFlg = 1;
break;
}
}
if( existFlg == 0 )pStartItem = NULL;
ModuleGraphicsItem* pEndItem = pConnectLine->GetEndItem();
existFlg = 0;
for(int i=0;i<oldModuleItem.count();i++)
{
if( pEndItem == oldModuleItem.at(i) )
{
pEndItem = static_cast<ModuleGraphicsItem*>(m_pCopyItems.at(i));
existFlg = 1;
break;
}
}
if( existFlg == 0 )pEndItem = NULL;
int nStartPortIndex = pConnectLine->GetStartPortIndex();
int nEndPortIndex = pConnectLine->GetEndPortIndex();
if( pStartItem != NULL && pEndItem != NULL )
{
ModuleConnectGraphicsItem *pConnectLine =
new ModuleConnectGraphicsItem(pStartItem,nStartPortIndex,pEndItem,nEndPortIndex);
if( pConnectLine != NULL )
m_pCopyItems << (QGraphicsItem*)pConnectLine;
}
}
}
oldModuleItem.clear();
GlobalWorkflowItems::GetInstance()->SetCopyGraphicItems(m_pCopyItems);
}
}
}