Gdml fixes

This commit is contained in:
Alexander Nozik 2021-03-07 19:22:30 +03:00
parent 7febb4452a
commit 8060933859
10 changed files with 115 additions and 17 deletions

View File

@ -5,8 +5,6 @@ plugins {
} }
val dataforgeVersion by extra("0.4.0-dev-2") 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 kotlinWrappersVersion by extra("pre.148-kotlin-1.4.30")
val fxVersion by extra("14") val fxVersion by extra("14")
@ -21,13 +19,10 @@ allprojects {
maven("http://maven.jzy3d.org/releases") maven("http://maven.jzy3d.org/releases")
} }
group = "hep.dataforge" group = "space.kscience"
version = "0.2.0-dev-7" version = "0.2.0-dev-8"
} }
val githubProject by extra("visionforge")
val bintrayRepo by extra("dataforge")
subprojects { subprojects {
if (name.startsWith("visionforge")) { if (name.startsWith("visionforge")) {
plugins.apply("maven-publish") plugins.apply("maven-publish")

View File

@ -7,7 +7,7 @@ plugins {
group = "ru.mipt.npm" group = "ru.mipt.npm"
val ktorVersion: String by rootProject.extra val ktorVersion: String = ru.mipt.npm.gradle.KScienceVersions.ktorVersion
kscience { kscience {
useSerialization() useSerialization()

View File

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

View File

@ -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<VisionForge>()
render<Gdml> { gdmlModel ->
val fragment = VisionForge.fragment {
vision(gdmlModel.toVision())
}
HTML(produceHtmlVisionString(fragment))
}
render<Vision> { vision ->
val fragment = VisionForge.fragment {
vision(vision)
}
HTML(produceHtmlVisionString(fragment))
}
render<Page> { page ->
HTML(page.render(createHTML()), true)
}
}
}

View File

@ -1,6 +1,6 @@
pluginManagement { pluginManagement {
val kotlinVersion = "1.4.31" val kotlinVersion = "1.4.31"
val toolsVersion = "0.9.0" val toolsVersion = "0.9.1"
repositories { repositories {
maven("https://repo.kotlin.link") maven("https://repo.kotlin.link")
@ -45,5 +45,6 @@ include(
":demo:muon-monitor", ":demo:muon-monitor",
":demo:sat-demo", ":demo:sat-demo",
":demo:playground", ":demo:playground",
":demo:jupyter-playground" ":demo:jupyter-playground",
) ":jupyter:visionforge-gdml-jupyter"
)

View File

@ -4,7 +4,6 @@ plugins {
val dataforgeVersion: String by rootProject.extra val dataforgeVersion: String by rootProject.extra
val kotlinWrappersVersion: String by rootProject.extra val kotlinWrappersVersion: String by rootProject.extra
val htmlVersion: String by rootProject.extra
kscience{ kscience{
useSerialization() useSerialization()
@ -15,7 +14,7 @@ kotlin {
commonMain { commonMain {
dependencies { dependencies {
api("space.kscience:dataforge-context:$dataforgeVersion") 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") api("org.jetbrains:kotlin-css:1.0.0-$kotlinWrappersVersion")
} }
} }

View File

@ -7,7 +7,7 @@ kotlin {
val commonMain by getting { val commonMain by getting {
dependencies { dependencies {
api(project(":visionforge-solid")) api(project(":visionforge-solid"))
api("space.kscience:gdml:0.3.0") api("space.kscience:gdml:0.3.2")
} }
} }
} }

View File

@ -13,7 +13,7 @@ public object GdmlShowcase {
val segment = solids.tube("segment", 20, 5.0) { val segment = solids.tube("segment", 20, 5.0) {
rmin = 17 rmin = 17
deltaphi = 60 deltaphi = 60
aunit = AUnit.DEG.title aunit = AUnit.DEG
} }
val worldBox = solids.box("largeBox", 200, 200, 200) val worldBox = solids.box("largeBox", 200, 200, 200)
val smallBox = solids.box("smallBox", 30, 30, 30) val smallBox = solids.box("smallBox", 30, 30, 30)
@ -25,7 +25,7 @@ public object GdmlShowcase {
positionref = center positionref = center
rotation { rotation {
z = 60 * i z = 60 * i
unit = AUnit.DEG.title unit = AUnit.DEG
} }
} }
} }

View File

@ -2,7 +2,7 @@ plugins {
id("ru.mipt.npm.gradle.jvm") id("ru.mipt.npm.gradle.jvm")
} }
val ktorVersion: String by rootProject.extra val ktorVersion = ru.mipt.npm.gradle.KScienceVersions.ktorVersion
dependencies { dependencies {
api(project(":visionforge-core")) api(project(":visionforge-core"))

View File

@ -1,5 +1,6 @@
package space.kscience.visionforge.three.server package space.kscience.visionforge.three.server
import kotlinx.browser.window
import space.kscience.dataforge.misc.DFExperimental import space.kscience.dataforge.misc.DFExperimental
import space.kscience.visionforge.VisionForge import space.kscience.visionforge.VisionForge
import space.kscience.visionforge.solid.three.useThreeJs import space.kscience.visionforge.solid.three.useThreeJs
@ -8,4 +9,6 @@ import space.kscience.visionforge.solid.three.useThreeJs
public fun main(): Unit = VisionForge.run { public fun main(): Unit = VisionForge.run {
useThreeJs() useThreeJs()
renderVisionsInWindow() renderVisionsInWindow()
window.asDynamic()["renderVisionsAt"] = ::renderVisionsAt
window.asDynamic()["renderVisionsInWindow"] = ::renderVisionsInWindow
} }