Codestyle

This commit is contained in:
Jaime van Kessel 2016-07-29 17:28:58 +02:00
parent 4a5b2465ae
commit 03aa9cf8d3
2 changed files with 37 additions and 37 deletions

View file

@ -42,7 +42,8 @@ class CuraEngineBackend(Backend):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
# Find out where the engine is located, and how it is called. This depends on how Cura is packaged and which OS we are running on. # Find out where the engine is located, and how it is called.
# This depends on how Cura is packaged and which OS we are running on.
default_engine_location = os.path.join(Application.getInstallPrefix(), "bin", "CuraEngine") default_engine_location = os.path.join(Application.getInstallPrefix(), "bin", "CuraEngine")
if hasattr(sys, "frozen"): if hasattr(sys, "frozen"):
default_engine_location = os.path.join(os.path.dirname(os.path.abspath(sys.executable)), "CuraEngine") default_engine_location = os.path.join(os.path.dirname(os.path.abspath(sys.executable)), "CuraEngine")
@ -61,7 +62,7 @@ class CuraEngineBackend(Backend):
self._stored_layer_data = [] self._stored_layer_data = []
self._stored_optimized_layer_data = [] self._stored_optimized_layer_data = []
#Triggers for when to (re)start slicing: # Triggers for when to (re)start slicing:
self._global_container_stack = None self._global_container_stack = None
Application.getInstance().globalContainerStackChanged.connect(self._onGlobalStackChanged) Application.getInstance().globalContainerStackChanged.connect(self._onGlobalStackChanged)
self._onGlobalStackChanged() self._onGlobalStackChanged()
@ -70,15 +71,15 @@ class CuraEngineBackend(Backend):
cura.Settings.ExtruderManager.getInstance().activeExtruderChanged.connect(self._onActiveExtruderChanged) cura.Settings.ExtruderManager.getInstance().activeExtruderChanged.connect(self._onActiveExtruderChanged)
self._onActiveExtruderChanged() self._onActiveExtruderChanged()
#When you update a setting and other settings get changed through inheritance, many propertyChanged signals are fired. # When you update a setting and other settings get changed through inheritance, many propertyChanged signals are fired.
#This timer will group them up, and only slice for the last setting changed signal. # This timer will group them up, and only slice for the last setting changed signal.
#TODO: Properly group propertyChanged signals by whether they are triggered by the same user interaction. # TODO: Properly group propertyChanged signals by whether they are triggered by the same user interaction.
self._change_timer = QTimer() self._change_timer = QTimer()
self._change_timer.setInterval(500) self._change_timer.setInterval(500)
self._change_timer.setSingleShot(True) self._change_timer.setSingleShot(True)
self._change_timer.timeout.connect(self.slice) self._change_timer.timeout.connect(self.slice)
#Listeners for receiving messages from the back-end. # Listeners for receiving messages from the back-end.
self._message_handlers["cura.proto.Layer"] = self._onLayerMessage self._message_handlers["cura.proto.Layer"] = self._onLayerMessage
self._message_handlers["cura.proto.LayerOptimized"] = self._onOptimizedLayerMessage self._message_handlers["cura.proto.LayerOptimized"] = self._onOptimizedLayerMessage
self._message_handlers["cura.proto.Progress"] = self._onProgressMessage self._message_handlers["cura.proto.Progress"] = self._onProgressMessage
@ -88,19 +89,19 @@ class CuraEngineBackend(Backend):
self._message_handlers["cura.proto.SlicingFinished"] = self._onSlicingFinishedMessage self._message_handlers["cura.proto.SlicingFinished"] = self._onSlicingFinishedMessage
self._start_slice_job = None self._start_slice_job = None
self._slicing = False #Are we currently slicing? self._slicing = False # Are we currently slicing?
self._restart = False #Back-end is currently restarting? self._restart = False # Back-end is currently restarting?
self._enabled = True #Should we be slicing? Slicing might be paused when, for instance, the user is dragging the mesh around. self._enabled = True # Should we be slicing? Slicing might be paused when, for instance, the user is dragging the mesh around.
self._always_restart = True #Always restart the engine when starting a new slice. Don't keep the process running. TODO: Fix engine statelessness. self._always_restart = True # Always restart the engine when starting a new slice. Don't keep the process running. TODO: Fix engine statelessness.
self._process_layers_job = None #The currently active job to process layers, or None if it is not processing layers. self._process_layers_job = None # The currently active job to process layers, or None if it is not processing layers.
self._backend_log_max_lines = 20000 # Maximum number of lines to buffer self._backend_log_max_lines = 20000 # Maximum number of lines to buffer
self._error_message = None #Pop-up message that shows errors. self._error_message = None # Pop-up message that shows errors.
self.backendQuit.connect(self._onBackendQuit) self.backendQuit.connect(self._onBackendQuit)
self.backendConnected.connect(self._onBackendConnected) self.backendConnected.connect(self._onBackendConnected)
#When a tool operation is in progress, don't slice. So we need to listen for tool operations. # When a tool operation is in progress, don't slice. So we need to listen for tool operations.
Application.getInstance().getController().toolOperationStarted.connect(self._onToolOperationStarted) Application.getInstance().getController().toolOperationStarted.connect(self._onToolOperationStarted)
Application.getInstance().getController().toolOperationStopped.connect(self._onToolOperationStopped) Application.getInstance().getController().toolOperationStopped.connect(self._onToolOperationStopped)
@ -121,7 +122,8 @@ class CuraEngineBackend(Backend):
json_path = Resources.getPath(Resources.DefinitionContainers, "fdmprinter.def.json") json_path = Resources.getPath(Resources.DefinitionContainers, "fdmprinter.def.json")
return [Preferences.getInstance().getValue("backend/location"), "connect", "127.0.0.1:{0}".format(self._port), "-j", json_path, ""] return [Preferences.getInstance().getValue("backend/location"), "connect", "127.0.0.1:{0}".format(self._port), "-j", json_path, ""]
## Emitted when we get a message containing print duration and material amount. This also implies the slicing has finished. ## Emitted when we get a message containing print duration and material amount.
# This also implies the slicing has finished.
# \param time The amount of time the print will take. # \param time The amount of time the print will take.
# \param material_amount The amount of material the print will use. # \param material_amount The amount of material the print will use.
printDurationMessage = Signal() printDurationMessage = Signal()
@ -135,7 +137,7 @@ class CuraEngineBackend(Backend):
## Perform a slice of the scene. ## Perform a slice of the scene.
def slice(self): def slice(self):
self._slice_start_time = time() self._slice_start_time = time()
if not self._enabled or not self._global_container_stack: #We shouldn't be slicing. if not self._enabled or not self._global_container_stack: # We shouldn't be slicing.
# try again in a short time # try again in a short time
self._change_timer.start() self._change_timer.start()
return return
@ -145,10 +147,10 @@ class CuraEngineBackend(Backend):
self._stored_layer_data = [] self._stored_layer_data = []
self._stored_optimized_layer_data = [] self._stored_optimized_layer_data = []
if self._slicing: #We were already slicing. Stop the old job. if self._slicing: # We were already slicing. Stop the old job.
self._terminate() self._terminate()
if self._process_layers_job: #We were processing layers. Stop that, the layers are going to change soon. if self._process_layers_job: # We were processing layers. Stop that, the layers are going to change soon.
self._process_layers_job.abort() self._process_layers_job.abort()
self._process_layers_job = None self._process_layers_job = None
@ -267,7 +269,7 @@ class CuraEngineBackend(Backend):
# \param instance The setting instance that has changed. # \param instance The setting instance that has changed.
# \param property The property of the setting instance that has changed. # \param property The property of the setting instance that has changed.
def _onSettingChanged(self, instance, property): def _onSettingChanged(self, instance, property):
if property == "value": #Only reslice if the value has changed. if property == "value": # Only reslice if the value has changed.
self._onChanged() self._onChanged()
## Called when a sliced layer data message is received from the engine. ## Called when a sliced layer data message is received from the engine.
@ -318,7 +320,7 @@ class CuraEngineBackend(Backend):
## Called when a print time message is received from the engine. ## Called when a print time message is received from the engine.
# #
# \param message The protobuf message containing the print time and # \param message The protobuff message containing the print time and
# material amount per extruder # material amount per extruder
def _onPrintTimeMaterialEstimates(self, message): def _onPrintTimeMaterialEstimates(self, message):
material_amounts = [] material_amounts = []
@ -368,7 +370,7 @@ class CuraEngineBackend(Backend):
def _onActiveViewChanged(self): def _onActiveViewChanged(self):
if Application.getInstance().getController().getActiveView(): if Application.getInstance().getController().getActiveView():
view = Application.getInstance().getController().getActiveView() view = Application.getInstance().getController().getActiveView()
if view.getPluginId() == "LayerView": #If switching to layer view, we should process the layers if that hasn't been done yet. if view.getPluginId() == "LayerView": # If switching to layer view, we should process the layers if that hasn't been done yet.
self._layer_view_active = True self._layer_view_active = True
# There is data and we're not slicing at the moment # There is data and we're not slicing at the moment
# if we are slicing, there is no need to re-calculate the data as it will be invalid in a moment. # if we are slicing, there is no need to re-calculate the data as it will be invalid in a moment.
@ -401,7 +403,7 @@ class CuraEngineBackend(Backend):
self._global_container_stack = Application.getInstance().getGlobalContainerStack() self._global_container_stack = Application.getInstance().getGlobalContainerStack()
if self._global_container_stack: if self._global_container_stack:
self._global_container_stack.propertyChanged.connect(self._onSettingChanged) #Note: Only starts slicing when the value changed. self._global_container_stack.propertyChanged.connect(self._onSettingChanged) # Note: Only starts slicing when the value changed.
self._global_container_stack.containersChanged.connect(self._onChanged) self._global_container_stack.containersChanged.connect(self._onChanged)
extruders = list(ExtruderManager.getInstance().getMachineExtruders(self._global_container_stack.getId())) extruders = list(ExtruderManager.getInstance().getMachineExtruders(self._global_container_stack.getId()))
if extruders: if extruders:

View file

@ -73,7 +73,7 @@ class ProcessSlicedLayersJob(Job):
# instead simply offset all other layers so the lowest layer is always 0. # instead simply offset all other layers so the lowest layer is always 0.
min_layer_number = 0 min_layer_number = 0
for layer in self._layers: for layer in self._layers:
if(layer.id < min_layer_number): if layer.id < min_layer_number:
min_layer_number = layer.id min_layer_number = layer.id
current_layer = 0 current_layer = 0
@ -108,14 +108,13 @@ class ProcessSlicedLayersJob(Job):
# faster. # faster.
new_points = numpy.empty((len(points), 3), numpy.float32) new_points = numpy.empty((len(points), 3), numpy.float32)
if polygon.point_type == 0: # Point2D if polygon.point_type == 0: # Point2D
new_points[:,0] = points[:,0] new_points[:, 0] = points[:, 0]
new_points[:,1] = layer.height/1000 # layer height value is in backend representation new_points[:, 1] = layer.height / 1000 # layer height value is in backend representation
new_points[:,2] = -points[:,1] new_points[:, 2] = -points[:, 1]
else: # Point3D else: # Point3D
new_points[:,0] = points[:,0] new_points[:, 0] = points[:, 0]
new_points[:,1] = points[:,2] new_points[:, 1] = points[:, 2]
new_points[:,2] = -points[:,1] new_points[:, 2] = -points[:, 1]
this_poly = LayerPolygon.LayerPolygon(layer_data, extruder, line_types, new_points, line_widths) this_poly = LayerPolygon.LayerPolygon(layer_data, extruder, line_types, new_points, line_widths)
this_poly.buildCache() this_poly.buildCache()
@ -184,4 +183,3 @@ class ProcessSlicedLayersJob(Job):
else: else:
if self._progress: if self._progress:
self._progress.hide() self._progress.hide()