Fixed build and dependencies

This commit is contained in:
Alexander Nozik 2019-06-13 22:23:39 +03:00
parent 74e70819ee
commit fc5af5e469
16 changed files with 90 additions and 58 deletions

View File

@ -21,7 +21,7 @@ interface DisplayObject {
// */ // */
// val type: String // val type: String
val properties: MutableMeta<*> val properties: Styled
companion object { companion object {
const val DEFAULT_TYPE = "" const val DEFAULT_TYPE = ""
@ -63,15 +63,14 @@ val DisplayObject.meta: Meta get() = properties[META_KEY]?.node ?: EmptyMeta
val DisplayObject.tags: List<String> get() = properties[TAGS_KEY].stringList val DisplayObject.tags: List<String> get() = properties[TAGS_KEY].stringList
///** /**
// * Basic [DisplayObject] leaf element * Basic [DisplayObject] leaf element
// */ */
//open class DisplayLeaf( open class DisplayLeaf(
// override val parent: DisplayObject?, override val parent: DisplayObject?,
//// override val type: String, meta: Meta = EmptyMeta
// meta: Meta = EmptyMeta ) : DisplayObject {
//) : DisplayObject { final override val properties = Styled(meta)
// final override val properties = Styled(meta) }
//}
interface DisplayGroup: DisplayObject, Iterable<DisplayObject> interface DisplayGroup: DisplayObject, Iterable<DisplayObject>

View File

@ -20,7 +20,7 @@ class MetaEditorDemo : View("Meta editor demo") {
"innerNode" to { "innerNode" to {
"innerValue" to true "innerValue" to true
} }
"b" to 22 "b" to 223
"c" to "StringValue" "c" to "StringValue"
} }
}.toConfig() }.toConfig()
@ -40,6 +40,10 @@ class MetaEditorDemo : View("Meta editor demo") {
} }
} }
} }
value("multiple"){
info = "A sns value"
multiple = true
}
} }
private val rootNode = FXMeta.root(meta,descriptor) private val rootNode = FXMeta.root(meta,descriptor)

View File

@ -19,12 +19,13 @@ import org.controlsfx.glyphfont.Glyph
import tornadofx.* import tornadofx.*
/** /**
* FXML Controller class * A configuration editor fragment
* *
* @author Alexander Nozik * @author Alexander Nozik
*/ */
class ConfigEditor( class ConfigEditor(
val rootNode: FXMetaNode<Config>, val rootNode: FXMetaNode<Config>,
val allowNew: Boolean = true,
title: String = "Configuration editor" title: String = "Configuration editor"
) : Fragment(title = title, icon = dfIconView) { ) : Fragment(title = title, icon = dfIconView) {
@ -129,6 +130,7 @@ class ConfigEditor(
graphic = chooser.node graphic = chooser.node
} }
is FXMetaNode<Config> -> { is FXMetaNode<Config> -> {
if(allowNew) {
text = null text = null
graphic = hbox { graphic = hbox {
button("node", Glyph("FontAwesome", "PLUS_CIRCLE")) { button("node", Glyph("FontAwesome", "PLUS_CIRCLE")) {
@ -150,6 +152,9 @@ class ConfigEditor(
} }
} }
} }
} else {
text = ""
}
} }
} }

View File

@ -168,7 +168,7 @@ fun <M : MutableMeta<M>> FXMetaNode<M>.remove(name: NameToken) {
children.invalidate() children.invalidate()
} }
private fun <M : MutableMeta<M>> M.createEmptyNode(token: NameToken): M { private fun <M : MutableMeta<M>> M.createEmptyNode(token: NameToken, append: Boolean): M {
this.setNode(token.asName(), EmptyMeta) this.setNode(token.asName(), EmptyMeta)
//FIXME possible concurrency bug //FIXME possible concurrency bug
return get(token).node!! return get(token).node!!
@ -178,7 +178,7 @@ fun <M : MutableMeta<M>> FXMetaNode<out M>.getOrCreateNode(): M {
val node = node val node = node
return when { return when {
node != null -> node node != null -> node
parent != null -> parent.getOrCreateNode().createEmptyNode(this.name).also { parent != null -> parent.getOrCreateNode().createEmptyNode(this.name, descriptor?.multiple == true).also {
parent.children.invalidate() parent.children.invalidate()
} }
else -> kotlin.error("Orphan empty node is not allowed") else -> kotlin.error("Orphan empty node is not allowed")
@ -191,13 +191,27 @@ fun <M : MutableMeta<M>> FXMeta<M>.remove() {
} }
fun <M : MutableMeta<M>> FXMetaNode<M>.addValue(key: String) { fun <M : MutableMeta<M>> FXMetaNode<M>.addValue(key: String) {
getOrCreateNode()[key] = Null val parent = getOrCreateNode()
if(descriptor?.multiple == true){
parent.append(key, Null)
} else{
parent[key] = Null
}
} }
fun <M : MutableMeta<M>> FXMetaNode<M>.addNode(key: String) { fun <M : MutableMeta<M>> FXMetaNode<M>.addNode(key: String) {
getOrCreateNode()[key] = EmptyMeta val parent = getOrCreateNode()
if(descriptor?.multiple == true){
parent.append(key, EmptyMeta)
} else{
parent[key] = EmptyMeta
}
} }
fun <M : MutableMeta<M>> FXMetaValue<M>.set(value: Value?) { fun <M : MutableMeta<M>> FXMetaValue<M>.set(value: Value?) {
if(descriptor?.multiple == true){
parent.getOrCreateNode().append(this.name.body, value)
} else {
parent.getOrCreateNode()[this.name] = value parent.getOrCreateNode()[this.name] = value
}
} }

View File

@ -1,8 +1,11 @@
package hep.dataforge.vis package hep.dataforge.vis.spatial
import hep.dataforge.meta.* import hep.dataforge.meta.*
import hep.dataforge.names.Name import hep.dataforge.names.Name
import hep.dataforge.names.toName import hep.dataforge.names.toName
import hep.dataforge.vis.DisplayObject
import hep.dataforge.vis.getProperty
import hep.dataforge.vis.onChange
import javafx.beans.binding.ObjectBinding import javafx.beans.binding.ObjectBinding
import tornadofx.* import tornadofx.*
@ -21,7 +24,7 @@ class DisplayObjectFXListener(val obj: DisplayObject) {
operator fun get(key: Name): ObjectBinding<MetaItem<*>?> { operator fun get(key: Name): ObjectBinding<MetaItem<*>?> {
return binndings.getOrPut(key) { return binndings.getOrPut(key) {
object : ObjectBinding<MetaItem<*>?>() { object : ObjectBinding<MetaItem<*>?>() {
override fun computeValue(): MetaItem<*>? = obj.get(key) override fun computeValue(): MetaItem<*>? = obj.getProperty(key)
} }
} }
} }

View File

@ -3,7 +3,8 @@ package hep.dataforge.vis.spatial
import hep.dataforge.context.Context import hep.dataforge.context.Context
import hep.dataforge.meta.Meta import hep.dataforge.meta.Meta
import hep.dataforge.output.Output import hep.dataforge.output.Output
import hep.dataforge.vis.* import hep.dataforge.vis.DisplayGroup
import hep.dataforge.vis.DisplayObject
import javafx.scene.Group import javafx.scene.Group
import javafx.scene.Node import javafx.scene.Node
import org.fxyz3d.shapes.primitives.CuboidMesh import org.fxyz3d.shapes.primitives.CuboidMesh
@ -26,7 +27,7 @@ class FX3DOutput(override val context: Context) : Output<DisplayObject> {
org.fxyz3d.geometry.Point3D(x.value ?: 0f, y.value ?: 0f, z.value ?: 0f) org.fxyz3d.geometry.Point3D(x.value ?: 0f, y.value ?: 0f, z.value ?: 0f)
} }
return when (obj) { return when (obj) {
is DisplayGroup -> Group(obj.children.map { buildNode(it) }).apply { is DisplayGroup -> Group(obj.map { buildNode(it) }).apply {
this.translateXProperty().bind(x) this.translateXProperty().bind(x)
this.translateYProperty().bind(y) this.translateYProperty().bind(y)
this.translateZProperty().bind(z) this.translateZProperty().bind(z)

View File

@ -3,7 +3,7 @@ package hep.dataforge.vis.spatial
import hep.dataforge.meta.boolean import hep.dataforge.meta.boolean
import hep.dataforge.provider.Type import hep.dataforge.provider.Type
import hep.dataforge.vis.DisplayObject import hep.dataforge.vis.DisplayObject
import hep.dataforge.vis.get import hep.dataforge.vis.getProperty
import hep.dataforge.vis.onChange import hep.dataforge.vis.onChange
import hep.dataforge.vis.spatial.ThreeFactory.Companion.TYPE import hep.dataforge.vis.spatial.ThreeFactory.Companion.TYPE
import hep.dataforge.vis.spatial.ThreeFactory.Companion.buildMesh import hep.dataforge.vis.spatial.ThreeFactory.Companion.buildMesh
@ -20,7 +20,7 @@ import info.laht.threekt.objects.LineSegments
import info.laht.threekt.objects.Mesh import info.laht.threekt.objects.Mesh
import kotlin.reflect.KClass import kotlin.reflect.KClass
internal val DisplayObject.material get() = this["color"].material() internal val DisplayObject.material get() = getProperty("color").material()
/** /**
* Builder and updater for three.js object * Builder and updater for three.js object
@ -49,13 +49,13 @@ interface ThreeFactory<T : DisplayObject> {
internal fun buildMesh(obj: DisplayObject, geometry: BufferGeometry): Mesh { internal fun buildMesh(obj: DisplayObject, geometry: BufferGeometry): Mesh {
val mesh = Mesh(geometry, obj.material) val mesh = Mesh(geometry, obj.material)
if (obj["edges.enabled"]?.boolean != false) { if (obj.getProperty("edges.enabled")?.boolean != false) {
val material = obj["edges.material"]?.material() ?: Materials.DEFAULT val material = obj.getProperty("edges.material")?.material() ?: Materials.DEFAULT
mesh.add(LineSegments(EdgesGeometry(mesh.geometry as BufferGeometry), material)) mesh.add(LineSegments(EdgesGeometry(mesh.geometry as BufferGeometry), material))
} }
if (obj["wireframe.enabled"]?.boolean == true) { if (obj.getProperty("wireframe.enabled")?.boolean == true) {
val material = obj["edges.material"]?.material() ?: Materials.DEFAULT val material = obj.getProperty("edges.material")?.material() ?: Materials.DEFAULT
mesh.add(LineSegments(WireframeGeometry(mesh.geometry as BufferGeometry), material)) mesh.add(LineSegments(WireframeGeometry(mesh.geometry as BufferGeometry), material))
} }
return mesh return mesh

View File

@ -64,7 +64,7 @@ class ThreeOutput(override val context: Context, val meta: Meta = EmptyMeta) : O
private fun buildNode(obj: DisplayObject): Object3D? { private fun buildNode(obj: DisplayObject): Object3D? {
return when (obj) { return when (obj) {
is DisplayGroup -> Group(obj.children.mapNotNull { buildNode(it) }).apply { is DisplayGroup -> Group(obj.mapNotNull { buildNode(it) }).apply {
ThreeFactory.updatePosition(obj, this) ThreeFactory.updatePosition(obj, this)
} }
//is Box -> ThreeBoxFactory(obj) //is Box -> ThreeBoxFactory(obj)

View File

@ -16,7 +16,7 @@ import info.laht.threekt.core.BufferGeometry
class GDMLShape(parent: DisplayObject?, meta: Meta, val shape: GDMLSolid) : class GDMLShape(parent: DisplayObject?, meta: Meta, val shape: GDMLSolid) :
DisplayLeaf(parent, "$TYPE.${shape.type}", meta) { DisplayLeaf(parent, meta) {
var facesLimit by int(0) var facesLimit by int(0)

View File

@ -8,7 +8,7 @@ import hep.dataforge.vis.*
import hep.dataforge.vis.spatial.MeshThreeFactory import hep.dataforge.vis.spatial.MeshThreeFactory
import info.laht.threekt.core.BufferGeometry import info.laht.threekt.core.BufferGeometry
class JSRootGeometry(parent: DisplayObject?, meta: Meta) : DisplayLeaf(parent, TYPE, meta) { class JSRootGeometry(parent: DisplayObject?, meta: Meta) : DisplayLeaf(parent, meta) {
var shape by node() var shape by node()
@ -53,7 +53,7 @@ class JSRootGeometry(parent: DisplayObject?, meta: Meta) : DisplayLeaf(parent, T
} }
} }
fun DisplayGroup.jsRootGeometry(meta: Meta = EmptyMeta, action: JSRootGeometry.() -> Unit = {}) = fun DisplayObjectList.jsRootGeometry(meta: Meta = EmptyMeta, action: JSRootGeometry.() -> Unit = {}) =
JSRootGeometry(this, meta).apply(action).also { addChild(it) } JSRootGeometry(this, meta).apply(action).also { addChild(it) }
//fun Meta.toDynamic(): dynamic { //fun Meta.toDynamic(): dynamic {

View File

@ -3,14 +3,14 @@ package hep.dataforge.vis.spatial.jsroot
import hep.dataforge.meta.EmptyMeta import hep.dataforge.meta.EmptyMeta
import hep.dataforge.meta.Meta import hep.dataforge.meta.Meta
import hep.dataforge.meta.toDynamic import hep.dataforge.meta.toDynamic
import hep.dataforge.vis.DisplayGroup
import hep.dataforge.vis.DisplayLeaf import hep.dataforge.vis.DisplayLeaf
import hep.dataforge.vis.DisplayObject import hep.dataforge.vis.DisplayObject
import hep.dataforge.vis.DisplayObjectList
import hep.dataforge.vis.node import hep.dataforge.vis.node
import hep.dataforge.vis.spatial.ThreeFactory import hep.dataforge.vis.spatial.ThreeFactory
import info.laht.threekt.core.Object3D import info.laht.threekt.core.Object3D
class JSRootObject(parent: DisplayObject?, meta: Meta, val data: dynamic) : DisplayLeaf(parent, TYPE, meta) { class JSRootObject(parent: DisplayObject?, meta: Meta, val data: dynamic) : DisplayLeaf(parent, meta) {
var options by node() var options by node()
@ -28,7 +28,7 @@ object ThreeJSRootObjectFactory : ThreeFactory<JSRootObject> {
} }
} }
fun DisplayGroup.jsRootObject(str: String) { fun DisplayObjectList.jsRootObject(str: String) {
val json = JSON.parse<Any>(str) val json = JSON.parse<Any>(str)
JSRootObject(this, EmptyMeta, json).also { addChild(it) } JSRootObject(this, EmptyMeta, json).also { addChild(it) }
} }

View File

@ -2,10 +2,12 @@ package hep.dataforge.vis.spatial
import hep.dataforge.meta.EmptyMeta import hep.dataforge.meta.EmptyMeta
import hep.dataforge.meta.Meta import hep.dataforge.meta.Meta
import hep.dataforge.vis.DisplayLeaf
import hep.dataforge.vis.DisplayObject import hep.dataforge.vis.DisplayObject
import hep.dataforge.vis.DisplayObjectList import hep.dataforge.vis.DisplayObjectList
import hep.dataforge.vis.double
class Box(parent: DisplayObject?, meta: Meta) : DisplayLeaf(parent, TYPE, meta) { class Box(parent: DisplayObject?, meta: Meta) : DisplayLeaf(parent, meta) {
var xSize by double(1.0) var xSize by double(1.0)
var ySize by double(1.0) var ySize by double(1.0)
var zSize by double(1.0) var zSize by double(1.0)

View File

@ -2,10 +2,11 @@ package hep.dataforge.vis.spatial
import hep.dataforge.meta.* import hep.dataforge.meta.*
import hep.dataforge.names.toName import hep.dataforge.names.toName
import hep.dataforge.vis.DisplayLeaf
import hep.dataforge.vis.DisplayObject import hep.dataforge.vis.DisplayObject
import hep.dataforge.vis.DisplayObjectList import hep.dataforge.vis.DisplayObjectList
class Convex(parent: DisplayObject?, meta: Meta) : DisplayLeaf(parent, TYPE, meta) { class Convex(parent: DisplayObject?, meta: Meta) : DisplayLeaf(parent, meta) {
val points = points(properties["points"] ?: error("Vertices not defined")) val points = points(properties["points"] ?: error("Vertices not defined"))

View File

@ -2,10 +2,11 @@ package hep.dataforge.vis.spatial
import hep.dataforge.meta.* import hep.dataforge.meta.*
import hep.dataforge.names.toName import hep.dataforge.names.toName
import hep.dataforge.vis.DisplayLeaf
import hep.dataforge.vis.DisplayObject import hep.dataforge.vis.DisplayObject
import hep.dataforge.vis.DisplayObjectList import hep.dataforge.vis.DisplayObjectList
class Extruded(parent: DisplayObject?, meta: Meta) : DisplayLeaf(parent, TYPE, meta) { class Extruded(parent: DisplayObject?, meta: Meta) : DisplayLeaf(parent, meta) {
val shape get() = shape(properties["shape"] ?: error("Shape not defined")) val shape get() = shape(properties["shape"] ?: error("Shape not defined"))

View File

@ -4,16 +4,15 @@ import hep.dataforge.meta.*
import hep.dataforge.output.Output import hep.dataforge.output.Output
import hep.dataforge.vis.DisplayGroup import hep.dataforge.vis.DisplayGroup
import hep.dataforge.vis.DisplayObject import hep.dataforge.vis.DisplayObject
import hep.dataforge.vis.DisplayObject.Companion.DEFAULT_TYPE
import hep.dataforge.vis.DisplayObjectList import hep.dataforge.vis.DisplayObjectList
import hep.dataforge.vis.getProperty import hep.dataforge.vis.getProperty
fun DisplayObjectList.group(meta: Meta = EmptyMeta, action: DisplayObjectList.() -> Unit = {}): DisplayGroup = fun DisplayObjectList.group(meta: Meta = EmptyMeta, action: DisplayObjectList.() -> Unit = {}): DisplayGroup =
DisplayObjectList(this, DEFAULT_TYPE, meta).apply(action).also { addChild(it) } DisplayObjectList(this, meta).apply(action).also { addChild(it) }
fun Output<DisplayObject>.render(meta: Meta = EmptyMeta, action: DisplayObjectList.() -> Unit) = fun Output<DisplayObject>.render(meta: Meta = EmptyMeta, action: DisplayObjectList.() -> Unit) =
render(DisplayObjectList(null, DEFAULT_TYPE, EmptyMeta).apply(action), meta) render(DisplayObjectList(null, EmptyMeta).apply(action), meta)
//TODO replace properties by containers? //TODO replace properties by containers?

View File

@ -1,5 +1,8 @@
package hep.dataforge.vis.spatial package hep.dataforge.vis.spatial
import hep.dataforge.meta.get
import hep.dataforge.meta.getAll
import hep.dataforge.meta.node
import hep.dataforge.names.toName import hep.dataforge.names.toName
import hep.dataforge.vis.DisplayObjectList import hep.dataforge.vis.DisplayObjectList
import kotlin.test.Test import kotlin.test.Test