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" group = "hep.dataforge"
version = "0.2.0-dev-5" version = "0.2.0-dev-6"
} }
val githubProject by extra("visionforge") 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.misc.DFExperimental
import hep.dataforge.vision.Vision import hep.dataforge.vision.Vision
import hep.dataforge.vision.VisionManager import hep.dataforge.vision.VisionManager
import hep.dataforge.vision.gdml.readFile
import hep.dataforge.vision.gdml.toVision import hep.dataforge.vision.gdml.toVision
import space.kscience.gdml.Gdml import space.kscience.gdml.Gdml
import space.kscience.gdml.decodeFromFile
import java.io.File import java.io.File
import java.util.zip.GZIPInputStream import java.util.zip.GZIPInputStream
import java.util.zip.ZipInputStream import java.util.zip.ZipInputStream
@ -13,20 +13,7 @@ import java.util.zip.ZipInputStream
@OptIn(DFExperimental::class) @OptIn(DFExperimental::class)
fun VisionManager.readFile(file: File): Vision = when { fun VisionManager.readFile(file: File): Vision = when {
file.extension == "gdml" || file.extension == "xml" -> { file.extension == "gdml" || file.extension == "xml" -> {
Gdml.readFile(file.toPath()).toVision { Gdml.decodeFromFile(file.toPath(),true).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
// }
// }
// }
}
} }
file.extension == "json" -> decodeFromString(file.readText()) file.extension == "json" -> decodeFromString(file.readText())
file.name.endsWith("json.zip") -> { file.name.endsWith("json.zip") -> {

View File

@ -1,21 +1,21 @@
package hep.dataforge.vision.gdml.demo package hep.dataforge.vision.gdml.demo
import hep.dataforge.vision.gdml.readFile
import hep.dataforge.vision.gdml.toVision import hep.dataforge.vision.gdml.toVision
import hep.dataforge.vision.solid.Solids import hep.dataforge.vision.solid.Solids
import space.kscience.gdml.Gdml import space.kscience.gdml.Gdml
import space.kscience.gdml.LUnit import space.kscience.gdml.LUnit
import space.kscience.gdml.decodeFromFile
import java.io.File import java.io.File
import java.nio.file.Paths import java.nio.file.Paths
fun main(args: Array<String>) { fun main(args: Array<String>) {
require(args.isNotEmpty()){"At least one argument is required"} require(args.isNotEmpty()) { "At least one argument is required" }
val inputFileName = args[0] val inputFileName = args[0]
require(inputFileName.endsWith(".gdml")){"GDML required"} require(inputFileName.endsWith(".gdml")) { "GDML required" }
val outputFileName = args.getOrNull(1)?:inputFileName.replace(".gdml",".json") 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")) //GDML.readFile(Paths.get("D:\\Work\\Projects\\visionforge\\visionforge-spatial-gdml\\src\\jvmTest\\resources\\gdml\\simple1.gdml"))
val vision = gdml.toVision { val vision = gdml.toVision {
lUnit = LUnit.CM lUnit = LUnit.CM

View File

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

View File

@ -26,7 +26,7 @@ public fun VisionForge.makeVisionFile(
resourceLocation: ResourceLocation = ResourceLocation.SYSTEM, resourceLocation: ResourceLocation = ResourceLocation.SYSTEM,
show: Boolean = true, show: Boolean = true,
): Unit { ): 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)) mapOf("threeJs" to scriptHeader("js/visionforge-playground.js", actualPath, resourceLocation))
} }
if (show) Desktop.getDesktop().browse(actualPath.toFile().toURI()) if (show) Desktop.getDesktop().browse(actualPath.toFile().toURI())

View File

@ -5,7 +5,7 @@ import hep.dataforge.vision.VisionForge
import kotlinx.html.FlowContent import kotlinx.html.FlowContent
import kotlinx.html.TagConsumer import kotlinx.html.TagConsumer
public typealias HtmlFragment = TagConsumer<*>.()->Unit public typealias HtmlFragment = TagConsumer<*>.() -> Unit
public fun TagConsumer<*>.fragment(fragment: HtmlFragment) { public fun TagConsumer<*>.fragment(fragment: HtmlFragment) {
fragment() fragment()

View File

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

View File

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

View File

@ -34,4 +34,12 @@ class TestConvertor {
val vision = gdml.toVision() val vision = gdml.toVision()
//println(SolidManager.encodeToString(vision)) //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, resourceLocation: ResourceLocation = ResourceLocation.SYSTEM,
show: Boolean = true, show: Boolean = true,
): Unit { ): 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)) mapOf("threeJs" to scriptHeader("js/visionforge-three.js", actualPath, resourceLocation))
} }
if (show) Desktop.getDesktop().browse(actualPath.toFile().toURI()) if (show) Desktop.getDesktop().browse(actualPath.toFile().toURI())