From 3df63394fbcda7cd2cecc9df6dd816bcca76bc59 Mon Sep 17 00:00:00 2001 From: crqiqi77 Date: Thu, 23 Apr 2026 16:42:00 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A3=82=E7=BC=9D=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logPlus/PickFrac.cpp | 230 +++++++++++++++++++++++++++++++++++-- logPlus/PickFrac.h | 15 ++- logPlus/PropertyWidget.cpp | 6 + logPlus/formdraw.cpp | 1 + logPlus/qmycustomplot.cpp | 161 +++++++++++++------------- 5 files changed, 323 insertions(+), 90 deletions(-) diff --git a/logPlus/PickFrac.cpp b/logPlus/PickFrac.cpp index 3f9b6d9..7e345cd 100644 --- a/logPlus/PickFrac.cpp +++ b/logPlus/PickFrac.cpp @@ -56,7 +56,7 @@ void CPickFrac::ReadFracDef() if (qs.length() < 8) break; sscanf(str, "%d %s %d %d %d %d %d", &fd.iCode, name, &fd.iType, &r, &g, &b, &fd.nLineWidth); fd.crColor = QColor(r, g, b); - fd.csName = name; + fd.csName = QString::fromLocal8Bit(name); fd.csName = fd.csName.trimmed(); fd.bDraw = 0; m_FracDef.append(fd); @@ -102,7 +102,7 @@ void CPickFrac::ReadData(QString strSlfName, QString csCurve) for (int j=0; jsetCrackCode(frac.ID); + item->csName = csName; + item->DIPorS = frac.DIPorS; + item->DIR = frac.DIR; + item->setLabelInfo(csName, frac.DIPorS, frac.DIR); connect(item, &DraggableCrackItem::dataChanged, this, &CPickFrac::saveToFile); connect(item, &DraggableCrackItem::removeMe, this, &CPickFrac::onRemoveCrackItem); m_items.append(item); @@ -261,6 +265,11 @@ void DraggableCrackItem::cleanupFromPlot() } } +void DraggableCrackItem::setShow(bool flag) +{ + setVisible(flag); +} + // ==================== DraggableCrackItem 实现 ==================== QPointer DraggableCrackItem::s_activeItem = nullptr; @@ -298,6 +307,13 @@ DraggableCrackItem::DraggableCrackItem(QCustomPlot *plot, Type type, const QColo m_curveC->setLayer("overlay"); m_plot->installEventFilter(this); } + // 创建文本标签 + m_labelText = new QCPItemText(m_plot); + m_labelText->setFont(QFont("微软雅黑", 7)); + m_labelText->setColor(Qt::black); + m_labelText->setPositionAlignment(Qt::AlignCenter); + m_labelText->setLayer("overlay"); + m_labelText->setVisible(false); } DraggableCrackItem::~DraggableCrackItem() @@ -314,6 +330,43 @@ DraggableCrackItem::~DraggableCrackItem() if (s_activeItem == this) s_activeItem = nullptr; } +void DraggableCrackItem::setLabelInfo(const QString &name, double angle, double angle2, int digitCapacity) +{ + QString text = name; + if (angle >= 0) { + text += QString(" %1").arg(angle, 0, 'f', digitCapacity) + "-" + QString("%1").arg(angle2, 0, 'f', digitCapacity); + } + if (m_labelText) { + m_labelText->setText(text); + } + updateLabelPosition(); +} + +void DraggableCrackItem::updateLabelPosition() +{ + if (!m_labelText) return; + QPointF pos; + if (m_type == TypeA_Sine) { + // 曲线中心点(起点和终点的中点) + double centerX = (m_orig_startX + m_orig_endX) / 2.0 + m_offsetXA; + double centerY = m_depth + m_offsetYA; + pos = QPointF(centerX, centerY); + } else if (m_type == TypeB_Polyline) { + if (!m_lines.isEmpty()) { + // 取第一条线段的中点 + QPointF p1 = m_lines.first().startOrig + QPointF(m_offsetXB, m_offsetYB); + QPointF p2 = m_lines.first().endOrig + QPointF(m_offsetXB, m_offsetYB); + pos = (p1 + p2) / 2.0; + } + } else if (m_type == TypeC_Closed) { + if (!m_pointsC.isEmpty()) { + // 取第一个点 + pos = m_pointsC.first() + QPointF(m_offsetXC, m_offsetYC); + } + } + m_labelText->position->setCoords(pos.x(), pos.y()); +} + void DraggableCrackItem::setVisible(bool visible) { if (m_pendingDelete) return; @@ -423,6 +476,7 @@ void DraggableCrackItem::setSineData(double depth, double amplitude, double phas updateCurveFromTargets(); updateCurvePosition(); updateTracers(); + updateLabelPosition(); } void DraggableCrackItem::updateCurveFromTargets() @@ -511,8 +565,10 @@ void DraggableCrackItem::setPolylineData(const QVector &points, double item.startTracer = startTracer; item.endTracer = endTracer; m_lines.append(item); + i++; } updateLinesPosition(); + updateLabelPosition(); } void DraggableCrackItem::updateLineEndpoints(LineItem &item) @@ -562,6 +618,7 @@ void DraggableCrackItem::setClosedData(const QVector &points, double sc } m_cFinished = true; updatePolylineC(true); + updateLabelPosition(); } void DraggableCrackItem::updatePolylineC(bool closed) @@ -587,18 +644,31 @@ void DraggableCrackItem::clearPolylineC() { for (auto label : m_labelsC) { if (label) { - m_plot->removeItem(label); + if (m_plot) m_plot->removeItem(label); } } m_labelsC.clear(); m_pointsC.clear(); - if (m_curveC) m_curveC->setData(QVector(), QVector()); + // 仅当曲线对象仍然存在于 plot 中时才清空数据 + if (m_curveC && m_plot && m_plot->plottableCount() > 0) { + // 检查 m_curveC 是否还在 plot 的 plottable 列表中 + bool found = false; + for (int i = 0; i < m_plot->plottableCount(); ++i) { + if (m_plot->plottable(i) == m_curveC) { + found = true; + break; + } + } + if (found) { + m_curveC->setData(QVector(), QVector()); + } + } m_offsetXC = m_offsetYC = 0.0; m_cFinished = false; m_cDragging = false; m_draggingPoint = false; m_draggedPointIndex = -1; - m_plot->replot(); + if (m_plot) m_plot->replot(); } // ---------- 保存辅助 ---------- @@ -915,6 +985,7 @@ bool DraggableCrackItem::eventFilter(QObject *obj, QEvent *event) updateTracers(); m_plot->replot(); m_lastDragPixelA = current; + updateLabelPosition(); return true; } } @@ -930,6 +1001,7 @@ bool DraggableCrackItem::eventFilter(QObject *obj, QEvent *event) m_offsetXB += dx; m_offsetYB += dy; updateLinesPosition(); + updateLabelPosition(); } else if (m_dragStateB == DraggingStartPoint || m_dragStateB == DraggingEndPoint) { int idx = m_draggedLineIndex; if (idx >= 0 && idx < m_lines.size()) { @@ -967,6 +1039,7 @@ bool DraggableCrackItem::eventFilter(QObject *obj, QEvent *event) updatePolylineC(true); m_plot->replot(); m_cDragStart = current; + updateLabelPosition(); return true; } else if (m_draggingPoint) { QPointF current = me->localPos(); @@ -1026,8 +1099,105 @@ bool DraggableCrackItem::eventFilter(QObject *obj, QEvent *event) } // ==================== 新建裂缝 ==================== -bool CPickFrac::createNewCrack(int iType, double depth) +bool CPickFrac::createNewCrack(double depth, QString type) { + int iType = 1; + QColor m_lineColor; + QString m_typeName; + if("高导缝" == type) + { + iType = 1; + m_lineColor.setNamedColor("#FF0000"); + m_typeName = "高导缝"; + } + else if("高阻缝" == type) + { + iType = 1; + m_lineColor.setNamedColor("#400040"); + m_typeName = "高阻缝"; + } + else if("诱导缝" == type) + { + iType = 1; + m_lineColor.setNamedColor("#00FFFF"); + m_typeName = "诱导缝"; + } + else if("层理" == type) + { + iType = 1; + m_lineColor.setNamedColor("#00FF00"); + m_typeName = "层理"; + } + else if("侵蚀面" == type) + { + iType = 1; + m_lineColor.setNamedColor("#409600"); + m_typeName = "侵蚀面"; + } + else if("断层" == type) + { + iType = 1; + m_lineColor.setNamedColor("#A65300"); + m_typeName = "断层"; + } + else if("自定义1" == type) + { + iType = 1; + m_lineColor.setNamedColor("#000000"); + m_typeName = "自定义1"; + } + else if("自定义2" == type) + { + iType = 1; + m_lineColor.setNamedColor("#000000"); + m_typeName = "自定义2"; + } + else if("网状缝" == type) + { + iType = 2; + m_lineColor.setNamedColor("#808000"); + m_typeName = "网状缝"; + } + else if("垂直缝" == type) + { + iType = 2; + m_lineColor.setNamedColor("#FF0000"); + m_typeName = "垂直缝"; + } + else if("孔洞" == type) + { + iType = 3; + m_lineColor.setNamedColor("#FF8064"); + m_typeName = "孔洞"; + } + else if("气孔" == type) + { + iType = 3; + m_lineColor.setNamedColor("#FFFF00"); + m_typeName = "气孔"; + } + else if("砾石" == type) + { + iType = 3; + m_lineColor.setNamedColor("#000096"); + m_typeName = "砾石"; + } + else if("结核" == type) + { + iType = 3; + m_lineColor.setNamedColor("#A65300"); + m_typeName = "结核"; + } + else if("团块" == type) + { + iType = 3; + m_lineColor.setNamedColor("#000000"); + m_typeName = "团块"; + } + + +// int iType, +// QString type // 从配置文件中查找第一个匹配 iType 的定义,获取颜色和线宽 FRAC_DEF_Crack def; bool found = false; @@ -1040,7 +1210,7 @@ bool CPickFrac::createNewCrack(int iType, double depth) } if (!found) { def.iType = iType; - def.crColor = QColor(255, 0, 0); + def.crColor = m_lineColor; def.nLineWidth = 2; } @@ -1053,11 +1223,15 @@ bool CPickFrac::createNewCrack(int iType, double depth) DraggableCrackItem *item = nullptr; + def.crColor = m_lineColor; + def.csName = m_typeName; if (iType == 1) { item = new DraggableCrackItem(m_myCustomPlot, DraggableCrackItem::TypeA_Sine, def.crColor, def.nLineWidth); + item->csName = m_typeName; + item->setLabelInfo(m_typeName, 0); double amplitude = 0.5; double phase = 0.0; - double width = xWidth * 0.8; + double width = xWidth; double xScale = 360.0 / width; double centerY = -(depth + amplitude); item->setSineData(centerY, amplitude, phase, xScale, width); @@ -1071,6 +1245,8 @@ bool CPickFrac::createNewCrack(int iType, double depth) } else if (iType == 2) { item = new DraggableCrackItem(m_myCustomPlot, DraggableCrackItem::TypeB_Polyline, def.crColor, def.nLineWidth); + item->csName = m_typeName; + item->setLabelInfo(m_typeName, 0); item->setCrackCode(def.iCode); connect(item, &DraggableCrackItem::dataChanged, this, &CPickFrac::saveToFile); connect(item, &DraggableCrackItem::removeMe, this, &CPickFrac::onRemoveCrackItem); @@ -1081,6 +1257,8 @@ bool CPickFrac::createNewCrack(int iType, double depth) } else if (iType == 3) { item = new DraggableCrackItem(m_myCustomPlot, DraggableCrackItem::TypeC_Closed, def.crColor, def.nLineWidth); + item->csName = m_typeName; + item->setLabelInfo(m_typeName, 0); item->setCrackCode(def.iCode); connect(item, &DraggableCrackItem::dataChanged, this, &CPickFrac::saveToFile); connect(item, &DraggableCrackItem::removeMe, this, &CPickFrac::onRemoveCrackItem); @@ -1091,3 +1269,37 @@ bool CPickFrac::createNewCrack(int iType, double depth) } return false; } + +void CPickFrac::setShowHide(QString names, int nameShow, int angleShow, int digitCapacity) +{ + for (DraggableCrackItem* item : m_items) + { + if(names.contains(item->csName)) + { + item->setShow(true); + item->m_labelText->setVisible(false); + if(angleShow == 0 && nameShow == 1) + { + item->setLabelInfo(item->csName, -1, -1, digitCapacity); + item->m_labelText->setVisible(true); + } + if(angleShow == 1 && nameShow == 0) + { + item->setLabelInfo("", item->DIPorS, item->DIR, digitCapacity); + item->m_labelText->setVisible(true); + } + if(angleShow == 1 && nameShow == 1) + { + item->setLabelInfo(item->csName, item->DIPorS, item->DIR, digitCapacity); + item->m_labelText->setVisible(true); + } + } + else + { + item->setShow(false); + item->m_labelText->setVisible(false); + } + } + m_myCustomPlot->replot(); +} + diff --git a/logPlus/PickFrac.h b/logPlus/PickFrac.h index 0cac56a..eeb7724 100644 --- a/logPlus/PickFrac.h +++ b/logPlus/PickFrac.h @@ -66,7 +66,8 @@ public: void setDraggingEnabled(bool enabled); QList getAllItems() const { return m_items; } bool saveToFile(); - bool createNewCrack(int iType, double depth); + bool createNewCrack(double depth, QString type); + void setShowHide(QString names, int nameShow, int angleShow, int digitCapacity); public: QMyCustomPlot *m_myCustomPlot; @@ -76,7 +77,8 @@ public: void ReadFracDef(); void ReadData(QString strSlfName, QString csCurve); - void drawOne(FRAC_TABLE_Crack frac, int iType, int nLineWidth, QColor crColor); + void drawOne(FRAC_TABLE_Crack frac, int iType, int nLineWidth, QColor crColor, QString csName); + protected: bool eventFilter(QObject *watched, QEvent *event) override; @@ -126,6 +128,14 @@ public: void cleanupFromPlot(); // 立即从画布移除所有图形项 + void setShow(bool flag); + QString csName; + float DIPorS; + float DIR; + void setLabelInfo(const QString &name, double angle = -1.0, double angle2 = -1.0, int digitCapacity = 2); // angle为-1时不显示角度 + void updateLabelPosition(); + QCPItemText *m_labelText = nullptr; + signals: void dataChanged(); void removeMe(DraggableCrackItem* item); @@ -139,6 +149,7 @@ private: double m_originalXETAorH = 0.0; double m_originalAorX = 0.0; + // 模式A QCPItemCurve *m_curve = nullptr; QCPItemTracer *m_tracer1 = nullptr, *m_tracer2 = nullptr; diff --git a/logPlus/PropertyWidget.cpp b/logPlus/PropertyWidget.cpp index a126f75..0cf8515 100644 --- a/logPlus/PropertyWidget.cpp +++ b/logPlus/PropertyWidget.cpp @@ -4465,6 +4465,7 @@ void PropertyWidget::changedCrackProperty(QString strProperty, QVariant varVal) else if ("小数位数" == strProperty) { this->m_formInfo->m_crack_decimal_digits = varVal.toInt(); + flag = true; } // 分类 else if ("高导缝" == strProperty) @@ -4563,6 +4564,11 @@ void PropertyWidget::changedCrackProperty(QString strProperty, QVariant varVal) QVariantMap variantMap; // 必须用来判断当前道 variantMap["m_strTrackName"] = this->m_formInfo->m_strTrackName; + // 数据 + variantMap["m_crack_drawName"] = this->m_formInfo->m_crack_drawName; + variantMap["m_crack_drawAngle"] = this->m_formInfo->m_crack_drawAngle; + // 显示控制 + variantMap["m_crack_decimal_digits"] = this->m_formInfo->m_crack_decimal_digits; // 分类 variantMap["m_pl_highGap"] = this->m_formInfo->m_pl_highGap; variantMap["m_pl_highReservoir"] = this->m_formInfo->m_pl_highReservoir; diff --git a/logPlus/formdraw.cpp b/logPlus/formdraw.cpp index c0f6837..0d70f95 100644 --- a/logPlus/formdraw.cpp +++ b/logPlus/formdraw.cpp @@ -3995,6 +3995,7 @@ void FormDraw::s_addCrack(QString strUuid, QString strSlfName, QString strWellNa //注意,不对调XY轴 curv->m_bX2Y = false; CPickFrac *pickFrac = new CPickFrac(curv, strSlfName, strWaveName, iMyWidth); + pickFrac->setShowHide("", false, false, 2); curv->m_cPickFrac = pickFrac; // diff --git a/logPlus/qmycustomplot.cpp b/logPlus/qmycustomplot.cpp index 0b26f55..9365690 100644 --- a/logPlus/qmycustomplot.cpp +++ b/logPlus/qmycustomplot.cpp @@ -2190,20 +2190,22 @@ void QMyCustomPlot::addCrackObject() QString type = cbbType->currentText(); QString showNames = ""; - if("高导缝" == type) - { - this->m_cPickFrac->createNewCrack(1 ,depth); - } - else if("网状缝" == type) - { - this->m_cPickFrac->createNewCrack(2 ,depth); - } - else if("孔洞" == type) - { - this->m_cPickFrac->createNewCrack(3 ,depth); - } -// auto curve = new CPickFrac(this, strUuid, -depth, type, showNames); + this->m_cPickFrac->createNewCrack(depth, type); +// if("高导缝" == type) +// { + +// } +// else if("网状缝" == type) +// { +// this->m_cPickFrac->createNewCrack(2, depth, type); +// } +// else if("孔洞" == type) +// { +// this->m_cPickFrac->createNewCrack(3, depth, type); +// } + +// auto curve = new CPickFrac(this, strUuid, -depth, type, showNames); // m_mapDraggable_CrackObject[strUuid] = curve; // ========= 这里就是你要的结果!========= @@ -10726,7 +10728,12 @@ void QMyCustomPlot::s_changeCrackProperty(QVariantMap variantMap) { return; } - + // 数据 + int m_crack_drawName = variantMap["m_crack_drawName"].toInt(); // + int m_crack_drawAngle = variantMap["m_crack_drawAngle"].toInt(); // + // 显示控制 + int m_crack_decimal_digits = variantMap["m_crack_decimal_digits"].toInt(); + // 分类 bool m_pl_highGap = variantMap["m_pl_highGap"].toBool(); // 高导缝 bool m_pl_highReservoir = variantMap["m_pl_highReservoir"].toBool(); // 高阻缝 bool m_pl_reticularFracture = variantMap["m_pl_reticularFracture"].toBool(); // 网状缝 @@ -10742,74 +10749,70 @@ void QMyCustomPlot::s_changeCrackProperty(QVariantMap variantMap) bool m_pl_verticalFracture = variantMap["m_pl_verticalFracture"].toBool(); // 垂直缝 bool m_pl_custom1 = variantMap["m_pl_custom1"].toBool(); // 自定义1 bool m_pl_custom2 = variantMap["m_pl_custom2"].toBool(); // 自定义2 + QString showNames = ""; - TransparentDraggableCrackObject *pDraggableRect = NULL; - QMap::Iterator it = m_mapDraggable_CrackObject.begin(); - while( it != m_mapDraggable_CrackObject.end() ) + if(m_pl_highGap) { - pDraggableRect = (TransparentDraggableCrackObject*)it.value(); - if("高导缝" == pDraggableRect->m_typeName) - { - pDraggableRect->isShow(m_pl_highGap); - } - else if("高阻缝" == pDraggableRect->m_typeName) - { - pDraggableRect->isShow(m_pl_highReservoir); - } - else if("诱导缝" == pDraggableRect->m_typeName) - { - pDraggableRect->isShow(m_pl_inducedFracture); - } - else if("层理" == pDraggableRect->m_typeName) - { - pDraggableRect->isShow(m_pl_bedLayer); - } - else if("侵蚀面" == pDraggableRect->m_typeName) - { - pDraggableRect->isShow(m_pl_erosionSurface); - } - else if("断层" == pDraggableRect->m_typeName) - { - pDraggableRect->isShow(m_pl_fault); - } - else if("自定义1" == pDraggableRect->m_typeName) - { - pDraggableRect->isShow(m_pl_custom1); - } - else if("自定义2" == pDraggableRect->m_typeName) - { - pDraggableRect->isShow(m_pl_custom2); - } - else if("网状缝" == pDraggableRect->m_typeName) - { - pDraggableRect->isShow(m_pl_reticularFracture); - } - else if("垂直缝" == pDraggableRect->m_typeName) - { - pDraggableRect->isShow(m_pl_verticalFracture); - } - else if("孔洞" == pDraggableRect->m_typeName) - { - pDraggableRect->isShow(m_pl_pore); - } - else if("气孔" == pDraggableRect->m_typeName) - { - pDraggableRect->isShow(m_pl_vesicle); - } - else if("砾石" == pDraggableRect->m_typeName) - { - pDraggableRect->isShow(m_pl_gravel); - } - else if("结核" == pDraggableRect->m_typeName) - { - pDraggableRect->isShow(m_pl_nodule); - } - else if("团块" == pDraggableRect->m_typeName) - { - pDraggableRect->isShow(m_pl_lumps); - } - it++; + showNames += "高导缝,"; } + if(m_pl_highReservoir) + { + showNames += "高阻缝,"; + } + if(m_pl_reticularFracture) + { + showNames += "网状缝,"; + } + if(m_pl_inducedFracture) + { + showNames += "诱导缝,"; + } + if(m_pl_bedLayer) + { + showNames += "层理,"; + } + if(m_pl_erosionSurface) + { + showNames += "侵蚀面,"; + } + if(m_pl_pore) + { + showNames += "孔洞,"; + } + if(m_pl_vesicle) + { + showNames += "气孔,"; + } + if(m_pl_gravel) + { + showNames += "砾石,"; + } + if(m_pl_nodule) + { + showNames += "结核,"; + } + if(m_pl_lumps) + { + showNames += "团块,"; + } + if(m_pl_fault) + { + showNames += "断层,"; + } + if(m_pl_verticalFracture) + { + showNames += "垂直缝,"; + } + if(m_pl_custom1) + { + showNames += "自定义1,"; + } + if(m_pl_custom2) + { + showNames += "自定义2,"; + } + this->m_cPickFrac->setShowHide(showNames, m_crack_drawName, m_crack_drawAngle, m_crack_decimal_digits); +// this->m_cPickFrac->setShowName(m_crack_drawName, m_crack_drawAngle); } void QMyCustomPlot::s_changePlObjectProperty(QVariantMap variantMap)