25 #include <QStyleOptionGraphicsItem>
32 const QColor EditableCellItem::DEFAULT_HIGHLIGHT_COLOR(230,0,0,255);
35 :
QGraphicsPolygonItem(), m_cell(cell), m_edges(edges), m_nodes(nodes), m_color(55, 255, 255, 255), m_highlight_color(DEFAULT_HIGHLIGHT_COLOR)
42 connect(node, SIGNAL(Moved()),
this, SLOT(
Update()));
57 return m_cell->HasBoundaryWall();
78 return std::find(m_nodes.begin(), m_nodes.end(), node) != m_nodes.end();
83 return std::find(m_edges.begin(), m_edges.end(), edge) != m_edges.end();
88 QPen pen(this->pen());
90 m_highlight_color.setAlpha(brush().color().alpha());
91 setBrush(m_highlight_color);
98 int alpha = brush().color().alpha();
100 m_color.setAlpha(alpha);
105 int alpha = brush().color().alpha();
106 m_highlight_color = color;
107 m_highlight_color.setAlpha(alpha);
112 int alpha = (transparent ? 64 : 255);
114 m_color.setAlpha(alpha);
115 QColor color = brush().color();
117 setBrush(QBrush(QColor(color.red(), color.green(), color.blue(), alpha)));
124 assert(connectedNode !=
nullptr &&
"The two new edges aren't connected.");
126 auto foundEdge = std::find(m_edges.begin(), m_edges.end(), oldEdge);
127 assert(foundEdge != m_edges.end() &&
"This cell doesn't contain the old edge. [inconsistency]");
128 auto foundNode = std::find(m_nodes.begin(), m_nodes.end(), nodeEdge1);
129 assert(foundNode != m_nodes.end() &&
"This cell doesn't contain the endpoints of the old edge. [inconsistency]");
133 if (foundEdge == m_edges.end()) {
134 foundEdge = m_edges.begin();
137 if ((*foundEdge)->First() == nodeEdge1 || (*foundEdge)->Second() == nodeEdge1) {
139 m_edges.insert(foundEdge, edge2);
140 m_edges.insert(foundEdge, edge1);
141 m_nodes.insert(foundNode, connectedNode);
145 m_edges.insert(foundEdge, edge1);
146 m_edges.insert(foundEdge, edge2);
147 m_nodes.insert(++foundNode, connectedNode);
149 m_edges.remove(oldEdge);
151 connect(connectedNode, SIGNAL(Moved()),
this, SLOT(
Update()));
168 assert(connectedNode !=
nullptr &&
"The two new edges aren't connected.");
169 assert(std::find(m_nodes.begin(), m_nodes.end(), connectedNode) != m_nodes.end() &&
"This cell doesn't contain the connected node. [inconsistency]");
170 assert(std::find(m_edges.begin(), m_edges.end(), oldEdge1) != m_edges.end() &&
"This cell doesn't contain the first old edge. [inconsistency]");
171 assert(std::find(m_edges.begin(), m_edges.end(), oldEdge2) != m_edges.end() &&
"This cell doesn't contain the second old edge. [inconsistency]");
173 m_nodes.remove(connectedNode);
175 m_edges.insert(std::find(m_edges.begin(), m_edges.end(), oldEdge1), edge);
176 m_edges.remove(oldEdge1);
177 m_edges.remove(oldEdge2);
191 endpoints.append(node->pos());
193 setPolygon(endpoints);
196 void EditableCellItem::paint(QPainter* painter,
const QStyleOptionGraphicsItem* option,
QWidget* widget)
198 if (flags().testFlag(QGraphicsItem::ItemIsSelectable)) {
199 setBrush(QBrush(QColor(220, 220, 220, brush().color().alpha())));
202 setBrush(QBrush(m_color));
206 QStyleOptionGraphicsItem noRectBorder(*option);
207 noRectBorder.state &= !QStyle::State_Selected;
208 QGraphicsPolygonItem::paint(painter, &noRectBorder, widget);
EditableNodeItem * Second() const
Returns the second endpoint of the edge item.
A cell contains walls and nodes.
Namespace for SimPT tissue editor package.
virtual void SetHighlightColor(const QColor &color=DEFAULT_HIGHLIGHT_COLOR)
Set the color the item should get when it gets highlighted.
void SetColor(const QColor &color)
Set the color of the cell.
void SetTransparent(bool transparent)
Set the transparency of a cell.
const std::list< EditableNodeItem * > & Nodes() const
Get the nodes in this cell.
const std::list< EditableEdgeItem * > & Edges() const
Get the edges in this cell.
see the online Qt documentation
Namespace for the core simulator.
void ReplaceTwoEdgesWithEdge(EditableEdgeItem *oldEdge1, EditableEdgeItem *oldEdge2, EditableEdgeItem *edge)
Replaces two given edges with one other edge.
Editable graphical representation for Edge.
virtual bool IsAtBoundary() const
Checks whether the cell is at the boundary of the cell complex.
Editable graphical representation for Node.
EditableCellItem(const std::list< EditableNodeItem * > &nodes, const std::list< EditableEdgeItem * > &edges, SimPT_Sim::Cell *cell)
Constructor.
EditableNodeItem * First() const
Returns the first endpoint of the edge item.
Interface for EditableNodeItem.
EditableNodeItem * ConnectingNode(EditableEdgeItem *edge) const
Returns the connecting node when this edge and the given edge connect.
bool ContainsEdge(EditableEdgeItem *edge) const
Checks whether this cell contains the given edge.
SimPT_Sim::Cell * Cell() const
Get the logical cell.
void Update()
Update the cell.
see the online Qt documentation
virtual void Highlight(bool highlighted)
Highlights the node in the canvas.
bool ContainsNode(EditableNodeItem *node) const
Checks whether this cell contains the given node.
virtual ~EditableCellItem()
Destructor.
void ReplaceEdgeWithTwoEdges(EditableEdgeItem *oldEdge, EditableEdgeItem *edge1, EditableEdgeItem *edge2)
Replaces a given edge with two other edges.
Interface for EditableEdgeItem.
Interface for EditableCellItem.