Merge branch 'development' of
authorFabian Stemmler <stemmler@in.tum.de>
Sun, 15 Sep 2019 11:10:22 +0000 (13:10 +0200)
committerFabian Stemmler <stemmler@in.tum.de>
Sun, 15 Sep 2019 11:10:22 +0000 (13:10 +0200)
https://gitlab.lrz.de/lrr-tum/students/eragp-misim-2019.git into
development

Conflicts:
net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/standardComponentIDMapping.json

16 files changed:
net.mograsim.logic.model.am2900/components/net/mograsim/logic/model/am2900/components/Am2900.json
net.mograsim.logic.model.am2900/components/net/mograsim/logic/model/am2900/components/am2904/Am2904muSR.json
net.mograsim.logic.model.am2900/components/net/mograsim/logic/model/am2900/components/am2910/Am2910.json
net.mograsim.logic.model.am2900/components/net/mograsim/logic/model/am2900/components/dff4.json
net.mograsim.logic.model.am2900/components/net/mograsim/logic/model/am2900/components/dff4_invwe.json
net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/Am2900Machine.java
net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/standardComponentIDMapping.json
net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/ReserializeAndVerifyJSONs.java [new file with mode: 0644]
net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/ReserializeJSONs.java [deleted file]
net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/am2901/Am2901Testbench.java
net.mograsim.logic.model/src/net/mograsim/logic/model/model/LogicModel.java
net.mograsim.logic.model/src/net/mograsim/logic/model/model/wires/Pin.java
net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/IndirectModelComponentCreator.java
net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/StandardComponentIdMappingContainer.java [new file with mode: 0644]
net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/standardComponentIDMapping.json
net.mograsim.machine/src/net/mograsim/machine/standardComponentIDMapping.json

index 64c5b0b..b5a3458 100644 (file)
@@ -5,6 +5,78 @@
   "innerScale": 0.4,
   "submodel": {
     "components": [
+      {
+        "id": "ManualSwitch",
+        "name": "@bz_pc_cpol",
+        "pos": {
+          "x": 10.0,
+          "y": 405.0
+        },
+        "params": 1
+      },
+      {
+        "id": "ManualSwitch",
+        "name": "@c",
+        "pos": {
+          "x": 10.0,
+          "y": 320.0
+        },
+        "params": 1
+      },
+      {
+        "id": "ManualSwitch",
+        "name": "@d_in",
+        "pos": {
+          "x": 10.0,
+          "y": 240.0
+        },
+        "params": 16
+      },
+      {
+        "id": "ManualSwitch",
+        "name": "@d_in_enable",
+        "pos": {
+          "x": 10.0,
+          "y": 215.0
+        },
+        "params": 1
+      },
+      {
+        "id": "ManualSwitch",
+        "name": "@ireg_cpol",
+        "pos": {
+          "x": 10.0,
+          "y": 380.0
+        },
+        "params": 1
+      },
+      {
+        "id": "ManualSwitch",
+        "name": "@micro_instr",
+        "pos": {
+          "x": 10.0,
+          "y": 290.0
+        },
+        "params": 80
+      },
+      {
+        "id": "ManualSwitch",
+        "name": "@mireg_cpol",
+        "pos": {
+          "x": 10.0,
+          "y": 355.0
+        },
+        "params": 1
+      },
+      {
+        "id": "ManualSwitch",
+        "name": "@mprom_y",
+        "pos": {
+          "x": 10.0,
+          "y": 265.0
+        },
+        "params": 12
+      },
       {
         "id": "Am2901",
         "name": "Am2901#0",
         },
         "params": 12
       },
-      {
-        "id": "Clock",
-        "name": "Clock#0",
-        "pos": {
-          "x": 325.0,
-          "y": 310.0
-        },
-        "params": {
-          "delta": 1000,
-          "orientation": "DOWN"
-        }
-      },
       {
         "id": "FixedOutput",
         "name": "FixedOutput#0",
         }
       },
       {
-        "id": "ManualSwitch",
-        "name": "ManualSwitch#0",
+        "id": "NandGate",
+        "name": "NandGate#0",
         "pos": {
-          "x": 10.0,
-          "y": 315.0
+          "x": 285.0,
+          "y": 165.0
         },
         "params": 1
       },
       {
-        "id": "ManualSwitch",
-        "name": "ManualSwitch#1",
-        "pos": {
-          "x": 10.0,
-          "y": 290.0
-        },
-        "params": 80
-      },
-      {
-        "id": "ManualSwitch",
-        "name": "ManualSwitch#2",
-        "pos": {
-          "x": 10.0,
-          "y": 265.0
-        },
-        "params": 12
-      },
-      {
-        "id": "ManualSwitch",
-        "name": "ManualSwitch#3",
+        "id": "NandGate",
+        "name": "NandGate#1",
         "pos": {
-          "x": 10.0,
-          "y": 340.0
+          "x": 225.0,
+          "y": 135.0
         },
         "params": 1
       },
       {
-        "id": "ManualSwitch",
-        "name": "ManualSwitch#4",
+        "id": "NandGate",
+        "name": "NandGate#2",
         "pos": {
-          "x": 10.0,
-          "y": 365.0
+          "x": 285.0,
+          "y": 190.0
         },
         "params": 1
       },
       {
-        "id": "ManualSwitch",
-        "name": "ManualSwitch#5",
+        "id": "NandGate",
+        "name": "NandGate#3",
         "pos": {
-          "x": 10.0,
-          "y": 215.0
+          "x": 825.0,
+          "y": 655.0
         },
         "params": 1
       },
-      {
-        "id": "ManualSwitch",
-        "name": "ManualSwitch#6",
-        "pos": {
-          "x": 10.0,
-          "y": 240.0
-        },
-        "params": 16
-      },
       {
         "id": "NandGate",
-        "name": "NandGate#1",
+        "name": "NandGate#4",
         "pos": {
-          "x": 225.0,
-          "y": 135.0
+          "x": 825.0,
+          "y": 680.0
         },
         "params": 1
       },
       },
       {
         "id": "TextComponent",
-        "name": "TextComponent#2",
+        "name": "TextComponent#13",
+        "pos": {
+          "x": -55.0,
+          "y": 355.0
+        },
+        "params": "mireg cpol"
+      },
+      {
+        "id": "TextComponent",
+        "name": "TextComponent#14",
         "pos": {
           "x": -50.0,
-          "y": 165.0
+          "y": 380.0
         },
-        "params": "instr"
+        "params": "ireg cpol"
       },
       {
         "id": "TextComponent",
-        "name": "TextComponent#3",
+        "name": "TextComponent#15",
         "pos": {
           "x": -50.0,
-          "y": 290.0
+          "y": 405.0
         },
-        "params": "micro instr"
+        "params": "bz/pc cpol"
       },
       {
         "id": "TextComponent",
-        "name": "TextComponent#4",
+        "name": "TextComponent#2",
         "pos": {
           "x": -50.0,
-          "y": 315.0
+          "y": 165.0
         },
-        "params": "mireg c"
+        "params": "instr"
       },
       {
         "id": "TextComponent",
-        "name": "TextComponent#5",
+        "name": "TextComponent#3",
         "pos": {
           "x": -50.0,
-          "y": 265.0
+          "y": 290.0
         },
-        "params": "mprom y"
+        "params": "micro instr"
       },
       {
         "id": "TextComponent",
-        "name": "TextComponent#6",
+        "name": "TextComponent#4",
         "pos": {
           "x": -50.0,
-          "y": 340.0
+          "y": 320.0
         },
-        "params": "ireg c"
+        "params": "c"
       },
       {
         "id": "TextComponent",
-        "name": "TextComponent#7",
+        "name": "TextComponent#5",
         "pos": {
           "x": -50.0,
-          "y": 365.0
+          "y": 265.0
         },
-        "params": "bz/pc c"
+        "params": "mprom y"
       },
       {
         "id": "TextComponent",
         "name": "TriStateBuffer#3",
         "pos": {
           "x": 315.0,
-          "y": 125.0
+          "y": 115.0
         },
         "params": {
           "logicWidth": 16,
         },
         "params": 1
       },
+      {
+        "id": "WireCrossPoint",
+        "name": "WireCrossPoint#21",
+        "pos": {
+          "x": 279.0,
+          "y": 179.0
+        },
+        "params": 1
+      },
       {
         "id": "WireCrossPoint",
         "name": "WireCrossPoint#22",
         },
         "params": 16
       },
+      {
+        "id": "WireCrossPoint",
+        "name": "WireCrossPoint#24",
+        "pos": {
+          "x": 279.0,
+          "y": 194.0
+        },
+        "params": 1
+      },
+      {
+        "id": "WireCrossPoint",
+        "name": "WireCrossPoint#25",
+        "pos": {
+          "x": 819.0,
+          "y": 684.0
+        },
+        "params": 1
+      },
       {
         "id": "WireCrossPoint",
         "name": "WireCrossPoint#26",
         },
         "params": 1
       },
+      {
+        "id": "WireCrossPoint",
+        "name": "WireCrossPoint#32",
+        "pos": {
+          "x": 819.0,
+          "y": 669.0
+        },
+        "params": 1
+      },
       {
         "id": "WireCrossPoint",
         "name": "WireCrossPoint#4",
           "x": 515.0,
           "y": 210.0
         }
+      },
+      {
+        "id": "xor",
+        "name": "xor#0",
+        "pos": {
+          "x": 70.0,
+          "y": 350.0
+        }
+      },
+      {
+        "id": "xor",
+        "name": "xor#1",
+        "pos": {
+          "x": 70.0,
+          "y": 375.0
+        }
+      },
+      {
+        "id": "xor",
+        "name": "xor#2",
+        "pos": {
+          "x": 70.0,
+          "y": 400.0
+        }
       }
     ],
     "wires": [
           }
         ]
       },
+      {
+        "pin1": {
+          "compName": "@mireg_cpol",
+          "pinName": ""
+        },
+        "pin2": {
+          "compName": "xor#0",
+          "pinName": "B"
+        },
+        "name": "unnamedWire#100",
+        "path": []
+      },
+      {
+        "pin1": {
+          "compName": "xor#0",
+          "pinName": "Y"
+        },
+        "pin2": {
+          "compName": "dff80#0",
+          "pinName": "C"
+        },
+        "name": "unnamedWire#101",
+        "path": []
+      },
+      {
+        "pin1": {
+          "compName": "xor#1",
+          "pinName": "Y"
+        },
+        "pin2": {
+          "compName": "dff16_invwe#0",
+          "pinName": "C"
+        },
+        "name": "unnamedWire#102",
+        "path": [
+          {
+            "x": 145.0,
+            "y": 305.0
+          },
+          {
+            "x": 370.0,
+            "y": 305.0
+          },
+          {
+            "x": 370.0,
+            "y": 140.0
+          }
+        ]
+      },
+      {
+        "pin1": {
+          "compName": "WireCrossPoint#21",
+          "pinName": ""
+        },
+        "pin2": {
+          "compName": "NandGate#0",
+          "pinName": "B"
+        },
+        "name": "unnamedWire#103",
+        "path": []
+      },
+      {
+        "pin1": {
+          "compName": "WireCrossPoint#21",
+          "pinName": ""
+        },
+        "pin2": {
+          "compName": "NandGate#0",
+          "pinName": "A"
+        },
+        "name": "unnamedWire#104",
+        "path": [
+          {
+            "x": 280.0,
+            "y": 170.0
+          }
+        ]
+      },
+      {
+        "pin1": {
+          "compName": "Splitter#46",
+          "pinName": "O2"
+        },
+        "pin2": {
+          "compName": "WireCrossPoint#21",
+          "pinName": ""
+        },
+        "name": "unnamedWire#105",
+        "path": [
+          {
+            "x": 210.0,
+            "y": 180.0
+          }
+        ]
+      },
+      {
+        "pin1": {
+          "compName": "NandGate#0",
+          "pinName": "Y"
+        },
+        "pin2": {
+          "compName": "TriStateBuffer#2",
+          "pinName": "EN"
+        },
+        "name": "unnamedWire#106",
+        "path": [
+          {
+            "x": 340.0,
+            "y": 175.0
+          },
+          {
+            "x": 340.0,
+            "y": 110.0
+          },
+          {
+            "x": 325.0,
+            "y": 110.0
+          }
+        ]
+      },
+      {
+        "pin1": {
+          "compName": "WireCrossPoint#24",
+          "pinName": ""
+        },
+        "pin2": {
+          "compName": "NandGate#2",
+          "pinName": "A"
+        },
+        "name": "unnamedWire#107",
+        "path": []
+      },
+      {
+        "pin1": {
+          "compName": "WireCrossPoint#24",
+          "pinName": ""
+        },
+        "pin2": {
+          "compName": "NandGate#2",
+          "pinName": "B"
+        },
+        "name": "unnamedWire#108",
+        "path": [
+          {
+            "x": 280.0,
+            "y": 205.0
+          }
+        ]
+      },
+      {
+        "pin1": {
+          "compName": "WireCrossPoint#24",
+          "pinName": ""
+        },
+        "pin2": {
+          "compName": "Splitter#46",
+          "pinName": "O0"
+        },
+        "name": "unnamedWire#109",
+        "path": [
+          {
+            "x": 230.0,
+            "y": 195.0
+          }
+        ]
+      },
       {
         "pin1": {
           "compName": "Am2904#0",
           }
         ]
       },
+      {
+        "pin1": {
+          "compName": "NandGate#2",
+          "pinName": "Y"
+        },
+        "pin2": {
+          "compName": "TriStateBuffer#3",
+          "pinName": "EN"
+        },
+        "name": "unnamedWire#110",
+        "path": [
+          {
+            "x": 325.0,
+            "y": 200.0
+          }
+        ]
+      },
+      {
+        "pin1": {
+          "compName": "WireCrossPoint#25",
+          "pinName": ""
+        },
+        "pin2": {
+          "compName": "NandGate#4",
+          "pinName": "A"
+        },
+        "name": "unnamedWire#111",
+        "path": []
+      },
+      {
+        "pin1": {
+          "compName": "WireCrossPoint#25",
+          "pinName": ""
+        },
+        "pin2": {
+          "compName": "NandGate#4",
+          "pinName": "B"
+        },
+        "name": "unnamedWire#112",
+        "path": [
+          {
+            "x": 820.0,
+            "y": 695.0
+          }
+        ]
+      },
       {
         "pin1": {
           "compName": "Splitter#14",
         "name": "unnamedWire#118",
         "path": []
       },
+      {
+        "pin1": {
+          "compName": "WireCrossPoint#25",
+          "pinName": ""
+        },
+        "pin2": {
+          "compName": "Splitter#16",
+          "pinName": "O37"
+        },
+        "name": "unnamedWire#119",
+        "path": [
+          {
+            "x": 720.0,
+            "y": 685.0
+          },
+          {
+            "x": 720.0,
+            "y": 780.0
+          },
+          {
+            "x": 605.0,
+            "y": 780.0
+          }
+        ]
+      },
       {
         "pin1": {
           "compName": "Am2901#0",
             "y": 505.0
           },
           {
-            "x": 730.0,
-            "y": 595.0
+            "x": 730.0,
+            "y": 595.0
+          }
+        ]
+      },
+      {
+        "pin1": {
+          "compName": "NandGate#4",
+          "pinName": "Y"
+        },
+        "pin2": {
+          "compName": "TriStateBuffer#0",
+          "pinName": "EN"
+        },
+        "name": "unnamedWire#120",
+        "path": [
+          {
+            "x": 905.0,
+            "y": 690.0
+          },
+          {
+            "x": 905.0,
+            "y": 580.0
+          },
+          {
+            "x": 890.0,
+            "y": 580.0
+          }
+        ]
+      },
+      {
+        "pin1": {
+          "compName": "Splitter#16",
+          "pinName": "O38"
+        },
+        "pin2": {
+          "compName": "WireCrossPoint#32",
+          "pinName": ""
+        },
+        "name": "unnamedWire#121",
+        "path": [
+          {
+            "x": 615.0,
+            "y": 775.0
+          },
+          {
+            "x": 715.0,
+            "y": 775.0
+          },
+          {
+            "x": 715.0,
+            "y": 670.0
+          }
+        ]
+      },
+      {
+        "pin1": {
+          "compName": "WireCrossPoint#32",
+          "pinName": ""
+        },
+        "pin2": {
+          "compName": "NandGate#3",
+          "pinName": "B"
+        },
+        "name": "unnamedWire#122",
+        "path": []
+      },
+      {
+        "pin1": {
+          "compName": "WireCrossPoint#32",
+          "pinName": ""
+        },
+        "pin2": {
+          "compName": "NandGate#3",
+          "pinName": "A"
+        },
+        "name": "unnamedWire#123",
+        "path": [
+          {
+            "x": 820.0,
+            "y": 660.0
+          }
+        ]
+      },
+      {
+        "pin1": {
+          "compName": "TriStateBuffer#1",
+          "pinName": "EN"
+        },
+        "pin2": {
+          "compName": "NandGate#3",
+          "pinName": "Y"
+        },
+        "name": "unnamedWire#124",
+        "path": [
+          {
+            "x": 890.0,
+            "y": 665.0
           }
         ]
       },
         "path": [
           {
             "x": 310.0,
-            "y": 135.0
+            "y": 125.0
           }
         ]
       },
       {
         "pin1": {
-          "compName": "ManualSwitch#2",
+          "compName": "@mprom_y",
           "pinName": ""
         },
         "pin2": {
           }
         ]
       },
-      {
-        "pin1": {
-          "compName": "ManualSwitch#3",
-          "pinName": ""
-        },
-        "pin2": {
-          "compName": "dff16_invwe#0",
-          "pinName": "C"
-        },
-        "name": "unnamedWire#159",
-        "path": [
-          {
-            "x": 145.0,
-            "y": 305.0
-          },
-          {
-            "x": 370.0,
-            "y": 305.0
-          },
-          {
-            "x": 370.0,
-            "y": 140.0
-          }
-        ]
-      },
       {
         "pin1": {
           "compName": "and#0",
           }
         ]
       },
-      {
-        "pin1": {
-          "compName": "Splitter#46",
-          "pinName": "O2"
-        },
-        "pin2": {
-          "compName": "TriStateBuffer#2",
-          "pinName": "EN"
-        },
-        "name": "unnamedWire#163",
-        "path": [
-          {
-            "x": 210.0,
-            "y": 190.0
-          },
-          {
-            "x": 340.0,
-            "y": 190.0
-          },
-          {
-            "x": 340.0,
-            "y": 115.0
-          },
-          {
-            "x": 325.0,
-            "y": 115.0
-          }
-        ]
-      },
       {
         "pin1": {
           "compName": "Splitter#16",
       },
       {
         "pin1": {
-          "compName": "ManualSwitch#0",
-          "pinName": ""
-        },
-        "pin2": {
-          "compName": "dff80#0",
-          "pinName": "C"
-        },
-        "name": "unnamedWire#241",
-        "path": []
-      },
-      {
-        "pin1": {
-          "compName": "ManualSwitch#1",
+          "compName": "@micro_instr",
           "pinName": ""
         },
         "pin2": {
       },
       {
         "pin1": {
-          "compName": "WireCrossPoint#20",
+          "compName": "@c",
           "pinName": ""
         },
         "pin2": {
-          "compName": "Clock#0",
+          "compName": "WireCrossPoint#20",
           "pinName": ""
         },
         "name": "unnamedWire#25",
         "path": [
           {
             "x": 345.0,
-            "y": 135.0
+            "y": 125.0
           }
         ]
       },
           }
         ]
       },
-      {
-        "pin1": {
-          "compName": "Splitter#46",
-          "pinName": "O0"
-        },
-        "pin2": {
-          "compName": "TriStateBuffer#3",
-          "pinName": "EN"
-        },
-        "name": "unnamedWire#292",
-        "path": [
-          {
-            "x": 230.0,
-            "y": 195.0
-          },
-          {
-            "x": 325.0,
-            "y": 195.0
-          }
-        ]
-      },
-      {
-        "pin1": {
-          "compName": "Splitter#16",
-          "pinName": "O37"
-        },
-        "pin2": {
-          "compName": "TriStateBuffer#0",
-          "pinName": "EN"
-        },
-        "name": "unnamedWire#293",
-        "path": [
-          {
-            "x": 605.0,
-            "y": 780.0
-          },
-          {
-            "x": 720.0,
-            "y": 780.0
-          },
-          {
-            "x": 720.0,
-            "y": 685.0
-          },
-          {
-            "x": 905.0,
-            "y": 685.0
-          },
-          {
-            "x": 905.0,
-            "y": 580.0
-          },
-          {
-            "x": 890.0,
-            "y": 580.0
-          }
-        ]
-      },
-      {
-        "pin1": {
-          "compName": "TriStateBuffer#1",
-          "pinName": "EN"
-        },
-        "pin2": {
-          "compName": "Splitter#16",
-          "pinName": "O38"
-        },
-        "name": "unnamedWire#294",
-        "path": [
-          {
-            "x": 890.0,
-            "y": 680.0
-          },
-          {
-            "x": 715.0,
-            "y": 680.0
-          },
-          {
-            "x": 715.0,
-            "y": 775.0
-          },
-          {
-            "x": 615.0,
-            "y": 775.0
-          }
-        ]
-      },
       {
         "pin1": {
           "compName": "Splitter#48",
           }
         ]
       },
-      {
-        "pin1": {
-          "compName": "dff16#0",
-          "pinName": "C"
-        },
-        "pin2": {
-          "compName": "ManualSwitch#4",
-          "pinName": ""
-        },
-        "name": "unnamedWire#331",
-        "path": [
-          {
-            "x": 255.0,
-            "y": 80.0
-          },
-          {
-            "x": 255.0,
-            "y": 240.0
-          },
-          {
-            "x": 135.0,
-            "y": 240.0
-          }
-        ]
-      },
       {
         "pin1": {
           "compName": "WireCrossPoint#29",
       },
       {
         "pin1": {
-          "compName": "ManualSwitch#5",
+          "compName": "@d_in_enable",
           "pinName": ""
         },
         "pin2": {
           "pinName": "IN"
         },
         "pin2": {
-          "compName": "ManualSwitch#6",
+          "compName": "@d_in",
           "pinName": ""
         },
         "name": "unnamedWire#335",
           "pinName": "C"
         },
         "name": "unnamedWire#34",
-        "path": []
+        "path": [
+          {
+            "x": 335.0,
+            "y": 335.0981951658187
+          }
+        ]
       },
       {
         "pin1": {
         },
         "name": "unnamedWire#93",
         "path": []
+      },
+      {
+        "pin1": {
+          "compName": "xor#2",
+          "pinName": "Y"
+        },
+        "pin2": {
+          "compName": "dff16#0",
+          "pinName": "C"
+        },
+        "name": "unnamedWire#94",
+        "path": [
+          {
+            "x": 135.0,
+            "y": 240.0
+          },
+          {
+            "x": 255.0,
+            "y": 240.0
+          },
+          {
+            "x": 255.0,
+            "y": 80.0
+          }
+        ]
+      },
+      {
+        "pin1": {
+          "compName": "@bz_pc_cpol",
+          "pinName": ""
+        },
+        "pin2": {
+          "compName": "xor#2",
+          "pinName": "B"
+        },
+        "name": "unnamedWire#95",
+        "path": []
+      },
+      {
+        "pin1": {
+          "compName": "@c",
+          "pinName": ""
+        },
+        "pin2": {
+          "compName": "xor#2",
+          "pinName": "A"
+        },
+        "name": "unnamedWire#96",
+        "path": []
+      },
+      {
+        "pin1": {
+          "compName": "xor#1",
+          "pinName": "B"
+        },
+        "pin2": {
+          "compName": "@ireg_cpol",
+          "pinName": ""
+        },
+        "name": "unnamedWire#97",
+        "path": []
+      },
+      {
+        "pin1": {
+          "compName": "xor#1",
+          "pinName": "A"
+        },
+        "pin2": {
+          "compName": "@c",
+          "pinName": ""
+        },
+        "name": "unnamedWire#98",
+        "path": []
+      },
+      {
+        "pin1": {
+          "compName": "xor#0",
+          "pinName": "A"
+        },
+        "pin2": {
+          "compName": "@c",
+          "pinName": ""
+        },
+        "name": "unnamedWire#99",
+        "path": []
       }
     ],
     "version": "0.1.1"
index 3b859b2..2949d8d 100644 (file)
           }
         ]
       },
-      {
-        "pin1": {
-          "compName": "WireCrossPoint#3",
-          "pinName": ""
-        },
-        "pin2": {
-          "compName": "WireCrossPoint#3",
-          "pinName": ""
-        },
-        "name": "unnamedWire#33",
-        "path": []
-      },
       {
         "pin1": {
           "compName": "WireCrossPoint#3",
           "compName": "NandGate#1",
           "pinName": "B"
         },
-        "name": "unnamedWire#34",
+        "name": "unnamedWire#33",
         "path": [
           {
             "x": 225.0,
           "compName": "xor#0",
           "pinName": "A"
         },
-        "name": "unnamedWire#35",
+        "name": "unnamedWire#34",
         "path": [
           {
             "x": 125.0,
           "compName": "xor#0",
           "pinName": "B"
         },
-        "name": "unnamedWire#36",
+        "name": "unnamedWire#35",
         "path": [
           {
             "x": 105.0,
           "compName": "_submodelinterface",
           "pinName": "_EZ"
         },
-        "name": "unnamedWire#37",
+        "name": "unnamedWire#36",
         "path": [
           {
             "x": 180.0,
           "compName": "dff4_finewe#0",
           "pinName": "C"
         },
-        "name": "unnamedWire#38",
+        "name": "unnamedWire#37",
         "path": [
           {
             "x": 55.0,
           "compName": "dff4_finewe#0",
           "pinName": "_WE4"
         },
-        "name": "unnamedWire#39",
+        "name": "unnamedWire#38",
         "path": [
           {
             "x": 200.0,
       },
       {
         "pin1": {
-          "compName": "Splitter#3",
-          "pinName": "I"
+          "compName": "dff4_finewe#0",
+          "pinName": "_WE3"
         },
         "pin2": {
           "compName": "_submodelinterface",
-          "pinName": "Q"
+          "pinName": "_EN"
         },
-        "name": "unnamedWire#4",
+        "name": "unnamedWire#39",
         "path": [
           {
-            "x": 245.0,
-            "y": 45.0
+            "x": 170.0,
+            "y": 60.0
           },
           {
-            "x": 245.0,
-            "y": 50.0
+            "x": 170.0,
+            "y": 15.0
+          },
+          {
+            "x": 150.0,
+            "y": 15.0
           }
         ]
       },
       {
         "pin1": {
-          "compName": "dff4_finewe#0",
-          "pinName": "_WE3"
+          "compName": "Splitter#3",
+          "pinName": "I"
         },
         "pin2": {
           "compName": "_submodelinterface",
-          "pinName": "_EN"
+          "pinName": "Q"
         },
-        "name": "unnamedWire#40",
+        "name": "unnamedWire#4",
         "path": [
           {
-            "x": 170.0,
-            "y": 60.0
-          },
-          {
-            "x": 170.0,
-            "y": 15.0
+            "x": 245.0,
+            "y": 45.0
           },
           {
-            "x": 150.0,
-            "y": 15.0
+            "x": 245.0,
+            "y": 50.0
           }
         ]
       },
           "compName": "dff4_finewe#0",
           "pinName": "_WE2"
         },
-        "name": "unnamedWire#41",
+        "name": "unnamedWire#40",
         "path": [
           {
             "x": 100.0,
           "compName": "mux1_4#1",
           "pinName": "Y1"
         },
-        "name": "unnamedWire#42",
+        "name": "unnamedWire#41",
         "path": []
       },
       {
           "compName": "dff4_finewe#0",
           "pinName": "D2"
         },
-        "name": "unnamedWire#43",
+        "name": "unnamedWire#42",
         "path": [
           {
             "x": 170.0,
           "compName": "mux1_4#1",
           "pinName": "Y3"
         },
-        "name": "unnamedWire#44",
+        "name": "unnamedWire#43",
         "path": []
       },
       {
           "compName": "mux1_4#1",
           "pinName": "Y4"
         },
-        "name": "unnamedWire#45",
+        "name": "unnamedWire#44",
         "path": [
           {
             "x": 115.0,
           "compName": "dff4_finewe#0",
           "pinName": "D4"
         },
-        "name": "unnamedWire#46",
+        "name": "unnamedWire#45",
         "path": [
           {
             "x": 180.0,
           "compName": "NandGate#2",
           "pinName": "A"
         },
-        "name": "unnamedWire#47",
+        "name": "unnamedWire#46",
         "path": []
       },
       {
           "compName": "NandGate#2",
           "pinName": "B"
         },
-        "name": "unnamedWire#48",
+        "name": "unnamedWire#47",
         "path": [
           {
             "x": 115.0,
           "compName": "mux1_4#0",
           "pinName": "I0_1"
         },
-        "name": "unnamedWire#49",
+        "name": "unnamedWire#48",
         "path": [
           {
             "x": 20.0,
index b1bc97f..9a6e0ba 100644 (file)
           "pinName": "_RLD"
         },
         "name": "unnamedWire#26",
-        "path": []
+        "path": [
+          {
+            "x": 50.0,
+            "y": 25.0
+          },
+          {
+            "x": 50.0,
+            "y": 20.0
+          }
+        ]
       },
       {
         "pin1": {
index 99b9a91..02286a9 100644 (file)
           }
         ]
       },
-      {
-        "pin1": {
-          "compName": "WireCrossPoint#6",
-          "pinName": ""
-        },
-        "pin2": {
-          "compName": "WireCrossPoint#6",
-          "pinName": ""
-        },
-        "name": "unnamedWire#27",
-        "path": []
-      },
       {
         "pin1": {
           "compName": "WireCrossPoint#6",
           "compName": "mux1_4#0",
           "pinName": "I0_4"
         },
-        "name": "unnamedWire#28",
+        "name": "unnamedWire#27",
         "path": [
           {
             "x": 155.0,
index 9a18841..704948e 100644 (file)
           }
         ]
       },
-      {
-        "pin1": {
-          "compName": "WireCrossPoint#6",
-          "pinName": ""
-        },
-        "pin2": {
-          "compName": "WireCrossPoint#6",
-          "pinName": ""
-        },
-        "name": "unnamedWire#27",
-        "path": []
-      },
       {
         "pin1": {
           "compName": "WireCrossPoint#6",
           "compName": "mux1_4#0",
           "pinName": "I1_4"
         },
-        "name": "unnamedWire#28",
+        "name": "unnamedWire#27",
         "path": [
           {
             "x": 155.0,
index 8470343..5aa348c 100644 (file)
@@ -5,6 +5,8 @@ import net.mograsim.logic.core.timeline.Timeline;
 import net.mograsim.logic.core.types.BitVector;
 import net.mograsim.logic.model.model.LogicModel;
 import net.mograsim.logic.model.model.LogicModelModifiable;
+import net.mograsim.logic.model.model.components.atomic.ModelClock;
+import net.mograsim.logic.model.model.components.atomic.ModelManualSwitch;
 import net.mograsim.logic.model.modeladapter.CoreModelParameters;
 import net.mograsim.logic.model.modeladapter.LogicCoreAdapter;
 import net.mograsim.logic.model.serializing.IndirectModelComponentCreator;
@@ -30,13 +32,14 @@ public class Am2900Machine implements Machine
                this.machineDefinition = am2900MachineDefinition;
                logicModel = new LogicModelModifiable();
                IndirectModelComponentCreator.createComponent(logicModel,
-                               "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/Am2900.json");
+                               "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/Am2900.json", "Am2900");
                CoreModelParameters params = new CoreModelParameters();
                params.gateProcessTime = 50;
                params.wireTravelTime = 10;
                mainMemory = new WordAddressableMemory(am2900MachineDefinition.getMainMemoryDefinition());
                instMemory = new StandardMicroInstructionMemory(am2900MachineDefinition.getMicroInstructionMemoryDefinition());
                timeline = LogicCoreAdapter.convert(logicModel, params);
+               logicModel.getComponentByPath("Am2900.@c", ModelManualSwitch.class).getManualSwitch();
        }
 
        @Override
index c0bce38..e042b3c 100644 (file)
@@ -1,65 +1,66 @@
-mograsim version: 0.1.3
 {
-  "Am2900MainMemory": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.ModelAm2900MainMemory",
-  "Am2900MicroInstructionMemory": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.ModelAm2900MicroInstructionMemory",
-  "Am2904RegCTInstrDecode": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.am2904.ModelAm2904RegCTInstrDecode",
-  "Am2904ShiftInstrDecode": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.am2904.ModelAm2904ShiftInstrDecode",
-  "Am2910InstrPLA": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.am2910.ModelAm2910InstrPLA",
-  "Am2910RegCntr": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.am2910.ModelAm2910RegCntr",
-  "Am2910SP": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.am2910.ModelAm2910SP",
-  "dff12": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.Modeldff12",
-  "dff4_finewe": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.Modeldff4_finewe",
-  "inc": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.Modelinc",
-  "nor12": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.Modelnor12",
-  "ram5_12": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.Modelram5_12",
-  "sel4_12": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.Modelsel4_12",
-  
-  "Am2900": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/Am2900.json",
-  "Am2901": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/am2901/Am2901.json",
-  "Am2901ALUFuncDecode": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/am2901/Am2901ALUFuncDecode.json",
-  "Am2901ALUInclDecode": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/am2901/Am2901ALUInclDecode.json",
-  "Am2901ALUInclSourceDecodeInclFunctionDecode": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/am2901/Am2901ALUInclSourceDecodeInclFunctionDecode.json",
-  "Am2901ALUOneBit": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/am2901/Am2901ALUOneBit.json",
-  "Am2904": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/am2904/Am2904.json",
-  "Am2910": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/am2910/Am2910.json",
-  "Am2904MSR": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/am2904/Am2904MSR.json",
-  "Am2904muSR": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/am2904/Am2904muSR.json",
-  "Am2904TestLogic": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/am2904/Am2904TestLogic.json",
-  "Am2901DestDecode": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/am2901/Am2901DestDecode.json",
-  "Am2901SourceDecode": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/am2901/Am2901SourceDecode.json",
-  "_rsLatch": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/_rsLatch.json",
-  "and": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/and.json",
-  "and41": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/and41.json",
-  "andor414": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/andor414.json",
-  "demux2": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/demux2.json",
-  "dff": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/dff.json",
-  "dff4": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/dff4.json",
-  "dff4_invwe": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/dff4_invwe.json",
-  "dff8": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/dff8.json",
-  "dff12_we": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/dff12_we.json",
-  "dff16": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/dff16.json",
-  "dff16_we": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/dff16_we.json",
-  "dff16_invwe": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/dff16_invwe.json",
-  "dff80": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/dff80.json",
-  "dlatch": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/dlatch.json",
-  "dlatch4": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/dlatch4.json",
-  "fulladder": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/fulladder.json",
-  "halfadder": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/halfadder.json",
-  "mux1": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/mux1.json",
-  "mux1_4": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/mux1_4.json",
-  "mux1_8": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/mux1_8.json",
-  "mux1_12": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/mux1_12.json",
-  "mux1_16": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/mux1_16.json",
-  "mux2": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/mux2.json",
-  "mux3": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/mux3.json",
-  "nand3": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/nand3.json",
-  "not4": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/not4.json",
-  "or4": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/or4.json",
-  "or_4": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/or_4.json",
-  "ram2": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/ram2.json",
-  "ram4": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/ram4.json",
-  "sel1": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/sel1.json",
-  "sel2_4": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/sel2_4.json",
-  "sel3_4": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/sel3_4.json",
-  "xor": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/xor.json"
+  "version": "0.1.0",
+  "map": {
+       "Am2900MainMemory": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.ModelAm2900MainMemory",
+       "Am2900MicroInstructionMemory": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.ModelAm2900MicroInstructionMemory",
+    "Am2904RegCTInstrDecode": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.am2904.ModelAm2904RegCTInstrDecode",
+    "Am2904ShiftInstrDecode": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.am2904.ModelAm2904ShiftInstrDecode",
+    "Am2910InstrPLA": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.am2910.ModelAm2910InstrPLA",
+    "Am2910RegCntr": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.am2910.ModelAm2910RegCntr",
+    "Am2910SP": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.am2910.ModelAm2910SP",
+    "dff12": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.Modeldff12",
+    "dff4_finewe": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.Modeldff4_finewe",
+    "inc": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.Modelinc",
+    "nor12": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.Modelnor12",
+    "ram5_12": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.Modelram5_12",
+    "sel4_12": "resloader:Am2900Loader:class:net.mograsim.logic.model.am2900.components.Modelsel4_12",
+    "Am2900": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/Am2900.json",
+    "Am2901": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/am2901/Am2901.json",
+    "Am2901ALUFuncDecode": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/am2901/Am2901ALUFuncDecode.json",
+    "Am2901ALUInclDecode": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/am2901/Am2901ALUInclDecode.json",
+    "Am2901ALUInclSourceDecodeInclFunctionDecode": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/am2901/Am2901ALUInclSourceDecodeInclFunctionDecode.json",
+    "Am2901ALUOneBit": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/am2901/Am2901ALUOneBit.json",
+    "Am2904": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/am2904/Am2904.json",
+    "Am2910": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/am2910/Am2910.json",
+    "Am2904MSR": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/am2904/Am2904MSR.json",
+    "Am2904muSR": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/am2904/Am2904muSR.json",
+    "Am2904TestLogic": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/am2904/Am2904TestLogic.json",
+    "Am2901DestDecode": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/am2901/Am2901DestDecode.json",
+    "Am2901SourceDecode": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/am2901/Am2901SourceDecode.json",
+    "_rsLatch": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/_rsLatch.json",
+    "and": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/and.json",
+    "and41": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/and41.json",
+    "andor414": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/andor414.json",
+    "demux2": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/demux2.json",
+    "dff": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/dff.json",
+    "dff4": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/dff4.json",
+    "dff4_invwe": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/dff4_invwe.json",
+    "dff8": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/dff8.json",
+    "dff12_we": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/dff12_we.json",
+    "dff16": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/dff16.json",
+    "dff16_we": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/dff16_we.json",
+    "dff16_invwe": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/dff16_invwe.json",
+    "dff80": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/dff80.json",
+    "dlatch": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/dlatch.json",
+    "dlatch4": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/dlatch4.json",
+    "fulladder": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/fulladder.json",
+    "halfadder": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/halfadder.json",
+    "mux1": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/mux1.json",
+    "mux1_4": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/mux1_4.json",
+    "mux1_8": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/mux1_8.json",
+    "mux1_12": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/mux1_12.json",
+    "mux1_16": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/mux1_16.json",
+    "mux2": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/mux2.json",
+    "mux3": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/mux3.json",
+    "nand3": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/nand3.json",
+    "not4": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/not4.json",
+    "or4": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/or4.json",
+    "or_4": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/or_4.json",
+    "ram2": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/ram2.json",
+    "ram4": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/ram4.json",
+    "sel1": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/sel1.json",
+    "sel2_4": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/sel2_4.json",
+    "sel3_4": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/sel3_4.json",
+    "xor": "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/xor.json"
+  }
 }
\ No newline at end of file
diff --git a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/ReserializeAndVerifyJSONs.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/ReserializeAndVerifyJSONs.java
new file mode 100644 (file)
index 0000000..f34bf34
--- /dev/null
@@ -0,0 +1,363 @@
+package net.mograsim.logic.model.examples;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Optional;
+import java.util.Scanner;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
+import net.mograsim.logic.model.am2900.Am2900Loader;
+import net.mograsim.logic.model.model.LogicModelModifiable;
+import net.mograsim.logic.model.model.components.ModelComponent;
+import net.mograsim.logic.model.model.components.submodels.SubmodelComponent;
+import net.mograsim.logic.model.model.components.submodels.SubmodelInterface;
+import net.mograsim.logic.model.model.wires.ModelWire;
+import net.mograsim.logic.model.model.wires.ModelWireCrossPoint;
+import net.mograsim.logic.model.model.wires.MovablePin;
+import net.mograsim.logic.model.model.wires.Pin;
+import net.mograsim.logic.model.model.wires.PinUsage;
+import net.mograsim.logic.model.serializing.DeserializedSubmodelComponent;
+import net.mograsim.logic.model.serializing.IdentifyParams;
+import net.mograsim.logic.model.serializing.IndirectModelComponentCreator;
+import net.mograsim.logic.model.serializing.SubmodelComponentSerializer;
+import net.mograsim.logic.model.snippets.highlevelstatehandlers.DefaultHighLevelStateHandler;
+
+public class ReserializeAndVerifyJSONs
+{
+       public static double GRIDSIZE = 2.5;
+       public static boolean changePinUsages = false;
+       public static boolean changeComponentNames = false;
+       public static boolean snapWCPs = true;
+       public static boolean warnNonSnappedPoints = true;
+       public static boolean warnNonVertHorizLines = true;
+       public static boolean warnRedundantWires = true;
+
+       public static void main(String[] args) throws IOException
+       {
+               Am2900Loader.setup();
+               try (Scanner sysin = new Scanner(System.in))
+               {
+                       System.out.print("Directory to search for JSONs in / JSON file to reserialize >");
+                       Path root = Paths.get(sysin.nextLine());
+                       if (!Files.exists(root))
+                               throw new IllegalArgumentException("Path doesn't exist");
+                       if (Files.isRegularFile(root))
+                               reserializeJSON(root, sysin);
+                       else
+                       {
+                               System.out.print("Recursive? >");
+                               boolean recursive = Boolean.valueOf(sysin.nextLine());
+                               try (Stream<Path> jsons = recursive ? Files.walk(root) : Files.list(root))
+                               {
+                                       jsons.filter(Files::isRegularFile).filter(p -> p.getFileName().toString().endsWith(".json"))
+                                                       .forEach(j -> reserializeJSON(j, sysin));
+                               }
+                       }
+               }
+       }
+
+       public static void reserializeJSON(Path componentPath, Scanner sysin)
+       {
+               try
+               {
+                       DeserializedSubmodelComponent comp = (DeserializedSubmodelComponent) IndirectModelComponentCreator
+                                       .createComponent(new LogicModelModifiable(), "jsonfile:" + componentPath.toString());
+                       System.out.println("Reserializing " + componentPath);
+                       LogicModelModifiable submodelModifiable = comp.getSubmodelModifiable();
+                       Map<String, String> componentNameRemapping = new HashMap<>();
+
+                       if (changePinUsages)
+                               changePinUsages(sysin, comp);
+                       if (changeComponentNames)
+                               changeComponentNames(sysin, submodelModifiable, componentNameRemapping);
+                       if (snapWCPs)
+                               snapWCPs(submodelModifiable);
+                       if (warnNonSnappedPoints)
+                               warnNonSnappedPoints(comp, submodelModifiable);
+                       if (warnNonVertHorizLines)
+                               warnNonVertHorizLines(submodelModifiable);
+                       if (warnRedundantWires)
+                               warnRedundantWires(submodelModifiable);
+
+                       SubmodelComponentSerializer.serialize(comp, componentPath.toString());
+
+                       if (changeComponentNames)
+                               changeComponentNames_AfterSerialization(sysin, comp, componentNameRemapping);
+               }
+               catch (Exception e)
+               {
+                       System.err.println("An error occurred visiting " + componentPath + ":");
+                       e.printStackTrace();
+               }
+       }
+
+       private static void warnRedundantWires(LogicModelModifiable submodelModifiable)
+       {
+               Map<Pin, Set<Pin>> connectedPinGroups = new HashMap<>();
+               submodelModifiable.getComponentsByName().values().stream().map(ModelComponent::getPins).map(Map::values).flatMap(Collection::stream)
+                               .forEach(p -> connectedPinGroups.put(p, new HashSet<>(Arrays.asList(p))));
+               submodelModifiable.getWiresByName().values().forEach(w ->
+               {
+                       Pin pin1 = w.getPin1();
+                       Pin pin2 = w.getPin2();
+                       Set<Pin> pin1Group = connectedPinGroups.get(pin1);
+                       Set<Pin> pin2Group = connectedPinGroups.get(pin2);
+                       if (pin1Group == pin2Group)
+                               System.out.println("  Wire " + w.name + " connecting " + pin1 + " and " + pin2 + " is redundant");
+                       else
+                       {
+                               pin1Group.addAll(pin2Group);
+                               pin2Group.forEach(p -> connectedPinGroups.put(p, pin1Group));
+                       }
+               });
+       }
+
+       private static void changePinUsages(Scanner sysin, DeserializedSubmodelComponent comp)
+       {
+               comp.getSupermodelPins().entrySet().stream().sorted(Comparator.comparing(Entry::getKey)).map(Entry::getValue).forEach(pin ->
+               {
+                       PinUsage usage = null;
+                       while (usage == null)
+                               try
+                               {
+                                       System.out.print("  Usage for interface pin " + pin.name + " (empty: " + pin.usage + ") >");
+                                       String usageStr = sysin.nextLine().toUpperCase();
+                                       usage = usageStr.equals("") ? pin.usage
+                                                       : usageStr.equals("I") ? PinUsage.INPUT
+                                                                       : usageStr.equals("O") ? PinUsage.OUTPUT
+                                                                                       : usageStr.equals("T") ? PinUsage.TRISTATE : PinUsage.valueOf(usageStr);
+                               }
+                               catch (@SuppressWarnings("unused") IllegalArgumentException e)
+                               {
+                                       System.err.println("  Illegal usage");
+                               }
+                       setInterfacePinUsage(comp, pin, usage);
+               });
+       }
+
+       private static void changeComponentNames(Scanner sysin, LogicModelModifiable submodelModifiable,
+                       Map<String, String> componentNameRemapping)
+       {
+               componentNameRemapping.put(SubmodelComponent.SUBMODEL_INTERFACE_NAME, SubmodelComponent.SUBMODEL_INTERFACE_NAME);
+               LogicModelModifiable tempModel = new LogicModelModifiable();
+               IdentifyParams iP = new IdentifyParams();
+               submodelModifiable.getComponentsByName().entrySet().stream()
+                               .filter(e -> !e.getKey().equals(SubmodelComponent.SUBMODEL_INTERFACE_NAME))
+                               .sorted(Comparator.comparing(Entry::getKey, ReserializeAndVerifyJSONs::compareStringsWithIntegers)).forEach(e ->
+                               {
+                                       String oldName = e.getKey();
+                                       ModelComponent subcomp = e.getValue();
+                                       String defaultName = tempModel.getDefaultComponentName(subcomp);
+                                       String newName = null;
+                                       while (newName == null)
+                                       {
+                                               System.out.print("  New name for component " + oldName + " of type " + subcomp.getIDForSerializing(iP) + " (empty: "
+                                                               + defaultName + ") >");
+                                               newName = sysin.nextLine();
+                                               if (newName.equals(""))
+                                                       newName = defaultName;
+                                               if (tempModel.getComponentsByName().containsKey(newName))
+                                               {
+                                                       System.err.println("  There already is a component with that name");
+                                                       newName = null;
+                                               }
+                                       }
+                                       componentNameRemapping.put(oldName, newName);
+                                       IndirectModelComponentCreator
+                                                       .createComponent(tempModel, subcomp.getIDForSerializing(iP), subcomp.getParamsForSerializingJSON(iP), newName)
+                                                       .moveTo(subcomp.getPosX(), subcomp.getPosY());
+                               });
+               SubmodelInterface tempSubmodelInterface = new SubmodelInterface(tempModel);
+               for (Pin p : submodelModifiable.getComponentsByName().get(SubmodelComponent.SUBMODEL_INTERFACE_NAME).getPins().values())
+                       tempSubmodelInterface
+                                       .addPin(new Pin(tempModel, tempSubmodelInterface, p.name, p.logicWidth, p.usage, p.getRelX(), p.getRelY()));
+               for (ModelWire w : submodelModifiable.getWiresByName().values())
+                       createWire(componentNameRemapping::get, tempModel, w);
+
+               Optional<ModelComponent> o;
+               while ((o = submodelModifiable.getComponentsByName().values().stream()
+                               .filter(c -> !c.getName().equals(SubmodelComponent.SUBMODEL_INTERFACE_NAME)).findAny()).isPresent())
+                       submodelModifiable.destroyComponent(o.get());
+
+               tempModel.getComponentsByName().values().stream().filter(c -> !c.getName().equals(SubmodelComponent.SUBMODEL_INTERFACE_NAME))
+                               .forEach(c -> IndirectModelComponentCreator
+                                               .createComponent(submodelModifiable, c.getIDForSerializing(iP), c.getParamsForSerializingJSON(iP), c.getName())
+                                               .moveTo(c.getPosX(), c.getPosY()));
+               for (ModelWire w : tempModel.getWiresByName().values())
+                       createWire(Function.identity(), submodelModifiable, w);
+       }
+
+       private static void changeComponentNames_AfterSerialization(Scanner sysin, DeserializedSubmodelComponent comp,
+                       Map<String, String> componentNameRemapping)
+       {
+               if (comp.getHighLevelStateHandler() == null || !(comp.getHighLevelStateHandler() instanceof DefaultHighLevelStateHandler))
+               {
+                       System.out.println("  A non-default HighLevelStateHandler was detected. Check for changes there manually.");
+                       System.out.print("  Empty line to continue to next component, old component name to get new component name >");
+                       for (String line = sysin.nextLine(); !line.equals(""); line = sysin.nextLine())
+                               System.out.println("  " + line + "->" + componentNameRemapping.get(line) + " >");
+               }
+       }
+
+       private static void snapWCPs(LogicModelModifiable submodelModifiable)
+       {
+               submodelModifiable.getComponentsByName().values().stream().filter(c -> c instanceof ModelWireCrossPoint).forEach(c ->
+               {
+                       double x = c.getPosX();
+                       double y = c.getPosY();
+                       double newX = x % GRIDSIZE == 0 ? x - 1 : x;
+                       double newY = y % GRIDSIZE == 0 ? y - 1 : y;
+                       if (x != newX || y != newY)
+                       {
+                               c.moveTo(newX, newY);
+                               System.out.println("  Snapping WCP " + c.getName());
+                       }
+               });
+       }
+
+       private static void warnNonSnappedPoints(DeserializedSubmodelComponent comp, LogicModelModifiable submodelModifiable)
+       {
+               if (comp.getWidth() % GRIDSIZE != 0 || comp.getHeight() % GRIDSIZE != 0)
+                       System.out.println("  Size is not snapped to grid: " + comp.getWidth() + "," + comp.getHeight());
+               submodelModifiable.getComponentsByName().values().forEach(c ->
+               {
+                       double x = c.getPosX();
+                       double y = c.getPosY();
+                       if (c instanceof ModelWireCrossPoint)
+                       {
+                               x++;
+                               y++;
+                       }
+                       if (x % GRIDSIZE != 0 || y % GRIDSIZE != 0)
+                               System.out.println("  Component " + c.getName() + " (type " + c.getIDForSerializing(new IdentifyParams())
+                                               + ") is not snapped to grid: " + x + "," + y);
+               });
+               submodelModifiable.getWiresByName().values().forEach(w ->
+               {
+                       Point[] p = w.getPath();
+                       if (p != null)
+                               for (int i = 0; i < p.length; i++)
+                                       if (p[i].x % GRIDSIZE != 0 || p[i].y % GRIDSIZE != 0)
+                                               System.out.println("  Wire " + w.name + " path point #" + i + " is not snapped to grid: " + p[i].x + "," + p[i].y);
+               });
+               comp.getPins().values().forEach(p ->
+               {
+                       if (p.getRelX() % GRIDSIZE != 0 || p.getRelY() % GRIDSIZE != 0)
+                               System.out.println("  Interface point " + p.name + " is not snapped to grid: " + p.getRelX() + "," + p.getRelY());
+               });
+       }
+
+       private static void warnNonVertHorizLines(LogicModelModifiable submodelModifiable)
+       {
+               submodelModifiable.getWiresByName().values().forEach(w ->
+               {
+                       double[] p = w.getEffectivePath();
+                       for (int i = 1; i < p.length / 2; i++)
+                       {
+                               double x1 = p[2 * i - 2];
+                               double y1 = p[2 * i - 1];
+                               double x2 = p[2 * i + 0];
+                               double y2 = p[2 * i + 1];
+                               if (x1 != x2 && y1 != y2)
+                                       System.out.println("  Wire " + w.name + " part #" + (i - 1) + " is neither vertical nor horizontal");
+                       }
+               });
+       }
+
+       private static ModelWire createWire(Function<String, String> componentNameRemapping, LogicModelModifiable tempModelForDefaultNames,
+                       ModelWire w)
+       {
+               return new ModelWire(tempModelForDefaultNames, w.name,
+                               getRemappedPin(componentNameRemapping, tempModelForDefaultNames, w.getPin1()),
+                               getRemappedPin(componentNameRemapping, tempModelForDefaultNames, w.getPin2()), w.getPath());
+       }
+
+       private static Pin getRemappedPin(Function<String, String> componentNameRemapping, LogicModelModifiable tempModelForDefaultNames,
+                       Pin pin)
+       {
+               return tempModelForDefaultNames.getComponentsByName().get(componentNameRemapping.apply(pin.component.getName())).getPin(pin.name);
+       }
+
+       private static int compareStringsWithIntegers(String a, String b)
+       {
+               int aLoc = 0;
+               int bLoc = 0;
+               for (;;)
+               {
+                       if (aLoc == a.length())
+                       {
+                               if (bLoc == b.length())
+                                       return 0;
+                               return -1;
+                       }
+                       if (bLoc == b.length())
+                               return 1;
+                       int aInt = 0;
+                       int aIntLen = 0;
+                       char nextCharA;
+                       for (;;)
+                       {
+                               nextCharA = a.charAt(aLoc++);
+                               if (nextCharA < '0' || nextCharA > '9')
+                                       break;
+                               aIntLen++;
+                               aInt = aInt * 10 + nextCharA - '0';
+                               if (aLoc == a.length())
+                                       break;
+                       }
+                       int bInt = 0;
+                       int bIntLen = 0;
+                       char nextCharB;
+                       for (;;)
+                       {
+                               nextCharB = b.charAt(bLoc++);
+                               if (nextCharB < '0' || nextCharB > '9')
+                                       break;
+                               bIntLen++;
+                               bInt = bInt * 10 + nextCharB - '0';
+                               if (bLoc == b.length())
+                                       break;
+                       }
+                       if (aIntLen != 0)
+                       {
+                               if (bIntLen == 0)
+                                       return -1;
+                               int comp = Integer.compare(aInt, bInt);
+                               if (comp != 0)
+                                       return comp;
+                       } else
+                       {
+                               if (bIntLen != 0)
+                                       return 1;
+                               int comp = Character.compare(nextCharA, nextCharB);
+                               if (comp != 0)
+                                       return comp;
+                       }
+               }
+       }
+
+       private static void setInterfacePinUsage(DeserializedSubmodelComponent comp, Pin interfacePin, PinUsage usage)
+       {
+               Set<ModelWire> wiresConnectedToPin = comp.submodel.getWiresByName().values().stream()
+                               .filter(w -> w.getPin1() == interfacePin || w.getPin2() == interfacePin).collect(Collectors.toSet());
+               LogicModelModifiable submodelModifiable = comp.getSubmodelModifiable();
+               wiresConnectedToPin.forEach(submodelModifiable::destroyWire);
+               comp.removeSubmodelInterface(interfacePin.name);
+               comp.addSubmodelInterface(new MovablePin(submodelModifiable, comp, interfacePin.name, interfacePin.logicWidth, usage,
+                               interfacePin.getRelX(), interfacePin.getRelY()));
+               wiresConnectedToPin.forEach(w -> new ModelWire(submodelModifiable, w.getPin1(), w.getPin2()));
+       }
+}
\ No newline at end of file
diff --git a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/ReserializeJSONs.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/ReserializeJSONs.java
deleted file mode 100644 (file)
index c9486cc..0000000
+++ /dev/null
@@ -1,284 +0,0 @@
-package net.mograsim.logic.model.examples;
-
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Optional;
-import java.util.Scanner;
-import java.util.Set;
-import java.util.function.Function;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
-import net.mograsim.logic.model.am2900.Am2900Loader;
-import net.mograsim.logic.model.model.LogicModelModifiable;
-import net.mograsim.logic.model.model.components.ModelComponent;
-import net.mograsim.logic.model.model.components.submodels.SubmodelComponent;
-import net.mograsim.logic.model.model.components.submodels.SubmodelInterface;
-import net.mograsim.logic.model.model.wires.ModelWire;
-import net.mograsim.logic.model.model.wires.ModelWireCrossPoint;
-import net.mograsim.logic.model.model.wires.MovablePin;
-import net.mograsim.logic.model.model.wires.Pin;
-import net.mograsim.logic.model.model.wires.PinUsage;
-import net.mograsim.logic.model.serializing.DeserializedSubmodelComponent;
-import net.mograsim.logic.model.serializing.IdentifyParams;
-import net.mograsim.logic.model.serializing.IndirectModelComponentCreator;
-import net.mograsim.logic.model.serializing.SubmodelComponentSerializer;
-import net.mograsim.logic.model.snippets.highlevelstatehandlers.DefaultHighLevelStateHandler;
-
-public class ReserializeJSONs
-{
-       public static double GRIDSIZE = 2.5;
-       public static boolean changePinUsages = false;
-       public static boolean changeComponentNames = false;
-       public static boolean snapWCPs = true;
-       public static boolean warnNonSnappedPoints = true;
-
-       public static void main(String[] args) throws IOException
-       {
-               Am2900Loader.setup();
-               try (Scanner sysin = new Scanner(System.in))
-               {
-                       System.out.print("Directory to search for JSONs in / JSON file to reserialize >");
-                       Path root = Paths.get(sysin.nextLine());
-                       if (!Files.exists(root))
-                               throw new IllegalArgumentException("Path doesn't exist");
-                       if (Files.isRegularFile(root))
-                               reserializeJSON(root, sysin);
-                       else
-                       {
-                               System.out.print("Recursive? >");
-                               boolean recursive = Boolean.valueOf(sysin.nextLine());
-                               try (Stream<Path> jsons = recursive ? Files.walk(root) : Files.list(root))
-                               {
-                                       jsons.filter(Files::isRegularFile).filter(p -> p.getFileName().toString().endsWith(".json"))
-                                                       .forEach(j -> reserializeJSON(j, sysin));
-                               }
-                       }
-               }
-       }
-
-       public static void reserializeJSON(Path componentPath, Scanner sysin)
-       {
-               try
-               {
-                       DeserializedSubmodelComponent comp = (DeserializedSubmodelComponent) IndirectModelComponentCreator
-                                       .createComponent(new LogicModelModifiable(), "jsonfile:" + componentPath.toString());
-                       System.out.println("Reserializing " + componentPath);
-                       if (changePinUsages)
-                               comp.getSupermodelPins().entrySet().stream().sorted(Comparator.comparing(Entry::getKey)).map(Entry::getValue).forEach(pin ->
-                               {
-                                       PinUsage usage = null;
-                                       while (usage == null)
-                                               try
-                                               {
-                                                       System.out.print("  Usage for interface pin " + pin.name + " (empty: " + pin.usage + ") >");
-                                                       String usageStr = sysin.nextLine().toUpperCase();
-                                                       usage = usageStr.equals("") ? pin.usage
-                                                                       : usageStr.equals("I") ? PinUsage.INPUT
-                                                                                       : usageStr.equals("O") ? PinUsage.OUTPUT
-                                                                                                       : usageStr.equals("T") ? PinUsage.TRISTATE : PinUsage.valueOf(usageStr);
-                                               }
-                                               catch (@SuppressWarnings("unused") IllegalArgumentException e)
-                                               {
-                                                       System.err.println("  Illegal usage");
-                                               }
-                                       setInterfacePinUsage(comp, pin, usage);
-                               });
-                       LogicModelModifiable submodelModifiable = comp.getSubmodelModifiable();
-                       Map<String, String> componentNameRemapping = new HashMap<>();
-                       if (changeComponentNames)
-                       {
-                               componentNameRemapping.put(SubmodelComponent.SUBMODEL_INTERFACE_NAME, SubmodelComponent.SUBMODEL_INTERFACE_NAME);
-                               LogicModelModifiable tempModel = new LogicModelModifiable();
-                               IdentifyParams iP = new IdentifyParams();
-                               submodelModifiable.getComponentsByName().entrySet().stream()
-                                               .filter(e -> !e.getKey().equals(SubmodelComponent.SUBMODEL_INTERFACE_NAME))
-                                               .sorted(Comparator.comparing(Entry::getKey, ReserializeJSONs::compareStringsWithIntegers)).forEach(e ->
-                                               {
-                                                       String oldName = e.getKey();
-                                                       ModelComponent subcomp = e.getValue();
-                                                       String defaultName = tempModel.getDefaultComponentName(subcomp);
-                                                       String newName = null;
-                                                       while (newName == null)
-                                                       {
-                                                               System.out.print("  New name for component " + oldName + " of type " + subcomp.getIDForSerializing(iP)
-                                                                               + " (empty: " + defaultName + ") >");
-                                                               newName = sysin.nextLine();
-                                                               if (newName.equals(""))
-                                                                       newName = defaultName;
-                                                               if (tempModel.getComponentsByName().containsKey(newName))
-                                                               {
-                                                                       System.err.println("  There already is a component with that name");
-                                                                       newName = null;
-                                                               }
-                                                       }
-                                                       componentNameRemapping.put(oldName, newName);
-                                                       IndirectModelComponentCreator.createComponent(tempModel, subcomp.getIDForSerializing(iP),
-                                                                       subcomp.getParamsForSerializingJSON(iP), newName).moveTo(subcomp.getPosX(), subcomp.getPosY());
-                                               });
-                               SubmodelInterface tempSubmodelInterface = new SubmodelInterface(tempModel);
-                               for (Pin p : submodelModifiable.getComponentsByName().get(SubmodelComponent.SUBMODEL_INTERFACE_NAME).getPins().values())
-                                       tempSubmodelInterface
-                                                       .addPin(new Pin(tempModel, tempSubmodelInterface, p.name, p.logicWidth, p.usage, p.getRelX(), p.getRelY()));
-                               for (ModelWire w : submodelModifiable.getWiresByName().values())
-                                       createWire(componentNameRemapping::get, tempModel, w);
-
-                               Optional<ModelComponent> o;
-                               while ((o = submodelModifiable.getComponentsByName().values().stream()
-                                               .filter(c -> !c.getName().equals(SubmodelComponent.SUBMODEL_INTERFACE_NAME)).findAny()).isPresent())
-                                       submodelModifiable.destroyComponent(o.get());
-
-                               tempModel.getComponentsByName().values().stream()
-                                               .filter(c -> !c.getName().equals(SubmodelComponent.SUBMODEL_INTERFACE_NAME))
-                                               .forEach(c -> IndirectModelComponentCreator.createComponent(submodelModifiable, c.getIDForSerializing(iP),
-                                                               c.getParamsForSerializingJSON(iP), c.getName()).moveTo(c.getPosX(), c.getPosY()));
-                               for (ModelWire w : tempModel.getWiresByName().values())
-                                       createWire(Function.identity(), submodelModifiable, w);
-                       }
-                       if (snapWCPs)
-                               submodelModifiable.getComponentsByName().values().stream().filter(c -> c instanceof ModelWireCrossPoint).forEach(c ->
-                               {
-                                       double x = c.getPosX();
-                                       double y = c.getPosY();
-                                       c.moveTo(x % GRIDSIZE == 0 ? x - 1 : x, y % GRIDSIZE == 0 ? y - 1 : y);
-                               });
-                       if (warnNonSnappedPoints)
-                       {
-                               if (comp.getWidth() % GRIDSIZE != 0 || comp.getHeight() % GRIDSIZE != 0)
-                                       System.out.println("  Size is not snapped to grid: " + comp.getWidth() + "," + comp.getHeight());
-                               submodelModifiable.getComponentsByName().values().forEach(c ->
-                               {
-                                       double x = c.getPosX();
-                                       double y = c.getPosY();
-                                       if (c instanceof ModelWireCrossPoint)
-                                       {
-                                               x++;
-                                               y++;
-                                       }
-                                       if (x % GRIDSIZE != 0 || y % GRIDSIZE != 0)
-                                               System.out.println("  Component " + c.getName() + " (type " + c.getIDForSerializing(new IdentifyParams())
-                                                               + ") is not snapped to grid: " + x + "," + y);
-                               });
-                               submodelModifiable.getWiresByName().values().stream().forEach(w ->
-                               {
-                                       Point[] p = w.getPath();
-                                       if (p != null)
-                                               for (int i = 0; i < p.length; i++)
-                                                       if (p[i].x % GRIDSIZE != 0 || p[i].y % GRIDSIZE != 0)
-                                                               System.out.println(
-                                                                               "  Wire " + w.name + " path point #" + i + " is not snapped to grid: " + p[i].x + "," + p[i].y);
-                               });
-                               comp.getPins().values().forEach(p ->
-                               {
-                                       if (p.getRelX() % GRIDSIZE != 0 || p.getRelY() % GRIDSIZE != 0)
-                                               System.out.println("  Interface point " + p.name + " is not snapped to grid: " + p.getRelX() + "," + p.getRelY());
-                               });
-                       }
-                       SubmodelComponentSerializer.serialize(comp, componentPath.toString());
-                       if (changeComponentNames && (comp.getHighLevelStateHandler() == null
-                                       || !(comp.getHighLevelStateHandler() instanceof DefaultHighLevelStateHandler)))
-                       {
-                               System.out.println("  A non-default HighLevelStateHandler was detected. Check for changes there manually.");
-                               System.out.print("  Empty line to continue to next component, old component name to get new component name >");
-                               for (String line = sysin.nextLine(); !line.equals(""); line = sysin.nextLine())
-                                       System.out.println("  " + line + "->" + componentNameRemapping.get(line) + " >");
-                       }
-               }
-               catch (Exception e)
-               {
-                       System.err.println("An error occurred visiting " + componentPath + ":");
-                       e.printStackTrace();
-               }
-       }
-
-       private static ModelWire createWire(Function<String, String> componentNameRemapping, LogicModelModifiable tempModelForDefaultNames,
-                       ModelWire w)
-       {
-               return new ModelWire(tempModelForDefaultNames, w.name,
-                               getRemappedPin(componentNameRemapping, tempModelForDefaultNames, w.getPin1()),
-                               getRemappedPin(componentNameRemapping, tempModelForDefaultNames, w.getPin2()), w.getPath());
-       }
-
-       private static Pin getRemappedPin(Function<String, String> componentNameRemapping, LogicModelModifiable tempModelForDefaultNames,
-                       Pin pin)
-       {
-               return tempModelForDefaultNames.getComponentsByName().get(componentNameRemapping.apply(pin.component.getName())).getPin(pin.name);
-       }
-
-       private static int compareStringsWithIntegers(String a, String b)
-       {
-               int aLoc = 0;
-               int bLoc = 0;
-               for (;;)
-               {
-                       if (aLoc == a.length())
-                       {
-                               if (bLoc == b.length())
-                                       return 0;
-                               return -1;
-                       }
-                       if (bLoc == b.length())
-                               return 1;
-                       int aInt = 0;
-                       int aIntLen = 0;
-                       char nextCharA;
-                       for (;;)
-                       {
-                               nextCharA = a.charAt(aLoc++);
-                               if (nextCharA < '0' || nextCharA > '9')
-                                       break;
-                               aIntLen++;
-                               aInt = aInt * 10 + nextCharA - '0';
-                               if (aLoc == a.length())
-                                       break;
-                       }
-                       int bInt = 0;
-                       int bIntLen = 0;
-                       char nextCharB;
-                       for (;;)
-                       {
-                               nextCharB = b.charAt(bLoc++);
-                               if (nextCharB < '0' || nextCharB > '9')
-                                       break;
-                               bIntLen++;
-                               bInt = bInt * 10 + nextCharB - '0';
-                               if (bLoc == b.length())
-                                       break;
-                       }
-                       if (aIntLen != 0)
-                       {
-                               if (bIntLen == 0)
-                                       return -1;
-                               int comp = Integer.compare(aInt, bInt);
-                               if (comp != 0)
-                                       return comp;
-                       } else
-                       {
-                               if (bIntLen != 0)
-                                       return 1;
-                               int comp = Character.compare(nextCharA, nextCharB);
-                               if (comp != 0)
-                                       return comp;
-                       }
-               }
-       }
-
-       private static void setInterfacePinUsage(DeserializedSubmodelComponent comp, Pin interfacePin, PinUsage usage)
-       {
-               Set<ModelWire> wiresConnectedToPin = comp.submodel.getWiresByName().values().stream()
-                               .filter(w -> w.getPin1() == interfacePin || w.getPin2() == interfacePin).collect(Collectors.toSet());
-               LogicModelModifiable submodelModifiable = comp.getSubmodelModifiable();
-               wiresConnectedToPin.forEach(submodelModifiable::destroyWire);
-               comp.removeSubmodelInterface(interfacePin.name);
-               comp.addSubmodelInterface(new MovablePin(submodelModifiable, comp, interfacePin.name, interfacePin.logicWidth, usage,
-                               interfacePin.getRelX(), interfacePin.getRelY()));
-               wiresConnectedToPin.forEach(w -> new ModelWire(submodelModifiable, w.getPin1(), w.getPin2()));
-       }
-}
\ No newline at end of file
index ef760f1..414054e 100644 (file)
@@ -22,6 +22,7 @@ import net.mograsim.logic.model.model.wires.ModelWireCrossPoint;
 import net.mograsim.logic.model.serializing.IndirectModelComponentCreator;
 import net.mograsim.logic.model.util.ModellingTool;
 
+@Deprecated
 public class Am2901Testbench
 {
        public static void main(String[] args)
index 839d5f9..33cc22e 100644 (file)
@@ -5,9 +5,11 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.function.Consumer;
 
 import net.mograsim.logic.model.model.components.ModelComponent;
+import net.mograsim.logic.model.model.components.submodels.SubmodelComponent;
 import net.mograsim.logic.model.model.wires.ModelWire;
 
 public class LogicModel
@@ -115,6 +117,46 @@ public class LogicModel
                return wiresUnmodifiable;
        }
 
+       public <T extends ModelComponent> T getComponentByName(String name, Class<T> modelClass)
+       {
+               return getByName(name, modelClass, components);
+       }
+
+       public ModelWire getWireByName(String name)
+       {
+               return getByName(name, ModelWire.class, wires);
+       }
+
+       @SuppressWarnings("unchecked")
+       private static <T> T getByName(String name, Class<T> modelClass, Map<String, ? super T> map)
+       {
+               Object comp = map.get(name);
+               Objects.requireNonNull(comp, "Invaild path, component " + name + " not found");
+               if (modelClass.isInstance(comp))
+                       return (T) comp;
+               throw new IllegalArgumentException("The component " + name + " is not an instance of " + modelClass);
+       }
+
+       public <T extends ModelComponent> T getComponentByPath(String path, Class<T> modelClass)
+       {
+               int firstDot = path.indexOf('.');
+               if (firstDot == -1)
+                       return getComponentByName(path, modelClass);
+               String first = path.substring(0, firstDot);
+               String rest = path.substring(firstDot + 1);
+               return getComponentByName(first, SubmodelComponent.class).submodel.getComponentByPath(rest, modelClass);
+       }
+
+       public ModelWire getWireByPath(String path)
+       {
+               int firstDot = path.indexOf('.');
+               if (firstDot == -1)
+                       return getWireByName(path);
+               String first = path.substring(0, firstDot);
+               String rest = path.substring(firstDot + 1);
+               return getComponentByName(first, SubmodelComponent.class).submodel.getWireByPath(rest);
+       }
+
        // @formatter:off
        public void addComponentAddedListener         (Consumer<? super ModelComponent> listener) {componentAddedListeners      .add   (listener);}
        public void addComponentRemovedListener       (Consumer<? super ModelComponent> listener) {componentRemovedListeners    .add   (listener);}
index 11a6908..e913641 100644 (file)
@@ -163,6 +163,6 @@ public class Pin
        @Override
        public String toString()
        {
-               return "Pin [" + name + ", point=" + getPos() + "]";
+               return "Pin " + name + " of " + component.getName();
        }
 }
\ No newline at end of file
index fce47c1..c149848 100644 (file)
@@ -16,9 +16,12 @@ import net.mograsim.logic.model.model.LogicModelModifiable;
 import net.mograsim.logic.model.model.components.ModelComponent;
 import net.mograsim.logic.model.model.components.submodels.SubmodelComponent;
 import net.mograsim.logic.model.util.JsonHandler;
+import net.mograsim.logic.model.util.Version;
 
 public class IndirectModelComponentCreator
 {
+       public static final Version CURRENT_STD_ID_MAPPING_VERSION = Version.parseSemver("0.1.0");
+
        private static final Map<String, String> standardComponentIDs = new HashMap<>();
        private static final Map<String, String> standardComponentIDsUnmodifiable = Collections.unmodifiableMap(standardComponentIDs);
 
@@ -39,7 +42,7 @@ public class IndirectModelComponentCreator
                {
                        if (s == null)
                                throw new IOException("Resource not found");
-                       Map<String, String> tmp = JsonHandler.readJson(s, Map.class);
+                       Map<String, String> tmp = JsonHandler.readJson(s, StandardComponentIdMappingContainer.class).getMap();
                        // don't use putAll to apply sanity checks
                        tmp.forEach((st, id) ->
                        {
@@ -184,7 +187,8 @@ public class IndirectModelComponentCreator
                return id.matches("jsonfile:(.+)|(resloader:([^:]+):)?(jsonres|class):[^:]+");
        }
 
-       private static SubmodelComponent loadComponentFromJsonObject(LogicModelModifiable model, String id, String name, JsonObject jsonContents)
+       private static SubmodelComponent loadComponentFromJsonObject(LogicModelModifiable model, String id, String name,
+                       JsonObject jsonContents)
        {
                componentCache.putIfAbsent(id, jsonContents);
                SerializablePojo jsonContentsAsSerializablePojo = JsonHandler.parser.fromJson(jsonContents, SerializablePojo.class);
diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/StandardComponentIdMappingContainer.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/StandardComponentIdMappingContainer.java
new file mode 100644 (file)
index 0000000..9467200
--- /dev/null
@@ -0,0 +1,20 @@
+package net.mograsim.logic.model.serializing;
+
+import java.util.Map;
+
+import net.mograsim.logic.model.util.Version;
+
+public class StandardComponentIdMappingContainer extends SerializablePojo
+{
+       public Map<String, String> map;
+
+       public StandardComponentIdMappingContainer(Version version)
+       {
+               super(version);
+       }
+
+       public Map<String, String> getMap()
+       {
+               return map;
+       }
+}
index aadc0b2..b0b8bed 100644 (file)
@@ -1,15 +1,17 @@
-mograsim version: 0.1.3
 {
-  "AndGate": "class:net.mograsim.logic.model.model.components.atomic.ModelAndGate",
-  "BitDisplay": "class:net.mograsim.logic.model.model.components.atomic.ModelBitDisplay",
-  "Clock": "class:net.mograsim.logic.model.model.components.atomic.ModelClock",
-  "FixedOutput": "class:net.mograsim.logic.model.model.components.atomic.ModelFixedOutput",
-  "ManualSwitch": "class:net.mograsim.logic.model.model.components.atomic.ModelManualSwitch",
-  "Merger": "class:net.mograsim.logic.model.model.components.atomic.ModelMerger",
-  "NandGate": "class:net.mograsim.logic.model.model.components.atomic.ModelNandGate",
-  "OrGate": "class:net.mograsim.logic.model.model.components.atomic.ModelOrGate",
-  "Splitter": "class:net.mograsim.logic.model.model.components.atomic.ModelSplitter",
-  "TriStateBuffer": "class:net.mograsim.logic.model.model.components.atomic.ModelTriStateBuffer",
-  "TextComponent": "class:net.mograsim.logic.model.model.components.atomic.ModelTextComponent",
-  "WireCrossPoint": "class:net.mograsim.logic.model.model.wires.ModelWireCrossPoint"
+  "version": "0.1.0",
+  "map": {
+    "AndGate": "class:net.mograsim.logic.model.model.components.atomic.ModelAndGate",
+    "BitDisplay": "class:net.mograsim.logic.model.model.components.atomic.ModelBitDisplay",
+    "Clock": "class:net.mograsim.logic.model.model.components.atomic.ModelClock",
+    "FixedOutput": "class:net.mograsim.logic.model.model.components.atomic.ModelFixedOutput",
+    "ManualSwitch": "class:net.mograsim.logic.model.model.components.atomic.ModelManualSwitch",
+    "Merger": "class:net.mograsim.logic.model.model.components.atomic.ModelMerger",
+    "NandGate": "class:net.mograsim.logic.model.model.components.atomic.ModelNandGate",
+    "OrGate": "class:net.mograsim.logic.model.model.components.atomic.ModelOrGate",
+    "Splitter": "class:net.mograsim.logic.model.model.components.atomic.ModelSplitter",
+    "TriStateBuffer": "class:net.mograsim.logic.model.model.components.atomic.ModelTriStateBuffer",
+    "TextComponent": "class:net.mograsim.logic.model.model.components.atomic.ModelTextComponent",
+    "WireCrossPoint": "class:net.mograsim.logic.model.model.wires.ModelWireCrossPoint"
+  }
 }
\ No newline at end of file
index eb8c941..8202b0c 100644 (file)
@@ -1,4 +1,5 @@
-mograsim version: 0.1.3
 {
-  "MemoryWA": "resloader:MachineLoader:class:net.mograsim.machine.standard.memory.ModelMemoryWA"
+  "version": "0.1.0",
+  "map": {
+   }
 }
\ No newline at end of file