From 2b02f151d283c9daeff8b9f228d3a508e17a64ce Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Fri, 25 Dec 2020 19:44:53 +0300 Subject: [PATCH] Migrate to DF 0.3 --- .../kotlin/ru/mipt/npm/muon/monitor/Model.kt | 1 - .../hep/dataforge/vision/solid/demo/demo.kt | 9 +++--- .../kotlin/hep/dataforge/vision/VisionBase.kt | 23 +++++++++++---- .../dataforge/vision/solid/ColorAccessor.kt | 2 +- .../hep/dataforge/vision/solid/SolidGroup.kt | 1 + .../dataforge/vision/solid/SolidMaterial.kt | 12 ++------ .../solid/specifications/Canvas3DOptions.kt | 6 ++-- .../dataforge/vision/solid/CompositeTest.kt | 29 +++++++++++++++++++ 8 files changed, 58 insertions(+), 25 deletions(-) create mode 100644 visionforge-solid/src/commonTest/kotlin/hep/dataforge/vision/solid/CompositeTest.kt diff --git a/demo/muon-monitor/src/commonMain/kotlin/ru/mipt/npm/muon/monitor/Model.kt b/demo/muon-monitor/src/commonMain/kotlin/ru/mipt/npm/muon/monitor/Model.kt index 9027b26a..b4b883fc 100644 --- a/demo/muon-monitor/src/commonMain/kotlin/ru/mipt/npm/muon/monitor/Model.kt +++ b/demo/muon-monitor/src/commonMain/kotlin/ru/mipt/npm/muon/monitor/Model.kt @@ -52,7 +52,6 @@ class Model { detector(it) } } - tracks = group("tracks") } 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 584a2b33..2dacf455 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 @@ -147,8 +147,7 @@ fun Page.showcaseCSG() { detail = 32 } material { - color(Colors.red) - wireframe = false + color(Colors.pink) } } composite(CompositeType.UNION) { @@ -158,8 +157,8 @@ fun Page.showcaseCSG() { sphere(50){ detail = 32 } - color(Colors.lightgreen) - opacity = 0.5 + color("lightgreen") + opacity = 0.7 } composite(CompositeType.SUBTRACT) { y = -300 @@ -169,7 +168,7 @@ fun Page.showcaseCSG() { sphere(50){ detail = 32 } - color(Colors.teal) + color("teal") opacity = 0.7 } } 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 753498f2..899c2877 100644 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionBase.kt +++ b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionBase.kt @@ -16,6 +16,7 @@ import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch +import kotlinx.css.th import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.Transient @@ -27,18 +28,28 @@ internal data class PropertyListener( ) +/** + * A full base implementation for a [Vision] + * @param properties Object own properties excluding styles and inheritance + */ @Serializable @SerialName("vision") -public open class VisionBase : Vision { +public open class VisionBase(internal var properties: Config? = null) : Vision { + + init { + //used during deserialization only + properties?.onChange(this) { name, oldItem, newItem -> + if (oldItem != newItem) { + scope.launch { + notifyPropertyChanged(name) + } + } + } + } @Transient override var parent: VisionGroup? = null - /** - * Object own properties excluding styles and inheritance - */ - internal var properties: Config? = null - override val meta: Meta get() = properties ?: Meta.EMPTY @Synchronized diff --git a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/ColorAccessor.kt b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/ColorAccessor.kt index 3b78d7b5..05e8cad9 100644 --- a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/ColorAccessor.kt +++ b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/ColorAccessor.kt @@ -46,6 +46,6 @@ public operator fun ColorAccessor?.invoke(r: UByte, g: UByte, b: UByte) { this?.value = Colors.rgbToString(r, g, b).asValue() } -public fun ColorAccessor?.clear(){ +public fun ColorAccessor?.clear() { this?.value = null } \ No newline at end of file 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 3b49f2fa..578a06e6 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 @@ -101,6 +101,7 @@ internal class Prototypes( ) : VisionGroupBase(children as? MutableMap ?: children.toMutableMap()), PrototypeHolder { init { + //used during deserialization only children.values.forEach { it.parent = parent } 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 3e81748e..314ea57e 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(items, COLOR_KEY) + public var color: ColorAccessor = ColorAccessor(this, COLOR_KEY) /** * Specular color for phong material */ - public var specularColor: ColorAccessor = ColorAccessor(items, SPECULAR_COLOR_KEY) + public var specularColor: ColorAccessor = ColorAccessor(this, SPECULAR_COLOR_KEY) /** * Opacity @@ -104,13 +104,7 @@ public var Solid.material: SolidMaterial? @VisionBuilder public fun Solid.material(builder: SolidMaterial.() -> Unit) { - setProperty(MATERIAL_KEY, SolidMaterial(builder)) -// val node = getOwnProperty(MATERIAL_KEY).node -// if (node != null) { -// configure(SolidMaterial(builder).config) -// } else { -// setProperty(MATERIAL_KEY, SolidMaterial(builder)) -// } + ownProperties.getChild(MATERIAL_KEY).update(SolidMaterial, builder) } public var Solid.opacity: Number? diff --git a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/specifications/Canvas3DOptions.kt b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/specifications/Canvas3DOptions.kt index b62ea275..cfe59171 100644 --- a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/specifications/Canvas3DOptions.kt +++ b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/specifications/Canvas3DOptions.kt @@ -4,9 +4,9 @@ import hep.dataforge.meta.* import hep.dataforge.names.Name public class Canvas3DOptions : Scheme() { - public var axes: Axes by spec(Axes, Axes.empty()) - public var camera: Camera by spec(Camera, Camera.empty()) - public var controls: Controls by spec(Controls, Controls.empty()) + public var axes: Axes by spec(Axes) + public var camera: Camera by spec(Camera) + public var controls: Controls by spec(Controls) public var minSize: Int by int(400) public var minWith: Number by number { minSize } diff --git a/visionforge-solid/src/commonTest/kotlin/hep/dataforge/vision/solid/CompositeTest.kt b/visionforge-solid/src/commonTest/kotlin/hep/dataforge/vision/solid/CompositeTest.kt new file mode 100644 index 00000000..45cc6d49 --- /dev/null +++ b/visionforge-solid/src/commonTest/kotlin/hep/dataforge/vision/solid/CompositeTest.kt @@ -0,0 +1,29 @@ +package hep.dataforge.vision.solid + +import hep.dataforge.vision.Colors +import kotlin.test.Test +import kotlin.test.assertEquals + +class CompositeTest { + + @Test + fun testCompositeBuilder(){ + lateinit var composite: Composite + SolidGroup { + composite = composite(CompositeType.INTERSECT) { + y = 300 + box(100, 100, 100) { + z = 50 + } + sphere(50) { + detail = 32 + } + material { + color("pink") + } + } + } + + assertEquals("pink", composite.color.string) + } +} \ No newline at end of file