From 4c235b0f53faf1fb6776ec5249589da571269d55 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sat, 19 Dec 2020 20:40:22 +0300 Subject: [PATCH] Fix color inheritance issues --- .../commonMain/kotlin/hep/dataforge/vision/Vision.kt | 11 +++++++++-- .../kotlin/hep/dataforge/vision/VisionBase.kt | 3 +-- .../kotlin/hep/dataforge/vision/VisionGroupBase.kt | 3 +-- .../kotlin/hep/dataforge/vision/solid/FX3DPlugin.kt | 2 +- .../kotlin/hep/dataforge/vision/solid/SolidGroup.kt | 2 -- .../dataforge/vision/solid/three/ThreeMaterials.kt | 2 +- 6 files changed, 13 insertions(+), 10 deletions(-) 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 7363d67e..abf24bc1 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,8 @@ import hep.dataforge.names.asName import hep.dataforge.names.toName import hep.dataforge.provider.Type import hep.dataforge.vision.Vision.Companion.TYPE +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.flow.Flow import kotlinx.serialization.Transient @@ -24,6 +26,11 @@ public interface Vision : Described { @Transient public var parent: VisionGroup? + /** + * A coroutine scope for asynchronous calls and locks + */ + public val scope: CoroutineScope get() = parent?.scope?: GlobalScope + /** * A fast accessor method to get own property (no inheritance or styles). * Should be equivalent to `getProperty(name,false,false,false)`. @@ -32,8 +39,8 @@ public interface Vision : Described { /** * Get property. - * @param inherit toggles parent node property lookup. Null means default inheritance. - * @param includeStyles toggles inclusion of. Null means default style inclusion. + * @param inherit toggles parent node property lookup. Null means inference from descriptor. Default is false. + * @param includeStyles toggles inclusion of. Null means inference from descriptor. Default is true. */ public fun getProperty( name: Name, diff --git a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionBase.kt b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionBase.kt index 94dbd2d8..27c9c92e 100644 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionBase.kt +++ b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionBase.kt @@ -11,7 +11,6 @@ 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.coroutines.GlobalScope import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.launch @@ -103,7 +102,7 @@ public open class VisionBase : Vision { if (propertyName == STYLE_KEY) { updateStyles(styles) } - GlobalScope.launch { + scope.launch { _propertyInvalidationFlow.emit(propertyName) } } diff --git a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionGroupBase.kt b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionGroupBase.kt index 5162809e..2d4f271f 100644 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionGroupBase.kt +++ b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionGroupBase.kt @@ -1,7 +1,6 @@ package hep.dataforge.vision import hep.dataforge.names.* -import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.launch @@ -45,7 +44,7 @@ public open class VisionGroupBase : VisionBase(), MutableVisionGroup { * Propagate children change event upwards */ private fun childrenChanged(name: NameToken, before: Vision?, after: Vision?) { - GlobalScope.launch { + scope.launch { _structureChanges.emit(MutableVisionGroup.StructureChange(name, before, after)) } } diff --git a/visionforge-fx/src/main/kotlin/hep/dataforge/vision/solid/FX3DPlugin.kt b/visionforge-fx/src/main/kotlin/hep/dataforge/vision/solid/FX3DPlugin.kt index b635485b..0032f83a 100644 --- a/visionforge-fx/src/main/kotlin/hep/dataforge/vision/solid/FX3DPlugin.kt +++ b/visionforge-fx/src/main/kotlin/hep/dataforge/vision/solid/FX3DPlugin.kt @@ -71,7 +71,7 @@ class FX3DPlugin : AbstractPlugin() { is PolyLine -> PolyLine3D( obj.points.map { Point3D(it.x, it.y, it.z) }, obj.thickness.toFloat(), - obj.getProperty(SolidMaterial.MATERIAL_COLOR_KEY)?.color() + obj.getProperty(SolidMaterial.MATERIAL_COLOR_KEY, inherit = true)?.color() ).apply { this.meshView.cullFace = CullFace.FRONT } 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 baf79443..e472bbd0 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 @@ -15,8 +15,6 @@ import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder public interface PrototypeHolder { - public val parent: VisionGroup? - @VisionBuilder public fun prototypes(builder: VisionContainerBuilder.() -> Unit) diff --git a/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/ThreeMaterials.kt b/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/ThreeMaterials.kt index f7ec681d..4401e8cd 100644 --- a/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/ThreeMaterials.kt +++ b/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/ThreeMaterials.kt @@ -76,7 +76,7 @@ public object ThreeMaterials { } public fun getMaterial(vision3D: Vision, cache: Boolean): Material { - val meta = vision3D.getProperty(SolidMaterial.MATERIAL_KEY).node ?: return DEFAULT + val meta = vision3D.getProperty(SolidMaterial.MATERIAL_KEY, inherit = true).node ?: return DEFAULT return if (cache) { materialCache.getOrPut(meta) { buildMaterial(meta) } } else {