Skip to content

Commit

Permalink
Fix cutting edge bug
Browse files Browse the repository at this point in the history
  • Loading branch information
don4get committed Jul 12, 2020
1 parent a89240c commit b610ea8
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ include_trailing_comma = True
force_grid_wrap=0
use_parentheses=True

known_third_party = PIL,PyQt5,pytest,pytestqt,recommonmark,setuptools
known_third_party = PIL,PySide2,pytest,pytestqt,recommonmark,setuptools

23 changes: 19 additions & 4 deletions nodedge/graphics_cut_line.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""Graphics cut line module containing
:class:`~nodedge.graphics_cut_line.GraphicsCutLine` class. """

import logging
from enum import IntEnum
from typing import List, Optional

Expand Down Expand Up @@ -31,7 +31,10 @@ class CutLine:
:class:`~nodedge.graphics_cut_line.CutLine` class.
"""

def __init__(self, graphicsView: "GraphicsView"): # type: ignore
def __init__(self, graphicsView: "GraphicsView") -> None: # type: ignore

self.__logger = logging.getLogger(__file__)
self.__logger.setLevel(logging.INFO)
self.mode: CutLineMode = CutLineMode.NOOP
self.graphicsCutLine: GraphicsCutLine = GraphicsCutLine()
self.graphicsView = graphicsView
Expand Down Expand Up @@ -92,7 +95,7 @@ def cutIntersectingEdges(self) -> None:
"""
try:
scene: "Scene" = self.graphicsView.graphicsScene.scene # type: ignore

self.__logger.debug(f"Cutting points: {self.graphicsCutLine.linePoints}")
for ix in range(len(self.graphicsCutLine.linePoints) - 1):
p1 = self.graphicsCutLine.linePoints[ix]
p2 = self.graphicsCutLine.linePoints[ix + 1]
Expand All @@ -102,12 +105,24 @@ def cutIntersectingEdges(self) -> None:
# all edges removed we could cut 3 edges leading to a single editor
# this will notify it 3x maybe we could use some Notifier class with
# methods collect() and dispatch()
for edge in scene.edges:

for edge in reversed(scene.edges):
if edge.graphicsEdge.intersectsWith(p1, p2):
self.__logger.debug(
f"[{p1.__pos__()}, {p2.__pos__()}] intersects with: {edge}"
)
edge.remove()
else:
self.__logger.debug(
f"[{p1.__pos__()}, {p2.__pos__()}] does not intersect with: "
f"{edge.graphicsEdge.path()}"
)

scene.history.store("Delete cut edges.")
self.__logger.debug("Cutting has been done.")

except Exception as e:
self.__logger.debug("e")
dumpException(e)


Expand Down
2 changes: 1 addition & 1 deletion nodedge/graphics_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def middleMouseButtonRelease(self, event: QMouseEvent):
event.localPos(),
event.screenPos(),
Qt.LeftButton,
event.buttons() & -Qt.LeftButton,
event.buttons() | -Qt.LeftButton,
event.modifiers(),
)
super().mouseReleaseEvent(fake_event)
Expand Down
1 change: 1 addition & 0 deletions nodedge/mdi_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ def checkStylesheet(self) -> None:
self.stylesheetLastModified = modTime
loadStyleSheets(self.styleSheetFilename)

@Slot(List[str]) # type: ignore
def showItemsInStatusBar(self, items: List[str]):
"""
Slot triggered when an item has been selected.
Expand Down
5 changes: 3 additions & 2 deletions nodedge/scene_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class SceneHistory:

# noinspection PyUnresolvedReferences
def __init__(
self, scene: "Scene", maxLength: int = 32
) -> None: # type: ignore # noqa: F821
self, scene: "Scene", maxLength: int = 32 # type: ignore # noqa: F821
) -> None:
"""
:param scene: reference to the :class:`~nodedge.scene.Scene`
:type scene: :class:`~nodedge.scene.Scene`
Expand Down Expand Up @@ -301,6 +301,7 @@ def _restoreStamp(self, stamp: Dict) -> None:
if node.id == nodeId:
node.graphicsNode.setSelected(True)
break
self.__logger.debug("History stamp has been restored.")
except Exception as e:
self.__logger.warning("Failed to restore stamp")
dumpException(e)
Expand Down

0 comments on commit b610ea8

Please sign in to comment.