diff --git a/.gitignore b/.gitignore index 44f45e0e..6d07da58 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,3 @@ data/ !gradle-wrapper.jar /kotlin-js-store/yarn.lock -. diff --git a/build.gradle.kts b/build.gradle.kts index 62623756..8cedd918 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,3 +1,4 @@ +import org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile import space.kscience.gradle.isInDevelopment import space.kscience.gradle.useApache2Licence import space.kscience.gradle.useSPCTeam @@ -30,6 +31,12 @@ subprojects { freeCompilerArgs = freeCompilerArgs + "-Xcontext-receivers" } } + + tasks.withType{ + kotlinOptions{ + useEsClasses = true + } + } } ksciencePublish { diff --git a/cern-root-loader/src/commonMain/kotlin/ru/mipt/npm/root/dRootToSolid.kt b/cern-root-loader/src/commonMain/kotlin/ru/mipt/npm/root/dRootToSolid.kt index af185db3..8015aea6 100644 --- a/cern-root-loader/src/commonMain/kotlin/ru/mipt/npm/root/dRootToSolid.kt +++ b/cern-root-loader/src/commonMain/kotlin/ru/mipt/npm/root/dRootToSolid.kt @@ -1,10 +1,8 @@ package ru.mipt.npm.root -import space.kscience.dataforge.meta.double -import space.kscience.dataforge.meta.doubleArray -import space.kscience.dataforge.meta.get -import space.kscience.dataforge.meta.int +import space.kscience.dataforge.meta.* import space.kscience.dataforge.names.Name +import space.kscience.dataforge.names.parseAsName import space.kscience.dataforge.names.plus import space.kscience.visionforge.MutableVisionContainer import space.kscience.visionforge.isEmpty @@ -25,6 +23,8 @@ private data class RootToSolidContext( val prototypeHolder: PrototypeHolder, val currentLayer: Int = 0, val maxLayer: Int = 5, + val ignoreRootColors: Boolean = false, + val colorCache: MutableMap = mutableMapOf(), ) // converting to XYZ to Tait–Bryan angles according to https://en.wikipedia.org/wiki/Euler_angles#Rotation_matrix @@ -300,7 +300,7 @@ private fun buildVolume(volume: DGeoVolume, context: RootToSolidContext): Solid? layer = context.currentLayer val nodes = volume.fNodes - if (nodes.isEmpty() || context.currentLayer >= context.maxLayer) { + if (volume.typename != "TGeoVolumeAssembly" && (nodes.isEmpty() || context.currentLayer >= context.maxLayer)) { //TODO add smart filter volume.fShape?.let { shape -> addShape(shape, context) @@ -326,6 +326,16 @@ private fun buildVolume(volume: DGeoVolume, context: RootToSolidContext): Solid? group.items.values.first().apply { parent = null } } else { group + }.apply { + volume.fMedium?.let { medium -> + color.set(context.colorCache.getOrPut(medium.meta) { RootColors[11 + context.colorCache.size] }) + } + + if (!context.ignoreRootColors) { + volume.fFillColor?.let { + properties[MATERIAL_COLOR_KEY] = RootColors[it] + } + } } } @@ -338,6 +348,7 @@ private fun SolidGroup.addRootVolume( cache: Boolean = true, block: Solid.() -> Unit = {}, ) { + val combinedName = if (volume.fName.isEmpty()) { name } else if (name == null) { @@ -347,12 +358,7 @@ private fun SolidGroup.addRootVolume( } if (!cache) { - val group = buildVolume(volume, context)?.apply { - volume.fFillColor?.let { - properties[MATERIAL_COLOR_KEY] = RootColors[it] - } - block() - } + val group = buildVolume(volume, context)?.apply(block) setChild(combinedName?.let { Name.parse(it) }, group) } else { val templateName = volumesName + volume.name @@ -364,17 +370,17 @@ private fun SolidGroup.addRootVolume( } } - ref(templateName, name).apply { - volume.fFillColor?.let { - properties[MATERIAL_COLOR_KEY] = RootColors[it] - } - block() - } + ref(templateName, name).apply(block) } } -public fun MutableVisionContainer.rootGeo(dGeoManager: DGeoManager): SolidGroup = solidGroup { - val context = RootToSolidContext(this) +public fun MutableVisionContainer.rootGeo( + dGeoManager: DGeoManager, + name: String? = null, + maxLayer: Int = 5, + ignoreRootColors: Boolean = false, +): SolidGroup = solidGroup(name = name?.parseAsName()) { + val context = RootToSolidContext(this, maxLayer = maxLayer, ignoreRootColors = ignoreRootColors) dGeoManager.fNodes.forEach { node -> addRootNode(node, context) } diff --git a/cern-root-loader/src/commonMain/kotlin/ru/mipt/npm/root/rootColor.kt b/cern-root-loader/src/commonMain/kotlin/ru/mipt/npm/root/rootColor.kt index 9ea9c040..9f06125e 100644 --- a/cern-root-loader/src/commonMain/kotlin/ru/mipt/npm/root/rootColor.kt +++ b/cern-root-loader/src/commonMain/kotlin/ru/mipt/npm/root/rootColor.kt @@ -1,7 +1,7 @@ package ru.mipt.npm.root public object RootColors { - private val colorMap = Array(924) { "white" } + private val colorMap = MutableList(924) { "white" } //colorMap[110] = "white" diff --git a/demo/muon-monitor/src/jvmMain/kotlin/ru/mipt/npm/muon/monitor/MMServer.kt b/demo/muon-monitor/src/jvmMain/kotlin/ru/mipt/npm/muon/monitor/MMServer.kt index aa533431..b9b8ce4c 100644 --- a/demo/muon-monitor/src/jvmMain/kotlin/ru/mipt/npm/muon/monitor/MMServer.kt +++ b/demo/muon-monitor/src/jvmMain/kotlin/ru/mipt/npm/muon/monitor/MMServer.kt @@ -23,7 +23,7 @@ import ru.mipt.npm.muon.monitor.sim.Cos2TrackGenerator import ru.mipt.npm.muon.monitor.sim.simulateOne import space.kscience.dataforge.context.Context import space.kscience.dataforge.context.Global -import space.kscience.dataforge.context.fetch +import space.kscience.dataforge.context.request import space.kscience.dataforge.misc.DFExperimental import space.kscience.visionforge.solid.Solids import java.awt.Desktop @@ -36,7 +36,7 @@ private val generator = Cos2TrackGenerator(JDKRandomGenerator(223)) fun Application.module(context: Context = Global) { val currentDir = File(".").absoluteFile environment.log.info("Current directory: $currentDir") - val solidManager = context.fetch(Solids) + val solidManager = context.request(Solids) install(ContentNegotiation) { json() diff --git a/demo/playground/src/jvmMain/kotlin/rootParser.kt b/demo/playground/src/jvmMain/kotlin/rootParser.kt index 1a4330f4..be70faf8 100644 --- a/demo/playground/src/jvmMain/kotlin/rootParser.kt +++ b/demo/playground/src/jvmMain/kotlin/rootParser.kt @@ -7,9 +7,14 @@ import space.kscience.dataforge.meta.Meta import space.kscience.dataforge.meta.get import space.kscience.dataforge.meta.isLeaf import space.kscience.dataforge.meta.string +import space.kscience.visionforge.Colors +import space.kscience.visionforge.html.ResourceLocation import space.kscience.visionforge.solid.Solids -import java.nio.file.Paths +import space.kscience.visionforge.solid.ambientLight +import space.kscience.visionforge.solid.set +import space.kscience.visionforge.solid.solid import java.util.zip.ZipInputStream +import kotlin.io.path.Path import kotlin.io.path.writeText @@ -34,73 +39,17 @@ fun main() { println(it) } - val solid = Solids.rootGeo(geo) - - Paths.get("BM@N.vf.json").writeText(Solids.encodeToString(solid)) - //println(Solids.encodeToString(solid)) - - makeVisionFile { + makeVisionFile(path = Path("data/output.html"), resourceLocation = ResourceLocation.EMBED) { vision("canvas") { requirePlugin(Solids) - solid + solid { + ambientLight { + color.set(Colors.white) + } + rootGeo(geo,"BM@N", maxLayer = 3, ignoreRootColors = true).also { + Path("data/BM@N.vf.json").writeText(Solids.encodeToString(it)) + } + } } } -} - - -/* SolidGroup { - set( - "Coil", - solid.getPrototype("Coil".asName())!!.apply { - parent = null - } - ) - *//* group("Shade") { - y = 200 - color("red") - coneSurface( - bottomOuterRadius = 135, - bottomInnerRadius = 25, - height = 50, - topOuterRadius = 135, - topInnerRadius = 25, - angle = 1.5707964 - ) { - position = Point3D(79.6, 0, -122.1) - rotation = Point3D(-1.5707964, 0, 0) - } - coneSurface( - bottomOuterRadius = 135, - bottomInnerRadius = 25, - height = 50, - topOuterRadius = 135, - topInnerRadius = 25, - angle = 1.5707964 - ) { - position = Point3D(-79.6, 0, -122.1) - rotation = Point3D(1.5707964, 0, -3.1415927) - } - coneSurface( - bottomOuterRadius = 135, - bottomInnerRadius = 25, - height = 50, - topOuterRadius = 135, - topInnerRadius = 25, - angle = 1.5707964 - ) { - position = Point3D(79.6, 0, 122.1) - rotation = Point3D(1.5707964, 0, 0) - } - coneSurface( - bottomOuterRadius = 135, - bottomInnerRadius = 25, - height = 50, - topOuterRadius = 135, - topInnerRadius = 25, - angle = 1.5707964 - ) { - position = Point3D(-79.6, 0, 122.1) - rotation = Point3D(-1.5707964, 0, -3.1415927) - } - }*//* - }*/ +} \ No newline at end of file diff --git a/visionforge-core/build.gradle.kts b/visionforge-core/build.gradle.kts index 505ff3be..218a1710 100644 --- a/visionforge-core/build.gradle.kts +++ b/visionforge-core/build.gradle.kts @@ -7,10 +7,11 @@ val dataforgeVersion: String by rootProject.extra kscience{ jvm() js() + native() dependencies { api("space.kscience:dataforge-context:$dataforgeVersion") api(spclibs.kotlinx.html) - api("org.jetbrains.kotlin-wrappers:kotlin-css") +// api("org.jetbrains.kotlin-wrappers:kotlin-css") } testDependencies { implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:${space.kscience.gradle.KScienceVersions.coroutinesVersion}") diff --git a/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/JvmSynchronized.kt b/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/JvmSynchronized.kt new file mode 100644 index 00000000..a6f8c374 --- /dev/null +++ b/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/JvmSynchronized.kt @@ -0,0 +1,5 @@ +package space.kscience.visionforge + +@OptIn(ExperimentalMultiplatform::class) +@OptionalExpectation +public expect annotation class JvmSynchronized() diff --git a/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionChange.kt b/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionChange.kt index 358e72aa..15d59a0f 100644 --- a/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionChange.kt +++ b/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionChange.kt @@ -13,7 +13,6 @@ import space.kscience.dataforge.meta.descriptors.MetaDescriptor import space.kscience.dataforge.names.Name import space.kscience.dataforge.names.isEmpty import space.kscience.dataforge.names.plus -import kotlin.jvm.Synchronized import kotlin.time.Duration /** @@ -59,11 +58,11 @@ public class VisionChangeBuilder : MutableVisionContainer { public fun isEmpty(): Boolean = propertyChange.isEmpty() && propertyChange.isEmpty() && children.isEmpty() - @Synchronized + @JvmSynchronized private fun getOrPutChild(visionName: Name): VisionChangeBuilder = children.getOrPut(visionName) { VisionChangeBuilder() } - @Synchronized + @JvmSynchronized internal fun reset() { vision = null propertyChange = MutableMeta() diff --git a/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionContainer.kt b/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionContainer.kt index 7ac01b74..77f989f4 100644 --- a/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionContainer.kt +++ b/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionContainer.kt @@ -6,7 +6,6 @@ import kotlinx.coroutines.flow.* import kotlinx.coroutines.launch import space.kscience.dataforge.names.* import space.kscience.visionforge.VisionChildren.Companion.STATIC_TOKEN_BODY -import kotlin.jvm.Synchronized @DslMarker public annotation class VisionBuilder @@ -132,7 +131,7 @@ internal abstract class VisionChildrenImpl( abstract var items: MutableMap? - @Synchronized + @JvmSynchronized private fun buildItems(): MutableMap { if (items == null) { items = LinkedHashMap() diff --git a/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionProperties.kt b/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionProperties.kt index 52bdd52f..2fa88248 100644 --- a/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionProperties.kt +++ b/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionProperties.kt @@ -11,7 +11,6 @@ import space.kscience.dataforge.meta.* import space.kscience.dataforge.meta.descriptors.MetaDescriptor import space.kscience.dataforge.meta.descriptors.get import space.kscience.dataforge.names.* -import kotlin.jvm.Synchronized public interface VisionProperties { @@ -155,7 +154,7 @@ public abstract class AbstractVisionProperties( override val own: Meta? get() = properties - @Synchronized + @JvmSynchronized protected fun getOrCreateProperties(): MutableMeta { if (properties == null) { //TODO check performance issues diff --git a/visionforge-core/src/jvmMain/kotlin/space/kscience/visionforge/JvmSynchronized.kt b/visionforge-core/src/jvmMain/kotlin/space/kscience/visionforge/JvmSynchronized.kt new file mode 100644 index 00000000..fc8fed09 --- /dev/null +++ b/visionforge-core/src/jvmMain/kotlin/space/kscience/visionforge/JvmSynchronized.kt @@ -0,0 +1,3 @@ +package space.kscience.visionforge + +public actual typealias JvmSynchronized = Synchronized \ No newline at end of file diff --git a/visionforge-core/src/jvmMain/kotlin/space/kscience/visionforge/html/htmlExport.kt b/visionforge-core/src/jvmMain/kotlin/space/kscience/visionforge/html/htmlExport.kt index ff0c3eee..f1efe1b4 100644 --- a/visionforge-core/src/jvmMain/kotlin/space/kscience/visionforge/html/htmlExport.kt +++ b/visionforge-core/src/jvmMain/kotlin/space/kscience/visionforge/html/htmlExport.kt @@ -67,9 +67,7 @@ public fun VisionPage.makeFile( path: Path?, fileHeaders: ((Path) -> Map)? = null, ): Path { - val actualFile = path?.let { - Path.of(System.getProperty("user.home")).resolve(path) - } ?: Files.createTempFile("tempPlot", ".html") + val actualFile = path ?: Files.createTempFile("tempPlot", ".html") val actualDefaultHeaders = fileHeaders?.invoke(actualFile) val actualHeaders = if (actualDefaultHeaders == null) pageHeaders else actualDefaultHeaders + pageHeaders diff --git a/visionforge-gdml/build.gradle.kts b/visionforge-gdml/build.gradle.kts index 494e648e..6dd3042a 100644 --- a/visionforge-gdml/build.gradle.kts +++ b/visionforge-gdml/build.gradle.kts @@ -12,6 +12,6 @@ kscience { api("space.kscience:gdml:0.4.0") } dependencies(jvmTest) { - implementation("ch.qos.logback:logback-classic:1.2.11") + implementation(spclibs.logback.classic) } } \ No newline at end of file diff --git a/visionforge-markdown/build.gradle.kts b/visionforge-markdown/build.gradle.kts index 502e2196..9790bf1a 100644 --- a/visionforge-markdown/build.gradle.kts +++ b/visionforge-markdown/build.gradle.kts @@ -2,7 +2,7 @@ plugins { id("space.kscience.gradle.mpp") } -val markdownVersion = "0.2.4" +val markdownVersion = "0.4.1" kscience { jvm() diff --git a/visionforge-solid/build.gradle.kts b/visionforge-solid/build.gradle.kts index d135e045..5eb92323 100644 --- a/visionforge-solid/build.gradle.kts +++ b/visionforge-solid/build.gradle.kts @@ -5,6 +5,7 @@ plugins { kscience { jvm() js() + native() useSerialization { json() } diff --git a/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/SolidGroup.kt b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/SolidGroup.kt index a089bf4d..f601a30e 100644 --- a/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/SolidGroup.kt +++ b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/SolidGroup.kt @@ -6,7 +6,10 @@ 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.* +import space.kscience.visionforge.AbstractVisionGroup +import space.kscience.visionforge.MutableVisionContainer +import space.kscience.visionforge.MutableVisionGroup +import space.kscience.visionforge.VisionBuilder /** @@ -53,7 +56,7 @@ public class SolidGroup : AbstractVisionGroup(), Solid, PrototypeHolder, Mutable /** * Get a prototype redirecting the request to the parent if prototype is not found. - * If prototype is a ref, then it is unfolded automatically. + * If a prototype is a ref, then it is unfolded automatically. */ override fun getPrototype(name: Name): Solid? = prototypes?.get(name)?.prototype ?: (parent as? PrototypeHolder)?.getPrototype(name) diff --git a/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/Solids.kt b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/Solids.kt index 62e56d2b..38d214bd 100644 --- a/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/Solids.kt +++ b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/Solids.kt @@ -10,7 +10,6 @@ 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.request import space.kscience.dataforge.meta.Meta import space.kscience.dataforge.misc.DFExperimental import space.kscience.dataforge.names.Name @@ -27,15 +26,9 @@ public class Solids(meta: Meta) : VisionPlugin(meta), MutableVisionContainer, MutableVisionContainer { + public companion object : PluginFactory { override val tag: PluginTag = PluginTag(name = "vision.solid", group = PluginTag.DATAFORGE_GROUP) - public val default: Solids by lazy { - Context("@Solids") { - plugin(Solids) - }.request(Solids) - } - override fun build(context: Context, meta: Meta): Solids = Solids(meta) private fun PolymorphicModuleBuilder.solids() { @@ -79,9 +72,9 @@ public class Solids(meta: Meta) : VisionPlugin(meta), MutableVisionContainer(Sphere::class) { override fun buildGeometry(obj: Sphere): BufferGeometry { - return obj.detail?.let {detail -> + return obj.detail?.let { detail -> SphereGeometry( radius = obj.radius, phiStart = obj.phiStart, @@ -17,7 +17,7 @@ public object ThreeSphereFactory : ThreeMeshFactory(Sphere::class) { widthSegments = detail, heightSegments = detail ) - }?: SphereGeometry( + } ?: SphereGeometry( radius = obj.radius, phiStart = obj.phiStart, phiLength = obj.phi, diff --git a/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/csg.kt b/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/csg.kt index 940d72c3..0d7f774d 100644 --- a/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/csg.kt +++ b/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/csg.kt @@ -3,8 +3,7 @@ "OVERRIDING_FINAL_MEMBER", "RETURN_TYPE_MISMATCH_ON_OVERRIDE", "CONFLICTING_OVERLOADS", - "EXTERNAL_DELEGATION", - "NO_EXPLICIT_VISIBILITY_IN_API_MODE_WARNING" + "EXTERNAL_DELEGATION" ) @file:JsModule("three-csg-ts")