Merge branch 'master' into simple_convex_hull

Conflicts:
	cura/BuildVolume.py
	cura/ConvexHullDecorator.py
	cura/ConvexHullJob.py
	cura/CuraApplication.py
This commit is contained in:
Simon Edwards 2016-06-21 14:47:10 +02:00
commit fd42a43270
215 changed files with 35977 additions and 5826 deletions

View file

@ -13,7 +13,7 @@ def getMetaData():
"author": "Ultimaker",
"version": "1.0",
"description": catalog.i18nc("@info:whatsthis", "Provides support for reading 3MF files."),
"api": 2
"api": 3
},
"mesh_reader": [
{

View file

@ -15,15 +15,9 @@ class AutoSave(Extension):
Preferences.getInstance().preferenceChanged.connect(self._triggerTimer)
machine_manager = Application.getInstance().getMachineManager()
self._profile = None
machine_manager.activeProfileChanged.connect(self._onActiveProfileChanged)
machine_manager.profileNameChanged.connect(self._triggerTimer)
machine_manager.profilesChanged.connect(self._triggerTimer)
machine_manager.machineInstanceNameChanged.connect(self._triggerTimer)
machine_manager.machineInstancesChanged.connect(self._triggerTimer)
self._onActiveProfileChanged()
self._global_stack = None
Application.getInstance().globalContainerStackChanged.connect(self._onGlobalStackChanged)
self._onGlobalStackChanged()
Preferences.getInstance().addPreference("cura/autosave_delay", 1000 * 10)
@ -38,24 +32,23 @@ class AutoSave(Extension):
if not self._saving:
self._change_timer.start()
def _onActiveProfileChanged(self):
if self._profile:
self._profile.settingValueChanged.disconnect(self._triggerTimer)
def _onGlobalStackChanged(self):
if self._global_stack:
self._global_stack.propertyChanged.disconnect(self._triggerTimer)
self._global_stack.containersChanged.disconnect(self._triggerTimer)
self._profile = Application.getInstance().getMachineManager().getWorkingProfile()
self._global_stack = Application.getInstance().getGlobalContainerStack()
if self._profile:
self._profile.settingValueChanged.connect(self._triggerTimer)
if self._global_stack:
self._global_stack.propertyChanged.connect(self._triggerTimer)
self._global_stack.containersChanged.connect(self._triggerTimer)
def _onTimeout(self):
self._saving = True # To prevent the save process from triggering another autosave.
Logger.log("d", "Autosaving preferences, instances and profiles")
machine_manager = Application.getInstance().getMachineManager()
Application.getInstance().saveSettings()
machine_manager.saveVisibility()
machine_manager.saveMachineInstances()
machine_manager.saveProfiles()
Preferences.getInstance().writeToFile(Resources.getStoragePath(Resources.Preferences, Application.getInstance().getApplicationName() + ".cfg"))
self._saving = False

View file

@ -13,7 +13,7 @@ def getMetaData():
"author": "Ultimaker",
"version": "1.0",
"description": catalog.i18nc("@info:whatsthis", "Automatically saves Preferences, Machines and Profiles after changes."),
"api": 2
"api": 3
},
}

View file

@ -48,7 +48,8 @@ class ChangeLog(Extension, QObject,):
result += "<h1>" + str(version) + "</h1><br>"
result += ""
for change in logs[version]:
result += "<b>" + str(change) + "</b><br>"
if str(change) != "":
result += "<b>" + str(change) + "</b><br>"
for line in logs[version][change]:
result += str(line) + "<br>"
result += "<br>"
@ -60,20 +61,21 @@ class ChangeLog(Extension, QObject,):
self._change_logs = collections.OrderedDict()
with open(os.path.join(PluginRegistry.getInstance().getPluginPath(self.getPluginId()), "ChangeLog.txt"), "r",-1, "utf-8") as f:
open_version = None
open_header = None
open_header = "" # Initialise to an empty header in case there is no "*" in the first line of the changelog
for line in f:
line = line.replace("\n","")
if "[" in line and "]" in line:
line = line.replace("[","")
line = line.replace("]","")
open_version = Version(line)
self._change_logs[Version(line)] = collections.OrderedDict()
self._change_logs[open_version] = collections.OrderedDict()
elif line.startswith("*"):
open_header = line.replace("*","")
self._change_logs[open_version][open_header] = []
else:
if line != "":
self._change_logs[open_version][open_header].append(line)
elif line != "":
if open_header not in self._change_logs[open_version]:
self._change_logs[open_version][open_header] = []
self._change_logs[open_version][open_header].append(line)
def _onEngineCreated(self):
if not self._version:
@ -105,4 +107,3 @@ class ChangeLog(Extension, QObject,):
self._changelog_context = QQmlContext(Application.getInstance()._engine.rootContext())
self._changelog_context.setContextProperty("manager", self)
self._changelog_window = component.create(self._changelog_context)
#print(self._changelog_window)

View file

@ -1,6 +1,5 @@
[2.1.0]
[2.1.2]
*2.1 Beta release
Cura has been completely reengineered from the ground up for an even more seamless integration between hardware, software and materials. Together with its intuitive new user interface, its now also ready for any future developments. For the beginner Cura makes 3D printing incredibly easy, and for more advanced users, there are over 140 new customisable settings.
*Select Multiple Objects

View file

@ -13,9 +13,9 @@ def getMetaData():
"author": "Ultimaker",
"version": "1.0",
"description": catalog.i18nc("@info:whatsthis", "Shows changes since latest checked version."),
"api": 2
"api": 3
}
}
def register(app):
return {"extension": ChangeLog.ChangeLog()}
return {"extension": ChangeLog.ChangeLog()}

View file

@ -5,12 +5,20 @@ package cura.proto;
message ObjectList
{
repeated Object objects = 1;
repeated Setting settings = 2;
repeated Setting settings = 2; // meshgroup settings (for one-at-a-time printing)
}
message Slice
{
repeated ObjectList object_lists = 1;
repeated ObjectList object_lists = 1; // The meshgroups to be printed one after another
SettingList global_settings = 2; // The global settings used for the whole print job
repeated Extruder extruders = 3; // The settings sent to each extruder object
}
message Extruder
{
int32 id = 1;
SettingList settings = 2;
}
message Object
@ -29,10 +37,10 @@ message Progress
message Layer {
int32 id = 1;
float height = 2;
float thickness = 3;
float height = 2; // Z position
float thickness = 3; // height of a single layer
repeated Polygon polygons = 4;
repeated Polygon polygons = 4; // layer data
}
message Polygon {
@ -48,19 +56,19 @@ message Polygon {
MoveCombingType = 8;
MoveRetractionType = 9;
}
Type type = 1;
bytes points = 2;
float line_width = 3;
Type type = 1; // Type of move
bytes points = 2; // The points of the polygon, or two points if only a line segment (Currently only line segments are used)
float line_width = 3; // The width of the line being laid down
}
message GCodeLayer {
bytes data = 2;
}
message ObjectPrintTime {
message ObjectPrintTime { // The print time for the whole print and material estimates for the first extruder
int64 id = 1;
float time = 2;
float material_amount = 3;
float time = 2; // Total time estimate
float material_amount = 3; // material used in the first extruder
}
message SettingList {
@ -68,13 +76,13 @@ message SettingList {
}
message Setting {
string name = 1;
string name = 1; // Internal key to signify a setting
bytes value = 2;
bytes value = 2; // The value of the setting
}
message GCodePrefix {
bytes data = 2;
bytes data = 2; // Header string to be prenpended before the rest of the gcode sent from the engine
}
message SlicingFinished {

View file

@ -1,16 +1,19 @@
# Copyright (c) 2015 Ultimaker B.V.
# Cura is released under the terms of the AGPLv3 or higher.
from UM.Backend.Backend import Backend
from UM.Backend.Backend import Backend, BackendState
from UM.Application import Application
from UM.Scene.SceneNode import SceneNode
from UM.Preferences import Preferences
from UM.Signal import Signal
from UM.Logger import Logger
from UM.Qt.Bindings.BackendProxy import BackendState #To determine the state of the slicing job.
from UM.Message import Message
from UM.PluginRegistry import PluginRegistry
from UM.Resources import Resources
from UM.Settings.Validator import ValidatorState #To find if a setting is in an error state. We can't slice then.
from UM.Platform import Platform
from cura.ExtruderManager import ExtruderManager
from cura.OneAtATimeIterator import OneAtATimeIterator
from . import ProcessSlicedLayersJob
@ -29,6 +32,10 @@ catalog = i18nCatalog("cura")
class CuraEngineBackend(Backend):
## Starts the back-end plug-in.
#
# This registers all the signal listeners and prepares for communication
# with the back-end in general.
def __init__(self):
super().__init__()
@ -36,7 +43,7 @@ class CuraEngineBackend(Backend):
default_engine_location = os.path.join(Application.getInstallPrefix(), "bin", "CuraEngine")
if hasattr(sys, "frozen"):
default_engine_location = os.path.join(os.path.dirname(os.path.abspath(sys.executable)), "CuraEngine")
if sys.platform == "win32":
if Platform.isWindows():
default_engine_location += ".exe"
default_engine_location = os.path.abspath(default_engine_location)
Preferences.getInstance().addPreference("backend/location", default_engine_location)
@ -50,19 +57,24 @@ class CuraEngineBackend(Backend):
self._onActiveViewChanged()
self._stored_layer_data = []
# When there are current settings and machine instance is changed, there is no profile changed event. We should
# pretend there is though.
Application.getInstance().getMachineManager().activeMachineInstanceChanged.connect(self._onActiveProfileChanged)
#Triggers for when to (re)start slicing:
self._global_container_stack = None
Application.getInstance().globalContainerStackChanged.connect(self._onGlobalStackChanged)
self._onGlobalStackChanged()
self._profile = None
Application.getInstance().getMachineManager().activeProfileChanged.connect(self._onActiveProfileChanged)
self._onActiveProfileChanged()
self._active_extruder_stack = None
ExtruderManager.getInstance().activeExtruderChanged.connect(self._onActiveExtruderChanged)
self._onActiveExtruderChanged()
#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.
#TODO: Properly group propertyChanged signals by whether they are triggered by the same user interaction.
self._change_timer = QTimer()
self._change_timer.setInterval(500)
self._change_timer.setSingleShot(True)
self._change_timer.timeout.connect(self.slice)
#Listeners for receiving messages from the back-end.
self._message_handlers["cura.proto.Layer"] = self._onLayerMessage
self._message_handlers["cura.proto.Progress"] = self._onProgressMessage
self._message_handlers["cura.proto.GCodeLayer"] = self._onGCodeLayerMessage
@ -70,39 +82,35 @@ class CuraEngineBackend(Backend):
self._message_handlers["cura.proto.ObjectPrintTime"] = self._onObjectPrintTimeMessage
self._message_handlers["cura.proto.SlicingFinished"] = self._onSlicingFinishedMessage
self._slicing = False
self._start_slice_job = None
self._restart = False
self._enabled = True
self._always_restart = True
self._slicing = False #Are we currently slicing?
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._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._message = None
self._error_message = None #Pop-up message that shows errors.
self.backendQuit.connect(self._onBackendQuit)
self.backendConnected.connect(self._onBackendConnected)
#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().toolOperationStopped.connect(self._onToolOperationStopped)
Application.getInstance().getMachineManager().activeMachineInstanceChanged.connect(self._onInstanceChanged)
## Called when closing the application.
#
# This function should terminate the engine process.
def close(self):
# Terminate CuraEngine if it is still running at this point
self._terminate()
super().close()
## Get the command that is used to call the engine.
# This is usefull for debugging and used to actually start the engine
# This is useful for debugging and used to actually start the engine.
# \return list of commands and args / parameters.
def getEngineCommand(self):
active_machine = Application.getInstance().getMachineManager().getActiveMachineInstance()
json_path = ""
if not active_machine:
json_path = Resources.getPath(Resources.MachineDefinitions, "fdmprinter.json")
else:
json_path = active_machine.getMachineDefinition().getPath()
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, "-vv"]
## Emitted when we get a message containing print duration and material amount. This also implies the slicing has finished.
@ -113,55 +121,39 @@ class CuraEngineBackend(Backend):
## Emitted when the slicing process starts.
slicingStarted = Signal()
## Emitted whne the slicing process is aborted forcefully.
## Emitted when the slicing process is aborted forcefully.
slicingCancelled = Signal()
## Perform a slice of the scene.
def slice(self):
self._stored_layer_data = []
if not self._enabled:
if not self._enabled or not self._global_container_stack: #We shouldn't be slicing.
return
if self._slicing:
if self._slicing: #We were already slicing. Stop the old job.
self._terminate()
if self._message:
self._message.hide()
self._message = None
return
if self._process_layers_job:
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 = None
if self._profile.hasErrorValue():
Logger.log("w", "Profile has error values. Aborting slicing")
if self._message:
self._message.hide()
self._message = None
self._message = Message(catalog.i18nc("@info:status", "Unable to slice. Please check your setting values for errors."))
self._message.show()
return #No slicing if we have error values since those are by definition illegal values.
if self._error_message:
self._error_message.hide()
self.processingProgress.emit(0.0)
self.backendStateChange.emit(BackendState.NOT_STARTED)
if self._message:
self._message.setProgress(-1)
#else:
# self._message = Message(catalog.i18nc("@info:status", "Slicing..."), 0, False, -1)
# self._message.show()
self.backendStateChange.emit(BackendState.NotStarted)
self._scene.gcode_list = []
self._slicing = True
self.slicingStarted.emit()
slice_message = self._socket.createMessage("cura.proto.Slice")
settings_message = self._socket.createMessage("cura.proto.SettingList");
self._start_slice_job = StartSliceJob.StartSliceJob(self._profile, slice_message, settings_message)
self._start_slice_job = StartSliceJob.StartSliceJob(slice_message)
self._start_slice_job.start()
self._start_slice_job.finished.connect(self._onStartSliceCompleted)
## Terminate the engine process.
def _terminate(self):
self._slicing = False
self._restart = True
@ -178,24 +170,51 @@ class CuraEngineBackend(Backend):
self._process.terminate()
Logger.log("d", "Engine process is killed. Received return code %s", self._process.wait())
self._process = None
#self._createSocket() # Re create the socket
except Exception as e: # terminating a process that is already terminating causes an exception, silently ignore this.
Logger.log("d", "Exception occured while trying to kill the engine %s", str(e))
Logger.log("d", "Exception occurred while trying to kill the engine %s", str(e))
## Event handler to call when the job to initiate the slicing process is
# completed.
#
# When the start slice job is successfully completed, it will be happily
# slicing. This function handles any errors that may occur during the
# bootstrapping of a slice job.
#
# \param job The start slice job that was just finished.
def _onStartSliceCompleted(self, job):
# Note that cancelled slice jobs can still call this method.
if self._start_slice_job is job:
self._start_slice_job = None
if job.isCancelled() or job.getError() or job.getResult() != True:
if self._message:
self._message.hide()
self._message = None
return
else:
# Preparation completed, send it to the backend.
self._socket.sendMessage(job.getSettingsMessage())
self._socket.sendMessage(job.getSliceMessage())
if job.isCancelled() or job.getError() or job.getResult() == StartSliceJob.StartJobResult.Error:
return
if job.getResult() == StartSliceJob.StartJobResult.SettingError:
if Application.getInstance().getPlatformActivity:
self._error_message = Message(catalog.i18nc("@info:status", "Unable to slice. Please check your setting values for errors."), lifetime = 10)
self._error_message.show()
self.backendStateChange.emit(BackendState.Error)
else:
self.backendStateChange.emit(BackendState.NotStarted)
return
if job.getResult() == StartSliceJob.StartJobResult.NothingToSlice:
if Application.getInstance().getPlatformActivity:
self._error_message = Message(catalog.i18nc("@info:status", "Unable to slice. No suitable objects found."), lifetime = 10)
self._error_message.show()
self.backendStateChange.emit(BackendState.Error)
else:
self.backendStateChange.emit(BackendState.NotStarted)
return
# Preparation completed, send it to the backend.
self._socket.sendMessage(job.getSliceMessage())
## Listener for when the scene has changed.
#
# This should start a slice if the scene is now ready to slice.
#
# \param source The scene node that was changed.
def _onSceneChanged(self, source):
if type(source) is not SceneNode:
return
@ -211,6 +230,9 @@ class CuraEngineBackend(Backend):
self._onChanged()
## Called when an error occurs in the socket connection towards the engine.
#
# \param error The exception that occurred.
def _onSocketError(self, error):
if Application.getInstance().isShuttingDown():
return
@ -221,54 +243,62 @@ class CuraEngineBackend(Backend):
if error.getErrorCode() not in [Arcus.ErrorCode.BindFailedError, Arcus.ErrorCode.ConnectionResetError, Arcus.ErrorCode.Debug]:
Logger.log("e", "A socket error caused the connection to be reset")
def _onActiveProfileChanged(self):
if self._profile:
self._profile.settingValueChanged.disconnect(self._onSettingChanged)
self._profile = Application.getInstance().getMachineManager().getWorkingProfile()
if self._profile:
self._profile.settingValueChanged.connect(self._onSettingChanged)
## A setting has changed, so check if we must reslice.
#
# \param instance The setting instance that has changed.
# \param property The property of the setting instance that has changed.
def _onSettingChanged(self, instance, property):
if property == "value": #Only reslice if the value has changed.
self._onChanged()
def _onSettingChanged(self, setting):
self._onChanged()
## Called when a sliced layer data message is received from the engine.
#
# \param message The protobuf message containing sliced layer data.
def _onLayerMessage(self, message):
self._stored_layer_data.append(message)
## Called when a progress message is received from the engine.
#
# \param message The protobuf message containing the slicing progress.
def _onProgressMessage(self, message):
if self._message:
self._message.setProgress(round(message.amount * 100))
self.processingProgress.emit(message.amount)
self.backendStateChange.emit(BackendState.PROCESSING)
self.backendStateChange.emit(BackendState.Processing)
## Called when the engine sends a message that slicing is finished.
#
# \param message The protobuf message signalling that slicing is finished.
def _onSlicingFinishedMessage(self, message):
self.backendStateChange.emit(BackendState.DONE)
self.backendStateChange.emit(BackendState.Done)
self.processingProgress.emit(1.0)
self._slicing = False
if self._message:
self._message.setProgress(100)
self._message.hide()
self._message = None
if self._layer_view_active and (self._process_layers_job is None or not self._process_layers_job.isRunning()):
self._process_layers_job = ProcessSlicedLayersJob.ProcessSlicedLayersJob(self._stored_layer_data)
self._process_layers_job.start()
self._stored_layer_data = []
## Called when a g-code message is received from the engine.
#
# \param message The protobuf message containing g-code, encoded as UTF-8.
def _onGCodeLayerMessage(self, message):
self._scene.gcode_list.append(message.data.decode("utf-8", "replace"))
## Called when a g-code prefix message is received from the engine.
#
# \param message The protobuf message containing the g-code prefix,
# encoded as UTF-8.
def _onGCodePrefixMessage(self, message):
self._scene.gcode_list.insert(0, message.data.decode("utf-8", "replace"))
## Called when a print time message is received from the engine.
#
# \param message The protobuf message containing the print time and
# material amount.
def _onObjectPrintTimeMessage(self, message):
self.printDurationMessage.emit(message.time, message.material_amount)
## Creates a new socket connection.
def _createSocket(self):
super()._createSocket(os.path.abspath(os.path.join(PluginRegistry.getInstance().getPluginPath(self.getPluginId()), "Cura.proto")))
@ -276,28 +306,41 @@ class CuraEngineBackend(Backend):
def forceSlice(self):
self._change_timer.start()
def _onChanged(self):
if not self._profile:
return
## Called when anything has changed to the stuff that needs to be sliced.
#
# This indicates that we should probably re-slice soon.
def _onChanged(self, *args, **kwargs):
self._change_timer.start()
## Called when the back-end connects to the front-end.
def _onBackendConnected(self):
if self._restart:
self._onChanged()
self._restart = False
## Called when the user starts using some tool.
#
# When the user starts using a tool, we should pause slicing to prevent
# continuously slicing while the user is dragging some tool handle.
#
# \param tool The tool that the user is using.
def _onToolOperationStarted(self, tool):
self._terminate() # Do not continue slicing once a tool has started
self._enabled = False # Do not reslice when a tool is doing it's 'thing'
## Called when the user stops using some tool.
#
# This indicates that we can safely start slicing again.
#
# \param tool The tool that the user was using.
def _onToolOperationStopped(self, tool):
self._enabled = True # Tool stop, start listening for changes again.
## Called when the user changes the active view mode.
def _onActiveViewChanged(self):
if Application.getInstance().getController().getActiveView():
view = Application.getInstance().getController().getActiveView()
if view.getPluginId() == "LayerView":
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
# 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.
@ -308,11 +351,36 @@ class CuraEngineBackend(Backend):
else:
self._layer_view_active = False
def _onInstanceChanged(self):
self._terminate()
## Called when the back-end self-terminates.
#
# We should reset our state and start listening for new connections.
def _onBackendQuit(self):
if not self._restart and self._process:
Logger.log("d", "Backend quit with return code %s. Resetting process and socket.", self._process.wait())
self._process = None
self._createSocket()
## Called when the global container stack changes
def _onGlobalStackChanged(self):
if self._global_container_stack:
self._global_container_stack.propertyChanged.disconnect(self._onSettingChanged)
self._global_container_stack.containersChanged.disconnect(self._onChanged)
self._global_container_stack = Application.getInstance().getGlobalContainerStack()
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.containersChanged.connect(self._onChanged)
self._onActiveExtruderChanged()
self._onChanged()
def _onActiveExtruderChanged(self):
if self._active_extruder_stack:
self._active_extruder_stack.propertyChanged.disconnect(self._onSettingChanged)
self._active_extruder_stack.containersChanged.disconnect(self._onChanged)
self._active_extruder_stack = ExtruderManager.getInstance().getActiveExtruderStack()
if self._active_extruder_stack:
self._active_extruder_stack.propertyChanged.connect(self._onSettingChanged) # Note: Only starts slicing when the value changed.
self._active_extruder_stack.containersChanged.connect(self._onChanged)
self._onChanged()

View file

@ -62,8 +62,6 @@ class ProcessSlicedLayersJob(Job):
self._progress.hide()
return
settings = Application.getInstance().getMachineManager().getWorkingProfile()
mesh = MeshData()
layer_data = LayerDataBuilder.LayerDataBuilder()
layer_count = len(self._layers)
@ -105,7 +103,7 @@ class ProcessSlicedLayersJob(Job):
Job.yieldThread()
Job.yieldThread()
current_layer += 1
progress = (current_layer / layer_count) * 100
progress = (current_layer / layer_count) * 99
# TODO: Rebuild the layer data mesh once the layer has been processed.
# This needs some work in LayerData so we can add the new layers instead of recreating the entire mesh.
@ -132,8 +130,9 @@ class ProcessSlicedLayersJob(Job):
new_node.setMeshData(mesh)
new_node.setParent(self._scene.getRoot()) # Note: After this we can no longer abort!
if not settings.getSettingValue("machine_center_is_zero"):
new_node.setPosition(Vector(-settings.getSettingValue("machine_width") / 2, 0.0, settings.getSettingValue("machine_depth") / 2))
settings = Application.getInstance().getGlobalContainerStack()
if not settings.getProperty("machine_center_is_zero", "value"):
new_node.setPosition(Vector(-settings.getProperty("machine_width", "value") / 2, 0.0, settings.getProperty("machine_depth", "value") / 2))
if self._progress:
self._progress.setProgress(100)

View file

@ -3,7 +3,7 @@
import numpy
from string import Formatter
import traceback
from enum import IntEnum
from UM.Job import Job
from UM.Application import Application
@ -12,8 +12,16 @@ from UM.Logger import Logger
from UM.Scene.SceneNode import SceneNode
from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
from cura.OneAtATimeIterator import OneAtATimeIterator
from UM.Settings.Validator import ValidatorState
from cura.OneAtATimeIterator import OneAtATimeIterator
from cura.ExtruderManager import ExtruderManager
class StartJobResult(IntEnum):
Finished = 1
Error = 2
SettingError = 3
NothingToSlice = 4
## Formatter class that handles token expansion in start/end gcod
class GcodeStartEndFormatter(Formatter):
@ -30,33 +38,65 @@ class GcodeStartEndFormatter(Formatter):
## Job class that builds up the message of scene data to send to CuraEngine.
class StartSliceJob(Job):
def __init__(self, profile, slice_message, settings_message):
def __init__(self, slice_message):
super().__init__()
self._scene = Application.getInstance().getController().getScene()
self._profile = profile
self._slice_message = slice_message
self._settings_message = settings_message
self._is_cancelled = False
def getSettingsMessage(self):
return self._settings_message
def getSliceMessage(self):
return self._slice_message
## Check if a stack has any errors.
## returns true if it has errors, false otherwise.
def _checkStackForErrors(self, stack):
if stack is None:
return False
for key in stack.getAllKeys():
validation_state = stack.getProperty(key, "validationState")
if validation_state in (ValidatorState.Exception, ValidatorState.MaximumError, ValidatorState.MinimumError):
Logger.log("w", "Setting %s is not valid, but %s. Aborting slicing.", key, validation_state)
return True
Job.yieldThread()
return False
## Runs the job that initiates the slicing.
def run(self):
stack = Application.getInstance().getGlobalContainerStack()
if not stack:
self.setResult(StartJobResult.Error)
return
# Don't slice if there is a setting with an error value.
if self._checkStackForErrors(stack):
self.setResult(StartJobResult.SettingError)
return
# Don't slice if there is a per object setting with an error value.
for node in DepthFirstIterator(self._scene.getRoot()):
if type(node) is not SceneNode or not node.isSelectable():
continue
if self._checkStackForErrors(node.callDecoration("getStack")):
self.setResult(StartJobResult.SettingError)
return
with self._scene.getSceneLock():
# Remove old layer data.
for node in DepthFirstIterator(self._scene.getRoot()):
if node.callDecoration("getLayerData"):
node.getParent().removeChild(node)
break
# Get the objects in their groups to print.
object_groups = []
if self._profile.getSettingValue("print_sequence") == "one_at_a_time":
if stack.getProperty("print_sequence", "value") == "one_at_a_time":
for node in OneAtATimeIterator(self._scene.getRoot()):
temp_list = []
# Node can't be printed, so don't bother sending it.
if getattr(node, "_outside_buildarea", False):
continue
@ -83,9 +123,13 @@ class StartSliceJob(Job):
object_groups.append(temp_list)
if not object_groups:
self.setResult(StartJobResult.NothingToSlice)
return
self._buildSettingsMessage(self._profile)
self._buildGlobalSettingsMessage(stack)
for extruder_stack in ExtruderManager.getInstance().getMachineExtruders(stack.getBottom().getId()):
self._buildExtruderMessage(extruder_stack)
for group in object_groups:
group_message = self._slice_message.addRepeatedMessage("object_lists")
@ -97,8 +141,10 @@ class StartSliceJob(Job):
obj = group_message.addRepeatedMessage("objects")
obj.id = id(object)
verts = numpy.array(mesh_data.getVertices())
verts[:,[1,2]] = verts[:,[2,1]]
verts[:,1] *= -1
# Convert from Y up axes to Z up axes. Equals a 90 degree rotation.
verts[:, [1, 2]] = verts[:, [2, 1]]
verts[:, 1] *= -1
obj.vertices = verts
@ -106,7 +152,7 @@ class StartSliceJob(Job):
Job.yieldThread()
self.setResult(True)
self.setResult(StartJobResult.Finished)
def cancel(self):
super().cancel()
@ -121,38 +167,45 @@ class StartSliceJob(Job):
fmt = GcodeStartEndFormatter()
return str(fmt.format(value, **settings)).encode("utf-8")
except:
Logger.log("w", "Unabled to do token replacement on start/end gcode %s", traceback.format_exc())
Logger.logException("w", "Unable to do token replacement on start/end gcode")
return str(value).encode("utf-8")
def _buildSettingsMessage(self, profile):
settings = profile.getAllSettingValues(include_machine = True)
def _buildExtruderMessage(self, stack):
message = self._slice_message.addRepeatedMessage("extruders")
message.id = int(stack.getMetaDataEntry("position"))
for key in stack.getAllKeys():
setting = message.getMessage("settings").addRepeatedMessage("settings")
setting.name = key
setting.value = str(stack.getProperty(key, "value")).encode("utf-8")
Job.yieldThread()
## Sends all global settings to the engine.
#
# The settings are taken from the global stack. This does not include any
# per-extruder settings or per-object settings.
def _buildGlobalSettingsMessage(self, stack):
keys = stack.getAllKeys()
settings = {}
for key in keys:
settings[key] = stack.getProperty(key, "value")
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 #Pre-compute material material_bed_temp_prepend and material_print_temp_prepend
settings["material_print_temp_prepend"] = "{material_print_temperature}" not in start_gcode
for key, value in settings.items():
s = self._settings_message.addRepeatedMessage("settings")
s.name = key
if key == "machine_start_gcode" or key == "machine_end_gcode":
s.value = self._expandGcodeTokens(key, value, settings)
for key, value in settings.items(): #Add all submessages for each individual setting.
setting_message = self._slice_message.getMessage("global_settings").addRepeatedMessage("settings")
setting_message.name = key
if key == "machine_start_gcode" or key == "machine_end_gcode": #If it's a g-code message, use special formatting.
setting_message.value = self._expandGcodeTokens(key, value, settings)
else:
s.value = str(value).encode("utf-8")
setting_message.value = str(value).encode("utf-8")
def _handlePerObjectSettings(self, node, message):
profile = node.callDecoration("getProfile")
if profile:
for key, value in profile.getAllSettingValues().items():
stack = node.callDecoration("getStack")
if stack:
for key in stack.getAllKeys():
setting = message.addRepeatedMessage("settings")
setting.name = key
setting.value = str(value).encode()
Job.yieldThread()
object_settings = node.callDecoration("getAllSettingValues")
if not object_settings:
return
for key, value in object_settings.items():
setting = message.addRepeatedMessage("settings")
setting.name = key
setting.value = str(value).encode()
Job.yieldThread()
setting.value = str(stack.getProperty(key, "value")).encode("utf-8")
Job.yieldThread()

View file

@ -13,7 +13,7 @@ def getMetaData():
"name": catalog.i18nc("@label", "CuraEngine Backend"),
"author": "Ultimaker",
"description": catalog.i18nc("@info:whatsthis", "Provides the link to the CuraEngine slicing backend."),
"api": 2
"api": 3
}
}

View file

@ -1,11 +1,12 @@
# Copyright (c) 2015 Ultimaker B.V.
# Cura is released under the terms of the AGPLv3 or higher.
import os.path
from UM.Application import Application #To get the machine manager to create the new profile in.
from UM.Logger import Logger
from UM.Settings.Profile import Profile
from UM.Settings.ProfileReader import ProfileReader
from UM.Settings.InstanceContainer import InstanceContainer #The new profile to make.
from cura.ProfileReader import ProfileReader
## A plugin that reads profile data from Cura profile files.
#
@ -25,17 +26,17 @@ class CuraProfileReader(ProfileReader):
# returned.
def read(self, file_name):
# Create an empty profile.
profile = Profile(machine_manager = Application.getInstance().getMachineManager(), read_only = False)
serialised = ""
profile = InstanceContainer(os.path.basename(os.path.splitext(file_name)[0]))
profile.addMetaDataEntry("type", "quality")
try:
with open(file_name) as f: # Open file for reading.
serialised = f.read()
serialized = f.read()
except IOError as e:
Logger.log("e", "Unable to open file %s for reading: %s", file_name, str(e))
return None
try:
profile.unserialise(serialised)
profile.deserialize(serialized)
except Exception as e: # Parsing error. This is not a (valid) Cura profile then.
Logger.log("e", "Error while trying to parse profile: %s", str(e))
return None

View file

@ -13,7 +13,7 @@ def getMetaData():
"author": "Ultimaker",
"version": "1.0",
"description": catalog.i18nc("@info:whatsthis", "Provides support for importing Cura profiles."),
"api": 2
"api": 3
},
"profile_reader": [
{

View file

@ -4,7 +4,7 @@
from UM.Logger import Logger
from UM.SaveFile import SaveFile
from UM.Settings.ProfileWriter import ProfileWriter
from cura.ProfileWriter import ProfileWriter
## Writes profiles to Cura's own profile format with config files.
@ -16,10 +16,10 @@ class CuraProfileWriter(ProfileWriter):
# \return \code True \endcode if the writing was successful, or \code
# False \endcode if it wasn't.
def write(self, path, profile):
serialised = profile.serialise()
serialized = profile.serialize()
try:
with SaveFile(path, "wt", -1, "utf-8") as f: # Open the specified file.
f.write(serialised)
f.write(serialized)
except Exception as e:
Logger.log("e", "Failed to write profile to %s: %s", path, str(e))
return False

View file

@ -13,7 +13,7 @@ def getMetaData():
"author": "Ultimaker",
"version": "1.0",
"description": catalog.i18nc("@info:whatsthis", "Provides support for exporting Cura profiles."),
"api": 2
"api": 3
},
"profile_writer": [
{

View file

@ -1,13 +1,22 @@
# Copyright (c) 2015 Ultimaker B.V.
# Copyright (c) 2016 Ultimaker B.V.
# Cura is released under the terms of the AGPLv3 or higher.
from UM.Mesh.MeshWriter import MeshWriter
from UM.Logger import Logger
from UM.Application import Application
from UM.Settings.InstanceContainer import InstanceContainer #To create a complete setting profile to store in the g-code.
import re #For escaping characters in the settings.
import copy
## Writes g-code to a file.
#
# While this poses as a mesh writer, what this really does is take the g-code
# in the entire scene and write it to an output device. Since the g-code of a
# single mesh isn't separable from the rest what with rafts and travel moves
# and all, it doesn't make sense to write just a single mesh.
#
# So this plug-in takes the g-code that is stored in the root of the scene
# node tree, adds a bit of extra information about the profiles and writes
# that to the output device.
class GCodeWriter(MeshWriter):
## The file format version of the serialised g-code.
#
@ -32,7 +41,7 @@ class GCodeWriter(MeshWriter):
def write(self, stream, node, mode = MeshWriter.OutputMode.TextMode):
if mode != MeshWriter.OutputMode.TextMode:
Logger.log("e", "GCode Writer does not support non-text mode")
Logger.log("e", "GCode Writer does not support non-text mode.")
return False
scene = Application.getInstance().getController().getScene()
@ -40,26 +49,30 @@ class GCodeWriter(MeshWriter):
if gcode_list:
for gcode in gcode_list:
stream.write(gcode)
# Serialise the profile and put them at the end of the file.
profile = self._serialiseProfile(Application.getInstance().getMachineManager().getWorkingProfile())
stream.write(profile)
# Serialise the current container stack and put it at the end of the file.
settings = self._serialiseSettings(Application.getInstance().getGlobalContainerStack())
stream.write(settings)
return True
return False
## Serialises the profile to prepare it for saving in the g-code.
## Serialises a container stack to prepare it for writing at the end of the
# g-code.
#
# The profile are serialised, and special characters (including newline)
# The settings are serialised, and special characters (including newline)
# are escaped.
#
# \param profile The profile to serialise.
# \return A serialised string of the profile.
def _serialiseProfile(self, profile):
# \param settings A container stack to serialise.
# \return A serialised string of the settings.
def _serialiseSettings(self, settings):
prefix = ";SETTING_" + str(GCodeWriter.version) + " " # The prefix to put before each line.
prefix_length = len(prefix)
# Serialise a deepcopy to remove the defaults from the profile
serialised = copy.deepcopy(profile).serialise()
all_settings = InstanceContainer("G-code-imported-profile") #Create a new 'profile' with ALL settings so that the slice can be precisely reproduced.
all_settings.setDefinition(settings.getBottom())
for key in settings.getAllKeys():
all_settings.setProperty(key, "value", settings.getProperty(key, "value")) #Just copy everything over to the setting instance.
serialised = all_settings.serialize()
# Escape characters that have a special meaning in g-code comments.
pattern = re.compile("|".join(GCodeWriter.escape_characters.keys()))

View file

@ -13,7 +13,7 @@ def getMetaData():
"author": "Ultimaker",
"version": "1.0",
"description": catalog.i18nc("@info:whatsthis", "Writes GCode to a file."),
"api": 2
"api": 3
},
"mesh_writer": {

View file

@ -13,7 +13,7 @@ def getMetaData():
"author": "Ultimaker",
"version": "1.0",
"description": i18n_catalog.i18nc("@info:whatsthis", "Enables ability to generate printable geometry from 2D image files."),
"api": 2
"api": 3
},
"mesh_reader": [
{

View file

@ -10,6 +10,7 @@ from UM.Scene.Selection import Selection
from UM.Math.Color import Color
from UM.Mesh.MeshBuilder import MeshBuilder
from UM.Job import Job
from UM.Preferences import Preferences
from UM.View.RenderBatch import RenderBatch
from UM.View.GL.OpenGL import OpenGL
@ -41,7 +42,10 @@ class LayerView(View):
self._top_layers_job = None
self._activity = False
self._solid_layers = 5
Preferences.getInstance().addPreference("view/top_layer_count", 1)
Preferences.getInstance().preferenceChanged.connect(self._onPreferencesChanged)
self._solid_layers = int(Preferences.getInstance().getValue("view/top_layer_count"))
self._top_layer_timer = QTimer()
self._top_layer_timer.setInterval(50)
@ -125,8 +129,7 @@ class LayerView(View):
if self._current_layer_num > self._max_layers:
self._current_layer_num = self._max_layers
self._current_layer_mesh = None
self._current_layer_jumps = None
self.resetLayerData()
self._top_layer_timer.start()
@ -209,6 +212,15 @@ class LayerView(View):
self._top_layers_job = None
def _onPreferencesChanged(self, preference):
if preference != "view/top_layer_count":
return
self._solid_layers = int(Preferences.getInstance().getValue("view/top_layer_count"))
self.resetLayerData()
self._top_layer_timer.start()
class _CreateTopLayersJob(Job):
def __init__(self, scene, layer_number, solid_layers):
super().__init__()

View file

@ -14,7 +14,7 @@ def getMetaData():
"author": "Ultimaker",
"version": "1.0",
"description": catalog.i18nc("@info:whatsthis", "Provides the Layer view."),
"api": 2
"api": 3
},
"view": {
"name": catalog.i18nc("@item:inlistbox", "Layers"),

View file

@ -50,7 +50,8 @@
"skirt_minimal_length": "skirt_minimal_length",
"brim_line_count": "brim_line_count",
"raft_margin": "raft_margin",
"raft_airgap": "raft_airgap_all",
"raft_airgap": "float(raft_airgap_all) + float(raft_airgap)",
"layer_0_z_overlap": "raft_airgap",
"raft_surface_layers": "raft_surface_layers",
"raft_surface_thickness": "raft_surface_thickness",
"raft_surface_line_width": "raft_surface_linewidth",

View file

@ -9,8 +9,9 @@ import os.path #For concatenating the path to the plugin and the relative path t
from UM.Application import Application #To get the machine manager to create the new profile in.
from UM.Logger import Logger #Logging errors.
from UM.PluginRegistry import PluginRegistry #For getting the path to this plugin's directory.
from UM.Settings.Profile import Profile
from UM.Settings.ProfileReader import ProfileReader
from UM.Settings.DefinitionContainer import DefinitionContainer #For getting the current machine's defaults.
from UM.Settings.InstanceContainer import InstanceContainer #The new profile to make.
from cura.ProfileReader import ProfileReader #The plug-in type to implement.
## A plugin that reads profile data from legacy Cura versions.
#
@ -66,7 +67,7 @@ class LegacyProfileReader(ProfileReader):
if file_name.split(".")[-1] != "ini":
return None
Logger.log("i", "Importing legacy profile from file " + file_name + ".")
profile = Profile(machine_manager = Application.getInstance().getMachineManager(), read_only = False) #Create an empty profile.
profile = InstanceContainer("Imported Legacy Profile") #Create an empty profile.
parser = configparser.ConfigParser(interpolation = None)
try:
@ -103,23 +104,24 @@ class LegacyProfileReader(ProfileReader):
if "target_version" not in dict_of_doom:
Logger.log("e", "Dictionary of Doom has no target version. Is it the correct JSON file?")
return None
if Profile.ProfileVersion != dict_of_doom["target_version"]:
Logger.log("e", "Dictionary of Doom of legacy profile reader (version %s) is not in sync with the profile version (version %s)!", dict_of_doom["target_version"], str(Profile.ProfileVersion))
if InstanceContainer.Version != dict_of_doom["target_version"]:
Logger.log("e", "Dictionary of Doom of legacy profile reader (version %s) is not in sync with the current instance container version (version %s)!", dict_of_doom["target_version"], str(InstanceContainer.Version))
return None
if "translation" not in dict_of_doom:
Logger.log("e", "Dictionary of Doom has no translation. Is it the correct JSON file?")
return None
current_printer = Application.getInstance().getGlobalContainerStack().findContainer({ }, DefinitionContainer)
for new_setting in dict_of_doom["translation"]: #Evaluate all new settings that would get a value from the translations.
old_setting_expression = dict_of_doom["translation"][new_setting]
compiled = compile(old_setting_expression, new_setting, "eval")
try:
new_value = eval(compiled, {"math": math}, legacy_settings) #Pass the legacy settings as local variables to allow access to in the evaluation.
value_using_defaults = eval(compiled, {"math": math}, defaults) #Evaluate again using only the default values to try to see if they are default.
except Exception as e: #Probably some setting name that was missing or something else that went wrong in the ini file.
except Exception: #Probably some setting name that was missing or something else that went wrong in the ini file.
Logger.log("w", "Setting " + new_setting + " could not be set because the evaluation failed. Something is probably missing from the imported legacy profile.")
continue
if new_value != value_using_defaults and profile.getSettingValue(new_setting) != new_value: #Not equal to the default in the new Cura OR the default in the legacy Cura.
if new_value != value_using_defaults and current_printer.findDefinitions(key = new_setting).default_value != new_value: #Not equal to the default in the new Cura OR the default in the legacy Cura.
profile.setSettingValue(new_setting, new_value) #Store the setting in the profile!
if len(profile.getChangedSettings()) == 0:

View file

@ -13,7 +13,7 @@ def getMetaData():
"author": "Ultimaker",
"version": "1.0",
"description": catalog.i18nc("@info:whatsthis", "Provides support for importing profiles from legacy Cura versions."),
"api": 2
"api": 3
},
"profile_reader": [
{

View file

@ -0,0 +1,29 @@
// Copyright (c) 2015 Ultimaker B.V.
// Uranium is released under the terms of the AGPLv3 or higher.
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Controls.Styles 1.1
import QtQuick.Layouts 1.1
import UM 1.1 as UM
import ".."
Button {
id: base;
style: UM.Theme.styles.sidebar_category;
signal showTooltip(string text);
signal hideTooltip();
signal contextMenuRequested()
text: definition.label
iconSource: UM.Theme.getIcon(definition.icon)
checkable: true
checked: definition.expanded
onClicked: definition.expanded ? settingDefinitionsModel.collapse(definition.key) : settingDefinitionsModel.expandAll(definition.key)
}

View file

@ -0,0 +1,34 @@
// Copyright (c) 2015 Ultimaker B.V.
// Uranium is released under the terms of the AGPLv3 or higher.
import QtQuick 2.1
import QtQuick.Layouts 1.1
import QtQuick.Controls 1.1
import QtQuick.Controls.Styles 1.1
import UM 1.2 as UM
UM.TooltipArea
{
x: model.depth * UM.Theme.getSize("default_margin").width;
text: model.description;
width: childrenRect.width;
height: childrenRect.height;
Button
{
id: check
text: definition.label
onClicked:
{
addedSettingsModel.setVisible(model.key, true);
settingPickDialog.visible = false
UM.ActiveTool.forceUpdate()
}
}
}

View file

@ -0,0 +1,76 @@
from PyQt5.QtCore import QObject, pyqtProperty, pyqtSignal
from UM.Application import Application
from UM.Settings.SettingInstance import SettingInstance
from UM.Logger import Logger
from cura.SettingOverrideDecorator import SettingOverrideDecorator
## The per object setting visibility handler ensures that only setting defintions that have a matching instance Container
# are returned as visible.
class PerObjectSettingVisibilityHandler(QObject):
def __init__(self, parent = None, *args, **kwargs):
super().__init__(parent = parent, *args, **kwargs)
self._selected_object_id = None
visibilityChanged = pyqtSignal()
def setSelectedObjectId(self, id):
self._selected_object_id = id
self.visibilityChanged.emit()
@pyqtProperty("quint64", fset = setSelectedObjectId)
def selectedObjectId(self):
pass
def setVisible(self, visible):
node = Application.getInstance().getController().getScene().findObject(self._selected_object_id)
if not node:
return
stack = node.callDecoration("getStack")
if not stack:
node.addDecorator(SettingOverrideDecorator())
stack = node.callDecoration("getStack")
settings = stack.getTop()
all_instances = settings.findInstances(**{})
visibility_changed = False # Flag to check if at the end the signal needs to be emitted
# Remove all instances that are not in visibility list
for instance in all_instances:
if instance.definition.key not in visible:
settings.removeInstance(instance.definition.key)
visibility_changed = True
# Add all instances that are not added, but are in visiblity list
for item in visible:
if not settings.getInstance(item):
definition_container = Application.getInstance().getGlobalContainerStack().getBottom()
definitions = definition_container.findDefinitions(key = item)
if definitions:
settings.addInstance(SettingInstance(definitions[0], settings))
visibility_changed = True
else:
Logger.log("w", "Unable to add instance (%s) to perobject visibility because we couldn't find the matching definition", item)
if visibility_changed:
self.visibilityChanged.emit()
def getVisible(self):
visible_settings = set()
node = Application.getInstance().getController().getScene().findObject(self._selected_object_id)
if not node:
return visible_settings
stack = node.callDecoration("getStack")
if not stack:
return visible_settings
settings = stack.getTop()
if not settings:
return visible_settings
all_instances = settings.findInstances(**{})
for instance in all_instances:
visible_settings.add(instance.definition.key)
return visible_settings

View file

@ -1,86 +0,0 @@
# Copyright (c) 2015 Ultimaker B.V.
# Uranium is released under the terms of the AGPLv3 or higher.
from PyQt5.QtCore import Qt, pyqtSlot, QUrl
from UM.Application import Application
from UM.Qt.ListModel import ListModel
from UM.Scene.Iterator.BreadthFirstIterator import BreadthFirstIterator
from UM.Scene.SceneNode import SceneNode
from UM.Settings.SettingOverrideDecorator import SettingOverrideDecorator
from UM.Settings.ProfileOverrideDecorator import ProfileOverrideDecorator
from . import SettingOverrideModel
class PerObjectSettingsModel(ListModel):
IdRole = Qt.UserRole + 1
XRole = Qt.UserRole + 2
YRole = Qt.UserRole + 3
MaterialRole = Qt.UserRole + 4
ProfileRole = Qt.UserRole + 5
SettingsRole = Qt.UserRole + 6
def __init__(self, parent = None):
super().__init__(parent)
self._scene = Application.getInstance().getController().getScene()
self._root = self._scene.getRoot()
self.addRoleName(self.IdRole,"id")
self.addRoleName(self.MaterialRole, "material")
self.addRoleName(self.ProfileRole, "profile")
self.addRoleName(self.SettingsRole, "settings")
self._updateModel()
@pyqtSlot("quint64", str)
def setObjectProfile(self, object_id, profile_name):
self.setProperty(self.find("id", object_id), "profile", profile_name)
profile = None
if profile_name != "global":
profile = Application.getInstance().getMachineManager().findProfile(profile_name)
node = self._scene.findObject(object_id)
if profile:
if not node.getDecorator(ProfileOverrideDecorator):
node.addDecorator(ProfileOverrideDecorator())
node.callDecoration("setProfile", profile)
else:
if node.getDecorator(ProfileOverrideDecorator):
node.removeDecorator(ProfileOverrideDecorator)
@pyqtSlot("quint64", str)
def addSettingOverride(self, object_id, key):
machine = Application.getInstance().getMachineManager().getActiveMachineInstance()
if not machine:
return
node = self._scene.findObject(object_id)
if not node.getDecorator(SettingOverrideDecorator):
node.addDecorator(SettingOverrideDecorator())
node.callDecoration("addSetting", key)
@pyqtSlot("quint64", str)
def removeSettingOverride(self, object_id, key):
node = self._scene.findObject(object_id)
node.callDecoration("removeSetting", key)
if len(node.callDecoration("getAllSettings")) == 0:
node.removeDecorator(SettingOverrideDecorator)
def _updateModel(self):
self.clear()
for node in BreadthFirstIterator(self._root):
if type(node) is not SceneNode or not node.isSelectable():
continue
node_profile = node.callDecoration("getProfile")
if not node_profile:
node_profile = "global"
else:
node_profile = node_profile.getName()
self.appendItem({
"id": id(node),
"material": "",
"profile": node_profile,
"settings": SettingOverrideModel.SettingOverrideModel(node)
})

View file

@ -1,4 +1,4 @@
// Copyright (c) 2015 Ultimaker B.V.
// Copyright (c) 2016 Ultimaker B.V.
// Uranium is released under the terms of the AGPLv3 or higher.
import QtQuick 2.2
@ -6,83 +6,231 @@ import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2
import QtQuick.Window 2.2
import UM 1.1 as UM
import UM 1.2 as UM
import Cura 1.0 as Cura
import ".."
Item {
id: base;
property int currentIndex: UM.ActiveTool.properties.getValue("SelectedIndex")
UM.I18nCatalog { id: catalog; name: "cura"; }
width: childrenRect.width;
height: childrenRect.height;
Column {
Column
{
id: items
anchors.top: parent.top;
anchors.left: parent.left;
spacing: UM.Theme.getSize("default_margin").height;
Column {
id: customisedSettings
spacing: UM.Theme.getSize("default_lining").height;
width: UM.Theme.getSize("setting").width + UM.Theme.getSize("setting").height/2;
Row
{
ComboBox
{
id: extruderSelector
Repeater {
id: settings;
model: Cura.ExtrudersModel
{
id: extruders_model
onRowsInserted: extruderSelector.visible = extruders_model.rowCount() > 1
onModelReset: extruderSelector.visible = extruders_model.rowCount() > 1
}
visible: extruders_model.rowCount() > 1
textRole: "name"
width: items.width
height: UM.Theme.getSize("section").height
MouseArea
{
anchors.fill: parent
acceptedButtons: Qt.NoButton
onWheel: wheel.accepted = true;
}
model: UM.ActiveTool.properties.getValue("Model").getItem(base.currentIndex).settings
style: ComboBoxStyle
{
background: Rectangle
{
color:
{
if(extruderSelector.hovered || base.activeFocus)
{
return UM.Theme.getColor("setting_control_highlight");
}
else
{
return UM.Theme.getColor("setting_control");
}
}
border.width: UM.Theme.getSize("default_lining").width
border.color: UM.Theme.getColor("setting_control_border")
}
label: Item
{
Rectangle
{
id: swatch
height: UM.Theme.getSize("setting_control").height / 2
width: height
anchors.left: parent.left
anchors.leftMargin: UM.Theme.getSize("default_lining").width
anchors.verticalCenter: parent.verticalCenter
UM.SettingItem {
color: extruders_model.getItem(extruderSelector.currentIndex).colour
border.width: UM.Theme.getSize("default_lining").width
border.color: !enabled ? UM.Theme.getColor("setting_control_disabled_border") : UM.Theme.getColor("setting_control_border")
}
Label
{
anchors.left: swatch.right
anchors.leftMargin: UM.Theme.getSize("default_lining").width
anchors.right: downArrow.left
anchors.rightMargin: UM.Theme.getSize("default_lining").width
anchors.verticalCenter: parent.verticalCenter
text: extruderSelector.currentText
font: UM.Theme.getFont("default")
color: !enabled ? UM.Theme.getColor("setting_control_disabled_text") : UM.Theme.getColor("setting_control_text")
elide: Text.ElideRight
verticalAlignment: Text.AlignVCenter
}
UM.RecolorImage
{
id: downArrow
anchors.right: parent.right
anchors.rightMargin: UM.Theme.getSize("default_lining").width * 2
anchors.verticalCenter: parent.verticalCenter
source: UM.Theme.getIcon("arrow_bottom")
width: UM.Theme.getSize("standard_arrow").width
height: UM.Theme.getSize("standard_arrow").height
sourceSize.width: width + 5
sourceSize.height: width + 5
color: UM.Theme.getColor("setting_control_text")
}
}
}
onActivated: UM.ActiveTool.setProperty("SelectedActiveExtruder", extruders_model.getItem(index).id);
onModelChanged: updateCurrentIndex();
function updateCurrentIndex()
{
for(var i = 0; i < extruders_model.rowCount(); ++i)
{
if(extruders_model.getItem(i).id == UM.ActiveTool.properties.getValue("SelectedActiveExtruder"))
{
extruderSelector.currentIndex = i;
return;
}
}
extruderSelector.currentIndex = -1;
}
}
}
Repeater
{
id: contents
height: childrenRect.height;
model: UM.SettingDefinitionsModel
{
id: addedSettingsModel;
containerId: Cura.MachineManager.activeDefinitionId
visibilityHandler: Cura.PerObjectSettingVisibilityHandler
{
selectedObjectId: UM.ActiveTool.properties.getValue("SelectedObjectId")
}
}
delegate: Row
{
Loader
{
id: settingLoader
width: UM.Theme.getSize("setting").width;
height: UM.Theme.getSize("setting").height;
height: UM.Theme.getSize("section").height;
name: model.label;
type: model.type;
value: model.value;
description: model.description;
unit: model.unit;
valid: model.valid;
visible: !model.global_only
options: model.options
indent: false
property var definition: model
property var settingDefinitionsModel: addedSettingsModel
property var propertyProvider: provider
style: UM.Theme.styles.setting_item;
//Qt5.4.2 and earlier has a bug where this causes a crash: https://bugreports.qt.io/browse/QTBUG-35989
//In addition, while it works for 5.5 and higher, the ordering of the actual combo box drop down changes,
//causing nasty issues when selecting different options. So disable asynchronous loading of enum type completely.
asynchronous: model.type != "enum" && model.type != "extruder"
onItemValueChanged: {
settings.model.setSettingValue(model.key, value)
onLoaded: {
settingLoader.item.showRevertButton = false
settingLoader.item.showInheritButton = false
settingLoader.item.doDepthIndentation = false
}
Button
sourceComponent:
{
anchors.left: parent.right;
width: UM.Theme.getSize("setting").height;
height: UM.Theme.getSize("setting").height;
onClicked: UM.ActiveTool.properties.getValue("Model").removeSettingOverride(UM.ActiveTool.properties.getValue("Model").getItem(base.currentIndex).id, model.key)
style: ButtonStyle
switch(model.type)
{
background: Rectangle
case "int":
return settingTextField
case "float":
return settingTextField
case "enum":
return settingComboBox
case "extruder":
return settingExtruder
case "bool":
return settingCheckBox
case "str":
return settingTextField
case "category":
return settingCategory
default:
return settingUnknown
}
}
}
Button
{
width: UM.Theme.getSize("setting").height;
height: UM.Theme.getSize("setting").height;
onClicked: addedSettingsModel.setVisible(model.key, false);
style: ButtonStyle
{
background: Rectangle
{
color: control.hovered ? control.parent.style.controlHighlightColor : control.parent.style.controlColor;
UM.RecolorImage
{
color: control.hovered ? control.parent.style.controlHighlightColor : control.parent.style.controlColor;
UM.RecolorImage
{
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width/2
height: parent.height/2
sourceSize.width: width
sourceSize.height: width
color: control.hovered ? UM.Theme.getColor("setting_control_button_hover") : UM.Theme.getColor("setting_control_button")
source: UM.Theme.getIcon("cross1")
}
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width/2
height: parent.height/2
sourceSize.width: width
sourceSize.height: width
color: control.hovered ? UM.Theme.getColor("setting_control_button_hover") : UM.Theme.getColor("setting_control_button")
source: UM.Theme.getIcon("cross1")
}
}
}
}
UM.SettingPropertyProvider
{
id: provider
containerStackId: UM.ActiveTool.properties.getValue("ContainerID")
key: model.key
watchedProperties: [ "value", "enabled", "validationState" ]
storeIndex: 0
}
}
}
@ -133,6 +281,7 @@ Item {
id: settingPickDialog
title: catalog.i18nc("@title:window", "Pick a Setting to Customize")
property string labelFilter: ""
TextField {
id: filter;
@ -145,123 +294,62 @@ Item {
placeholderText: catalog.i18nc("@label:textbox", "Filter...");
onTextChanged: settingCategoriesModel.filter(text);
onTextChanged:
{
if(text != "")
{
listview.model.filter = {"settable_per_mesh": true, "label": "*" + text}
}
else
{
listview.model.filter = {"settable_per_mesh": true}
}
}
}
ScrollView {
id: view;
anchors {
ScrollView
{
id: scrollView
anchors
{
top: filter.bottom;
left: parent.left;
right: parent.right;
bottom: parent.bottom;
}
ListView
{
id:listview
model: UM.SettingDefinitionsModel
{
id: definitionsModel;
containerId: Cura.MachineManager.activeDefinitionId
filter:
{
"settable_per_mesh": true
}
visibilityHandler: UM.SettingPreferenceVisibilityHandler {}
}
delegate:Loader
{
id: loader
Column {
width: view.width - UM.Theme.getSize("default_margin").width * 2;
height: childrenRect.height;
width: parent.width
height: model.type != undefined ? UM.Theme.getSize("section").height : 0;
Repeater {
id: settingList;
property var definition: model
property var settingDefinitionsModel: definitionsModel
model: UM.SettingCategoriesModel { id: settingCategoriesModel; }
delegate: Item {
id: delegateItem;
width: parent.width;
height: childrenRect.height;
visible: model.visible && settingsColumn.childrenHeight != 0 //If all children are hidden, the height is 0, and then the category header must also be hidden.
ToolButton {
id: categoryHeader;
text: model.name;
checkable: true;
width: parent.width;
onCheckedChanged: settingsColumn.state != "" ? settingsColumn.state = "" : settingsColumn.state = "collapsed";
style: ButtonStyle {
background: Rectangle
{
width: control.width;
height: control.height;
color: control.hovered ? palette.highlight : "transparent";
}
label: Row
{
spacing: UM.Theme.getSize("default_margin").width;
Image
{
anchors.verticalCenter: parent.verticalCenter;
source: control.checked ? UM.Theme.getIcon("arrow_right") : UM.Theme.getIcon("arrow_bottom");
}
Label
{
text: control.text;
font.bold: true;
color: control.hovered ? palette.highlightedText : palette.text;
}
}
}
}
property variant settingsModel: model.settings;
Column {
id: settingsColumn;
anchors.top: categoryHeader.bottom;
property real childrenHeight:
{
var h = 0.0;
for(var i in children)
{
var item = children[i];
h += children[i].height;
if(item.settingVisible)
{
if(i > 0)
{
h += spacing;
}
}
}
return h;
}
width: childrenRect.width;
height: childrenHeight;
Repeater {
model: delegateItem.settingsModel;
delegate: ToolButton {
id: button;
x: model.visible_depth * UM.Theme.getSize("default_margin").width;
text: model.name;
tooltip: model.description;
visible: !model.global_only
height: model.global_only ? 0 : undefined
onClicked: {
var object_id = UM.ActiveTool.properties.getValue("Model").getItem(base.currentIndex).id;
UM.ActiveTool.properties.getValue("Model").addSettingOverride(object_id, model.key);
settingPickDialog.visible = false;
}
states: State {
name: "filtered"
when: model.filtered || !model.visible || !model.enabled
PropertyChanges { target: button; height: 0; opacity: 0; }
}
}
}
states: State {
name: "collapsed";
PropertyChanges { target: settingsColumn; opacity: 0; height: 0; }
}
asynchronous: true
source:
{
switch(model.type)
{
case "category":
return "PerObjectCategory.qml"
default:
return "PerObjectItem.qml"
}
}
}
@ -279,4 +367,46 @@ Item {
}
SystemPalette { id: palette; }
Component
{
id: settingTextField;
Cura.SettingTextField { }
}
Component
{
id: settingComboBox;
Cura.SettingComboBox { }
}
Component
{
id: settingExtruder;
Cura.SettingExtruder { }
}
Component
{
id: settingCheckBox;
Cura.SettingCheckBox { }
}
Component
{
id: settingCategory;
Cura.SettingCategory { }
}
Component
{
id: settingUnknown;
Cura.SettingUnknown { }
}
}

View file

@ -1,44 +1,57 @@
# Copyright (c) 2015 Ultimaker B.V.
# Copyright (c) 2016 Ultimaker B.V.
# Uranium is released under the terms of the AGPLv3 or higher.
from UM.Tool import Tool
from UM.Scene.Selection import Selection
from UM.Application import Application
from UM.Preferences import Preferences
from cura.SettingOverrideDecorator import SettingOverrideDecorator
from . import PerObjectSettingsModel
## This tool allows the user to add & change settings per node in the scene.
# The settings per object are kept in a ContainerStack, which is linked to a node by decorator.
class PerObjectSettingsTool(Tool):
def __init__(self):
super().__init__()
self._model = None
self.setExposedProperties("Model", "SelectedIndex")
self.setExposedProperties("SelectedObjectId", "ContainerID", "SelectedActiveExtruder")
Preferences.getInstance().preferenceChanged.connect(self._onPreferenceChanged)
Selection.selectionChanged.connect(self.propertyChanged)
self._onPreferenceChanged("cura/active_mode")
def event(self, event):
return False
def getModel(self):
if not self._model:
self._model = PerObjectSettingsModel.PerObjectSettingsModel()
#For some reason, casting this model to itself causes the model to properly be cast to a QVariant, even though it ultimately inherits from QVariant.
#Yeah, we have no idea either...
return PerObjectSettingsModel.PerObjectSettingsModel(self._model)
def getSelectedIndex(self):
try:
selected_object = Selection.getSelectedObject(0)
if selected_object.getParent().callDecoration("isGroup"):
selected_object = selected_object.getParent()
except:
selected_object = None
def getSelectedObjectId(self):
selected_object = Selection.getSelectedObject(0)
selected_object_id = id(selected_object)
index = self.getModel().find("id", selected_object_id)
return index
return selected_object_id
def getContainerID(self):
selected_object = Selection.getSelectedObject(0)
try:
return selected_object.callDecoration("getStack").getId()
except AttributeError:
return ""
## Gets the active extruder of the currently selected object.
#
# \return The active extruder of the currently selected object.
def getSelectedActiveExtruder(self):
selected_object = Selection.getSelectedObject(0)
return selected_object.callDecoration("getActiveExtruder")
## Changes the active extruder of the currently selected object.
#
# \param extruder_stack_id The ID of the extruder to print the currently
# selected object with.
def setSelectedActiveExtruder(self, extruder_stack_id):
selected_object = Selection.getSelectedObject(0)
stack = selected_object.callDecoration("getStack") #Don't try to get the active extruder since it may be None anyway.
if not stack:
selected_object.addDecorator(SettingOverrideDecorator())
selected_object.callDecoration("setActiveExtruder", extruder_stack_id)
def _onPreferenceChanged(self, preference):
if preference == "cura/active_mode":

View file

@ -1,137 +0,0 @@
# Copyright (c) 2015 Ultimaker B.V.
# Uranium is released under the terms of the AGPLv3 or higher.
from PyQt5.QtCore import Qt, pyqtSlot, QUrl
from UM.Application import Application
from UM.Qt.ListModel import ListModel
from UM.Settings.SettingOverrideDecorator import SettingOverrideDecorator
class SettingOverrideModel(ListModel):
KeyRole = Qt.UserRole + 1
LabelRole = Qt.UserRole + 2
DescriptionRole = Qt.UserRole + 3
ValueRole = Qt.UserRole + 4
TypeRole = Qt.UserRole + 5
UnitRole = Qt.UserRole + 6
ValidRole = Qt.UserRole + 7
OptionsRole = Qt.UserRole + 8
WarningDescriptionRole = Qt.UserRole + 9
ErrorDescriptionRole = Qt.UserRole + 10
GlobalOnlyRole = Qt.UserRole + 11
def __init__(self, node, parent = None):
super().__init__(parent)
self._ignore_setting_change = None
self._node = node
self._node.decoratorsChanged.connect(self._onDecoratorsChanged)
self._onDecoratorsChanged(None)
self._activeProfile = Application.getInstance().getMachineManager().getWorkingProfile() #To be able to get notified when a setting changes.
self._activeProfile.settingValueChanged.connect(self._onProfileSettingValueChanged)
Application.getInstance().getMachineManager().activeProfileChanged.connect(self._onProfileChanged)
self.addRoleName(self.KeyRole, "key")
self.addRoleName(self.LabelRole, "label")
self.addRoleName(self.DescriptionRole, "description")
self.addRoleName(self.ValueRole,"value")
self.addRoleName(self.TypeRole, "type")
self.addRoleName(self.UnitRole, "unit")
self.addRoleName(self.ValidRole, "valid")
self.addRoleName(self.OptionsRole, "options")
self.addRoleName(self.WarningDescriptionRole, "warning_description")
self.addRoleName(self.ErrorDescriptionRole, "error_description")
self.addRoleName(self.GlobalOnlyRole, "global_only")
@pyqtSlot(str, "QVariant")
def setSettingValue(self, key, value):
if not self._decorator:
return
self._decorator.setSettingValue(key, value)
def _onDecoratorsChanged(self, node):
if not self._node.getDecorator(SettingOverrideDecorator):
self.clear()
return
self._decorator = self._node.getDecorator(SettingOverrideDecorator)
self._decorator.settingAdded.connect(self._onSettingsChanged)
self._decorator.settingRemoved.connect(self._onSettingsChanged)
self._decorator.settingValueChanged.connect(self._onSettingValueChanged)
self._onSettingsChanged()
def _createOptionsModel(self, options):
if not options:
return None
model = ListModel()
model.addRoleName(Qt.UserRole + 1, "value")
model.addRoleName(Qt.UserRole + 2, "name")
for value, name in options.items():
model.appendItem({"value": str(value), "name": str(name)})
return model
## Updates the active profile in this model if the active profile is
# changed.
#
# This links the settingValueChanged of the new profile to this model's
# _onSettingValueChanged function, so that it properly listens to those
# events again.
def _onProfileChanged(self):
if self._activeProfile: #Unlink from the old profile.
self._activeProfile.settingValueChanged.disconnect(self._onProfileSettingValueChanged)
old_profile = self._activeProfile
self._activeProfile = Application.getInstance().getMachineManager().getWorkingProfile()
self._activeProfile.settingValueChanged.connect(self._onProfileSettingValueChanged) #Re-link to the new profile.
for setting_name in old_profile.getChangedSettings().keys(): #Update all changed settings in the old and new profiles.
self._onProfileSettingValueChanged(setting_name)
for setting_name in self._activeProfile.getChangedSettings().keys():
self._onProfileSettingValueChanged(setting_name)
## Updates the global_only property of a setting once a setting value
# changes.
#
# This method should only get called on settings that are dependent on the
# changed setting.
#
# \param setting_name The setting that needs to be updated.
def _onProfileSettingValueChanged(self, setting_name):
index = self.find("key", setting_name)
if index != -1:
self.setProperty(index, "global_only", Application.getInstance().getMachineManager().getActiveMachineInstance().getMachineDefinition().getSetting(setting_name).getGlobalOnly())
def _onSettingsChanged(self):
self.clear()
items = []
for key, setting in self._decorator.getAllSettings().items():
value = self._decorator.getSettingValue(key)
items.append({
"key": key,
"label": setting.getLabel(),
"description": setting.getDescription(),
"value": str(value),
"type": setting.getType(),
"unit": setting.getUnit(),
"valid": setting.validate(value),
"options": self._createOptionsModel(setting.getOptions()),
"warning_description": setting.getWarningDescription(),
"error_description": setting.getErrorDescription(),
"global_only": setting.getGlobalOnly()
})
items.sort(key = lambda i: i["key"])
for item in items:
self.appendItem(item)
def _onSettingValueChanged(self, setting):
index = self.find("key", setting.getKey())
value = self._decorator.getSettingValue(setting.getKey())
if index != -1:
self.setProperty(index, "value", str(value))
self.setProperty(index, "valid", setting.validate(value))
self.setProperty(index, "global_only", setting.getGlobalOnly())

View file

@ -2,6 +2,8 @@
# Uranium is released under the terms of the AGPLv3 or higher.
from . import PerObjectSettingsTool
from . import PerObjectSettingVisibilityHandler
from PyQt5.QtQml import qmlRegisterType
from UM.i18n import i18nCatalog
i18n_catalog = i18nCatalog("cura")
@ -13,7 +15,7 @@ def getMetaData():
"author": "Ultimaker",
"version": "1.0",
"description": i18n_catalog.i18nc("@info:whatsthis", "Provides the Per Object Settings."),
"api": 2
"api": 3
},
"tool": {
"name": i18n_catalog.i18nc("@label", "Per Object Settings"),
@ -25,4 +27,6 @@ def getMetaData():
}
def register(app):
qmlRegisterType(PerObjectSettingVisibilityHandler.PerObjectSettingVisibilityHandler, "Cura", 1, 0,
"PerObjectSettingVisibilityHandler")
return { "tool": PerObjectSettingsTool.PerObjectSettingsTool() }

View file

@ -29,17 +29,26 @@ class RemovableDriveOutputDevice(OutputDevice):
if self._writing:
raise OutputDeviceError.DeviceBusyError()
file_formats = Application.getInstance().getMeshFileHandler().getSupportedFileTypesWrite() #Formats supported by this application.
# Formats supported by this application (File types that we can actually write)
file_formats = Application.getInstance().getMeshFileHandler().getSupportedFileTypesWrite()
if filter_by_machine:
machine_file_formats = Application.getInstance().getMachineManager().getActiveMachineInstance().getMachineDefinition().getFileFormats()
file_formats = list(filter(lambda file_format: file_format["mime_type"] in machine_file_formats, file_formats)) #Take the intersection between file_formats and machine_file_formats.
container = Application.getInstance().getGlobalContainerStack().findContainer({"file_formats": "*"})
# Create a list from supported file formats string
machine_file_formats = [file_type.strip() for file_type in container.getMetaDataEntry("file_formats").split(";")]
# Take the intersection between file_formats and machine_file_formats.
file_formats = list(filter(lambda file_format: file_format["mime_type"] in machine_file_formats, file_formats))
if len(file_formats) == 0:
Logger.log("e", "There are no file formats available to write with!")
raise OutputDeviceError.WriteRequestFailedError()
writer = Application.getInstance().getMeshFileHandler().getWriterByMimeType(file_formats[0]["mime_type"]) #Just take the first file format available.
# Just take the first file format available.
writer = Application.getInstance().getMeshFileHandler().getWriterByMimeType(file_formats[0]["mime_type"])
extension = file_formats[0]["extension"]
if file_name == None:
if file_name is None:
for n in BreadthFirstIterator(node):
if n.getMeshData():
file_name = n.getName()
@ -50,7 +59,7 @@ class RemovableDriveOutputDevice(OutputDevice):
Logger.log("e", "Could not determine a proper file name when trying to write to %s, aborting", self.getName())
raise OutputDeviceError.WriteRequestFailedError()
if extension: #Not empty string.
if extension: # Not empty string.
extension = "." + extension
file_name = os.path.join(self.getId(), os.path.splitext(file_name)[0] + extension)

View file

@ -13,7 +13,7 @@ def getMetaData():
"author": "Ultimaker B.V.",
"description": catalog.i18nc("@info:whatsthis", "Provides removable drive hotplugging and writing support."),
"version": "1.0",
"api": 2
"api": 3
}
}

View file

@ -34,12 +34,10 @@ class SolidView(View):
self._disabled_shader.setUniformValue("u_diffuseColor", [0.68, 0.68, 0.68, 1.0])
self._disabled_shader.setUniformValue("u_overhangAngle", math.cos(math.radians(0)))
if Application.getInstance().getMachineManager().getWorkingProfile():
profile = Application.getInstance().getMachineManager().getWorkingProfile()
if Application.getInstance().getGlobalContainerStack():
if Preferences.getInstance().getValue("view/show_overhang"):
angle = profile.getSettingValue("support_angle")
if angle != None:
angle = Application.getInstance().getGlobalContainerStack().getProperty("support_angle", "value")
if angle is not None:
self._enabled_shader.setUniformValue("u_overhangAngle", math.cos(math.radians(90 - angle)))
else:
self._enabled_shader.setUniformValue("u_overhangAngle", math.cos(math.radians(0))) #Overhang angle of 0 causes no area at all to be marked as overhang.

View file

@ -13,7 +13,7 @@ def getMetaData():
"author": "Ultimaker",
"version": "1.0",
"description": i18n_catalog.i18nc("@info:whatsthis", "Provides a normal solid mesh view."),
"api": 2
"api": 3
},
"view": {
"name": i18n_catalog.i18nc("@item:inmenu", "Solid"),

View file

@ -256,7 +256,7 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
if not self.setBaudRate(baud_rate):
continue # Could not set the baud rate, go to the next
time.sleep(1.5) # Ensure that we are not talking to the bootloader. 1.5 sec seems to be the magic number
time.sleep(1.5) # Ensure that we are not talking to the bootloader. 1.5 seconds seems to be the magic number
sucesfull_responses = 0
timeout_time = time.time() + 5
self._serial.write(b"\n")

View file

@ -128,8 +128,18 @@ class USBPrinterOutputDeviceManager(QObject, SignalEmitter, OutputDevicePlugin,
return USBPrinterOutputDeviceManager._instance
def _getDefaultFirmwareName(self):
machine_instance = Application.getInstance().getMachineManager().getActiveMachineInstance()
machine_type = machine_instance.getMachineDefinition().getId()
# Check if there is a valid global container stack
global_container_stack = Application.getInstance().getGlobalContainerStack()
if not global_container_stack:
Logger.log("e", "There is no global container stack. Can not update firmware.")
self._firmware_view.close()
return ""
# The bottom of the containerstack is the machine definition
machine_id = global_container_stack.getBottom().id
machine_has_heated_bed = global_container_stack.getProperty("machine_heated_bed", "value")
if platform.system() == "Linux":
baudrate = 115200
else:
@ -151,23 +161,22 @@ class USBPrinterOutputDeviceManager(QObject, SignalEmitter, OutputDevicePlugin,
}
machine_with_heated_bed = {"ultimaker_original" : "MarlinUltimaker-HBK-{baudrate}.hex",
}
##TODO: Add check for multiple extruders
hex_file = None
if machine_type in machine_without_extras.keys(): # The machine needs to be defined here!
if machine_type in machine_with_heated_bed.keys() and machine_instance.getMachineSettingValue("machine_heated_bed"):
Logger.log("d", "Choosing firmware with heated bed enabled for machine %s.", machine_type)
hex_file = machine_with_heated_bed[machine_type] # Return firmware with heated bed enabled
if machine_id in machine_without_extras.keys(): # The machine needs to be defined here!
if machine_id in machine_with_heated_bed.keys() and machine_has_heated_bed:
Logger.log("d", "Choosing firmware with heated bed enabled for machine %s.", machine_id)
hex_file = machine_with_heated_bed[machine_id] # Return firmware with heated bed enabled
else:
Logger.log("d", "Choosing basic firmware for machine %s.", machine_type)
hex_file = machine_without_extras[machine_type] # Return "basic" firmware
Logger.log("d", "Choosing basic firmware for machine %s.", machine_id)
hex_file = machine_without_extras[machine_id] # Return "basic" firmware
else:
Logger.log("e", "There is no firmware for machine %s.", machine_type)
Logger.log("e", "There is no firmware for machine %s.", machine_id)
if hex_file:
return hex_file.format(baudrate=baudrate)
else:
Logger.log("e", "Could not find any firmware for machine %s.", machine_type)
Logger.log("e", "Could not find any firmware for machine %s.", machine_id)
raise FileNotFoundError()
## Helper to identify serial ports (and scan for them)
@ -223,7 +232,7 @@ class USBPrinterOutputDeviceManager(QObject, SignalEmitter, OutputDevicePlugin,
def getSerialPortList(self, only_list_usb = False):
base_list = []
if platform.system() == "Windows":
import winreg
import winreg #@UnresolvedImport
try:
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,"HARDWARE\\DEVICEMAP\\SERIALCOMM")
i = 0

View file

@ -13,7 +13,7 @@ def getMetaData():
"name": i18n_catalog.i18nc("@label", "USB printing"),
"author": "Ultimaker",
"version": "1.0",
"api": 2,
"api": 3,
"description": i18n_catalog.i18nc("@info:whatsthis","Accepts G-Code and sends them to a printer. Plugin can also update firmware.")
}
}

View file

@ -13,7 +13,7 @@ def getMetaData():
"author": "Ultimaker",
"version": "1.0",
"description": catalog.i18nc("@info:whatsthis", "Provides the X-Ray view."),
"api": 2
"api": 3
},
"view": {
"name": catalog.i18nc("@item:inlistbox", "X-Ray"),

View file

@ -0,0 +1,189 @@
# Copyright (c) 2016 Ultimaker B.V.
# Cura is released under the terms of the AGPLv3 or higher.
import math
import copy
import xml.etree.ElementTree as ET
from UM.Logger import Logger
import UM.Settings
# The namespace is prepended to the tag name but between {}.
# We are only interested in the actual tag name, so discard everything
# before the last }
def _tag_without_namespace(element):
return element.tag[element.tag.rfind("}") + 1:]
class XmlMaterialProfile(UM.Settings.InstanceContainer):
def __init__(self, container_id, *args, **kwargs):
super().__init__(container_id, *args, **kwargs)
def serialize(self):
raise NotImplementedError("Writing material profiles has not yet been implemented")
def deserialize(self, serialized):
data = ET.fromstring(serialized)
self.addMetaDataEntry("type", "material")
# TODO: Add material verfication
self.addMetaDataEntry("status", "Unknown")
metadata = data.iterfind("./um:metadata/*", self.__namespaces)
for entry in metadata:
tag_name = _tag_without_namespace(entry)
if tag_name == "name":
brand = entry.find("./um:brand", self.__namespaces)
material = entry.find("./um:material", self.__namespaces)
color = entry.find("./um:color", self.__namespaces)
self.setName("{0} {1} ({2})".format(brand.text, material.text, color.text))
self.addMetaDataEntry("brand", brand.text)
self.addMetaDataEntry("material", material.text)
self.addMetaDataEntry("color_name", color.text)
continue
self.addMetaDataEntry(tag_name, entry.text)
property_values = {}
properties = data.iterfind("./um:properties/*", self.__namespaces)
for entry in properties:
tag_name = _tag_without_namespace(entry)
property_values[tag_name] = entry.text
diameter = float(property_values.get("diameter", 2.85)) # In mm
density = float(property_values.get("density", 1.3)) # In g/cm3
weight_per_cm = (math.pi * (diameter / 20) ** 2 * 0.1) * density
spool_weight = property_values.get("spool_weight")
spool_length = property_values.get("spool_length")
if spool_weight:
length = float(spool_weight) / weight_per_cm
property_values["spool_length"] = str(length / 100)
elif spool_length:
weight = (float(spool_length) * 100) * weight_per_cm
property_values["spool_weight"] = str(weight)
self.addMetaDataEntry("properties", property_values)
self.setDefinition(UM.Settings.ContainerRegistry.getInstance().findDefinitionContainers(id = "fdmprinter")[0])
global_setting_values = {}
settings = data.iterfind("./um:settings/um:setting", self.__namespaces)
for entry in settings:
key = entry.get("key")
if key in self.__material_property_setting_map:
self.setProperty(self.__material_property_setting_map[key], "value", entry.text, self._definition)
global_setting_values[self.__material_property_setting_map[key]] = entry.text
else:
Logger.log("d", "Unsupported material setting %s", key)
machines = data.iterfind("./um:settings/um:machine", self.__namespaces)
for machine in machines:
machine_setting_values = {}
settings = machine.iterfind("./um:setting", self.__namespaces)
for entry in settings:
key = entry.get("key")
if key in self.__material_property_setting_map:
machine_setting_values[self.__material_property_setting_map[key]] = entry.text
else:
Logger.log("d", "Unsupported material setting %s", key)
identifiers = machine.iterfind("./um:machine_identifier", self.__namespaces)
for identifier in identifiers:
machine_id = self.__product_id_map.get(identifier.get("product"), None)
if machine_id is None:
Logger.log("w", "Cannot create material for unknown machine %s", machine_id)
continue
definitions = UM.Settings.ContainerRegistry.getInstance().findDefinitionContainers(id = machine_id)
if not definitions:
Logger.log("w", "No definition found for machine ID %s", machine_id)
continue
definition = definitions[0]
new_material = XmlMaterialProfile(self.id + "_" + machine_id)
new_material.setName(self.getName())
new_material.setMetaData(copy.deepcopy(self.getMetaData()))
new_material.setDefinition(definition)
for key, value in global_setting_values.items():
new_material.setProperty(key, "value", value, definition)
for key, value in machine_setting_values.items():
new_material.setProperty(key, "value", value, definition)
new_material._dirty = False
UM.Settings.ContainerRegistry.getInstance().addContainer(new_material)
hotends = machine.iterfind("./um:hotend", self.__namespaces)
for hotend in hotends:
hotend_id = hotend.get("id")
if hotend_id is None:
continue
variant_containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = hotend_id)
if not variant_containers:
# It is not really properly defined what "ID" is so also search for variants by name.
variant_containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(definition = definition.id, name = hotend_id)
if not variant_containers:
Logger.log("d", "No variants found with ID or name %s for machine %s", hotend_id, definition.id)
continue
new_hotend_material = XmlMaterialProfile(self.id + "_" + machine_id + "_" + hotend_id.replace(" ", "_"))
new_hotend_material.setName(self.getName())
new_hotend_material.setMetaData(copy.deepcopy(self.getMetaData()))
new_hotend_material.setDefinition(definition)
new_hotend_material.addMetaDataEntry("variant", variant_containers[0].id)
for key, value in global_setting_values.items():
new_hotend_material.setProperty(key, "value", value, definition)
for key, value in machine_setting_values.items():
new_hotend_material.setProperty(key, "value", value, definition)
settings = hotend.iterfind("./um:setting", self.__namespaces)
for entry in settings:
key = entry.get("key")
if key in self.__material_property_setting_map:
new_hotend_material.setProperty(self.__material_property_setting_map[key], "value", entry.text, definition)
else:
Logger.log("d", "Unsupported material setting %s", key)
new_hotend_material._dirty = False
UM.Settings.ContainerRegistry.getInstance().addContainer(new_hotend_material)
# Map XML file setting names to internal names
__material_property_setting_map = {
"print temperature": "material_print_temperature",
"heated bed temperature": "material_bed_temperature",
"standby temperature": "material_standby_temperature",
"print cooling": "cool_fan_speed",
"retraction amount": "retraction_amount",
"retraction speed": "retraction_speed",
}
# Map XML file product names to internal ids
__product_id_map = {
"Ultimaker2": "ultimaker2",
"Ultimaker2+": "ultimaker2_plus",
"Ultimaker2go": "ultimaker2_go",
"Ultimaker2extended": "ultimaker2_extended",
"Ultimaker2extended+": "ultimaker2_extended_plus",
"Ultimaker Original": "ultimaker_original",
"Ultimaker Original+": "ultimaker_original_plus"
}
__namespaces = {
"um": "http://www.ultimaker.com/material"
}

View file

@ -0,0 +1,32 @@
# Copyright (c) 2016 Ultimaker B.V.
# Cura is released under the terms of the AGPLv3 or higher.
from . import XmlMaterialProfile
from UM.MimeTypeDatabase import MimeType, MimeTypeDatabase
from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura")
def getMetaData():
return {
"plugin": {
"name": catalog.i18nc("@label", "Material Profiles"),
"author": "Ultimaker",
"version": "1.0",
"description": catalog.i18nc("@info:whatsthis", "Provides capabilities to read and write XML-based material profiles."),
"api": 3
},
"settings_container": {
"mimetype": "application/x-ultimaker-material-profile"
}
}
def register(app):
mime_type = MimeType(
name = "application/x-ultimaker-material-profile",
comment = "Ultimaker Material Profile",
suffixes = [ "xml.fdm_material" ]
)
MimeTypeDatabase.addMimeType(mime_type)
return { "settings_container": XmlMaterialProfile.XmlMaterialProfile("default_xml_material_profile") }