| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9926200 commit 07264cd
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -238,7 +238,6 @@ nodePortIndexUnderScenePoint(PortType portType, | |||
| 238 | 238 | PortIndex portIndex = nodeGeom.checkHitScenePoint(portType, | |
| 239 | 239 | scenePoint, | |
| 240 | 240 | sceneTransform); | |
| 241 | - | ||
| 242 | 241 | return portIndex; | |
| 243 | 242 | } | |
| 244 | 243 | ||
@@ -251,6 +250,8 @@ nodePortIsEmpty(PortType portType, PortIndex portIndex) const | |||
| 251 | 250 | ||
| 252 | 251 | auto const & entries = nodeState.getEntries(portType); | |
| 253 | 252 | ||
| 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); | ||
| 256 | 257 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -77,6 +77,15 @@ class NODE_EDITOR_PUBLIC NodeDataModel | |||
| 77 | 77 | NodeDataType | |
| 78 | 78 | dataType(PortType portType, PortIndex portIndex) const = 0; | |
| 79 | 79 | ||
| 80 | + enum NodeConnectionPolicy { | ||
| 81 | + One, | ||
| 82 | + Many, | ||
| 83 | + }; | ||
| 84 | + | ||
| 85 | + virtual NodeConnectionPolicy portOutConnectionPolicy(PortIndex /*portIndex*/) const { | ||
| 86 | + return NodeConnectionPolicy::Many; | ||
| 87 | + } | ||
| 88 | + | ||
| 80 | 89 | public: | |
| 81 | 90 | ||
| 82 | 91 | /// Triggers the algorithm | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -201,28 +201,34 @@ mousePressEvent(QGraphicsSceneMouseEvent * event) | |||
| 201 | 201 | std::unordered_map<QUuid, Connection*> connections = | |
| 202 | 202 | nodeState.connections(portToCheck, portIndex); | |
| 203 | 203 | ||
| 204 | + | ||
| 204 | 205 | // start dragging existing connection | |
| 205 | - if (!connections.empty() && portToCheck == PortType::In) | ||
| 206 | + if ( !connections.empty() && portToCheck == PortType::In ) | ||
| 206 | 207 | { | |
| 207 | - auto con = connections.begin()->second; | ||
| 208 | + auto con = connections.begin()->second; | ||
| 208 | 209 | ||
| 209 | - NodeConnectionInteraction interaction(_node, *con, _scene); | ||
| 210 | + NodeConnectionInteraction interaction(_node, *con, _scene); | ||
| 210 | 211 | ||
| 211 | - interaction.disconnect(portToCheck); | ||
| 212 | + interaction.disconnect(portToCheck); | ||
| 212 | 213 | } | |
| 213 | - // initialize new Connection | ||
| 214 | - else | ||
| 214 | + else // initialize new Connection | ||
| 215 | 215 | { | |
| 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(); | ||
| 226 | 232 | } | |
| 227 | 233 | } | |
| 228 | 234 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -124,11 +124,14 @@ drawConnectionPoints(QPainter* painter, | |||
| 124 | 124 | ||
| 125 | 125 | auto const & dataType = model->dataType(portType, i); | |
| 126 | 126 | ||
| 127 | + bool canConnect = (state.getEntries(portType)[i].empty() || | ||
| 128 | + (portType == PortType::Out && | ||
| 129 | + model->portOutConnectionPolicy(i) == NodeDataModel::Many) ); | ||
| 130 | + | ||
| 127 | 131 | double r = 1.0; | |
| 128 | 132 | if (state.isReacting() && | |
| 129 | - (state.getEntries(portType)[i].empty() || | ||
| 130 | - portType == PortType::Out) && | ||
| 131 | - portType == state.reactingPortType()) | ||
| 133 | + canConnect && | ||
| 134 | + portType == state.reactingPortType()) | ||
| 132 | 135 | { | |
| 133 | 136 | ||
| 134 | 137 | auto diff = geom.draggingPos() - p; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments