From 157008bfc051febdc930029be623e76172fc9ff5 Mon Sep 17 00:00:00 2001 From: jiayulong Date: Tue, 16 Dec 2025 18:13:53 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BC=98=E5=8C=96svg=E5=9B=BE=E5=BD=A2?= =?UTF-8?q?=EF=BC=8C=E4=B8=8D=E6=94=B9=E5=8F=98=E5=A4=A7=E5=B0=8F=202.?= =?UTF-8?q?=E6=96=B0=E5=A2=9Egeo=5Flith=E5=BD=95=E4=BA=95=E5=89=96?= =?UTF-8?q?=E9=9D=A2=E7=BB=98=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/geometryutils.h | 14 + logPlus/TransparentDraggableGeoLith.h | 732 ++++++++++++++++++++++++++ logPlus/TransparentDraggableRect.h | 2 +- logPlus/TransparentDraggableResult.h | 40 +- logPlus/formdraw.cpp | 160 +++++- logPlus/formdraw.h | 4 + logPlus/logPlus.pro | 1 + logPlus/qmycustomplot.cpp | 32 +- logPlus/qmycustomplot.h | 3 + 9 files changed, 975 insertions(+), 13 deletions(-) create mode 100644 logPlus/TransparentDraggableGeoLith.h diff --git a/common/geometryutils.h b/common/geometryutils.h index a90d3ed..4a64a0a 100644 --- a/common/geometryutils.h +++ b/common/geometryutils.h @@ -155,6 +155,20 @@ public: return m_DataSourceZ; } }; + +//录井剖面 +typedef struct GEOLITH_Table +{ + int NO;//序号 + float SDEP;//起始深度 + float EDEP;//终止深度 + int Oil;//含油性 + int Lith;//岩性 + int Color;//颜色 + char Dest[64]; +} GeoLith_DATA; + + QString GetProjectFolder(); QString GetLogdataPath(); void GetWellNameAndPath(QString slf,QString &wellname,QString &path); diff --git a/logPlus/TransparentDraggableGeoLith.h b/logPlus/TransparentDraggableGeoLith.h new file mode 100644 index 0000000..8f1fbd6 --- /dev/null +++ b/logPlus/TransparentDraggableGeoLith.h @@ -0,0 +1,732 @@ +#ifndef TRANSPARENTDRAGGABLEGEOLITH_H +#define TRANSPARENTDRAGGABLEGEOLITH_H + +#include +#include "qmycustomplot.h" +#include +#include +#include "geometryutils.h" +#include + +#pragma execution_character_set("utf-8") // 强制指定执行字符集为 UTF-8 + +class TransparentDraggableGeoLith : public QObject +{ + Q_OBJECT +public: + explicit TransparentDraggableGeoLith(QMyCustomPlot *parentPlot, QString strUuid="", double minWidth = 1.0, QString strTitle = "") + : QObject(parentPlot), mPlot(parentPlot), mstrTitle(strTitle), mMinWidth(minWidth) + { + m_strUuid = strUuid; + // + initRect(); + } + + ~TransparentDraggableGeoLith() { + if(mPlot) { +// mPlot->removeItem(mRect); +// mPlot->removeItem(mLeftHandle); +// mPlot->removeItem(mRightHandle); + } + } + + void DrawSVGNormal(QPainter* painter,QString svgFileName,QRectF borderRect,bool IsWellSectonHorizonLayout) + { + QString svg=svgFileName; + QRectF boundingRect = painter->transform().mapRect(borderRect); + painter->save(); + QTransform transform; + transform.reset(); + if (!IsWellSectonHorizonLayout) + { + painter->setWorldTransform(transform); + } + else + { + } + QPixmap tiledmap(svg); + QRect border(boundingRect.left(),boundingRect.top(),boundingRect.width(),boundingRect.height()); + painter->drawPixmap(border,tiledmap); + painter->restore(); + } + //拉伸 + void DrawSVGSteched(QPainter* painter,QString svgFileName,QRectF borderRect,bool IsWellSectonHorizonLayout) + { + QString svg=svgFileName; + QSvgRenderer m_SvgRenderer; + m_SvgRenderer.load(svg); + m_SvgRenderer.render(painter,borderRect); + } + //平铺 + void DrawSVGTiled(QPainter* painter,QString svgFileName,QRectF borderRect,bool IsWellSectonHorizonLayout) + { + QString svg=svgFileName; + QRectF boundingRect = painter->transform().mapRect(borderRect); + painter->save(); + QTransform transform; + transform.reset(); + if (!IsWellSectonHorizonLayout) + { + painter->setWorldTransform(transform); + } + else + { + } + QPixmap tiledmap(svg); + painter->drawTiledPixmap(boundingRect,tiledmap); + painter->restore(); + } + + + //设置最小宽度 + void setMinWidth(double minWidth){ + mMinWidth = minWidth; + } + + //设置标题 + void setTitle(QString strTitle){ + mstrTitle = strTitle; + mItemTitle->setText(mstrTitle); + mPlot->replot(); + } + + //设置解释结论 + void setLith(QString filePath, QString colorPath){ + m_Lith = filePath; + // + QString strLast = filePath.right(4); + if(strLast.toLower()==".svg") + { + QString path,filename; + GetWellNameAndPath(filePath, filename, path); + QString basename = filename.left(filename.size()-4); + + QString val=filePath; + QImage image(320,160,QImage::Format_RGB32); + QPainter painter(&image); + QRectF fillRect(0,0,320,160); + painter.fillRect(fillRect,Qt::white); + // + painter.setBrush(QBrush(QPixmap(colorPath))); + + //拉伸 + DrawSVGSteched(&painter,filePath,fillRect,0); + //平铺 + //DrawSVGTiled(&painter,filePath,fillRect,0); + //正常 + //DrawSVGNormal(&painter,filePath,fillRect,0); + + val=GetImagePath()+"TempNew"; + QDir ss; + if(!ss.exists(val)) { + ss.mkdir(val); + } + val+=QDir::separator(); + val+=basename+".png"; + image.save(val); + + // + mPixmap_Lith->setPixmap(QPixmap(val)); // 设置图片 + + +// QSvgRenderer* svgRender = new QSvgRenderer(); +// svgRender->load(result); +// // +// QPixmap* pixmap = new QPixmap(10, 10); +// pixmap->fill(Qt::transparent);//设置背景透明 +// QPainter p(pixmap); +// svgRender->render(&p); +// // +// mPixmap->setPixmap(*pixmap); // 设置图片 + } + else + { +// QString val=filePath; +// QImage image(47,16,QImage::Format_RGB32); +// QPainter painter(&image); +// QRectF fillRect(0,0,47,16); +// painter.fillRect(fillRect, QColor(0, 0, 0, 0)); +// // +// painter.setBrush(QBrush(QPixmap(colorPath))); + +// QPixmap* pixmap = new QPixmap(filePath); +// pixmap->fill(Qt::transparent);//设置背景透明 +// mPixmap_Lith->setPixmap(*pixmap); // 设置图片 + + mPixmap_Lith->setPixmap(QPixmap(filePath)); // 设置图片 + } + + + mPlot->replot(); + } + + //设置m_Oil + void setOil(QString filePath){ + m_Oil = filePath; + } + + void drawOil(double left_Low, double right_Hight, double lY1, double lY2) + { + if(m_Oil=="") + { + return; + } + + double x1 = mPlot->xAxis->coordToPixel(left_Low); + double x2 = mPlot->xAxis->coordToPixel(right_Hight); + double y1 = mPlot->yAxis->coordToPixel(lY1); + double y2 = mPlot->yAxis->coordToPixel(lY2); + + bool bWidthBig = false; + double newWidth = y2-y1; + double newHeight = x1-x2; + if(newWidth>newHeight) + { + //取小,画正方形框 + newWidth = newHeight; + bWidthBig = true; + } + + float rect_xRight = x2 + newHeight/ 2 - newWidth/ 2; + double xNewRight = mPlot->xAxis->pixelToCoord(rect_xRight); + // + float rect_xLeft = rect_xRight + newWidth; + double xNewLeft = mPlot->xAxis->pixelToCoord(rect_xLeft); + + // + QString filePath = m_Oil; + // + QString strLast = filePath.right(4); + if(strLast.toLower()==".svg") + { + QString path,filename; + GetWellNameAndPath(filePath, filename, path); + QString basename = filename.left(filename.size()-4); + + QString val=filePath; + QImage image(newWidth, newWidth,QImage::Format_RGB32); + QPainter painter(&image); + QRectF fillRect(0,0, newWidth, newWidth); + painter.fillRect(fillRect,Qt::white); + //拉伸 + DrawSVGSteched(&painter,filePath,fillRect,0); + //平铺 + //DrawSVGTiled(&painter,filePath,fillRect,0); + //正常 + //DrawSVGNormal(&painter,filePath,fillRect,0); + + val=GetImagePath()+"TempNew"; + QDir ss; + if(!ss.exists(val)) { + ss.mkdir(val); + } + val+=QDir::separator(); + val+=basename+".png"; + image.save(val); + + // + mPixmap_Oil->setPixmap(QPixmap(val)); // 设置图片 + } + else + { + mPixmap_Oil->setPixmap(QPixmap(filePath)); // 设置图片 + } + + mPixmap_Oil->topLeft->setCoords(xNewRight, mPlot->yAxis->pixelToCoord(y1+1)); //right_Hight, lY1 + mPixmap_Oil->bottomRight->setCoords(xNewLeft, lY2); //left_Low + + mPlot->replot(); + } + + //设置Color + void setColor(QString filePath){ + m_Color = filePath; + // + QString strLast = filePath.right(4); + if(strLast.toLower()==".svg") + { + QString path,filename; + GetWellNameAndPath(filePath, filename, path); + QString basename = filename.left(filename.size()-4); + + QString val=filePath; + QImage image(320,160,QImage::Format_RGB32); + QPainter painter(&image); + QRectF fillRect(0,0,320,160); + painter.fillRect(fillRect,Qt::white); + //拉伸 + DrawSVGSteched(&painter,filePath,fillRect,0); + //平铺 + //DrawSVGTiled(&painter,filePath,fillRect,0); + //正常 + //DrawSVGNormal(&painter,filePath,fillRect,0); + + val=GetImagePath()+"TempNew"; + QDir ss; + if(!ss.exists(val)) { + ss.mkdir(val); + } + val+=QDir::separator(); + val+=basename+".png"; + image.save(val); + + // + mPixmap_Color->setPixmap(QPixmap(val)); // 设置图片 + } + else + { + mPixmap_Color->setPixmap(QPixmap(filePath)); // 设置图片 + } + + //mPlot->replot(); + } + + // 设置矩形范围 + void setRange(double left_Low, double right_Hight) { + if(left_Low >= right_Hight) return; + + double lY1 = mPlot->yAxis->range().lower;//+10 + double lY2 = mPlot->yAxis->range().upper; + mRect->topLeft->setCoords(left_Low, lY1); + mRect->bottomRight->setCoords(right_Hight, lY2); + + //位置与rect不一样,否则图像反转 + mPixmap_Color->topLeft->setCoords(right_Hight, lY1+(lY2-lY1)/4); + mPixmap_Color->bottomRight->setCoords(left_Low, lY2); + // + mPixmap_Lith->topLeft->setCoords(right_Hight, lY1+(lY2-lY1)/4); + mPixmap_Lith->bottomRight->setCoords(left_Low, lY2); + + //位置与rect不一样,否则图像反转 + //mPixmap_Oil->topLeft->setCoords(right_Hight, lY1); + //mPixmap_Oil->bottomRight->setCoords(left_Low, lY1+(lY2-lY1)/4); + drawOil(left_Low, right_Hight, lY1, lY1+(lY2-lY1)/4); + + //mItemTitle->position->setCoords(0.5, 0.5); + // 设置父锚点,定位点 + //mItemTitle->position->setParentAnchor(mRect->bottom); + mItemTitle->position->setCoords((mRect->topLeft->coords().x() + mRect->bottomRight->coords().x())/2, + (mRect->topLeft->coords().y() + mRect->bottomRight->coords().y())/2); // 设置文本在矩形中心位置 + + //mRect->topLeft->setCoords(left, mPlot->yAxis->range().upper); + //mRect->bottomRight->setCoords(right, mPlot->yAxis->range().lower); + + updateHandles(); + mPlot->replot(); + } + + // 获取当前范围 + QCPRange getRange() const { + return QCPRange(mRect->topLeft->coords().x(), mRect->bottomRight->coords().x()); + } + + // 设置矩形颜色 + void setColor(const QColor &color) { + mRect->setBrush(QBrush(color)); + mRect->setPen(QPen(color.darker())); + mPlot->replot(); + } + + // 删除框图 + void deleteRect() { + if(mPlot) { + +// mRect->deleteLater(); +// mLeftHandle->deleteLater(); +// mRightHandle->deleteLater(); +// mPixmap->deleteLater(); + + mPlot->m_mapDraggable_GeoLith.remove(m_strUuid); + + mPlot->removeItem(mRect); + mPlot->removeItem(mLeftHandle); + mPlot->removeItem(mRightHandle); + mPlot->removeItem(mPixmap_Lith); + mPlot->removeItem(mPixmap_Oil); + mPlot->removeItem(mPixmap_Color); + mPlot->removeItem(mItemTitle); + + mPlot->replot(); + this->deleteLater(); + + // +// //避免二次绘制框图 +// mPlot->m_bDrawRect = false; +// mDragMode = DragNone; +// //取消选中框 +// mPlot->selectionRect()->cancel(); +// mPlot->replot(); +// mPlot->selectionRect()->mActive=true; + } + } + +signals: + void rangeChanged(QCPRange newRange); + +private: + void initRect() { + // 创建透明矩形 + mRect = new QCPItemRect(mPlot); + mRect->setLayer("overlay"); // 确保在最上层 + mRect->setBrush(QBrush(QColor(255, 255, 255, 50))); // 半透明蓝色100, 100, 255, 50 + mRect->setPen(QPen(QColor(70, 70, 255, 200))); + + // 创建左右边界控制点 + mLeftHandle = new QCPItemRect(mPlot); + mLeftHandle->setLayer("overlay"); + mLeftHandle->setBrush(QBrush(Qt::red)); + mLeftHandle->setPen(QPen(Qt::darkRed)); + + mRightHandle = new QCPItemRect(mPlot); + mRightHandle->setLayer("overlay"); + mRightHandle->setBrush(QBrush(Qt::red)); + mRightHandle->setPen(QPen(Qt::darkRed)); + + // 设置初始位置 + //double center = mPlot->xAxis->range().center(); +// setRange(center - 10, center + 10); + + // 连接鼠标事件 + connect(mPlot, &QCustomPlot::mousePress, this, &TransparentDraggableGeoLith::onMousePress); + connect(mPlot, &QCustomPlot::mouseMove, this, &TransparentDraggableGeoLith::onMouseMove); + connect(mPlot, &QCustomPlot::mouseRelease, this, &TransparentDraggableGeoLith::onMouseRelease); + + mPixmap_Lith = new QCPItemPixmap(mPlot); + //mPixmap->setPixmap(QPixmap(":/image/file.png")); // 设置图片 + mPixmap_Lith->setScaled(true, Qt::IgnoreAspectRatio); // 设置缩放方式 KeepAspectRatio + mPixmap_Lith->setLayer("overlay"); // 确保在最上层 + + mPixmap_Oil = new QCPItemPixmap(mPlot); + //mPixmap_Oil->setPixmap(QPixmap(":/image/file.png")); // 设置图片 + mPixmap_Oil->setScaled(true, Qt::IgnoreAspectRatio); // 设置缩放方式 KeepAspectRatio + mPixmap_Oil->setLayer("overlay"); // 确保在最上层 + + mPixmap_Color = new QCPItemPixmap(mPlot); + //mPixmap_Color->setPixmap(QPixmap(":/image/file.png")); // 设置图片 + mPixmap_Color->setScaled(true, Qt::IgnoreAspectRatio); // 设置缩放方式 KeepAspectRatio + mPixmap_Color->setLayer("overlay"); // 确保在最上层 + + mItemTitle = new QCPItemText(mPlot); + mItemTitle->setText(mstrTitle); + //mItemTitle->setBrush(QBrush(Qt::red)); + mItemTitle->setFont(QFont("Arial", 12, QFont::Bold)); + mItemTitle->setColor(Qt::black); + mItemTitle->setPositionAlignment(Qt::AlignTop | Qt::AlignHCenter); + mItemTitle->position->setType(QCPItemPosition::ptPlotCoords); + //mItemTitle->position->setType(QCPItemPosition::ptAxisRectRatio); + mItemTitle->position->setCoords(0.5, 0); + mItemTitle->setLayer("overlay"); + } + + void updateHandles() { + // 左边界矩形控制点 + mLeftHandle->topLeft->setParentAnchor(mRect->topLeft); + mLeftHandle->bottomRight->setParentAnchor(mRect->topRight);//(mRect->bottomLeft); + mLeftHandle->topLeft->setCoords(-0.5, 0.5); // 矩形大小 + mLeftHandle->bottomRight->setCoords(0.5, -0.5); // 矩形大小 + + // 右边界矩形控制点 + mRightHandle->topLeft->setParentAnchor(mRect->bottomLeft); + mRightHandle->bottomRight->setParentAnchor(mRect->bottomRight); + mRightHandle->topLeft->setCoords(-0.5, 0.5); // 矩形大小 + mRightHandle->bottomRight->setCoords(0.5, -0.5); // 矩形大小 + + } + +private slots: + void onDelRect() + { + //mDragMode = DragNone; + //删除框图 + deleteRect(); + } + + // 事件过滤器处理函数 +// bool eventFilter(QObject* object, QEvent* event) { +// if (event->type() == QEvent::MouseButtonPress) { +// // 拦截操作 +// return true; // 阻止事件传递 + +//// if (object == action) { +//// // 验证权限 +//// if (1) { +//// // 允许操作 +//// action->trigger(); +//// } else { +//// // 拦截操作 +//// return true; // 阻止事件传递 +//// } +//// } +// } +// return false; // 默认不拦截其他事件 +// } + + void onMousePress(QMouseEvent *event) { +// //右键 +// if(event->button() != Qt::LeftButton) +// { +// double y = mPlot->xAxis->pixelToCoord(event->pos().y());//x轴展示深度 +// QCPRange currentRange = getRange(); +// if(mLeftHandle->selectTest(event->pos(), false) < 5) { +// mDragMode = DragNone; +// } +// else if(mRightHandle->selectTest(event->pos(), false) < 5) { +// mDragMode = DragNone; +// } +// //else if(x >= currentRange.lower && x <= currentRange.upper) { +// else if(y >= currentRange.lower && y <= currentRange.upper) { +// mDragMode = DragNone; +// } +// else { +// mDragMode = DragNone; +// return; +// } +// //event->accept(); +// QMenu menu(nullptr); +// QAction *delAction = menu.addAction("删除框图"); +// //delAction->installEventFilter(this); +// connect(delAction, &QAction::triggered, this, &TransparentDraggableResult::onDelRect); +// QAction* pItem = menu.exec(event->globalPos()); +// if(pItem == delAction) +// { +// //event->accept(); +// int ii=0; +// ii++; +// } +// menu.exec(event->globalPos()); +// return; +// } + + event->accept(); + + // 检查点击了哪个部分 + //double x = mPlot->xAxis->pixelToCoord(event->pos().x()); + //double y = mPlot->yAxis->pixelToCoord(event->pos().y()); + + double y = mPlot->xAxis->pixelToCoord(event->pos().y());//x轴展示深度 + + QCPRange currentRange = getRange(); + + if(mLeftHandle->selectTest(event->pos(), false) < 5) { + mDragMode = DragLeft; + } + else if(mRightHandle->selectTest(event->pos(), false) < 5) { + mDragMode = DragRight; + } + //else if(x >= currentRange.lower && x <= currentRange.upper) { + else if(y >= currentRange.lower && y <= currentRange.upper) { + mDragMode = DragRect; + } + else { + mDragMode = DragNone; + return; + } + + //mDragStartX = x; + mDragStartY = y; + mDragStartRange = currentRange; + + } + + void onMouseMove(QMouseEvent *event) { + if(mDragMode == DragNone) return; + + event->accept(); + + //double x = mPlot->xAxis->pixelToCoord(event->pos().x()); + //double dx = x - mDragStartX; + + double y = mPlot->xAxis->pixelToCoord(event->pos().y()); + double dy = y - mDragStartY; + + QCPRange newRange = mDragStartRange; + + switch(mDragMode) { + case DragLeft: { + //double proposedLeft = mDragStartRange.lower + dx; + double proposedLeft = mDragStartRange.lower + dy; + // 确保不超出轴范围且不使宽度小于最小值 + newRange.lower = qBound( + //mPlot->xAxis->range().lower, + getMyLower(), + proposedLeft, + mDragStartRange.upper - mMinWidth); + break; + } + case DragRight: { + //double proposedRight = mDragStartRange.upper + dx; + double proposedRight = mDragStartRange.upper + dy; + // 确保不超出轴范围且不使宽度小于最小值 + newRange.upper = qBound( + mDragStartRange.lower + mMinWidth, + proposedRight, + getMyUpper()); + //mPlot->xAxis->range().upper); + break; + } + case DragRect: { + double width = mDragStartRange.size(); + //double center = mDragStartRange.center() + dx; + double center = mDragStartRange.center() + dy; + newRange.lower = center - width/2; + newRange.upper = center + width/2; + + // 检查是否超出轴范围 + if(newRange.lower < getMyLower()) { + newRange.lower = getMyLower(); + newRange.upper = newRange.lower + width; + } + else if(newRange.upper > getMyUpper()) { + newRange.upper = getMyUpper(); + newRange.lower = newRange.upper - width; + } + +// QCPRange axisRange = mPlot->xAxis->range(); +// if(newRange.lower < axisRange.lower) { +// newRange.lower = axisRange.lower; +// newRange.upper = newRange.lower + width; +// } +// else if(newRange.upper > axisRange.upper) { +// newRange.upper = axisRange.upper; +// newRange.lower = newRange.upper - width; +// } + break; + } + default: + break; + } + +// //取整数(方便显示统计,左右边界整数显示。) +// newRange.lower = (int)newRange.lower; +// QCPRange rangeByFile = mPlot->xAxis->range(); +// if (std::fabs(rangeByFile.upper - (int)newRange.upper) >= 1.0) +// { +// newRange.upper = (int)newRange.upper; +// } + + // 最终确保宽度不小于最小值(针对整体拖动的情况) + if(newRange.size() < mMinWidth) { + if(mDragMode == DragRect) { + // 如果是整体拖动,保持中心点不变 + double center = newRange.center(); + newRange.lower = center - mMinWidth/2; + newRange.upper = center + mMinWidth/2; + } else { + // 如果是边界拖动,强制设置最小宽度 + if(mDragMode == DragLeft) { + newRange.lower = newRange.upper - mMinWidth; + } else if(mDragMode == DragRight) { + newRange.upper = newRange.lower + mMinWidth; + } + } + } + + setRange(newRange.lower, newRange.upper); + + } + + void onMouseRelease(QMouseEvent *event) { + if(event->button() == Qt::LeftButton && mDragMode != DragNone) { + event->accept(); + //避免二次绘制框图 + mPlot->m_bDrawRect = false; + //emit rangeChanged(getRange()); + mDragMode = DragNone; + //取消选中状态 +// QCPDataSelection emptySelection; +// mPlot->graph(0)->setSelection(emptySelection); +// mPlot->replot(); + + //取消选中框 + mPlot->selectionRect()->cancel(); + mPlot->replot(); + mPlot->selectionRect()->mActive=true; + } + } + + double getMyLower() + { + double dLower = mPlot->xAxis->range().lower; + double proposedLeft = mDragStartRange.lower; + + TransparentDraggableGeoLith *pDraggableRect =NULL; + { + QMap::Iterator it = mPlot->m_mapDraggable_GeoLith.begin(); + while( it != mPlot->m_mapDraggable_GeoLith.end() ) + { + if(it.key() == m_strUuid) + { + it++; + continue; + } + pDraggableRect = (TransparentDraggableGeoLith*)it.value(); + // + QCPRange tmpRange = pDraggableRect->getRange(); + if(tmpRange.upper >= dLower && tmpRange.upper <= proposedLeft) + { + dLower = tmpRange.upper; + } + it++; + } + } + + return dLower; + } + + double getMyUpper() + { + double dUpper = mPlot->xAxis->range().upper; + double proposedRight = mDragStartRange.upper; + + TransparentDraggableGeoLith *pDraggableRect =NULL; + { + QMap::Iterator it = mPlot->m_mapDraggable_GeoLith.begin(); + while( it != mPlot->m_mapDraggable_GeoLith.end() ) + { + if(it.key() == m_strUuid) + { + it++; + continue; + } + pDraggableRect = (TransparentDraggableGeoLith*)it.value(); + // + QCPRange tmpRange = pDraggableRect->getRange(); + if(tmpRange.lower <= dUpper && tmpRange.lower >= proposedRight) + { + dUpper = tmpRange.lower; + } + it++; + } + } + + return dUpper; + } + +private: + QMyCustomPlot *mPlot; + QCPItemRect *mRect; + QCPItemRect *mLeftHandle; + QCPItemRect *mRightHandle; + + QCPItemPixmap *mPixmap_Lith; + QCPItemPixmap *mPixmap_Oil; + QCPItemPixmap *mPixmap_Color; + QCPItemText *mItemTitle; + QString mstrTitle=""; + QString m_strUuid = ""; + + QString m_Lith; + QString m_Oil; + QString m_Color; + + enum DragMode { DragNone, DragLeft, DragRight, DragRect }; + DragMode mDragMode = DragNone; + //double mDragStartX = 0; + double mDragStartY = 0; + QCPRange mDragStartRange; + + // 添加最小宽度成员变量 + double mMinWidth; +}; + +#endif // TRANSPARENTDRAGGABLEGEOLITH_H diff --git a/logPlus/TransparentDraggableRect.h b/logPlus/TransparentDraggableRect.h index c0a6bea..30f6ff5 100644 --- a/logPlus/TransparentDraggableRect.h +++ b/logPlus/TransparentDraggableRect.h @@ -117,7 +117,7 @@ private: // 创建透明矩形 mRect = new QCPItemRect(mPlot); mRect->setLayer("overlay"); // 确保在最上层 - mRect->setBrush(QBrush(QColor(100, 100, 255, 50))); // 半透明蓝色 + mRect->setBrush(QBrush(QColor(255, 255, 255, 50))); // 半透明蓝色 mRect->setPen(QPen(QColor(70, 70, 255, 200))); // 创建左右边界控制点 diff --git a/logPlus/TransparentDraggableResult.h b/logPlus/TransparentDraggableResult.h index cb8e3e6..0f3c1f1 100644 --- a/logPlus/TransparentDraggableResult.h +++ b/logPlus/TransparentDraggableResult.h @@ -98,8 +98,25 @@ public: } //设置解释结论 - void setResult(QString filePath){ + void setResult(QString filePath) + { m_Result = filePath; + } + + void drawResult(double left_Low, double right_Hight, double lY1, double lY2) + { + if(m_Result=="") + { + return; + } + + double x1 = mPlot->xAxis->coordToPixel(left_Low); + double x2 = mPlot->xAxis->coordToPixel(right_Hight); + double y1 = mPlot->yAxis->coordToPixel(lY1); + double y2 = mPlot->yAxis->coordToPixel(lY2); + + // + QString filePath = m_Result; // QString strLast = filePath.right(4); if(strLast.toLower()==".svg") @@ -109,9 +126,9 @@ public: QString basename = filename.left(filename.size()-4); QString val=filePath; - QImage image(320,160,QImage::Format_RGB32); + QImage image(y2-y1, x1-x2,QImage::Format_RGB32); QPainter painter(&image); - QRectF fillRect(0,0,320,160); + QRectF fillRect(0,0, y2-y1, x1-x2); painter.fillRect(fillRect,Qt::white); //拉伸 DrawSVGSteched(&painter,filePath,fillRect,0); @@ -157,13 +174,22 @@ public: if(left_Low >= right_Hight) return; double lY1 = mPlot->yAxis->range().lower;//+10 - double lY2 = mPlot->yAxis->range().upper/4; + double lY2 = (mPlot->yAxis->range().upper-mPlot->yAxis->range().lower)/4; mRect->topLeft->setCoords(left_Low, lY1); mRect->bottomRight->setCoords(right_Hight, lY2); //位置与rect不一样,否则图像反转 - mPixmap->topLeft->setCoords(right_Hight, lY1); - mPixmap->bottomRight->setCoords(left_Low, lY2); +// double dbCenterX = (right_Hight+left_Low)/2.0; //right_Hight; // +// double dbCenterY = (lY1+lY2)/2.0; //lY2; // +// double x1 = mPlot->xAxis->coordToPixel(dbCenterX); +// double y1 = mPlot->yAxis->coordToPixel(dbCenterY); +// mPixmap->topLeft->setCoords(mPlot->xAxis->pixelToCoord(x1), mPlot->yAxis->pixelToCoord(y1)); + mPixmap->topLeft->setCoords(right_Hight, lY2); + mPixmap->bottomRight->setCoords(left_Low, lY1); + drawResult(left_Low, right_Hight, lY1, lY2); + +// mPixmap->topLeft->setCoords(right_Hight, lY1); +// mPixmap->bottomRight->setCoords(left_Low, lY1); //mItemTitle->position->setCoords(0.5, 0.5); // 设置父锚点,定位点 @@ -233,7 +259,7 @@ private: // 创建透明矩形 mRect = new QCPItemRect(mPlot); mRect->setLayer("overlay"); // 确保在最上层 - mRect->setBrush(QBrush(QColor(100, 100, 255, 50))); // 半透明蓝色 + mRect->setBrush(QBrush(QColor(255, 255, 255, 50))); // 半透明蓝色 mRect->setPen(QPen(QColor(70, 70, 255, 200))); // 创建左右边界控制点 diff --git a/logPlus/formdraw.cpp b/logPlus/formdraw.cpp index 81f5b5a..d4bbe7f 100644 --- a/logPlus/formdraw.cpp +++ b/logPlus/formdraw.cpp @@ -272,7 +272,7 @@ void FormDraw::s_addWave(QString strUuid, QString strSlfName, QString strWellNam void FormDraw::s_addTableLine(QString strUuid, QString strSlfName, QString strWellName, QString strTrackName, QString strLineName) { - if(strLineName == "FRAC_HOLE.TABLE" || strLineName == "WORDS_RELUST" || strLineName == "RESULT") + if(strLineName == "FRAC_HOLE.TABLE" || strLineName == "WORDS_RELUST" || strLineName == "RESULT"|| strLineName == "GEO_LITH") { } @@ -350,6 +350,12 @@ void FormDraw::s_addTableLine(QString strUuid, QString strSlfName, QString strWe //解释结论 initResult(curv, strSlfName, strLineName); } + else if(strLineName == "GEO_LITH") + { + //录井剖面 + initGeoLith(curv, strSlfName, strLineName); + } + connect(curv, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(s_mouseWheel(QWheelEvent*))); // @@ -1594,6 +1600,158 @@ void FormDraw::initResult(QMyCustomPlot *widget, QString strSlfName, QString str } +//录井剖面 +void FormDraw::initGeoLith(QMyCustomPlot *widget, QString strSlfName, QString strLineName) +{ + + int iMyWidth = widget->axisRect(0)->width(); + float vmax = iMyWidth; + float vmin = 0; + widget->m_iX1 = vmin; + widget->m_iX2 = iMyWidth; + widget->m_iY1 = g_iY1; + widget->m_iY2 = g_iY2; + // + widget->xAxis->setRange(vmin, vmax); + widget->yAxis->setRange(g_iY1, g_iY2); + widget->axisRect()->setupFullAxesBox(); + // + widget->xAxis->ticker()->setTickCount(10);//x个主刻度 + widget->yAxis->ticker()->setTickCount(60);//y个主刻度 + + //对调XY轴,在最前面设置 + QCPAxis *yAxis = widget->yAxis; + QCPAxis *xAxis = widget->xAxis; + widget->xAxis = yAxis; + widget->yAxis = xAxis; + + + m_LeftVal = 0; + m_RightVal = 90; + //隐藏刻度 + widget->xAxis->setTicks(false); + widget->yAxis->setTicks(false); + widget->xAxis2->setTicks(false); + widget->yAxis2->setTicks(false); + // + LoadFromSLF_GeoLith(widget, strSlfName, strLineName); + + QString strAliasName = ""; + QString strUnit = ""; + QColor newlineColor=QColor(0,0,0); + double width=2; + QString strScaleType = ""; + //道-对象 + m_formTrack->Add(strSlfName, m_strWellName, m_strTrackName, strLineName, strAliasName, strUnit, newlineColor, width, m_RightVal, m_LeftVal, strScaleType, "tableObject"); + +} + +bool FormDraw::LoadFromSLF_GeoLith(QMyCustomPlot *widget, QString strSlfName, QString strLineName) +{ + CMemRdWt *logio=new CMemRdWt(); + if(!logio->Open(strSlfName.toStdString().c_str(),CSlfIO::modeRead)) + { + delete logio; + return false; + } + int iIndex=logio->OpenTable(strLineName.toStdString().c_str()); + if(iIndex>-1) { + int len=logio->GetTableRecordLength(iIndex); + int sl=sizeof(GeoLith_DATA); + if(sl>len) len=sl; + GeoLith_DATA *m_Result; + m_Result=(GeoLith_DATA *)new char[len+1]; + int count=logio->GetTableRecordCount(iIndex); + for(int i=0;iReadTable(iIndex,i+1,m_Result); + // + QMap OilOrder; + QMap LithOrder; + QMap ColorOrder; + QMap ColorInds; + // + LithOrder=GetZoneOrder(QString("GeoLith")); + OilOrder=GetZoneOrder(QString("CoreOil")); + ColorOrder=GetZoneOrder(QString("CoreColor")); + ColorInds=GetZoneOrder(QString("ColorInd")); + + QString iconshotname=""; + QString IntLith = QString::number(m_Result->Lith); + if(IntLith=="0") { + iconshotname=""; + } + else + { + iconshotname=LithOrder.key(IntLith); + } + + // + QString Lith = ""; + if(iconshotname!="") + Lith=::GetMudSymbolDir()+""+iconshotname+".svg"; + int len=2; + int pos=Lith.indexOf(".//"); + if(pos<0) pos=Lith.indexOf("./"); + else len=3; + QString svg; + if(pos==0) + { + svg=QCoreApplication::applicationDirPath()+ QDir::separator(); + svg+=Lith.mid(len-1); + } + else svg=Lith; + QDir ss; + if(!ss.exists(svg)) + { + QString path=svg.left(svg.lastIndexOf('.')+1); + svg=path+"png"; + } + Lith=svg; + + // + QString Oil = ""; + iconshotname=OilOrder.key(QString::number(m_Result->Oil)); + if(iconshotname!="") + Oil=::GetGasSymbolDir()+""+iconshotname+".svg"; + len=2; + pos=Oil.indexOf(".//"); + if(pos<0) pos=Oil.indexOf("./"); + else len=3; + if(pos==0) + { + svg=QCoreApplication::applicationDirPath()+ QDir::separator(); + svg+=Oil.mid(len-1); + } + else svg=Oil; + if(!ss.exists(svg)) + { + QString path=svg.left(svg.lastIndexOf('.')+1); + svg=path+"png"; + } + Oil=svg; + + // + QString Color = ""; + int ind=ColorInds.value(QString::number(m_Result->Color)).toInt(); + if (ind>-1&&indaddGeoLithToPlot(-m_Result->EDEP, -m_Result->SDEP, Lith, Oil, Color); + } + logio->CloseTable(iIndex); + delete m_Result; + } + delete logio; + return true; +} + bool FormDraw::LoadFromSLF_Result(QMyCustomPlot *widget, QString strSlfName, QString strLineName) { static bool isrun=false; diff --git a/logPlus/formdraw.h b/logPlus/formdraw.h index 377c0b6..766e30e 100644 --- a/logPlus/formdraw.h +++ b/logPlus/formdraw.h @@ -142,6 +142,10 @@ public: void initResult(QMyCustomPlot *widget, QString strSlfName, QString strLineName); bool LoadFromSLF_Result(QMyCustomPlot *widget, QString strSlfName, QString strLineName); + //录井剖面 + void initGeoLith(QMyCustomPlot *widget, QString strSlfName, QString strLineName); + bool LoadFromSLF_GeoLith(QMyCustomPlot *widget, QString strSlfName, QString strLineName); + signals: //void sig_AddLine(QString strSlfName, QString strWellName, QString strTrackName, QString strLineName); diff --git a/logPlus/logPlus.pro b/logPlus/logPlus.pro index e0bc2e3..8be6611 100644 --- a/logPlus/logPlus.pro +++ b/logPlus/logPlus.pro @@ -70,6 +70,7 @@ HEADERS += \ PropertyWidget.h \ QCPSizeHandle.h \ QCPSizeHandleManager.h \ + TransparentDraggableGeoLith.h \ TransparentDraggableRect.h \ TransparentDraggableResult.h \ backgrounddelegate.h \ diff --git a/logPlus/qmycustomplot.cpp b/logPlus/qmycustomplot.cpp index 0638ff3..82e50e3 100644 --- a/logPlus/qmycustomplot.cpp +++ b/logPlus/qmycustomplot.cpp @@ -3,6 +3,7 @@ #include "geometryutils.h" #include "TransparentDraggableRect.h" #include "TransparentDraggableResult.h" +#include "TransparentDraggableGeoLith.h" #include "qtcommonclass.h" //是否隐藏刻度 @@ -240,7 +241,7 @@ void QMyCustomPlot::addImageToPlot(double left_Low, double right_Hight, const QS // 设置初始范围 dragRect->setRange(left_Low, right_Hight); // 可选:设置颜色 - dragRect->setColor(QColor(255, 100, 100, 80)); // 半透明红色 + dragRect->setColor(QColor(255, 255, 255, 80)); // 半透明红色 //最小宽度 dragRect->setMinWidth(0.1); @@ -257,7 +258,7 @@ void QMyCustomPlot::addTextToPlot(double left_Low, double right_Hight, const QSt // 设置初始范围 dragRect->setRange(left_Low, right_Hight); // 可选:设置颜色 - dragRect->setColor(QColor(255, 100, 100, 80)); // 半透明红色 + dragRect->setColor(QColor(255, 255, 255, 80)); // 半透明红色 //最小宽度 dragRect->setMinWidth(0.1); dragRect->setTitle(strText); @@ -280,18 +281,41 @@ void QMyCustomPlot::addResultToPlot(double left_Low, double right_Hight, QStrin // 在初始化代码中 TransparentDraggableResult *dragRect = new TransparentDraggableResult(this, upDragRect, strUuid); + //图片,提前设值,后面setRange改变 + dragRect->setResult(myResult); // 设置初始范围 dragRect->setRange(left_Low, right_Hight); // 可选:设置颜色 - dragRect->setColor(QColor(255, 100, 100, 80)); // 半透明红色 + dragRect->setColor(QColor(255, 255, 255, 80)); // 半透明红色 //最小宽度 dragRect->setMinWidth(0.1); - dragRect->setResult(myResult); dragRect->setTitle(strText); m_mapDraggable_Result[strUuid] = dragRect; } +void QMyCustomPlot::addGeoLithToPlot(double left_Low, double right_Hight, const QString myLith, const QString myOil, const QString myColor) +{ + QtCommonClass *qtCommon = new QtCommonClass(this); + QString strUuid = qtCommon->getUUid(); + + // 在初始化代码中 + TransparentDraggableGeoLith *dragRect = new TransparentDraggableGeoLith(this, strUuid); + //图片,提前设值,后面setRange改变 + dragRect->setOil(myOil); + + // 设置初始范围 + dragRect->setRange(left_Low, right_Hight); + // 可选:设置颜色 + dragRect->setColor(QColor(255, 255, 255, 80)); // 半透明红色255, 100, 100, 80 + //最小宽度 + dragRect->setMinWidth(0.1); + //dragRect->setColor(myColor); + dragRect->setLith(myLith,myColor); + + m_mapDraggable_GeoLith[strUuid] = dragRect; +} + void QMyCustomPlot::onResetZoom() { diff --git a/logPlus/qmycustomplot.h b/logPlus/qmycustomplot.h index 0dccb53..8ce45a8 100644 --- a/logPlus/qmycustomplot.h +++ b/logPlus/qmycustomplot.h @@ -61,6 +61,7 @@ public: QMap m_mapDraggableRect; QMap m_mapDraggable_Result; + QMap m_mapDraggable_GeoLith; public slots: void slot_time(); @@ -75,6 +76,8 @@ public: void addResultToPlot(double left_Low, double right_Hight, QString myResult, QString &strUuid, QString strText=""); + void addGeoLithToPlot(double left_Low, double right_Hight, const QString myLith, const QString myOil, const QString myColor); + public slots: void s_LineClicked(int index); void onResetZoom();