2021-03-07 16:19:43 +03:00
|
|
|
package space.kscience.visionforge.gdml
|
2021-03-01 19:10:15 +03:00
|
|
|
|
2021-03-07 16:19:43 +03:00
|
|
|
import space.kscience.dataforge.context.Context
|
2021-08-07 11:27:57 +03:00
|
|
|
import space.kscience.dataforge.names.Name
|
2021-05-05 15:28:06 +03:00
|
|
|
import space.kscience.gdml.*
|
2021-03-07 16:19:43 +03:00
|
|
|
import space.kscience.visionforge.Vision
|
|
|
|
import space.kscience.visionforge.get
|
|
|
|
import space.kscience.visionforge.solid.*
|
|
|
|
import space.kscience.visionforge.visionManager
|
2021-03-01 19:10:15 +03:00
|
|
|
import kotlin.test.Test
|
|
|
|
import kotlin.test.assertEquals
|
|
|
|
import kotlin.test.assertNotNull
|
|
|
|
|
|
|
|
internal val testContext = Context("TEST") {
|
|
|
|
plugin(Solids)
|
|
|
|
}
|
|
|
|
|
|
|
|
class TestCubes {
|
|
|
|
|
2021-05-05 15:28:06 +03:00
|
|
|
val cubes = GdmlShowCase.cubes()
|
|
|
|
|
2021-03-01 19:10:15 +03:00
|
|
|
@Test
|
|
|
|
fun testCubesDirect() {
|
|
|
|
val vision = cubes.toVision()
|
2021-05-05 15:28:06 +03:00
|
|
|
// println(Solids.encodeToString(vision))
|
2021-08-07 11:27:57 +03:00
|
|
|
val smallBoxPrototype = vision.getPrototype(Name.parse("solids.smallBox")) as? Box
|
2021-03-01 19:10:15 +03:00
|
|
|
assertNotNull(smallBoxPrototype)
|
|
|
|
assertEquals(30.0, smallBoxPrototype.xSize.toDouble())
|
2021-07-12 10:01:21 +03:00
|
|
|
val smallBoxVision = vision["composite-111.smallBox"]?.unref as? Box
|
2021-03-01 19:10:15 +03:00
|
|
|
assertNotNull(smallBoxVision)
|
|
|
|
assertEquals(30.0, smallBoxVision.xSize.toDouble())
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun testGdmlExport() {
|
|
|
|
val xml = cubes.encodeToString()
|
|
|
|
//println(xml)
|
|
|
|
val gdml = Gdml.decodeFromString(xml)
|
|
|
|
val smallBox = gdml.getSolid<GdmlBox>("smallBox")
|
|
|
|
assertNotNull(smallBox)
|
|
|
|
assertEquals(30.0, smallBox.x.toDouble())
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun testCubesReSerialize() {
|
|
|
|
val vision = cubes.toVision()
|
|
|
|
val serialized = Solids.encodeToString(vision)
|
|
|
|
val deserialized = testContext.visionManager.decodeFromString(serialized) as SolidGroup
|
2021-08-07 11:27:57 +03:00
|
|
|
val smallBox = deserialized.getPrototype(Name.parse("solids.smallBox")) as? Box
|
2021-03-01 19:10:15 +03:00
|
|
|
assertNotNull(smallBox)
|
|
|
|
assertEquals(30.0, smallBox.xSize.toDouble())
|
|
|
|
//println(testContext.visionManager.encodeToString(deserialized))
|
|
|
|
fun Vision.checkPrototypes() {
|
|
|
|
if (this is SolidReference) {
|
|
|
|
assertNotNull(this.prototype)
|
|
|
|
}
|
|
|
|
if (this is SolidGroup) {
|
|
|
|
children.forEach {
|
|
|
|
it.value.checkPrototypes()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
deserialized.checkPrototypes()
|
|
|
|
}
|
|
|
|
}
|