From 8f6c3822ffa8c851b8b9c52774110498ae46ab54 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sat, 31 Oct 2020 12:10:03 +0300 Subject: [PATCH] Remove unnecessary coordinates and properties for solids after serialization fix. --- CHANGELOG.md | 3 + .../ru/mipt/npm/muon/monitor/MMDemoApp.kt | 2 +- .../ru/mipt/npm/muon/monitor/readResource.kt | 4 +- .../vision/bootstrap/outputConfig.kt | 3 +- .../vision/bootstrap/visionPropertyEditor.kt | 4 +- ui/ring/src/main/kotlin/ringui/RingUI.kt | 2 +- .../src/main/kotlin/ringui/header/Header.kt | 2 +- ui/ring/src/main/kotlin/ringui/header/Logo.kt | 2 +- ui/ring/src/main/kotlin/ringui/header/Tray.kt | 2 +- visionforge-core/build.gradle.kts | 1 - .../dataforge/properties/ConfigProperty.kt | 23 ------- .../hep/dataforge/properties/Property.kt | 60 ------------------- .../hep/dataforge/vision/AbstractVision.kt | 6 +- .../kotlin/hep/dataforge/vision/Vision.kt | 1 + .../kotlin/hep/dataforge/js/Application.kt | 31 +++++----- .../kotlin/hep/dataforge/js/bindings.kt | 33 ---------- .../jsMain/kotlin/hep/dataforge/js/jsExtra.kt | 20 ------- visionforge-server/build.gradle.kts | 47 +++++++-------- .../dataforge/vision/solid/AbstractSolid.kt | 17 ++++++ .../kotlin/hep/dataforge/vision/solid/Box.kt | 8 +-- .../hep/dataforge/vision/solid/Composite.kt | 8 +-- .../hep/dataforge/vision/solid/ConeSegment.kt | 8 +-- .../hep/dataforge/vision/solid/Convex.kt | 11 +--- .../hep/dataforge/vision/solid/Extruded.kt | 8 +-- .../hep/dataforge/vision/solid/PolyLine.kt | 16 ++--- .../hep/dataforge/vision/solid/Proxy.kt | 17 ++---- .../hep/dataforge/vision/solid/Solid.kt | 4 +- .../hep/dataforge/vision/solid/SolidGroup.kt | 4 -- .../hep/dataforge/vision/solid/SolidLabel.kt | 19 ++---- .../dataforge/vision/solid/SolidManager.kt | 8 +-- .../hep/dataforge/vision/solid/Sphere.kt | 21 ++----- .../kotlin/hep/dataforge/vision/solid/Tube.kt | 18 +----- .../vision/solid/three/ThreeLabelFactory.kt | 3 +- .../vision/solid/three/ThreeVision.kt | 22 ++----- 34 files changed, 111 insertions(+), 327 deletions(-) delete mode 100644 visionforge-core/src/commonMain/kotlin/hep/dataforge/properties/ConfigProperty.kt delete mode 100644 visionforge-core/src/commonMain/kotlin/hep/dataforge/properties/Property.kt delete mode 100644 visionforge-core/src/jsMain/kotlin/hep/dataforge/js/bindings.kt delete mode 100644 visionforge-core/src/jsMain/kotlin/hep/dataforge/js/jsExtra.kt create mode 100644 visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/AbstractSolid.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index db566d2c..c3200775 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,13 +2,16 @@ ## [Unreleased] ### Added +- Server module ### Changed ### Deprecated ### Removed +- Primary modules dependencies on UI ### Fixed +- Version conflicts ### Security diff --git a/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMDemoApp.kt b/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMDemoApp.kt index f4f93495..62b538ab 100644 --- a/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMDemoApp.kt +++ b/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMDemoApp.kt @@ -19,7 +19,7 @@ private class MMDemoApp : Application { private val connection = HttpClient { install(JsonFeature) { - serializer = KotlinxSerializer(Json { serializersModule = SolidManager.serialModule }) + serializer = KotlinxSerializer(Json { serializersModule = SolidManager.serializersModule }) } } diff --git a/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/readResource.kt b/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/readResource.kt index 46242a20..4fce1715 100644 --- a/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/readResource.kt +++ b/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/readResource.kt @@ -1,9 +1,7 @@ package ru.mipt.npm.muon.monitor -import hep.dataforge.js.requireJS - actual fun readResource(path: String): String { - return requireJS(path) as String + return kotlinext.js.require(path) as String } // TODO replace by resource diff --git a/ui/bootstrap/src/main/kotlin/hep/dataforge/vision/bootstrap/outputConfig.kt b/ui/bootstrap/src/main/kotlin/hep/dataforge/vision/bootstrap/outputConfig.kt index 9e5e1a4b..e3579fc0 100644 --- a/ui/bootstrap/src/main/kotlin/hep/dataforge/vision/bootstrap/outputConfig.kt +++ b/ui/bootstrap/src/main/kotlin/hep/dataforge/vision/bootstrap/outputConfig.kt @@ -1,6 +1,5 @@ package hep.dataforge.vision.bootstrap -import hep.dataforge.js.requireJS import hep.dataforge.meta.DFExperimental import hep.dataforge.vision.solid.SolidGroup import hep.dataforge.vision.solid.SolidManager @@ -27,7 +26,7 @@ private fun saveData(event: Event, fileName: String, mimeType: String = "text/pl event.stopPropagation(); event.preventDefault(); - val fileSaver = requireJS("file-saver") + val fileSaver = kotlinext.js.require("file-saver") val blob = Blob(arrayOf(dataBuilder()), BlobPropertyBag("$mimeType;charset=utf-8")) fileSaver.saveAs(blob, fileName) } diff --git a/ui/bootstrap/src/main/kotlin/hep/dataforge/vision/bootstrap/visionPropertyEditor.kt b/ui/bootstrap/src/main/kotlin/hep/dataforge/vision/bootstrap/visionPropertyEditor.kt index 0c46e386..5651257b 100644 --- a/ui/bootstrap/src/main/kotlin/hep/dataforge/vision/bootstrap/visionPropertyEditor.kt +++ b/ui/bootstrap/src/main/kotlin/hep/dataforge/vision/bootstrap/visionPropertyEditor.kt @@ -10,7 +10,7 @@ import org.w3c.dom.Element import react.RBuilder import react.dom.render -fun RBuilder.visionPropertyEditor( +public fun RBuilder.visionPropertyEditor( item: Vision, descriptor: NodeDescriptor? = item.descriptor, default: Meta? = null, @@ -36,7 +36,7 @@ fun RBuilder.visionPropertyEditor( } } -fun Element.visionPropertyEditor( +public fun Element.visionPropertyEditor( item: Vision, descriptor: NodeDescriptor? = item.descriptor, default: Meta? = null diff --git a/ui/ring/src/main/kotlin/ringui/RingUI.kt b/ui/ring/src/main/kotlin/ringui/RingUI.kt index c7d3b5ef..7d9a475c 100644 --- a/ui/ring/src/main/kotlin/ringui/RingUI.kt +++ b/ui/ring/src/main/kotlin/ringui/RingUI.kt @@ -1,7 +1,7 @@ package ringui -import ringui.header.HeaderProps import react.RClass +import ringui.header.HeaderProps @JsModule("@jetbrains/ring-ui") external object RingUI { diff --git a/ui/ring/src/main/kotlin/ringui/header/Header.kt b/ui/ring/src/main/kotlin/ringui/header/Header.kt index e04635be..a9c9b1d6 100644 --- a/ui/ring/src/main/kotlin/ringui/header/Header.kt +++ b/ui/ring/src/main/kotlin/ringui/header/Header.kt @@ -1,10 +1,10 @@ package ringui.header -import ringui.RingUI import react.RBuilder import react.RClass import react.RHandler import react.dom.WithClassName +import ringui.RingUI @JsModule("@jetbrains/ring-ui/components/header/header") internal external object HeaderModule { diff --git a/ui/ring/src/main/kotlin/ringui/header/Logo.kt b/ui/ring/src/main/kotlin/ringui/header/Logo.kt index 4a6b4472..f6fd40de 100644 --- a/ui/ring/src/main/kotlin/ringui/header/Logo.kt +++ b/ui/ring/src/main/kotlin/ringui/header/Logo.kt @@ -1,9 +1,9 @@ package ringui.header -import ringui.IconProps import kotlinx.html.A import react.RElementBuilder import react.RHandler +import ringui.IconProps import styled.StyledDOMBuilder external interface HeaderLogoProps : IconProps diff --git a/ui/ring/src/main/kotlin/ringui/header/Tray.kt b/ui/ring/src/main/kotlin/ringui/header/Tray.kt index ce47a44d..cadac0ee 100644 --- a/ui/ring/src/main/kotlin/ringui/header/Tray.kt +++ b/ui/ring/src/main/kotlin/ringui/header/Tray.kt @@ -1,9 +1,9 @@ package ringui.header -import ringui.ButtonProps import react.RElementBuilder import react.RHandler import react.dom.WithClassName +import ringui.ButtonProps // https://github.com/JetBrains/ring-ui/blob/master/components/header/tray.js external interface HeaderTrayProps : WithClassName diff --git a/visionforge-core/build.gradle.kts b/visionforge-core/build.gradle.kts index 6e59b5da..b878791b 100644 --- a/visionforge-core/build.gradle.kts +++ b/visionforge-core/build.gradle.kts @@ -7,7 +7,6 @@ val kotlinWrappersVersion: String by rootProject.extra kotlin { - sourceSets { commonMain { dependencies { diff --git a/visionforge-core/src/commonMain/kotlin/hep/dataforge/properties/ConfigProperty.kt b/visionforge-core/src/commonMain/kotlin/hep/dataforge/properties/ConfigProperty.kt deleted file mode 100644 index 550d39a7..00000000 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/properties/ConfigProperty.kt +++ /dev/null @@ -1,23 +0,0 @@ -package hep.dataforge.properties - -import hep.dataforge.meta.* -import hep.dataforge.names.Name - -@DFExperimental -internal class ConfigProperty(val config: Config, val name: Name) : Property?> { - override var value: MetaItem<*>? - get() = config[name] - set(value) { - config[name] = value - } - - override fun onChange(owner: Any?, callback: (MetaItem<*>?) -> Unit) { - config.onChange(owner) { name, oldItem, newItem -> - if (name == this.name && oldItem != newItem) callback(newItem) - } - } - - override fun removeChangeListener(owner: Any?) { - config.removeListener(owner) - } -} \ No newline at end of file diff --git a/visionforge-core/src/commonMain/kotlin/hep/dataforge/properties/Property.kt b/visionforge-core/src/commonMain/kotlin/hep/dataforge/properties/Property.kt deleted file mode 100644 index 540b0247..00000000 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/properties/Property.kt +++ /dev/null @@ -1,60 +0,0 @@ -package hep.dataforge.properties - -import hep.dataforge.meta.DFExperimental -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.Job -import kotlinx.coroutines.channels.awaitClose -import kotlinx.coroutines.flow.callbackFlow -import kotlinx.coroutines.flow.collect -import kotlinx.coroutines.launch - -//TODO move to core - -@DFExperimental -interface Property { - var value: T - - fun onChange(owner: Any? = null, callback: (T) -> Unit) - fun removeChangeListener(owner: Any? = null) -} - -@DFExperimental -@OptIn(ExperimentalCoroutinesApi::class) -fun Property.flow() = callbackFlow { - send(value) - onChange(this) { - //TODO add exception handler? - launch { - send(it) - } - } - awaitClose { removeChangeListener(this) } -} - -/** - * Reflect all changes in the [source] property onto this property - * - * @return a mirroring job - */ -@DFExperimental -fun Property.mirror(source: Property, scope: CoroutineScope): Job { - return scope.launch { - source.flow().collect { - value = it - } - } -} - -/** - * Bi-directional connection between properties - */ -@DFExperimental -fun Property.bind(other: Property) { - onChange(other) { - other.value = it - } - other.onChange { - this.value = it - } -} \ No newline at end of file diff --git a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/AbstractVision.kt b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/AbstractVision.kt index 68e6ee85..909d021d 100644 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/AbstractVision.kt +++ b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/AbstractVision.kt @@ -6,6 +6,7 @@ import hep.dataforge.names.Name import hep.dataforge.names.asName import hep.dataforge.values.ValueType import hep.dataforge.vision.Vision.Companion.STYLE_KEY +import kotlinx.serialization.Serializable import kotlinx.serialization.Transient internal data class PropertyListener( @@ -13,7 +14,8 @@ internal data class PropertyListener( val action: (name: Name) -> Unit ) -abstract class AbstractVision : Vision { +@Serializable +public open class AbstractVision : Vision { @Transient override var parent: VisionGroup? = null @@ -21,7 +23,7 @@ abstract class AbstractVision : Vision { /** * Object own properties excluding styles and inheritance */ - abstract override var properties: Config? + override var properties: Config? = null protected set protected fun updateStyles(names: List) { diff --git a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/Vision.kt b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/Vision.kt index 7ccdd81e..01f33d9b 100644 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/Vision.kt +++ b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/Vision.kt @@ -9,6 +9,7 @@ import hep.dataforge.values.asValue import hep.dataforge.vision.Vision.Companion.TYPE import hep.dataforge.vision.Vision.Companion.VISIBLE_KEY import kotlinx.serialization.PolymorphicSerializer +import kotlinx.serialization.Serializable import kotlinx.serialization.Transient /** diff --git a/visionforge-core/src/jsMain/kotlin/hep/dataforge/js/Application.kt b/visionforge-core/src/jsMain/kotlin/hep/dataforge/js/Application.kt index 1d43aecd..92a55e20 100644 --- a/visionforge-core/src/jsMain/kotlin/hep/dataforge/js/Application.kt +++ b/visionforge-core/src/jsMain/kotlin/hep/dataforge/js/Application.kt @@ -1,22 +1,23 @@ package hep.dataforge.js -import kotlin.browser.document -import kotlin.dom.hasClass +import kotlinx.browser.document +import kotlinx.dom.hasClass -external val module: Module -external interface Hot { - val data: dynamic +public external val module: Module - fun accept() - fun accept(dependency: String, callback: () -> Unit) - fun accept(dependencies: Array, callback: (updated: Array) -> Unit) +public external interface Hot { + public val data: dynamic - fun dispose(callback: (data: dynamic) -> Unit) + public fun accept() + public fun accept(dependency: String, callback: () -> Unit) + public fun accept(dependencies: Array, callback: (updated: Array) -> Unit) + + public fun dispose(callback: (data: dynamic) -> Unit) } -external interface Module { - val hot: Hot? +public external interface Module { + public val hot: Hot? } /** @@ -24,21 +25,21 @@ external interface Module { * * Base interface for applications supporting Hot Module Replacement (HMR). */ -interface Application { +public interface Application { /** * Starting point for an application. * @param state Initial state between Hot Module Replacement (HMR). */ - fun start(state: Map) + public fun start(state: Map) /** * Ending point for an application. * @return final state for Hot Module Replacement (HMR). */ - fun dispose(): Map = emptyMap() + public fun dispose(): Map = emptyMap() } -fun startApplication(builder: () -> Application) { +public fun startApplication(builder: () -> Application) { fun start(state: dynamic): Application? { return if (document.body?.hasClass("application") == true) { val application = builder() diff --git a/visionforge-core/src/jsMain/kotlin/hep/dataforge/js/bindings.kt b/visionforge-core/src/jsMain/kotlin/hep/dataforge/js/bindings.kt deleted file mode 100644 index c310fe6a..00000000 --- a/visionforge-core/src/jsMain/kotlin/hep/dataforge/js/bindings.kt +++ /dev/null @@ -1,33 +0,0 @@ -package hep.dataforge.js - -import hep.dataforge.meta.DFExperimental -import hep.dataforge.properties.Property -import org.w3c.dom.HTMLInputElement - -@DFExperimental -fun HTMLInputElement.bindValue(property: Property) { - if (this.onchange != null) error("Input element already bound") - this.onchange = { - property.value = this.value - Unit - } - property.onChange(this) { - if (value != it) { - value = it - } - } -} - -@DFExperimental -fun HTMLInputElement.bindChecked(property: Property) { - if (this.onchange != null) error("Input element already bound") - this.onchange = { - property.value = this.checked - Unit - } - property.onChange(this) { - if (checked != it) { - checked = it - } - } -} \ No newline at end of file diff --git a/visionforge-core/src/jsMain/kotlin/hep/dataforge/js/jsExtra.kt b/visionforge-core/src/jsMain/kotlin/hep/dataforge/js/jsExtra.kt deleted file mode 100644 index e3105dd5..00000000 --- a/visionforge-core/src/jsMain/kotlin/hep/dataforge/js/jsExtra.kt +++ /dev/null @@ -1,20 +0,0 @@ -package hep.dataforge.js - -@JsName("require") -external fun requireJS(name: String): dynamic - -inline fun jsObject(builder: T.() -> Unit): T { - val obj: T = js("({})") as T - return obj.apply { - builder() - } -} - -inline fun js(builder: dynamic.() -> Unit): dynamic = jsObject(builder) - -fun toPlainObjectStripNull(obj: Any) = js { - for (key in Object.keys(obj)) { - val value = obj.asDynamic()[key] - if (value != null) this[key] = value - } -} \ No newline at end of file diff --git a/visionforge-server/build.gradle.kts b/visionforge-server/build.gradle.kts index 0eec3285..60d5624b 100644 --- a/visionforge-server/build.gradle.kts +++ b/visionforge-server/build.gradle.kts @@ -1,38 +1,38 @@ -import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation.Companion.MAIN_COMPILATION_NAME +//import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation.Companion.MAIN_COMPILATION_NAME plugins { id("ru.mipt.npm.mpp") - application +// application } val ktorVersion: String by rootProject.extra -kscience { - application() -} +//kscience { +// application() +//} kotlin { - afterEvaluate { - val jsBrowserDistribution by tasks.getting - - jvm { - withJava() - compilations[MAIN_COMPILATION_NAME]?.apply { - tasks.getByName(processResourcesTaskName) { - dependsOn(jsBrowserDistribution) - afterEvaluate { - from(jsBrowserDistribution) - } - } - } - - } - } +// afterEvaluate { +// val jsBrowserDistribution by tasks.getting +// +// jvm { +// withJava() +// compilations[MAIN_COMPILATION_NAME]?.apply { +// tasks.getByName(processResourcesTaskName) { +// dependsOn(jsBrowserDistribution) +// afterEvaluate { +// from(jsBrowserDistribution) +// } +// } +// } +// +// } +// } sourceSets { commonMain { dependencies { - implementation(project(":visionforge-solid")) + implementation(project(":visionforge-core")) } } jvmMain { @@ -50,9 +50,6 @@ kotlin { } } -application { - mainClass.set("ru.mipt.npm.muon.monitor.server.MMServerKt") -} //distributions { // main { diff --git a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/AbstractSolid.kt b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/AbstractSolid.kt new file mode 100644 index 00000000..109ec39e --- /dev/null +++ b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/AbstractSolid.kt @@ -0,0 +1,17 @@ +package hep.dataforge.vision.solid + +import hep.dataforge.vision.AbstractVision +import kotlinx.serialization.Serializable +import kotlinx.serialization.UseSerializers + +@Serializable +public open class AbstractSolid: AbstractVision(), Solid { + @Serializable(Point3DSerializer::class) + override var position: Point3D? = null + + @Serializable(Point3DSerializer::class) + override var rotation: Point3D? = null + + @Serializable(Point3DSerializer::class) + override var scale: Point3D? = null +} \ No newline at end of file diff --git a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Box.kt b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Box.kt index 5bd6aef5..aa2e42f0 100644 --- a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Box.kt +++ b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Box.kt @@ -18,13 +18,7 @@ public class Box( public val xSize: Float, public val ySize: Float, public val zSize: Float -) : AbstractVision(), GeometrySolid { - - override var position: Point3D? = null - override var rotation: Point3D? = null - override var scale: Point3D? = null - - override var properties: Config? = null +) : AbstractSolid(), GeometrySolid { //TODO add helper for color configuration override fun toGeometry(geometryBuilder: GeometryBuilder) { diff --git a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Composite.kt b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Composite.kt index 06da6e07..a019e368 100644 --- a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Composite.kt +++ b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Composite.kt @@ -22,19 +22,13 @@ public class Composite( public val compositeType: CompositeType, public val first: Solid, public val second: Solid -) : AbstractVision(), Solid, VisionGroup { +) : AbstractSolid(), Solid, VisionGroup { init { first.parent = this second.parent = this } - override var position: Point3D? = null - override var rotation: Point3D? = null - override var scale: Point3D? = null - - override var properties: Config? = null - override val children: Map get() = mapOf(NameToken("first") to first, NameToken("second") to second) diff --git a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/ConeSegment.kt b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/ConeSegment.kt index 428e6271..084f2f8e 100644 --- a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/ConeSegment.kt +++ b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/ConeSegment.kt @@ -24,13 +24,7 @@ public class ConeSegment( public var upperRadius: Float, public var startAngle: Float = 0f, public var angle: Float = PI2 -) : AbstractVision(), GeometrySolid { - - override var properties: Config? = null - - override var position: Point3D? = null - override var rotation: Point3D? = null - override var scale: Point3D? = null +) : AbstractSolid(), GeometrySolid { override fun toGeometry(geometryBuilder: GeometryBuilder) { val segments = detail ?: 8 diff --git a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Convex.kt b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Convex.kt index fd2b0389..a96cc8bb 100644 --- a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Convex.kt +++ b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Convex.kt @@ -13,16 +13,7 @@ import kotlinx.serialization.UseSerializers @Serializable @SerialName("solid.convex") -public class Convex(public val points: List) : AbstractVision(), Solid { - - override var properties: Config? = null - - override var position: Point3D? = null - override var rotation: Point3D? = null - override var scale: Point3D? = null - - -} +public class Convex(public val points: List) : AbstractSolid(), Solid public inline fun VisionContainerBuilder.convex(name: String = "", action: ConvexBuilder.() -> Unit = {}): Convex = ConvexBuilder().apply(action).build().also { set(name, it) } diff --git a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Extruded.kt b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Extruded.kt index 8ca27740..afab61f9 100644 --- a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Extruded.kt +++ b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Extruded.kt @@ -44,13 +44,7 @@ public data class Layer(var x: Float, var y: Float, var z: Float, var scale: Flo public class Extruded( public var shape: List = ArrayList(), public var layers: MutableList = ArrayList() -) : AbstractVision(), GeometrySolid { - - override var properties: Config? = null - - override var position: Point3D? = null - override var rotation: Point3D? = null - override var scale: Point3D? = null +) : AbstractSolid(), GeometrySolid { public fun shape(block: Shape2DBuilder.() -> Unit) { this.shape = Shape2DBuilder().apply(block).build() diff --git a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/PolyLine.kt b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/PolyLine.kt index 67e22080..aac82df5 100644 --- a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/PolyLine.kt +++ b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/PolyLine.kt @@ -2,13 +2,10 @@ package hep.dataforge.vision.solid -import hep.dataforge.meta.Config import hep.dataforge.meta.number import hep.dataforge.names.Name import hep.dataforge.names.asName import hep.dataforge.names.plus -import hep.dataforge.vision.AbstractVision -import hep.dataforge.vision.MutableVisionGroup import hep.dataforge.vision.VisionContainerBuilder import hep.dataforge.vision.set import kotlinx.serialization.SerialName @@ -17,12 +14,7 @@ import kotlinx.serialization.UseSerializers @Serializable @SerialName("solid.line") -public class PolyLine(public var points: List) : AbstractVision(), Solid { - override var properties: Config? = null - - override var position: Point3D? = null - override var rotation: Point3D? = null - override var scale: Point3D? = null +public class PolyLine(public var points: List) : AbstractSolid(), Solid { //var lineType by string() public var thickness: Number by number(1.0, key = SolidMaterial.MATERIAL_KEY + THICKNESS_KEY) @@ -33,5 +25,9 @@ public class PolyLine(public var points: List) : AbstractVision(), Soli } -public fun VisionContainerBuilder.polyline(vararg points: Point3D, name: String = "", action: PolyLine.() -> Unit = {}): PolyLine = +public fun VisionContainerBuilder.polyline( + vararg points: Point3D, + name: String = "", + action: PolyLine.() -> Unit = {}, +): PolyLine = PolyLine(points.toList()).apply(action).also { set(name, it) } \ No newline at end of file diff --git a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Proxy.kt b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Proxy.kt index cc56f827..2c75b669 100644 --- a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Proxy.kt +++ b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Proxy.kt @@ -1,5 +1,3 @@ -@file:UseSerializers(Point3DSerializer::class) - package hep.dataforge.vision.solid import hep.dataforge.meta.* @@ -9,10 +7,9 @@ import hep.dataforge.vision.* import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.Transient -import kotlinx.serialization.UseSerializers import kotlin.collections.set -public abstract class AbstractProxy : AbstractVision(), VisionGroup { +public abstract class AbstractProxy : AbstractSolid(), VisionGroup { public abstract val prototype: Vision override fun getProperty(name: Name, inherit: Boolean): MetaItem<*>? { @@ -54,19 +51,13 @@ public abstract class AbstractProxy : AbstractVision(), VisionGroup { @Serializable @SerialName("solid.proxy") public class Proxy private constructor( - public val templateName: Name + public val templateName: Name, ) : AbstractProxy(), Solid { public constructor(parent: SolidGroup, templateName: Name) : this(templateName) { this.parent = parent } - override var position: Point3D? = null - override var rotation: Point3D? = null - override var scale: Point3D? = null - - override var properties: Config? = null - /** * Recursively search for defined template in the parent */ @@ -155,7 +146,7 @@ public val Vision.prototype: Vision */ public fun SolidGroup.ref( templateName: Name, - name: String = "" + name: String = "", ): Proxy = Proxy(this, templateName).also { set(name, it) } /** @@ -164,7 +155,7 @@ public fun SolidGroup.ref( public fun SolidGroup.proxy( name: String, obj: Solid, - templateName: Name = name.toName() + templateName: Name = name.toName(), ): Proxy { val existing = getPrototype(templateName) if (existing == null) { diff --git a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Solid.kt b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Solid.kt index fce83d6d..7e9c044b 100644 --- a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Solid.kt +++ b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Solid.kt @@ -1,5 +1,3 @@ -@file:UseSerializers(Point3DSerializer::class) - package hep.dataforge.vision.solid import hep.dataforge.meta.* @@ -75,7 +73,7 @@ public interface Solid : Vision { item(SolidMaterial.MATERIAL_KEY.toString(), SolidMaterial.descriptor) - enum(ROTATION_ORDER_KEY,default = RotationOrder.XYZ) + enum(ROTATION_ORDER_KEY,default = RotationOrder.XYZ) } } diff --git a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidGroup.kt b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidGroup.kt index 1e2dd7a4..7c9f16fc 100644 --- a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidGroup.kt +++ b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidGroup.kt @@ -1,7 +1,3 @@ -@file:UseSerializers( - Point3DSerializer::class -) - package hep.dataforge.vision.solid import hep.dataforge.meta.Config diff --git a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidLabel.kt b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidLabel.kt index c7f459a5..a9740cb0 100644 --- a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidLabel.kt +++ b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidLabel.kt @@ -1,26 +1,17 @@ -@file:UseSerializers(Point3DSerializer::class) - package hep.dataforge.vision.solid -import hep.dataforge.meta.Config -import hep.dataforge.vision.AbstractVision -import hep.dataforge.vision.MutableVisionGroup import hep.dataforge.vision.VisionContainerBuilder import hep.dataforge.vision.set import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable -import kotlinx.serialization.UseSerializers @Serializable @SerialName("solid.label") -public class SolidLabel(public var text: String, public var fontSize: Double, public var fontFamily: String) : AbstractVision(), Solid { - override var properties: Config? = null - - override var position: Point3D? = null - override var rotation: Point3D? = null - override var scale: Point3D? = null - -} +public class SolidLabel( + public var text: String, + public var fontSize: Double, + public var fontFamily: String, +) : AbstractSolid(), Solid public fun VisionContainerBuilder.label( text: String, diff --git a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidManager.kt b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidManager.kt index 676ee9ba..bdd83669 100644 --- a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidManager.kt +++ b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/SolidManager.kt @@ -85,8 +85,8 @@ public class SolidManager(meta: Meta) : AbstractPlugin(meta) { override val tag: PluginTag get() = Companion.tag override fun content(target: String): Map = when (target) { - VisionForm.TYPE -> serialModule.extractFactories().associateBy { it.name } - VISION_SERIAL_MODULE_TARGET -> mapOf(tag.name.toName() to serialModule) + VisionForm.TYPE -> serializersModule.extractFactories().associateBy { it.name } + VISION_SERIAL_MODULE_TARGET -> mapOf(tag.name.toName() to serializersModule) else -> super.content(target) } @@ -95,7 +95,7 @@ public class SolidManager(meta: Meta) : AbstractPlugin(meta) { override val type: KClass = SolidManager::class override fun invoke(meta: Meta, context: Context): SolidManager = SolidManager(meta) - public val serialModule: SerializersModule = SerializersModule { + public val serializersModule: SerializersModule = SerializersModule { contextual(Point3DSerializer) contextual(Point2DSerializer) @@ -132,7 +132,7 @@ public class SolidManager(meta: Meta) : AbstractPlugin(meta) { useArrayPolymorphism = false encodeDefaults = false ignoreUnknownKeys = true - serializersModule = this@Companion.serialModule + serializersModule = this@Companion.serializersModule } } } diff --git a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Sphere.kt b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Sphere.kt index f21dfbc6..9a647155 100644 --- a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Sphere.kt +++ b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Sphere.kt @@ -1,15 +1,9 @@ -@file:UseSerializers(Point3DSerializer::class) - package hep.dataforge.vision.solid -import hep.dataforge.meta.Config -import hep.dataforge.vision.AbstractVision -import hep.dataforge.vision.MutableVisionGroup import hep.dataforge.vision.VisionContainerBuilder import hep.dataforge.vision.set import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable -import kotlinx.serialization.UseSerializers import kotlin.math.PI import kotlin.math.cos import kotlin.math.sin @@ -21,23 +15,18 @@ public class Sphere( public var phiStart: Float = 0f, public var phi: Float = PI2, public var thetaStart: Float = 0f, - public var theta: Float = PI.toFloat() -) : AbstractVision(), GeometrySolid { - - override var properties: Config? = null - - override var position: Point3D? = null - override var rotation: Point3D? = null - override var scale: Point3D? = null + public var theta: Float = PI.toFloat(), +) : AbstractSolid(), GeometrySolid { override fun toGeometry(geometryBuilder: GeometryBuilder) { fun point3DfromSphCoord(r: Float, theta: Float, phi: Float): Point3D { // This transformation matches three.js sphere implementation val y = r * cos(theta) val z = r * sin(theta) * sin(phi) - val x = - r * sin(theta) * cos(phi) + val x = -r * sin(theta) * cos(phi) return Point3D(x, y, z) } + val segments = this.detail ?: 8 require(segments >= 4) { "The detail for sphere must be >= 4" } val phiStep = phi / segments @@ -66,7 +55,7 @@ public inline fun VisionContainerBuilder.sphere( phi: Number = 2 * PI, theta: Number = PI, name: String = "", - action: Sphere.() -> Unit = {} + action: Sphere.() -> Unit = {}, ): Sphere = Sphere( radius.toFloat(), phi = phi.toFloat(), diff --git a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Tube.kt b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Tube.kt index 9bc2add9..d03dfa98 100644 --- a/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Tube.kt +++ b/visionforge-solid/src/commonMain/kotlin/hep/dataforge/vision/solid/Tube.kt @@ -1,15 +1,9 @@ -@file:UseSerializers(Point3DSerializer::class) - package hep.dataforge.vision.solid -import hep.dataforge.meta.Config -import hep.dataforge.vision.AbstractVision -import hep.dataforge.vision.MutableVisionGroup import hep.dataforge.vision.VisionContainerBuilder import hep.dataforge.vision.set import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable -import kotlinx.serialization.UseSerializers import kotlin.math.PI import kotlin.math.cos import kotlin.math.sin @@ -24,14 +18,8 @@ public class Tube( public var height: Float, public var innerRadius: Float = 0f, public var startAngle: Float = 0f, - public var angle: Float = PI2 -) : AbstractVision(), GeometrySolid { - - override var position: Point3D? = null - override var rotation: Point3D? = null - override var scale: Point3D? = null - - override var properties: Config? = null + public var angle: Float = PI2, +) : AbstractSolid(), GeometrySolid { init { require(radius > 0) @@ -137,7 +125,7 @@ public inline fun VisionContainerBuilder.tube( startAngle: Number = 0f, angle: Number = 2 * PI, name: String = "", - block: Tube.() -> Unit = {} + block: Tube.() -> Unit = {}, ): Tube = Tube( r.toFloat(), height.toFloat(), diff --git a/visionforge-solid/src/jsMain/kotlin/hep/dataforge/vision/solid/three/ThreeLabelFactory.kt b/visionforge-solid/src/jsMain/kotlin/hep/dataforge/vision/solid/three/ThreeLabelFactory.kt index f6c677c4..dad40782 100644 --- a/visionforge-solid/src/jsMain/kotlin/hep/dataforge/vision/solid/three/ThreeLabelFactory.kt +++ b/visionforge-solid/src/jsMain/kotlin/hep/dataforge/vision/solid/three/ThreeLabelFactory.kt @@ -1,11 +1,12 @@ package hep.dataforge.vision.solid.three -import hep.dataforge.js.jsObject + import hep.dataforge.vision.solid.SolidLabel import hep.dataforge.vision.solid.three.ThreeMaterials.getMaterial import info.laht.threekt.core.Object3D import info.laht.threekt.geometries.TextBufferGeometry import info.laht.threekt.objects.Mesh +import kotlinext.js.jsObject import kotlin.reflect.KClass /** diff --git a/visionforge-solid/src/jsMain/kotlin/hep/dataforge/vision/solid/three/ThreeVision.kt b/visionforge-solid/src/jsMain/kotlin/hep/dataforge/vision/solid/three/ThreeVision.kt index 9aeb96e0..fe3d1039 100644 --- a/visionforge-solid/src/jsMain/kotlin/hep/dataforge/vision/solid/three/ThreeVision.kt +++ b/visionforge-solid/src/jsMain/kotlin/hep/dataforge/vision/solid/three/ThreeVision.kt @@ -1,32 +1,18 @@ -@file:UseSerializers(Point3DSerializer::class) - package hep.dataforge.vision.solid.three -import hep.dataforge.meta.Config -import hep.dataforge.vision.AbstractVision -import hep.dataforge.vision.solid.Point3D -import hep.dataforge.vision.solid.Point3DSerializer +import hep.dataforge.vision.solid.AbstractSolid import hep.dataforge.vision.solid.Solid import info.laht.threekt.core.Object3D import kotlinx.serialization.Serializable -import kotlinx.serialization.UseSerializers /** * A custom visual object that has its own Three.js renderer */ -interface ThreeVision : Solid { - fun toObject3D(): Object3D +public interface ThreeVision : Solid { + public fun toObject3D(): Object3D } @Serializable -class CustomThreeVision(val threeFactory: ThreeFactory) : AbstractVision(), - ThreeVision { - override var position: Point3D? = null - override var rotation: Point3D? = null - override var scale: Point3D? = null - - override var properties: Config? = null - +public class CustomThreeVision(public val threeFactory: ThreeFactory) : AbstractSolid(), ThreeVision { override fun toObject3D(): Object3D = threeFactory(this) - } \ No newline at end of file