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