24#include <QGraphicsRectItem>
32using namespace SILICON::core;
36constexpr QRectF RegisterBodyRect(0.0, 0.0, 100.0, 80.0);
38std::shared_ptr<Register> makeRegister()
43QString registerLabel(
const std::string& inputType,
const std::string& outputType)
47 return inputPrefix + outputSuffix +
"\nRegister";
50class RegisterShape :
public QGraphicsRectItem {
52 explicit RegisterShape(QString label, QGraphicsItem* parent =
nullptr)
53 : QGraphicsRectItem(RegisterBodyRect, parent), label(std::move(label))
57 void paint(QPainter* painter,
const QStyleOptionGraphicsItem* option,
58 QWidget* widget)
override
64 painter->setRenderHint(QPainter::Antialiasing,
false);
67 painter->drawRect(rect());
70 painter->setFont(QFont(
"Quicksand", 8, QFont::Bold));
71 painter->drawText(rect().adjusted(6, 26, -6, -6), label,
72 QTextOption(Qt::AlignCenter));
84 new RegisterShape(registerLabel(
"Parallel",
"Parallel")),
97 throw std::logic_error(
"GraphicalRegister requires a Register component");
119 const std::string inputType =
122 const std::string outputType =
130 const std::string& outputType)
132 setItemShape(
new RegisterShape(registerLabel(inputType, outputType)));
139 std::vector<PortPair> inputs{
PortPair{dataInput, QPoint(-20, 20)},
142 PortPair{
"clr", needsLoad ? QPoint(80, -20) : QPoint(50, -20)}};
144 inputs.push_back(
PortPair{
"ld", QPoint(50, -20)});
162 return appliedInputType;
167 const std::string appliedOutputType =
172 return appliedOutputType;
184 component->getPropertyValue<std::string>(
"inputType")
187 component->getPropertyValue<std::string>(
"outputType")
std::string setInputType(std::string inputType)
static constexpr std::string_view SERIAL_TYPE
std::string setOutputType(std::string outputType)
static constexpr std::string_view PARALLEL_TYPE
bool printPortNames
Whether to print port names.
void setItemShape(QGraphicsItem *shape)
Sets the component shape graphics item.
void setPorts(const std::vector< PortPair > &busToPortInputs, const std::vector< PortPair > &busToPortOutputs) override
Sets ports and validates against component I/O.
bool isEditable
Whether the component allows property editing.
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.
GraphicalRegister(QGraphicsItem *parent=nullptr)
std::string applyOutputType(const std::string &outputType)
std::string applyInputType(const std::string &inputType)
void setComponent(const Component_ptr &component) override
Sets the associated logical component.
Register * getComponentAsRegister() const
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