Skip to content

Commit f7f35fb

Browse files
authored
Merge pull request #302 from jchanvfx/pipe_slicer_enable/disable
added ability to disable pipe slicing.
2 parents f18aafb + 3f4a4f9 commit f7f35fb

File tree

3 files changed

+53
-12
lines changed

3 files changed

+53
-12
lines changed

NodeGraphQt/base/graph.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ def set_acyclic(self, mode=False):
881881
mode (bool): true to enable acyclic.
882882
"""
883883
self._model.acyclic = mode
884-
self._viewer.acyclic = mode
884+
self._viewer.acyclic = self._model.acyclic
885885

886886
def pipe_collision(self):
887887
"""
@@ -910,7 +910,39 @@ def set_pipe_collision(self, mode=True):
910910
mode (bool): False to disable pipe collision.
911911
"""
912912
self._model.pipe_collision = mode
913-
self._viewer.pipe_collision = mode
913+
self._viewer.pipe_collision = self._model.pipe_collision
914+
915+
def pipe_slicing(self):
916+
"""
917+
Returns if pipe slicing is enabled.
918+
919+
See Also:
920+
To enable/disable pipe slicer
921+
:meth:`NodeGraph.set_pipe_slicing`
922+
923+
Returns:
924+
bool: True if pipe slicing is enabled.
925+
"""
926+
return self._model.pipe_collision
927+
928+
def set_pipe_slicing(self, mode=True):
929+
"""
930+
Enable/Disable pipe slicer.
931+
932+
When set to true holding down `Alt + Shift + LMB Drag` will allow node
933+
pipe connections to be sliced.
934+
935+
.. image:: _images/slicer.png
936+
:width: 400px
937+
938+
See Also:
939+
:meth:`NodeGraph.pipe_slicing`
940+
941+
Args:
942+
mode (bool): False to disable the slicer pipe.
943+
"""
944+
self._model.pipe_slicing = mode
945+
self._viewer.pipe_slicing = self._model.pipe_slicing
914946

915947
def set_pipe_style(self, style=PipeLayoutEnum.CURVED.value):
916948
"""
@@ -1466,6 +1498,7 @@ def _serialize(self, nodes):
14661498
# serialize graph session.
14671499
serial_data['graph']['acyclic'] = self.acyclic()
14681500
serial_data['graph']['pipe_collision'] = self.pipe_collision()
1501+
serial_data['graph']['pipe_slicing'] = self.pipe_slicing()
14691502

14701503
# serialize nodes.
14711504
for n in nodes:
@@ -1526,6 +1559,8 @@ def _deserialize(self, data, relative_pos=False, pos=None):
15261559
self.set_acyclic(attr_value)
15271560
elif attr_name == 'pipe_collision':
15281561
self.set_pipe_collision(attr_value)
1562+
elif attr_name == 'pipe_slicing':
1563+
self.set_pipe_slicing(attr_value)
15291564

15301565
# build the nodes.
15311566
nodes = {}

NodeGraphQt/base/model.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ def __init__(self):
356356
self.session = ''
357357
self.acyclic = True
358358
self.pipe_collision = False
359+
self.pipe_slicing = True
359360
self.layout_direction = LayoutDirectionEnum.HORIZONTAL.value
360361

361362
def common_properties(self):

NodeGraphQt/widgets/viewer.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def __init__(self, parent=None, undo_stack=None):
122122

123123
self.acyclic = True
124124
self.pipe_collision = False
125+
self.pipe_slicing = True
125126

126127
self.LMB_state = False
127128
self.RMB_state = False
@@ -370,11 +371,14 @@ def mousePressEvent(self, event):
370371
map_pos = self.mapToScene(event.pos())
371372

372373
# pipe slicer enabled.
373-
slicer_mode = all([self.ALT_state, self.SHIFT_state, self.LMB_state])
374-
if slicer_mode:
375-
self._SLICER_PIPE.draw_path(map_pos, map_pos)
376-
self._SLICER_PIPE.setVisible(True)
377-
return
374+
if self.pipe_slicing:
375+
slicer_mode = all([
376+
self.ALT_state, self.SHIFT_state, self.LMB_state
377+
])
378+
if slicer_mode:
379+
self._SLICER_PIPE.draw_path(map_pos, map_pos)
380+
self._SLICER_PIPE.setVisible(True)
381+
return
378382

379383
# pan mode.
380384
if self.ALT_state:
@@ -487,11 +491,12 @@ def mouseReleaseEvent(self, event):
487491

488492
def mouseMoveEvent(self, event):
489493
if self.ALT_state and self.SHIFT_state:
490-
if self.LMB_state and self._SLICER_PIPE.isVisible():
491-
p1 = self._SLICER_PIPE.path().pointAtPercent(0)
492-
p2 = self.mapToScene(self._previous_pos)
493-
self._SLICER_PIPE.draw_path(p1, p2)
494-
self._SLICER_PIPE.show()
494+
if self.pipe_slicing:
495+
if self.LMB_state and self._SLICER_PIPE.isVisible():
496+
p1 = self._SLICER_PIPE.path().pointAtPercent(0)
497+
p2 = self.mapToScene(self._previous_pos)
498+
self._SLICER_PIPE.draw_path(p1, p2)
499+
self._SLICER_PIPE.show()
495500
self._previous_pos = event.pos()
496501
super(NodeViewer, self).mouseMoveEvent(event)
497502
return

0 commit comments

Comments
 (0)