This commit is contained in:
Alexander Nozik 2021-03-02 16:33:29 +03:00
parent 30e6370204
commit 545753b14b
11 changed files with 1098 additions and 37 deletions

View File

@ -22,7 +22,7 @@ allprojects {
}
group = "hep.dataforge"
version = "0.2.0-dev-5"
version = "0.2.0-dev-6"
}
val githubProject by extra("visionforge")

View File

@ -3,9 +3,9 @@ package hep.dataforge.vision.gdml.demo
import hep.dataforge.misc.DFExperimental
import hep.dataforge.vision.Vision
import hep.dataforge.vision.VisionManager
import hep.dataforge.vision.gdml.readFile
import hep.dataforge.vision.gdml.toVision
import space.kscience.gdml.Gdml
import space.kscience.gdml.decodeFromFile
import java.io.File
import java.util.zip.GZIPInputStream
import java.util.zip.ZipInputStream
@ -13,20 +13,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 {
// lUnit = LUnit.CM
//
// solidConfiguration = { parent, solid ->
// if (solid.name == "cave") {
// setItem(SolidMaterial.MATERIAL_WIREFRAME_KEY, true.asValue())
// }
// if (parent.physVolumes.isNotEmpty()) {
// useStyle("opaque") {
// SolidMaterial.MATERIAL_OPACITY_KEY put 0.3
// }
// }
// }
}
Gdml.decodeFromFile(file.toPath(),true).toVision()
}
file.extension == "json" -> decodeFromString(file.readText())
file.name.endsWith("json.zip") -> {

View File

@ -1,10 +1,10 @@
package hep.dataforge.vision.gdml.demo
import hep.dataforge.vision.gdml.readFile
import hep.dataforge.vision.gdml.toVision
import hep.dataforge.vision.solid.Solids
import space.kscience.gdml.Gdml
import space.kscience.gdml.LUnit
import space.kscience.gdml.decodeFromFile
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.decodeFromFile(Paths.get(inputFileName), true)
//GDML.readFile(Paths.get("D:\\Work\\Projects\\visionforge\\visionforge-spatial-gdml\\src\\jvmTest\\resources\\gdml\\simple1.gdml"))
val vision = gdml.toVision {

View File

@ -60,7 +60,9 @@ internal class VisionForgePlayGroundForJupyter : JupyterIntegration() {
"kscience.plotly.*",
"kscience.plotly.models.*",
"kotlinx.html.*",
"hep.dataforge.vision.solid.*"
"hep.dataforge.vision.solid.*",
"hep.dataforge.vision.html.Page",
"hep.dataforge.vision.html.page"
)
import<VisionForge>()

View File

@ -26,7 +26,7 @@ public fun VisionForge.makeVisionFile(
resourceLocation: ResourceLocation = ResourceLocation.SYSTEM,
show: Boolean = true,
): Unit {
val actualPath = page(title, content).makeFile(path) { actualPath ->
val actualPath = page(title, content = content).makeFile(path) { actualPath ->
mapOf("threeJs" to scriptHeader("js/visionforge-playground.js", actualPath, resourceLocation))
}
if (show) Desktop.getDesktop().browse(actualPath.toFile().toURI())

View File

@ -32,7 +32,7 @@ public data class Page(
@DFExperimental
public fun VisionForge.page(
title: String,
content: HtmlVisionFragment,
title: String = "VisionForge page",
vararg headers: Pair<String, HtmlFragment>,
content: HtmlVisionFragment,
): Page = Page(context, title, mapOf(*headers), content)

View File

@ -1,20 +1,19 @@
package hep.dataforge.vision.gdml
import hep.dataforge.vision.solid.SolidGroup
import nl.adaptivity.xmlutil.StAXReader
import space.kscience.gdml.Gdml
import java.nio.file.Files
import space.kscience.gdml.decodeFromFile
import java.nio.file.Path
import java.util.concurrent.atomic.AtomicInteger
public actual typealias Counter = AtomicInteger
public fun Gdml.Companion.readFile(file: Path): Gdml {
val xmlReader = StAXReader(Files.newInputStream(file), "UTF-8")
return format.decodeFromReader(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 = "",
usePreprocessor: Boolean = false,
transformer: GdmlTransformerSettings.() -> Unit = {},
) {
val gdml = Gdml.decodeFromFile(file, usePreprocessor)
gdml(gdml, key, transformer)
}

View File

@ -34,4 +34,12 @@ class TestConvertor {
val vision = gdml.toVision()
//println(SolidManager.encodeToString(vision))
}
@Test
fun testIaxo() {
val stream = javaClass.getResourceAsStream("/gdml/babyIAXO.gdml")!!
val gdml = Gdml.decodeFromStream(stream, true)
val vision = gdml.toVision()
println(Solids.encodeToString(vision))
}
}

File diff suppressed because it is too large Load Diff

View File

@ -23,7 +23,7 @@ public fun VisionForge.makeThreeJsFile(
resourceLocation: ResourceLocation = ResourceLocation.SYSTEM,
show: Boolean = true,
): Unit {
val actualPath = page(title, content).makeFile(path) { actualPath ->
val actualPath = page(title, content = content).makeFile(path) { actualPath ->
mapOf("threeJs" to scriptHeader("js/visionforge-three.js", actualPath, resourceLocation))
}
if (show) Desktop.getDesktop().browse(actualPath.toFile().toURI())