/* * 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 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 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(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<type() == ModuleConnectGraphicsItem::Type ) { ModuleConnectGraphicsItem *pConnectLine = static_cast(pItem); ModuleGraphicsItem* pStartItem = pConnectLine->GetStartItem(); existFlg = 0; for(int i=0;i (m_pCopyItems.at(i)); existFlg = 1; break; } } if( existFlg == 0 )pStartItem = NULL; ModuleGraphicsItem* pEndItem = pConnectLine->GetEndItem(); existFlg = 0; for(int i=0;i(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); } } }