From 66caebb090c9a47e983ad43b52055965b4895883 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Thu, 19 Sep 2019 11:17:20 +0300 Subject: [PATCH] Correct tree controls for groups and proxy --- .../dataforge/vis/spatial/gdml/visualGDML.kt | 6 +- .../vis/spatial/gdml/demo/GDMLDemoApp.kt | 38 +- .../vis/spatial/gdml/demo/treeTools.kt | 13 + .../src/jsMain/web/index.html | 9 +- .../src/jsMain/web/main.css | 2 +- dataforge-vis-spatial/build.gradle.kts | 4 +- .../dataforge/vis/spatial/VisualGroup3D.kt | 2 +- .../dataforge/vis/spatial/tree/VisualTree.kt | 8 + .../hep/dataforge/vis/fancytree/Fancytree.kt | 427 ------------------ .../hep/dataforge/vis/fancytree/extensions.kt | 78 ---- .../hep/dataforge/vis/fancytree/kotlinized.kt | 6 - .../vis/spatial/three/ThreePlugin.kt | 17 +- .../vis/spatial/three/ThreeProxyFactory.kt | 17 + .../vis/spatial/tree/JSVisualTree.kt | 74 +++ 14 files changed, 160 insertions(+), 541 deletions(-) create mode 100644 dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/treeTools.kt create mode 100644 dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/tree/VisualTree.kt delete mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/fancytree/Fancytree.kt delete mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/fancytree/extensions.kt delete mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/fancytree/kotlinized.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/tree/JSVisualTree.kt diff --git a/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/visualGDML.kt b/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/visualGDML.kt index f2e31d30..580f487e 100644 --- a/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/visualGDML.kt +++ b/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/visualGDML.kt @@ -80,7 +80,7 @@ private fun VisualGroup3D.addSolid( val innerSolid = solid.solidref.resolve(context.root) ?: error("Solid with tag ${solid.solidref.ref} for scaled solid ${solid.name} not defined") - addSolid(context, innerSolid) { + addSolid(context, innerSolid, name) { block() scaleX *= solid.scale.x.toFloat() scaleY *= solid.scale.y.toFloat() @@ -152,7 +152,7 @@ private fun VisualGroup3D.addPhysicalVolume( val group = volume(context, volume) //optimizing single child case if (context.optimizeSingleChild && group.children.size == 1) { - this[physVolume.name ?: "@unnamed"] = group.children.values.first().apply { + this[physVolume.name ?: ""] = group.children.values.first().apply { //Must ser this to avoid parent reset error parent = null //setting offset from physical volume @@ -167,7 +167,7 @@ private fun VisualGroup3D.addPhysicalVolume( rotation += group.rotation } } else { - this[physVolume.name ?: "@unnamed"] = group.apply { + this[physVolume.name ?: ""] = group.apply { withPosition( context.lUnit, physVolume.resolvePosition(context.root), diff --git a/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt b/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt index 7e74041a..77aa1977 100644 --- a/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt +++ b/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt @@ -15,8 +15,9 @@ import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import kotlinx.html.InputType import kotlinx.html.dom.append -import kotlinx.html.js.div import kotlinx.html.js.input +import kotlinx.html.js.li +import kotlinx.html.js.ul import org.w3c.dom.Element import org.w3c.dom.HTMLDivElement import org.w3c.dom.events.Event @@ -79,27 +80,30 @@ private class GDMLDemoApp : ApplicationBase() { } } - fun setupSidebar(element: Element, output: ThreeOutput) { + fun setupSidebar(element: Element, output: ThreeOutput, root: VisualObject3D) { element.clear() - (0..9).forEach { layer -> - element.append { - div("row") { - +"layer $layer" - input(type = InputType.checkBox).apply { - if (layer == 0) { - checked = true - } - onchange = { - if (checked) { - output.camera.layers.enable(layer) - } else { - output.camera.layers.disable(layer) + element.append { + ul("list-group") { + (0..9).forEach { layer -> + li("list-group-item") { + +"layer $layer" + input(type = InputType.checkBox).apply { + if (layer == 0) { + checked = true + } + onchange = { + if (checked) { + output.camera.layers.enable(layer) + } else { + output.camera.layers.disable(layer) + } } } } } } } + element.appendFancyTree(root) } private val gdmlConfiguration: GDMLTransformer.() -> Unit = { @@ -118,8 +122,6 @@ private class GDMLDemoApp : ApplicationBase() { } } -// optimizeSingleChild = true - solidConfiguration = { parent, solid -> if (!parent.physVolumes.isEmpty()) { opacity = 0.3 @@ -169,7 +171,7 @@ private class GDMLDemoApp : ApplicationBase() { //output.camera.layers.enable(1) output.camera.layers.set(0) - setupSidebar(sidebar, output) + setupSidebar(sidebar, output, visual) output.render(visual) launch { diff --git a/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/treeTools.kt b/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/treeTools.kt new file mode 100644 index 00000000..c8cc5636 --- /dev/null +++ b/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/treeTools.kt @@ -0,0 +1,13 @@ +package hep.dataforge.vis.spatial.gdml.demo + +import hep.dataforge.vis.spatial.VisualObject3D +import hep.dataforge.vis.spatial.tree.JSVisualTree +import nl.adaptivity.js.util.asElement +import org.w3c.dom.Element + +fun Element.appendFancyTree(root: VisualObject3D){ + val visualTree = JSVisualTree("world", root) {} + val treeNode = visualTree.root + treeNode.asElement()!!.id = "fancytree" + appendChild(treeNode) +} \ No newline at end of file diff --git a/dataforge-vis-spatial-gdml/src/jsMain/web/index.html b/dataforge-vis-spatial-gdml/src/jsMain/web/index.html index 1a27e18d..d7e24b00 100644 --- a/dataforge-vis-spatial-gdml/src/jsMain/web/index.html +++ b/dataforge-vis-spatial-gdml/src/jsMain/web/index.html @@ -6,7 +6,8 @@ Three js demo for particle physics - + + @@ -22,15 +23,15 @@ -
+
-