Plots to kotlin. Multiple fixes to control.
This commit is contained in:
parent
d708afa5de
commit
0085ff3142
@ -190,7 +190,7 @@ class PKT8Display : DeviceDisplay<PKT8Device>(), PKT8ValueListener {
|
||||
if (rawDataButton.isSelected) {
|
||||
TimePlot.put(this, rawValue)
|
||||
} else {
|
||||
if(temperature != null) {
|
||||
if (temperature != null) {
|
||||
TimePlot.put(this, temperature)
|
||||
}
|
||||
}
|
||||
@ -201,16 +201,13 @@ class PKT8Display : DeviceDisplay<PKT8Device>(), PKT8ValueListener {
|
||||
}
|
||||
|
||||
private fun getPlot(channelName: String): Plot? {
|
||||
return if (plotFrame.plots.has(channelName)) {
|
||||
plotFrame.get(channelName)
|
||||
} else {
|
||||
device.channels.values.find { it.name == channelName }?.let {
|
||||
TimePlot(it.name).apply {
|
||||
configure(it.meta)
|
||||
plotFrame.add(this)
|
||||
}
|
||||
return plotFrame[channelName] ?: device.channels.values.find { it.name == channelName }?.let {
|
||||
TimePlot(it.name).apply {
|
||||
configure(it.meta)
|
||||
plotFrame.add(this)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun clearPlot() {
|
||||
|
@ -70,7 +70,7 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
|
||||
|
||||
var filament by valueState("filament") { old, value ->
|
||||
selectFilament(value.intValue())
|
||||
}
|
||||
}.int
|
||||
|
||||
var filamentOn: Boolean by valueState("filamentOn") { _, value ->
|
||||
setFilamentOn(value.booleanValue())
|
||||
|
@ -28,6 +28,8 @@ import hep.dataforge.plots.PlotFrame
|
||||
import hep.dataforge.plots.PlotGroup
|
||||
import hep.dataforge.plots.PlotUtils
|
||||
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.values.Value
|
||||
import inr.numass.control.DeviceDisplay
|
||||
@ -84,24 +86,21 @@ class MspDisplay() : DeviceDisplay<MspDevice>(), DeviceListener, NamedValueListe
|
||||
|
||||
|
||||
JFreeChartFrame(basePlotConfig).apply {
|
||||
PlotUtils.setXAxis(this, "timestamp", null, "time")
|
||||
PlotUtils.setXAxis(this, "timestamp", "", "time")
|
||||
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")) {
|
||||
for (peakMeta in plotFrameMeta.getMetaList("peakJump.peak")) {
|
||||
val mass = peakMeta.getString("mass")
|
||||
if (!this.has(mass)) {
|
||||
val newPlottable = TimePlot(mass, mass)
|
||||
newPlottable.configure(peakMeta)
|
||||
newPlottable.setMaxItems(1000)
|
||||
newPlottable.setPrefItems(400)
|
||||
newPlottable.configureValue("titleBase", peakMeta.getString("title", mass))
|
||||
add(newPlottable)
|
||||
} else {
|
||||
get(mass).configure(peakMeta)
|
||||
}
|
||||
get(mass) ?: TimePlot(mass, mass).also {
|
||||
it.configureValue("titleBase", peakMeta.getString("title", mass))
|
||||
add(it)
|
||||
}.configure(peakMeta)
|
||||
}
|
||||
} else {
|
||||
showError("No peaks defined in config")
|
||||
@ -117,7 +116,7 @@ class MspDisplay() : DeviceDisplay<MspDevice>(), DeviceListener, NamedValueListe
|
||||
addListener { _, oldValue, newValue ->
|
||||
if (newValue != oldValue) {
|
||||
runAsync {
|
||||
device.setState("filament", newValue);
|
||||
device.filament = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -133,13 +132,12 @@ class MspDisplay() : DeviceDisplay<MspDevice>(), DeviceListener, NamedValueListe
|
||||
cellFormat {
|
||||
text = "Filament $it"
|
||||
}
|
||||
disableProperty()
|
||||
.bind(getBooleanStateBinding(PortSensor.CONNECTED_STATE).not())
|
||||
disableProperty().bind(getBooleanBinding(PortSensor.CONNECTED_STATE).not())
|
||||
}
|
||||
switch {
|
||||
padding = Insets(5.0, 0.0, 0.0, 0.0)
|
||||
disableProperty()
|
||||
.bind(getStateBinding(PortSensor.CONNECTED_STATE).booleanBinding { !it!!.booleanValue() })
|
||||
.bind(getBooleanBinding(PortSensor.CONNECTED_STATE))
|
||||
bindBooleanToState("filamentOn", selectedProperty())
|
||||
}
|
||||
deviceStateIndicator(this@MspDisplay, "filamentStatus", false) {
|
||||
@ -154,15 +152,13 @@ class MspDisplay() : DeviceDisplay<MspDevice>(), DeviceListener, NamedValueListe
|
||||
|
||||
togglebutton("Measure") {
|
||||
isSelected = false
|
||||
disableProperty()
|
||||
.bind(getStateBinding(PortSensor.CONNECTED_STATE).booleanBinding { !it!!.booleanValue() })
|
||||
disableProperty().bind(getBooleanBinding(PortSensor.CONNECTED_STATE).not())
|
||||
|
||||
bindBooleanToState(Sensor.MEASURING_STATE, selectedProperty())
|
||||
}
|
||||
togglebutton("Store") {
|
||||
isSelected = false
|
||||
disableProperty()
|
||||
.bind(getStateBinding(Sensor.MEASURING_STATE).booleanBinding { !it!!.booleanValue() })
|
||||
disableProperty().bind(getBooleanBinding(Sensor.MEASURING_STATE).not())
|
||||
bindBooleanToState("storing", selectedProperty())
|
||||
}
|
||||
separator(Orientation.VERTICAL)
|
||||
@ -187,7 +183,7 @@ class MspDisplay() : DeviceDisplay<MspDevice>(), DeviceListener, NamedValueListe
|
||||
init {
|
||||
table.addListener { change: MapChangeListener.Change<out String, out Value> ->
|
||||
if (change.wasAdded()) {
|
||||
val pl = plottables.get(change.key)
|
||||
val pl = plottables[change.key] as TimePlot?
|
||||
val value = change.valueAdded
|
||||
if (pl != null) {
|
||||
if (value.doubleValue() > 0) {
|
||||
|
@ -11,6 +11,7 @@ import hep.dataforge.fx.bindWindow
|
||||
import hep.dataforge.states.State
|
||||
import hep.dataforge.states.ValueState
|
||||
import hep.dataforge.values.Value
|
||||
import javafx.beans.binding.BooleanBinding
|
||||
import javafx.beans.binding.ObjectBinding
|
||||
import javafx.beans.property.BooleanProperty
|
||||
import javafx.beans.property.SimpleObjectProperty
|
||||
@ -99,6 +100,10 @@ abstract class DeviceDisplay<D : Device> : Component(), Connection, DeviceListen
|
||||
return bindState(state)
|
||||
}
|
||||
|
||||
fun getBooleanBinding(stateName: String): BooleanBinding{
|
||||
return getValueBinding(stateName).booleanBinding{it?.booleanValue()?:false}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind existing boolean property to writable device state
|
||||
|
||||
|
@ -5,14 +5,8 @@
|
||||
*/
|
||||
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.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.switch
|
||||
import javafx.application.Platform
|
||||
@ -66,31 +60,34 @@ open class VacDisplay : DeviceDisplay<Sensor>() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun notifyMetaStateChanged(device: Device, name: String, state: Meta) {
|
||||
super.notifyMetaStateChanged(device, name, state)
|
||||
// override fun notifyMetaStateChanged(device: Device, name: String, state: Meta) {
|
||||
// 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 {
|
||||
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)
|
||||
pane {
|
||||
minHeight = 30.0
|
||||
|
@ -6,6 +6,7 @@ import hep.dataforge.fx.runGoal
|
||||
import hep.dataforge.fx.ui
|
||||
import hep.dataforge.kodex.configure
|
||||
import hep.dataforge.plots.PlotFrame
|
||||
import hep.dataforge.plots.data.DataPlot
|
||||
import hep.dataforge.plots.data.TimePlot
|
||||
import hep.dataforge.plots.jfreechart.JFreeChartFrame
|
||||
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.type" to "time"
|
||||
"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);
|
||||
|
||||
@ -47,17 +57,7 @@ class HVView : View(title = "High voltage time plot", icon = ImageView(dfIcon))
|
||||
} ui { hvData ->
|
||||
hvData.ifPresent {
|
||||
for (dp in it) {
|
||||
//val blockName = dp.getString("block", "default").replace(".", "_");
|
||||
//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;
|
||||
val plot: TimePlot = frame[change.key] as TimePlot? ?: TimePlot(change.key).apply { frame.add(this) }
|
||||
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);
|
||||
}
|
||||
|
||||
fun clear(){
|
||||
fun clear() {
|
||||
data.clear()
|
||||
}
|
||||
|
||||
|
@ -165,11 +165,7 @@ class SpectrumView(
|
||||
val totalProgress = data.values.stream().mapToLong() { it.points.count() }.sum()
|
||||
|
||||
data.forEach { name, set ->
|
||||
val plot = frame.opt(name).orElseGet {
|
||||
DataPlot(name).apply {
|
||||
frame.add(this)
|
||||
}
|
||||
} as DataPlot
|
||||
val plot: DataPlot = frame[name] as DataPlot? ?: DataPlot(name).apply { frame.add(this) }
|
||||
|
||||
runGoal("spectrumData[$name]") {
|
||||
set.points.map { point ->
|
||||
@ -200,7 +196,7 @@ class SpectrumView(
|
||||
data.remove(key)
|
||||
}
|
||||
|
||||
fun clear(){
|
||||
fun clear() {
|
||||
data.clear()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user