From 75a988b546b879f5f0000df705fe2818612eeca6 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 16 Mar 2020 22:24:57 +0300 Subject: [PATCH] Move to new kotlin and plugin --- build.gradle.kts | 22 ++++---- dataforge-vis-common/build.gradle.kts | 21 ++----- .../vis/common/AbstractVisualObject.kt | 4 +- .../kotlin/hep/dataforge/vis/common/Colors.kt | 7 ++- .../hep/dataforge/vis/common/StyleSheet.kt | 5 +- .../hep/dataforge/vis/common/VisualObject.kt | 21 +++---- .../hep/dataforge/vis/common/valueWidget.kt | 9 +-- .../dataforge/vis/js/editor/propertyEditor.kt | 4 +- .../dataforge/vis/fx/editor/ConfigEditor.kt | 2 +- .../hep/dataforge/vis/fx/editor/FXMeta.kt | 6 +- .../dataforge/vis/fx/editor/ValueChooser.kt | 2 +- .../vis/fx/editor/ValueChooserBase.kt | 2 +- .../fx/editor/VisualObjectEditorFragment.kt | 2 +- .../dataforge/vis/fx/demo/MetaEditorDemo.kt | 22 ++++---- .../vis/spatial/gdml/GDMLTransformer.kt | 3 +- .../vis/spatial/gdml/generateSchema.kt | 10 ++-- dataforge-vis-spatial/build.gradle.kts | 18 ++---- .../kotlin/hep/dataforge/vis/spatial/Box.kt | 2 - .../hep/dataforge/vis/spatial/Composite.kt | 2 - .../hep/dataforge/vis/spatial/ConeSegment.kt | 2 - .../hep/dataforge/vis/spatial/Convex.kt | 2 - .../hep/dataforge/vis/spatial/Extruded.kt | 2 - .../hep/dataforge/vis/spatial/Label3D.kt | 5 +- .../hep/dataforge/vis/spatial/Material3D.kt | 32 ++++++----- .../hep/dataforge/vis/spatial/PolyLine.kt | 4 +- .../kotlin/hep/dataforge/vis/spatial/Proxy.kt | 5 +- .../hep/dataforge/vis/spatial/Sphere.kt | 2 - .../kotlin/hep/dataforge/vis/spatial/Tube.kt | 2 - .../hep/dataforge/vis/spatial/Visual3D.kt | 17 +++--- .../dataforge/vis/spatial/VisualGroup3D.kt | 9 +-- .../dataforge/vis/spatial/VisualObject3D.kt | 15 ++--- .../hep/dataforge/vis/spatial/geometry.kt | 5 +- .../dataforge/vis/spatial/serialization.kt | 56 +++++++------------ .../vis/spatial/specifications/Axes.kt | 18 ++++++ .../vis/spatial/specifications/AxesSpec.kt | 17 ------ .../{CameraSpec.kt => Camera.kt} | 13 +++-- .../vis/spatial/specifications/Canvas.kt | 15 +++++ .../vis/spatial/specifications/CanvasSpec.kt | 15 ----- .../vis/spatial/specifications/Controls.kt | 9 +++ .../spatial/specifications/ControlsSpec.kt | 11 ---- .../hep/dataforge/vis/spatial/ConvexTest.kt | 7 ++- .../vis/spatial/three/ThreeCanvas.kt | 28 +++++----- .../vis/spatial/three/ThreeVisualObject.kt | 2 - .../hep/dataforge/vis/spatial/three/csg.kt | 2 +- .../dataforge/vis/spatial/fx/FXCanvas3D.kt | 4 +- .../dataforge/vis/spatial/fx/OrbitControls.kt | 2 +- demo/gdml/build.gradle.kts | 17 ++---- .../vis/spatial/gdml/demo/GDMLDemoApp.kt | 8 +-- .../{web => resources}/css/jsoneditor.min.css | 0 .../jsMain/{web => resources}/css/main.css | 0 .../img/jsoneditor-icons.svg | 0 .../src/jsMain/{web => resources}/index.html | 0 .../vis/spatial/gdml/demo/readFile.kt | 4 +- demo/muon-monitor/build.gradle.kts | 13 ++--- .../ru/mipt/npm/muon/monitor/MMDemoApp.kt | 4 +- .../{web => resources}/css/jsoneditor.min.css | 0 .../jsMain/{web => resources}/css/main.css | 0 .../img/jsoneditor-icons.svg | 0 .../src/jsMain/{web => resources}/index.html | 0 demo/spatial-showcase/build.gradle.kts | 12 ++-- .../hep/dataforge/vis/spatial/demo/demo.kt | 12 ++-- .../vis/spatial/demo/ThreeDemoApp.kt | 9 --- .../vis/spatial/demo/ThreeDemoGrid.kt | 4 -- .../src/jsMain/{web => resources}/index.html | 0 .../dataforge/vis/spatial/demo/FXDemoGrid.kt | 4 +- 65 files changed, 230 insertions(+), 322 deletions(-) create mode 100644 dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/specifications/Axes.kt delete mode 100644 dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/specifications/AxesSpec.kt rename dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/specifications/{CameraSpec.kt => Camera.kt} (67%) create mode 100644 dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/specifications/Canvas.kt delete mode 100644 dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/specifications/CanvasSpec.kt create mode 100644 dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/specifications/Controls.kt delete mode 100644 dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/specifications/ControlsSpec.kt rename demo/gdml/src/jsMain/{web => resources}/css/jsoneditor.min.css (100%) rename demo/gdml/src/jsMain/{web => resources}/css/main.css (100%) rename demo/gdml/src/jsMain/{web => resources}/img/jsoneditor-icons.svg (100%) rename demo/gdml/src/jsMain/{web => resources}/index.html (100%) rename demo/muon-monitor/src/jsMain/{web => resources}/css/jsoneditor.min.css (100%) rename demo/muon-monitor/src/jsMain/{web => resources}/css/main.css (100%) rename demo/muon-monitor/src/jsMain/{web => resources}/img/jsoneditor-icons.svg (100%) rename demo/muon-monitor/src/jsMain/{web => resources}/index.html (100%) rename demo/spatial-showcase/src/jsMain/{web => resources}/index.html (100%) diff --git a/build.gradle.kts b/build.gradle.kts index c1218820..82f0e8d5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,13 +1,10 @@ -import scientifik.useSerialization +import scientifik.fx +import scientifik.serialization -val dataforgeVersion by extra("0.1.5-dev-6") +val dataforgeVersion by extra("0.1.5") plugins { - val kotlinVersion = "1.3.61" - val toolsVersion = "0.3.2" - - kotlin("jvm") version kotlinVersion apply false - id("kotlin-dce-js") version kotlinVersion apply false + val toolsVersion = "0.4.0" id("scientifik.mpp") version toolsVersion apply false id("scientifik.jvm") version toolsVersion apply false id("scientifik.js") version toolsVersion apply false @@ -26,16 +23,17 @@ allprojects { } group = "hep.dataforge" - version = "0.1.1-dev" -} - -subprojects{ - this.useSerialization() + version = "0.1.2-dev" } val githubProject by extra("dataforge-vis") val bintrayRepo by extra("dataforge") +val fxVersion by extra("14") subprojects { apply(plugin = "scientifik.publish") + serialization() + afterEvaluate { + fx(scientifik.FXModule.CONTROLS, version = fxVersion) + } } \ No newline at end of file diff --git a/dataforge-vis-common/build.gradle.kts b/dataforge-vis-common/build.gradle.kts index 6459c337..1774b6ed 100644 --- a/dataforge-vis-common/build.gradle.kts +++ b/dataforge-vis-common/build.gradle.kts @@ -1,21 +1,16 @@ -import org.openjfx.gradle.JavaFXOptions -import scientifik.useSerialization +import scientifik.serialization plugins { id("scientifik.mpp") - id("org.openjfx.javafxplugin") } val dataforgeVersion: String by rootProject.extra //val kvisionVersion: String by rootProject.extra("2.0.0-M1") -useSerialization() +serialization() +val fxVersion: String by rootProject.extra kotlin { - jvm{ - withJava() - } - sourceSets { commonMain{ dependencies { @@ -24,7 +19,7 @@ kotlin { } jvmMain{ dependencies { - api("no.tornado:tornadofx:1.7.19") + api("no.tornado:tornadofx:1.7.20") //api("no.tornado:tornadofx-controlsfx:0.1.1") api("de.jensd:fontawesomefx-fontawesome:4.7.0-11"){ exclude(group = "org.openjfx") @@ -38,13 +33,9 @@ kotlin { dependencies { api("hep.dataforge:dataforge-output-html:$dataforgeVersion") //api(npm("bootstrap","4.4.1")) - implementation(npm("jsoneditor")) + implementation(npm("jsoneditor","8.6.1")) implementation(npm("file-saver")) } } } -} - -configure { - modules("javafx.controls") -} +} \ No newline at end of file diff --git a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualObject.kt b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualObject.kt index 5487a304..3c76a4cc 100644 --- a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualObject.kt +++ b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualObject.kt @@ -1,8 +1,10 @@ package hep.dataforge.vis.common import hep.dataforge.meta.* +import hep.dataforge.meta.scheme.setProperty import hep.dataforge.names.Name import hep.dataforge.names.asName +import hep.dataforge.values.Value import hep.dataforge.vis.common.VisualObject.Companion.STYLE_KEY import kotlinx.serialization.Transient @@ -22,7 +24,7 @@ abstract class AbstractVisualObject : VisualObject { get() = properties?.get(STYLE_KEY).stringList set(value) { //val allStyles = (field + value).distinct() - setProperty(STYLE_KEY, value) + setProperty(STYLE_KEY, Value.of(value)) updateStyles(value) } diff --git a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/Colors.kt b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/Colors.kt index 3335c086..5681f572 100644 --- a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/Colors.kt +++ b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/Colors.kt @@ -1,6 +1,9 @@ package hep.dataforge.vis.common -import hep.dataforge.meta.* +import hep.dataforge.meta.Meta +import hep.dataforge.meta.MetaItem +import hep.dataforge.meta.get +import hep.dataforge.meta.number import hep.dataforge.values.ValueType import hep.dataforge.values.int import kotlin.math.max @@ -234,7 +237,7 @@ object Colors { /** * Convert three bytes representing color to Meta */ - fun rgbToMeta(r: UByte, g: UByte, b: UByte): Meta = buildMeta { + fun rgbToMeta(r: UByte, g: UByte, b: UByte): Meta = Meta { RED_KEY put r.toInt() GREEN_KEY put g.toInt() BLUE_KEY put b.toInt() diff --git a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/StyleSheet.kt b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/StyleSheet.kt index 7b70a0dc..365fff8e 100644 --- a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/StyleSheet.kt +++ b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/StyleSheet.kt @@ -2,7 +2,6 @@ package hep.dataforge.vis.common -import hep.dataforge.io.serialization.MetaSerializer import hep.dataforge.meta.* import hep.dataforge.names.Name import hep.dataforge.names.asName @@ -46,7 +45,7 @@ class StyleSheet() { } operator fun set(key: String, builder: MetaBuilder.() -> Unit) { - val newStyle = get(key)?.let { buildMeta(it, builder) } ?: buildMeta(builder) + val newStyle = get(key)?.edit(builder) ?: Meta(builder) set(key, newStyle.seal()) } @@ -58,7 +57,7 @@ class StyleSheet() { TODO("Not yet implemented") } - override fun serialize(encoder: Encoder, obj: StyleSheet) { + override fun serialize(encoder: Encoder, value: StyleSheet) { TODO("Not yet implemented") } diff --git a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualObject.kt b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualObject.kt index 6aad894a..9e4cfd0b 100644 --- a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualObject.kt +++ b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualObject.kt @@ -1,6 +1,9 @@ package hep.dataforge.vis.common -import hep.dataforge.meta.* +import hep.dataforge.meta.Laminate +import hep.dataforge.meta.Meta +import hep.dataforge.meta.MetaItem +import hep.dataforge.meta.scheme.Configurable import hep.dataforge.names.Name import hep.dataforge.names.asName import hep.dataforge.names.toName @@ -28,17 +31,12 @@ interface VisualObject : Configurable { */ fun allProperties(): Laminate - /** - * Set property for this object - */ - fun setProperty(name: Name, value: Any?) { - config[name] = value - } - /** * Get property including or excluding parent properties */ - fun getProperty(name: Name, inherit: Boolean = true): MetaItem<*>? + fun getProperty(name: Name, inherit: Boolean): MetaItem<*>? + + override fun getProperty(name: Name): MetaItem<*>? = getProperty(name, true) /** * Trigger property invalidation event. If [name] is empty, notify that the whole object is changed @@ -77,11 +75,6 @@ interface VisualObject : Configurable { */ fun VisualObject.getProperty(key: String, inherit: Boolean = true): MetaItem<*>? = getProperty(key.toName(), inherit) -/** - * Set [VisualObject] property using key as a String - */ -fun VisualObject.setProperty(key: String, value: Any?) = setProperty(key.toName(), value) - /** * Add style name to the list of styles to be resolved later. The style with given name does not necessary exist at the moment. */ diff --git a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/valueWidget.kt b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/valueWidget.kt index 8c45686f..8f3ade43 100644 --- a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/valueWidget.kt +++ b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/valueWidget.kt @@ -1,7 +1,8 @@ package hep.dataforge.vis.common -import hep.dataforge.descriptors.ValueDescriptor import hep.dataforge.meta.* +import hep.dataforge.meta.descriptors.ValueDescriptor +import hep.dataforge.meta.scheme.getProperty /** * Extension property to access the "widget" key of [ValueDescriptor] @@ -9,14 +10,14 @@ import hep.dataforge.meta.* var ValueDescriptor.widget: Meta get() = this.config["widget"].node?: EmptyMeta set(value) { - this.config["widget"] = value + config["widget"] = value } /** * Extension property to access the "widget.type" key of [ValueDescriptor] */ var ValueDescriptor.widgetType: String? - get() = this["widget.type"].string + get() = getProperty("widget.type").string set(value) { - this.config["widget.type"] = value + config["widget.type"] = value } \ No newline at end of file diff --git a/dataforge-vis-common/src/jsMain/kotlin/hep/dataforge/vis/js/editor/propertyEditor.kt b/dataforge-vis-common/src/jsMain/kotlin/hep/dataforge/vis/js/editor/propertyEditor.kt index 590c208f..19f715a0 100644 --- a/dataforge-vis-common/src/jsMain/kotlin/hep/dataforge/vis/js/editor/propertyEditor.kt +++ b/dataforge-vis-common/src/jsMain/kotlin/hep/dataforge/vis/js/editor/propertyEditor.kt @@ -1,9 +1,9 @@ package hep.dataforge.vis.js.editor -import hep.dataforge.io.toJson import hep.dataforge.js.jsObject import hep.dataforge.meta.DynamicMeta import hep.dataforge.meta.Meta +import hep.dataforge.meta.toJson import hep.dataforge.meta.update import hep.dataforge.names.Name import hep.dataforge.names.isEmpty @@ -12,8 +12,6 @@ import hep.dataforge.vis.common.findStyle import kotlinx.html.dom.append import kotlinx.html.js.* import org.w3c.dom.Element -import kotlin.collections.forEach -import kotlin.collections.isNotEmpty import kotlin.collections.set import kotlin.dom.clear diff --git a/dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/editor/ConfigEditor.kt b/dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/editor/ConfigEditor.kt index 93af2df4..c04b0719 100644 --- a/dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/editor/ConfigEditor.kt +++ b/dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/editor/ConfigEditor.kt @@ -8,8 +8,8 @@ package hep.dataforge.vis.fx.editor import de.jensd.fx.glyphs.fontawesome.FontAwesomeIcon import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView import hep.dataforge.context.Global -import hep.dataforge.descriptors.NodeDescriptor import hep.dataforge.meta.Config +import hep.dataforge.meta.descriptors.NodeDescriptor import hep.dataforge.names.NameToken import hep.dataforge.vis.fx.dfIconView import javafx.scene.Node diff --git a/dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/editor/FXMeta.kt b/dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/editor/FXMeta.kt index 2eb14215..7a9395ee 100644 --- a/dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/editor/FXMeta.kt +++ b/dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/editor/FXMeta.kt @@ -1,9 +1,9 @@ package hep.dataforge.vis.fx.editor -import hep.dataforge.descriptors.ItemDescriptor -import hep.dataforge.descriptors.NodeDescriptor -import hep.dataforge.descriptors.ValueDescriptor import hep.dataforge.meta.* +import hep.dataforge.meta.descriptors.ItemDescriptor +import hep.dataforge.meta.descriptors.NodeDescriptor +import hep.dataforge.meta.descriptors.ValueDescriptor import hep.dataforge.names.Name import hep.dataforge.names.NameToken import hep.dataforge.names.asName diff --git a/dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/editor/ValueChooser.kt b/dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/editor/ValueChooser.kt index f8946a4a..72128543 100644 --- a/dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/editor/ValueChooser.kt +++ b/dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/editor/ValueChooser.kt @@ -7,9 +7,9 @@ package hep.dataforge.vis.fx.editor import hep.dataforge.context.Context import hep.dataforge.context.Named -import hep.dataforge.descriptors.ValueDescriptor import hep.dataforge.meta.EmptyMeta import hep.dataforge.meta.Meta +import hep.dataforge.meta.descriptors.ValueDescriptor import hep.dataforge.names.toName import hep.dataforge.provider.Type import hep.dataforge.provider.provideByType diff --git a/dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/editor/ValueChooserBase.kt b/dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/editor/ValueChooserBase.kt index 7cbbcc1f..dc474cb5 100644 --- a/dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/editor/ValueChooserBase.kt +++ b/dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/editor/ValueChooserBase.kt @@ -5,7 +5,7 @@ */ package hep.dataforge.vis.fx.editor -import hep.dataforge.descriptors.ValueDescriptor +import hep.dataforge.meta.descriptors.ValueDescriptor import hep.dataforge.values.Null import hep.dataforge.values.Value import javafx.beans.property.SimpleObjectProperty diff --git a/dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/editor/VisualObjectEditorFragment.kt b/dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/editor/VisualObjectEditorFragment.kt index fd52d64c..05d9315c 100644 --- a/dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/editor/VisualObjectEditorFragment.kt +++ b/dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/editor/VisualObjectEditorFragment.kt @@ -1,8 +1,8 @@ package hep.dataforge.vis.fx.editor -import hep.dataforge.descriptors.NodeDescriptor import hep.dataforge.meta.Config import hep.dataforge.meta.Meta +import hep.dataforge.meta.descriptors.NodeDescriptor import hep.dataforge.meta.update import hep.dataforge.vis.common.VisualObject import hep.dataforge.vis.common.findStyle diff --git a/dataforge-vis-common/src/jvmTest/kotlin/hep/dataforge/vis/fx/demo/MetaEditorDemo.kt b/dataforge-vis-common/src/jvmTest/kotlin/hep/dataforge/vis/fx/demo/MetaEditorDemo.kt index 09ec35fc..62ca8870 100644 --- a/dataforge-vis-common/src/jvmTest/kotlin/hep/dataforge/vis/fx/demo/MetaEditorDemo.kt +++ b/dataforge-vis-common/src/jvmTest/kotlin/hep/dataforge/vis/fx/demo/MetaEditorDemo.kt @@ -1,8 +1,8 @@ package hep.dataforge.vis.fx.demo -import hep.dataforge.descriptors.NodeDescriptor -import hep.dataforge.meta.buildMeta -import hep.dataforge.meta.toConfig +import hep.dataforge.meta.Meta +import hep.dataforge.meta.asConfig +import hep.dataforge.meta.descriptors.NodeDescriptor import hep.dataforge.values.ValueType import hep.dataforge.vis.fx.editor.ConfigEditor import hep.dataforge.vis.fx.editor.FXMeta @@ -15,7 +15,7 @@ class MetaEditorDemoApp : App(MetaEditorDemo::class) class MetaEditorDemo : View("Meta editor demo") { - val meta = buildMeta { + val meta = Meta { "aNode" put { "innerNode" put { "innerValue" put true @@ -23,30 +23,30 @@ class MetaEditorDemo : View("Meta editor demo") { "b" put 223 "c" put "StringValue" } - }.toConfig() + }.asConfig() val descriptor = NodeDescriptor { - node("aNode") { + defineNode("aNode") { info = "A root demo node" - value("b") { + defineValue("b") { info = "b number value" type(ValueType.NUMBER) } - node("otherNode") { - value("otherValue") { + defineNode("otherNode") { + defineValue("otherValue") { type(ValueType.BOOLEAN) default(false) info = "default value" } } } - value("multiple"){ + defineValue("multiple") { info = "A sns value" multiple = true } } - private val rootNode = FXMeta.root(meta,descriptor) + private val rootNode = FXMeta.root(meta, descriptor) override val root = splitpane(Orientation.HORIZONTAL, MetaViewer(rootNode).root, ConfigEditor(rootNode).root) diff --git a/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/GDMLTransformer.kt b/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/GDMLTransformer.kt index 9d664aff..bf8f81ac 100644 --- a/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/GDMLTransformer.kt +++ b/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/GDMLTransformer.kt @@ -2,7 +2,6 @@ package hep.dataforge.vis.spatial.gdml import hep.dataforge.meta.Meta import hep.dataforge.meta.MetaBuilder -import hep.dataforge.meta.buildMeta import hep.dataforge.names.Name import hep.dataforge.names.toName import hep.dataforge.vis.common.useStyle @@ -44,7 +43,7 @@ class GDMLTransformer(val root: GDML) { fun VisualObject3D.useStyle(name: String, builder: MetaBuilder.() -> Unit) { styleCache.getOrPut(name.toName()) { - buildMeta(builder) + Meta(builder) } useStyle(name) } diff --git a/dataforge-vis-spatial-gdml/src/jvmMain/kotlin/hep/dataforge/vis/spatial/gdml/generateSchema.kt b/dataforge-vis-spatial-gdml/src/jvmMain/kotlin/hep/dataforge/vis/spatial/gdml/generateSchema.kt index 53768de4..857cc4e6 100644 --- a/dataforge-vis-spatial-gdml/src/jvmMain/kotlin/hep/dataforge/vis/spatial/gdml/generateSchema.kt +++ b/dataforge-vis-spatial-gdml/src/jvmMain/kotlin/hep/dataforge/vis/spatial/gdml/generateSchema.kt @@ -60,13 +60,13 @@ private fun SerialModule.enumerate(type: KClass<*>): Sequence */ private fun jsonSchema(descriptor: SerialDescriptor, context: SerialModule): JsonObject { - if (descriptor.name in arrayOf( + if (descriptor.serialName in arrayOf( "hep.dataforge.vis.spatial.Point3D", "hep.dataforge.vis.spatial.Point2D", Meta::class.qualifiedName ) ) return json { - "\$ref" to "#/definitions/${descriptor.name}" + "\$ref" to "#/definitions/${descriptor.serialName}" } @@ -109,7 +109,7 @@ private fun jsonSchema(descriptor: SerialDescriptor, context: SerialModule): Jso val jsonType = descriptor.jsonType val objectData: MutableMap = mutableMapOf( - "description" to JsonLiteral(descriptor.name), + "description" to JsonLiteral(descriptor.serialName), "type" to JsonLiteral(jsonType) ) if (isEnum) { @@ -140,9 +140,9 @@ fun main() { "children" to json { "anyOf" to jsonArray { context.enumerate(VisualObject3D::class).forEach { - if (it.name == "hep.dataforge.vis.spatial.VisualGroup3D") { + if (it.serialName == "hep.dataforge.vis.spatial.VisualGroup3D") { +json { - "\$ref" to "#/definitions/${it.name}" + "\$ref" to "#/definitions/${it.serialName}" } } else { +jsonSchema(it, context) diff --git a/dataforge-vis-spatial/build.gradle.kts b/dataforge-vis-spatial/build.gradle.kts index f587d39d..b6b050a5 100644 --- a/dataforge-vis-spatial/build.gradle.kts +++ b/dataforge-vis-spatial/build.gradle.kts @@ -1,17 +1,12 @@ -import org.openjfx.gradle.JavaFXOptions -import scientifik.useSerialization +import scientifik.serialization plugins { id("scientifik.mpp") - id("org.openjfx.javafxplugin") } -useSerialization() +serialization() kotlin { - jvm { - withJava() - } sourceSets { commonMain { dependencies { @@ -32,14 +27,9 @@ kotlin { jsMain { dependencies { // api(project(":wrappers")) - implementation(npm("three", "0.106.2")) - implementation(npm("@hi-level/three-csg", "1.0.6")) + implementation(npm("three", "0.114.0")) + implementation(npm("three-csg-ts", "1.0.1")) } } } } - -configure { - modules("javafx.controls") -} - diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Box.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Box.kt index c2010a0f..26f35cb5 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Box.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Box.kt @@ -2,7 +2,6 @@ package hep.dataforge.vis.spatial import hep.dataforge.context.Context -import hep.dataforge.io.serialization.ConfigSerializer import hep.dataforge.meta.Config import hep.dataforge.meta.Meta import hep.dataforge.meta.float @@ -29,7 +28,6 @@ class Box( override var rotation: Point3D? = null override var scale: Point3D? = null - @Serializable(ConfigSerializer::class) override var properties: Config? = null //TODO add helper for color configuration diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Composite.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Composite.kt index a7b3c774..46cf3b0e 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Composite.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Composite.kt @@ -2,7 +2,6 @@ package hep.dataforge.vis.spatial -import hep.dataforge.io.serialization.ConfigSerializer import hep.dataforge.meta.Config import hep.dataforge.meta.update import hep.dataforge.vis.common.AbstractVisualObject @@ -34,7 +33,6 @@ class Composite( override var rotation: Point3D? = null override var scale: Point3D? = null - @Serializable(ConfigSerializer::class) override var properties: Config? = null } diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/ConeSegment.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/ConeSegment.kt index f373a8de..c58f77fd 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/ConeSegment.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/ConeSegment.kt @@ -2,7 +2,6 @@ package hep.dataforge.vis.spatial -import hep.dataforge.io.serialization.ConfigSerializer import hep.dataforge.meta.Config import hep.dataforge.vis.common.AbstractVisualObject import hep.dataforge.vis.common.set @@ -25,7 +24,6 @@ class ConeSegment( var angle: Float = PI2 ) : AbstractVisualObject(), VisualObject3D, Shape { - @Serializable(ConfigSerializer::class) override var properties: Config? = null override var position: Point3D? = null diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Convex.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Convex.kt index e4168ed6..b7751919 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Convex.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Convex.kt @@ -2,7 +2,6 @@ package hep.dataforge.vis.spatial -import hep.dataforge.io.serialization.ConfigSerializer import hep.dataforge.meta.Config import hep.dataforge.vis.common.AbstractVisualObject import hep.dataforge.vis.common.set @@ -14,7 +13,6 @@ import kotlinx.serialization.UseSerializers @SerialName("3d.convex") class Convex(val points: List) : AbstractVisualObject(), VisualObject3D { - @Serializable(ConfigSerializer::class) override var properties: Config? = null override var position: Point3D? = null diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Extruded.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Extruded.kt index ae81eace..c713a2bb 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Extruded.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Extruded.kt @@ -1,7 +1,6 @@ @file:UseSerializers(Point2DSerializer::class, Point3DSerializer::class) package hep.dataforge.vis.spatial -import hep.dataforge.io.serialization.ConfigSerializer import hep.dataforge.meta.Config import hep.dataforge.vis.common.AbstractVisualObject import hep.dataforge.vis.common.set @@ -45,7 +44,6 @@ class Extruded( var layers: MutableList = ArrayList() ) : AbstractVisualObject(), VisualObject3D, Shape { - @Serializable(ConfigSerializer::class) override var properties: Config? = null override var position: Point3D? = null diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Label3D.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Label3D.kt index 906b03de..31a416eb 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Label3D.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Label3D.kt @@ -2,7 +2,6 @@ package hep.dataforge.vis.spatial -import hep.dataforge.io.serialization.ConfigSerializer import hep.dataforge.meta.Config import hep.dataforge.vis.common.AbstractVisualObject import hep.dataforge.vis.common.set @@ -12,9 +11,7 @@ import kotlinx.serialization.UseSerializers @Serializable @SerialName("3d.label") -class Label3D(var text: String, var fontSize: Double, var fontFamily: String) : AbstractVisualObject(), - VisualObject3D { - @Serializable(ConfigSerializer::class) +class Label3D(var text: String, var fontSize: Double, var fontFamily: String) : AbstractVisualObject(), VisualObject3D { override var properties: Config? = null override var position: Point3D? = null diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Material3D.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Material3D.kt index f489c62a..0030ce53 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Material3D.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Material3D.kt @@ -1,16 +1,21 @@ package hep.dataforge.vis.spatial -import hep.dataforge.descriptors.NodeDescriptor -import hep.dataforge.meta.* +import hep.dataforge.meta.descriptors.NodeDescriptor +import hep.dataforge.meta.double +import hep.dataforge.meta.get +import hep.dataforge.meta.node +import hep.dataforge.meta.scheme.* +import hep.dataforge.meta.set import hep.dataforge.names.asName import hep.dataforge.names.plus import hep.dataforge.values.ValueType +import hep.dataforge.values.asValue import hep.dataforge.vis.common.Colors import hep.dataforge.vis.spatial.Material3D.Companion.MATERIAL_COLOR_KEY import hep.dataforge.vis.spatial.Material3D.Companion.MATERIAL_KEY import hep.dataforge.vis.spatial.Material3D.Companion.MATERIAL_OPACITY_KEY -class Material3D(override val config: Config) : Specific { +class Material3D : Scheme() { /** * Primary web-color for the material @@ -32,8 +37,7 @@ class Material3D(override val config: Config) : Specific { */ var wireframe by boolean(false, WIREFRAME_KEY) - companion object : Specification { - override fun wrap(config: Config): Material3D = Material3D(config) + companion object : SchemeSpec(::Material3D) { val MATERIAL_KEY = "material".asName() internal val COLOR_KEY = "color".asName() @@ -45,20 +49,20 @@ class Material3D(override val config: Config) : Specific { val MATERIAL_WIREFRAME_KEY = MATERIAL_KEY + WIREFRAME_KEY val descriptor = NodeDescriptor { - value(VisualObject3D.VISIBLE_KEY) { + defineValue(VisualObject3D.VISIBLE_KEY) { type(ValueType.BOOLEAN) default(true) } - node(MATERIAL_KEY) { - value(COLOR_KEY) { + defineNode(MATERIAL_KEY) { + defineValue(COLOR_KEY) { type(ValueType.STRING, ValueType.NUMBER) default("#ffffff") } - value(OPACITY_KEY) { + defineValue(OPACITY_KEY) { type(ValueType.NUMBER) default(1.0) } - value(WIREFRAME_KEY) { + defineValue(WIREFRAME_KEY) { type(ValueType.BOOLEAN) default(false) } @@ -71,14 +75,14 @@ class Material3D(override val config: Config) : Specific { * Set color as web-color */ fun VisualObject3D.color(webColor: String) { - setProperty(MATERIAL_COLOR_KEY, webColor) + setProperty(MATERIAL_COLOR_KEY, webColor.asValue()) } /** * Set color as integer */ fun VisualObject3D.color(rgb: Int) { - setProperty(MATERIAL_COLOR_KEY, rgb) + setProperty(MATERIAL_COLOR_KEY, rgb.asValue()) } fun VisualObject3D.color(r: UByte, g: UByte, b: UByte) = setProperty( @@ -92,7 +96,7 @@ fun VisualObject3D.color(r: UByte, g: UByte, b: UByte) = setProperty( var VisualObject3D.color: String? get() = getProperty(MATERIAL_COLOR_KEY)?.let { Colors.fromMeta(it) } set(value) { - setProperty(MATERIAL_COLOR_KEY, value) + setProperty(MATERIAL_COLOR_KEY, value?.asValue()) } val VisualObject3D.material: Material3D? @@ -110,5 +114,5 @@ fun VisualObject3D.material(builder: Material3D.() -> Unit) { var VisualObject3D.opacity: Double? get() = getProperty(MATERIAL_OPACITY_KEY).double set(value) { - setProperty(MATERIAL_OPACITY_KEY, value) + setProperty(MATERIAL_OPACITY_KEY, value?.asValue()) } \ No newline at end of file diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/PolyLine.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/PolyLine.kt index 24f5a3b9..20cdf0f2 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/PolyLine.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/PolyLine.kt @@ -2,9 +2,8 @@ package hep.dataforge.vis.spatial -import hep.dataforge.io.serialization.ConfigSerializer import hep.dataforge.meta.Config -import hep.dataforge.meta.number +import hep.dataforge.meta.scheme.number import hep.dataforge.names.asName import hep.dataforge.names.plus import hep.dataforge.vis.common.AbstractVisualObject @@ -16,7 +15,6 @@ import kotlinx.serialization.UseSerializers @Serializable @SerialName("3d.line") class PolyLine(var points: List) : AbstractVisualObject(), VisualObject3D { - @Serializable(ConfigSerializer::class) override var properties: Config? = null override var position: Point3D? = null diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt index 9b72e6d5..e11bb4ba 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt @@ -1,9 +1,7 @@ -@file:UseSerializers(Point3DSerializer::class, NameSerializer::class, ConfigSerializer::class) +@file:UseSerializers(Point3DSerializer::class) package hep.dataforge.vis.spatial -import hep.dataforge.io.serialization.ConfigSerializer -import hep.dataforge.io.serialization.NameSerializer import hep.dataforge.meta.Config import hep.dataforge.meta.Laminate import hep.dataforge.meta.MetaItem @@ -36,7 +34,6 @@ class Proxy private constructor(val templateName: Name) : AbstractVisualObject() override var rotation: Point3D? = null override var scale: Point3D? = null - @Serializable(ConfigSerializer::class) override var properties: Config? = null /** diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Sphere.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Sphere.kt index b29af3c8..b9e628b7 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Sphere.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Sphere.kt @@ -2,7 +2,6 @@ package hep.dataforge.vis.spatial -import hep.dataforge.io.serialization.ConfigSerializer import hep.dataforge.meta.Config import hep.dataforge.vis.common.AbstractVisualObject import hep.dataforge.vis.common.set @@ -23,7 +22,6 @@ class Sphere( var theta: Float = PI.toFloat() ) : AbstractVisualObject(), VisualObject3D, Shape { - @Serializable(ConfigSerializer::class) override var properties: Config? = null override var position: Point3D? = null diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Tube.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Tube.kt index d97ccce6..4822a560 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Tube.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Tube.kt @@ -1,7 +1,6 @@ @file:UseSerializers(Point3DSerializer::class) package hep.dataforge.vis.spatial -import hep.dataforge.io.serialization.ConfigSerializer import hep.dataforge.meta.Config import hep.dataforge.vis.common.AbstractVisualObject import hep.dataforge.vis.common.set @@ -29,7 +28,6 @@ class Tube( override var rotation: Point3D? = null override var scale: Point3D? = null - @Serializable(ConfigSerializer::class) override var properties: Config? = null init { diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Visual3D.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Visual3D.kt index cb362558..3ee6cc93 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Visual3D.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Visual3D.kt @@ -4,10 +4,11 @@ import hep.dataforge.context.AbstractPlugin import hep.dataforge.context.Context import hep.dataforge.context.PluginFactory import hep.dataforge.context.PluginTag -import hep.dataforge.io.serialization.ConfigSerializer -import hep.dataforge.io.serialization.MetaSerializer -import hep.dataforge.io.serialization.NameSerializer -import hep.dataforge.meta.* +import hep.dataforge.meta.Meta +import hep.dataforge.meta.float +import hep.dataforge.meta.get +import hep.dataforge.meta.node +import hep.dataforge.meta.scheme.configure import hep.dataforge.names.Name import hep.dataforge.names.toName import hep.dataforge.vis.common.Visual @@ -39,10 +40,6 @@ class Visual3D(meta: Meta) : AbstractPlugin(meta) { val serialModule = SerializersModule { contextual(Point3DSerializer) contextual(Point2DSerializer) - contextual(NameSerializer) - contextual(NameTokenSerializer) - contextual(MetaSerializer) - contextual(ConfigSerializer) polymorphic(VisualObject::class, VisualObject3D::class) { VisualGroup3D::class with VisualGroup3D.serializer() @@ -52,8 +49,8 @@ class Visual3D(meta: Meta) : AbstractPlugin(meta) { Box::class with Box.serializer() Convex::class with Convex.serializer() Extruded::class with Extruded.serializer() - addSubclass(PolyLine.serializer()) - addSubclass(Label3D.serializer()) + subclass(PolyLine.serializer()) + subclass(Label3D.serializer()) } } diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt index 402290f8..cc9c23ea 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt @@ -1,16 +1,9 @@ @file:UseSerializers( - Point3DSerializer::class, - ConfigSerializer::class, - NameTokenSerializer::class, - NameSerializer::class, - MetaSerializer::class + Point3DSerializer::class ) package hep.dataforge.vis.spatial -import hep.dataforge.io.serialization.ConfigSerializer -import hep.dataforge.io.serialization.MetaSerializer -import hep.dataforge.io.serialization.NameSerializer import hep.dataforge.meta.Config import hep.dataforge.names.Name import hep.dataforge.names.NameToken diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt index 8e94ed65..6e1accd8 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt @@ -1,12 +1,13 @@ -@file:UseSerializers(Point3DSerializer::class, NameSerializer::class, NameTokenSerializer::class) +@file:UseSerializers(Point3DSerializer::class) package hep.dataforge.vis.spatial -import hep.dataforge.io.serialization.NameSerializer import hep.dataforge.meta.* +import hep.dataforge.meta.scheme.setProperty import hep.dataforge.names.asName import hep.dataforge.names.plus import hep.dataforge.output.Renderer +import hep.dataforge.values.asValue import hep.dataforge.vis.common.VisualObject import hep.dataforge.vis.spatial.VisualObject3D.Companion.DETAIL_KEY import hep.dataforge.vis.spatial.VisualObject3D.Companion.IGNORE_KEY @@ -64,7 +65,7 @@ interface VisualObject3D : VisualObject { var VisualObject3D.layer: Int get() = getProperty(LAYER_KEY).int ?: 0 set(value) { - setProperty(LAYER_KEY, value) + setProperty(LAYER_KEY, value.asValue()) } fun Renderer.render(meta: Meta = EmptyMeta, action: VisualGroup3D.() -> Unit) = @@ -86,7 +87,7 @@ enum class RotationOrder { */ var VisualObject3D.rotationOrder: RotationOrder get() = getProperty(VisualObject3D.rotationOrder).enum() ?: RotationOrder.XYZ - set(value) = setProperty(VisualObject3D.rotationOrder, value.name) + set(value) = setProperty(VisualObject3D.rotationOrder, value.name.asValue()) /** @@ -94,11 +95,11 @@ var VisualObject3D.rotationOrder: RotationOrder */ var VisualObject3D.detail: Int? get() = getProperty(DETAIL_KEY, false).int - set(value) = setProperty(DETAIL_KEY, value) + set(value) = setProperty(DETAIL_KEY, value?.asValue()) var VisualObject.visible: Boolean? get() = getProperty(VISIBLE_KEY).boolean - set(value) = setProperty(VISIBLE_KEY, value) + set(value) = setProperty(VISIBLE_KEY, value?.asValue()) /** * If this property is true, the object will be ignored on render. @@ -106,7 +107,7 @@ var VisualObject.visible: Boolean? */ var VisualObject.ignore: Boolean? get() = getProperty(IGNORE_KEY,false).boolean - set(value) = setProperty(IGNORE_KEY, value) + set(value) = setProperty(IGNORE_KEY, value?.asValue()) //var VisualObject.selected: Boolean? // get() = getProperty(SELECTED_KEY).boolean diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/geometry.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/geometry.kt index 75336e60..85d5466a 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/geometry.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/geometry.kt @@ -1,7 +1,6 @@ package hep.dataforge.vis.spatial import hep.dataforge.meta.Meta -import hep.dataforge.meta.buildMeta import hep.dataforge.meta.get import hep.dataforge.meta.number @@ -13,7 +12,7 @@ expect class Point2D(x: Number, y: Number) { operator fun Point2D.component1() = x operator fun Point2D.component2() = y -fun Point2D.toMeta() = buildMeta { +fun Point2D.toMeta() = Meta { VisualObject3D.x put x VisualObject3D.y put y } @@ -34,7 +33,7 @@ operator fun Point3D.component3() = z fun Meta.point3D() = Point3D(this["x"].number ?: 0, this["y"].number ?: 0, this["y"].number ?: 0) -fun Point3D.toMeta() = buildMeta { +fun Point3D.toMeta() = Meta { VisualObject3D.x put x VisualObject3D.y put y VisualObject3D.z put z diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/serialization.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/serialization.kt index 37115129..5bb95aea 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/serialization.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/serialization.kt @@ -1,17 +1,14 @@ package hep.dataforge.vis.spatial -import hep.dataforge.io.serialization.descriptor -import hep.dataforge.names.NameToken -import hep.dataforge.names.toName +import hep.dataforge.meta.double import kotlinx.serialization.* -import kotlinx.serialization.internal.DoubleSerializer -import kotlinx.serialization.internal.StringDescriptor -import kotlinx.serialization.internal.nullable +import kotlinx.serialization.builtins.nullable +import kotlinx.serialization.builtins.serializer inline fun Decoder.decodeStructure( desc: SerialDescriptor, vararg typeParams: KSerializer<*> = emptyArray(), - crossinline block: CompositeDecoder.() -> R + crossinline block: CompositeDecoder.() -> R ): R { val decoder = beginStructure(desc, *typeParams) val res = decoder.block() @@ -31,7 +28,7 @@ inline fun Encoder.encodeStructure( @Serializer(Point3D::class) object Point3DSerializer : KSerializer { - override val descriptor: SerialDescriptor = descriptor("hep.dataforge.vis.spatial.Point3D") { + override val descriptor: SerialDescriptor = SerialDescriptor("hep.dataforge.vis.spatial.Point3D") { double("x", true) double("y", true) double("z", true) @@ -45,28 +42,28 @@ object Point3DSerializer : KSerializer { loop@ while (true) { when (val i = decodeElementIndex(descriptor)) { CompositeDecoder.READ_DONE -> break@loop - 0 -> x = decodeNullableSerializableElement(descriptor, 0, DoubleSerializer.nullable) ?: 0.0 - 1 -> y = decodeNullableSerializableElement(descriptor, 1, DoubleSerializer.nullable) ?: 0.0 - 2 -> z = decodeNullableSerializableElement(descriptor, 2, DoubleSerializer.nullable) ?: 0.0 + 0 -> x = decodeNullableSerializableElement(descriptor, 0, Double.serializer().nullable) ?: 0.0 + 1 -> y = decodeNullableSerializableElement(descriptor, 1, Double.serializer().nullable) ?: 0.0 + 2 -> z = decodeNullableSerializableElement(descriptor, 2, Double.serializer().nullable) ?: 0.0 else -> throw SerializationException("Unknown index $i") } } } - return Point3D(x?:0.0, y?:0.0, z?:0.0) + return Point3D(x ?: 0.0, y ?: 0.0, z ?: 0.0) } - override fun serialize(encoder: Encoder, obj: Point3D) { + override fun serialize(encoder: Encoder, value: Point3D) { encoder.encodeStructure(descriptor) { - if (obj.x != 0.0) encodeDoubleElement(descriptor, 0, obj.x) - if (obj.y != 0.0) encodeDoubleElement(descriptor, 1, obj.y) - if (obj.z != 0.0) encodeDoubleElement(descriptor, 2, obj.z) + if (value.x != 0.0) encodeDoubleElement(descriptor, 0, value.x) + if (value.y != 0.0) encodeDoubleElement(descriptor, 1, value.y) + if (value.z != 0.0) encodeDoubleElement(descriptor, 2, value.z) } } } @Serializer(Point2D::class) object Point2DSerializer : KSerializer { - override val descriptor: SerialDescriptor = descriptor("hep.dataforge.vis.spatial.Point2D") { + override val descriptor: SerialDescriptor = SerialDescriptor("hep.dataforge.vis.spatial.Point2D") { double("x", true) double("y", true) } @@ -78,32 +75,19 @@ object Point2DSerializer : KSerializer { loop@ while (true) { when (val i = decodeElementIndex(descriptor)) { CompositeDecoder.READ_DONE -> break@loop - 0 -> x = decodeNullableSerializableElement(descriptor, 0, DoubleSerializer.nullable) ?: 0.0 - 1 -> y = decodeNullableSerializableElement(descriptor, 1, DoubleSerializer.nullable) ?: 0.0 + 0 -> x = decodeNullableSerializableElement(descriptor, 0, Double.serializer().nullable) ?: 0.0 + 1 -> y = decodeNullableSerializableElement(descriptor, 1, Double.serializer().nullable) ?: 0.0 else -> throw SerializationException("Unknown index $i") } } } - return Point2D(x?:0.0, y?:0.0) + return Point2D(x ?: 0.0, y ?: 0.0) } - override fun serialize(encoder: Encoder, obj: Point2D) { + override fun serialize(encoder: Encoder, value: Point2D) { encoder.encodeStructure(descriptor) { - if (obj.x != 0.0) encodeDoubleElement(descriptor, 0, obj.x) - if (obj.y != 0.0) encodeDoubleElement(descriptor, 1, obj.y) + if (value.x != 0.0) encodeDoubleElement(descriptor, 0, value.x) + if (value.y != 0.0) encodeDoubleElement(descriptor, 1, value.y) } } -} - -@Serializer(NameToken::class) -object NameTokenSerializer : KSerializer { - override val descriptor: SerialDescriptor = StringDescriptor.withName("NameToken") - - override fun deserialize(decoder: Decoder): NameToken { - return decoder.decodeString().toName().first()!! - } - - override fun serialize(encoder: Encoder, obj: NameToken) { - encoder.encodeString(obj.toString()) - } } \ No newline at end of file diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/specifications/Axes.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/specifications/Axes.kt new file mode 100644 index 00000000..cda776c1 --- /dev/null +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/specifications/Axes.kt @@ -0,0 +1,18 @@ +package hep.dataforge.vis.spatial.specifications + +import hep.dataforge.meta.isEmpty +import hep.dataforge.meta.scheme.Scheme +import hep.dataforge.meta.scheme.SchemeSpec +import hep.dataforge.meta.scheme.boolean +import hep.dataforge.meta.scheme.double + +class Axes : Scheme() { + var visible by boolean(!config.isEmpty()) + var size by double(AXIS_SIZE) + var width by double(AXIS_WIDTH) + + companion object : SchemeSpec(::Axes) { + const val AXIS_SIZE = 1000.0 + const val AXIS_WIDTH = 3.0 + } +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/specifications/AxesSpec.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/specifications/AxesSpec.kt deleted file mode 100644 index b46b9f4d..00000000 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/specifications/AxesSpec.kt +++ /dev/null @@ -1,17 +0,0 @@ -package hep.dataforge.vis.spatial.specifications - -import hep.dataforge.meta.* - -class AxesSpec(override val config: Config) : Specific { - var visible by boolean(!config.isEmpty()) - var size by double(AXIS_SIZE) - var width by double(AXIS_WIDTH) - - companion object : Specification { - override fun wrap(config: Config): AxesSpec = AxesSpec(config) - - const val AXIS_SIZE = 1000.0 - const val AXIS_WIDTH = 3.0 - - } -} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/specifications/CameraSpec.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/specifications/Camera.kt similarity index 67% rename from dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/specifications/CameraSpec.kt rename to dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/specifications/Camera.kt index eb23472f..fc131b4a 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/specifications/CameraSpec.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/specifications/Camera.kt @@ -1,10 +1,14 @@ package hep.dataforge.vis.spatial.specifications -import hep.dataforge.meta.* +import hep.dataforge.meta.scheme.Scheme +import hep.dataforge.meta.scheme.SchemeSpec +import hep.dataforge.meta.scheme.double +import hep.dataforge.meta.scheme.int import kotlin.math.PI -class CameraSpec(override val config: Config) : Specific { +class Camera : Scheme() { var fov by int(FIELD_OF_VIEW) + //var aspect by double(1.0) var nearClip by double(NEAR_CLIP) var farClip by double(FAR_CLIP) @@ -14,11 +18,10 @@ class CameraSpec(override val config: Config) : Specific { var latitude by double(INITIAL_LATITUDE) val zenith: Double get() = PI / 2 - latitude - companion object : Specification { - override fun wrap(config: Config): CameraSpec = CameraSpec(config) + companion object : SchemeSpec(::Camera) { const val INITIAL_DISTANCE = 300.0 const val INITIAL_AZIMUTH = 0.0 - const val INITIAL_LATITUDE = PI/6 + const val INITIAL_LATITUDE = PI / 6 const val NEAR_CLIP = 0.1 const val FAR_CLIP = 10000.0 const val FIELD_OF_VIEW = 75 diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/specifications/Canvas.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/specifications/Canvas.kt new file mode 100644 index 00000000..a10b3186 --- /dev/null +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/specifications/Canvas.kt @@ -0,0 +1,15 @@ +package hep.dataforge.vis.spatial.specifications + +import hep.dataforge.meta.scheme.Scheme +import hep.dataforge.meta.scheme.SchemeSpec +import hep.dataforge.meta.scheme.int +import hep.dataforge.meta.scheme.spec + +class Canvas : Scheme() { + var axes by spec(Axes, Axes.empty()) + var camera by spec(Camera, Camera.empty()) + var controls by spec(Controls, Controls.empty()) + var minSize by int(300) + + companion object : SchemeSpec(::Canvas) +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/specifications/CanvasSpec.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/specifications/CanvasSpec.kt deleted file mode 100644 index d9cbded6..00000000 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/specifications/CanvasSpec.kt +++ /dev/null @@ -1,15 +0,0 @@ -package hep.dataforge.vis.spatial.specifications - -import hep.dataforge.meta.* - -class CanvasSpec(override val config: Config) : Specific { - var axes by spec(AxesSpec) - var camera by spec(CameraSpec) - var controls by spec(ControlsSpec) - var minSize by int(300) - - companion object: Specification{ - override fun wrap(config: Config): CanvasSpec = CanvasSpec(config) - - } -} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/specifications/Controls.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/specifications/Controls.kt new file mode 100644 index 00000000..7d142b67 --- /dev/null +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/specifications/Controls.kt @@ -0,0 +1,9 @@ +package hep.dataforge.vis.spatial.specifications + +import hep.dataforge.meta.scheme.Scheme +import hep.dataforge.meta.scheme.SchemeSpec + + +class Controls : Scheme() { + companion object : SchemeSpec(::Controls) +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/specifications/ControlsSpec.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/specifications/ControlsSpec.kt deleted file mode 100644 index 2a828766..00000000 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/specifications/ControlsSpec.kt +++ /dev/null @@ -1,11 +0,0 @@ -package hep.dataforge.vis.spatial.specifications - -import hep.dataforge.meta.Config -import hep.dataforge.meta.Specific -import hep.dataforge.meta.Specification - -class ControlsSpec(override val config: Config) : Specific { - companion object : Specification { - override fun wrap(config: Config): ControlsSpec = ControlsSpec(config) - } -} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/commonTest/kotlin/hep/dataforge/vis/spatial/ConvexTest.kt b/dataforge-vis-spatial/src/commonTest/kotlin/hep/dataforge/vis/spatial/ConvexTest.kt index 0c2b4143..62482282 100644 --- a/dataforge-vis-spatial/src/commonTest/kotlin/hep/dataforge/vis/spatial/ConvexTest.kt +++ b/dataforge-vis-spatial/src/commonTest/kotlin/hep/dataforge/vis/spatial/ConvexTest.kt @@ -1,8 +1,9 @@ package hep.dataforge.vis.spatial -import hep.dataforge.io.toMeta import hep.dataforge.meta.MetaItem import hep.dataforge.meta.getIndexed +import hep.dataforge.meta.node +import hep.dataforge.meta.toMetaItem import kotlin.test.Test import kotlin.test.assertEquals @@ -26,9 +27,9 @@ class ConvexTest { val convex = group.first() as Convex val json = Visual3D.json.toJson(Convex.serializer(), convex) - val meta = json.toMeta() + 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 MetaItem.NodeItem<*>).node.point3D() } assertEquals(8, points.count()) assertEquals(8, convex.points.size) diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeCanvas.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeCanvas.kt index 08717e92..483d48ec 100644 --- a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeCanvas.kt +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeCanvas.kt @@ -2,7 +2,7 @@ package hep.dataforge.vis.spatial.three import hep.dataforge.context.Context import hep.dataforge.meta.Meta -import hep.dataforge.meta.get +import hep.dataforge.meta.scheme.getProperty import hep.dataforge.meta.string import hep.dataforge.names.Name import hep.dataforge.names.plus @@ -10,9 +10,9 @@ import hep.dataforge.names.toName import hep.dataforge.output.Renderer import hep.dataforge.vis.common.Colors import hep.dataforge.vis.spatial.VisualObject3D -import hep.dataforge.vis.spatial.specifications.CameraSpec -import hep.dataforge.vis.spatial.specifications.CanvasSpec -import hep.dataforge.vis.spatial.specifications.ControlsSpec +import hep.dataforge.vis.spatial.specifications.Camera +import hep.dataforge.vis.spatial.specifications.Canvas +import hep.dataforge.vis.spatial.specifications.Controls import hep.dataforge.vis.spatial.three.ThreeMaterials.HIGHLIGHT_MATERIAL import info.laht.threekt.WebGLRenderer import info.laht.threekt.cameras.PerspectiveCamera @@ -39,7 +39,7 @@ import kotlin.math.sin /** * */ -class ThreeCanvas(element: HTMLElement, val three: ThreePlugin, val spec: CanvasSpec) : Renderer { +class ThreeCanvas(element: HTMLElement, val three: ThreePlugin, val canvas: Canvas) : Renderer { override val context: Context get() = three.context @@ -53,15 +53,15 @@ class ThreeCanvas(element: HTMLElement, val three: ThreePlugin, val spec: Canvas var clickListener: ((Name) -> Unit)? = null - val axes = AxesHelper(spec.axes.size.toInt()).apply { - visible = spec.axes.visible + val axes = AxesHelper(canvas.axes.size.toInt()).apply { + visible = canvas.axes.visible } val scene: Scene = Scene().apply { add(axes) } - val camera = buildCamera(spec.camera) + val camera = buildCamera(canvas.camera) init { element.clear() @@ -90,7 +90,7 @@ class ThreeCanvas(element: HTMLElement, val three: ThreePlugin, val spec: Canvas } - addControls(renderer.domElement, spec.controls) + addControls(renderer.domElement, canvas.controls) fun animate() { val mesh = pick() @@ -108,7 +108,7 @@ class ThreeCanvas(element: HTMLElement, val three: ThreePlugin, val spec: Canvas element.appendChild(renderer.domElement) - renderer.setSize(max(spec.minSize, element.offsetWidth), max(spec.minSize, element.offsetWidth)) + renderer.setSize(max(canvas.minSize, element.offsetWidth), max(canvas.minSize, element.offsetWidth)) element.onresize = { renderer.setSize(element.offsetWidth, element.offsetWidth) @@ -142,7 +142,7 @@ class ThreeCanvas(element: HTMLElement, val three: ThreePlugin, val spec: Canvas } } - private fun buildCamera(spec: CameraSpec) = PerspectiveCamera( + private fun buildCamera(spec: Camera) = PerspectiveCamera( spec.fov, 1.0, spec.nearClip, @@ -153,8 +153,8 @@ class ThreeCanvas(element: HTMLElement, val three: ThreePlugin, val spec: Canvas translateZ(spec.distance * sin(spec.zenith) * cos(spec.azimuth)) } - private fun addControls(element: Node, controlsSpec: ControlsSpec) { - when (controlsSpec["type"].string) { + private fun addControls(element: Node, controls: Controls) { + when (controls.getProperty("type").string) { "trackball" -> TrackballControls(camera, element) else -> OrbitControls(camera, element) } @@ -211,5 +211,5 @@ class ThreeCanvas(element: HTMLElement, val three: ThreePlugin, val spec: Canvas } } -fun ThreePlugin.output(element: HTMLElement, spec: CanvasSpec = CanvasSpec.empty()): ThreeCanvas = +fun ThreePlugin.output(element: HTMLElement, spec: Canvas = Canvas.empty()): ThreeCanvas = ThreeCanvas(element, this, spec) \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeVisualObject.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeVisualObject.kt index 5970a76d..16b5b37d 100644 --- a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeVisualObject.kt +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeVisualObject.kt @@ -2,7 +2,6 @@ package hep.dataforge.vis.spatial.three -import hep.dataforge.io.serialization.ConfigSerializer import hep.dataforge.meta.Config import hep.dataforge.vis.common.AbstractVisualObject import hep.dataforge.vis.spatial.Point3D @@ -26,7 +25,6 @@ class CustomThreeVisualObject(val threeFactory: ThreeFactory) : override var rotation: Point3D? = null override var scale: Point3D? = null - @Serializable(ConfigSerializer::class) override var properties: Config? = null override fun toObject3D(): Object3D = threeFactory(this) diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/csg.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/csg.kt index 036f729a..615e4624 100644 --- a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/csg.kt +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/csg.kt @@ -1,4 +1,4 @@ -@file:JsModule("@hi-level/three-csg") +@file:JsModule("three-csg-ts") @file:JsNonModule @file:Suppress( "INTERFACE_WITH_SUPERCLASS", diff --git a/dataforge-vis-spatial/src/jvmMain/kotlin/hep/dataforge/vis/spatial/fx/FXCanvas3D.kt b/dataforge-vis-spatial/src/jvmMain/kotlin/hep/dataforge/vis/spatial/fx/FXCanvas3D.kt index 1704eeb2..499a2e5d 100644 --- a/dataforge-vis-spatial/src/jvmMain/kotlin/hep/dataforge/vis/spatial/fx/FXCanvas3D.kt +++ b/dataforge-vis-spatial/src/jvmMain/kotlin/hep/dataforge/vis/spatial/fx/FXCanvas3D.kt @@ -5,7 +5,7 @@ import hep.dataforge.context.ContextAware import hep.dataforge.meta.Meta import hep.dataforge.output.Renderer import hep.dataforge.vis.spatial.VisualObject3D -import hep.dataforge.vis.spatial.specifications.CanvasSpec +import hep.dataforge.vis.spatial.specifications.Canvas import javafx.application.Platform import javafx.beans.property.ObjectProperty import javafx.beans.property.SimpleObjectProperty @@ -14,7 +14,7 @@ import javafx.scene.paint.Color import org.fxyz3d.scene.Axes import tornadofx.* -class FXCanvas3D(val plugin: FX3DPlugin, val spec: CanvasSpec = CanvasSpec.empty()) : +class FXCanvas3D(val plugin: FX3DPlugin, val spec: Canvas = Canvas.empty()) : Fragment(), Renderer, ContextAware { override val context: Context get() = plugin.context diff --git a/dataforge-vis-spatial/src/jvmMain/kotlin/hep/dataforge/vis/spatial/fx/OrbitControls.kt b/dataforge-vis-spatial/src/jvmMain/kotlin/hep/dataforge/vis/spatial/fx/OrbitControls.kt index aaa90ee9..ce3f2d7d 100644 --- a/dataforge-vis-spatial/src/jvmMain/kotlin/hep/dataforge/vis/spatial/fx/OrbitControls.kt +++ b/dataforge-vis-spatial/src/jvmMain/kotlin/hep/dataforge/vis/spatial/fx/OrbitControls.kt @@ -1,6 +1,5 @@ package hep.dataforge.vis.spatial.fx -import hep.dataforge.vis.spatial.specifications.CameraSpec import javafx.beans.InvalidationListener import javafx.beans.property.SimpleDoubleProperty import javafx.event.EventHandler @@ -15,6 +14,7 @@ import javafx.scene.transform.Rotate import javafx.scene.transform.Translate import tornadofx.* import kotlin.math.* +import hep.dataforge.vis.spatial.specifications.Camera as CameraSpec class OrbitControls internal constructor(camera: Camera, canvas: SubScene, spec: CameraSpec) { diff --git a/demo/gdml/build.gradle.kts b/demo/gdml/build.gradle.kts index 7558d178..864255b6 100644 --- a/demo/gdml/build.gradle.kts +++ b/demo/gdml/build.gradle.kts @@ -1,11 +1,15 @@ -import org.openjfx.gradle.JavaFXOptions +import scientifik.DependencyConfiguration +import scientifik.FXModule +import scientifik.fx plugins { id("scientifik.mpp") - id("org.openjfx.javafxplugin") id("application") } +val fxVersion: String by rootProject.extra +fx(FXModule.CONTROLS, version = fxVersion, configuration = DependencyConfiguration.IMPLEMENTATION) + kotlin { jvm { @@ -27,18 +31,9 @@ kotlin { api(project(":dataforge-vis-spatial-gdml")) } } - jvmMain{ - dependencies { - api("org.fxyz3d:fxyz3d:0.5.2") - } - } } } application { mainClassName = "hep.dataforge.vis.spatial.gdml.demo.GDMLDemoAppKt" -} - -configure { - modules("javafx.controls") } \ No newline at end of file diff --git a/demo/gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt b/demo/gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt index 88a948f3..6eba931a 100644 --- a/demo/gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt +++ b/demo/gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt @@ -3,7 +3,7 @@ package hep.dataforge.vis.spatial.gdml.demo import hep.dataforge.context.Global import hep.dataforge.js.Application import hep.dataforge.js.startApplication -import hep.dataforge.meta.buildMeta +import hep.dataforge.meta.Meta import hep.dataforge.meta.withBottom import hep.dataforge.names.Name import hep.dataforge.names.isEmpty @@ -167,7 +167,7 @@ private class GDMLDemoApp : Application { //val descriptorMeta = Material3D.descriptor val properties = item.allProperties() - val bottom = buildMeta { + val bottom = Meta { VISIBLE_KEY put (item.visible ?: true) if (item is VisualObject3D) { MATERIAL_COLOR_KEY put "#ffffff" @@ -186,10 +186,6 @@ private class GDMLDemoApp : Application { selectElement(treeName) canvas.highlight(treeName) } - canvas.render(visual) - - - canvas.render(visual) message(null) spinner(false) diff --git a/demo/gdml/src/jsMain/web/css/jsoneditor.min.css b/demo/gdml/src/jsMain/resources/css/jsoneditor.min.css similarity index 100% rename from demo/gdml/src/jsMain/web/css/jsoneditor.min.css rename to demo/gdml/src/jsMain/resources/css/jsoneditor.min.css diff --git a/demo/gdml/src/jsMain/web/css/main.css b/demo/gdml/src/jsMain/resources/css/main.css similarity index 100% rename from demo/gdml/src/jsMain/web/css/main.css rename to demo/gdml/src/jsMain/resources/css/main.css diff --git a/demo/gdml/src/jsMain/web/img/jsoneditor-icons.svg b/demo/gdml/src/jsMain/resources/img/jsoneditor-icons.svg similarity index 100% rename from demo/gdml/src/jsMain/web/img/jsoneditor-icons.svg rename to demo/gdml/src/jsMain/resources/img/jsoneditor-icons.svg diff --git a/demo/gdml/src/jsMain/web/index.html b/demo/gdml/src/jsMain/resources/index.html similarity index 100% rename from demo/gdml/src/jsMain/web/index.html rename to demo/gdml/src/jsMain/resources/index.html diff --git a/demo/gdml/src/jvmMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/readFile.kt b/demo/gdml/src/jvmMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/readFile.kt index 532e1399..b93f00c5 100644 --- a/demo/gdml/src/jvmMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/readFile.kt +++ b/demo/gdml/src/jvmMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/readFile.kt @@ -10,6 +10,8 @@ import scientifik.gdml.GDML import java.io.File import java.util.zip.GZIPInputStream import java.util.zip.ZipInputStream +import hep.dataforge.meta.* +import hep.dataforge.values.* fun Visual3D.Companion.readFile(file: File): VisualGroup3D = when { file.extension == "gdml" || file.extension == "xml" -> { @@ -18,7 +20,7 @@ fun Visual3D.Companion.readFile(file: File): VisualGroup3D = when { solidConfiguration = { parent, solid -> if (solid.name == "cave") { - setProperty(Material3D.MATERIAL_WIREFRAME_KEY, true) + setProperty(Material3D.MATERIAL_WIREFRAME_KEY, true.asValue()) } if (parent.physVolumes.isNotEmpty()) { useStyle("opaque") { diff --git a/demo/muon-monitor/build.gradle.kts b/demo/muon-monitor/build.gradle.kts index 48b34d0b..d2d746f9 100644 --- a/demo/muon-monitor/build.gradle.kts +++ b/demo/muon-monitor/build.gradle.kts @@ -1,15 +1,12 @@ -import scientifik.useSerialization +import scientifik.jsDistDirectory plugins { id("scientifik.mpp") - //id("org.openjfx.javafxplugin") id("application") } group = "ru.mipt.npm" -useSerialization() - val ktor_version = "1.3.0-rc" kotlin { @@ -22,7 +19,7 @@ kotlin { } } - val installJS = tasks.getByName("installJsDist") + val installJS = tasks.getByName("jsBrowserWebpack") jvm { withJava() @@ -30,7 +27,7 @@ kotlin { tasks.getByName("jvmProcessResources") { dependsOn(installJS) afterEvaluate { - from(installJS.destinationDir) + from(project.jsDistDirectory) } } } @@ -49,8 +46,8 @@ kotlin { implementation("io.ktor:ktor-serialization:$ktor_version") } } - jsMain{ - dependencies{ + jsMain { + dependencies { implementation("io.ktor:ktor-client-js:$ktor_version") implementation("io.ktor:ktor-client-serialization-js:$ktor_version") implementation(npm("text-encoding")) diff --git a/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMDemoApp.kt b/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMDemoApp.kt index 3e680952..54f58f26 100644 --- a/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMDemoApp.kt +++ b/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMDemoApp.kt @@ -3,7 +3,7 @@ package ru.mipt.npm.muon.monitor import hep.dataforge.context.Global import hep.dataforge.js.Application import hep.dataforge.js.startApplication -import hep.dataforge.meta.buildMeta +import hep.dataforge.meta.Meta import hep.dataforge.meta.withBottom import hep.dataforge.names.Name import hep.dataforge.names.isEmpty @@ -98,7 +98,7 @@ private class MMDemoApp : Application { //val descriptorMeta = Material3D.descriptor val properties = item.allProperties() - val bottom = buildMeta { + val bottom = Meta { VISIBLE_KEY put (item.visible ?: true) if (item is VisualObject3D) { MATERIAL_COLOR_KEY put "#ffffff" diff --git a/demo/muon-monitor/src/jsMain/web/css/jsoneditor.min.css b/demo/muon-monitor/src/jsMain/resources/css/jsoneditor.min.css similarity index 100% rename from demo/muon-monitor/src/jsMain/web/css/jsoneditor.min.css rename to demo/muon-monitor/src/jsMain/resources/css/jsoneditor.min.css diff --git a/demo/muon-monitor/src/jsMain/web/css/main.css b/demo/muon-monitor/src/jsMain/resources/css/main.css similarity index 100% rename from demo/muon-monitor/src/jsMain/web/css/main.css rename to demo/muon-monitor/src/jsMain/resources/css/main.css diff --git a/demo/muon-monitor/src/jsMain/web/img/jsoneditor-icons.svg b/demo/muon-monitor/src/jsMain/resources/img/jsoneditor-icons.svg similarity index 100% rename from demo/muon-monitor/src/jsMain/web/img/jsoneditor-icons.svg rename to demo/muon-monitor/src/jsMain/resources/img/jsoneditor-icons.svg diff --git a/demo/muon-monitor/src/jsMain/web/index.html b/demo/muon-monitor/src/jsMain/resources/index.html similarity index 100% rename from demo/muon-monitor/src/jsMain/web/index.html rename to demo/muon-monitor/src/jsMain/resources/index.html diff --git a/demo/spatial-showcase/build.gradle.kts b/demo/spatial-showcase/build.gradle.kts index 46d63633..fef9057c 100644 --- a/demo/spatial-showcase/build.gradle.kts +++ b/demo/spatial-showcase/build.gradle.kts @@ -1,11 +1,15 @@ -import org.openjfx.gradle.JavaFXOptions +import scientifik.DependencyConfiguration +import scientifik.FXModule +import scientifik.fx plugins { id("scientifik.mpp") - id("org.openjfx.javafxplugin") id("application") } +val fxVersion: String by rootProject.extra +fx(FXModule.CONTROLS, version = fxVersion, configuration = DependencyConfiguration.IMPLEMENTATION) + kotlin { jvm { @@ -32,8 +36,4 @@ kotlin { application { mainClassName = "hep.dataforge.vis.spatial.demo.FXDemoAppKt" -} - -configure { - modules("javafx.controls") } \ No newline at end of file diff --git a/demo/spatial-showcase/src/commonMain/kotlin/hep/dataforge/vis/spatial/demo/demo.kt b/demo/spatial-showcase/src/commonMain/kotlin/hep/dataforge/vis/spatial/demo/demo.kt index ddb92491..9bc63834 100644 --- a/demo/spatial-showcase/src/commonMain/kotlin/hep/dataforge/vis/spatial/demo/demo.kt +++ b/demo/spatial-showcase/src/commonMain/kotlin/hep/dataforge/vis/spatial/demo/demo.kt @@ -1,13 +1,13 @@ package hep.dataforge.vis.spatial.demo -import hep.dataforge.meta.buildMeta -import hep.dataforge.meta.invoke +import hep.dataforge.meta.Meta +import hep.dataforge.meta.scheme.invoke import hep.dataforge.names.toName import hep.dataforge.output.OutputManager import hep.dataforge.vis.common.Colors import hep.dataforge.vis.common.VisualObject import hep.dataforge.vis.spatial.* -import hep.dataforge.vis.spatial.specifications.CanvasSpec +import hep.dataforge.vis.spatial.specifications.Canvas import kotlinx.coroutines.* import kotlin.math.PI import kotlin.math.cos @@ -16,14 +16,14 @@ import kotlin.random.Random fun OutputManager.demo(name: String, title: String = name, block: VisualGroup3D.() -> Unit) { - val meta = buildMeta { + val meta = Meta { "title" put title } val output = get(VisualObject::class, name.toName(), meta = meta) output.render(action = block) } -val canvasOptions = CanvasSpec { +val canvasOptions = Canvas { minSize = 500 axes { size = 500.0 @@ -31,7 +31,7 @@ val canvasOptions = CanvasSpec { } camera { distance = 600.0 - latitude = PI/6 + latitude = PI / 6 } } diff --git a/demo/spatial-showcase/src/jsMain/kotlin/hep/dataforge/vis/spatial/demo/ThreeDemoApp.kt b/demo/spatial-showcase/src/jsMain/kotlin/hep/dataforge/vis/spatial/demo/ThreeDemoApp.kt index 7d9adc3e..984a3bcf 100644 --- a/demo/spatial-showcase/src/jsMain/kotlin/hep/dataforge/vis/spatial/demo/ThreeDemoApp.kt +++ b/demo/spatial-showcase/src/jsMain/kotlin/hep/dataforge/vis/spatial/demo/ThreeDemoApp.kt @@ -2,16 +2,7 @@ package hep.dataforge.vis.spatial.demo import hep.dataforge.js.Application import hep.dataforge.js.startApplication -import hep.dataforge.vis.spatial.three.MeshThreeFactory.Companion.EDGES_ENABLED_KEY -import hep.dataforge.vis.spatial.three.MeshThreeFactory.Companion.WIREFRAME_ENABLED_KEY -import hep.dataforge.vis.spatial.x -import hep.dataforge.vis.spatial.y -import kotlinx.coroutines.GlobalScope -import kotlinx.coroutines.delay -import kotlinx.coroutines.isActive -import kotlinx.coroutines.launch import kotlin.browser.document -import kotlin.random.Random private class ThreeDemoApp : Application { diff --git a/demo/spatial-showcase/src/jsMain/kotlin/hep/dataforge/vis/spatial/demo/ThreeDemoGrid.kt b/demo/spatial-showcase/src/jsMain/kotlin/hep/dataforge/vis/spatial/demo/ThreeDemoGrid.kt index 44a71b5a..0aee069d 100644 --- a/demo/spatial-showcase/src/jsMain/kotlin/hep/dataforge/vis/spatial/demo/ThreeDemoGrid.kt +++ b/demo/spatial-showcase/src/jsMain/kotlin/hep/dataforge/vis/spatial/demo/ThreeDemoGrid.kt @@ -3,15 +3,11 @@ package hep.dataforge.vis.spatial.demo import hep.dataforge.context.Global import hep.dataforge.meta.Meta import hep.dataforge.meta.get -import hep.dataforge.meta.invoke import hep.dataforge.meta.string import hep.dataforge.names.Name import hep.dataforge.output.OutputManager import hep.dataforge.output.Renderer import hep.dataforge.vis.common.VisualObject -import hep.dataforge.vis.spatial.specifications.AxesSpec -import hep.dataforge.vis.spatial.specifications.CameraSpec -import hep.dataforge.vis.spatial.specifications.CanvasSpec import hep.dataforge.vis.spatial.three.ThreeCanvas import hep.dataforge.vis.spatial.three.ThreePlugin import hep.dataforge.vis.spatial.three.output diff --git a/demo/spatial-showcase/src/jsMain/web/index.html b/demo/spatial-showcase/src/jsMain/resources/index.html similarity index 100% rename from demo/spatial-showcase/src/jsMain/web/index.html rename to demo/spatial-showcase/src/jsMain/resources/index.html diff --git a/demo/spatial-showcase/src/jvmMain/kotlin/hep/dataforge/vis/spatial/demo/FXDemoGrid.kt b/demo/spatial-showcase/src/jvmMain/kotlin/hep/dataforge/vis/spatial/demo/FXDemoGrid.kt index 9357e5de..b608d100 100644 --- a/demo/spatial-showcase/src/jvmMain/kotlin/hep/dataforge/vis/spatial/demo/FXDemoGrid.kt +++ b/demo/spatial-showcase/src/jvmMain/kotlin/hep/dataforge/vis/spatial/demo/FXDemoGrid.kt @@ -9,8 +9,8 @@ import hep.dataforge.output.Renderer import hep.dataforge.vis.common.VisualObject import hep.dataforge.vis.spatial.fx.FX3DPlugin import hep.dataforge.vis.spatial.fx.FXCanvas3D -import hep.dataforge.vis.spatial.specifications.AxesSpec -import hep.dataforge.vis.spatial.specifications.CanvasSpec +import hep.dataforge.vis.spatial.specifications.Axes as AxesSpec +import hep.dataforge.vis.spatial.specifications.Canvas as CanvasSpec import javafx.collections.FXCollections import javafx.scene.Parent import javafx.scene.control.Tab