Ver Fonte

接入料盒真实数据

JonYang há 6 horas atrás
pai
commit
1ee758b69b

+ 12 - 0
View/die-bonder-ui/CameraMaterialGroupWnd/CameraImage/CameraImageHandler.cpp

@@ -134,6 +134,18 @@ QString CameraImageHandler::CreateMaterialType(MATERIAL_TYPE materialType)
         {
             strLoadPatch = "MaterialBox";
             m_pMaterialBox = new MaterialBox(0);
+            if (m_pCViewInterface != nullptr)
+            {
+                std::vector<ns_module::MATERIAL_BOX_STRUCT> veMaterial;
+
+                m_pCViewInterface->GetMaterialBoxAllPointInfo(veMaterial);
+                m_pMaterialBox->UpdataVal(veMaterial);
+            }
+            else
+            {
+                m_pMaterialBox->UpdataGenerateTestData();
+            }
+
         }
         break;
         case MATERIAL_BOND:

+ 12 - 0
View/die-bonder-ui/CameraMaterialGroupWnd/Group.cpp

@@ -76,6 +76,18 @@ Group::Group(int groupId,const CameraInfo& cameraInfo, ns_module::CViewInterface
     else if (cameraInfo.eType == 3) 
     {
         m_pMaterialbox = new MaterialBox(0, ui->Imagewidget_right);
+        if (m_pCViewInterface != nullptr)
+        {
+            std::vector<ns_module::MATERIAL_BOX_STRUCT> veMaterial;
+
+            m_pCViewInterface->GetMaterialBoxAllPointInfo(veMaterial);
+            m_pMaterialbox->UpdataVal(veMaterial);
+        }
+        else
+        {
+            m_pMaterialbox->UpdataGenerateTestData();
+        }
+
         MaterialBoxWidget();
     }
     else if (cameraInfo.eType == 4)

+ 63 - 36
View/die-bonder-ui/CameraMaterialGroupWnd/MaterialWindow/MaterialBox.cpp

@@ -1,17 +1,10 @@
 #include "MaterialBox.h"
 
 // 构造函数
-MaterialBox::MaterialBox(int flag, QWidget *parent) : QWidget(parent)
+MaterialBox::MaterialBox(int flag, QWidget *parent) : 
+    QWidget(parent)
 {
-    boxes = {
-        2,      // iCurrLayers
-        32,      // iLayersTotal
-        100,    // iTopLev
-        50,     // iBottomLev
-        {15.5, 20.3}, // 补全所有子成员
-        {1,0,1,1,0},
-        // ...后续成员保持相同
-    };
+    
 
 }
 
@@ -52,22 +45,28 @@ void MaterialBox::paintInitFrom(QWidget *parent)
     int innerY = containerHeightdp + 5;
 
     // 根据层数自动计算间距和矩形高度
-    const int totalLayers = boxes.iLayersTotal;
+    const int totalLayers = m_boxes.iLayersTotal;
     const float spacing = static_cast<float>((static_cast<float>(innerHeight -totalLayers)) /static_cast<float>(totalLayers)); // 每个矩形之间的固定间距(像素)
-    qDebug()<<spacing;
+    //qDebug()<<spacing;
     float rectHeight =  2.5;
     const float rectWeight = static_cast<float>(innerWidth);
-    if((0<=totalLayers)&&(totalLayers<=8)){
+    if ((0 <= totalLayers) && (totalLayers <= 8))
+    {
         rectHeight =  2.5;
-    }else if((9<=totalLayers)&&(totalLayers<=16)){
+    }
+    else if((9<=totalLayers)&&(totalLayers<=16))
+    {
         rectHeight =  1.5;
-    }else{
+    }
+    else
+    {
         rectHeight =  1;
     }
 
     // 逐层绘制状态矩形
-    for(int i = 0; i < totalLayers; ++i) {
-        const QColor color = boxes.iStatas[i] ? QColor(40, 129, 5) : QColor(255, 0, 0); // 1=绿,0=红
+    for(int i = 0; i < totalLayers; ++i)
+    {
+        const QColor color = m_boxes.iStatas[i] ? QColor(40, 129, 5) : QColor(255, 0, 0); // 1=绿,0=红
         const int yPos = innerY + i * (rectHeight + spacing);
         painter.setPen(Qt::NoPen); // 去掉边框
         painter.setBrush(color);
@@ -76,12 +75,13 @@ void MaterialBox::paintInitFrom(QWidget *parent)
 
 }
 
-QPixmap MaterialBox::getGlobalPixmap() const {
+QPixmap MaterialBox::getGlobalPixmap() const 
+{
     return globalPixmap;
 }
 
-void MaterialBox::initFrom(QWidget *parent){
-
+void MaterialBox::initFrom(QWidget *parent)
+{
     int ratio = parent->height()/100;
     // 主容器尺寸(占窗口80%)
     // qDebug()<<ratio;
@@ -97,37 +97,64 @@ void MaterialBox::initFrom(QWidget *parent){
     int innerY = containerHeightdp + 5*ratio;
 
     // 根据层数自动计算间距和矩形高度
-    const int totalLayers = boxes.iLayersTotal;
+    const int totalLayers = m_boxes.iLayersTotal;
     const float spacing = static_cast<float>((static_cast<float>(innerHeight -totalLayers*ratio)) /static_cast<float>(totalLayers)); // 每个矩形之间的固定间距(像素)
-    qDebug()<<spacing;
+    //qDebug()<<spacing;
     float rectHeight =  2.5*ratio;
     const float rectWeight = static_cast<float>(innerWidth);
-    if((0<=totalLayers)&&(totalLayers<=8)){
+    if((0<=totalLayers)&&(totalLayers<=8))
+    {
         rectHeight =  2.5*ratio;
-    }else if((9<=totalLayers)&&(totalLayers<=16)){
+    }
+    else if((9<=totalLayers)&&(totalLayers<=16))
+    {
         rectHeight =  1.5*ratio;
-    }else{
+    }
+    else
+    {
         rectHeight =  1*ratio;
     }
 
     BackgroundRect* backgroundRect = new BackgroundRect(containerWidthdp, containerHeightdp, containerWidth, containerHeight);
-    scene = new QGraphicsScene(parent);
-    view = new MaterialBoxGraphicsView(scene);
-    scene->addItem(backgroundRect);
-    for (int i = 0; i < totalLayers; ++i) {
-        MaterialBoxDie* materialBoxDie = new MaterialBoxDie(i, 0, boxes.iStatas[i],rectWeight, rectHeight);
+    m_pScene = new QGraphicsScene(parent);
+    m_pView = new MaterialBoxGraphicsView(m_pScene);
+    m_pScene->addItem(backgroundRect);
+    for (int i = 0; i < totalLayers; ++i) 
+    {
+        MaterialBoxDie* materialBoxDie = new MaterialBoxDie(i, 0, m_boxes.iStatas[i],rectWeight, rectHeight);
         materialBoxDie->setPos(innerX,(innerY+ i * (rectHeight + spacing) ));
-        scene->addItem(materialBoxDie);
+        m_pScene->addItem(materialBoxDie);
 
     }
-    connect(view, &MaterialBoxGraphicsView::layerRightClicked, this, &MaterialBox::handleLayerRightClicked);
-    view->resize(parent->width(), parent->height());
-    view->resetTransform();
-    view->setSceneRect(0, 0, parent->width(), parent->height());
+    connect(m_pView, &MaterialBoxGraphicsView::layerRightClicked, this, &MaterialBox::handleLayerRightClicked);
+    m_pView->resize(parent->width(), parent->height());
+    m_pView->resetTransform();
+    m_pView->setSceneRect(0, 0, parent->width(), parent->height());
+}
 
+void MaterialBox::UpdataVal(std::vector<ns_module::MATERIAL_BOX_STRUCT>& veMaterial)
+{
+    for (auto& a : veMaterial)
+    {
+        m_boxes = a;
+    }
+}
 
+void MaterialBox::UpdataGenerateTestData()
+{
+    m_boxes = {
+        2,      // iCurrLayers
+        32,      // iLayersTotal
+        100,    // iTopLev
+        50,     // iBottomLev
+        {15.5, 20.3}, // 补全所有子成员
+        {1,0,1,1,0},
+        // ...后续成员保持相同
+    };
 }
-void MaterialBox::handleLayerRightClicked(int layer) {
+
+void MaterialBox::handleLayerRightClicked(int layer)
+{
     qDebug() << "Right-clicked on layer:" << layer;
     // 在这里可以添加其他处理逻辑,例如发送信号到其他对象
 }

+ 21 - 20
View/die-bonder-ui/CameraMaterialGroupWnd/MaterialWindow/MaterialBox.h

@@ -11,44 +11,45 @@
 #include "MaterialBoxGraphicsView.h"
 #include <QFrame>
 #include <dt.h>
+#include "CViewInterface.h"
 // 枚举定义:料盒的状态
 enum BoxStatus {
     Idle,       // 空闲
     Occupied,   // 已占用
 };
 
-typedef struct
-{
-    int iCurrLayers;				//当前工作层
-    int iLayersTotal;               //总层数
-    int iTopLev;                    //最上层高度
-    int iBottomLev;                 //最下层高度
-    XY_DOUBLE_STRUCT stPos;         //料盒位置;
-    int iStatas[32];				//每层状态,0表示空,1表示有料。
-    int iLength;                    //料盒长度
-    int iLeight;                    //料盒高度
-    int iWall;                      //侧壁厚
-    int iTopWall;                   //上壁厚
-    int iBelowWall;                 //下壁厚
-}MATERIAL_BOX_STRUCT;
-
 // 料盒
-class MaterialBox : public QWidget {
+class MaterialBox : public QWidget 
+{
 public:
     MaterialBox(int flag, QWidget *parent = nullptr);
+
     void paintInitFrom(QWidget *parent);
+
     QPixmap getGlobalPixmap() const;
+
     void initFrom(QWidget *parent);
-    MaterialBoxGraphicsView* view;
-    QGraphicsScene* scene;
+
+    void UpdataVal(std::vector<ns_module::MATERIAL_BOX_STRUCT>& veMaterial);
+
+    void UpdataGenerateTestData();
+
 private slots:
     void handleLayerRightClicked(int layer);
+
 protected:
     void paintEvent(QPaintEvent *event) override;
 
 private:
-    MATERIAL_BOX_STRUCT boxes; // 所有料盒的数据
-    QPixmap globalPixmap;
+    // 所有料盒的数据
+    ns_module::MATERIAL_BOX_STRUCT  m_boxes; 
+
+    QPixmap                         globalPixmap;
+
+public:
+    MaterialBoxGraphicsView*        m_pView = nullptr;
+
+    QGraphicsScene*                 m_pScene = nullptr;
 };
 
 #endif // MATERIALBOX_H

+ 2 - 2
View/die-bonder-ui/Src/RewriteControl/ControlOperationPage.cpp

@@ -197,8 +197,8 @@ void ControlOperationPage::KindsofWidget(kinds kind)
         {
             isRun = true;
             m_materialbox->initFrom(ui->Operatewidget);
-            layout->addWidget(m_materialbox->view);
-            m_currentView = m_materialbox->view;
+            layout->addWidget(m_materialbox->m_pView);
+            m_currentView = m_materialbox->m_pView;
         }
 
     }