From 929832f3a5b1a63ceef4729305309093a2f5e2c7 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 15 Dec 2020 19:37:33 +0300 Subject: [PATCH] Change property and structure subscription to flows. --- .../hep/dataforge/vision/gdml/demo/GdmlFxDemoApp.kt | 3 ++- .../main/kotlin/hep/dataforge/vision/solid/FX3DPlugin.kt | 2 +- .../hep/dataforge/vision/solid/FXReferenceFactory.kt | 6 ++++-- .../hep/dataforge/vision/solid/VisualObjectFXBinding.kt | 8 +++++--- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/demo/gdml/src/jvmMain/kotlin/hep/dataforge/vision/gdml/demo/GdmlFxDemoApp.kt b/demo/gdml/src/jvmMain/kotlin/hep/dataforge/vision/gdml/demo/GdmlFxDemoApp.kt index 1d5a4a89..03915243 100644 --- a/demo/gdml/src/jvmMain/kotlin/hep/dataforge/vision/gdml/demo/GdmlFxDemoApp.kt +++ b/demo/gdml/src/jvmMain/kotlin/hep/dataforge/vision/gdml/demo/GdmlFxDemoApp.kt @@ -2,6 +2,7 @@ package hep.dataforge.vision.gdml.demo import hep.dataforge.context.Global import hep.dataforge.vision.VisionManager +import hep.dataforge.vision.describedProperties import hep.dataforge.vision.editor.VisualObjectEditorFragment import hep.dataforge.vision.editor.VisualObjectTreeFragment import hep.dataforge.vision.gdml.toVision @@ -26,7 +27,7 @@ class GDMLView : View() { } private val propertyEditor = VisualObjectEditorFragment { - it.allProperties + it.describedProperties }.apply { descriptorProperty.set(SolidMaterial.descriptor) itemProperty.bind(treeFragment.selectedProperty) diff --git a/visionforge-fx/src/main/kotlin/hep/dataforge/vision/solid/FX3DPlugin.kt b/visionforge-fx/src/main/kotlin/hep/dataforge/vision/solid/FX3DPlugin.kt index ce88a14c..b635485b 100644 --- a/visionforge-fx/src/main/kotlin/hep/dataforge/vision/solid/FX3DPlugin.kt +++ b/visionforge-fx/src/main/kotlin/hep/dataforge/vision/solid/FX3DPlugin.kt @@ -43,7 +43,7 @@ class FX3DPlugin : AbstractPlugin() { } fun buildNode(obj: Solid): Node { - val binding = VisualObjectFXBinding(obj) + val binding = VisualObjectFXBinding(this, obj) return when (obj) { is SolidReferenceGroup -> referenceFactory(obj, binding) is SolidGroup -> { diff --git a/visionforge-fx/src/main/kotlin/hep/dataforge/vision/solid/FXReferenceFactory.kt b/visionforge-fx/src/main/kotlin/hep/dataforge/vision/solid/FXReferenceFactory.kt index 77244de2..2ffb2660 100644 --- a/visionforge-fx/src/main/kotlin/hep/dataforge/vision/solid/FXReferenceFactory.kt +++ b/visionforge-fx/src/main/kotlin/hep/dataforge/vision/solid/FXReferenceFactory.kt @@ -4,6 +4,8 @@ import hep.dataforge.names.* import hep.dataforge.vision.Vision import javafx.scene.Group import javafx.scene.Node +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach import kotlin.reflect.KClass class FXReferenceFactory(val plugin: FX3DPlugin) : FX3DFactory { @@ -13,7 +15,7 @@ class FXReferenceFactory(val plugin: FX3DPlugin) : FX3DFactory + obj.propertyInvalidated.onEach { name-> if (name.firstOrNull()?.body == SolidReferenceGroup.REFERENCE_CHILD_PROPERTY_PREFIX) { val childName = name.firstOrNull()?.index?.toName() ?: error("Wrong syntax for reference child property: '$name'") val propertyName = name.cutFirst() @@ -21,7 +23,7 @@ class FXReferenceFactory(val plugin: FX3DPlugin) : FX3DFactory?>>() init { - obj.onPropertyChange(this) { name -> + obj.propertyInvalidated.onEach { name -> bindings.filter { it.key.startsWith(name) }.forEach { entry -> Platform.runLater { entry.value.invalidate() @@ -28,7 +30,7 @@ class VisualObjectFXBinding(val obj: Vision) { // bindings[currentName]?.invalidate() // currentName = currentName.cutLast() // } - } + }.launchIn(fx.context) } operator fun get(key: Name): ObjectBinding?> {