Migrate to DF 0.3

This commit is contained in:
Alexander Nozik 2020-12-25 19:44:53 +03:00
parent 25a47a9719
commit 2b02f151d2
8 changed files with 58 additions and 25 deletions

View File

@ -52,7 +52,6 @@ class Model {
detector(it) detector(it)
} }
} }
tracks = group("tracks") tracks = group("tracks")
} }

View File

@ -147,8 +147,7 @@ fun Page<Solid>.showcaseCSG() {
detail = 32 detail = 32
} }
material { material {
color(Colors.red) color(Colors.pink)
wireframe = false
} }
} }
composite(CompositeType.UNION) { composite(CompositeType.UNION) {
@ -158,8 +157,8 @@ fun Page<Solid>.showcaseCSG() {
sphere(50){ sphere(50){
detail = 32 detail = 32
} }
color(Colors.lightgreen) color("lightgreen")
opacity = 0.5 opacity = 0.7
} }
composite(CompositeType.SUBTRACT) { composite(CompositeType.SUBTRACT) {
y = -300 y = -300
@ -169,7 +168,7 @@ fun Page<Solid>.showcaseCSG() {
sphere(50){ sphere(50){
detail = 32 detail = 32
} }
color(Colors.teal) color("teal")
opacity = 0.7 opacity = 0.7
} }
} }

View File

@ -16,6 +16,7 @@ import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.css.th
import kotlinx.serialization.SerialName import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient import kotlinx.serialization.Transient
@ -27,18 +28,28 @@ internal data class PropertyListener(
) )
/**
* A full base implementation for a [Vision]
* @param properties Object own properties excluding styles and inheritance
*/
@Serializable @Serializable
@SerialName("vision") @SerialName("vision")
public open class VisionBase : Vision { public open class VisionBase(internal var properties: Config? = null) : Vision {
init {
//used during deserialization only
properties?.onChange(this) { name, oldItem, newItem ->
if (oldItem != newItem) {
scope.launch {
notifyPropertyChanged(name)
}
}
}
}
@Transient @Transient
override var parent: VisionGroup? = null override var parent: VisionGroup? = null
/**
* Object own properties excluding styles and inheritance
*/
internal var properties: Config? = null
override val meta: Meta get() = properties ?: Meta.EMPTY override val meta: Meta get() = properties ?: Meta.EMPTY
@Synchronized @Synchronized

View File

@ -46,6 +46,6 @@ public operator fun ColorAccessor?.invoke(r: UByte, g: UByte, b: UByte) {
this?.value = Colors.rgbToString(r, g, b).asValue() this?.value = Colors.rgbToString(r, g, b).asValue()
} }
public fun ColorAccessor?.clear(){ public fun ColorAccessor?.clear() {
this?.value = null this?.value = null
} }

View File

@ -101,6 +101,7 @@ internal class Prototypes(
) : VisionGroupBase(children as? MutableMap<NameToken, Vision> ?: children.toMutableMap()), PrototypeHolder { ) : VisionGroupBase(children as? MutableMap<NameToken, Vision> ?: children.toMutableMap()), PrototypeHolder {
init { init {
//used during deserialization only
children.values.forEach { children.values.forEach {
it.parent = parent it.parent = parent
} }

View File

@ -19,12 +19,12 @@ public class SolidMaterial : Scheme() {
/** /**
* Primary web-color for the material * Primary web-color for the material
*/ */
public var color: ColorAccessor = ColorAccessor(items, COLOR_KEY) public var color: ColorAccessor = ColorAccessor(this, COLOR_KEY)
/** /**
* Specular color for phong material * Specular color for phong material
*/ */
public var specularColor: ColorAccessor = ColorAccessor(items, SPECULAR_COLOR_KEY) public var specularColor: ColorAccessor = ColorAccessor(this, SPECULAR_COLOR_KEY)
/** /**
* Opacity * Opacity
@ -104,13 +104,7 @@ public var Solid.material: SolidMaterial?
@VisionBuilder @VisionBuilder
public fun Solid.material(builder: SolidMaterial.() -> Unit) { public fun Solid.material(builder: SolidMaterial.() -> Unit) {
setProperty(MATERIAL_KEY, SolidMaterial(builder)) ownProperties.getChild(MATERIAL_KEY).update(SolidMaterial, builder)
// val node = getOwnProperty(MATERIAL_KEY).node
// if (node != null) {
// configure(SolidMaterial(builder).config)
// } else {
// setProperty(MATERIAL_KEY, SolidMaterial(builder))
// }
} }
public var Solid.opacity: Number? public var Solid.opacity: Number?

View File

@ -4,9 +4,9 @@ import hep.dataforge.meta.*
import hep.dataforge.names.Name import hep.dataforge.names.Name
public class Canvas3DOptions : Scheme() { public class Canvas3DOptions : Scheme() {
public var axes: Axes by spec(Axes, Axes.empty()) public var axes: Axes by spec(Axes)
public var camera: Camera by spec(Camera, Camera.empty()) public var camera: Camera by spec(Camera)
public var controls: Controls by spec(Controls, Controls.empty()) public var controls: Controls by spec(Controls)
public var minSize: Int by int(400) public var minSize: Int by int(400)
public var minWith: Number by number { minSize } public var minWith: Number by number { minSize }

View File

@ -0,0 +1,29 @@
package hep.dataforge.vision.solid
import hep.dataforge.vision.Colors
import kotlin.test.Test
import kotlin.test.assertEquals
class CompositeTest {
@Test
fun testCompositeBuilder(){
lateinit var composite: Composite
SolidGroup {
composite = composite(CompositeType.INTERSECT) {
y = 300
box(100, 100, 100) {
z = 50
}
sphere(50) {
detail = 32
}
material {
color("pink")
}
}
}
assertEquals("pink", composite.color.string)
}
}