Fix proxy display

This commit is contained in:
Alexander Nozik 2019-12-23 21:38:28 +03:00
parent a5a03f1c02
commit a564e078e5
9 changed files with 55 additions and 23 deletions

View File

@ -17,7 +17,7 @@ import kotlin.random.Random
class GDMLTransformer(val root: GDML) { class GDMLTransformer(val root: GDML) {
private val materialCache = HashMap<GDMLMaterial, Meta>() private val materialCache = HashMap<GDMLMaterial, Meta>()
private val random = Random(111) private val random = Random(222)
enum class Action { enum class Action {
ACCEPT, ACCEPT,

View File

@ -5,6 +5,8 @@ import hep.dataforge.names.asName
import hep.dataforge.names.plus import hep.dataforge.names.plus
import hep.dataforge.vis.common.get import hep.dataforge.vis.common.get
import hep.dataforge.vis.spatial.* import hep.dataforge.vis.spatial.*
import hep.dataforge.vis.spatial.GeometryConstants.one
import hep.dataforge.vis.spatial.GeometryConstants.zero
import scientifik.gdml.* import scientifik.gdml.*
import kotlin.math.cos import kotlin.math.cos
import kotlin.math.sin import kotlin.math.sin
@ -12,25 +14,28 @@ import kotlin.math.sin
private fun VisualObject3D.withPosition( private fun VisualObject3D.withPosition(
lUnit: LUnit, lUnit: LUnit,
pos: GDMLPosition? = null, newPos: GDMLPosition? = null,
rotation: GDMLRotation? = null, newRotation: GDMLRotation? = null,
scale: GDMLScale? = null newScale: GDMLScale? = null
): VisualObject3D = apply { ): VisualObject3D = apply {
pos?.let { newPos?.let {
this@withPosition.x = pos.x(lUnit) val point = Point3D(it.x(lUnit), it.y(lUnit), it.z(lUnit))
this@withPosition.y = pos.y(lUnit) if (position != null || point != zero) {
this@withPosition.z = pos.z(lUnit) position = point
}
}
newRotation?.let {
val point = Point3D(it.x(), it.y(), it.z())
if (rotation != null || point != zero) {
rotation = point
} }
rotation?.let {
this@withPosition.rotationX = rotation.x()
this@withPosition.rotationY = rotation.y()
this@withPosition.rotationZ = rotation.z()
//this@withPosition.rotationOrder = RotationOrder.ZXY //this@withPosition.rotationOrder = RotationOrder.ZXY
} }
scale?.let { newScale?.let {
this@withPosition.scaleX = scale.x.toFloat() val point = Point3D(it.x, it.y, it.z)
this@withPosition.scaleY = scale.y.toFloat() if (scale != null || point != one) {
this@withPosition.scaleZ = scale.z.toFloat() scale = point
}
} }
//TODO convert units if needed //TODO convert units if needed
} }
@ -251,6 +256,6 @@ fun GDML.toVisual(block: GDMLTransformer.() -> Unit = {}): VisualGroup3D {
*/ */
fun VisualGroup3D.gdml(gdml: GDML, key: String = "", transformer: GDMLTransformer.() -> Unit = {}) { fun VisualGroup3D.gdml(gdml: GDML, key: String = "", transformer: GDMLTransformer.() -> Unit = {}) {
val visual = gdml.toVisual(transformer) val visual = gdml.toVisual(transformer)
println(Visual3DPlugin.json.stringify(VisualGroup3D.serializer(),visual)) println(Visual3DPlugin.json.stringify(VisualGroup3D.serializer(), visual))
set(key, visual) set(key, visual)
} }

View File

@ -10,11 +10,13 @@ import hep.dataforge.meta.get
import hep.dataforge.vis.common.AbstractVisualObject import hep.dataforge.vis.common.AbstractVisualObject
import hep.dataforge.vis.common.VisualFactory import hep.dataforge.vis.common.VisualFactory
import hep.dataforge.vis.common.VisualObject import hep.dataforge.vis.common.VisualObject
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import kotlinx.serialization.UseSerializers import kotlinx.serialization.UseSerializers
import kotlin.reflect.KClass import kotlin.reflect.KClass
@Serializable @Serializable
@SerialName("3d.box")
class Box( class Box(
val xSize: Float, val xSize: Float,
val ySize: Float, val ySize: Float,

View File

@ -12,6 +12,7 @@ import hep.dataforge.names.NameToken
import hep.dataforge.names.asName import hep.dataforge.names.asName
import hep.dataforge.names.plus import hep.dataforge.names.plus
import hep.dataforge.vis.common.* import hep.dataforge.vis.common.*
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient import kotlinx.serialization.Transient
import kotlinx.serialization.UseSerializers import kotlinx.serialization.UseSerializers
@ -23,6 +24,7 @@ import kotlin.collections.set
* A proxy [VisualObject3D] to reuse a template object * A proxy [VisualObject3D] to reuse a template object
*/ */
@Serializable @Serializable
@SerialName("3d.proxy")
class Proxy(val templateName: Name) : AbstractVisualObject(), VisualGroup, VisualObject3D { class Proxy(val templateName: Name) : AbstractVisualObject(), VisualGroup, VisualObject3D {
override var position: Point3D? = null override var position: Point3D? = null
@ -90,6 +92,13 @@ class Proxy(val templateName: Name) : AbstractVisualObject(), VisualGroup, Visua
override val styleSheet: StyleSheet get() = this@Proxy.styleSheet override val styleSheet: StyleSheet get() = this@Proxy.styleSheet
override var styles: List<String>
get() = super.styles + prototype.styles
set(value) {
setProperty(VisualObject.STYLE_KEY, value)
updateStyles(value)
}
override val children: Map<NameToken, VisualObject> override val children: Map<NameToken, VisualObject>
get() = (prototype as? VisualGroup)?.children?.mapValues { (key, _) -> get() = (prototype as? VisualGroup)?.children?.mapValues { (key, _) ->
ProxyChild( ProxyChild(

View File

@ -25,6 +25,7 @@ import kotlinx.serialization.UseSerializers
import kotlin.collections.set import kotlin.collections.set
@Serializable @Serializable
@SerialName("group.3d")
class VisualGroup3D : AbstractVisualGroup(), VisualObject3D { class VisualGroup3D : AbstractVisualGroup(), VisualObject3D {
/** /**
* A container for templates visible inside this group * A container for templates visible inside this group

View File

@ -50,10 +50,13 @@ operator fun Point3D.component3() = z
fun Meta.point3D() = Point3D(this["x"].number ?: 0, this["y"].number ?: 0, this["y"].number ?: 0) fun Meta.point3D() = Point3D(this["x"].number ?: 0, this["y"].number ?: 0, this["y"].number ?: 0)
val zero = Point3D(0, 0, 0)
fun Point3D.toMeta() = buildMeta { fun Point3D.toMeta() = buildMeta {
VisualObject3D.x put x VisualObject3D.x put x
VisualObject3D.y put y VisualObject3D.y put y
VisualObject3D.z put z VisualObject3D.z put z
} }
object GeometryConstants{
val zero = Point3D(0.0, 0.0, 0.0)
val one = Point3D(1.0, 1.0, 1.0)
}

View File

@ -5,6 +5,7 @@ import hep.dataforge.meta.float
import hep.dataforge.meta.get import hep.dataforge.meta.get
import hep.dataforge.meta.node import hep.dataforge.meta.node
import hep.dataforge.vis.spatial.* import hep.dataforge.vis.spatial.*
import hep.dataforge.vis.spatial.GeometryConstants.zero
import info.laht.threekt.core.* import info.laht.threekt.core.*
import info.laht.threekt.external.controls.OrbitControls import info.laht.threekt.external.controls.OrbitControls
import info.laht.threekt.materials.Material import info.laht.threekt.materials.Material

View File

@ -1,8 +1,7 @@
package hep.dataforge.vis.spatial package hep.dataforge.vis.spatial
actual class Point2D actual constructor(x: Number, y: Number) { actual data class Point2D(actual var x: Double, actual var y: Double){
actual var x = x.toDouble() actual constructor(x: Number, y: Number): this(x.toDouble(),y.toDouble())
actual var y = y.toDouble()
} }
actual class Point3D(val point: org.fxyz3d.geometry.Point3D) { actual class Point3D(val point: org.fxyz3d.geometry.Point3D) {
@ -29,4 +28,16 @@ actual class Point3D(val point: org.fxyz3d.geometry.Point3D) {
inline set(value) { inline set(value) {
point.z = value.toFloat() point.z = value.toFloat()
} }
override fun equals(other: Any?): Boolean {
return this.point == (other as? hep.dataforge.vis.spatial.Point3D)?.point
}
override fun hashCode(): Int {
return point.hashCode()
}
override fun toString(): String {
return point.toString()
}
} }

View File

@ -17,7 +17,7 @@ class FXDemoApp : App(FXDemoGrid::class) {
stage.width = 400.0 stage.width = 400.0
stage.height = 400.0 stage.height = 400.0
view.showcase() //view.showcase()
view.demo("gdml", "gdml") { view.demo("gdml", "gdml") {
gdml(Paths.get("D:\\Work\\Projects\\gdml.kt\\gdml-source\\cubes.gdml")) { gdml(Paths.get("D:\\Work\\Projects\\gdml.kt\\gdml-source\\cubes.gdml")) {
lUnit = LUnit.CM lUnit = LUnit.CM