|
@@ -1,11 +1,17 @@
|
|
|
#include "mainwindow.h"
|
|
|
#include "ui_mainwindow.h"
|
|
|
|
|
|
+#include <QFileDialog>
|
|
|
+#include <QMessageBox>
|
|
|
+#include <iostream>
|
|
|
+
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
|
: QMainWindow(parent)
|
|
|
, ui(new Ui::MainWindow)
|
|
|
{
|
|
|
ui->setupUi(this);
|
|
|
+
|
|
|
+ setWindowTitle("Apollo Conf Make");
|
|
|
}
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
@@ -16,28 +22,83 @@ MainWindow::~MainWindow()
|
|
|
|
|
|
void MainWindow::on_pushButton_Save_clicked()
|
|
|
{
|
|
|
- apollo::control::ControlConf xConf1;
|
|
|
- xConf1.set_steer_angle_rate(100.0);
|
|
|
-
|
|
|
- google::protobuf::Message * px = (google::protobuf::Message *)&xConf1;
|
|
|
-
|
|
|
apollo::control::ControlConf xConf;
|
|
|
- xConf.CopyFrom(*px);
|
|
|
+ QString strtxt = ui->plainTextEdit->toPlainText();
|
|
|
+
|
|
|
+ std::string strconf = strtxt.toStdString();
|
|
|
|
|
|
using google::protobuf::TextFormat;
|
|
|
using google::protobuf::io::FileOutputStream;
|
|
|
using google::protobuf::io::ZeroCopyOutputStream;
|
|
|
+ using google::protobuf::io::ZeroCopyInputStream;
|
|
|
+
|
|
|
+ std::istringstream xstrstream(strconf);
|
|
|
+ ZeroCopyInputStream *input = new google::protobuf::io::IstreamInputStream(&xstrstream);
|
|
|
+ bool success = TextFormat::Parse(input, &xConf);
|
|
|
+ if(success)
|
|
|
+ {
|
|
|
+ mConf.CopyFrom(xConf);
|
|
|
+ UpdateConf();
|
|
|
+ qDebug("Parse OK.");
|
|
|
+ QString str = QFileDialog::getSaveFileName(this,"Save Conf",".","*.txt");
|
|
|
+ if(str.isEmpty())return;
|
|
|
+ if(str.right(4) != ".txt")
|
|
|
+ {
|
|
|
+ str.append(".txt");
|
|
|
+ }
|
|
|
+
|
|
|
+ bool bRes = apollo::cyber::common::SetProtoToASCIIFile(mConf,str.toStdString());
|
|
|
|
|
|
-// google::protobuf::io::StringOutputStream
|
|
|
+ if(bRes == false)
|
|
|
+ {
|
|
|
+ QMessageBox::warning(this,"Warning","Save Conf File Fail.",QMessageBox::YesAll);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ QMessageBox::warning(this,"Warning","Parse Conf Error.",QMessageBox::YesAll);
|
|
|
+ }
|
|
|
+// if (!success) {
|
|
|
+// AERROR << "Failed to parse file " << file_name << " as text proto.";
|
|
|
+// }
|
|
|
+
|
|
|
+// std::string strout;
|
|
|
+ // ZeroCopyOutputStream *output = new google::protobuf::io::StringOutputStream(&strout);//new FileOutputStream(file_descriptor);
|
|
|
+// bool success = TextFormat::Print(xConf, output);
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
|
|
|
+void MainWindow::on_pushButton_LoadTemplate_clicked()
|
|
|
+{
|
|
|
+ QString str = QFileDialog::getOpenFileName(this,"Load Conf",".","*.txt");
|
|
|
+ if(str.isEmpty())return;
|
|
|
+
|
|
|
+ bool bRes = apollo::cyber::common::GetProtoFromASCIIFile(str.toStdString(),&mConf);
|
|
|
+
|
|
|
+ if(bRes == false)
|
|
|
+ {
|
|
|
+ QMessageBox::warning(this,"Warning","Load Template File Fail.",QMessageBox::YesAll);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ UpdateConf();
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::UpdateConf()
|
|
|
+{
|
|
|
+ using google::protobuf::TextFormat;
|
|
|
+ using google::protobuf::io::FileOutputStream;
|
|
|
+ using google::protobuf::io::ZeroCopyOutputStream;
|
|
|
std::string strout;
|
|
|
ZeroCopyOutputStream *output = new google::protobuf::io::StringOutputStream(&strout);//new FileOutputStream(file_descriptor);
|
|
|
- bool success = TextFormat::Print(xConf, output);
|
|
|
-
|
|
|
+ bool success = TextFormat::Print(mConf, output);
|
|
|
if(success)
|
|
|
{
|
|
|
- qDebug("str:\n %s",strout.data());
|
|
|
+ ui->plainTextEdit->setPlainText(strout.data());
|
|
|
}
|
|
|
-
|
|
|
- apollo::cyber::common::SetProtoToASCIIFile(xConf,"/home/yuchuli/xconf.txt");
|
|
|
}
|