diff --git a/demo/gdml/src/commonTest/kotlin/hep/dataforge/vision/gdml/GDMLVisualTest.kt b/demo/gdml/src/commonTest/kotlin/hep/dataforge/vision/gdml/GDMLVisualTest.kt index 59545bdf..0fa982dc 100644 --- a/demo/gdml/src/commonTest/kotlin/hep/dataforge/vision/gdml/GDMLVisualTest.kt +++ b/demo/gdml/src/commonTest/kotlin/hep/dataforge/vision/gdml/GDMLVisualTest.kt @@ -1,13 +1,14 @@ package hep.dataforge.vision.gdml -import hep.dataforge.meta.setItem import hep.dataforge.meta.string import hep.dataforge.names.toName import hep.dataforge.values.asValue import hep.dataforge.vision.gdml.demo.cubes +import hep.dataforge.vision.setProperty import hep.dataforge.vision.solid.SolidMaterial import kotlin.test.Test import kotlin.test.assertEquals +import kotlin.test.assertTrue class GDMLVisualTest { val gdml = cubes() @@ -24,7 +25,9 @@ class GDMLVisualTest { @Test fun testPrototypeProperty() { val visual = gdml.toVision() - visual["composite000.segment_0".toName()]?.setItem(SolidMaterial.MATERIAL_COLOR_KEY, "red".asValue()) - assertEquals("red", visual["composite000.segment_0".toName()]?.getItem(SolidMaterial.MATERIAL_COLOR_KEY).string) + val child = visual["composite000.segment_0".toName()] + assertTrue { child!= null } + child?.setProperty(SolidMaterial.MATERIAL_COLOR_KEY, "red".asValue()) + assertEquals("red", child?.getProperty(SolidMaterial.MATERIAL_COLOR_KEY).string) } } \ No newline at end of file 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 55d88a11..2d731fe2 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 @@ -1,6 +1,7 @@ package ru.mipt.npm.muon.monitor import hep.dataforge.vision.removeAll +import hep.dataforge.vision.setProperty import hep.dataforge.vision.solid.* import ru.mipt.npm.muon.monitor.Monitor.CENTRAL_LAYER_Z import ru.mipt.npm.muon.monitor.Monitor.LOWER_LAYER_Z @@ -63,7 +64,7 @@ class Model { fun reset() { map.values.forEach { it.config - it.setItem(SolidMaterial.MATERIAL_COLOR_KEY, null) + it.setProperty(SolidMaterial.MATERIAL_COLOR_KEY, null) } tracks.removeAll() } diff --git a/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMAppComponent.kt b/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMAppComponent.kt index 9917d75a..aeb8d815 100644 --- a/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMAppComponent.kt +++ b/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMAppComponent.kt @@ -1,6 +1,7 @@ package ru.mipt.npm.muon.monitor import hep.dataforge.context.Context +import hep.dataforge.meta.invoke import hep.dataforge.names.Name import hep.dataforge.names.NameToken import hep.dataforge.names.isEmpty @@ -172,7 +173,12 @@ val MMApp = functionalComponent("Muon monitor") { props -> else -> root[selected] } if (selectedObject != null) { - configEditor(selectedObject, default = selectedObject.getAllProperties(), key = selected) + configEditor( + selectedObject.config, + selectedObject.descriptor, + default = selectedObject.getAllProperties(), + key = selected + ) } } } 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 c5f023ff..08830f35 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 @@ -5,12 +5,12 @@ package hep.dataforge.vision.solid.demo import hep.dataforge.meta.int import hep.dataforge.meta.number import hep.dataforge.meta.set -import hep.dataforge.meta.setItem import hep.dataforge.names.plus import hep.dataforge.names.startsWith import hep.dataforge.values.asValue import hep.dataforge.vision.getProperty 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.three.* @@ -84,13 +84,13 @@ internal class VariableBox(xSize: Number, ySize: Number, zSize: Number) : ThreeV var variableZSize: Number get() = getProperty(Z_SIZE_KEY, false).number ?: 0f set(value) { - setItem(Z_SIZE_KEY, value.asValue()) + setProperty(Z_SIZE_KEY, value.asValue()) } var value: Int get() = getProperty("value", false).int ?: 0 set(value) { - setItem("value", value.asValue()) + setProperty("value", value.asValue()) val size = value.toFloat() / 255f * 20f scaleZ = size z = size / 2 diff --git a/playground/src/jsMain/kotlin/PlayGroundApp.kt b/playground/src/jsMain/kotlin/PlayGroundApp.kt index 4542a9e9..d5d1ce13 100644 --- a/playground/src/jsMain/kotlin/PlayGroundApp.kt +++ b/playground/src/jsMain/kotlin/PlayGroundApp.kt @@ -1,6 +1,7 @@ import hep.dataforge.context.Global import hep.dataforge.js.Application import hep.dataforge.js.startApplication +import hep.dataforge.meta.invoke import hep.dataforge.vision.bootstrap.visionPropertyEditor import hep.dataforge.vision.react.ThreeCanvasComponent import hep.dataforge.vision.react.objectTree @@ -18,7 +19,7 @@ public fun RBuilder.threeCanvas(object3D: Solid, options: Canvas3DOptions.() -> child(ThreeCanvasComponent) { attrs { this.obj = object3D - this.options = Canvas3DOptions.invoke(options) + this.options = Canvas3DOptions(options) } } } diff --git a/ui/bootstrap/src/main/kotlin/hep/dataforge/vision/bootstrap/visionPropertyEditor.kt b/ui/bootstrap/src/main/kotlin/hep/dataforge/vision/bootstrap/visionPropertyEditor.kt index 5651257b..b69c631b 100644 --- a/ui/bootstrap/src/main/kotlin/hep/dataforge/vision/bootstrap/visionPropertyEditor.kt +++ b/ui/bootstrap/src/main/kotlin/hep/dataforge/vision/bootstrap/visionPropertyEditor.kt @@ -17,7 +17,7 @@ public fun RBuilder.visionPropertyEditor( key: Any? = null ) { card("Properties") { - configEditor(item, descriptor, default, key) + configEditor(item.config, descriptor, default, key) } val styles = item.styles if(styles.isNotEmpty()) { @@ -40,6 +40,6 @@ public fun Element.visionPropertyEditor( item: Vision, descriptor: NodeDescriptor? = item.descriptor, default: Meta? = null -) = render(this) { +): Unit = render(this) { visionPropertyEditor(item, descriptor, default) } \ No newline at end of file diff --git a/ui/react/src/main/kotlin/hep/dataforge/vision/react/ConfigEditor.kt b/ui/react/src/main/kotlin/hep/dataforge/vision/react/ConfigEditor.kt index 9d9078f7..56bb24a6 100644 --- a/ui/react/src/main/kotlin/hep/dataforge/vision/react/ConfigEditor.kt +++ b/ui/react/src/main/kotlin/hep/dataforge/vision/react/ConfigEditor.kt @@ -233,10 +233,10 @@ public fun RBuilder.configEditor(config: Config, descriptor: NodeDescriptor? = n } } } - -public fun RBuilder.configEditor( - obj: Configurable, - descriptor: NodeDescriptor? = obj.descriptor, - default: Meta? = null, - key: Any? = null -) = configEditor(obj.config,descriptor, default, key) +// +//public fun RBuilder.configEditor( +// obj: Configurable, +// descriptor: NodeDescriptor?, +// default: Meta? = null, +// key: Any? = null +//): Unit = configEditor(obj.config, descriptor, default, key) diff --git a/ui/react/src/main/kotlin/hep/dataforge/vision/react/ThreeCanvasComponent.kt b/ui/react/src/main/kotlin/hep/dataforge/vision/react/ThreeCanvasComponent.kt index 5d961741..da424bab 100644 --- a/ui/react/src/main/kotlin/hep/dataforge/vision/react/ThreeCanvasComponent.kt +++ b/ui/react/src/main/kotlin/hep/dataforge/vision/react/ThreeCanvasComponent.kt @@ -1,6 +1,7 @@ package hep.dataforge.vision.react import hep.dataforge.context.Context +import hep.dataforge.meta.empty import hep.dataforge.names.Name import hep.dataforge.vision.solid.Solid import hep.dataforge.vision.solid.specifications.Canvas3DOptions diff --git a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/SimpleVisionGroup.kt b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/SimpleVisionGroup.kt deleted file mode 100644 index 96c2325c..00000000 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/SimpleVisionGroup.kt +++ /dev/null @@ -1,24 +0,0 @@ -package hep.dataforge.vision - -import hep.dataforge.names.NameToken -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable - - -@Serializable -@SerialName("vision.group") -public class SimpleVisionGroup : AbstractVisionGroup() { - @SerialName("children") - private val _children = HashMap() - override val children: Map get() = _children - - override fun removeChild(token: NameToken) { - _children.remove(token)?.apply { parent = null } - } - - override fun setChild(token: NameToken, child: Vision) { - _children[token] = child - } - - override fun createGroup(): SimpleVisionGroup = SimpleVisionGroup() -} \ No newline at end of file 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 3ceadc65..3a9cc81c 100644 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/Vision.kt +++ b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/Vision.kt @@ -2,6 +2,7 @@ package hep.dataforge.vision import hep.dataforge.meta.* import hep.dataforge.meta.descriptors.Described +import hep.dataforge.meta.descriptors.NodeDescriptor import hep.dataforge.names.Name import hep.dataforge.names.asName import hep.dataforge.names.toName @@ -70,6 +71,8 @@ public interface Vision : Configurable, Described { */ public fun update(change: Vision) + override val descriptor: NodeDescriptor? + public companion object { public const val TYPE: String = "vision" public val STYLE_KEY: Name = "@style".asName() @@ -133,8 +136,7 @@ public fun Vision.property( } } -//TODO replace by value -fun Vision.properties(inherit: Boolean = true): MutableItemProvider = object : MutableItemProvider { +public fun Vision.properties(inherit: Boolean = true): MutableItemProvider = object : MutableItemProvider { override fun getItem(name: Name): MetaItem<*>? { return getProperty(name, inherit) } diff --git a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/AbstractVisionGroup.kt b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionGroupBase.kt similarity index 84% rename from visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/AbstractVisionGroup.kt rename to visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionGroupBase.kt index aa43a14e..af8fee4e 100644 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/AbstractVisionGroup.kt +++ b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionGroupBase.kt @@ -1,20 +1,27 @@ package hep.dataforge.vision import hep.dataforge.names.* +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable import kotlinx.serialization.Transient /** * Abstract implementation of mutable group of [Vision] */ -public abstract class AbstractVisionGroup : VisionBase(), MutableVisionGroup { +@Serializable +@SerialName("vision.group") +public open class VisionGroupBase : VisionBase(), MutableVisionGroup { //protected abstract val _children: MutableMap + @SerialName("children") + protected val childrenInternal = LinkedHashMap() + /** * A map of top level named children */ - abstract override val children: Map + override val children: Map get() = childrenInternal final override var styleSheet: StyleSheet? = null private set @@ -24,7 +31,7 @@ public abstract class AbstractVisionGroup : VisionBase(), MutableVisionGroup { */ public open fun styleSheet(block: StyleSheet.() -> Unit) { if (styleSheet == null) { - styleSheet = StyleSheet(this@AbstractVisionGroup) + styleSheet = StyleSheet(this@VisionGroupBase) } styleSheet!!.block() } @@ -70,12 +77,9 @@ public abstract class AbstractVisionGroup : VisionBase(), MutableVisionGroup { /** * Remove a child with given name token */ - protected abstract fun removeChild(token: NameToken) - - /** - * Add, remove or replace child with given name - */ - protected abstract fun setChild(token: NameToken, child: Vision) + public fun removeChild(token: NameToken) { + childrenInternal.remove(token) + } /** * Add a static child. Statics could not be found by name, removed or replaced. Changing statics also do not trigger events. @@ -84,15 +88,15 @@ public abstract class AbstractVisionGroup : VisionBase(), MutableVisionGroup { attach(NameToken("@static", index = child.hashCode().toString()), child) } - protected abstract fun createGroup(): AbstractVisionGroup + protected open fun createGroup(): VisionGroupBase = VisionGroupBase() /** * Set parent for given child and attach it */ - protected fun attach(token: NameToken, child: Vision) { + private fun attach(token: NameToken, child: Vision) { if (child.parent == null) { child.parent = this - setChild(token, child) + childrenInternal[token] = child } else if (child.parent !== this) { error("Can't reassign existing parent for $child") } @@ -101,7 +105,7 @@ public abstract class AbstractVisionGroup : VisionBase(), MutableVisionGroup { /** * Recursively create a child group */ - private fun createGroups(name: Name): AbstractVisionGroup { + private fun createGroups(name: Name): VisionGroupBase { return when { name.isEmpty() -> error("Should be unreachable") name.length == 1 -> { @@ -110,7 +114,7 @@ public abstract class AbstractVisionGroup : VisionBase(), MutableVisionGroup { null -> createGroup().also { child -> attach(token, child) } - is AbstractVisionGroup -> current + is VisionGroupBase -> current else -> error("Can't create group with name $name because it exists and not a group") } } diff --git a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionManager.kt b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionManager.kt index 1078abd6..63dc4930 100644 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionManager.kt +++ b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionManager.kt @@ -83,7 +83,7 @@ public class VisionManager(meta: Meta) : AbstractPlugin(meta) { private val defaultSerialModule: SerializersModule = SerializersModule { polymorphic(Vision::class) { - subclass(SimpleVisionGroup.serializer()) + subclass(VisionGroupBase.serializer()) } } } diff --git a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/collectChange.kt b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/collectChange.kt index e2a128bc..cb61939f 100644 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/collectChange.kt +++ b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/collectChange.kt @@ -1,7 +1,7 @@ package hep.dataforge.vision import hep.dataforge.meta.* -import hep.dataforge.meta.descriptors.ItemDescriptor +import hep.dataforge.meta.descriptors.NodeDescriptor import hep.dataforge.names.Name import hep.dataforge.names.NameToken import kotlinx.coroutines.CoroutineScope @@ -43,7 +43,7 @@ public object NullVision : Vision { } override val config: Config get() = Config() - override val descriptor: ItemDescriptor? get() = null + override val descriptor: NodeDescriptor? get() = null } private fun Vision.collectChange(scope: CoroutineScope, collector: Vision): Job = scope.launch { @@ -56,7 +56,7 @@ private fun Vision.collectChange(scope: CoroutineScope, collector: Vision): Job //Subscribe for children changes children.forEach { (token, child) -> val childCollector: Vision = if (child is VisionGroup) { - SimpleVisionGroup() + VisionGroupBase() } else { VisionBase() } @@ -94,7 +94,7 @@ public fun Vision.flowChanges(scope: CoroutineScope, collectionDuration: Duratio emit(this@flowChanges) while (true) { val collector: Vision = if (this is VisionGroup) { - SimpleVisionGroup() + VisionGroupBase() } else { VisionBase() } diff --git a/visionforge-core/src/jvmMain/kotlin/hep/dataforge/vision/editor/VisualObjectEditorFragment.kt b/visionforge-core/src/jvmMain/kotlin/hep/dataforge/vision/editor/VisualObjectEditorFragment.kt index 7da6885d..5a559d4f 100644 --- a/visionforge-core/src/jvmMain/kotlin/hep/dataforge/vision/editor/VisualObjectEditorFragment.kt +++ b/visionforge-core/src/jvmMain/kotlin/hep/dataforge/vision/editor/VisualObjectEditorFragment.kt @@ -6,6 +6,7 @@ import hep.dataforge.meta.descriptors.NodeDescriptor import hep.dataforge.meta.update import hep.dataforge.vision.Vision import hep.dataforge.vision.resolveStyle +import hep.dataforge.vision.setProperty import javafx.beans.binding.Binding import javafx.beans.property.SimpleObjectProperty import javafx.scene.Node @@ -36,7 +37,7 @@ class VisualObjectEditorFragment(val selector: (Vision) -> Meta) : Fragment() { val config = Config().apply { update(meta) onChange(this@VisualObjectEditorFragment) { key, _, after -> - visualObject.setItem(key, after) + visualObject.setProperty(key, after) } } //remember old config reference to cleanup listeners 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 e7d3587f..6e176501 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 @@ -11,6 +11,7 @@ import hep.dataforge.values.asValue import hep.dataforge.vision.Vision import hep.dataforge.vision.Vision.Companion.VISIBLE_KEY import hep.dataforge.vision.enum +import hep.dataforge.vision.setProperty import hep.dataforge.vision.solid.Solid.Companion.DETAIL_KEY import hep.dataforge.vision.solid.Solid.Companion.IGNORE_KEY import hep.dataforge.vision.solid.Solid.Companion.LAYER_KEY @@ -121,8 +122,8 @@ public enum class RotationOrder { * Rotation order */ public var Solid.rotationOrder: RotationOrder - get() = getItem(Solid.ROTATION_ORDER_KEY).enum() ?: RotationOrder.XYZ - set(value) = setValue(Solid.ROTATION_ORDER_KEY, value.name.asValue()) + get() = getProperty(Solid.ROTATION_ORDER_KEY).enum() ?: RotationOrder.XYZ + set(value) = setProperty(Solid.ROTATION_ORDER_KEY, value.name.asValue()) /** @@ -130,7 +131,7 @@ public var Solid.rotationOrder: RotationOrder */ public var Solid.detail: Int? get() = getProperty(DETAIL_KEY, false).int - set(value) = setValue(DETAIL_KEY, value?.asValue()) + set(value) = setProperty(DETAIL_KEY, value?.asValue()) /** * If this property is true, the object will be ignored on render. @@ -138,7 +139,7 @@ public var Solid.detail: Int? */ public var Vision.ignore: Boolean? get() = getProperty(IGNORE_KEY, false).boolean - set(value) = setValue(IGNORE_KEY, value?.asValue()) + set(value) = setProperty(IGNORE_KEY, value?.asValue()) //var VisualObject.selected: Boolean? // get() = getProperty(SELECTED_KEY).boolean 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 381a2f5c..d4c76661 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 @@ -7,7 +7,6 @@ import hep.dataforge.names.NameToken import hep.dataforge.vision.* import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable -import kotlin.collections.set public interface PrototypeHolder { public val parent: VisionGroup? @@ -19,7 +18,7 @@ public interface PrototypeHolder { */ @Serializable @SerialName("group.solid") -public class SolidGroup : AbstractVisionGroup(), Solid, PrototypeHolder { +public class SolidGroup : VisionGroupBase(), Solid, PrototypeHolder { override val descriptor: NodeDescriptor get() = Solid.descriptor @@ -36,7 +35,7 @@ public class SolidGroup : AbstractVisionGroup(), Solid, PrototypeHolder { public fun prototypes(builder: MutableVisionGroup.() -> Unit): Unit { (prototypes ?: Prototypes().also { prototypes = it - attach(it) + it.parent = this }).run(builder) } @@ -49,23 +48,12 @@ public class SolidGroup : AbstractVisionGroup(), Solid, PrototypeHolder { @Serializable(Point3DSerializer::class) override var scale: Point3D? = null - @SerialName("children") - private val _children = LinkedHashMap() - override val children: Map get() = _children - override fun attachChildren() { prototypes?.parent = this prototypes?.attachChildren() super.attachChildren() } - override fun removeChild(token: NameToken) { - _children.remove(token)?.apply { parent = null } - } - - override fun setChild(token: NameToken, child: Vision) { - _children[token] = child - } // /** // * TODO add special static group to hold statics without propagation @@ -103,25 +91,15 @@ public fun MutableVisionGroup.group(name: String, action: SolidGroup.() -> Unit /** * A special class which works as a holder for prototypes */ +@Serializable(PrototypesSerializer::class) internal class Prototypes( override var children: MutableMap = LinkedHashMap(), -) : AbstractVisionGroup(), MutableVisionGroup, PrototypeHolder { +) : VisionGroupBase(), PrototypeHolder { override fun styleSheet(block: StyleSheet.() -> Unit) { error("Can't define stylesheet for prototypes block") } - override fun removeChild(token: NameToken) { - children.remove(token) - childrenChanged(token, null) - } - - override fun setChild(token: NameToken, child: Vision) { - children[token] = child - } - - override fun createGroup() = SimpleVisionGroup() - override var properties: Config? get() = null set(_) { diff --git a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidManager.kt b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidManager.kt index 8db54e7e..be737599 100644 --- a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidManager.kt +++ b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidManager.kt @@ -4,12 +4,12 @@ import hep.dataforge.context.AbstractPlugin import hep.dataforge.context.Context import hep.dataforge.context.PluginFactory import hep.dataforge.context.PluginTag -import hep.dataforge.meta.* +import hep.dataforge.meta.Meta import hep.dataforge.names.Name import hep.dataforge.names.toName -import hep.dataforge.vision.SimpleVisionGroup import hep.dataforge.vision.Vision import hep.dataforge.vision.VisionGroup +import hep.dataforge.vision.VisionGroupBase import hep.dataforge.vision.VisionManager import hep.dataforge.vision.VisionManager.Companion.VISION_SERIAL_MODULE_TARGET import kotlinx.serialization.json.Json @@ -51,7 +51,7 @@ public class SolidManager(meta: Meta) : AbstractPlugin(meta) { contextual(Point2DSerializer) polymorphic(Vision::class) { - subclass(SimpleVisionGroup.serializer()) + subclass(VisionGroupBase.serializer()) solids() } 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 50d7d508..34a12916 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 @@ -9,6 +9,7 @@ import hep.dataforge.names.plus import hep.dataforge.values.ValueType import hep.dataforge.values.asValue import hep.dataforge.vision.Colors +import hep.dataforge.vision.setProperty import hep.dataforge.vision.solid.SolidMaterial.Companion.MATERIAL_COLOR_KEY import hep.dataforge.vision.solid.SolidMaterial.Companion.MATERIAL_KEY import hep.dataforge.vision.solid.SolidMaterial.Companion.MATERIAL_OPACITY_KEY @@ -48,7 +49,7 @@ public class SolidMaterial : Scheme() { internal val WIREFRAME_KEY = "wireframe".asName() public val MATERIAL_WIREFRAME_KEY: Name = MATERIAL_KEY + WIREFRAME_KEY - public val descriptor: NodeDescriptor by lazy { + public override val descriptor: NodeDescriptor by lazy { //must be lazy to avoid initialization bug NodeDescriptor { value(COLOR_KEY) { @@ -79,17 +80,17 @@ public class SolidMaterial : Scheme() { * Set color as web-color */ public fun Solid.color(webColor: String) { - setItem(MATERIAL_COLOR_KEY, webColor.asValue()) + setProperty(MATERIAL_COLOR_KEY, webColor.asValue()) } /** * Set color as integer */ public fun Solid.color(rgb: Int) { - setItem(MATERIAL_COLOR_KEY, rgb.asValue()) + setProperty(MATERIAL_COLOR_KEY, rgb.asValue()) } -public fun Solid.color(r: UByte, g: UByte, b: UByte): Unit = setItem( +public fun Solid.color(r: UByte, g: UByte, b: UByte): Unit = setProperty( MATERIAL_COLOR_KEY, Colors.rgbToString(r, g, b).asValue() ) @@ -98,13 +99,13 @@ public fun Solid.color(r: UByte, g: UByte, b: UByte): Unit = setItem( * Web colors representation of the color in `#rrggbb` format or HTML name */ public var Solid.color: String? - get() = getItem(MATERIAL_COLOR_KEY)?.let { Colors.fromMeta(it) } + get() = getProperty(MATERIAL_COLOR_KEY)?.let { Colors.fromMeta(it) } set(value) { - setItem(MATERIAL_COLOR_KEY, value?.asValue()) + setProperty(MATERIAL_COLOR_KEY, value?.asValue()) } public val Solid.material: SolidMaterial? - get() = getItem(MATERIAL_KEY).node?.let { SolidMaterial.wrap(it) } + get() = getProperty(MATERIAL_KEY).node?.let { SolidMaterial.wrap(it) } public fun Solid.material(builder: SolidMaterial.() -> Unit) { val node = config[MATERIAL_KEY].node @@ -116,7 +117,7 @@ public fun Solid.material(builder: SolidMaterial.() -> Unit) { } public var Solid.opacity: Double? - get() = getItem(MATERIAL_OPACITY_KEY).double + get() = getProperty(MATERIAL_OPACITY_KEY).double set(value) { - setItem(MATERIAL_OPACITY_KEY, value?.asValue()) + setProperty(MATERIAL_OPACITY_KEY, value?.asValue()) } \ No newline at end of file diff --git a/visionforge-solid/src/commonTest/kotlin/hep/dataforge/vision/solid/PropertyTest.kt b/visionforge-solid/src/commonTest/kotlin/hep/dataforge/vision/solid/PropertyTest.kt index 48c7ec9d..a12679e5 100644 --- a/visionforge-solid/src/commonTest/kotlin/hep/dataforge/vision/solid/PropertyTest.kt +++ b/visionforge-solid/src/commonTest/kotlin/hep/dataforge/vision/solid/PropertyTest.kt @@ -18,7 +18,7 @@ class PropertyTest { box = box(100, 100, 100) } } - assertEquals(22, box?.getItem("test".asName()).int) + assertEquals(22, box?.getProperty("test".asName()).int) } @Test @@ -36,7 +36,7 @@ class PropertyTest { } } } - assertEquals(22, box?.getItem("test".asName()).int) + assertEquals(22, box?.getProperty("test".asName()).int) } @Test diff --git a/visionforge-solid/src/jsMain/kotlin/hep/dataforge/vision/solid/three/MeshThreeFactory.kt b/visionforge-solid/src/jsMain/kotlin/hep/dataforge/vision/solid/three/MeshThreeFactory.kt index 5cd52b01..44478c61 100644 --- a/visionforge-solid/src/jsMain/kotlin/hep/dataforge/vision/solid/three/MeshThreeFactory.kt +++ b/visionforge-solid/src/jsMain/kotlin/hep/dataforge/vision/solid/three/MeshThreeFactory.kt @@ -85,9 +85,9 @@ fun Mesh.applyProperties(obj: Solid): Mesh = apply{ fun Mesh.applyEdges(obj: Solid) { val edges = children.find { it.name == "@edges" } as? LineSegments //inherited edges definition, enabled by default - if (obj.getItem(MeshThreeFactory.EDGES_ENABLED_KEY).boolean != false) { + if (obj.getProperty(MeshThreeFactory.EDGES_ENABLED_KEY).boolean != false) { val bufferGeometry = geometry as? BufferGeometry ?: return - val material = ThreeMaterials.getLineMaterial(obj.getItem(MeshThreeFactory.EDGES_MATERIAL_KEY).node, true) + val material = ThreeMaterials.getLineMaterial(obj.getProperty(MeshThreeFactory.EDGES_MATERIAL_KEY).node, true) if (edges == null) { add( LineSegments( @@ -114,9 +114,9 @@ fun Mesh.applyWireFrame(obj: Solid) { (it as LineSegments).dispose() } //inherited wireframe definition, disabled by default - if (obj.getItem(MeshThreeFactory.WIREFRAME_ENABLED_KEY).boolean == true) { + if (obj.getProperty(MeshThreeFactory.WIREFRAME_ENABLED_KEY).boolean == true) { val bufferGeometry = geometry as? BufferGeometry ?: return - val material = ThreeMaterials.getLineMaterial(obj.getItem(MeshThreeFactory.WIREFRAME_MATERIAL_KEY).node, true) + val material = ThreeMaterials.getLineMaterial(obj.getProperty(MeshThreeFactory.WIREFRAME_MATERIAL_KEY).node, true) add( LineSegments( WireframeGeometry(bufferGeometry), diff --git a/visionforge-solid/src/jsMain/kotlin/hep/dataforge/vision/solid/three/ThreeCanvas.kt b/visionforge-solid/src/jsMain/kotlin/hep/dataforge/vision/solid/three/ThreeCanvas.kt index 33a86ebf..14a5e12e 100644 --- a/visionforge-solid/src/jsMain/kotlin/hep/dataforge/vision/solid/three/ThreeCanvas.kt +++ b/visionforge-solid/src/jsMain/kotlin/hep/dataforge/vision/solid/three/ThreeCanvas.kt @@ -1,9 +1,7 @@ package hep.dataforge.vision.solid.three import hep.dataforge.context.Context -import hep.dataforge.meta.Meta -import hep.dataforge.meta.getItem -import hep.dataforge.meta.string +import hep.dataforge.meta.* import hep.dataforge.names.Name import hep.dataforge.names.plus import hep.dataforge.names.toName @@ -275,4 +273,4 @@ public fun ThreePlugin.render( obj: Solid, onSelect: ((Name?) -> Unit)? = null, options: Canvas3DOptions.() -> Unit = {}, -): Unit = output(element, Canvas3DOptions(options), onSelect).render(obj) \ No newline at end of file +): Unit = output(element, Canvas3DOptions.invoke(options), onSelect).render(obj) \ No newline at end of file diff --git a/visionforge-solid/src/jsMain/kotlin/hep/dataforge/vision/solid/three/ThreeLineFactory.kt b/visionforge-solid/src/jsMain/kotlin/hep/dataforge/vision/solid/three/ThreeLineFactory.kt index 5954a5a3..987f19b1 100644 --- a/visionforge-solid/src/jsMain/kotlin/hep/dataforge/vision/solid/three/ThreeLineFactory.kt +++ b/visionforge-solid/src/jsMain/kotlin/hep/dataforge/vision/solid/three/ThreeLineFactory.kt @@ -18,7 +18,7 @@ public object ThreeLineFactory : ThreeFactory { vertices = obj.points.toTypedArray() } - val material = ThreeMaterials.getLineMaterial(obj.getItem(MeshThreeFactory.EDGES_MATERIAL_KEY).node, true) + val material = ThreeMaterials.getLineMaterial(obj.getProperty(MeshThreeFactory.EDGES_MATERIAL_KEY).node, true) material.linewidth = obj.thickness.toDouble() material.color = obj.color?.let { Color(it) } ?: DEFAULT_LINE_COLOR diff --git a/visionforge-solid/src/jsMain/kotlin/hep/dataforge/vision/solid/three/ThreeMaterials.kt b/visionforge-solid/src/jsMain/kotlin/hep/dataforge/vision/solid/three/ThreeMaterials.kt index 7566e136..969e725f 100644 --- a/visionforge-solid/src/jsMain/kotlin/hep/dataforge/vision/solid/three/ThreeMaterials.kt +++ b/visionforge-solid/src/jsMain/kotlin/hep/dataforge/vision/solid/three/ThreeMaterials.kt @@ -12,23 +12,22 @@ import info.laht.threekt.materials.MeshPhongMaterial import info.laht.threekt.math.Color -object ThreeMaterials { - val DEFAULT_COLOR = Color(Colors.darkgreen) - val DEFAULT = MeshBasicMaterial().apply { +public object ThreeMaterials { + public val DEFAULT_COLOR: Color = Color(Colors.darkgreen) + public val DEFAULT: MeshBasicMaterial = MeshBasicMaterial().apply { color.set(DEFAULT_COLOR) } - val DEFAULT_LINE_COLOR = Color(Colors.black) - val DEFAULT_LINE = LineBasicMaterial().apply { + public val DEFAULT_LINE_COLOR: Color = Color(Colors.black) + public val DEFAULT_LINE: LineBasicMaterial = LineBasicMaterial().apply { color.set(DEFAULT_LINE_COLOR) } - val SELECTED_MATERIAL = LineBasicMaterial().apply { + public val SELECTED_MATERIAL: LineBasicMaterial = LineBasicMaterial().apply { color.set(Colors.ivory) linewidth = 8.0 } - - val HIGHLIGHT_MATERIAL = LineBasicMaterial().apply { + public val HIGHLIGHT_MATERIAL: LineBasicMaterial = LineBasicMaterial().apply { color.set(Colors.blue) linewidth = 8.0 } @@ -75,7 +74,7 @@ object ThreeMaterials { } fun getMaterial(vision3D: Vision, cache: Boolean): Material { - val meta = vision3D.getItem(SolidMaterial.MATERIAL_KEY).node ?: return DEFAULT + val meta = vision3D.getProperty(SolidMaterial.MATERIAL_KEY).node ?: return DEFAULT return if (cache) { materialCache.getOrPut(meta) { buildMaterial(meta) } } else { diff --git a/visionforge-solid/src/jvmMain/kotlin/hep/dataforge/vision/solid/fx/FX3DPlugin.kt b/visionforge-solid/src/jvmMain/kotlin/hep/dataforge/vision/solid/fx/FX3DPlugin.kt index 712b2b2e..8d90d3b2 100644 --- a/visionforge-solid/src/jvmMain/kotlin/hep/dataforge/vision/solid/fx/FX3DPlugin.kt +++ b/visionforge-solid/src/jvmMain/kotlin/hep/dataforge/vision/solid/fx/FX3DPlugin.kt @@ -71,7 +71,7 @@ class FX3DPlugin : AbstractPlugin() { is PolyLine -> PolyLine3D( obj.points.map { it.point }, obj.thickness.toFloat(), - obj.getItem(SolidMaterial.MATERIAL_COLOR_KEY)?.color() + obj.getProperty(SolidMaterial.MATERIAL_COLOR_KEY)?.color() ).apply { this.meshView.cullFace = CullFace.FRONT } diff --git a/visionforge-solid/src/jvmMain/kotlin/hep/dataforge/vision/solid/fx/FXCanvas3D.kt b/visionforge-solid/src/jvmMain/kotlin/hep/dataforge/vision/solid/fx/FXCanvas3D.kt index 996d4fe5..1c90819b 100644 --- a/visionforge-solid/src/jvmMain/kotlin/hep/dataforge/vision/solid/fx/FXCanvas3D.kt +++ b/visionforge-solid/src/jvmMain/kotlin/hep/dataforge/vision/solid/fx/FXCanvas3D.kt @@ -3,6 +3,7 @@ package hep.dataforge.vision.solid.fx import hep.dataforge.context.Context import hep.dataforge.context.ContextAware import hep.dataforge.meta.Meta +import hep.dataforge.meta.empty import hep.dataforge.output.Renderer import hep.dataforge.vision.solid.Solid import hep.dataforge.vision.solid.specifications.Canvas3DOptions diff --git a/visionforge-solid/src/jvmMain/kotlin/hep/dataforge/vision/solid/fx/VisualObjectFXBinding.kt b/visionforge-solid/src/jvmMain/kotlin/hep/dataforge/vision/solid/fx/VisualObjectFXBinding.kt index 164110ad..0ba7af20 100644 --- a/visionforge-solid/src/jvmMain/kotlin/hep/dataforge/vision/solid/fx/VisualObjectFXBinding.kt +++ b/visionforge-solid/src/jvmMain/kotlin/hep/dataforge/vision/solid/fx/VisualObjectFXBinding.kt @@ -34,7 +34,7 @@ class VisualObjectFXBinding(val obj: Vision) { operator fun get(key: Name): ObjectBinding?> { return bindings.getOrPut(key) { object : ObjectBinding?>() { - override fun computeValue(): MetaItem<*>? = obj.getItem(key) + override fun computeValue(): MetaItem<*>? = obj.getProperty(key) } } }