Class name refactoring

This commit is contained in:
Alexander Nozik 2020-08-05 22:22:24 +03:00
parent 37cda0010a
commit 3217a53dd6
55 changed files with 294 additions and 294 deletions

View File

@ -3,14 +3,14 @@ package hep.dataforge.vision.spatial.gdml.demo
import hep.dataforge.context.Context import hep.dataforge.context.Context
import hep.dataforge.names.Name import hep.dataforge.names.Name
import hep.dataforge.names.isEmpty import hep.dataforge.names.isEmpty
import hep.dataforge.vision.VisualGroup import hep.dataforge.vision.Vision
import hep.dataforge.vision.VisualObject import hep.dataforge.vision.VisionGroup
import hep.dataforge.vision.bootstrap.* import hep.dataforge.vision.bootstrap.*
import hep.dataforge.vision.react.component import hep.dataforge.vision.react.component
import hep.dataforge.vision.react.configEditor import hep.dataforge.vision.react.configEditor
import hep.dataforge.vision.react.flexColumn import hep.dataforge.vision.react.flexColumn
import hep.dataforge.vision.react.state import hep.dataforge.vision.react.state
import hep.dataforge.vision.spatial.VisualGroup3D import hep.dataforge.vision.spatial.VisionGroup3D
import hep.dataforge.vision.spatial.VisualObject3D import hep.dataforge.vision.spatial.VisualObject3D
import hep.dataforge.vision.spatial.gdml.toVisual import hep.dataforge.vision.spatial.gdml.toVisual
import hep.dataforge.vision.spatial.specifications.Camera import hep.dataforge.vision.spatial.specifications.Camera
@ -35,7 +35,7 @@ import kotlin.math.PI
interface GDMLAppProps : RProps { interface GDMLAppProps : RProps {
var context: Context var context: Context
var rootObject: VisualObject? var rootObject: Vision?
var selected: Name? var selected: Name?
} }
@ -50,7 +50,7 @@ private val canvasConfig = Canvas3DOptions {
val GDMLApp = component<GDMLAppProps> { props -> val GDMLApp = component<GDMLAppProps> { props ->
var selected by state { props.selected } var selected by state { props.selected }
var canvas: ThreeCanvas? by state { null } var canvas: ThreeCanvas? by state { null }
var visual: VisualObject? by state { props.rootObject } var visual: Vision? by state { props.rootObject }
val select: (Name?) -> Unit = { val select: (Name?) -> Unit = {
selected = it selected = it
@ -62,7 +62,7 @@ val GDMLApp = component<GDMLAppProps> { props ->
val gdml = GDML.parse(data) val gdml = GDML.parse(data)
gdml.toVisual(gdmlConfiguration) gdml.toVisual(gdmlConfiguration)
} }
name.endsWith(".json") -> VisualGroup3D.parseJson(data) name.endsWith(".json") -> VisionGroup3D.parseJson(data)
else -> { else -> {
window.alert("File extension is not recognized: $name") window.alert("File extension is not recognized: $name")
error("File extension is not recognized: $name") error("File extension is not recognized: $name")
@ -137,10 +137,10 @@ val GDMLApp = component<GDMLAppProps> { props ->
//properties //properties
card("Properties") { card("Properties") {
selected.let { selected -> selected.let { selected ->
val selectedObject: VisualObject? = when { val selectedObject: Vision? = when {
selected == null -> null selected == null -> null
selected.isEmpty() -> visual selected.isEmpty() -> visual
else -> (visual as? VisualGroup)?.get(selected) else -> (visual as? VisionGroup)?.get(selected)
} }
if (selectedObject != null) { if (selectedObject != null) {
configEditor(selectedObject, default = selectedObject.properties(), key = selected) configEditor(selectedObject, default = selectedObject.properties(), key = selected)

View File

@ -3,8 +3,8 @@ package hep.dataforge.vision.spatial.gdml.demo
import hep.dataforge.meta.setItem import hep.dataforge.meta.setItem
import hep.dataforge.values.asValue import hep.dataforge.values.asValue
import hep.dataforge.vision.spatial.Material3D import hep.dataforge.vision.spatial.Material3D
import hep.dataforge.vision.spatial.VisionGroup3D
import hep.dataforge.vision.spatial.Visual3D import hep.dataforge.vision.spatial.Visual3D
import hep.dataforge.vision.spatial.VisualGroup3D
import hep.dataforge.vision.spatial.gdml.LUnit import hep.dataforge.vision.spatial.gdml.LUnit
import hep.dataforge.vision.spatial.gdml.readFile import hep.dataforge.vision.spatial.gdml.readFile
import hep.dataforge.vision.spatial.gdml.toVisual import hep.dataforge.vision.spatial.gdml.toVisual
@ -13,7 +13,7 @@ import java.io.File
import java.util.zip.GZIPInputStream import java.util.zip.GZIPInputStream
import java.util.zip.ZipInputStream import java.util.zip.ZipInputStream
fun Visual3D.Companion.readFile(file: File): VisualGroup3D = when { fun Visual3D.Companion.readFile(file: File): VisionGroup3D = when {
file.extension == "gdml" || file.extension == "xml" -> { file.extension == "gdml" || file.extension == "xml" -> {
GDML.readFile(file.toPath()).toVisual { GDML.readFile(file.toPath()).toVisual {
lUnit = LUnit.CM lUnit = LUnit.CM
@ -30,22 +30,22 @@ fun Visual3D.Companion.readFile(file: File): VisualGroup3D = when {
} }
} }
} }
file.extension == "json" -> VisualGroup3D.parseJson(file.readText()) file.extension == "json" -> VisionGroup3D.parseJson(file.readText())
file.name.endsWith("json.zip") -> { file.name.endsWith("json.zip") -> {
file.inputStream().use { file.inputStream().use {
val unzip = ZipInputStream(it, Charsets.UTF_8) val unzip = ZipInputStream(it, Charsets.UTF_8)
val text = unzip.readBytes().decodeToString() val text = unzip.readBytes().decodeToString()
VisualGroup3D.parseJson(text) VisionGroup3D.parseJson(text)
} }
} }
file.name.endsWith("json.gz") -> { file.name.endsWith("json.gz") -> {
file.inputStream().use { file.inputStream().use {
val unzip = GZIPInputStream(it) val unzip = GZIPInputStream(it)
val text = unzip.readBytes().decodeToString() val text = unzip.readBytes().decodeToString()
VisualGroup3D.parseJson(text) VisionGroup3D.parseJson(text)
} }
} }
else -> error("Unknown extension ${file.extension}") else -> error("Unknown extension ${file.extension}")
} }
fun Visual3D.Companion.readFile(fileName: String): VisualGroup3D = readFile(File(fileName)) fun Visual3D.Companion.readFile(fileName: String): VisionGroup3D = readFile(File(fileName))

View File

@ -9,7 +9,7 @@ class FileSerializationTest {
@Ignore @Ignore
fun testFileRead(){ fun testFileRead(){
val text = this::class.java.getResourceAsStream("/cubes.json").readBytes().decodeToString() val text = this::class.java.getResourceAsStream("/cubes.json").readBytes().decodeToString()
val visual = VisualGroup3D.parseJson(text) val visual = VisionGroup3D.parseJson(text)
visual["composite_001".asName()] visual["composite_001".asName()]
} }
} }

View File

@ -8,10 +8,10 @@ import ru.mipt.npm.muon.monitor.Monitor.UPPER_LAYER_Z
import kotlin.math.PI import kotlin.math.PI
class Model { class Model {
private val map = HashMap<String, VisualGroup3D>() private val map = HashMap<String, VisionGroup3D>()
private val events = HashSet<Event>() private val events = HashSet<Event>()
private fun VisualGroup3D.pixel(pixel: SC1) { private fun VisionGroup3D.pixel(pixel: SC1) {
val group = group(pixel.name) { val group = group(pixel.name) {
position = Point3D(pixel.center.x, pixel.center.y, pixel.center.z) position = Point3D(pixel.center.x, pixel.center.y, pixel.center.z)
box(pixel.xSize, pixel.ySize, pixel.zSize) box(pixel.xSize, pixel.ySize, pixel.zSize)
@ -23,7 +23,7 @@ class Model {
map[pixel.name] = group map[pixel.name] = group
} }
private fun VisualGroup3D.detector(detector: SC16) { private fun VisionGroup3D.detector(detector: SC16) {
group(detector.name) { group(detector.name) {
detector.pixels.forEach { detector.pixels.forEach {
pixel(it) pixel(it)
@ -31,9 +31,9 @@ class Model {
} }
} }
var tracks: VisualGroup3D var tracks: VisionGroup3D
val root: VisualGroup3D = VisualGroup3D().apply { val root: VisionGroup3D = VisionGroup3D().apply {
rotationX = PI / 2 rotationX = PI / 2
group("bottom") { group("bottom") {
Monitor.detectors.filter { it.center.z == LOWER_LAYER_Z }.forEach { Monitor.detectors.filter { it.center.z == LOWER_LAYER_Z }.forEach {

View File

@ -4,7 +4,7 @@ import hep.dataforge.context.Context
import hep.dataforge.names.Name import hep.dataforge.names.Name
import hep.dataforge.names.NameToken import hep.dataforge.names.NameToken
import hep.dataforge.names.isEmpty import hep.dataforge.names.isEmpty
import hep.dataforge.vision.VisualObject import hep.dataforge.vision.Vision
import hep.dataforge.vision.bootstrap.card import hep.dataforge.vision.bootstrap.card
import hep.dataforge.vision.bootstrap.objectTree import hep.dataforge.vision.bootstrap.objectTree
import hep.dataforge.vision.react.component import hep.dataforge.vision.react.component
@ -149,7 +149,7 @@ val MMApp = component<MMAppProps> { props ->
//properties //properties
card("Properties") { card("Properties") {
selected.let { selected -> selected.let { selected ->
val selectedObject: VisualObject? = when { val selectedObject: Vision? = when {
selected == null -> null selected == null -> null
selected.isEmpty() -> visual selected.isEmpty() -> visual
else -> visual[selected] else -> visual[selected]

View File

@ -5,7 +5,7 @@ import hep.dataforge.meta.invoke
import hep.dataforge.names.toName import hep.dataforge.names.toName
import hep.dataforge.output.OutputManager import hep.dataforge.output.OutputManager
import hep.dataforge.vision.Colors import hep.dataforge.vision.Colors
import hep.dataforge.vision.VisualObject import hep.dataforge.vision.Vision
import hep.dataforge.vision.spatial.* import hep.dataforge.vision.spatial.*
import hep.dataforge.vision.spatial.specifications.Canvas3DOptions import hep.dataforge.vision.spatial.specifications.Canvas3DOptions
import kotlinx.coroutines.* import kotlinx.coroutines.*
@ -15,11 +15,11 @@ import kotlin.math.sin
import kotlin.random.Random import kotlin.random.Random
fun OutputManager.demo(name: String, title: String = name, block: VisualGroup3D.() -> Unit) { fun OutputManager.demo(name: String, title: String = name, block: VisionGroup3D.() -> Unit) {
val meta = Meta { val meta = Meta {
"title" put title "title" put title
} }
val output = get(VisualObject::class, name.toName(), meta = meta) val output = get(Vision::class, name.toName(), meta = meta)
output.render (action = block) output.render (action = block)
} }

View File

@ -7,7 +7,7 @@ import hep.dataforge.meta.string
import hep.dataforge.names.Name import hep.dataforge.names.Name
import hep.dataforge.output.OutputManager import hep.dataforge.output.OutputManager
import hep.dataforge.output.Renderer import hep.dataforge.output.Renderer
import hep.dataforge.vision.VisualObject import hep.dataforge.vision.Vision
import hep.dataforge.vision.spatial.three.ThreeCanvas import hep.dataforge.vision.spatial.three.ThreeCanvas
import hep.dataforge.vision.spatial.three.ThreePlugin import hep.dataforge.vision.spatial.three.ThreePlugin
import hep.dataforge.vision.spatial.three.output import hep.dataforge.vision.spatial.three.output
@ -39,7 +39,7 @@ class ThreeDemoGrid(element: Element, meta: Meta = Meta.EMPTY) : OutputManager {
override fun <T : Any> get(type: KClass<out T>, name: Name, stage: Name, meta: Meta): Renderer<T> { override fun <T : Any> get(type: KClass<out T>, name: Name, stage: Name, meta: Meta): Renderer<T> {
return outputs.getOrPut(name) { return outputs.getOrPut(name) {
if (type != VisualObject::class) error("Supports only DisplayObject") if (type != Vision::class) error("Supports only DisplayObject")
lateinit var output: ThreeCanvas lateinit var output: ThreeCanvas
//TODO calculate cell width here using jquery //TODO calculate cell width here using jquery
gridRoot.append { gridRoot.append {

View File

@ -43,7 +43,7 @@ internal var VisualObject3D.value: Int
color(r.toUByte(), g.toUByte(), b.toUByte()) color(r.toUByte(), g.toUByte(), b.toUByte())
} }
fun VisualGroup3D.varBox( fun VisionGroup3D.varBox(
xSize: Number, xSize: Number,
ySize: Number, ySize: Number,
zSize: Number, zSize: Number,

View File

@ -5,7 +5,7 @@ import hep.dataforge.meta.Meta
import hep.dataforge.names.Name import hep.dataforge.names.Name
import hep.dataforge.output.OutputManager import hep.dataforge.output.OutputManager
import hep.dataforge.output.Renderer import hep.dataforge.output.Renderer
import hep.dataforge.vision.VisualObject import hep.dataforge.vision.Vision
import hep.dataforge.vision.spatial.fx.FX3DPlugin import hep.dataforge.vision.spatial.fx.FX3DPlugin
import hep.dataforge.vision.spatial.fx.FXCanvas3D import hep.dataforge.vision.spatial.fx.FXCanvas3D
import javafx.collections.FXCollections import javafx.collections.FXCollections
@ -30,7 +30,7 @@ class FXDemoGrid : View(title = "DataForge-vis FX demo"), OutputManager {
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
override fun <T : Any> get(type: KClass<out T>, name: Name, stage: Name, meta: Meta): Renderer<T> { override fun <T : Any> get(type: KClass<out T>, name: Name, stage: Name, meta: Meta): Renderer<T> {
return outputs.getOrPut(name) { return outputs.getOrPut(name) {
if (type != VisualObject::class) kotlin.error("Supports only DisplayObject") if (type != Vision::class) kotlin.error("Supports only DisplayObject")
val output = FXCanvas3D(fx3d, canvasOptions) val output = FXCanvas3D(fx3d, canvasOptions)
output output

View File

@ -5,7 +5,7 @@ import hep.dataforge.names.Name
import hep.dataforge.vision.bootstrap.objectTree import hep.dataforge.vision.bootstrap.objectTree
import hep.dataforge.vision.bootstrap.visualPropertyEditor import hep.dataforge.vision.bootstrap.visualPropertyEditor
import hep.dataforge.vision.spatial.Point3D import hep.dataforge.vision.spatial.Point3D
import hep.dataforge.vision.spatial.VisualGroup3D import hep.dataforge.vision.spatial.VisionGroup3D
import hep.dataforge.vision.spatial.box import hep.dataforge.vision.spatial.box
import hep.dataforge.vision.spatial.group import hep.dataforge.vision.spatial.group
import hep.dataforge.vision.spatial.three.ThreePlugin import hep.dataforge.vision.spatial.three.ThreePlugin
@ -24,7 +24,7 @@ private class PlayGroundApp : Application {
val element = val element =
document.getElementById("app") as? HTMLElement ?: error("Element with id 'canvas' not found on page") document.getElementById("app") as? HTMLElement ?: error("Element with id 'canvas' not found on page")
val obj = VisualGroup3D().apply { val obj = VisionGroup3D().apply {
box(100, 100, 100, name = "A") box(100, 100, 100, name = "A")
group("B") { group("B") {
position = Point3D(120, 0, 0) position = Point3D(120, 0, 0)

View File

@ -3,8 +3,8 @@ package hep.dataforge.vision.bootstrap
import hep.dataforge.names.Name import hep.dataforge.names.Name
import hep.dataforge.names.plus import hep.dataforge.names.plus
import hep.dataforge.names.startsWith import hep.dataforge.names.startsWith
import hep.dataforge.vision.VisualGroup import hep.dataforge.vision.Vision
import hep.dataforge.vision.VisualObject import hep.dataforge.vision.VisionGroup
import hep.dataforge.vision.isEmpty import hep.dataforge.vision.isEmpty
import hep.dataforge.vision.react.RFBuilder import hep.dataforge.vision.react.RFBuilder
import hep.dataforge.vision.react.component import hep.dataforge.vision.react.component
@ -18,7 +18,7 @@ import react.dom.*
interface ObjectTreeProps : RProps { interface ObjectTreeProps : RProps {
var name: Name var name: Name
var selected: Name? var selected: Name?
var obj: VisualObject var obj: Vision
var clickCallback: (Name) -> Unit var clickCallback: (Name) -> Unit
} }
@ -49,7 +49,7 @@ private fun RFBuilder.objectTree(props: ObjectTreeProps): Unit {
val obj = props.obj val obj = props.obj
//display as node if any child is visible //display as node if any child is visible
if (obj is VisualGroup) { if (obj is VisionGroup) {
div("d-block text-truncate") { div("d-block text-truncate") {
if (obj.children.any { !it.key.body.startsWith("@") }) { if (obj.children.any { !it.key.body.startsWith("@") }) {
span("tree-caret") { span("tree-caret") {
@ -67,7 +67,7 @@ private fun RFBuilder.objectTree(props: ObjectTreeProps): Unit {
ul("tree") { ul("tree") {
obj.children.entries obj.children.entries
.filter { !it.key.toString().startsWith("@") } // ignore statics and other hidden children .filter { !it.key.toString().startsWith("@") } // ignore statics and other hidden children
.sortedBy { (it.value as? VisualGroup)?.isEmpty ?: true } .sortedBy { (it.value as? VisionGroup)?.isEmpty ?: true }
.forEach { (childToken, child) -> .forEach { (childToken, child) ->
li("tree-item") { li("tree-item") {
child(ObjectTree) { child(ObjectTree) {
@ -95,14 +95,14 @@ val ObjectTree: FunctionalComponent<ObjectTreeProps> = component { props ->
} }
fun Element.renderObjectTree( fun Element.renderObjectTree(
visualObject: VisualObject, vision: Vision,
clickCallback: (Name) -> Unit = {} clickCallback: (Name) -> Unit = {}
) = render(this) { ) = render(this) {
card("Object tree") { card("Object tree") {
child(ObjectTree) { child(ObjectTree) {
attrs { attrs {
this.name = Name.EMPTY this.name = Name.EMPTY
this.obj = visualObject this.obj = vision
this.selected = null this.selected = null
this.clickCallback = clickCallback this.clickCallback = clickCallback
} }
@ -111,14 +111,14 @@ fun Element.renderObjectTree(
} }
fun RBuilder.objectTree( fun RBuilder.objectTree(
visualObject: VisualObject, vision: Vision,
selected: Name? = null, selected: Name? = null,
clickCallback: (Name) -> Unit = {} clickCallback: (Name) -> Unit = {}
) { ) {
child(ObjectTree) { child(ObjectTree) {
attrs { attrs {
this.name = Name.EMPTY this.name = Name.EMPTY
this.obj = visualObject this.obj = vision
this.selected = selected this.selected = selected
this.clickCallback = clickCallback this.clickCallback = clickCallback
} }

View File

@ -4,7 +4,7 @@ import hep.dataforge.meta.Meta
import hep.dataforge.meta.descriptors.NodeDescriptor import hep.dataforge.meta.descriptors.NodeDescriptor
import hep.dataforge.names.Name import hep.dataforge.names.Name
import hep.dataforge.names.isEmpty import hep.dataforge.names.isEmpty
import hep.dataforge.vision.VisualObject import hep.dataforge.vision.Vision
import hep.dataforge.vision.react.configEditor import hep.dataforge.vision.react.configEditor
import org.w3c.dom.Element import org.w3c.dom.Element
import react.RBuilder import react.RBuilder
@ -16,7 +16,7 @@ import kotlin.collections.set
fun RBuilder.visualPropertyEditor( fun RBuilder.visualPropertyEditor(
path: Name, path: Name,
item: VisualObject, item: Vision,
descriptor: NodeDescriptor? = item.descriptor, descriptor: NodeDescriptor? = item.descriptor,
default: Meta? = null default: Meta? = null
) { ) {
@ -41,7 +41,7 @@ fun RBuilder.visualPropertyEditor(
fun Element.visualPropertyEditor( fun Element.visualPropertyEditor(
path: Name, path: Name,
item: VisualObject, item: Vision,
descriptor: NodeDescriptor? = item.descriptor, descriptor: NodeDescriptor? = item.descriptor,
default: Meta? = null default: Meta? = null
) = render(this) { ) = render(this) {

View File

@ -3,8 +3,8 @@ package hep.dataforge.vision.material
import hep.dataforge.names.Name import hep.dataforge.names.Name
import hep.dataforge.names.plus import hep.dataforge.names.plus
import hep.dataforge.names.toName import hep.dataforge.names.toName
import hep.dataforge.vision.VisualGroup import hep.dataforge.vision.Vision
import hep.dataforge.vision.VisualObject import hep.dataforge.vision.VisionGroup
import hep.dataforge.vision.isEmpty import hep.dataforge.vision.isEmpty
import hep.dataforge.vision.react.component import hep.dataforge.vision.react.component
import hep.dataforge.vision.react.state import hep.dataforge.vision.react.state
@ -21,11 +21,11 @@ import react.dom.span
interface ObjectTreeProps : RProps { interface ObjectTreeProps : RProps {
var name: Name var name: Name
var selected: Name? var selected: Name?
var obj: VisualObject var obj: Vision
var clickCallback: (Name?) -> Unit var clickCallback: (Name?) -> Unit
} }
private fun RBuilder.treeBranch(name: Name, obj: VisualObject): Unit { private fun RBuilder.treeBranch(name: Name, obj: Vision): Unit {
treeItem { treeItem {
val token = name.last()?.toString() ?: "World" val token = name.last()?.toString() ?: "World"
attrs { attrs {
@ -37,10 +37,10 @@ private fun RBuilder.treeBranch(name: Name, obj: VisualObject): Unit {
} }
} }
if (obj is VisualGroup) { if (obj is VisionGroup) {
obj.children.entries obj.children.entries
.filter { !it.key.toString().startsWith("@") } // ignore statics and other hidden children .filter { !it.key.toString().startsWith("@") } // ignore statics and other hidden children
.sortedBy { (it.value as? VisualGroup)?.isEmpty ?: true } .sortedBy { (it.value as? VisionGroup)?.isEmpty ?: true }
.forEach { (childToken, child) -> .forEach { (childToken, child) ->
treeBranch(name + childToken, child) treeBranch(name + childToken, child)
} }
@ -78,14 +78,14 @@ val ObjectTree: FunctionalComponent<ObjectTreeProps> = component { props ->
} }
fun RBuilder.objectTree( fun RBuilder.objectTree(
visualObject: VisualObject, vision: Vision,
selected: Name? = null, selected: Name? = null,
clickCallback: (Name?) -> Unit = {} clickCallback: (Name?) -> Unit = {}
) { ) {
child(ObjectTree) { child(ObjectTree) {
attrs { attrs {
this.name = Name.EMPTY this.name = Name.EMPTY
this.obj = visualObject this.obj = vision
this.selected = selected this.selected = selected
this.clickCallback = clickCallback this.clickCallback = clickCallback
} }

View File

@ -8,14 +8,15 @@ kotlin {
} }
} }
val reactVersion by extra("16.13.1")
dependencies{ dependencies{
api(project(":visionforge-core")) api(project(":visionforge-core"))
//api("org.jetbrains:kotlin-react:16.13.1-pre.104-kotlin-1.3.72") //api("org.jetbrains:kotlin-react:16.13.1-pre.104-kotlin-1.3.72")
api("org.jetbrains:kotlin-react-dom:16.13.1-pre.104-kotlin-1.3.72") api("org.jetbrains:kotlin-react-dom:$reactVersion-pre.104-kotlin-1.3.72")
api(npm("react", "16.13.1")) api(npm("react", reactVersion))
api(npm("react-dom", "16.13.1")) api(npm("react-dom", reactVersion))
api(npm("react-is", "16.13.1")) api(npm("react-is", reactVersion))
} }

View File

@ -6,7 +6,7 @@ import hep.dataforge.names.Name
import hep.dataforge.names.asName import hep.dataforge.names.asName
import hep.dataforge.values.Value import hep.dataforge.values.Value
import hep.dataforge.values.ValueType import hep.dataforge.values.ValueType
import hep.dataforge.vision.VisualObject.Companion.STYLE_KEY import hep.dataforge.vision.Vision.Companion.STYLE_KEY
import kotlinx.serialization.Transient import kotlinx.serialization.Transient
internal data class PropertyListener( internal data class PropertyListener(
@ -14,10 +14,10 @@ internal data class PropertyListener(
val action: (name: Name, oldItem: MetaItem<*>?, newItem: MetaItem<*>?) -> Unit val action: (name: Name, oldItem: MetaItem<*>?, newItem: MetaItem<*>?) -> Unit
) )
abstract class AbstractVisualObject : VisualObject { abstract class AbstractVisualObject : Vision {
@Transient @Transient
override var parent: VisualGroup? = null override var parent: VisionGroup? = null
/** /**
* Object own properties excluding styles and inheritance * Object own properties excluding styles and inheritance

View File

@ -9,16 +9,16 @@ import kotlinx.serialization.Transient
/** /**
* Abstract implementation of mutable group of [VisualObject] * Abstract implementation of mutable group of [Vision]
*/ */
abstract class AbstractVisualGroup : AbstractVisualObject(), MutableVisualGroup { abstract class AbstractVision : AbstractVisualObject(), MutableVisionGroup {
//protected abstract val _children: MutableMap<NameToken, T> //protected abstract val _children: MutableMap<NameToken, T>
/** /**
* A map of top level named children * A map of top level named children
*/ */
abstract override val children: Map<NameToken, VisualObject> abstract override val children: Map<NameToken, Vision>
abstract override var styleSheet: StyleSheet? abstract override var styleSheet: StyleSheet?
protected set protected set
@ -39,7 +39,7 @@ abstract class AbstractVisualGroup : AbstractVisualObject(), MutableVisualGroup
} }
// TODO Consider renaming to `StructureChangeListener` (singular) // TODO Consider renaming to `StructureChangeListener` (singular)
private data class StructureChangeListeners(val owner: Any?, val callback: (Name, VisualObject?) -> Unit) private data class StructureChangeListeners(val owner: Any?, val callback: (Name, Vision?) -> Unit)
@Transient @Transient
private val structureChangeListeners = HashSet<StructureChangeListeners>() private val structureChangeListeners = HashSet<StructureChangeListeners>()
@ -47,7 +47,7 @@ abstract class AbstractVisualGroup : AbstractVisualObject(), MutableVisualGroup
/** /**
* Add listener for children change * Add listener for children change
*/ */
override fun onChildrenChange(owner: Any?, action: (Name, VisualObject?) -> Unit) { override fun onChildrenChange(owner: Any?, action: (Name, Vision?) -> Unit) {
structureChangeListeners.add( structureChangeListeners.add(
StructureChangeListeners( StructureChangeListeners(
owner, owner,
@ -66,7 +66,7 @@ abstract class AbstractVisualGroup : AbstractVisualObject(), MutableVisualGroup
/** /**
* Propagate children change event upwards * Propagate children change event upwards
*/ */
protected fun childrenChanged(name: Name, child: VisualObject?) { protected fun childrenChanged(name: Name, child: Vision?) {
structureChangeListeners.forEach { it.callback(name, child) } structureChangeListeners.forEach { it.callback(name, child) }
} }
@ -78,20 +78,20 @@ abstract class AbstractVisualGroup : AbstractVisualObject(), MutableVisualGroup
/** /**
* Add, remove or replace child with given name * Add, remove or replace child with given name
*/ */
protected abstract fun setChild(token: NameToken, child: VisualObject) protected abstract fun setChild(token: NameToken, child: Vision)
/** /**
* Add a static child. Statics could not be found by name, removed or replaced * Add a static child. Statics could not be found by name, removed or replaced
*/ */
protected open fun addStatic(child: VisualObject) = protected open fun addStatic(child: Vision) =
set(NameToken("@static(${child.hashCode()})").asName(), child) set(NameToken("@static(${child.hashCode()})").asName(), child)
protected abstract fun createGroup(): AbstractVisualGroup protected abstract fun createGroup(): AbstractVision
/** /**
* Set this node as parent for given node * Set this node as parent for given node
*/ */
protected fun attach(child: VisualObject) { protected fun attach(child: Vision) {
if (child.parent == null) { if (child.parent == null) {
child.parent = this child.parent = this
} else if (child.parent !== this) { } else if (child.parent !== this) {
@ -102,7 +102,7 @@ abstract class AbstractVisualGroup : AbstractVisualObject(), MutableVisualGroup
/** /**
* Recursively create a child group * Recursively create a child group
*/ */
private fun createGroups(name: Name): AbstractVisualGroup { private fun createGroups(name: Name): AbstractVision {
return when { return when {
name.isEmpty() -> error("Should be unreachable") name.isEmpty() -> error("Should be unreachable")
name.length == 1 -> { name.length == 1 -> {
@ -112,7 +112,7 @@ abstract class AbstractVisualGroup : AbstractVisualObject(), MutableVisualGroup
attach(child) attach(child)
setChild(token, child) setChild(token, child)
} }
is AbstractVisualGroup -> current is AbstractVision -> current
else -> error("Can't create group with name $name because it exists and not a group") else -> error("Can't create group with name $name because it exists and not a group")
} }
} }
@ -124,7 +124,7 @@ abstract class AbstractVisualGroup : AbstractVisualObject(), MutableVisualGroup
* Add named or unnamed child to the group. If key is null the child is considered unnamed. Both key and value are not * Add named or unnamed child to the group. If key is null the child is considered unnamed. Both key and value are not
* allowed to be null in the same time. If name is present and [child] is null, the appropriate element is removed. * allowed to be null in the same time. If name is present and [child] is null, the appropriate element is removed.
*/ */
override fun set(name: Name, child: VisualObject?): Unit { override fun set(name: Name, child: Vision?): Unit {
when { when {
name.isEmpty() -> { name.isEmpty() -> {
if (child != null) { if (child != null) {
@ -142,7 +142,7 @@ abstract class AbstractVisualGroup : AbstractVisualObject(), MutableVisualGroup
} }
else -> { else -> {
//TODO add safety check //TODO add safety check
val parent = (get(name.cutLast()) as? MutableVisualGroup) ?: createGroups(name.cutLast()) val parent = (get(name.cutLast()) as? MutableVisionGroup) ?: createGroups(name.cutLast())
parent[name.last()!!.asName()] = child parent[name.last()!!.asName()] = child
} }
} }

View File

@ -8,7 +8,7 @@ import kotlinx.serialization.Serializable
@Serializable @Serializable
@SerialName("group") @SerialName("group")
class SimpleVisualGroup : AbstractVisualGroup() { class SimpleVisionGroup : AbstractVision() {
override var styleSheet: StyleSheet? = null override var styleSheet: StyleSheet? = null
@ -16,16 +16,16 @@ class SimpleVisualGroup : AbstractVisualGroup() {
override var ownProperties: Config? = null override var ownProperties: Config? = null
@SerialName("children") @SerialName("children")
private val _children = HashMap<NameToken, VisualObject>() private val _children = HashMap<NameToken, Vision>()
override val children: Map<NameToken, VisualObject> get() = _children override val children: Map<NameToken, Vision> get() = _children
override fun removeChild(token: NameToken) { override fun removeChild(token: NameToken) {
_children.remove(token)?.apply { parent = null } _children.remove(token)?.apply { parent = null }
} }
override fun setChild(token: NameToken, child: VisualObject) { override fun setChild(token: NameToken, child: Vision) {
_children[token] = child _children[token] = child
} }
override fun createGroup(): SimpleVisualGroup = SimpleVisualGroup() override fun createGroup(): SimpleVisionGroup = SimpleVisionGroup()
} }

View File

@ -15,9 +15,9 @@ import kotlinx.serialization.builtins.serializer
@Serializable @Serializable
class StyleSheet private constructor(private val styleMap: MutableMap<String, Meta> = LinkedHashMap()) { class StyleSheet private constructor(private val styleMap: MutableMap<String, Meta> = LinkedHashMap()) {
@Transient @Transient
internal var owner: VisualObject? = null internal var owner: Vision? = null
constructor(owner: VisualObject) : this() { constructor(owner: Vision) : this() {
this.owner = owner this.owner = owner
} }
@ -73,14 +73,14 @@ class StyleSheet private constructor(private val styleMap: MutableMap<String, Me
} }
} }
private fun VisualObject.styleChanged(key: String, oldStyle: Meta?, newStyle: Meta?) { private fun Vision.styleChanged(key: String, oldStyle: Meta?, newStyle: Meta?) {
if (styles.contains(key)) { if (styles.contains(key)) {
//TODO optimize set concatenation //TODO optimize set concatenation
val tokens: Collection<Name> = ((oldStyle?.items?.keys ?: emptySet()) + (newStyle?.items?.keys ?: emptySet())) val tokens: Collection<Name> = ((oldStyle?.items?.keys ?: emptySet()) + (newStyle?.items?.keys ?: emptySet()))
.map { it.asName() } .map { it.asName() }
tokens.forEach { parent?.propertyChanged(it, oldStyle?.get(it), newStyle?.get(it)) } tokens.forEach { parent?.propertyChanged(it, oldStyle?.get(it), newStyle?.get(it)) }
} }
if (this is VisualGroup) { if (this is VisionGroup) {
for (obj in this) { for (obj in this) {
obj.styleChanged(key, oldStyle, newStyle) obj.styleChanged(key, oldStyle, newStyle)
} }

View File

@ -8,7 +8,7 @@ import hep.dataforge.names.Name
import hep.dataforge.names.asName import hep.dataforge.names.asName
import hep.dataforge.names.toName import hep.dataforge.names.toName
import hep.dataforge.provider.Type import hep.dataforge.provider.Type
import hep.dataforge.vision.VisualObject.Companion.TYPE import hep.dataforge.vision.Vision.Companion.TYPE
import kotlinx.serialization.PolymorphicSerializer import kotlinx.serialization.PolymorphicSerializer
import kotlinx.serialization.Transient import kotlinx.serialization.Transient
@ -16,13 +16,13 @@ import kotlinx.serialization.Transient
* A root type for display hierarchy * A root type for display hierarchy
*/ */
@Type(TYPE) @Type(TYPE)
interface VisualObject : Configurable { interface Vision : Configurable {
/** /**
* The parent object of this one. If null, this one is a root. * The parent object of this one. If null, this one is a root.
*/ */
@Transient @Transient
var parent: VisualGroup? var parent: VisionGroup?
/** /**
* All properties including styles and prototypes if present, including inherited ones * All properties including styles and prototypes if present, including inherited ones
@ -68,26 +68,26 @@ interface VisualObject : Configurable {
const val TYPE = "visual" const val TYPE = "visual"
val STYLE_KEY = "@style".asName() val STYLE_KEY = "@style".asName()
private val VISUAL_OBJECT_SERIALIZER = PolymorphicSerializer(VisualObject::class) private val VISUAL_OBJECT_SERIALIZER = PolymorphicSerializer(Vision::class)
fun serializer() = VISUAL_OBJECT_SERIALIZER fun serializer() = VISUAL_OBJECT_SERIALIZER
} }
} }
/** /**
* Get [VisualObject] property using key as a String * Get [Vision] property using key as a String
*/ */
fun VisualObject.getProperty(key: String, inherit: Boolean = true): MetaItem<*>? = fun Vision.getProperty(key: String, inherit: Boolean = true): MetaItem<*>? =
getProperty(key.toName(), inherit) getProperty(key.toName(), inherit)
/** /**
* Add style name to the list of styles to be resolved later. The style with given name does not necessary exist at the moment. * Add style name to the list of styles to be resolved later. The style with given name does not necessary exist at the moment.
*/ */
fun VisualObject.useStyle(name: String) { fun Vision.useStyle(name: String) {
styles = styles + name styles = styles + name
} }
tailrec fun VisualObject.findStyle(name: String): Meta? = tailrec fun Vision.findStyle(name: String): Meta? =
(this as? VisualGroup)?.styleSheet?.get(name) ?: parent?.findStyle(name) (this as? VisionGroup)?.styleSheet?.get(name) ?: parent?.findStyle(name)
fun VisualObject.findAllStyles(): Laminate = Laminate(styles.mapNotNull(::findStyle)) fun Vision.findAllStyles(): Laminate = Laminate(styles.mapNotNull(::findStyle))

View File

@ -4,15 +4,15 @@ import hep.dataforge.names.*
import hep.dataforge.provider.Provider import hep.dataforge.provider.Provider
/** /**
* Represents a group of [VisualObject] instances * Represents a group of [Vision] instances
*/ */
interface VisualGroup : Provider, VisualObject { interface VisionGroup : Provider, Vision {
/** /**
* A map of top level named children * A map of top level named children
*/ */
val children: Map<NameToken, VisualObject> val children: Map<NameToken, Vision>
override val defaultTarget: String get() = VisualObject.TYPE override val defaultTarget: String get() = Vision.TYPE
/** /**
* A stylesheet for this group and its descendants. Stylesheet is not applied directly, * A stylesheet for this group and its descendants. Stylesheet is not applied directly,
@ -26,8 +26,8 @@ interface VisualGroup : Provider, VisualObject {
*/ */
override fun provideTop(target: String): Map<Name, Any> = override fun provideTop(target: String): Map<Name, Any> =
when (target) { when (target) {
VisualObject.TYPE -> children.flatMap { (key, value) -> Vision.TYPE -> children.flatMap { (key, value) ->
val res: Map<Name, Any> = if (value is VisualGroup) { val res: Map<Name, Any> = if (value is VisionGroup) {
value.provideTop(target).mapKeys { key + it.key } value.provideTop(target).mapKeys { key + it.key }
} else { } else {
mapOf(key.asName() to value) mapOf(key.asName() to value)
@ -38,11 +38,11 @@ interface VisualGroup : Provider, VisualObject {
else -> emptyMap() else -> emptyMap()
} }
operator fun get(name: Name): VisualObject? { operator fun get(name: Name): Vision? {
return when { return when {
name.isEmpty() -> this name.isEmpty() -> this
name.length == 1 -> children[name.first()!!] name.length == 1 -> children[name.first()!!]
else -> (children[name.first()!!] as? VisualGroup)?.get(name.cutFirst()) else -> (children[name.first()!!] as? VisionGroup)?.get(name.cutFirst())
} }
} }
@ -53,7 +53,7 @@ interface VisualGroup : Provider, VisualObject {
styleSheet?.owner = this styleSheet?.owner = this
children.values.forEach { children.values.forEach {
it.parent = this it.parent = this
(it as? VisualGroup)?.attachChildren() (it as? VisionGroup)?.attachChildren()
} }
} }
@ -65,34 +65,34 @@ interface VisualGroup : Provider, VisualObject {
/** /**
* Iterate over children of this group * Iterate over children of this group
*/ */
operator fun VisualGroup.iterator(): Iterator<VisualObject> = children.values.iterator() operator fun VisionGroup.iterator(): Iterator<Vision> = children.values.iterator()
val VisualGroup.isEmpty: Boolean get() = this.children.isEmpty() val VisionGroup.isEmpty: Boolean get() = this.children.isEmpty()
/** /**
* Mutable version of [VisualGroup] * Mutable version of [VisionGroup]
*/ */
interface MutableVisualGroup : VisualGroup { interface MutableVisionGroup : VisionGroup {
/** /**
* Add listener for children structure change. * Add listener for children structure change.
* @param owner the handler to properly remove listeners * @param owner the handler to properly remove listeners
* @param action First argument of the action is the name of changed child. Second argument is the new value of the object. * @param action First argument of the action is the name of changed child. Second argument is the new value of the object.
*/ */
fun onChildrenChange(owner: Any?, action: (Name, VisualObject?) -> Unit) fun onChildrenChange(owner: Any?, action: (Name, Vision?) -> Unit)
/** /**
* Remove children change listener * Remove children change listener
*/ */
fun removeChildrenChangeListener(owner: Any?) fun removeChildrenChangeListener(owner: Any?)
operator fun set(name: Name, child: VisualObject?) operator fun set(name: Name, child: Vision?)
} }
operator fun VisualGroup.get(str: String?): VisualObject? = get(str?.toName() ?: Name.EMPTY) operator fun VisionGroup.get(str: String?): Vision? = get(str?.toName() ?: Name.EMPTY)
operator fun MutableVisualGroup.set(key: String, child: VisualObject?) { operator fun MutableVisionGroup.set(key: String, child: Vision?) {
set(key.toName(), child) set(key.toName(), child)
} }
fun MutableVisualGroup.removeAll() = children.keys.map { it.asName() }.forEach { this[it] = null } fun MutableVisionGroup.removeAll() = children.keys.map { it.asName() }.forEach { this[it] = null }

View File

@ -4,16 +4,16 @@ import hep.dataforge.context.*
import hep.dataforge.meta.Meta import hep.dataforge.meta.Meta
import kotlin.reflect.KClass import kotlin.reflect.KClass
interface VisualFactory<T : VisualObject> { interface VisualFactory<T : Vision> {
val type: KClass<T> val type: KClass<T>
operator fun invoke( operator fun invoke(
context: Context, context: Context,
parent: VisualObject?, parent: Vision?,
meta: Meta meta: Meta
): T ): T
} }
class Visual(meta: Meta) : AbstractPlugin(meta) { class VisionManager(meta: Meta) : AbstractPlugin(meta) {
override val tag: PluginTag get() = Companion.tag override val tag: PluginTag get() = Companion.tag
/** /**
@ -23,17 +23,16 @@ class Visual(meta: Meta) : AbstractPlugin(meta) {
context.content<VisualFactory<*>>(VISUAL_FACTORY_TYPE).mapKeys { it.value.type } context.content<VisualFactory<*>>(VISUAL_FACTORY_TYPE).mapKeys { it.value.type }
} }
inline fun <reified T : VisualObject> buildVisual(parent: VisualObject?, meta: Meta): T? { inline fun <reified T : Vision> buildVisual(parent: Vision?, meta: Meta): T? {
return visualFactories[T::class]?.invoke(context, parent, meta) as T? return visualFactories[T::class]?.invoke(context, parent, meta) as T?
} }
companion object : PluginFactory<Visual> { companion object : PluginFactory<VisionManager> {
override val tag: PluginTag = PluginTag(name = "visual", group = PluginTag.DATAFORGE_GROUP) override val tag: PluginTag = PluginTag(name = "vision", group = PluginTag.DATAFORGE_GROUP)
override val type: KClass<out Visual> = Visual::class override val type: KClass<out VisionManager> = VisionManager::class
override fun invoke(meta: Meta, context: Context): Visual = override fun invoke(meta: Meta, context: Context): VisionManager = VisionManager(meta)
Visual(meta)
const val VISUAL_FACTORY_TYPE = "visual.factory" const val VISUAL_FACTORY_TYPE = "vision.factory"
} }
} }

View File

@ -4,7 +4,7 @@ import hep.dataforge.meta.Config
import hep.dataforge.meta.Meta import hep.dataforge.meta.Meta
import hep.dataforge.meta.descriptors.NodeDescriptor import hep.dataforge.meta.descriptors.NodeDescriptor
import hep.dataforge.meta.update import hep.dataforge.meta.update
import hep.dataforge.vision.VisualObject import hep.dataforge.vision.Vision
import hep.dataforge.vision.findStyle import hep.dataforge.vision.findStyle
import javafx.beans.binding.Binding import javafx.beans.binding.Binding
import javafx.beans.property.SimpleObjectProperty import javafx.beans.property.SimpleObjectProperty
@ -13,16 +13,16 @@ import javafx.scene.Parent
import javafx.scene.layout.VBox import javafx.scene.layout.VBox
import tornadofx.* import tornadofx.*
class VisualObjectEditorFragment(val selector: (VisualObject) -> Meta) : Fragment() { class VisualObjectEditorFragment(val selector: (Vision) -> Meta) : Fragment() {
val itemProperty = SimpleObjectProperty<VisualObject>() val itemProperty = SimpleObjectProperty<Vision>()
var item: VisualObject? by itemProperty var item: Vision? by itemProperty
val descriptorProperty = SimpleObjectProperty<NodeDescriptor>() val descriptorProperty = SimpleObjectProperty<NodeDescriptor>()
constructor( constructor(
item: VisualObject?, item: Vision?,
descriptor: NodeDescriptor?, descriptor: NodeDescriptor?,
selector: (VisualObject) -> Config = { it.config } selector: (Vision) -> Config = { it.config }
) : this(selector) { ) : this(selector) {
this.item = item this.item = item
this.descriptorProperty.set(descriptor) this.descriptorProperty.set(descriptor)

View File

@ -1,20 +1,20 @@
package hep.dataforge.vision.editor package hep.dataforge.vision.editor
import hep.dataforge.vision.VisualGroup import hep.dataforge.vision.Vision
import hep.dataforge.vision.VisualObject import hep.dataforge.vision.VisionGroup
import javafx.beans.property.SimpleObjectProperty import javafx.beans.property.SimpleObjectProperty
import javafx.scene.control.SelectionMode import javafx.scene.control.SelectionMode
import javafx.scene.control.TreeItem import javafx.scene.control.TreeItem
import tornadofx.* import tornadofx.*
private fun toTreeItem(visualObject: VisualObject, title: String): TreeItem<Pair<String, VisualObject>> { private fun toTreeItem(vision: Vision, title: String): TreeItem<Pair<String, Vision>> {
return object : TreeItem<Pair<String, VisualObject>>(title to visualObject) { return object : TreeItem<Pair<String, Vision>>(title to vision) {
init { init {
if (visualObject is VisualGroup) { if (vision is VisionGroup) {
//lazy populate the tree //lazy populate the tree
expandedProperty().onChange { expanded -> expandedProperty().onChange { expanded ->
if (expanded && children.isEmpty()) { if (expanded && children.isEmpty()) {
children.setAll(visualObject.children.map { children.setAll(vision.children.map {
toTreeItem(it.value, it.key.toString()) toTreeItem(it.value, it.key.toString())
}) })
} }
@ -23,21 +23,21 @@ private fun toTreeItem(visualObject: VisualObject, title: String): TreeItem<Pair
} }
override fun isLeaf(): Boolean { override fun isLeaf(): Boolean {
return !(visualObject is VisualGroup && visualObject.children.isNotEmpty()) return !(vision is VisionGroup && vision.children.isNotEmpty())
} }
} }
} }
class VisualObjectTreeFragment : Fragment() { class VisualObjectTreeFragment : Fragment() {
val itemProperty = SimpleObjectProperty<VisualObject>() val itemProperty = SimpleObjectProperty<Vision>()
var item: VisualObject? by itemProperty var item: Vision? by itemProperty
val selectedProperty = SimpleObjectProperty<VisualObject>() val selectedProperty = SimpleObjectProperty<Vision>()
override val root = vbox { override val root = vbox {
titledpane("Object tree", collapsible = false) { titledpane("Object tree", collapsible = false) {
treeview<Pair<String, VisualObject>> { treeview<Pair<String, Vision>> {
cellFormat { cellFormat {
text = item.first text = item.first
} }

View File

@ -24,7 +24,7 @@ class GDMLTransformer(val root: GDML) {
/** /**
* A special group for local templates * A special group for local templates
*/ */
val proto by lazy { VisualGroup3D() } val proto by lazy { VisionGroup3D() }
private val styleCache = HashMap<Name, Meta>() private val styleCache = HashMap<Name, Meta>()
var lUnit: LUnit = LUnit.MM var lUnit: LUnit = LUnit.MM
@ -68,7 +68,7 @@ class GDMLTransformer(val root: GDML) {
var onFinish: GDMLTransformer.() -> Unit = {} var onFinish: GDMLTransformer.() -> Unit = {}
internal fun finalize(final: VisualGroup3D): VisualGroup3D { internal fun finalize(final: VisionGroup3D): VisionGroup3D {
//final.prototypes = proto //final.prototypes = proto
final.prototypes { final.prototypes {
proto.children.forEach { (token, item) -> proto.children.forEach { (token, item) ->

View File

@ -48,7 +48,7 @@ private inline operator fun Number.times(d: Double) = toDouble() * d
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
private inline operator fun Number.times(f: Float) = toFloat() * f private inline operator fun Number.times(f: Float) = toFloat() * f
private fun VisualGroup3D.addSolid( private fun VisionGroup3D.addSolid(
context: GDMLTransformer, context: GDMLTransformer,
solid: GDMLSolid, solid: GDMLSolid,
name: String = "", name: String = "",
@ -154,7 +154,7 @@ private fun VisualGroup3D.addSolid(
private val volumesName = "volumes".asName() private val volumesName = "volumes".asName()
private fun VisualGroup3D.addPhysicalVolume( private fun VisionGroup3D.addPhysicalVolume(
context: GDMLTransformer, context: GDMLTransformer,
physVolume: GDMLPhysVolume physVolume: GDMLPhysVolume
) { ) {
@ -194,7 +194,7 @@ private fun VisualGroup3D.addPhysicalVolume(
} }
} }
private fun VisualGroup3D.addDivisionVolume( private fun VisionGroup3D.addDivisionVolume(
context: GDMLTransformer, context: GDMLTransformer,
divisionVolume: GDMLDivisionVolume divisionVolume: GDMLDivisionVolume
) { ) {
@ -216,8 +216,8 @@ private val solidsName = "solids".asName()
private fun volume( private fun volume(
context: GDMLTransformer, context: GDMLTransformer,
group: GDMLGroup group: GDMLGroup
): VisualGroup3D { ): VisionGroup3D {
return VisualGroup3D().apply { return VisionGroup3D().apply {
if (group is GDMLVolume) { if (group is GDMLVolume) {
val solid = group.solidref.resolve(context.root) val solid = group.solidref.resolve(context.root)
?: error("Solid with tag ${group.solidref.ref} for volume ${group.name} not defined") ?: error("Solid with tag ${group.solidref.ref} for volume ${group.name} not defined")
@ -253,7 +253,7 @@ private fun volume(
} }
} }
fun GDML.toVisual(block: GDMLTransformer.() -> Unit = {}): VisualGroup3D { fun GDML.toVisual(block: GDMLTransformer.() -> Unit = {}): VisionGroup3D {
val context = GDMLTransformer(this).apply(block) val context = GDMLTransformer(this).apply(block)
return context.finalize(volume(context, world)) return context.finalize(volume(context, world))
} }
@ -261,7 +261,7 @@ fun GDML.toVisual(block: GDMLTransformer.() -> Unit = {}): VisualGroup3D {
/** /**
* Append gdml node to the group * Append gdml node to the group
*/ */
fun VisualGroup3D.gdml(gdml: GDML, key: String = "", transformer: GDMLTransformer.() -> Unit = {}) { fun VisionGroup3D.gdml(gdml: GDML, key: String = "", transformer: GDMLTransformer.() -> Unit = {}) {
val visual = gdml.toVisual(transformer) val visual = gdml.toVisual(transformer)
//println(Visual3DPlugin.json.stringify(VisualGroup3D.serializer(), visual)) //println(Visual3DPlugin.json.stringify(VisualGroup3D.serializer(), visual))
set(key, visual) set(key, visual)

View File

@ -1,6 +1,6 @@
package hep.dataforge.vision.spatial.gdml package hep.dataforge.vision.spatial.gdml
import hep.dataforge.vision.spatial.VisualGroup3D import hep.dataforge.vision.spatial.VisionGroup3D
import nl.adaptivity.xmlutil.StAXReader import nl.adaptivity.xmlutil.StAXReader
import scientifik.gdml.GDML import scientifik.gdml.GDML
import java.nio.file.Files import java.nio.file.Files
@ -11,7 +11,7 @@ fun GDML.Companion.readFile(file: Path): GDML {
return format.parse(GDML.serializer(), xmlReader) return format.parse(GDML.serializer(), xmlReader)
} }
fun VisualGroup3D.gdml(file: Path, key: String = "", transformer: GDMLTransformer.() -> Unit = {}) { fun VisionGroup3D.gdml(file: Path, key: String = "", transformer: GDMLTransformer.() -> Unit = {}) {
val gdml = GDML.readFile(file) val gdml = GDML.readFile(file)
gdml(gdml, key, transformer) gdml(gdml, key, transformer)
} }

View File

@ -54,7 +54,7 @@ class Box(
override val type: KClass<Box> get() = Box::class override val type: KClass<Box> get() = Box::class
override fun invoke(context: Context, parent: VisualObject?, meta: Meta): Box = Box( override fun invoke(context: Context, parent: Vision?, meta: Meta): Box = Box(
meta["xSize"].float!!, meta["xSize"].float!!,
meta["ySize"].float!!, meta["ySize"].float!!,
meta["zSize"].float!! meta["zSize"].float!!
@ -64,7 +64,7 @@ class Box(
} }
} }
inline fun MutableVisualGroup.box( inline fun MutableVisionGroup.box(
xSize: Number, xSize: Number,
ySize: Number, ySize: Number,
zSize: Number, zSize: Number,

View File

@ -22,7 +22,7 @@ class Composite(
val compositeType: CompositeType, val compositeType: CompositeType,
val first: VisualObject3D, val first: VisualObject3D,
val second: VisualObject3D val second: VisualObject3D
) : AbstractVisualObject(), VisualObject3D, VisualGroup { ) : AbstractVisualObject(), VisualObject3D, VisionGroup {
init { init {
first.parent = this first.parent = this
@ -35,19 +35,19 @@ class Composite(
override var ownProperties: Config? = null override var ownProperties: Config? = null
override val children: Map<NameToken, VisualObject> override val children: Map<NameToken, Vision>
get() = mapOf(NameToken("first") to first, NameToken("second") to second) get() = mapOf(NameToken("first") to first, NameToken("second") to second)
override val styleSheet: StyleSheet? override val styleSheet: StyleSheet?
get() = null get() = null
} }
inline fun MutableVisualGroup.composite( inline fun MutableVisionGroup.composite(
type: CompositeType, type: CompositeType,
name: String = "", name: String = "",
builder: VisualGroup3D.() -> Unit builder: VisionGroup3D.() -> Unit
): Composite { ): Composite {
val group = VisualGroup3D().apply(builder) val group = VisionGroup3D().apply(builder)
val children = group.children.values.filterIsInstance<VisualObject3D>() val children = group.children.values.filterIsInstance<VisualObject3D>()
if (children.size != 2) error("Composite requires exactly two children") if (children.size != 2) error("Composite requires exactly two children")
return Composite(type, children[0], children[1]).also { return Composite(type, children[0], children[1]).also {
@ -67,11 +67,11 @@ inline fun MutableVisualGroup.composite(
} }
} }
inline fun MutableVisualGroup.union(name: String = "", builder: VisualGroup3D.() -> Unit) = inline fun MutableVisionGroup.union(name: String = "", builder: VisionGroup3D.() -> Unit) =
composite(CompositeType.UNION, name, builder = builder) composite(CompositeType.UNION, name, builder = builder)
inline fun MutableVisualGroup.subtract(name: String = "", builder: VisualGroup3D.() -> Unit) = inline fun MutableVisionGroup.subtract(name: String = "", builder: VisionGroup3D.() -> Unit) =
composite(CompositeType.SUBTRACT, name, builder = builder) composite(CompositeType.SUBTRACT, name, builder = builder)
inline fun MutableVisualGroup.intersect(name: String = "", builder: VisualGroup3D.() -> Unit) = inline fun MutableVisionGroup.intersect(name: String = "", builder: VisionGroup3D.() -> Unit) =
composite(CompositeType.INTERSECT, name, builder = builder) composite(CompositeType.INTERSECT, name, builder = builder)

View File

@ -4,7 +4,7 @@ package hep.dataforge.vision.spatial
import hep.dataforge.meta.Config import hep.dataforge.meta.Config
import hep.dataforge.vision.AbstractVisualObject import hep.dataforge.vision.AbstractVisualObject
import hep.dataforge.vision.MutableVisualGroup import hep.dataforge.vision.MutableVisionGroup
import hep.dataforge.vision.set import hep.dataforge.vision.set
import kotlinx.serialization.SerialName import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
@ -75,7 +75,7 @@ class ConeSegment(
} }
inline fun MutableVisualGroup.cylinder( inline fun MutableVisionGroup.cylinder(
r: Number, r: Number,
height: Number, height: Number,
name: String = "", name: String = "",
@ -87,7 +87,7 @@ inline fun MutableVisualGroup.cylinder(
).apply(block).also { set(name, it) } ).apply(block).also { set(name, it) }
inline fun MutableVisualGroup.cone( inline fun MutableVisionGroup.cone(
bottomRadius: Number, bottomRadius: Number,
height: Number, height: Number,
upperRadius: Number = 0.0, upperRadius: Number = 0.0,

View File

@ -4,7 +4,7 @@ package hep.dataforge.vision.spatial
import hep.dataforge.meta.Config import hep.dataforge.meta.Config
import hep.dataforge.vision.AbstractVisualObject import hep.dataforge.vision.AbstractVisualObject
import hep.dataforge.vision.MutableVisualGroup import hep.dataforge.vision.MutableVisionGroup
import hep.dataforge.vision.set import hep.dataforge.vision.set
import kotlinx.serialization.SerialName import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
@ -25,7 +25,7 @@ class Convex(val points: List<Point3D>) : AbstractVisualObject(), VisualObject3D
} }
} }
inline fun MutableVisualGroup.convex(name: String = "", action: ConvexBuilder.() -> Unit = {}) = inline fun MutableVisionGroup.convex(name: String = "", action: ConvexBuilder.() -> Unit = {}) =
ConvexBuilder().apply(action).build().also { set(name, it) } ConvexBuilder().apply(action).build().also { set(name, it) }
class ConvexBuilder { class ConvexBuilder {

View File

@ -3,7 +3,7 @@ package hep.dataforge.vision.spatial
import hep.dataforge.meta.Config import hep.dataforge.meta.Config
import hep.dataforge.vision.AbstractVisualObject import hep.dataforge.vision.AbstractVisualObject
import hep.dataforge.vision.MutableVisualGroup import hep.dataforge.vision.MutableVisionGroup
import hep.dataforge.vision.set import hep.dataforge.vision.set
import kotlinx.serialization.SerialName import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
@ -112,5 +112,5 @@ class Extruded(
} }
} }
fun MutableVisualGroup.extrude(name: String = "", action: Extruded.() -> Unit = {}) = fun MutableVisionGroup.extrude(name: String = "", action: Extruded.() -> Unit = {}) =
Extruded().apply(action).also { set(name, it) } Extruded().apply(action).also { set(name, it) }

View File

@ -4,7 +4,7 @@ package hep.dataforge.vision.spatial
import hep.dataforge.meta.Config import hep.dataforge.meta.Config
import hep.dataforge.vision.AbstractVisualObject import hep.dataforge.vision.AbstractVisualObject
import hep.dataforge.vision.MutableVisualGroup import hep.dataforge.vision.MutableVisionGroup
import hep.dataforge.vision.set import hep.dataforge.vision.set
import kotlinx.serialization.SerialName import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
@ -21,7 +21,7 @@ class Label3D(var text: String, var fontSize: Double, var fontFamily: String) :
} }
fun MutableVisualGroup.label( fun MutableVisionGroup.label(
text: String, text: String,
fontSize: Number = 20, fontSize: Number = 20,
fontFamily: String = "Arial", fontFamily: String = "Arial",

View File

@ -7,7 +7,7 @@ import hep.dataforge.meta.number
import hep.dataforge.names.asName import hep.dataforge.names.asName
import hep.dataforge.names.plus import hep.dataforge.names.plus
import hep.dataforge.vision.AbstractVisualObject import hep.dataforge.vision.AbstractVisualObject
import hep.dataforge.vision.MutableVisualGroup import hep.dataforge.vision.MutableVisionGroup
import hep.dataforge.vision.set import hep.dataforge.vision.set
import kotlinx.serialization.SerialName import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
@ -31,5 +31,5 @@ class PolyLine(var points: List<Point3D>) : AbstractVisualObject(), VisualObject
} }
fun MutableVisualGroup.polyline(vararg points: Point3D, name: String = "", action: PolyLine.() -> Unit = {}) = fun MutableVisionGroup.polyline(vararg points: Point3D, name: String = "", action: PolyLine.() -> Unit = {}) =
PolyLine(points.toList()).apply(action).also { set(name, it) } PolyLine(points.toList()).apply(action).also { set(name, it) }

View File

@ -22,9 +22,9 @@ import kotlin.collections.set
@SerialName("3d.proxy") @SerialName("3d.proxy")
class Proxy private constructor( class Proxy private constructor(
val templateName: Name val templateName: Name
) : AbstractVisualObject(), VisualGroup, VisualObject3D { ) : AbstractVisualObject(), VisionGroup, VisualObject3D {
constructor(parent: VisualGroup3D, templateName: Name) : this(templateName) { constructor(parent: VisionGroup3D, templateName: Name) : this(templateName) {
this.parent = parent this.parent = parent
} }
@ -38,7 +38,7 @@ class Proxy private constructor(
* Recursively search for defined template in the parent * Recursively search for defined template in the parent
*/ */
val prototype: VisualObject3D val prototype: VisualObject3D
get() = (parent as? VisualGroup3D)?.getPrototype(templateName) get() = (parent as? VisionGroup3D)?.getPrototype(templateName)
?: error("Prototype with name $templateName not found in $parent") ?: error("Prototype with name $templateName not found in $parent")
override val styleSheet: StyleSheet override val styleSheet: StyleSheet
@ -64,7 +64,7 @@ class Proxy private constructor(
} }
override val children: Map<NameToken, ProxyChild> override val children: Map<NameToken, ProxyChild>
get() = (prototype as? VisualGroup)?.children get() = (prototype as? VisionGroup)?.children
?.filter { !it.key.toString().startsWith("@") } ?.filter { !it.key.toString().startsWith("@") }
?.mapValues { ?.mapValues {
ProxyChild(it.key.asName()) ProxyChild(it.key.asName())
@ -77,8 +77,8 @@ class Proxy private constructor(
return NameToken(PROXY_CHILD_PROPERTY_PREFIX, childName.toString()) + propertyName return NameToken(PROXY_CHILD_PROPERTY_PREFIX, childName.toString()) + propertyName
} }
private fun prototypeFor(name: Name): VisualObject { private fun prototypeFor(name: Name): Vision {
return (prototype as? VisualGroup)?.get(name) return (prototype as? VisionGroup)?.get(name)
?: error("Prototype with name $name not found in $this") ?: error("Prototype with name $name not found in $this")
} }
@ -95,14 +95,14 @@ class Proxy private constructor(
get() = prototype.descriptor get() = prototype.descriptor
inner class ProxyChild(val name: Name) : AbstractVisualObject(), inner class ProxyChild(val name: Name) : AbstractVisualObject(),
VisualGroup { VisionGroup {
val prototype: VisualObject get() = prototypeFor(name) val prototype: Vision get() = prototypeFor(name)
override val styleSheet: StyleSheet get() = this@Proxy.styleSheet override val styleSheet: StyleSheet get() = this@Proxy.styleSheet
override val children: Map<NameToken, VisualObject> override val children: Map<NameToken, Vision>
get() = (prototype as? VisualGroup)?.children?.mapValues { (key, _) -> get() = (prototype as? VisionGroup)?.children?.mapValues { (key, _) ->
ProxyChild( ProxyChild(
name + key.asName() name + key.asName()
) )
@ -159,7 +159,7 @@ class Proxy private constructor(
} }
} }
val VisualObject.prototype: VisualObject val Vision.prototype: Vision
get() = when (this) { get() = when (this) {
is Proxy -> prototype is Proxy -> prototype
is Proxy.ProxyChild -> prototype is Proxy.ProxyChild -> prototype
@ -169,7 +169,7 @@ val VisualObject.prototype: VisualObject
/** /**
* Create ref for existing prototype * Create ref for existing prototype
*/ */
fun VisualGroup3D.ref( fun VisionGroup3D.ref(
templateName: Name, templateName: Name,
name: String = "" name: String = ""
): Proxy = Proxy(this, templateName).also { set(name, it) } ): Proxy = Proxy(this, templateName).also { set(name, it) }
@ -177,7 +177,7 @@ fun VisualGroup3D.ref(
/** /**
* Add new proxy wrapping given object and automatically adding it to the prototypes * Add new proxy wrapping given object and automatically adding it to the prototypes
*/ */
fun VisualGroup3D.proxy( fun VisionGroup3D.proxy(
name: String, name: String,
obj: VisualObject3D, obj: VisualObject3D,
templateName: Name = name.toName() templateName: Name = name.toName()
@ -193,11 +193,11 @@ fun VisualGroup3D.proxy(
return ref(templateName, name) return ref(templateName, name)
} }
fun VisualGroup3D.proxyGroup( fun VisionGroup3D.proxyGroup(
name: String, name: String,
templateName: Name = name.toName(), templateName: Name = name.toName(),
block: MutableVisualGroup.() -> Unit block: MutableVisionGroup.() -> Unit
): Proxy { ): Proxy {
val group = VisualGroup3D().apply (block) val group = VisionGroup3D().apply (block)
return proxy(name, group, templateName) return proxy(name, group, templateName)
} }

View File

@ -4,7 +4,7 @@ package hep.dataforge.vision.spatial
import hep.dataforge.meta.Config import hep.dataforge.meta.Config
import hep.dataforge.vision.AbstractVisualObject import hep.dataforge.vision.AbstractVisualObject
import hep.dataforge.vision.MutableVisualGroup import hep.dataforge.vision.MutableVisionGroup
import hep.dataforge.vision.set import hep.dataforge.vision.set
import kotlinx.serialization.SerialName import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
@ -60,7 +60,7 @@ class Sphere(
} }
} }
inline fun MutableVisualGroup.sphere( inline fun MutableVisionGroup.sphere(
radius: Number, radius: Number,
phi: Number = 2 * PI, phi: Number = 2 * PI,
theta: Number = PI, theta: Number = PI,

View File

@ -4,7 +4,7 @@ package hep.dataforge.vision.spatial
import hep.dataforge.meta.Config import hep.dataforge.meta.Config
import hep.dataforge.vision.AbstractVisualObject import hep.dataforge.vision.AbstractVisualObject
import hep.dataforge.vision.MutableVisualGroup import hep.dataforge.vision.MutableVisionGroup
import hep.dataforge.vision.set import hep.dataforge.vision.set
import kotlinx.serialization.SerialName import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
@ -129,7 +129,7 @@ class Tube(
} }
inline fun MutableVisualGroup.tube( inline fun MutableVisionGroup.tube(
r: Number, r: Number,
height: Number, height: Number,
innerRadius: Number = 0f, innerRadius: Number = 0f,

View File

@ -15,8 +15,8 @@ import kotlinx.serialization.UseSerializers
import kotlin.collections.set import kotlin.collections.set
interface PrototypeHolder { interface PrototypeHolder {
val parent: VisualGroup? val parent: VisionGroup?
val prototypes: MutableVisualGroup? val prototypes: MutableVisionGroup?
} }
/** /**
@ -24,7 +24,7 @@ interface PrototypeHolder {
*/ */
@Serializable @Serializable
@SerialName("group.3d") @SerialName("group.3d")
class VisualGroup3D : AbstractVisualGroup(), VisualObject3D, PrototypeHolder { class VisionGroup3D : AbstractVision(), VisualObject3D, PrototypeHolder {
override var styleSheet: StyleSheet? = null override var styleSheet: StyleSheet? = null
@ -32,13 +32,13 @@ class VisualGroup3D : AbstractVisualGroup(), VisualObject3D, PrototypeHolder {
* A container for templates visible inside this group * A container for templates visible inside this group
*/ */
@Serializable(PrototypesSerializer::class) @Serializable(PrototypesSerializer::class)
override var prototypes: MutableVisualGroup? = null override var prototypes: MutableVisionGroup? = null
private set private set
/** /**
* Create or edit prototype node as a group * Create or edit prototype node as a group
*/ */
fun prototypes(builder: MutableVisualGroup.() -> Unit): Unit { fun prototypes(builder: MutableVisionGroup.() -> Unit): Unit {
(prototypes ?: Prototypes().also { (prototypes ?: Prototypes().also {
prototypes = it prototypes = it
attach(it) attach(it)
@ -53,8 +53,8 @@ class VisualGroup3D : AbstractVisualGroup(), VisualObject3D, PrototypeHolder {
override var scale: Point3D? = null override var scale: Point3D? = null
@SerialName("children") @SerialName("children")
private val _children = HashMap<NameToken, VisualObject>() private val _children = HashMap<NameToken, Vision>()
override val children: Map<NameToken, VisualObject> get() = _children override val children: Map<NameToken, Vision> get() = _children
override fun attachChildren() { override fun attachChildren() {
prototypes?.parent = this prototypes?.parent = this
@ -66,7 +66,7 @@ class VisualGroup3D : AbstractVisualGroup(), VisualObject3D, PrototypeHolder {
_children.remove(token)?.apply { parent = null } _children.remove(token)?.apply { parent = null }
} }
override fun setChild(token: NameToken, child: VisualObject) { override fun setChild(token: NameToken, child: Vision) {
_children[token] = child _children[token] = child
} }
@ -75,13 +75,13 @@ class VisualGroup3D : AbstractVisualGroup(), VisualObject3D, PrototypeHolder {
// */ // */
// override fun addStatic(child: VisualObject) = setChild(NameToken("@static(${child.hashCode()})"), child) // override fun addStatic(child: VisualObject) = setChild(NameToken("@static(${child.hashCode()})"), child)
override fun createGroup(): VisualGroup3D = VisualGroup3D() override fun createGroup(): VisionGroup3D = VisionGroup3D()
companion object { companion object {
// val PROTOTYPES_KEY = NameToken("@prototypes") // val PROTOTYPES_KEY = NameToken("@prototypes")
fun parseJson(json: String): VisualGroup3D = fun parseJson(json: String): VisionGroup3D =
Visual3D.json.parse(serializer(), json).also { it.attachChildren() } Visual3D.json.parse(serializer(), json).also { it.attachChildren() }
} }
} }
@ -95,14 +95,14 @@ tailrec fun PrototypeHolder.getPrototype(name: Name): VisualObject3D? =
/** /**
* Define a group with given [name], attach it to this parent and return it. * Define a group with given [name], attach it to this parent and return it.
*/ */
fun MutableVisualGroup.group(name: String = "", action: VisualGroup3D.() -> Unit = {}): VisualGroup3D = fun MutableVisionGroup.group(name: String = "", action: VisionGroup3D.() -> Unit = {}): VisionGroup3D =
VisualGroup3D().apply(action).also { VisionGroup3D().apply(action).also {
set(name, it) set(name, it)
} }
internal class Prototypes( internal class Prototypes(
override var children: MutableMap<NameToken, VisualObject> = LinkedHashMap() override var children: MutableMap<NameToken, Vision> = LinkedHashMap()
) : AbstractVisualGroup(), MutableVisualGroup, PrototypeHolder { ) : AbstractVision(), MutableVisionGroup, PrototypeHolder {
override var styleSheet: StyleSheet? override var styleSheet: StyleSheet?
get() = null get() = null
@ -115,11 +115,11 @@ internal class Prototypes(
childrenChanged(token.asName(), null) childrenChanged(token.asName(), null)
} }
override fun setChild(token: NameToken, child: VisualObject) { override fun setChild(token: NameToken, child: Vision) {
children[token] = child children[token] = child
} }
override fun createGroup() = SimpleVisualGroup() override fun createGroup() = SimpleVisionGroup()
override var ownProperties: Config? override var ownProperties: Config?
get() = null get() = null
@ -127,12 +127,12 @@ internal class Prototypes(
error("Can't define properties for prototypes block") error("Can't define properties for prototypes block")
} }
override val prototypes: MutableVisualGroup get() = this override val prototypes: MutableVisionGroup get() = this
override fun attachChildren() { override fun attachChildren() {
children.values.forEach { children.values.forEach {
it.parent = parent it.parent = parent
(it as? VisualGroup)?.attachChildren() (it as? VisionGroup)?.attachChildren()
} }
} }
} }

View File

@ -7,9 +7,9 @@ import hep.dataforge.context.PluginTag
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.vision.SimpleVisualGroup import hep.dataforge.vision.SimpleVisionGroup
import hep.dataforge.vision.Visual import hep.dataforge.vision.Vision
import hep.dataforge.vision.VisualObject import hep.dataforge.vision.VisionManager
import kotlinx.serialization.UnstableDefault import kotlinx.serialization.UnstableDefault
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonConfiguration import kotlinx.serialization.json.JsonConfiguration
@ -19,11 +19,11 @@ import kotlin.reflect.KClass
class Visual3D(meta: Meta) : AbstractPlugin(meta) { class Visual3D(meta: Meta) : AbstractPlugin(meta) {
val visual by require(Visual) val visual by require(VisionManager)
override val tag: PluginTag get() = Companion.tag override val tag: PluginTag get() = Companion.tag
override fun provideTop(target: String): Map<Name, Any> = if (target == Visual.VISUAL_FACTORY_TYPE) { override fun provideTop(target: String): Map<Name, Any> = if (target == VisionManager.VISUAL_FACTORY_TYPE) {
mapOf(Box.TYPE_NAME.toName() to Box) mapOf(Box.TYPE_NAME.toName() to Box)
} else { } else {
super.provideTop(target) super.provideTop(target)
@ -39,9 +39,9 @@ class Visual3D(meta: Meta) : AbstractPlugin(meta) {
contextual(Point3DSerializer) contextual(Point3DSerializer)
contextual(Point2DSerializer) contextual(Point2DSerializer)
polymorphic(VisualObject::class, VisualObject3D::class) { polymorphic(Vision::class, VisualObject3D::class) {
subclass(SimpleVisualGroup.serializer()) subclass(SimpleVisionGroup.serializer())
subclass(VisualGroup3D.serializer()) subclass(VisionGroup3D.serializer())
subclass(Proxy.serializer()) subclass(Proxy.serializer())
subclass(Composite.serializer()) subclass(Composite.serializer())
subclass(Tube.serializer()) subclass(Tube.serializer())

View File

@ -9,7 +9,7 @@ import hep.dataforge.names.plus
import hep.dataforge.output.Renderer import hep.dataforge.output.Renderer
import hep.dataforge.values.ValueType import hep.dataforge.values.ValueType
import hep.dataforge.values.asValue import hep.dataforge.values.asValue
import hep.dataforge.vision.VisualObject import hep.dataforge.vision.Vision
import hep.dataforge.vision.enum import hep.dataforge.vision.enum
import hep.dataforge.vision.spatial.VisualObject3D.Companion.DETAIL_KEY import hep.dataforge.vision.spatial.VisualObject3D.Companion.DETAIL_KEY
import hep.dataforge.vision.spatial.VisualObject3D.Companion.IGNORE_KEY import hep.dataforge.vision.spatial.VisualObject3D.Companion.IGNORE_KEY
@ -18,9 +18,9 @@ import hep.dataforge.vision.spatial.VisualObject3D.Companion.VISIBLE_KEY
import kotlinx.serialization.UseSerializers import kotlinx.serialization.UseSerializers
/** /**
* Interface for 3-dimensional [VisualObject] * Interface for 3-dimensional [Vision]
*/ */
interface VisualObject3D : VisualObject { interface VisualObject3D : Vision {
var position: Point3D? var position: Point3D?
var rotation: Point3D? var rotation: Point3D?
var scale: Point3D? var scale: Point3D?
@ -70,7 +70,7 @@ interface VisualObject3D : VisualObject {
} }
//TODO replace by descriptor merge //TODO replace by descriptor merge
value(VisualObject.STYLE_KEY) { value(Vision.STYLE_KEY) {
type(ValueType.STRING) type(ValueType.STRING)
multiple = true multiple = true
} }
@ -92,8 +92,8 @@ var VisualObject3D.layer: Int
setItem(LAYER_KEY, value.asValue()) setItem(LAYER_KEY, value.asValue())
} }
fun Renderer<VisualObject3D>.render(meta: Meta = Meta.EMPTY, action: VisualGroup3D.() -> Unit) = fun Renderer<VisualObject3D>.render(meta: Meta = Meta.EMPTY, action: VisionGroup3D.() -> Unit) =
render(VisualGroup3D().apply(action), meta) render(VisionGroup3D().apply(action), meta)
// Common properties // Common properties
@ -121,7 +121,7 @@ var VisualObject3D.detail: Int?
get() = getProperty(DETAIL_KEY, false).int get() = getProperty(DETAIL_KEY, false).int
set(value) = setItem(DETAIL_KEY, value?.asValue()) set(value) = setItem(DETAIL_KEY, value?.asValue())
var VisualObject.visible: Boolean? var Vision.visible: Boolean?
get() = getItem(VISIBLE_KEY).boolean get() = getItem(VISIBLE_KEY).boolean
set(value) = setItem(VISIBLE_KEY, value?.asValue()) set(value) = setItem(VISIBLE_KEY, value?.asValue())
@ -129,7 +129,7 @@ var VisualObject.visible: Boolean?
* If this property is true, the object will be ignored on render. * If this property is true, the object will be ignored on render.
* Property is not inherited. * Property is not inherited.
*/ */
var VisualObject.ignore: Boolean? var Vision.ignore: Boolean?
get() = getProperty(IGNORE_KEY, false).boolean get() = getProperty(IGNORE_KEY, false).boolean
set(value) = setItem(IGNORE_KEY, value?.asValue()) set(value) = setItem(IGNORE_KEY, value?.asValue())

View File

@ -2,9 +2,9 @@ package hep.dataforge.vision.spatial
import hep.dataforge.meta.double import hep.dataforge.meta.double
import hep.dataforge.names.NameToken import hep.dataforge.names.NameToken
import hep.dataforge.vision.MutableVisualGroup import hep.dataforge.vision.MutableVisionGroup
import hep.dataforge.vision.VisualGroup import hep.dataforge.vision.Vision
import hep.dataforge.vision.VisualObject import hep.dataforge.vision.VisionGroup
import kotlinx.serialization.* import kotlinx.serialization.*
import kotlinx.serialization.builtins.MapSerializer import kotlinx.serialization.builtins.MapSerializer
import kotlinx.serialization.builtins.nullable import kotlinx.serialization.builtins.nullable
@ -97,31 +97,31 @@ object Point2DSerializer : KSerializer<Point2D> {
} }
} }
@Serializer(MutableVisualGroup::class) @Serializer(MutableVisionGroup::class)
internal object PrototypesSerializer : KSerializer<MutableVisualGroup> { internal object PrototypesSerializer : KSerializer<MutableVisionGroup> {
private val mapSerializer: KSerializer<Map<NameToken, VisualObject>> = private val mapSerializer: KSerializer<Map<NameToken, Vision>> =
MapSerializer( MapSerializer(
NameToken.serializer(), NameToken.serializer(),
VisualObject.serializer() Vision.serializer()
) )
override val descriptor: SerialDescriptor get() = mapSerializer.descriptor override val descriptor: SerialDescriptor get() = mapSerializer.descriptor
override fun deserialize(decoder: Decoder): MutableVisualGroup { override fun deserialize(decoder: Decoder): MutableVisionGroup {
val map = mapSerializer.deserialize(decoder) val map = mapSerializer.deserialize(decoder)
return Prototypes(map as? MutableMap<NameToken, VisualObject> ?: LinkedHashMap(map)) return Prototypes(map as? MutableMap<NameToken, Vision> ?: LinkedHashMap(map))
} }
override fun serialize(encoder: Encoder, value: MutableVisualGroup) { override fun serialize(encoder: Encoder, value: MutableVisionGroup) {
mapSerializer.serialize(encoder, value.children) mapSerializer.serialize(encoder, value.children)
} }
} }
fun VisualObject.stringify(): String = Visual3D.json.stringify(VisualObject.serializer(), this) fun Vision.stringify(): String = Visual3D.json.stringify(Vision.serializer(), this)
fun VisualObject.Companion.parseJson(str: String) = Visual3D.json.parse(VisualObject.serializer(), str).also { fun Vision.Companion.parseJson(str: String) = Visual3D.json.parse(Vision.serializer(), str).also {
if(it is VisualGroup){ if(it is VisionGroup){
it.attachChildren() it.attachChildren()
} }
} }

View File

@ -2,12 +2,12 @@ package hep.dataforge.vision.spatial.transform
import hep.dataforge.meta.update import hep.dataforge.meta.update
import hep.dataforge.names.asName import hep.dataforge.names.asName
import hep.dataforge.vision.MutableVisualGroup import hep.dataforge.vision.MutableVisionGroup
import hep.dataforge.vision.VisualGroup import hep.dataforge.vision.Vision
import hep.dataforge.vision.VisualObject import hep.dataforge.vision.VisionGroup
import hep.dataforge.vision.spatial.* import hep.dataforge.vision.spatial.*
internal fun mergeChild(parent: VisualGroup, child: VisualObject): VisualObject { internal fun mergeChild(parent: VisionGroup, child: Vision): Vision {
return child.apply { return child.apply {
config.update(parent.config) config.update(parent.config)
@ -32,16 +32,16 @@ internal fun mergeChild(parent: VisualGroup, child: VisualObject): VisualObject
} }
} }
object RemoveSingleChild : VisualTreeTransform<VisualGroup3D>() { object RemoveSingleChild : VisualTreeTransform<VisionGroup3D>() {
override fun VisualGroup3D.transformInPlace() { override fun VisionGroup3D.transformInPlace() {
fun MutableVisualGroup.replaceChildren() { fun MutableVisionGroup.replaceChildren() {
children.forEach { (childName, parent) -> children.forEach { (childName, parent) ->
if (parent is Proxy) return@forEach //ignore refs if (parent is Proxy) return@forEach //ignore refs
if (parent is MutableVisualGroup) { if (parent is MutableVisionGroup) {
parent.replaceChildren() parent.replaceChildren()
} }
if (parent is VisualGroup && parent.children.size == 1) { if (parent is VisionGroup && parent.children.size == 1) {
val child = parent.children.values.first() val child = parent.children.values.first()
val newParent = mergeChild(parent, child) val newParent = mergeChild(parent, child)
newParent.parent = null newParent.parent = null
@ -56,7 +56,7 @@ object RemoveSingleChild : VisualTreeTransform<VisualGroup3D>() {
} }
} }
override fun VisualGroup3D.clone(): VisualGroup3D { override fun VisionGroup3D.clone(): VisionGroup3D {
TODO() TODO()
} }
} }

View File

@ -2,15 +2,15 @@ package hep.dataforge.vision.spatial.transform
import hep.dataforge.names.Name import hep.dataforge.names.Name
import hep.dataforge.names.asName import hep.dataforge.names.asName
import hep.dataforge.vision.MutableVisualGroup import hep.dataforge.vision.MutableVisionGroup
import hep.dataforge.vision.VisualGroup import hep.dataforge.vision.VisionGroup
import hep.dataforge.vision.spatial.Proxy import hep.dataforge.vision.spatial.Proxy
import hep.dataforge.vision.spatial.VisualGroup3D import hep.dataforge.vision.spatial.VisionGroup3D
object UnRef : VisualTreeTransform<VisualGroup3D>() { object UnRef : VisualTreeTransform<VisionGroup3D>() {
private fun VisualGroup.countRefs(): Map<Name, Int> { private fun VisionGroup.countRefs(): Map<Name, Int> {
return children.values.fold(HashMap()) { reducer, obj -> return children.values.fold(HashMap()) { reducer, obj ->
if (obj is VisualGroup) { if (obj is VisionGroup) {
val counter = obj.countRefs() val counter = obj.countRefs()
counter.forEach { (key, value) -> counter.forEach { (key, value) ->
reducer[key] = (reducer[key] ?: 0) + value reducer[key] = (reducer[key] ?: 0) + value
@ -23,8 +23,8 @@ object UnRef : VisualTreeTransform<VisualGroup3D>() {
} }
} }
private fun MutableVisualGroup.unref(name: Name) { private fun MutableVisionGroup.unref(name: Name) {
(this as? VisualGroup3D)?.prototypes?.set(name, null) (this as? VisionGroup3D)?.prototypes?.set(name, null)
children.filter { (it.value as? Proxy)?.templateName == name }.forEach { (key, value) -> children.filter { (it.value as? Proxy)?.templateName == name }.forEach { (key, value) ->
val proxy = value as Proxy val proxy = value as Proxy
val newChild = mergeChild(proxy, proxy.prototype) val newChild = mergeChild(proxy, proxy.prototype)
@ -32,17 +32,17 @@ object UnRef : VisualTreeTransform<VisualGroup3D>() {
set(key.asName(), newChild) // replace proxy with merged object set(key.asName(), newChild) // replace proxy with merged object
} }
children.values.filterIsInstance<MutableVisualGroup>().forEach { it.unref(name) } children.values.filterIsInstance<MutableVisionGroup>().forEach { it.unref(name) }
} }
override fun VisualGroup3D.transformInPlace() { override fun VisionGroup3D.transformInPlace() {
val counts = countRefs() val counts = countRefs()
counts.filter { it.value <= 1 }.forEach { counts.filter { it.value <= 1 }.forEach {
this.unref(it.key) this.unref(it.key)
} }
} }
override fun VisualGroup3D.clone(): VisualGroup3D { override fun VisionGroup3D.clone(): VisionGroup3D {
TODO() TODO()
} }

View File

@ -1,11 +1,11 @@
package hep.dataforge.vision.spatial.transform package hep.dataforge.vision.spatial.transform
import hep.dataforge.vision.VisualObject import hep.dataforge.vision.Vision
/** /**
* A root class for [VisualObject] tree optimization * A root class for [Vision] tree optimization
*/ */
abstract class VisualTreeTransform<T : VisualObject> { abstract class VisualTreeTransform<T : Vision> {
protected abstract fun T.transformInPlace() protected abstract fun T.transformInPlace()
protected abstract fun T.clone(): T protected abstract fun T.clone(): T
@ -21,7 +21,7 @@ abstract class VisualTreeTransform<T : VisualObject> {
} }
} }
fun <T : VisualObject> T.transform(vararg transform: VisualTreeTransform<T>): T { fun <T : Vision> T.transform(vararg transform: VisualTreeTransform<T>): T {
var res = this var res = this
transform.forEach { transform.forEach {
res = it(res) res = it(res)
@ -29,6 +29,6 @@ fun <T : VisualObject> T.transform(vararg transform: VisualTreeTransform<T>): T
return res return res
} }
fun <T : VisualObject> T.transformInPlace(vararg transform: VisualTreeTransform<in T>) { fun <T : Vision> T.transformInPlace(vararg transform: VisualTreeTransform<in T>) {
transform.forEach { it(this) } transform.forEach { it(this) }
} }

View File

@ -11,7 +11,7 @@ class ConvexTest {
@Suppress("UNUSED_VARIABLE") @Suppress("UNUSED_VARIABLE")
@Test @Test
fun testConvexBuilder() { fun testConvexBuilder() {
val group = VisualGroup3D().apply { val group = VisionGroup3D().apply {
convex { convex {
point(50, 50, -50) point(50, 50, -50)
point(50, -50, -50) point(50, -50, -50)

View File

@ -9,7 +9,7 @@ import kotlin.test.assertEquals
class GroupTest { class GroupTest {
@Test @Test
fun testGroupWithComposite() { fun testGroupWithComposite() {
val group = VisualGroup3D().apply { val group = VisionGroup3D().apply {
union("union") { union("union") {
box(100, 100, 100) { box(100, 100, 100) {
z = 100 z = 100

View File

@ -12,7 +12,7 @@ class PropertyTest {
@Test @Test
fun testInheritedProperty() { fun testInheritedProperty() {
var box: Box? = null var box: Box? = null
val group = VisualGroup3D().apply { val group = VisionGroup3D().apply {
config["test"] = 22 config["test"] = 22
group { group {
box = box(100, 100, 100) box = box(100, 100, 100)
@ -24,7 +24,7 @@ class PropertyTest {
@Test @Test
fun testStyleProperty() { fun testStyleProperty() {
var box: Box? = null var box: Box? = null
val group = VisualGroup3D().apply { val group = VisionGroup3D().apply {
styleSheet { styleSheet {
set("testStyle") { set("testStyle") {
"test" put 22 "test" put 22
@ -42,7 +42,7 @@ class PropertyTest {
@Test @Test
fun testColor() { fun testColor() {
var box: Box? = null var box: Box? = null
val group = VisualGroup3D().apply { val group = VisionGroup3D().apply {
styleSheet { styleSheet {
set("testStyle") { set("testStyle") {
Material3D.MATERIAL_COLOR_KEY put "#555555" Material3D.MATERIAL_COLOR_KEY put "#555555"
@ -60,7 +60,7 @@ class PropertyTest {
@Test @Test
fun testProxyStyleProperty() { fun testProxyStyleProperty() {
var box: Proxy? = null var box: Proxy? = null
val group = VisualGroup3D().apply { val group = VisionGroup3D().apply {
styleSheet { styleSheet {
set("testStyle") { set("testStyle") {
Material3D.MATERIAL_COLOR_KEY put "#555555" Material3D.MATERIAL_COLOR_KEY put "#555555"

View File

@ -1,7 +1,7 @@
package hep.dataforge.vision.spatial package hep.dataforge.vision.spatial
import hep.dataforge.names.toName import hep.dataforge.names.toName
import hep.dataforge.vision.VisualObject import hep.dataforge.vision.Vision
import hep.dataforge.vision.get import hep.dataforge.vision.get
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals
@ -16,7 +16,7 @@ class SerializationTest {
} }
val string = cube.stringify() val string = cube.stringify()
println(string) println(string)
val newCube = VisualObject.parseJson(string) val newCube = Vision.parseJson(string)
assertEquals(cube.config, newCube.config) assertEquals(cube.config, newCube.config)
} }
@ -27,7 +27,7 @@ class SerializationTest {
x = 100 x = 100
z = -100 z = -100
} }
val group = VisualGroup3D().apply { val group = VisionGroup3D().apply {
proxy("cube", cube) proxy("cube", cube)
proxyGroup("pg", "pg.content".toName()){ proxyGroup("pg", "pg.content".toName()){
sphere(50){ sphere(50){
@ -37,7 +37,7 @@ class SerializationTest {
} }
val string = group.stringify() val string = group.stringify()
println(string) println(string)
val reconstructed = VisualGroup3D.parseJson(string) val reconstructed = VisionGroup3D.parseJson(string)
assertEquals(group["cube"]?.config, reconstructed["cube"]?.config) assertEquals(group["cube"]?.config, reconstructed["cube"]?.config)
} }
} }

View File

@ -3,7 +3,7 @@ package hep.dataforge.vision.spatial.three
import hep.dataforge.names.Name import hep.dataforge.names.Name
import hep.dataforge.names.startsWith import hep.dataforge.names.startsWith
import hep.dataforge.provider.Type import hep.dataforge.provider.Type
import hep.dataforge.vision.VisualObject import hep.dataforge.vision.Vision
import hep.dataforge.vision.spatial.* import hep.dataforge.vision.spatial.*
import hep.dataforge.vision.spatial.Material3D.Companion.MATERIAL_KEY import hep.dataforge.vision.spatial.Material3D.Companion.MATERIAL_KEY
import hep.dataforge.vision.spatial.three.ThreeFactory.Companion.TYPE import hep.dataforge.vision.spatial.three.ThreeFactory.Companion.TYPE
@ -17,7 +17,7 @@ import kotlin.reflect.KClass
* Builder and updater for three.js object * Builder and updater for three.js object
*/ */
@Type(TYPE) @Type(TYPE)
interface ThreeFactory<in T : VisualObject> { interface ThreeFactory<in T : Vision> {
val type: KClass<in T> val type: KClass<in T>
@ -31,7 +31,7 @@ interface ThreeFactory<in T : VisualObject> {
/** /**
* Update position, rotation and visibility * Update position, rotation and visibility
*/ */
fun Object3D.updatePosition(obj: VisualObject) { fun Object3D.updatePosition(obj: Vision) {
visible = obj.visible ?: true visible = obj.visible ?: true
if(obj is VisualObject3D) { if(obj is VisualObject3D) {
position.set(obj.x, obj.y, obj.z) position.set(obj.x, obj.y, obj.z)
@ -56,7 +56,7 @@ fun Object3D.updatePosition(obj: VisualObject) {
/** /**
* Update non-position non-geometry property * Update non-position non-geometry property
*/ */
fun Object3D.updateProperty(source: VisualObject, propertyName: Name) { fun Object3D.updateProperty(source: Vision, propertyName: Name) {
if (this is Mesh && propertyName.startsWith(MATERIAL_KEY)) { if (this is Mesh && propertyName.startsWith(MATERIAL_KEY)) {
this.material = getMaterial(source) this.material = getMaterial(source)
} else if ( } else if (

View File

@ -3,7 +3,7 @@ package hep.dataforge.vision.spatial.three
import hep.dataforge.meta.* import hep.dataforge.meta.*
import hep.dataforge.values.ValueType import hep.dataforge.values.ValueType
import hep.dataforge.vision.Colors import hep.dataforge.vision.Colors
import hep.dataforge.vision.VisualObject import hep.dataforge.vision.Vision
import hep.dataforge.vision.spatial.Material3D import hep.dataforge.vision.spatial.Material3D
import info.laht.threekt.materials.LineBasicMaterial import info.laht.threekt.materials.LineBasicMaterial
import info.laht.threekt.materials.Material import info.laht.threekt.materials.Material
@ -43,8 +43,8 @@ object ThreeMaterials {
} }
} }
fun getMaterial(visualObject3D: VisualObject): Material { fun getMaterial(vision3D: Vision): Material {
val meta = visualObject3D.getItem(Material3D.MATERIAL_KEY).node ?: return ThreeMaterials.DEFAULT val meta = vision3D.getItem(Material3D.MATERIAL_KEY).node ?: return ThreeMaterials.DEFAULT
return if (meta[Material3D.SPECULAR_COLOR_KEY] != null) { return if (meta[Material3D.SPECULAR_COLOR_KEY] != null) {
MeshPhongMaterial().apply { MeshPhongMaterial().apply {
color = meta[Material3D.COLOR_KEY]?.getColor() ?: DEFAULT_COLOR color = meta[Material3D.COLOR_KEY]?.getColor() ?: DEFAULT_COLOR

View File

@ -3,7 +3,7 @@ package hep.dataforge.vision.spatial.three
import hep.dataforge.context.* import hep.dataforge.context.*
import hep.dataforge.meta.Meta import hep.dataforge.meta.Meta
import hep.dataforge.names.* import hep.dataforge.names.*
import hep.dataforge.vision.VisualObject import hep.dataforge.vision.Vision
import hep.dataforge.vision.spatial.* import hep.dataforge.vision.spatial.*
import info.laht.threekt.core.Object3D import info.laht.threekt.core.Object3D
import kotlin.collections.set import kotlin.collections.set
@ -28,7 +28,7 @@ class ThreePlugin : AbstractPlugin() {
} }
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
private fun findObjectFactory(type: KClass<out VisualObject>): ThreeFactory<VisualObject3D>? { private fun findObjectFactory(type: KClass<out Vision>): ThreeFactory<VisualObject3D>? {
return (objectFactories[type] return (objectFactories[type]
?: context.content<ThreeFactory<*>>(ThreeFactory.TYPE).values.find { it.type == type }) ?: context.content<ThreeFactory<*>>(ThreeFactory.TYPE).values.find { it.type == type })
as ThreeFactory<VisualObject3D>? as ThreeFactory<VisualObject3D>?
@ -38,7 +38,7 @@ class ThreePlugin : AbstractPlugin() {
return when (obj) { return when (obj) {
is ThreeVisualObject -> obj.toObject3D() is ThreeVisualObject -> obj.toObject3D()
is Proxy -> proxyFactory(obj) is Proxy -> proxyFactory(obj)
is VisualGroup3D -> { is VisionGroup3D -> {
val group = ThreeGroup() val group = ThreeGroup()
obj.children.forEach { (token, child) -> obj.children.forEach { (token, child) ->
if (child is VisualObject3D && child.ignore != true) { if (child is VisualObject3D && child.ignore != true) {

View File

@ -3,8 +3,8 @@ package hep.dataforge.vision.spatial.three
import hep.dataforge.js.requireJS import hep.dataforge.js.requireJS
import hep.dataforge.vision.bootstrap.accordion import hep.dataforge.vision.bootstrap.accordion
import hep.dataforge.vision.bootstrap.entry import hep.dataforge.vision.bootstrap.entry
import hep.dataforge.vision.spatial.VisionGroup3D
import hep.dataforge.vision.spatial.Visual3D import hep.dataforge.vision.spatial.Visual3D
import hep.dataforge.vision.spatial.VisualGroup3D
import kotlinx.html.* import kotlinx.html.*
import kotlinx.html.dom.append import kotlinx.html.dom.append
import kotlinx.html.js.onChangeFunction import kotlinx.html.js.onChangeFunction
@ -52,9 +52,9 @@ fun RBuilder.canvasControls(canvas: ThreeCanvas) = accordion("controls") {
+"Export" +"Export"
attrs { attrs {
onClickFunction = { onClickFunction = {
val json = (canvas.content as? VisualGroup3D)?.let { group -> val json = (canvas.content as? VisionGroup3D)?.let { group ->
Visual3D.json.stringify( Visual3D.json.stringify(
VisualGroup3D.serializer(), VisionGroup3D.serializer(),
group group
) )
} }
@ -116,9 +116,9 @@ fun Element.displayCanvasControls(canvas: ThreeCanvas, block: TagConsumer<HTMLEl
button { button {
+"Export" +"Export"
onClickFunction = { onClickFunction = {
val json = (canvas.content as? VisualGroup3D)?.let { group -> val json = (canvas.content as? VisionGroup3D)?.let { group ->
Visual3D.json.stringify( Visual3D.json.stringify(
VisualGroup3D.serializer(), VisionGroup3D.serializer(),
group group
) )
} }

View File

@ -46,7 +46,7 @@ class FX3DPlugin : AbstractPlugin() {
val binding = VisualObjectFXBinding(obj) val binding = VisualObjectFXBinding(obj)
return when (obj) { return when (obj) {
is Proxy -> proxyFactory(obj, binding) is Proxy -> proxyFactory(obj, binding)
is VisualGroup3D -> { is VisionGroup3D -> {
Group(obj.children.mapNotNull { (token, obj) -> Group(obj.children.mapNotNull { (token, obj) ->
(obj as? VisualObject3D)?.let { (obj as? VisualObject3D)?.let {
buildNode(it).apply { buildNode(it).apply {

View File

@ -3,7 +3,7 @@ package hep.dataforge.vision.spatial.fx
import hep.dataforge.names.Name import hep.dataforge.names.Name
import hep.dataforge.names.isEmpty import hep.dataforge.names.isEmpty
import hep.dataforge.names.toName import hep.dataforge.names.toName
import hep.dataforge.vision.VisualObject import hep.dataforge.vision.Vision
import hep.dataforge.vision.spatial.Proxy import hep.dataforge.vision.spatial.Proxy
import javafx.scene.Group import javafx.scene.Group
import javafx.scene.Node import javafx.scene.Node
@ -40,7 +40,7 @@ private fun Node.findChild(name: Name): Node? {
} }
} }
private fun Node.updateProperty(obj: VisualObject, propertyName: Name) { private fun Node.updateProperty(obj: Vision, propertyName: Name) {
// if (propertyName.startsWith(Material3D.MATERIAL_KEY)) { // if (propertyName.startsWith(Material3D.MATERIAL_KEY)) {
// (this as? Shape3D)?.let { it.material = obj.getProperty(Material3D.MATERIAL_KEY).material() } // (this as? Shape3D)?.let { it.material = obj.getProperty(Material3D.MATERIAL_KEY).material() }
// } // }

View File

@ -4,15 +4,15 @@ import hep.dataforge.meta.*
import hep.dataforge.names.Name import hep.dataforge.names.Name
import hep.dataforge.names.startsWith import hep.dataforge.names.startsWith
import hep.dataforge.names.toName import hep.dataforge.names.toName
import hep.dataforge.vision.VisualObject import hep.dataforge.vision.Vision
import javafx.application.Platform import javafx.application.Platform
import javafx.beans.binding.ObjectBinding import javafx.beans.binding.ObjectBinding
import tornadofx.* import tornadofx.*
/** /**
* A caching binding collection for [VisualObject] properties * A caching binding collection for [Vision] properties
*/ */
class VisualObjectFXBinding(val obj: VisualObject) { class VisualObjectFXBinding(val obj: Vision) {
private val bindings = HashMap<Name, ObjectBinding<MetaItem<*>?>>() private val bindings = HashMap<Name, ObjectBinding<MetaItem<*>?>>()
init { init {

View File

@ -186,7 +186,7 @@ fun main() {
} }
} }
"hep.dataforge.vis.spatial.VisualGroup3D" to jsonSchema( "hep.dataforge.vis.spatial.VisualGroup3D" to jsonSchema(
VisualGroup3D.serializer().descriptor, VisionGroup3D.serializer().descriptor,
context context
) )