Skip to content

Commit

Permalink
Merge branch 'master' into python_type_hinting
Browse files Browse the repository at this point in the history
  • Loading branch information
sedwards2009 committed Jan 27, 2017
2 parents d5c96c1 + 35cbedc commit eb43806
Show file tree
Hide file tree
Showing 51 changed files with 9,423 additions and 217 deletions.
76 changes: 51 additions & 25 deletions cura/BuildVolume.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,18 @@

## Build volume is a special kind of node that is responsible for rendering the printable area & disallowed areas.
class BuildVolume(SceneNode):
VolumeOutlineColor = Color(12, 169, 227, 255)
XAxisColor = Color(255, 0, 0, 255)
YAxisColor = Color(0, 0, 255, 255)
ZAxisColor = Color(0, 255, 0, 255)

raftThicknessChanged = Signal()

def __init__(self, parent = None):
super().__init__(parent)

self._volume_outline_color = None
self._x_axis_color = None
self._y_axis_color = None
self._z_axis_color = None
self._disallowed_area_color = None
self._error_area_color = None

self._width = 0
self._height = 0
self._depth = 0
Expand Down Expand Up @@ -73,6 +75,9 @@ def __init__(self, parent = None):
Application.getInstance().globalContainerStackChanged.connect(self._onStackChanged)
self._onStackChanged()

self._engine_ready = False
Application.getInstance().engineCreatedSignal.connect(self._onEngineCreated)

self._has_errors = False
Application.getInstance().getController().getScene().sceneChanged.connect(self._onSceneChanged)

Expand All @@ -97,6 +102,7 @@ def __init__(self, parent = None):
# but it does not update the disallowed areas after material change
Application.getInstance().getMachineManager().activeStackChanged.connect(self._onStackChanged)


def _onSceneChanged(self, source):
if self._global_container_stack:
self._change_timer.start()
Expand Down Expand Up @@ -156,6 +162,9 @@ def render(self, renderer):
if not self._shader:
self._shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "default.shader"))
self._grid_shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "grid.shader"))
theme = Application.getInstance().getTheme()
self._grid_shader.setUniformValue("u_gridColor0", Color(*theme.getColor("buildplate").getRgb()))
self._grid_shader.setUniformValue("u_gridColor1", Color(*theme.getColor("buildplate_alt").getRgb()))

renderer.queueNode(self, mode = RenderBatch.RenderMode.Lines)
renderer.queueNode(self, mesh = self._origin_mesh)
Expand All @@ -174,6 +183,18 @@ def rebuild(self):
if not self._width or not self._height or not self._depth:
return

if not Application.getInstance()._engine:
return

if not self._volume_outline_color:
theme = Application.getInstance().getTheme()
self._volume_outline_color = Color(*theme.getColor("volume_outline").getRgb())
self._x_axis_color = Color(*theme.getColor("x_axis").getRgb())
self._y_axis_color = Color(*theme.getColor("y_axis").getRgb())
self._z_axis_color = Color(*theme.getColor("z_axis").getRgb())
self._disallowed_area_color = Color(*theme.getColor("disallowed_area").getRgb())
self._error_area_color = Color(*theme.getColor("error_area").getRgb())

min_w = -self._width / 2
max_w = self._width / 2
min_h = 0.0
Expand All @@ -186,20 +207,20 @@ def rebuild(self):
if self._shape != "elliptic":
# Outline 'cube' of the build volume
mb = MeshBuilder()
mb.addLine(Vector(min_w, min_h, min_d), Vector(max_w, min_h, min_d), color = self.VolumeOutlineColor)
mb.addLine(Vector(min_w, min_h, min_d), Vector(min_w, max_h, min_d), color = self.VolumeOutlineColor)
mb.addLine(Vector(min_w, max_h, min_d), Vector(max_w, max_h, min_d), color = self.VolumeOutlineColor)
mb.addLine(Vector(max_w, min_h, min_d), Vector(max_w, max_h, min_d), color = self.VolumeOutlineColor)
mb.addLine(Vector(min_w, min_h, min_d), Vector(max_w, min_h, min_d), color = self._volume_outline_color)
mb.addLine(Vector(min_w, min_h, min_d), Vector(min_w, max_h, min_d), color = self._volume_outline_color)
mb.addLine(Vector(min_w, max_h, min_d), Vector(max_w, max_h, min_d), color = self._volume_outline_color)
mb.addLine(Vector(max_w, min_h, min_d), Vector(max_w, max_h, min_d), color = self._volume_outline_color)

mb.addLine(Vector(min_w, min_h, max_d), Vector(max_w, min_h, max_d), color = self.VolumeOutlineColor)
mb.addLine(Vector(min_w, min_h, max_d), Vector(min_w, max_h, max_d), color = self.VolumeOutlineColor)
mb.addLine(Vector(min_w, max_h, max_d), Vector(max_w, max_h, max_d), color = self.VolumeOutlineColor)
mb.addLine(Vector(max_w, min_h, max_d), Vector(max_w, max_h, max_d), color = self.VolumeOutlineColor)
mb.addLine(Vector(min_w, min_h, max_d), Vector(max_w, min_h, max_d), color = self._volume_outline_color)
mb.addLine(Vector(min_w, min_h, max_d), Vector(min_w, max_h, max_d), color = self._volume_outline_color)
mb.addLine(Vector(min_w, max_h, max_d), Vector(max_w, max_h, max_d), color = self._volume_outline_color)
mb.addLine(Vector(max_w, min_h, max_d), Vector(max_w, max_h, max_d), color = self._volume_outline_color)

mb.addLine(Vector(min_w, min_h, min_d), Vector(min_w, min_h, max_d), color = self.VolumeOutlineColor)
mb.addLine(Vector(max_w, min_h, min_d), Vector(max_w, min_h, max_d), color = self.VolumeOutlineColor)
mb.addLine(Vector(min_w, max_h, min_d), Vector(min_w, max_h, max_d), color = self.VolumeOutlineColor)
mb.addLine(Vector(max_w, max_h, min_d), Vector(max_w, max_h, max_d), color = self.VolumeOutlineColor)
mb.addLine(Vector(min_w, min_h, min_d), Vector(min_w, min_h, max_d), color = self._volume_outline_color)
mb.addLine(Vector(max_w, min_h, min_d), Vector(max_w, min_h, max_d), color = self._volume_outline_color)
mb.addLine(Vector(min_w, max_h, min_d), Vector(min_w, max_h, max_d), color = self._volume_outline_color)
mb.addLine(Vector(max_w, max_h, min_d), Vector(max_w, max_h, max_d), color = self._volume_outline_color)

self.setMeshData(mb.build())

Expand All @@ -226,8 +247,8 @@ def rebuild(self):
aspect = self._depth / self._width
scale_matrix.compose(scale = Vector(1, 1, aspect))
mb = MeshBuilder()
mb.addArc(max_w, Vector.Unit_Y, center = (0, min_h - z_fight_distance, 0), color = self.VolumeOutlineColor)
mb.addArc(max_w, Vector.Unit_Y, center = (0, max_h, 0), color = self.VolumeOutlineColor)
mb.addArc(max_w, Vector.Unit_Y, center = (0, min_h - z_fight_distance, 0), color = self._volume_outline_color)
mb.addArc(max_w, Vector.Unit_Y, center = (0, max_h, 0), color = self._volume_outline_color)
self.setMeshData(mb.build().getTransformed(scale_matrix))

# Build plate grid mesh
Expand Down Expand Up @@ -258,29 +279,29 @@ def rebuild(self):
height = self._origin_line_width,
depth = self._origin_line_width,
center = origin + Vector(self._origin_line_length / 2, 0, 0),
color = self.XAxisColor
color = self._x_axis_color
)
mb.addCube(
width = self._origin_line_width,
height = self._origin_line_length,
depth = self._origin_line_width,
center = origin + Vector(0, self._origin_line_length / 2, 0),
color = self.YAxisColor
color = self._y_axis_color
)
mb.addCube(
width = self._origin_line_width,
height = self._origin_line_width,
depth = self._origin_line_length,
center = origin - Vector(0, 0, self._origin_line_length / 2),
color = self.ZAxisColor
color = self._z_axis_color
)
self._origin_mesh = mb.build()

disallowed_area_height = 0.1
disallowed_area_size = 0
if self._disallowed_areas:
mb = MeshBuilder()
color = Color(0.0, 0.0, 0.0, 0.15)
color = self._disallowed_area_color
for polygon in self._disallowed_areas:
points = polygon.getPoints()
if len(points) == 0:
Expand Down Expand Up @@ -309,7 +330,7 @@ def rebuild(self):
if self._error_areas:
mb = MeshBuilder()
for error_area in self._error_areas:
color = Color(1.0, 0.0, 0.0, 0.5)
color = self._error_area_color
points = error_area.getPoints()
first = Vector(self._clamp(points[0][0], min_w, max_w), disallowed_area_height,
self._clamp(points[0][1], min_d, max_d))
Expand Down Expand Up @@ -396,7 +417,12 @@ def _onStackChanged(self):
self._updateDisallowedAreas()
self._updateRaftThickness()

self.rebuild()
if self._engine_ready:
self.rebuild()

def _onEngineCreated(self):
self._engine_ready = True
self.rebuild()

def _onSettingPropertyChanged(self, setting_key, property_name):
if property_name != "value":
Expand Down
5 changes: 3 additions & 2 deletions cura/ConvexHullNode.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (c) 2015 Ultimaker B.V.
# Cura is released under the terms of the AGPLv3 or higher.

from UM.Application import Application
from UM.Scene.SceneNode import SceneNode
from UM.Resources import Resources
from UM.Math.Color import Color
Expand All @@ -23,7 +24,7 @@ def __init__(self, node, hull, thickness, parent = None):
self._original_parent = parent

# Color of the drawn convex hull
self._color = Color(0.4, 0.4, 0.4, 1.0)
self._color = None

# The y-coordinate of the convex hull mesh. Must not be 0, to prevent z-fighting.
self._mesh_height = 0.1
Expand Down Expand Up @@ -72,7 +73,7 @@ def render(self, renderer):
return True

def _onNodeDecoratorsChanged(self, node):
self._color = Color(35, 35, 35, 0.5)
self._color = Color(*Application.getInstance().getTheme().getColor("convex_hull").getRgb())

convex_hull_head = self._node.callDecoration("getConvexHullHead")
if convex_hull_head:
Expand Down
11 changes: 10 additions & 1 deletion cura/CuraApplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,14 @@ def __init__(self):
Preferences.getInstance().addPreference("cura/categories_expanded", "")
Preferences.getInstance().addPreference("cura/jobname_prefix", True)
Preferences.getInstance().addPreference("view/center_on_select", False)
Preferences.getInstance().addPreference("mesh/scale_to_fit", True)
Preferences.getInstance().addPreference("mesh/scale_to_fit", False)
Preferences.getInstance().addPreference("mesh/scale_tiny_meshes", True)
Preferences.getInstance().addPreference("cura/dialog_on_project_save", True)
Preferences.getInstance().addPreference("cura/asked_dialog_on_project_save", False)

Preferences.getInstance().addPreference("cura/currency", "€")
Preferences.getInstance().addPreference("cura/material_settings", "{}")

for key in [
"dialog_load_path", # dialog_save_path is in LocalFileOutputDevicePlugin
"dialog_profile_path",
Expand Down Expand Up @@ -330,6 +334,11 @@ def messageBoxClosed(self, button):

showPrintMonitor = pyqtSignal(bool, arguments = ["show"])

def setViewLegendItems(self, items):
self.viewLegendItemsChanged.emit(items)

viewLegendItemsChanged = pyqtSignal("QVariantList", arguments = ["items"])

## Cura has multiple locations where instance containers need to be saved, so we need to handle this differently.
#
# Note that the AutoSave plugin also calls this method.
Expand Down
39 changes: 24 additions & 15 deletions cura/LayerPolygon.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from UM.Math.Color import Color
from UM.Application import Application

import numpy

Expand Down Expand Up @@ -37,7 +38,7 @@ def __init__(self, mesh, extruder, line_types, data, line_widths):

# Buffering the colors shouldn't be necessary as it is not
# re-used and can save alot of memory usage.
self._color_map = self.__color_map * [1, 1, 1, self._extruder] # The alpha component is used to store the extruder nr
self._color_map = LayerPolygon.getColorMap() * [1, 1, 1, self._extruder] # The alpha component is used to store the extruder nr
self._colors = self._color_map[self._types]

# When type is used as index returns true if type == LayerPolygon.InfillType or type == LayerPolygon.SkinType or type == LayerPolygon.SupportInfillType
Expand Down Expand Up @@ -172,17 +173,25 @@ def getNormals(self):

return normals

# Should be generated in better way, not hardcoded.
__color_map = numpy.array([
[1.0, 1.0, 1.0, 1.0], # NoneType
[1.0, 0.0, 0.0, 1.0], # Inset0Type
[0.0, 1.0, 0.0, 1.0], # InsetXType
[1.0, 1.0, 0.0, 1.0], # SkinType
[0.0, 1.0, 1.0, 1.0], # SupportType
[0.0, 1.0, 1.0, 1.0], # SkirtType
[1.0, 0.75, 0.0, 1.0], # InfillType
[0.0, 1.0, 1.0, 1.0], # SupportInfillType
[0.0, 0.0, 1.0, 1.0], # MoveCombingType
[0.5, 0.5, 1.0, 1.0], # MoveRetractionType
[0.25, 0.75, 1.0, 1.0] # SupportInterfaceType
])
__color_map = None

## Gets the instance of the VersionUpgradeManager, or creates one.
@classmethod
def getColorMap(cls):
if cls.__color_map is None:
theme = Application.getInstance().getTheme()
cls.__color_map = numpy.array([
theme.getColor("layerview_none").getRgbF(), # NoneType
theme.getColor("layerview_inset_0").getRgbF(), # Inset0Type
theme.getColor("layerview_inset_x").getRgbF(), # InsetXType
theme.getColor("layerview_skin").getRgbF(), # SkinType
theme.getColor("layerview_support").getRgbF(), # SupportType
theme.getColor("layerview_skirt").getRgbF(), # SkirtType
theme.getColor("layerview_infill").getRgbF(), # InfillType
theme.getColor("layerview_support_infill").getRgbF(), # SupportInfillType
theme.getColor("layerview_move_combing").getRgbF(), # MoveCombingType
theme.getColor("layerview_move_retraction").getRgbF(), # MoveRetractionType
theme.getColor("layerview_support_interface").getRgbF() # SupportInterfaceType
])

return cls.__color_map
Loading

0 comments on commit eb43806

Please sign in to comment.