Temporary property editor

This commit is contained in:
Alexander Nozik 2019-10-02 22:02:26 +03:00
parent d1e2d8d60b
commit 39ca362aa8
5 changed files with 39 additions and 16 deletions

View File

@ -18,6 +18,7 @@ allprojects {
jcenter() jcenter()
maven("https://kotlin.bintray.com/kotlinx") maven("https://kotlin.bintray.com/kotlinx")
maven("https://kotlin.bintray.com/js-externals") maven("https://kotlin.bintray.com/js-externals")
maven("https://kotlin.bintray.com/kotlin-js-wrappers")
maven("https://dl.bintray.com/pdvrieze/maven") maven("https://dl.bintray.com/pdvrieze/maven")
maven("https://dl.bintray.com/kotlin/kotlin-eap") maven("https://dl.bintray.com/kotlin/kotlin-eap")
} }

View File

@ -34,6 +34,8 @@ kotlin {
implementation(npm("inspire-tree","6.0.1")) implementation(npm("inspire-tree","6.0.1"))
implementation(npm("inspire-tree-dom","4.0.6")) implementation(npm("inspire-tree-dom","4.0.6"))
implementation(npm("jsoneditor")) implementation(npm("jsoneditor"))
// api("org.jetbrains:kotlin-extensions:1.0.1-pre.83-kotlin-1.3.50")
// api(npm("core-js"))
} }
} }
} }

View File

@ -110,6 +110,12 @@ class Proxy(val templateName: Name) : AbstractVisualObject(), VisualGroup, Visua
} }
} }
val VisualObject.prototype: VisualObject? get() = when(this){
is Proxy -> prototype
is Proxy.ProxyChild -> prototype
else -> null
}
inline fun VisualGroup3D.ref( inline fun VisualGroup3D.ref(
templateName: Name, templateName: Name,
name: String = "", name: String = "",

View File

@ -113,8 +113,8 @@ var VisualObject.material: Meta?
get() = getProperty(MATERIAL_KEY).node get() = getProperty(MATERIAL_KEY).node
set(value) = setProperty(MATERIAL_KEY, value) set(value) = setProperty(MATERIAL_KEY, value)
var VisualObject.opacity: Double var VisualObject.opacity: Double?
get() = getProperty(OPACITY_KEY).double ?: 1.0 get() = getProperty(OPACITY_KEY).double
set(value) { set(value) {
setProperty(OPACITY_KEY, value) setProperty(OPACITY_KEY, value)
} }

View File

@ -1,10 +1,16 @@
package hep.dataforge.vis.spatial.tree package hep.dataforge.vis.spatial.tree
import hep.dataforge.io.toJson import hep.dataforge.io.toJson
import hep.dataforge.meta.DynamicMeta
import hep.dataforge.meta.builder
import hep.dataforge.meta.update
import hep.dataforge.vis.common.VisualObject import hep.dataforge.vis.common.VisualObject
import hep.dataforge.vis.spatial.Proxy import hep.dataforge.vis.spatial.VisualObject3D.Companion.COLOR_KEY
import hep.dataforge.vis.spatial.VisualObject3D.Companion.OPACITY_KEY
import hep.dataforge.vis.spatial.VisualObject3D.Companion.VISIBLE_KEY
import hep.dataforge.vis.spatial.color import hep.dataforge.vis.spatial.color
import hep.dataforge.vis.spatial.opacity import hep.dataforge.vis.spatial.opacity
import hep.dataforge.vis.spatial.prototype
import hep.dataforge.vis.spatial.visible import hep.dataforge.vis.spatial.visible
import kotlinx.html.InputType import kotlinx.html.InputType
import kotlinx.html.dom.append import kotlinx.html.dom.append
@ -18,7 +24,9 @@ fun Element.propertyEditor(item: VisualObject?, name: String?) {
append { append {
div("card") { div("card") {
div("card-body") { div("card-body") {
h3(classes = "card-title") { +(name ?: "") } h3(classes = "card-title") {
+(name ?: "")
}
form { form {
div("form-group row") { div("form-group row") {
label("col-form-label col-4") { label("col-form-label col-4") {
@ -64,18 +72,24 @@ fun Element.propertyEditor(item: VisualObject?, name: String?) {
} }
} }
} }
(item.properties ?: (item as? Proxy)?.prototype?.properties (item.properties ?: item.prototype?.properties)?.let { config ->
?: (item as? Proxy.ProxyChild)?.prototype?.properties)
?.let { config ->
div("card") { div("card") {
div("card-body") { div("card-body") {
h3(classes = "card-title") { +"Properties" } h3(classes = "card-title") { +"Properties" }
}.apply { }.apply {
val metaToEdit = config.builder().apply {
VISIBLE_KEY to (item.visible ?: true)
COLOR_KEY to (item.color ?: "#ffffff")
OPACITY_KEY to (item.opacity ?: 1.0)
}
//FIXME something rotten in JS-Meta converter
val jsObject: dynamic = JSON.parse(metaToEdit.toJson().toString())
//jsObject.material.color != null
val options = (js("{}") as JSONEditorOptions).apply { val options = (js("{}") as JSONEditorOptions).apply {
mode = "view" mode = "form"
onChangeJSON = { item.config.update(DynamicMeta(it.asDynamic())) }
} }
JSONEditor(this, options, JSON.parse(config.toJson().toString())) JSONEditor(this, options, jsObject)
} }
} }
} }