diff --git a/CMakeLists.txt b/CMakeLists.txt index f43ddd4..f11ac2d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wall -Werror -std=c++11") -set(SOURCE_FILES src/components/Clock.cpp include/MainWindow.hpp include/Connection.hpp include/Editor.hpp include/c4001.hpp include/c4001.hpp include/c4008.hpp include/c4013.hpp include/c4040.hpp src/components/c4040.cpp src/components/AComponent.cpp src/components/c4008.cpp src/components/c4013.cpp src/components/c4017.cpp src/components/c4001.cpp src/components/False.cpp src/components/Input.cpp src/components/c4011.cpp src/components/c4030.cpp src/components/c4069.cpp src/components/c4071.cpp src/components/c4081.cpp src/components/Pin.cpp src/components/Tristate.cpp src/components/Output.cpp src/components/True.cpp src/main_editor.cpp src/editor/elements/Block.cpp src/editor/elements/Connection.cpp src/editor/MainWindow.cpp src/editor/elements/Port.cpp src/editor/Editor.cpp src/editor/EditorView.cpp include/EditorView.hpp) +set(SOURCE_FILES src/components/Clock.cpp include/c4030.hpp include/c4071.hpp include/Clock.hpp include/False.hpp include/Editor.hpp include/EditorView.hpp include/MainWindow.hpp include/Connection.hpp include/Editor.hpp include/c4001.hpp include/c4001.hpp include/c4008.hpp include/c4013.hpp include/c4040.hpp src/components/c4040.cpp src/components/AComponent.cpp src/components/c4008.cpp src/components/c4013.cpp src/components/c4017.cpp src/components/c4001.cpp src/components/False.cpp src/components/Input.cpp src/components/c4011.cpp src/components/c4030.cpp src/components/c4069.cpp src/components/c4071.cpp src/components/c4081.cpp src/components/Pin.cpp src/components/Tristate.cpp src/components/Output.cpp src/components/True.cpp src/main_editor.cpp src/editor/elements/Block.cpp src/editor/elements/Connection.cpp src/editor/MainWindow.cpp src/editor/elements/Port.cpp src/editor/Editor.cpp src/editor/EditorView.cpp include/EditorView.hpp) add_executable(cpp_nanotekspice ${SOURCE_FILES}) target_link_libraries(cpp_nanotekspice ${CURSES_LIBRARIES}) diff --git a/src/editor/Editor.cpp b/src/editor/Editor.cpp index ce0d270..a7817d0 100644 --- a/src/editor/Editor.cpp +++ b/src/editor/Editor.cpp @@ -22,8 +22,8 @@ namespace nts { ::QGraphicsItem *Editor::itemAt(const ::QPointF &pos) { ::QList<::QGraphicsItem *> items = scene->items(::QRectF(pos - ::QPointF(1, 1), ::QSize(3, 3))); - foreach(::QGraphicsItem *item, items) if (item->type() > ::QGraphicsItem::UserType) - return item; + foreach(::QGraphicsItem *item, items) if (item->type() > ::QGraphicsItem::UserType) + return item; return 0; } @@ -39,6 +39,7 @@ namespace nts { QGraphicsItem *item = itemAt(me->scenePos()); if (item && item->type() == Port::Type) { conn = new Connection(0); + scene->addItem(conn); conn->setPort1((Port *) item); conn->setPos1(item->scenePos()); @@ -76,7 +77,7 @@ namespace nts { Port *port1 = conn->port1(); Port *port2 = (Port *) item; - if (port1->block() != port2->block() && port1->isOutput() != port2->isOutput() && + if (/*!port1->getPin()->getTargetPin() && !port2->getPin()->getTargetPin()&&*/ port1->block() != port2->block() && port1->getPin()->getMode() != port2->getPin()->getMode() && !port1->isConnected(port2)) { conn->setPos2(port2->scenePos()); conn->setPort2(port2); diff --git a/src/editor/EditorView.cpp b/src/editor/EditorView.cpp index 5a1affc..e23cc8e 100644 --- a/src/editor/EditorView.cpp +++ b/src/editor/EditorView.cpp @@ -24,9 +24,9 @@ namespace nts { void EditorView::showContextMenu(const QPoint &pos) { QMenu contextMenu("Context menu", this); - std::string components[4] = {"true", "false", "clock", "output"}; + std::string components[14] = {"true", "false", "clock", "output", "c4001", "c4008", "c4011", "c4013", "c4017", "c4030", "c4040", "c4069", "c4071", "c4081"}; - for (unsigned int i = 0; i < components->size(); ++i) { + for (unsigned int i = 0; i < 14; i++) { QString text = QString::fromStdString("add " + components[i]); QAction *action = new QAction(text, this); diff --git a/src/editor/MainWindow.cpp b/src/editor/MainWindow.cpp index e5345a3..1f179fa 100644 --- a/src/editor/MainWindow.cpp +++ b/src/editor/MainWindow.cpp @@ -4,6 +4,16 @@ #include "Port.hpp" #include +#include +#include "c4001.hpp" +#include "c4008.hpp" +#include "c4011.hpp" +#include "c4013.hpp" +#include "c4017.hpp" +#include "c4030.hpp" +#include "c4069.hpp" +#include "c4081.hpp" +#include "c4040.hpp" #include "Input.hpp" #include "True.hpp" #include "False.hpp" @@ -51,7 +61,7 @@ namespace nts { nodesEditor = new Editor(this); nodesEditor->install(scene); - blocks = new std::list(); + blocks = new std::list(); this->setMinimumWidth(480); this->setMinimumHeight(640); @@ -72,6 +82,26 @@ namespace nts { component = new nts::Clock(); } else if (name == "output") { component = new nts::Output(); + } else if (name == "c4001") { + component = new nts::c4001(); + } else if (name == "c4008") { + component = new nts::c4008(); + } else if (name == "c4011") { + component = new nts::c4011(); + } else if (name == "c4013") { + component = new nts::c4013(); + } else if (name == "c4017") { + component = new nts::c4017(); + } else if (name == "c4030") { + component = new nts::c4030(); + } else if (name == "c4040") { + component = new nts::c4040(); + } else if (name == "c4069") { + component = new nts::c4069(); + } else if (name == "c4071") { + component = new nts::c4071(); + } else if (name == "c4081") { + component = new nts::c4081(); } else { return; } @@ -135,13 +165,11 @@ namespace nts { QDataStream ds(&f); } - void MainWindow::setComponents(std::vector components) - { - blocks = new std::list(); + void MainWindow::setComponents(std::vector components) { + blocks = new std::list(); int index = 0; - for (const auto& component : components) - { + for (const auto &component : components) { index++; Block *b = new Block(0); b->setPos(120 * index, index / 3 * 120); @@ -152,8 +180,8 @@ namespace nts { //printf("block: x(%d), y(%d)\n", (int) b->pos().x(), (int) b->pos().y()); - for (const auto& pin : component->getPins()) { - switch(pin.getMode()) { + for (const auto &pin : component->getPins()) { + switch (pin.getMode()) { case Pin::Mode::U: b->addInputPort("UNDEFINED", &pin); break; @@ -181,7 +209,7 @@ namespace nts { } } - for (const auto& block : *blocks) { + for (const auto &block : *blocks) { const AComponent *component = block->getAComponent(); for (const auto &pin : component->getPins()) { if (&pin.getComponent()) { @@ -189,7 +217,7 @@ namespace nts { connection->setPort1(block->getPortFromPin(&pin)); scene->addItem(connection); Block *target; - for (const auto& ba : *blocks) { + for (const auto &ba : *blocks) { if (ba->getAComponent() == &pin.getComponent()) { target = ba; break; diff --git a/src/editor/elements/Connection.cpp b/src/editor/elements/Connection.cpp index 5cde0df..63009da 100644 --- a/src/editor/elements/Connection.cpp +++ b/src/editor/elements/Connection.cpp @@ -50,9 +50,6 @@ namespace nts { void Connection::updatePath() { QPainterPath p; - //QPointF pos1(m_port1->scenePos()); - //QPointF pos2(m_port2->scenePos()); - p.moveTo(pos1); qreal dx = pos2.x() - pos1.x();