New properties #34

Merged
altavir merged 19 commits from new-properties into dev 2020-12-29 13:35:01 +03:00
4 changed files with 12 additions and 7 deletions
Showing only changes of commit 929832f3a5 - Show all commits

View File

@ -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)

View File

@ -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 -> {

View File

@ -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<SolidReferenceGroup> {
@ -13,7 +15,7 @@ class FXReferenceFactory(val plugin: FX3DPlugin) : FX3DFactory<SolidReferenceGro
val prototype = obj.prototype
val node = plugin.buildNode(prototype)
obj.onPropertyChange(this) { name->
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<SolidReferenceGro
val child = node.findChild(childName) ?: error("Object child with name '$childName' not found")
child.updateProperty(referenceChild, propertyName)
}
}
}.launchIn(plugin.context)
return node
}
}

View File

@ -7,16 +7,18 @@ import hep.dataforge.names.toName
import hep.dataforge.vision.Vision
import javafx.application.Platform
import javafx.beans.binding.ObjectBinding
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import tornadofx.*
/**
* 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<*>?>>()
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<MetaItem<*>?> {