Minor specification fix, optional includebuild
This commit is contained in:
parent
953bafb02e
commit
f8f6deda86
@ -1,6 +1,8 @@
|
|||||||
package hep.dataforge.vis.spatial.gdml
|
package hep.dataforge.vis.spatial.gdml
|
||||||
|
|
||||||
import hep.dataforge.meta.*
|
import hep.dataforge.meta.*
|
||||||
|
import kotlin.properties.ReadWriteProperty
|
||||||
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
sealed class GDMLNode(override val config: Config) : Specification {
|
sealed class GDMLNode(override val config: Config) : Specification {
|
||||||
var pName by string()
|
var pName by string()
|
||||||
@ -13,6 +15,10 @@ class GDMLPosition(config: Config) : GDMLDefine(config) {
|
|||||||
var y by number(0f).float
|
var y by number(0f).float
|
||||||
var z by number(0f).float
|
var z by number(0f).float
|
||||||
var unit by string("cm")
|
var unit by string("cm")
|
||||||
|
|
||||||
|
companion object : SpecificationCompanion<GDMLPosition> {
|
||||||
|
override fun wrap(config: Config) = GDMLPosition(config)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class GDMLRotation(config: Config) : GDMLDefine(config) {
|
class GDMLRotation(config: Config) : GDMLDefine(config) {
|
||||||
@ -20,10 +26,12 @@ class GDMLRotation(config: Config) : GDMLDefine(config) {
|
|||||||
var y by number(0f).float
|
var y by number(0f).float
|
||||||
var z by number(0f).float
|
var z by number(0f).float
|
||||||
var unit by string("deg")
|
var unit by string("deg")
|
||||||
|
|
||||||
|
companion object : SpecificationCompanion<GDMLRotation> {
|
||||||
|
override fun wrap(config: Config) = GDMLRotation(config)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
sealed class GDMLSolid(config: Config) : GDMLNode(config) {
|
sealed class GDMLSolid(config: Config) : GDMLNode(config) {
|
||||||
abstract val type: String
|
abstract val type: String
|
||||||
}
|
}
|
||||||
@ -93,14 +101,64 @@ class GDMLXtru(config: Config) : GDMLSolid(config) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class GDMLUnion(config: Config) : GDMLSolid(config) {
|
internal class GDMLRefDelegate(val key: String?) : ReadWriteProperty<GDMLNode, String?> {
|
||||||
override val type: String = "union"
|
override fun getValue(thisRef: GDMLNode, property: KProperty<*>): String? {
|
||||||
|
val realKey = key ?: property.name
|
||||||
|
return thisRef.config["$realKey.ref"].string
|
||||||
|
}
|
||||||
|
|
||||||
val first by node()
|
override fun setValue(thisRef: GDMLNode, property: KProperty<*>, value: String?) {
|
||||||
val second by node()
|
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> {
|
companion object : SpecificationCompanion<GDMLUnion> {
|
||||||
override fun wrap(config: Config): GDMLUnion = GDMLUnion(config)
|
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)
|
||||||
|
}
|
||||||
|
}
|
@ -37,20 +37,20 @@ object ThreeGDMLFactory : MeshThreeFactory<GDMLShape>(GDMLShape::class) {
|
|||||||
override fun buildGeometry(obj: GDMLShape): BufferGeometry {
|
override fun buildGeometry(obj: GDMLShape): BufferGeometry {
|
||||||
return when (obj.shape) {
|
return when (obj.shape) {
|
||||||
is GDMLBox -> createTubeBuffer(
|
is GDMLBox -> createTubeBuffer(
|
||||||
obj.shape.config.toJsRoot(),
|
obj.shape.config.toJsRoot()?.toDynamic(),
|
||||||
obj.facesLimit
|
obj.facesLimit
|
||||||
)
|
)
|
||||||
is GDMLTube -> createTubeBuffer(
|
is GDMLTube -> createTubeBuffer(
|
||||||
obj.shape.config.toJsRoot(),
|
obj.shape.config.toJsRoot()?.toDynamic(),
|
||||||
obj.facesLimit
|
obj.facesLimit
|
||||||
)
|
)
|
||||||
is GDMLXtru -> {
|
is GDMLXtru -> {
|
||||||
val meta = buildMeta {
|
val meta = buildMeta {
|
||||||
|
"_typename" to "TGeoXtru"
|
||||||
val vertices = obj.shape.verteces
|
val vertices = obj.shape.verteces
|
||||||
val zs = obj.shape.sections.sortedBy { it.zOrder!! }
|
val zs = obj.shape.sections.sortedBy { it.zOrder!! }
|
||||||
"fNz" to zs.size
|
"fNz" to zs.size
|
||||||
"fNvert" to vertices.size
|
"fNvert" to vertices.size
|
||||||
"_typename" to "TGeoXtru"
|
|
||||||
"fX" to vertices.map { it.x }
|
"fX" to vertices.map { it.x }
|
||||||
"fY" to vertices.map { it.y }
|
"fY" to vertices.map { it.y }
|
||||||
"fX0" to zs.map { it.xOffsset }
|
"fX0" to zs.map { it.xOffsset }
|
||||||
@ -60,6 +60,9 @@ object ThreeGDMLFactory : MeshThreeFactory<GDMLShape>(GDMLShape::class) {
|
|||||||
}
|
}
|
||||||
createGeometry(meta.toDynamic(), obj.facesLimit)
|
createGeometry(meta.toDynamic(), obj.facesLimit)
|
||||||
}
|
}
|
||||||
|
is GDMLUnion -> TODO()
|
||||||
|
is GDMLSubtraction -> TODO()
|
||||||
|
is GDMLIntersection -> TODO()
|
||||||
// is GDMLUnion -> {
|
// is GDMLUnion -> {
|
||||||
// val meta = buildMeta {
|
// val meta = buildMeta {
|
||||||
// "fNode.fLeft" to obj.shape.first.toJsRoot()
|
// "fNode.fLeft" to obj.shape.first.toJsRoot()
|
||||||
@ -68,6 +71,7 @@ object ThreeGDMLFactory : MeshThreeFactory<GDMLShape>(GDMLShape::class) {
|
|||||||
// }
|
// }
|
||||||
// createGeometry(meta.toDynamic(), obj.facesLimit)
|
// createGeometry(meta.toDynamic(), obj.facesLimit)
|
||||||
// }
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -26,4 +26,6 @@ include(
|
|||||||
":dataforge-vis-spatial-js"
|
":dataforge-vis-spatial-js"
|
||||||
)
|
)
|
||||||
|
|
||||||
includeBuild("../dataforge-core")
|
if(file("../dataforge-core").exists()) {
|
||||||
|
includeBuild("../dataforge-core")
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user