32using namespace SILICON::core;
33using namespace SILICON::extra;
37 class UnaryArithmeticShape :
public QGraphicsRectItem {
39 explicit UnaryArithmeticShape(QString iconName, QGraphicsItem* parent =
nullptr)
40 : QGraphicsRectItem(0, 0, 20, 90, parent), iconName(std::move(iconName))
44 void paint(QPainter* painter,
const QStyleOptionGraphicsItem* option,
45 QWidget* widget)
override
52 painter->setRenderHint(QPainter::Antialiasing,
false);
53 painter->setPen(QPen(ink, 3));
55 painter->drawRect(rect());
57 const int iconWidth = rect().width() - 5;
58 const QPoint leftPoint =
59 rect().center().toPoint() - QPoint(iconWidth / 2, iconWidth / 2);
60 painter->setPen(QPen(ink));
62 .paint(painter, leftPoint.x(), leftPoint.y(), iconWidth, iconWidth);
71 explicit ComparatorShape(QString mode, QGraphicsItem* parent =
nullptr)
72 : ThemedSvgItem(
":/other_components/COMPARATOR.svg", parent), mode(std::move(mode))
76 void setMode(QString mode)
78 this->mode = std::move(mode);
82 void paint(QPainter* painter,
const QStyleOptionGraphicsItem* option,
83 QWidget* widget)
override
85 ThemedSvgItem::paint(painter, option, widget);
89 painter->setFont(QFont(
"Quicksand", 12, QFont::Bold));
90 painter->drawText(QRect(QPoint(40, 30), QPoint(60, 40)), mode, QTextOption(Qt::AlignCenter));
98 std::shared_ptr<Extender> makeExtender()
100 return std::make_shared<Extender>(
Bus(4),
Bus(8));
103 std::shared_ptr<Complementer> makeComplementer()
105 return std::make_shared<Complementer>(
Bus(4),
Bus(4));
108std::shared_ptr<HalfAdder> makeHalfAdder()
110 return std::make_shared<HalfAdder>(std::array<Wire_ptr, 2>{
Wire_ptr{},
Wire_ptr{}},
114std::shared_ptr<FullAdder> makeFullAdder()
116 return std::make_shared<FullAdder>(std::array<Wire_ptr, 2>{
Wire_ptr{},
Wire_ptr{}},
120std::shared_ptr<Comparator> makeComparator()
122 return std::make_shared<Comparator>(std::array<Bus, 2>{
Bus(4),
Bus(4)},
Wire_ptr{});
125std::shared_ptr<AdderNBits> makeAdderNBits()
127 constexpr unsigned short DEFAULT_SIZE = 4;
128 return std::make_shared<AdderNBits>(
129 std::array<Bus, 2>{
Bus(DEFAULT_SIZE),
Bus(DEFAULT_SIZE)},
Bus(DEFAULT_SIZE),
133std::shared_ptr<Shifter> makeShifter()
135 constexpr unsigned short DEFAULT_SIZE = 4;
136 return std::make_shared<Shifter>(
Bus(DEFAULT_SIZE),
Bus(DEFAULT_SIZE),
179 makeAdderNBits(), new
ThemedSvgItem(
":/other_components/ADDER.svg"), parent, true)
189 new ThemedSvgItem(
":/other_components/MULTIPLIER.svg"), parent,
true)
191 printPortNames =
true;
193 {
PortPair{
"product", QPoint(50, 120)}});
199 new ThemedSvgItem(
":/other_components/DIVIDER.svg"), parent,
true)
201 printPortNames =
true;
208 makeShifter(), new
ThemedSvgItem(
":/other_components/SHIFTR.svg"), parent, true)
212 {
PortPair{
"result", QPoint(90, 20)}});
221 return applyMode(std::get<std::string>(value));
228 throw std::invalid_argument(
"Shifter mode must be 'left' or 'right'");
231 ?
":/other_components/SHIFTL.svg"
232 :
":/other_components/SHIFTR.svg"));
243 applyMode(component->getPropertyValue<std::string>(
"mode")
263 return applyMode(std::get<std::string>(value));
269 if (
auto* shape =
dynamic_cast<ComparatorShape*
>(
getItemShape()))
270 shape->setMode(QString::fromStdString(mode));
281 applyMode(component->getPropertyValue<std::string>(
"mode").value_or(
"=="));
GraphicalAdderNBits(QGraphicsItem *parent=nullptr)
void setComponent(const Component_ptr &component) override
Sets the associated logical component.
GraphicalComparator(QGraphicsItem *parent=nullptr)
std::string applyMode(std::string mode)
GraphicalComplementer(QGraphicsItem *parent=nullptr)
QGraphicsItem * getItemShape() const
Gets the component shape.
bool printPortNames
Whether to print port names.
void setItemShape(QGraphicsItem *shape)
Sets the component shape graphics item.
GraphicalDivider(QGraphicsItem *parent=nullptr)
GraphicalExtender(QGraphicsItem *parent=nullptr)
GraphicalFullAdder(QGraphicsItem *parent=nullptr)
GraphicalHalfAdder(QGraphicsItem *parent=nullptr)
void setPorts(const std::vector< PortPair > &busToPortInputs, const std::vector< PortPair > &busToPortOutputs) override
Sets ports and validates against component I/O.
GraphicalLogicComponent(ItemCategory category, const Component_ptr &component, QGraphicsItem *shape, QGraphicsItem *parent, bool scanShape=false)
virtual void setComponent(const Component_ptr &component)
Sets the associated logical component.
Component_ptr associatedComponent
The logical component this graphical component represents.
GraphicalMultiplier(QGraphicsItem *parent=nullptr)
GraphicalShifter(QGraphicsItem *parent=nullptr)
void setComponent(const Component_ptr &component) override
Sets the associated logical component.
std::string applyMode(std::string mode)
static const QColor & getColor(theme::ColorToken token)
std::shared_ptr< Component > Component_ptr
std::shared_ptr< Wire > Wire_ptr
std::variant< int, bool, std::string, BusValue > PropertyValue
Variant type for component properties.
std::pair< QString, QPoint > PortPair