circuit-logic-simulator/UndoCommands/AddWire.cpp

34 lines
673 B
C++
Raw Normal View History

2020-03-24 20:18:39 +01:00
#include "AddWire.h"
#include "../Scene.h"
#include "../Logic.h"
#include "../Wire.h"
2020-03-29 18:25:08 +02:00
#include "../Connector.h"
#include "../Part.h"
2020-03-24 20:18:39 +01:00
AddWire::AddWire(Scene* scene, Connector* connectorInput, Connector* connectorOutput)
:m_scene(scene), m_connectorInput(connectorInput), m_connectorOutput(connectorOutput)
{
setText("Add Wire");
}
AddWire::~AddWire()
{
2020-03-29 18:25:08 +02:00
m_scene->m_logic->deleteWire(m_wire);
2020-03-24 20:18:39 +01:00
}
void AddWire::redo()
{
2020-03-29 18:25:08 +02:00
if(m_wire == nullptr)
m_wire = m_scene->m_logic->createWire(m_connectorInput, m_connectorOutput);
else
{
m_scene->startTrackingWire(m_wire);
}
2020-03-24 20:18:39 +01:00
}
void AddWire::undo()
{
2020-03-29 18:25:08 +02:00
m_scene->stopTrackingWire(m_wire);
2020-03-24 20:18:39 +01:00
}