WIP Root to Solid conversion
This commit is contained in:
parent
193665b99a
commit
68704086e9
@ -9,14 +9,14 @@ import kotlinx.serialization.Serializable
|
|||||||
public class TGeoManager : TNamed() {
|
public class TGeoManager : TNamed() {
|
||||||
|
|
||||||
@Contextual
|
@Contextual
|
||||||
public val fMatrices: TObjArray<TGeoMatrix> = TObjArray.getEmpty()
|
public val fMatrices: TObjArray<@Contextual TGeoMatrix> = TObjArray.getEmpty()
|
||||||
|
|
||||||
@Contextual
|
@Contextual
|
||||||
public val fShapes: TObjArray<TGeoShape> = TObjArray.getEmpty()
|
public val fShapes: TObjArray<@Contextual TGeoShape> = TObjArray.getEmpty()
|
||||||
|
|
||||||
@Contextual
|
@Contextual
|
||||||
public val fVolumes: TObjArray<TGeoVolume> = TObjArray.getEmpty()
|
public val fVolumes: TObjArray<@Contextual TGeoVolume> = TObjArray.getEmpty()
|
||||||
|
|
||||||
@Contextual
|
@Contextual
|
||||||
public val fNodes: TObjArray<TGeoNode> = TObjArray.getEmpty()
|
public val fNodes: TObjArray<@Contextual TGeoNode> = TObjArray.getEmpty()
|
||||||
}
|
}
|
||||||
|
@ -81,19 +81,19 @@ private object RootDecoder {
|
|||||||
): SerializersModule = SerializersModule {
|
): SerializersModule = SerializersModule {
|
||||||
include(serializersModule)
|
include(serializersModule)
|
||||||
|
|
||||||
contextual(TGeoManager.serializer().unref(refCache))
|
//contextual(TGeoManager.serializer().unref(refCache))
|
||||||
contextual(TObjArray::class) { TObjArray.serializer(it[0]).unref(refCache) }
|
contextual(TObjArray::class) { TObjArray.serializer(it[0]).unref(refCache) }
|
||||||
contextual(TGeoVolumeAssembly.serializer().unref(refCache))
|
//contextual(TGeoVolumeAssembly.serializer().unref(refCache))
|
||||||
contextual(TGeoShapeAssembly.serializer().unref(refCache))
|
//contextual(TGeoShapeAssembly.serializer().unref(refCache))
|
||||||
contextual(TGeoRotation.serializer().unref(refCache))
|
contextual(TGeoRotation.serializer().unref(refCache))
|
||||||
contextual(TGeoMedium.serializer().unref(refCache))
|
contextual(TGeoMedium.serializer().unref(refCache))
|
||||||
contextual(TGeoVolume.serializer().unref(refCache))
|
//contextual(TGeoVolume.serializer().unref(refCache))
|
||||||
contextual(TGeoMatrix.serializer().unref(refCache))
|
//contextual(TGeoMatrix.serializer().unref(refCache))
|
||||||
contextual(TGeoNode.serializer().unref(refCache))
|
//contextual(TGeoNode.serializer().unref(refCache))
|
||||||
contextual(TGeoNodeOffset.serializer().unref(refCache))
|
//contextual(TGeoNodeOffset.serializer().unref(refCache))
|
||||||
contextual(TGeoNodeMatrix.serializer().unref(refCache))
|
//contextual(TGeoNodeMatrix.serializer().unref(refCache))
|
||||||
contextual(TGeoShape.serializer().unref(refCache))
|
//contextual(TGeoShape.serializer().unref(refCache))
|
||||||
contextual(TObject.serializer().unref(refCache))
|
//contextual(TObject.serializer().unref(refCache))
|
||||||
|
|
||||||
|
|
||||||
polymorphicDefault(TGeoShape::class) {
|
polymorphicDefault(TGeoShape::class) {
|
||||||
@ -245,7 +245,8 @@ private object RootDecoder {
|
|||||||
subclass(TGeoNodeOffset.serializer())
|
subclass(TGeoNodeOffset.serializer())
|
||||||
}
|
}
|
||||||
|
|
||||||
polymorphic(TGeoVolume::class, TGeoVolume.serializer()) {
|
polymorphic(TGeoVolume::class) {
|
||||||
|
subclass(TGeoVolume.serializer())
|
||||||
subclass(TGeoVolumeAssembly.serializer())
|
subclass(TGeoVolumeAssembly.serializer())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ private fun SolidGroup.addShape(shape: TGeoShape) {
|
|||||||
|
|
||||||
private fun SolidGroup.node(obj: TGeoNode) {
|
private fun SolidGroup.node(obj: TGeoNode) {
|
||||||
if (obj.fVolume != null) {
|
if (obj.fVolume != null) {
|
||||||
volume(obj.fVolume).apply {
|
volume(obj.fVolume, obj.fName).apply {
|
||||||
when (obj) {
|
when (obj) {
|
||||||
is TGeoNodeMatrix -> {
|
is TGeoNodeMatrix -> {
|
||||||
useMatrix(obj.fMatrix)
|
useMatrix(obj.fMatrix)
|
||||||
@ -145,15 +145,22 @@ private fun buildGroup(volume: TGeoVolume): SolidGroup {
|
|||||||
|
|
||||||
private val SolidGroup.rootPrototypes: SolidGroup get() = (parent as? SolidGroup)?.rootPrototypes ?: this
|
private val SolidGroup.rootPrototypes: SolidGroup get() = (parent as? SolidGroup)?.rootPrototypes ?: this
|
||||||
|
|
||||||
private fun SolidGroup.volume(volume: TGeoVolume, cache: Boolean = true): Solid {
|
private fun SolidGroup.volume(volume: TGeoVolume, name: String? = null, cache: Boolean = true): Solid {
|
||||||
val group = buildGroup(volume)
|
val group = buildGroup(volume)
|
||||||
|
val combinedName = if (volume.fName.isEmpty()) {
|
||||||
|
name
|
||||||
|
} else if (name == null) {
|
||||||
|
volume.fName
|
||||||
|
} else {
|
||||||
|
"${name}_${volume.fName}"
|
||||||
|
}
|
||||||
return if (!cache) {
|
return if (!cache) {
|
||||||
group
|
group
|
||||||
} else newRef(
|
} else newRef(
|
||||||
name = volume.fName.ifEmpty { null },
|
name = combinedName,
|
||||||
obj = group,
|
obj = group,
|
||||||
prototypeHolder = rootPrototypes,
|
prototypeHolder = rootPrototypes,
|
||||||
templateName = volumesName + Name.parse(volume.fName.ifEmpty { group.toString() })
|
templateName = volumesName + Name.parse(combinedName ?: "volume[${group.hashCode()}]")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package ru.mipt.npm.root
|
package ru.mipt.npm.root
|
||||||
|
|
||||||
import kotlinx.serialization.json.*
|
import kotlinx.serialization.json.*
|
||||||
|
import space.kscience.visionforge.solid.Solids
|
||||||
import java.time.Duration
|
import java.time.Duration
|
||||||
import kotlin.system.measureTimeMillis
|
import kotlin.system.measureTimeMillis
|
||||||
|
|
||||||
private fun JsonElement.countTypes(): Sequence<String> = sequence {
|
private fun JsonElement.countTypes(): Sequence<String> = sequence {
|
||||||
val json = this@countTypes
|
when (val json = this@countTypes){
|
||||||
when (json){
|
|
||||||
is JsonObject -> {
|
is JsonObject -> {
|
||||||
json["_typename"]?.let { yield(it.jsonPrimitive.content) }
|
json["_typename"]?.let { yield(it.jsonPrimitive.content) }
|
||||||
json.values.forEach { yieldAll(it.countTypes()) }
|
json.values.forEach { yieldAll(it.countTypes()) }
|
||||||
@ -33,7 +33,7 @@ fun main() {
|
|||||||
val geo = TObject.decodeFromString(TGeoManager.serializer(), string)
|
val geo = TObject.decodeFromString(TGeoManager.serializer(), string)
|
||||||
val solid = geo.toSolid()
|
val solid = geo.toSolid()
|
||||||
|
|
||||||
println(solid)
|
println(Solids.encodeToString(solid))
|
||||||
}
|
}
|
||||||
|
|
||||||
println(Duration.ofMillis(time))
|
println(Duration.ofMillis(time))
|
||||||
|
Loading…
Reference in New Issue
Block a user