Skip to content

Commit 9435602

Browse files
committed
study : gate shapes accroding functionality in graph view
1 parent b66f5a5 commit 9435602

9 files changed

Lines changed: 210 additions & 239 deletions

File tree

examples/gateicon_demo.zip

12.6 KB
Binary file not shown.

plugins/gui/include/gui/graph_widget/items/nodes/gates/graphics_gate.h

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@
2626
#pragma once
2727

2828
#include "gui/graph_widget/items/nodes/graphics_node.h"
29+
#include "hal_core/netlist/gate_library/enums/gate_type_property.h"
2930

3031
#include <memory>
31-
#include <QHash>
32+
#include <QPainterPath>
3233

3334
namespace hal
3435
{
@@ -56,6 +57,17 @@ namespace hal
5657

5758
protected:
5859

60+
struct GraphicsGatePin
61+
{
62+
QString name;
63+
float textWidth;
64+
u32 netId;
65+
int index;
66+
bool isInput;
67+
};
68+
69+
enum ShapeType { StandardShape, InverterShape, AndShape, OrShape };
70+
5971
/**
6072
* Pointer to gate in hal core
6173
*/
@@ -66,14 +78,18 @@ namespace hal
6678
*/
6779
QString mType;
6880

81+
ShapeType mShapeType;
82+
83+
QPainterPath mPath;
84+
6985
/**
7086
* The input pin type identifiers of the underlying gate (from top to bottom)
7187
*/
72-
QVector<QString> mInputPins;
88+
QVector<struct GraphicsGatePin> mInputPinStruct;
7389

7490
/**
7591
* The output pin type identifiers of the underlying gate (from top to bottom)
7692
*/
77-
QVector<QString> mOutputPins;
93+
QVector<struct GraphicsGatePin> mOutputPinStruct;
7894
};
7995
}

plugins/gui/include/gui/graph_widget/items/nodes/gates/standard_graphics_gate.h

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,6 @@ namespace hal
6666
*/
6767
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = nullptr) override;
6868

69-
/**
70-
* Given the id of a net and the type of the pin of one of its destinations, this function returns
71-
* the position of the input pin in the scene.
72-
*
73-
* @param mNetId - The net id
74-
* @param pin_type - The input pin type
75-
* @returns The pin's position in the scene
76-
*/
77-
QPointF getInputScenePosition(const u32 mNetId, const QString& pin_type) const override;
78-
79-
/**
80-
* Given the id of a net and the type of the pin of one of its sources, this function returns
81-
* the position of the output pin in the scene.
82-
*
83-
* @param mNetId - The net id
84-
* @param pin_type - The output pin type
85-
* @returns The pin's position in the scene
86-
*/
87-
QPointF getOutputScenePosition(const u32 mNetId, const QString& pin_type) const override;
88-
8969
/**
9070
* Given the index of an input/output pin, this function returns the position of this pin in the scene. <br>
9171
* (Pins are positioned from top (idx=0) to bottom (idx=maxIdx))
@@ -142,14 +122,13 @@ namespace hal
142122

143123
void format(const bool& adjust_size_to_grid);
144124

145-
QVector<float> mInputPinTextWidth;
146-
QVector<float> mOutputPinTextWidth;
147125
static const int sIconPadding;
148126
static const QSize sIconSize;
149127

150-
static QPixmap* sIconInstance;
151-
static const QPixmap& iconPixmap();
152128
static QColor legibleColor(const QColor& bgColor);
153129

130+
enum FocusType { NoFocus, GateFocus, PinFocus };
131+
132+
void paintPin(QPainter* painter, QStyle::State state, const GraphicsGatePin& pin, FocusType focusType);
154133
};
155134
}

plugins/gui/include/gui/graph_widget/items/nodes/graphics_node.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -82,26 +82,6 @@ namespace hal
8282
*/
8383
virtual QPainterPath shape() const override;
8484

85-
/**
86-
* Given the id of a net and the type of the pin of one of its destinations, this function returns
87-
* the position of the input pin in the scene.
88-
*
89-
* @param mNetId - The net id
90-
* @param pin_type - The input pin type
91-
* @returns The pin's position in the scene
92-
*/
93-
virtual QPointF getInputScenePosition(const u32 mNetId, const QString& pin_type) const = 0;
94-
95-
/**
96-
* Given the id of a net and the type of the pin of one of its sources, this function returns
97-
* the position of the output pin in the scene.
98-
*
99-
* @param mNetId - The net id
100-
* @param pin_type - The output pin type
101-
* @returns The pin's position in the scene
102-
*/
103-
virtual QPointF getOutputScenePosition(const u32 mNetId, const QString& pin_type) const = 0;
104-
10585
/**
10686
* Given the index of an input/output pin, this function returns the position of this pin in the scene. <br>
10787
* (Pins are positioned from top (idx=0) to bottom (idx=maxIdx))

plugins/gui/include/gui/graph_widget/items/nodes/modules/standard_graphics_module.h

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -67,26 +67,6 @@ namespace hal
6767
*/
6868
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = nullptr) override;
6969

70-
/**
71-
* Given the id of a net and the type of the pin of one of its destinations, this function returns
72-
* the position of the input pin in the scene.
73-
*
74-
* @param mNetId - The net id
75-
* @param pin_type - The input pin type
76-
* @returns The pins position in the scene
77-
*/
78-
QPointF getInputScenePosition(const u32 mNetId, const QString& pin_type) const override;
79-
80-
/**
81-
* Given the id of a net and the type of the pin of one of its sources, this function returns
82-
* the position of the output pin in the scene.
83-
*
84-
* @param mNetId - The net id
85-
* @param pin_type - The output pin type
86-
* @returns The pins position in the scene
87-
*/
88-
QPointF getOutputScenePosition(const u32 mNetId, const QString& pin_type) const override;
89-
9070
/**
9171
* Given the index of an input/output pin, this function returns the position of this pin in the scene. <br>
9272
* (Pins are positioned from top (idx=0) to bottom (idx=maxIdx))
@@ -143,7 +123,5 @@ namespace hal
143123
static const int sIconPadding;
144124
static const QSize sIconSize;
145125

146-
static QPixmap* sIconInstance;
147-
static const QPixmap& iconPixmap();
148126
};
149127
} // namespace hal

plugins/gui/src/graph_widget/graph_graphics_view.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,6 @@ namespace hal
333333
// TODO set MIME type and icon
334334
mimeData->setText("dragTest");
335335
drag->setMimeData(mimeData);
336-
// drag->setPixmap(iconPixmap);
337336

338337
// enable DragMoveEvents until mouse released
339338
drag->exec(Qt::MoveAction);

plugins/gui/src/graph_widget/items/nodes/gates/graphics_gate.cpp

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,73 @@
22

33
#include "hal_core/netlist/gate.h"
44
#include "hal_core/netlist/net.h"
5+
#include <QHash>
56

67
namespace hal
78
{
8-
GraphicsGate::GraphicsGate(Gate* g) : GraphicsNode(ItemType::Gate, g->get_id()), mGate(g), mType(QString::fromStdString(g->get_type()->get_name()))
9+
GraphicsGate::GraphicsGate(Gate* g)
10+
: GraphicsNode(ItemType::Gate, g->get_id()),
11+
mGate(g),
12+
mType(QString::fromStdString(g->get_type()->get_name())),
13+
mShapeType(StandardShape)
914
{
1015
QString textLines[3];
1116
textLines[0] = QString::fromStdString(g->get_name());
1217
const GateType* gt = g->get_type();
18+
19+
for (GateTypeProperty& gtprop : gt->get_property_list())
20+
{
21+
switch(gtprop) {
22+
case GateTypeProperty::c_inverter:
23+
mShapeType = InverterShape;
24+
break;
25+
case hal::GateTypeProperty::c_and:
26+
case hal::GateTypeProperty::c_nand:
27+
mShapeType = AndShape;
28+
break;
29+
case hal::GateTypeProperty::c_or:
30+
case hal::GateTypeProperty::c_nor:
31+
case hal::GateTypeProperty::c_xor:
32+
case hal::GateTypeProperty::c_xnor:
33+
mShapeType = OrShape;
34+
break;
35+
default:
36+
break;
37+
}
38+
}
39+
1340
for (const GatePin* input_pin : gt->get_input_pins())
1441
{
42+
u32 netId = 0;
43+
int index = mInputPinStruct.size();
1544
const Net* n = g->get_fan_in_net(input_pin);
1645
if (n)
1746
{
18-
mInputByNet.insert(n->get_id(), mInputPins.size());
47+
netId = n->get_id();
48+
mInputByNet.insert(netId, index);
1949
}
2050
else
2151
{
22-
mInputByNet.insert(0, mInputPins.size());
52+
mInputByNet.insert(0, index);
2353
}
24-
mInputPins.append(QString::fromStdString(input_pin->get_name()));
54+
mInputPinStruct.append({QString::fromStdString(input_pin->get_name()), 0., netId, index, true});
2555
}
2656

2757
for (const GatePin* output_pin : gt->get_output_pins())
2858
{
59+
u32 netId = 0;
60+
int index = mOutputPinStruct.size();
2961
const Net* n = g->get_fan_out_net(output_pin);
3062
if (n)
3163
{
32-
mOutputByNet.insert(n->get_id(), mOutputPins.size());
64+
netId = n->get_id();
65+
mOutputByNet.insert(netId, index);
3366
}
3467
else
3568
{
36-
mOutputByNet.insert(0, mOutputPins.size());
69+
mOutputByNet.insert(0, index);
3770
}
38-
mOutputPins.append(QString::fromStdString(output_pin->get_name()));
71+
mOutputPinStruct.append({QString::fromStdString(output_pin->get_name()), 0., netId, index, false});
3972
}
4073

4174
textLines[1] = QString::fromStdString(gt->get_name());

0 commit comments

Comments
 (0)