Fix SO in style definition

This commit is contained in:
Alexander Nozik 2020-08-08 09:57:02 +03:00
parent 423b36b3de
commit c60c8564e1
9 changed files with 24 additions and 30 deletions

View File

@ -51,7 +51,7 @@ val MMApp = component<MMAppProps> { props ->
div("row") { div("row") {
h1("mx-auto") { h1("mx-auto") {
+"GDML/JSON render demo" +"Muon monitor demo"
} }
} }
div("row") { div("row") {

View File

@ -27,5 +27,5 @@ kotlin {
} }
application { application {
mainClassName = "hep.dataforge.vis.solid.demo.FXDemoAppKt" mainClassName = "hep.dataforge.vision.solid.demo.FXDemoAppKt"
} }

View File

@ -21,7 +21,8 @@ abstract class AbstractVision : Vision {
/** /**
* Object own properties excluding styles and inheritance * Object own properties excluding styles and inheritance
*/ */
protected abstract var properties: Config? abstract override var properties: Config?
protected set
protected fun updateStyles(names: List<String>) { protected fun updateStyles(names: List<String>) {
styleCache = null styleCache = null
@ -64,6 +65,10 @@ abstract class AbstractVision : Vision {
listeners.removeAll { it.owner == owner } 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 private var styleCache: Meta? = null
/** /**
@ -83,13 +88,13 @@ abstract class AbstractVision : Vision {
return if (inherit) { return if (inherit) {
sequence { sequence {
yield(properties?.get(name)) yield(properties?.get(name))
yield(mergedStyles[name]) yield(getStyleItem(name))
yield(parent?.getProperty(name, inherit)) yield(parent?.getProperty(name, inherit))
}.merge() }.merge()
} else { } else {
sequence { sequence {
yield(properties?.get(name)) yield(properties?.get(name))
yield(mergedStyles[name]) yield(getStyleItem(name))
}.merge() }.merge()
} }
} }

View File

@ -94,7 +94,7 @@ class StyleSheet private constructor(private val styleMap: MutableMap<String, Me
* List of names of styles applied to this object. Order matters. Not inherited * List of names of styles applied to this object. Order matters. Not inherited
*/ */
var Vision.styles: List<String> var Vision.styles: List<String>
get() = getItem(Vision.STYLE_KEY).stringList get() = properties?.get(Vision.STYLE_KEY).stringList
set(value) { set(value) {
setItem(Vision.STYLE_KEY,value.map { it.asValue() }.asValue()) setItem(Vision.STYLE_KEY,value.map { it.asValue() }.asValue())
} }

View File

@ -1,9 +1,6 @@
package hep.dataforge.vision package hep.dataforge.vision
import hep.dataforge.meta.Configurable import hep.dataforge.meta.*
import hep.dataforge.meta.Laminate
import hep.dataforge.meta.Meta
import hep.dataforge.meta.MetaItem
import hep.dataforge.names.Name import hep.dataforge.names.Name
import hep.dataforge.names.asName import hep.dataforge.names.asName
import hep.dataforge.names.toName import hep.dataforge.names.toName
@ -24,6 +21,11 @@ interface Vision : Configurable {
@Transient @Transient
var parent: VisionGroup? 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 * All properties including styles and prototypes if present, including inherited ones
*/ */

View File

@ -9,7 +9,7 @@ import hep.dataforge.values.ValueType
import hep.dataforge.values.asValue import hep.dataforge.values.asValue
fun Sequence<MetaItem<*>?>.merge(): MetaItem<*>? { fun Sequence<MetaItem<*>?>.merge(): MetaItem<*>? {
return when (val first = filterNotNull().firstOrNull()) { return when (val first = firstOrNull { it != null }) {
null -> null null -> null
is MetaItem.ValueItem -> first //fast search for first entry if it is value is MetaItem.ValueItem -> first //fast search for first entry if it is value
is MetaItem.NodeItem -> { is MetaItem.NodeItem -> {

View File

@ -48,14 +48,14 @@ class Proxy private constructor(
return if (inherit) { return if (inherit) {
sequence { sequence {
yield(properties?.get(name)) yield(properties?.get(name))
yield(mergedStyles[name]) yield(getStyleItem(name))
yield(prototype.getItem(name)) yield(prototype.getItem(name))
yield(parent?.getProperty(name, inherit)) yield(parent?.getProperty(name, inherit))
}.merge() }.merge()
} else { } else {
sequence { sequence {
yield(properties?.get(name)) yield(properties?.get(name))
yield(mergedStyles[name]) yield(getStyleItem(name))
yield(prototype.getProperty(name, false)) yield(prototype.getProperty(name, false))
}.merge() }.merge()
} }
@ -92,8 +92,7 @@ class Proxy private constructor(
override val descriptor: NodeDescriptor? override val descriptor: NodeDescriptor?
get() = prototype.descriptor get() = prototype.descriptor
inner class ProxyChild(val name: Name) : AbstractVision(), inner class ProxyChild(val name: Name) : AbstractVision(), VisionGroup {
VisionGroup {
val prototype: Vision get() = prototypeFor(name) val prototype: Vision get() = prototypeFor(name)
@ -127,14 +126,14 @@ class Proxy private constructor(
return if (inherit) { return if (inherit) {
sequence { sequence {
yield(properties?.get(name)) yield(properties?.get(name))
yield(mergedStyles[name]) yield(getStyleItem(name))
yield(prototype.getItem(name)) yield(prototype.getItem(name))
yield(parent?.getProperty(name, inherit)) yield(parent?.getProperty(name, inherit))
}.merge() }.merge()
} else { } else {
sequence { sequence {
yield(properties?.get(name)) yield(properties?.get(name))
yield(mergedStyles[name]) yield(getStyleItem(name))
yield(prototype.getProperty(name, false)) yield(prototype.getProperty(name, false))
}.merge() }.merge()
} }

View File

@ -25,8 +25,6 @@ interface Solid : Vision {
var rotation: Point3D? var rotation: Point3D?
var scale: Point3D? var scale: Point3D?
val properties: Config?
override val descriptor: NodeDescriptor? get() = Companion.descriptor override val descriptor: NodeDescriptor? get() = Companion.descriptor
companion object { companion object {

View File

@ -51,16 +51,6 @@ private class SolidForm<T :Solid>(
private fun SerialModule.extractFactories(): List<SolidForm<*>> { private fun SerialModule.extractFactories(): List<SolidForm<*>> {
val list = ArrayList<SolidForm<*>>() val list = ArrayList<SolidForm<*>>()
val jsonEngine = Json(
JsonConfiguration(
prettyPrint = true,
useArrayPolymorphism = false,
encodeDefaults = false,
ignoreUnknownKeys = true
),
context = this
)
val collector = object : SerialModuleCollector { val collector = object : SerialModuleCollector {
override fun <T : Any> contextual(kClass: KClass<T>, serializer: KSerializer<T>) { override fun <T : Any> contextual(kClass: KClass<T>, serializer: KSerializer<T>) {
//Do nothing //Do nothing