Added extruder count detection to layer view. CURA-3273

This commit is contained in:
Jack Ha 2017-01-30 13:29:35 +01:00
parent 5f6ed488d1
commit 5a2aa8846b
4 changed files with 54 additions and 10 deletions

View file

@ -50,6 +50,7 @@ class ExtruderManager(QObject):
except KeyError: # Extruder index could be -1 if the global tab is selected, or the entry doesn't exist if the machine definition is wrong. except KeyError: # Extruder index could be -1 if the global tab is selected, or the entry doesn't exist if the machine definition is wrong.
return None return None
## Return extruder count according to extruder trains.
@pyqtProperty(int, notify = extrudersChanged) @pyqtProperty(int, notify = extrudersChanged)
def extruderCount(self): def extruderCount(self):
if not UM.Application.getInstance().getGlobalContainerStack(): if not UM.Application.getInstance().getGlobalContainerStack():

View file

@ -18,6 +18,7 @@ from UM.Message import Message
from UM.Application import Application from UM.Application import Application
from cura.ConvexHullNode import ConvexHullNode from cura.ConvexHullNode import ConvexHullNode
from cura.Settings.ExtruderManager import ExtruderManager
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication from PyQt5.QtWidgets import QApplication
@ -59,13 +60,7 @@ class LayerView(View):
self._proxy = LayerViewProxy.LayerViewProxy() self._proxy = LayerViewProxy.LayerViewProxy()
self._controller.getScene().getRoot().childrenChanged.connect(self._onSceneChanged) self._controller.getScene().getRoot().childrenChanged.connect(self._onSceneChanged)
self._layer_view_type = 0 # 0 is material color, 1 is color by linetype, 2 is speed self._resetSettings()
self._extruder_opacity = [1.0, 1.0, 1.0, 1.0]
self._show_travel_moves = 0
self._show_support = 1
self._show_adhesion = 1
self._show_skin = 1
self._show_infill = 1
self._legend_items = None self._legend_items = None
Preferences.getInstance().addPreference("view/top_layer_count", 5) Preferences.getInstance().addPreference("view/top_layer_count", 5)
@ -80,6 +75,16 @@ class LayerView(View):
self._wireprint_warning_message = Message(catalog.i18nc("@info:status", "Cura does not accurately display layers when Wire Printing is enabled")) self._wireprint_warning_message = Message(catalog.i18nc("@info:status", "Cura does not accurately display layers when Wire Printing is enabled"))
def _resetSettings(self):
self._layer_view_type = 0 # 0 is material color, 1 is color by linetype, 2 is speed
self._extruder_count = 0
self._extruder_opacity = [1.0, 1.0, 1.0, 1.0]
self._show_travel_moves = 0
self._show_support = 1
self._show_adhesion = 1
self._show_skin = 1
self._show_infill = 1
def getActivity(self): def getActivity(self):
return self._activity return self._activity
@ -211,6 +216,9 @@ class LayerView(View):
def getCompatibilityMode(self): def getCompatibilityMode(self):
return self._compatibility_mode return self._compatibility_mode
def getExtruderCount(self):
return self._extruder_count
def calculateMaxLayers(self): def calculateMaxLayers(self):
scene = self.getController().getScene() scene = self.getController().getScene()
self._activity = True self._activity = True
@ -242,6 +250,7 @@ class LayerView(View):
maxLayersChanged = Signal() maxLayersChanged = Signal()
currentLayerNumChanged = Signal() currentLayerNumChanged = Signal()
globalStackChanged = Signal()
## Hackish way to ensure the proxy is already created, which ensures that the layerview.qml is already created ## Hackish way to ensure the proxy is already created, which ensures that the layerview.qml is already created
# as this caused some issues. # as this caused some issues.
@ -302,7 +311,9 @@ class LayerView(View):
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._onPropertyChanged) self._global_container_stack.propertyChanged.connect(self._onPropertyChanged)
self._extruder_count = self._global_container_stack.getProperty("machine_extruder_count", "value")
self._onPropertyChanged("wireframe_enabled", "value") self._onPropertyChanged("wireframe_enabled", "value")
self.globalStackChanged.emit()
else: else:
self._wireprint_warning_message.hide() self._wireprint_warning_message.hide()

View file

@ -203,7 +203,7 @@ Item
UM.LayerView.setExtruderOpacity(0, checked ? 1.0 : 0.0); UM.LayerView.setExtruderOpacity(0, checked ? 1.0 : 0.0);
} }
text: "Extruder 1" text: "Extruder 1"
visible: !UM.LayerView.compatibilityMode visible: !UM.LayerView.compatibilityMode && (UM.LayerView.getExtruderCount >= 1)
} }
CheckBox { CheckBox {
checked: true checked: true
@ -211,7 +211,27 @@ Item
UM.LayerView.setExtruderOpacity(1, checked ? 1.0 : 0.0); UM.LayerView.setExtruderOpacity(1, checked ? 1.0 : 0.0);
} }
text: "Extruder 2" text: "Extruder 2"
visible: !UM.LayerView.compatibilityMode visible: !UM.LayerView.compatibilityMode && (UM.LayerView.getExtruderCount >= 2)
}
CheckBox {
checked: true
onClicked: {
UM.LayerView.setExtruderOpacity(2, checked ? 1.0 : 0.0);
}
text: "Extruder 3"
visible: !UM.LayerView.compatibilityMode && (UM.LayerView.getExtruderCount >= 3)
}
CheckBox {
checked: true
onClicked: {
UM.LayerView.setExtruderOpacity(3, checked ? 1.0 : 0.0);
}
text: "Extruder 4"
visible: !UM.LayerView.compatibilityMode && (UM.LayerView.getExtruderCount >= 4)
}
Label {
text: "Other extruders always visible"
visible: !UM.LayerView.compatibilityMode && (UM.LayerView.getExtruderCount >= 5)
} }
CheckBox { CheckBox {
onClicked: { onClicked: {

View file

@ -16,6 +16,7 @@ class LayerViewProxy(QObject):
currentLayerChanged = pyqtSignal() currentLayerChanged = pyqtSignal()
maxLayersChanged = pyqtSignal() maxLayersChanged = pyqtSignal()
activityChanged = pyqtSignal() activityChanged = pyqtSignal()
globalStackChanged = pyqtSignal()
@pyqtProperty(bool, notify = activityChanged) @pyqtProperty(bool, notify = activityChanged)
def getLayerActivity(self): def getLayerActivity(self):
@ -121,6 +122,13 @@ class LayerViewProxy(QObject):
if type(active_view) == LayerView.LayerView.LayerView: if type(active_view) == LayerView.LayerView.LayerView:
active_view.setShowInfill(show) active_view.setShowInfill(show)
@pyqtProperty(int, notify = globalStackChanged)
def getExtruderCount(self):
active_view = self._controller.getActiveView()
if type(active_view) == LayerView.LayerView.LayerView:
return active_view.getExtruderCount()
return 0
def _layerActivityChanged(self): def _layerActivityChanged(self):
self.activityChanged.emit() self.activityChanged.emit()
@ -134,9 +142,13 @@ class LayerViewProxy(QObject):
def _onBusyChanged(self): def _onBusyChanged(self):
self.busyChanged.emit() self.busyChanged.emit()
def _onGlobalStackChanged(self):
self.globalStackChanged.emit()
def _onActiveViewChanged(self): def _onActiveViewChanged(self):
active_view = self._controller.getActiveView() active_view = self._controller.getActiveView()
if type(active_view) == LayerView.LayerView.LayerView: if type(active_view) == LayerView.LayerView.LayerView:
active_view.currentLayerNumChanged.connect(self._onLayerChanged) active_view.currentLayerNumChanged.connect(self._onLayerChanged)
active_view.maxLayersChanged.connect(self._onMaxLayersChanged) active_view.maxLayersChanged.connect(self._onMaxLayersChanged)
active_view.busyChanged.connect(self._onBusyChanged) active_view.busyChanged.connect(self._onBusyChanged)
active_view.globalStackChanged.connect(self._onGlobalStackChanged)