Minor specification fix, optional includebuild

This commit is contained in:
Alexander Nozik 2019-04-03 09:29:10 +03:00
parent 953bafb02e
commit f8f6deda86
3 changed files with 74 additions and 10 deletions

View File

@ -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<GDMLPosition> {
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<GDMLRotation> {
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<GDMLNode, String?> {
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<GDMLUnion> {
override fun wrap(config: Config): GDMLUnion = GDMLUnion(config)
}
}
class GDMLSubtraction(config: Config) : GDMLBoolSolid(config) {
override val type: String = "subtraction"
companion object : SpecificationCompanion<GDMLUnion> {
override fun wrap(config: Config) = GDMLUnion(config)
}
}
class GDMLIntersection(config: Config) : GDMLBoolSolid(config) {
override val type: String = "intersection"
companion object : SpecificationCompanion<GDMLIntersection> {
override fun wrap(config: Config) = GDMLIntersection(config)
}
}

View File

@ -37,20 +37,20 @@ object ThreeGDMLFactory : MeshThreeFactory<GDMLShape>(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>(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>(GDMLShape::class) {
// }
// createGeometry(meta.toDynamic(), obj.facesLimit)
// }
}
}
}

View File

@ -26,4 +26,6 @@ include(
":dataforge-vis-spatial-js"
)
includeBuild("../dataforge-core")
if(file("../dataforge-core").exists()) {
includeBuild("../dataforge-core")
}