diff --git a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/StyleSheet.kt b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/StyleSheet.kt index f831bf68..7b70a0dc 100644 --- a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/StyleSheet.kt +++ b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/StyleSheet.kt @@ -6,9 +6,7 @@ import hep.dataforge.io.serialization.MetaSerializer import hep.dataforge.meta.* import hep.dataforge.names.Name import hep.dataforge.names.asName -import kotlinx.serialization.Serializable -import kotlinx.serialization.Transient -import kotlinx.serialization.UseSerializers +import kotlinx.serialization.* /** * A container for styles @@ -51,6 +49,20 @@ class StyleSheet() { val newStyle = get(key)?.let { buildMeta(it, builder) } ?: buildMeta(builder) set(key, newStyle.seal()) } + + companion object: KSerializer{ + override val descriptor: SerialDescriptor + get() = TODO("Not yet implemented") + + override fun deserialize(decoder: Decoder): StyleSheet { + TODO("Not yet implemented") + } + + override fun serialize(encoder: Encoder, obj: StyleSheet) { + TODO("Not yet implemented") + } + + } } private fun VisualObject.styleChanged(key: String, oldStyle: Meta?, newStyle: Meta?) { 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 97594bd0..1f72a899 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 @@ -68,8 +68,8 @@ private fun VisualGroup3D.addSolid( name ) is GDMLCone -> cone(solid.rmax1, solid.z, solid.rmax2, name = name) { - require(solid.rmin1 == 0.0){"Empty cones are not supported"} - require(solid.rmin2 == 0.0){"Empty cones are not supported"} + require(solid.rmin1 == 0.0) { "Empty cones are not supported" } + require(solid.rmin2 == 0.0) { "Empty cones are not supported" } startAngle = solid.startphi.toFloat() angle = solid.deltaphi.toFloat() } @@ -178,7 +178,7 @@ private fun VisualGroup3D.addPhysicalVolume( context.proto[fullName] = volume(context, volume) } - this[physVolume.name ?: ""] = Proxy(fullName).apply { + this[physVolume.name ?: ""] = Proxy(this, fullName).apply { withPosition( context.lUnit, physVolume.resolvePosition(context.root), 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 13b13f2c..9b72e6d5 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 @@ -26,7 +26,11 @@ import kotlin.collections.set */ @Serializable @SerialName("3d.proxy") -class Proxy(val templateName: Name) : AbstractVisualObject(), VisualGroup, VisualObject3D { +class Proxy private constructor(val templateName: Name) : AbstractVisualObject(), VisualGroup, VisualObject3D { + + constructor(parent: VisualGroup3D, templateName: Name) : this(templateName) { + this.parent = parent + } override var position: Point3D? = null override var rotation: Point3D? = null @@ -155,7 +159,7 @@ inline fun VisualGroup3D.ref( templateName: Name, name: String = "", block: Proxy.() -> Unit = {} -) = Proxy(templateName).apply(block).also { set(name, it) } +) = Proxy(this, templateName).apply(block).also { set(name, it) } /** * Add new proxy wrapping given object and automatically adding it to the prototypes @@ -168,7 +172,7 @@ fun VisualGroup3D.proxy( ): Proxy { val existing = getPrototype(templateName) if (existing == null) { - prototypes{ + prototypes { this[templateName] = obj } } else if (existing != obj) { 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 1afa0647..2f271041 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 @@ -62,6 +62,7 @@ class VisualGroup3D : AbstractVisualGroup(), VisualObject3D { override fun attachChildren() { prototypes?.parent = this + prototypes?.attachChildren() super.attachChildren() } @@ -74,7 +75,7 @@ class VisualGroup3D : AbstractVisualGroup(), VisualObject3D { } override fun removeChild(token: NameToken) { - _children.remove(token) + _children.remove(token)?.run { parent = null } childrenChanged(token.asName(), null) } diff --git a/dataforge-vis-spatial/src/jvmMain/kotlin/hep/dataforge/vis/spatial/fx/FXProxyFactory.kt b/dataforge-vis-spatial/src/jvmMain/kotlin/hep/dataforge/vis/spatial/fx/FXProxyFactory.kt index 6cdb6610..6052afcd 100644 --- a/dataforge-vis-spatial/src/jvmMain/kotlin/hep/dataforge/vis/spatial/fx/FXProxyFactory.kt +++ b/dataforge-vis-spatial/src/jvmMain/kotlin/hep/dataforge/vis/spatial/fx/FXProxyFactory.kt @@ -13,8 +13,8 @@ class FXProxyFactory(val plugin: FX3DPlugin) : FX3DFactory { override val type: KClass get() = Proxy::class override fun invoke(obj: Proxy, binding: VisualObjectFXBinding): Node { - val template = obj.prototype - val node = plugin.buildNode(template) + val prototype = obj.prototype + val node = plugin.buildNode(prototype) obj.onPropertyChange(this) { name, _, _ -> if (name.first()?.body == Proxy.PROXY_CHILD_PROPERTY_PREFIX) {