GDML references

This commit is contained in:
Alexander Nozik 2019-04-03 14:01:11 +03:00
parent f8f6deda86
commit fb6a149b5e
4 changed files with 86 additions and 40 deletions

View File

@ -2,39 +2,53 @@ package hep.dataforge.vis.spatial.gdml
import hep.dataforge.meta.Config import hep.dataforge.meta.Config
@DslMarker
annotation class GDMLApi
@GDMLApi
class GDML { class GDML {
private var defines: List<GDMLDefine> = emptyList() private val defines = GDMLDefineContainer()
private var solids: Map<String, GDMLSolid> = emptyMap() private var solids = GDMLSolidContainer()
fun define(block: GDMLDefineBuilder.() -> Unit) { fun define(block: GDMLDefineContainer.() -> Unit) {
defines = GDMLDefineBuilder().apply(block).defines defines.apply(block).map
} }
fun solids(block: GDMLSolidBuilder.() -> Unit) { fun solids(block: GDMLSolidContainer.() -> Unit) {
solids = GDMLSolidBuilder().apply(block).solids solids.apply(block).map
}
fun getPosition(ref: String) = defines.map[ref] as? GDMLPosition
fun getRotation(ref: String) = defines.map[ref] as? GDMLRotation
fun getSolid(ref:String) = solids.map[ref]
}
@GDMLApi
class GDMLDefineContainer {
internal val map = HashMap<String, GDMLDefine>()
fun position(name: String, block: GDMLPosition.() -> Unit) {
map[name] = GDMLPosition(Config()).apply(block).apply { this.pName = name }
}
fun rotation(name: String, block: GDMLRotation.() -> Unit) {
map[name] = GDMLRotation(Config()).apply(block).apply { this.pName = name }
} }
} }
class GDMLDefineBuilder { @GDMLApi
internal val defines = ArrayList<GDMLDefine>() class GDMLSolidContainer {
internal val map = HashMap<String, GDMLSolid>()
fun position(block: GDMLPosition.() -> Unit) { operator fun get(ref: String) = map[ref]
defines.add(GDMLPosition(Config()).apply(block))
fun box(name: String, block: GDMLBox.() -> Unit) {
map[name] = GDMLBox.build(block).apply{this.pName = name}
} }
fun tube(name: String, block: GDMLTube.() -> Unit){
fun rotation(block: GDMLRotation.() -> Unit) { map[name] = GDMLTube.build(block).apply{this.pName = name}
defines.add(GDMLRotation(Config()).apply(block))
} }
} fun xtru(name: String, block: GDMLXtru.() -> Unit) {
map[name] = GDMLXtru.build(block).apply{this.pName = name}
class GDMLSolidBuilder {
internal val solids = HashMap<String, GDMLSolid>()
private fun put(solid: GDMLSolid) {
solids[solid.pName!!] = solid
} }
fun box(block: GDMLBox.() -> Unit) = put(GDMLBox.build(block))
fun tube(block: GDMLTube.() -> Unit) = put(GDMLTube.build(block))
fun xtru(block: GDMLXtru.() -> Unit) = put(GDMLXtru.build(block))
} }

View File

@ -120,19 +120,37 @@ internal class GDMLRefDelegate(val key: String?) : ReadWriteProperty<GDMLNode, S
internal fun GDMLNode.ref(key: String? = null) = GDMLRefDelegate(key) internal fun GDMLNode.ref(key: String? = null) = GDMLRefDelegate(key)
sealed class GDMLBoolSolid(config: Config) : GDMLSolid(config) { sealed class GDMLBoolSolid(config: Config, var root: GDML? = null) : GDMLSolid(config) {
var first by ref() var first by ref()
@JsName("resolveFirst")
fun first() = first?.let{ref -> root?.getSolid(ref)}
var second by ref() var second by ref()
@JsName("resolveSecond")
fun second() = second?.let{ref -> root?.getSolid(ref)}
var position by spec(GDMLPosition) var position by spec(GDMLPosition)
var positionref by ref() var positionref by ref()
/**
* Get the position from either position block or reference (if root is provided)
*/
@JsName("resolvePosition")
fun position() = position ?: positionref?.let{ref -> root?.getPosition(ref)}
var rotation by spec(GDMLRotation) var rotation by spec(GDMLRotation)
var rotationref by ref() var rotationref by ref()
/**
* Get the rotation from either position block or reference (if root is provided)
*/
@JsName("resolveRotation")
fun rotation() = rotation ?: rotationref?.let{ref -> root?.getRotation(ref)}
var firstposition by spec(GDMLPosition) var firstposition by spec(GDMLPosition)
var firstrotation by spec(GDMLRotation) var firstrotation by spec(GDMLRotation)

View File

@ -4,6 +4,7 @@ import hep.dataforge.context.AbstractPlugin
import hep.dataforge.context.Context import hep.dataforge.context.Context
import hep.dataforge.context.PluginFactory import hep.dataforge.context.PluginFactory
import hep.dataforge.context.PluginTag import hep.dataforge.context.PluginTag
import hep.dataforge.names.toName
import hep.dataforge.vis.spatial.ThreePlugin import hep.dataforge.vis.spatial.ThreePlugin
class GDMLPlugin : AbstractPlugin() { class GDMLPlugin : AbstractPlugin() {
@ -13,10 +14,9 @@ class GDMLPlugin : AbstractPlugin() {
override fun attach(context: Context) { override fun attach(context: Context) {
super.attach(context) super.attach(context)
// context.plugins.get<ThreePlugin>()?.factories?.apply { context.plugins.get<ThreePlugin>()?.factories?.apply {
// this["jsRoot.geometry".toName()] = ThreeJSRootGeometryFactory this["gdml".toName()] = ThreeGDMLFactory
// this["jsRoot.object".toName()] = ThreeJSRootObjectFactory }
// }
} }
override fun detach() { override fun detach() {

View File

@ -60,17 +60,31 @@ object ThreeGDMLFactory : MeshThreeFactory<GDMLShape>(GDMLShape::class) {
} }
createGeometry(meta.toDynamic(), obj.facesLimit) createGeometry(meta.toDynamic(), obj.facesLimit)
} }
is GDMLUnion -> TODO() is GDMLUnion -> {
is GDMLSubtraction -> TODO() val meta = buildMeta {
is GDMLIntersection -> TODO() "fNode.fLeft" to obj.shape.first()?.config.toJsRoot()
// is GDMLUnion -> { "fNode.fRight" to obj.shape.second()?.config.toJsRoot()
// val meta = buildMeta { "fNode._typename" to "TGeoUnion"
// "fNode.fLeft" to obj.shape.first.toJsRoot() }
// "fNode.fRight" to obj.shape.second.toJsRoot() createGeometry(meta.toDynamic(), obj.facesLimit)
// "fNode._typename" to "TGeoUnion" }
// } is GDMLSubtraction -> {
// createGeometry(meta.toDynamic(), obj.facesLimit) val meta = buildMeta {
// } "fNode.fLeft" to obj.shape.first()?.config.toJsRoot()
"fNode.fRight" to obj.shape.second()?.config.toJsRoot()
"fNode._typename" to "TGeoSubtraction"
}
createGeometry(meta.toDynamic(), obj.facesLimit)
}
is GDMLIntersection -> {
val meta = buildMeta {
"fNode.fLeft" to obj.shape.first()?.config.toJsRoot()
"fNode.fRight" to obj.shape.second()?.config.toJsRoot()
"fNode._typename" to "TGeoIntersection"
}
createGeometry(meta.toDynamic(), obj.facesLimit)
}
} }
} }