forked from kscience/visionforge
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 {
|
||||||
"${name}_${volume.fName}"
|
it
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
@ -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