Explorar el Código

0406 处理类

caizm hace 2 años
padre
commit
b8c206e4fa

+ 2 - 4
CAE_Solution/src/Rabbitmq/rabbitClient/rabbitClient.pri

@@ -1,9 +1,7 @@
 HEADERS += \
         $$PWD/ \
-        $$PWD/rabbitclient.h \
-    $$PWD/vtkjsonobject.h
+        $$PWD/rabbitclient.h
 
 SOURCES += \
         $$PWD/ \
-        $$PWD/rabbitclient.cpp \
-    $$PWD/vtkjsonobject.cpp
+        $$PWD/rabbitclient.cpp

+ 55 - 114
CAE_Solution/src/Rabbitmq/rabbitClient/rabbitclient.cpp

@@ -61,17 +61,15 @@ int rabbitClient::sendMsg(const std::string str)
     printf("-------------rabbit client sendmsg----------------------\n");
     int iRet;
     amqp_basic_properties_t properties = {};
-    std::string msg = this->readImg(str);
-    CMessage cmsg(msg, properties, objRabbitmq->routing_keys_name);
+    CMessage cmsg(str, properties, objRabbitmq->routing_keys_name);
     iRet = objRabbitmq->PublishMessage(cmsg, ErrorReturn);
-
     if(iRet!=0){
         cout<<"Send Rabbitmq publish Message : "<<ErrorReturn <<endl;
         disconnect_index++;
         if(disconnect_index == 15){
             connection_state = false;
             disConnect();
-            emit restart_send_client_signal();
+            emit restart_send_client_signal();//信号
             return -1;
         }
     }else {
@@ -100,27 +98,23 @@ int rabbitClient::recvMsg()
             if(disconnect_index == 15){
                 connection_state = false;
                 disConnect();
-                emit restart_recv_client_signal();
+                emit restart_recv_client_signal();//信号
                 return -1;
             }
         }
         disconnect_index = 0;
         cout<<str<<endl;
         printf("------------recvClient recvMsg-------------------\n");
-
-
-        if(str!="") emit recv(QString::fromStdString(str));
-
+        if(str!="")
+            emit sendmsg_recvclientToRecvstate(QString::fromStdString(str));//信号
         QThread::sleep(1);
-        //cout<<"recv"<<endl;
-
     }
     return 0;
 }
 
 
 /*
- * @brief: init recvClient
+ * @brief: init recvClient(初始化接收客户机)
  * @param: void
  * @ret: void
  * @birth: created by czm in 20230327
@@ -130,9 +124,7 @@ void rabbitClient::initRecv()
     rconf = new ReadConf();
     QString path = QDir::currentPath()+"/"+RECVCONFPATH;
     ReadConf rconf_;
-    //cout<<path.toStdString()<<endl;
     rconf->Read_Conf(path.toStdString(),rconf_);
-
     objRabbitmq = new CRabbitMqClient(rconf_.host,
                                       rconf_.port,
                                       rconf_.userName,
@@ -146,7 +138,7 @@ void rabbitClient::initRecv()
 }
 
 /*
- * @brief: init sendClient
+ * @brief: init sendClient(初始化发送客户机)
  * @param: void
  * @ret: void
  * @birth: created by czm in 20230327
@@ -155,11 +147,8 @@ void rabbitClient::initSend()
 {
     rconf = new ReadConf();
     QString path = QDir::currentPath()+"/"+SENDCONFPATH;
-    //printf("path: %s\n", path.toStdString().c_str());
     ReadConf rconf_;
     rconf->Read_Conf(path.toStdString(),rconf_);
-    //std::cout<<"host :"<<rconf_.host<<" port:"<<rconf_.port<<" usr name:"<<rconf_.userName<<" psword:"<<rconf_.password<<" channel_id:"<<rconf_.channel_id<<" queue_name:"<<rconf_.queue_name<<" exchange_name:"<<rconf_.exchange_name<<" keys_name:"<<rconf_.keys_name<<std::endl;
-
     objRabbitmq = new CRabbitMqClient(rconf_.host,
                                       rconf_.port,
                                       rconf_.userName,
@@ -173,7 +162,7 @@ void rabbitClient::initSend()
 }
 
 /*
- * @brief: disconnect Client
+ * @brief: disconnect Client(断开连接)
  * @param: void
  * @ret: int 0-success other-fail
  * @birth: created by czm in 20230327
@@ -185,7 +174,7 @@ int rabbitClient::disConnect()
 }
 
 /*
- * @brief: connect recv Client
+ * @brief: connect recv Client(接收客户机连接)
  * @param: void
  * @ret: int 0-success other-fail
  * @birth: created by czm in 20230327
@@ -195,126 +184,78 @@ void rabbitClient::recv_connect()
     int iRet = objRabbitmq->Connect(ErrorReturn);
     if(iRet != 0){
         connection_state = false;
-        emit restart_recv_client_signal();
+        emit restart_recv_client_signal();//信号
         cout<<iRet<<endl;
         cout<<"Recv Rabbitmq Connect : "<<ErrorReturn<<endl;
         return;
     }
     connection_state = true;
 
-    CExchange my_exchange(objRabbitmq->exchange_name);
-    iRet = objRabbitmq->DeclareExchange(my_exchange,
-                                        ErrorReturn);
-    if(iRet!=0){
-        cout<<iRet<<endl;
-        cout<<"Recv Rabbitmq ExchangeDeclare : "<<ErrorReturn<<endl;
-    }
-
-    CQueue my_Queue(objRabbitmq->queue_name);
-    iRet = objRabbitmq->DeclareQueue(my_Queue,
-                                     ErrorReturn);
-    if(iRet!=0){
-        cout<<iRet<<endl;
-        cout<<"Recv Rabbitmq QueueDeclare : "<<ErrorReturn<<endl;
-    }
-
-    iRet = objRabbitmq->BindQueueToExchange(my_Queue, my_exchange,
-                                            objRabbitmq->routing_keys_name,
-                                            ErrorReturn);
-    if(iRet!=0){
-        cout<<iRet<<endl;
-        cout<<"Recv Rabbitmq QueueBind : "<<ErrorReturn<<endl;
-    }
+//    CExchange my_exchange(objRabbitmq->exchange_name);
+//    iRet = objRabbitmq->DeclareExchange(my_exchange,
+//                                        ErrorReturn);
+//    if(iRet!=0){
+//        cout<<iRet<<endl;
+//        cout<<"Recv Rabbitmq ExchangeDeclare : "<<ErrorReturn<<endl;
+//    }
+
+//    CQueue my_Queue(objRabbitmq->queue_name);
+//    iRet = objRabbitmq->DeclareQueue(my_Queue,
+//                                     ErrorReturn);
+//    if(iRet!=0){
+//        cout<<iRet<<endl;
+//        cout<<"Recv Rabbitmq QueueDeclare : "<<ErrorReturn<<endl;
+//    }
+
+//    iRet = objRabbitmq->BindQueueToExchange(my_Queue, my_exchange,
+//                                            objRabbitmq->routing_keys_name,
+//                                            ErrorReturn);
+//    if(iRet!=0){
+//        cout<<iRet<<endl;
+//        cout<<"Recv Rabbitmq QueueBind : "<<ErrorReturn<<endl;
+//    }
     disconnect_index =0;
 }
 
 /*
- * @brief: connect send Client
+ * @brief: connect send Client(连接发送客户机)
  * @param: void
  * @ret: int 0-success other-fail
  * @birth: created by czm in 20230327
  */
 void rabbitClient::send_connect()
 {
-    //std::cout<<"host :"<<rconf_.host<<" port: "<<rconf_.port<<" usr name:"<<rconf_.userName<<" psword: "<<rconf_.password<<" channel_id: "<<rconf_.channel_id<<" queue_name: "<<rconf_.queue_name<<" exchange_name: "<<rconf_.exchange_name<<" keys_name: "<<rconf_.keys_name<<std::endl;
     int iRet = objRabbitmq->Connect(ErrorReturn);
     if(iRet != 0){
         connection_state = false;
-        emit restart_send_client_signal();
+        emit restart_send_client_signal();//信号
         cout<<iRet<<endl;
         cout<<"Send Rabbitmq Connect : "<<ErrorReturn<<endl;
         return;
     }
     connection_state = true;
 
-    CExchange my_exchange(objRabbitmq->exchange_name);
-    iRet = objRabbitmq->DeclareExchange(my_exchange,ErrorReturn);
-    if(iRet!=0){
-        cout<<iRet<<endl;
-        cout<<"Send Rabbitmq ExchangeDeclare : "<<ErrorReturn<<endl;
-    }
-
-
-    CQueue my_Queue(objRabbitmq->queue_name);
-    iRet = objRabbitmq->DeclareQueue(my_Queue, ErrorReturn);
-    if(iRet!=0){
-        cout<<iRet<<endl;
-        cout<<"Send Rabbitmq QueueDeclare : "<<ErrorReturn<<endl;
-    }
-
-    iRet = objRabbitmq->BindQueueToExchange(my_Queue, my_exchange, objRabbitmq->routing_keys_name, ErrorReturn);
-    if(iRet!=0){
-        cout<<iRet<<endl;
-        cout<<"Send Rabbitmq QueueBind : "<<ErrorReturn<<endl;
-    }
+//    CExchange my_exchange(objRabbitmq->exchange_name);
+//    iRet = objRabbitmq->DeclareExchange(my_exchange,ErrorReturn);
+//    if(iRet!=0){
+//        cout<<iRet<<endl;
+//        cout<<"Send Rabbitmq ExchangeDeclare : "<<ErrorReturn<<endl;
+//    }
+
+
+//    CQueue my_Queue(objRabbitmq->queue_name);
+//    iRet = objRabbitmq->DeclareQueue(my_Queue, ErrorReturn);
+//    if(iRet!=0){
+//        cout<<iRet<<endl;
+//        cout<<"Send Rabbitmq QueueDeclare : "<<ErrorReturn<<endl;
+//    }
+
+//    iRet = objRabbitmq->BindQueueToExchange(my_Queue, my_exchange, objRabbitmq->routing_keys_name, ErrorReturn);
+//    if(iRet!=0){
+//        cout<<iRet<<endl;
+//        cout<<"Send Rabbitmq QueueBind : "<<ErrorReturn<<endl;
+//    }
     disconnect_index = 0;
 }
 
 
-/*
- * @brief: read img by binary and change to base64
- * @param: img path
- * @ret: Base64 encoded image information
- * @birth: created by czm in 20230404
- */
-string rabbitClient::readImg(string img_path)
-{
-    //    printf("-----------read img start-----------------\n");
-    //    //用来存储读取出来的字节数据
-    //    std::string img_data_str;
-    //    ifstream i_f_stream(img, ifstream::binary);
-    //    i_f_stream.seekg(0, i_f_stream.end);
-    //    int length = i_f_stream.tellg();
-    //    i_f_stream.seekg(0, i_f_stream.beg);
-
-    //    char *buffer = new char[length];
-    //    i_f_stream.read(buffer, length);
-    //    i_f_stream.close();
-    //    // 将img_data的img_size个数据赋值给img_data_str
-    //    img_data_str.assign(buffer, length);
-    //    // 防止内存泄露
-    //    delete buffer;
-    QImage *img = new QImage;
-    if( !(img->load(QString::fromStdString(img_path))) )   //如果图片不存在
-    {
-        delete img;
-        return "";
-    }
-    QFileInfo imageInfo = QFileInfo(QString::fromStdString(img_path));
-    QString sImgSuffix = imageInfo.suffix(); //获取图片文件后缀
-    QByteArray baImgSuffix = sImgSuffix.toLatin1(); //将后缀QString转char *
-    QByteArray baImgData; //保存图片数据的字符数组
-    QBuffer buf(&baImgData);  //将字符数组与buffer缓存区绑定,以便写入数据
-    //原型为 img->save(&buf, "jpg"),将图片以JPG格式写入buffer; 但有时候所选图片后缀为其他格式,为避免错误,选择用获取图片后缀方式填写,类型为char*
-    img->save(&buf, baImgSuffix.data());
-    QByteArray baImgToHexed = baImgData.toBase64(); //因为缓存已与baImgData绑定,故缓存的数据也绑定在baImgData中
-    buf.close();
-    QString sImgB64Data(baImgToHexed); //将Base64转QString
-
-
-       ofstream outfile("img.txt",ios::app);
-       outfile<<sImgB64Data.toStdString()<<endl;
-        outfile.close();
-
-    return sImgB64Data.toStdString();
-}

+ 1 - 3
CAE_Solution/src/Rabbitmq/rabbitClient/rabbitclient.h

@@ -9,7 +9,6 @@
 #include "../c_rabbitmq/crabbitmqclient.h"
 #include "../../../Libs/rabbitmq/win/include/rabbitmq-c/amqp.h"
 #include "../../../Libs/rabbitmq/win/include/amqp.h"
-#include "vtkjsonobject.h"
 #include <QtGlobal>
 using namespace std;
 
@@ -27,7 +26,6 @@ public :
     int disConnect();
     void recv_connect();
     void send_connect();
-    string readImg(std::string);
 
 
     std::string ErrorReturn;
@@ -42,7 +40,7 @@ public slots:
 signals:
     void restart_recv_client_signal();
     void restart_send_client_signal();
-    void recv(QString str);
+    void sendmsg_recvclientToRecvstate(QString str);
 
 
 private:

+ 34 - 5
CAE_Solution/src/VTK/QVTKRenderer/qvtkrenderer.cpp

@@ -7,6 +7,29 @@
  * @birth: created by czm in 20230321
  */
 QVTKRenderer::QVTKRenderer()
+{
+
+}
+
+/*
+ * @brief: the destructor
+ * @param: void
+ * @ret: void
+ * @birth: created by czm in 20230321
+ */
+QVTKRenderer::~QVTKRenderer()
+{
+    this->renderer->Delete();
+    this->renderWin->Delete();
+}
+
+/*
+ * @brief: init(初始化)
+ * @param: void
+ * @ret: void
+ * @birth: created by czm in 20230406
+ */
+void QVTKRenderer::init()
 {
     qvtkWidget = new QVTKOpenGLNativeWidget();
     this->renderWin = vtkGenericOpenGLRenderWindow::New();
@@ -23,15 +46,21 @@ QVTKRenderer::QVTKRenderer()
 }
 
 /*
- * @brief: the destructor
+ * @brief: Capture widget Images(截取窗口图片)
  * @param: void
  * @ret: void
- * @birth: created by czm in 20230321
+ * @birth: created by czm in 20230406
  */
-QVTKRenderer::~QVTKRenderer()
+void QVTKRenderer::CaptureWindowImages()
 {
-    this->renderer->Delete();
-    this->renderWin->Delete();
+    if(qvtkWidget == NULL) return;
+    QPixmap pix = QPixmap::grabWidget(qvtkWidget);
+    QByteArray bytes;
+    QBuffer buffer(&bytes);
+    buffer.open(QIODevice::WriteOnly);
+    pix.save(&buffer,"PNG");
+    img = QString(bytes.toBase64());//转base64
+    //emit sendImgFile(img); //发送图片(信号)
 }
 
 /*

+ 11 - 0
CAE_Solution/src/VTK/QVTKRenderer/qvtkrenderer.h

@@ -20,6 +20,9 @@
 #include <vtkActorCollection.h>
 #include <vtkProperty.h>
 #include <vtkPropCollection.h>
+#include <QPixmap>
+#include <QByteArray>
+#include <QBuffer>
 
 
 class QVTKRenderer
@@ -28,6 +31,8 @@ public:
     QVTKRenderer();
     virtual ~QVTKRenderer();
 
+    void init();
+    void CaptureWindowImages();
     QWidget* GetWidget();
     vtkRenderer* GetRenderer();
     void Show();
@@ -82,6 +87,12 @@ protected:
     int curRenderMode_;
     bool surfaceVisible_;
     SelectionMode curSelMode_;
+
+//signals:
+//    void sendImgFile(QString img);
+
+public:
+    QString img;//保存图片内容
 };
 
 #endif // QVTKRENDERER_H

+ 21 - 27
CAE_Solution/src/main.cpp

@@ -9,24 +9,18 @@ VTK_MODULE_INIT(vtkRenderingFreeType)
 #include <QDir>
 #include <QTextCodec>
 #include <QThread>
-
 #include <iostream>
-
 #include "commonheaders.h"
 #include "Rabbitmq/ReadConf/readconf.h"
 #include "Rabbitmq/rabbitClient/rabbitclient.h"
 #include "Display/display.h"
 #include "threadPool_and_statemachine/stateMachine/statemachine.h"
-//#include "threadPool_and_statemachine/myBoost/threadpool.h"
-#include "threadPool_and_statemachine/dealWith/vtkVisNativeWidget.h"
-//#include "threadPool_and_statemachine/myBoost/task.h"
-//#include "threadPool_and_statemachine/myBoost/worker.h"
-//#include "threadPool_and_statemachine/myBoost/taskqueue.h"
 #include <QTabWidget>
 #include <QDesktopWidget>
 #include <QGuiApplication>
 #include <QMutex>
 #include "widget.h"
+#include "threadPool_and_statemachine/dealWith/handlepool.h"
 
 
 int main(int argc, char *argv[])
@@ -38,31 +32,31 @@ int main(int argc, char *argv[])
     }
 #endif
 
-//    QTextCodec *codec = QTextCodec::codecForName("UTF-8");
-//    QTextCodec::setCodecForLocale(codec);
     qRegisterMetaType<std::string>("std::string");
     QApplication a(argc, argv);
     Widget w;
 
-    w.resize(QApplication::desktop()->availableGeometry().size());
+    w.resize(QApplication::desktop()->availableGeometry().size());//最大化
     w.move(0,0);
+    w.show();
+//初始化状态机
+    stateMachine* recvstate= new stateMachine("recvClient");
+    QThread *thread_recvsate = new QThread();
+    QThread *thread_sendstate = new QThread();
+    QThread *thread_handlePool = new QThread();
+    stateMachine* sendstate= new stateMachine("sendClient") ;
+    handlePool *handle = new handlePool();
+
+    recvstate->moveToThread(thread_recvsate);
+    thread_recvsate->start();
+    sendstate->moveToThread(thread_sendstate);
+    thread_sendstate->start();
+    handle->moveToThread(thread_handlePool);
+    thread_handlePool->start();
+
+    QObject::connect(handle,SIGNAL(sendImg_handlePoolToSendstate(std::string)),sendstate,SLOT(getImg_handlePoolToSendstate(std::string)));
+    QObject::connect(recvstate,SIGNAL(sendmsg_recvstateTohandlePool(QString)),handle,SLOT(getmsg_recvstateTohandlePool(QString)));
+    QObject::connect(handle,SIGNAL(sendWidget_handlePoolToWidget(QWidget*)),&w,SLOT(getWidget_handlePoolToWidget(QWidget*)));
 
-    //stateMachine& m_state = stateMachine::Instance();
-    stateMachine* recvstate = new stateMachine("recvClient");
-    stateMachine* sendstate = new stateMachine("sendClient");
-    //ThreadPool *threadPool=new ThreadPool(5);
-    //threadPool->setTaskQueueMaxSize(20);
-    vtkVisNativeWidget *deal = new vtkVisNativeWidget();
-    QObject::connect(deal,SIGNAL(sendImgFile(QString)),sendstate,SLOT(getImgFile(QString)));
-    QObject::connect(recvstate,SIGNAL(sendJsonObject(vtkJsonObject*)),sendstate,SLOT(getJsonObject(vtkJsonObject*)));
-    QObject::connect(recvstate,&stateMachine::add_task,[=](){
-//        //QString tmp = m_state.recvMsgQueue[0];
-        //QString tmp="cylinder";
-//        fn_type fn = boost::bind(&vtkVisNativeWidget::createGeometry,deal,tmp);
-//        task_ptr task1(new Task(fn,HIGH_PRIO));
-//        threadPool->addTask(task1);
-//        printf("-----------------------threadPool addTask-------------------------\n");
-        deal->createGeometry("sphere");
-    });
     return a.exec();
 }

+ 1 - 6
CAE_Solution/src/src.pro

@@ -322,12 +322,7 @@ else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../Libs/vtk8.2/win/lib/
 win32:INCLUDEPATH += $$PWD/../Libs/vtk8.2/win/include/vtk-8.2
 win32:DEPENDPATH += $$PWD/../Libs/vtk8.2/win/include/vtk-8.2
 ############################################################################
-#添加外部库rabbitmq-c(msvc2015 32位)
-#win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../Libs/rabbitmq/win/lib/ -lrabbitmq.4
-#win32:INCLUDEPATH += $$PWD/../Libs/rabbitmq/win/include
-#win32:DEPENDPATH += $$PWD/../Libs/rabbitmq/win/include
-#win32:INCLUDEPATH += $$PWD/../Libs/rabbitmq/win/include/rabbitmq-c
-#win32:DEPENDPATH += $$PWD/../Libs/rabbitmq/win/include/rabbitmq-c
+#添加外部库rabbitmq-c(msvc2015 64位)
 CONFIG(release, debug|release):{
 win32: LIBS += -L$$PWD/../Libs/rabbitmq/win/debug/lib/ -lrabbitmq.4
 

+ 4 - 4
CAE_Solution/src/threadPool_and_statemachine/dealWith/dealWith.pri

@@ -1,8 +1,8 @@
 SOURCES += \
-    $$PWD/dealwithmsg.cpp \
-    $$PWD/vtkvisnativewidget.cpp
+    $$PWD/handlepool.cpp \
+    $$PWD/vtkjsonobject.cpp
 
 
 HEADERS += \
-    $$PWD/dealwithmsg.h \
-    $$PWD/vtkvisnativewidget.h
+    $$PWD/handlepool.h \
+    $$PWD/vtkjsonobject.h

+ 92 - 0
CAE_Solution/src/threadPool_and_statemachine/dealWith/handlepool.cpp

@@ -0,0 +1,92 @@
+#include "handlepool.h"
+
+/*
+ * @brief:the constructor
+ * @param:
+ * @ret:
+ * @birth: creadted by czm in 20230406
+ */
+handlePool::handlePool(QObject *parent) : QObject(parent)
+{
+    jsonObject = new vtkJsonObject();
+}
+
+/*
+ * @brief:the destructor
+ * @param:
+ * @ret:
+ * @birth: creadted by czm in 20230406
+ */
+handlePool::~handlePool()
+{
+    if(render){
+        delete render;
+        render = NULL;
+    }
+    if(jsonObject){
+        delete jsonObject;
+        jsonObject = NULL;
+    }
+    qDeleteAll(vector_render.begin(),vector_render.end());
+    vector_render.clear();
+    qDeleteAll(vector_json.begin(),vector_json.end());
+    vector_json.clear();
+}
+
+/*
+ * @brief: handle msg from recvstate(slot)(处理来自接收状态机的消息,槽函数)
+ * @param:recv msg
+ * @ret:void
+ * @birth: creadted by czm in 20230406
+ */
+void handlePool::getmsg_recvstateTohandlePool(QString recvmsg)
+{
+    this->jsonObject->FromJSON(recvmsg.toStdString());
+    int numOfUID = judgeMsgUID(this->jsonObject);
+    if(numOfUID == -1){
+        render = new QVTKRenderer();
+        vector_render.append(render);
+        vector_json.append(this->jsonObject);
+    }else{
+        this->render = vector_render[numOfUID];
+    }
+
+    operateRender(this->jsonObject->action);
+
+    std::string img_ = this->render->img.toStdString();
+    std::string json_ = this->jsonObject->ToJson(img_);
+    emit sendImg_handlePoolToSendstate(json_);//信号
+}
+
+/*
+ * @brief: judge msg's uid is it inside the vector(通过消息中的uid判断是否需要生成新的处理类)
+ * @param: jsonobject
+ * @ret:num of jsonobj
+ * @birth: creadted by czm in 20230406
+ */
+int handlePool::judgeMsgUID(vtkJsonObject *obj)
+{
+    for(int i=0;i<vector_json.size();i++){
+        if(obj->usrId == vector_json[i]->usrId)
+            return i;
+    }
+    return -1;
+}
+
+/*
+ * @brief: Operate render according to commands(根据命令操作render)
+ * @param: this->jsonObject->action
+ * @ret:void
+ * @birth: creadted by czm in 20230406
+ */
+void handlePool::operateRender(QString action)
+{
+    if(action == "init"){
+        this->render->init();
+        emit sendWidget_handlePoolToWidget(this->render->GetWidget());
+    }else{
+        cout<<"action:"<<action.toStdString()<<endl;
+    }
+    this->render->CaptureWindowImages();
+}
+

+ 36 - 0
CAE_Solution/src/threadPool_and_statemachine/dealWith/handlepool.h

@@ -0,0 +1,36 @@
+#ifndef HANDLEPOOL_H
+#define HANDLEPOOL_H
+
+#include <QObject>
+#include <QVector>
+
+#include "../../VTK/QVTKRenderer/qvtkrenderer.h"
+#include "vtkjsonobject.h"
+
+
+class handlePool : public QObject
+{
+    Q_OBJECT
+public:
+    explicit handlePool(QObject *parent = nullptr);
+    ~handlePool();
+
+    int judgeMsgUID(vtkJsonObject*);
+    void operateRender(QString);
+
+
+public:
+    QVector<QVTKRenderer*> vector_render;
+    QVector<vtkJsonObject*> vector_json;
+    QVTKRenderer *render;
+    vtkJsonObject *jsonObject;
+
+
+signals:
+    void sendImg_handlePoolToSendstate(std::string);
+    void sendWidget_handlePoolToWidget(QWidget*);
+public slots:
+    void getmsg_recvstateTohandlePool(QString);
+};
+
+#endif // HANDLEPOOL_H

+ 115 - 0
CAE_Solution/src/threadPool_and_statemachine/dealWith/vtkjsonobject.cpp

@@ -0,0 +1,115 @@
+#include "vtkjsonobject.h"
+
+/*
+ * @brief: the constructor
+ * @param:
+ * @brief:
+ * @birth: created by czm in 20230404
+ */
+vtkJsonObject::vtkJsonObject()
+{
+
+}
+
+/*
+ * @brief: the destructor
+ * @param:
+ * @brief:
+ * @birth: created by czm in 20230404
+ */
+vtkJsonObject::~vtkJsonObject()
+{
+
+}
+
+/*
+ * @brief: parsing json msg(解析json数据)
+ * @param: json msg
+ * @brief: void
+ * @birth: created by czm in 20230404
+ */
+void vtkJsonObject::FromJSON(std::string msg)
+{
+    QByteArray byteArray(msg.c_str(),msg.length());
+    QJsonParseError jsonError;
+    QJsonDocument doucment = QJsonDocument::fromJson(byteArray, &jsonError);  // 转化为 JSON 文档
+    if (!doucment.isNull() && (jsonError.error == QJsonParseError::NoError)) {  // 解析未发生错误
+        if (doucment.isObject()) {  // JSON 文档为对象
+            QJsonObject object = doucment.object();  // 转化为对象
+            if (object.contains("usrId")) {
+                QJsonValue value = object.value("usrId");
+                if (value.isString()) {
+                    this->usrId = value.toString();
+                }
+            }
+            if (object.contains("solverConfigid")) {
+                QJsonValue value = object.value("solverConfigid");
+                if (value.isString()) {
+                    this->solverConfigid = value.toString();;
+                }
+            }
+            if (object.contains("proId")) {
+                QJsonValue value = object.value("proId");
+                if (value.isString()) {
+                    this->proId = value.toString();
+                }
+            }
+            if (object.contains("paramJson")) {
+                QJsonValue value = object.value("paramJson");
+                if (value.isString()) {
+                   this->paramJson = value.toString();
+                }
+            }
+            if (object.contains("action")) {
+                QJsonValue value = object.value("action");
+                if (value.isString()) {
+                   this->action = value.toString();
+                }
+            }
+
+        }
+    }
+
+}
+
+/*
+ * @brief: operator =(重载=符号)
+ * @param: vtkJsonObject
+ * @brief: this pointer
+ * @birth: created by czm in 20230406
+ */
+vtkJsonObject *vtkJsonObject::operator=(vtkJsonObject *object)
+{
+    this->usrId = object->usrId;
+    this->solverConfigid = object->solverConfigid;
+    this->proId = object->proId;
+    this->paramJson = object->paramJson;
+    this->action = object->action;
+    return this;
+}
+
+/*
+ * @brief: Build JSON message(组成json数据)
+ * @param: img file
+ * @brief: josn msg
+ * @birth: created by czm in 20230404
+ */
+std::string vtkJsonObject::ToJson(std::string imgfile)
+{
+    qDebug()<<"imgfile"<<QString::fromStdString(imgfile);
+    QJsonObject json;
+    json.insert("usrId",this->usrId);
+    json.insert("solverConfigid",this->solverConfigid);
+    json.insert("proId",this->proId);
+    json.insert("paramJson",this->paramJson);
+    json.insert("action",this->action);
+    json.insert("img",QString::fromStdString(imgfile));
+
+    QJsonDocument document;
+    document.setObject(json);
+    QByteArray byteArray = document.toJson(QJsonDocument::Compact);
+    QString strJson(byteArray);
+    qDebug()<<"strJson:"<<strJson;
+    return strJson.toStdString();
+}
+

+ 32 - 0
CAE_Solution/src/threadPool_and_statemachine/dealWith/vtkjsonobject.h

@@ -0,0 +1,32 @@
+#ifndef VTKJSONOBJECT_H
+#define VTKJSONOBJECT_H
+
+#include <QObject>
+#include <QJsonDocument>
+#include <QJsonParseError>
+#include <QJsonObject>
+#include <QJsonValue>
+#include <QJsonArray>
+#include <string>
+#include <QDebug>
+
+
+class vtkJsonObject
+{
+public:
+    vtkJsonObject();
+    ~vtkJsonObject();
+    void FromJSON(std::string msg);
+    vtkJsonObject* operator=(vtkJsonObject* object);
+    std::string ToJson(std::string imgfile);
+
+public:
+     QString usrId;
+     QString solverConfigid;
+     QString proId;
+     QString paramJson;
+     QString action;
+
+};
+
+#endif // VTKJSONOBJECT_H

+ 19 - 31
CAE_Solution/src/threadPool_and_statemachine/stateMachine/statemachine.cpp

@@ -9,7 +9,6 @@
 stateMachine::stateMachine(QString tmp)
 {
     init(tmp);
-    jsonObject = new vtkJsonObject();
     printf("----------------init----------------\n");
 }
 
@@ -42,7 +41,7 @@ stateMachine::~stateMachine()
 }
 
 /*
- * @brief: init
+ * @brief: init(初始化)
  * @param: void
  * @ret: void
  * @birth: created by czm in 20230326
@@ -53,7 +52,7 @@ void stateMachine::init(QString tmp){
         printf("------------recvThread started-------------------\n");
         recvThread = new QThread();
         recvClient = new rabbitClient("recvClient");
-        connect(recvClient,SIGNAL(recv(QString)),this,SLOT(recv(QString)));
+        connect(recvClient,SIGNAL(sendmsg_recvclientToRecvstate(QString)),this,SLOT(getmsg_recvclientToRecvstate(QString)));
         connect(recvClient,SIGNAL(restart_recv_client_signal()),this,SLOT(restart_recv_client_slot()));
         recvClient->moveToThread(recvThread);
         connect(recvThread,&QThread::finished,[=](){
@@ -66,12 +65,12 @@ void stateMachine::init(QString tmp){
             recvClient->recvMsg();
         });
         recvThread->start();
-}else{
+    }else{
 
         printf("------------sendThread started-------------------\n");
         sendThread = new QThread();
         sendClient = new rabbitClient("sendClient");
-        connect(this,SIGNAL(send(std::string)),sendClient,SLOT(sendMsg(std::string)));
+        connect(this,SIGNAL(sendImg_sendstateToSendclient(std::string)),sendClient,SLOT(sendMsg(std::string)));
         connect(sendClient,SIGNAL(restart_send_client_signal()),this,SLOT(restart_send_client_slot()));
         sendClient->moveToThread(sendThread);
         connect(sendThread,&QThread::finished,sendClient,[=](){
@@ -80,35 +79,28 @@ void stateMachine::init(QString tmp){
             sendClient = NULL;
             sendThread = NULL;
         });
-
         sendThread->start();
-
-}
-
-
-
+    }
 }
 
 /*
- * @brief: get the recvClient's message which is consumed and push them into queue
+ * @brief: get the recvClient's message which is consumed and push them into queue(接收状态机接收来自接收客户端的信息)
  * @param: recv msg
  * @ret: void
  * @birth: created by czm in 20230326
  */
-void stateMachine::recv(QString Recvmsg)
+void stateMachine::getmsg_recvclientToRecvstate(QString Recvmsg)
 {
     mutex.lock();
     printf("---------------state Machine slot recv(QString)-----------------------\n");
     recvMsgQueue.push_back(Recvmsg);
-    this->jsonObject->FromJSON(Recvmsg.toStdString());
-    emit sendJsonObject(jsonObject);
-    emit add_task();
+    emit sendmsg_recvstateTohandlePool(Recvmsg);//信号
     recvMsgQueue.clear();
     mutex.unlock();
 }
 
 /*
- * @brief: the slot(restart recv client)
+ * @brief: the slot(restart recv client)(槽函数重启接收客户机)
  * @param: void
  * @ret: void
  * @birth: created by czm in 20230328
@@ -120,7 +112,7 @@ void stateMachine::restart_recv_client_slot()
 }
 
 /*
- * @brief: the slot(restart send client)
+ * @brief: the slot(restart send client)(槽函数重启发送客户端)
  * @param: void
  * @ret: void
  * @birth: created by czm in 20230328
@@ -131,22 +123,18 @@ void stateMachine::restart_send_client_slot()
     this->sendClient->send_connect();
 }
 
-void stateMachine::getImgFile(QString img)
-{
-    cout<<"slot getImgFile"<<endl;
-    mutex.lock();
-    printf("------------------statemachine getimgfile----------------------\n");
-    emit send(this->jsonObject->ToJson(img.toStdString()));
-    mutex.unlock();
-}
 
 /*
- * @brief: slot(get jsonobject from recvclient)
- * @param: jsonobject
+ * @brief: get img from handlepool(槽函数获得从handlepool发送过来的图片)
+ * @param: img
  * @ret: void
- * @birth: created by czm in 20230404
+ * @birth: created by czm in 20230406
  */
-void stateMachine::getJsonObject(vtkJsonObject *object)
+void stateMachine::getImg_handlePoolToSendstate(std::string img)
 {
-    this->jsonObject = object;
+    mutex.lock();
+    printf("------------------statemachine getimgfile----------------------\n");
+    emit sendImg_sendstateToSendclient(img);//信号
+    mutex.unlock();
 }
+

+ 5 - 14
CAE_Solution/src/threadPool_and_statemachine/stateMachine/statemachine.h

@@ -15,33 +15,24 @@ public:
 
 public:
     ~stateMachine();
-//    stateMachine(const stateMachine&) = delete;
-//    stateMachine& operator=(const stateMachine&) = delete;
-//    static stateMachine& Instance(){
-//       static stateMachine m_state;
-//        return m_state;
-//    }
     void init(QString tmp);
 
 public:
     rabbitClient *recvClient, *sendClient;
     QThread *recvThread,*sendThread;
-    QThread *listenThread;
     QList<QString> sendMsgQueue,recvMsgQueue;
     QMutex mutex;
-    vtkJsonObject * jsonObject;
 
 signals:
-    void send(std::string);
-    void add_task();//send to thread Pool
-    void sendJsonObject(vtkJsonObject*);
+    void sendImg_sendstateToSendclient(std::string);
+    void sendmsg_recvstateTohandlePool(QString);
 
 public slots:
-    void recv(QString);
+    void getmsg_recvclientToRecvstate(QString);
+    void getImg_handlePoolToSendstate(std::string);
     void restart_recv_client_slot();
     void restart_send_client_slot();
-    void getImgFile(QString img);
-    void getJsonObject(vtkJsonObject*);
+
 };
 
 #endif // STATEMACHINE_H

+ 8 - 1
CAE_Solution/src/widget.cpp

@@ -1,9 +1,16 @@
 #include "widget.h"
 #include <QTabWidget>
+
 Widget::Widget(QTabWidget *parent)
 {
-
+    num =0;
 }
 Widget::~Widget(){
 
 }
+
+void Widget::getWidget_handlePoolToWidget(QWidget *widget)
+{
+    num++;
+    this->addTab(widget,"test"+QString::number(num));
+}

+ 4 - 0
CAE_Solution/src/widget.h

@@ -10,6 +10,10 @@ class Widget :public QTabWidget
 public:
     Widget(QTabWidget *parent = 0);
     ~Widget();
+
+    int num;
+public slots:
+    void getWidget_handlePoolToWidget(QWidget*);
 };
 
 #endif // WIDGET_H