From 5ffaeefb40dbbc3aacf2a3b5f1df909f53182f9e Mon Sep 17 00:00:00 2001 From: webdevred <148627186+webdevred@users.noreply.github.com> Date: Fri, 26 Sep 2025 18:06:12 +0200 Subject: [PATCH] added transformation test for a example configuration file --- app/Main.hs | 2 +- examples/jbeam-edit.yaml | 7 + ...{fender.jbeam => fender-cfg-default.jbeam} | 0 .../fender-cfg-example.jbeam | 297 +++++++++++++ ...ion.jbeam => suspension-cfg-default.jbeam} | 0 .../suspension-cfg-example.jbeam | 398 ++++++++++++++++++ src-extra/transformation/Config.hs | 6 +- test/TransformationSpec.hs | 17 +- tools/dump_ast/Main.hs | 24 +- 9 files changed, 734 insertions(+), 17 deletions(-) create mode 100644 examples/jbeam-edit.yaml rename examples/transformed_jbeam/{fender.jbeam => fender-cfg-default.jbeam} (100%) create mode 100644 examples/transformed_jbeam/fender-cfg-example.jbeam rename examples/transformed_jbeam/{suspension.jbeam => suspension-cfg-default.jbeam} (100%) create mode 100644 examples/transformed_jbeam/suspension-cfg-example.jbeam diff --git a/app/Main.hs b/app/Main.hs index 851d5391..e151b2e9 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -57,7 +57,7 @@ processNodes opts outFile nodes formattingConfig = do applyTransform :: Options -> Node -> IO (Either Text Node) #ifdef ENABLE_TRANSFORMATION applyTransform opts node = do - tfConfig <- loadTransformationConfig + tfConfig <- loadTransformationConfig ".jbeam-edit.yaml" pure (transform (optUpdateNames opts) tfConfig node) #else applyTransform _ = pure . Right diff --git a/examples/jbeam-edit.yaml b/examples/jbeam-edit.yaml new file mode 100644 index 00000000..2f82e540 --- /dev/null +++ b/examples/jbeam-edit.yaml @@ -0,0 +1,7 @@ +z-sorting-threshold: 0.05 +support-threshold: 80 + +x-breakpoints: + LeftTree: '>= 0.09' + Middle: '> -0.09' + RightTree: <= -0.09 diff --git a/examples/transformed_jbeam/fender.jbeam b/examples/transformed_jbeam/fender-cfg-default.jbeam similarity index 100% rename from examples/transformed_jbeam/fender.jbeam rename to examples/transformed_jbeam/fender-cfg-default.jbeam diff --git a/examples/transformed_jbeam/fender-cfg-example.jbeam b/examples/transformed_jbeam/fender-cfg-example.jbeam new file mode 100644 index 00000000..3b03415e --- /dev/null +++ b/examples/transformed_jbeam/fender-cfg-example.jbeam @@ -0,0 +1,297 @@ +{ + "cot_fender" : { + "information" : {"authors" : "gittarrgy01", "name" : "Fenders"}, + "slotType" : "cot_fender", + "nodes" : [ + ["id", "posX", "posY", "posZ"], + {"frictionCoef" : 0.7}, + {"nodeMaterial" : "|NM_METAL"}, + + // Left side + {"collision" : true}, + {"group" : "cot_fender_l"}, + {"nodeWeight" : 0.65}, + {"selfCollision" : true}, + ["bfl0", 0.739, -1.845, 0.716], + ["bfl1", 0.959, -1.762, 0.576], + ["bfl2", 0.855, -1.788, 0.707], + ["bfl3", 0.948, -1.435, 0.73], + ["bfl4", 0.963, -1.024, 0.112], + ["bfl5", 0.778, -1.008, 0.873], + ["bfl6", 0.987, -0.743, 0.109], + ["bfl7", 0.812, -0.759, 0.896], + + // Right side + {"group" : "cot_fender_r"}, + ["bfr0", -0.691, -1.829, 0.716], + ["bfr1", -0.906, -1.737, 0.578], + ["bfr2", -0.807, -1.769, 0.707], + ["bfr3", -0.89, -1.409, 0.729], + ["bfr4", -0.899, -1.005, 0.112], + ["bfr5", -0.715, -0.991, 0.873], + ["bfr6", -0.916, -0.742, 0.112], + ["bfr7", -0.734, -0.746, 0.888], + + // Support nodes + {"collision" : false}, + {"group" : ""}, + {"nodeWeight" : 1.2}, + {"selfCollision" : false}, + ["bfsl", 0.684, -1.079, 0.507], + ["bfsr", -0.623, -1.064, 0.507], + {"collision" : true}, + {"group" : "cot_fender_l"}, + {"nodeWeight" : 0.65}, + {"selfCollision" : true}, + ["bflsl", 0.756, -1.413, 0.843], + ["bflsl1", 0.964, -1.072, 0.507], + ["bflsl2", 0.987, -0.744, 0.494], + {"group" : "cot_fender_r"}, + ["bfrsr", -0.7, -1.397, 0.843], + ["bfrsr1", -0.9, -1.053, 0.508], + ["bfrsr2", -0.917, -0.746, 0.494] + ], + "beams" : [ + ["id1:", "id2:"], + + // Structural beams + {"beamType" : "|NORMAL"}, + {"beamSpring" : 451000.0, "beamDamp" : 50.0}, + {"beamStrength" : "FLT_MAX"}, + {"deformLimitExpansion" : 1.1}, + {"beamDeform" : 6000.0}, + + // Front + ["bfr0", "bfrsr"], + ["bfr0", "bfr2"], + ["bfr2", "bfrsr"], + ["bflsl", "bfl0"], + ["bfl0", "bfl2"], + ["bfl1", "bfl2"], + ["bflsl", "bfl3"], + ["bfl1", "bfl3"], + ["bfr2", "bfr1"], + ["bfrsr", "bfr3"], + ["bfr1", "bfr3"], + ["bflsl", "bfl2"], + + // Middle + {"beamDeform" : 12000.0}, + ["bflsl1", "bfl3"], + ["bfrsr1", "bfr3"], + ["bflsl", "bfl5"], + ["bfrsr", "bfr5"], + + // Rear + ["bfl5", "bfl7"], + ["bfl4", "bflsl1"], + ["bfl5", "bflsl1"], + ["bfl4", "bfl6"], + ["bflsl1", "bflsl2"], + ["bfl6", "bflsl2"], + ["bfl7", "bflsl2"], + ["bfr5", "bfr7"], + ["bfrsr1", "bfr4"], + ["bfrsr1", "bfr5"], + ["bfr4", "bfr6"], + ["bfrsr1", "bfrsr2"], + ["bfr6", "bfrsr2"], + ["bfr7", "bfrsr2"], + + // Crossing beams + {"deformLimitExpansion" : ""}, + + // Front + ["bfl1", "bflsl"], + ["bflsl", "bflsl1"], + ["bfl5", "bfl3"], + ["bfrsr", "bfrsr1"], + ["bfr5", "bfr3"], + ["bfl2", "bfl3"], + ["bfr3", "bfr2"], + ["bfrsr", "bfr1"], + + // Rear + ["bflsl1", "bfl7"], + ["bfl5", "bflsl2"], + ["bfl4", "bflsl2"], + ["bflsl1", "bfl6"], + ["bfrsr1", "bfr7"], + ["bfr5", "bfrsr2"], + ["bfr4", "bfrsr2"], + ["bfrsr1", "bfr6"], + + // Support beams + ["bfl0", "bfsl"], + ["bflsl1", "bfsl"], + ["bfl4", "bfsl"], + ["bfl3", "bfsl"], + ["bfl1", "bfsl"], + ["bfl2", "bfsl"], + ["bflsl", "bfsl"], + ["bfl5", "bfsl"], + ["bfl6", "bfsl"], + ["bflsl2", "bfsl"], + ["bfl7", "bfsl"], + ["bfr0", "bfsr"], + ["bfrsr1", "bfsr"], + ["bfr4", "bfsr"], + ["bfr3", "bfsr"], + ["bfr1", "bfsr"], + ["bfr2", "bfsr"], + ["bfrsr", "bfsr"], + ["bfr5", "bfsr"], + ["bfr6", "bfsr"], + ["bfrsr2", "bfsr"], + ["bfr7", "bfsr"], + + // Front rigid + {"beamSpring" : 350000.0, "beamDamp" : 115.0}, + {"beamDeform" : 900.0}, + + // Left side + ["bfl3", "bflsl2"], + ["bflsl", "bfl7"], + + // Right side + ["bfr3", "bfrsr2"], + ["bfrsr", "bfr7"], + + // Attachment beams + {"beamType" : "|NORMAL"}, + {"beamSpring" : 501000.0, "beamDamp" : 75.0, "beamStrength" : 20000.0, "beamDeform" : 1000.0}, + {"deformLimitExpansion" : ""}, + + // Frame + + // Left side + + // Front + {"breakGroup" : "fender_l"}, + {"breakGroupType" : 1.0}, + ["bfl1", "fr17"], + ["bfl1", "fr9"], + ["bfl2", "fr17"], + ["bfl2", "fr9"], + ["bfl0", "fr17"], + ["bfl0", "fr9"], + + // Middle + {"beamDeform" : 18000.0}, + {"beamStrength" : 4000.0}, + {"breakGroupType" : 1.0}, + ["bfl3", "fr17"], + ["bflsl", "fr17"], + ["bflsl", "fr9"], + {"breakGroupType" : 0.0}, + + // Rear + {"beamStrength" : 16000.0, "beamDeform" : 12000.0}, + ["bfl4", "fr18"], + ["bfl4", "fr27"], + ["bflsl1", "fr17"], + ["bflsl1", "fr21"], + ["bfl5", "fr17"], + ["bfl5", "fr29"], + ["bfl6", "fr18"], + ["bfl6", "fr27"], + ["bflsl2", "fr28"], + ["bflsl2", "fr21"], + ["bfl7", "fr17"], + ["bfl7", "fr29"], + + // Right side + + // Front + {"beamStrength" : 20000.0, "beamDeform" : 1000.0}, + {"breakGroup" : "fender_r"}, + {"breakGroupType" : 1.0}, + ["bfr1", "fr16"], + ["bfr1", "fr7"], + ["bfr2", "fr16"], + ["bfr2", "fr7"], + ["bfr0", "fr16"], + ["bfr0", "fr7"], + + // Middle + {"beamDeform" : 18000.0}, + {"beamStrength" : 4000.0}, + {"breakGroupType" : 1.0}, + ["bfr3", "fr16"], + ["bfrsr", "fr16"], + ["bfrsr", "fr7"], + {"breakGroupType" : 0.0}, + + // Rear + {"beamStrength" : 16000.0, "beamDeform" : 12000.0}, + ["bfr4", "fr19"], + ["bfr4", "fr32"], + ["bfrsr1", "fr16"], + ["bfrsr1", "fr20"], + ["bfr5", "fr16"], + ["bfr5", "fr34"], + ["bfr6", "fr19"], + ["bfr6", "fr32"], + ["bfrsr2", "fr33"], + ["bfrsr2", "fr20"], + ["bfr7", "fr16"], + ["bfr7", "fr34"], + {"beamStrength" : 16000.0, "beamDeform" : "FLT_MAX"}, + + // Body + + // Left side + {"breakGroup" : "fender_l"}, + ["bfl6", "mbl0"], + ["bflsl2", "mbl1"], + ["bfl7", "mbl2"], + + // Right side + {"breakGroup" : "fender_r"}, + ["bfr6", "mbr0"], + ["bfrsr2", "mbr1"], + ["bfr7", "mbr2"], + {"breakGroup" : "", "breakGroupType" : "", "beamType" : "|NORMAL"} + ], + "triangles" : [ + ["id1:", "id2:", "id3:"], + ["bfl3", "bflsl", "bfl2"], + ["bfl1", "bfl3", "bfl2"], + ["bflsl", "bfl0", "bfl2"], + ["bflsl", "bfl3", "bfl5"], + ["bflsl1", "bfl5", "bfl3"], + ["bfl7", "bfl5", "bflsl1"], + ["bflsl2", "bfl7", "bflsl1"], + ["bfl4", "bfl6", "bflsl1"], + ["bflsl2", "bflsl1", "bfl6"], + ["bfrsr", "bfr2", "bfr0"], + ["bfr3", "bfr2", "bfrsr"], + ["bfr1", "bfr2", "bfr3"], + ["bfrsr1", "bfr3", "bfr5"], + ["bfrsr", "bfr5", "bfr3"], + ["bfr7", "bfrsr1", "bfr5"], + ["bfrsr2", "bfrsr1", "bfr7"], + ["bfrsr2", "bfr6", "bfrsr1"], + ["bfr4", "bfrsr1", "bfr6"] + ], + "flexbodies" : [ + ["mesh", "[group]:", "nonFlexMaterials"], + [ + "impala_fender_l", + ["cot_fender_l"] + ], + [ + "impala_fender_inter_l", + ["cot_fender_l"] + ], + [ + "impala_fender_r", + ["cot_fender_r"] + ], + [ + "impala_fender_inter_r", + ["cot_fender_r"] + ] + ] + } +} \ No newline at end of file diff --git a/examples/transformed_jbeam/suspension.jbeam b/examples/transformed_jbeam/suspension-cfg-default.jbeam similarity index 100% rename from examples/transformed_jbeam/suspension.jbeam rename to examples/transformed_jbeam/suspension-cfg-default.jbeam diff --git a/examples/transformed_jbeam/suspension-cfg-example.jbeam b/examples/transformed_jbeam/suspension-cfg-example.jbeam new file mode 100644 index 00000000..e1ef2f4c --- /dev/null +++ b/examples/transformed_jbeam/suspension-cfg-example.jbeam @@ -0,0 +1,398 @@ +{ + "chassis_rails" : { + "information" : {"authors" : "gittarrgy01", "name" : ""}, + "slotType" : "main", + + // --Nodes-- + "nodes" : [ + ["id", "posX", "posY", "posZ"], + {"group" : "chassis_rails"}, + + // Left side + ["rll0", 0.523, -2.093, 0.268], + ["rll1", 0.523, -2.098, 0.319], + ["rll2", 0.531, -1.721, 0.289], + ["rll3", 0.531, -1.724, 0.341], + ["rll4", 0.547, -1.35, 0.31], + ["rll5", 0.547, -1.35, 0.364], + ["rll6", 0.79, -0.919, 0.182], + ["rll7", 0.79, -0.919, 0.233], + ["rll8", 0.415, 0.002, 0.182], + ["rll9", 0.837, 0.002, 0.182], + ["rll10", 0.415, 0.002, 0.233], + ["rll11", 0.837, 0.002, 0.233], + ["rll12", 0.822, 0.791, 0.182], + ["rll13", 0.822, 0.791, 0.233], + ["rll14", 0.651, 1.152, 0.565], + ["rll15", 0.651, 1.121, 0.628], + ["rll16", 0.602, 1.514, 0.566], + ["rll17", 0.602, 1.532, 0.623], + ["rll18", 0.553, 1.654, 0.359], + ["rll19", 0.553, 1.679, 0.448], + ["rll20", 0.558, 2.284, 0.364], + ["rll21", 0.558, 2.284, 0.447], + + // Middle side + ["rlm0", 0.053, -2.09, 0.269], + ["rlm1", 0.053, -2.095, 0.319], + ["rlm2", 0.053, 0.002, 0.182], + ["rlm3", 0.053, 0.002, 0.233], + ["rlm4", 0.053, 1.152, 0.565], + ["rlm5", 0.053, 1.121, 0.628], + ["rlm6", 0.053, 2.284, 0.37], + ["rlm7", 0.053, 2.284, 0.441], + + // Right side + ["rlr0", -0.417, -2.093, 0.268], + ["rlr1", -0.417, -2.098, 0.319], + ["rlr2", -0.424, -1.721, 0.289], + ["rlr3", -0.424, -1.724, 0.341], + ["rlr4", -0.44, -1.35, 0.31], + ["rlr5", -0.44, -1.35, 0.364], + ["rlr6", -0.683, -0.919, 0.182], + ["rlr7", -0.683, -0.919, 0.233], + ["rlr8", -0.73, 0.002, 0.182], + ["rlr9", -0.308, 0.002, 0.182], + ["rlr10", -0.73, 0.002, 0.233], + ["rlr11", -0.308, 0.002, 0.233], + ["rlr12", -0.715, 0.791, 0.182], + ["rlr13", -0.715, 0.791, 0.233], + ["rlr14", -0.544, 1.152, 0.565], + ["rlr15", -0.544, 1.121, 0.628], + ["rlr16", -0.495, 1.514, 0.566], + ["rlr17", -0.495, 1.532, 0.623], + ["rlr18", -0.446, 1.654, 0.359], + ["rlr19", -0.446, 1.679, 0.448], + ["rlr20", -0.451, 2.284, 0.364], + ["rlr21", -0.451, 2.284, 0.447], + + // Support nodes + ["rlsm", 0.053, -1.314, 0.382], + ["rlsm1", 0.053, -0.024, 0.578], + ["rlsm2", 0.053, 1.71, 0.565] + ], + + // --Beams-- + "beams" : [ + ["id1:", "id2:"], + + // Structural beams + {"beamStrength" : "FLT_MAX", "beamSpring" : "3800000"}, + {"beamDamp" : 130.0, "deformLimit" : 1.1}, + + // Front end + {"beamDeform" : 20600.0, "deformLimit" : 1.1}, + ["rll0", "rlm0"], + ["rll1", "rll0"], + ["rll2", "rll0"], + ["rll6", "rll4"], + ["rll2", "rll3"], + ["rll5", "rll4"], + ["rll4", "rll2"], + ["rlr2", "rlr3"], + ["rlr6", "rlr4"], + ["rll3", "rll5"], + ["rll5", "rll7"], + ["rlr5", "rlr7"], + ["rlr5", "rlr4"], + ["rlr1", "rlr0"], + ["rlm1", "rlr1"], + ["rlm1", "rlm0"], + ["rlr4", "rlr2"], + ["rlr3", "rlr5"], + ["rll1", "rll3"], + ["rlr2", "rlr0"], + ["rlm1", "rll1"], + ["rlr0", "rlm0"], + ["rlr1", "rlr3"], + + // Middle + {"beamDeform" : 27000.0}, + ["rll7", "rll6"], + ["rll9", "rll12"], + ["rll7", "rll10"], + ["rlr7", "rlr6"], + ["rlr6", "rlr8"], + ["rlr9", "rlr6"], + ["rlr7", "rlr11"], + ["rlr9", "rlm2"], + ["rlm3", "rlm2"], + ["rlm3", "rlr11"], + ["rll11", "rll7"], + ["rll8", "rll6"], + ["rll6", "rll9"], + ["rlr10", "rlr11"], + ["rlr8", "rlr12"], + ["rlr10", "rlr7"], + ["rll8", "rlm2"], + ["rll13", "rll11"], + ["rlr8", "rlr10"], + ["rlr12", "rlr13"], + ["rll12", "rll13"], + ["rlr13", "rlr10"], + ["rll12", "rll8"], + ["rlm3", "rll10"], + ["rlr12", "rlr9"], + ["rll9", "rll11"], + ["rll13", "rll10"], + ["rll9", "rll8"], + ["rll11", "rll10"], + ["rlr13", "rlr11"], + ["rll10", "rll8"], + ["rlr8", "rlr9"], + ["rlr11", "rlr9"], + + // Rear end + {"beamDeform" : 22000.0}, + ["rll14", "rll15"], + ["rlr14", "rlr16"], + ["rll18", "rll19"], + ["rlr13", "rlr15"], + ["rll19", "rll17"], + ["rll13", "rll15"], + ["rll14", "rll12"], + ["rll20", "rlm6"], + ["rlm7", "rll21"], + ["rll21", "rll19"], + ["rll20", "rll21"], + ["rll17", "rll15"], + ["rll16", "rll18"], + ["rll16", "rll17"], + ["rlr16", "rlr18"], + ["rlr14", "rlr15"], + ["rlr15", "rlm5"], + ["rlm4", "rlm5"], + ["rlr20", "rlr21"], + ["rlm7", "rlr21"], + ["rlm6", "rlm7"], + ["rlr18", "rlr20"], + ["rlr21", "rlr19"], + ["rlr17", "rlr15"], + ["rlr20", "rlm6"], + ["rll15", "rlm5"], + ["rlm4", "rll14"], + ["rlr18", "rlr19"], + ["rlr16", "rlr17"], + ["rlm4", "rlr14"], + ["rlr14", "rlr12"], + ["rlr19", "rlr17"], + ["rll18", "rll20"], + ["rll14", "rll16"], + + // Crossing beams + + // Front end + {"beamDeform" : 16000.0}, + ["rlr0", "rlm1"], + ["rll1", "rll2"], + ["rll7", "rll4"], + ["rll6", "rll5"], + ["rll4", "rll3"], + ["rll5", "rll2"], + ["rlr1", "rlm0"], + ["rlr0", "rlr3"], + ["rlr1", "rlr2"], + ["rlr4", "rlr3"], + ["rll0", "rll3"], + ["rll1", "rlm0"], + ["rll0", "rlm1"], + ["rlr5", "rlr2"], + ["rlr6", "rlr5"], + ["rlr7", "rlr4"], + + // Middle + {"beamDeform" : 6500.0}, + ["rll7", "rll9"], + ["rll6", "rll10"], + ["rlr7", "rlr8"], + ["rlr7", "rlr9"], + ["rlr6", "rlr11"], + ["rlr11", "rlm2"], + ["rlr9", "rlm3"], + ["rll13", "rll9"], + ["rll6", "rll11"], + ["rll7", "rll8"], + ["rlr12", "rlr10"], + ["rll12", "rll11"], + ["rll10", "rlm2"], + ["rlr12", "rlr11"], + ["rlr6", "rlr10"], + ["rlr13", "rlr8"], + ["rlr10", "rlr9"], + ["rll12", "rll10"], + ["rlr13", "rlr9"], + ["rll8", "rlm3"], + ["rll9", "rll10"], + ["rlr8", "rlr11"], + ["rll13", "rll8"], + ["rll11", "rll8"], + + // Rear end + {"beamDeform" : 16000.0}, + ["rlr21", "rlr18"], + ["rlr12", "rlr15"], + ["rlr15", "rlr16"], + ["rll21", "rlm6"], + ["rll13", "rll14"], + ["rll12", "rll15"], + ["rll19", "rll16"], + ["rlr20", "rlr19"], + ["rll21", "rll18"], + ["rll20", "rll19"], + ["rll14", "rll17"], + ["rll15", "rll16"], + ["rll15", "rlm4"], + ["rlr13", "rlr14"], + ["rlr14", "rlm5"], + ["rlr15", "rlm4"], + ["rlr20", "rlm7"], + ["rlr21", "rlm6"], + ["rlr18", "rlr17"], + ["rlr19", "rlr16"], + ["rlr14", "rlr17"], + ["rll14", "rlm5"], + ["rll20", "rlm7"], + ["rll18", "rll17"], + + // Support beams + + // Front end + {"beamDeform" : 19000.0}, + ["rll2", "rlsm"], + ["rlr2", "rlsm"], + ["rlsm", "rll0"], + ["rll4", "rlsm"], + ["rlsm", "rlr5"], + ["rlr1", "rlsm"], + ["rll1", "rlsm"], + ["rlr4", "rlsm"], + ["rlm0", "rlsm"], + ["rlsm", "rlr0"], + ["rlsm", "rll3"], + ["rlsm", "rlr3"], + ["rlsm", "rlm1"], + ["rlsm", "rll5"], + + // Middle + {"beamDeform" : 11000.0}, + ["rlr11", "rlsm1"], + ["rlr9", "rlsm1"], + ["rlm2", "rlsm1"], + ["rll10", "rlsm1"], + ["rll9", "rlsm1"], + ["rlsm1", "rll7"], + ["rlsm1", "rll6"], + ["rll13", "rlsm1"], + ["rlr13", "rlsm1"], + ["rlr8", "rlsm1"], + ["rlsm1", "rlm3"], + ["rll11", "rlsm1"], + ["rll8", "rlsm1"], + ["rlsm1", "rlr12"], + ["rlr10", "rlsm1"], + ["rlsm1", "rlr7"], + ["rlsm1", "rlr6"], + ["rlsm1", "rll12"], + + // Rear end + {"beamDeform" : 19000.0}, + ["rlsm2", "rlm6"], + ["rlsm2", "rlr21"], + ["rlr18", "rlsm2"], + ["rlsm2", "rll21"], + ["rlsm2", "rll17"], + ["rlsm2", "rlr19"], + ["rll20", "rlsm2"], + ["rlm5", "rlsm2"], + ["rlsm2", "rlr17"], + ["rll18", "rlsm2"], + ["rlr20", "rlsm2"], + ["rlm7", "rlsm2"], + ["rll16", "rlsm2"], + ["rlsm2", "rlm4"], + ["rlr16", "rlsm2"], + ["rlsm2", "rll19"], + + // Front crush + {"beamDeform" : 8500.0}, + ["rlr6", "rlr2"], + ["rll6", "rll2"] + ], + + // --Collision Triangles-- + "triangles" : [ + ["id1:", "id2:", "id3:"], + ["rlm0", "rll0", "rlm1"], + ["rll1", "rlm1", "rll0"], + ["rlm0", "rlm1", "rlr0"], + ["rlr1", "rlr0", "rlm1"], + ["rlr0", "rlr1", "rlr3"], + ["rlr0", "rlr3", "rlr2"], + ["rlr3", "rlr5", "rlr2"], + ["rlr4", "rlr2", "rlr5"], + ["rlr4", "rlr5", "rlr7"], + ["rlr7", "rlr6", "rlr4"], + ["rll0", "rll3", "rll1"], + ["rll0", "rll2", "rll3"], + ["rll4", "rll5", "rll2"], + ["rll3", "rll2", "rll5"], + ["rll4", "rll7", "rll5"], + ["rll7", "rll4", "rll6"], + ["rll6", "rll9", "rll7"], + ["rll11", "rll7", "rll9"], + ["rll12", "rll11", "rll9"], + ["rll13", "rll11", "rll12"], + ["rlr6", "rlr7", "rlr8"], + ["rlr10", "rlr8", "rlr7"], + ["rlr12", "rlr8", "rlr10"], + ["rlr13", "rlr12", "rlr10"], + ["rlr12", "rlr13", "rlr14"], + ["rlr14", "rlr13", "rlr15"], + ["rlr15", "rlr16", "rlr14"], + ["rlr17", "rlr16", "rlr15"], + ["rlr18", "rlr16", "rlr17"], + ["rlr19", "rlr18", "rlr17"], + ["rlr20", "rlr18", "rlr19"], + ["rlr21", "rlr20", "rlr19"], + ["rlr21", "rlm6", "rlr20"], + ["rlm6", "rlr21", "rlm7"], + ["rlm7", "rll21", "rlm6"], + ["rll21", "rll20", "rlm6"], + ["rll19", "rll18", "rll20"], + ["rll21", "rll19", "rll20"], + ["rll19", "rll17", "rll18"], + ["rll18", "rll17", "rll16"], + ["rll15", "rll14", "rll16"], + ["rll17", "rll15", "rll16"], + ["rll15", "rlm5", "rll14"], + ["rlm5", "rlm4", "rll14"], + ["rlm5", "rlr14", "rlm4"], + ["rlr14", "rlm5", "rlr15"], + ["rll12", "rll14", "rll13"], + ["rll14", "rll15", "rll13"], + ["rll7", "rll6", "rll8"], + ["rll7", "rll8", "rll10"], + ["rll10", "rll8", "rll11"], + ["rll11", "rll8", "rll9"], + ["rlr11", "rlr10", "rlr9"], + ["rlr10", "rlr8", "rlr9"], + ["rlr7", "rlr9", "rlr6"], + ["rlr11", "rlr9", "rlr7"], + ["rlm2", "rll8", "rll10"], + ["rlr11", "rlr9", "rlm2"], + ["rlm2", "rlm3", "rlr11"], + ["rlm2", "rll10", "rlm3"], + ["rll12", "rll10", "rll8"], + ["rll12", "rll13", "rll10"], + ["rlr9", "rlr11", "rlr12"], + ["rlr13", "rlr12", "rlr11"] + ], + "flexbodies" : [ + ["mesh", "[group]:", "nonFlexMaterials"], + [ + "rails", + ["chassis_rails"] + ] + ] + } +} \ No newline at end of file diff --git a/src-extra/transformation/Config.hs b/src-extra/transformation/Config.hs index bb51fc21..51c0413e 100644 --- a/src-extra/transformation/Config.hs +++ b/src-extra/transformation/Config.hs @@ -99,9 +99,9 @@ instance FromJSON TransformationConfig where <*> o .:? "x-group-breakpoints" .!= defaultBreakpoints <*> o .:? "support-threshold" .!= defaultSupportThreshold -loadTransformationConfig :: IO TransformationConfig -loadTransformationConfig = do - res <- decodeFileEither ".jbeam-edit.yaml" +loadTransformationConfig :: FilePath -> IO TransformationConfig +loadTransformationConfig filename = do + res <- decodeFileEither filename pure $ case res of Right tc -> tc Left _ -> diff --git a/test/TransformationSpec.hs b/test/TransformationSpec.hs index 40264a82..4168a732 100644 --- a/test/TransformationSpec.hs +++ b/test/TransformationSpec.hs @@ -13,22 +13,25 @@ import Formatting import Config import Data.Map qualified as M -topNodeSpec :: FilePath -> FilePath -> Spec -topNodeSpec inFilename outFilename = do +topNodeSpec :: String -> TransformationConfig -> FilePath -> FilePath -> Spec +topNodeSpec cfName tfConfig inFilename outFilename = do let inputPath = "examples/ast/jbeam/" ++ inFilename input <- runIO $ baseReadFile inputPath output <- runIO $ baseReadFile outFilename - let desc = "should transform AST in " ++ inFilename ++ " to Jbeam in " ++ outFilename + let desc = "with " ++ cfName ++ ": should transform AST in " ++ inFilename ++ " to Jbeam in " ++ outFilename describe desc . works $ - formatNode newRuleSet <$> transform M.empty newTransformationConfig (read input) `shouldBe` Right (toText output) + formatNode newRuleSet <$> transform M.empty tfConfig (read input) `shouldBe` Right (toText output) spec :: Spec spec = do + let exampleConfigPath = "examples/jbeam-edit.yaml" + tfConfig <- runIO $ loadTransformationConfig exampleConfigPath inputFiles <- runIO $ listFilesInDir "examples/ast/jbeam" - let outputFile inFile = "examples/transformed_jbeam/" ++ takeWhile (/= '.') inFile ++ ".jbeam" - testInputFile inFile = topNodeSpec inFile (outputFile inFile) - mapM_ testInputFile inputFiles + let outputFile cfName inFile = "examples/transformed_jbeam/" ++ takeWhile (/= '.') inFile ++ "-" ++ cfName ++ ".jbeam" + testInputFile cfName tfConfig' inFile = topNodeSpec cfName tfConfig' inFile (outputFile cfName inFile) + mapM_ (testInputFile "cfg-default" newTransformationConfig) inputFiles + mapM_ (testInputFile "cfg-example" tfConfig) inputFiles #else spec :: Spec spec = pass diff --git a/tools/dump_ast/Main.hs b/tools/dump_ast/Main.hs index 15c79d58..81241b12 100644 --- a/tools/dump_ast/Main.hs +++ b/tools/dump_ast/Main.hs @@ -19,7 +19,8 @@ import Data.Map qualified as M import System.IO qualified as IO (readFile) main :: IO () -main = +main = do + exampleCfg <- loadTransformationConfig "examples/jbeam-edit.yaml" let examplesDir = "examples" jbflInputDir = examplesDir "jbfl" jbeamInputDir = examplesDir "jbeam" @@ -43,7 +44,17 @@ main = | jbeamAST <- jbeamASTs , jbflAST <- jbflASTs ] - mapM_ (dumpTransformedJbeam jbeamAstDir transformedDir) jbeamFiles + mapM_ + ( dumpTransformedJbeam + "cfg-default" + newTransformationConfig + jbeamAstDir + transformedDir + ) + jbeamFiles + mapM_ + (dumpTransformedJbeam "cfg-example" exampleCfg jbeamAstDir transformedDir) + jbeamFiles saveDump :: String -> Text -> IO () saveDump outFile formatted = @@ -88,13 +99,14 @@ dumpFormattedJbeam outDir (jbeamFile, ruleFile) = do let outFile = outDir filename in saveDump outFile contents -dumpTransformedJbeam :: FilePath -> FilePath -> FilePath -> IO () -dumpTransformedJbeam jbeamInputAstDir outDir jbeamFile = do +dumpTransformedJbeam + :: String -> TransformationConfig -> FilePath -> FilePath -> FilePath -> IO () +dumpTransformedJbeam cfName tfConfig jbeamInputAstDir outDir jbeamFile = do jbeam <- read <$> IO.readFile (jbeamInputAstDir (takeBaseName jbeamFile <> ".hs")) - let outFilename = takeBaseName jbeamFile ++ ".jbeam" + let outFilename = takeBaseName jbeamFile ++ "-" ++ cfName ++ ".jbeam" transformedJbeam <- - case transform M.empty newTransformationConfig jbeam of + case transform M.empty tfConfig jbeam of Left err -> do putTextLn $ "error occurred during transformation" <> err exitFailure