Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions NodeGraphQt/base/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ def set_acyclic(self, mode=False):
mode (bool): true to enable acyclic.
"""
self._model.acyclic = mode
self._viewer.acyclic = mode
self._viewer.acyclic = self._model.acyclic

def pipe_collision(self):
"""
Expand Down Expand Up @@ -910,7 +910,39 @@ def set_pipe_collision(self, mode=True):
mode (bool): False to disable pipe collision.
"""
self._model.pipe_collision = mode
self._viewer.pipe_collision = mode
self._viewer.pipe_collision = self._model.pipe_collision

def pipe_slicing(self):
"""
Returns if pipe slicing is enabled.

See Also:
To enable/disable pipe slicer
:meth:`NodeGraph.set_pipe_slicing`

Returns:
bool: True if pipe slicing is enabled.
"""
return self._model.pipe_collision

def set_pipe_slicing(self, mode=True):
"""
Enable/Disable pipe slicer.

When set to true holding down `Alt + Shift + LMB Drag` will allow node
pipe connections to be sliced.

.. image:: _images/slicer.png
:width: 400px

See Also:
:meth:`NodeGraph.pipe_slicing`

Args:
mode (bool): False to disable the slicer pipe.
"""
self._model.pipe_slicing = mode
self._viewer.pipe_slicing = self._model.pipe_slicing

def set_pipe_style(self, style=PipeLayoutEnum.CURVED.value):
"""
Expand Down Expand Up @@ -1466,6 +1498,7 @@ def _serialize(self, nodes):
# serialize graph session.
serial_data['graph']['acyclic'] = self.acyclic()
serial_data['graph']['pipe_collision'] = self.pipe_collision()
serial_data['graph']['pipe_slicing'] = self.pipe_slicing()

# serialize nodes.
for n in nodes:
Expand Down Expand Up @@ -1526,6 +1559,8 @@ def _deserialize(self, data, relative_pos=False, pos=None):
self.set_acyclic(attr_value)
elif attr_name == 'pipe_collision':
self.set_pipe_collision(attr_value)
elif attr_name == 'pipe_slicing':
self.set_pipe_slicing(attr_value)

# build the nodes.
nodes = {}
Expand Down
1 change: 1 addition & 0 deletions NodeGraphQt/base/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ def __init__(self):
self.session = ''
self.acyclic = True
self.pipe_collision = False
self.pipe_slicing = True
self.layout_direction = LayoutDirectionEnum.HORIZONTAL.value

def common_properties(self):
Expand Down
25 changes: 15 additions & 10 deletions NodeGraphQt/widgets/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def __init__(self, parent=None, undo_stack=None):

self.acyclic = True
self.pipe_collision = False
self.pipe_slicing = True

self.LMB_state = False
self.RMB_state = False
Expand Down Expand Up @@ -370,11 +371,14 @@ def mousePressEvent(self, event):
map_pos = self.mapToScene(event.pos())

# pipe slicer enabled.
slicer_mode = all([self.ALT_state, self.SHIFT_state, self.LMB_state])
if slicer_mode:
self._SLICER_PIPE.draw_path(map_pos, map_pos)
self._SLICER_PIPE.setVisible(True)
return
if self.pipe_slicing:
slicer_mode = all([
self.ALT_state, self.SHIFT_state, self.LMB_state
])
if slicer_mode:
self._SLICER_PIPE.draw_path(map_pos, map_pos)
self._SLICER_PIPE.setVisible(True)
return

# pan mode.
if self.ALT_state:
Expand Down Expand Up @@ -487,11 +491,12 @@ def mouseReleaseEvent(self, event):

def mouseMoveEvent(self, event):
if self.ALT_state and self.SHIFT_state:
if self.LMB_state and self._SLICER_PIPE.isVisible():
p1 = self._SLICER_PIPE.path().pointAtPercent(0)
p2 = self.mapToScene(self._previous_pos)
self._SLICER_PIPE.draw_path(p1, p2)
self._SLICER_PIPE.show()
if self.pipe_slicing:
if self.LMB_state and self._SLICER_PIPE.isVisible():
p1 = self._SLICER_PIPE.path().pointAtPercent(0)
p2 = self.mapToScene(self._previous_pos)
self._SLICER_PIPE.draw_path(p1, p2)
self._SLICER_PIPE.show()
self._previous_pos = event.pos()
super(NodeViewer, self).mouseMoveEvent(event)
return
Expand Down