Fix reference child bug

This commit is contained in:
Alexander Nozik 2021-06-06 22:42:50 +03:00
parent 288307eaa8
commit bd1f7d75fc
7 changed files with 29 additions and 14 deletions

View File

@ -109,7 +109,7 @@ val GDMLApp = functionalComponent<GDMLAppProps>("GDMLApp") { props ->
}
}
}
ringThreeControls(options, props.vision, selected, onSelect)
ringThreeControls(options, vision, selected, onSelect)
}
}
}

View File

@ -3,6 +3,7 @@ package space.kscience.visionforge.examples
import space.kscience.dataforge.context.Context
import space.kscience.gdml.GdmlShowCase
import space.kscience.visionforge.gdml.toVision
import space.kscience.visionforge.html.ResourceLocation
import space.kscience.visionforge.solid.Solids
fun main() {
@ -10,7 +11,7 @@ fun main() {
plugin(Solids)
}
context.makeVisionFile {
context.makeVisionFile( resourceLocation = ResourceLocation.EMBED) {
vision("canvas") { GdmlShowCase.babyIaxo().toVision() }
}
}

View File

@ -14,14 +14,14 @@ import space.kscience.visionforge.solid.specifications.Canvas3DOptions
import styled.css
import styled.styledDiv
public external interface ThreeWithControlsProps : RProps {
public external interface ThreeViewWithControlsProps : RProps {
public var context: Context
public var vision: Vision?
public var selected: Name?
}
@JsExport
public val ThreeViewWithControls: (props: ThreeWithControlsProps) -> dynamic =
public val ThreeViewWithControls: (props: ThreeViewWithControlsProps) -> dynamic =
functionalComponent("ThreeViewWithControls") { props ->
var selected by useState { props.selected }
val onSelect: (Name?) -> Unit = {
@ -36,6 +36,8 @@ public val ThreeViewWithControls: (props: ThreeWithControlsProps) -> dynamic =
styledDiv {
css {
height = 100.pct
maxHeight = 100.vh
maxWidth = 100.vw
}
ringGrid {
ringRow {

View File

@ -12,11 +12,14 @@ import space.kscience.visionforge.Vision
import space.kscience.visionforge.VisionManager
import kotlin.collections.set
@DslMarker
public annotation class VisionDSL
/**
* A placeholder object to attach inline vision builders.
*/
@DFExperimental
@VisionDSL
public class VisionOutput @PublishedApi internal constructor(public val manager: VisionManager) {
public var meta: Meta = Meta.EMPTY
@ -30,6 +33,7 @@ public class VisionOutput @PublishedApi internal constructor(public val manager:
/**
* Modified [TagConsumer] that allows rendering output fragments and visions in them
*/
@VisionDSL
public abstract class VisionTagConsumer<R>(
private val root: TagConsumer<R>,
public val manager:VisionManager,
@ -86,6 +90,7 @@ public abstract class VisionTagConsumer<R>(
* TODO to be replaced by multi-receiver
*/
@OptIn(DFExperimental::class)
@VisionDSL
public inline fun <T> TagConsumer<T>.vision(
name: String = DEFAULT_VISION_NAME,
visionProvider: VisionOutput.() -> Vision,

View File

@ -74,8 +74,13 @@ public class SolidReferenceGroup(
private fun prototypeFor(name: Name): Solid {
return if (name.isEmpty()) prototype else {
(prototype as? SolidGroup)?.get(name) as? Solid
val proto = (prototype as? SolidGroup)?.get(name)
?: error("Prototype with name $name not found in SolidReferenceGroup $refName")
when (proto) {
is Solid -> proto
is SolidReference -> proto.prototype
else -> error("Prototype with name $name is ${proto::class} but expected Solid")
}
}
}

View File

@ -39,8 +39,11 @@ import kotlin.math.sin
*/
public class ThreeCanvas(
public val three: ThreePlugin,
public val element: Element,
public val options: Canvas3DOptions = Canvas3DOptions()
) {
private var boundingBox: Box3? = null
private var root: Object3D? = null
set(value) {
@ -136,6 +139,13 @@ public class ThreeCanvas(
}
}
init {
check(element.getElementsByClassName("three-canvas").length == 0) {
"Three canvas already created in this element"
}
element.appendChild(canvas)
updateSize()
}
/**
* Force camera aspect ration and renderer size recalculation
@ -191,12 +201,6 @@ public class ThreeCanvas(
}
}
internal fun attach(element: Element) {
check(element.getElementsByClassName("three-canvas").length == 0) { "Three canvas already created in this element" }
element.appendChild(canvas)
updateSize()
}
/**
* Resolve full name of the object relative to the global root
*/

View File

@ -118,9 +118,7 @@ public class ThreePlugin : AbstractPlugin(), ElementVisionRenderer {
element: Element,
options: Canvas3DOptions = Canvas3DOptions(),
): ThreeCanvas = canvasCache.getOrPut(element) {
ThreeCanvas(this, options).apply {
attach(element)
}
ThreeCanvas(this, element, options)
}
override fun content(target: String): Map<Name, Any> {