From 78a04728ba4ba2182bc610e8724a0aada1ff5165 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 1 Mar 2021 19:10:15 +0300 Subject: [PATCH] A lot of small fixes --- build.gradle.kts | 2 + .../hep/dataforge/vision/gdml/demo/cubes.kt | 54 ----------- .../dataforge/vision/gdml/GDMLVisualTest.kt | 7 +- .../vision/gdml/demo/GdmlJsDemoApp.kt | 3 +- .../vision/gdml/demo/GdmlFxDemoApp.kt | 3 +- .../src/jvmMain/kotlin/gdmlCubes.kt | 14 +-- .../main/kotlin/ru/mipt/npm/sat/geometry.kt | 2 + .../hep/dataforge/vision/html/HtmlTagTest.kt | 4 +- .../vision/editor/ColorValueChooser.kt | 2 +- .../vision/editor/ComboBoxValueChooser.kt | 2 +- .../dataforge/vision/editor/ConfigEditor.kt | 11 ++- .../dataforge/vision/editor/ValueChooser.kt | 22 ++--- visionforge-gdml/build.gradle.kts | 2 +- .../hep/dataforge/vision/gdml/GdmlShowcase.kt | 57 +++++++++++ .../dataforge/vision/gdml/GdmlTransformer.kt | 7 +- .../src/commonTest/kotlin/TestCubes.kt | 66 +++++++++++++ .../hep/dataforge/vision/gdml/TestCubes.kt | 96 ------------------- .../dataforge/vision/solid/SolidReference.kt | 2 +- .../vision/solid/SolidReferenceTest.kt | 2 + .../vision/solid/three/ThreePlugin.kt | 4 +- .../dataforge/vision/three/server/jsMain.kt | 2 + 21 files changed, 177 insertions(+), 187 deletions(-) delete mode 100644 demo/gdml/src/commonMain/kotlin/hep/dataforge/vision/gdml/demo/cubes.kt create mode 100644 visionforge-gdml/src/commonMain/kotlin/hep/dataforge/vision/gdml/GdmlShowcase.kt create mode 100644 visionforge-gdml/src/commonTest/kotlin/TestCubes.kt delete mode 100644 visionforge-gdml/src/jvmTest/kotlin/hep/dataforge/vision/gdml/TestCubes.kt diff --git a/build.gradle.kts b/build.gradle.kts index 949d00a6..5d5b70f3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -12,8 +12,10 @@ val fxVersion by extra("14") allprojects { repositories { + mavenLocal() mavenCentral() jcenter() + maven("https://repo.kotlin.link") maven("https://kotlin.bintray.com/kotlin-js-wrappers") maven("https://dl.bintray.com/pdvrieze/maven") maven("http://maven.jzy3d.org/releases") diff --git a/demo/gdml/src/commonMain/kotlin/hep/dataforge/vision/gdml/demo/cubes.kt b/demo/gdml/src/commonMain/kotlin/hep/dataforge/vision/gdml/demo/cubes.kt deleted file mode 100644 index 1ddc853e..00000000 --- a/demo/gdml/src/commonMain/kotlin/hep/dataforge/vision/gdml/demo/cubes.kt +++ /dev/null @@ -1,54 +0,0 @@ -package hep.dataforge.vision.gdml.demo - -import space.kscience.gdml.* - - -fun cubes(): Gdml = Gdml { - val center = define.position("center") - structure { - val air = ref("G4_AIR") - val tubeMaterial = ref("tube") - val boxMaterial = ref("box") - val segment = solids.tube("segment", 20, 5.0) { - rmin = 17 - deltaphi = 60 - aunit = AUnit.DEG.title - } - val worldBox = solids.box("LargeBox", 200, 200, 200) - val smallBox = solids.box("smallBox", 30, 30, 30) - val segmentVolume = volume("segment", tubeMaterial, segment.ref()) {} - val circle = volume("composite", boxMaterial, smallBox.ref()) { - for (i in 0 until 6) { - physVolume(segmentVolume) { - name = "segment_$i" - positionref = center.ref() - rotation { - z = 60 * i - unit = AUnit.DEG.title - } - } - } - } - world = volume("world", air, worldBox.ref()) { - for (i in 0 until 3) { - for (j in 0 until 3) { - for (k in 0 until 3) { - physVolume(circle) { - name = "composite$i$j$k" - position { - x = (-50 + i * 50) - y = (-50 + j * 50) - z = (-50 + k * 50) - } - rotation { - x = i * 120 - y = j * 120 - z = 120 * k - } - } - } - } - } - } - } -} \ No newline at end of file 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 0fa982dc..728c592c 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 @@ -3,7 +3,7 @@ package hep.dataforge.vision.gdml 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.gdml.GdmlShowcase.cubes import hep.dataforge.vision.setProperty import hep.dataforge.vision.solid.SolidMaterial import kotlin.test.Test @@ -11,7 +11,6 @@ import kotlin.test.assertEquals import kotlin.test.assertTrue class GDMLVisualTest { - val gdml = cubes() // @Test // fun testCubesStyles(){ @@ -24,8 +23,8 @@ class GDMLVisualTest { @Test fun testPrototypeProperty() { - val visual = gdml.toVision() - val child = visual["composite000.segment_0".toName()] + val visual = cubes.toVision() + val child = visual["composite[0,0,0].segment[0]".toName()] assertTrue { child!= null } child?.setProperty(SolidMaterial.MATERIAL_COLOR_KEY, "red".asValue()) assertEquals("red", child?.getProperty(SolidMaterial.MATERIAL_COLOR_KEY).string) diff --git a/demo/gdml/src/jsMain/kotlin/hep/dataforge/vision/gdml/demo/GdmlJsDemoApp.kt b/demo/gdml/src/jsMain/kotlin/hep/dataforge/vision/gdml/demo/GdmlJsDemoApp.kt index 6058db60..9591c475 100644 --- a/demo/gdml/src/jsMain/kotlin/hep/dataforge/vision/gdml/demo/GdmlJsDemoApp.kt +++ b/demo/gdml/src/jsMain/kotlin/hep/dataforge/vision/gdml/demo/GdmlJsDemoApp.kt @@ -2,6 +2,7 @@ package hep.dataforge.vision.gdml.demo import hep.dataforge.context.Global import hep.dataforge.vision.Application +import hep.dataforge.vision.gdml.GdmlShowcase import hep.dataforge.vision.gdml.toVision import hep.dataforge.vision.solid.three.ThreePlugin import hep.dataforge.vision.startApplication @@ -20,7 +21,7 @@ private class GDMLDemoApp : Application { } render(element) { child(GDMLApp) { - val vision = cubes().toVision() + val vision = GdmlShowcase.cubes.toVision() //println(context.plugins.fetch(VisionManager).encodeToString(vision)) attrs { this.context = context diff --git a/demo/gdml/src/jvmMain/kotlin/hep/dataforge/vision/gdml/demo/GdmlFxDemoApp.kt b/demo/gdml/src/jvmMain/kotlin/hep/dataforge/vision/gdml/demo/GdmlFxDemoApp.kt index 03915243..a4a75780 100644 --- a/demo/gdml/src/jvmMain/kotlin/hep/dataforge/vision/gdml/demo/GdmlFxDemoApp.kt +++ b/demo/gdml/src/jvmMain/kotlin/hep/dataforge/vision/gdml/demo/GdmlFxDemoApp.kt @@ -5,6 +5,7 @@ import hep.dataforge.vision.VisionManager import hep.dataforge.vision.describedProperties import hep.dataforge.vision.editor.VisualObjectEditorFragment import hep.dataforge.vision.editor.VisualObjectTreeFragment +import hep.dataforge.vision.gdml.GdmlShowcase.cubes import hep.dataforge.vision.gdml.toVision import hep.dataforge.vision.solid.FX3DPlugin import hep.dataforge.vision.solid.FXCanvas3D @@ -60,7 +61,7 @@ class GDMLView : View() { init { runAsync { - cubes().toVision() + cubes.toVision() } ui { canvas.render(it) } diff --git a/demo/playground/src/jvmMain/kotlin/gdmlCubes.kt b/demo/playground/src/jvmMain/kotlin/gdmlCubes.kt index b5a10dc5..090a1a61 100644 --- a/demo/playground/src/jvmMain/kotlin/gdmlCubes.kt +++ b/demo/playground/src/jvmMain/kotlin/gdmlCubes.kt @@ -12,9 +12,9 @@ import space.kscience.gdml.* internal val cubes = Gdml { val center = define.position("center") structure { - val air = ref("G4_AIR") - val tubeMaterial = ref("tube") - val boxMaterial = ref("box") + val air = materials.composite("G4_AIR") {} + val tubeMaterial = materials.composite("tube") {} + val boxMaterial = materials.composite("box") {} val segment = solids.tube("segment", 20, 5.0) { rmin = 17 @@ -23,11 +23,11 @@ internal val cubes = Gdml { } val worldBox = solids.box("largeBox", 200, 200, 200) val smallBox = solids.box("smallBox", 30, 30, 30) - val segmentVolume = volume("segment", tubeMaterial, segment.ref()) {} - val circle = volume("composite", boxMaterial, smallBox.ref()) { + val segmentVolume = volume("segment", tubeMaterial, segment) {} + val circle = volume("composite", boxMaterial, smallBox) { for (i in 0 until 6) { physVolume(segmentVolume) { - positionref = center.ref() + positionref = center rotation { z = 60 * i unit = AUnit.DEG.title @@ -36,7 +36,7 @@ internal val cubes = Gdml { } } - world = volume("world", air, worldBox.ref()) { + world = volume("world", air, worldBox) { for (i in 0 until 3) { for (j in 0 until 3) { for (k in 0 until 3) { diff --git a/demo/sat-demo/src/main/kotlin/ru/mipt/npm/sat/geometry.kt b/demo/sat-demo/src/main/kotlin/ru/mipt/npm/sat/geometry.kt index 283d31ef..76ac5391 100644 --- a/demo/sat-demo/src/main/kotlin/ru/mipt/npm/sat/geometry.kt +++ b/demo/sat-demo/src/main/kotlin/ru/mipt/npm/sat/geometry.kt @@ -1,11 +1,13 @@ package ru.mipt.npm.sat import hep.dataforge.meta.set +import hep.dataforge.misc.DFExperimental import hep.dataforge.vision.solid.* import hep.dataforge.vision.style import hep.dataforge.vision.useStyle import kotlin.math.PI +@DFExperimental internal fun visionOfSatellite( layers: Int = 10, layerHeight: Number = 10, diff --git a/visionforge-core/src/commonTest/kotlin/hep/dataforge/vision/html/HtmlTagTest.kt b/visionforge-core/src/commonTest/kotlin/hep/dataforge/vision/html/HtmlTagTest.kt index 7d558b45..ae19ab16 100644 --- a/visionforge-core/src/commonTest/kotlin/hep/dataforge/vision/html/HtmlTagTest.kt +++ b/visionforge-core/src/commonTest/kotlin/hep/dataforge/vision/html/HtmlTagTest.kt @@ -9,13 +9,13 @@ import kotlinx.html.* import kotlinx.html.stream.createHTML import kotlin.test.Test +@DFExperimental class HtmlTagTest { - @OptIn(DFExperimental::class) fun VisionOutput.base(block: VisionBase.() -> Unit) = VisionBase().apply(block) - val fragment: HtmlVisionFragment = { + val fragment: HtmlVisionFragment = { div { h1 { +"Head" } vision("ddd") { diff --git a/visionforge-fx/src/main/kotlin/hep/dataforge/vision/editor/ColorValueChooser.kt b/visionforge-fx/src/main/kotlin/hep/dataforge/vision/editor/ColorValueChooser.kt index 3487f95c..3fb053e5 100644 --- a/visionforge-fx/src/main/kotlin/hep/dataforge/vision/editor/ColorValueChooser.kt +++ b/visionforge-fx/src/main/kotlin/hep/dataforge/vision/editor/ColorValueChooser.kt @@ -42,7 +42,7 @@ public class ColorValueChooser : ValueChooserBase() { return node } - companion object : ValueChooser.Factory { + public companion object : ValueChooser.Factory { override val name: Name = "color".asName() override fun invoke(meta: Meta): ValueChooser = diff --git a/visionforge-fx/src/main/kotlin/hep/dataforge/vision/editor/ComboBoxValueChooser.kt b/visionforge-fx/src/main/kotlin/hep/dataforge/vision/editor/ComboBoxValueChooser.kt index 5ce3d960..dc1e80ac 100644 --- a/visionforge-fx/src/main/kotlin/hep/dataforge/vision/editor/ComboBoxValueChooser.kt +++ b/visionforge-fx/src/main/kotlin/hep/dataforge/vision/editor/ComboBoxValueChooser.kt @@ -52,7 +52,7 @@ public class ComboBoxValueChooser(public val values: Collection? = null) node.selectionModel.select(value) } - companion object : ValueChooser.Factory { + public companion object : ValueChooser.Factory { override val name: Name = "combo".asName() override fun invoke(meta: Meta): ValueChooser = diff --git a/visionforge-fx/src/main/kotlin/hep/dataforge/vision/editor/ConfigEditor.kt b/visionforge-fx/src/main/kotlin/hep/dataforge/vision/editor/ConfigEditor.kt index bff11a59..2d48b5d1 100644 --- a/visionforge-fx/src/main/kotlin/hep/dataforge/vision/editor/ConfigEditor.kt +++ b/visionforge-fx/src/main/kotlin/hep/dataforge/vision/editor/ConfigEditor.kt @@ -15,6 +15,7 @@ import hep.dataforge.vision.dfIconView import javafx.scene.Node import javafx.scene.control.* import javafx.scene.control.cell.TextFieldTreeTableCell +import javafx.scene.layout.BorderPane import javafx.scene.layout.HBox import javafx.scene.layout.Priority import javafx.scene.paint.Color @@ -26,17 +27,17 @@ import tornadofx.* * * @author Alexander Nozik */ -class ConfigEditor( - val rootNode: FXMetaNode, - val allowNew: Boolean = true, +public class ConfigEditor( + public val rootNode: FXMetaNode, + public val allowNew: Boolean = true, title: String = "Configuration editor" ) : Fragment(title = title, icon = dfIconView) { //TODO replace parameters by properties - constructor(config: Config, descriptor: NodeDescriptor?, title: String = "Configuration editor") : + public constructor(config: Config, descriptor: NodeDescriptor?, title: String = "Configuration editor") : this(FXMeta.root(config, descriptor = descriptor), title = title) - override val root = borderpane { + override val root: BorderPane = borderpane { center = treetableview> { root = TreeItem(rootNode) root.isExpanded = true diff --git a/visionforge-fx/src/main/kotlin/hep/dataforge/vision/editor/ValueChooser.kt b/visionforge-fx/src/main/kotlin/hep/dataforge/vision/editor/ValueChooser.kt index 52d2a25e..1530484a 100644 --- a/visionforge-fx/src/main/kotlin/hep/dataforge/vision/editor/ValueChooser.kt +++ b/visionforge-fx/src/main/kotlin/hep/dataforge/vision/editor/ValueChooser.kt @@ -35,18 +35,18 @@ public interface ValueChooser { * * @return */ - val node: Node + public val node: Node /** * The descriptor property for this value. Could be null * * @return */ - val descriptorProperty: ObjectProperty - var descriptor: ValueDescriptor? + public val descriptorProperty: ObjectProperty + public var descriptor: ValueDescriptor? - val valueProperty: ObjectProperty - var value: Value? + public val valueProperty: ObjectProperty + public var value: Value? /** @@ -54,21 +54,21 @@ public interface ValueChooser { * * @param value */ - fun setDisplayValue(value: Value) + public fun setDisplayValue(value: Value) - fun setDisabled(disabled: Boolean) { + public fun setDisabled(disabled: Boolean) { //TODO replace by property } - fun setCallback(callback: ValueCallback) + public fun setCallback(callback: ValueCallback) @Type("hep.dataforge.vis.fx.valueChooserFactory") - interface Factory : Named { - operator fun invoke(meta: Meta = Meta.EMPTY): ValueChooser + public interface Factory : Named { + public operator fun invoke(meta: Meta = Meta.EMPTY): ValueChooser } - companion object { + public companion object { private fun findWidgetByType(context: Context, type: String): Factory? { return when (type.toName()) { diff --git a/visionforge-gdml/build.gradle.kts b/visionforge-gdml/build.gradle.kts index 24090940..b1ee36ce 100644 --- a/visionforge-gdml/build.gradle.kts +++ b/visionforge-gdml/build.gradle.kts @@ -7,7 +7,7 @@ kotlin { val commonMain by getting { dependencies { api(project(":visionforge-solid")) - api("space.kscience:gdml:0.2.0") + api("space.kscience:gdml:0.3.0-dev") } } } diff --git a/visionforge-gdml/src/commonMain/kotlin/hep/dataforge/vision/gdml/GdmlShowcase.kt b/visionforge-gdml/src/commonMain/kotlin/hep/dataforge/vision/gdml/GdmlShowcase.kt new file mode 100644 index 00000000..1d845619 --- /dev/null +++ b/visionforge-gdml/src/commonMain/kotlin/hep/dataforge/vision/gdml/GdmlShowcase.kt @@ -0,0 +1,57 @@ +package hep.dataforge.vision.gdml + +import space.kscience.gdml.* + +public object GdmlShowcase { + public val cubes = Gdml { + val center = define.position("center") + structure { + val air = materials.composite("G4_AIR") {} + val tubeMaterial = materials.composite("tube") {} + val boxMaterial = materials.composite("box") {} + + val segment = solids.tube("segment", 20, 5.0) { + rmin = 17 + deltaphi = 60 + aunit = AUnit.DEG.title + } + val worldBox = solids.box("largeBox", 200, 200, 200) + val smallBox = solids.box("smallBox", 30, 30, 30) + val segmentVolume = volume("segment", tubeMaterial, segment) {} + val circle = volume("composite", boxMaterial, smallBox) { + for (i in 0 until 6) { + physVolume(segmentVolume) { + name = "segment[$i]" + positionref = center + rotation { + z = 60 * i + unit = AUnit.DEG.title + } + } + } + } + + world = volume("world", air, worldBox) { + for (i in 0 until 3) { + for (j in 0 until 3) { + for (k in 0 until 3) { + physVolume(circle) { + name = "composite[$i,$j,$k]" + position { + x = (-50 + i * 50) + y = (-50 + j * 50) + z = (-50 + k * 50) + } + rotation { + x = i * 120 + y = j * 120 + z = 120 * k + } + } + } + } + } + } + } + } +} \ No newline at end of file diff --git a/visionforge-gdml/src/commonMain/kotlin/hep/dataforge/vision/gdml/GdmlTransformer.kt b/visionforge-gdml/src/commonMain/kotlin/hep/dataforge/vision/gdml/GdmlTransformer.kt index c1fef40b..23b6d690 100644 --- a/visionforge-gdml/src/commonMain/kotlin/hep/dataforge/vision/gdml/GdmlTransformer.kt +++ b/visionforge-gdml/src/commonMain/kotlin/hep/dataforge/vision/gdml/GdmlTransformer.kt @@ -66,7 +66,12 @@ private class GdmlTransformer(val settings: GdmlTransformerSettings) { return ref } - private fun proxyVolume(root: Gdml, group: SolidGroup, physVolume: GdmlPhysVolume, volume: GdmlGroup): SolidReferenceGroup { + private fun proxyVolume( + root: Gdml, + group: SolidGroup, + physVolume: GdmlPhysVolume, + volume: GdmlGroup, + ): SolidReferenceGroup { val templateName = volumesName + volume.name.asName() if (proto[templateName] == null) { proto[templateName] = volume(root, volume) diff --git a/visionforge-gdml/src/commonTest/kotlin/TestCubes.kt b/visionforge-gdml/src/commonTest/kotlin/TestCubes.kt new file mode 100644 index 00000000..ca6f71ab --- /dev/null +++ b/visionforge-gdml/src/commonTest/kotlin/TestCubes.kt @@ -0,0 +1,66 @@ +package hep.dataforge.vision.gdml + +import hep.dataforge.context.Context +import hep.dataforge.names.toName +import hep.dataforge.vision.Vision +import hep.dataforge.vision.gdml.GdmlShowcase.cubes +import hep.dataforge.vision.get +import hep.dataforge.vision.solid.* +import hep.dataforge.vision.visionManager +import space.kscience.gdml.Gdml +import space.kscience.gdml.GdmlBox +import space.kscience.gdml.decodeFromString +import space.kscience.gdml.encodeToString +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotNull + +internal val testContext = Context("TEST") { + plugin(Solids) +} + +class TestCubes { + + @Test + fun testCubesDirect() { + val vision = cubes.toVision() + val smallBoxPrototype = vision.getPrototype("solids.smallBox".toName()) as? Box + assertNotNull(smallBoxPrototype) + assertEquals(30.0, smallBoxPrototype.xSize.toDouble()) + val smallBoxVision = vision["composite[1,1,1].smallBox"]?.prototype as? Box + assertNotNull(smallBoxVision) + assertEquals(30.0, smallBoxVision.xSize.toDouble()) + } + + @Test + fun testGdmlExport() { + val xml = cubes.encodeToString() + //println(xml) + val gdml = Gdml.decodeFromString(xml) + val smallBox = gdml.getSolid("smallBox") + assertNotNull(smallBox) + assertEquals(30.0, smallBox.x.toDouble()) + } + + @Test + fun testCubesReSerialize() { + val vision = cubes.toVision() + val serialized = Solids.encodeToString(vision) + val deserialized = testContext.visionManager.decodeFromString(serialized) as SolidGroup + val smallBox = deserialized.getPrototype("solids.smallBox".toName()) as? Box + assertNotNull(smallBox) + assertEquals(30.0, smallBox.xSize.toDouble()) + //println(testContext.visionManager.encodeToString(deserialized)) + fun Vision.checkPrototypes() { + if (this is SolidReference) { + assertNotNull(this.prototype) + } + if (this is SolidGroup) { + children.forEach { + it.value.checkPrototypes() + } + } + } + deserialized.checkPrototypes() + } +} \ No newline at end of file diff --git a/visionforge-gdml/src/jvmTest/kotlin/hep/dataforge/vision/gdml/TestCubes.kt b/visionforge-gdml/src/jvmTest/kotlin/hep/dataforge/vision/gdml/TestCubes.kt deleted file mode 100644 index d0d0f054..00000000 --- a/visionforge-gdml/src/jvmTest/kotlin/hep/dataforge/vision/gdml/TestCubes.kt +++ /dev/null @@ -1,96 +0,0 @@ -package hep.dataforge.vision.gdml - -import hep.dataforge.context.Context -import hep.dataforge.names.toName -import hep.dataforge.vision.Vision -import hep.dataforge.vision.solid.SolidGroup -import hep.dataforge.vision.solid.SolidReference -import hep.dataforge.vision.solid.Solids -import hep.dataforge.vision.visionManager -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertDoesNotThrow -import space.kscience.gdml.* -import kotlin.test.assertNotNull - -internal val testContext = Context("TEST"){ - plugin(Solids) -} - -class TestCubes { - - internal val cubes = Gdml { - val center = define.position("center") - structure { - val air = ref("G4_AIR") - val tubeMaterial = ref("tube") - val boxMaterial = ref("box") - - val segment = solids.tube("segment", 20, 5.0) { - rmin = 17 - deltaphi = 60 - aunit = AUnit.DEG.title - } - val worldBox = solids.box("largeBox", 200, 200, 200) - val smallBox = solids.box("smallBox", 30, 30, 30) - val segmentVolume = volume("segment", tubeMaterial, segment.ref()) {} - val circle = volume("composite", boxMaterial, smallBox.ref()) { - for (i in 0 until 6) { - physVolume(segmentVolume) { - positionref = center.ref() - rotation { - z = 60 * i - unit = AUnit.DEG.title - } - } - } - } - - world = volume("world", air, worldBox.ref()) { - for (i in 0 until 3) { - for (j in 0 until 3) { - for (k in 0 until 3) { - physVolume(circle) { - position { - x = (-50 + i * 50) - y = (-50 + j * 50) - z = (-50 + k * 50) - } - rotation { - x = i * 120 - y = j * 120 - z = 120 * k - } - } - } - } - } - } - } - } - - @Test - fun testCubesDirect(){ - val vision = cubes.toVision() - assertNotNull(vision.getPrototype("solids.smallBox".toName())) - } - - @Test - fun testCubesReSerialize(){ - val vision = cubes.toVision() - val serialized = Solids.encodeToString(vision) - val deserialized = testContext.visionManager.decodeFromString(serialized) as SolidGroup - assertNotNull(deserialized.getPrototype("solids.smallBox".toName())) - //println(testContext.visionManager.encodeToString(deserialized)) - fun Vision.checkPrototypes(){ - if(this is SolidReference){ - assertDoesNotThrow { this.prototype } - } - if(this is SolidGroup){ - children.forEach { - it.value.checkPrototypes() - } - } - } - deserialized.checkPrototypes() - } -} \ No newline at end of file diff --git a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidReference.kt b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidReference.kt index c70db5f8..c5b3554c 100644 --- a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidReference.kt +++ b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidReference.kt @@ -163,7 +163,7 @@ public class SolidReferenceGroup( * Get a vision prototype if it is a [SolidReferenceGroup] or vision itself if it is not */ public val Vision.prototype: Vision - get() = if (this is SolidReference) prototype else this + get() = if (this is SolidReference) prototype.prototype else this /** * Create ref for existing prototype diff --git a/visionforge-solid/src/commonTest/kotlin/hep/dataforge/vision/solid/SolidReferenceTest.kt b/visionforge-solid/src/commonTest/kotlin/hep/dataforge/vision/solid/SolidReferenceTest.kt index 04bb38e5..bb84eb31 100644 --- a/visionforge-solid/src/commonTest/kotlin/hep/dataforge/vision/solid/SolidReferenceTest.kt +++ b/visionforge-solid/src/commonTest/kotlin/hep/dataforge/vision/solid/SolidReferenceTest.kt @@ -1,5 +1,6 @@ package hep.dataforge.vision.solid +import hep.dataforge.misc.DFExperimental import hep.dataforge.vision.get import hep.dataforge.vision.style import hep.dataforge.vision.useStyle @@ -7,6 +8,7 @@ import kotlinx.serialization.json.encodeToJsonElement import kotlin.test.Test import kotlin.test.assertEquals +@DFExperimental class SolidReferenceTest { val groupWithReference = SolidGroup { val theStyle by style { diff --git a/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/ThreePlugin.kt b/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/ThreePlugin.kt index 1e8427bd..63eb4e28 100644 --- a/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/ThreePlugin.kt +++ b/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/ThreePlugin.kt @@ -2,6 +2,7 @@ package hep.dataforge.vision.solid.three import hep.dataforge.context.* import hep.dataforge.meta.Meta +import hep.dataforge.misc.DFExperimental import hep.dataforge.names.* import hep.dataforge.vision.* import hep.dataforge.vision.solid.* @@ -50,7 +51,7 @@ public class ThreePlugin : AbstractPlugin(), ElementVisionRenderer { is SolidGroup -> { val group = ThreeGroup() obj.children.forEach { (token, child) -> - if (child is Solid && child.ignore != true) { + if (child is Solid && token != SolidGroup.PROTOTYPES_TOKEN && child.ignore != true) { try { val object3D = buildObject3D(child) group[token] = object3D @@ -151,6 +152,7 @@ public class ThreePlugin : AbstractPlugin(), ElementVisionRenderer { /** * Ensure that [ThreePlugin] is loaded in the global [VisionForge] context */ +@DFExperimental public fun VisionForge.useThreeJs() { plugins.fetch(ThreePlugin) } diff --git a/visionforge-threejs/visionforge-threejs-server/src/jsMain/kotlin/hep/dataforge/vision/three/server/jsMain.kt b/visionforge-threejs/visionforge-threejs-server/src/jsMain/kotlin/hep/dataforge/vision/three/server/jsMain.kt index 07bdcb4a..9fd1ebf4 100644 --- a/visionforge-threejs/visionforge-threejs-server/src/jsMain/kotlin/hep/dataforge/vision/three/server/jsMain.kt +++ b/visionforge-threejs/visionforge-threejs-server/src/jsMain/kotlin/hep/dataforge/vision/three/server/jsMain.kt @@ -1,8 +1,10 @@ package hep.dataforge.vision.three.server +import hep.dataforge.misc.DFExperimental import hep.dataforge.vision.VisionForge import hep.dataforge.vision.solid.three.useThreeJs +@DFExperimental public fun main(): Unit = VisionForge.run { useThreeJs() renderVisionsInWindow()