New properties #34

Merged
altavir merged 19 commits from new-properties into dev 2020-12-29 13:35:01 +03:00
6 changed files with 13 additions and 10 deletions
Showing only changes of commit 4c235b0f53 - Show all commits

View File

@ -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,

View File

@ -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)
}
}

View File

@ -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))
}
}

View File

@ -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
}

View File

@ -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<Solid>.() -> Unit)

View File

@ -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 {