Added simulation functionality
This commit is contained in:
parent
79c5d147a3
commit
78da43f51d
23 changed files with 385 additions and 21 deletions
14
include/components/ANDgate.hpp
Normal file
14
include/components/ANDgate.hpp
Normal file
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#include <QWidget.h>
|
||||
#include "../Component.hpp"
|
||||
|
||||
class ANDGate : public Component
|
||||
{
|
||||
public:
|
||||
ANDGate(QWidget* parent) : Component(parent, ":/components/and.png") { type = "and"; }
|
||||
|
||||
bool Action() override {
|
||||
return (connections[0]->Action() && connections[1]->Action());
|
||||
}
|
||||
};
|
24
include/components/Lamp.hpp
Normal file
24
include/components/Lamp.hpp
Normal file
|
@ -0,0 +1,24 @@
|
|||
#pragma once
|
||||
|
||||
#include <QWidget.h>
|
||||
#include "../Component.hpp"
|
||||
|
||||
class Lamp : public Component
|
||||
{
|
||||
public:
|
||||
Lamp(QWidget* parent) : Component(parent, ":/components/lamp_off.png") { type = "lamp"; }
|
||||
|
||||
bool Action() override {
|
||||
return connections[0]->Action();
|
||||
}
|
||||
|
||||
void Turn(bool state) {
|
||||
if (state)
|
||||
ui->label->setPixmap(QPixmap(":/components/lamp_on.png"));
|
||||
else
|
||||
ui->label->setPixmap(QPixmap(":/components/lamp_off.png"));
|
||||
}
|
||||
|
||||
private:
|
||||
bool state = false;
|
||||
};
|
14
include/components/NANDgate.hpp
Normal file
14
include/components/NANDgate.hpp
Normal file
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#include <QWidget.h>
|
||||
#include "../Component.hpp"
|
||||
|
||||
class NANDGate : public Component
|
||||
{
|
||||
public:
|
||||
NANDGate(QWidget* parent) : Component(parent, ":/components/nand.png") { type = "nand"; }
|
||||
|
||||
bool Action() override {
|
||||
return !(connections[0]->Action() && connections[1]->Action());
|
||||
}
|
||||
};
|
14
include/components/NORgate.hpp
Normal file
14
include/components/NORgate.hpp
Normal file
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#include <QWidget.h>
|
||||
#include "../Component.hpp"
|
||||
|
||||
class NORGate : public Component
|
||||
{
|
||||
public:
|
||||
NORGate(QWidget* parent) : Component(parent, ":/components/nor.png") { type = "nor"; }
|
||||
|
||||
bool Action() override {
|
||||
return !(connections[0]->Action() || connections[1]->Action());
|
||||
}
|
||||
};
|
14
include/components/NOTgate.hpp
Normal file
14
include/components/NOTgate.hpp
Normal file
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#include <QWidget.h>
|
||||
#include "../Component.hpp"
|
||||
|
||||
class NOTGate : public Component
|
||||
{
|
||||
public:
|
||||
NOTGate(QWidget* parent) : Component(parent, ":/components/not.png") { type = "not"; }
|
||||
|
||||
bool Action() override {
|
||||
return !connections[0]->Action();
|
||||
}
|
||||
};
|
14
include/components/ORgate.hpp
Normal file
14
include/components/ORgate.hpp
Normal file
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#include <QWidget.h>
|
||||
#include "../Component.hpp"
|
||||
|
||||
class ORGate : public Component
|
||||
{
|
||||
public:
|
||||
ORGate(QWidget* parent) : Component(parent, ":/components/or.png") { type = "or"; }
|
||||
|
||||
bool Action() override {
|
||||
return (connections[0]->Action() || connections[1]->Action());
|
||||
}
|
||||
};
|
26
include/components/Switch.hpp
Normal file
26
include/components/Switch.hpp
Normal file
|
@ -0,0 +1,26 @@
|
|||
#pragma once
|
||||
|
||||
#include <QWidget.h>
|
||||
#include "ui_Component.h"
|
||||
#include "../Component.hpp"
|
||||
|
||||
class Switch : public Component
|
||||
{
|
||||
public:
|
||||
Switch(QWidget* parent) : Component(parent, ":/components/switch_off.png") { type = "switch"; }
|
||||
|
||||
bool Action() override {
|
||||
return state;
|
||||
}
|
||||
|
||||
void Toggle() {
|
||||
state = !state;
|
||||
if (state)
|
||||
ui->label->setPixmap(QPixmap(":/components/switch_on.png"));
|
||||
else
|
||||
ui->label->setPixmap(QPixmap(":/components/switch_off.png"));
|
||||
}
|
||||
|
||||
private:
|
||||
bool state = false;
|
||||
};
|
14
include/components/XNORgate.hpp
Normal file
14
include/components/XNORgate.hpp
Normal file
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#include <QWidget.h>
|
||||
#include "../Component.hpp"
|
||||
|
||||
class XNORGate : public Component
|
||||
{
|
||||
public:
|
||||
XNORGate(QWidget* parent) : Component(parent, ":/components/xnor.png") { type = "xnor"; }
|
||||
|
||||
bool Action() override {
|
||||
return !((connections[0]->Action() || connections[1]->Action()) && !(connections[0]->Action() && connections[1]->Action()));
|
||||
}
|
||||
};
|
14
include/components/XORgate.hpp
Normal file
14
include/components/XORgate.hpp
Normal file
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#include <QWidget.h>
|
||||
#include "../Component.hpp"
|
||||
|
||||
class XORGate : public Component
|
||||
{
|
||||
public:
|
||||
XORGate(QWidget* parent) : Component(parent, ":/components/xor.png") { type = "xor"; }
|
||||
|
||||
bool Action() override {
|
||||
return ((connections[0]->Action() || connections[1]->Action()) && !(connections[0]->Action() && connections[1]->Action()));
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue