From 25a47a971942e6fadfacd88ec2c6b83c35955802 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Fri, 25 Dec 2020 15:28:33 +0300 Subject: [PATCH] Migrate to DF 0.3 --- build.gradle.kts | 4 +-- .../dataforge/vision/gdml/demo/readFile.kt | 1 - .../hep/dataforge/vision/solid/demo/demo.kt | 10 ++++-- .../vision/solid/demo/VariableBox.kt | 8 +---- .../hep/dataforge/vision/react/MetaViewer.kt | 7 ++-- .../dataforge/vision/react/PropertyEditor.kt | 8 +++-- .../hep/dataforge/vision/react/TreeStyles.kt | 20 +++++------ .../dataforge/vision/react/valueChooser.kt | 4 +-- .../kotlin/hep/dataforge/vision/Colors.kt | 10 +++--- .../kotlin/hep/dataforge/vision/StyleSheet.kt | 4 +-- .../kotlin/hep/dataforge/vision/Vision.kt | 23 +++++++----- .../kotlin/hep/dataforge/vision/VisionBase.kt | 30 ++++++---------- .../hep/dataforge/vision/VisionChange.kt | 2 +- .../vision/VisionPropertyContainer.kt | 4 +-- .../kotlin/hep/dataforge/vision/misc.kt | 14 +++----- .../hep/dataforge/vision/html/HtmlTagTest.kt | 3 +- .../dataforge/vision/client/VisionClient.kt | 4 +-- .../hep/dataforge/vision/editor/FXMeta.kt | 20 +++++------ .../hep/dataforge/vision/solid/FXMaterials.kt | 17 ++++----- .../vision/solid/VisualObjectFXBinding.kt | 36 +++++++++---------- .../dataforge/vision/gdml/GdmlOptimizer.kt | 5 ++- .../hep/dataforge/vision/solid/Composite.kt | 15 ++++---- .../hep/dataforge/vision/solid/Solid.kt | 2 +- .../hep/dataforge/vision/solid/SolidGroup.kt | 6 ++-- .../dataforge/vision/solid/SolidMaterial.kt | 19 +++++----- .../dataforge/vision/solid/SolidReference.kt | 16 +++++---- .../vision/solid/specifications/Axes.kt | 2 +- .../solid/transform/RemoveSingleChild.kt | 2 +- .../hep/dataforge/vision/solid/ConvexTest.kt | 2 +- .../vision/solid/SerializationTest.kt | 5 ++- .../vision/solid/three/ThreeCanvas.kt | 4 +-- .../vision/solid/three/ThreeMaterials.kt | 8 ++--- .../hep/dataforge/vision/solid/three/three.kt | 2 +- 33 files changed, 156 insertions(+), 161 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 38355ee0..4589fe5e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,8 +2,8 @@ plugins { id("ru.mipt.npm.project") } -val dataforgeVersion by extra("0.2.1-dev-5") -val ktorVersion by extra("1.4.3") +val dataforgeVersion by extra("0.3.0-dev") +val ktorVersion by extra("1.5.0") val htmlVersion by extra("0.7.2") val kotlinWrappersVersion by extra("pre.129-kotlin-1.4.20") val fxVersion by extra("14") diff --git a/demo/gdml/src/jvmMain/kotlin/hep/dataforge/vision/gdml/demo/readFile.kt b/demo/gdml/src/jvmMain/kotlin/hep/dataforge/vision/gdml/demo/readFile.kt index da958c46..bcf18e51 100644 --- a/demo/gdml/src/jvmMain/kotlin/hep/dataforge/vision/gdml/demo/readFile.kt +++ b/demo/gdml/src/jvmMain/kotlin/hep/dataforge/vision/gdml/demo/readFile.kt @@ -1,7 +1,6 @@ package hep.dataforge.vision.gdml.demo import hep.dataforge.meta.DFExperimental -import hep.dataforge.meta.setItem import hep.dataforge.values.asValue import hep.dataforge.vision.gdml.readFile import hep.dataforge.vision.gdml.toVision diff --git a/demo/spatial-showcase/src/commonMain/kotlin/hep/dataforge/vision/solid/demo/demo.kt b/demo/spatial-showcase/src/commonMain/kotlin/hep/dataforge/vision/solid/demo/demo.kt index 76c871e6..584a2b33 100644 --- a/demo/spatial-showcase/src/commonMain/kotlin/hep/dataforge/vision/solid/demo/demo.kt +++ b/demo/spatial-showcase/src/commonMain/kotlin/hep/dataforge/vision/solid/demo/demo.kt @@ -39,15 +39,18 @@ fun Page.showcase() { demo("shapes", "Basic shapes") { box(100.0, 100.0, 100.0) { z = -110.0 + color("teal") } sphere(50.0) { x = 110 detail = 16 + color("red") } tube(50, height = 10, innerRadius = 25, angle = PI) { y = 110 detail = 16 rotationX = PI / 4 + color("blue") } } @@ -55,6 +58,7 @@ fun Page.showcase() { val group = group { box(100, 100, 100) { z = 110.0 + opacity = 0.5 } box(100, 100, 100) { @@ -155,7 +159,7 @@ fun Page.showcaseCSG() { detail = 32 } color(Colors.lightgreen) - opacity = 0.3 + opacity = 0.5 } composite(CompositeType.SUBTRACT) { y = -300 @@ -173,9 +177,11 @@ fun Page.showcaseCSG() { demo("CSG.custom", "CSG with manually created object") { intersect { tube(60, 10) { - detail = 64 + detail = 32 } box(100, 100, 100) + color("red") + opacity = 0.5 } } } \ No newline at end of file diff --git a/demo/spatial-showcase/src/jsMain/kotlin/hep/dataforge/vision/solid/demo/VariableBox.kt b/demo/spatial-showcase/src/jsMain/kotlin/hep/dataforge/vision/solid/demo/VariableBox.kt index 4fbb0903..206f4f0c 100644 --- a/demo/spatial-showcase/src/jsMain/kotlin/hep/dataforge/vision/solid/demo/VariableBox.kt +++ b/demo/spatial-showcase/src/jsMain/kotlin/hep/dataforge/vision/solid/demo/VariableBox.kt @@ -9,7 +9,6 @@ import hep.dataforge.vision.set import hep.dataforge.vision.setProperty import hep.dataforge.vision.solid.* import hep.dataforge.vision.solid.Solid.Companion.GEOMETRY_KEY -import hep.dataforge.vision.solid.SolidMaterial.Companion.MATERIAL_COLOR_KEY import hep.dataforge.vision.solid.three.* import info.laht.threekt.core.BufferGeometry import info.laht.threekt.core.Object3D @@ -30,8 +29,6 @@ internal class VariableBox(xSize: Number, ySize: Number, zSize: Number) : ThreeV scaleX = xSize scaleY = ySize scaleZ = zSize -// getProperty(MeshThreeFactory.EDGES_ENABLED_KEY, inherit = false, includeStyles = false) -// getProperty(MeshThreeFactory.WIREFRAME_ENABLED_KEY, inherit = false, includeStyles = false) } override fun render(three: ThreePlugin): Object3D { @@ -69,11 +66,8 @@ internal class VariableBox(xSize: Number, ySize: Number, zSize: Number) : ThreeV mesh.scale.set(newXSize, newYSize, newZSize) mesh.updateMatrix() } - //name.startsWith(MeshThreeFactory.WIREFRAME_KEY) -> mesh.applyWireFrame(this@VariableBox) name.startsWith(MeshThreeFactory.EDGES_KEY) -> mesh.applyEdges(this@VariableBox) - name.startsWith(MATERIAL_COLOR_KEY) -> { - mesh.updateMaterial(this) - } + //name.startsWith(MATERIAL_COLOR_KEY) -> mesh.updateMaterialProperty(this, name) else -> mesh.updateProperty(this@VariableBox, name) } } diff --git a/ui/react/src/main/kotlin/hep/dataforge/vision/react/MetaViewer.kt b/ui/react/src/main/kotlin/hep/dataforge/vision/react/MetaViewer.kt index 9c17206d..b3b1b25f 100644 --- a/ui/react/src/main/kotlin/hep/dataforge/vision/react/MetaViewer.kt +++ b/ui/react/src/main/kotlin/hep/dataforge/vision/react/MetaViewer.kt @@ -1,7 +1,8 @@ package hep.dataforge.vision.react import hep.dataforge.meta.Meta -import hep.dataforge.meta.MetaItem +import hep.dataforge.meta.NodeItem +import hep.dataforge.meta.ValueItem import hep.dataforge.meta.descriptors.ItemDescriptor import hep.dataforge.meta.descriptors.NodeDescriptor import hep.dataforge.meta.descriptors.defaultItem @@ -51,7 +52,7 @@ private fun RBuilder.metaViewerItem(props: MetaViewerProps) { } when (actualItem) { - is MetaItem.NodeItem -> { + is NodeItem -> { styledDiv { css { +TreeStyles.treeLeaf @@ -108,7 +109,7 @@ private fun RBuilder.metaViewerItem(props: MetaViewerProps) { } } } - is MetaItem.ValueItem -> { + is ValueItem -> { styledDiv { css { +TreeStyles.treeLeaf diff --git a/ui/react/src/main/kotlin/hep/dataforge/vision/react/PropertyEditor.kt b/ui/react/src/main/kotlin/hep/dataforge/vision/react/PropertyEditor.kt index ebd62473..c4eb03a0 100644 --- a/ui/react/src/main/kotlin/hep/dataforge/vision/react/PropertyEditor.kt +++ b/ui/react/src/main/kotlin/hep/dataforge/vision/react/PropertyEditor.kt @@ -9,6 +9,7 @@ import hep.dataforge.names.plus import hep.dataforge.values.Value import hep.dataforge.vision.hidden import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow @@ -65,12 +66,12 @@ private val PropertyEditorItem: FunctionalComponent = private fun RBuilder.propertyEditorItem(props: PropertyEditorProps) { var expanded: Boolean by useState { true } val itemName by useState { props.name ?: Name.EMPTY } - var item: MetaItem<*>? by useState { props.provider.getItem(itemName) } + var item: MetaItem? by useState { props.provider.getItem(itemName) } val descriptorItem: ItemDescriptor? = props.descriptor?.get(itemName) if(descriptorItem?.hidden == true) return //fail fast for hidden property - var actualItem: MetaItem? by useState { + var actualItem: MetaItem? by useState { item ?: props.defaultProvider?.getItem(itemName) ?: descriptorItem?.defaultItem() } @@ -110,7 +111,7 @@ private fun RBuilder.propertyEditorItem(props: PropertyEditorProps) { update() } - if (actualItem is MetaItem.NodeItem) { + if (actualItem is NodeItem) { styledDiv { css { +TreeStyles.treeLeaf @@ -248,6 +249,7 @@ public fun RBuilder.propertyEditor( } } +@OptIn(ExperimentalCoroutinesApi::class) private fun Config.flowUpdates(): Flow = callbackFlow { onChange(this) { name, _, _ -> launch { diff --git a/ui/react/src/main/kotlin/hep/dataforge/vision/react/TreeStyles.kt b/ui/react/src/main/kotlin/hep/dataforge/vision/react/TreeStyles.kt index 5afcedac..16602699 100644 --- a/ui/react/src/main/kotlin/hep/dataforge/vision/react/TreeStyles.kt +++ b/ui/react/src/main/kotlin/hep/dataforge/vision/react/TreeStyles.kt @@ -17,7 +17,7 @@ public object TreeStyles : StyleSheet("treeStyles", true) { /** * Style the caret/arrow */ - public val treeCaret by css { + public val treeCaret: RuleSet by css { cursor = Cursor.pointer userSelect = UserSelect.none /* Create the caret/arrow with a unicode, and style it */ @@ -32,7 +32,7 @@ public object TreeStyles : StyleSheet("treeStyles", true) { /** * Rotate the caret/arrow icon when clicked on (using JavaScript) */ - val treeCaredDown by css { + public val treeCaredDown:RuleSet by css { before { content = "\u25B6".quoted color = Color.black @@ -42,7 +42,7 @@ public object TreeStyles : StyleSheet("treeStyles", true) { } } - val treeItem by css { + public val treeItem:RuleSet by css { alignItems = Align.center paddingLeft = 10.px borderLeftStyle = BorderStyle.dashed @@ -53,27 +53,27 @@ public object TreeStyles : StyleSheet("treeStyles", true) { borderBottomColor = Color.lightGray } - val treeLeaf by css { + public val treeLeaf:RuleSet by css { display = Display.flex flexDirection = FlexDirection.row flexWrap = FlexWrap.nowrap //alignItems = Align.center } - val treeLabel by css { + public val treeLabel:RuleSet by css { overflow = Overflow.hidden flex(flexGrow = 1.0, flexShrink = 1.0) } - val treeLabelInactive by css { + public val treeLabelInactive: RuleSet by css { color = Color.lightGray } - val treeLabelSelected by css { + public val treeLabelSelected:RuleSet by css { backgroundColor = Color.lightBlue } - val linkButton by css { + public val linkButton:RuleSet by css { backgroundColor = Color.white border = "none" padding(left = 4.pt, right = 4.pt, top = 0.pt, bottom = 0.pt) @@ -86,7 +86,7 @@ public object TreeStyles : StyleSheet("treeStyles", true) { } } - val removeButton by css { + public val removeButton:RuleSet by css { backgroundColor = Color.white borderStyle = BorderStyle.solid borderRadius = 2.px @@ -104,7 +104,7 @@ public object TreeStyles : StyleSheet("treeStyles", true) { } } - val resizeableInput by css { + public val resizeableInput: RuleSet by css { overflow = Overflow.hidden maxWidth = 120.pt flex(flexGrow = 2.0, flexShrink = 2.0, flexBasis = 60.pt) diff --git a/ui/react/src/main/kotlin/hep/dataforge/vision/react/valueChooser.kt b/ui/react/src/main/kotlin/hep/dataforge/vision/react/valueChooser.kt index e0888a46..884791b5 100644 --- a/ui/react/src/main/kotlin/hep/dataforge/vision/react/valueChooser.kt +++ b/ui/react/src/main/kotlin/hep/dataforge/vision/react/valueChooser.kt @@ -20,7 +20,7 @@ import styled.styledInput import styled.styledSelect public external interface ValueChooserProps : RProps { - var item: MetaItem<*>? + var item: MetaItem? var descriptor: ValueDescriptor? var valueChanged: ((Value?) -> Unit)? } @@ -140,7 +140,7 @@ class ValueChooserComponent(props: ValueChooserProps) : RComponent?, + item: MetaItem?, descriptor: ValueDescriptor? = null, callback: (Value?) -> Unit ) { diff --git a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/Colors.kt b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/Colors.kt index 7dc41632..605f398c 100644 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/Colors.kt +++ b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/Colors.kt @@ -1,8 +1,6 @@ package hep.dataforge.vision -import hep.dataforge.meta.MetaItem -import hep.dataforge.meta.get -import hep.dataforge.meta.number +import hep.dataforge.meta.* import hep.dataforge.values.ValueType import hep.dataforge.values.int import hep.dataforge.values.string @@ -192,9 +190,9 @@ public object Colors { /** * Convert color represented as Meta to string of format #rrggbb */ - fun fromMeta(item: MetaItem<*>): String { + fun fromMeta(item: MetaItem): String { return when (item) { - is MetaItem.NodeItem<*> -> { + is NodeItem -> { val node = item.node rgbToString( node[RED_KEY].number?.toByte()?.toUByte() ?: 0u, @@ -202,7 +200,7 @@ public object Colors { node[BLUE_KEY].number?.toByte()?.toUByte() ?: 0u ) } - is MetaItem.ValueItem -> { + is ValueItem -> { if (item.value.type == ValueType.NUMBER) { rgbToString(item.value.int) } else { diff --git a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/StyleSheet.kt b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/StyleSheet.kt index a22ea6bb..80d5cdd2 100644 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/StyleSheet.kt +++ b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/StyleSheet.kt @@ -40,7 +40,7 @@ public inline class StyleSheet(private val owner: VisionGroup) { * Create and set a style */ public operator fun set(key: String, builder: MetaBuilder.() -> Unit) { - val newStyle = get(key)?.edit(builder) ?: Meta(builder) + val newStyle = get(key)?.builder()?.apply(builder) ?: Meta(builder) set(key, newStyle.seal()) } @@ -99,7 +99,7 @@ public tailrec fun Vision.getStyle(name: String): Meta? = /** * Resolve an item in all style layers */ -public fun Vision.getStyleItems(name: Name): Sequence> { +public fun Vision.getStyleItems(name: Name): Sequence { return styles.asSequence().map { getStyle(it) }.map { diff --git a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/Vision.kt b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/Vision.kt index 39d5ae5a..836d6f26 100644 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/Vision.kt +++ b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/Vision.kt @@ -1,5 +1,6 @@ package hep.dataforge.vision +import hep.dataforge.meta.Meta import hep.dataforge.meta.MetaItem import hep.dataforge.meta.MutableItemProvider import hep.dataforge.meta.descriptors.Described @@ -28,6 +29,12 @@ public interface Vision : Described { @Transient public var parent: VisionGroup? + /** + * Properties belonging to this [Vision] potentially including artificial properties + */ + @Transient + public val meta: Meta + /** * A coroutine scope for asynchronous calls and locks */ @@ -37,7 +44,7 @@ public interface Vision : Described { * A fast accessor method to get own property (no inheritance or styles). * Should be equivalent to `getProperty(name,false,false,false)`. */ - public fun getOwnProperty(name: Name): MetaItem<*>? + public fun getOwnProperty(name: Name): MetaItem? /** * Get property. @@ -49,13 +56,13 @@ public interface Vision : Described { inherit: Boolean = false, includeStyles: Boolean = true, includeDefaults: Boolean = true, - ): MetaItem<*>? + ): MetaItem? /** * Set the property value */ - public fun setProperty(name: Name, item: MetaItem<*>?, notify: Boolean = true) + public fun setProperty(name: Name, item: MetaItem?, notify: Boolean = true) /** * Subscribe on property updates. The subscription is bound to the given [scope] and canceled when the scope is canceled @@ -109,8 +116,8 @@ public fun Vision.asyncNotifyPropertyChange(propertyName: Name) { */ public val Vision.ownProperties: MutableItemProvider get() = object : MutableItemProvider { - override fun getItem(name: Name): MetaItem<*>? = getOwnProperty(name) - override fun setItem(name: Name, item: MetaItem<*>?): Unit = setProperty(name, item) + override fun getItem(name: Name): MetaItem? = getOwnProperty(name) + override fun setItem(name: Name, item: MetaItem?): Unit = setProperty(name, item) } @@ -123,14 +130,14 @@ public fun Vision.allProperties( includeStyles: Boolean? = null, includeDefaults: Boolean = true, ): MutableItemProvider = object : MutableItemProvider { - override fun getItem(name: Name): MetaItem<*>? = getProperty( + override fun getItem(name: Name): MetaItem? = getProperty( name, inherit = inherit ?: (descriptor?.get(name)?.inherited != false), includeStyles = includeStyles ?: (descriptor?.get(name)?.usesStyles == true), includeDefaults = includeDefaults ) - override fun setItem(name: Name, item: MetaItem<*>?): Unit = setProperty(name, item) + override fun setItem(name: Name, item: MetaItem?): Unit = setProperty(name, item) } /** @@ -141,7 +148,7 @@ public fun Vision.getProperty( inherit: Boolean = false, includeStyles: Boolean = true, includeDefaults: Boolean = true, -): MetaItem<*>? = getProperty(key.toName(), inherit, includeStyles, includeDefaults) +): MetaItem? = getProperty(key.toName(), inherit, includeStyles, includeDefaults) /** * A convenience method to pair [getProperty] diff --git a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionBase.kt b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionBase.kt index a70cdf21..753498f2 100644 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionBase.kt +++ b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionBase.kt @@ -1,9 +1,6 @@ package hep.dataforge.vision -import hep.dataforge.meta.Config -import hep.dataforge.meta.MetaItem -import hep.dataforge.meta.MutableMeta -import hep.dataforge.meta.asMetaItem +import hep.dataforge.meta.* import hep.dataforge.meta.descriptors.NodeDescriptor import hep.dataforge.meta.descriptors.defaultItem import hep.dataforge.meta.descriptors.get @@ -40,14 +37,14 @@ public open class VisionBase : Vision { /** * Object own properties excluding styles and inheritance */ - public var properties: Config? = null - private set + internal var properties: Config? = null + + override val meta: Meta get() = properties ?: Meta.EMPTY @Synchronized private fun getOrCreateConfig(): Config { if (properties == null) { val newProperties = Config() - properties = newProperties newProperties.onChange(this) { name, oldItem, newItem -> if (oldItem != newItem) { scope.launch { @@ -55,6 +52,7 @@ public open class VisionBase : Vision { } } } + properties = newProperties } return properties!! } @@ -62,7 +60,7 @@ public open class VisionBase : Vision { /** * A fast accessor method to get own property (no inheritance or styles */ - override fun getOwnProperty(name: Name): MetaItem<*>? { + override fun getOwnProperty(name: Name): MetaItem? { return properties?.getItem(name) } @@ -71,7 +69,7 @@ public open class VisionBase : Vision { inherit: Boolean, includeStyles: Boolean, includeDefaults: Boolean, - ): MetaItem<*>? = sequence { + ): MetaItem? = sequence { yield(getOwnProperty(name)) if (includeStyles) { yieldAll(getStyleItems(name)) @@ -83,7 +81,7 @@ public open class VisionBase : Vision { }.merge() @Synchronized - override fun setProperty(name: Name, item: MetaItem<*>?, notify: Boolean) { + override fun setProperty(name: Name, item: MetaItem?, notify: Boolean) { getOrCreateConfig().setItem(name, item) if (notify) { scope.launch { @@ -121,23 +119,17 @@ public open class VisionBase : Vision { propertyInvalidationFlow.emit(propertyName) } - public fun configure(block: suspend MutableMeta<*>.() -> Unit) { - scope.launch { - getOrCreateConfig().block() - } - } - override fun update(change: VisionChange) { - fun updateProperties(at: Name, item: MetaItem<*>) { + fun updateProperties(at: Name, item: MetaItem) { when (item) { - is MetaItem.ValueItem -> { + is ValueItem -> { if (item.value == Null) { setProperty(at, null) } else setProperty(at, item) } - is MetaItem.NodeItem -> item.node.items.forEach { (token, childItem) -> + is NodeItem -> item.node.items.forEach { (token, childItem) -> updateProperties(at + token, childItem) } } diff --git a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionChange.kt b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionChange.kt index 2bfde782..8d799ef8 100644 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionChange.kt +++ b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionChange.kt @@ -29,7 +29,7 @@ public class VisionChangeBuilder : VisionContainerBuilder { private fun getOrPutChild(visionName: Name): VisionChangeBuilder = children.getOrPut(visionName) { VisionChangeBuilder() } - public fun propertyChanged(visionName: Name, propertyName: Name, item: MetaItem<*>?) { + public fun propertyChanged(visionName: Name, propertyName: Name, item: MetaItem?) { if (visionName == Name.EMPTY) { //Write property removal as [Null] propertyChange[propertyName] = (item ?: Null.asMetaItem()) diff --git a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionPropertyContainer.kt b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionPropertyContainer.kt index f206f063..a8b3ecad 100644 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionPropertyContainer.kt +++ b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionPropertyContainer.kt @@ -12,7 +12,7 @@ public interface VisionPropertyContainer { inherit: Boolean = false, includeStyles: Boolean = true, includeDefaults: Boolean = true, - ): MetaItem<*>? + ): MetaItem? - public fun setProperty(name: Name, item: MetaItem<*>?, notify: Boolean = true) + public fun setProperty(name: Name, item: MetaItem?, notify: Boolean = true) } \ No newline at end of file diff --git a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/misc.kt b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/misc.kt index 047cd2fa..fb070582 100644 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/misc.kt +++ b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/misc.kt @@ -6,20 +6,16 @@ import hep.dataforge.values.asValue @DslMarker public annotation class VisionBuilder -public fun Sequence?>.merge(): MetaItem<*>? = when (val first = firstOrNull { it != null }) { +public fun Sequence.merge(): MetaItem? = when (val first = firstOrNull { it != null }) { null -> null - is MetaItem.ValueItem -> first //fast search for first entry if it is value - is MetaItem.NodeItem -> { + is ValueItem -> first //fast search for first entry if it is value + is NodeItem -> { //merge nodes if first encountered node is meta val laminate: Laminate = Laminate(mapNotNull { it.node }.toList()) - MetaItem.NodeItem(laminate) + NodeItem(laminate) } } -@DFExperimental -public val Vision.properties: Config? - get() = (this as? VisionBase)?.properties - /** * Control visibility of the element */ @@ -29,4 +25,4 @@ public var Vision.visible: Boolean? public fun Vision.configure(meta: Meta?): Unit = update(VisionChange(properties = meta)) -public fun Vision.configure(block: MutableMeta<*>.() -> Unit): Unit = configure(Meta(block)) \ No newline at end of file +public fun Vision.configure(block: MetaBuilder.() -> Unit): Unit = configure(Meta(block)) \ No newline at end of file diff --git a/visionforge-core/src/commonTest/kotlin/hep/dataforge/vision/html/HtmlTagTest.kt b/visionforge-core/src/commonTest/kotlin/hep/dataforge/vision/html/HtmlTagTest.kt index c6efe090..2d2ad125 100644 --- a/visionforge-core/src/commonTest/kotlin/hep/dataforge/vision/html/HtmlTagTest.kt +++ b/visionforge-core/src/commonTest/kotlin/hep/dataforge/vision/html/HtmlTagTest.kt @@ -3,6 +3,7 @@ package hep.dataforge.vision.html import hep.dataforge.meta.DFExperimental import hep.dataforge.meta.set import hep.dataforge.vision.VisionBase +import hep.dataforge.vision.configure import kotlinx.html.* import kotlinx.html.stream.createHTML import kotlin.test.Test @@ -34,7 +35,7 @@ class HtmlTagTest { div { h2 { +"Properties" } ul { - (vision as? VisionBase)?.properties?.items?.forEach { + (vision as? VisionBase)?.meta?.items?.forEach { li { a { +it.key.toString() } p { +it.value.toString() } diff --git a/visionforge-core/src/jsMain/kotlin/hep/dataforge/vision/client/VisionClient.kt b/visionforge-core/src/jsMain/kotlin/hep/dataforge/vision/client/VisionClient.kt index 11eaa0e1..edd5ae4d 100644 --- a/visionforge-core/src/jsMain/kotlin/hep/dataforge/vision/client/VisionClient.kt +++ b/visionforge-core/src/jsMain/kotlin/hep/dataforge/vision/client/VisionClient.kt @@ -134,11 +134,11 @@ public class VisionClient : AbstractPlugin() { stringData ) - if(change.vision!= null){ + if (change.vision != null) { renderVision(element, change.vision, outputMeta) } - logger.info { "Got update ${change.toString()} for output with name $name" } + logger.debug { "Got update $change for output with name $name" } visionMap[element]?.update(change) ?: console.info("Target vision for element $element with name $name not found") } else { diff --git a/visionforge-fx/src/main/kotlin/hep/dataforge/vision/editor/FXMeta.kt b/visionforge-fx/src/main/kotlin/hep/dataforge/vision/editor/FXMeta.kt index 84a286ed..c7460ff3 100644 --- a/visionforge-fx/src/main/kotlin/hep/dataforge/vision/editor/FXMeta.kt +++ b/visionforge-fx/src/main/kotlin/hep/dataforge/vision/editor/FXMeta.kt @@ -18,7 +18,7 @@ import tornadofx.* /** * A display for meta and descriptor */ -sealed class FXMeta> : Comparable> { +sealed class FXMeta> : Comparable> { abstract val name: NameToken abstract val parent: FXMetaNode? abstract val descriptionProperty: ObservableStringValue @@ -35,7 +35,7 @@ sealed class FXMeta> : Comparable> { } companion object { - fun > root( + fun > root( node: M, descriptor: NodeDescriptor? = null, rootName: String = "root" @@ -47,7 +47,7 @@ sealed class FXMeta> : Comparable> { } } -class FXMetaNode>( +class FXMetaNode>( override val name: NameToken, override val parent: FXMetaNode?, nodeValue: M? = null, @@ -89,7 +89,7 @@ class FXMetaNode>( init { bind(nodeProperty, descriptorProperty) - val listener: (Name, MetaItem<*>?, MetaItem<*>?) -> Unit = { name, _, _ -> + val listener: (Name, MetaItem?, MetaItem?) -> Unit = { name, _, _ -> if (name.length == 1) invalidate() } @@ -115,7 +115,7 @@ class FXMetaNode>( val actualItem = node?.items?.get(token) val actualDescriptor = descriptor?.items?.get(token.body) - if (actualItem is MetaItem.NodeItem || actualDescriptor is NodeDescriptor) { + if (actualItem is NodeItem || actualDescriptor is NodeDescriptor) { FXMetaNode(token, this@FXMetaNode) } else { FXMetaValue(token, this@FXMetaNode) @@ -134,7 +134,7 @@ class FXMetaNode>( } } -public class FXMetaValue>( +public class FXMetaValue>( override val name: NameToken, override val parent: FXMetaNode ) : FXMeta() { @@ -151,10 +151,10 @@ public class FXMetaValue>( //private val innerValueProperty = SimpleObjectProperty(value) public val valueProperty = descriptorProperty.objectBinding { descriptor -> - parent.node[name].value ?: descriptor?.default + parent.node?.get(name).value ?: descriptor?.default } - override val hasValue: ObservableBooleanValue = parent.nodeProperty.booleanBinding { it[name] != null } + override val hasValue: ObservableBooleanValue = parent.nodeProperty.booleanBinding { it?.get(name) != null } public val value by valueProperty @@ -169,12 +169,12 @@ public fun > FXMetaNode.remove(name: NameToken) { private fun > M.createEmptyNode(token: NameToken, append: Boolean): M { return if (append && token.hasIndex()) { val name = token.asName() - val index = (getIndexed(name).keys.mapNotNull { it.toIntOrNull() }.max() ?: -1) + 1 + val index = (getIndexed(name).keys.mapNotNull { it?.toIntOrNull() }.maxOrNull() ?: -1) + 1 val newName = name.withIndex(index.toString()) set(newName, Meta.EMPTY) get(newName).node!! } else { - this.setNode(token.asName(), Meta.EMPTY) + this.set(token.asName(), Meta.EMPTY) //FIXME possible concurrency bug get(token).node!! } diff --git a/visionforge-fx/src/main/kotlin/hep/dataforge/vision/solid/FXMaterials.kt b/visionforge-fx/src/main/kotlin/hep/dataforge/vision/solid/FXMaterials.kt index 9ae8fcf3..9e417438 100644 --- a/visionforge-fx/src/main/kotlin/hep/dataforge/vision/solid/FXMaterials.kt +++ b/visionforge-fx/src/main/kotlin/hep/dataforge/vision/solid/FXMaterials.kt @@ -1,9 +1,6 @@ package hep.dataforge.vision.solid -import hep.dataforge.meta.MetaItem -import hep.dataforge.meta.double -import hep.dataforge.meta.get -import hep.dataforge.meta.int +import hep.dataforge.meta.* import hep.dataforge.values.ValueType import hep.dataforge.values.int import hep.dataforge.values.string @@ -35,9 +32,9 @@ public object FXMaterials { * Infer color based on meta item * @param opacity default opacity */ -public fun MetaItem<*>.color(opacity: Double = 1.0): Color { +public fun MetaItem.color(opacity: Double = 1.0): Color { return when (this) { - is MetaItem.ValueItem -> if (this.value.type == ValueType.NUMBER) { + is ValueItem -> if (this.value.type == ValueType.NUMBER) { val int = value.int val red = int and 0x00ff0000 shr 16 val green = int and 0x0000ff00 shr 8 @@ -46,7 +43,7 @@ public fun MetaItem<*>.color(opacity: Double = 1.0): Color { } else { Color.web(this.value.string) } - is MetaItem.NodeItem -> { + is NodeItem -> { Color.rgb( node[Colors.RED_KEY]?.int ?: 0, node[Colors.GREEN_KEY]?.int ?: 0, @@ -60,11 +57,11 @@ public fun MetaItem<*>.color(opacity: Double = 1.0): Color { /** * Infer FX material based on meta item */ -public fun MetaItem<*>?.material(): Material { +public fun MetaItem?.material(): Material { return when (this) { null -> FXMaterials.GREY - is MetaItem.ValueItem -> PhongMaterial(color()) - is MetaItem.NodeItem -> PhongMaterial().apply { + is ValueItem -> PhongMaterial(color()) + is NodeItem -> PhongMaterial().apply { val opacity = node[SolidMaterial.OPACITY_KEY].double ?: 1.0 diffuseColor = node[SolidMaterial.COLOR_KEY]?.color(opacity) ?: Color.DARKGREY specularColor = node[SolidMaterial.SPECULAR_COLOR_KEY]?.color(opacity) ?: Color.WHITE diff --git a/visionforge-fx/src/main/kotlin/hep/dataforge/vision/solid/VisualObjectFXBinding.kt b/visionforge-fx/src/main/kotlin/hep/dataforge/vision/solid/VisualObjectFXBinding.kt index 75d9307c..f6f72e54 100644 --- a/visionforge-fx/src/main/kotlin/hep/dataforge/vision/solid/VisualObjectFXBinding.kt +++ b/visionforge-fx/src/main/kotlin/hep/dataforge/vision/solid/VisualObjectFXBinding.kt @@ -13,7 +13,7 @@ import tornadofx.* * A caching binding collection for [Vision] properties */ class VisualObjectFXBinding(val fx: FX3DPlugin, val obj: Vision) { - private val bindings = HashMap?>>() + private val bindings = HashMap>() init { obj.onPropertyChange(fx.context) { name -> @@ -31,10 +31,10 @@ class VisualObjectFXBinding(val fx: FX3DPlugin, val obj: Vision) { } } - operator fun get(key: Name): ObjectBinding?> { + operator fun get(key: Name): ObjectBinding { return bindings.getOrPut(key) { - object : ObjectBinding?>() { - override fun computeValue(): MetaItem<*>? = obj.getProperty(key) + object : ObjectBinding() { + override fun computeValue(): MetaItem? = obj.getProperty(key) } } } @@ -42,19 +42,19 @@ class VisualObjectFXBinding(val fx: FX3DPlugin, val obj: Vision) { operator fun get(key: String) = get(key.toName()) } -fun ObjectBinding?>.value() = objectBinding { it.value } -fun ObjectBinding?>.string() = stringBinding { it.string } -fun ObjectBinding?>.number() = objectBinding { it.number } -fun ObjectBinding?>.double() = objectBinding { it.double } -fun ObjectBinding?>.float() = objectBinding { it.float } -fun ObjectBinding?>.int() = objectBinding { it.int } -fun ObjectBinding?>.long() = objectBinding { it.long } -fun ObjectBinding?>.node() = objectBinding { it.node } +fun ObjectBinding.value() = objectBinding { it.value } +fun ObjectBinding.string() = stringBinding { it.string } +fun ObjectBinding.number() = objectBinding { it.number } +fun ObjectBinding.double() = objectBinding { it.double } +fun ObjectBinding.float() = objectBinding { it.float } +fun ObjectBinding.int() = objectBinding { it.int } +fun ObjectBinding.long() = objectBinding { it.long } +fun ObjectBinding.node() = objectBinding { it.node } -fun ObjectBinding?>.string(default: String) = stringBinding { it.string ?: default } -fun ObjectBinding?>.double(default: Double) = doubleBinding { it.double ?: default } -fun ObjectBinding?>.float(default: Float) = floatBinding { it.float ?: default } -fun ObjectBinding?>.int(default: Int) = integerBinding { it.int ?: default } -fun ObjectBinding?>.long(default: Long) = longBinding { it.long ?: default } +fun ObjectBinding.string(default: String) = stringBinding { it.string ?: default } +fun ObjectBinding.double(default: Double) = doubleBinding { it.double ?: default } +fun ObjectBinding.float(default: Float) = floatBinding { it.float ?: default } +fun ObjectBinding.int(default: Int) = integerBinding { it.int ?: default } +fun ObjectBinding.long(default: Long) = longBinding { it.long ?: default } -fun ObjectBinding?>.transform(transform: (MetaItem<*>) -> T) = objectBinding { it?.let(transform) } +fun ObjectBinding.transform(transform: (MetaItem) -> T) = objectBinding { it?.let(transform) } diff --git a/visionforge-gdml/src/commonMain/kotlin/hep/dataforge/vision/gdml/GdmlOptimizer.kt b/visionforge-gdml/src/commonMain/kotlin/hep/dataforge/vision/gdml/GdmlOptimizer.kt index 125614c6..a01e3db0 100644 --- a/visionforge-gdml/src/commonMain/kotlin/hep/dataforge/vision/gdml/GdmlOptimizer.kt +++ b/visionforge-gdml/src/commonMain/kotlin/hep/dataforge/vision/gdml/GdmlOptimizer.kt @@ -1,9 +1,8 @@ package hep.dataforge.vision.gdml import hep.dataforge.meta.DFExperimental -import hep.dataforge.meta.sequence +import hep.dataforge.meta.itemSequence import hep.dataforge.vision.Vision -import hep.dataforge.vision.properties import hep.dataforge.vision.solid.* public expect class Counter() { @@ -27,7 +26,7 @@ internal fun Vision.updateFrom(other: Vision): Vision { scaleY = scaleY.toDouble() * other.scaleY.toDouble() scaleZ = scaleZ.toDouble() * other.scaleZ.toDouble() } - other.properties?.sequence()?.forEach { (name, item) -> + other.meta.itemSequence().forEach { (name, item) -> if (getProperty(name) == null) { setProperty(name, item) } diff --git a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Composite.kt b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Composite.kt index e1e79ef8..6dc96076 100644 --- a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Composite.kt +++ b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Composite.kt @@ -1,6 +1,5 @@ package hep.dataforge.vision.solid -import hep.dataforge.meta.Meta import hep.dataforge.meta.update import hep.dataforge.names.NameToken import hep.dataforge.vision.* @@ -39,18 +38,20 @@ public inline fun VisionContainerBuilder.composite( val group = SolidGroup().apply(builder) val children = group.children.values.filterIsInstance() if (children.size != 2) error("Composite requires exactly two children") - return Composite(type, children[0], children[1]).also { - it.configure { update(group.properties ?: Meta.EMPTY) } + return Composite(type, children[0], children[1]).also { composite -> + composite.configure { + update(group.meta) + } if (group.position != null) { - it.position = group.position + composite.position = group.position } if (group.rotation != null) { - it.rotation = group.rotation + composite.rotation = group.rotation } if (group.scale != null) { - it.scale = group.scale + composite.scale = group.scale } - set(name, it) + set(name, composite) } } diff --git a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Solid.kt b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Solid.kt index 987fec3c..61710713 100644 --- a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Solid.kt +++ b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Solid.kt @@ -85,7 +85,7 @@ public interface Solid : Vision { if (first.position != second.position) return false if (first.rotation != second.rotation) return false if (first.scale != second.scale) return false - if (first.properties != second.properties) return false + if (first.meta != second.meta) return false return true } diff --git a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidGroup.kt b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidGroup.kt index b64074da..3b49f2fa 100644 --- a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidGroup.kt +++ b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidGroup.kt @@ -106,16 +106,16 @@ internal class Prototypes( } } - override fun getOwnProperty(name: Name): MetaItem<*>? = null + override fun getOwnProperty(name: Name): MetaItem? = null override fun getProperty( name: Name, inherit: Boolean, includeStyles: Boolean, includeDefaults: Boolean, - ): MetaItem<*>? = null + ): MetaItem? = null - override fun setProperty(name: Name, item: MetaItem<*>?, notify: Boolean) { + override fun setProperty(name: Name, item: MetaItem?, notify: Boolean) { error("Can't ser property of prototypes container") } diff --git a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidMaterial.kt b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidMaterial.kt index 2394030b..3e81748e 100644 --- a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidMaterial.kt +++ b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidMaterial.kt @@ -19,12 +19,12 @@ public class SolidMaterial : Scheme() { /** * Primary web-color for the material */ - public var color: ColorAccessor = ColorAccessor(config, COLOR_KEY) + public var color: ColorAccessor = ColorAccessor(items, COLOR_KEY) /** * Specular color for phong material */ - public var specularColor: ColorAccessor = ColorAccessor(config, SPECULAR_COLOR_KEY) + public var specularColor: ColorAccessor = ColorAccessor(items, SPECULAR_COLOR_KEY) /** * Opacity @@ -100,16 +100,17 @@ public val Solid.color: ColorAccessor public var Solid.material: SolidMaterial? get() = getProperty(MATERIAL_KEY, inherit = true).node?.let { SolidMaterial.read(it) } - set(value) = setProperty(MATERIAL_KEY, value?.config) + set(value) = setProperty(MATERIAL_KEY, value?.rootNode) @VisionBuilder public fun Solid.material(builder: SolidMaterial.() -> Unit) { - val node = allProperties(inherit = true).getItem(MATERIAL_KEY).node - if (node != null) { - SolidMaterial.update(node, builder) - } else { - setProperty(MATERIAL_KEY, SolidMaterial(builder)) - } + setProperty(MATERIAL_KEY, SolidMaterial(builder)) +// val node = getOwnProperty(MATERIAL_KEY).node +// if (node != null) { +// configure(SolidMaterial(builder).config) +// } else { +// setProperty(MATERIAL_KEY, SolidMaterial(builder)) +// } } public var Solid.opacity: Number? diff --git a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidReference.kt b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidReference.kt index d9fbdba0..261f16d8 100644 --- a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidReference.kt +++ b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidReference.kt @@ -17,7 +17,7 @@ private fun SolidReference.getRefProperty( inherit: Boolean, includeStyles: Boolean, includeDefaults: Boolean, -): MetaItem<*>? { +): MetaItem? { return sequence { yield(getOwnProperty(name)) if (includeStyles) { @@ -59,11 +59,11 @@ public class SolidReferenceGroup( private fun childPropertyName(childName: Name, propertyName: Name): Name = childToken(childName) + propertyName - private fun getChildProperty(childName: Name, propertyName: Name): MetaItem<*>? { + private fun getChildProperty(childName: Name, propertyName: Name): MetaItem? { return getOwnProperty(childPropertyName(childName, propertyName)) } - private fun setChildProperty(childName: Name, propertyName: Name, item: MetaItem<*>?, notify: Boolean) { + private fun setChildProperty(childName: Name, propertyName: Name, item: MetaItem?, notify: Boolean) { setProperty(childPropertyName(childName, propertyName), item, notify) } @@ -79,7 +79,7 @@ public class SolidReferenceGroup( inherit: Boolean, includeStyles: Boolean, includeDefaults: Boolean, - ): MetaItem<*>? = getRefProperty(name, inherit, includeStyles, includeDefaults) + ): MetaItem? = getRefProperty(name, inherit, includeStyles, includeDefaults) override val descriptor: NodeDescriptor get() = prototype.descriptor @@ -99,9 +99,11 @@ public class SolidReferenceGroup( ReferenceChild(childName + key.asName()) } ?: emptyMap() - override fun getOwnProperty(name: Name): MetaItem<*>? = getChildProperty(childName, name) + override val meta: Meta get() =TODO()// getChildProperty(childName, Name.EMPTY).node ?: Meta.EMPTY - override fun setProperty(name: Name, item: MetaItem<*>?, notify: Boolean) { + override fun getOwnProperty(name: Name): MetaItem? = getChildProperty(childName, name) + + override fun setProperty(name: Name, item: MetaItem?, notify: Boolean) { setChildProperty(childName, name, item, notify) } @@ -110,7 +112,7 @@ public class SolidReferenceGroup( inherit: Boolean, includeStyles: Boolean, includeDefaults: Boolean, - ): MetaItem<*>? = getRefProperty(name, inherit, includeStyles, includeDefaults) + ): MetaItem? = getRefProperty(name, inherit, includeStyles, includeDefaults) override var parent: VisionGroup? get() { diff --git a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/specifications/Axes.kt b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/specifications/Axes.kt index 5e835c83..022fd028 100644 --- a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/specifications/Axes.kt +++ b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/specifications/Axes.kt @@ -3,7 +3,7 @@ package hep.dataforge.vision.solid.specifications import hep.dataforge.meta.* public class Axes : Scheme() { - public var visible: Boolean by boolean(!config.isEmpty()) + public var visible: Boolean by boolean(rootNode?.isEmpty() != false) public var size: Double by double(AXIS_SIZE) public var width: Double by double(AXIS_WIDTH) diff --git a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/transform/RemoveSingleChild.kt b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/transform/RemoveSingleChild.kt index a5b5f1ba..0b69d23b 100644 --- a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/transform/RemoveSingleChild.kt +++ b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/transform/RemoveSingleChild.kt @@ -9,7 +9,7 @@ import hep.dataforge.vision.solid.* internal fun mergeChild(parent: VisionGroup, child: Vision): Vision { return child.apply { - configure(parent.properties) + configure(parent.meta) //parent.properties?.let { config.update(it) } diff --git a/visionforge-solid/src/commonTest/kotlin/hep/dataforge/vision/solid/ConvexTest.kt b/visionforge-solid/src/commonTest/kotlin/hep/dataforge/vision/solid/ConvexTest.kt index d2dbc4b3..912e3b5a 100644 --- a/visionforge-solid/src/commonTest/kotlin/hep/dataforge/vision/solid/ConvexTest.kt +++ b/visionforge-solid/src/commonTest/kotlin/hep/dataforge/vision/solid/ConvexTest.kt @@ -28,7 +28,7 @@ class ConvexTest { val json = SolidManager.jsonForSolids.encodeToJsonElement(Convex.serializer(), convex) val meta = json.toMetaItem().node!! - val points = meta.getIndexed("points").values.map { (it as MetaItem.NodeItem<*>).node.point3D() } + val points = meta.getIndexed("points").values.map { (it as NodeItem<*>).node.point3D() } assertEquals(8, points.count()) assertEquals(8, convex.points.size) diff --git a/visionforge-solid/src/commonTest/kotlin/hep/dataforge/vision/solid/SerializationTest.kt b/visionforge-solid/src/commonTest/kotlin/hep/dataforge/vision/solid/SerializationTest.kt index c7090eee..10531796 100644 --- a/visionforge-solid/src/commonTest/kotlin/hep/dataforge/vision/solid/SerializationTest.kt +++ b/visionforge-solid/src/commonTest/kotlin/hep/dataforge/vision/solid/SerializationTest.kt @@ -4,7 +4,6 @@ import hep.dataforge.names.Name import hep.dataforge.names.toName import hep.dataforge.vision.MutableVisionGroup import hep.dataforge.vision.get -import hep.dataforge.vision.properties import kotlin.test.Test import kotlin.test.assertEquals @@ -33,7 +32,7 @@ class SerializationTest { val string = SolidManager.encodeToString(cube) println(string) val newCube = SolidManager.decodeFromString(string) - assertEquals(cube.properties, newCube.properties) + assertEquals(cube.meta, newCube.meta) } @Test @@ -54,7 +53,7 @@ class SerializationTest { val string = SolidManager.encodeToString(group) println(string) val reconstructed = SolidManager.decodeFromString(string) as SolidGroup - assertEquals(group["cube"]?.properties, reconstructed["cube"]?.properties) + assertEquals(group["cube"]?.meta, reconstructed["cube"]?.meta) } } \ No newline at end of file diff --git a/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/ThreeCanvas.kt b/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/ThreeCanvas.kt index f5b679e5..a17ab549 100644 --- a/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/ThreeCanvas.kt +++ b/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/ThreeCanvas.kt @@ -1,6 +1,6 @@ package hep.dataforge.vision.solid.three -import hep.dataforge.meta.getItem +import hep.dataforge.meta.get import hep.dataforge.meta.string import hep.dataforge.names.Name import hep.dataforge.names.plus @@ -177,7 +177,7 @@ public class ThreeCanvas( } private fun addControls(element: Node, controls: Controls) { - when (controls.getItem("type").string) { + when (controls.get("type").string) { "trackball" -> TrackballControls(camera, element) else -> OrbitControls(camera, element) } diff --git a/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/ThreeMaterials.kt b/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/ThreeMaterials.kt index e9471af8..2d459217 100644 --- a/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/ThreeMaterials.kt +++ b/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/ThreeMaterials.kt @@ -109,15 +109,15 @@ public object ThreeMaterials { /** * Infer color based on meta item */ -public fun MetaItem<*>.getColor(): Color { +public fun MetaItem.getColor(): Color { return when (this) { - is MetaItem.ValueItem -> if (this.value.type == ValueType.NUMBER) { + is ValueItem -> if (this.value.type == ValueType.NUMBER) { val int = value.int Color(int) } else { Color(this.value.string) } - is MetaItem.NodeItem -> { + is NodeItem -> { Color( node[Colors.RED_KEY]?.int ?: 0, node[Colors.GREEN_KEY]?.int ?: 0, @@ -160,7 +160,7 @@ public fun Mesh.updateMaterial(vision: Vision) { } public fun Mesh.updateMaterialProperty(vision: Vision, propertyName: Name) { - if (material.cached) { + if (material.cached || propertyName == SolidMaterial.MATERIAL_KEY) { //generate a new material since cached material should not be changed updateMaterial(vision) } else { diff --git a/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/three.kt b/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/three.kt index 862960a9..9a11c550 100644 --- a/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/three.kt +++ b/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/three.kt @@ -17,7 +17,7 @@ import kotlin.math.PI public val Solid.euler: Euler get() = Euler(rotationX, rotationY, rotationZ, rotationOrder.name) -public val MetaItem<*>.vector: Vector3 get() = Vector3(node["x"].float ?: 0f, node["y"].float ?: 0f, node["z"].float ?: 0f) +public val MetaItem.vector: Vector3 get() = Vector3(node["x"].float ?: 0f, node["y"].float ?: 0f, node["z"].float ?: 0f) public fun Geometry.toBufferGeometry(): BufferGeometry = BufferGeometry().apply { fromGeometry(this@toBufferGeometry) }