Style refactoring
This commit is contained in:
parent
c60c8564e1
commit
190a5fc7d3
@ -19,7 +19,7 @@ allprojects {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "hep.dataforge"
|
group = "hep.dataforge"
|
||||||
version = "0.1.4"
|
version = "0.1.5-dev"
|
||||||
}
|
}
|
||||||
|
|
||||||
val githubProject by extra("visionforge")
|
val githubProject by extra("visionforge")
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package hep.dataforge.vision.solid.gdml.demo
|
package hep.dataforge.vision.solid.gdml.demo
|
||||||
|
|
||||||
|
import hep.dataforge.meta.DFExperimental
|
||||||
import hep.dataforge.meta.setItem
|
import hep.dataforge.meta.setItem
|
||||||
import hep.dataforge.values.asValue
|
import hep.dataforge.values.asValue
|
||||||
import hep.dataforge.vision.solid.SolidGroup
|
import hep.dataforge.vision.solid.SolidGroup
|
||||||
@ -13,6 +14,7 @@ import java.io.File
|
|||||||
import java.util.zip.GZIPInputStream
|
import java.util.zip.GZIPInputStream
|
||||||
import java.util.zip.ZipInputStream
|
import java.util.zip.ZipInputStream
|
||||||
|
|
||||||
|
@OptIn(DFExperimental::class)
|
||||||
fun SolidManager.Companion.readFile(file: File): SolidGroup = when {
|
fun SolidManager.Companion.readFile(file: File): SolidGroup = when {
|
||||||
file.extension == "gdml" || file.extension == "xml" -> {
|
file.extension == "gdml" || file.extension == "xml" -> {
|
||||||
GDML.readFile(file.toPath()).toVision {
|
GDML.readFile(file.toPath()).toVision {
|
||||||
@ -48,4 +50,5 @@ fun SolidManager.Companion.readFile(file: File): SolidGroup = when {
|
|||||||
else -> error("Unknown extension ${file.extension}")
|
else -> error("Unknown extension ${file.extension}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(DFExperimental::class)
|
||||||
fun SolidManager.Companion.readFile(fileName: String): SolidGroup = readFile(File(fileName))
|
fun SolidManager.Companion.readFile(fileName: String): SolidGroup = readFile(File(fileName))
|
@ -25,7 +25,6 @@ abstract class AbstractVision : Vision {
|
|||||||
protected set
|
protected set
|
||||||
|
|
||||||
protected fun updateStyles(names: List<String>) {
|
protected fun updateStyles(names: List<String>) {
|
||||||
styleCache = null
|
|
||||||
names.mapNotNull { resolveStyle(it) }.asSequence()
|
names.mapNotNull { resolveStyle(it) }.asSequence()
|
||||||
.flatMap { it.items.asSequence() }
|
.flatMap { it.items.asSequence() }
|
||||||
.distinctBy { it.key }
|
.distinctBy { it.key }
|
||||||
@ -65,24 +64,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
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
* 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<*>? {
|
override fun getProperty(name: Name, inherit: Boolean): MetaItem<*>? {
|
||||||
return if (inherit) {
|
return if (inherit) {
|
||||||
|
@ -104,4 +104,13 @@ var Vision.styles: List<String>
|
|||||||
*/
|
*/
|
||||||
fun Vision.useStyle(name: String) {
|
fun Vision.useStyle(name: String) {
|
||||||
styles = styles + name
|
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))
|
@ -81,7 +81,7 @@ class Proxy private constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getAllProperties(): Laminate =
|
override fun getAllProperties(): Laminate =
|
||||||
Laminate(properties, mergedStyles, prototype.getAllProperties(), parent?.getAllProperties())
|
Laminate(properties, allStyles, prototype.getAllProperties(), parent?.getAllProperties())
|
||||||
|
|
||||||
override fun attachChildren() {
|
override fun attachChildren() {
|
||||||
//do nothing
|
//do nothing
|
||||||
@ -144,7 +144,7 @@ class Proxy private constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getAllProperties(): Laminate =
|
override fun getAllProperties(): Laminate =
|
||||||
Laminate(properties, mergedStyles, prototype.getAllProperties(), parent?.getAllProperties())
|
Laminate(properties, allStyles, prototype.getAllProperties(), parent?.getAllProperties())
|
||||||
|
|
||||||
|
|
||||||
override val descriptor: NodeDescriptor?
|
override val descriptor: NodeDescriptor?
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
package hep.dataforge.vision.solid
|
package hep.dataforge.vision.solid
|
||||||
|
|
||||||
import hep.dataforge.meta.Config
|
import hep.dataforge.meta.Config
|
||||||
|
import hep.dataforge.meta.DFExperimental
|
||||||
import hep.dataforge.names.Name
|
import hep.dataforge.names.Name
|
||||||
import hep.dataforge.names.NameToken
|
import hep.dataforge.names.NameToken
|
||||||
import hep.dataforge.names.asName
|
import hep.dataforge.names.asName
|
||||||
@ -81,6 +82,7 @@ class SolidGroup : AbstractVisionGroup(), Solid, PrototypeHolder {
|
|||||||
companion object {
|
companion object {
|
||||||
// val PROTOTYPES_KEY = NameToken("@prototypes")
|
// val PROTOTYPES_KEY = NameToken("@prototypes")
|
||||||
|
|
||||||
|
@OptIn(DFExperimental::class)
|
||||||
fun parseJson(json: String): SolidGroup =
|
fun parseJson(json: String): SolidGroup =
|
||||||
SolidManager.jsonForSolids.parse(serializer(), json).also { it.attachChildren() }
|
SolidManager.jsonForSolids.parse(serializer(), json).also { it.attachChildren() }
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,6 @@ private fun SerialModule.extractFactories(): List<SolidForm<*>> {
|
|||||||
actualClass as KClass<Solid>,
|
actualClass as KClass<Solid>,
|
||||||
actualSerializer as KSerializer<Solid>
|
actualSerializer as KSerializer<Solid>
|
||||||
)
|
)
|
||||||
val name = actualSerializer.descriptor.serialName.toName()
|
|
||||||
list.add(factory)
|
list.add(factory)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user