From f8f6deda8640bf8e5c6cd675b1e2339153dccabc Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Wed, 3 Apr 2019 09:29:10 +0300 Subject: [PATCH] Minor specification fix, optional includebuild --- .../dataforge/vis/spatial/gdml/GDMLNodes.kt | 70 +++++++++++++++++-- .../vis/spatial/gdml/ThreeGDMLFactory.kt | 10 ++- settings.gradle.kts | 4 +- 3 files changed, 74 insertions(+), 10 deletions(-) diff --git a/dataforge-vis-spatial-js/src/main/kotlin/hep/dataforge/vis/spatial/gdml/GDMLNodes.kt b/dataforge-vis-spatial-js/src/main/kotlin/hep/dataforge/vis/spatial/gdml/GDMLNodes.kt index 2c72bb76..a2c6ef72 100644 --- a/dataforge-vis-spatial-js/src/main/kotlin/hep/dataforge/vis/spatial/gdml/GDMLNodes.kt +++ b/dataforge-vis-spatial-js/src/main/kotlin/hep/dataforge/vis/spatial/gdml/GDMLNodes.kt @@ -1,6 +1,8 @@ package hep.dataforge.vis.spatial.gdml import hep.dataforge.meta.* +import kotlin.properties.ReadWriteProperty +import kotlin.reflect.KProperty sealed class GDMLNode(override val config: Config) : Specification { var pName by string() @@ -13,6 +15,10 @@ class GDMLPosition(config: Config) : GDMLDefine(config) { var y by number(0f).float var z by number(0f).float var unit by string("cm") + + companion object : SpecificationCompanion { + override fun wrap(config: Config) = GDMLPosition(config) + } } class GDMLRotation(config: Config) : GDMLDefine(config) { @@ -20,10 +26,12 @@ class GDMLRotation(config: Config) : GDMLDefine(config) { var y by number(0f).float var z by number(0f).float var unit by string("deg") + + companion object : SpecificationCompanion { + override fun wrap(config: Config) = GDMLRotation(config) + } } - - sealed class GDMLSolid(config: Config) : GDMLNode(config) { abstract val type: String } @@ -93,14 +101,64 @@ class GDMLXtru(config: Config) : GDMLSolid(config) { } } -class GDMLUnion(config: Config) : GDMLSolid(config) { - override val type: String = "union" +internal class GDMLRefDelegate(val key: String?) : ReadWriteProperty { + override fun getValue(thisRef: GDMLNode, property: KProperty<*>): String? { + val realKey = key ?: property.name + return thisRef.config["$realKey.ref"].string + } - val first by node() - val second by node() + override fun setValue(thisRef: GDMLNode, property: KProperty<*>, value: String?) { + val realKey = key ?: property.name + if (value == null) { + thisRef.config.remove(realKey) + } else { + thisRef.config["$realKey.ref"] = value + } + } +} + +internal fun GDMLNode.ref(key: String? = null) = GDMLRefDelegate(key) + + +sealed class GDMLBoolSolid(config: Config) : GDMLSolid(config) { + var first by ref() + + var second by ref() + + var position by spec(GDMLPosition) + + var positionref by ref() + + var rotation by spec(GDMLRotation) + + var rotationref by ref() + + var firstposition by spec(GDMLPosition) + + var firstrotation by spec(GDMLRotation) +} + + +class GDMLUnion(config: Config) : GDMLBoolSolid(config) { + override val type: String = "union" companion object : SpecificationCompanion { override fun wrap(config: Config): GDMLUnion = GDMLUnion(config) } } +class GDMLSubtraction(config: Config) : GDMLBoolSolid(config) { + override val type: String = "subtraction" + + companion object : SpecificationCompanion { + override fun wrap(config: Config) = GDMLUnion(config) + } +} + +class GDMLIntersection(config: Config) : GDMLBoolSolid(config) { + override val type: String = "intersection" + + companion object : SpecificationCompanion { + override fun wrap(config: Config) = GDMLIntersection(config) + } +} \ No newline at end of file diff --git a/dataforge-vis-spatial-js/src/main/kotlin/hep/dataforge/vis/spatial/gdml/ThreeGDMLFactory.kt b/dataforge-vis-spatial-js/src/main/kotlin/hep/dataforge/vis/spatial/gdml/ThreeGDMLFactory.kt index 8f3b7daf..ccd72c78 100644 --- a/dataforge-vis-spatial-js/src/main/kotlin/hep/dataforge/vis/spatial/gdml/ThreeGDMLFactory.kt +++ b/dataforge-vis-spatial-js/src/main/kotlin/hep/dataforge/vis/spatial/gdml/ThreeGDMLFactory.kt @@ -37,20 +37,20 @@ object ThreeGDMLFactory : MeshThreeFactory(GDMLShape::class) { override fun buildGeometry(obj: GDMLShape): BufferGeometry { return when (obj.shape) { is GDMLBox -> createTubeBuffer( - obj.shape.config.toJsRoot(), + obj.shape.config.toJsRoot()?.toDynamic(), obj.facesLimit ) is GDMLTube -> createTubeBuffer( - obj.shape.config.toJsRoot(), + obj.shape.config.toJsRoot()?.toDynamic(), obj.facesLimit ) is GDMLXtru -> { val meta = buildMeta { + "_typename" to "TGeoXtru" val vertices = obj.shape.verteces val zs = obj.shape.sections.sortedBy { it.zOrder!! } "fNz" to zs.size "fNvert" to vertices.size - "_typename" to "TGeoXtru" "fX" to vertices.map { it.x } "fY" to vertices.map { it.y } "fX0" to zs.map { it.xOffsset } @@ -60,6 +60,9 @@ object ThreeGDMLFactory : MeshThreeFactory(GDMLShape::class) { } createGeometry(meta.toDynamic(), obj.facesLimit) } + is GDMLUnion -> TODO() + is GDMLSubtraction -> TODO() + is GDMLIntersection -> TODO() // is GDMLUnion -> { // val meta = buildMeta { // "fNode.fLeft" to obj.shape.first.toJsRoot() @@ -68,6 +71,7 @@ object ThreeGDMLFactory : MeshThreeFactory(GDMLShape::class) { // } // createGeometry(meta.toDynamic(), obj.facesLimit) // } + } } } \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 45e4afa4..ba7e8cc0 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -26,4 +26,6 @@ include( ":dataforge-vis-spatial-js" ) -includeBuild("../dataforge-core") \ No newline at end of file +if(file("../dataforge-core").exists()) { + includeBuild("../dataforge-core") +} \ No newline at end of file