diff --git a/SchemeEditor.pro b/SchemeEditor.pro index c70655c..b6bc69c 100644 --- a/SchemeEditor.pro +++ b/SchemeEditor.pro @@ -18,6 +18,7 @@ SOURCES += \ comdel/domain/schemacreator.cpp \ comdel/domain/component.cpp \ comdel/domain/connection.cpp \ + comdel/domain/comdelvalidator.cpp \ comdel/domain/connectioninstance.cpp \ comdel/domain/display.cpp \ comdel/domain/functionsignature.cpp \ @@ -50,6 +51,7 @@ HEADERS += \ comdel/domain/schemacreator.h \ comdel/domain/component.h \ comdel/domain/connection.h \ + comdel/domain/comdelvalidator.h \ comdel/domain/connectioninstance.h \ comdel/domain/display.h \ comdel/domain/functionsignature.h \ diff --git a/SchemeEditor.pro.user b/SchemeEditor.pro.user index 2670782..2130b65 100644 --- a/SchemeEditor.pro.user +++ b/SchemeEditor.pro.user @@ -1,10 +1,10 @@ - + EnvironmentId - {391729b0-9fcc-4b56-ba51-7d7ee685fc97} + {1f5ef7b0-cf08-4d4a-b37d-18ed0b7a2084} ProjectExplorer.Project.ActiveTarget @@ -83,25 +83,22 @@ true - - true - ProjectExplorer.Project.Target.0 Desktop - Desktop - Desktop - {8ccd2350-ba56-4630-b9a6-4b0b4b193aaf} + Desktop Qt 5.15.2 clang 64bit + Desktop Qt 5.15.2 clang 64bit + qt.qt5.5152.clang_64_kit 0 0 0 0 - /home/bbr/build-SchemeEditor-Desktop-Debug - /home/bbr/build-SchemeEditor-Desktop-Debug + /Users/s2ismac/Desktop/comdel/build-SchemeEditor-Desktop_Qt_5_15_2_clang_64bit-Debug + /Users/s2ismac/Desktop/comdel/build-SchemeEditor-Desktop_Qt_5_15_2_clang_64bit-Debug true @@ -139,8 +136,8 @@ 2 - /home/bbr/build-SchemeEditor-Desktop-Release - /home/bbr/build-SchemeEditor-Desktop-Release + /Users/s2ismac/Desktop/comdel/build-SchemeEditor-Desktop_Qt_5_15_2_clang_64bit-Release + /Users/s2ismac/Desktop/comdel/build-SchemeEditor-Desktop_Qt_5_15_2_clang_64bit-Release true @@ -180,8 +177,8 @@ 0 - /home/bbr/build-SchemeEditor-Desktop-Profile - /home/bbr/build-SchemeEditor-Desktop-Profile + /Users/s2ismac/Desktop/comdel/build-SchemeEditor-Desktop_Qt_5_15_2_clang_64bit-Profile + /Users/s2ismac/Desktop/comdel/build-SchemeEditor-Desktop_Qt_5_15_2_clang_64bit-Profile true @@ -241,14 +238,14 @@ 2 - Qt4ProjectManager.Qt4RunConfiguration:/home/bbr/SchemeEditor/SchemeEditor.pro - /home/bbr/SchemeEditor/SchemeEditor.pro + Qt4ProjectManager.Qt4RunConfiguration:/Users/s2ismac/Desktop/comdel/schema_editor/SchemeEditor.pro + /Users/s2ismac/Desktop/comdel/schema_editor/SchemeEditor.pro false true true false true - /home/bbr/build-SchemeEditor-Desktop-Debug + /Users/s2ismac/Desktop/comdel/build-SchemeEditor-Desktop_Qt_5_15_2_clang_64bit-Debug/SchemeEditor.app/Contents/MacOS 1 diff --git a/SchemeEditor.pro.user.391729b b/SchemeEditor.pro.user.391729b new file mode 100644 index 0000000..2670782 --- /dev/null +++ b/SchemeEditor.pro.user.391729b @@ -0,0 +1,268 @@ + + + + + + EnvironmentId + {391729b0-9fcc-4b56-ba51-7d7ee685fc97} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + false + true + false + 0 + true + true + 0 + 8 + true + false + 1 + true + true + true + *.md, *.MD, Makefile + false + true + + + + ProjectExplorer.Project.PluginSettings + + + true + false + true + true + true + true + + + 0 + true + + true + Builtin.BuildSystem + + true + true + Builtin.DefaultTidyAndClazy + 4 + + + + true + + + true + + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop + Desktop + {8ccd2350-ba56-4630-b9a6-4b0b4b193aaf} + 0 + 0 + 0 + + 0 + /home/bbr/build-SchemeEditor-Desktop-Debug + /home/bbr/build-SchemeEditor-Desktop-Debug + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + + + /home/bbr/build-SchemeEditor-Desktop-Release + /home/bbr/build-SchemeEditor-Desktop-Release + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + + + 0 + /home/bbr/build-SchemeEditor-Desktop-Profile + /home/bbr/build-SchemeEditor-Desktop-Profile + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + 0 + + 3 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + true + + 2 + + Qt4ProjectManager.Qt4RunConfiguration:/home/bbr/SchemeEditor/SchemeEditor.pro + /home/bbr/SchemeEditor/SchemeEditor.pro + false + true + true + false + true + /home/bbr/build-SchemeEditor-Desktop-Debug + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/comdel/domain/attribute.h b/comdel/domain/attribute.h index 43e2960..8fc3256 100644 --- a/comdel/domain/attribute.h +++ b/comdel/domain/attribute.h @@ -1,11 +1,11 @@ #ifndef DOMAIN_ATTRIBUTE_H #define DOMAIN_ATTRIBUTE_H +#include + #include "rule.h" #include "value.h" -#include - namespace domain { class Enumeration { diff --git a/comdel/domain/connection.cpp b/comdel/domain/connection.cpp index 08b8611..7f611b7 100644 --- a/comdel/domain/connection.cpp +++ b/comdel/domain/connection.cpp @@ -30,7 +30,7 @@ std::optional> Connection::getSecondWires() { } Attribute Connection::getAttribute(std::string name) { - for(uint i=0; i +#include + #include "value.h" namespace domain { diff --git a/comdel/domain/rule.cpp b/comdel/domain/rule.cpp index 3c59763..3204d00 100644 --- a/comdel/domain/rule.cpp +++ b/comdel/domain/rule.cpp @@ -8,7 +8,7 @@ Condition::Condition(std::string function, std::vector params, bool negat bool Condition::evaluate(RuleContext &context) { std::vector request; - for(uint i=0; i statements) {} std::optional Rule::evaluate(RuleContext &context) { - for(uint i=0; i ComdelParser::parseValue() { return unexpected(); } - //return spanner(value); - return value; + return spanner(value); } std::optional ComdelParser::parseSchema() { diff --git a/comdel/parser/parserutil.cpp b/comdel/parser/parserutil.cpp index 5811870..a6dddab 100644 --- a/comdel/parser/parserutil.cpp +++ b/comdel/parser/parserutil.cpp @@ -5,6 +5,7 @@ #include #include #include +#include std::optional loadLibraryFromFile(ParseContext * parseContext, const char* name, @@ -75,7 +76,17 @@ std::optional loadSchemaFromFile(ParseContext * parseContext, } if(unit->source) { - unit->library = loadLibraryFromFile(parseContext, unit->source->asString().c_str(), stream); + QFileInfo info(name); + auto filepath = info.absolutePath(); + QDir dir; + dir.setCurrent(filepath); + + auto libraryPath = dir.absoluteFilePath(QString::fromStdString(unit->source->asString())); + + unit->library = loadLibraryFromFile(parseContext, libraryPath.toUtf8().data(), stream); + if(unit->library == std::nullopt) { + return std::nullopt; + } } diff --git a/mainwindow.cpp b/mainwindow.cpp index 652aa15..b6bb74b 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -27,13 +27,14 @@ MainWindow::MainWindow(QWidget *parent) void MainWindow::setupUi() { + setWindowTitle("COMDEL schema editor"); + 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); connect(ui->actionValidate, &QAction::triggered, this, &MainWindow::onValidateSchema); @@ -54,56 +55,23 @@ void MainWindow::setupUi() log = new QPlainTextEdit(); log->setFont(QFont("Courier")); + log->setReadOnly(false); schemaLayout->addWidget(log); } -void MainWindow::onTestModal() { - QString filename = "/home/bbr/Documents/personal/projects/modeler/schema.csl"; - - std::ostringstream buffer; - - if(!filename.isEmpty()) { - clear(); - - ParseContext parseContext; - auto schemaNode = loadSchemaFromFile(&parseContext, filename.toStdString().c_str(), buffer); - - if(schemaNode) { - domain::SchemaCreator generator(signatures); - library = generator.loadLibrary(*schemaNode->library); - - if(library) { - schema = generator.loadSchema(*schemaNode, *library); - } - - for (auto& error : generator.getErrors()) { - parseContext.formatError(error, buffer, "ERROR: "); - } - - if(generator.getErrors().empty()) { - libraryDisplay->setLibrary(library); - schemaDisplay->setSchema(schema); - } else { - libraryDisplay->setLibrary(std::nullopt); - schemaDisplay->setSchema(std::nullopt); - } - - } - } - - log->appendPlainText(QString::fromStdString(buffer.str())); - -} - void MainWindow::onLoadLibrary() { auto filename = QFileDialog::getOpenFileName(this, tr("Open library"), "/home", tr("Comdel library (*.csl)")); + std::ostringstream buffer; + + log->clear(); + if(!filename.isEmpty()) { clear(); ParseContext parseContext; - auto libraryNode = loadLibraryFromFile(&parseContext, filename.toStdString().c_str(), std::cout); + auto libraryNode = loadLibraryFromFile(&parseContext, filename.toStdString().c_str(), buffer); if(libraryNode) { domain::SchemaCreator generator(signatures); library = generator.loadLibrary(*libraryNode); @@ -112,22 +80,35 @@ void MainWindow::onLoadLibrary() { parseContext.formatError(error, std::cout, "ERROR: "); } - libraryDisplay->setLibrary(library); + if(generator.getErrors().empty()) { + libraryDisplay->setLibrary(library); + + // on library load we create a new schema + schema = domain::Schema(); + schemaDisplay->setSchema(schema); + } } else { std::cout<<"Bad request"<appendPlainText(QString::fromStdString(buffer.str())); } + void MainWindow::onLoadSchema() { auto filename = QFileDialog::getOpenFileName(this, tr("Open schema"), "/home", tr("Comdel schema (*.csl)")); + std::ostringstream buffer; + + log->clear(); + if(!filename.isEmpty()) { clear(); ParseContext parseContext; - auto schemaNode = loadSchemaFromFile(&parseContext, filename.toStdString().c_str(), std::cout); + auto schemaNode = loadSchemaFromFile(&parseContext, filename.toStdString().c_str(), buffer); if(schemaNode) { domain::SchemaCreator generator(signatures); @@ -145,15 +126,22 @@ void MainWindow::onLoadSchema() { } } - - - libraryDisplay->setLibrary(library); - schemaDisplay->setSchema(schema); + if(generator.getErrors().empty()) { + libraryDisplay->setLibrary(library); + schemaDisplay->setSchema(schema); + } } } + + log->appendPlainText(QString::fromStdString(buffer.str())); } void MainWindow::onValidateSchema(bool /*toggled*/) { + if(!schema.has_value()) { + return; + } + + this->validationErrors.clear(); std::map callbacks; diff --git a/mainwindow.h b/mainwindow.h index a8af3e6..bb89262 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -38,7 +38,6 @@ public: private slots: void onLoadLibrary(); void onLoadSchema(); - void onTestModal(); void onValidateSchema(bool toggled); private: