From 3217a53dd61bdf5c2c7d0286c003f9133f8e2e9a Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Wed, 5 Aug 2020 22:22:24 +0300 Subject: [PATCH] Class name refactoring --- .../spatial/gdml/demo/GDMLAppComponent.kt | 16 ++++----- .../vision/spatial/gdml/demo/readFile.kt | 12 +++---- .../vision/spatial/FileSerializationTest.kt | 2 +- .../kotlin/ru/mipt/npm/muon/monitor/Model.kt | 10 +++--- .../mipt/npm/muon/monitor/MMAppComponent.kt | 4 +-- .../hep/dataforge/vision/spatial/demo/demo.kt | 6 ++-- .../vision/spatial/demo/ThreeDemoGrid.kt | 4 +-- .../vision/spatial/demo/VariableBox.kt | 2 +- .../vision/spatial/demo/FXDemoGrid.kt | 4 +-- playground/src/jsMain/kotlin/PlayGroundApp.kt | 4 +-- .../dataforge/vision/bootstrap/ObjectTree.kt | 18 +++++----- .../vision/bootstrap/propertyEditor.kt | 6 ++-- .../dataforge/vision/material/objectTree.kt | 16 ++++----- ui/react/build.gradle.kts | 9 ++--- ...tractVisualObject.kt => AbstractVision.kt} | 6 ++-- ...VisualGroup.kt => AbstractVisionlGroup.kt} | 28 +++++++-------- ...pleVisualGroup.kt => SimpleVisionGroup.kt} | 10 +++--- .../kotlin/hep/dataforge/vision/StyleSheet.kt | 8 ++--- .../vision/{VisualObject.kt => Vision.kt} | 20 +++++------ .../vision/{VisualGroup.kt => VisionGroup.kt} | 36 +++++++++---------- .../vision/{Visual.kt => VisionManager.kt} | 19 +++++----- .../editor/VisualObjectEditorFragment.kt | 12 +++---- .../vision/editor/VisualObjectTreeFragment.kt | 22 ++++++------ .../vision/spatial/gdml/GDMLTransformer.kt | 4 +-- .../vision/spatial/gdml/visualGDML.kt | 14 ++++---- .../vision/spatial/gdml/visualGDMLJvm.kt | 4 +-- .../hep/dataforge/vision/spatial/Box.kt | 4 +-- .../hep/dataforge/vision/spatial/Composite.kt | 16 ++++----- .../dataforge/vision/spatial/ConeSegment.kt | 6 ++-- .../hep/dataforge/vision/spatial/Convex.kt | 4 +-- .../hep/dataforge/vision/spatial/Extruded.kt | 4 +-- .../hep/dataforge/vision/spatial/Label3D.kt | 4 +-- .../hep/dataforge/vision/spatial/PolyLine.kt | 4 +-- .../hep/dataforge/vision/spatial/Proxy.kt | 32 ++++++++--------- .../hep/dataforge/vision/spatial/Sphere.kt | 4 +-- .../hep/dataforge/vision/spatial/Tube.kt | 4 +-- .../{VisualGroup3D.kt => VisionGroup3D.kt} | 36 +++++++++---------- .../hep/dataforge/vision/spatial/Visual3D.kt | 16 ++++----- .../vision/spatial/VisualObject3D.kt | 16 ++++----- .../dataforge/vision/spatial/serialization.kt | 26 +++++++------- .../spatial/transform/RemoveSingleChild.kt | 20 +++++------ .../vision/spatial/transform/UnRef.kt | 22 ++++++------ .../spatial/transform/VisualTreeTransform.kt | 10 +++--- .../dataforge/vision/spatial/ConvexTest.kt | 2 +- .../hep/dataforge/vision/spatial/GroupTest.kt | 2 +- .../dataforge/vision/spatial/PropertyTest.kt | 8 ++--- .../vision/spatial/SerializationTest.kt | 8 ++--- .../vision/spatial/three/ThreeFactory.kt | 8 ++--- .../vision/spatial/three/ThreeMaterials.kt | 6 ++-- .../vision/spatial/three/ThreePlugin.kt | 6 ++-- .../vision/spatial/three/outputConfig.kt | 10 +++--- .../dataforge/vision/spatial/fx/FX3DPlugin.kt | 2 +- .../vision/spatial/fx/FXProxyFactory.kt | 4 +-- .../spatial/fx/VisualObjectFXBinding.kt | 6 ++-- .../vision/spatial/generateSchema.kt | 2 +- 55 files changed, 294 insertions(+), 294 deletions(-) rename visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/{AbstractVisualObject.kt => AbstractVision.kt} (95%) rename visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/{AbstractVisualGroup.kt => AbstractVisionlGroup.kt} (84%) rename visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/{SimpleVisualGroup.kt => SimpleVisionGroup.kt} (66%) rename visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/{VisualObject.kt => Vision.kt} (80%) rename visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/{VisualGroup.kt => VisionGroup.kt} (62%) rename visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/{Visual.kt => VisionManager.kt} (52%) rename visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/{VisualGroup3D.kt => VisionGroup3D.kt} (72%) diff --git a/demo/gdml/src/jsMain/kotlin/hep/dataforge/vision/spatial/gdml/demo/GDMLAppComponent.kt b/demo/gdml/src/jsMain/kotlin/hep/dataforge/vision/spatial/gdml/demo/GDMLAppComponent.kt index 8469a310..9bedb697 100644 --- a/demo/gdml/src/jsMain/kotlin/hep/dataforge/vision/spatial/gdml/demo/GDMLAppComponent.kt +++ b/demo/gdml/src/jsMain/kotlin/hep/dataforge/vision/spatial/gdml/demo/GDMLAppComponent.kt @@ -3,14 +3,14 @@ package hep.dataforge.vision.spatial.gdml.demo import hep.dataforge.context.Context import hep.dataforge.names.Name import hep.dataforge.names.isEmpty -import hep.dataforge.vision.VisualGroup -import hep.dataforge.vision.VisualObject +import hep.dataforge.vision.Vision +import hep.dataforge.vision.VisionGroup import hep.dataforge.vision.bootstrap.* import hep.dataforge.vision.react.component import hep.dataforge.vision.react.configEditor import hep.dataforge.vision.react.flexColumn 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.gdml.toVisual import hep.dataforge.vision.spatial.specifications.Camera @@ -35,7 +35,7 @@ import kotlin.math.PI interface GDMLAppProps : RProps { var context: Context - var rootObject: VisualObject? + var rootObject: Vision? var selected: Name? } @@ -50,7 +50,7 @@ private val canvasConfig = Canvas3DOptions { val GDMLApp = component { props -> var selected by state { props.selected } var canvas: ThreeCanvas? by state { null } - var visual: VisualObject? by state { props.rootObject } + var visual: Vision? by state { props.rootObject } val select: (Name?) -> Unit = { selected = it @@ -62,7 +62,7 @@ val GDMLApp = component { props -> val gdml = GDML.parse(data) gdml.toVisual(gdmlConfiguration) } - name.endsWith(".json") -> VisualGroup3D.parseJson(data) + name.endsWith(".json") -> VisionGroup3D.parseJson(data) else -> { window.alert("File extension is not recognized: $name") error("File extension is not recognized: $name") @@ -137,10 +137,10 @@ val GDMLApp = component { props -> //properties card("Properties") { selected.let { selected -> - val selectedObject: VisualObject? = when { + val selectedObject: Vision? = when { selected == null -> null selected.isEmpty() -> visual - else -> (visual as? VisualGroup)?.get(selected) + else -> (visual as? VisionGroup)?.get(selected) } if (selectedObject != null) { configEditor(selectedObject, default = selectedObject.properties(), key = selected) diff --git a/demo/gdml/src/jvmMain/kotlin/hep/dataforge/vision/spatial/gdml/demo/readFile.kt b/demo/gdml/src/jvmMain/kotlin/hep/dataforge/vision/spatial/gdml/demo/readFile.kt index 15019f0c..226f8fb4 100644 --- a/demo/gdml/src/jvmMain/kotlin/hep/dataforge/vision/spatial/gdml/demo/readFile.kt +++ b/demo/gdml/src/jvmMain/kotlin/hep/dataforge/vision/spatial/gdml/demo/readFile.kt @@ -3,8 +3,8 @@ package hep.dataforge.vision.spatial.gdml.demo import hep.dataforge.meta.setItem import hep.dataforge.values.asValue import hep.dataforge.vision.spatial.Material3D +import hep.dataforge.vision.spatial.VisionGroup3D 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.readFile import hep.dataforge.vision.spatial.gdml.toVisual @@ -13,7 +13,7 @@ import java.io.File import java.util.zip.GZIPInputStream 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" -> { GDML.readFile(file.toPath()).toVisual { 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.inputStream().use { val unzip = ZipInputStream(it, Charsets.UTF_8) val text = unzip.readBytes().decodeToString() - VisualGroup3D.parseJson(text) + VisionGroup3D.parseJson(text) } } file.name.endsWith("json.gz") -> { file.inputStream().use { val unzip = GZIPInputStream(it) val text = unzip.readBytes().decodeToString() - VisualGroup3D.parseJson(text) + VisionGroup3D.parseJson(text) } } else -> error("Unknown extension ${file.extension}") } -fun Visual3D.Companion.readFile(fileName: String): VisualGroup3D = readFile(File(fileName)) \ No newline at end of file +fun Visual3D.Companion.readFile(fileName: String): VisionGroup3D = readFile(File(fileName)) \ No newline at end of file diff --git a/demo/gdml/src/jvmTest/kotlin/hep/dataforge/vision/spatial/FileSerializationTest.kt b/demo/gdml/src/jvmTest/kotlin/hep/dataforge/vision/spatial/FileSerializationTest.kt index cd9efe74..0d36ff42 100644 --- a/demo/gdml/src/jvmTest/kotlin/hep/dataforge/vision/spatial/FileSerializationTest.kt +++ b/demo/gdml/src/jvmTest/kotlin/hep/dataforge/vision/spatial/FileSerializationTest.kt @@ -9,7 +9,7 @@ class FileSerializationTest { @Ignore fun testFileRead(){ val text = this::class.java.getResourceAsStream("/cubes.json").readBytes().decodeToString() - val visual = VisualGroup3D.parseJson(text) + val visual = VisionGroup3D.parseJson(text) visual["composite_001".asName()] } } \ No newline at end of file diff --git a/demo/muon-monitor/src/commonMain/kotlin/ru/mipt/npm/muon/monitor/Model.kt b/demo/muon-monitor/src/commonMain/kotlin/ru/mipt/npm/muon/monitor/Model.kt index d9572f83..888ee2de 100644 --- a/demo/muon-monitor/src/commonMain/kotlin/ru/mipt/npm/muon/monitor/Model.kt +++ b/demo/muon-monitor/src/commonMain/kotlin/ru/mipt/npm/muon/monitor/Model.kt @@ -8,10 +8,10 @@ import ru.mipt.npm.muon.monitor.Monitor.UPPER_LAYER_Z import kotlin.math.PI class Model { - private val map = HashMap() + private val map = HashMap() private val events = HashSet() - private fun VisualGroup3D.pixel(pixel: SC1) { + private fun VisionGroup3D.pixel(pixel: SC1) { val group = group(pixel.name) { position = Point3D(pixel.center.x, pixel.center.y, pixel.center.z) box(pixel.xSize, pixel.ySize, pixel.zSize) @@ -23,7 +23,7 @@ class Model { map[pixel.name] = group } - private fun VisualGroup3D.detector(detector: SC16) { + private fun VisionGroup3D.detector(detector: SC16) { group(detector.name) { detector.pixels.forEach { 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 group("bottom") { Monitor.detectors.filter { it.center.z == LOWER_LAYER_Z }.forEach { diff --git a/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMAppComponent.kt b/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMAppComponent.kt index dd7ecd09..ef800764 100644 --- a/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMAppComponent.kt +++ b/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMAppComponent.kt @@ -4,7 +4,7 @@ import hep.dataforge.context.Context import hep.dataforge.names.Name import hep.dataforge.names.NameToken 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.objectTree import hep.dataforge.vision.react.component @@ -149,7 +149,7 @@ val MMApp = component { props -> //properties card("Properties") { selected.let { selected -> - val selectedObject: VisualObject? = when { + val selectedObject: Vision? = when { selected == null -> null selected.isEmpty() -> visual else -> visual[selected] diff --git a/demo/spatial-showcase/src/commonMain/kotlin/hep/dataforge/vision/spatial/demo/demo.kt b/demo/spatial-showcase/src/commonMain/kotlin/hep/dataforge/vision/spatial/demo/demo.kt index 92e0d926..084ddd4c 100644 --- a/demo/spatial-showcase/src/commonMain/kotlin/hep/dataforge/vision/spatial/demo/demo.kt +++ b/demo/spatial-showcase/src/commonMain/kotlin/hep/dataforge/vision/spatial/demo/demo.kt @@ -5,7 +5,7 @@ import hep.dataforge.meta.invoke import hep.dataforge.names.toName import hep.dataforge.output.OutputManager 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.specifications.Canvas3DOptions import kotlinx.coroutines.* @@ -15,11 +15,11 @@ import kotlin.math.sin 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 { "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) } diff --git a/demo/spatial-showcase/src/jsMain/kotlin/hep/dataforge/vision/spatial/demo/ThreeDemoGrid.kt b/demo/spatial-showcase/src/jsMain/kotlin/hep/dataforge/vision/spatial/demo/ThreeDemoGrid.kt index 66c0918d..11a6f1de 100644 --- a/demo/spatial-showcase/src/jsMain/kotlin/hep/dataforge/vision/spatial/demo/ThreeDemoGrid.kt +++ b/demo/spatial-showcase/src/jsMain/kotlin/hep/dataforge/vision/spatial/demo/ThreeDemoGrid.kt @@ -7,7 +7,7 @@ import hep.dataforge.meta.string import hep.dataforge.names.Name import hep.dataforge.output.OutputManager 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.ThreePlugin import hep.dataforge.vision.spatial.three.output @@ -39,7 +39,7 @@ class ThreeDemoGrid(element: Element, meta: Meta = Meta.EMPTY) : OutputManager { override fun get(type: KClass, name: Name, stage: Name, meta: Meta): Renderer { return outputs.getOrPut(name) { - if (type != VisualObject::class) error("Supports only DisplayObject") + if (type != Vision::class) error("Supports only DisplayObject") lateinit var output: ThreeCanvas //TODO calculate cell width here using jquery gridRoot.append { diff --git a/demo/spatial-showcase/src/jsMain/kotlin/hep/dataforge/vision/spatial/demo/VariableBox.kt b/demo/spatial-showcase/src/jsMain/kotlin/hep/dataforge/vision/spatial/demo/VariableBox.kt index de11586c..d22f7a0e 100644 --- a/demo/spatial-showcase/src/jsMain/kotlin/hep/dataforge/vision/spatial/demo/VariableBox.kt +++ b/demo/spatial-showcase/src/jsMain/kotlin/hep/dataforge/vision/spatial/demo/VariableBox.kt @@ -43,7 +43,7 @@ internal var VisualObject3D.value: Int color(r.toUByte(), g.toUByte(), b.toUByte()) } -fun VisualGroup3D.varBox( +fun VisionGroup3D.varBox( xSize: Number, ySize: Number, zSize: Number, diff --git a/demo/spatial-showcase/src/jvmMain/kotlin/hep/dataforge/vision/spatial/demo/FXDemoGrid.kt b/demo/spatial-showcase/src/jvmMain/kotlin/hep/dataforge/vision/spatial/demo/FXDemoGrid.kt index 81fc18e1..83cce18e 100644 --- a/demo/spatial-showcase/src/jvmMain/kotlin/hep/dataforge/vision/spatial/demo/FXDemoGrid.kt +++ b/demo/spatial-showcase/src/jvmMain/kotlin/hep/dataforge/vision/spatial/demo/FXDemoGrid.kt @@ -5,7 +5,7 @@ import hep.dataforge.meta.Meta import hep.dataforge.names.Name import hep.dataforge.output.OutputManager 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.FXCanvas3D import javafx.collections.FXCollections @@ -30,7 +30,7 @@ class FXDemoGrid : View(title = "DataForge-vis FX demo"), OutputManager { @Suppress("UNCHECKED_CAST") override fun get(type: KClass, name: Name, stage: Name, meta: Meta): Renderer { 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) output diff --git a/playground/src/jsMain/kotlin/PlayGroundApp.kt b/playground/src/jsMain/kotlin/PlayGroundApp.kt index 659b8f5d..1d479294 100644 --- a/playground/src/jsMain/kotlin/PlayGroundApp.kt +++ b/playground/src/jsMain/kotlin/PlayGroundApp.kt @@ -5,7 +5,7 @@ import hep.dataforge.names.Name import hep.dataforge.vision.bootstrap.objectTree import hep.dataforge.vision.bootstrap.visualPropertyEditor 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.group import hep.dataforge.vision.spatial.three.ThreePlugin @@ -24,7 +24,7 @@ private class PlayGroundApp : Application { val element = 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") group("B") { position = Point3D(120, 0, 0) diff --git a/ui/bootstrap/src/main/kotlin/hep/dataforge/vision/bootstrap/ObjectTree.kt b/ui/bootstrap/src/main/kotlin/hep/dataforge/vision/bootstrap/ObjectTree.kt index bf20f744..d2ed503f 100644 --- a/ui/bootstrap/src/main/kotlin/hep/dataforge/vision/bootstrap/ObjectTree.kt +++ b/ui/bootstrap/src/main/kotlin/hep/dataforge/vision/bootstrap/ObjectTree.kt @@ -3,8 +3,8 @@ package hep.dataforge.vision.bootstrap import hep.dataforge.names.Name import hep.dataforge.names.plus import hep.dataforge.names.startsWith -import hep.dataforge.vision.VisualGroup -import hep.dataforge.vision.VisualObject +import hep.dataforge.vision.Vision +import hep.dataforge.vision.VisionGroup import hep.dataforge.vision.isEmpty import hep.dataforge.vision.react.RFBuilder import hep.dataforge.vision.react.component @@ -18,7 +18,7 @@ import react.dom.* interface ObjectTreeProps : RProps { var name: Name var selected: Name? - var obj: VisualObject + var obj: Vision var clickCallback: (Name) -> Unit } @@ -49,7 +49,7 @@ private fun RFBuilder.objectTree(props: ObjectTreeProps): Unit { val obj = props.obj //display as node if any child is visible - if (obj is VisualGroup) { + if (obj is VisionGroup) { div("d-block text-truncate") { if (obj.children.any { !it.key.body.startsWith("@") }) { span("tree-caret") { @@ -67,7 +67,7 @@ private fun RFBuilder.objectTree(props: ObjectTreeProps): Unit { ul("tree") { obj.children.entries .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) -> li("tree-item") { child(ObjectTree) { @@ -95,14 +95,14 @@ val ObjectTree: FunctionalComponent = component { props -> } fun Element.renderObjectTree( - visualObject: VisualObject, + vision: Vision, clickCallback: (Name) -> Unit = {} ) = render(this) { card("Object tree") { child(ObjectTree) { attrs { this.name = Name.EMPTY - this.obj = visualObject + this.obj = vision this.selected = null this.clickCallback = clickCallback } @@ -111,14 +111,14 @@ fun Element.renderObjectTree( } fun RBuilder.objectTree( - visualObject: VisualObject, + vision: Vision, selected: Name? = null, clickCallback: (Name) -> Unit = {} ) { child(ObjectTree) { attrs { this.name = Name.EMPTY - this.obj = visualObject + this.obj = vision this.selected = selected this.clickCallback = clickCallback } diff --git a/ui/bootstrap/src/main/kotlin/hep/dataforge/vision/bootstrap/propertyEditor.kt b/ui/bootstrap/src/main/kotlin/hep/dataforge/vision/bootstrap/propertyEditor.kt index edc4a89c..d51375ee 100644 --- a/ui/bootstrap/src/main/kotlin/hep/dataforge/vision/bootstrap/propertyEditor.kt +++ b/ui/bootstrap/src/main/kotlin/hep/dataforge/vision/bootstrap/propertyEditor.kt @@ -4,7 +4,7 @@ import hep.dataforge.meta.Meta import hep.dataforge.meta.descriptors.NodeDescriptor import hep.dataforge.names.Name import hep.dataforge.names.isEmpty -import hep.dataforge.vision.VisualObject +import hep.dataforge.vision.Vision import hep.dataforge.vision.react.configEditor import org.w3c.dom.Element import react.RBuilder @@ -16,7 +16,7 @@ import kotlin.collections.set fun RBuilder.visualPropertyEditor( path: Name, - item: VisualObject, + item: Vision, descriptor: NodeDescriptor? = item.descriptor, default: Meta? = null ) { @@ -41,7 +41,7 @@ fun RBuilder.visualPropertyEditor( fun Element.visualPropertyEditor( path: Name, - item: VisualObject, + item: Vision, descriptor: NodeDescriptor? = item.descriptor, default: Meta? = null ) = render(this) { diff --git a/ui/material/src/main/kotlin/hep/dataforge/vision/material/objectTree.kt b/ui/material/src/main/kotlin/hep/dataforge/vision/material/objectTree.kt index 63b99385..22d56684 100644 --- a/ui/material/src/main/kotlin/hep/dataforge/vision/material/objectTree.kt +++ b/ui/material/src/main/kotlin/hep/dataforge/vision/material/objectTree.kt @@ -3,8 +3,8 @@ package hep.dataforge.vision.material import hep.dataforge.names.Name import hep.dataforge.names.plus import hep.dataforge.names.toName -import hep.dataforge.vision.VisualGroup -import hep.dataforge.vision.VisualObject +import hep.dataforge.vision.Vision +import hep.dataforge.vision.VisionGroup import hep.dataforge.vision.isEmpty import hep.dataforge.vision.react.component import hep.dataforge.vision.react.state @@ -21,11 +21,11 @@ import react.dom.span interface ObjectTreeProps : RProps { var name: Name var selected: Name? - var obj: VisualObject + var obj: Vision var clickCallback: (Name?) -> Unit } -private fun RBuilder.treeBranch(name: Name, obj: VisualObject): Unit { +private fun RBuilder.treeBranch(name: Name, obj: Vision): Unit { treeItem { val token = name.last()?.toString() ?: "World" 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 .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) -> treeBranch(name + childToken, child) } @@ -78,14 +78,14 @@ val ObjectTree: FunctionalComponent = component { props -> } fun RBuilder.objectTree( - visualObject: VisualObject, + vision: Vision, selected: Name? = null, clickCallback: (Name?) -> Unit = {} ) { child(ObjectTree) { attrs { this.name = Name.EMPTY - this.obj = visualObject + this.obj = vision this.selected = selected this.clickCallback = clickCallback } diff --git a/ui/react/build.gradle.kts b/ui/react/build.gradle.kts index 8e55fa9a..64586c43 100644 --- a/ui/react/build.gradle.kts +++ b/ui/react/build.gradle.kts @@ -8,14 +8,15 @@ kotlin { } } +val reactVersion by extra("16.13.1") dependencies{ api(project(":visionforge-core")) //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-dom", "16.13.1")) - api(npm("react-is", "16.13.1")) + api(npm("react", reactVersion)) + api(npm("react-dom", reactVersion)) + api(npm("react-is", reactVersion)) } \ No newline at end of file diff --git a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/AbstractVisualObject.kt b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/AbstractVision.kt similarity index 95% rename from visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/AbstractVisualObject.kt rename to visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/AbstractVision.kt index 5cae43e4..11f8b652 100644 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/AbstractVisualObject.kt +++ b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/AbstractVision.kt @@ -6,7 +6,7 @@ import hep.dataforge.names.Name import hep.dataforge.names.asName import hep.dataforge.values.Value 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 internal data class PropertyListener( @@ -14,10 +14,10 @@ internal data class PropertyListener( val action: (name: Name, oldItem: MetaItem<*>?, newItem: MetaItem<*>?) -> Unit ) -abstract class AbstractVisualObject : VisualObject { +abstract class AbstractVisualObject : Vision { @Transient - override var parent: VisualGroup? = null + override var parent: VisionGroup? = null /** * Object own properties excluding styles and inheritance diff --git a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/AbstractVisualGroup.kt b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/AbstractVisionlGroup.kt similarity index 84% rename from visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/AbstractVisualGroup.kt rename to visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/AbstractVisionlGroup.kt index e7c8b279..6a1ecf51 100644 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/AbstractVisualGroup.kt +++ b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/AbstractVisionlGroup.kt @@ -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 /** * A map of top level named children */ - abstract override val children: Map + abstract override val children: Map abstract override var styleSheet: StyleSheet? protected set @@ -39,7 +39,7 @@ abstract class AbstractVisualGroup : AbstractVisualObject(), MutableVisualGroup } // 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 private val structureChangeListeners = HashSet() @@ -47,7 +47,7 @@ abstract class AbstractVisualGroup : AbstractVisualObject(), MutableVisualGroup /** * 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( owner, @@ -66,7 +66,7 @@ abstract class AbstractVisualGroup : AbstractVisualObject(), MutableVisualGroup /** * 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) } } @@ -78,20 +78,20 @@ abstract class AbstractVisualGroup : AbstractVisualObject(), MutableVisualGroup /** * 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 */ - protected open fun addStatic(child: VisualObject) = + protected open fun addStatic(child: Vision) = 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 */ - protected fun attach(child: VisualObject) { + protected fun attach(child: Vision) { if (child.parent == null) { child.parent = this } else if (child.parent !== this) { @@ -102,7 +102,7 @@ abstract class AbstractVisualGroup : AbstractVisualObject(), MutableVisualGroup /** * Recursively create a child group */ - private fun createGroups(name: Name): AbstractVisualGroup { + private fun createGroups(name: Name): AbstractVision { return when { name.isEmpty() -> error("Should be unreachable") name.length == 1 -> { @@ -112,7 +112,7 @@ abstract class AbstractVisualGroup : AbstractVisualObject(), MutableVisualGroup attach(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") } } @@ -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 * 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 { name.isEmpty() -> { if (child != null) { @@ -142,7 +142,7 @@ abstract class AbstractVisualGroup : AbstractVisualObject(), MutableVisualGroup } else -> { //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 } } diff --git a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/SimpleVisualGroup.kt b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/SimpleVisionGroup.kt similarity index 66% rename from visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/SimpleVisualGroup.kt rename to visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/SimpleVisionGroup.kt index 03f8c79a..2b87dbf4 100644 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/SimpleVisualGroup.kt +++ b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/SimpleVisionGroup.kt @@ -8,7 +8,7 @@ import kotlinx.serialization.Serializable @Serializable @SerialName("group") -class SimpleVisualGroup : AbstractVisualGroup() { +class SimpleVisionGroup : AbstractVision() { override var styleSheet: StyleSheet? = null @@ -16,16 +16,16 @@ class SimpleVisualGroup : AbstractVisualGroup() { override var ownProperties: Config? = null @SerialName("children") - private val _children = HashMap() - override val children: Map get() = _children + private val _children = HashMap() + override val children: Map get() = _children override fun removeChild(token: NameToken) { _children.remove(token)?.apply { parent = null } } - override fun setChild(token: NameToken, child: VisualObject) { + override fun setChild(token: NameToken, child: Vision) { _children[token] = child } - override fun createGroup(): SimpleVisualGroup = SimpleVisualGroup() + override fun createGroup(): SimpleVisionGroup = SimpleVisionGroup() } \ No newline at end of file diff --git a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/StyleSheet.kt b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/StyleSheet.kt index f81ea5a2..7a0d93f7 100644 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/StyleSheet.kt +++ b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/StyleSheet.kt @@ -15,9 +15,9 @@ import kotlinx.serialization.builtins.serializer @Serializable class StyleSheet private constructor(private val styleMap: MutableMap = LinkedHashMap()) { @Transient - internal var owner: VisualObject? = null + internal var owner: Vision? = null - constructor(owner: VisualObject) : this() { + constructor(owner: Vision) : this() { this.owner = owner } @@ -73,14 +73,14 @@ class StyleSheet private constructor(private val styleMap: MutableMap = ((oldStyle?.items?.keys ?: emptySet()) + (newStyle?.items?.keys ?: emptySet())) .map { it.asName() } tokens.forEach { parent?.propertyChanged(it, oldStyle?.get(it), newStyle?.get(it)) } } - if (this is VisualGroup) { + if (this is VisionGroup) { for (obj in this) { obj.styleChanged(key, oldStyle, newStyle) } diff --git a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisualObject.kt b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/Vision.kt similarity index 80% rename from visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisualObject.kt rename to visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/Vision.kt index 38fdc48f..22ba90d1 100644 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisualObject.kt +++ b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/Vision.kt @@ -8,7 +8,7 @@ import hep.dataforge.names.Name import hep.dataforge.names.asName import hep.dataforge.names.toName 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.Transient @@ -16,13 +16,13 @@ import kotlinx.serialization.Transient * A root type for display hierarchy */ @Type(TYPE) -interface VisualObject : Configurable { +interface Vision : Configurable { /** * The parent object of this one. If null, this one is a root. */ @Transient - var parent: VisualGroup? + var parent: VisionGroup? /** * All properties including styles and prototypes if present, including inherited ones @@ -68,26 +68,26 @@ interface VisualObject : Configurable { const val TYPE = "visual" 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 } } /** - * 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) /** * 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 } -tailrec fun VisualObject.findStyle(name: String): Meta? = - (this as? VisualGroup)?.styleSheet?.get(name) ?: parent?.findStyle(name) +tailrec fun Vision.findStyle(name: String): Meta? = + (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)) diff --git a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisualGroup.kt b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionGroup.kt similarity index 62% rename from visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisualGroup.kt rename to visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionGroup.kt index d81f8cc8..af7b871c 100644 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisualGroup.kt +++ b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionGroup.kt @@ -4,15 +4,15 @@ import hep.dataforge.names.* 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 */ - val children: Map + val children: Map - 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, @@ -26,8 +26,8 @@ interface VisualGroup : Provider, VisualObject { */ override fun provideTop(target: String): Map = when (target) { - VisualObject.TYPE -> children.flatMap { (key, value) -> - val res: Map = if (value is VisualGroup) { + Vision.TYPE -> children.flatMap { (key, value) -> + val res: Map = if (value is VisionGroup) { value.provideTop(target).mapKeys { key + it.key } } else { mapOf(key.asName() to value) @@ -38,11 +38,11 @@ interface VisualGroup : Provider, VisualObject { else -> emptyMap() } - operator fun get(name: Name): VisualObject? { + operator fun get(name: Name): Vision? { return when { name.isEmpty() -> this 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 children.values.forEach { 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 */ -operator fun VisualGroup.iterator(): Iterator = children.values.iterator() +operator fun VisionGroup.iterator(): Iterator = 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. * @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. */ - fun onChildrenChange(owner: Any?, action: (Name, VisualObject?) -> Unit) + fun onChildrenChange(owner: Any?, action: (Name, Vision?) -> Unit) /** * Remove children change listener */ 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) } -fun MutableVisualGroup.removeAll() = children.keys.map { it.asName() }.forEach { this[it] = null } \ No newline at end of file +fun MutableVisionGroup.removeAll() = children.keys.map { it.asName() }.forEach { this[it] = null } \ No newline at end of file diff --git a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/Visual.kt b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionManager.kt similarity index 52% rename from visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/Visual.kt rename to visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionManager.kt index 14c94121..a8887d31 100644 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/Visual.kt +++ b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionManager.kt @@ -4,16 +4,16 @@ import hep.dataforge.context.* import hep.dataforge.meta.Meta import kotlin.reflect.KClass -interface VisualFactory { +interface VisualFactory { val type: KClass operator fun invoke( context: Context, - parent: VisualObject?, + parent: Vision?, meta: Meta ): T } -class Visual(meta: Meta) : AbstractPlugin(meta) { +class VisionManager(meta: Meta) : AbstractPlugin(meta) { override val tag: PluginTag get() = Companion.tag /** @@ -23,17 +23,16 @@ class Visual(meta: Meta) : AbstractPlugin(meta) { context.content>(VISUAL_FACTORY_TYPE).mapKeys { it.value.type } } - inline fun buildVisual(parent: VisualObject?, meta: Meta): T? { + inline fun buildVisual(parent: Vision?, meta: Meta): T? { return visualFactories[T::class]?.invoke(context, parent, meta) as T? } - companion object : PluginFactory { - override val tag: PluginTag = PluginTag(name = "visual", group = PluginTag.DATAFORGE_GROUP) - override val type: KClass = Visual::class + companion object : PluginFactory { + override val tag: PluginTag = PluginTag(name = "vision", group = PluginTag.DATAFORGE_GROUP) + override val type: KClass = VisionManager::class - override fun invoke(meta: Meta, context: Context): Visual = - Visual(meta) + override fun invoke(meta: Meta, context: Context): VisionManager = VisionManager(meta) - const val VISUAL_FACTORY_TYPE = "visual.factory" + const val VISUAL_FACTORY_TYPE = "vision.factory" } } \ No newline at end of file diff --git a/visionforge-core/src/jvmMain/kotlin/hep/dataforge/vision/editor/VisualObjectEditorFragment.kt b/visionforge-core/src/jvmMain/kotlin/hep/dataforge/vision/editor/VisualObjectEditorFragment.kt index 56f1e1e0..b541261b 100644 --- a/visionforge-core/src/jvmMain/kotlin/hep/dataforge/vision/editor/VisualObjectEditorFragment.kt +++ b/visionforge-core/src/jvmMain/kotlin/hep/dataforge/vision/editor/VisualObjectEditorFragment.kt @@ -4,7 +4,7 @@ import hep.dataforge.meta.Config import hep.dataforge.meta.Meta import hep.dataforge.meta.descriptors.NodeDescriptor import hep.dataforge.meta.update -import hep.dataforge.vision.VisualObject +import hep.dataforge.vision.Vision import hep.dataforge.vision.findStyle import javafx.beans.binding.Binding import javafx.beans.property.SimpleObjectProperty @@ -13,16 +13,16 @@ import javafx.scene.Parent import javafx.scene.layout.VBox import tornadofx.* -class VisualObjectEditorFragment(val selector: (VisualObject) -> Meta) : Fragment() { +class VisualObjectEditorFragment(val selector: (Vision) -> Meta) : Fragment() { - val itemProperty = SimpleObjectProperty() - var item: VisualObject? by itemProperty + val itemProperty = SimpleObjectProperty() + var item: Vision? by itemProperty val descriptorProperty = SimpleObjectProperty() constructor( - item: VisualObject?, + item: Vision?, descriptor: NodeDescriptor?, - selector: (VisualObject) -> Config = { it.config } + selector: (Vision) -> Config = { it.config } ) : this(selector) { this.item = item this.descriptorProperty.set(descriptor) diff --git a/visionforge-core/src/jvmMain/kotlin/hep/dataforge/vision/editor/VisualObjectTreeFragment.kt b/visionforge-core/src/jvmMain/kotlin/hep/dataforge/vision/editor/VisualObjectTreeFragment.kt index 079abf01..409fa1ff 100644 --- a/visionforge-core/src/jvmMain/kotlin/hep/dataforge/vision/editor/VisualObjectTreeFragment.kt +++ b/visionforge-core/src/jvmMain/kotlin/hep/dataforge/vision/editor/VisualObjectTreeFragment.kt @@ -1,20 +1,20 @@ package hep.dataforge.vision.editor -import hep.dataforge.vision.VisualGroup -import hep.dataforge.vision.VisualObject +import hep.dataforge.vision.Vision +import hep.dataforge.vision.VisionGroup import javafx.beans.property.SimpleObjectProperty import javafx.scene.control.SelectionMode import javafx.scene.control.TreeItem import tornadofx.* -private fun toTreeItem(visualObject: VisualObject, title: String): TreeItem> { - return object : TreeItem>(title to visualObject) { +private fun toTreeItem(vision: Vision, title: String): TreeItem> { + return object : TreeItem>(title to vision) { init { - if (visualObject is VisualGroup) { + if (vision is VisionGroup) { //lazy populate the tree expandedProperty().onChange { expanded -> if (expanded && children.isEmpty()) { - children.setAll(visualObject.children.map { + children.setAll(vision.children.map { toTreeItem(it.value, it.key.toString()) }) } @@ -23,21 +23,21 @@ private fun toTreeItem(visualObject: VisualObject, title: String): TreeItem() - var item: VisualObject? by itemProperty + val itemProperty = SimpleObjectProperty() + var item: Vision? by itemProperty - val selectedProperty = SimpleObjectProperty() + val selectedProperty = SimpleObjectProperty() override val root = vbox { titledpane("Object tree", collapsible = false) { - treeview> { + treeview> { cellFormat { text = item.first } diff --git a/visionforge-gdml/src/commonMain/kotlin/hep/dataforge/vision/spatial/gdml/GDMLTransformer.kt b/visionforge-gdml/src/commonMain/kotlin/hep/dataforge/vision/spatial/gdml/GDMLTransformer.kt index cb5fe784..0eb1750a 100644 --- a/visionforge-gdml/src/commonMain/kotlin/hep/dataforge/vision/spatial/gdml/GDMLTransformer.kt +++ b/visionforge-gdml/src/commonMain/kotlin/hep/dataforge/vision/spatial/gdml/GDMLTransformer.kt @@ -24,7 +24,7 @@ class GDMLTransformer(val root: GDML) { /** * A special group for local templates */ - val proto by lazy { VisualGroup3D() } + val proto by lazy { VisionGroup3D() } private val styleCache = HashMap() var lUnit: LUnit = LUnit.MM @@ -68,7 +68,7 @@ class GDMLTransformer(val root: GDML) { var onFinish: GDMLTransformer.() -> Unit = {} - internal fun finalize(final: VisualGroup3D): VisualGroup3D { + internal fun finalize(final: VisionGroup3D): VisionGroup3D { //final.prototypes = proto final.prototypes { proto.children.forEach { (token, item) -> diff --git a/visionforge-gdml/src/commonMain/kotlin/hep/dataforge/vision/spatial/gdml/visualGDML.kt b/visionforge-gdml/src/commonMain/kotlin/hep/dataforge/vision/spatial/gdml/visualGDML.kt index 023875c3..85adb06b 100644 --- a/visionforge-gdml/src/commonMain/kotlin/hep/dataforge/vision/spatial/gdml/visualGDML.kt +++ b/visionforge-gdml/src/commonMain/kotlin/hep/dataforge/vision/spatial/gdml/visualGDML.kt @@ -48,7 +48,7 @@ private inline operator fun Number.times(d: Double) = toDouble() * d @Suppress("NOTHING_TO_INLINE") private inline operator fun Number.times(f: Float) = toFloat() * f -private fun VisualGroup3D.addSolid( +private fun VisionGroup3D.addSolid( context: GDMLTransformer, solid: GDMLSolid, name: String = "", @@ -154,7 +154,7 @@ private fun VisualGroup3D.addSolid( private val volumesName = "volumes".asName() -private fun VisualGroup3D.addPhysicalVolume( +private fun VisionGroup3D.addPhysicalVolume( context: GDMLTransformer, physVolume: GDMLPhysVolume ) { @@ -194,7 +194,7 @@ private fun VisualGroup3D.addPhysicalVolume( } } -private fun VisualGroup3D.addDivisionVolume( +private fun VisionGroup3D.addDivisionVolume( context: GDMLTransformer, divisionVolume: GDMLDivisionVolume ) { @@ -216,8 +216,8 @@ private val solidsName = "solids".asName() private fun volume( context: GDMLTransformer, group: GDMLGroup -): VisualGroup3D { - return VisualGroup3D().apply { +): VisionGroup3D { + return VisionGroup3D().apply { if (group is GDMLVolume) { val solid = group.solidref.resolve(context.root) ?: 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) return context.finalize(volume(context, world)) } @@ -261,7 +261,7 @@ fun GDML.toVisual(block: GDMLTransformer.() -> Unit = {}): VisualGroup3D { /** * 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) //println(Visual3DPlugin.json.stringify(VisualGroup3D.serializer(), visual)) set(key, visual) diff --git a/visionforge-gdml/src/jvmMain/kotlin/hep/dataforge/vision/spatial/gdml/visualGDMLJvm.kt b/visionforge-gdml/src/jvmMain/kotlin/hep/dataforge/vision/spatial/gdml/visualGDMLJvm.kt index 178c300f..3d01be2f 100644 --- a/visionforge-gdml/src/jvmMain/kotlin/hep/dataforge/vision/spatial/gdml/visualGDMLJvm.kt +++ b/visionforge-gdml/src/jvmMain/kotlin/hep/dataforge/vision/spatial/gdml/visualGDMLJvm.kt @@ -1,6 +1,6 @@ package hep.dataforge.vision.spatial.gdml -import hep.dataforge.vision.spatial.VisualGroup3D +import hep.dataforge.vision.spatial.VisionGroup3D import nl.adaptivity.xmlutil.StAXReader import scientifik.gdml.GDML import java.nio.file.Files @@ -11,7 +11,7 @@ fun GDML.Companion.readFile(file: Path): GDML { 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) gdml(gdml, key, transformer) } diff --git a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Box.kt b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Box.kt index 741cec2a..0bac53c1 100644 --- a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Box.kt +++ b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Box.kt @@ -54,7 +54,7 @@ class Box( override val type: KClass 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["ySize"].float!!, meta["zSize"].float!! @@ -64,7 +64,7 @@ class Box( } } -inline fun MutableVisualGroup.box( +inline fun MutableVisionGroup.box( xSize: Number, ySize: Number, zSize: Number, diff --git a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Composite.kt b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Composite.kt index 6de1b7be..b822263d 100644 --- a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Composite.kt +++ b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Composite.kt @@ -22,7 +22,7 @@ class Composite( val compositeType: CompositeType, val first: VisualObject3D, val second: VisualObject3D -) : AbstractVisualObject(), VisualObject3D, VisualGroup { +) : AbstractVisualObject(), VisualObject3D, VisionGroup { init { first.parent = this @@ -35,19 +35,19 @@ class Composite( override var ownProperties: Config? = null - override val children: Map + override val children: Map get() = mapOf(NameToken("first") to first, NameToken("second") to second) override val styleSheet: StyleSheet? get() = null } -inline fun MutableVisualGroup.composite( +inline fun MutableVisionGroup.composite( type: CompositeType, name: String = "", - builder: VisualGroup3D.() -> Unit + builder: VisionGroup3D.() -> Unit ): Composite { - val group = VisualGroup3D().apply(builder) + val group = VisionGroup3D().apply(builder) val children = group.children.values.filterIsInstance() if (children.size != 2) error("Composite requires exactly two children") 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) -inline fun MutableVisualGroup.subtract(name: String = "", builder: VisualGroup3D.() -> Unit) = +inline fun MutableVisionGroup.subtract(name: String = "", builder: VisionGroup3D.() -> Unit) = 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) \ No newline at end of file diff --git a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/ConeSegment.kt b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/ConeSegment.kt index f1c7d6e3..0bf79daa 100644 --- a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/ConeSegment.kt +++ b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/ConeSegment.kt @@ -4,7 +4,7 @@ package hep.dataforge.vision.spatial import hep.dataforge.meta.Config import hep.dataforge.vision.AbstractVisualObject -import hep.dataforge.vision.MutableVisualGroup +import hep.dataforge.vision.MutableVisionGroup import hep.dataforge.vision.set import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -75,7 +75,7 @@ class ConeSegment( } -inline fun MutableVisualGroup.cylinder( +inline fun MutableVisionGroup.cylinder( r: Number, height: Number, name: String = "", @@ -87,7 +87,7 @@ inline fun MutableVisualGroup.cylinder( ).apply(block).also { set(name, it) } -inline fun MutableVisualGroup.cone( +inline fun MutableVisionGroup.cone( bottomRadius: Number, height: Number, upperRadius: Number = 0.0, diff --git a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Convex.kt b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Convex.kt index 4e39bfc4..2623ace7 100644 --- a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Convex.kt +++ b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Convex.kt @@ -4,7 +4,7 @@ package hep.dataforge.vision.spatial import hep.dataforge.meta.Config import hep.dataforge.vision.AbstractVisualObject -import hep.dataforge.vision.MutableVisualGroup +import hep.dataforge.vision.MutableVisionGroup import hep.dataforge.vision.set import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -25,7 +25,7 @@ class Convex(val points: List) : 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) } class ConvexBuilder { diff --git a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Extruded.kt b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Extruded.kt index 47605024..a0fc132c 100644 --- a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Extruded.kt +++ b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Extruded.kt @@ -3,7 +3,7 @@ package hep.dataforge.vision.spatial import hep.dataforge.meta.Config import hep.dataforge.vision.AbstractVisualObject -import hep.dataforge.vision.MutableVisualGroup +import hep.dataforge.vision.MutableVisionGroup import hep.dataforge.vision.set import kotlinx.serialization.SerialName 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) } \ No newline at end of file diff --git a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Label3D.kt b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Label3D.kt index 867cdd3f..e3345900 100644 --- a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Label3D.kt +++ b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Label3D.kt @@ -4,7 +4,7 @@ package hep.dataforge.vision.spatial import hep.dataforge.meta.Config import hep.dataforge.vision.AbstractVisualObject -import hep.dataforge.vision.MutableVisualGroup +import hep.dataforge.vision.MutableVisionGroup import hep.dataforge.vision.set import kotlinx.serialization.SerialName 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, fontSize: Number = 20, fontFamily: String = "Arial", diff --git a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/PolyLine.kt b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/PolyLine.kt index fdca47d6..0d1b5caa 100644 --- a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/PolyLine.kt +++ b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/PolyLine.kt @@ -7,7 +7,7 @@ import hep.dataforge.meta.number import hep.dataforge.names.asName import hep.dataforge.names.plus import hep.dataforge.vision.AbstractVisualObject -import hep.dataforge.vision.MutableVisualGroup +import hep.dataforge.vision.MutableVisionGroup import hep.dataforge.vision.set import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -31,5 +31,5 @@ class PolyLine(var points: List) : 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) } \ No newline at end of file diff --git a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Proxy.kt b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Proxy.kt index db9fb05b..80cdf6fa 100644 --- a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Proxy.kt +++ b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Proxy.kt @@ -22,9 +22,9 @@ import kotlin.collections.set @SerialName("3d.proxy") class Proxy private constructor( 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 } @@ -38,7 +38,7 @@ class Proxy private constructor( * Recursively search for defined template in the parent */ val prototype: VisualObject3D - get() = (parent as? VisualGroup3D)?.getPrototype(templateName) + get() = (parent as? VisionGroup3D)?.getPrototype(templateName) ?: error("Prototype with name $templateName not found in $parent") override val styleSheet: StyleSheet @@ -64,7 +64,7 @@ class Proxy private constructor( } override val children: Map - get() = (prototype as? VisualGroup)?.children + get() = (prototype as? VisionGroup)?.children ?.filter { !it.key.toString().startsWith("@") } ?.mapValues { ProxyChild(it.key.asName()) @@ -77,8 +77,8 @@ class Proxy private constructor( return NameToken(PROXY_CHILD_PROPERTY_PREFIX, childName.toString()) + propertyName } - private fun prototypeFor(name: Name): VisualObject { - return (prototype as? VisualGroup)?.get(name) + private fun prototypeFor(name: Name): Vision { + return (prototype as? VisionGroup)?.get(name) ?: error("Prototype with name $name not found in $this") } @@ -95,14 +95,14 @@ class Proxy private constructor( get() = prototype.descriptor 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 children: Map - get() = (prototype as? VisualGroup)?.children?.mapValues { (key, _) -> + override val children: Map + get() = (prototype as? VisionGroup)?.children?.mapValues { (key, _) -> ProxyChild( name + key.asName() ) @@ -159,7 +159,7 @@ class Proxy private constructor( } } -val VisualObject.prototype: VisualObject +val Vision.prototype: Vision get() = when (this) { is Proxy -> prototype is Proxy.ProxyChild -> prototype @@ -169,7 +169,7 @@ val VisualObject.prototype: VisualObject /** * Create ref for existing prototype */ -fun VisualGroup3D.ref( +fun VisionGroup3D.ref( templateName: Name, name: String = "" ): 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 */ -fun VisualGroup3D.proxy( +fun VisionGroup3D.proxy( name: String, obj: VisualObject3D, templateName: Name = name.toName() @@ -193,11 +193,11 @@ fun VisualGroup3D.proxy( return ref(templateName, name) } -fun VisualGroup3D.proxyGroup( +fun VisionGroup3D.proxyGroup( name: String, templateName: Name = name.toName(), - block: MutableVisualGroup.() -> Unit + block: MutableVisionGroup.() -> Unit ): Proxy { - val group = VisualGroup3D().apply (block) + val group = VisionGroup3D().apply (block) return proxy(name, group, templateName) } diff --git a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Sphere.kt b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Sphere.kt index 43e23b6f..24f2b5a1 100644 --- a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Sphere.kt +++ b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Sphere.kt @@ -4,7 +4,7 @@ package hep.dataforge.vision.spatial import hep.dataforge.meta.Config import hep.dataforge.vision.AbstractVisualObject -import hep.dataforge.vision.MutableVisualGroup +import hep.dataforge.vision.MutableVisionGroup import hep.dataforge.vision.set import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -60,7 +60,7 @@ class Sphere( } } -inline fun MutableVisualGroup.sphere( +inline fun MutableVisionGroup.sphere( radius: Number, phi: Number = 2 * PI, theta: Number = PI, diff --git a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Tube.kt b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Tube.kt index c8a2f846..ae2480eb 100644 --- a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Tube.kt +++ b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Tube.kt @@ -4,7 +4,7 @@ package hep.dataforge.vision.spatial import hep.dataforge.meta.Config import hep.dataforge.vision.AbstractVisualObject -import hep.dataforge.vision.MutableVisualGroup +import hep.dataforge.vision.MutableVisionGroup import hep.dataforge.vision.set import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -129,7 +129,7 @@ class Tube( } -inline fun MutableVisualGroup.tube( +inline fun MutableVisionGroup.tube( r: Number, height: Number, innerRadius: Number = 0f, diff --git a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/VisualGroup3D.kt b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/VisionGroup3D.kt similarity index 72% rename from visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/VisualGroup3D.kt rename to visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/VisionGroup3D.kt index 6c4cd8cb..06165aae 100644 --- a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/VisualGroup3D.kt +++ b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/VisionGroup3D.kt @@ -15,8 +15,8 @@ import kotlinx.serialization.UseSerializers import kotlin.collections.set interface PrototypeHolder { - val parent: VisualGroup? - val prototypes: MutableVisualGroup? + val parent: VisionGroup? + val prototypes: MutableVisionGroup? } /** @@ -24,7 +24,7 @@ interface PrototypeHolder { */ @Serializable @SerialName("group.3d") -class VisualGroup3D : AbstractVisualGroup(), VisualObject3D, PrototypeHolder { +class VisionGroup3D : AbstractVision(), VisualObject3D, PrototypeHolder { override var styleSheet: StyleSheet? = null @@ -32,13 +32,13 @@ class VisualGroup3D : AbstractVisualGroup(), VisualObject3D, PrototypeHolder { * A container for templates visible inside this group */ @Serializable(PrototypesSerializer::class) - override var prototypes: MutableVisualGroup? = null + override var prototypes: MutableVisionGroup? = null private set /** * Create or edit prototype node as a group */ - fun prototypes(builder: MutableVisualGroup.() -> Unit): Unit { + fun prototypes(builder: MutableVisionGroup.() -> Unit): Unit { (prototypes ?: Prototypes().also { prototypes = it attach(it) @@ -53,8 +53,8 @@ class VisualGroup3D : AbstractVisualGroup(), VisualObject3D, PrototypeHolder { override var scale: Point3D? = null @SerialName("children") - private val _children = HashMap() - override val children: Map get() = _children + private val _children = HashMap() + override val children: Map get() = _children override fun attachChildren() { prototypes?.parent = this @@ -66,7 +66,7 @@ class VisualGroup3D : AbstractVisualGroup(), VisualObject3D, PrototypeHolder { _children.remove(token)?.apply { parent = null } } - override fun setChild(token: NameToken, child: VisualObject) { + override fun setChild(token: NameToken, child: Vision) { _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 createGroup(): VisualGroup3D = VisualGroup3D() + override fun createGroup(): VisionGroup3D = VisionGroup3D() companion object { // val PROTOTYPES_KEY = NameToken("@prototypes") - fun parseJson(json: String): VisualGroup3D = + fun parseJson(json: String): VisionGroup3D = 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. */ -fun MutableVisualGroup.group(name: String = "", action: VisualGroup3D.() -> Unit = {}): VisualGroup3D = - VisualGroup3D().apply(action).also { +fun MutableVisionGroup.group(name: String = "", action: VisionGroup3D.() -> Unit = {}): VisionGroup3D = + VisionGroup3D().apply(action).also { set(name, it) } internal class Prototypes( - override var children: MutableMap = LinkedHashMap() -) : AbstractVisualGroup(), MutableVisualGroup, PrototypeHolder { + override var children: MutableMap = LinkedHashMap() +) : AbstractVision(), MutableVisionGroup, PrototypeHolder { override var styleSheet: StyleSheet? get() = null @@ -115,11 +115,11 @@ internal class Prototypes( childrenChanged(token.asName(), null) } - override fun setChild(token: NameToken, child: VisualObject) { + override fun setChild(token: NameToken, child: Vision) { children[token] = child } - override fun createGroup() = SimpleVisualGroup() + override fun createGroup() = SimpleVisionGroup() override var ownProperties: Config? get() = null @@ -127,12 +127,12 @@ internal class Prototypes( error("Can't define properties for prototypes block") } - override val prototypes: MutableVisualGroup get() = this + override val prototypes: MutableVisionGroup get() = this override fun attachChildren() { children.values.forEach { it.parent = parent - (it as? VisualGroup)?.attachChildren() + (it as? VisionGroup)?.attachChildren() } } } diff --git a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Visual3D.kt b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Visual3D.kt index 6ccd9cfb..94af42a5 100644 --- a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Visual3D.kt +++ b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Visual3D.kt @@ -7,9 +7,9 @@ import hep.dataforge.context.PluginTag import hep.dataforge.meta.* import hep.dataforge.names.Name import hep.dataforge.names.toName -import hep.dataforge.vision.SimpleVisualGroup -import hep.dataforge.vision.Visual -import hep.dataforge.vision.VisualObject +import hep.dataforge.vision.SimpleVisionGroup +import hep.dataforge.vision.Vision +import hep.dataforge.vision.VisionManager import kotlinx.serialization.UnstableDefault import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonConfiguration @@ -19,11 +19,11 @@ import kotlin.reflect.KClass class Visual3D(meta: Meta) : AbstractPlugin(meta) { - val visual by require(Visual) + val visual by require(VisionManager) override val tag: PluginTag get() = Companion.tag - override fun provideTop(target: String): Map = if (target == Visual.VISUAL_FACTORY_TYPE) { + override fun provideTop(target: String): Map = if (target == VisionManager.VISUAL_FACTORY_TYPE) { mapOf(Box.TYPE_NAME.toName() to Box) } else { super.provideTop(target) @@ -39,9 +39,9 @@ class Visual3D(meta: Meta) : AbstractPlugin(meta) { contextual(Point3DSerializer) contextual(Point2DSerializer) - polymorphic(VisualObject::class, VisualObject3D::class) { - subclass(SimpleVisualGroup.serializer()) - subclass(VisualGroup3D.serializer()) + polymorphic(Vision::class, VisualObject3D::class) { + subclass(SimpleVisionGroup.serializer()) + subclass(VisionGroup3D.serializer()) subclass(Proxy.serializer()) subclass(Composite.serializer()) subclass(Tube.serializer()) diff --git a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/VisualObject3D.kt b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/VisualObject3D.kt index e31ba99c..8ab6616e 100644 --- a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/VisualObject3D.kt +++ b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/VisualObject3D.kt @@ -9,7 +9,7 @@ import hep.dataforge.names.plus import hep.dataforge.output.Renderer import hep.dataforge.values.ValueType import hep.dataforge.values.asValue -import hep.dataforge.vision.VisualObject +import hep.dataforge.vision.Vision import hep.dataforge.vision.enum import hep.dataforge.vision.spatial.VisualObject3D.Companion.DETAIL_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 /** - * Interface for 3-dimensional [VisualObject] + * Interface for 3-dimensional [Vision] */ -interface VisualObject3D : VisualObject { +interface VisualObject3D : Vision { var position: Point3D? var rotation: Point3D? var scale: Point3D? @@ -70,7 +70,7 @@ interface VisualObject3D : VisualObject { } //TODO replace by descriptor merge - value(VisualObject.STYLE_KEY) { + value(Vision.STYLE_KEY) { type(ValueType.STRING) multiple = true } @@ -92,8 +92,8 @@ var VisualObject3D.layer: Int setItem(LAYER_KEY, value.asValue()) } -fun Renderer.render(meta: Meta = Meta.EMPTY, action: VisualGroup3D.() -> Unit) = - render(VisualGroup3D().apply(action), meta) +fun Renderer.render(meta: Meta = Meta.EMPTY, action: VisionGroup3D.() -> Unit) = + render(VisionGroup3D().apply(action), meta) // Common properties @@ -121,7 +121,7 @@ var VisualObject3D.detail: Int? get() = getProperty(DETAIL_KEY, false).int set(value) = setItem(DETAIL_KEY, value?.asValue()) -var VisualObject.visible: Boolean? +var Vision.visible: Boolean? get() = getItem(VISIBLE_KEY).boolean 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. * Property is not inherited. */ -var VisualObject.ignore: Boolean? +var Vision.ignore: Boolean? get() = getProperty(IGNORE_KEY, false).boolean set(value) = setItem(IGNORE_KEY, value?.asValue()) diff --git a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/serialization.kt b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/serialization.kt index 628c2b9f..2a273e66 100644 --- a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/serialization.kt +++ b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/serialization.kt @@ -2,9 +2,9 @@ package hep.dataforge.vision.spatial import hep.dataforge.meta.double import hep.dataforge.names.NameToken -import hep.dataforge.vision.MutableVisualGroup -import hep.dataforge.vision.VisualGroup -import hep.dataforge.vision.VisualObject +import hep.dataforge.vision.MutableVisionGroup +import hep.dataforge.vision.Vision +import hep.dataforge.vision.VisionGroup import kotlinx.serialization.* import kotlinx.serialization.builtins.MapSerializer import kotlinx.serialization.builtins.nullable @@ -97,31 +97,31 @@ object Point2DSerializer : KSerializer { } } -@Serializer(MutableVisualGroup::class) -internal object PrototypesSerializer : KSerializer { +@Serializer(MutableVisionGroup::class) +internal object PrototypesSerializer : KSerializer { - private val mapSerializer: KSerializer> = + private val mapSerializer: KSerializer> = MapSerializer( NameToken.serializer(), - VisualObject.serializer() + Vision.serializer() ) override val descriptor: SerialDescriptor get() = mapSerializer.descriptor - override fun deserialize(decoder: Decoder): MutableVisualGroup { + override fun deserialize(decoder: Decoder): MutableVisionGroup { val map = mapSerializer.deserialize(decoder) - return Prototypes(map as? MutableMap ?: LinkedHashMap(map)) + return Prototypes(map as? MutableMap ?: LinkedHashMap(map)) } - override fun serialize(encoder: Encoder, value: MutableVisualGroup) { + override fun serialize(encoder: Encoder, value: MutableVisionGroup) { 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 { - if(it is VisualGroup){ +fun Vision.Companion.parseJson(str: String) = Visual3D.json.parse(Vision.serializer(), str).also { + if(it is VisionGroup){ it.attachChildren() } } \ No newline at end of file diff --git a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/transform/RemoveSingleChild.kt b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/transform/RemoveSingleChild.kt index 666b0935..cd81d460 100644 --- a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/transform/RemoveSingleChild.kt +++ b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/transform/RemoveSingleChild.kt @@ -2,12 +2,12 @@ package hep.dataforge.vision.spatial.transform import hep.dataforge.meta.update import hep.dataforge.names.asName -import hep.dataforge.vision.MutableVisualGroup -import hep.dataforge.vision.VisualGroup -import hep.dataforge.vision.VisualObject +import hep.dataforge.vision.MutableVisionGroup +import hep.dataforge.vision.Vision +import hep.dataforge.vision.VisionGroup import hep.dataforge.vision.spatial.* -internal fun mergeChild(parent: VisualGroup, child: VisualObject): VisualObject { +internal fun mergeChild(parent: VisionGroup, child: Vision): Vision { return child.apply { config.update(parent.config) @@ -32,16 +32,16 @@ internal fun mergeChild(parent: VisualGroup, child: VisualObject): VisualObject } } -object RemoveSingleChild : VisualTreeTransform() { +object RemoveSingleChild : VisualTreeTransform() { - override fun VisualGroup3D.transformInPlace() { - fun MutableVisualGroup.replaceChildren() { + override fun VisionGroup3D.transformInPlace() { + fun MutableVisionGroup.replaceChildren() { children.forEach { (childName, parent) -> if (parent is Proxy) return@forEach //ignore refs - if (parent is MutableVisualGroup) { + if (parent is MutableVisionGroup) { 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 newParent = mergeChild(parent, child) newParent.parent = null @@ -56,7 +56,7 @@ object RemoveSingleChild : VisualTreeTransform() { } } - override fun VisualGroup3D.clone(): VisualGroup3D { + override fun VisionGroup3D.clone(): VisionGroup3D { TODO() } } \ No newline at end of file diff --git a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/transform/UnRef.kt b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/transform/UnRef.kt index a72d766e..8b88e790 100644 --- a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/transform/UnRef.kt +++ b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/transform/UnRef.kt @@ -2,15 +2,15 @@ package hep.dataforge.vision.spatial.transform import hep.dataforge.names.Name import hep.dataforge.names.asName -import hep.dataforge.vision.MutableVisualGroup -import hep.dataforge.vision.VisualGroup +import hep.dataforge.vision.MutableVisionGroup +import hep.dataforge.vision.VisionGroup import hep.dataforge.vision.spatial.Proxy -import hep.dataforge.vision.spatial.VisualGroup3D +import hep.dataforge.vision.spatial.VisionGroup3D -object UnRef : VisualTreeTransform() { - private fun VisualGroup.countRefs(): Map { +object UnRef : VisualTreeTransform() { + private fun VisionGroup.countRefs(): Map { return children.values.fold(HashMap()) { reducer, obj -> - if (obj is VisualGroup) { + if (obj is VisionGroup) { val counter = obj.countRefs() counter.forEach { (key, value) -> reducer[key] = (reducer[key] ?: 0) + value @@ -23,8 +23,8 @@ object UnRef : VisualTreeTransform() { } } - private fun MutableVisualGroup.unref(name: Name) { - (this as? VisualGroup3D)?.prototypes?.set(name, null) + private fun MutableVisionGroup.unref(name: Name) { + (this as? VisionGroup3D)?.prototypes?.set(name, null) children.filter { (it.value as? Proxy)?.templateName == name }.forEach { (key, value) -> val proxy = value as Proxy val newChild = mergeChild(proxy, proxy.prototype) @@ -32,17 +32,17 @@ object UnRef : VisualTreeTransform() { set(key.asName(), newChild) // replace proxy with merged object } - children.values.filterIsInstance().forEach { it.unref(name) } + children.values.filterIsInstance().forEach { it.unref(name) } } - override fun VisualGroup3D.transformInPlace() { + override fun VisionGroup3D.transformInPlace() { val counts = countRefs() counts.filter { it.value <= 1 }.forEach { this.unref(it.key) } } - override fun VisualGroup3D.clone(): VisualGroup3D { + override fun VisionGroup3D.clone(): VisionGroup3D { TODO() } diff --git a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/transform/VisualTreeTransform.kt b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/transform/VisualTreeTransform.kt index f1615dbe..2bbd8df6 100644 --- a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/transform/VisualTreeTransform.kt +++ b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/transform/VisualTreeTransform.kt @@ -1,11 +1,11 @@ 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 { +abstract class VisualTreeTransform { protected abstract fun T.transformInPlace() protected abstract fun T.clone(): T @@ -21,7 +21,7 @@ abstract class VisualTreeTransform { } } -fun T.transform(vararg transform: VisualTreeTransform): T { +fun T.transform(vararg transform: VisualTreeTransform): T { var res = this transform.forEach { res = it(res) @@ -29,6 +29,6 @@ fun T.transform(vararg transform: VisualTreeTransform): T return res } -fun T.transformInPlace(vararg transform: VisualTreeTransform) { +fun T.transformInPlace(vararg transform: VisualTreeTransform) { transform.forEach { it(this) } } \ No newline at end of file diff --git a/visionforge-spatial/src/commonTest/kotlin/hep/dataforge/vision/spatial/ConvexTest.kt b/visionforge-spatial/src/commonTest/kotlin/hep/dataforge/vision/spatial/ConvexTest.kt index 6f455d48..c1252ca2 100644 --- a/visionforge-spatial/src/commonTest/kotlin/hep/dataforge/vision/spatial/ConvexTest.kt +++ b/visionforge-spatial/src/commonTest/kotlin/hep/dataforge/vision/spatial/ConvexTest.kt @@ -11,7 +11,7 @@ class ConvexTest { @Suppress("UNUSED_VARIABLE") @Test fun testConvexBuilder() { - val group = VisualGroup3D().apply { + val group = VisionGroup3D().apply { convex { point(50, 50, -50) point(50, -50, -50) diff --git a/visionforge-spatial/src/commonTest/kotlin/hep/dataforge/vision/spatial/GroupTest.kt b/visionforge-spatial/src/commonTest/kotlin/hep/dataforge/vision/spatial/GroupTest.kt index a816701f..d313eefa 100644 --- a/visionforge-spatial/src/commonTest/kotlin/hep/dataforge/vision/spatial/GroupTest.kt +++ b/visionforge-spatial/src/commonTest/kotlin/hep/dataforge/vision/spatial/GroupTest.kt @@ -9,7 +9,7 @@ import kotlin.test.assertEquals class GroupTest { @Test fun testGroupWithComposite() { - val group = VisualGroup3D().apply { + val group = VisionGroup3D().apply { union("union") { box(100, 100, 100) { z = 100 diff --git a/visionforge-spatial/src/commonTest/kotlin/hep/dataforge/vision/spatial/PropertyTest.kt b/visionforge-spatial/src/commonTest/kotlin/hep/dataforge/vision/spatial/PropertyTest.kt index 21bde40d..c66f7752 100644 --- a/visionforge-spatial/src/commonTest/kotlin/hep/dataforge/vision/spatial/PropertyTest.kt +++ b/visionforge-spatial/src/commonTest/kotlin/hep/dataforge/vision/spatial/PropertyTest.kt @@ -12,7 +12,7 @@ class PropertyTest { @Test fun testInheritedProperty() { var box: Box? = null - val group = VisualGroup3D().apply { + val group = VisionGroup3D().apply { config["test"] = 22 group { box = box(100, 100, 100) @@ -24,7 +24,7 @@ class PropertyTest { @Test fun testStyleProperty() { var box: Box? = null - val group = VisualGroup3D().apply { + val group = VisionGroup3D().apply { styleSheet { set("testStyle") { "test" put 22 @@ -42,7 +42,7 @@ class PropertyTest { @Test fun testColor() { var box: Box? = null - val group = VisualGroup3D().apply { + val group = VisionGroup3D().apply { styleSheet { set("testStyle") { Material3D.MATERIAL_COLOR_KEY put "#555555" @@ -60,7 +60,7 @@ class PropertyTest { @Test fun testProxyStyleProperty() { var box: Proxy? = null - val group = VisualGroup3D().apply { + val group = VisionGroup3D().apply { styleSheet { set("testStyle") { Material3D.MATERIAL_COLOR_KEY put "#555555" diff --git a/visionforge-spatial/src/commonTest/kotlin/hep/dataforge/vision/spatial/SerializationTest.kt b/visionforge-spatial/src/commonTest/kotlin/hep/dataforge/vision/spatial/SerializationTest.kt index 00707d68..8be6fcfa 100644 --- a/visionforge-spatial/src/commonTest/kotlin/hep/dataforge/vision/spatial/SerializationTest.kt +++ b/visionforge-spatial/src/commonTest/kotlin/hep/dataforge/vision/spatial/SerializationTest.kt @@ -1,7 +1,7 @@ package hep.dataforge.vision.spatial import hep.dataforge.names.toName -import hep.dataforge.vision.VisualObject +import hep.dataforge.vision.Vision import hep.dataforge.vision.get import kotlin.test.Test import kotlin.test.assertEquals @@ -16,7 +16,7 @@ class SerializationTest { } val string = cube.stringify() println(string) - val newCube = VisualObject.parseJson(string) + val newCube = Vision.parseJson(string) assertEquals(cube.config, newCube.config) } @@ -27,7 +27,7 @@ class SerializationTest { x = 100 z = -100 } - val group = VisualGroup3D().apply { + val group = VisionGroup3D().apply { proxy("cube", cube) proxyGroup("pg", "pg.content".toName()){ sphere(50){ @@ -37,7 +37,7 @@ class SerializationTest { } val string = group.stringify() println(string) - val reconstructed = VisualGroup3D.parseJson(string) + val reconstructed = VisionGroup3D.parseJson(string) assertEquals(group["cube"]?.config, reconstructed["cube"]?.config) } } \ No newline at end of file diff --git a/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/ThreeFactory.kt b/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/ThreeFactory.kt index 9889da23..4a7c5600 100644 --- a/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/ThreeFactory.kt +++ b/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/ThreeFactory.kt @@ -3,7 +3,7 @@ package hep.dataforge.vision.spatial.three import hep.dataforge.names.Name import hep.dataforge.names.startsWith 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.Material3D.Companion.MATERIAL_KEY import hep.dataforge.vision.spatial.three.ThreeFactory.Companion.TYPE @@ -17,7 +17,7 @@ import kotlin.reflect.KClass * Builder and updater for three.js object */ @Type(TYPE) -interface ThreeFactory { +interface ThreeFactory { val type: KClass @@ -31,7 +31,7 @@ interface ThreeFactory { /** * Update position, rotation and visibility */ -fun Object3D.updatePosition(obj: VisualObject) { +fun Object3D.updatePosition(obj: Vision) { visible = obj.visible ?: true if(obj is VisualObject3D) { position.set(obj.x, obj.y, obj.z) @@ -56,7 +56,7 @@ fun Object3D.updatePosition(obj: VisualObject) { /** * 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)) { this.material = getMaterial(source) } else if ( diff --git a/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/ThreeMaterials.kt b/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/ThreeMaterials.kt index 61d09ec7..bec36997 100644 --- a/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/ThreeMaterials.kt +++ b/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/ThreeMaterials.kt @@ -3,7 +3,7 @@ package hep.dataforge.vision.spatial.three import hep.dataforge.meta.* import hep.dataforge.values.ValueType import hep.dataforge.vision.Colors -import hep.dataforge.vision.VisualObject +import hep.dataforge.vision.Vision import hep.dataforge.vision.spatial.Material3D import info.laht.threekt.materials.LineBasicMaterial import info.laht.threekt.materials.Material @@ -43,8 +43,8 @@ object ThreeMaterials { } } - fun getMaterial(visualObject3D: VisualObject): Material { - val meta = visualObject3D.getItem(Material3D.MATERIAL_KEY).node ?: return ThreeMaterials.DEFAULT + fun getMaterial(vision3D: Vision): Material { + val meta = vision3D.getItem(Material3D.MATERIAL_KEY).node ?: return ThreeMaterials.DEFAULT return if (meta[Material3D.SPECULAR_COLOR_KEY] != null) { MeshPhongMaterial().apply { color = meta[Material3D.COLOR_KEY]?.getColor() ?: DEFAULT_COLOR diff --git a/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/ThreePlugin.kt b/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/ThreePlugin.kt index 705424b2..e81e5b3a 100644 --- a/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/ThreePlugin.kt +++ b/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/ThreePlugin.kt @@ -3,7 +3,7 @@ package hep.dataforge.vision.spatial.three import hep.dataforge.context.* import hep.dataforge.meta.Meta import hep.dataforge.names.* -import hep.dataforge.vision.VisualObject +import hep.dataforge.vision.Vision import hep.dataforge.vision.spatial.* import info.laht.threekt.core.Object3D import kotlin.collections.set @@ -28,7 +28,7 @@ class ThreePlugin : AbstractPlugin() { } @Suppress("UNCHECKED_CAST") - private fun findObjectFactory(type: KClass): ThreeFactory? { + private fun findObjectFactory(type: KClass): ThreeFactory? { return (objectFactories[type] ?: context.content>(ThreeFactory.TYPE).values.find { it.type == type }) as ThreeFactory? @@ -38,7 +38,7 @@ class ThreePlugin : AbstractPlugin() { return when (obj) { is ThreeVisualObject -> obj.toObject3D() is Proxy -> proxyFactory(obj) - is VisualGroup3D -> { + is VisionGroup3D -> { val group = ThreeGroup() obj.children.forEach { (token, child) -> if (child is VisualObject3D && child.ignore != true) { diff --git a/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/outputConfig.kt b/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/outputConfig.kt index b881d4e3..d4ea812b 100644 --- a/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/outputConfig.kt +++ b/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/outputConfig.kt @@ -3,8 +3,8 @@ package hep.dataforge.vision.spatial.three import hep.dataforge.js.requireJS import hep.dataforge.vision.bootstrap.accordion import hep.dataforge.vision.bootstrap.entry +import hep.dataforge.vision.spatial.VisionGroup3D import hep.dataforge.vision.spatial.Visual3D -import hep.dataforge.vision.spatial.VisualGroup3D import kotlinx.html.* import kotlinx.html.dom.append import kotlinx.html.js.onChangeFunction @@ -52,9 +52,9 @@ fun RBuilder.canvasControls(canvas: ThreeCanvas) = accordion("controls") { +"Export" attrs { onClickFunction = { - val json = (canvas.content as? VisualGroup3D)?.let { group -> + val json = (canvas.content as? VisionGroup3D)?.let { group -> Visual3D.json.stringify( - VisualGroup3D.serializer(), + VisionGroup3D.serializer(), group ) } @@ -116,9 +116,9 @@ fun Element.displayCanvasControls(canvas: ThreeCanvas, block: TagConsumer + val json = (canvas.content as? VisionGroup3D)?.let { group -> Visual3D.json.stringify( - VisualGroup3D.serializer(), + VisionGroup3D.serializer(), group ) } diff --git a/visionforge-spatial/src/jvmMain/kotlin/hep/dataforge/vision/spatial/fx/FX3DPlugin.kt b/visionforge-spatial/src/jvmMain/kotlin/hep/dataforge/vision/spatial/fx/FX3DPlugin.kt index 4d675833..b9d5f663 100644 --- a/visionforge-spatial/src/jvmMain/kotlin/hep/dataforge/vision/spatial/fx/FX3DPlugin.kt +++ b/visionforge-spatial/src/jvmMain/kotlin/hep/dataforge/vision/spatial/fx/FX3DPlugin.kt @@ -46,7 +46,7 @@ class FX3DPlugin : AbstractPlugin() { val binding = VisualObjectFXBinding(obj) return when (obj) { is Proxy -> proxyFactory(obj, binding) - is VisualGroup3D -> { + is VisionGroup3D -> { Group(obj.children.mapNotNull { (token, obj) -> (obj as? VisualObject3D)?.let { buildNode(it).apply { diff --git a/visionforge-spatial/src/jvmMain/kotlin/hep/dataforge/vision/spatial/fx/FXProxyFactory.kt b/visionforge-spatial/src/jvmMain/kotlin/hep/dataforge/vision/spatial/fx/FXProxyFactory.kt index 760a6121..c76317c3 100644 --- a/visionforge-spatial/src/jvmMain/kotlin/hep/dataforge/vision/spatial/fx/FXProxyFactory.kt +++ b/visionforge-spatial/src/jvmMain/kotlin/hep/dataforge/vision/spatial/fx/FXProxyFactory.kt @@ -3,7 +3,7 @@ package hep.dataforge.vision.spatial.fx import hep.dataforge.names.Name import hep.dataforge.names.isEmpty import hep.dataforge.names.toName -import hep.dataforge.vision.VisualObject +import hep.dataforge.vision.Vision import hep.dataforge.vision.spatial.Proxy import javafx.scene.Group 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)) { // (this as? Shape3D)?.let { it.material = obj.getProperty(Material3D.MATERIAL_KEY).material() } // } diff --git a/visionforge-spatial/src/jvmMain/kotlin/hep/dataforge/vision/spatial/fx/VisualObjectFXBinding.kt b/visionforge-spatial/src/jvmMain/kotlin/hep/dataforge/vision/spatial/fx/VisualObjectFXBinding.kt index 34d9d7d6..bf1fa70e 100644 --- a/visionforge-spatial/src/jvmMain/kotlin/hep/dataforge/vision/spatial/fx/VisualObjectFXBinding.kt +++ b/visionforge-spatial/src/jvmMain/kotlin/hep/dataforge/vision/spatial/fx/VisualObjectFXBinding.kt @@ -4,15 +4,15 @@ import hep.dataforge.meta.* import hep.dataforge.names.Name import hep.dataforge.names.startsWith import hep.dataforge.names.toName -import hep.dataforge.vision.VisualObject +import hep.dataforge.vision.Vision import javafx.application.Platform import javafx.beans.binding.ObjectBinding 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?>>() init { diff --git a/visionforge-spatial/src/jvmMain/kotlin/hep/dataforge/vision/spatial/generateSchema.kt b/visionforge-spatial/src/jvmMain/kotlin/hep/dataforge/vision/spatial/generateSchema.kt index ae1dc8e2..6a6addae 100644 --- a/visionforge-spatial/src/jvmMain/kotlin/hep/dataforge/vision/spatial/generateSchema.kt +++ b/visionforge-spatial/src/jvmMain/kotlin/hep/dataforge/vision/spatial/generateSchema.kt @@ -186,7 +186,7 @@ fun main() { } } "hep.dataforge.vis.spatial.VisualGroup3D" to jsonSchema( - VisualGroup3D.serializer().descriptor, + VisionGroup3D.serializer().descriptor, context )