Fix orphaned template bug

This commit is contained in:
Alexander Nozik 2020-03-07 15:44:14 +03:00
parent 5e1abf7d9d
commit f6bde47042
5 changed files with 29 additions and 12 deletions

View File

@ -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<StyleSheet>{
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?) {

View File

@ -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),

View File

@ -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) {

View File

@ -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)
}

View File

@ -13,8 +13,8 @@ class FXProxyFactory(val plugin: FX3DPlugin) : FX3DFactory<Proxy> {
override val type: KClass<in Proxy> 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) {