forked from kscience/visionforge
GDML references
This commit is contained in:
parent
f8f6deda86
commit
fb6a149b5e
@ -2,39 +2,53 @@ package hep.dataforge.vis.spatial.gdml
|
||||
|
||||
import hep.dataforge.meta.Config
|
||||
|
||||
@DslMarker
|
||||
annotation class GDMLApi
|
||||
|
||||
@GDMLApi
|
||||
class GDML {
|
||||
private var defines: List<GDMLDefine> = emptyList()
|
||||
private var solids: Map<String, GDMLSolid> = emptyMap()
|
||||
private val defines = GDMLDefineContainer()
|
||||
private var solids = GDMLSolidContainer()
|
||||
|
||||
fun define(block: GDMLDefineBuilder.() -> Unit) {
|
||||
defines = GDMLDefineBuilder().apply(block).defines
|
||||
fun define(block: GDMLDefineContainer.() -> Unit) {
|
||||
defines.apply(block).map
|
||||
}
|
||||
|
||||
fun solids(block: GDMLSolidBuilder.() -> Unit) {
|
||||
solids = GDMLSolidBuilder().apply(block).solids
|
||||
fun solids(block: GDMLSolidContainer.() -> Unit) {
|
||||
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 {
|
||||
internal val defines = ArrayList<GDMLDefine>()
|
||||
@GDMLApi
|
||||
class GDMLSolidContainer {
|
||||
internal val map = HashMap<String, GDMLSolid>()
|
||||
|
||||
fun position(block: GDMLPosition.() -> Unit) {
|
||||
defines.add(GDMLPosition(Config()).apply(block))
|
||||
operator fun get(ref: String) = map[ref]
|
||||
|
||||
fun box(name: String, block: GDMLBox.() -> Unit) {
|
||||
map[name] = GDMLBox.build(block).apply{this.pName = name}
|
||||
}
|
||||
|
||||
fun rotation(block: GDMLRotation.() -> Unit) {
|
||||
defines.add(GDMLRotation(Config()).apply(block))
|
||||
fun tube(name: String, block: GDMLTube.() -> Unit){
|
||||
map[name] = GDMLTube.build(block).apply{this.pName = name}
|
||||
}
|
||||
}
|
||||
|
||||
class GDMLSolidBuilder {
|
||||
internal val solids = HashMap<String, GDMLSolid>()
|
||||
|
||||
private fun put(solid: GDMLSolid) {
|
||||
solids[solid.pName!!] = solid
|
||||
fun xtru(name: String, block: GDMLXtru.() -> Unit) {
|
||||
map[name] = GDMLXtru.build(block).apply{this.pName = name}
|
||||
}
|
||||
|
||||
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))
|
||||
}
|
@ -120,19 +120,37 @@ internal class GDMLRefDelegate(val key: String?) : ReadWriteProperty<GDMLNode, S
|
||||
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()
|
||||
|
||||
@JsName("resolveFirst")
|
||||
fun first() = first?.let{ref -> root?.getSolid(ref)}
|
||||
|
||||
var second by ref()
|
||||
|
||||
@JsName("resolveSecond")
|
||||
fun second() = second?.let{ref -> root?.getSolid(ref)}
|
||||
|
||||
var position by spec(GDMLPosition)
|
||||
|
||||
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 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 firstrotation by spec(GDMLRotation)
|
||||
|
@ -4,6 +4,7 @@ import hep.dataforge.context.AbstractPlugin
|
||||
import hep.dataforge.context.Context
|
||||
import hep.dataforge.context.PluginFactory
|
||||
import hep.dataforge.context.PluginTag
|
||||
import hep.dataforge.names.toName
|
||||
import hep.dataforge.vis.spatial.ThreePlugin
|
||||
|
||||
class GDMLPlugin : AbstractPlugin() {
|
||||
@ -13,10 +14,9 @@ class GDMLPlugin : AbstractPlugin() {
|
||||
|
||||
override fun attach(context: Context) {
|
||||
super.attach(context)
|
||||
// context.plugins.get<ThreePlugin>()?.factories?.apply {
|
||||
// this["jsRoot.geometry".toName()] = ThreeJSRootGeometryFactory
|
||||
// this["jsRoot.object".toName()] = ThreeJSRootObjectFactory
|
||||
// }
|
||||
context.plugins.get<ThreePlugin>()?.factories?.apply {
|
||||
this["gdml".toName()] = ThreeGDMLFactory
|
||||
}
|
||||
}
|
||||
|
||||
override fun detach() {
|
||||
|
@ -60,17 +60,31 @@ 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()
|
||||
// "fNode.fRight" to obj.shape.second.toJsRoot()
|
||||
// "fNode._typename" to "TGeoUnion"
|
||||
// }
|
||||
// createGeometry(meta.toDynamic(), obj.facesLimit)
|
||||
// }
|
||||
is GDMLUnion -> {
|
||||
val meta = buildMeta {
|
||||
"fNode.fLeft" to obj.shape.first()?.config.toJsRoot()
|
||||
"fNode.fRight" to obj.shape.second()?.config.toJsRoot()
|
||||
"fNode._typename" to "TGeoUnion"
|
||||
}
|
||||
createGeometry(meta.toDynamic(), obj.facesLimit)
|
||||
}
|
||||
is GDMLSubtraction -> {
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user