Extracted schema and library management to Application
This commit is contained in:
1 parent
0c4afe87d9
commit
86b8861533
12 files changed
+334
-182
No files matched your search
@@ -5,6 +5,8 @@
|
||||
#include "attribute_dialog.h"
|
||||
#include "mainwindow.h"
|
||||
|
||||
#include "application.h"
|
||||
|
||||
namespace display {
|
||||
|
||||
void AttributeDialog::onUpdate() {
|
||||
@@ -15,7 +17,7 @@ namespace display {
|
||||
|
||||
domain::ValidationContext context;
|
||||
|
||||
for (auto &addressSpace: MainWindow::getLibrary()->getAddressSpaces()) {
|
||||
for (auto &addressSpace: Application::instance()->getLibrary()->getAddressSpaces()) {
|
||||
context.addressSpaces.insert(std::make_pair(addressSpace.getName(), addressSpace));
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "attribute_dialog.h"
|
||||
#include "name_dialog.h"
|
||||
#include "mainwindow.h"
|
||||
#include "application.h"
|
||||
|
||||
#include <QMenu>
|
||||
#include <QLine>
|
||||
@@ -24,7 +25,7 @@ namespace display {
|
||||
[attr]() {
|
||||
if (attr->value.getType() == domain::Value::MEMORY_REFERENCE) {
|
||||
auto dialog = new MemoryDialog(attr,
|
||||
MainWindow::getSchema()->componentInstances);
|
||||
Application::instance()->getSchema()->componentInstances);
|
||||
dialog->exec();
|
||||
} else {
|
||||
auto dialog = new AttributeDialog(attr);
|
||||
|
||||
@@ -10,13 +10,14 @@ namespace display {
|
||||
Schema::Schema() {
|
||||
this->selectedBrush.setColor(QColor::fromRgb(20, 20, 125));
|
||||
this->selectedPen.setColor(QColor::fromRgb(20, 20, 125));
|
||||
|
||||
schema = nullptr;
|
||||
library = std::nullopt;
|
||||
this->setScene(&scene);
|
||||
this->setAcceptDrops(true);
|
||||
}
|
||||
|
||||
|
||||
void Schema::setSchema(domain::Schema *_schema, domain::Library *_library) {
|
||||
void Schema::setSchema(domain::Schema *_schema, std::optional<domain::Library> _library) {
|
||||
components.clear();
|
||||
buses.clear();
|
||||
|
||||
@@ -216,6 +217,9 @@ namespace display {
|
||||
|
||||
for (auto bus: busInstances) {
|
||||
auto &group = buses[bus->name];
|
||||
if(group == nullptr) {
|
||||
continue;
|
||||
}
|
||||
auto rect = new QGraphicsRectItem(group->boundingRect());
|
||||
rect->setPen(selectedPen);
|
||||
rect->setPos(group->scenePos());
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace display {
|
||||
std::vector<BusConnection *> busConnections;
|
||||
std::vector<DirectConnection *> directConnections;
|
||||
|
||||
void setSchema(domain::Schema *schema, domain::Library *library);
|
||||
void setSchema(domain::Schema *schema, std::optional<domain::Library> library);
|
||||
|
||||
void updateConnections();
|
||||
|
||||
@@ -65,8 +65,8 @@ namespace display {
|
||||
private:
|
||||
QGraphicsScene scene;
|
||||
|
||||
domain::Schema *schema;
|
||||
domain::Library *library;
|
||||
domain::Schema *schema{};
|
||||
std::optional<domain::Library> library;
|
||||
|
||||
std::vector<domain::BusInstance *>
|
||||
getAvailableConnectionBusses(domain::ComponentInstance *instance, domain::Pin &pin);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include <set>
|
||||
#include "comdel_validator.h"
|
||||
#include "library.h"
|
||||
|
||||
@@ -38,11 +39,11 @@ namespace domain {
|
||||
auto message = populateMessage(
|
||||
"Not enough instances of component '{componentName}' required at least {min}, found {count}",
|
||||
context);
|
||||
errors.push_back(ValidationError{nullptr, nullptr, Action::ERROR, message});
|
||||
errors.emplace_back(Action::ERROR, message);
|
||||
} else if (count > comp.getCount().second) {
|
||||
auto message = populateMessage(
|
||||
"To many instances of component '{componentName}' allow at most {max}, found {count}", context);
|
||||
errors.push_back(ValidationError{nullptr, nullptr, Action::ERROR, message});
|
||||
errors.emplace_back(Action::ERROR, message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,11 +65,11 @@ namespace domain {
|
||||
if (count < bus.getCount().first) {
|
||||
auto message = populateMessage(
|
||||
"Not enough instances of bus '{busName}' required at least {min}, found {count}", context);
|
||||
errors.push_back(ValidationError{nullptr, nullptr, Action::ERROR, message});
|
||||
errors.emplace_back(Action::ERROR, message);
|
||||
} else if (count > bus.getCount().second) {
|
||||
auto message = populateMessage(
|
||||
"To many instances of bus '{busName}' allow at most {max}, found {count}", context);
|
||||
errors.push_back(ValidationError{nullptr, nullptr, Action::ERROR, message});
|
||||
errors.emplace_back(Action::ERROR, message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +87,7 @@ namespace domain {
|
||||
context.instance = inst.get();
|
||||
context.attributes["instanceName"] = Value::fromString(inst->name);
|
||||
auto message = populateMessage(pin.getConnection().getMessage(), context);
|
||||
errors.push_back(ValidationError{nullptr, nullptr, Action::ERROR, message});
|
||||
errors.emplace_back(Action::ERROR, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -152,6 +153,24 @@ namespace domain {
|
||||
return nullopt;
|
||||
}
|
||||
|
||||
std::vector<ValidationError>
|
||||
ComdelValidator::validateInstanceNames(Schema &schema, Library &library, ValidationContext context) {
|
||||
std::set<std::string> names;
|
||||
std::vector<ValidationError> errors;
|
||||
|
||||
for(auto& component: schema.componentInstances) {
|
||||
if(names.find(component->name) != names.end()) {
|
||||
context.attributes["componentName"] = Value::fromString(component->name);
|
||||
auto message = populateMessage(
|
||||
"There are multiple component instances named '{componentName}'", context);
|
||||
errors.emplace_back(Action::ERROR, message);
|
||||
}
|
||||
names.insert(component->name);
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
|
||||
|
||||
std::string ComdelValidator::populateMessage(string source, ValidationContext context) {
|
||||
for (auto &[key, value]: context.attributes) {
|
||||
source = replacePlaceholder(source, key, value);
|
||||
@@ -202,5 +221,4 @@ namespace domain {
|
||||
this->validators.insert(std::make_pair(validator->getName(), validator));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,6 +12,10 @@ namespace domain {
|
||||
InstanceAttribute *attribute;
|
||||
Action::ActionType type;
|
||||
std::string message;
|
||||
|
||||
ValidationError(Action::ActionType type, std::string message): instance(nullptr), attribute(nullptr), type(type), message(message) {}
|
||||
|
||||
ValidationError(ComponentInstance* instance, InstanceAttribute* attribute, Action::ActionType type, std::string message): instance(instance), attribute(attribute), type(type), message(message) {}
|
||||
};
|
||||
|
||||
struct ValidationContext {
|
||||
@@ -31,6 +35,8 @@ namespace domain {
|
||||
|
||||
std::optional<ValidationError> validateRule(Rule rule, ValidationContext context);
|
||||
|
||||
std::vector<ValidationError> validateInstanceNames(Schema &schema, Library &library, ValidationContext context);
|
||||
|
||||
std::vector<ValidationError> validateInstanceCount(Schema &schema, Library &library, ValidationContext context);
|
||||
|
||||
std::vector<ValidationError>
|
||||
|
||||
Reference in new issue
Block a user