Plots to kotlin. Multiple fixes to control.

This commit is contained in:
Alexander Nozik 2018-04-02 11:01:34 +03:00
parent d708afa5de
commit 0085ff3142
7 changed files with 70 additions and 79 deletions

View File

@ -190,7 +190,7 @@ class PKT8Display : DeviceDisplay<PKT8Device>(), PKT8ValueListener {
if (rawDataButton.isSelected) { if (rawDataButton.isSelected) {
TimePlot.put(this, rawValue) TimePlot.put(this, rawValue)
} else { } else {
if(temperature != null) { if (temperature != null) {
TimePlot.put(this, temperature) TimePlot.put(this, temperature)
} }
} }
@ -201,16 +201,13 @@ class PKT8Display : DeviceDisplay<PKT8Device>(), PKT8ValueListener {
} }
private fun getPlot(channelName: String): Plot? { private fun getPlot(channelName: String): Plot? {
return if (plotFrame.plots.has(channelName)) { return plotFrame[channelName] ?: device.channels.values.find { it.name == channelName }?.let {
plotFrame.get(channelName)
} else {
device.channels.values.find { it.name == channelName }?.let {
TimePlot(it.name).apply { TimePlot(it.name).apply {
configure(it.meta) configure(it.meta)
plotFrame.add(this) plotFrame.add(this)
} }
} }
}
} }
private fun clearPlot() { private fun clearPlot() {

View File

@ -70,7 +70,7 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
var filament by valueState("filament") { old, value -> var filament by valueState("filament") { old, value ->
selectFilament(value.intValue()) selectFilament(value.intValue())
} }.int
var filamentOn: Boolean by valueState("filamentOn") { _, value -> var filamentOn: Boolean by valueState("filamentOn") { _, value ->
setFilamentOn(value.booleanValue()) setFilamentOn(value.booleanValue())

View File

@ -28,6 +28,8 @@ import hep.dataforge.plots.PlotFrame
import hep.dataforge.plots.PlotGroup import hep.dataforge.plots.PlotGroup
import hep.dataforge.plots.PlotUtils import hep.dataforge.plots.PlotUtils
import hep.dataforge.plots.data.TimePlot import hep.dataforge.plots.data.TimePlot
import hep.dataforge.plots.data.TimePlot.Companion.setMaxItems
import hep.dataforge.plots.data.TimePlot.Companion.setPrefItems
import hep.dataforge.plots.jfreechart.JFreeChartFrame import hep.dataforge.plots.jfreechart.JFreeChartFrame
import hep.dataforge.values.Value import hep.dataforge.values.Value
import inr.numass.control.DeviceDisplay import inr.numass.control.DeviceDisplay
@ -84,24 +86,21 @@ class MspDisplay() : DeviceDisplay<MspDevice>(), DeviceListener, NamedValueListe
JFreeChartFrame(basePlotConfig).apply { JFreeChartFrame(basePlotConfig).apply {
PlotUtils.setXAxis(this, "timestamp", null, "time") PlotUtils.setXAxis(this, "timestamp", "", "time")
configure(plotFrameMeta) configure(plotFrameMeta)
} }
} }
val plottables = PlotGroup("peakJump").apply { val plottables = PlotGroup.typed<TimePlot>("peakJump").apply {
setMaxItems(this, 1000)
setPrefItems(this, 400)
if (plotFrameMeta.hasMeta("peakJump.peak")) { if (plotFrameMeta.hasMeta("peakJump.peak")) {
for (peakMeta in plotFrameMeta.getMetaList("peakJump.peak")) { for (peakMeta in plotFrameMeta.getMetaList("peakJump.peak")) {
val mass = peakMeta.getString("mass") val mass = peakMeta.getString("mass")
if (!this.has(mass)) { get(mass) ?: TimePlot(mass, mass).also {
val newPlottable = TimePlot(mass, mass) it.configureValue("titleBase", peakMeta.getString("title", mass))
newPlottable.configure(peakMeta) add(it)
newPlottable.setMaxItems(1000) }.configure(peakMeta)
newPlottable.setPrefItems(400)
newPlottable.configureValue("titleBase", peakMeta.getString("title", mass))
add(newPlottable)
} else {
get(mass).configure(peakMeta)
}
} }
} else { } else {
showError("No peaks defined in config") showError("No peaks defined in config")
@ -117,7 +116,7 @@ class MspDisplay() : DeviceDisplay<MspDevice>(), DeviceListener, NamedValueListe
addListener { _, oldValue, newValue -> addListener { _, oldValue, newValue ->
if (newValue != oldValue) { if (newValue != oldValue) {
runAsync { runAsync {
device.setState("filament", newValue); device.filament = newValue
} }
} }
} }
@ -133,13 +132,12 @@ class MspDisplay() : DeviceDisplay<MspDevice>(), DeviceListener, NamedValueListe
cellFormat { cellFormat {
text = "Filament $it" text = "Filament $it"
} }
disableProperty() disableProperty().bind(getBooleanBinding(PortSensor.CONNECTED_STATE).not())
.bind(getBooleanStateBinding(PortSensor.CONNECTED_STATE).not())
} }
switch { switch {
padding = Insets(5.0, 0.0, 0.0, 0.0) padding = Insets(5.0, 0.0, 0.0, 0.0)
disableProperty() disableProperty()
.bind(getStateBinding(PortSensor.CONNECTED_STATE).booleanBinding { !it!!.booleanValue() }) .bind(getBooleanBinding(PortSensor.CONNECTED_STATE))
bindBooleanToState("filamentOn", selectedProperty()) bindBooleanToState("filamentOn", selectedProperty())
} }
deviceStateIndicator(this@MspDisplay, "filamentStatus", false) { deviceStateIndicator(this@MspDisplay, "filamentStatus", false) {
@ -154,15 +152,13 @@ class MspDisplay() : DeviceDisplay<MspDevice>(), DeviceListener, NamedValueListe
togglebutton("Measure") { togglebutton("Measure") {
isSelected = false isSelected = false
disableProperty() disableProperty().bind(getBooleanBinding(PortSensor.CONNECTED_STATE).not())
.bind(getStateBinding(PortSensor.CONNECTED_STATE).booleanBinding { !it!!.booleanValue() })
bindBooleanToState(Sensor.MEASURING_STATE, selectedProperty()) bindBooleanToState(Sensor.MEASURING_STATE, selectedProperty())
} }
togglebutton("Store") { togglebutton("Store") {
isSelected = false isSelected = false
disableProperty() disableProperty().bind(getBooleanBinding(Sensor.MEASURING_STATE).not())
.bind(getStateBinding(Sensor.MEASURING_STATE).booleanBinding { !it!!.booleanValue() })
bindBooleanToState("storing", selectedProperty()) bindBooleanToState("storing", selectedProperty())
} }
separator(Orientation.VERTICAL) separator(Orientation.VERTICAL)
@ -187,7 +183,7 @@ class MspDisplay() : DeviceDisplay<MspDevice>(), DeviceListener, NamedValueListe
init { init {
table.addListener { change: MapChangeListener.Change<out String, out Value> -> table.addListener { change: MapChangeListener.Change<out String, out Value> ->
if (change.wasAdded()) { if (change.wasAdded()) {
val pl = plottables.get(change.key) val pl = plottables[change.key] as TimePlot?
val value = change.valueAdded val value = change.valueAdded
if (pl != null) { if (pl != null) {
if (value.doubleValue() > 0) { if (value.doubleValue() > 0) {

View File

@ -11,6 +11,7 @@ import hep.dataforge.fx.bindWindow
import hep.dataforge.states.State import hep.dataforge.states.State
import hep.dataforge.states.ValueState import hep.dataforge.states.ValueState
import hep.dataforge.values.Value import hep.dataforge.values.Value
import javafx.beans.binding.BooleanBinding
import javafx.beans.binding.ObjectBinding import javafx.beans.binding.ObjectBinding
import javafx.beans.property.BooleanProperty import javafx.beans.property.BooleanProperty
import javafx.beans.property.SimpleObjectProperty import javafx.beans.property.SimpleObjectProperty
@ -99,6 +100,10 @@ abstract class DeviceDisplay<D : Device> : Component(), Connection, DeviceListen
return bindState(state) return bindState(state)
} }
fun getBooleanBinding(stateName: String): BooleanBinding{
return getValueBinding(stateName).booleanBinding{it?.booleanValue()?:false}
}
/** /**
* Bind existing boolean property to writable device state * Bind existing boolean property to writable device state

View File

@ -5,14 +5,8 @@
*/ */
package inr.numass.control.readvac package inr.numass.control.readvac
import hep.dataforge.control.devices.Device
import hep.dataforge.control.devices.PortSensor.Companion.CONNECTED_STATE import hep.dataforge.control.devices.PortSensor.Companion.CONNECTED_STATE
import hep.dataforge.control.devices.Sensor import hep.dataforge.control.devices.Sensor
import hep.dataforge.kodex.stringValue
import hep.dataforge.kodex.timeValue
import hep.dataforge.kodex.value
import hep.dataforge.meta.Meta
import hep.dataforge.values.Value
import inr.numass.control.DeviceDisplay import inr.numass.control.DeviceDisplay
import inr.numass.control.switch import inr.numass.control.switch
import javafx.application.Platform import javafx.application.Platform
@ -66,31 +60,34 @@ open class VacDisplay : DeviceDisplay<Sensor>() {
} }
} }
override fun notifyMetaStateChanged(device: Device, name: String, state: Meta) { // override fun notifyMetaStateChanged(device: Device, name: String, state: Meta) {
super.notifyMetaStateChanged(device, name, state) // super.notifyMetaStateChanged(device, name, state)
//
// when (name) {
// Sensor.MEASUREMENT_RESULT_STATE -> {
// if(state.getBoolean(Sensor.RESULT_SUCCESS)) {
// val res by state.value(Sensor.RESULT_VALUE)
// val time by state.timeValue(Sensor.RESULT_TIMESTAMP)
// onResult(res, time)
// } else{
// Platform.runLater {
// value = "Err"
// }
// }
// }
// Sensor.MEASUREMENT_ERROR_STATE -> {
// val message by state.stringValue("message")
// message(message)
// }
// }
// }
//
// override fun notifyStateChanged(device: Device, name: String, state: Any?) {
// super.notifyStateChanged(device, name, state)
// }
when (name) {
Sensor.MEASUREMENT_RESULT_STATE -> {
if(state.getBoolean(Sensor.RESULT_SUCCESS)) {
val res by state.value(Sensor.RESULT_VALUE)
val time by state.timeValue(Sensor.RESULT_TIMESTAMP)
onResult(res, time)
} else{
Platform.runLater {
value = "Err"
}
}
}
Sensor.MEASUREMENT_ERROR_STATE -> {
val message by state.stringValue("message")
message(message)
}
}
}
override fun notifyStateChanged(device: Device, name: String, state: Value) {
super.notifyStateChanged(device, name, state)
}
fun getTitle(): String { fun getTitle(): String {
return device.meta.getString("title", device.name); return device.meta.getString("title", device.name);
@ -158,7 +155,7 @@ open class VacDisplay : DeviceDisplay<Sensor>() {
} }
} }
} }
if (device.hasState("power")) { if (device.stateNames.contains("power")) {
separator(Orientation.HORIZONTAL) separator(Orientation.HORIZONTAL)
pane { pane {
minHeight = 30.0 minHeight = 30.0

View File

@ -6,6 +6,7 @@ import hep.dataforge.fx.runGoal
import hep.dataforge.fx.ui import hep.dataforge.fx.ui
import hep.dataforge.kodex.configure import hep.dataforge.kodex.configure
import hep.dataforge.plots.PlotFrame import hep.dataforge.plots.PlotFrame
import hep.dataforge.plots.data.DataPlot
import hep.dataforge.plots.data.TimePlot import hep.dataforge.plots.data.TimePlot
import hep.dataforge.plots.jfreechart.JFreeChartFrame import hep.dataforge.plots.jfreechart.JFreeChartFrame
import inr.numass.data.api.NumassSet import inr.numass.data.api.NumassSet
@ -25,6 +26,15 @@ class HVView : View(title = "High voltage time plot", icon = ImageView(dfIcon))
"xAxis.title" to "time" "xAxis.title" to "time"
"xAxis.type" to "time" "xAxis.type" to "time"
"yAxis.title" to "HV" "yAxis.title" to "HV"
}.apply {
plots.configure {
"connectionType" to "step"
"thickness" to 2
"showLine" to true
"showSymbol" to false
"showErrors" to false
}
plots.setType(DataPlot::class)
} }
private val container = PlotContainer(frame); private val container = PlotContainer(frame);
@ -47,17 +57,7 @@ class HVView : View(title = "High voltage time plot", icon = ImageView(dfIcon))
} ui { hvData -> } ui { hvData ->
hvData.ifPresent { hvData.ifPresent {
for (dp in it) { for (dp in it) {
//val blockName = dp.getString("block", "default").replace(".", "_"); val plot: TimePlot = frame[change.key] as TimePlot? ?: TimePlot(change.key).apply { frame.add(this) }
//val opt = frame.opt(blockName)
val plot = frame.opt(change.key).orElseGet {
TimePlot(change.key).configure {
"connectionType" to "step"
"thickness" to 2
"showLine" to true
"showSymbol" to false
"showErrors" to false
}.apply { frame.add(this) }
} as TimePlot;
plot.put(dp.getValue("timestamp").timeValue(), dp.getValue("value")) plot.put(dp.getValue("timestamp").timeValue(), dp.getValue("value"))
} }
} }
@ -77,7 +77,7 @@ class HVView : View(title = "High voltage time plot", icon = ImageView(dfIcon))
data.remove(id); data.remove(id);
} }
fun clear(){ fun clear() {
data.clear() data.clear()
} }

View File

@ -165,11 +165,7 @@ class SpectrumView(
val totalProgress = data.values.stream().mapToLong() { it.points.count() }.sum() val totalProgress = data.values.stream().mapToLong() { it.points.count() }.sum()
data.forEach { name, set -> data.forEach { name, set ->
val plot = frame.opt(name).orElseGet { val plot: DataPlot = frame[name] as DataPlot? ?: DataPlot(name).apply { frame.add(this) }
DataPlot(name).apply {
frame.add(this)
}
} as DataPlot
runGoal("spectrumData[$name]") { runGoal("spectrumData[$name]") {
set.points.map { point -> set.points.map { point ->
@ -200,7 +196,7 @@ class SpectrumView(
data.remove(key) data.remove(key)
} }
fun clear(){ fun clear() {
data.clear() data.clear()
} }
} }