Move to new kotlin and plugin
This commit is contained in:
parent
439b02c03e
commit
75a988b546
@ -1,13 +1,10 @@
|
||||
import scientifik.useSerialization
|
||||
import scientifik.fx
|
||||
import scientifik.serialization
|
||||
|
||||
val dataforgeVersion by extra("0.1.5-dev-6")
|
||||
val dataforgeVersion by extra("0.1.5")
|
||||
|
||||
plugins {
|
||||
val kotlinVersion = "1.3.61"
|
||||
val toolsVersion = "0.3.2"
|
||||
|
||||
kotlin("jvm") version kotlinVersion apply false
|
||||
id("kotlin-dce-js") version kotlinVersion apply false
|
||||
val toolsVersion = "0.4.0"
|
||||
id("scientifik.mpp") version toolsVersion apply false
|
||||
id("scientifik.jvm") version toolsVersion apply false
|
||||
id("scientifik.js") version toolsVersion apply false
|
||||
@ -26,16 +23,17 @@ allprojects {
|
||||
}
|
||||
|
||||
group = "hep.dataforge"
|
||||
version = "0.1.1-dev"
|
||||
}
|
||||
|
||||
subprojects{
|
||||
this.useSerialization()
|
||||
version = "0.1.2-dev"
|
||||
}
|
||||
|
||||
val githubProject by extra("dataforge-vis")
|
||||
val bintrayRepo by extra("dataforge")
|
||||
val fxVersion by extra("14")
|
||||
|
||||
subprojects {
|
||||
apply(plugin = "scientifik.publish")
|
||||
serialization()
|
||||
afterEvaluate {
|
||||
fx(scientifik.FXModule.CONTROLS, version = fxVersion)
|
||||
}
|
||||
}
|
@ -1,21 +1,16 @@
|
||||
import org.openjfx.gradle.JavaFXOptions
|
||||
import scientifik.useSerialization
|
||||
import scientifik.serialization
|
||||
|
||||
plugins {
|
||||
id("scientifik.mpp")
|
||||
id("org.openjfx.javafxplugin")
|
||||
}
|
||||
|
||||
val dataforgeVersion: String by rootProject.extra
|
||||
//val kvisionVersion: String by rootProject.extra("2.0.0-M1")
|
||||
|
||||
useSerialization()
|
||||
serialization()
|
||||
val fxVersion: String by rootProject.extra
|
||||
|
||||
kotlin {
|
||||
jvm{
|
||||
withJava()
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
commonMain{
|
||||
dependencies {
|
||||
@ -24,7 +19,7 @@ kotlin {
|
||||
}
|
||||
jvmMain{
|
||||
dependencies {
|
||||
api("no.tornado:tornadofx:1.7.19")
|
||||
api("no.tornado:tornadofx:1.7.20")
|
||||
//api("no.tornado:tornadofx-controlsfx:0.1.1")
|
||||
api("de.jensd:fontawesomefx-fontawesome:4.7.0-11"){
|
||||
exclude(group = "org.openjfx")
|
||||
@ -38,13 +33,9 @@ kotlin {
|
||||
dependencies {
|
||||
api("hep.dataforge:dataforge-output-html:$dataforgeVersion")
|
||||
//api(npm("bootstrap","4.4.1"))
|
||||
implementation(npm("jsoneditor"))
|
||||
implementation(npm("jsoneditor","8.6.1"))
|
||||
implementation(npm("file-saver"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
configure<JavaFXOptions> {
|
||||
modules("javafx.controls")
|
||||
}
|
||||
}
|
@ -1,8 +1,10 @@
|
||||
package hep.dataforge.vis.common
|
||||
|
||||
import hep.dataforge.meta.*
|
||||
import hep.dataforge.meta.scheme.setProperty
|
||||
import hep.dataforge.names.Name
|
||||
import hep.dataforge.names.asName
|
||||
import hep.dataforge.values.Value
|
||||
import hep.dataforge.vis.common.VisualObject.Companion.STYLE_KEY
|
||||
import kotlinx.serialization.Transient
|
||||
|
||||
@ -22,7 +24,7 @@ abstract class AbstractVisualObject : VisualObject {
|
||||
get() = properties?.get(STYLE_KEY).stringList
|
||||
set(value) {
|
||||
//val allStyles = (field + value).distinct()
|
||||
setProperty(STYLE_KEY, value)
|
||||
setProperty(STYLE_KEY, Value.of(value))
|
||||
updateStyles(value)
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,9 @@
|
||||
package hep.dataforge.vis.common
|
||||
|
||||
import hep.dataforge.meta.*
|
||||
import hep.dataforge.meta.Meta
|
||||
import hep.dataforge.meta.MetaItem
|
||||
import hep.dataforge.meta.get
|
||||
import hep.dataforge.meta.number
|
||||
import hep.dataforge.values.ValueType
|
||||
import hep.dataforge.values.int
|
||||
import kotlin.math.max
|
||||
@ -234,7 +237,7 @@ object Colors {
|
||||
/**
|
||||
* Convert three bytes representing color to Meta
|
||||
*/
|
||||
fun rgbToMeta(r: UByte, g: UByte, b: UByte): Meta = buildMeta {
|
||||
fun rgbToMeta(r: UByte, g: UByte, b: UByte): Meta = Meta {
|
||||
RED_KEY put r.toInt()
|
||||
GREEN_KEY put g.toInt()
|
||||
BLUE_KEY put b.toInt()
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
package hep.dataforge.vis.common
|
||||
|
||||
import hep.dataforge.io.serialization.MetaSerializer
|
||||
import hep.dataforge.meta.*
|
||||
import hep.dataforge.names.Name
|
||||
import hep.dataforge.names.asName
|
||||
@ -46,7 +45,7 @@ class StyleSheet() {
|
||||
}
|
||||
|
||||
operator fun set(key: String, builder: MetaBuilder.() -> Unit) {
|
||||
val newStyle = get(key)?.let { buildMeta(it, builder) } ?: buildMeta(builder)
|
||||
val newStyle = get(key)?.edit(builder) ?: Meta(builder)
|
||||
set(key, newStyle.seal())
|
||||
}
|
||||
|
||||
@ -58,7 +57,7 @@ class StyleSheet() {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, obj: StyleSheet) {
|
||||
override fun serialize(encoder: Encoder, value: StyleSheet) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,9 @@
|
||||
package hep.dataforge.vis.common
|
||||
|
||||
import hep.dataforge.meta.*
|
||||
import hep.dataforge.meta.Laminate
|
||||
import hep.dataforge.meta.Meta
|
||||
import hep.dataforge.meta.MetaItem
|
||||
import hep.dataforge.meta.scheme.Configurable
|
||||
import hep.dataforge.names.Name
|
||||
import hep.dataforge.names.asName
|
||||
import hep.dataforge.names.toName
|
||||
@ -28,17 +31,12 @@ interface VisualObject : Configurable {
|
||||
*/
|
||||
fun allProperties(): Laminate
|
||||
|
||||
/**
|
||||
* Set property for this object
|
||||
*/
|
||||
fun setProperty(name: Name, value: Any?) {
|
||||
config[name] = value
|
||||
}
|
||||
|
||||
/**
|
||||
* Get property including or excluding parent properties
|
||||
*/
|
||||
fun getProperty(name: Name, inherit: Boolean = true): MetaItem<*>?
|
||||
fun getProperty(name: Name, inherit: Boolean): MetaItem<*>?
|
||||
|
||||
override fun getProperty(name: Name): MetaItem<*>? = getProperty(name, true)
|
||||
|
||||
/**
|
||||
* Trigger property invalidation event. If [name] is empty, notify that the whole object is changed
|
||||
@ -77,11 +75,6 @@ interface VisualObject : Configurable {
|
||||
*/
|
||||
fun VisualObject.getProperty(key: String, inherit: Boolean = true): MetaItem<*>? = getProperty(key.toName(), inherit)
|
||||
|
||||
/**
|
||||
* Set [VisualObject] property using key as a String
|
||||
*/
|
||||
fun VisualObject.setProperty(key: String, value: Any?) = setProperty(key.toName(), value)
|
||||
|
||||
/**
|
||||
* Add style name to the list of styles to be resolved later. The style with given name does not necessary exist at the moment.
|
||||
*/
|
||||
|
@ -1,7 +1,8 @@
|
||||
package hep.dataforge.vis.common
|
||||
|
||||
import hep.dataforge.descriptors.ValueDescriptor
|
||||
import hep.dataforge.meta.*
|
||||
import hep.dataforge.meta.descriptors.ValueDescriptor
|
||||
import hep.dataforge.meta.scheme.getProperty
|
||||
|
||||
/**
|
||||
* Extension property to access the "widget" key of [ValueDescriptor]
|
||||
@ -9,14 +10,14 @@ import hep.dataforge.meta.*
|
||||
var ValueDescriptor.widget: Meta
|
||||
get() = this.config["widget"].node?: EmptyMeta
|
||||
set(value) {
|
||||
this.config["widget"] = value
|
||||
config["widget"] = value
|
||||
}
|
||||
|
||||
/**
|
||||
* Extension property to access the "widget.type" key of [ValueDescriptor]
|
||||
*/
|
||||
var ValueDescriptor.widgetType: String?
|
||||
get() = this["widget.type"].string
|
||||
get() = getProperty("widget.type").string
|
||||
set(value) {
|
||||
this.config["widget.type"] = value
|
||||
config["widget.type"] = value
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
package hep.dataforge.vis.js.editor
|
||||
|
||||
import hep.dataforge.io.toJson
|
||||
import hep.dataforge.js.jsObject
|
||||
import hep.dataforge.meta.DynamicMeta
|
||||
import hep.dataforge.meta.Meta
|
||||
import hep.dataforge.meta.toJson
|
||||
import hep.dataforge.meta.update
|
||||
import hep.dataforge.names.Name
|
||||
import hep.dataforge.names.isEmpty
|
||||
@ -12,8 +12,6 @@ import hep.dataforge.vis.common.findStyle
|
||||
import kotlinx.html.dom.append
|
||||
import kotlinx.html.js.*
|
||||
import org.w3c.dom.Element
|
||||
import kotlin.collections.forEach
|
||||
import kotlin.collections.isNotEmpty
|
||||
import kotlin.collections.set
|
||||
import kotlin.dom.clear
|
||||
|
||||
|
@ -8,8 +8,8 @@ package hep.dataforge.vis.fx.editor
|
||||
import de.jensd.fx.glyphs.fontawesome.FontAwesomeIcon
|
||||
import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView
|
||||
import hep.dataforge.context.Global
|
||||
import hep.dataforge.descriptors.NodeDescriptor
|
||||
import hep.dataforge.meta.Config
|
||||
import hep.dataforge.meta.descriptors.NodeDescriptor
|
||||
import hep.dataforge.names.NameToken
|
||||
import hep.dataforge.vis.fx.dfIconView
|
||||
import javafx.scene.Node
|
||||
|
@ -1,9 +1,9 @@
|
||||
package hep.dataforge.vis.fx.editor
|
||||
|
||||
import hep.dataforge.descriptors.ItemDescriptor
|
||||
import hep.dataforge.descriptors.NodeDescriptor
|
||||
import hep.dataforge.descriptors.ValueDescriptor
|
||||
import hep.dataforge.meta.*
|
||||
import hep.dataforge.meta.descriptors.ItemDescriptor
|
||||
import hep.dataforge.meta.descriptors.NodeDescriptor
|
||||
import hep.dataforge.meta.descriptors.ValueDescriptor
|
||||
import hep.dataforge.names.Name
|
||||
import hep.dataforge.names.NameToken
|
||||
import hep.dataforge.names.asName
|
||||
|
@ -7,9 +7,9 @@ package hep.dataforge.vis.fx.editor
|
||||
|
||||
import hep.dataforge.context.Context
|
||||
import hep.dataforge.context.Named
|
||||
import hep.dataforge.descriptors.ValueDescriptor
|
||||
import hep.dataforge.meta.EmptyMeta
|
||||
import hep.dataforge.meta.Meta
|
||||
import hep.dataforge.meta.descriptors.ValueDescriptor
|
||||
import hep.dataforge.names.toName
|
||||
import hep.dataforge.provider.Type
|
||||
import hep.dataforge.provider.provideByType
|
||||
|
@ -5,7 +5,7 @@
|
||||
*/
|
||||
package hep.dataforge.vis.fx.editor
|
||||
|
||||
import hep.dataforge.descriptors.ValueDescriptor
|
||||
import hep.dataforge.meta.descriptors.ValueDescriptor
|
||||
import hep.dataforge.values.Null
|
||||
import hep.dataforge.values.Value
|
||||
import javafx.beans.property.SimpleObjectProperty
|
||||
|
@ -1,8 +1,8 @@
|
||||
package hep.dataforge.vis.fx.editor
|
||||
|
||||
import hep.dataforge.descriptors.NodeDescriptor
|
||||
import hep.dataforge.meta.Config
|
||||
import hep.dataforge.meta.Meta
|
||||
import hep.dataforge.meta.descriptors.NodeDescriptor
|
||||
import hep.dataforge.meta.update
|
||||
import hep.dataforge.vis.common.VisualObject
|
||||
import hep.dataforge.vis.common.findStyle
|
||||
|
@ -1,8 +1,8 @@
|
||||
package hep.dataforge.vis.fx.demo
|
||||
|
||||
import hep.dataforge.descriptors.NodeDescriptor
|
||||
import hep.dataforge.meta.buildMeta
|
||||
import hep.dataforge.meta.toConfig
|
||||
import hep.dataforge.meta.Meta
|
||||
import hep.dataforge.meta.asConfig
|
||||
import hep.dataforge.meta.descriptors.NodeDescriptor
|
||||
import hep.dataforge.values.ValueType
|
||||
import hep.dataforge.vis.fx.editor.ConfigEditor
|
||||
import hep.dataforge.vis.fx.editor.FXMeta
|
||||
@ -15,7 +15,7 @@ class MetaEditorDemoApp : App(MetaEditorDemo::class)
|
||||
|
||||
class MetaEditorDemo : View("Meta editor demo") {
|
||||
|
||||
val meta = buildMeta {
|
||||
val meta = Meta {
|
||||
"aNode" put {
|
||||
"innerNode" put {
|
||||
"innerValue" put true
|
||||
@ -23,30 +23,30 @@ class MetaEditorDemo : View("Meta editor demo") {
|
||||
"b" put 223
|
||||
"c" put "StringValue"
|
||||
}
|
||||
}.toConfig()
|
||||
}.asConfig()
|
||||
|
||||
val descriptor = NodeDescriptor {
|
||||
node("aNode") {
|
||||
defineNode("aNode") {
|
||||
info = "A root demo node"
|
||||
value("b") {
|
||||
defineValue("b") {
|
||||
info = "b number value"
|
||||
type(ValueType.NUMBER)
|
||||
}
|
||||
node("otherNode") {
|
||||
value("otherValue") {
|
||||
defineNode("otherNode") {
|
||||
defineValue("otherValue") {
|
||||
type(ValueType.BOOLEAN)
|
||||
default(false)
|
||||
info = "default value"
|
||||
}
|
||||
}
|
||||
}
|
||||
value("multiple"){
|
||||
defineValue("multiple") {
|
||||
info = "A sns value"
|
||||
multiple = true
|
||||
}
|
||||
}
|
||||
|
||||
private val rootNode = FXMeta.root(meta,descriptor)
|
||||
private val rootNode = FXMeta.root(meta, descriptor)
|
||||
|
||||
override val root =
|
||||
splitpane(Orientation.HORIZONTAL, MetaViewer(rootNode).root, ConfigEditor(rootNode).root)
|
||||
|
@ -2,7 +2,6 @@ package hep.dataforge.vis.spatial.gdml
|
||||
|
||||
import hep.dataforge.meta.Meta
|
||||
import hep.dataforge.meta.MetaBuilder
|
||||
import hep.dataforge.meta.buildMeta
|
||||
import hep.dataforge.names.Name
|
||||
import hep.dataforge.names.toName
|
||||
import hep.dataforge.vis.common.useStyle
|
||||
@ -44,7 +43,7 @@ class GDMLTransformer(val root: GDML) {
|
||||
|
||||
fun VisualObject3D.useStyle(name: String, builder: MetaBuilder.() -> Unit) {
|
||||
styleCache.getOrPut(name.toName()) {
|
||||
buildMeta(builder)
|
||||
Meta(builder)
|
||||
}
|
||||
useStyle(name)
|
||||
}
|
||||
|
@ -60,13 +60,13 @@ private fun SerialModule.enumerate(type: KClass<*>): Sequence<SerialDescriptor>
|
||||
*/
|
||||
private fun jsonSchema(descriptor: SerialDescriptor, context: SerialModule): JsonObject {
|
||||
|
||||
if (descriptor.name in arrayOf(
|
||||
if (descriptor.serialName in arrayOf(
|
||||
"hep.dataforge.vis.spatial.Point3D",
|
||||
"hep.dataforge.vis.spatial.Point2D",
|
||||
Meta::class.qualifiedName
|
||||
)
|
||||
) return json {
|
||||
"\$ref" to "#/definitions/${descriptor.name}"
|
||||
"\$ref" to "#/definitions/${descriptor.serialName}"
|
||||
}
|
||||
|
||||
|
||||
@ -109,7 +109,7 @@ private fun jsonSchema(descriptor: SerialDescriptor, context: SerialModule): Jso
|
||||
|
||||
val jsonType = descriptor.jsonType
|
||||
val objectData: MutableMap<String, JsonElement> = mutableMapOf(
|
||||
"description" to JsonLiteral(descriptor.name),
|
||||
"description" to JsonLiteral(descriptor.serialName),
|
||||
"type" to JsonLiteral(jsonType)
|
||||
)
|
||||
if (isEnum) {
|
||||
@ -140,9 +140,9 @@ fun main() {
|
||||
"children" to json {
|
||||
"anyOf" to jsonArray {
|
||||
context.enumerate(VisualObject3D::class).forEach {
|
||||
if (it.name == "hep.dataforge.vis.spatial.VisualGroup3D") {
|
||||
if (it.serialName == "hep.dataforge.vis.spatial.VisualGroup3D") {
|
||||
+json {
|
||||
"\$ref" to "#/definitions/${it.name}"
|
||||
"\$ref" to "#/definitions/${it.serialName}"
|
||||
}
|
||||
} else {
|
||||
+jsonSchema(it, context)
|
||||
|
@ -1,17 +1,12 @@
|
||||
import org.openjfx.gradle.JavaFXOptions
|
||||
import scientifik.useSerialization
|
||||
import scientifik.serialization
|
||||
|
||||
plugins {
|
||||
id("scientifik.mpp")
|
||||
id("org.openjfx.javafxplugin")
|
||||
}
|
||||
|
||||
useSerialization()
|
||||
serialization()
|
||||
|
||||
kotlin {
|
||||
jvm {
|
||||
withJava()
|
||||
}
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
@ -32,14 +27,9 @@ kotlin {
|
||||
jsMain {
|
||||
dependencies {
|
||||
// api(project(":wrappers"))
|
||||
implementation(npm("three", "0.106.2"))
|
||||
implementation(npm("@hi-level/three-csg", "1.0.6"))
|
||||
implementation(npm("three", "0.114.0"))
|
||||
implementation(npm("three-csg-ts", "1.0.1"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
configure<JavaFXOptions> {
|
||||
modules("javafx.controls")
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
package hep.dataforge.vis.spatial
|
||||
|
||||
import hep.dataforge.context.Context
|
||||
import hep.dataforge.io.serialization.ConfigSerializer
|
||||
import hep.dataforge.meta.Config
|
||||
import hep.dataforge.meta.Meta
|
||||
import hep.dataforge.meta.float
|
||||
@ -29,7 +28,6 @@ class Box(
|
||||
override var rotation: Point3D? = null
|
||||
override var scale: Point3D? = null
|
||||
|
||||
@Serializable(ConfigSerializer::class)
|
||||
override var properties: Config? = null
|
||||
|
||||
//TODO add helper for color configuration
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
package hep.dataforge.vis.spatial
|
||||
|
||||
import hep.dataforge.io.serialization.ConfigSerializer
|
||||
import hep.dataforge.meta.Config
|
||||
import hep.dataforge.meta.update
|
||||
import hep.dataforge.vis.common.AbstractVisualObject
|
||||
@ -34,7 +33,6 @@ class Composite(
|
||||
override var rotation: Point3D? = null
|
||||
override var scale: Point3D? = null
|
||||
|
||||
@Serializable(ConfigSerializer::class)
|
||||
override var properties: Config? = null
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
package hep.dataforge.vis.spatial
|
||||
|
||||
import hep.dataforge.io.serialization.ConfigSerializer
|
||||
import hep.dataforge.meta.Config
|
||||
import hep.dataforge.vis.common.AbstractVisualObject
|
||||
import hep.dataforge.vis.common.set
|
||||
@ -25,7 +24,6 @@ class ConeSegment(
|
||||
var angle: Float = PI2
|
||||
) : AbstractVisualObject(), VisualObject3D, Shape {
|
||||
|
||||
@Serializable(ConfigSerializer::class)
|
||||
override var properties: Config? = null
|
||||
|
||||
override var position: Point3D? = null
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
package hep.dataforge.vis.spatial
|
||||
|
||||
import hep.dataforge.io.serialization.ConfigSerializer
|
||||
import hep.dataforge.meta.Config
|
||||
import hep.dataforge.vis.common.AbstractVisualObject
|
||||
import hep.dataforge.vis.common.set
|
||||
@ -14,7 +13,6 @@ import kotlinx.serialization.UseSerializers
|
||||
@SerialName("3d.convex")
|
||||
class Convex(val points: List<Point3D>) : AbstractVisualObject(), VisualObject3D {
|
||||
|
||||
@Serializable(ConfigSerializer::class)
|
||||
override var properties: Config? = null
|
||||
|
||||
override var position: Point3D? = null
|
||||
|
@ -1,7 +1,6 @@
|
||||
@file:UseSerializers(Point2DSerializer::class, Point3DSerializer::class)
|
||||
package hep.dataforge.vis.spatial
|
||||
|
||||
import hep.dataforge.io.serialization.ConfigSerializer
|
||||
import hep.dataforge.meta.Config
|
||||
import hep.dataforge.vis.common.AbstractVisualObject
|
||||
import hep.dataforge.vis.common.set
|
||||
@ -45,7 +44,6 @@ class Extruded(
|
||||
var layers: MutableList<Layer> = ArrayList()
|
||||
) : AbstractVisualObject(), VisualObject3D, Shape {
|
||||
|
||||
@Serializable(ConfigSerializer::class)
|
||||
override var properties: Config? = null
|
||||
|
||||
override var position: Point3D? = null
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
package hep.dataforge.vis.spatial
|
||||
|
||||
import hep.dataforge.io.serialization.ConfigSerializer
|
||||
import hep.dataforge.meta.Config
|
||||
import hep.dataforge.vis.common.AbstractVisualObject
|
||||
import hep.dataforge.vis.common.set
|
||||
@ -12,9 +11,7 @@ import kotlinx.serialization.UseSerializers
|
||||
|
||||
@Serializable
|
||||
@SerialName("3d.label")
|
||||
class Label3D(var text: String, var fontSize: Double, var fontFamily: String) : AbstractVisualObject(),
|
||||
VisualObject3D {
|
||||
@Serializable(ConfigSerializer::class)
|
||||
class Label3D(var text: String, var fontSize: Double, var fontFamily: String) : AbstractVisualObject(), VisualObject3D {
|
||||
override var properties: Config? = null
|
||||
|
||||
override var position: Point3D? = null
|
||||
|
@ -1,16 +1,21 @@
|
||||
package hep.dataforge.vis.spatial
|
||||
|
||||
import hep.dataforge.descriptors.NodeDescriptor
|
||||
import hep.dataforge.meta.*
|
||||
import hep.dataforge.meta.descriptors.NodeDescriptor
|
||||
import hep.dataforge.meta.double
|
||||
import hep.dataforge.meta.get
|
||||
import hep.dataforge.meta.node
|
||||
import hep.dataforge.meta.scheme.*
|
||||
import hep.dataforge.meta.set
|
||||
import hep.dataforge.names.asName
|
||||
import hep.dataforge.names.plus
|
||||
import hep.dataforge.values.ValueType
|
||||
import hep.dataforge.values.asValue
|
||||
import hep.dataforge.vis.common.Colors
|
||||
import hep.dataforge.vis.spatial.Material3D.Companion.MATERIAL_COLOR_KEY
|
||||
import hep.dataforge.vis.spatial.Material3D.Companion.MATERIAL_KEY
|
||||
import hep.dataforge.vis.spatial.Material3D.Companion.MATERIAL_OPACITY_KEY
|
||||
|
||||
class Material3D(override val config: Config) : Specific {
|
||||
class Material3D : Scheme() {
|
||||
|
||||
/**
|
||||
* Primary web-color for the material
|
||||
@ -32,8 +37,7 @@ class Material3D(override val config: Config) : Specific {
|
||||
*/
|
||||
var wireframe by boolean(false, WIREFRAME_KEY)
|
||||
|
||||
companion object : Specification<Material3D> {
|
||||
override fun wrap(config: Config): Material3D = Material3D(config)
|
||||
companion object : SchemeSpec<Material3D>(::Material3D) {
|
||||
|
||||
val MATERIAL_KEY = "material".asName()
|
||||
internal val COLOR_KEY = "color".asName()
|
||||
@ -45,20 +49,20 @@ class Material3D(override val config: Config) : Specific {
|
||||
val MATERIAL_WIREFRAME_KEY = MATERIAL_KEY + WIREFRAME_KEY
|
||||
|
||||
val descriptor = NodeDescriptor {
|
||||
value(VisualObject3D.VISIBLE_KEY) {
|
||||
defineValue(VisualObject3D.VISIBLE_KEY) {
|
||||
type(ValueType.BOOLEAN)
|
||||
default(true)
|
||||
}
|
||||
node(MATERIAL_KEY) {
|
||||
value(COLOR_KEY) {
|
||||
defineNode(MATERIAL_KEY) {
|
||||
defineValue(COLOR_KEY) {
|
||||
type(ValueType.STRING, ValueType.NUMBER)
|
||||
default("#ffffff")
|
||||
}
|
||||
value(OPACITY_KEY) {
|
||||
defineValue(OPACITY_KEY) {
|
||||
type(ValueType.NUMBER)
|
||||
default(1.0)
|
||||
}
|
||||
value(WIREFRAME_KEY) {
|
||||
defineValue(WIREFRAME_KEY) {
|
||||
type(ValueType.BOOLEAN)
|
||||
default(false)
|
||||
}
|
||||
@ -71,14 +75,14 @@ class Material3D(override val config: Config) : Specific {
|
||||
* Set color as web-color
|
||||
*/
|
||||
fun VisualObject3D.color(webColor: String) {
|
||||
setProperty(MATERIAL_COLOR_KEY, webColor)
|
||||
setProperty(MATERIAL_COLOR_KEY, webColor.asValue())
|
||||
}
|
||||
|
||||
/**
|
||||
* Set color as integer
|
||||
*/
|
||||
fun VisualObject3D.color(rgb: Int) {
|
||||
setProperty(MATERIAL_COLOR_KEY, rgb)
|
||||
setProperty(MATERIAL_COLOR_KEY, rgb.asValue())
|
||||
}
|
||||
|
||||
fun VisualObject3D.color(r: UByte, g: UByte, b: UByte) = setProperty(
|
||||
@ -92,7 +96,7 @@ fun VisualObject3D.color(r: UByte, g: UByte, b: UByte) = setProperty(
|
||||
var VisualObject3D.color: String?
|
||||
get() = getProperty(MATERIAL_COLOR_KEY)?.let { Colors.fromMeta(it) }
|
||||
set(value) {
|
||||
setProperty(MATERIAL_COLOR_KEY, value)
|
||||
setProperty(MATERIAL_COLOR_KEY, value?.asValue())
|
||||
}
|
||||
|
||||
val VisualObject3D.material: Material3D?
|
||||
@ -110,5 +114,5 @@ fun VisualObject3D.material(builder: Material3D.() -> Unit) {
|
||||
var VisualObject3D.opacity: Double?
|
||||
get() = getProperty(MATERIAL_OPACITY_KEY).double
|
||||
set(value) {
|
||||
setProperty(MATERIAL_OPACITY_KEY, value)
|
||||
setProperty(MATERIAL_OPACITY_KEY, value?.asValue())
|
||||
}
|
@ -2,9 +2,8 @@
|
||||
|
||||
package hep.dataforge.vis.spatial
|
||||
|
||||
import hep.dataforge.io.serialization.ConfigSerializer
|
||||
import hep.dataforge.meta.Config
|
||||
import hep.dataforge.meta.number
|
||||
import hep.dataforge.meta.scheme.number
|
||||
import hep.dataforge.names.asName
|
||||
import hep.dataforge.names.plus
|
||||
import hep.dataforge.vis.common.AbstractVisualObject
|
||||
@ -16,7 +15,6 @@ import kotlinx.serialization.UseSerializers
|
||||
@Serializable
|
||||
@SerialName("3d.line")
|
||||
class PolyLine(var points: List<Point3D>) : AbstractVisualObject(), VisualObject3D {
|
||||
@Serializable(ConfigSerializer::class)
|
||||
override var properties: Config? = null
|
||||
|
||||
override var position: Point3D? = null
|
||||
|
@ -1,9 +1,7 @@
|
||||
@file:UseSerializers(Point3DSerializer::class, NameSerializer::class, ConfigSerializer::class)
|
||||
@file:UseSerializers(Point3DSerializer::class)
|
||||
|
||||
package hep.dataforge.vis.spatial
|
||||
|
||||
import hep.dataforge.io.serialization.ConfigSerializer
|
||||
import hep.dataforge.io.serialization.NameSerializer
|
||||
import hep.dataforge.meta.Config
|
||||
import hep.dataforge.meta.Laminate
|
||||
import hep.dataforge.meta.MetaItem
|
||||
@ -36,7 +34,6 @@ class Proxy private constructor(val templateName: Name) : AbstractVisualObject()
|
||||
override var rotation: Point3D? = null
|
||||
override var scale: Point3D? = null
|
||||
|
||||
@Serializable(ConfigSerializer::class)
|
||||
override var properties: Config? = null
|
||||
|
||||
/**
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
package hep.dataforge.vis.spatial
|
||||
|
||||
import hep.dataforge.io.serialization.ConfigSerializer
|
||||
import hep.dataforge.meta.Config
|
||||
import hep.dataforge.vis.common.AbstractVisualObject
|
||||
import hep.dataforge.vis.common.set
|
||||
@ -23,7 +22,6 @@ class Sphere(
|
||||
var theta: Float = PI.toFloat()
|
||||
) : AbstractVisualObject(), VisualObject3D, Shape {
|
||||
|
||||
@Serializable(ConfigSerializer::class)
|
||||
override var properties: Config? = null
|
||||
|
||||
override var position: Point3D? = null
|
||||
|
@ -1,7 +1,6 @@
|
||||
@file:UseSerializers(Point3DSerializer::class)
|
||||
package hep.dataforge.vis.spatial
|
||||
|
||||
import hep.dataforge.io.serialization.ConfigSerializer
|
||||
import hep.dataforge.meta.Config
|
||||
import hep.dataforge.vis.common.AbstractVisualObject
|
||||
import hep.dataforge.vis.common.set
|
||||
@ -29,7 +28,6 @@ class Tube(
|
||||
override var rotation: Point3D? = null
|
||||
override var scale: Point3D? = null
|
||||
|
||||
@Serializable(ConfigSerializer::class)
|
||||
override var properties: Config? = null
|
||||
|
||||
init {
|
||||
|
@ -4,10 +4,11 @@ import hep.dataforge.context.AbstractPlugin
|
||||
import hep.dataforge.context.Context
|
||||
import hep.dataforge.context.PluginFactory
|
||||
import hep.dataforge.context.PluginTag
|
||||
import hep.dataforge.io.serialization.ConfigSerializer
|
||||
import hep.dataforge.io.serialization.MetaSerializer
|
||||
import hep.dataforge.io.serialization.NameSerializer
|
||||
import hep.dataforge.meta.*
|
||||
import hep.dataforge.meta.Meta
|
||||
import hep.dataforge.meta.float
|
||||
import hep.dataforge.meta.get
|
||||
import hep.dataforge.meta.node
|
||||
import hep.dataforge.meta.scheme.configure
|
||||
import hep.dataforge.names.Name
|
||||
import hep.dataforge.names.toName
|
||||
import hep.dataforge.vis.common.Visual
|
||||
@ -39,10 +40,6 @@ class Visual3D(meta: Meta) : AbstractPlugin(meta) {
|
||||
val serialModule = SerializersModule {
|
||||
contextual(Point3DSerializer)
|
||||
contextual(Point2DSerializer)
|
||||
contextual(NameSerializer)
|
||||
contextual(NameTokenSerializer)
|
||||
contextual(MetaSerializer)
|
||||
contextual(ConfigSerializer)
|
||||
|
||||
polymorphic(VisualObject::class, VisualObject3D::class) {
|
||||
VisualGroup3D::class with VisualGroup3D.serializer()
|
||||
@ -52,8 +49,8 @@ class Visual3D(meta: Meta) : AbstractPlugin(meta) {
|
||||
Box::class with Box.serializer()
|
||||
Convex::class with Convex.serializer()
|
||||
Extruded::class with Extruded.serializer()
|
||||
addSubclass(PolyLine.serializer())
|
||||
addSubclass(Label3D.serializer())
|
||||
subclass(PolyLine.serializer())
|
||||
subclass(Label3D.serializer())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,16 +1,9 @@
|
||||
@file:UseSerializers(
|
||||
Point3DSerializer::class,
|
||||
ConfigSerializer::class,
|
||||
NameTokenSerializer::class,
|
||||
NameSerializer::class,
|
||||
MetaSerializer::class
|
||||
Point3DSerializer::class
|
||||
)
|
||||
|
||||
package hep.dataforge.vis.spatial
|
||||
|
||||
import hep.dataforge.io.serialization.ConfigSerializer
|
||||
import hep.dataforge.io.serialization.MetaSerializer
|
||||
import hep.dataforge.io.serialization.NameSerializer
|
||||
import hep.dataforge.meta.Config
|
||||
import hep.dataforge.names.Name
|
||||
import hep.dataforge.names.NameToken
|
||||
|
@ -1,12 +1,13 @@
|
||||
@file:UseSerializers(Point3DSerializer::class, NameSerializer::class, NameTokenSerializer::class)
|
||||
@file:UseSerializers(Point3DSerializer::class)
|
||||
|
||||
package hep.dataforge.vis.spatial
|
||||
|
||||
import hep.dataforge.io.serialization.NameSerializer
|
||||
import hep.dataforge.meta.*
|
||||
import hep.dataforge.meta.scheme.setProperty
|
||||
import hep.dataforge.names.asName
|
||||
import hep.dataforge.names.plus
|
||||
import hep.dataforge.output.Renderer
|
||||
import hep.dataforge.values.asValue
|
||||
import hep.dataforge.vis.common.VisualObject
|
||||
import hep.dataforge.vis.spatial.VisualObject3D.Companion.DETAIL_KEY
|
||||
import hep.dataforge.vis.spatial.VisualObject3D.Companion.IGNORE_KEY
|
||||
@ -64,7 +65,7 @@ interface VisualObject3D : VisualObject {
|
||||
var VisualObject3D.layer: Int
|
||||
get() = getProperty(LAYER_KEY).int ?: 0
|
||||
set(value) {
|
||||
setProperty(LAYER_KEY, value)
|
||||
setProperty(LAYER_KEY, value.asValue())
|
||||
}
|
||||
|
||||
fun Renderer<VisualObject3D>.render(meta: Meta = EmptyMeta, action: VisualGroup3D.() -> Unit) =
|
||||
@ -86,7 +87,7 @@ enum class RotationOrder {
|
||||
*/
|
||||
var VisualObject3D.rotationOrder: RotationOrder
|
||||
get() = getProperty(VisualObject3D.rotationOrder).enum<RotationOrder>() ?: RotationOrder.XYZ
|
||||
set(value) = setProperty(VisualObject3D.rotationOrder, value.name)
|
||||
set(value) = setProperty(VisualObject3D.rotationOrder, value.name.asValue())
|
||||
|
||||
|
||||
/**
|
||||
@ -94,11 +95,11 @@ var VisualObject3D.rotationOrder: RotationOrder
|
||||
*/
|
||||
var VisualObject3D.detail: Int?
|
||||
get() = getProperty(DETAIL_KEY, false).int
|
||||
set(value) = setProperty(DETAIL_KEY, value)
|
||||
set(value) = setProperty(DETAIL_KEY, value?.asValue())
|
||||
|
||||
var VisualObject.visible: Boolean?
|
||||
get() = getProperty(VISIBLE_KEY).boolean
|
||||
set(value) = setProperty(VISIBLE_KEY, value)
|
||||
set(value) = setProperty(VISIBLE_KEY, value?.asValue())
|
||||
|
||||
/**
|
||||
* If this property is true, the object will be ignored on render.
|
||||
@ -106,7 +107,7 @@ var VisualObject.visible: Boolean?
|
||||
*/
|
||||
var VisualObject.ignore: Boolean?
|
||||
get() = getProperty(IGNORE_KEY,false).boolean
|
||||
set(value) = setProperty(IGNORE_KEY, value)
|
||||
set(value) = setProperty(IGNORE_KEY, value?.asValue())
|
||||
|
||||
//var VisualObject.selected: Boolean?
|
||||
// get() = getProperty(SELECTED_KEY).boolean
|
||||
|
@ -1,7 +1,6 @@
|
||||
package hep.dataforge.vis.spatial
|
||||
|
||||
import hep.dataforge.meta.Meta
|
||||
import hep.dataforge.meta.buildMeta
|
||||
import hep.dataforge.meta.get
|
||||
import hep.dataforge.meta.number
|
||||
|
||||
@ -13,7 +12,7 @@ expect class Point2D(x: Number, y: Number) {
|
||||
operator fun Point2D.component1() = x
|
||||
operator fun Point2D.component2() = y
|
||||
|
||||
fun Point2D.toMeta() = buildMeta {
|
||||
fun Point2D.toMeta() = Meta {
|
||||
VisualObject3D.x put x
|
||||
VisualObject3D.y put y
|
||||
}
|
||||
@ -34,7 +33,7 @@ operator fun Point3D.component3() = z
|
||||
|
||||
fun Meta.point3D() = Point3D(this["x"].number ?: 0, this["y"].number ?: 0, this["y"].number ?: 0)
|
||||
|
||||
fun Point3D.toMeta() = buildMeta {
|
||||
fun Point3D.toMeta() = Meta {
|
||||
VisualObject3D.x put x
|
||||
VisualObject3D.y put y
|
||||
VisualObject3D.z put z
|
||||
|
@ -1,17 +1,14 @@
|
||||
package hep.dataforge.vis.spatial
|
||||
|
||||
import hep.dataforge.io.serialization.descriptor
|
||||
import hep.dataforge.names.NameToken
|
||||
import hep.dataforge.names.toName
|
||||
import hep.dataforge.meta.double
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.DoubleSerializer
|
||||
import kotlinx.serialization.internal.StringDescriptor
|
||||
import kotlinx.serialization.internal.nullable
|
||||
import kotlinx.serialization.builtins.nullable
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
|
||||
inline fun <R> Decoder.decodeStructure(
|
||||
desc: SerialDescriptor,
|
||||
vararg typeParams: KSerializer<*> = emptyArray(),
|
||||
crossinline block: CompositeDecoder.() -> R
|
||||
crossinline block: CompositeDecoder.() -> R
|
||||
): R {
|
||||
val decoder = beginStructure(desc, *typeParams)
|
||||
val res = decoder.block()
|
||||
@ -31,7 +28,7 @@ inline fun Encoder.encodeStructure(
|
||||
|
||||
@Serializer(Point3D::class)
|
||||
object Point3DSerializer : KSerializer<Point3D> {
|
||||
override val descriptor: SerialDescriptor = descriptor("hep.dataforge.vis.spatial.Point3D") {
|
||||
override val descriptor: SerialDescriptor = SerialDescriptor("hep.dataforge.vis.spatial.Point3D") {
|
||||
double("x", true)
|
||||
double("y", true)
|
||||
double("z", true)
|
||||
@ -45,28 +42,28 @@ object Point3DSerializer : KSerializer<Point3D> {
|
||||
loop@ while (true) {
|
||||
when (val i = decodeElementIndex(descriptor)) {
|
||||
CompositeDecoder.READ_DONE -> break@loop
|
||||
0 -> x = decodeNullableSerializableElement(descriptor, 0, DoubleSerializer.nullable) ?: 0.0
|
||||
1 -> y = decodeNullableSerializableElement(descriptor, 1, DoubleSerializer.nullable) ?: 0.0
|
||||
2 -> z = decodeNullableSerializableElement(descriptor, 2, DoubleSerializer.nullable) ?: 0.0
|
||||
0 -> x = decodeNullableSerializableElement(descriptor, 0, Double.serializer().nullable) ?: 0.0
|
||||
1 -> y = decodeNullableSerializableElement(descriptor, 1, Double.serializer().nullable) ?: 0.0
|
||||
2 -> z = decodeNullableSerializableElement(descriptor, 2, Double.serializer().nullable) ?: 0.0
|
||||
else -> throw SerializationException("Unknown index $i")
|
||||
}
|
||||
}
|
||||
}
|
||||
return Point3D(x?:0.0, y?:0.0, z?:0.0)
|
||||
return Point3D(x ?: 0.0, y ?: 0.0, z ?: 0.0)
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, obj: Point3D) {
|
||||
override fun serialize(encoder: Encoder, value: Point3D) {
|
||||
encoder.encodeStructure(descriptor) {
|
||||
if (obj.x != 0.0) encodeDoubleElement(descriptor, 0, obj.x)
|
||||
if (obj.y != 0.0) encodeDoubleElement(descriptor, 1, obj.y)
|
||||
if (obj.z != 0.0) encodeDoubleElement(descriptor, 2, obj.z)
|
||||
if (value.x != 0.0) encodeDoubleElement(descriptor, 0, value.x)
|
||||
if (value.y != 0.0) encodeDoubleElement(descriptor, 1, value.y)
|
||||
if (value.z != 0.0) encodeDoubleElement(descriptor, 2, value.z)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Serializer(Point2D::class)
|
||||
object Point2DSerializer : KSerializer<Point2D> {
|
||||
override val descriptor: SerialDescriptor = descriptor("hep.dataforge.vis.spatial.Point2D") {
|
||||
override val descriptor: SerialDescriptor = SerialDescriptor("hep.dataforge.vis.spatial.Point2D") {
|
||||
double("x", true)
|
||||
double("y", true)
|
||||
}
|
||||
@ -78,32 +75,19 @@ object Point2DSerializer : KSerializer<Point2D> {
|
||||
loop@ while (true) {
|
||||
when (val i = decodeElementIndex(descriptor)) {
|
||||
CompositeDecoder.READ_DONE -> break@loop
|
||||
0 -> x = decodeNullableSerializableElement(descriptor, 0, DoubleSerializer.nullable) ?: 0.0
|
||||
1 -> y = decodeNullableSerializableElement(descriptor, 1, DoubleSerializer.nullable) ?: 0.0
|
||||
0 -> x = decodeNullableSerializableElement(descriptor, 0, Double.serializer().nullable) ?: 0.0
|
||||
1 -> y = decodeNullableSerializableElement(descriptor, 1, Double.serializer().nullable) ?: 0.0
|
||||
else -> throw SerializationException("Unknown index $i")
|
||||
}
|
||||
}
|
||||
}
|
||||
return Point2D(x?:0.0, y?:0.0)
|
||||
return Point2D(x ?: 0.0, y ?: 0.0)
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, obj: Point2D) {
|
||||
override fun serialize(encoder: Encoder, value: Point2D) {
|
||||
encoder.encodeStructure(descriptor) {
|
||||
if (obj.x != 0.0) encodeDoubleElement(descriptor, 0, obj.x)
|
||||
if (obj.y != 0.0) encodeDoubleElement(descriptor, 1, obj.y)
|
||||
if (value.x != 0.0) encodeDoubleElement(descriptor, 0, value.x)
|
||||
if (value.y != 0.0) encodeDoubleElement(descriptor, 1, value.y)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Serializer(NameToken::class)
|
||||
object NameTokenSerializer : KSerializer<NameToken> {
|
||||
override val descriptor: SerialDescriptor = StringDescriptor.withName("NameToken")
|
||||
|
||||
override fun deserialize(decoder: Decoder): NameToken {
|
||||
return decoder.decodeString().toName().first()!!
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, obj: NameToken) {
|
||||
encoder.encodeString(obj.toString())
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package hep.dataforge.vis.spatial.specifications
|
||||
|
||||
import hep.dataforge.meta.isEmpty
|
||||
import hep.dataforge.meta.scheme.Scheme
|
||||
import hep.dataforge.meta.scheme.SchemeSpec
|
||||
import hep.dataforge.meta.scheme.boolean
|
||||
import hep.dataforge.meta.scheme.double
|
||||
|
||||
class Axes : Scheme() {
|
||||
var visible by boolean(!config.isEmpty())
|
||||
var size by double(AXIS_SIZE)
|
||||
var width by double(AXIS_WIDTH)
|
||||
|
||||
companion object : SchemeSpec<Axes>(::Axes) {
|
||||
const val AXIS_SIZE = 1000.0
|
||||
const val AXIS_WIDTH = 3.0
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package hep.dataforge.vis.spatial.specifications
|
||||
|
||||
import hep.dataforge.meta.*
|
||||
|
||||
class AxesSpec(override val config: Config) : Specific {
|
||||
var visible by boolean(!config.isEmpty())
|
||||
var size by double(AXIS_SIZE)
|
||||
var width by double(AXIS_WIDTH)
|
||||
|
||||
companion object : Specification<AxesSpec> {
|
||||
override fun wrap(config: Config): AxesSpec = AxesSpec(config)
|
||||
|
||||
const val AXIS_SIZE = 1000.0
|
||||
const val AXIS_WIDTH = 3.0
|
||||
|
||||
}
|
||||
}
|
@ -1,10 +1,14 @@
|
||||
package hep.dataforge.vis.spatial.specifications
|
||||
|
||||
import hep.dataforge.meta.*
|
||||
import hep.dataforge.meta.scheme.Scheme
|
||||
import hep.dataforge.meta.scheme.SchemeSpec
|
||||
import hep.dataforge.meta.scheme.double
|
||||
import hep.dataforge.meta.scheme.int
|
||||
import kotlin.math.PI
|
||||
|
||||
class CameraSpec(override val config: Config) : Specific {
|
||||
class Camera : Scheme() {
|
||||
var fov by int(FIELD_OF_VIEW)
|
||||
|
||||
//var aspect by double(1.0)
|
||||
var nearClip by double(NEAR_CLIP)
|
||||
var farClip by double(FAR_CLIP)
|
||||
@ -14,11 +18,10 @@ class CameraSpec(override val config: Config) : Specific {
|
||||
var latitude by double(INITIAL_LATITUDE)
|
||||
val zenith: Double get() = PI / 2 - latitude
|
||||
|
||||
companion object : Specification<CameraSpec> {
|
||||
override fun wrap(config: Config): CameraSpec = CameraSpec(config)
|
||||
companion object : SchemeSpec<Camera>(::Camera) {
|
||||
const val INITIAL_DISTANCE = 300.0
|
||||
const val INITIAL_AZIMUTH = 0.0
|
||||
const val INITIAL_LATITUDE = PI/6
|
||||
const val INITIAL_LATITUDE = PI / 6
|
||||
const val NEAR_CLIP = 0.1
|
||||
const val FAR_CLIP = 10000.0
|
||||
const val FIELD_OF_VIEW = 75
|
@ -0,0 +1,15 @@
|
||||
package hep.dataforge.vis.spatial.specifications
|
||||
|
||||
import hep.dataforge.meta.scheme.Scheme
|
||||
import hep.dataforge.meta.scheme.SchemeSpec
|
||||
import hep.dataforge.meta.scheme.int
|
||||
import hep.dataforge.meta.scheme.spec
|
||||
|
||||
class Canvas : Scheme() {
|
||||
var axes by spec(Axes, Axes.empty())
|
||||
var camera by spec(Camera, Camera.empty())
|
||||
var controls by spec(Controls, Controls.empty())
|
||||
var minSize by int(300)
|
||||
|
||||
companion object : SchemeSpec<Canvas>(::Canvas)
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
package hep.dataforge.vis.spatial.specifications
|
||||
|
||||
import hep.dataforge.meta.*
|
||||
|
||||
class CanvasSpec(override val config: Config) : Specific {
|
||||
var axes by spec(AxesSpec)
|
||||
var camera by spec(CameraSpec)
|
||||
var controls by spec(ControlsSpec)
|
||||
var minSize by int(300)
|
||||
|
||||
companion object: Specification<CanvasSpec>{
|
||||
override fun wrap(config: Config): CanvasSpec = CanvasSpec(config)
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package hep.dataforge.vis.spatial.specifications
|
||||
|
||||
import hep.dataforge.meta.scheme.Scheme
|
||||
import hep.dataforge.meta.scheme.SchemeSpec
|
||||
|
||||
|
||||
class Controls : Scheme() {
|
||||
companion object : SchemeSpec<Controls>(::Controls)
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package hep.dataforge.vis.spatial.specifications
|
||||
|
||||
import hep.dataforge.meta.Config
|
||||
import hep.dataforge.meta.Specific
|
||||
import hep.dataforge.meta.Specification
|
||||
|
||||
class ControlsSpec(override val config: Config) : Specific {
|
||||
companion object : Specification<ControlsSpec> {
|
||||
override fun wrap(config: Config): ControlsSpec = ControlsSpec(config)
|
||||
}
|
||||
}
|
@ -1,8 +1,9 @@
|
||||
package hep.dataforge.vis.spatial
|
||||
|
||||
import hep.dataforge.io.toMeta
|
||||
import hep.dataforge.meta.MetaItem
|
||||
import hep.dataforge.meta.getIndexed
|
||||
import hep.dataforge.meta.node
|
||||
import hep.dataforge.meta.toMetaItem
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@ -26,9 +27,9 @@ class ConvexTest {
|
||||
val convex = group.first() as Convex
|
||||
|
||||
val json = Visual3D.json.toJson(Convex.serializer(), convex)
|
||||
val meta = json.toMeta()
|
||||
val meta = json.toMetaItem().node!!
|
||||
|
||||
val points = meta.getIndexed("points").values.map { (it as MetaItem.NodeItem<*>).node.point3D()}
|
||||
val points = meta.getIndexed("points").values.map { (it as MetaItem.NodeItem<*>).node.point3D() }
|
||||
assertEquals(8, points.count())
|
||||
|
||||
assertEquals(8, convex.points.size)
|
||||
|
@ -2,7 +2,7 @@ package hep.dataforge.vis.spatial.three
|
||||
|
||||
import hep.dataforge.context.Context
|
||||
import hep.dataforge.meta.Meta
|
||||
import hep.dataforge.meta.get
|
||||
import hep.dataforge.meta.scheme.getProperty
|
||||
import hep.dataforge.meta.string
|
||||
import hep.dataforge.names.Name
|
||||
import hep.dataforge.names.plus
|
||||
@ -10,9 +10,9 @@ import hep.dataforge.names.toName
|
||||
import hep.dataforge.output.Renderer
|
||||
import hep.dataforge.vis.common.Colors
|
||||
import hep.dataforge.vis.spatial.VisualObject3D
|
||||
import hep.dataforge.vis.spatial.specifications.CameraSpec
|
||||
import hep.dataforge.vis.spatial.specifications.CanvasSpec
|
||||
import hep.dataforge.vis.spatial.specifications.ControlsSpec
|
||||
import hep.dataforge.vis.spatial.specifications.Camera
|
||||
import hep.dataforge.vis.spatial.specifications.Canvas
|
||||
import hep.dataforge.vis.spatial.specifications.Controls
|
||||
import hep.dataforge.vis.spatial.three.ThreeMaterials.HIGHLIGHT_MATERIAL
|
||||
import info.laht.threekt.WebGLRenderer
|
||||
import info.laht.threekt.cameras.PerspectiveCamera
|
||||
@ -39,7 +39,7 @@ import kotlin.math.sin
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class ThreeCanvas(element: HTMLElement, val three: ThreePlugin, val spec: CanvasSpec) : Renderer<VisualObject3D> {
|
||||
class ThreeCanvas(element: HTMLElement, val three: ThreePlugin, val canvas: Canvas) : Renderer<VisualObject3D> {
|
||||
|
||||
override val context: Context get() = three.context
|
||||
|
||||
@ -53,15 +53,15 @@ class ThreeCanvas(element: HTMLElement, val three: ThreePlugin, val spec: Canvas
|
||||
|
||||
var clickListener: ((Name) -> Unit)? = null
|
||||
|
||||
val axes = AxesHelper(spec.axes.size.toInt()).apply {
|
||||
visible = spec.axes.visible
|
||||
val axes = AxesHelper(canvas.axes.size.toInt()).apply {
|
||||
visible = canvas.axes.visible
|
||||
}
|
||||
|
||||
val scene: Scene = Scene().apply {
|
||||
add(axes)
|
||||
}
|
||||
|
||||
val camera = buildCamera(spec.camera)
|
||||
val camera = buildCamera(canvas.camera)
|
||||
|
||||
init {
|
||||
element.clear()
|
||||
@ -90,7 +90,7 @@ class ThreeCanvas(element: HTMLElement, val three: ThreePlugin, val spec: Canvas
|
||||
|
||||
}
|
||||
|
||||
addControls(renderer.domElement, spec.controls)
|
||||
addControls(renderer.domElement, canvas.controls)
|
||||
|
||||
fun animate() {
|
||||
val mesh = pick()
|
||||
@ -108,7 +108,7 @@ class ThreeCanvas(element: HTMLElement, val three: ThreePlugin, val spec: Canvas
|
||||
|
||||
element.appendChild(renderer.domElement)
|
||||
|
||||
renderer.setSize(max(spec.minSize, element.offsetWidth), max(spec.minSize, element.offsetWidth))
|
||||
renderer.setSize(max(canvas.minSize, element.offsetWidth), max(canvas.minSize, element.offsetWidth))
|
||||
|
||||
element.onresize = {
|
||||
renderer.setSize(element.offsetWidth, element.offsetWidth)
|
||||
@ -142,7 +142,7 @@ class ThreeCanvas(element: HTMLElement, val three: ThreePlugin, val spec: Canvas
|
||||
}
|
||||
}
|
||||
|
||||
private fun buildCamera(spec: CameraSpec) = PerspectiveCamera(
|
||||
private fun buildCamera(spec: Camera) = PerspectiveCamera(
|
||||
spec.fov,
|
||||
1.0,
|
||||
spec.nearClip,
|
||||
@ -153,8 +153,8 @@ class ThreeCanvas(element: HTMLElement, val three: ThreePlugin, val spec: Canvas
|
||||
translateZ(spec.distance * sin(spec.zenith) * cos(spec.azimuth))
|
||||
}
|
||||
|
||||
private fun addControls(element: Node, controlsSpec: ControlsSpec) {
|
||||
when (controlsSpec["type"].string) {
|
||||
private fun addControls(element: Node, controls: Controls) {
|
||||
when (controls.getProperty("type").string) {
|
||||
"trackball" -> TrackballControls(camera, element)
|
||||
else -> OrbitControls(camera, element)
|
||||
}
|
||||
@ -211,5 +211,5 @@ class ThreeCanvas(element: HTMLElement, val three: ThreePlugin, val spec: Canvas
|
||||
}
|
||||
}
|
||||
|
||||
fun ThreePlugin.output(element: HTMLElement, spec: CanvasSpec = CanvasSpec.empty()): ThreeCanvas =
|
||||
fun ThreePlugin.output(element: HTMLElement, spec: Canvas = Canvas.empty()): ThreeCanvas =
|
||||
ThreeCanvas(element, this, spec)
|
@ -2,7 +2,6 @@
|
||||
|
||||
package hep.dataforge.vis.spatial.three
|
||||
|
||||
import hep.dataforge.io.serialization.ConfigSerializer
|
||||
import hep.dataforge.meta.Config
|
||||
import hep.dataforge.vis.common.AbstractVisualObject
|
||||
import hep.dataforge.vis.spatial.Point3D
|
||||
@ -26,7 +25,6 @@ class CustomThreeVisualObject(val threeFactory: ThreeFactory<VisualObject3D>) :
|
||||
override var rotation: Point3D? = null
|
||||
override var scale: Point3D? = null
|
||||
|
||||
@Serializable(ConfigSerializer::class)
|
||||
override var properties: Config? = null
|
||||
|
||||
override fun toObject3D(): Object3D = threeFactory(this)
|
||||
|
@ -1,4 +1,4 @@
|
||||
@file:JsModule("@hi-level/three-csg")
|
||||
@file:JsModule("three-csg-ts")
|
||||
@file:JsNonModule
|
||||
@file:Suppress(
|
||||
"INTERFACE_WITH_SUPERCLASS",
|
||||
|
@ -5,7 +5,7 @@ import hep.dataforge.context.ContextAware
|
||||
import hep.dataforge.meta.Meta
|
||||
import hep.dataforge.output.Renderer
|
||||
import hep.dataforge.vis.spatial.VisualObject3D
|
||||
import hep.dataforge.vis.spatial.specifications.CanvasSpec
|
||||
import hep.dataforge.vis.spatial.specifications.Canvas
|
||||
import javafx.application.Platform
|
||||
import javafx.beans.property.ObjectProperty
|
||||
import javafx.beans.property.SimpleObjectProperty
|
||||
@ -14,7 +14,7 @@ import javafx.scene.paint.Color
|
||||
import org.fxyz3d.scene.Axes
|
||||
import tornadofx.*
|
||||
|
||||
class FXCanvas3D(val plugin: FX3DPlugin, val spec: CanvasSpec = CanvasSpec.empty()) :
|
||||
class FXCanvas3D(val plugin: FX3DPlugin, val spec: Canvas = Canvas.empty()) :
|
||||
Fragment(), Renderer<VisualObject3D>, ContextAware {
|
||||
|
||||
override val context: Context get() = plugin.context
|
||||
|
@ -1,6 +1,5 @@
|
||||
package hep.dataforge.vis.spatial.fx
|
||||
|
||||
import hep.dataforge.vis.spatial.specifications.CameraSpec
|
||||
import javafx.beans.InvalidationListener
|
||||
import javafx.beans.property.SimpleDoubleProperty
|
||||
import javafx.event.EventHandler
|
||||
@ -15,6 +14,7 @@ import javafx.scene.transform.Rotate
|
||||
import javafx.scene.transform.Translate
|
||||
import tornadofx.*
|
||||
import kotlin.math.*
|
||||
import hep.dataforge.vis.spatial.specifications.Camera as CameraSpec
|
||||
|
||||
|
||||
class OrbitControls internal constructor(camera: Camera, canvas: SubScene, spec: CameraSpec) {
|
||||
|
@ -1,11 +1,15 @@
|
||||
import org.openjfx.gradle.JavaFXOptions
|
||||
import scientifik.DependencyConfiguration
|
||||
import scientifik.FXModule
|
||||
import scientifik.fx
|
||||
|
||||
plugins {
|
||||
id("scientifik.mpp")
|
||||
id("org.openjfx.javafxplugin")
|
||||
id("application")
|
||||
}
|
||||
|
||||
val fxVersion: String by rootProject.extra
|
||||
fx(FXModule.CONTROLS, version = fxVersion, configuration = DependencyConfiguration.IMPLEMENTATION)
|
||||
|
||||
kotlin {
|
||||
|
||||
jvm {
|
||||
@ -27,18 +31,9 @@ kotlin {
|
||||
api(project(":dataforge-vis-spatial-gdml"))
|
||||
}
|
||||
}
|
||||
jvmMain{
|
||||
dependencies {
|
||||
api("org.fxyz3d:fxyz3d:0.5.2")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
application {
|
||||
mainClassName = "hep.dataforge.vis.spatial.gdml.demo.GDMLDemoAppKt"
|
||||
}
|
||||
|
||||
configure<JavaFXOptions> {
|
||||
modules("javafx.controls")
|
||||
}
|
@ -3,7 +3,7 @@ package hep.dataforge.vis.spatial.gdml.demo
|
||||
import hep.dataforge.context.Global
|
||||
import hep.dataforge.js.Application
|
||||
import hep.dataforge.js.startApplication
|
||||
import hep.dataforge.meta.buildMeta
|
||||
import hep.dataforge.meta.Meta
|
||||
import hep.dataforge.meta.withBottom
|
||||
import hep.dataforge.names.Name
|
||||
import hep.dataforge.names.isEmpty
|
||||
@ -167,7 +167,7 @@ private class GDMLDemoApp : Application {
|
||||
//val descriptorMeta = Material3D.descriptor
|
||||
|
||||
val properties = item.allProperties()
|
||||
val bottom = buildMeta {
|
||||
val bottom = Meta {
|
||||
VISIBLE_KEY put (item.visible ?: true)
|
||||
if (item is VisualObject3D) {
|
||||
MATERIAL_COLOR_KEY put "#ffffff"
|
||||
@ -186,10 +186,6 @@ private class GDMLDemoApp : Application {
|
||||
selectElement(treeName)
|
||||
canvas.highlight(treeName)
|
||||
}
|
||||
canvas.render(visual)
|
||||
|
||||
|
||||
|
||||
canvas.render(visual)
|
||||
message(null)
|
||||
spinner(false)
|
||||
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 31 KiB |
@ -10,6 +10,8 @@ import scientifik.gdml.GDML
|
||||
import java.io.File
|
||||
import java.util.zip.GZIPInputStream
|
||||
import java.util.zip.ZipInputStream
|
||||
import hep.dataforge.meta.*
|
||||
import hep.dataforge.values.*
|
||||
|
||||
fun Visual3D.Companion.readFile(file: File): VisualGroup3D = when {
|
||||
file.extension == "gdml" || file.extension == "xml" -> {
|
||||
@ -18,7 +20,7 @@ fun Visual3D.Companion.readFile(file: File): VisualGroup3D = when {
|
||||
|
||||
solidConfiguration = { parent, solid ->
|
||||
if (solid.name == "cave") {
|
||||
setProperty(Material3D.MATERIAL_WIREFRAME_KEY, true)
|
||||
setProperty(Material3D.MATERIAL_WIREFRAME_KEY, true.asValue())
|
||||
}
|
||||
if (parent.physVolumes.isNotEmpty()) {
|
||||
useStyle("opaque") {
|
||||
|
@ -1,15 +1,12 @@
|
||||
import scientifik.useSerialization
|
||||
import scientifik.jsDistDirectory
|
||||
|
||||
plugins {
|
||||
id("scientifik.mpp")
|
||||
//id("org.openjfx.javafxplugin")
|
||||
id("application")
|
||||
}
|
||||
|
||||
group = "ru.mipt.npm"
|
||||
|
||||
useSerialization()
|
||||
|
||||
val ktor_version = "1.3.0-rc"
|
||||
|
||||
kotlin {
|
||||
@ -22,7 +19,7 @@ kotlin {
|
||||
}
|
||||
}
|
||||
|
||||
val installJS = tasks.getByName<Copy>("installJsDist")
|
||||
val installJS = tasks.getByName("jsBrowserWebpack")
|
||||
|
||||
jvm {
|
||||
withJava()
|
||||
@ -30,7 +27,7 @@ kotlin {
|
||||
tasks.getByName<ProcessResources>("jvmProcessResources") {
|
||||
dependsOn(installJS)
|
||||
afterEvaluate {
|
||||
from(installJS.destinationDir)
|
||||
from(project.jsDistDirectory)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -49,8 +46,8 @@ kotlin {
|
||||
implementation("io.ktor:ktor-serialization:$ktor_version")
|
||||
}
|
||||
}
|
||||
jsMain{
|
||||
dependencies{
|
||||
jsMain {
|
||||
dependencies {
|
||||
implementation("io.ktor:ktor-client-js:$ktor_version")
|
||||
implementation("io.ktor:ktor-client-serialization-js:$ktor_version")
|
||||
implementation(npm("text-encoding"))
|
||||
|
@ -3,7 +3,7 @@ package ru.mipt.npm.muon.monitor
|
||||
import hep.dataforge.context.Global
|
||||
import hep.dataforge.js.Application
|
||||
import hep.dataforge.js.startApplication
|
||||
import hep.dataforge.meta.buildMeta
|
||||
import hep.dataforge.meta.Meta
|
||||
import hep.dataforge.meta.withBottom
|
||||
import hep.dataforge.names.Name
|
||||
import hep.dataforge.names.isEmpty
|
||||
@ -98,7 +98,7 @@ private class MMDemoApp : Application {
|
||||
//val descriptorMeta = Material3D.descriptor
|
||||
|
||||
val properties = item.allProperties()
|
||||
val bottom = buildMeta {
|
||||
val bottom = Meta {
|
||||
VISIBLE_KEY put (item.visible ?: true)
|
||||
if (item is VisualObject3D) {
|
||||
MATERIAL_COLOR_KEY put "#ffffff"
|
||||
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 31 KiB |
@ -1,11 +1,15 @@
|
||||
import org.openjfx.gradle.JavaFXOptions
|
||||
import scientifik.DependencyConfiguration
|
||||
import scientifik.FXModule
|
||||
import scientifik.fx
|
||||
|
||||
plugins {
|
||||
id("scientifik.mpp")
|
||||
id("org.openjfx.javafxplugin")
|
||||
id("application")
|
||||
}
|
||||
|
||||
val fxVersion: String by rootProject.extra
|
||||
fx(FXModule.CONTROLS, version = fxVersion, configuration = DependencyConfiguration.IMPLEMENTATION)
|
||||
|
||||
kotlin {
|
||||
|
||||
jvm {
|
||||
@ -32,8 +36,4 @@ kotlin {
|
||||
|
||||
application {
|
||||
mainClassName = "hep.dataforge.vis.spatial.demo.FXDemoAppKt"
|
||||
}
|
||||
|
||||
configure<JavaFXOptions> {
|
||||
modules("javafx.controls")
|
||||
}
|
@ -1,13 +1,13 @@
|
||||
package hep.dataforge.vis.spatial.demo
|
||||
|
||||
import hep.dataforge.meta.buildMeta
|
||||
import hep.dataforge.meta.invoke
|
||||
import hep.dataforge.meta.Meta
|
||||
import hep.dataforge.meta.scheme.invoke
|
||||
import hep.dataforge.names.toName
|
||||
import hep.dataforge.output.OutputManager
|
||||
import hep.dataforge.vis.common.Colors
|
||||
import hep.dataforge.vis.common.VisualObject
|
||||
import hep.dataforge.vis.spatial.*
|
||||
import hep.dataforge.vis.spatial.specifications.CanvasSpec
|
||||
import hep.dataforge.vis.spatial.specifications.Canvas
|
||||
import kotlinx.coroutines.*
|
||||
import kotlin.math.PI
|
||||
import kotlin.math.cos
|
||||
@ -16,14 +16,14 @@ import kotlin.random.Random
|
||||
|
||||
|
||||
fun OutputManager.demo(name: String, title: String = name, block: VisualGroup3D.() -> Unit) {
|
||||
val meta = buildMeta {
|
||||
val meta = Meta {
|
||||
"title" put title
|
||||
}
|
||||
val output = get(VisualObject::class, name.toName(), meta = meta)
|
||||
output.render(action = block)
|
||||
}
|
||||
|
||||
val canvasOptions = CanvasSpec {
|
||||
val canvasOptions = Canvas {
|
||||
minSize = 500
|
||||
axes {
|
||||
size = 500.0
|
||||
@ -31,7 +31,7 @@ val canvasOptions = CanvasSpec {
|
||||
}
|
||||
camera {
|
||||
distance = 600.0
|
||||
latitude = PI/6
|
||||
latitude = PI / 6
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,16 +2,7 @@ package hep.dataforge.vis.spatial.demo
|
||||
|
||||
import hep.dataforge.js.Application
|
||||
import hep.dataforge.js.startApplication
|
||||
import hep.dataforge.vis.spatial.three.MeshThreeFactory.Companion.EDGES_ENABLED_KEY
|
||||
import hep.dataforge.vis.spatial.three.MeshThreeFactory.Companion.WIREFRAME_ENABLED_KEY
|
||||
import hep.dataforge.vis.spatial.x
|
||||
import hep.dataforge.vis.spatial.y
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.isActive
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlin.browser.document
|
||||
import kotlin.random.Random
|
||||
|
||||
private class ThreeDemoApp : Application {
|
||||
|
||||
|
@ -3,15 +3,11 @@ package hep.dataforge.vis.spatial.demo
|
||||
import hep.dataforge.context.Global
|
||||
import hep.dataforge.meta.Meta
|
||||
import hep.dataforge.meta.get
|
||||
import hep.dataforge.meta.invoke
|
||||
import hep.dataforge.meta.string
|
||||
import hep.dataforge.names.Name
|
||||
import hep.dataforge.output.OutputManager
|
||||
import hep.dataforge.output.Renderer
|
||||
import hep.dataforge.vis.common.VisualObject
|
||||
import hep.dataforge.vis.spatial.specifications.AxesSpec
|
||||
import hep.dataforge.vis.spatial.specifications.CameraSpec
|
||||
import hep.dataforge.vis.spatial.specifications.CanvasSpec
|
||||
import hep.dataforge.vis.spatial.three.ThreeCanvas
|
||||
import hep.dataforge.vis.spatial.three.ThreePlugin
|
||||
import hep.dataforge.vis.spatial.three.output
|
||||
|
@ -9,8 +9,8 @@ import hep.dataforge.output.Renderer
|
||||
import hep.dataforge.vis.common.VisualObject
|
||||
import hep.dataforge.vis.spatial.fx.FX3DPlugin
|
||||
import hep.dataforge.vis.spatial.fx.FXCanvas3D
|
||||
import hep.dataforge.vis.spatial.specifications.AxesSpec
|
||||
import hep.dataforge.vis.spatial.specifications.CanvasSpec
|
||||
import hep.dataforge.vis.spatial.specifications.Axes as AxesSpec
|
||||
import hep.dataforge.vis.spatial.specifications.Canvas as CanvasSpec
|
||||
import javafx.collections.FXCollections
|
||||
import javafx.scene.Parent
|
||||
import javafx.scene.control.Tab
|
||||
|
Loading…
Reference in New Issue
Block a user