Fixe recursive prototype search

This commit is contained in:
Alexander Nozik 2020-05-08 15:11:42 +03:00
parent aca1a8af78
commit 56e4ba2903
2 changed files with 9 additions and 2 deletions

View File

@ -5,6 +5,7 @@ package hep.dataforge.vis.spatial
import hep.dataforge.meta.Config import hep.dataforge.meta.Config
import hep.dataforge.meta.Laminate import hep.dataforge.meta.Laminate
import hep.dataforge.meta.MetaItem import hep.dataforge.meta.MetaItem
import hep.dataforge.meta.descriptors.NodeDescriptor
import hep.dataforge.meta.get import hep.dataforge.meta.get
import hep.dataforge.names.* import hep.dataforge.names.*
import hep.dataforge.vis.* import hep.dataforge.vis.*
@ -88,6 +89,9 @@ class Proxy private constructor(
//override fun findAllStyles(): Laminate = Laminate((styles + prototype.styles).mapNotNull { findStyle(it) }) //override fun findAllStyles(): Laminate = Laminate((styles + prototype.styles).mapNotNull { findStyle(it) })
override val descriptor: NodeDescriptor?
get() = prototype.descriptor
inner class ProxyChild(val name: Name) : AbstractVisualObject(), inner class ProxyChild(val name: Name) : AbstractVisualObject(),
VisualGroup { VisualGroup {
@ -139,6 +143,9 @@ class Proxy private constructor(
override fun allProperties(): Laminate = override fun allProperties(): Laminate =
Laminate(properties, mergedStyles, prototype.allProperties(), parent?.allProperties()) Laminate(properties, mergedStyles, prototype.allProperties(), parent?.allProperties())
override val descriptor: NodeDescriptor?
get() = prototype.descriptor
} }
companion object { companion object {

View File

@ -40,8 +40,8 @@ class VisualGroup3D : AbstractVisualGroup(), VisualObject3D, PrototypeHolder {
*/ */
fun prototypes(builder: MutableVisualGroup.() -> Unit): Unit { fun prototypes(builder: MutableVisualGroup.() -> Unit): Unit {
(prototypes ?: Prototypes().also { (prototypes ?: Prototypes().also {
attach(it)
prototypes = it prototypes = it
attach(it)
}).run(builder) }).run(builder)
} }
@ -90,7 +90,7 @@ class VisualGroup3D : AbstractVisualGroup(), VisualObject3D, PrototypeHolder {
* Ger a prototype redirecting the request to the parent if prototype is not found * Ger a prototype redirecting the request to the parent if prototype is not found
*/ */
tailrec fun PrototypeHolder.getPrototype(name: Name): VisualObject3D? = tailrec fun PrototypeHolder.getPrototype(name: Name): VisualObject3D? =
prototypes?.get(name) as? VisualObject3D ?: (parent as? VisualGroup3D)?.getPrototype(name) prototypes?.get(name) as? VisualObject3D ?: (parent as? PrototypeHolder)?.getPrototype(name)
/** /**
* Define a group with given [name], attach it to this parent and return it. * Define a group with given [name], attach it to this parent and return it.