Moved to DF 0.1.4

This commit is contained in:
Alexander Nozik 2019-10-30 16:39:01 +03:00
parent 1d5debb8a6
commit 9bf438749c
22 changed files with 112 additions and 56 deletions

View File

@ -1,4 +1,4 @@
val dataforgeVersion by extra("0.1.3")
val dataforgeVersion by extra("0.1.4")
plugins {
val kotlinVersion = "1.3.50"
@ -15,6 +15,7 @@ plugins {
allprojects {
repositories {
mavenLocal()
maven("https://dl.bintray.com/pdvrieze/maven")
maven("http://maven.jzy3d.org/releases")
maven("https://kotlin.bintray.com/js-externals")

View File

@ -30,7 +30,8 @@ class VisualPlugin(meta: Meta) : AbstractPlugin(meta) {
companion object : PluginFactory<VisualPlugin> {
override val tag: PluginTag = PluginTag(name = "visual", group = PluginTag.DATAFORGE_GROUP)
override val type: KClass<out VisualPlugin> = VisualPlugin::class
override fun invoke(meta: Meta): VisualPlugin = VisualPlugin(meta)
override fun invoke(meta: Meta, context: Context): VisualPlugin = VisualPlugin(meta)
const val VISUAL_FACTORY_TYPE = "visual.factory"
}

View File

@ -96,7 +96,7 @@ class FXPlugin(meta: Meta = EmptyMeta) : AbstractPlugin(meta) {
companion object : PluginFactory<FXPlugin> {
override val type: KClass<out FXPlugin> = FXPlugin::class
override val tag: PluginTag = PluginTag("vis.fx", group = PluginTag.DATAFORGE_GROUP)
override fun invoke(meta: Meta): FXPlugin = FXPlugin(meta)
override fun invoke(meta: Meta, context: Context): FXPlugin = FXPlugin(meta)
}
}

View File

@ -84,7 +84,7 @@ class FXMetaNode<M : MetaNode<M>>(
override val hasValue: ObservableBooleanValue = nodeProperty.booleanBinding { it != null }
private val filter: (FXMeta<M>) -> Boolean = { cfg ->
!(cfg.descriptor?.tags?.contains(ConfigEditor.NO_CONFIGURATOR_TAG) ?: false)
!(cfg.descriptor?.attributes?.get(ConfigEditor.NO_CONFIGURATOR_TAG)?.boolean ?: false)
}
val children = object : ListBinding<FXMeta<M>>() {
@ -172,7 +172,7 @@ fun <M : MutableMeta<M>> FXMetaNode<M>.remove(name: NameToken) {
private fun <M : MutableMeta<M>> M.createEmptyNode(token: NameToken, append: Boolean): M {
return if (append && token.index.isNotEmpty()) {
val name = token.asName()
val index = (getAll(name).keys.mapNotNull { it.toIntOrNull() }.max() ?: -1) + 1
val index = (getIndexed(name).keys.mapNotNull { it.toIntOrNull() }.max() ?: -1) + 1
val newName = name.withIndex(index.toString())
set(newName, EmptyMeta)
get(newName).node!!

View File

@ -1,6 +1,8 @@
package hep.dataforge.vis.fx.values
import hep.dataforge.meta.Meta
import hep.dataforge.names.Name
import hep.dataforge.names.asName
import hep.dataforge.values.Null
import hep.dataforge.values.Value
import hep.dataforge.values.asValue
@ -39,8 +41,8 @@ class ColorValueChooser : ValueChooserBase<ColorPicker>() {
return node
}
companion object: ValueChooser.Factory{
override val name: String = "color"
companion object : ValueChooser.Factory {
override val name: Name = "color".asName()
override fun invoke(meta: Meta): ValueChooser = ColorValueChooser()
}

View File

@ -8,6 +8,8 @@ package hep.dataforge.vis.fx.values
import hep.dataforge.meta.Meta
import hep.dataforge.meta.get
import hep.dataforge.meta.value
import hep.dataforge.names.Name
import hep.dataforge.names.asName
import hep.dataforge.values.Value
import hep.dataforge.values.parseValue
import javafx.collections.FXCollections
@ -50,7 +52,7 @@ class ComboBoxValueChooser(val values: Collection<Value>? = null) : ValueChooser
}
companion object : ValueChooser.Factory {
override val name: String = "combo"
override val name: Name = "combo".asName()
override fun invoke(meta: Meta): ValueChooser = ComboBoxValueChooser(meta["values"].value?.list)
}

View File

@ -6,6 +6,8 @@
package hep.dataforge.vis.fx.values
import hep.dataforge.meta.Meta
import hep.dataforge.names.Name
import hep.dataforge.names.asName
import hep.dataforge.values.*
import javafx.beans.value.ObservableValue
import javafx.scene.control.TextField
@ -100,7 +102,7 @@ class TextValueChooser : ValueChooserBase<TextField>() {
}
companion object : ValueChooser.Factory {
override val name: String = "text"
override val name: Name = "text".asName()
override fun invoke(meta: Meta): ValueChooser = TextValueChooser()
}
}

View File

@ -10,6 +10,7 @@ import hep.dataforge.context.Named
import hep.dataforge.descriptors.ValueDescriptor
import hep.dataforge.meta.EmptyMeta
import hep.dataforge.meta.Meta
import hep.dataforge.names.toName
import hep.dataforge.provider.Type
import hep.dataforge.provider.provideByType
import hep.dataforge.values.Null
@ -71,7 +72,7 @@ interface ValueChooser {
companion object {
private fun findWidgetByType(context: Context, type: String): Factory? {
return when (type) {
return when (type.toName()) {
TextValueChooser.name -> TextValueChooser
ColorValueChooser.name -> ColorValueChooser
ComboBoxValueChooser.name -> ComboBoxValueChooser

View File

@ -29,7 +29,7 @@ class GDMLTransformer(val root: GDML) {
/**
* A special group for local templates
*/
val templates by lazy { VisualGroup3D() }
val proto by lazy { VisualGroup3D() }
private val styleCache = HashMap<Name, Meta>()
var lUnit: LUnit = LUnit.MM
@ -67,7 +67,7 @@ class GDMLTransformer(val root: GDML) {
var onFinish: GDMLTransformer.() -> Unit = {}
internal fun finalize(final: VisualGroup3D): VisualGroup3D {
final.templates = templates
final.prototypes = proto
styleCache.forEach {
final.addStyle(it.key, it.value, false)
}

View File

@ -161,8 +161,8 @@ private fun VisualGroup3D.addPhysicalVolume(
}
GDMLTransformer.Action.CACHE -> {
val fullName = volumesName + volume.name.asName()
if (context.templates[fullName] == null) {
context.templates[fullName] = volume(context, volume)
if (context.proto[fullName] == null) {
context.proto[fullName] = volume(context, volume)
}
this[physVolume.name ?: ""] = Proxy(fullName).apply {
@ -215,8 +215,8 @@ private fun volume(
}
}
GDMLTransformer.Action.CACHE -> {
if (context.templates[solid.name] == null) {
context.templates.addSolid(context, solid, solid.name) {
if (context.proto[solid.name] == null) {
context.proto.addSolid(context, solid, solid.name) {
context.configureSolid(this, group, solid)
}
}

View File

@ -119,14 +119,14 @@ private class GDMLDemoApp : Application {
val three = context.plugins.load(ThreePlugin)
//val url = URL("https://drive.google.com/open?id=1w5e7fILMN83JGgB8WANJUYm8OW2s0WVO")
val canvas = document.getElementById("canvas") ?: error("Element with id 'canvas' not found on page")
val layers = document.getElementById("layers") ?: error("Element with id 'layers' not found on page")
val tree = document.getElementById("tree") ?: error("Element with id 'tree' not found on page")
val editor = document.getElementById("editor") ?: error("Element with id 'editor' not found on page")
canvas.clear()
val canvasElement = document.getElementById("canvas") ?: error("Element with id 'canvas' not found on page")
val configElement = document.getElementById("layers") ?: error("Element with id 'layers' not found on page")
val treeElement = document.getElementById("tree") ?: error("Element with id 'tree' not found on page")
val editorElement = document.getElementById("editor") ?: error("Element with id 'editor' not found on page")
canvasElement.clear()
val action: (name: String, data: String) -> Unit = { name, data ->
canvas.clear()
canvasElement.clear()
spinner(true)
message("Loading GDML")
val gdml = GDML.format.parse(GDML.serializer(), data)
@ -149,12 +149,12 @@ private class GDMLDemoApp : Application {
message("Rendering")
//output.camera.layers.enable(1)
val output = three.output(canvas as HTMLElement)
val output = three.output(canvasElement as HTMLElement)
output.camera.layers.set(0)
layers.threeOutputConfig(output)
configElement.threeOutputConfig(output)
//tree.visualObjectTree(visual, editor::propertyEditor)
tree.objectTree(NameToken("World"),visual, editor::propertyEditor)
treeElement.objectTree(NameToken("World"),visual, editorElement::propertyEditor)
output.render(visual)

View File

@ -0,0 +1,16 @@
package hep.dataforge.vis.spatial.gdml
import hep.dataforge.names.toName
import hep.dataforge.vis.spatial.*
fun main() {
val vis = VisualGroup3D().apply {
val box = Box(100f, 100f, 20f).apply {
color(0u, 0u, 255u)
}
proxy("some.name".toName(), box, "obj")
}
val string = Visual3DPlugin.json.stringify(VisualGroup3D.serializer(),vis)
println(string)
}

View File

@ -21,7 +21,6 @@ kotlin {
}
jvmMain {
dependencies {
implementation(project(":dataforge-vis-fx"))
implementation("org.fxyz3d:fxyz3d:0.5.2")
}
}

View File

@ -3,7 +3,8 @@
package hep.dataforge.vis.spatial
import hep.dataforge.io.ConfigSerializer
import hep.dataforge.io.NameSerializer
import hep.dataforge.io.serialization.NameSerializer
import hep.dataforge.meta.*
import hep.dataforge.names.Name
import hep.dataforge.names.NameToken
@ -36,7 +37,7 @@ class Proxy(val templateName: Name) : AbstractVisualObject(), VisualGroup, Visua
* Recursively search for defined template in the parent
*/
val prototype: VisualObject3D
get() = (parent as? VisualGroup3D)?.getTemplate(templateName)
get() = (parent as? VisualGroup3D)?.getPrototype(templateName)
?: error("Template with name $templateName not found in $parent")
override fun getStyle(name: Name): Meta? = (parent as VisualGroup?)?.getStyle(name)
@ -65,9 +66,11 @@ class Proxy(val templateName: Name) : AbstractVisualObject(), VisualGroup, Visua
}
override val children: Map<NameToken, ProxyChild>
get() = (prototype as? MutableVisualGroup)?.children?.mapValues {
ProxyChild(it.key.asName())
} ?: emptyMap()
get() = (prototype as? MutableVisualGroup)?.children
?.filter { !it.key.toString().startsWith("@") }
?.mapValues {
ProxyChild(it.key.asName())
} ?: emptyMap()
private val propertyCache: HashMap<Name, Config> = HashMap()
@ -152,8 +155,30 @@ val VisualObject.prototype: VisualObject?
else -> null
}
/**
* Create ref for existing prototype
*/
inline fun VisualGroup3D.ref(
templateName: Name,
name: String = "",
action: Proxy.() -> Unit = {}
) = Proxy(templateName).apply(action).also { set(name, it) }
block: Proxy.() -> Unit = {}
) = Proxy(templateName).apply(block).also { set(name, it) }
/**
* Add new proxy wrapping given object and automatically adding it to the prototypes
*/
fun VisualGroup3D.proxy(
templateName: Name,
obj: VisualObject3D,
name: String = "",
attachToParent: Boolean = false,
block: Proxy.() -> Unit = {}
): Proxy {
val existing = getPrototype(templateName)
if (existing == null) {
setPrototype(templateName,obj, attachToParent)
} else if(existing != obj) {
error("Can't add different prototype on top of existing one")
}
return ref(templateName, name, block)
}

View File

@ -1,11 +1,12 @@
package hep.dataforge.vis.spatial
import hep.dataforge.context.AbstractPlugin
import hep.dataforge.context.Context
import hep.dataforge.context.PluginFactory
import hep.dataforge.context.PluginTag
import hep.dataforge.io.ConfigSerializer
import hep.dataforge.io.MetaSerializer
import hep.dataforge.io.NameSerializer
import hep.dataforge.io.serialization.NameSerializer
import hep.dataforge.meta.*
import hep.dataforge.names.Name
import hep.dataforge.vis.common.VisualObject
@ -30,7 +31,7 @@ class Visual3DPlugin(meta: Meta) : AbstractPlugin(meta) {
companion object : PluginFactory<Visual3DPlugin> {
override val tag: PluginTag = PluginTag(name = "visual.spatial", group = PluginTag.DATAFORGE_GROUP)
override val type: KClass<out Visual3DPlugin> = Visual3DPlugin::class
override fun invoke(meta: Meta): Visual3DPlugin = Visual3DPlugin(meta)
override fun invoke(meta: Meta, context: Context): Visual3DPlugin = Visual3DPlugin(meta)
val serialModule = SerializersModule {
contextual(Point3DSerializer)

View File

@ -10,7 +10,7 @@ package hep.dataforge.vis.spatial
import hep.dataforge.io.ConfigSerializer
import hep.dataforge.io.MetaSerializer
import hep.dataforge.io.NameSerializer
import hep.dataforge.io.serialization.NameSerializer
import hep.dataforge.meta.Config
import hep.dataforge.meta.Meta
import hep.dataforge.meta.MetaBuilder
@ -32,7 +32,8 @@ class VisualGroup3D : AbstractVisualGroup(), VisualObject3D {
/**
* A container for templates visible inside this group
*/
var templates: VisualGroup3D? = null
@SerialName(PROTOTYPES_KEY)
var prototypes: VisualGroup3D? = null
set(value) {
value?.parent = this
field = value
@ -85,18 +86,26 @@ class VisualGroup3D : AbstractVisualGroup(), VisualObject3D {
}
}
fun getTemplate(name: Name): VisualObject3D? =
templates?.get(name) as? VisualObject3D
?: (parent as? VisualGroup3D)?.getTemplate(name)
fun getPrototype(name: Name): VisualObject3D? =
prototypes?.get(name) as? VisualObject3D ?: (parent as? VisualGroup3D)?.getPrototype(name)
fun setPrototype(name: Name, obj: VisualObject3D, attachToParent: Boolean = false) {
val parent = this.parent
if (attachToParent && parent is VisualGroup3D) {
parent.setPrototype(name, obj, attachToParent)
} else {
(prototypes ?: VisualGroup3D().also { this.prototypes = it }).set(name, obj)
}
}
override fun MetaBuilder.updateMeta() {
set(TEMPLATES_KEY, templates?.toMeta())
set(PROTOTYPES_KEY, prototypes?.toMeta())
updatePosition()
updateChildren()
}
companion object {
const val TEMPLATES_KEY = "templates"
const val PROTOTYPES_KEY = "templates"
}
}
@ -109,7 +118,7 @@ fun VisualGroup.attachChildren() {
(it as? VisualGroup)?.attachChildren()
}
if (this is VisualGroup3D) {
templates?.also {
prototypes?.also {
it.parent = this
it.attachChildren()
}

View File

@ -2,15 +2,15 @@
package hep.dataforge.vis.spatial
import hep.dataforge.io.NameSerializer
import hep.dataforge.io.serialization.NameSerializer
import hep.dataforge.meta.*
import hep.dataforge.names.asName
import hep.dataforge.names.plus
import hep.dataforge.output.Output
import hep.dataforge.vis.common.VisualObject
import hep.dataforge.vis.spatial.VisualObject3D.Companion.DETAIL_KEY
import hep.dataforge.vis.spatial.VisualObject3D.Companion.LAYER_KEY
import hep.dataforge.vis.spatial.VisualObject3D.Companion.IGNORE_KEY
import hep.dataforge.vis.spatial.VisualObject3D.Companion.LAYER_KEY
import hep.dataforge.vis.spatial.VisualObject3D.Companion.SELECTED_KEY
import hep.dataforge.vis.spatial.VisualObject3D.Companion.VISIBLE_KEY
import kotlinx.serialization.UseSerializers

View File

@ -49,7 +49,7 @@ object RemoveSingleChild : VisualTreeTransform<VisualGroup3D>() {
}
replaceChildren()
templates?.replaceChildren()
prototypes?.replaceChildren()
}
override fun VisualGroup3D.clone(): VisualGroup3D {

View File

@ -24,7 +24,7 @@ object UnRef : VisualTreeTransform<VisualGroup3D>() {
}
private fun MutableVisualGroup.unref(name: Name) {
(this as? VisualGroup3D)?.templates?.set(name, null)
(this as? VisualGroup3D)?.prototypes?.set(name, null)
children.filter { (it.value as? Proxy)?.templateName == name }.forEach { (key, value) ->
val proxy = value as Proxy
val newChild = mergeChild(proxy, proxy.prototype)

View File

@ -1,9 +1,6 @@
package hep.dataforge.vis.spatial.three
import hep.dataforge.context.AbstractPlugin
import hep.dataforge.context.PluginFactory
import hep.dataforge.context.PluginTag
import hep.dataforge.context.content
import hep.dataforge.context.*
import hep.dataforge.meta.Meta
import hep.dataforge.names.Name
import hep.dataforge.names.asName
@ -88,7 +85,7 @@ class ThreePlugin : AbstractPlugin() {
companion object : PluginFactory<ThreePlugin> {
override val tag = PluginTag("visual.three", PluginTag.DATAFORGE_GROUP)
override val type = ThreePlugin::class
override fun invoke(meta: Meta) = ThreePlugin()
override fun invoke(meta: Meta,context: Context) = ThreePlugin()
}
}

View File

@ -79,7 +79,7 @@ class ThreeDemoGrid(meta: Meta) : AbstractPlugin(meta), OutputManager {
override val type: KClass<out ThreeDemoGrid> = ThreeDemoGrid::class
override fun invoke(meta: Meta): ThreeDemoGrid = ThreeDemoGrid(meta)
override fun invoke(meta: Meta,context: Context): ThreeDemoGrid = ThreeDemoGrid(meta)
}
}

View File

@ -13,8 +13,8 @@ kotlin{
sourceSets["main"].apply{
dependencies{
api(npm("style-loader"))
api(npm("inspire-tree","6.0.1"))
api(npm("inspire-tree-dom","4.0.6"))
// api(npm("inspire-tree","6.0.1"))
// api(npm("inspire-tree-dom","4.0.6"))
api(npm("jsoneditor"))
api(npm("dat.gui"))
//api("org.jetbrains:kotlin-extensions:1.0.1-pre.83-kotlin-1.3.50")