You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nmWTAI-Platform/Src/nmNum/nmPlot/nmObjDeleteTool.cpp

195 lines
5.0 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <QPainter>
#include "ZxBaseUtil.h"
#include "nmObjDelete.h"
#include "nmObjDeleteTool.h"
#include "nmSingalCenter.h"
#include "ZxPlot.h"
#include <vector>
#include "nmObjLineCrack.h"
nmObjDeleteTool::nmObjDeleteTool() : nmObjToolBase()
, m_pPlot(nullptr)
{
setText(tr("nObjDeleteTool"));
m_oNot = NMOT_Delete;
m_bShowDeleteIcon = false;
m_hoverObj = nullptr;
m_deleteIcon.load(ZxBaseUtil::getDirOf(s_Dir_Res, "Icon") + "nmTrash.png");
}
nmObjDeleteTool::nmObjDeleteTool(ZxPlot* pPlot)
: nmObjToolBase()
, m_pPlot(pPlot)
{
setText(tr("nObjDeleteTool"));
m_oNot = NMOT_Delete;
nmDataLogFile::getInstance()->writeLog(" nmObjDeleteTool ++++++++ " + QString::number(m_oNot));
this->m_delObj.clear();
m_bShowDeleteIcon = false;
m_hoverObj = nullptr;
m_deleteIcon.load(ZxBaseUtil::getDirOf(s_Dir_Res, "Icon") + "nmTrash.png");
}
bool nmObjDeleteTool::onLeftUp(const QPointF& pt)
{
if (NULL == m_pObj) //绘图对象尚未创建(鼠标选点ing
{
//changeCursor(Qt::CrossCursor);
// 判断鼠标是否进入了要删除的对象上
if (!m_delObj.isEmpty())
{
int objCount = this->m_delObj.count();
for(int i = 0; i < objCount; i++) {
ZxObjBase* obj = this->m_delObj[i];
if (obj == NULL)
{
continue;
}
QVector<QPointF> pts = obj->getAllPos();
// 井或区域标记
if (pts.count() == 1)
{
// 计算鼠标点击位置与井的中心点的距离
float distance = QLineF(pt, pts[0]).length();
if (distance <= 1.f * 5) // 如果距离在5像素范围内
{
if (obj != NULL)
{
nmSingalCenter::getInstance()->emitSigDeleteOneObj(obj->getName(), (void*)this);
return true;
}
}
}
// 线
for (int i = 0; i < pts.count(); i++)
{
int n1 = i;
int n2 = (i == pts.count() - 1 ? 0 : i + 1);
if (_isNearLine(pt, pts[n1], pts[n2], 1.f * 3))
{
if (obj != NULL)
{
nmSingalCenter::getInstance()->emitSigDeleteOneObj(obj->getName(),(void*) this);
return true;
}
}
}
}
} else {
return nmObjToolBase::onLeftUp(pt);
}
return true;
}
else //业已绑定绘图对象
{
return nmObjToolBase::onLeftUp(pt);
}
}
void nmObjDeleteTool::onPaint(QPainter* painter, const ZxPaintParam& param)
{
nmObjDelete* pObj = dynamic_cast<nmObjDelete*>(m_pObj);
if (pObj == NULL) //绘图对象尚未创建(鼠标选点ing
{
m_currentMousePos = getCurrentPos();
m_bShowDeleteIcon = false;
m_hoverObj = nullptr;
if (this->m_pPlot == NULL) {
return;
}
// 处理可删除对象列表
int objCount = this->m_pPlot->getObjCount();
for(int i = 0; i < objCount; i++) {
ZxObjBase* obj = this->m_pPlot->getObjByIndex(i);
if (obj == NULL) {
continue;
}
if(_isSame("nObjLineFracture", obj->getTagName()) || \
_isSame("nObjLineFault", obj->getTagName()) || \
_isSame("nObjRegion", obj->getTagName()) || \
_isSame("nObjPointWell", obj->getTagName()) || \
_isSame("nObjRegionMark", obj->getTagName()))
{
// 判断裂缝是不是裂缝
if(_isSame("nObjLineFracture", obj->getTagName())) {
nmObjLineCrack* pFractureObj = dynamic_cast<nmObjLineCrack*>(obj);
if (pFractureObj == NULL || pFractureObj->getFractureData() == NULL) {
continue;
}
// 如果是DFN生成的裂缝那么不做处理
if (pFractureObj->getFractureData()->getFractureType().getValue() == tr("DFN")) {
continue;
}
}
bool isContain = false;
// 遍历 m_delObj检查是否存在相同的指针
for (int j = 0; j < m_delObj.count(); j++) {
if (m_delObj[j] == obj) {
isContain = true;
break;
}
}
if (!isContain)
{
m_delObj.append(obj);
}
// 检查鼠标是否在此对象上
QVector<QPointF> pts = obj->getAllPos();
// 井或区域标记
if (pts.count() == 1)
{
float distance = QLineF(m_currentMousePos, pts[0]).length();
if (distance <= 1.f * 5) // 如果距离在5像素范围内
{
m_bShowDeleteIcon = true;
m_hoverObj = obj;
}
}
// 线
else
{
for (int j = 0; j < pts.count(); j++)
{
int n1 = j;
int n2 = (j == pts.count() - 1 ? 0 : j + 1);
if (_isNearLine(m_currentMousePos, pts[n1], pts[n2], 1.f * 3))
{
m_bShowDeleteIcon = true;
m_hoverObj = obj;
break;
}
}
}
}
}
// 如果鼠标悬停在可删除对象上,绘制删除图标
if (m_bShowDeleteIcon && !m_deleteIcon.isNull()) {
// 在鼠标右侧绘制图标
QPointF iconPos = m_currentMousePos + QPointF(4, 2);
int iconSize = 10; // 图标尺寸
QRectF iconRect(iconPos.x(), iconPos.y(), iconSize, iconSize);
painter->drawPixmap(iconRect, m_deleteIcon, m_deleteIcon.rect());
}
}
else //业已绑定绘图对象
{
// paintTrackingRealObj(painter, param);
}
}