mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-10 04:49:01 +08:00
Add some simple tests to CuraSceneNode
This commit is contained in:
parent
6bb9e6097a
commit
28184ad999
@ -6,13 +6,13 @@ from typing import cast, Dict, List, Optional
|
||||
|
||||
from UM.Application import Application
|
||||
from UM.Math.AxisAlignedBox import AxisAlignedBox
|
||||
from UM.Math.Polygon import Polygon #For typing.
|
||||
from UM.Math.Polygon import Polygon # For typing.
|
||||
from UM.Scene.SceneNode import SceneNode
|
||||
from UM.Scene.SceneNodeDecorator import SceneNodeDecorator #To cast the deepcopy of every decorator back to SceneNodeDecorator.
|
||||
from UM.Scene.SceneNodeDecorator import SceneNodeDecorator # To cast the deepcopy of every decorator back to SceneNodeDecorator.
|
||||
|
||||
import cura.CuraApplication #To get the build plate.
|
||||
from cura.Settings.ExtruderStack import ExtruderStack #For typing.
|
||||
from cura.Settings.SettingOverrideDecorator import SettingOverrideDecorator #For per-object settings.
|
||||
import cura.CuraApplication # To get the build plate.
|
||||
from cura.Settings.ExtruderStack import ExtruderStack # For typing.
|
||||
from cura.Settings.SettingOverrideDecorator import SettingOverrideDecorator # For per-object settings.
|
||||
|
||||
|
||||
## Scene nodes that are models are only seen when selecting the corresponding build plate
|
||||
@ -21,7 +21,7 @@ class CuraSceneNode(SceneNode):
|
||||
def __init__(self, parent: Optional["SceneNode"] = None, visible: bool = True, name: str = "", no_setting_override: bool = False) -> None:
|
||||
super().__init__(parent = parent, visible = visible, name = name)
|
||||
if not no_setting_override:
|
||||
self.addDecorator(SettingOverrideDecorator()) # now we always have a getActiveExtruderPosition, unless explicitly disabled
|
||||
self.addDecorator(SettingOverrideDecorator()) # Now we always have a getActiveExtruderPosition, unless explicitly disabled
|
||||
self._outside_buildarea = False
|
||||
|
||||
def setOutsideBuildArea(self, new_value: bool) -> None:
|
||||
@ -59,7 +59,7 @@ class CuraSceneNode(SceneNode):
|
||||
if extruder_id is not None:
|
||||
if extruder_id == extruder.getId():
|
||||
return extruder
|
||||
else: # If the id is unknown, then return the extruder in the position 0
|
||||
else: # If the id is unknown, then return the extruder in the position 0
|
||||
try:
|
||||
if extruder.getMetaDataEntry("position", default = "0") == "0": # Check if the position is zero
|
||||
return extruder
|
||||
@ -93,7 +93,7 @@ class CuraSceneNode(SceneNode):
|
||||
if not convex_hull.isValid():
|
||||
return False
|
||||
|
||||
# Check for collisions between disallowed areas and the object
|
||||
# Check for collisions between provided areas and the object
|
||||
for area in areas:
|
||||
overlap = convex_hull.intersectsPolygon(area)
|
||||
if overlap is None:
|
||||
|
54
tests/TestCuraSceneNode.py
Normal file
54
tests/TestCuraSceneNode.py
Normal file
@ -0,0 +1,54 @@
|
||||
from UM.Math.Polygon import Polygon
|
||||
from UM.Scene.SceneNodeDecorator import SceneNodeDecorator
|
||||
from cura.Scene.CuraSceneNode import CuraSceneNode
|
||||
import pytest
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
|
||||
class TestConvexHullDecorator(SceneNodeDecorator):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def getConvexHull(self):
|
||||
return Polygon([[5, 5], [-5, 5], [-5, -5], [5, -5]])
|
||||
|
||||
|
||||
class TestInvalidConvexHullDecorator(SceneNodeDecorator):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def getConvexHull(self):
|
||||
return Polygon()
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def cura_scene_node():
|
||||
# Replace the SettingOverrideDecorator with an empty decorator
|
||||
with patch("cura.Scene.CuraSceneNode.SettingOverrideDecorator", SceneNodeDecorator):
|
||||
return CuraSceneNode()
|
||||
|
||||
|
||||
class TestCollidesWithAreas:
|
||||
def test_noConvexHull(self, cura_scene_node):
|
||||
assert not cura_scene_node.collidesWithAreas([Polygon([[10, 10], [-10, 10], [-10, -10], [10, -10]])])
|
||||
|
||||
def test_convexHullIntersects(self, cura_scene_node):
|
||||
cura_scene_node.addDecorator(TestConvexHullDecorator())
|
||||
assert cura_scene_node.collidesWithAreas([Polygon([[10, 10], [-10, 10], [-10, -10], [10, -10]])])
|
||||
|
||||
def test_convexHullNoIntersection(self, cura_scene_node):
|
||||
cura_scene_node.addDecorator(TestConvexHullDecorator())
|
||||
|
||||
assert not cura_scene_node.collidesWithAreas([Polygon([[60, 60], [40, 60], [40, 40], [60, 40]])])
|
||||
|
||||
def test_invalidConvexHull(self, cura_scene_node):
|
||||
cura_scene_node.addDecorator(TestInvalidConvexHullDecorator())
|
||||
assert not cura_scene_node.collidesWithAreas([Polygon([[10, 10], [-10, 10], [-10, -10], [10, -10]])])
|
||||
|
||||
|
||||
def test_outsideBuildArea(cura_scene_node):
|
||||
cura_scene_node.setOutsideBuildArea(True)
|
||||
assert cura_scene_node.isOutsideBuildArea
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user