123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- #include "qtmessagedef.h"
- #include <time.h>
- MainWindow::MainWindow(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::MainWindow)
- {
- ui->setupUi(this);
- setWindowIcon(QIcon("./Resource/log.jpg"));
- }
- MainWindow::~MainWindow()
- {
- delete ui;
- }
- void MainWindow::AddLog(std::string log)
- {
- if(ui->m_log_list->count()>50)
- ui->m_log_list->clear();
- char buf[255]={0};
- time_t tt = time(0);//时间cuo
- struct tm* t = localtime(&tt);
- memset(buf,0,255);
- sprintf(buf, "%d-%02d-%02d %02d:%02d:%02d %s", t->tm_year + 1900,
- t->tm_mon + 1,t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec,log.c_str());
- ui->m_log_list->insertItem(ui->m_log_list->count(),buf);
- ui->m_log_list->scrollToBottom();
- }
- #include "qmessagebox.h"
- void MainWindow::ProcessSlot(QVariant var)
- {
- QtMessageData data=var.value<QtMessageData>();
- if(data.msg_type==ePlcSignal)
- {
- static unsigned short last_data[255]={0};
- for(int i=0;i<data.signal_size;++i)
- {
- if(data.plc_data[i]!=last_data[i])
- {
- char buf[255]={0};
- sprintf(buf,"P[%d] %d ---> %d",i,last_data[i],data.plc_data[i]);
- AddLog(buf);
- }
- }
- }
- else if(data.msg_type==eMeasure)
- {
- std::string msgstr="Laser ID : ";
- char buf[255];
- memset(buf,0,255);
- std::vector<int> IDS;
- for(int i=0;i<16;++i)
- {
- if(((0x01<<i) & data.lasers_id) !=0)
- IDS.push_back(i);
- }
- for(int i=0;i<IDS.size();++i)
- sprintf(buf+strlen(buf),"%d ",IDS[i]+1);
- msgstr+=buf;
- msgstr+='\n';
- memset(buf,0,255);
- sprintf(buf,"Project dir : %s\n",data.project_dir);
- msgstr+=buf;
- memset(buf,0,255);
- sprintf(buf,"x:%.2f y:%.2f c:%.2f\nl:%.2f w:%.2f h:%.2f D:%.2f\nPosition id:%d\n",
- data.x,data.y,data.c,data.l,data.w,data.h,data.d,data.position_id);
- msgstr+=buf;
- msgstr+=(data.OK!=0)?"Result OK\n":"Result Failed\n";
- msgstr+=data.time_str;
- ui->m_measure_result->setText(msgstr.c_str());
- }
- }
- #include "qmessagebox.h"
- #include "src/pathcreator.h"
- void MainWindow::on_m_test_btn_clicked()
- {
- PathCreator pathCreator;
- pathCreator.CreateDatePath("/home/zx/data");
- }
- #include "Process.h"
- extern CProcess* m_pProcess;
- void MainWindow::on_m_add_clicked()
- {
- m_pProcess->PushTask(0xFF,1,false);
- AddLog(" test tsak ");
- }
- void MainWindow::on_m_signal_test_clicked()
- {
- switch(label_color){
- case 0:
- ui->m_test_label->setStyleSheet(red_style);
- label_color++;
- break;
- case 1:
- ui->m_test_label->setStyleSheet(green_style);
- label_color++;
- break;
- case 2:
- ui->m_test_label->setStyleSheet(blue_style);
- label_color = 0;
- break;
- }
- }
|