CURA-4425 first thumbnail in UFP file; updated CuraSceneModel and PreviewPass

This commit is contained in:
Jack Ha 2018-01-31 17:08:32 +01:00
parent 2fe9860bb9
commit c42f186812
4 changed files with 189 additions and 14 deletions

View file

@ -1,7 +1,10 @@
from typing import List
from UM.Application import Application
from UM.Logger import Logger
from UM.Scene.SceneNode import SceneNode
from copy import deepcopy
from cura.Settings.ExtrudersModel import ExtrudersModel
## Scene nodes that are models are only seen when selecting the corresponding build plate
@ -23,6 +26,75 @@ class CuraSceneNode(SceneNode):
def isSelectable(self) -> bool:
return super().isSelectable() and self.callDecoration("getBuildPlateNumber") == Application.getInstance().getBuildPlateModel().activeBuildPlate
def getPrintingExtruderPosition(self) -> int:
# took bits and pieces from extruders model, solid view
global_container_stack = Application.getInstance().getGlobalContainerStack()
per_mesh_stack = self.callDecoration("getStack")
# It's only set if you explicitly choose an extruder
extruder_id = self.callDecoration("getActiveExtruder")
machine_extruder_count = global_container_stack.getProperty("machine_extruder_count", "value")
extruder_index = 0
for extruder in Application.getInstance().getExtruderManager().getMachineExtruders(global_container_stack.getId()):
position = extruder.getMetaDataEntry("position", default = "0") # Get the position
try:
position = int(position)
except ValueError:
# Not a proper int.
position = -1
if position > machine_extruder_count:
continue
# Find out the extruder index if we know the id.
if extruder_id is not None and extruder_id == extruder.getId():
extruder_index = position
break
# Use the support extruder instead of the active extruder if this is a support_mesh
if per_mesh_stack:
if per_mesh_stack.getProperty("support_mesh", "value"):
extruder_index = int(global_container_stack.getProperty("support_extruder_nr", "value"))
return extruder_index
def getDiffuseColor(self) -> List[float]:
# took bits and pieces from extruders model, solid view
global_container_stack = Application.getInstance().getGlobalContainerStack()
machine_extruder_count = global_container_stack.getProperty("machine_extruder_count", "value")
extruder_index = self.getPrintingExtruderPosition()
material_color = ExtrudersModel.defaultColors[extruder_index]
# Collect color from the extruder we want
for extruder in Application.getInstance().getExtruderManager().getMachineExtruders(global_container_stack.getId()):
position = extruder.getMetaDataEntry("position", default = "0") # Get the position
try:
position = int(position)
except ValueError:
# Not a proper int.
position = -1
if position > machine_extruder_count:
continue
if extruder.material and position == extruder_index:
material_color = extruder.material.getMetaDataEntry("color_code", default = material_color)
break
# Colors are passed as rgb hex strings (eg "#ffffff"), and the shader needs
# an rgba list of floats (eg [1.0, 1.0, 1.0, 1.0])
return [
int(material_color[1:3], 16) / 255,
int(material_color[3:5], 16) / 255,
int(material_color[5:7], 16) / 255,
1.0
]
## Taken from SceneNode, but replaced SceneNode with CuraSceneNode
def __deepcopy__(self, memo):
copy = CuraSceneNode()