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.dataforge.context.Context
import space.kscience.gdml.GdmlShowCase import space.kscience.gdml.GdmlShowCase
import space.kscience.visionforge.gdml.toVision import space.kscience.visionforge.gdml.toVision
import space.kscience.visionforge.html.ResourceLocation
import space.kscience.visionforge.solid.Solids import space.kscience.visionforge.solid.Solids
fun main() { fun main() {
@ -10,7 +11,7 @@ fun main() {
plugin(Solids) plugin(Solids)
} }
context.makeVisionFile { context.makeVisionFile( resourceLocation = ResourceLocation.EMBED) {
vision("canvas") { GdmlShowCase.babyIaxo().toVision() } vision("canvas") { GdmlShowCase.babyIaxo().toVision() }
} }
} }

View File

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

View File

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

View File

@ -74,8 +74,13 @@ public class SolidReferenceGroup(
private fun prototypeFor(name: Name): Solid { private fun prototypeFor(name: Name): Solid {
return if (name.isEmpty()) prototype else { 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") ?: 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 class ThreeCanvas(
public val three: ThreePlugin, public val three: ThreePlugin,
public val element: Element,
public val options: Canvas3DOptions = Canvas3DOptions() public val options: Canvas3DOptions = Canvas3DOptions()
) { ) {
private var boundingBox: Box3? = null private var boundingBox: Box3? = null
private var root: Object3D? = null private var root: Object3D? = null
set(value) { 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 * 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 * Resolve full name of the object relative to the global root
*/ */

View File

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