153 lines
4.8 KiB
C++
153 lines
4.8 KiB
C++
#include "mainwindow.h"
|
|
#include "ui_mainwindow.h"
|
|
|
|
#include <QFileDialog>
|
|
#include <QHBoxLayout>
|
|
|
|
#include <comdel/parser/parsecontext.h>
|
|
#include <comdel/parser/parserutil.h>
|
|
#include <comdel/domain/comdelgenerator.h>
|
|
|
|
#include <iostream>
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
: QMainWindow(parent)
|
|
, ui(new Ui::MainWindow)
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
setupUi();
|
|
|
|
// define allowed methods
|
|
signatures.push_back(domain::FunctionSignature("divisible", std::vector<domain::Value::ValueType>{domain::Value::INT, domain::Value::INT}));
|
|
signatures.push_back(domain::FunctionSignature("less_then", std::vector<domain::Value::ValueType>{domain::Value::INT, domain::Value::INT}));
|
|
signatures.push_back(domain::FunctionSignature("greater_then", std::vector<domain::Value::ValueType>{domain::Value::INT, domain::Value::INT}));
|
|
signatures.push_back(domain::FunctionSignature("contains_address", std::vector<domain::Value::ValueType>{domain::Value::ADDRESS_SPACE, domain::Value::INT}));
|
|
signatures.push_back(domain::FunctionSignature("contains", std::vector<domain::Value::ValueType>{domain::Value::ADDRESS_SPACE, domain::Value::INT, domain::Value::INT}));
|
|
signatures.push_back(domain::FunctionSignature("unique", std::vector<domain::Value::ValueType>{domain::Value::ADDRESS_SPACE, domain::Value::INT, domain::Value::INT}));
|
|
|
|
}
|
|
|
|
void MainWindow::setupUi()
|
|
{
|
|
auto layout = new QHBoxLayout();
|
|
ui->centralwidget->setLayout(layout);
|
|
|
|
// setup toolbar
|
|
ui->toolBar->addAction("Load library", this, &MainWindow::onLoadLibrary);
|
|
ui->toolBar->addAction("Load schema", this, &MainWindow::onLoadSchema);
|
|
ui->toolBar->addAction("Load test", this, &MainWindow::onTestModal);
|
|
|
|
// setup central content
|
|
libraryDisplay = new display::Library();
|
|
schemaDisplay = new display::Schema();
|
|
|
|
layout->setMargin(0);
|
|
layout->addWidget(libraryDisplay);
|
|
layout->addWidget(schemaDisplay, 1);
|
|
|
|
|
|
}
|
|
|
|
void MainWindow::onTestModal() {
|
|
QString filename = "/home/bbr/Documents/personal/projects/modeler/schema.csl";
|
|
|
|
if(!filename.isEmpty()) {
|
|
clear();
|
|
|
|
ParseContext parseContext;
|
|
auto schemaNode = loadSchemaFromFile(&parseContext, filename.toStdString().c_str(), std::cout);
|
|
|
|
if(schemaNode) {
|
|
domain::ComdelGenerator generator(signatures);
|
|
library = generator.loadLibrary(*schemaNode->library);
|
|
|
|
for (auto& error : generator.getErrors()) {
|
|
parseContext.formatError(error, std::cout, "ERROR: ");
|
|
}
|
|
|
|
if(library) {
|
|
schema = generator.loadSchema(*schemaNode, *library);
|
|
|
|
for (auto& error : generator.getErrors()) {
|
|
parseContext.formatError(error, std::cout, "ERROR: ");
|
|
}
|
|
}
|
|
|
|
libraryDisplay->setLibrary(library);
|
|
schemaDisplay->setSchema(schema);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
void MainWindow::onLoadLibrary() {
|
|
auto filename = QFileDialog::getOpenFileName(this,
|
|
tr("Open library"), "/home", tr("Comdel library (*.csl)"));
|
|
|
|
if(!filename.isEmpty()) {
|
|
clear();
|
|
|
|
ParseContext parseContext;
|
|
auto libraryNode = loadLibraryFromFile(&parseContext, filename.toStdString().c_str(), std::cout);
|
|
if(libraryNode) {
|
|
domain::ComdelGenerator generator(signatures);
|
|
library = generator.loadLibrary(*libraryNode);
|
|
|
|
for (auto& error : generator.getErrors()) {
|
|
parseContext.formatError(error, std::cout, "ERROR: ");
|
|
}
|
|
|
|
libraryDisplay->setLibrary(library);
|
|
|
|
} else {
|
|
std::cout<<"Bad request"<<std::endl;
|
|
}
|
|
}
|
|
}
|
|
void MainWindow::onLoadSchema() {
|
|
auto filename = QFileDialog::getOpenFileName(this,
|
|
tr("Open schema"), "/home", tr("Comdel schema (*.csl)"));
|
|
|
|
if(!filename.isEmpty()) {
|
|
clear();
|
|
|
|
ParseContext parseContext;
|
|
auto schemaNode = loadSchemaFromFile(&parseContext, filename.toStdString().c_str(), std::cout);
|
|
|
|
if(schemaNode) {
|
|
domain::ComdelGenerator generator(signatures);
|
|
library = generator.loadLibrary(*schemaNode->library);
|
|
|
|
for (auto& error : generator.getErrors()) {
|
|
parseContext.formatError(error, std::cout, "ERROR: ");
|
|
}
|
|
|
|
if(library) {
|
|
schema = generator.loadSchema(*schemaNode, *library);
|
|
|
|
for (auto& error : generator.getErrors()) {
|
|
parseContext.formatError(error, std::cout, "ERROR: ");
|
|
}
|
|
}
|
|
|
|
libraryDisplay->setLibrary(library);
|
|
schemaDisplay->setSchema(schema);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
void MainWindow::clear() {
|
|
schema = std::nullopt;
|
|
library = std::nullopt;
|
|
|
|
libraryDisplay->setLibrary(library);
|
|
schemaDisplay->setSchema(schema);
|
|
}
|
|
|
|
MainWindow::~MainWindow()
|
|
{
|
|
delete ui;
|
|
}
|