Added connection generation
This commit is contained in:
1 parent
cbff8ff5f2
commit
5cf8235608
16 files changed
+440
-35
No files matched your search
@@ -94,6 +94,7 @@ void generateComdelFile(Schema *schema, Library &library, std::ostream &buffer)
|
||||
}
|
||||
|
||||
void generateBus(BusInstance *bus, ostream &buffer);
|
||||
void generateConnection(ConnectionInstance *connection, ostream &buffer);
|
||||
|
||||
void generateDisplay(Schema *schema, ostream &buffer) {
|
||||
buffer << "\n\tdisplay {\n";
|
||||
@@ -106,9 +107,20 @@ void generateDisplay(Schema *schema, ostream &buffer) {
|
||||
generateBus(bus.get(), buffer);
|
||||
}
|
||||
|
||||
buffer << "\n";
|
||||
|
||||
for(auto &connection: schema->connections) {
|
||||
generateConnection(connection.get(), buffer);
|
||||
}
|
||||
|
||||
buffer << "\t}\n";
|
||||
}
|
||||
|
||||
void generateConnection(ConnectionInstance *connection, ostream &buffer) {
|
||||
buffer << "\t\tline {x1:" << connection->start.first << "; y1:" << connection->start.second << "; " <<
|
||||
"x2:" << connection->end.first << "; y2:" << connection->end.second << ";}" << "\n";
|
||||
}
|
||||
|
||||
void generateBus(BusInstance *bus, ostream &buffer) {
|
||||
buffer << "\n";
|
||||
buffer << "\t\t// " << bus->name << " bus\n\n";
|
||||
|
||||
@@ -63,4 +63,14 @@ bool Connection::isConnecting(ConnectionComponent component, std::string bus, Co
|
||||
(this->first == secondComponent && this->bus == bus && this->second == component);
|
||||
}
|
||||
|
||||
|
||||
bool Connection::isConnecting(ConnectionComponent component, ConnectionComponent secondComponent) {
|
||||
if(!second.has_value()) {
|
||||
return false;
|
||||
}
|
||||
return (this->first == component && this->second == secondComponent) ||
|
||||
(this->first == secondComponent && this->second == component);
|
||||
}
|
||||
|
||||
|
||||
} // namespace domain
|
||||
@@ -21,6 +21,17 @@ struct ConnectionComponent
|
||||
{
|
||||
return !operator==(rhs);
|
||||
}
|
||||
bool operator<(const ConnectionComponent& rhs) const
|
||||
{
|
||||
if(component < rhs.component) {
|
||||
return true;
|
||||
} else if(component == rhs.component) {
|
||||
if(pin < rhs.pin) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
class Connection
|
||||
@@ -40,6 +51,7 @@ public:
|
||||
bool isConnecting(ConnectionComponent first);
|
||||
bool isConnecting(ConnectionComponent first, std::string bus);
|
||||
bool isConnecting(ConnectionComponent first, std::string bus, ConnectionComponent second);
|
||||
bool isConnecting(ConnectionComponent first, ConnectionComponent second);
|
||||
|
||||
|
||||
ConnectionComponent getComponent();
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
#include "instance.h"
|
||||
#include "wireinstance.h"
|
||||
|
||||
|
||||
|
||||
namespace domain {
|
||||
|
||||
class ConnectionInstance
|
||||
@@ -19,6 +17,9 @@ public:
|
||||
|
||||
std::vector<InstanceAttribute> attributes;
|
||||
|
||||
std::pair<int, int> start;
|
||||
std::pair<int, int> end;
|
||||
|
||||
ConnectionInstance(ComponentInstance *instance, std::vector<InstanceAttribute> attributes, Connection connection);
|
||||
|
||||
InstanceAttribute getAttribute(string attribute);
|
||||
|
||||
@@ -5,7 +5,10 @@ namespace domain {
|
||||
BusInstance::BusInstance(std::string name, std::pair<int, int> position, Bus bus, int size)
|
||||
: name(name), position(position), bus(bus), size(size)
|
||||
{}
|
||||
ComponentInstance::ComponentInstance(std::string name, std::vector<InstanceAttribute> attributes, std::pair<int, int> position, Component component)
|
||||
|
||||
BusInstance::BusInstance(std::string name, Bus bus): name(name), bus(bus), position(0,0), size(0) {}
|
||||
|
||||
ComponentInstance::ComponentInstance(std::string name, std::vector<InstanceAttribute> attributes, std::pair<int, int> position, Component component)
|
||||
: name(name), attributes(std::move(attributes)), position(position), component(component)
|
||||
{}
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@ public:
|
||||
Bus bus;
|
||||
int size;
|
||||
|
||||
BusInstance(std::string name, Bus bus);
|
||||
|
||||
BusInstance(std::string name, std::pair<int, int> position, Bus bus, int size);
|
||||
|
||||
virtual ~BusInstance() = default;
|
||||
|
||||
@@ -113,4 +113,18 @@ std::string Library::getMessage(std::string key) {
|
||||
return messages[key];
|
||||
}
|
||||
|
||||
bool Library::hasConnection(ConnectionComponent component, ConnectionComponent secondComponent) {
|
||||
return getConnection(component, secondComponent).has_value();
|
||||
}
|
||||
|
||||
std::optional<Connection>
|
||||
Library::getConnection(ConnectionComponent component, ConnectionComponent secondComponent) {
|
||||
for(auto & connection : connections) {
|
||||
if(connection.isConnecting(component, secondComponent)) {
|
||||
return connection;
|
||||
}
|
||||
}
|
||||
return nullopt;
|
||||
}
|
||||
|
||||
} // namespace domain
|
||||
@@ -60,6 +60,10 @@ public:
|
||||
|
||||
bool hasConnection(ConnectionComponent component, std::string bus, ConnectionComponent secondComponent);
|
||||
std::optional<Connection> getConnection(ConnectionComponent component, std::string bus, ConnectionComponent secondComponent);
|
||||
|
||||
bool hasConnection(ConnectionComponent component, ConnectionComponent secondComponent);
|
||||
std::optional<Connection> getConnection(ConnectionComponent component, ConnectionComponent secondComponent);
|
||||
|
||||
};
|
||||
|
||||
} // namespace domain
|
||||
|
||||
+15
-14
@@ -9,8 +9,7 @@
|
||||
|
||||
namespace domain {
|
||||
|
||||
class Schema
|
||||
{
|
||||
class Schema {
|
||||
public:
|
||||
Schema();
|
||||
|
||||
@@ -19,16 +18,8 @@ public:
|
||||
|
||||
std::vector<shared_ptr<ConnectionInstance>> connections;
|
||||
|
||||
BusInstance *getBusInstance(std::string& name) {
|
||||
for(auto& instance: busInstances) {
|
||||
if (instance->name == name) {
|
||||
return instance.get();
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
ComponentInstance *getComponentInstance(std::string& name) {
|
||||
for(auto& instance: componentInstances) {
|
||||
BusInstance *getBusInstance(std::string &name) {
|
||||
for (auto &instance: busInstances) {
|
||||
if (instance->name == name) {
|
||||
return instance.get();
|
||||
}
|
||||
@@ -36,8 +27,18 @@ public:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool hasConnection(string& component, string& pin);
|
||||
ConnectionInstance* getConnection(string& component, string& pin);
|
||||
ComponentInstance *getComponentInstance(std::string &name) {
|
||||
for (auto &instance: componentInstances) {
|
||||
if (instance->name == name) {
|
||||
return instance.get();
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool hasConnection(string &component, string &pin);
|
||||
|
||||
ConnectionInstance *getConnection(string &component, string &pin);
|
||||
};
|
||||
|
||||
} // namespace domain
|
||||
|
||||
Reference in new issue
Block a user