Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
darktorres committed Sep 27, 2022
1 parent a49d67e commit 71fb707
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
20 changes: 10 additions & 10 deletions app/elementmapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ void ElementMapping::generateMap()

void ElementMapping::generateLogic(GraphicElement *elm)
{
auto logicElm = ElementFactory::buildLogicElement(elm);
elm->setLogic(logicElm.get());
m_logicElms.append(logicElm);
auto logic = ElementFactory::buildLogicElement(elm);
elm->setLogic(logic.get());
m_logicElms.append(logic);
}

void ElementMapping::connectElements()
Expand All @@ -56,32 +56,32 @@ void ElementMapping::connectElements()

void ElementMapping::applyConnection(GraphicElement *elm, QNEInputPort *inputPort)
{
LogicElement *currentLogElm;
LogicElement *currentLogic;
int inputIndex = 0;

if (elm->elementType() == ElementType::IC) {
auto *ic = qobject_cast<IC *>(elm);
currentLogElm = ic->inputLogic(inputPort->index());
currentLogic = ic->inputLogic(inputPort->index());
} else {
currentLogElm = elm->logic();
currentLogic = elm->logic();
inputIndex = inputPort->index();
}

const auto connections = inputPort->connections();

if ((connections.size() == 0) && !inputPort->isRequired()) {
auto *predecessorLogic = (inputPort->defaultValue() == Status::Active) ? &m_globalVCC : &m_globalGND;
currentLogElm->connectPredecessor(inputIndex, predecessorLogic, 0);
currentLogic->connectPredecessor(inputIndex, predecessorLogic, 0);
}

if (connections.size() == 1) {
if (auto *outputPort = connections.constFirst()->startPort()) {
if (auto *predecessorElement = outputPort->graphicElement()) {
if (predecessorElement->elementType() == ElementType::IC) {
auto *logic = qobject_cast<IC *>(predecessorElement)->outputLogic(outputPort->index());
currentLogElm->connectPredecessor(inputIndex, logic, 0);
auto *predecessorLogic = qobject_cast<IC *>(predecessorElement)->outputLogic(outputPort->index());
currentLogic->connectPredecessor(inputIndex, predecessorLogic, 0);
} else {
currentLogElm->connectPredecessor(inputIndex, predecessorElement->logic(), outputPort->index());
currentLogic->connectPredecessor(inputIndex, predecessorElement->logic(), outputPort->index());
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions app/ic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ void IC::loadFile(const QString &fileName)
}

m_fileWatcher.addPath(fileInfo.absoluteFilePath());
m_file = fileInfo.absoluteFilePath();
setToolTip(m_file);

// ----------------------------------------------

Expand Down Expand Up @@ -186,19 +188,15 @@ void IC::loadFile(const QString &fileName)
sortPorts(m_icOutputs);
loadInputsLabels();
loadOutputsLabels();
loadInputs();
loadOutputs();

// ----------------------------------------------

m_file = fileInfo.absoluteFilePath();
setToolTip(m_file);

if (label().isEmpty()) {
setLabel(fileInfo.baseName().toUpper());
}

loadInputs();
loadOutputs();

const qreal bottom = portsBoundingRect().united(QRectF(0, 0, 64, 64)).bottom();
m_label->setPos(30, bottom + 5);

Expand Down

0 comments on commit 71fb707

Please sign in to comment.