add a workaround for root duplicating names
This commit is contained in:
parent
f5fba4747e
commit
1e29c5dbaa
@ -4,6 +4,7 @@ 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.dataforge.names.withIndex
|
||||
import space.kscience.visionforge.MutableVisionContainer
|
||||
import space.kscience.visionforge.isEmpty
|
||||
import space.kscience.visionforge.set
|
||||
@ -223,7 +224,7 @@ private fun SolidGroup.addShape(
|
||||
"TGeoShapeAssembly" -> {
|
||||
val fVolume by shape.dObject(::DGeoVolume)
|
||||
fVolume?.let { volume ->
|
||||
addRootVolume(volume, context, block = block)
|
||||
addRootVolume(volume, context, name = volume.fName.ifEmpty { null }, block = block)
|
||||
}
|
||||
}
|
||||
|
||||
@ -348,29 +349,29 @@ private fun SolidGroup.addRootVolume(
|
||||
cache: Boolean = true,
|
||||
block: Solid.() -> Unit = {},
|
||||
) {
|
||||
|
||||
val combinedName = if (volume.fName.isEmpty()) {
|
||||
name
|
||||
} else if (name == null) {
|
||||
volume.fName
|
||||
} else {
|
||||
"${name}_${volume.fName}"
|
||||
val combinedName = name?.parseAsName()?.let {
|
||||
// this fix is required to work around malformed root files with duplicated node names
|
||||
if (get(it) != null) {
|
||||
it.withIndex(volume.hashCode().toString(16))
|
||||
} else {
|
||||
it
|
||||
}
|
||||
}
|
||||
|
||||
if (!cache) {
|
||||
val group = buildVolume(volume, context)?.apply(block)
|
||||
setChild(combinedName?.let { Name.parse(it) }, group)
|
||||
val group = buildVolume(volume, context)?.apply(block) ?: return
|
||||
setChild(combinedName, group)
|
||||
} else {
|
||||
val templateName = volumesName + volume.name
|
||||
val existing = getPrototype(templateName)
|
||||
val existing = context.prototypeHolder.getPrototype(templateName)
|
||||
if (existing == null) {
|
||||
context.prototypeHolder.prototypes {
|
||||
val group = buildVolume(volume, context)
|
||||
val group = buildVolume(volume, context) ?: return@prototypes
|
||||
setChild(templateName, group)
|
||||
}
|
||||
}
|
||||
|
||||
ref(templateName, name).apply(block)
|
||||
ref(templateName, combinedName).apply(block)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ private fun Meta.countTypes(): Sequence<String> = sequence {
|
||||
}
|
||||
|
||||
fun main() {
|
||||
val string = ZipInputStream(TGeoManager::class.java.getResourceAsStream("/root/BM@N_geometry.zip")!!).use {
|
||||
val string = ZipInputStream(TGeoManager::class.java.getResourceAsStream("/root/geometry_run_7-2076.zip")!!).use {
|
||||
it.nextEntry
|
||||
it.readAllBytes().decodeToString()
|
||||
}
|
||||
|
Binary file not shown.
@ -17,7 +17,7 @@ import space.kscience.visionforge.VisionBuilder
|
||||
*/
|
||||
public interface PrototypeHolder {
|
||||
/**
|
||||
* Build or update prototype tree
|
||||
* Build or update the prototype tree
|
||||
*/
|
||||
@VisionBuilder
|
||||
public fun prototypes(builder: MutableVisionContainer<Solid>.() -> Unit)
|
||||
|
@ -2,7 +2,9 @@ package space.kscience.visionforge.solid
|
||||
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.flow.*
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.emptyFlow
|
||||
import kotlinx.coroutines.flow.filter
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
@ -61,7 +63,7 @@ public class SolidReference(
|
||||
}
|
||||
|
||||
override fun getValue(name: Name, inherit: Boolean?, includeStyles: Boolean?): Value? {
|
||||
if(name == Vision.STYLE_KEY){
|
||||
if (name == Vision.STYLE_KEY) {
|
||||
return buildList {
|
||||
properties?.getValue(Vision.STYLE_KEY)?.list?.forEach {
|
||||
add(it)
|
||||
@ -90,7 +92,7 @@ public class SolidReference(
|
||||
prototype.getStyleProperty(name)?.value?.let { return it }
|
||||
}
|
||||
|
||||
if(inheritFlag){
|
||||
if (inheritFlag) {
|
||||
//5. own inheritance
|
||||
parent?.properties?.getValue(name, inheritFlag, includeStyles)?.let { return it }
|
||||
//6. prototype inheritance
|
||||
@ -226,9 +228,14 @@ internal class SolidReferenceChild(
|
||||
*/
|
||||
public fun MutableVisionContainer<Solid>.ref(
|
||||
templateName: Name,
|
||||
name: String? = null,
|
||||
name: Name? = null,
|
||||
): SolidReference = SolidReference(templateName).also { setChild(name, it) }
|
||||
|
||||
public fun MutableVisionContainer<Solid>.ref(
|
||||
templateName: Name,
|
||||
name: String? = null,
|
||||
): SolidReference = ref(templateName, name?.parseAsName())
|
||||
|
||||
public fun MutableVisionContainer<Solid>.ref(
|
||||
templateName: String,
|
||||
name: String? = null,
|
||||
|
Loading…
Reference in New Issue
Block a user