CURA-4870 Prepare the UI to show the list of configurations

This commit is contained in:
Diego Prado Gesto 2018-03-04 17:26:37 +01:00
parent 6e35fc5035
commit 49fcf35d9b
9 changed files with 113 additions and 100 deletions

View file

@ -1,11 +1,13 @@
# Copyright (c) 2018 Ultimaker B.V. # Copyright (c) 2018 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher. # Cura is released under the terms of the LGPLv3 or higher.
from PyQt5.QtCore import pyqtProperty, QObject from PyQt5.QtCore import pyqtProperty, QObject, pyqtSignal
class ConfigurationModel(QObject): class ConfigurationModel(QObject):
configurationChanged = pyqtSignal()
def __init__(self): def __init__(self):
self._printer_type = None self._printer_type = None
self._extruder_configurations = [] self._extruder_configurations = []
@ -21,14 +23,14 @@ class ConfigurationModel(QObject):
def setExtruderConfigurations(self, extruder_configurations): def setExtruderConfigurations(self, extruder_configurations):
self._extruder_configurations = extruder_configurations self._extruder_configurations = extruder_configurations
@pyqtProperty("QVariantList", fset = setExtruderConfigurations, constant = True) @pyqtProperty("QVariantList", fset = setExtruderConfigurations, notify = configurationChanged)
def extruderConfigurations(self): def extruderConfigurations(self):
return self._extruder_configurations return self._extruder_configurations
def setBuildplateConfiguration(self, buildplate_configuration): def setBuildplateConfiguration(self, buildplate_configuration):
self._buildplate_configuration = buildplate_configuration self._buildplate_configuration = buildplate_configuration
@pyqtProperty(str, fset = setBuildplateConfiguration, constant = True) @pyqtProperty(str, fset = setBuildplateConfiguration, notify = configurationChanged)
def buildplateConfiguration(self): def buildplateConfiguration(self):
return self._buildplate_configuration return self._buildplate_configuration

View file

@ -1,8 +1,7 @@
# Copyright (c) 2017 Ultimaker B.V. # Copyright (c) 2018 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher. # Cura is released under the terms of the LGPLv3 or higher.
from PyQt5.QtCore import pyqtSignal, pyqtProperty, QObject, QVariant, pyqtSlot from PyQt5.QtCore import pyqtSignal, pyqtProperty, QObject, pyqtSlot
from UM.Logger import Logger
from typing import Optional from typing import Optional
@ -83,7 +82,7 @@ class ExtruderOutputModel(QObject):
self._extruder_configuration = { self._extruder_configuration = {
"position": self._position, "position": self._position,
"material": self._active_material.type if self.activeMaterial is not None else None, "material": self._active_material.type if self.activeMaterial is not None else None,
"hotend_id": self._hotend_id "hotendID": self._hotend_id
} }
print("Recalculating extruder configuration:", self._extruder_configuration) print("Recalculating extruder configuration:", self._extruder_configuration)
self.extruderConfigurationChanged.emit() self.extruderConfigurationChanged.emit()

View file

@ -1,9 +1,8 @@
# Copyright (c) 2017 Ultimaker B.V. # Copyright (c) 2018 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher. # Cura is released under the terms of the LGPLv3 or higher.
from PyQt5.QtCore import pyqtSignal, pyqtProperty, QObject, QVariant, pyqtSlot from PyQt5.QtCore import pyqtSignal, pyqtProperty, QObject, QVariant, pyqtSlot
from UM.Logger import Logger from typing import Optional
from typing import Optional, List
from UM.Math.Vector import Vector from UM.Math.Vector import Vector
from cura.PrinterOutput.ConfigurationModel import ConfigurationModel from cura.PrinterOutput.ConfigurationModel import ConfigurationModel
from cura.PrinterOutput.ExtruderOutputModel import ExtruderOutputModel from cura.PrinterOutput.ExtruderOutputModel import ExtruderOutputModel
@ -42,7 +41,7 @@ class PrinterOutputModel(QObject):
self._printer_state = "unknown" self._printer_state = "unknown"
self._is_preheating = False self._is_preheating = False
self._type = "" self._type = ""
# Update the configuration every time the one of the extruders changes its configuration # Update the printer configuration every time any of the extruders changes its configuration
for extruder in self._extruders: for extruder in self._extruders:
extruder.extruderConfigurationChanged.connect(self._updatePrinterConfiguration) extruder.extruderConfigurationChanged.connect(self._updatePrinterConfiguration)

View file

@ -1,4 +1,4 @@
# Copyright (c) 2017 Ultimaker B.V. # Copyright (c) 2018 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher. # Cura is released under the terms of the LGPLv3 or higher.
from UM.i18n import i18nCatalog from UM.i18n import i18nCatalog
@ -6,13 +6,12 @@ from UM.OutputDevice.OutputDevice import OutputDevice
from PyQt5.QtCore import pyqtProperty, QObject, QTimer, pyqtSignal from PyQt5.QtCore import pyqtProperty, QObject, QTimer, pyqtSignal
from PyQt5.QtWidgets import QMessageBox from PyQt5.QtWidgets import QMessageBox
from UM.Logger import Logger from UM.Logger import Logger
from UM.Signal import signalemitter from UM.Signal import signalemitter
from UM.Application import Application from UM.Application import Application
from enum import IntEnum # For the connection state tracking. from enum import IntEnum # For the connection state tracking.
from typing import List, Optional from typing import List, Set, Optional
MYPY = False MYPY = False
if MYPY: if MYPY:
@ -46,13 +45,13 @@ class PrinterOutputDevice(QObject, OutputDevice):
connectionTextChanged = pyqtSignal() connectionTextChanged = pyqtSignal()
# Signal to indicate that the configuration of one of the printers has changed. # Signal to indicate that the configuration of one of the printers has changed.
configurationChanged = pyqtSignal() uniqueConfigurationsChanged = pyqtSignal()
def __init__(self, device_id, parent = None): def __init__(self, device_id, parent = None):
super().__init__(device_id = device_id, parent = parent) super().__init__(device_id = device_id, parent = parent)
self._printers = [] # type: List[PrinterOutputModel] self._printers = [] # type: List[PrinterOutputModel]
self._unique_configurations = [] # type: List[ConfigurationModel] self._unique_configurations = {} # type: Set[ConfigurationModel]
self._monitor_view_qml_path = "" self._monitor_view_qml_path = ""
self._monitor_component = None self._monitor_component = None
@ -182,20 +181,22 @@ class PrinterOutputDevice(QObject, OutputDevice):
self.acceptsCommandsChanged.emit() self.acceptsCommandsChanged.emit()
# Returns the unique configurations of the current printers # Returns the unique configurations of the current printers
@pyqtProperty("QVariantList", notify = configurationChanged) @pyqtProperty("QVariantMap", notify = uniqueConfigurationsChanged)
def uniqueConfiguration(self): def uniqueConfigurations(self):
return self._unique_configurations return self._unique_configurations
def _updateUniqueConfigurations(self): def _updateUniqueConfigurations(self):
print("Calculating the unique configurations") self._unique_configurations = set([printer.printerConfiguration for printer in self._printers])
self._unique_configurations = list(set([printer.printerConfiguration for printer in self._printers])) self.uniqueConfigurationsChanged.emit()
print(self._unique_configurations)
self.configurationChanged.emit()
def _onPrintersChanged(self): def _onPrintersChanged(self):
for printer in self._printers: for printer in self._printers:
printer.configurationChanged.connect(self._updateUniqueConfigurations) printer.configurationChanged.connect(self._updateUniqueConfigurations)
# If at this point the list of unique configurations is empty, we force the calculation
if not self._unique_configurations:
self._updateUniqueConfigurations()
## The current processing state of the backend. ## The current processing state of the backend.
class ConnectionState(IntEnum): class ConnectionState(IntEnum):

View file

@ -11,7 +11,7 @@ Rectangle
{ {
id: configurationItem id: configurationItem
property var printer: null property var configuration: null
signal configurationSelected() signal configurationSelected()
height: childrenRect.height height: childrenRect.height
@ -26,7 +26,7 @@ Rectangle
Label Label
{ {
text: printer.name text: configuration.printerType
} }
Row Row
@ -41,7 +41,7 @@ Rectangle
Repeater Repeater
{ {
height: childrenRect.height height: childrenRect.height
model: printer.extruders model: configuration.extruderConfigurations
delegate: PrintCoreConfiguration delegate: PrintCoreConfiguration
{ {
printCoreConfiguration: modelData printCoreConfiguration: modelData
@ -55,7 +55,7 @@ Rectangle
// //
// Label // Label
// { // {
// text: printer.name + "-" + printer.type // text: configuration.buildplateConfiguration
// } // }
// } // }
} }

View file

@ -2,7 +2,8 @@
// Cura is released under the terms of the LGPLv3 or higher. // Cura is released under the terms of the LGPLv3 or higher.
import QtQuick 2.7 import QtQuick 2.7
import QtQuick.Controls 2.0 import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
import UM 1.2 as UM import UM 1.2 as UM
import Cura 1.0 as Cura import Cura 1.0 as Cura
@ -21,12 +22,13 @@ Column
width: parent.width - 2 * parent.padding width: parent.width - 2 * parent.padding
} }
Item ScrollView {
{
id: container id: container
width: parent.width - 2 * parent.padding width: parent.width - 2 * parent.padding
height: childrenRect.height height: childrenRect.height
style: UM.Theme.styles.scrollview
Repeater { Repeater {
height: childrenRect.height height: childrenRect.height
model: outputDevice != null ? outputDevice.connectedPrintersTypeCount : null model: outputDevice != null ? outputDevice.connectedPrintersTypeCount : null
@ -42,23 +44,24 @@ Column
ListView ListView
{ {
id: grid id: configurationList
anchors.top: printerTypeHeader.bottom anchors.top: printerTypeHeader.bottom
anchors.topMargin: UM.Theme.getSize("default_margin").height anchors.topMargin: UM.Theme.getSize("default_margin").height
width: container.width width: container.width
height: childrenRect.height height: childrenRect.height
model: outputDevice.printers model: outputDevice.uniqueConfigurations
delegate: ConfigurationItem delegate: ConfigurationItem
{ {
height: parent.height height: parent.height
width: parent.width width: parent.width
printer: modelData configuration: modelData
onConfigurationSelected: onConfigurationSelected:
{ {
print("SELECCIONANDO IMPRESORA", printer.name) print("SELECCIONANDO CONFIGURACION", JSON.stringify(configuration))
outputDevice.setActivePrinter(printer)
} }
Component.onCompleted: {print("$$$$$$$$$$$$$$$$$$ Configuracion", JSON.stringify(configuration))}
} }
Component.onCompleted: {print("$$$$$$$$$$$$$$$$$$ Elementos del modelo", JSON.stringify(outputDevice.uniqueConfigurations))}
} }
} }
} }

View file

@ -2,9 +2,7 @@
// Cura is released under the terms of the LGPLv3 or higher. // Cura is released under the terms of the LGPLv3 or higher.
import QtQuick 2.7 import QtQuick 2.7
import QtQuick.Controls 1.4 import QtQuick.Controls 2.3
import QtQuick.Controls 2.3 as QQC2
import QtQuick.Layouts 1.1
import QtQuick.Controls.Styles 1.4 import QtQuick.Controls.Styles 1.4
import UM 1.2 as UM import UM 1.2 as UM
@ -15,70 +13,10 @@ Item
id: configurationSelector id: configurationSelector
property var panelWidth: control.width property var panelWidth: control.width
property var panelVisible: false property var panelVisible: false
Button
{
text: "Matched"
width: parent.width
height: parent.height
style: ButtonStyle SyncButton { }
{
background: Rectangle
{
color:
{
if(control.pressed)
{
return UM.Theme.getColor("sidebar_header_active");
}
else if(control.hovered)
{
return UM.Theme.getColor("sidebar_header_hover");
}
else
{
return UM.Theme.getColor("sidebar_header_bar");
}
}
Behavior on color { ColorAnimation { duration: 50; } }
UM.RecolorImage Popup
{
id: downArrow
anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right
anchors.rightMargin: UM.Theme.getSize("default_margin").width
width: UM.Theme.getSize("standard_arrow").width
height: UM.Theme.getSize("standard_arrow").height
sourceSize.width: width
sourceSize.height: width
color: UM.Theme.getColor("text_emphasis")
source: UM.Theme.getIcon("arrow_bottom")
}
Label
{
id: sidebarComboBoxLabel
color: UM.Theme.getColor("sidebar_header_text_active")
text: control.text
elide: Text.ElideRight
anchors.left: parent.left
anchors.leftMargin: UM.Theme.getSize("default_margin").width * 2
anchors.right: downArrow.left
anchors.rightMargin: control.rightMargin
anchors.verticalCenter: parent.verticalCenter;
font: UM.Theme.getFont("large")
}
}
label: Label {}
}
onClicked:
{
panelVisible = !panelVisible
}
}
QQC2.Popup
{ {
id: popup id: popup
y: configurationSelector.height - UM.Theme.getSize("default_lining").height y: configurationSelector.height - UM.Theme.getSize("default_lining").height

View file

@ -17,7 +17,7 @@ Item
Label Label
{ {
id: materialLabel id: materialLabel
text: printCoreConfiguration.activeMaterial != null ? printCoreConfiguration.activeMaterial.name : "" text: printCoreConfiguration.material
elide: Text.ElideRight elide: Text.ElideRight
width: parent.width width: parent.width
font: UM.Theme.getFont("very_small") font: UM.Theme.getFont("very_small")

View file

@ -0,0 +1,71 @@
// Copyright (c) 2018 Ultimaker B.V.
// Cura is released under the terms of the LGPLv3 or higher.
import QtQuick 2.7
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
import UM 1.2 as UM
Button
{
text: "Matched"
width: parent.width
height: parent.height
style: ButtonStyle
{
background: Rectangle
{
color:
{
if(control.pressed)
{
return UM.Theme.getColor("sidebar_header_active");
}
else if(control.hovered)
{
return UM.Theme.getColor("sidebar_header_hover");
}
else
{
return UM.Theme.getColor("sidebar_header_bar");
}
}
Behavior on color { ColorAnimation { duration: 50; } }
UM.RecolorImage
{
id: downArrow
anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right
anchors.rightMargin: UM.Theme.getSize("default_margin").width
width: UM.Theme.getSize("standard_arrow").width
height: UM.Theme.getSize("standard_arrow").height
sourceSize.width: width
sourceSize.height: width
color: UM.Theme.getColor("text_emphasis")
source: UM.Theme.getIcon("arrow_bottom")
}
Label
{
id: sidebarComboBoxLabel
color: UM.Theme.getColor("sidebar_header_text_active")
text: control.text
elide: Text.ElideRight
anchors.left: parent.left
anchors.leftMargin: UM.Theme.getSize("default_margin").width * 2
anchors.right: downArrow.left
anchors.rightMargin: control.rightMargin
anchors.verticalCenter: parent.verticalCenter;
font: UM.Theme.getFont("large")
}
}
label: Label {}
}
onClicked:
{
panelVisible = !panelVisible
}
}