Style refactoring

This commit is contained in:
Alexander Nozik 2020-08-08 10:10:48 +03:00
parent c60c8564e1
commit 190a5fc7d3
7 changed files with 19 additions and 21 deletions

View File

@ -19,7 +19,7 @@ allprojects {
}
group = "hep.dataforge"
version = "0.1.4"
version = "0.1.5-dev"
}
val githubProject by extra("visionforge")

View File

@ -1,5 +1,6 @@
package hep.dataforge.vision.solid.gdml.demo
import hep.dataforge.meta.DFExperimental
import hep.dataforge.meta.setItem
import hep.dataforge.values.asValue
import hep.dataforge.vision.solid.SolidGroup
@ -13,6 +14,7 @@ import java.io.File
import java.util.zip.GZIPInputStream
import java.util.zip.ZipInputStream
@OptIn(DFExperimental::class)
fun SolidManager.Companion.readFile(file: File): SolidGroup = when {
file.extension == "gdml" || file.extension == "xml" -> {
GDML.readFile(file.toPath()).toVision {
@ -48,4 +50,5 @@ fun SolidManager.Companion.readFile(file: File): SolidGroup = when {
else -> error("Unknown extension ${file.extension}")
}
@OptIn(DFExperimental::class)
fun SolidManager.Companion.readFile(fileName: String): SolidGroup = readFile(File(fileName))

View File

@ -25,7 +25,6 @@ abstract class AbstractVision : Vision {
protected set
protected fun updateStyles(names: List<String>) {
styleCache = null
names.mapNotNull { resolveStyle(it) }.asSequence()
.flatMap { it.items.asSequence() }
.distinctBy { it.key }
@ -65,24 +64,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
/**
* Collect all styles for this object in a single cached meta
*/
protected val mergedStyles: Meta
get() = styleCache ?: Laminate(styles.mapNotNull(::resolveStyle)).merge().also {
styleCache = it
}
/**
* All available properties in a layered form
*/
override fun getAllProperties(): Laminate = Laminate(properties, mergedStyles, parent?.getAllProperties())
override fun getAllProperties(): Laminate = Laminate(properties, allStyles, parent?.getAllProperties())
override fun getProperty(name: Name, inherit: Boolean): MetaItem<*>? {
return if (inherit) {

View File

@ -104,4 +104,13 @@ var Vision.styles: List<String>
*/
fun Vision.useStyle(name: String) {
styles = styles + name
}
}
fun Vision.getStyleItem(name: Name): MetaItem<*>? {
return styles.asSequence().map { resolveStyle(it) }.map { it[name] }.firstOrNull()
}
/**
* Collect all styles for this object in a single laminate
*/
val Vision.allStyles: Laminate get() = Laminate(styles.mapNotNull(::resolveStyle))

View File

@ -81,7 +81,7 @@ class Proxy private constructor(
}
override fun getAllProperties(): Laminate =
Laminate(properties, mergedStyles, prototype.getAllProperties(), parent?.getAllProperties())
Laminate(properties, allStyles, prototype.getAllProperties(), parent?.getAllProperties())
override fun attachChildren() {
//do nothing
@ -144,7 +144,7 @@ class Proxy private constructor(
}
override fun getAllProperties(): Laminate =
Laminate(properties, mergedStyles, prototype.getAllProperties(), parent?.getAllProperties())
Laminate(properties, allStyles, prototype.getAllProperties(), parent?.getAllProperties())
override val descriptor: NodeDescriptor?

View File

@ -5,6 +5,7 @@
package hep.dataforge.vision.solid
import hep.dataforge.meta.Config
import hep.dataforge.meta.DFExperimental
import hep.dataforge.names.Name
import hep.dataforge.names.NameToken
import hep.dataforge.names.asName
@ -81,6 +82,7 @@ class SolidGroup : AbstractVisionGroup(), Solid, PrototypeHolder {
companion object {
// val PROTOTYPES_KEY = NameToken("@prototypes")
@OptIn(DFExperimental::class)
fun parseJson(json: String): SolidGroup =
SolidManager.jsonForSolids.parse(serializer(), json).also { it.attachChildren() }
}

View File

@ -66,7 +66,6 @@ private fun SerialModule.extractFactories(): List<SolidForm<*>> {
actualClass as KClass<Solid>,
actualSerializer as KSerializer<Solid>
)
val name = actualSerializer.descriptor.serialName.toName()
list.add(factory)
}
}