Add a property that indicates when the layer slider or the path slider

has changed manually.

With this we can differentiate when the layer changed automatically
(during simulation) or manually (by user interaction). In case it was
changed manually, the simulation will stop.

Contributes to CURA-5725.
This commit is contained in:
Diego Prado Gesto 2018-09-17 14:02:04 +02:00
parent 2bf617b53a
commit dfae4a9a86
3 changed files with 55 additions and 16 deletions

View file

@ -39,6 +39,7 @@ Item {
property real lowerValue: minimumValue property real lowerValue: minimumValue
property bool layersVisible: true property bool layersVisible: true
property bool manuallyChanged: true // Indicates whether the value was changed manually or during simulation
function getUpperValueFromSliderHandle() { function getUpperValueFromSliderHandle() {
return upperHandle.getValue() return upperHandle.getValue()
@ -97,6 +98,7 @@ Item {
// set the new value when dragging // set the new value when dragging
function onHandleDragged() { function onHandleDragged() {
sliderRoot.manuallyChanged = true
upperHandle.y = y - upperHandle.height upperHandle.y = y - upperHandle.height
lowerHandle.y = y + height lowerHandle.y = y + height
@ -169,6 +171,7 @@ Item {
visible: sliderRoot.layersVisible visible: sliderRoot.layersVisible
function onHandleDragged() { function onHandleDragged() {
sliderRoot.manuallyChanged = true
// don't allow the lower handle to be heigher than the upper handle // don't allow the lower handle to be heigher than the upper handle
if (lowerHandle.y - (y + height) < sliderRoot.minimumRangeHandleSize) { if (lowerHandle.y - (y + height) < sliderRoot.minimumRangeHandleSize) {
@ -205,8 +208,16 @@ Item {
sliderRoot.updateRangeHandle() sliderRoot.updateRangeHandle()
} }
Keys.onUpPressed: upperHandleLabel.setValue(upperHandleLabel.value + ((event.modifiers & Qt.ShiftModifier) ? 10 : 1)) Keys.onUpPressed:
Keys.onDownPressed: upperHandleLabel.setValue(upperHandleLabel.value - ((event.modifiers & Qt.ShiftModifier) ? 10 : 1)) {
sliderRoot.manuallyChanged = true
upperHandleLabel.setValue(upperHandleLabel.value + ((event.modifiers & Qt.ShiftModifier) ? 10 : 1))
}
Keys.onDownPressed:
{
sliderRoot.manuallyChanged = true
upperHandleLabel.setValue(upperHandleLabel.value - ((event.modifiers & Qt.ShiftModifier) ? 10 : 1))
}
// dragging // dragging
MouseArea { MouseArea {
@ -257,6 +268,7 @@ Item {
visible: sliderRoot.layersVisible visible: sliderRoot.layersVisible
function onHandleDragged() { function onHandleDragged() {
sliderRoot.manuallyChanged = true
// don't allow the upper handle to be lower than the lower handle // don't allow the upper handle to be lower than the lower handle
if (y - (upperHandle.y + upperHandle.height) < sliderRoot.minimumRangeHandleSize) { if (y - (upperHandle.y + upperHandle.height) < sliderRoot.minimumRangeHandleSize) {

View file

@ -34,6 +34,7 @@ Item {
property real handleValue: maximumValue property real handleValue: maximumValue
property bool pathsVisible: true property bool pathsVisible: true
property bool manuallyChanged: true // Indicates whether the value was changed manually or during simulation
function getHandleValueFromSliderHandle () { function getHandleValueFromSliderHandle () {
return handle.getValue() return handle.getValue()
@ -97,6 +98,7 @@ Item {
visible: sliderRoot.pathsVisible visible: sliderRoot.pathsVisible
function onHandleDragged () { function onHandleDragged () {
sliderRoot.manuallyChanged = true
// update the range handle // update the range handle
sliderRoot.updateRangeHandle() sliderRoot.updateRangeHandle()
@ -128,8 +130,16 @@ Item {
sliderRoot.updateRangeHandle() sliderRoot.updateRangeHandle()
} }
Keys.onRightPressed: handleLabel.setValue(handleLabel.value + ((event.modifiers & Qt.ShiftModifier) ? 10 : 1)) Keys.onRightPressed:
Keys.onLeftPressed: handleLabel.setValue(handleLabel.value - ((event.modifiers & Qt.ShiftModifier) ? 10 : 1)) {
sliderRoot.manuallyChanged = true
handleLabel.setValue(handleLabel.value + ((event.modifiers & Qt.ShiftModifier) ? 10 : 1))
}
Keys.onLeftPressed:
{
sliderRoot.manuallyChanged = true
handleLabel.setValue(handleLabel.value - ((event.modifiers & Qt.ShiftModifier) ? 10 : 1))
}
// dragging // dragging
MouseArea { MouseArea {

View file

@ -623,7 +623,15 @@ Item
{ {
target: UM.SimulationView target: UM.SimulationView
onMaxPathsChanged: pathSlider.setHandleValue(UM.SimulationView.currentPath) onMaxPathsChanged: pathSlider.setHandleValue(UM.SimulationView.currentPath)
onCurrentPathChanged: pathSlider.setHandleValue(UM.SimulationView.currentPath) onCurrentPathChanged:
{
// Only pause the simulation when the layer was changed manually, not when the simulation is running
if (pathSlider.manuallyChanged)
{
playButton.pauseSimulation()
}
pathSlider.setHandleValue(UM.SimulationView.currentPath)
}
} }
// make sure the slider handlers show the correct value after switching views // make sure the slider handlers show the correct value after switching views
@ -667,9 +675,14 @@ Item
{ {
target: UM.SimulationView target: UM.SimulationView
onMaxLayersChanged: layerSlider.setUpperValue(UM.SimulationView.currentLayer) onMaxLayersChanged: layerSlider.setUpperValue(UM.SimulationView.currentLayer)
onMinimumLayerChanged: layerSlider.setLowerValue(UM.SimulationView.minimumLayer)
onCurrentLayerChanged: onCurrentLayerChanged:
{
// Only pause the simulation when the layer was changed manually, not when the simulation is running
if (layerSlider.manuallyChanged)
{ {
playButton.pauseSimulation() playButton.pauseSimulation()
}
layerSlider.setUpperValue(UM.SimulationView.currentLayer) layerSlider.setUpperValue(UM.SimulationView.currentLayer)
} }
} }
@ -719,6 +732,8 @@ Item
iconSource = "./resources/simulation_resume.svg" iconSource = "./resources/simulation_resume.svg"
simulationTimer.stop() simulationTimer.stop()
status = 0 status = 0
layerSlider.manuallyChanged = true
pathSlider.manuallyChanged = true
} }
function resumeSimulation() function resumeSimulation()
@ -726,7 +741,8 @@ Item
UM.SimulationView.setSimulationRunning(true) UM.SimulationView.setSimulationRunning(true)
iconSource = "./resources/simulation_pause.svg" iconSource = "./resources/simulation_pause.svg"
simulationTimer.start() simulationTimer.start()
status = 1 layerSlider.manuallyChanged = false
pathSlider.manuallyChanged = false
} }
} }
@ -770,7 +786,6 @@ Item
{ {
UM.SimulationView.setCurrentLayer(currentLayer+1) UM.SimulationView.setCurrentLayer(currentLayer+1)
UM.SimulationView.setCurrentPath(0) UM.SimulationView.setCurrentPath(0)
playButton.resumeSimulation()
} }
} }
else else
@ -778,6 +793,8 @@ Item
UM.SimulationView.setCurrentPath(currentPath+1) UM.SimulationView.setCurrentPath(currentPath+1)
} }
} }
// The status must be set here instead of in the resumeSimulation function otherwise it won't work
// correctly, because part of the logic is in this trigger function.
playButton.status = 1 playButton.status = 1
} }
} }