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 @@