Migrate to the new plugin

This commit is contained in:
Alexander Nozik 2021-02-23 21:47:18 +03:00
parent 1da4381a4c
commit 60906db32e
44 changed files with 290 additions and 161 deletions

View File

@ -1,31 +1,35 @@
plugins {
id("ru.mipt.npm.project")
id("ru.mipt.npm.gradle.project")
kotlin("jvm") apply false
kotlin("jupyter.api") apply false
}
val dataforgeVersion by extra("0.3.0")
val ktorVersion by extra("1.5.1")
val htmlVersion by extra("0.7.2")
val kotlinWrappersVersion by extra("pre.129-kotlin-1.4.20")
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")
allprojects {
repositories {
mavenLocal()
mavenCentral()
jcenter()
maven("https://kotlin.bintray.com/kotlin-js-wrappers")
maven("https://dl.bintray.com/pdvrieze/maven")
maven("http://maven.jzy3d.org/releases")
}
group = "hep.dataforge"
version = "0.2.0-dev-4"
version = "0.2.0-dev-5"
}
val githubProject by extra("visionforge")
val bintrayRepo by extra("dataforge")
subprojects {
if(name.startsWith("visionforge")) {
apply<ru.mipt.npm.gradle.KSciencePublishPlugin>()
if (name.startsWith("visionforge")) {
plugins.apply("ru.mipt.npm.gradle.publish")
}
}

View File

@ -2,7 +2,7 @@ import ru.mipt.npm.gradle.DependencyConfiguration
import ru.mipt.npm.gradle.FXModule
plugins {
id("ru.mipt.npm.mpp")
id("ru.mipt.npm.gradle.mpp")
application
}

View File

@ -1,14 +1,14 @@
package hep.dataforge.vision.gdml.demo
import kscience.gdml.*
import space.kscience.gdml.*
fun cubes(): GDML = GDML {
fun cubes(): Gdml = Gdml {
val center = define.position("center")
structure {
val air = ref<GDMLMaterial>("G4_AIR")
val tubeMaterial = ref<GDMLMaterial>("tube")
val boxMaterial = ref<GDMLMaterial>("box")
val air = ref<GdmlMaterial>("G4_AIR")
val tubeMaterial = ref<GdmlMaterial>("tube")
val boxMaterial = ref<GdmlMaterial>("box")
val segment = solids.tube("segment", 20, 5.0) {
rmin = 17
deltaphi = 60

View File

@ -15,8 +15,8 @@ import hep.dataforge.vision.solid.specifications.Canvas3DOptions
import hep.dataforge.vision.solid.three.ThreeCanvas
import kotlinx.browser.window
import kotlinx.css.*
import kscience.gdml.GDML
import kscience.gdml.decodeFromString
import space.kscience.gdml.Gdml
import space.kscience.gdml.decodeFromString
import org.w3c.files.FileReader
import org.w3c.files.get
import react.RProps
@ -55,7 +55,7 @@ val GDMLApp = functionalComponent<GDMLAppProps>("GDMLApp") { props ->
val visionManager = props.context.plugins.fetch(SolidManager).visionManager
val parsedVision = when {
name.endsWith(".gdml") || name.endsWith(".xml") -> {
val gdml = GDML.decodeFromString(data)
val gdml = Gdml.decodeFromString(data)
gdml.toVision()
}
name.endsWith(".json") -> visionManager.decodeFromString(data)

View File

@ -9,7 +9,7 @@ import hep.dataforge.vision.solid.SolidManager
import hep.dataforge.vision.solid.SolidMaterial
import hep.dataforge.vision.Vision
import hep.dataforge.vision.VisionManager
import kscience.gdml.GDML
import space.kscience.gdml.Gdml
import java.io.File
import java.util.zip.GZIPInputStream
import java.util.zip.ZipInputStream
@ -17,7 +17,7 @@ import java.util.zip.ZipInputStream
@OptIn(DFExperimental::class)
fun VisionManager.readFile(file: File): Vision = when {
file.extension == "gdml" || file.extension == "xml" -> {
GDML.readFile(file.toPath()).toVision {
Gdml.readFile(file.toPath()).toVision {
// lUnit = LUnit.CM
//
// solidConfiguration = { parent, solid ->

View File

@ -3,8 +3,8 @@ package hep.dataforge.vision.gdml.demo
import hep.dataforge.vision.gdml.readFile
import hep.dataforge.vision.gdml.toVision
import hep.dataforge.vision.solid.SolidManager
import kscience.gdml.GDML
import kscience.gdml.LUnit
import space.kscience.gdml.Gdml
import space.kscience.gdml.LUnit
import java.io.File
import java.nio.file.Paths
@ -14,7 +14,7 @@ fun main(args: Array<String>) {
require(inputFileName.endsWith(".gdml")){"GDML required"}
val outputFileName = args.getOrNull(1)?:inputFileName.replace(".gdml",".json")
val gdml = GDML.readFile(Paths.get(inputFileName))
val gdml = Gdml.readFile(Paths.get(inputFileName))
//GDML.readFile(Paths.get("D:\\Work\\Projects\\visionforge\\visionforge-spatial-gdml\\src\\jvmTest\\resources\\gdml\\simple1.gdml"))
val vision = gdml.toVision {

View File

@ -0,0 +1,36 @@
plugins {
kotlin("jvm")
kotlin("jupyter.api")
id("com.github.johnrengelman.shadow") version "6.1.0"
}
repositories {
mavenCentral()
maven("https://repo.kotlin.link")
maven("https://dl.bintray.com/mipt-npm/dataforge")
maven("https://dl.bintray.com/mipt-npm/kscience")
maven("https://dl.bintray.com/mipt-npm/dev")
}
dependencies {
implementation(project(":demo:playground"))
}
tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompile> {
kotlinOptions {
useIR = true
jvmTarget = ru.mipt.npm.gradle.KScienceVersions.JVM_TARGET.toString()
}
}
extensions.findByType<JavaPluginExtension>()?.apply {
targetCompatibility = ru.mipt.npm.gradle.KScienceVersions.JVM_TARGET
}
tasks.withType<Test> {
useJUnitPlatform()
}
tasks.processJupyterApiResources {
libraryProducers = listOf("hep.dataforge.playground.VisionForgePlayGroundForJupyter")
}

View File

@ -0,0 +1,88 @@
package hep.dataforge.playground
import hep.dataforge.context.Context
import hep.dataforge.vision.VisionManager
import hep.dataforge.vision.gdml.gdml
import hep.dataforge.vision.html.Page
import hep.dataforge.vision.html.embedVisionFragment
import hep.dataforge.vision.html.fragment
import hep.dataforge.vision.html.scriptHeader
import hep.dataforge.vision.plotly.PlotlyPlugin
import hep.dataforge.vision.plotly.VisionOfPlotly
import hep.dataforge.vision.solid.SolidManager
import hep.dataforge.vision.solid.solid
import hep.dataforge.vision.visionManager
import kotlinx.html.div
import kotlinx.html.stream.createHTML
import kscience.plotly.Plot
import kscience.plotly.PlotlyFragment
import org.jetbrains.kotlinx.jupyter.api.HTML
import org.jetbrains.kotlinx.jupyter.api.Notebook
import org.jetbrains.kotlinx.jupyter.api.annotations.JupyterLibrary
import org.jetbrains.kotlinx.jupyter.api.libraries.*
import space.kscience.gdml.Gdml
@JupyterLibrary
internal class VisionForgePlayGroundForJupyter : JupyterIntegration() {
private val context = Context("Playground") {
plugin(SolidManager)
plugin(PlotlyPlugin)
}
val jsBundle = ResourceFallbacksBundle(listOf(ResourceLocation("js/visionforge-playground.js",
ResourcePathType.CLASSPATH_PATH)))
val jsResource = LibraryResource(name = "VisionForge", type = ResourceType.JS, bundles = listOf(jsBundle))
override fun Builder.onLoaded(notebook: Notebook?) {
resource(jsResource)
import("space.kscience.gdml.*", "kscience.plotly.*", "kscience.plotly.models.*")
onLoaded {
val header = scriptHeader("js/visionforge-playground.js", null, hep.dataforge.vision.html.ResourceLocation.EMBED)
display(HTML(createHTML().apply(header).finalize()))
}
render<Gdml> { gdmlModel ->
val fragment = VisionManager.fragment {
vision {
solid {
gdml(gdmlModel)
}
}
}
val html = createHTML().div {
embedVisionFragment(context.visionManager, fragment = fragment)
}
HTML(html)
}
render<Plot> { plot ->
val fragment = VisionManager.fragment {
vision {
VisionOfPlotly(plot.config)
}
}
val html = createHTML().div {
embedVisionFragment(context.visionManager, fragment = fragment)
}
HTML(html)
}
render<kscience.plotly.HtmlFragment> { fragment ->
HTML(createHTML().apply(fragment.visit).finalize())
}
render<Page> { page ->
HTML(page.render(createHTML()), true)
}
}
}

View File

@ -1,7 +1,7 @@
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation.Companion.MAIN_COMPILATION_NAME
plugins {
id("ru.mipt.npm.mpp")
id("ru.mipt.npm.gradle.mpp")
application
}
@ -57,7 +57,7 @@ kotlin {
}
application {
mainClass.set("ru.mipt.npm.muon.monitor.server.MMServerKt")
mainClass.set("ru.mipt.npm.gradle.muon.monitor.server.MMServerKt")
}
distributions {

View File

@ -46,22 +46,22 @@ kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation(project(":visionforge-solid"))
implementation(project(":visionforge-gdml"))
implementation(project(":visionforge-plotly"))
api(project(":visionforge-solid"))
api(project(":visionforge-gdml"))
api(project(":visionforge-plotly"))
}
}
val jsMain by getting{
dependencies {
implementation(project(":ui:bootstrap"))
implementation(project(":visionforge-threejs"))
api(project(":ui:bootstrap"))
api(project(":visionforge-threejs"))
}
}
val jvmMain by getting{
dependencies {
implementation(project(":visionforge-server"))
api(project(":visionforge-server"))
implementation("com.github.Ricky12Awesome:json-schema-serialization:0.6.6")
}
}

View File

@ -6,8 +6,6 @@ import hep.dataforge.vision.VisionManager
import hep.dataforge.vision.html.fragment
import hep.dataforge.vision.plotly.plotly
import hep.dataforge.vision.plotly.withPlotly
import kotlinx.html.hr
import kotlinx.html.p
import kscience.plotly.scatter
@DFExperimental

View File

@ -4,9 +4,9 @@ import hep.dataforge.context.Context
import hep.dataforge.misc.DFExperimental
import hep.dataforge.vision.html.HtmlVisionFragment
import hep.dataforge.vision.html.ResourceLocation
import hep.dataforge.vision.html.page
import hep.dataforge.vision.html.scriptHeader
import hep.dataforge.vision.makeFile
import hep.dataforge.vision.page
import hep.dataforge.vision.three.server.VisionServer
import hep.dataforge.vision.three.server.useScript
import java.awt.Desktop

View File

@ -1,5 +1,5 @@
plugins {
id("ru.mipt.npm.jvm")
id("ru.mipt.npm.gradle.jvm")
application
}
@ -18,5 +18,5 @@ dependencies{
}
application {
mainClass.set("ru.mipt.npm.sat.SatServerKt")
mainClass.set("ru.mipt.npm.gradle.sat.SatServerKt")
}

View File

@ -2,7 +2,7 @@ import ru.mipt.npm.gradle.DependencyConfiguration
import ru.mipt.npm.gradle.FXModule
plugins {
id("ru.mipt.npm.mpp")
id("ru.mipt.npm.gradle.mpp")
application
}

View File

@ -4,7 +4,10 @@ import hep.dataforge.meta.*
import hep.dataforge.names.plus
import hep.dataforge.names.startsWith
import hep.dataforge.values.asValue
import hep.dataforge.vision.getProperty
import hep.dataforge.vision.onPropertyChange
import hep.dataforge.vision.set
import hep.dataforge.vision.setProperty
import hep.dataforge.vision.solid.*
import hep.dataforge.vision.solid.Solid.Companion.GEOMETRY_KEY
import hep.dataforge.vision.solid.three.*

View File

@ -14,4 +14,6 @@ The actual layering scheme is more complicated. All objects support styling. The
### Intermediate representation
An important thing about VisionForge is that it does not strictly bound to a single format representation.
### Kotlin DSL for creating vision-graphs

View File

@ -74,4 +74,4 @@ Not all GDML solids are currently supported by the converter, they could be adde
VisionForge is not tied to any single renderer. Right now the primary target is the Browser rendering with [Three.js library](https://threejs.org/). The Three.js supports different renderers including WebGL with hardware support and virtual reality.
The bindings for three-js was implemented in kotlin-js based on a [work by Lars Ivar Hatledal](https://github.com/markaren/three-kt-wrapper). The wrapper allows seamless integration with a lot of different library APIs incliding custom cameras and CSG.
The bindings for three-js was implemented in kotlin-js based on a [work by Lars Ivar Hatledal](https://github.com/markaren/three-kt-wrapper). The wrapper allows seamless integration with a lot of different library APIs including custom cameras and CSG.

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@ -1,25 +1,23 @@
pluginManagement {
val kotlinVersion = "1.4.30"
val toolsVersion = "0.7.6"
val toolsVersion = "0.8.3"
repositories {
mavenLocal()
maven("https://repo.kotlin.link")
mavenCentral()
jcenter()
gradlePluginPortal()
maven("https://dl.bintray.com/kotlin/kotlin-eap")
maven("https://dl.bintray.com/kotlin/kotlinx")
maven("https://dl.bintray.com/mipt-npm/dataforge")
maven("https://dl.bintray.com/mipt-npm/kscience")
maven("https://dl.bintray.com/mipt-npm/dev")
}
plugins {
id("ru.mipt.npm.project") version toolsVersion
id("ru.mipt.npm.mpp") version toolsVersion
id("ru.mipt.npm.jvm") version toolsVersion
id("ru.mipt.npm.js") version toolsVersion
id("ru.mipt.npm.publish") version toolsVersion
id("ru.mipt.npm.gradle.project") version toolsVersion
id("ru.mipt.npm.gradle.mpp") version toolsVersion
id("ru.mipt.npm.gradle.jvm") version toolsVersion
id("ru.mipt.npm.gradle.js") version toolsVersion
id("ru.mipt.npm.gradle.publish") version toolsVersion
kotlin("jvm") version kotlinVersion
kotlin("jupyter.api") version "0.8.3.218"
kotlin("js") version kotlinVersion
kotlin("multiplatform") version kotlinVersion
}
@ -45,8 +43,9 @@ include(
":visionforge-server",
":visionforge-plotly",
":demo:solid-showcase",
// ":demo:gdml",
":demo:gdml",
":demo:muon-monitor",
":demo:sat-demo"
// ":playground"
":demo:sat-demo",
":demo:playground",
":demo:jupyter-playground"
)

View File

@ -1,5 +1,5 @@
plugins {
id("ru.mipt.npm.js")
id("ru.mipt.npm.gradle.js")
}
val dataforgeVersion: String by rootProject.extra

View File

@ -1,5 +1,5 @@
plugins {
id("ru.mipt.npm.js")
id("ru.mipt.npm.gradle.js")
}
val dataforgeVersion: String by rootProject.extra

View File

@ -1,13 +1,13 @@
plugins {
id("ru.mipt.npm.js")
id("ru.mipt.npm.gradle.js")
}
val reactVersion by extra("17.0.0")
val reactVersion by extra("17.0.1")
val kotlinWrappersVersion: String by rootProject.extra
dependencies{
api(project(":visionforge-solid"))
api("org.jetbrains:kotlin-styled:5.2.0-$kotlinWrappersVersion")
api("org.jetbrains:kotlin-styled:5.2.1-$kotlinWrappersVersion")
api("org.jetbrains:kotlin-react-dom:$reactVersion-$kotlinWrappersVersion")
implementation(project(":visionforge-threejs"))
}

View File

@ -1,5 +1,5 @@
plugins {
id("ru.mipt.npm.js")
id("ru.mipt.npm.gradle.js")
}
val dataforgeVersion: String by rootProject.extra

View File

@ -1,5 +1,5 @@
plugins {
id("ru.mipt.npm.mpp")
id("ru.mipt.npm.gradle.mpp")
}
val dataforgeVersion: String by rootProject.extra

View File

@ -1,8 +1,10 @@
package hep.dataforge.vision.html
import hep.dataforge.context.Context
import hep.dataforge.misc.DFExperimental
import hep.dataforge.vision.visionManager
import kotlinx.html.*
import kotlinx.html.stream.createHTML
public data class Page(
public val context: Context,
@ -24,4 +26,12 @@ public data class Page(
embedVisionFragment(context.visionManager, fragment = content)
}
}.finalize()
}
}
@DFExperimental
public fun Context.page(
title: String,
content: HtmlVisionFragment,
vararg headers: Pair<String, HtmlFragment>,
): Page = Page(this, title, mapOf(*headers), content)

View File

@ -56,25 +56,17 @@ import java.nio.file.Path
// }
//}
@DFExperimental
public fun Context.page(
title: String,
content: HtmlVisionFragment,
vararg headers: Pair<String, HtmlFragment>,
): Page = Page(this, title, mapOf(*headers), content)
@DFExperimental
public fun Page.makeFile(
path: Path?,
defaultHeaders: ((Path) -> Map<String,HtmlFragment>)? = null,
defaultHeaders: ((Path) -> Map<String, HtmlFragment>)? = null,
): Path {
val actualFile = path?.let {
Path.of(System.getProperty("user.home")).resolve(path)
} ?: Files.createTempFile("tempPlot", ".html")
val actualDefaultHeaders = defaultHeaders?.invoke(actualFile)
val actualPage = if(actualDefaultHeaders == null) this else copy(headers = actualDefaultHeaders + headers)
val actualPage = if (actualDefaultHeaders == null) this else copy(headers = actualDefaultHeaders + headers)
val htmlString = actualPage.render(createHTML())

View File

@ -1,5 +1,5 @@
plugins {
id("ru.mipt.npm.jvm")
id("ru.mipt.npm.gradle.jvm")
}
val dataforgeVersion: String by rootProject.extra

View File

@ -1,5 +1,5 @@
plugins {
id("ru.mipt.npm.mpp")
id("ru.mipt.npm.gradle.mpp")
}
kotlin {
@ -7,7 +7,7 @@ kotlin {
val commonMain by getting {
dependencies {
api(project(":visionforge-solid"))
api("kscience.gdml:gdml:0.2.0")
api("space.kscience:gdml:0.2.0")
}
}
}

View File

@ -12,7 +12,7 @@ import hep.dataforge.vision.solid.*
import hep.dataforge.vision.solid.SolidMaterial.Companion.MATERIAL_COLOR_KEY
import hep.dataforge.vision.styleSheet
import hep.dataforge.vision.useStyle
import kscience.gdml.*
import space.kscience.gdml.*
import kotlin.math.cos
import kotlin.math.sin
import kotlin.random.Random
@ -26,7 +26,7 @@ private inline operator fun Number.times(d: Double) = toDouble() * d
@Suppress("NOTHING_TO_INLINE")
private inline operator fun Number.times(f: Float) = toFloat() * f
public class GDMLTransformerSettings {
public class GdmlTransformerSettings {
public enum class Action {
ADD,
REJECT,
@ -36,12 +36,12 @@ public class GDMLTransformerSettings {
public var lUnit: LUnit = LUnit.CM
public var aUnit: AUnit = AUnit.RADIAN
public var solidAction: (GDMLSolid) -> Action = { Action.PROTOTYPE }
public var volumeAction: (GDMLGroup) -> Action = { Action.PROTOTYPE }
public var solidAction: (GdmlSolid) -> Action = { Action.PROTOTYPE }
public var volumeAction: (GdmlGroup) -> Action = { Action.PROTOTYPE }
}
private class GDMLTransformer(val settings: GDMLTransformerSettings) {
//private val materialCache = HashMap<GDMLMaterial, Meta>()
private class GdmlTransformer(val settings: GdmlTransformerSettings) {
//private val materialCache = HashMap<GdmlMaterial, Meta>()
private val random = Random(222)
/**
@ -56,7 +56,7 @@ private class GDMLTransformer(val settings: GDMLTransformerSettings) {
private val referenceStore = HashMap<Name, MutableList<SolidReferenceGroup>>()
private fun proxySolid(root: GDML, group: SolidGroup, solid: GDMLSolid, name: String): SolidReferenceGroup {
private fun proxySolid(root: Gdml, group: SolidGroup, solid: GdmlSolid, name: String): SolidReferenceGroup {
val templateName = solidsName + name
if (proto[templateName] == null) {
solids.addSolid(root, solid, name)
@ -66,7 +66,7 @@ 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)
@ -78,7 +78,7 @@ private class GDMLTransformer(val settings: GDMLTransformerSettings) {
private val styleCache = HashMap<Name, Meta>()
var solidConfiguration: Solid.(parent: GDMLVolume, solid: GDMLSolid) -> Unit = { parent, _ ->
var solidConfiguration: Solid.(parent: GdmlVolume, solid: GdmlSolid) -> Unit = { parent, _ ->
if (parent.physVolumes.isNotEmpty()) {
useStyle("opaque") {
SolidMaterial.MATERIAL_OPACITY_KEY put 0.3
@ -94,23 +94,23 @@ private class GDMLTransformer(val settings: GDMLTransformerSettings) {
useStyle(name)
}
fun configureSolid(root: GDML, obj: Solid, parent: GDMLVolume, solid: GDMLSolid) {
val material = parent.materialref.resolve(root) ?: GDMLElement(parent.materialref.ref)
fun configureSolid(root: Gdml, obj: Solid, parent: GdmlVolume, solid: GdmlSolid) {
val material = parent.materialref.resolve(root) ?: GdmlElement(parent.materialref.ref)
val styleName = "materials.${material.name}"
obj.useStyle(styleName) {
MATERIAL_COLOR_KEY put random.nextInt(16777216)
"gdml.material" put material.name
"Gdml.material" put material.name
}
obj.solidConfiguration(parent, solid)
}
fun <T : Solid> T.withPosition(
newPos: GDMLPosition? = null,
newRotation: GDMLRotation? = null,
newScale: GDMLScale? = null,
newPos: GdmlPosition? = null,
newRotation: GdmlRotation? = null,
newScale: GdmlScale? = null,
): T = apply {
newPos?.let {
val point = Point3D(it.x(settings.lUnit), it.y(settings.lUnit), it.z(settings.lUnit))
@ -134,23 +134,23 @@ private class GDMLTransformer(val settings: GDMLTransformerSettings) {
//TODO convert units if needed
}
fun <T : Solid> T.withPosition(root: GDML, physVolume: GDMLPhysVolume): T = withPosition(
fun <T : Solid> T.withPosition(root: Gdml, physVolume: GdmlPhysVolume): T = withPosition(
physVolume.resolvePosition(root),
physVolume.resolveRotation(root),
physVolume.resolveScale(root)
)
fun SolidGroup.addSolid(
root: GDML,
solid: GDMLSolid,
root: Gdml,
solid: GdmlSolid,
name: String = "",
): Solid {
//context.solidAdded(solid)
val lScale = solid.lscale(settings.lUnit)
val aScale = solid.ascale()
return when (solid) {
is GDMLBox -> box(solid.x * lScale, solid.y * lScale, solid.z * lScale, name)
is GDMLTube -> tube(
is GdmlBox -> box(solid.x * lScale, solid.y * lScale, solid.z * lScale, name)
is GdmlTube -> tube(
solid.rmax * lScale,
solid.z * lScale,
solid.rmin * lScale,
@ -158,13 +158,13 @@ private class GDMLTransformer(val settings: GDMLTransformerSettings) {
solid.deltaphi * aScale,
name
)
is GDMLCone -> cone(solid.rmax1, solid.z, solid.rmax2, name = name) {
is GdmlCone -> cone(solid.rmax1, solid.z, solid.rmax2, name = name) {
require(solid.rmin1 == 0.0) { "Empty cones are not supported" }
require(solid.rmin2 == 0.0) { "Empty cones are not supported" }
startAngle = solid.startphi.toFloat()
angle = solid.deltaphi.toFloat()
}
is GDMLXtru -> extrude(name) {
is GdmlXtru -> extrude(name) {
shape {
solid.vertices.forEach {
point(it.x * lScale, it.y * lScale)
@ -179,9 +179,9 @@ private class GDMLTransformer(val settings: GDMLTransformerSettings) {
)
}
}
is GDMLScaledSolid -> {
is GdmlScaledSolid -> {
//Add solid with modified scale
val innerSolid: GDMLSolid = solid.solidref.resolve(root)
val innerSolid: GdmlSolid = solid.solidref.resolve(root)
?: error("Solid with tag ${solid.solidref.ref} for scaled solid ${solid.name} not defined")
addSolid(root, innerSolid, name).apply {
@ -190,12 +190,12 @@ private class GDMLTransformer(val settings: GDMLTransformerSettings) {
scaleZ = solid.scale.z.toFloat()
}
}
is GDMLSphere -> sphere(solid.rmax * lScale, solid.deltaphi * aScale, solid.deltatheta * aScale, name) {
is GdmlSphere -> sphere(solid.rmax * lScale, solid.deltaphi * aScale, solid.deltatheta * aScale, name) {
phiStart = solid.startphi * aScale
thetaStart = solid.starttheta * aScale
}
is GDMLOrb -> sphere(solid.r * lScale, name = name)
is GDMLPolyhedra -> extrude(name) {
is GdmlOrb -> sphere(solid.r * lScale, name = name)
is GdmlPolyhedra -> extrude(name) {
//getting the radius of first
require(solid.planes.size > 1) { "The polyhedron geometry requires at least two planes" }
val baseRadius = solid.planes.first().rmax * lScale
@ -210,13 +210,13 @@ private class GDMLTransformer(val settings: GDMLTransformerSettings) {
layer(plane.z * lScale, scale = plane.rmax * lScale / baseRadius)
}
}
is GDMLBoolSolid -> {
val first: GDMLSolid = solid.first.resolve(root) ?: error("")
val second: GDMLSolid = solid.second.resolve(root) ?: error("")
is GdmlBoolSolid -> {
val first: GdmlSolid = solid.first.resolve(root) ?: error("")
val second: GdmlSolid = solid.second.resolve(root) ?: error("")
val type: CompositeType = when (solid) {
is GDMLUnion -> CompositeType.UNION
is GDMLSubtraction -> CompositeType.SUBTRACT
is GDMLIntersection -> CompositeType.INTERSECT
is GdmlUnion -> CompositeType.UNION
is GdmlSubtraction -> CompositeType.SUBTRACT
is GdmlIntersection -> CompositeType.INTERSECT
}
return composite(type, name) {
@ -234,30 +234,30 @@ private class GDMLTransformer(val settings: GDMLTransformerSettings) {
}
}
is GDMLEllipsoid -> TODO("Renderer for $solid not supported yet")
is GDMLElTube -> TODO("Renderer for $solid not supported yet")
is GDMLElCone -> TODO("Renderer for $solid not supported yet")
is GDMLParaboloid -> TODO("Renderer for $solid not supported yet")
is GDMLParallelepiped -> TODO("Renderer for $solid not supported yet")
is GDMLTorus -> TODO("Renderer for $solid not supported yet")
is GDMLTrapezoid -> TODO("Renderer for $solid not supported yet")
is GDMLPolycone -> TODO("Renderer for $solid not supported yet")
is GdmlEllipsoid -> TODO("Renderer for $solid not supported yet")
is GdmlElTube -> TODO("Renderer for $solid not supported yet")
is GdmlElCone -> TODO("Renderer for $solid not supported yet")
is GdmlParaboloid -> TODO("Renderer for $solid not supported yet")
is GdmlParallelepiped -> TODO("Renderer for $solid not supported yet")
is GdmlTorus -> TODO("Renderer for $solid not supported yet")
is GdmlTrapezoid -> TODO("Renderer for $solid not supported yet")
is GdmlPolycone -> TODO("Renderer for $solid not supported yet")
}
}
fun SolidGroup.addSolidWithCaching(
root: GDML,
solid: GDMLSolid,
root: Gdml,
solid: GdmlSolid,
name: String = solid.name,
): Solid? {
return when (settings.solidAction(solid)) {
GDMLTransformerSettings.Action.ADD -> {
GdmlTransformerSettings.Action.ADD -> {
addSolid(root, solid, name)
}
GDMLTransformerSettings.Action.PROTOTYPE -> {
GdmlTransformerSettings.Action.PROTOTYPE -> {
proxySolid(root, this, solid, name)
}
GDMLTransformerSettings.Action.REJECT -> {
GdmlTransformerSettings.Action.REJECT -> {
//ignore
null
}
@ -265,14 +265,14 @@ private class GDMLTransformer(val settings: GDMLTransformerSettings) {
}
fun SolidGroup.addPhysicalVolume(
root: GDML,
physVolume: GDMLPhysVolume,
root: Gdml,
physVolume: GdmlPhysVolume,
) {
val volume: GDMLGroup = physVolume.volumeref.resolve(root)
val volume: GdmlGroup = physVolume.volumeref.resolve(root)
?: error("Volume with ref ${physVolume.volumeref.ref} could not be resolved")
// a special case for single solid volume
if (volume is GDMLVolume && volume.physVolumes.isEmpty() && volume.placement == null) {
if (volume is GdmlVolume && volume.physVolumes.isEmpty() && volume.placement == null) {
val solid = volume.solidref.resolve(root)
?: error("Solid with tag ${volume.solidref.ref} for volume ${volume.name} not defined")
addSolidWithCaching(root, solid, physVolume.name ?: "")?.apply {
@ -283,24 +283,24 @@ private class GDMLTransformer(val settings: GDMLTransformerSettings) {
}
when (settings.volumeAction(volume)) {
GDMLTransformerSettings.Action.ADD -> {
GdmlTransformerSettings.Action.ADD -> {
val group: SolidGroup = volume(root, volume)
this[physVolume.name ?: ""] = group.withPosition(root, physVolume)
}
GDMLTransformerSettings.Action.PROTOTYPE -> {
GdmlTransformerSettings.Action.PROTOTYPE -> {
proxyVolume(root, this, physVolume, volume)
}
GDMLTransformerSettings.Action.REJECT -> {
GdmlTransformerSettings.Action.REJECT -> {
//ignore
}
}
}
fun SolidGroup.addDivisionVolume(
root: GDML,
divisionVolume: GDMLDivisionVolume,
root: Gdml,
divisionVolume: GdmlDivisionVolume,
) {
val volume: GDMLGroup = divisionVolume.volumeref.resolve(root)
val volume: GdmlGroup = divisionVolume.volumeref.resolve(root)
?: error("Volume with ref ${divisionVolume.volumeref.ref} could not be resolved")
//TODO add divisions
@ -308,20 +308,20 @@ private class GDMLTransformer(val settings: GDMLTransformerSettings) {
}
private fun volume(
root: GDML,
group: GDMLGroup,
root: Gdml,
group: GdmlGroup,
): SolidGroup = SolidGroup().apply {
if (group is GDMLVolume) {
val solid: GDMLSolid = group.solidref.resolve(root)
if (group is GdmlVolume) {
val solid: GdmlSolid = group.solidref.resolve(root)
?: error("Solid with tag ${group.solidref.ref} for volume ${group.name} not defined")
addSolidWithCaching(root, solid)?.apply {
configureSolid(root, this, group, solid)
}
when (val vol: GDMLPlacement? = group.placement) {
is GDMLPhysVolume -> addPhysicalVolume(root, vol)
is GDMLDivisionVolume -> addDivisionVolume(root, vol)
when (val vol: GdmlPlacement? = group.placement) {
is GdmlPhysVolume -> addPhysicalVolume(root, vol)
is GdmlDivisionVolume -> addDivisionVolume(root, vol)
}
}
@ -332,7 +332,7 @@ private class GDMLTransformer(val settings: GDMLTransformerSettings) {
private fun finalize(final: SolidGroup): SolidGroup {
//final.prototypes = proto
final.useStyle("GDML") {
final.useStyle("Gdml") {
Solid.ROTATION_ORDER_KEY put RotationOrder.ZXY
}
@ -364,19 +364,19 @@ private class GDMLTransformer(val settings: GDMLTransformerSettings) {
return final
}
fun transform(root: GDML): SolidGroup = finalize(volume(root, root.world))
fun transform(root: Gdml): SolidGroup = finalize(volume(root, root.world))
}
public fun GDML.toVision(block: GDMLTransformerSettings.() -> Unit = {}): SolidGroup {
val context = GDMLTransformer(GDMLTransformerSettings().apply(block))
public fun Gdml.toVision(block: GdmlTransformerSettings.() -> Unit = {}): SolidGroup {
val context = GdmlTransformer(GdmlTransformerSettings().apply(block))
return context.transform(this)
}
/**
* Append gdml node to the group
* Append Gdml node to the group
*/
public fun SolidGroup.gdml(gdml: GDML, key: String = "", transformer: GDMLTransformerSettings.() -> Unit = {}) {
public fun SolidGroup.gdml(gdml: Gdml, key: String = "", transformer: GdmlTransformerSettings.() -> Unit = {}) {
val visual = gdml.toVision(transformer)
//println(Visual3DPlugin.json.stringify(VisualGroup3D.serializer(), visual))
set(key, visual)

View File

@ -1,20 +1,20 @@
package hep.dataforge.vision.gdml
import hep.dataforge.vision.solid.SolidGroup
import kscience.gdml.GDML
import nl.adaptivity.xmlutil.StAXReader
import space.kscience.gdml.Gdml
import java.nio.file.Files
import java.nio.file.Path
import java.util.concurrent.atomic.AtomicInteger
public actual typealias Counter = AtomicInteger
public fun GDML.Companion.readFile(file: Path): GDML {
public fun Gdml.Companion.readFile(file: Path): Gdml {
val xmlReader = StAXReader(Files.newInputStream(file), "UTF-8")
return format.parse(GDML.serializer(), xmlReader)
return format.parse(Gdml.serializer(), xmlReader)
}
public fun SolidGroup.gdml(file: Path, key: String = "", transformer: GDMLTransformerSettings.() -> Unit = {}) {
val gdml = GDML.readFile(file)
public fun SolidGroup.gdml(file: Path, key: String = "", transformer: GdmlTransformerSettings.() -> Unit = {}) {
val gdml = Gdml.readFile(file)
gdml(gdml, key, transformer)
}

View File

@ -1,7 +1,7 @@
package hep.dataforge.vision.gdml
import hep.dataforge.vision.solid.SolidManager
import kscience.gdml.GDML
import space.kscience.gdml.Gdml
import nl.adaptivity.xmlutil.StAXReader
import org.junit.jupiter.api.Test
@ -11,7 +11,7 @@ class TestConvertor {
fun testBMNGeometry() {
val stream = javaClass.getResourceAsStream("/gdml/BM@N.gdml")
val xmlReader = StAXReader(stream, "UTF-8")
val xml = GDML.format.parse(GDML.serializer(), xmlReader)
val xml = Gdml.format.parse(Gdml.serializer(), xmlReader)
val vision = xml.toVision()
println(SolidManager.encodeToString(vision))
}
@ -21,7 +21,7 @@ class TestConvertor {
val stream = javaClass.getResourceAsStream("/gdml/cubes.gdml")
val xmlReader = StAXReader(stream, "UTF-8")
val xml = GDML.format.parse(GDML.serializer(), xmlReader)
val xml = Gdml.format.parse(Gdml.serializer(), xmlReader)
val visual = xml.toVision()
// println(visual)
}
@ -31,7 +31,7 @@ class TestConvertor {
val stream = javaClass.getResourceAsStream("/gdml/simple1.gdml")
val xmlReader = StAXReader(stream, "UTF-8")
val xml = GDML.format.parse(GDML.serializer(), xmlReader)
val xml = Gdml.format.parse(Gdml.serializer(), xmlReader)
val vision = xml.toVision()
println(SolidManager.encodeToString(vision))
}

View File

@ -5,7 +5,7 @@ import hep.dataforge.vision.visitor.countDistinct
import hep.dataforge.vision.visitor.flowStatistics
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import kscience.gdml.GDML
import space.kscience.gdml.Gdml
import nl.adaptivity.xmlutil.StAXReader
import java.io.File
import kotlin.reflect.KClass
@ -17,7 +17,7 @@ suspend fun main() {
File("D:\\Work\\Projects\\dataforge-vis\\visionforge-gdml\\src\\jvmTest\\resources\\gdml\\BM@N.gdml").inputStream()
val xmlReader = StAXReader(stream, "UTF-8")
val xml = GDML.format.parse(GDML.serializer(), xmlReader)
val xml = Gdml.format.parse(Gdml.serializer(), xmlReader)
val vision = xml.toVision()

View File

@ -1,5 +1,5 @@
plugins {
id("ru.mipt.npm.mpp")
id("ru.mipt.npm.gradle.mpp")
}
val plotlyVersion = "0.3.1"

View File

@ -1,7 +1,5 @@
//import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation.Companion.MAIN_COMPILATION_NAME
plugins {
id("ru.mipt.npm.jvm")
id("ru.mipt.npm.gradle.jvm")
}
val ktorVersion: String by rootProject.extra

View File

@ -1,5 +1,5 @@
plugins {
id("ru.mipt.npm.mpp")
id("ru.mipt.npm.gradle.mpp")
}
kscience{
@ -7,7 +7,6 @@ kscience{
}
kotlin {
sourceSets {
commonMain {
dependencies {

View File

@ -1,5 +1,5 @@
plugins {
id("ru.mipt.npm.js")
id("ru.mipt.npm.gradle.js")
}
kotlin{

View File

@ -1,5 +1,5 @@
plugins {
id("ru.mipt.npm.mpp")
id("ru.mipt.npm.gradle.mpp")
}
val ktorVersion: String by rootProject.extra

View File

@ -4,9 +4,9 @@ import hep.dataforge.context.Context
import hep.dataforge.misc.DFExperimental
import hep.dataforge.vision.html.HtmlVisionFragment
import hep.dataforge.vision.html.ResourceLocation
import hep.dataforge.vision.html.page
import hep.dataforge.vision.html.scriptHeader
import hep.dataforge.vision.makeFile
import hep.dataforge.vision.page
import java.awt.Desktop
import java.nio.file.Path