forked from kscience/visionforge
Change property and structure subscription to flows.
This commit is contained in:
parent
b2ba92e745
commit
929832f3a5
@ -2,6 +2,7 @@ package hep.dataforge.vision.gdml.demo
|
|||||||
|
|
||||||
import hep.dataforge.context.Global
|
import hep.dataforge.context.Global
|
||||||
import hep.dataforge.vision.VisionManager
|
import hep.dataforge.vision.VisionManager
|
||||||
|
import hep.dataforge.vision.describedProperties
|
||||||
import hep.dataforge.vision.editor.VisualObjectEditorFragment
|
import hep.dataforge.vision.editor.VisualObjectEditorFragment
|
||||||
import hep.dataforge.vision.editor.VisualObjectTreeFragment
|
import hep.dataforge.vision.editor.VisualObjectTreeFragment
|
||||||
import hep.dataforge.vision.gdml.toVision
|
import hep.dataforge.vision.gdml.toVision
|
||||||
@ -26,7 +27,7 @@ class GDMLView : View() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val propertyEditor = VisualObjectEditorFragment {
|
private val propertyEditor = VisualObjectEditorFragment {
|
||||||
it.allProperties
|
it.describedProperties
|
||||||
}.apply {
|
}.apply {
|
||||||
descriptorProperty.set(SolidMaterial.descriptor)
|
descriptorProperty.set(SolidMaterial.descriptor)
|
||||||
itemProperty.bind(treeFragment.selectedProperty)
|
itemProperty.bind(treeFragment.selectedProperty)
|
||||||
|
@ -43,7 +43,7 @@ class FX3DPlugin : AbstractPlugin() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun buildNode(obj: Solid): Node {
|
fun buildNode(obj: Solid): Node {
|
||||||
val binding = VisualObjectFXBinding(obj)
|
val binding = VisualObjectFXBinding(this, obj)
|
||||||
return when (obj) {
|
return when (obj) {
|
||||||
is SolidReferenceGroup -> referenceFactory(obj, binding)
|
is SolidReferenceGroup -> referenceFactory(obj, binding)
|
||||||
is SolidGroup -> {
|
is SolidGroup -> {
|
||||||
|
@ -4,6 +4,8 @@ import hep.dataforge.names.*
|
|||||||
import hep.dataforge.vision.Vision
|
import hep.dataforge.vision.Vision
|
||||||
import javafx.scene.Group
|
import javafx.scene.Group
|
||||||
import javafx.scene.Node
|
import javafx.scene.Node
|
||||||
|
import kotlinx.coroutines.flow.launchIn
|
||||||
|
import kotlinx.coroutines.flow.onEach
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
class FXReferenceFactory(val plugin: FX3DPlugin) : FX3DFactory<SolidReferenceGroup> {
|
class FXReferenceFactory(val plugin: FX3DPlugin) : FX3DFactory<SolidReferenceGroup> {
|
||||||
@ -13,7 +15,7 @@ class FXReferenceFactory(val plugin: FX3DPlugin) : FX3DFactory<SolidReferenceGro
|
|||||||
val prototype = obj.prototype
|
val prototype = obj.prototype
|
||||||
val node = plugin.buildNode(prototype)
|
val node = plugin.buildNode(prototype)
|
||||||
|
|
||||||
obj.onPropertyChange(this) { name->
|
obj.propertyInvalidated.onEach { name->
|
||||||
if (name.firstOrNull()?.body == SolidReferenceGroup.REFERENCE_CHILD_PROPERTY_PREFIX) {
|
if (name.firstOrNull()?.body == SolidReferenceGroup.REFERENCE_CHILD_PROPERTY_PREFIX) {
|
||||||
val childName = name.firstOrNull()?.index?.toName() ?: error("Wrong syntax for reference child property: '$name'")
|
val childName = name.firstOrNull()?.index?.toName() ?: error("Wrong syntax for reference child property: '$name'")
|
||||||
val propertyName = name.cutFirst()
|
val propertyName = name.cutFirst()
|
||||||
@ -21,7 +23,7 @@ class FXReferenceFactory(val plugin: FX3DPlugin) : FX3DFactory<SolidReferenceGro
|
|||||||
val child = node.findChild(childName) ?: error("Object child with name '$childName' not found")
|
val child = node.findChild(childName) ?: error("Object child with name '$childName' not found")
|
||||||
child.updateProperty(referenceChild, propertyName)
|
child.updateProperty(referenceChild, propertyName)
|
||||||
}
|
}
|
||||||
}
|
}.launchIn(plugin.context)
|
||||||
return node
|
return node
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,16 +7,18 @@ import hep.dataforge.names.toName
|
|||||||
import hep.dataforge.vision.Vision
|
import hep.dataforge.vision.Vision
|
||||||
import javafx.application.Platform
|
import javafx.application.Platform
|
||||||
import javafx.beans.binding.ObjectBinding
|
import javafx.beans.binding.ObjectBinding
|
||||||
|
import kotlinx.coroutines.flow.launchIn
|
||||||
|
import kotlinx.coroutines.flow.onEach
|
||||||
import tornadofx.*
|
import tornadofx.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A caching binding collection for [Vision] properties
|
* A caching binding collection for [Vision] properties
|
||||||
*/
|
*/
|
||||||
class VisualObjectFXBinding(val obj: Vision) {
|
class VisualObjectFXBinding(val fx: FX3DPlugin, val obj: Vision) {
|
||||||
private val bindings = HashMap<Name, ObjectBinding<MetaItem<*>?>>()
|
private val bindings = HashMap<Name, ObjectBinding<MetaItem<*>?>>()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
obj.onPropertyChange(this) { name ->
|
obj.propertyInvalidated.onEach { name ->
|
||||||
bindings.filter { it.key.startsWith(name) }.forEach { entry ->
|
bindings.filter { it.key.startsWith(name) }.forEach { entry ->
|
||||||
Platform.runLater {
|
Platform.runLater {
|
||||||
entry.value.invalidate()
|
entry.value.invalidate()
|
||||||
@ -28,7 +30,7 @@ class VisualObjectFXBinding(val obj: Vision) {
|
|||||||
// bindings[currentName]?.invalidate()
|
// bindings[currentName]?.invalidate()
|
||||||
// currentName = currentName.cutLast()
|
// currentName = currentName.cutLast()
|
||||||
// }
|
// }
|
||||||
}
|
}.launchIn(fx.context)
|
||||||
}
|
}
|
||||||
|
|
||||||
operator fun get(key: Name): ObjectBinding<MetaItem<*>?> {
|
operator fun get(key: Name): ObjectBinding<MetaItem<*>?> {
|
||||||
|
Loading…
Reference in New Issue
Block a user