Fix coding style issues

This commit is contained in:
Arjen Hiemstra 2015-11-27 13:57:53 +01:00
parent 743b403b29
commit 9267b517d6
12 changed files with 68 additions and 60 deletions

View File

@ -83,38 +83,38 @@ class BuildVolume(SceneNode):
if self._width == 0 or self._height == 0 or self._depth == 0: if self._width == 0 or self._height == 0 or self._depth == 0:
return return
minW = -self._width / 2 min_w = -self._width / 2
maxW = self._width / 2 max_w = self._width / 2
minH = 0.0 min_h = 0.0
maxH = self._height max_h = self._height
minD = -self._depth / 2 min_d = -self._depth / 2
maxD = self._depth / 2 max_d = self._depth / 2
mb = MeshBuilder() mb = MeshBuilder()
mb.addLine(Vector(minW, minH, minD), Vector(maxW, minH, minD), color = self.VolumeOutlineColor) mb.addLine(Vector(min_w, min_h, min_d), Vector(max_w, min_h, min_d), color = self.VolumeOutlineColor)
mb.addLine(Vector(minW, minH, minD), Vector(minW, maxH, minD), 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(minW, maxH, minD), Vector(maxW, maxH, minD), 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(maxW, minH, minD), Vector(maxW, maxH, minD), 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(minW, minH, maxD), Vector(maxW, minH, maxD), color = self.VolumeOutlineColor) mb.addLine(Vector(min_w, min_h, max_d), Vector(max_w, min_h, max_d), color = self.VolumeOutlineColor)
mb.addLine(Vector(minW, minH, maxD), Vector(minW, maxH, maxD), 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(minW, maxH, maxD), Vector(maxW, maxH, maxD), 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(maxW, minH, maxD), Vector(maxW, maxH, maxD), 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(minW, minH, minD), Vector(minW, minH, maxD), color = self.VolumeOutlineColor) mb.addLine(Vector(min_w, min_h, min_d), Vector(min_w, min_h, max_d), color = self.VolumeOutlineColor)
mb.addLine(Vector(maxW, minH, minD), Vector(maxW, minH, maxD), 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(minW, maxH, minD), Vector(minW, maxH, maxD), 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(maxW, maxH, minD), Vector(maxW, maxH, maxD), color = self.VolumeOutlineColor) mb.addLine(Vector(max_w, max_h, min_d), Vector(max_w, max_h, max_d), color = self.VolumeOutlineColor)
self.setMeshData(mb.getData()) self.setMeshData(mb.getData())
mb = MeshBuilder() mb = MeshBuilder()
mb.addQuad( mb.addQuad(
Vector(minW, minH, minD), Vector(min_w, min_h, min_d),
Vector(maxW, minH, minD), Vector(max_w, min_h, min_d),
Vector(maxW, minH, maxD), Vector(max_w, min_h, max_d),
Vector(minW, minH, maxD) Vector(min_w, min_h, max_d)
) )
self._grid_mesh = mb.getData() self._grid_mesh = mb.getData()
for n in range(0, 6): for n in range(0, 6):
@ -128,10 +128,10 @@ class BuildVolume(SceneNode):
color = Color(0.0, 0.0, 0.0, 0.15) color = Color(0.0, 0.0, 0.0, 0.15)
for polygon in self._disallowed_areas: for polygon in self._disallowed_areas:
points = polygon.getPoints() points = polygon.getPoints()
first = Vector(self._clamp(points[0][0], minW, maxW), disallowed_area_height, self._clamp(points[0][1], minD, maxD)) first = Vector(self._clamp(points[0][0], min_w, max_w), disallowed_area_height, self._clamp(points[0][1], min_d, max_d))
previous_point = Vector(self._clamp(points[0][0], minW, maxW), disallowed_area_height, self._clamp(points[0][1], minD, maxD)) previous_point = Vector(self._clamp(points[0][0], min_w, max_w), disallowed_area_height, self._clamp(points[0][1], min_d, max_d))
for point in points: for point in points:
new_point = Vector(self._clamp(point[0], minW, maxW), disallowed_area_height, self._clamp(point[1], minD, maxD)) new_point = Vector(self._clamp(point[0], min_w, max_w), disallowed_area_height, self._clamp(point[1], min_d, max_d))
mb.addFace(first, previous_point, new_point, color = color) mb.addFace(first, previous_point, new_point, color = color)
previous_point = new_point previous_point = new_point
@ -143,7 +143,7 @@ class BuildVolume(SceneNode):
else: else:
self._disallowed_area_mesh = None self._disallowed_area_mesh = None
self._aabb = AxisAlignedBox(minimum = Vector(minW, minH - 1.0, minD), maximum = Vector(maxW, maxH, maxD)) self._aabb = AxisAlignedBox(minimum = Vector(min_w, min_h - 1.0, min_d), maximum = Vector(max_w, max_h, max_d))
skirt_size = 0.0 skirt_size = 0.0
@ -152,8 +152,8 @@ class BuildVolume(SceneNode):
skirt_size = self._getSkirtSize(profile) skirt_size = self._getSkirtSize(profile)
scale_to_max_bounds = AxisAlignedBox( scale_to_max_bounds = AxisAlignedBox(
minimum = Vector(minW + skirt_size, minH, minD + skirt_size + disallowed_area_size), minimum = Vector(min_w + skirt_size, min_h, min_d + skirt_size + disallowed_area_size),
maximum = Vector(maxW - skirt_size, maxH, maxD - skirt_size - disallowed_area_size) maximum = Vector(max_w - skirt_size, max_h, max_d - skirt_size - disallowed_area_size)
) )
Application.getInstance().getController().getScene()._maximum_bounds = scale_to_max_bounds Application.getInstance().getController().getScene()._maximum_bounds = scale_to_max_bounds

View File

@ -29,7 +29,7 @@ class ConvexHullNode(SceneNode):
self._node.parentChanged.connect(self._onNodeParentChanged) self._node.parentChanged.connect(self._onNodeParentChanged)
self._node.decoratorsChanged.connect(self._onNodeDecoratorsChanged) self._node.decoratorsChanged.connect(self._onNodeDecoratorsChanged)
self._onNodeDecoratorsChanged(self._node) self._onNodeDecoratorsChanged(self._node)
self.convexHullHeadMesh = None self._convex_hull_head_mesh = None
self._hull = hull self._hull = hull
hull_points = self._hull.getPoints() hull_points = self._hull.getPoints()
@ -38,7 +38,7 @@ class ConvexHullNode(SceneNode):
self.setMeshData(hull_mesh) self.setMeshData(hull_mesh)
convex_hull_head = self._node.callDecoration("getConvexHullHead") convex_hull_head = self._node.callDecoration("getConvexHullHead")
if convex_hull_head: if convex_hull_head:
self.convexHullHeadMesh = self.createHullMesh(convex_hull_head.getPoints()) self._convex_hull_head_mesh = self.createHullMesh(convex_hull_head.getPoints())
def createHullMesh(self, hull_points): def createHullMesh(self, hull_points):
mesh = MeshData() mesh = MeshData()
@ -68,8 +68,8 @@ class ConvexHullNode(SceneNode):
if self.getParent(): if self.getParent():
self._material.setUniformValue("u_color", self._color) self._material.setUniformValue("u_color", self._color)
renderer.queueNode(self, material = self._material, transparent = True) renderer.queueNode(self, material = self._material, transparent = True)
if self.convexHullHeadMesh: if self._convex_hull_head_mesh:
renderer.queueNode(self, material = self._material,transparent = True, mesh = self.convexHullHeadMesh) renderer.queueNode(self, material = self._material,transparent = True, mesh = self._convex_hull_head_mesh)
return True return True

View File

@ -3,11 +3,6 @@
import platform import platform
if platform.system() == "Linux": # Needed for platform.linux_distribution, which is not available on Windows and OSX
# For Ubuntu: https://bugs.launchpad.net/ubuntu/+source/python-qt4/+bug/941826
if platform.linux_distribution()[0] in ("Ubuntu", ): # Just in case it also happens on Debian, so it can be added
from OpenGL import GL
from UM.Qt.QtApplication import QtApplication from UM.Qt.QtApplication import QtApplication
from UM.Scene.SceneNode import SceneNode from UM.Scene.SceneNode import SceneNode
from UM.Scene.Camera import Camera from UM.Scene.Camera import Camera
@ -59,10 +54,15 @@ import numpy
import copy import copy
numpy.seterr(all="ignore") numpy.seterr(all="ignore")
if platform.system() == "Linux": # Needed for platform.linux_distribution, which is not available on Windows and OSX
# For Ubuntu: https://bugs.launchpad.net/ubuntu/+source/python-qt4/+bug/941826
if platform.linux_distribution()[0] in ("Ubuntu", ): # Just in case it also happens on Debian, so it can be added
from OpenGL import GL
try: try:
from cura.CuraVersion import CuraVersion from cura.CuraVersion import CuraVersion
except ImportError: except ImportError:
CuraVersion = "master" CuraVersion = "master" # [CodeStyle: Reflecting imported value]
class CuraApplication(QtApplication): class CuraApplication(QtApplication):
class ResourceTypes: class ResourceTypes:
@ -263,6 +263,7 @@ class CuraApplication(QtApplication):
self.jobNameChanged.emit() self.jobNameChanged.emit()
jobNameChanged = pyqtSignal() jobNameChanged = pyqtSignal()
@pyqtProperty(str, notify = jobNameChanged) @pyqtProperty(str, notify = jobNameChanged)
def jobName(self): def jobName(self):
return self._job_name return self._job_name
@ -427,6 +428,7 @@ class CuraApplication(QtApplication):
return log return log
recentFilesChanged = pyqtSignal() recentFilesChanged = pyqtSignal()
@pyqtProperty("QVariantList", notify = recentFilesChanged) @pyqtProperty("QVariantList", notify = recentFilesChanged)
def recentFiles(self): def recentFiles(self):
return self._recent_files return self._recent_files
@ -441,6 +443,7 @@ class CuraApplication(QtApplication):
self.expandedCategoriesChanged.emit() self.expandedCategoriesChanged.emit()
expandedCategoriesChanged = pyqtSignal() expandedCategoriesChanged = pyqtSignal()
@pyqtProperty("QStringList", notify = expandedCategoriesChanged) @pyqtProperty("QStringList", notify = expandedCategoriesChanged)
def expandedCategories(self): def expandedCategories(self):
return Preferences.getInstance().getValue("cura/categories_expanded").split(";") return Preferences.getInstance().getValue("cura/categories_expanded").split(";")

View File

@ -45,7 +45,7 @@ class OneAtATimeIterator(Iterator.Iterator):
# This does not decrease the worst case running time, but should improve it in most cases. # This does not decrease the worst case running time, but should improve it in most cases.
sorted(node_list, key = cmp_to_key(self._calculateScore)) sorted(node_list, key = cmp_to_key(self._calculateScore))
todo_node_list = [_objectOrder([], node_list)] todo_node_list = [_ObjectOrder([], node_list)]
while len(todo_node_list) > 0: while len(todo_node_list) > 0:
current = todo_node_list.pop() current = todo_node_list.pop()
for node in current.todo: for node in current.todo:
@ -61,7 +61,7 @@ class OneAtATimeIterator(Iterator.Iterator):
self._node_stack = new_order self._node_stack = new_order
return return
todo_node_list.append(_objectOrder(new_order, new_todo_list)) todo_node_list.append(_ObjectOrder(new_order, new_todo_list))
self._node_stack = [] #No result found! self._node_stack = [] #No result found!
@ -99,7 +99,7 @@ class OneAtATimeIterator(Iterator.Iterator):
## Internal object used to keep track of a possible order in which to print objects. ## Internal object used to keep track of a possible order in which to print objects.
class _objectOrder(): class _ObjectOrder():
def __init__(self, order, todo): def __init__(self, order, todo):
""" """
:param order: List of indexes in which to print objects, ordered by printing order. :param order: List of indexes in which to print objects, ordered by printing order.

View File

@ -19,7 +19,8 @@ except ImportError:
else: else:
os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "cpp" os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "cpp"
import cura.CuraApplication if True: # To make the code style checker stop complaining
import cura.CuraApplication
if sys.platform == "win32" and hasattr(sys, "frozen"): if sys.platform == "win32" and hasattr(sys, "frozen"):
import os import os

View File

@ -109,10 +109,10 @@ class ThreeMFReader(MeshReader):
node.setOrientation(temp_quaternion) node.setOrientation(temp_quaternion)
# Magical scale extraction # Magical scale extraction
S2 = temp_mat.getTransposed().multiply(temp_mat) scale = temp_mat.getTransposed().multiply(temp_mat)
scale_x = math.sqrt(S2.at(0,0)) scale_x = math.sqrt(scale.at(0,0))
scale_y = math.sqrt(S2.at(1,1)) scale_y = math.sqrt(scale.at(1,1))
scale_z = math.sqrt(S2.at(2,2)) scale_z = math.sqrt(scale.at(2,2))
node.setScale(Vector(scale_x,scale_y,scale_z)) node.setScale(Vector(scale_x,scale_y,scale_z))
# We use a different coordinate frame, so rotate. # We use a different coordinate frame, so rotate.

View File

@ -1,9 +1,9 @@
# Copyright (c) 2015 Ultimaker B.V. # Copyright (c) 2015 Ultimaker B.V.
# Cura is released under the terms of the AGPLv3 or higher. # Cura is released under the terms of the AGPLv3 or higher.
from UM.i18n import i18nCatalog
from . import ThreeMFReader from . import ThreeMFReader
from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura") catalog = i18nCatalog("cura")
def getMetaData(): def getMetaData():

View File

@ -32,7 +32,7 @@ class ProcessSlicedObjectListJob(Job):
Application.getInstance().getController().activeViewChanged.connect(self._onActiveViewChanged) Application.getInstance().getController().activeViewChanged.connect(self._onActiveViewChanged)
objectIdMap = {} object_id_map = {}
new_node = SceneNode() new_node = SceneNode()
## Put all nodes in a dict identified by ID ## Put all nodes in a dict identified by ID
for node in DepthFirstIterator(self._scene.getRoot()): for node in DepthFirstIterator(self._scene.getRoot()):
@ -40,11 +40,10 @@ class ProcessSlicedObjectListJob(Job):
if node.callDecoration("getLayerData"): if node.callDecoration("getLayerData"):
self._scene.getRoot().removeChild(node) self._scene.getRoot().removeChild(node)
else: else:
objectIdMap[id(node)] = node object_id_map[id(node)] = node
Job.yieldThread() Job.yieldThread()
settings = Application.getInstance().getMachineManager().getActiveProfile() settings = Application.getInstance().getMachineManager().getActiveProfile()
layerHeight = settings.getSettingValue("layer_height")
center = None center = None
if not settings.getSettingValue("machine_center_is_zero"): if not settings.getSettingValue("machine_center_is_zero"):
@ -62,7 +61,7 @@ class ProcessSlicedObjectListJob(Job):
current_layer = 0 current_layer = 0
for object in self._message.objects: for object in self._message.objects:
try: try:
node = objectIdMap[object.id] node = object_id_map[object.id]
except KeyError: except KeyError:
continue continue

View File

@ -115,12 +115,17 @@ class StartSliceJob(Job):
return str(value).encode("utf-8") return str(value).encode("utf-8")
def _sendSettings(self, profile): def _sendSettings(self, profile):
Application.getInstance().getMachineManager().getActiveMachineInstance().setMachineSettingValue("machine_gcode_flavor", "RepRap")
msg = Cura_pb2.SettingList() msg = Cura_pb2.SettingList()
settings = profile.getAllSettingValues(include_machine = True) settings = profile.getAllSettingValues(include_machine = True)
start_gcode = settings["machine_start_gcode"] start_gcode = settings["machine_start_gcode"]
settings["material_bed_temp_prepend"] = "{material_bed_temperature}" not in start_gcode settings["material_bed_temp_prepend"] = "{material_bed_temperature}" not in start_gcode
settings["material_print_temp_prepend"] = "{material_print_temperature}" not in start_gcode settings["material_print_temp_prepend"] = "{material_print_temperature}" not in start_gcode
for key, value in settings.items(): for key, value in settings.items():
if key == "machine_gcode_flavor":
print("machine_gcode_flavor", value)
s = msg.settings.add() s = msg.settings.add()
s.name = key s.name = key
if key == "machine_start_gcode" or key == "machine_end_gcode": if key == "machine_start_gcode" or key == "machine_end_gcode":

View File

@ -1,9 +1,9 @@
# Copyright (c) 2015 Ultimaker B.V. # Copyright (c) 2015 Ultimaker B.V.
# Cura is released under the terms of the AGPLv3 or higher. # Cura is released under the terms of the AGPLv3 or higher.
from UM.i18n import i18nCatalog
from . import GCodeReader from . import GCodeReader
from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura") catalog = i18nCatalog("cura")
def getMetaData(): def getMetaData():

View File

@ -20,17 +20,17 @@ catalog = i18nCatalog("cura")
# WinAPI Constants that we need # WinAPI Constants that we need
# Hardcoded here due to stupid WinDLL stuff that does not give us access to these values. # Hardcoded here due to stupid WinDLL stuff that does not give us access to these values.
DRIVE_REMOVABLE = 2 DRIVE_REMOVABLE = 2 # [CodeStyle: Windows Enum value]
GENERIC_READ = 2147483648 GENERIC_READ = 2147483648 # [CodeStyle: Windows Enum value]
GENERIC_WRITE = 1073741824 GENERIC_WRITE = 1073741824 # [CodeStyle: Windows Enum value]
FILE_SHARE_READ = 1 FILE_SHARE_READ = 1 # [CodeStyle: Windows Enum value]
FILE_SHARE_WRITE = 2 FILE_SHARE_WRITE = 2 # [CodeStyle: Windows Enum value]
IOCTL_STORAGE_EJECT_MEDIA = 2967560 IOCTL_STORAGE_EJECT_MEDIA = 2967560 # [CodeStyle: Windows Enum value]
OPEN_EXISTING = 3 OPEN_EXISTING = 3 # [CodeStyle: Windows Enum value]
## Removable drive support for windows ## Removable drive support for windows
class WindowsRemovableDrivePlugin(RemovableDrivePlugin.RemovableDrivePlugin): class WindowsRemovableDrivePlugin(RemovableDrivePlugin.RemovableDrivePlugin):