From c60c8564e1d65054847892950aa757849cb34332 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sat, 8 Aug 2020 09:57:02 +0300 Subject: [PATCH] Fix SO in style definition --- .../kotlin/ru/mipt/npm/muon/monitor/MMAppComponent.kt | 2 +- demo/spatial-showcase/build.gradle.kts | 2 +- .../kotlin/hep/dataforge/vision/AbstractVision.kt | 11 ++++++++--- .../kotlin/hep/dataforge/vision/StyleSheet.kt | 2 +- .../commonMain/kotlin/hep/dataforge/vision/Vision.kt | 10 ++++++---- .../commonMain/kotlin/hep/dataforge/vision/misc.kt | 4 ++-- .../kotlin/hep/dataforge/vision/solid/Proxy.kt | 11 +++++------ .../kotlin/hep/dataforge/vision/solid/Solid.kt | 2 -- .../kotlin/hep/dataforge/vision/solid/SolidManager.kt | 10 ---------- 9 files changed, 24 insertions(+), 30 deletions(-) diff --git a/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMAppComponent.kt b/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMAppComponent.kt index 99908d0d..1291efb0 100644 --- a/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMAppComponent.kt +++ b/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMAppComponent.kt @@ -51,7 +51,7 @@ val MMApp = component { props -> div("row") { h1("mx-auto") { - +"GDML/JSON render demo" + +"Muon monitor demo" } } div("row") { diff --git a/demo/spatial-showcase/build.gradle.kts b/demo/spatial-showcase/build.gradle.kts index 61cf59c9..b2816c18 100644 --- a/demo/spatial-showcase/build.gradle.kts +++ b/demo/spatial-showcase/build.gradle.kts @@ -27,5 +27,5 @@ kotlin { } application { - mainClassName = "hep.dataforge.vis.solid.demo.FXDemoAppKt" + mainClassName = "hep.dataforge.vision.solid.demo.FXDemoAppKt" } \ No newline at end of file diff --git a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/AbstractVision.kt b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/AbstractVision.kt index 270f64f2..2b12ba74 100644 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/AbstractVision.kt +++ b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/AbstractVision.kt @@ -21,7 +21,8 @@ abstract class AbstractVision : Vision { /** * Object own properties excluding styles and inheritance */ - protected abstract var properties: Config? + abstract override var properties: Config? + protected set protected fun updateStyles(names: List) { styleCache = null @@ -64,6 +65,10 @@ abstract class AbstractVision : Vision { listeners.removeAll { it.owner == owner } } + protected fun getStyleItem(name: Name): MetaItem<*>?{ + return styles.asSequence().map { resolveStyle(it) }.map { it[name] }.firstOrNull() + } + private var styleCache: Meta? = null /** @@ -83,13 +88,13 @@ abstract class AbstractVision : Vision { return if (inherit) { sequence { yield(properties?.get(name)) - yield(mergedStyles[name]) + yield(getStyleItem(name)) yield(parent?.getProperty(name, inherit)) }.merge() } else { sequence { yield(properties?.get(name)) - yield(mergedStyles[name]) + yield(getStyleItem(name)) }.merge() } } diff --git a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/StyleSheet.kt b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/StyleSheet.kt index 7f995eda..a99f8954 100644 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/StyleSheet.kt +++ b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/StyleSheet.kt @@ -94,7 +94,7 @@ class StyleSheet private constructor(private val styleMap: MutableMap - get() = getItem(Vision.STYLE_KEY).stringList + get() = properties?.get(Vision.STYLE_KEY).stringList set(value) { setItem(Vision.STYLE_KEY,value.map { it.asValue() }.asValue()) } diff --git a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/Vision.kt b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/Vision.kt index 19670145..8af6989b 100644 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/Vision.kt +++ b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/Vision.kt @@ -1,9 +1,6 @@ package hep.dataforge.vision -import hep.dataforge.meta.Configurable -import hep.dataforge.meta.Laminate -import hep.dataforge.meta.Meta -import hep.dataforge.meta.MetaItem +import hep.dataforge.meta.* import hep.dataforge.names.Name import hep.dataforge.names.asName import hep.dataforge.names.toName @@ -24,6 +21,11 @@ interface Vision : Configurable { @Transient var parent: VisionGroup? + /** + * Nullable version of [config] used to check if this [Vision] has custom properties + */ + val properties: Config? + /** * All properties including styles and prototypes if present, including inherited ones */ diff --git a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/misc.kt b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/misc.kt index 14e5fb3c..6b2d5fc7 100644 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/misc.kt +++ b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/misc.kt @@ -9,7 +9,7 @@ import hep.dataforge.values.ValueType import hep.dataforge.values.asValue fun Sequence?>.merge(): MetaItem<*>? { - return when (val first = filterNotNull().firstOrNull()) { + return when (val first = firstOrNull { it != null }) { null -> null is MetaItem.ValueItem -> first //fast search for first entry if it is value is MetaItem.NodeItem -> { @@ -25,5 +25,5 @@ inline fun > NodeDescriptor.enum(key: Name, default: E?) = v default?.let { default(default) } - allowedValues = enumValues().map{it.asValue()} + allowedValues = enumValues().map { it.asValue() } } \ No newline at end of file diff --git a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Proxy.kt b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Proxy.kt index 80c07326..e7252a9e 100644 --- a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Proxy.kt +++ b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Proxy.kt @@ -48,14 +48,14 @@ class Proxy private constructor( return if (inherit) { sequence { yield(properties?.get(name)) - yield(mergedStyles[name]) + yield(getStyleItem(name)) yield(prototype.getItem(name)) yield(parent?.getProperty(name, inherit)) }.merge() } else { sequence { yield(properties?.get(name)) - yield(mergedStyles[name]) + yield(getStyleItem(name)) yield(prototype.getProperty(name, false)) }.merge() } @@ -92,8 +92,7 @@ class Proxy private constructor( override val descriptor: NodeDescriptor? get() = prototype.descriptor - inner class ProxyChild(val name: Name) : AbstractVision(), - VisionGroup { + inner class ProxyChild(val name: Name) : AbstractVision(), VisionGroup { val prototype: Vision get() = prototypeFor(name) @@ -127,14 +126,14 @@ class Proxy private constructor( return if (inherit) { sequence { yield(properties?.get(name)) - yield(mergedStyles[name]) + yield(getStyleItem(name)) yield(prototype.getItem(name)) yield(parent?.getProperty(name, inherit)) }.merge() } else { sequence { yield(properties?.get(name)) - yield(mergedStyles[name]) + yield(getStyleItem(name)) yield(prototype.getProperty(name, false)) }.merge() } diff --git a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Solid.kt b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Solid.kt index 08a018ec..d1cfdaca 100644 --- a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Solid.kt +++ b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Solid.kt @@ -25,8 +25,6 @@ interface Solid : Vision { var rotation: Point3D? var scale: Point3D? - val properties: Config? - override val descriptor: NodeDescriptor? get() = Companion.descriptor companion object { diff --git a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidManager.kt b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidManager.kt index 57a89998..d5128544 100644 --- a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidManager.kt +++ b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidManager.kt @@ -51,16 +51,6 @@ private class SolidForm( private fun SerialModule.extractFactories(): List> { val list = ArrayList>() - val jsonEngine = Json( - JsonConfiguration( - prettyPrint = true, - useArrayPolymorphism = false, - encodeDefaults = false, - ignoreUnknownKeys = true - ), - context = this - ) - val collector = object : SerialModuleCollector { override fun contextual(kClass: KClass, serializer: KSerializer) { //Do nothing