FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Allow single connection policy for output ports (#83) · BehaviorTree/nodeeditor@07264cd · GitHub

Commit 07264cd

Browse files
authored andcommitted
Allow single connection policy for output ports (paceholder#83)
1 parent 9926200 commit 07264cd

4 files changed

Lines changed: 41 additions & 22 deletions

File tree

‎src/NodeConnectionInteraction.cpp‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ nodePortIndexUnderScenePoint(PortType portType,
238238
PortIndex portIndex = nodeGeom.checkHitScenePoint(portType,
239239
scenePoint,
240240
sceneTransform);
241-
242241
return portIndex;
243242
}
244243

@@ -251,6 +250,8 @@ nodePortIsEmpty(PortType portType, PortIndex portIndex) const
251250

252251
auto const & entries = nodeState.getEntries(portType);
253252

254-
return (portType == PortType::Out) ||
255-
(entries[portIndex].empty());
253+
if (entries[portIndex].empty()) return true;
254+
255+
const auto outPolicy = _node->nodeDataModel()->portOutConnectionPolicy(portIndex);
256+
return ( portType == PortType::Out && outPolicy == NodeDataModel::Many);
256257
}

‎src/NodeDataModel.hpp‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ class NODE_EDITOR_PUBLIC NodeDataModel
7777
NodeDataType
7878
dataType(PortType portType, PortIndex portIndex) const = 0;
7979

80+
enum NodeConnectionPolicy {
81+
One,
82+
Many,
83+
};
84+
85+
virtual NodeConnectionPolicy portOutConnectionPolicy(PortIndex /*portIndex*/) const {
86+
return NodeConnectionPolicy::Many;
87+
}
88+
8089
public:
8190

8291
/// Triggers the algorithm

‎src/NodeGraphicsObject.cpp‎

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -201,28 +201,34 @@ mousePressEvent(QGraphicsSceneMouseEvent * event)
201201
std::unordered_map<QUuid, Connection*> connections =
202202
nodeState.connections(portToCheck, portIndex);
203203

204+
204205
// start dragging existing connection
205-
if (!connections.empty() && portToCheck == PortType::In)
206+
if ( !connections.empty() && portToCheck == PortType::In )
206207
{
207-
auto con = connections.begin()->second;
208+
auto con = connections.begin()->second;
208209

209-
NodeConnectionInteraction interaction(_node, *con, _scene);
210+
NodeConnectionInteraction interaction(_node, *con, _scene);
210211

211-
interaction.disconnect(portToCheck);
212+
interaction.disconnect(portToCheck);
212213
}
213-
// initialize new Connection
214-
else
214+
else // initialize new Connection
215215
{
216-
// todo add to FlowScene
217-
auto connection = _scene.createConnection(portToCheck,
218-
_node,
219-
portIndex);
220-
221-
_node.nodeState().setConnection(portToCheck,
222-
portIndex,
223-
*connection);
224-
225-
connection->getConnectionGraphicsObject().grabMouse();
216+
const auto outPolicy = _node.nodeDataModel()->portOutConnectionPolicy(portIndex);
217+
if ( !connections.empty() && (portToCheck == PortType::Out && outPolicy == NodeDataModel::One) )
218+
{
219+
_scene.deleteConnection( *connections.begin()->second );
220+
}
221+
222+
// todo add to FlowScene
223+
auto connection = _scene.createConnection(portToCheck,
224+
_node,
225+
portIndex);
226+
227+
_node.nodeState().setConnection(portToCheck,
228+
portIndex,
229+
*connection);
230+
231+
connection->getConnectionGraphicsObject().grabMouse();
226232
}
227233
}
228234
};

‎src/NodePainter.cpp‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,14 @@ drawConnectionPoints(QPainter* painter,
124124

125125
auto const & dataType = model->dataType(portType, i);
126126

127+
bool canConnect = (state.getEntries(portType)[i].empty() ||
128+
(portType == PortType::Out &&
129+
model->portOutConnectionPolicy(i) == NodeDataModel::Many) );
130+
127131
double r = 1.0;
128132
if (state.isReacting() &&
129-
(state.getEntries(portType)[i].empty() ||
130-
portType == PortType::Out) &&
131-
portType == state.reactingPortType())
133+
canConnect &&
134+
portType == state.reactingPortType())
132135
{
133136

134137
auto diff = geom.draggingPos() - p;

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL