From e6bd9f8cc6cb8941dfad13ab4c557604c91ceb00 Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Thu, 19 Mar 2015 12:16:07 +0100 Subject: [PATCH] Add support for rendering disallowed areas --- BuildVolume.py | 23 +++++++++++++++++++++++ PrinterApplication.py | 23 ++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/BuildVolume.py b/BuildVolume.py index 8dfdad69cb..eda3bff26d 100644 --- a/BuildVolume.py +++ b/BuildVolume.py @@ -24,6 +24,9 @@ class BuildVolume(SceneNode): self._grid_mesh = None self._grid_material = None + self._disallowed_areas = [] + self._disallowed_area_mesh = None + def setWidth(self, width): self._width = width @@ -33,6 +36,9 @@ class BuildVolume(SceneNode): def setDepth(self, depth): self._depth = depth + def setDisallowedAreas(self, areas): + self._disallowed_areas = areas + def render(self, renderer): if not self.getMeshData(): return True @@ -51,6 +57,8 @@ class BuildVolume(SceneNode): renderer.queueNode(self, material = self._material, mode = Renderer.RenderLines) renderer.queueNode(self, mesh = self._grid_mesh, material = self._grid_material) + if self._disallowed_area_mesh: + renderer.queueNode(self, mesh = self._disallowed_area_mesh, material = self._material) return True def rebuild(self): @@ -94,3 +102,18 @@ class BuildVolume(SceneNode): for n in range(0, 6): v = self._grid_mesh.getVertex(n) self._grid_mesh.setVertexUVCoordinates(n, v[0], v[2]) + + if self._disallowed_areas: + mb = MeshBuilder() + for area in self._disallowed_areas: + mb.addQuad( + area[0], + area[1], + area[2], + area[3], + color = Color(0.8, 0.8, 0.8, 1.0) + ) + + self._disallowed_area_mesh = mb.getData() + else: + self._disallowed_area_mesh = None diff --git a/PrinterApplication.py b/PrinterApplication.py index a2f9560c2b..b835baa41b 100644 --- a/PrinterApplication.py +++ b/PrinterApplication.py @@ -45,6 +45,7 @@ class PrinterApplication(QtApplication): ]) self._physics = None self._volume = None + self._platform = None self.activeMachineChanged.connect(self._onActiveMachineChanged) def _loadPlugins(self): @@ -75,7 +76,7 @@ class PrinterApplication(QtApplication): self._physics = PlatformPhysics(controller) root = controller.getScene().getRoot() - platform = Platform(root) + self._platform = Platform(root) self._volume = BuildVolume(root) @@ -233,8 +234,28 @@ class PrinterApplication(QtApplication): self._volume.setWidth(machine.getSettingValueByKey('machine_width')) self._volume.setHeight(machine.getSettingValueByKey('machine_height')) self._volume.setDepth(machine.getSettingValueByKey('machine_depth')) + + disallowed_areas = machine.getSettingValueByKey('machine_disallowed_areas') + areas = [] + if disallowed_areas: + + for area in disallowed_areas: + polygon = [] + polygon.append(Vector(area[0][0], 0.1, area[0][1])) + polygon.append(Vector(area[1][0], 0.1, area[1][1])) + polygon.append(Vector(area[2][0], 0.1, area[2][1])) + polygon.append(Vector(area[3][0], 0.1, area[3][1])) + areas.append(polygon) + self._volume.setDisallowedAreas(areas) + self._volume.rebuild() + offset = machine.getSettingValueByKey('machine_platform_offset') + if offset: + self._platform.setPosition(Vector(offset[0], offset[1], offset[2])) + else: + self._platform.setPosition(Vector(0.0, 0.0, 0.0)) + removableDrivesChanged = pyqtSignal() @pyqtProperty("QStringList", notify = removableDrivesChanged)