SILICON
Loading...
Searching...
No Matches
graphicalGates.hpp
Go to the documentation of this file.
1/*
2 Copyright (c) 2025. Giulio Cocconi
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#pragma once
19
20#include <core/gates.hpp>
23
24namespace SILICON::ui {
25using namespace SILICON::core;
26
28 Q_OBJECT
29public:
30 void setComponent(const Component_ptr& component) override;
31
32protected:
33 GraphicalGate(const std::shared_ptr<Gate> gate, QGraphicsItem* shape,
34 QGraphicsItem* parent = nullptr, bool scanShape = false);
35
36 void updateGatePorts();
37 void updatePortSizes() override;
38
39 int type() const override { return SiliconTypes::UNKNOWN; }
40};
41
43 Q_OBJECT
44public:
45 explicit GraphicalAnd(QGraphicsItem* parent = nullptr)
47 std::make_shared<AndGate>(std::vector<Wire_ptr>{nullptr, nullptr}, nullptr),
48 new ThemedSvgItem(":/gates/AND_ANSI.svg"), parent)
49 {
50 }
51
52 int type() const override { return SiliconTypes::AND_GATE; }
53};
54
55class GraphicalOr : public GraphicalGate {
56 Q_OBJECT
57public:
58 explicit GraphicalOr(QGraphicsItem* parent = nullptr)
60 std::make_shared<OrGate>(std::vector<Wire_ptr>{nullptr, nullptr}, nullptr),
61 new ThemedSvgItem(":/gates/OR_ANSI.svg"), parent)
62 {
63 }
64
65 int type() const override { return SiliconTypes::OR_GATE; }
66};
67
69 Q_OBJECT
70public:
71 explicit GraphicalNot(QGraphicsItem* parent = nullptr);
72 int type() const override { return SiliconTypes::NOT_GATE; }
73};
74
76 Q_OBJECT
77public:
78 explicit GraphicalNand(QGraphicsItem* parent = nullptr)
80 std::make_shared<NandGate>(std::vector<Wire_ptr>{nullptr, nullptr}, nullptr),
81 new ThemedSvgItem(":/gates/NAND_ANSI.svg"), parent)
82 {
83 }
84
85 int type() const override { return SiliconTypes::NAND_GATE; }
86};
87
89 Q_OBJECT
90public:
91 explicit GraphicalNor(QGraphicsItem* parent = nullptr)
93 std::make_shared<NorGate>(std::vector<Wire_ptr>{nullptr, nullptr}, nullptr),
94 new ThemedSvgItem(":/gates/NOR_ANSI.svg"), parent)
95 {
96 }
97
98 int type() const override { return SiliconTypes::NOR_GATE; }
99};
100
102 Q_OBJECT
103public:
104 explicit GraphicalXor(QGraphicsItem* parent = nullptr)
105
107 std::make_shared<XorGate>(std::array<Wire_ptr, 2>{nullptr, nullptr}, nullptr),
108 new ThemedSvgItem(":/gates/XOR_ANSI.svg"), parent, true)
109 {
110 }
111
112 int type() const override { return SiliconTypes::XOR_GATE; }
113};
114
115} // namespace SILICON::ui
int type() const override
GraphicalAnd(QGraphicsItem *parent=nullptr)
bool scanShape
Whether to scan shape alpha for port placement.
int type() const override
GraphicalGate(const std::shared_ptr< Gate > gate, QGraphicsItem *shape, QGraphicsItem *parent=nullptr, bool scanShape=false)
void setComponent(const Component_ptr &component) override
Sets the associated logical component.
void updatePortSizes() override
Copies associated component bus sizes into graphical ports.
GraphicalLogicComponent(ItemCategory category, const Component_ptr &component, QGraphicsItem *shape, QGraphicsItem *parent, bool scanShape=false)
int type() const override
GraphicalNand(QGraphicsItem *parent=nullptr)
GraphicalNor(QGraphicsItem *parent=nullptr)
int type() const override
int type() const override
GraphicalNot(QGraphicsItem *parent=nullptr)
GraphicalOr(QGraphicsItem *parent=nullptr)
int type() const override
int type() const override
GraphicalXor(QGraphicsItem *parent=nullptr)
std::shared_ptr< Component > Component_ptr
std::shared_ptr< Wire > Wire_ptr
Definition wire.hpp:116