diff --git a/build.gradle.kts b/build.gradle.kts index 0378807d..c1218820 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -26,7 +26,7 @@ allprojects { } group = "hep.dataforge" - version = "0.1.0-dev" + version = "0.1.1-dev" } subprojects{ diff --git a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualGroup.kt b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualGroup.kt index 889cb0dc..a0af25b7 100644 --- a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualGroup.kt +++ b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualGroup.kt @@ -1,7 +1,10 @@ package hep.dataforge.vis.common import hep.dataforge.meta.MetaItem -import hep.dataforge.names.* +import hep.dataforge.names.Name +import hep.dataforge.names.NameToken +import hep.dataforge.names.asName +import hep.dataforge.names.isEmpty import kotlinx.serialization.Transient @@ -76,7 +79,7 @@ abstract class AbstractVisualGroup : AbstractVisualObject(), MutableVisualGroup * Add named or unnamed child to the group. If key is null the child is considered unnamed. Both key and value are not * allowed to be null in the same time. If name is present and [child] is null, the appropriate element is removed. */ - override fun set(name: Name, child: VisualObject?) { + override fun set(name: Name, child: VisualObject?): Unit { when { name.isEmpty() -> { if (child != null) { @@ -100,13 +103,4 @@ abstract class AbstractVisualGroup : AbstractVisualObject(), MutableVisualGroup structureChangeListeners.forEach { it.callback(name, child) } } - operator fun set(key: String, child: VisualObject?): Unit { - if (key.isBlank()) { - if(child!= null) { - addStatic(child) - } - } else { - set(key.toName(), child) - } - } } \ No newline at end of file diff --git a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualObject.kt b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualObject.kt index 7701eb1c..5487a304 100644 --- a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualObject.kt +++ b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualObject.kt @@ -73,6 +73,9 @@ abstract class AbstractVisualObject : VisualObject { styleCache = it } + /** + * All available properties in a layered form + */ override fun allProperties(): Laminate = Laminate(properties, mergedStyles) override fun getProperty(name: Name, inherit: Boolean): MetaItem<*>? { diff --git a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualGroup.kt b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualGroup.kt index 0a90adff..7108209e 100644 --- a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualGroup.kt +++ b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualGroup.kt @@ -53,7 +53,7 @@ interface VisualGroup : Provider, Iterable, VisualObject { */ fun attachChildren() { styleSheet?.owner = this - this.children.values.forEach { + children.values.forEach { it.parent = this (it as? VisualGroup)?.attachChildren() } @@ -90,4 +90,8 @@ interface MutableVisualGroup : VisualGroup { operator fun VisualGroup.get(str: String?) = get(str?.toName() ?: Name.EMPTY) +operator fun MutableVisualGroup.set(key: String, child: VisualObject?) { + set(key.toName(), child) +} + fun MutableVisualGroup.removeAll() = children.keys.map { it.asName() }.forEach { this[it] = null } \ No newline at end of file diff --git a/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/visualGDML.kt b/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/visualGDML.kt index 26e1ef98..97594bd0 100644 --- a/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/visualGDML.kt +++ b/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/visualGDML.kt @@ -5,6 +5,7 @@ import hep.dataforge.names.Name import hep.dataforge.names.asName import hep.dataforge.names.plus import hep.dataforge.vis.common.get +import hep.dataforge.vis.common.set import hep.dataforge.vis.spatial.* import hep.dataforge.vis.spatial.World.ONE import hep.dataforge.vis.spatial.World.ZERO diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Box.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Box.kt index fd6358a2..438fe2f0 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Box.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Box.kt @@ -10,6 +10,7 @@ import hep.dataforge.meta.get import hep.dataforge.vis.common.AbstractVisualObject import hep.dataforge.vis.common.VisualFactory import hep.dataforge.vis.common.VisualObject +import hep.dataforge.vis.common.set import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.UseSerializers diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Composite.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Composite.kt index ed6f087b..a1f5df12 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Composite.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Composite.kt @@ -6,6 +6,7 @@ import hep.dataforge.io.serialization.ConfigSerializer import hep.dataforge.meta.Config import hep.dataforge.meta.update import hep.dataforge.vis.common.AbstractVisualObject +import hep.dataforge.vis.common.set import kotlinx.serialization.Serializable import kotlinx.serialization.UseSerializers diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/ConeSegment.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/ConeSegment.kt index 86abbe61..9d1c94d7 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/ConeSegment.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/ConeSegment.kt @@ -5,6 +5,7 @@ package hep.dataforge.vis.spatial import hep.dataforge.io.serialization.ConfigSerializer import hep.dataforge.meta.Config import hep.dataforge.vis.common.AbstractVisualObject +import hep.dataforge.vis.common.set import kotlinx.serialization.Serializable import kotlinx.serialization.UseSerializers import kotlin.math.cos diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Convex.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Convex.kt index 1ca46886..eac4d39f 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Convex.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Convex.kt @@ -5,6 +5,7 @@ package hep.dataforge.vis.spatial import hep.dataforge.io.serialization.ConfigSerializer import hep.dataforge.meta.Config import hep.dataforge.vis.common.AbstractVisualObject +import hep.dataforge.vis.common.set import kotlinx.serialization.Serializable import kotlinx.serialization.UseSerializers diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Extruded.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Extruded.kt index 18dac3d0..54577af6 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Extruded.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Extruded.kt @@ -4,6 +4,7 @@ package hep.dataforge.vis.spatial import hep.dataforge.io.serialization.ConfigSerializer import hep.dataforge.meta.Config import hep.dataforge.vis.common.AbstractVisualObject +import hep.dataforge.vis.common.set import kotlinx.serialization.Serializable import kotlinx.serialization.UseSerializers import kotlin.math.PI diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Label3D.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Label3D.kt index 01ff005e..97ac5adf 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Label3D.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Label3D.kt @@ -5,6 +5,7 @@ package hep.dataforge.vis.spatial import hep.dataforge.io.serialization.ConfigSerializer import hep.dataforge.meta.Config import hep.dataforge.vis.common.AbstractVisualObject +import hep.dataforge.vis.common.set import kotlinx.serialization.Serializable import kotlinx.serialization.UseSerializers diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/PolyLine.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/PolyLine.kt index eb850165..d028c81e 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/PolyLine.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/PolyLine.kt @@ -8,6 +8,7 @@ import hep.dataforge.meta.number import hep.dataforge.names.asName import hep.dataforge.names.plus import hep.dataforge.vis.common.AbstractVisualObject +import hep.dataforge.vis.common.set import kotlinx.serialization.Serializable import kotlinx.serialization.UseSerializers diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt index 62d7b5c0..f56437b2 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt @@ -79,6 +79,10 @@ class Proxy(val templateName: Name) : AbstractVisualObject(), VisualGroup, Visua override fun allProperties(): Laminate = Laminate(properties, mergedStyles, prototype.allProperties()) + override fun attachChildren() { + //do nothing + } + //override fun findAllStyles(): Laminate = Laminate((styles + prototype.styles).mapNotNull { findStyle(it) }) @Serializable @@ -125,6 +129,9 @@ class Proxy(val templateName: Name) : AbstractVisualObject(), VisualGroup, Visua } } + override fun attachChildren() { + //do nothing + } override fun allProperties(): Laminate = Laminate(properties, mergedStyles, prototype.allProperties()) diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Sphere.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Sphere.kt index 58e2c8b6..43c2cdb2 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Sphere.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Sphere.kt @@ -5,6 +5,7 @@ package hep.dataforge.vis.spatial import hep.dataforge.io.serialization.ConfigSerializer import hep.dataforge.meta.Config import hep.dataforge.vis.common.AbstractVisualObject +import hep.dataforge.vis.common.set import kotlinx.serialization.Serializable import kotlinx.serialization.UseSerializers import kotlin.math.PI diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Tube.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Tube.kt index 248fbfce..c3b8f113 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Tube.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Tube.kt @@ -4,6 +4,7 @@ package hep.dataforge.vis.spatial import hep.dataforge.io.serialization.ConfigSerializer import hep.dataforge.meta.Config import hep.dataforge.vis.common.AbstractVisualObject +import hep.dataforge.vis.common.set import kotlinx.serialization.Serializable import kotlinx.serialization.UseSerializers import kotlin.math.PI diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt index 83a089a8..1cb85e23 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt @@ -19,6 +19,8 @@ import hep.dataforge.names.isEmpty import hep.dataforge.vis.common.AbstractVisualGroup import hep.dataforge.vis.common.StyleSheet import hep.dataforge.vis.common.VisualObject +import hep.dataforge.vis.common.set +import hep.dataforge.vis.spatial.VisualGroup3D.Companion.PROTOTYPES_KEY import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.UseSerializers @@ -30,15 +32,6 @@ import kotlin.collections.set @Serializable @SerialName("group.3d") class VisualGroup3D : AbstractVisualGroup(), VisualObject3D { - /** - * A container for templates visible inside this group - */ - @SerialName(PROTOTYPES_KEY) - var prototypes: VisualGroup3D? = null - set(value) { - value?.parent = this - field = value - } override var styleSheet: StyleSheet? = null private set @@ -52,7 +45,7 @@ class VisualGroup3D : AbstractVisualGroup(), VisualObject3D { @SerialName("children") private val _children = HashMap() - override val children: Map get() = _children + override val children: Map get() = _children.filterKeys { it != PROTOTYPES_KEY } // init { // //Do after deserialization @@ -111,13 +104,22 @@ class VisualGroup3D : AbstractVisualGroup(), VisualObject3D { } companion object { - const val PROTOTYPES_KEY = "templates" + val PROTOTYPES_KEY = NameToken("@prototypes") fun fromJson(json: String): VisualGroup3D = - Visual3DPlugin.json.parse(serializer(),json).also { it.attachChildren() } + Visual3DPlugin.json.parse(serializer(), json).also { it.attachChildren() } } } +/** + * A container for templates visible inside this group + */ +var VisualGroup3D.prototypes: VisualGroup3D? + get() = children[PROTOTYPES_KEY] as? VisualGroup3D + set(value) { + this[PROTOTYPES_KEY.asName()] = value + } + /** * Ger a prototype redirecting the request to the parent if prototype is not found */ diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/transform/UnRef.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/transform/UnRef.kt index 12681b24..c96be89c 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/transform/UnRef.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/transform/UnRef.kt @@ -6,6 +6,7 @@ import hep.dataforge.vis.common.MutableVisualGroup import hep.dataforge.vis.common.VisualGroup import hep.dataforge.vis.spatial.Proxy import hep.dataforge.vis.spatial.VisualGroup3D +import hep.dataforge.vis.spatial.prototypes object UnRef : VisualTreeTransform() { private fun VisualGroup.countRefs(): Map { diff --git a/demo/spatial-showcase/src/jsMain/kotlin/hep/dataforge/vis/spatial/demo/VariableBox.kt b/demo/spatial-showcase/src/jsMain/kotlin/hep/dataforge/vis/spatial/demo/VariableBox.kt index 20540777..63e6c975 100644 --- a/demo/spatial-showcase/src/jsMain/kotlin/hep/dataforge/vis/spatial/demo/VariableBox.kt +++ b/demo/spatial-showcase/src/jsMain/kotlin/hep/dataforge/vis/spatial/demo/VariableBox.kt @@ -7,6 +7,7 @@ import hep.dataforge.meta.number import hep.dataforge.names.plus import hep.dataforge.names.startsWith import hep.dataforge.vis.common.getProperty +import hep.dataforge.vis.common.set import hep.dataforge.vis.common.setProperty import hep.dataforge.vis.spatial.* import hep.dataforge.vis.spatial.VisualObject3D.Companion.GEOMETRY_KEY