[WIP] Completed solid refactoring

This commit is contained in:
Alexander Nozik 2022-08-09 14:53:46 +03:00
parent 47bde02488
commit 9221df785d
No known key found for this signature in database
GPG Key ID: F7FCF2DD25C71357
53 changed files with 97 additions and 147 deletions

View File

@ -3,7 +3,7 @@ plugins {
// id("org.jetbrains.kotlinx.kover") version "0.5.0"
}
val dataforgeVersion by extra("0.6.0-dev-12")
val dataforgeVersion by extra("0.6.0-dev-13")
val fxVersion by extra("11")
allprojects{

View File

@ -5,7 +5,6 @@ import space.kscience.dataforge.meta.*
import space.kscience.dataforge.misc.Named
import space.kscience.dataforge.names.Name
import space.kscience.dataforge.names.asName
import space.kscience.dataforge.values.doubleArray
import kotlin.properties.ReadOnlyProperty
public fun MetaProvider.doubleArray(

View File

@ -1,13 +1,13 @@
package ru.mipt.npm.root
import space.kscience.dataforge.meta.double
import space.kscience.dataforge.meta.doubleArray
import space.kscience.dataforge.meta.get
import space.kscience.dataforge.meta.int
import space.kscience.dataforge.names.Name
import space.kscience.dataforge.names.plus
import space.kscience.dataforge.values.doubleArray
import space.kscience.visionforge.isEmpty
import space.kscience.visionforge.setPropertyValue
import space.kscience.visionforge.set
import space.kscience.visionforge.solid.*
import space.kscience.visionforge.solid.SolidMaterial.Companion.MATERIAL_COLOR_KEY
import kotlin.math.*
@ -321,7 +321,7 @@ private fun buildVolume(volume: DGeoVolume, context: RootToSolidContext): Solid?
}
return if (group.children.isEmpty()) {
null
} else if (group.items.size == 1 && group.meta== null) {
} else if (group.items.size == 1 && group.properties.raw == null) {
group.items.values.first().apply { parent = null }
} else {
group
@ -348,7 +348,7 @@ private fun SolidGroup.addRootVolume(
if (!cache) {
val group = buildVolume(volume, context)?.apply {
volume.fFillColor?.let {
setPropertyValue(MATERIAL_COLOR_KEY, RootColors[it])
properties[MATERIAL_COLOR_KEY] = RootColors[it]
}
block()
}
@ -365,7 +365,7 @@ private fun SolidGroup.addRootVolume(
ref(templateName, name).apply {
volume.fFillColor?.let {
setPropertyValue(MATERIAL_COLOR_KEY, RootColors[it])
properties[MATERIAL_COLOR_KEY] = RootColors[it]
}
block()
}

View File

@ -14,7 +14,7 @@ import kotlinx.serialization.modules.subclass
private fun <T> jsonRootDeserializer(
tSerializer: KSerializer<T>,
builder: (JsonElement) -> T
builder: (JsonElement) -> T,
): DeserializationStrategy<T> = object :
DeserializationStrategy<T> {
private val jsonElementSerializer = JsonElement.serializer()
@ -46,6 +46,7 @@ private object RootDecoder {
private val refCache: List<RefEntry>,
) : KSerializer<T> by tSerializer {
@OptIn(ExperimentalSerializationApi::class)
@Suppress("UNCHECKED_CAST")
override fun deserialize(decoder: Decoder): T {
val input = decoder as JsonDecoder
@ -92,7 +93,7 @@ private object RootDecoder {
@OptIn(ExperimentalSerializationApi::class)
fun unrefSerializersModule(
refCache: List<RefEntry>
refCache: List<RefEntry>,
): SerializersModule = SerializersModule {
contextual(TObjArray::class) {
@ -197,11 +198,13 @@ private object RootDecoder {
fillCache(it)
}
}
is JsonArray -> {
element.forEach {
fillCache(it)
}
}
else -> {
//ignore primitives
}

View File

@ -1,8 +1,8 @@
package space.kscience.visionforge.gdml
import space.kscience.dataforge.meta.asValue
import space.kscience.dataforge.meta.string
import space.kscience.dataforge.names.Name
import space.kscience.dataforge.values.asValue
import space.kscience.gdml.GdmlShowCase
import space.kscience.visionforge.Vision
import space.kscience.visionforge.get

View File

@ -69,7 +69,7 @@ class Model(val manager: VisionManager) {
fun reset() {
map.values.forEach {
it.setPropertyValue(SolidMaterial.MATERIAL_COLOR_KEY, null)
it.properties[SolidMaterial.MATERIAL_COLOR_KEY] = null
}
tracks.children.clear()
}

View File

@ -1,7 +1,7 @@
package space.kscience.visionforge.examples
import kotlinx.html.h2
import space.kscience.dataforge.values.ValueType
import space.kscience.dataforge.meta.ValueType
import space.kscience.plotly.layout
import space.kscience.plotly.models.ScatterMode
import space.kscience.plotly.models.TextPosition

View File

@ -6,7 +6,7 @@ import ru.mipt.npm.root.toSolid
import space.kscience.dataforge.meta.Meta
import space.kscience.dataforge.meta.get
import space.kscience.dataforge.meta.isLeaf
import space.kscience.dataforge.values.string
import space.kscience.dataforge.meta.string
import space.kscience.visionforge.solid.Solids
import java.nio.file.Paths
import java.util.zip.ZipInputStream

View File

@ -1,6 +1,6 @@
package space.kscience.visionforge.examples
import space.kscience.dataforge.values.ValueType
import space.kscience.dataforge.meta.ValueType
import space.kscience.tables.ColumnHeader
import space.kscience.tables.valueRow
import space.kscience.visionforge.html.ResourceLocation

View File

@ -3,12 +3,12 @@ package space.kscience.visionforge.solid.demo
import info.laht.threekt.core.Object3D
import info.laht.threekt.geometries.BoxGeometry
import info.laht.threekt.objects.Mesh
import space.kscience.dataforge.meta.asValue
import space.kscience.dataforge.meta.get
import space.kscience.dataforge.meta.int
import space.kscience.dataforge.meta.number
import space.kscience.dataforge.names.asName
import space.kscience.dataforge.names.startsWith
import space.kscience.dataforge.values.asValue
import space.kscience.visionforge.onPropertyChange
import space.kscience.visionforge.set
import space.kscience.visionforge.solid.SolidGroup

View File

@ -2,10 +2,10 @@ package space.kscience.visionforge.demo
import javafx.geometry.Orientation
import space.kscience.dataforge.meta.MutableMeta
import space.kscience.dataforge.meta.ValueType
import space.kscience.dataforge.meta.descriptors.MetaDescriptor
import space.kscience.dataforge.meta.descriptors.node
import space.kscience.dataforge.meta.descriptors.value
import space.kscience.dataforge.values.ValueType
import space.kscience.visionforge.editor.FXMetaModel
import space.kscience.visionforge.editor.MetaViewer
import space.kscience.visionforge.editor.MutableMetaEditor

View File

@ -10,9 +10,9 @@ import react.dom.attrs
import react.dom.option
import react.dom.select
import react.fc
import space.kscience.dataforge.meta.asValue
import space.kscience.dataforge.meta.descriptors.allowedValues
import space.kscience.dataforge.values.asValue
import space.kscience.dataforge.values.string
import space.kscience.dataforge.meta.string
@JsExport
public val MultiSelectChooser: FC<ValueChooserProps> = fc("MultiSelectChooser") { props ->

View File

@ -10,11 +10,11 @@ import react.FC
import react.dom.attrs
import react.fc
import react.useState
import space.kscience.dataforge.meta.asValue
import space.kscience.dataforge.meta.descriptors.ValueRequirement
import space.kscience.dataforge.meta.double
import space.kscience.dataforge.meta.get
import space.kscience.dataforge.meta.string
import space.kscience.dataforge.values.asValue
import styled.css
import styled.styledInput

View File

@ -19,10 +19,6 @@ import react.useState
import space.kscience.dataforge.meta.*
import space.kscience.dataforge.meta.descriptors.MetaDescriptor
import space.kscience.dataforge.meta.descriptors.allowedValues
import space.kscience.dataforge.values.ValueType
import space.kscience.dataforge.values.asValue
import space.kscience.dataforge.values.int
import space.kscience.dataforge.values.string
import space.kscience.visionforge.Colors
import space.kscience.visionforge.widgetType
import styled.css

View File

@ -1,11 +1,6 @@
package space.kscience.visionforge
import space.kscience.dataforge.meta.Meta
import space.kscience.dataforge.meta.get
import space.kscience.dataforge.meta.number
import space.kscience.dataforge.values.ValueType
import space.kscience.dataforge.values.int
import space.kscience.dataforge.values.string
import space.kscience.dataforge.meta.*
import kotlin.math.max
/**

View File

@ -5,8 +5,6 @@ import space.kscience.dataforge.names.Name
import space.kscience.dataforge.names.NameToken
import space.kscience.dataforge.names.asName
import space.kscience.dataforge.names.plus
import space.kscience.dataforge.values.asValue
import space.kscience.dataforge.values.stringList
import kotlin.jvm.JvmInline
/**

View File

@ -4,14 +4,14 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import space.kscience.dataforge.context.Global
import space.kscience.dataforge.meta.asValue
import space.kscience.dataforge.meta.boolean
import space.kscience.dataforge.meta.descriptors.Described
import space.kscience.dataforge.meta.descriptors.MetaDescriptor
import space.kscience.dataforge.misc.Type
import space.kscience.dataforge.names.Name
import space.kscience.dataforge.names.asName
import space.kscience.dataforge.names.startsWith
import space.kscience.dataforge.values.asValue
import space.kscience.dataforge.values.boolean
import space.kscience.visionforge.AbstractVisionGroup.Companion.updateProperties
import space.kscience.visionforge.Vision.Companion.TYPE
import kotlin.reflect.KProperty1

View File

@ -9,7 +9,6 @@ import kotlinx.serialization.Serializable
import space.kscience.dataforge.meta.*
import space.kscience.dataforge.names.Name
import space.kscience.dataforge.names.plus
import space.kscience.dataforge.values.Null
import kotlin.jvm.Synchronized
import kotlin.time.Duration

View File

@ -3,12 +3,12 @@ package space.kscience.visionforge
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import space.kscience.dataforge.meta.Meta
import space.kscience.dataforge.meta.ValueType
import space.kscience.dataforge.meta.descriptors.MetaDescriptor
import space.kscience.dataforge.meta.descriptors.value
import space.kscience.dataforge.names.Name
import space.kscience.dataforge.names.NameToken
import space.kscience.dataforge.names.plus
import space.kscience.dataforge.values.ValueType
import space.kscience.visionforge.Vision.Companion.STYLE_KEY
import kotlin.js.JsName

View File

@ -5,15 +5,10 @@ import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.launch
import kotlinx.serialization.Transient
import space.kscience.dataforge.meta.Meta
import space.kscience.dataforge.meta.MutableMeta
import space.kscience.dataforge.meta.asMutableMeta
import space.kscience.dataforge.meta.*
import space.kscience.dataforge.meta.descriptors.MetaDescriptor
import space.kscience.dataforge.meta.descriptors.get
import space.kscience.dataforge.meta.get
import space.kscience.dataforge.names.*
import space.kscience.dataforge.values.Value
import space.kscience.dataforge.values.asValue
import kotlin.jvm.Synchronized
public interface VisionProperties {

View File

@ -2,8 +2,7 @@ package space.kscience.visionforge
import space.kscience.dataforge.meta.*
import space.kscience.dataforge.meta.descriptors.*
import space.kscience.dataforge.values.asValue
import space.kscience.dataforge.values.set
import space.kscience.dataforge.meta.set
private const val INHERITED_DESCRIPTOR_ATTRIBUTE = "inherited"
private const val STYLE_DESCRIPTOR_ATTRIBUTE = "useStyles"

View File

@ -1,12 +1,6 @@
package space.kscience.visionforge.meta
import space.kscience.dataforge.meta.Scheme
import space.kscience.dataforge.meta.SchemeSpec
import space.kscience.dataforge.meta.int
import space.kscience.dataforge.meta.updateWith
import space.kscience.dataforge.values.asValue
import space.kscience.dataforge.values.boolean
import space.kscience.dataforge.values.int
import space.kscience.dataforge.meta.*
import space.kscience.visionforge.VisionGroup
import space.kscience.visionforge.get
import space.kscience.visionforge.getValue

View File

@ -3,13 +3,9 @@ package space.kscience.visionforge.editor
import javafx.scene.control.ColorPicker
import javafx.scene.paint.Color
import org.slf4j.LoggerFactory
import space.kscience.dataforge.meta.Meta
import space.kscience.dataforge.meta.*
import space.kscience.dataforge.names.Name
import space.kscience.dataforge.names.asName
import space.kscience.dataforge.values.Null
import space.kscience.dataforge.values.Value
import space.kscience.dataforge.values.asValue
import space.kscience.dataforge.values.string
import tornadofx.*
/**

View File

@ -8,14 +8,10 @@ package space.kscience.visionforge.editor
import javafx.collections.FXCollections
import javafx.scene.control.ComboBox
import javafx.util.StringConverter
import space.kscience.dataforge.meta.Meta
import space.kscience.dataforge.meta.*
import space.kscience.dataforge.meta.descriptors.allowedValues
import space.kscience.dataforge.meta.get
import space.kscience.dataforge.names.Name
import space.kscience.dataforge.names.asName
import space.kscience.dataforge.values.Value
import space.kscience.dataforge.values.parseValue
import space.kscience.dataforge.values.string
import java.util.*
public class ComboBoxValueChooser(public val values: Collection<Value>? = null) : ValueChooserBase<ComboBox<Value>>() {

View File

@ -5,14 +5,10 @@ import javafx.beans.binding.BooleanBinding
import javafx.beans.binding.ListBinding
import javafx.beans.binding.ObjectBinding
import javafx.collections.ObservableList
import space.kscience.dataforge.meta.Meta
import space.kscience.dataforge.meta.ObservableMeta
import space.kscience.dataforge.meta.boolean
import space.kscience.dataforge.meta.*
import space.kscience.dataforge.meta.descriptors.MetaDescriptor
import space.kscience.dataforge.meta.descriptors.get
import space.kscience.dataforge.meta.get
import space.kscience.dataforge.names.*
import space.kscience.dataforge.values.Value
import tornadofx.*
/**

View File

@ -21,7 +21,7 @@ import javafx.scene.control.TreeSortMode
import javafx.scene.control.TreeTableView
import javafx.scene.layout.BorderPane
import space.kscience.dataforge.meta.Meta
import space.kscience.dataforge.values.string
import space.kscience.dataforge.meta.string
import space.kscience.visionforge.dfIconView
import tornadofx.*

View File

@ -9,11 +9,10 @@ import javafx.beans.value.ObservableValue
import javafx.scene.control.TextField
import javafx.scene.input.KeyCode
import javafx.scene.input.KeyEvent
import space.kscience.dataforge.meta.Meta
import space.kscience.dataforge.meta.*
import space.kscience.dataforge.meta.descriptors.validate
import space.kscience.dataforge.names.Name
import space.kscience.dataforge.names.asName
import space.kscience.dataforge.values.*
import tornadofx.*
public class TextValueChooser : ValueChooserBase<TextField>() {

View File

@ -5,7 +5,7 @@
*/
package space.kscience.visionforge.editor
import space.kscience.dataforge.values.Value
import space.kscience.dataforge.meta.Value
/**

View File

@ -10,14 +10,14 @@ import javafx.beans.value.ObservableValue
import javafx.scene.Node
import space.kscience.dataforge.context.Context
import space.kscience.dataforge.meta.Meta
import space.kscience.dataforge.meta.Null
import space.kscience.dataforge.meta.Value
import space.kscience.dataforge.meta.descriptors.MetaDescriptor
import space.kscience.dataforge.meta.descriptors.allowedValues
import space.kscience.dataforge.meta.descriptors.validate
import space.kscience.dataforge.misc.Named
import space.kscience.dataforge.misc.Type
import space.kscience.dataforge.names.Name
import space.kscience.dataforge.values.Null
import space.kscience.dataforge.values.Value
import space.kscience.visionforge.widget
import space.kscience.visionforge.widgetType
import tornadofx.*

View File

@ -8,9 +8,9 @@ package space.kscience.visionforge.editor
import javafx.beans.property.SimpleObjectProperty
import javafx.scene.Node
import org.slf4j.LoggerFactory
import space.kscience.dataforge.meta.Null
import space.kscience.dataforge.meta.Value
import space.kscience.dataforge.meta.descriptors.MetaDescriptor
import space.kscience.dataforge.values.Null
import space.kscience.dataforge.values.Value
import tornadofx.*
/**

View File

@ -10,6 +10,7 @@ import space.kscience.dataforge.meta.descriptors.MetaDescriptor
import space.kscience.dataforge.names.Name
import space.kscience.visionforge.Vision
import space.kscience.visionforge.getStyle
import space.kscience.visionforge.root
import space.kscience.visionforge.styles
import tornadofx.*
@ -20,7 +21,7 @@ public class VisionEditorFragment : Fragment() {
public val descriptorProperty: SimpleObjectProperty<MetaDescriptor> = SimpleObjectProperty<MetaDescriptor>()
private val configProperty: Binding<MutableMeta?> = visionProperty.objectBinding { vision ->
vision?.getProperty(Name.EMPTY)
vision?.properties?.root()
}
private val configEditorProperty: Binding<Node?> = configProperty.objectBinding(descriptorProperty) {
@ -28,7 +29,7 @@ public class VisionEditorFragment : Fragment() {
val node:FXMetaModel<MutableMeta> = FXMetaModel(
meta,
vision?.descriptor,
vision?.meta,
vision?.properties?.root(),
Name.EMPTY,
"Vision properties"
)

View File

@ -16,6 +16,7 @@ import space.kscience.dataforge.context.*
import space.kscience.dataforge.meta.Meta
import space.kscience.dataforge.meta.boolean
import space.kscience.dataforge.misc.Type
import space.kscience.visionforge.get
import space.kscience.visionforge.solid.FX3DFactory.Companion.TYPE
import space.kscience.visionforge.solid.SolidMaterial.Companion.MATERIAL_KEY
import space.kscience.visionforge.solid.SolidMaterial.Companion.MATERIAL_WIREFRAME_KEY
@ -76,7 +77,7 @@ public class FX3DPlugin : AbstractPlugin() {
is PolyLine -> PolyLine3D(
obj.points.map { Point3D(it.x, it.y, it.z) },
obj.thickness.toFloat(),
obj.get(SolidMaterial.MATERIAL_COLOR_KEY).color()
obj.properties.get(SolidMaterial.MATERIAL_COLOR_KEY).color()
).apply {
this.meshView.cullFace = CullFace.FRONT
}

View File

@ -3,13 +3,7 @@ package space.kscience.visionforge.solid
import javafx.scene.paint.Color
import javafx.scene.paint.Material
import javafx.scene.paint.PhongMaterial
import space.kscience.dataforge.meta.Meta
import space.kscience.dataforge.meta.double
import space.kscience.dataforge.meta.get
import space.kscience.dataforge.meta.int
import space.kscience.dataforge.values.ValueType
import space.kscience.dataforge.values.int
import space.kscience.dataforge.values.string
import space.kscience.dataforge.meta.*
import space.kscience.visionforge.Colors
import space.kscience.visionforge.solid.FXMaterials.GREY

View File

@ -5,8 +5,8 @@ import javafx.beans.binding.*
import space.kscience.dataforge.meta.*
import space.kscience.dataforge.names.Name
import space.kscience.dataforge.names.startsWith
import space.kscience.dataforge.values.Value
import space.kscience.visionforge.Vision
import space.kscience.visionforge.get
import space.kscience.visionforge.onPropertyChange
import tornadofx.*
@ -35,7 +35,7 @@ public class VisualObjectFXBinding(public val fx: FX3DPlugin, public val obj: Vi
public operator fun get(key: Name): ObjectBinding<Meta?> {
return bindings.getOrPut(key) {
object : ObjectBinding<Meta?>() {
override fun computeValue(): Meta = obj.getProperty(key)
override fun computeValue(): Meta = obj.properties[key]
}
}
}
@ -57,4 +57,5 @@ public fun ObjectBinding<Meta?>.float(default: Float): FloatBinding = floatBindi
public fun ObjectBinding<Meta?>.int(default: Int): IntegerBinding = integerBinding { it.int ?: default }
public fun ObjectBinding<Meta?>.long(default: Long): LongBinding = longBinding { it.long ?: default }
public fun <T> ObjectBinding<Meta?>.transform(transform: (Meta) -> T): Binding<T?> = objectBinding { it?.let(transform) }
public fun <T> ObjectBinding<Meta?>.transform(transform: (Meta) -> T): Binding<T?> =
objectBinding { it?.let(transform) }

View File

@ -30,7 +30,7 @@ private class GdmlLoader(val settings: GdmlLoaderOptions) {
private val proto = SolidGroup()
private val solids = proto.group(solidsName) {
setPropertyValue("edges.enabled", false)
properties["edges.enabled"] = false
}
private val referenceStore = HashMap<Name, MutableList<SolidReference>>()

View File

@ -8,19 +8,19 @@ import kotlinx.serialization.modules.subclass
import space.kscience.dataforge.meta.string
import space.kscience.dataforge.names.Name
import space.kscience.dataforge.names.asName
import space.kscience.visionforge.AbstractVision
import space.kscience.visionforge.Vision
import space.kscience.visionforge.VisionGroup
import space.kscience.visionforge.properties
import space.kscience.visionforge.root
@Serializable
@SerialName("vision.markup")
public class VisionOfMarkup(
public val format: String = COMMONMARK_FORMAT
) : VisionGroup() {
public val format: String = COMMONMARK_FORMAT,
) : AbstractVision() {
//TODO add templates
public var content: String? by properties().string(CONTENT_PROPERTY_KEY)
public var content: String? by properties.root().string(CONTENT_PROPERTY_KEY)
public companion object {
public val CONTENT_PROPERTY_KEY: Name = "content".asName()

View File

@ -9,16 +9,17 @@ import space.kscience.plotly.Plot
import space.kscience.plotly.Plotly
import space.kscience.visionforge.AbstractVision
import space.kscience.visionforge.html.VisionOutput
import space.kscience.visionforge.root
@Serializable
@SerialName("vision.plotly")
public class VisionOfPlotly private constructor() : AbstractVision() {
public constructor(plot: Plot) : this() {
setProperty(Name.EMPTY, plot.meta)
properties[Name.EMPTY] = plot.meta
}
public val plot: Plot get() = Plot(getProperty(Name.EMPTY).asObservable())
public val plot: Plot get() = Plot(properties.root().asObservable())
}
public fun Plot.asVision(): VisionOfPlotly = VisionOfPlotly(this)

View File

@ -1,9 +1,9 @@
package space.kscience.visionforge.solid
import space.kscience.dataforge.meta.*
import space.kscience.dataforge.names.Name
import space.kscience.dataforge.names.asName
import space.kscience.dataforge.names.plus
import space.kscience.dataforge.values.*
import space.kscience.visionforge.Colors
import space.kscience.visionforge.Vision
import space.kscience.visionforge.VisionBuilder

View File

@ -2,11 +2,11 @@ package space.kscience.visionforge.solid
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import space.kscience.dataforge.meta.ValueType
import space.kscience.dataforge.meta.descriptors.MetaDescriptor
import space.kscience.dataforge.meta.descriptors.node
import space.kscience.dataforge.meta.descriptors.value
import space.kscience.dataforge.meta.number
import space.kscience.dataforge.values.ValueType
import space.kscience.visionforge.*
@Serializable

View File

@ -1,15 +1,13 @@
package space.kscience.visionforge.solid
import space.kscience.dataforge.meta.*
import space.kscience.dataforge.meta.descriptors.MetaDescriptor
import space.kscience.dataforge.meta.descriptors.enum
import space.kscience.dataforge.meta.descriptors.node
import space.kscience.dataforge.meta.descriptors.value
import space.kscience.dataforge.meta.float
import space.kscience.dataforge.meta.get
import space.kscience.dataforge.names.Name
import space.kscience.dataforge.names.asName
import space.kscience.dataforge.names.plus
import space.kscience.dataforge.values.*
import space.kscience.visionforge.*
import space.kscience.visionforge.Vision.Companion.VISIBLE_KEY
import space.kscience.visionforge.solid.Solid.Companion.DETAIL_KEY

View File

@ -3,13 +3,10 @@ package space.kscience.visionforge.solid
import space.kscience.dataforge.meta.*
import space.kscience.dataforge.meta.descriptors.MetaDescriptor
import space.kscience.dataforge.meta.descriptors.value
import space.kscience.dataforge.meta.set
import space.kscience.dataforge.names.Name
import space.kscience.dataforge.names.asName
import space.kscience.dataforge.names.plus
import space.kscience.dataforge.values.ValueType
import space.kscience.dataforge.values.asValue
import space.kscience.dataforge.values.number
import space.kscience.dataforge.values.set
import space.kscience.visionforge.*
import space.kscience.visionforge.solid.SolidMaterial.Companion.MATERIAL_COLOR_KEY
import space.kscience.visionforge.solid.SolidMaterial.Companion.MATERIAL_KEY

View File

@ -7,7 +7,6 @@ import kotlinx.serialization.Transient
import space.kscience.dataforge.meta.*
import space.kscience.dataforge.meta.descriptors.MetaDescriptor
import space.kscience.dataforge.names.*
import space.kscience.dataforge.values.Value
import space.kscience.visionforge.*
import space.kscience.visionforge.AbstractVisionGroup.Companion.updateProperties
import space.kscience.visionforge.solid.SolidReference.Companion.REFERENCE_CHILD_PROPERTY_PREFIX

View File

@ -4,8 +4,8 @@ import space.kscience.dataforge.meta.*
import space.kscience.dataforge.meta.descriptors.MetaDescriptor
import space.kscience.dataforge.meta.descriptors.scheme
import space.kscience.dataforge.meta.descriptors.value
import space.kscience.dataforge.meta.set
import space.kscience.dataforge.names.Name
import space.kscience.dataforge.values.set
import space.kscience.visionforge.hide
import space.kscience.visionforge.widgetType

View File

@ -1,7 +1,7 @@
package space.kscience.visionforge.solid
import space.kscience.dataforge.meta.ValueType
import space.kscience.dataforge.meta.descriptors.get
import space.kscience.dataforge.values.ValueType
import space.kscience.visionforge.solid.specifications.Canvas3DOptions
import kotlin.test.Test
import kotlin.test.assertNotNull

View File

@ -4,9 +4,9 @@ import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.withTimeout
import space.kscience.dataforge.meta.int
import space.kscience.dataforge.meta.string
import space.kscience.dataforge.names.asName
import space.kscience.dataforge.values.int
import space.kscience.dataforge.values.string
import space.kscience.visionforge.*
import kotlin.test.Test
import kotlin.test.assertEquals

View File

@ -3,8 +3,8 @@ package space.kscience.visionforge.solid
import space.kscience.dataforge.context.Global
import space.kscience.dataforge.context.fetch
import space.kscience.dataforge.meta.Meta
import space.kscience.dataforge.meta.asValue
import space.kscience.dataforge.names.asName
import space.kscience.dataforge.values.asValue
import space.kscience.visionforge.VisionChange
import space.kscience.visionforge.get
import kotlin.test.Test

View File

@ -8,13 +8,10 @@ import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import space.kscience.dataforge.meta.*
import space.kscience.dataforge.misc.DFExperimental
import space.kscience.dataforge.values.Null
import space.kscience.dataforge.values.Value
import space.kscience.dataforge.values.asValue
import space.kscience.tables.*
import space.kscience.visionforge.AbstractVision
import space.kscience.visionforge.html.VisionOutput
import space.kscience.visionforge.properties
import space.kscience.visionforge.root
import kotlin.jvm.JvmName
import kotlin.reflect.typeOf
@ -45,14 +42,14 @@ public class VisionOfTable(
) : AbstractVision(), Rows<Value> {
public var data: List<Meta>
get() = meta?.getIndexed("rows")?.entries?.sortedBy {
get() = properties.root().getIndexed("rows").entries.sortedBy {
it.key?.toInt()
}?.map {
}.map {
it.value
} ?: emptyList()
}
set(value) {
//TODO Make it better
properties()["rows"] = value
properties.root()["rows"] = value
}
public val rows: List<MetaRow> get() = data.map(::MetaRow)

View File

@ -1,9 +1,9 @@
package space.kscience.visionforge.tables
import space.kscience.dataforge.values.Value
import space.kscience.dataforge.values.asValue
import space.kscience.dataforge.values.double
import space.kscience.dataforge.values.int
import space.kscience.dataforge.meta.Value
import space.kscience.dataforge.meta.asValue
import space.kscience.dataforge.meta.double
import space.kscience.dataforge.meta.int
import space.kscience.tables.ColumnHeader
import space.kscience.tables.ColumnTable
import space.kscience.tables.get

View File

@ -10,8 +10,9 @@ import space.kscience.dataforge.names.asName
import space.kscience.dataforge.names.plus
import space.kscience.dataforge.names.startsWith
import space.kscience.visionforge.VisionBuilder
import space.kscience.visionforge.get
import space.kscience.visionforge.onPropertyChange
import space.kscience.visionforge.setPropertyValue
import space.kscience.visionforge.set
import space.kscience.visionforge.solid.Solid
import space.kscience.visionforge.solid.SolidMaterial
import space.kscience.visionforge.solid.layer
@ -76,8 +77,8 @@ public abstract class MeshThreeFactory<in T : Solid>(
@VisionBuilder
public fun Solid.edges(enabled: Boolean = true, block: SolidMaterial.() -> Unit = {}) {
setPropertyValue(EDGES_ENABLED_KEY, enabled)
SolidMaterial.write(getProperty(EDGES_MATERIAL_KEY)).apply(block)
properties.set(EDGES_ENABLED_KEY, enabled)
SolidMaterial.write(properties[EDGES_MATERIAL_KEY]).apply(block)
}
internal fun Mesh.applyProperties(obj: Solid): Mesh = apply {
@ -93,9 +94,9 @@ internal fun Mesh.applyProperties(obj: Solid): Mesh = apply {
public fun Mesh.applyEdges(obj: Solid) {
val edges = children.find { it.name == "@edges" } as? LineSegments
//inherited edges definition, enabled by default
if (obj.getProperty(EDGES_ENABLED_KEY, inherit = true).boolean != false) {
if (obj.properties.get(EDGES_ENABLED_KEY, inherit = true).boolean != false) {
val bufferGeometry = geometry as? BufferGeometry ?: return
val material = ThreeMaterials.getLineMaterial(obj.getProperty(EDGES_MATERIAL_KEY), true)
val material = ThreeMaterials.getLineMaterial(obj.properties[EDGES_MATERIAL_KEY], true)
if (edges == null) {
add(
LineSegments(

View File

@ -11,6 +11,7 @@ import org.w3c.dom.CanvasRenderingContext2D
import org.w3c.dom.CanvasTextBaseline
import org.w3c.dom.HTMLCanvasElement
import org.w3c.dom.MIDDLE
import space.kscience.visionforge.get
import space.kscience.visionforge.solid.SolidLabel
import space.kscience.visionforge.solid.SolidMaterial
import space.kscience.visionforge.solid.three.ThreeCanvas.Companion.DO_NOT_HIGHLIGHT_TAG
@ -26,7 +27,7 @@ public object ThreeCanvasLabelFactory : ThreeFactory<SolidLabel> {
val canvas = document.createElement("canvas") as HTMLCanvasElement
val context = canvas.getContext("2d") as CanvasRenderingContext2D
context.font = "Bold ${obj.fontSize}pt ${obj.fontFamily}"
context.fillStyle = obj.get(SolidMaterial.MATERIAL_COLOR_KEY)?.value ?: "black"
context.fillStyle = obj.properties[SolidMaterial.MATERIAL_COLOR_KEY].value ?: "black"
context.textBaseline = CanvasTextBaseline.MIDDLE
val metrics = context.measureText(obj.text)
//canvas.width = metrics.width.toInt()

View File

@ -6,6 +6,6 @@ import space.kscience.visionforge.solid.SolidBase
/**
* A custom visual object that has its own Three.js renderer
*/
public abstract class ThreeJsVision : SolidBase() {
public abstract class ThreeJsVision : SolidBase<ThreeJsVision>() {
public abstract fun render(three: ThreePlugin): Object3D
}

View File

@ -4,6 +4,7 @@ import info.laht.threekt.core.BufferGeometry
import info.laht.threekt.core.Object3D
import info.laht.threekt.math.Color
import info.laht.threekt.objects.LineSegments
import space.kscience.visionforge.get
import space.kscience.visionforge.onPropertyChange
import space.kscience.visionforge.solid.PolyLine
import space.kscience.visionforge.solid.SolidMaterial
@ -24,7 +25,7 @@ public object ThreeLineFactory : ThreeFactory<PolyLine> {
}
val material = ThreeMaterials.getLineMaterial(
obj.get(SolidMaterial.MATERIAL_KEY),
obj.properties[SolidMaterial.MATERIAL_KEY],
false
)

View File

@ -10,11 +10,7 @@ import space.kscience.dataforge.meta.*
import space.kscience.dataforge.names.Name
import space.kscience.dataforge.names.asName
import space.kscience.dataforge.names.plus
import space.kscience.dataforge.values.*
import space.kscience.visionforge.Colors
import space.kscience.visionforge.Vision
import space.kscience.visionforge.computePropertyNode
import space.kscience.visionforge.getStyleNodes
import space.kscience.visionforge.*
import space.kscience.visionforge.solid.ColorAccessor
import space.kscience.visionforge.solid.SolidMaterial
import space.kscience.visionforge.solid.SolidReference
@ -98,7 +94,8 @@ public object ThreeMaterials {
* Compute color
*/
public fun Meta.threeColor(): Color? {
val value = getValue(Name.EMPTY)
if(isEmpty()) return null
val value = value
return if (isLeaf) {
when {
value == null -> null
@ -132,19 +129,15 @@ private var Material.cached: Boolean
}
public fun Mesh.updateMaterial(vision: Vision) {
val ownMaterialMeta = vision.meta.getMeta(SolidMaterial.MATERIAL_KEY)
val ownMaterialMeta = vision.properties.raw?.get(SolidMaterial.MATERIAL_KEY)
if (ownMaterialMeta == null) {
if (vision is SolidReference && vision.getStyleNodes(SolidMaterial.MATERIAL_KEY).isEmpty()) {
updateMaterial(vision.prototype)
} else {
material = vision.computePropertyNode(SolidMaterial.MATERIAL_KEY)?.let {
ThreeMaterials.cacheMaterial(it)
} ?: ThreeMaterials.DEFAULT
material = ThreeMaterials.cacheMaterial(vision.properties[SolidMaterial.MATERIAL_KEY])
}
} else {
material = vision.computePropertyNode(SolidMaterial.MATERIAL_KEY)?.let {
ThreeMaterials.buildMaterial(it)
} ?: ThreeMaterials.DEFAULT
material = ThreeMaterials.buildMaterial(vision.properties[SolidMaterial.MATERIAL_KEY])
}
}
@ -159,19 +152,19 @@ public fun Mesh.updateMaterialProperty(vision: Vision, propertyName: Name) {
} else {
when (propertyName) {
SolidMaterial.MATERIAL_COLOR_KEY -> {
material.asDynamic().color = vision.computePropertyNode(SolidMaterial.MATERIAL_COLOR_KEY)?.threeColor()
material.asDynamic().color = vision.properties[SolidMaterial.MATERIAL_COLOR_KEY].threeColor()
?: ThreeMaterials.DEFAULT_COLOR
}
SolidMaterial.SPECULAR_COLOR_KEY -> {
material.asDynamic().specular = vision.computePropertyNode(SolidMaterial.SPECULAR_COLOR_KEY)?.threeColor()
material.asDynamic().specular = vision.properties[SolidMaterial.SPECULAR_COLOR_KEY].threeColor()
?: ThreeMaterials.DEFAULT_COLOR
}
SolidMaterial.MATERIAL_EMISSIVE_COLOR_KEY -> {
material.asDynamic().emissive = vision.computePropertyNode(SolidMaterial.MATERIAL_EMISSIVE_COLOR_KEY)?.threeColor()
material.asDynamic().emissive = vision.properties[SolidMaterial.MATERIAL_EMISSIVE_COLOR_KEY].threeColor()
?: ThreeMaterials.BLACK_COLOR
}
SolidMaterial.MATERIAL_OPACITY_KEY -> {
val opacity = vision.getProperty(
val opacity = vision.properties.getValue(
SolidMaterial.MATERIAL_OPACITY_KEY,
inherit = true,
)?.double ?: 1.0
@ -179,7 +172,7 @@ public fun Mesh.updateMaterialProperty(vision: Vision, propertyName: Name) {
material.transparent = opacity < 1.0
}
SolidMaterial.MATERIAL_WIREFRAME_KEY -> {
material.asDynamic().wireframe = vision.getProperty(
material.asDynamic().wireframe = vision.properties.getValue(
SolidMaterial.MATERIAL_WIREFRAME_KEY,
inherit = true,
)?.boolean ?: false