From 806093385949f95f1134b4fcb17e78920a177f4e Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 7 Mar 2021 19:22:30 +0300 Subject: [PATCH] Gdml fixes --- build.gradle.kts | 9 +- demo/muon-monitor/build.gradle.kts | 2 +- .../visionforge-gdml-jupyter/build.gradle.kts | 16 ++++ .../src/main/kotlin/GdmlForJupyter.kt | 84 +++++++++++++++++++ settings.gradle.kts | 7 +- visionforge-core/build.gradle.kts | 3 +- visionforge-gdml/build.gradle.kts | 2 +- .../kscience/visionforge/gdml/GdmlShowcase.kt | 4 +- visionforge-server/build.gradle.kts | 2 +- .../visionforge/three/server/jsMain.kt | 3 + 10 files changed, 115 insertions(+), 17 deletions(-) create mode 100644 jupyter/visionforge-gdml-jupyter/build.gradle.kts create mode 100644 jupyter/visionforge-gdml-jupyter/src/main/kotlin/GdmlForJupyter.kt diff --git a/build.gradle.kts b/build.gradle.kts index 12a8077e..c3f88591 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,8 +5,6 @@ plugins { } val dataforgeVersion by extra("0.4.0-dev-2") -val ktorVersion by extra(ru.mipt.npm.gradle.KScienceVersions.ktorVersion) -val htmlVersion by extra(ru.mipt.npm.gradle.KScienceVersions.htmlVersion) val kotlinWrappersVersion by extra("pre.148-kotlin-1.4.30") val fxVersion by extra("14") @@ -21,13 +19,10 @@ allprojects { maven("http://maven.jzy3d.org/releases") } - group = "hep.dataforge" - version = "0.2.0-dev-7" + group = "space.kscience" + version = "0.2.0-dev-8" } -val githubProject by extra("visionforge") -val bintrayRepo by extra("dataforge") - subprojects { if (name.startsWith("visionforge")) { plugins.apply("maven-publish") diff --git a/demo/muon-monitor/build.gradle.kts b/demo/muon-monitor/build.gradle.kts index 0e0d1dab..72e086b0 100644 --- a/demo/muon-monitor/build.gradle.kts +++ b/demo/muon-monitor/build.gradle.kts @@ -7,7 +7,7 @@ plugins { group = "ru.mipt.npm" -val ktorVersion: String by rootProject.extra +val ktorVersion: String = ru.mipt.npm.gradle.KScienceVersions.ktorVersion kscience { useSerialization() diff --git a/jupyter/visionforge-gdml-jupyter/build.gradle.kts b/jupyter/visionforge-gdml-jupyter/build.gradle.kts new file mode 100644 index 00000000..cc1988dc --- /dev/null +++ b/jupyter/visionforge-gdml-jupyter/build.gradle.kts @@ -0,0 +1,16 @@ +plugins { + id("ru.mipt.npm.gradle.jvm") + kotlin("jupyter.api") +} + +description = "Jupyter api artifact for GDML rendering" + +dependencies { + implementation(project(":visionforge-gdml")) + implementation(project(":visionforge-threejs:visionforge-threejs-server")) +} + +readme{ + maturity = ru.mipt.npm.gradle.Maturity.EXPERIMENTAL +} + diff --git a/jupyter/visionforge-gdml-jupyter/src/main/kotlin/GdmlForJupyter.kt b/jupyter/visionforge-gdml-jupyter/src/main/kotlin/GdmlForJupyter.kt new file mode 100644 index 00000000..5c8c32d0 --- /dev/null +++ b/jupyter/visionforge-gdml-jupyter/src/main/kotlin/GdmlForJupyter.kt @@ -0,0 +1,84 @@ +package space.kscience.visionforge.gdml.jupyter + +import kotlinx.html.div +import kotlinx.html.id +import kotlinx.html.script +import kotlinx.html.stream.createHTML +import kotlinx.html.unsafe +import org.jetbrains.kotlinx.jupyter.api.HTML +import org.jetbrains.kotlinx.jupyter.api.annotations.JupyterLibrary +import org.jetbrains.kotlinx.jupyter.api.libraries.* +import space.kscience.dataforge.misc.DFExperimental +import space.kscience.gdml.Gdml +import space.kscience.visionforge.Vision +import space.kscience.visionforge.VisionForge +import space.kscience.visionforge.gdml.toVision +import space.kscience.visionforge.html.HtmlVisionFragment +import space.kscience.visionforge.html.Page +import space.kscience.visionforge.html.embedVisionFragment +import space.kscience.visionforge.html.fragment +import space.kscience.visionforge.plugins +import space.kscience.visionforge.solid.Solids +import space.kscience.visionforge.visionManager + +@JupyterLibrary +@DFExperimental +internal class GdmlForJupyter : JupyterIntegration() { + + private val jsBundle = ResourceFallbacksBundle(listOf( + ResourceLocation("js/visionforge-three.js", ResourcePathType.CLASSPATH_PATH)) + ) + private val jsResource = LibraryResource(name = "visionforge-three", type = ResourceType.JS, bundles = listOf(jsBundle)) + + private var counter = 0 + + private fun produceHtmlVisionString(fragment: HtmlVisionFragment) = createHTML().div { + val id = "visionforge.vision[${counter++}]" + div { + this.id = id + embedVisionFragment(VisionForge.visionManager, fragment = fragment) + } + script { + type = "text/javascript" + unsafe { +"window.renderVisionsAt(\"$id\");" } + } + } + + override fun Builder.onLoaded() { + resource(jsResource) + + onLoaded { + VisionForge.plugins.fetch(Solids) + } + + import( + "space.kscience.gdml.*", + "kotlinx.html.*", + "space.kscience.visionforge.solid.*", + "space.kscience.visionforge.html.Page", + "space.kscience.visionforge.html.page", + "space.kscience.visionforge.gdml.jupyter.*" + ) + + import() + + render { gdmlModel -> + val fragment = VisionForge.fragment { + vision(gdmlModel.toVision()) + } + HTML(produceHtmlVisionString(fragment)) + } + + render { vision -> + val fragment = VisionForge.fragment { + vision(vision) + } + + HTML(produceHtmlVisionString(fragment)) + } + + render { page -> + HTML(page.render(createHTML()), true) + } + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index b85d49a3..d8a039bc 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,6 +1,6 @@ pluginManagement { val kotlinVersion = "1.4.31" - val toolsVersion = "0.9.0" + val toolsVersion = "0.9.1" repositories { maven("https://repo.kotlin.link") @@ -45,5 +45,6 @@ include( ":demo:muon-monitor", ":demo:sat-demo", ":demo:playground", - ":demo:jupyter-playground" -) + ":demo:jupyter-playground", + ":jupyter:visionforge-gdml-jupyter" +) \ No newline at end of file diff --git a/visionforge-core/build.gradle.kts b/visionforge-core/build.gradle.kts index d33d733d..89a3b693 100644 --- a/visionforge-core/build.gradle.kts +++ b/visionforge-core/build.gradle.kts @@ -4,7 +4,6 @@ plugins { val dataforgeVersion: String by rootProject.extra val kotlinWrappersVersion: String by rootProject.extra -val htmlVersion: String by rootProject.extra kscience{ useSerialization() @@ -15,7 +14,7 @@ kotlin { commonMain { dependencies { api("space.kscience:dataforge-context:$dataforgeVersion") - api("org.jetbrains.kotlinx:kotlinx-html:$htmlVersion") + api("org.jetbrains.kotlinx:kotlinx-html:${ru.mipt.npm.gradle.KScienceVersions.htmlVersion}") api("org.jetbrains:kotlin-css:1.0.0-$kotlinWrappersVersion") } } diff --git a/visionforge-gdml/build.gradle.kts b/visionforge-gdml/build.gradle.kts index b99fef45..738b0724 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.3.0") + api("space.kscience:gdml:0.3.2") } } } diff --git a/visionforge-gdml/src/commonMain/kotlin/space/kscience/visionforge/gdml/GdmlShowcase.kt b/visionforge-gdml/src/commonMain/kotlin/space/kscience/visionforge/gdml/GdmlShowcase.kt index b677e124..03c403aa 100644 --- a/visionforge-gdml/src/commonMain/kotlin/space/kscience/visionforge/gdml/GdmlShowcase.kt +++ b/visionforge-gdml/src/commonMain/kotlin/space/kscience/visionforge/gdml/GdmlShowcase.kt @@ -13,7 +13,7 @@ public object GdmlShowcase { val segment = solids.tube("segment", 20, 5.0) { rmin = 17 deltaphi = 60 - aunit = AUnit.DEG.title + aunit = AUnit.DEG } val worldBox = solids.box("largeBox", 200, 200, 200) val smallBox = solids.box("smallBox", 30, 30, 30) @@ -25,7 +25,7 @@ public object GdmlShowcase { positionref = center rotation { z = 60 * i - unit = AUnit.DEG.title + unit = AUnit.DEG } } } diff --git a/visionforge-server/build.gradle.kts b/visionforge-server/build.gradle.kts index 8c98f498..18fda1cf 100644 --- a/visionforge-server/build.gradle.kts +++ b/visionforge-server/build.gradle.kts @@ -2,7 +2,7 @@ plugins { id("ru.mipt.npm.gradle.jvm") } -val ktorVersion: String by rootProject.extra +val ktorVersion = ru.mipt.npm.gradle.KScienceVersions.ktorVersion dependencies { api(project(":visionforge-core")) diff --git a/visionforge-threejs/visionforge-threejs-server/src/jsMain/kotlin/space/kscience/visionforge/three/server/jsMain.kt b/visionforge-threejs/visionforge-threejs-server/src/jsMain/kotlin/space/kscience/visionforge/three/server/jsMain.kt index e65b2503..9ed1536e 100644 --- a/visionforge-threejs/visionforge-threejs-server/src/jsMain/kotlin/space/kscience/visionforge/three/server/jsMain.kt +++ b/visionforge-threejs/visionforge-threejs-server/src/jsMain/kotlin/space/kscience/visionforge/three/server/jsMain.kt @@ -1,5 +1,6 @@ package space.kscience.visionforge.three.server +import kotlinx.browser.window import space.kscience.dataforge.misc.DFExperimental import space.kscience.visionforge.VisionForge import space.kscience.visionforge.solid.three.useThreeJs @@ -8,4 +9,6 @@ import space.kscience.visionforge.solid.three.useThreeJs public fun main(): Unit = VisionForge.run { useThreeJs() renderVisionsInWindow() + window.asDynamic()["renderVisionsAt"] = ::renderVisionsAt + window.asDynamic()["renderVisionsInWindow"] = ::renderVisionsInWindow } \ No newline at end of file