forked from kscience/visionforge
Cleanup vision root rules
This commit is contained in:
parent
eeec89f0e6
commit
34fbb23c60
@ -6,6 +6,7 @@ import space.kscience.dataforge.meta.get
|
||||
import space.kscience.dataforge.meta.int
|
||||
import space.kscience.dataforge.names.Name
|
||||
import space.kscience.dataforge.names.plus
|
||||
import space.kscience.visionforge.MutableVisionContainer
|
||||
import space.kscience.visionforge.isEmpty
|
||||
import space.kscience.visionforge.set
|
||||
import space.kscience.visionforge.solid.*
|
||||
@ -262,7 +263,7 @@ private fun SolidGroup.addShape(
|
||||
val fShape by shape.dObject(::DGeoShape)
|
||||
val fScale by shape.dObject(::DGeoScale)
|
||||
fShape?.let { scaledShape ->
|
||||
group(name?.let { Name.parse(it) }) {
|
||||
solidGroup(name?.let { Name.parse(it) }) {
|
||||
scale = Point3D(fScale?.x ?: 1.0, fScale?.y ?: 1.0, fScale?.z ?: 1.0)
|
||||
addShape(scaledShape, context)
|
||||
apply(block)
|
||||
@ -294,7 +295,7 @@ private fun SolidGroup.addRootNode(obj: DGeoNode, context: RootToSolidContext) {
|
||||
}
|
||||
|
||||
private fun buildVolume(volume: DGeoVolume, context: RootToSolidContext): Solid? {
|
||||
val group = SolidGroup {
|
||||
val group = SolidGroup().apply {
|
||||
//set current layer
|
||||
layer = context.currentLayer
|
||||
val nodes = volume.fNodes
|
||||
@ -372,9 +373,9 @@ private fun SolidGroup.addRootVolume(
|
||||
}
|
||||
}
|
||||
|
||||
public fun DGeoManager.toSolid(): SolidGroup = SolidGroup {
|
||||
public fun MutableVisionContainer<Solid>.rootGeo(dGeoManager: DGeoManager): SolidGroup = solidGroup {
|
||||
val context = RootToSolidContext(this)
|
||||
fNodes.forEach { node ->
|
||||
dGeoManager.fNodes.forEach { node ->
|
||||
addRootNode(node, context)
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ package ru.mipt.npm.root.serialization
|
||||
import space.kscience.dataforge.names.Name
|
||||
import space.kscience.dataforge.names.asName
|
||||
import space.kscience.dataforge.names.plus
|
||||
import space.kscience.visionforge.MutableVisionContainer
|
||||
import space.kscience.visionforge.solid.*
|
||||
import kotlin.math.PI
|
||||
import kotlin.math.atan2
|
||||
@ -132,7 +133,7 @@ private fun buildGroup(volume: TGeoVolume): SolidGroup {
|
||||
return if (volume is TGeoVolumeAssemblyRef) {
|
||||
buildGroup(volume.value)
|
||||
} else {
|
||||
SolidGroup {
|
||||
SolidGroup().apply {
|
||||
volume.fShape?.let { addShape(it) }
|
||||
volume.fNodes?.let {
|
||||
it.arr.forEach { obj ->
|
||||
@ -180,8 +181,8 @@ private fun SolidGroup.volume(volume: TGeoVolume, name: String? = null, cache: B
|
||||
// }
|
||||
|
||||
|
||||
public fun TGeoManager.toSolid(): SolidGroup = SolidGroup {
|
||||
fNodes.arr.forEach {
|
||||
public fun MutableVisionContainer<Solid>.rootGeo(tGeoManager: TGeoManager): SolidGroup = solidGroup {
|
||||
tGeoManager.fNodes.arr.forEach {
|
||||
node(it)
|
||||
}
|
||||
}
|
@ -10,10 +10,7 @@ import org.w3c.files.get
|
||||
import react.Props
|
||||
import react.dom.h2
|
||||
import react.fc
|
||||
import react.useMemo
|
||||
import react.useState
|
||||
import space.kscience.dataforge.context.Context
|
||||
import space.kscience.dataforge.context.fetch
|
||||
import space.kscience.dataforge.names.Name
|
||||
import space.kscience.gdml.Gdml
|
||||
import space.kscience.gdml.decodeFromString
|
||||
@ -31,14 +28,13 @@ import styled.css
|
||||
import styled.styledDiv
|
||||
|
||||
external interface GDMLAppProps : Props {
|
||||
var context: Context
|
||||
var solids: Solids
|
||||
var vision: Solid?
|
||||
var selected: Name?
|
||||
}
|
||||
|
||||
@JsExport
|
||||
val GDMLApp = fc<GDMLAppProps>("GDMLApp") { props ->
|
||||
val visionManager = useMemo(props.context) { props.context.fetch(Solids).visionManager }
|
||||
var deferredVision: Deferred<Solid?> by useState {
|
||||
CompletableDeferred(props.vision)
|
||||
}
|
||||
@ -53,7 +49,7 @@ val GDMLApp = fc<GDMLAppProps>("GDMLApp") { props ->
|
||||
name.endsWith(".gdml") || name.endsWith(".xml") -> {
|
||||
val gdml = Gdml.decodeFromString(data)
|
||||
gdml.toVision().apply {
|
||||
setAsRoot(visionManager)
|
||||
setAsRoot(props.solids.visionManager)
|
||||
console.info("Marking layers for file $name")
|
||||
markLayers()
|
||||
ambientLight {
|
||||
@ -61,7 +57,7 @@ val GDMLApp = fc<GDMLAppProps>("GDMLApp") { props ->
|
||||
}
|
||||
}
|
||||
}
|
||||
name.endsWith(".json") -> visionManager.decodeFromString(data)
|
||||
name.endsWith(".json") -> props.solids.visionManager.decodeFromString(data)
|
||||
else -> {
|
||||
window.alert("File extension is not recognized: $name")
|
||||
error("File extension is not recognized: $name")
|
||||
@ -82,7 +78,7 @@ val GDMLApp = fc<GDMLAppProps>("GDMLApp") { props ->
|
||||
}
|
||||
child(ThreeCanvasWithControls) {
|
||||
attrs {
|
||||
this.context = props.context
|
||||
this.solids = props.solids
|
||||
this.builderOfSolid = deferredVision
|
||||
this.selected = props.selected
|
||||
tab("Load") {
|
||||
|
@ -4,11 +4,13 @@ import kotlinx.browser.document
|
||||
import kotlinx.css.*
|
||||
import react.dom.client.createRoot
|
||||
import space.kscience.dataforge.context.Context
|
||||
import space.kscience.dataforge.context.fetch
|
||||
import space.kscience.gdml.GdmlShowCase
|
||||
import space.kscience.visionforge.Application
|
||||
import space.kscience.visionforge.Colors
|
||||
import space.kscience.visionforge.gdml.toVision
|
||||
import space.kscience.visionforge.react.render
|
||||
import space.kscience.visionforge.solid.Solids
|
||||
import space.kscience.visionforge.solid.ambientLight
|
||||
import space.kscience.visionforge.solid.set
|
||||
import space.kscience.visionforge.solid.three.ThreePlugin
|
||||
@ -52,7 +54,7 @@ private class GDMLDemoApp : Application {
|
||||
}
|
||||
//println(context.plugins.fetch(VisionManager).encodeToString(vision))
|
||||
attrs {
|
||||
this.context = context
|
||||
this.solids = context.fetch(Solids)
|
||||
this.vision = vision
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import react.dom.client.createRoot
|
||||
import ringui.SmartTabs
|
||||
import ringui.Tab
|
||||
import space.kscience.dataforge.context.Context
|
||||
import space.kscience.dataforge.context.fetch
|
||||
import space.kscience.plotly.models.Trace
|
||||
import space.kscience.plotly.scatter
|
||||
import space.kscience.visionforge.Application
|
||||
@ -51,7 +52,7 @@ private class JsPlaygroundApp : Application {
|
||||
Tab("gravity") {
|
||||
GravityDemo {
|
||||
attrs {
|
||||
this.context = playgroundContext
|
||||
this.solids = playgroundContext.fetch(Solids)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -72,7 +73,7 @@ private class JsPlaygroundApp : Application {
|
||||
child(ThreeCanvasWithControls) {
|
||||
val random = Random(112233)
|
||||
attrs {
|
||||
context = playgroundContext
|
||||
solids = playgroundContext.fetch(Solids)
|
||||
solid {
|
||||
ambientLight {
|
||||
color.set(Colors.white)
|
||||
|
@ -4,7 +4,6 @@ import kotlinx.coroutines.launch
|
||||
import kotlinx.css.*
|
||||
import react.Props
|
||||
import react.fc
|
||||
import space.kscience.dataforge.context.Context
|
||||
import space.kscience.plotly.layout
|
||||
import space.kscience.plotly.models.Trace
|
||||
import space.kscience.visionforge.Colors
|
||||
@ -18,7 +17,7 @@ import styled.styledDiv
|
||||
import kotlin.math.sqrt
|
||||
|
||||
external interface DemoProps : Props {
|
||||
var context: Context
|
||||
var solids: Solids
|
||||
}
|
||||
|
||||
val GravityDemo = fc<DemoProps> { props ->
|
||||
@ -40,7 +39,7 @@ val GravityDemo = fc<DemoProps> { props ->
|
||||
}
|
||||
child(ThreeCanvasWithControls) {
|
||||
attrs {
|
||||
context = props.context
|
||||
solids = props.solids
|
||||
solid {
|
||||
pointLight(200, 200, 200, name = "light"){
|
||||
color.set(Colors.white)
|
||||
@ -52,7 +51,7 @@ val GravityDemo = fc<DemoProps> { props ->
|
||||
color.set("red")
|
||||
val h = 100.0
|
||||
y = h
|
||||
context.launch {
|
||||
solids.context.launch {
|
||||
val g = 10.0
|
||||
val dt = 0.1
|
||||
var time = 0.0
|
||||
|
@ -15,7 +15,7 @@ class Model(val manager: VisionManager) {
|
||||
private val events = HashSet<Event>()
|
||||
|
||||
private fun MutableVisionContainer<Solid>.pixel(pixel: SC1) {
|
||||
val group = group(pixel.name) {
|
||||
val group = solidGroup(pixel.name) {
|
||||
position = Point3D(pixel.center.x, pixel.center.y, pixel.center.z)
|
||||
box(pixel.xSize, pixel.ySize, pixel.zSize)
|
||||
label(pixel.name) {
|
||||
@ -27,7 +27,7 @@ class Model(val manager: VisionManager) {
|
||||
}
|
||||
|
||||
private fun SolidGroup.detector(detector: SC16) {
|
||||
group(detector.name) {
|
||||
solidGroup(detector.name) {
|
||||
detector.pixels.forEach {
|
||||
pixel(it)
|
||||
}
|
||||
@ -42,24 +42,24 @@ class Model(val manager: VisionManager) {
|
||||
color.set("darkgreen")
|
||||
}
|
||||
rotationX = PI / 2
|
||||
group("bottom") {
|
||||
solidGroup("bottom") {
|
||||
Monitor.detectors.filter { it.center.z == LOWER_LAYER_Z }.forEach {
|
||||
detector(it)
|
||||
}
|
||||
}
|
||||
|
||||
group("middle") {
|
||||
solidGroup("middle") {
|
||||
Monitor.detectors.filter { it.center.z == CENTRAL_LAYER_Z }.forEach {
|
||||
detector(it)
|
||||
}
|
||||
}
|
||||
|
||||
group("top") {
|
||||
solidGroup("top") {
|
||||
Monitor.detectors.filter { it.center.z == UPPER_LAYER_Z }.forEach {
|
||||
detector(it)
|
||||
}
|
||||
}
|
||||
tracks = group("tracks")
|
||||
tracks = solidGroup("tracks")
|
||||
}
|
||||
|
||||
private fun highlight(pixel: String) {
|
||||
|
@ -49,7 +49,7 @@ fun main() {
|
||||
}
|
||||
|
||||
vision("form") { form }
|
||||
form.onPropertyChange { _, _ ->
|
||||
form.onPropertyChange {
|
||||
println(this)
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package space.kscience.visionforge.examples
|
||||
|
||||
import ru.mipt.npm.root.DGeoManager
|
||||
import ru.mipt.npm.root.rootGeo
|
||||
import ru.mipt.npm.root.serialization.TGeoManager
|
||||
import ru.mipt.npm.root.toSolid
|
||||
import space.kscience.dataforge.meta.Meta
|
||||
import space.kscience.dataforge.meta.get
|
||||
import space.kscience.dataforge.meta.isLeaf
|
||||
@ -34,7 +34,7 @@ fun main() {
|
||||
println(it)
|
||||
}
|
||||
|
||||
val solid = geo.toSolid()
|
||||
val solid = Solids.rootGeo(geo)
|
||||
|
||||
Paths.get("BM@N.vf.json").writeText(Solids.encodeToString(solid))
|
||||
//println(Solids.encodeToString(solid))
|
||||
|
@ -15,7 +15,7 @@ group = "ru.mipt.npm"
|
||||
|
||||
dependencies{
|
||||
implementation(project(":visionforge-threejs:visionforge-threejs-server"))
|
||||
implementation("ch.qos.logback:logback-classic:1.2.3")
|
||||
implementation("ch.qos.logback:logback-classic:1.2.11")
|
||||
}
|
||||
|
||||
application {
|
||||
|
@ -6,7 +6,7 @@ import space.kscience.visionforge.style
|
||||
import space.kscience.visionforge.useStyle
|
||||
import kotlin.math.PI
|
||||
|
||||
internal fun visionOfSatellite(
|
||||
internal fun Solids.visionOfSatellite(
|
||||
layers: Int = 10,
|
||||
layerHeight: Number = 10,
|
||||
xSegments: Int = 3,
|
||||
@ -14,7 +14,7 @@ internal fun visionOfSatellite(
|
||||
xSegmentSize: Number = 30,
|
||||
ySegmentSize: Number = xSegmentSize,
|
||||
fiberDiameter: Number = 1.0,
|
||||
): SolidGroup = SolidGroup {
|
||||
): SolidGroup = solidGroup {
|
||||
color.set("darkgreen")
|
||||
val transparent by style {
|
||||
this[SolidMaterial.MATERIAL_OPACITY_KEY] = 0.3
|
||||
@ -31,7 +31,7 @@ internal fun visionOfSatellite(
|
||||
val totalXSize = xSegments * xSegmentSize.toDouble()
|
||||
val totalYSize = ySegments * ySegmentSize.toDouble()
|
||||
for (layer in 1..layers) {
|
||||
group("layer[$layer]") {
|
||||
solidGroup("layer[$layer]") {
|
||||
for (i in 1..xSegments) {
|
||||
for (j in 1..ySegments) {
|
||||
box(xSegmentSize, ySegmentSize, layerHeight, name = "segment[$i,$j]") {
|
||||
@ -42,7 +42,7 @@ internal fun visionOfSatellite(
|
||||
}
|
||||
}
|
||||
}
|
||||
group("fibers") {
|
||||
solidGroup("fibers") {
|
||||
for (i in 1..xSegments) {
|
||||
cylinder(fiberDiameter, totalYSize) {
|
||||
useStyle(red)
|
||||
|
@ -5,6 +5,8 @@ import kotlinx.coroutines.*
|
||||
import kotlinx.html.div
|
||||
import kotlinx.html.h1
|
||||
import space.kscience.dataforge.context.Context
|
||||
import space.kscience.dataforge.context.fetch
|
||||
import space.kscience.dataforge.misc.DFExperimental
|
||||
import space.kscience.dataforge.names.Name
|
||||
import space.kscience.visionforge.html.Page
|
||||
import space.kscience.visionforge.html.plus
|
||||
@ -17,13 +19,16 @@ import space.kscience.visionforge.visionManager
|
||||
import kotlin.random.Random
|
||||
|
||||
|
||||
@OptIn(DFExperimental::class)
|
||||
fun main() {
|
||||
val satContext = Context("sat") {
|
||||
plugin(Solids)
|
||||
}
|
||||
|
||||
val solids = satContext.fetch(Solids)
|
||||
|
||||
//Create a geometry
|
||||
val sat = visionOfSatellite(ySegments = 3)
|
||||
val sat = solids.visionOfSatellite(ySegments = 3)
|
||||
|
||||
val server = satContext.visionManager.serve {
|
||||
page(header = Page.threeJsHeader + Page.styleSheetHeader("css/styles.css")) {
|
||||
|
@ -5,7 +5,6 @@ import space.kscience.dataforge.meta.Meta
|
||||
import space.kscience.dataforge.meta.invoke
|
||||
import space.kscience.dataforge.names.Name
|
||||
import space.kscience.visionforge.Colors
|
||||
import space.kscience.visionforge.setAsRoot
|
||||
import space.kscience.visionforge.solid.*
|
||||
import space.kscience.visionforge.solid.specifications.Canvas3DOptions
|
||||
import space.kscience.visionforge.visible
|
||||
@ -19,11 +18,11 @@ fun VisionLayout<Solid>.demo(name: String, title: String = name, block: SolidGro
|
||||
val meta = Meta {
|
||||
"title" put title
|
||||
}
|
||||
val vision = SolidGroup(block).apply {
|
||||
val vision = solids.solidGroup {
|
||||
block()
|
||||
ambientLight{
|
||||
color.set(Colors.white)
|
||||
}
|
||||
setAsRoot(solids.visionManager)
|
||||
}
|
||||
render(Name.parse(name), vision, meta)
|
||||
}
|
||||
@ -69,7 +68,7 @@ fun VisionLayout<Solid>.showcase() {
|
||||
}
|
||||
|
||||
demo("dynamic", "Dynamic properties") {
|
||||
val group = group {
|
||||
val group = solidGroup {
|
||||
box(100, 100, 100) {
|
||||
z = 110.0
|
||||
opacity = 0.5
|
||||
@ -101,7 +100,7 @@ fun VisionLayout<Solid>.showcase() {
|
||||
|
||||
demo("rotation", "Rotations") {
|
||||
box(100, 100, 100)
|
||||
group {
|
||||
solidGroup {
|
||||
x = 200
|
||||
rotationY = PI / 4
|
||||
box(100, 100, 100) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
kotlin.code.style=official
|
||||
kotlin.mpp.stability.nowarn=true
|
||||
kotlin.jupyter.add.scanner=false
|
||||
#kotlin.incremental.js.ir=true
|
||||
kotlin.incremental.js.ir=true
|
||||
|
||||
org.gradle.parallel=true
|
||||
org.gradle.jvmargs=-Xmx4G
|
||||
|
@ -10,7 +10,6 @@ import react.dom.div
|
||||
import react.dom.p
|
||||
import react.dom.span
|
||||
import ringui.*
|
||||
import space.kscience.dataforge.context.Context
|
||||
import space.kscience.dataforge.meta.get
|
||||
import space.kscience.dataforge.names.Name
|
||||
import space.kscience.dataforge.names.NameToken
|
||||
@ -20,21 +19,25 @@ import space.kscience.visionforge.*
|
||||
import space.kscience.visionforge.react.*
|
||||
import space.kscience.visionforge.solid.Solid
|
||||
import space.kscience.visionforge.solid.SolidGroup
|
||||
import space.kscience.visionforge.solid.Solids
|
||||
import space.kscience.visionforge.solid.solidGroup
|
||||
import space.kscience.visionforge.solid.specifications.Canvas3DOptions
|
||||
import styled.css
|
||||
import styled.styledDiv
|
||||
|
||||
public external interface ThreeCanvasWithControlsProps : Props {
|
||||
public var context: Context
|
||||
public var solids: Solids
|
||||
public var builderOfSolid: Deferred<Solid?>
|
||||
public var selected: Name?
|
||||
public var options: Canvas3DOptions?
|
||||
public var additionalTabs: Map<String, RBuilder.() -> Unit>?
|
||||
}
|
||||
|
||||
private val ThreeCanvasWithControlsProps.context get() = solids.context
|
||||
|
||||
public fun ThreeCanvasWithControlsProps.solid(block: SolidGroup.() -> Unit) {
|
||||
builderOfSolid = context.async {
|
||||
SolidGroup(block)
|
||||
solids.solidGroup(null, block)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ public class ThreeWithControlsPlugin : AbstractPlugin(), ElementVisionRenderer {
|
||||
createRoot(element).render {
|
||||
child(ThreeCanvasWithControls) {
|
||||
attrs {
|
||||
this.context = this@ThreeWithControlsPlugin.context
|
||||
this.solids = three.solids
|
||||
this.builderOfSolid = context.async { vision as Solid}
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import space.kscience.dataforge.meta.descriptors.MetaDescriptor
|
||||
import space.kscience.dataforge.meta.descriptors.value
|
||||
import space.kscience.dataforge.names.Name
|
||||
import space.kscience.dataforge.names.NameToken
|
||||
import space.kscience.dataforge.names.parseAsName
|
||||
import space.kscience.dataforge.names.plus
|
||||
import space.kscience.visionforge.Vision.Companion.STYLE_KEY
|
||||
|
||||
@ -95,19 +96,19 @@ public class SimpleVisionGroup : AbstractVisionGroup(), MutableVisionContainer<V
|
||||
}
|
||||
|
||||
@VisionBuilder
|
||||
public fun MutableVisionContainer<Vision>.group(
|
||||
public inline fun MutableVisionContainer<Vision>.group(
|
||||
name: Name? = null,
|
||||
builder: SimpleVisionGroup.() -> Unit = {},
|
||||
): SimpleVisionGroup = SimpleVisionGroup().apply(builder).also { setChild(name, it) }
|
||||
): SimpleVisionGroup = SimpleVisionGroup().also { setChild(name, it) }.apply(builder)
|
||||
|
||||
/**
|
||||
* Define a group with given [name], attach it to this parent and return it.
|
||||
*/
|
||||
@VisionBuilder
|
||||
public fun MutableVisionContainer<Vision>.group(
|
||||
public inline fun MutableVisionContainer<Vision>.group(
|
||||
name: String,
|
||||
builder: SimpleVisionGroup.() -> Unit = {},
|
||||
): SimpleVisionGroup = SimpleVisionGroup().apply(builder).also { setChild(name, it) }
|
||||
): SimpleVisionGroup = group(name.parseAsName(), builder)
|
||||
|
||||
//fun VisualObject.findStyle(styleName: Name): Meta? {
|
||||
// if (this is VisualGroup) {
|
||||
|
@ -65,6 +65,7 @@ public class VisionClient : AbstractPlugin() {
|
||||
|
||||
private fun renderVision(name: String, element: Element, vision: Vision?, outputMeta: Meta) {
|
||||
if (vision != null) {
|
||||
vision.setAsRoot(visionManager)
|
||||
val renderer = findRendererFor(vision)
|
||||
?: error("Could not find renderer for ${visionManager.encodeToString(vision)}")
|
||||
renderer.render(element, vision, outputMeta)
|
||||
|
@ -29,7 +29,7 @@ private class GdmlLoader(val settings: GdmlLoaderOptions) {
|
||||
*/
|
||||
private val proto = SolidGroup()
|
||||
|
||||
private val solids = proto.group(solidsName) {
|
||||
private val solids = proto.solidGroup(solidsName) {
|
||||
properties["edges.enabled"] = false
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ public inline fun MutableVisionContainer<Solid>.composite(
|
||||
name: String? = null,
|
||||
@VisionBuilder builder: SolidGroup.() -> Unit,
|
||||
): Composite {
|
||||
val group = SolidGroup(builder)
|
||||
val group = SolidGroup().apply(builder)
|
||||
val children = group.items.values.toList()
|
||||
if (children.size != 2) {
|
||||
error("Composite requires exactly two children, but found ${children.size}")
|
||||
@ -48,7 +48,7 @@ public fun SolidGroup.smartComposite(
|
||||
name: String? = null,
|
||||
@VisionBuilder builder: SolidGroup.() -> Unit,
|
||||
): Solid = if (type == CompositeType.GROUP) {
|
||||
val group = SolidGroup(builder)
|
||||
val group = SolidGroup().apply(builder)
|
||||
if (name == null && group.properties.own == null) {
|
||||
//append directly to group if no properties are defined
|
||||
group.items.forEach { (_, value) ->
|
||||
|
@ -5,6 +5,7 @@ import kotlinx.serialization.Serializable
|
||||
import space.kscience.dataforge.meta.descriptors.MetaDescriptor
|
||||
import space.kscience.dataforge.names.Name
|
||||
import space.kscience.dataforge.names.NameToken
|
||||
import space.kscience.dataforge.names.parseAsName
|
||||
import space.kscience.visionforge.*
|
||||
|
||||
|
||||
@ -30,7 +31,8 @@ public interface PrototypeHolder {
|
||||
*/
|
||||
@Serializable
|
||||
@SerialName("group.solid")
|
||||
public class SolidGroup : AbstractVisionGroup(), Solid, PrototypeHolder, MutableVisionGroup, MutableVisionContainer<Solid> {
|
||||
public class SolidGroup : AbstractVisionGroup(), Solid, PrototypeHolder, MutableVisionGroup,
|
||||
MutableVisionContainer<Solid> {
|
||||
|
||||
public val items: Map<NameToken, Solid>
|
||||
get() = children.keys.mapNotNull {
|
||||
@ -79,19 +81,18 @@ public class SolidGroup : AbstractVisionGroup(), Solid, PrototypeHolder, Mutable
|
||||
}
|
||||
}
|
||||
|
||||
public inline fun SolidGroup(block: SolidGroup.() -> Unit): SolidGroup = SolidGroup().apply(block)
|
||||
|
||||
@VisionBuilder
|
||||
public fun MutableVisionContainer<Solid>.group(
|
||||
public inline fun MutableVisionContainer<Solid>.solidGroup(
|
||||
name: Name? = null,
|
||||
builder: SolidGroup.() -> Unit = {},
|
||||
): SolidGroup = SolidGroup(builder).also { setChild(name, it) }
|
||||
): SolidGroup = SolidGroup().also { setChild(name, it) }.apply(builder)
|
||||
//root first, update later
|
||||
|
||||
/**
|
||||
* Define a group with given [name], attach it to this parent and return it.
|
||||
*/
|
||||
@VisionBuilder
|
||||
public fun MutableVisionContainer<Solid>.group(
|
||||
public inline fun MutableVisionContainer<Solid>.solidGroup(
|
||||
name: String,
|
||||
action: SolidGroup.() -> Unit = {},
|
||||
): SolidGroup = SolidGroup(action).also { setChild(name, it) }
|
||||
): SolidGroup = solidGroup(name.parseAsName(), action)
|
||||
|
@ -71,24 +71,30 @@ public class SolidReference(
|
||||
}
|
||||
}.distinct().asValue()
|
||||
}
|
||||
//1. resolve own properties
|
||||
properties?.getValue(name)?.let { return it }
|
||||
|
||||
val descriptor = descriptor?.get(name)
|
||||
val inheritFlag = inherit ?: descriptor?.inherited ?: false
|
||||
val stylesFlag = includeStyles ?: descriptor?.usesStyles ?: true
|
||||
|
||||
if (stylesFlag) {
|
||||
getStyleProperty(name)?.value?.let { return it }
|
||||
}
|
||||
|
||||
if (inheritFlag) {
|
||||
parent?.properties?.getValue(name, inherit, includeStyles)?.let { return it }
|
||||
}
|
||||
|
||||
//2. Resolve prototype onw properties
|
||||
prototype.properties.getValue(name, inheritFlag, stylesFlag)?.let { return it }
|
||||
|
||||
if (stylesFlag) {
|
||||
//3. own styles
|
||||
own?.getValue(Vision.STYLE_KEY)?.list?.forEach { styleName ->
|
||||
getStyle(styleName.string)?.getValue(name)?.let { return it }
|
||||
}
|
||||
//4. prototype styles
|
||||
prototype.getStyleProperty(name)?.value?.let { return it }
|
||||
}
|
||||
|
||||
if(inheritFlag){
|
||||
//5. own inheritance
|
||||
parent?.properties?.getValue(name, inheritFlag, includeStyles)?.let { return it }
|
||||
//6. prototype inheritance
|
||||
prototype.parent?.properties?.getValue(name, inheritFlag, includeStyles)?.let { return it }
|
||||
}
|
||||
|
||||
return null
|
||||
|
@ -10,22 +10,34 @@ import kotlinx.serialization.serializer
|
||||
import space.kscience.dataforge.context.Context
|
||||
import space.kscience.dataforge.context.PluginFactory
|
||||
import space.kscience.dataforge.context.PluginTag
|
||||
import space.kscience.dataforge.context.fetch
|
||||
import space.kscience.dataforge.meta.Meta
|
||||
import space.kscience.dataforge.misc.DFExperimental
|
||||
import space.kscience.dataforge.names.Name
|
||||
import space.kscience.visionforge.*
|
||||
import space.kscience.visionforge.html.VisionOutput
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
|
||||
public class Solids(meta: Meta) : VisionPlugin(meta) {
|
||||
public class Solids(meta: Meta) : VisionPlugin(meta), MutableVisionContainer<Solid> {
|
||||
override val tag: PluginTag get() = Companion.tag
|
||||
|
||||
override val visionSerializersModule: SerializersModule get() = serializersModuleForSolids
|
||||
|
||||
public companion object : PluginFactory<Solids> {
|
||||
override fun setChild(name: Name?, child: Solid?) {
|
||||
child?.setAsRoot(visionManager)
|
||||
}
|
||||
|
||||
public companion object : PluginFactory<Solids>, MutableVisionContainer<Solid> {
|
||||
override val tag: PluginTag = PluginTag(name = "vision.solid", group = PluginTag.DATAFORGE_GROUP)
|
||||
override val type: KClass<out Solids> = Solids::class
|
||||
|
||||
public val default: Solids by lazy {
|
||||
Context("@Solids"){
|
||||
plugin(Solids)
|
||||
}.fetch(Solids)
|
||||
}
|
||||
|
||||
override fun build(context: Context, meta: Meta): Solids = Solids(meta)
|
||||
|
||||
private fun PolymorphicModuleBuilder<Solid>.solids() {
|
||||
@ -68,6 +80,10 @@ public class Solids(meta: Meta) : VisionPlugin(meta) {
|
||||
|
||||
public fun decodeFromString(str: String): Solid =
|
||||
jsonForSolids.decodeFromString(PolymorphicSerializer(Solid::class), str)
|
||||
|
||||
override fun setChild(name: Name?, child: Solid?) {
|
||||
default.setChild(name, child)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ class CompositeTest {
|
||||
@Test
|
||||
fun testCompositeBuilder(){
|
||||
lateinit var composite: Composite
|
||||
SolidGroup {
|
||||
Solids.solidGroup {
|
||||
composite = composite(CompositeType.INTERSECT) {
|
||||
y = 300
|
||||
box(100, 100, 100) {
|
||||
|
@ -11,7 +11,7 @@ class ConvexTest {
|
||||
@Suppress("UNUSED_VARIABLE")
|
||||
@Test
|
||||
fun testConvexBuilder() {
|
||||
val group = SolidGroup{
|
||||
val group = Solids.solidGroup {
|
||||
convex {
|
||||
point(50, 50, -50)
|
||||
point(50, -50, -50)
|
||||
|
@ -9,7 +9,7 @@ import kotlin.test.assertEquals
|
||||
class GroupTest {
|
||||
@Test
|
||||
fun testGroupWithComposite() {
|
||||
val group = SolidGroup{
|
||||
val group = Solids.solidGroup{
|
||||
union("union") {
|
||||
box(100, 100, 100) {
|
||||
z = 100
|
||||
|
@ -41,7 +41,7 @@ class SerializationTest {
|
||||
x = 100
|
||||
z = -100
|
||||
}
|
||||
val group = SolidGroup {
|
||||
val group = Solids.solidGroup {
|
||||
newRef("cube", cube)
|
||||
refGroup("pg", Name.parse("pg.content")) {
|
||||
sphere(50) {
|
||||
@ -57,7 +57,7 @@ class SerializationTest {
|
||||
|
||||
@Test
|
||||
fun lightSerialization(){
|
||||
val group = SolidGroup {
|
||||
val group = Solids.solidGroup {
|
||||
ambientLight {
|
||||
color.set(Colors.white)
|
||||
intensity = 100.0
|
||||
|
@ -8,7 +8,7 @@ import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class SolidPluginTest {
|
||||
val vision = SolidGroup {
|
||||
val vision = Solids.solidGroup {
|
||||
box(100, 100, 100, name = "aBox")
|
||||
|
||||
sphere(100, name = "aSphere") {
|
||||
|
@ -52,7 +52,7 @@ class SolidPropertyTest {
|
||||
var box: Box? = null
|
||||
val group = SolidGroup().apply {
|
||||
properties["test"] = 22
|
||||
group {
|
||||
solidGroup {
|
||||
box = box(100, 100, 100)
|
||||
}
|
||||
}
|
||||
@ -62,13 +62,13 @@ class SolidPropertyTest {
|
||||
@Test
|
||||
fun testStyleProperty() {
|
||||
var box: Box? = null
|
||||
val group = SolidGroup {
|
||||
val group = Solids.solidGroup {
|
||||
styleSheet {
|
||||
update("testStyle") {
|
||||
"test" put 22
|
||||
}
|
||||
}
|
||||
group {
|
||||
solidGroup {
|
||||
box = box(100, 100, 100) {
|
||||
useStyle("testStyle")
|
||||
}
|
||||
@ -86,7 +86,7 @@ class SolidPropertyTest {
|
||||
SolidMaterial.MATERIAL_COLOR_KEY put "#555555"
|
||||
}
|
||||
}
|
||||
group {
|
||||
solidGroup {
|
||||
box = box(100, 100, 100) {
|
||||
useStyle("testStyle")
|
||||
}
|
||||
@ -98,7 +98,7 @@ class SolidPropertyTest {
|
||||
@Test
|
||||
fun testReferenceStyleProperty() {
|
||||
var box: SolidReference? = null
|
||||
val group = SolidGroup {
|
||||
val group = Solids.solidGroup {
|
||||
styleSheet {
|
||||
update("testStyle") {
|
||||
SolidMaterial.MATERIAL_COLOR_KEY put "#555555"
|
||||
@ -109,7 +109,7 @@ class SolidPropertyTest {
|
||||
styles = listOf("testStyle")
|
||||
}
|
||||
}
|
||||
group {
|
||||
solidGroup {
|
||||
box = ref("box".asName())
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import kotlin.test.assertEquals
|
||||
|
||||
@DFExperimental
|
||||
class SolidReferenceTest {
|
||||
val groupWithReference = SolidGroup {
|
||||
val groupWithReference = Solids.solidGroup {
|
||||
val theStyle by style {
|
||||
SolidMaterial.MATERIAL_COLOR_KEY put "red"
|
||||
}
|
||||
|
@ -17,11 +17,11 @@ internal class VisionUpdateTest {
|
||||
|
||||
@Test
|
||||
fun testVisionUpdate(){
|
||||
val targetVision = SolidGroup {
|
||||
val targetVision = Solids.solidGroup {
|
||||
box(200,200,200, name = "origin")
|
||||
}
|
||||
val dif = visionManager.VisionChange{
|
||||
group ("top") {
|
||||
solidGroup ("top") {
|
||||
color.set(123)
|
||||
box(100,100,100)
|
||||
}
|
||||
@ -37,7 +37,7 @@ internal class VisionUpdateTest {
|
||||
@Test
|
||||
fun testVisionChangeSerialization(){
|
||||
val change = visionManager.VisionChange{
|
||||
group("top") {
|
||||
solidGroup("top") {
|
||||
color.set(123)
|
||||
box(100,100,100)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user