Skip to content

Commit

Permalink
somes changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gmardon committed Mar 4, 2017
1 parent 5ed2f90 commit acb76fe
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 19 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
7 changes: 4 additions & 3 deletions src/editor/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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());
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/editor/EditorView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
48 changes: 38 additions & 10 deletions src/editor/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@

#include "Port.hpp"
#include <typeinfo>
#include <include/c4071.hpp>
#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"
Expand Down Expand Up @@ -51,7 +61,7 @@ namespace nts {
nodesEditor = new Editor(this);
nodesEditor->install(scene);

blocks = new std::list<Block*>();
blocks = new std::list<Block *>();

this->setMinimumWidth(480);
this->setMinimumHeight(640);
Expand All @@ -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;
}
Expand Down Expand Up @@ -135,13 +165,11 @@ namespace nts {
QDataStream ds(&f);
}

void MainWindow::setComponents(std::vector<AComponent*> components)
{
blocks = new std::list<Block*>();
void MainWindow::setComponents(std::vector<AComponent *> components) {
blocks = new std::list<Block *>();

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);
Expand All @@ -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;
Expand Down Expand Up @@ -181,15 +209,15 @@ 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()) {
Connection *connection = new Connection(0);
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;
Expand Down
3 changes: 0 additions & 3 deletions src/editor/elements/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit acb76fe

Please sign in to comment.