/* * @file AddLineCmd.h * @brief AddLineCmd是为工作流编辑界面模块添加连线的命令 * @date: 2012-10-10 * @author: limengzhuo */ #ifndef PAI_FRAME_WORKFLOWVIEW_ADDLINECMD_H #define PAI_FRAME_WORKFLOWVIEW_ADDLINECMD_H #include #include #include "ModuleConnection.h" namespace pai { namespace objectmodel { class PaiWorkflowDataModel; } namespace graphics2d { class ModuleGraphicsItem; class WorkflowSceneManager; } /** * @class AddLineCmd * @brief AddLineCmd是为工作流编辑界面模块添加连线的命令 */ class AddLineCmd :public QUndoCommand { public: /** * @brief 构造函数 * @param[in] pSceneManager 场景 * @param[in] pWorkflow 工作流 * @param[in] pStartItem 开始Item * @param[in] pEndItem 结束Item * @param[in] parent 命令的父亲 */ AddLineCmd(pai::graphics2d::WorkflowSceneManager *pSceneManager, pai::objectmodel::PaiWorkflowDataModel *pWorkflow, pai::graphics2d::ModuleGraphicsItem *pStartItem, pai::graphics2d::ModuleGraphicsItem *pEndItem, QUndoCommand *pParent = 0); /** * @brief 构造函数 * @param[in] pSceneManager 场景 * @param[in] pWorkflow 工作流 * @param[in] pStartItem 开始Item * @param[in] pEndItem 结束Item * @param[in] nStartPortIndex 开始端口 * @param[in] nEndPortIndex 结束端口 * @param[in] parent 命令的父亲 */ AddLineCmd(pai::graphics2d::WorkflowSceneManager *pSceneManager, pai::objectmodel::PaiWorkflowDataModel *pWorkflow, pai::graphics2d::ModuleGraphicsItem *pStartItem, pai::graphics2d::ModuleGraphicsItem *pEndItem, int nStartPortIndex, int nEndPortIndex, QUndoCommand *pParent = 0); /** * @biref 析构函数 */ virtual ~AddLineCmd(); /** * @brief 撤销操作 */ void undo(); /** * @brief 添加连线操作 */ void redo(); /** *@brief 判断端口连线是否已经存在 */ bool GetPortHasbeenLined(); /** * @brief 设置连线开始模块的stepID * @param[in] first 开始模块的stepID */ void SetFirstStepID(int first); /** * @brief 设置连线结束模块的stepID * @param[in] second 结束模块的stepID */ void SetSecondStepID(int second); private: /** * @brief 删除添加的连线 */ void RemoveLine(); /** * @brief 添加连线 */ void AddLine(); /** * @brief 检查两模块间是否有生成环路的可能 * @param[in] pStartItem 期望连线的开始模块 * @param[in] pEndItem 期望连线的中止模块 */ bool DetectCircle(pai::graphics2d::ModuleGraphicsItem *pStartItem, pai::graphics2d::ModuleGraphicsItem *pEndItem); private: enum AddLineType { AddLineType_General = 0, //只选定了两个模块添加连线 AddLineType_Destinated = 1, //选定了两个模块,并明确了起点和终点端口,添加连线的情况 }; pai::graphics2d::WorkflowSceneManager *m_pSceneManager; //场景 pai::objectmodel::PaiWorkflowDataModel* m_pWorkflow; //工作流模型 workflow::CModuleConnection* m_pConnection; //被添加连线指针 int m_nStepIdFirst; //开始Item的stepID int m_nStepIdSecond; //结束Item的stepID int m_nStartPortIndex; //连线起点的端口 int m_nEndPortIndex; //连线终点的端口 AddLineType m_type; //连线添加的类型,见AddLineType bool m_bPortBeenLined; //端口是否被连线 }; } #endif /* PAI_FRAME_WORKFLOWVIEW_ADDLINECMD_H */