901 lines
31 KiB
C++
901 lines
31 KiB
C++
/**
|
||
* @file GeneralWorkflowScene.cpp
|
||
* @brief 作业,日志的场景
|
||
*/
|
||
#include <QtAlgorithms>
|
||
#include <QtDebug>
|
||
#include <QGraphicsView>
|
||
#include <QApplication>
|
||
#include <QClipboard>
|
||
#include <QScrollBar>
|
||
#include <QtDebug>
|
||
#include <iostream>
|
||
#include <QAction>
|
||
#include <QGraphicsSceneMouseEvent>
|
||
|
||
#include "GeneralWorkflowScene.h"
|
||
// #include "ModuleGraphicsItem.h"
|
||
// #include "ModuleInformation.h"
|
||
// #include "ModuleConnectGraphicsItem.h"
|
||
// #include "PaiWorkflowDataModel.h"
|
||
// #include "ModuleConnection.h"
|
||
// #include "ModuleManager.h"
|
||
// #include "PaiModuleStyle.h"
|
||
#include "ModuleToolBarGraphicsItem.h"
|
||
// #include "ModuleCheckResult.h"
|
||
// #include "ModulePortInfoGraphicsItem.h"
|
||
#include "ModuleMonitorGraphicsItem.h"
|
||
// #include "PaiGeoObject.h"
|
||
// #include "PaiSeisData.h"
|
||
// #include "PaiDataMaster.h"
|
||
// #include "PaiJob.h"
|
||
// #include "PaiLineEdit.h"
|
||
#include "WorkflowConst.h"
|
||
// #include "PaiLineEdit.h"
|
||
// #include "Utils.h"
|
||
// #include "PAIConst.h"
|
||
// #include "Log.h"
|
||
// #include "ConsoleGUIService.h"
|
||
#include "WorkflowWidget.h"
|
||
// #include "WorkFlowFile.h"
|
||
#include "ModelProgressGraphicsItem.h"
|
||
#include "PaiJobSummaryItem.h"
|
||
#include "PaiJobParameterItem.h"
|
||
#include "PaiJobErrorInfoItem.h"
|
||
#include "PaiJobErrorInfoWidget.h"
|
||
#include "PaiJobSummaryWidget.h"
|
||
|
||
using namespace pai;
|
||
using namespace pai::graphics2d;
|
||
using namespace pai::objectmodel;
|
||
using namespace pai::gui;
|
||
using namespace pai::workflow;
|
||
|
||
int const BOTTOM_MARGIN = 20;
|
||
int const RIGHT_MARGIN = 20;
|
||
int const SUMMARY_EDGE = 80;
|
||
int const SUMMARY_EDGEHEIGHT = -25;
|
||
int const JOBERROR_EDGE = 550;
|
||
int const JOBERROR_EDGEHEIGHT = 240;
|
||
int const JOBSECENVIEW_WIDTH = 1577;
|
||
int const JOBSECENVIEW_HEIGHT = 520;
|
||
|
||
GeneralWorkflowScene::GeneralWorkflowScene(qreal x, qreal y, qreal width, qreal height, QObject *pParant) :
|
||
QGraphicsScene(pParant),
|
||
m_pWorkflow(NULL),
|
||
// m_pModuleToolBarItem(new ModuleToolBarGraphicsItem()),
|
||
m_pJobErrorInfoItem(NULL),
|
||
m_pJob(NULL),
|
||
m_pSummaryItem(NULL),
|
||
m_pWorkflowWidget(NULL),
|
||
m_IsChangeTableWidget(false),
|
||
m_IsAddErrorInfo(false),
|
||
m_ErrorInfoItem(false),
|
||
m_ScenceReadOnly(false),
|
||
m_JobType(false)
|
||
{
|
||
m_OriginalSceneRect = QRectF(x, y, width, height);
|
||
// m_pModuleToolBarItem->SetToolBarVisible(false);
|
||
// addItem(m_pModuleToolBarItem);
|
||
|
||
connect(this, SIGNAL(changed(const QList<QRectF> &)), this, SLOT(UpdateScene(const QList<QRectF> &)));
|
||
connect(this, SIGNAL(UpdateSceneRect()), this, SLOT(SceneRectAutoAdaptive()));
|
||
}
|
||
|
||
GeneralWorkflowScene::~GeneralWorkflowScene()
|
||
{
|
||
|
||
}
|
||
|
||
void GeneralWorkflowScene::UpdateScene(const QList< QRectF > & /*region*/)
|
||
{
|
||
// foreach(QGraphicsItem *pItem, items())
|
||
// {
|
||
// if(pItem->type() == pai::graphics2d::ModuleConnectGraphicsItem::Type)
|
||
// {
|
||
// ModuleConnectGraphicsItem* pConnectionItem = dynamic_cast<ModuleConnectGraphicsItem*> (pItem);
|
||
// if (pConnectionItem)
|
||
// {
|
||
// pConnectionItem->UpdatePosition();
|
||
// }
|
||
// }
|
||
|
||
// if(pItem->type() == ModelProgressGraphicsItem::Type)
|
||
// {
|
||
// ModelProgressGraphicsItem *pBarItem = dynamic_cast<ModelProgressGraphicsItem*> (pItem);
|
||
// if(NULL != pBarItem)
|
||
// {
|
||
// pBarItem->UpdatePosition();
|
||
// }
|
||
// }
|
||
|
||
// if(pItem->type() == PaiJobSummaryItem::Type)
|
||
// {
|
||
// PaiJobSummaryItem *pSummaryItem = dynamic_cast<PaiJobSummaryItem*> (pItem);
|
||
// if(NULL != pSummaryItem)
|
||
// {
|
||
// pSummaryItem->UpdatePosition();
|
||
// }
|
||
// }
|
||
|
||
// if(pItem->type() == PaiJobParameterItem::Type)
|
||
// {
|
||
// PaiJobParameterItem *pParamerItem = dynamic_cast<PaiJobParameterItem*> (pItem);
|
||
// if(NULL != pParamerItem)
|
||
// {
|
||
// pParamerItem->UpdatePosition();
|
||
// }
|
||
// }
|
||
// }
|
||
}
|
||
|
||
void GeneralWorkflowScene::ExpandSceneRect()
|
||
{
|
||
// if(views().count() <= 0)
|
||
// {
|
||
// return;
|
||
// }
|
||
// QRectF scenerect(sceneRect());
|
||
// scenerect.setWidth(10);
|
||
// scenerect.setHeight(10);
|
||
// views().at(0)->setSceneRect(scenerect);
|
||
// QList< QGraphicsItem* > lstItems = items();
|
||
// if(lstItems.count() > 0)
|
||
// {
|
||
// QGraphicsItem* pMostRightItem = lstItems.at(0);
|
||
// QGraphicsItem* pMostBottomItem = lstItems.at(0);
|
||
// foreach(QGraphicsItem* pItem,lstItems)
|
||
// {
|
||
// if(pItem->pos().x() > pMostRightItem->pos().x())
|
||
// {
|
||
// pMostRightItem=pItem;
|
||
// }
|
||
// if(pItem->pos().y() > pMostBottomItem->pos().y())
|
||
// {
|
||
// pMostBottomItem=pItem;
|
||
// }
|
||
// }
|
||
// ModuleGraphicsItem *pModuleItem = dynamic_cast< ModuleGraphicsItem* > (pMostRightItem);
|
||
// if(pModuleItem && pModuleItem->GetModule())
|
||
// {
|
||
// ExpandSceneRectIfNeeded(pModuleItem->GetModule()->GetStepID());
|
||
// }
|
||
|
||
// pModuleItem = dynamic_cast< ModuleGraphicsItem* > (pMostBottomItem);
|
||
// if(pModuleItem && pModuleItem->GetModule())
|
||
// {
|
||
// ExpandSceneRectIfNeeded(pModuleItem->GetModule()->GetStepID());
|
||
// }
|
||
// }
|
||
}
|
||
|
||
void GeneralWorkflowScene::AddWorkflow(pai::objectmodel::PaiWorkflowDataModel* pWorkflow, bool jobRelated)
|
||
{
|
||
// if(!pWorkflow)
|
||
// {
|
||
// return;
|
||
// }
|
||
|
||
// m_pWorkflow = pWorkflow;
|
||
|
||
// //添加模块图元
|
||
// int moduleCount = pWorkflow->GetModuleCount();
|
||
// for(int i = 0; i < moduleCount; ++i)
|
||
// {
|
||
// CModuleInformation *pModule = pWorkflow->GetModule(i);
|
||
// if(!pModule)
|
||
// {
|
||
// continue;
|
||
// }
|
||
|
||
// if(pModule->GetName() == "RealTimeModule")
|
||
// {
|
||
// //目前不做任何事情
|
||
// }
|
||
// else
|
||
// {
|
||
// ModuleGraphicsItem *pModuleItem = AddModule(pModule,
|
||
// pWorkflow->GetModuleStyle(pModule->GetStepID()),
|
||
// jobRelated);
|
||
// if(!pModuleItem)
|
||
// {
|
||
// continue;
|
||
// }
|
||
|
||
// pModuleItem->SetWorkflow(m_pWorkflow);
|
||
// pModuleItem->SetInitialValidated(true);
|
||
// }
|
||
// }
|
||
// //添加模块之间的连线
|
||
// int connectionCount = pWorkflow->GetConnectionCount();
|
||
// for(int i = 0; i < connectionCount; ++i)
|
||
// {
|
||
// AddConnection(pWorkflow->GetConnection(i));
|
||
// }
|
||
}
|
||
|
||
pai::graphics2d::ModuleMonitorGraphicsItem* GeneralWorkflowScene::AddMonitorModule(CModuleInformation *pModule,
|
||
pai::graphics2d::PaiModuleStyle *pStyle,
|
||
bool jobRelated)
|
||
{
|
||
return NULL;
|
||
// if((NULL == pModule) || (NULL == pStyle))
|
||
// {
|
||
// return NULL;
|
||
// }
|
||
// //添加监控
|
||
// ModuleMonitorGraphicsItem *pMonitor = new ModuleMonitorGraphicsItem(pModule, pStyle, jobRelated);
|
||
// addItem(pMonitor);
|
||
// return pMonitor;
|
||
}
|
||
|
||
void GeneralWorkflowScene::SetWorkflowWidget(WorkflowWidget *pWorkflowWidget)
|
||
{
|
||
if(pWorkflowWidget != NULL)
|
||
{
|
||
m_pWorkflowWidget = pWorkflowWidget;
|
||
}
|
||
}
|
||
|
||
void GeneralWorkflowScene::AddJob(pai::objectmodel::PaiJob* pJob, bool jobType)
|
||
{
|
||
// if(!pJob)
|
||
// {
|
||
// return;
|
||
// }
|
||
|
||
// m_pJob = pJob;
|
||
// m_JobType = jobType;
|
||
|
||
// int rightItemX = 0; // 场景中最右端item的x坐标
|
||
// QMap< ModuleGraphicsItem*, ModelProgressGraphicsItem* > topPorts;
|
||
// QMap< ModuleGraphicsItem*, ModelProgressGraphicsItem* > bottomPorts;
|
||
|
||
// foreach(QGraphicsItem *pItem, items())
|
||
// {
|
||
// if(pItem->type() == ModuleGraphicsItem::Type)
|
||
// {
|
||
// ModuleGraphicsItem *pModuleItem = dynamic_cast<ModuleGraphicsItem*>(pItem);
|
||
// if(pModuleItem != NULL)
|
||
// {
|
||
// pModuleItem->SetJobType(m_JobType);// 设置模块在日志作业操作类型下
|
||
// }
|
||
// }
|
||
// else if(pItem->type() == ModuleConnectGraphicsItem::Type)
|
||
// {
|
||
// ModuleConnectGraphicsItem* pConnectionItem = dynamic_cast<ModuleConnectGraphicsItem*> (pItem);
|
||
// if((pConnectionItem) && (pConnectionItem->GetEndItem()) && (pConnectionItem->GetStartItem()))
|
||
// {
|
||
// if(!topPorts.contains(pConnectionItem->GetEndItem()))
|
||
// {
|
||
// int nTopPortID = pConnectionItem->GetEndItem()->GetModule()->GetStepID();
|
||
// ModelProgressGraphicsItem *pBarItem = new ModelProgressGraphicsItem(INPUT_BARTYPE,nTopPortID,pConnectionItem->GetEndItem());
|
||
// topPorts[pConnectionItem->GetEndItem()] = pBarItem;
|
||
// QColor colorBefro("#ffc867");
|
||
// QColor colorEnd("#ff660e");
|
||
// QColor colorFont("#666666");
|
||
// pBarItem->SetBarColor(colorBefro, colorEnd ,colorFont);
|
||
// //设置input条坐标
|
||
// QPointF point = pBarItem->mapToParent(151,7);
|
||
// pBarItem->setPos(point);
|
||
// pBarItem->SetBarText(QString(tr("%1")).arg(0),tr("--"),tr("Input"));
|
||
// }
|
||
|
||
// if(!bottomPorts.contains(pConnectionItem->GetStartItem()))
|
||
// {
|
||
// int nEndPortID = pConnectionItem->GetStartItem()->GetModule()->GetStepID();
|
||
// ModelProgressGraphicsItem *pBarItem = new ModelProgressGraphicsItem(OUTPUT_BARTYPE,nEndPortID,pConnectionItem->GetStartItem());
|
||
// bottomPorts[pConnectionItem->GetStartItem()] = pBarItem;
|
||
// QColor colorBefro("#76cb00");
|
||
// QColor colorEnd("#307800");
|
||
// QColor colorFont("#666666");
|
||
// pBarItem->SetBarColor(colorBefro, colorEnd ,colorFont);
|
||
// //设置Output条坐标
|
||
// QPointF point = pBarItem->mapToParent(151,39);
|
||
// pBarItem->setPos(point);
|
||
// pBarItem->SetBarText(QString(tr("%1")).arg(0),tr("--"),tr("Output"));
|
||
// }
|
||
// }
|
||
// }
|
||
|
||
// // 计算场景中最右端item的x坐标
|
||
// if(pItem->pos().x() > rightItemX)
|
||
// {
|
||
// rightItemX = pItem->pos().x();
|
||
// ModuleGraphicsItem *pModuleItem = dynamic_cast<ModuleGraphicsItem *>(pItem);
|
||
// if(pModuleItem)
|
||
// {
|
||
// rightItemX += (pModuleItem->GetSize().width())/2 + SUMMARY_EDGE;
|
||
// }
|
||
// else
|
||
// {
|
||
// rightItemX += 100 + SUMMARY_EDGE;
|
||
// }
|
||
// }
|
||
// }
|
||
|
||
// if(jobType)
|
||
// {
|
||
// // 预先计算增加Summary和错误信息界面后的场景大小
|
||
// rightItemX = (rightItemX + JOBERROR_EDGE > JOBSECENVIEW_WIDTH) ?
|
||
// (rightItemX + JOBERROR_EDGE): JOBSECENVIEW_WIDTH;
|
||
|
||
// // 重新设置场景大小
|
||
// QRectF rect(sceneRect());
|
||
// rect.setWidth(rightItemX);
|
||
// this->views().at(0)->setSceneRect(rect);
|
||
|
||
// // 添加日志Summary界面
|
||
// m_pSummaryItem = new PaiJobSummaryItem(pJob);
|
||
// addItem(m_pSummaryItem);
|
||
// int summaryWidth = m_pSummaryItem->GetSummaryWidget()->width();
|
||
// int workflowWgtWidth = rect.width();
|
||
// QPointF summaryPoint = QPointF(workflowWgtWidth - summaryWidth - SUMMARY_EDGE, SUMMARY_EDGEHEIGHT);
|
||
// m_pSummaryItem->setPos(summaryPoint);
|
||
|
||
// // 添加错误信息界面
|
||
// m_pJobErrorInfoItem = new PaiJobErrorInfoItem();
|
||
// addItem(m_pJobErrorInfoItem);
|
||
// QPointF jobErrorPoint = QPointF(workflowWgtWidth - JOBERROR_EDGE, rect.topRight().y() + JOBERROR_EDGEHEIGHT);
|
||
// m_pJobErrorInfoItem->setPos(jobErrorPoint);
|
||
// if(!m_ErrorInfoItem)
|
||
// {
|
||
// m_pJobErrorInfoItem->hide();
|
||
// }
|
||
// }
|
||
|
||
// QMultiMap< PaiJob *, QString >::const_iterator iter = m_MultiMapErrorInfo.constBegin();
|
||
// while(iter != m_MultiMapErrorInfo.constEnd())
|
||
// {
|
||
// if(m_pJob == iter.key())
|
||
// {
|
||
// m_IsChangeTableWidget = false;
|
||
// break;
|
||
// }
|
||
// ++iter;
|
||
// }
|
||
|
||
// m_IsAddErrorInfo = true;
|
||
}
|
||
|
||
void GeneralWorkflowScene::SetJobErrorInfo(pai::objectmodel::PaiJob *pJob,const QString& error)
|
||
{
|
||
// m_MultiMapErrorInfo.clear();
|
||
// if(pJob == NULL || m_pJobErrorInfoItem == NULL)
|
||
// {
|
||
// return;
|
||
// }
|
||
|
||
// if(error.indexOf("[ERROR]") >= 0)
|
||
// {
|
||
// if(m_pJobErrorInfoItem)
|
||
// {
|
||
// m_pJobErrorInfoItem->ShowErrorInfoWgt();
|
||
// }
|
||
// if(m_IsAddErrorInfo)
|
||
// {
|
||
// m_IsAddErrorInfo = false;
|
||
// if(m_pJobErrorInfoItem)
|
||
// {
|
||
// m_pJobErrorInfoItem->AddErrorInfo(error);
|
||
// }
|
||
// if(pJob)
|
||
// {
|
||
// m_MultiMapErrorInfo.insert(pJob, error);
|
||
// }
|
||
// }
|
||
// }
|
||
}
|
||
|
||
void GeneralWorkflowScene::ShowCurrentErrorInfo(pai::objectmodel::PaiJob *pJob)
|
||
{
|
||
// if(m_IsChangeTableWidget || m_pJobErrorInfoItem == NULL)
|
||
// {
|
||
// return;
|
||
// }
|
||
// m_IsChangeTableWidget = true;
|
||
// QMultiMap< PaiJob *, QString >::const_iterator iter = m_MultiMapErrorInfo.constBegin();
|
||
// while(iter != m_MultiMapErrorInfo.constEnd())
|
||
// {
|
||
// if(pJob == iter.key())
|
||
// {
|
||
// if(m_pJobErrorInfoItem)
|
||
// {
|
||
// m_pJobErrorInfoItem->AddErrorInfo(iter.value());
|
||
// }
|
||
// }
|
||
// ++iter;
|
||
// }
|
||
// if(m_pJobErrorInfoItem && m_pJobErrorInfoItem->EnableError())
|
||
// {
|
||
// m_pJobErrorInfoItem->ShowErrorInfoWgt();
|
||
// }
|
||
}
|
||
|
||
void GeneralWorkflowScene::EnableMultiSelect(QGraphicsView *pWorkflowView, bool /*enable*/)
|
||
{
|
||
pWorkflowView->setDragMode(QGraphicsView::NoDrag);
|
||
}
|
||
|
||
pai::graphics2d::ModuleGraphicsItem* GeneralWorkflowScene::AddModule(CModuleInformation *pModule,
|
||
pai::graphics2d::PaiModuleStyle *pStyle,
|
||
bool jobRelated)
|
||
{
|
||
return NULL;
|
||
// if((NULL == pModule) || (NULL == pStyle))
|
||
// {
|
||
// return NULL;
|
||
// }
|
||
|
||
// ModuleGraphicsItem* pItem = new ModuleGraphicsItem(pModule, pStyle, jobRelated);
|
||
// pItem->SetToolBarItem(m_pModuleToolBarItem);
|
||
|
||
// addItem(pItem);
|
||
// return pItem;
|
||
}
|
||
|
||
void GeneralWorkflowScene::AddConnection(CModuleConnection *pConnect)
|
||
{
|
||
// ModuleGraphicsItem *pStartItem = FindModule(pConnect->GetSourceId());
|
||
// ModuleGraphicsItem *pEndItem = FindModule(pConnect->GetDestId());
|
||
// int startSelectedPortIndex = QString::fromStdString(pConnect->GetOutPort()).toInt();
|
||
// int endSelectedPortIndex = QString::fromStdString(pConnect->GetInPort()).toInt();
|
||
// QGraphicsItem* pLineItem = new ModuleConnectGraphicsItem(pStartItem,
|
||
// startSelectedPortIndex,
|
||
// pEndItem,
|
||
// endSelectedPortIndex);
|
||
// addItem(pLineItem);
|
||
// update();
|
||
}
|
||
|
||
void GeneralWorkflowScene::HilightOtherItems(int stepID, bool light)
|
||
{
|
||
ModuleGraphicsItem *pStartItem = FindModule(stepID);
|
||
HilightOtherItems(pStartItem, light);
|
||
}
|
||
|
||
void GeneralWorkflowScene::HilightOtherItems(ModuleGraphicsItem *pStartItem, bool light)
|
||
{
|
||
// if(pStartItem == NULL)
|
||
// {
|
||
// return;
|
||
// }
|
||
|
||
// pai::graphics2d::PortDirection selectedPortDirection;
|
||
// int selectedPortIndex;
|
||
|
||
// pStartItem->GetSelectedPort(selectedPortDirection, selectedPortIndex);
|
||
|
||
// pai::graphics2d::PortDirection eHilightPortDirection = (selectedPortDirection == Top) ? Bottom : Top;
|
||
|
||
// foreach(QGraphicsItem *pOtherItem, items())
|
||
// {
|
||
// if((pOtherItem != pStartItem) && (pOtherItem->type() == ModuleGraphicsItem::Type))
|
||
// {
|
||
// ((ModuleGraphicsItem*)pOtherItem)->HilightPorts(eHilightPortDirection,light);
|
||
// }
|
||
// }
|
||
// foreach(QGraphicsItem *pOtherItem, items())
|
||
// {
|
||
// if(pOtherItem->type() == ModuleConnectGraphicsItem::Type)
|
||
// {
|
||
// ModuleConnectGraphicsItem* pConnectionItem = dynamic_cast<ModuleConnectGraphicsItem*> (pOtherItem);
|
||
// if (pConnectionItem)
|
||
// {
|
||
// ModuleGraphicsItem *pStart = NULL;
|
||
// ModuleGraphicsItem *pEnd = NULL;
|
||
// pConnectionItem->GetConnectLineStartEnd(pStart, pEnd);
|
||
// if(pStart == pStartItem)
|
||
// {
|
||
// eHilightPortDirection = Top;
|
||
// ((pai::graphics2d::ModuleGraphicsItem*)pEnd)->HilightPorts(eHilightPortDirection, false);
|
||
// }
|
||
// else if(pEnd == pStartItem)
|
||
// {
|
||
// eHilightPortDirection = Bottom;
|
||
// ((pai::graphics2d::ModuleGraphicsItem*)pStart)->HilightPorts(eHilightPortDirection, false);
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
}
|
||
|
||
void GeneralWorkflowScene::ExpandSceneRectIfNeeded(int stepID)
|
||
{
|
||
// ModuleGraphicsItem *pModuleItem = FindModule(stepID);
|
||
// if(pModuleItem)
|
||
// {
|
||
// if(views().count() > 0)
|
||
// {
|
||
// QRectF rect(sceneRect());
|
||
// qreal dHalfModuleItemHeight = ((QGraphicsItem*)pModuleItem)->boundingRect().height() / 2;
|
||
// qreal dHalfModuleItemWidth = ((QGraphicsItem*)pModuleItem)->boundingRect().width() / 2;
|
||
// qreal dToolItemWidth = ((QGraphicsItem*)m_pModuleToolBarItem)->boundingRect().width();
|
||
// dHalfModuleItemWidth += dToolItemWidth;
|
||
// ExpandSceneRectIfNeeded(pModuleItem->pos(), dHalfModuleItemWidth, dHalfModuleItemHeight);
|
||
// }
|
||
// }
|
||
}
|
||
|
||
void GeneralWorkflowScene::ExpandSceneRectIfNeeded(const QPointF& point, qreal xExtra, qreal yExtra)
|
||
{
|
||
//保证单元测试
|
||
if(views().size() <= 0)
|
||
{
|
||
return;
|
||
}
|
||
|
||
QRectF rect(sceneRect());
|
||
qreal yAddExtra = point.y() + yExtra;
|
||
qreal xAddExtra = point.x() + xExtra;
|
||
qreal ySubExtra = point.y() - yExtra;
|
||
qreal xSubExtra = point.x() - xExtra;
|
||
|
||
if((rect.bottom() < yAddExtra) || (views().at(0)->sceneRect().bottom() < yAddExtra))
|
||
{
|
||
rect.setBottom(yAddExtra);//扩展场景范围
|
||
}
|
||
if((rect.right() < xAddExtra) || (views().at(0)->sceneRect().right() < xAddExtra))
|
||
{
|
||
rect.setRight(xAddExtra);//扩展场景范围
|
||
}
|
||
|
||
if((rect.top() > ySubExtra) || (views().at(0)->sceneRect().top() > ySubExtra))
|
||
{
|
||
rect.setTop(ySubExtra);//扩展场景范围
|
||
}
|
||
if((rect.left() > xSubExtra) || (views().at(0)->sceneRect().left() > xSubExtra))
|
||
{
|
||
rect.setLeft(xSubExtra);//扩展场景范围
|
||
}
|
||
|
||
if(rect != views().at(0)->sceneRect())
|
||
{
|
||
views().at(0)->setSceneRect(rect);
|
||
}
|
||
}
|
||
|
||
void GeneralWorkflowScene::SetScenceReadOnly(bool readyOnly)
|
||
{
|
||
// m_pModuleToolBarItem->SetScenceReadOnly(readyOnly);
|
||
// m_ScenceReadOnly = readyOnly;
|
||
}
|
||
|
||
void GeneralWorkflowScene::SceneRectAutoAdaptive()
|
||
{
|
||
// if((views().size() <= 0) || (items().count() <= 0))
|
||
// {
|
||
// return;
|
||
// }
|
||
|
||
// QGraphicsItem* pMostBottomItem = NULL;
|
||
// QGraphicsItem* pMostRightItem = NULL;
|
||
|
||
// foreach(QGraphicsItem *pItem, items())
|
||
// {
|
||
// if(pItem->type() == ModuleGraphicsItem::Type)
|
||
// {
|
||
// ModuleGraphicsItem* pLoopModuleItem = dynamic_cast<ModuleGraphicsItem*> (pItem);
|
||
// if (pLoopModuleItem)
|
||
// {
|
||
// if ((NULL == pMostBottomItem) || (pItem->pos().y() > pMostBottomItem->pos().y()))
|
||
// {
|
||
// pMostBottomItem = pItem;
|
||
// }
|
||
// if ((NULL == pMostRightItem) || (pItem->pos().x() > pMostRightItem->pos().x()))
|
||
// {
|
||
// pMostRightItem = pItem;
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
|
||
// ModuleGraphicsItem *pMostBottomModuleItem = dynamic_cast< ModuleGraphicsItem* > (pMostBottomItem);
|
||
// ModuleGraphicsItem *pMostRightModuleItem = dynamic_cast< ModuleGraphicsItem* > (pMostRightItem);
|
||
|
||
// if(NULL == pMostBottomModuleItem && NULL == pMostRightModuleItem)
|
||
// {
|
||
// views().at(0)->setSceneRect(m_OriginalSceneRect);
|
||
// return;
|
||
// }
|
||
|
||
// QRectF rect(sceneRect());
|
||
// if(pMostBottomModuleItem)
|
||
// {
|
||
// qreal bottom = pMostBottomItem->pos().y() + (pMostBottomItem->boundingRect().height()) / 2 + BOTTOM_MARGIN;
|
||
// rect.setBottom(bottom);
|
||
// }
|
||
// if(pMostRightModuleItem)
|
||
// {
|
||
// qreal right = pMostRightItem->pos().x() + (pMostRightItem->boundingRect().width()) / 2 + RIGHT_MARGIN;
|
||
// rect.setRight(right);
|
||
// }
|
||
// if(rect != views().at(0)->sceneRect())
|
||
// {
|
||
// views().at(0)->setSceneRect(rect);
|
||
// //设置被点击的模板焦点
|
||
// views().at(0)->centerOn(pMostRightItem);
|
||
// }
|
||
}
|
||
|
||
pai::graphics2d::ModuleGraphicsItem* GeneralWorkflowScene::FindModule(int stepID)
|
||
{
|
||
// foreach(QGraphicsItem *pItem, items())
|
||
// {
|
||
// if (pItem->type() == ModuleGraphicsItem::Type)
|
||
// {
|
||
// ModuleGraphicsItem* pModuleItem = dynamic_cast<ModuleGraphicsItem*> (pItem);
|
||
// if (pModuleItem && (pModuleItem->GetModule()->GetStepID() == stepID))
|
||
// {
|
||
// return pModuleItem;
|
||
// }
|
||
// }
|
||
// }
|
||
return NULL;
|
||
}
|
||
|
||
QGraphicsItem* GeneralWorkflowScene::FindConnection(CModuleConnection *pConnection)
|
||
{
|
||
// if(NULL == pConnection)
|
||
// {
|
||
// return NULL;
|
||
// }
|
||
// foreach(QGraphicsItem *pItem, items())
|
||
// {
|
||
// if (pItem->type() == ModuleConnectGraphicsItem::Type)
|
||
// {
|
||
// ModuleConnectGraphicsItem *pConnectionItem = dynamic_cast<ModuleConnectGraphicsItem*> (pItem);
|
||
// if (pConnectionItem &&
|
||
// pConnectionItem->GetConnection() &&
|
||
// (*(pConnectionItem->GetConnection()) == *pConnection))
|
||
// {
|
||
// return pItem;
|
||
// }
|
||
// }
|
||
// }
|
||
return NULL;
|
||
}
|
||
|
||
void GeneralWorkflowScene::SetJobPrgsInfo()
|
||
{
|
||
// //没有addjob m_pJob可能为空
|
||
// if(NULL == m_pJob)
|
||
// {
|
||
// return;
|
||
// }
|
||
|
||
// std::vector < pai::ios::job::ModuleProgress > modules;
|
||
// try
|
||
// {
|
||
// // 此处使用GetJob()无需判断返回值是否为空,如为空则有异常,且使用GetJob()可以保证其线程安全
|
||
// modules = m_pJob->GetJob()->GetModulesProgress();
|
||
// }
|
||
// catch (pai::error::generic_error& e)
|
||
// {
|
||
// string error_message = e.what();
|
||
// int error_code = e.which();
|
||
// pai::log::Error(_FLF(pai::utils::CUtils::IntToStr(error_code) + error_message));
|
||
// return;
|
||
// }
|
||
// catch(std::exception& e)//主要用于捕捉json转换时抛出的异常
|
||
// {
|
||
// pai::log::Error(_FLF(e.what()));
|
||
// return;
|
||
// }
|
||
|
||
// //获取当前作业状态
|
||
// pai::objectmodel::JobInfos jobInfos = m_pJob->GetJobInfos();
|
||
// for(unsigned int i = 0; i < modules.size(); i++)
|
||
// {
|
||
// pai::ios::job::ModuleProgress mInfo = modules[i];
|
||
|
||
// int icount = mInfo.input.size();
|
||
// int ocount = mInfo.output.size();
|
||
|
||
// //遍历模块
|
||
// QList< QGraphicsItem* > gphItems = items();
|
||
// foreach(QGraphicsItem *pItem, gphItems)
|
||
// {
|
||
// if (pItem->type() == ModelProgressGraphicsItem::Type)
|
||
// {
|
||
// ModelProgressGraphicsItem *pBarItem = dynamic_cast<ModelProgressGraphicsItem*> (pItem);
|
||
// if(pBarItem && (pBarItem->GetStepID() == atoi(mInfo.id.c_str())))
|
||
// {
|
||
// int ncount = 0;
|
||
// QString barItemName;//数据条名称
|
||
// std::vector<pai::ios::job::Processing>::iterator iter;
|
||
|
||
// if(pBarItem && (pBarItem->GetBarType() == INPUT_BARTYPE))
|
||
// {
|
||
// ncount = icount;
|
||
// iter = mInfo.input.begin();
|
||
// barItemName = tr("Input");
|
||
// }
|
||
// else if(pBarItem && (pBarItem->GetBarType() == OUTPUT_BARTYPE))
|
||
// {
|
||
// ncount = ocount;
|
||
// iter = mInfo.output.begin();
|
||
// barItemName = tr("Output");
|
||
// }
|
||
|
||
// int sum = 0;
|
||
// int speed = 0;
|
||
// //遍历要显示的模块的数据和速率
|
||
// for(int i = 0; i < ncount; ++i)
|
||
// {
|
||
// if(barItemName == QString("Output"))
|
||
// {
|
||
// sum = iter->data;
|
||
// speed = iter->speed;
|
||
// }
|
||
// else
|
||
// {
|
||
// sum += (iter->data);
|
||
// speed += (iter->speed);
|
||
// }
|
||
// switch(jobInfos.GetJobStatus())
|
||
// {
|
||
// case pai::ios::job::Unknown:
|
||
// {
|
||
// pBarItem->SetBarText(tr(""), tr(""), barItemName);
|
||
// }
|
||
// break;
|
||
// case pai::ios::job::Running:
|
||
// case pai::ios::job::Suspended:
|
||
// {
|
||
// pBarItem->SetBarText(QString(tr("%1")).arg(sum), QString("%1/s").arg(speed), barItemName);
|
||
// }
|
||
// break;
|
||
// case pai::ios::job::Completed:
|
||
// case pai::ios::job::Terminated:
|
||
// case pai::ios::job::Failed:
|
||
// {
|
||
// pBarItem->SetBarText(QString(tr("%1")).arg(sum), tr(""), barItemName);
|
||
// }
|
||
// break;
|
||
// default:
|
||
// break;
|
||
// }
|
||
// pBarItem->update();
|
||
|
||
// //速度值改变后刷新视口,解决速度值显示不完全的问题。
|
||
// if(this->views().count() > 0)
|
||
// {
|
||
// this->views().at(0)->update();
|
||
// }
|
||
// ++iter;
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
}
|
||
|
||
void GeneralWorkflowScene::Clear()
|
||
{
|
||
//解除item间的父子关系,因为在清空场景时,delete父item时,子item也会一起析构
|
||
//虽然子item析构了,但是它的对象指针并没有从场景中移除,如果再次调用机会导致程序崩溃,defect31416
|
||
//解除了父子关系以后,再清理场景这个问题就不会存在
|
||
foreach(QGraphicsItem *pItem, items())
|
||
{
|
||
if (pItem->type() != ModuleToolBarGraphicsItem::Type)
|
||
{
|
||
pItem->setParentItem(NULL);
|
||
}
|
||
}
|
||
//清空场景
|
||
foreach(QGraphicsItem *pItem, items())
|
||
{
|
||
if (pItem->type() != ModuleToolBarGraphicsItem::Type)
|
||
{
|
||
removeItem(pItem);
|
||
delete pItem;
|
||
pItem = NULL;
|
||
}
|
||
}
|
||
|
||
//m_pWorkflow表示Job Manager插件B1区对应的工作流,或者日志插件A1区对应的工作流,或者工作流插件对应的工作流
|
||
//Job Manager插件B1区对应的工作流和日志插件A1区对应的工作流,工作流对象的管理由场景对应的View或者View的父亲管理
|
||
//对于工作流插件对应的编辑区工作流,目前由数据树管理,因此清理场景时m_pWorkflow直接置空即可
|
||
m_pWorkflow = NULL;
|
||
}
|
||
|
||
void GeneralWorkflowScene::SetModulePosition(const QPointF& point, pai::graphics2d::ModuleGraphicsItem *pItem)
|
||
{
|
||
// if(pItem)
|
||
// {
|
||
// pItem->setPos(point);
|
||
// }
|
||
// if(pItem && (pItem->GetMonitorItem()))
|
||
// {
|
||
// pItem->GetMonitorItem()->setPos(pItem->pos() + QPointF(-120,-20));
|
||
// pItem->GetMonitorItem()->GetStyle()->SetPosition(pItem->pos() + QPointF(-120, -20));
|
||
// }
|
||
}
|
||
|
||
QList< QGraphicsItem* > GeneralWorkflowScene::GetDisabledItems() const
|
||
{
|
||
QList< QGraphicsItem* > disabledItems;
|
||
return disabledItems;
|
||
// foreach (QGraphicsItem *pItem, items())
|
||
// {
|
||
// ModuleGraphicsItem *pModuleItem = dynamic_cast<ModuleGraphicsItem*>(pItem);
|
||
// if (pModuleItem && (pModuleItem->IsDisable()))
|
||
// {
|
||
// disabledItems << pItem;
|
||
// }
|
||
// }
|
||
|
||
// return disabledItems;
|
||
}
|
||
|
||
void GeneralWorkflowScene::EnableErrorInfoItem(bool flag)
|
||
{
|
||
m_ErrorInfoItem = flag;
|
||
}
|
||
|
||
void GeneralWorkflowScene::SetFocusViewport()
|
||
{
|
||
if(views().count() > 0)
|
||
{
|
||
views().at(0)->setFocus();
|
||
}
|
||
}
|
||
|
||
pai::graphics2d::ModuleGraphicsItem* GeneralWorkflowScene::GetSingleSelectedItem() const
|
||
{
|
||
// QList<QGraphicsItem *> selectedModules = selectedItems();
|
||
// // 被选中的只有一个模块,并且类型是ModuleGraphicsItem
|
||
// if ((1 == selectedModules.count()) && (selectedModules.at(0)->type() == ModuleGraphicsItem::Type))
|
||
// {
|
||
// ModuleGraphicsItem *pSelectedModule = dynamic_cast<ModuleGraphicsItem*>(selectedModules.at(0));
|
||
// if (pSelectedModule)
|
||
// {
|
||
// return pSelectedModule;
|
||
// }
|
||
// }
|
||
return NULL;
|
||
}
|
||
|
||
void GeneralWorkflowScene::mousePressEvent(QGraphicsSceneMouseEvent *pEvent)
|
||
{
|
||
// QGraphicsScene::mousePressEvent(pEvent);
|
||
// if(m_ScenceReadOnly)
|
||
// {
|
||
// ModuleGraphicsItem *pSelectedModule = GetSingleSelectedItem();
|
||
// //点击场景
|
||
// if(!pSelectedModule)
|
||
// {
|
||
// emit ClickScene(NULL);
|
||
// }
|
||
// else
|
||
// {
|
||
// CModuleInformation* pModule = pSelectedModule->GetModule();
|
||
// if(pModule)
|
||
// {
|
||
// emit ClickScene(pModule);
|
||
// }
|
||
// }
|
||
// }
|
||
}
|
||
|
||
void GeneralWorkflowScene::SetWorkflow(pai::objectmodel::PaiWorkflowDataModel *pWorkflow)
|
||
{
|
||
m_pWorkflow = pWorkflow;
|
||
}
|
||
|
||
pai::objectmodel::PaiWorkflowDataModel* GeneralWorkflowScene::GetWorkflow() const
|
||
{
|
||
return m_pWorkflow;
|
||
}
|
||
|
||
ModuleToolBarGraphicsItem* GeneralWorkflowScene::GetModuleToolBar() const
|
||
{
|
||
return m_pModuleToolBarItem;
|
||
}
|
||
|
||
bool GeneralWorkflowScene::IsReadOnly() const
|
||
{
|
||
return m_ScenceReadOnly;
|
||
}
|