From 9ca90120a47e07c9182162351dc47aa89ae703be Mon Sep 17 00:00:00 2001 From: Daniel Kirschten Date: Thu, 4 Jul 2019 10:24:44 +0200 Subject: [PATCH] Added two SymbolRendererProviders --- .../components/GUI_rsLatch.json | 8 ++ .../components/GUIand.json | 8 ++ .../components/GUIand41.json | 8 ++ .../components/GUIandor414.json | 8 ++ .../components/GUIdemux2.json | 8 ++ .../components/GUIdff.json | 8 ++ .../components/GUIdlatch.json | 8 ++ .../components/GUIdlatch4.json | 8 ++ .../components/GUIfulladder.json | 8 ++ .../components/GUIhalfadder.json | 8 ++ .../components/GUImux1.json | 8 ++ .../components/GUImux1_4.json | 8 ++ .../components/GUInand3.json | 8 ++ .../components/GUInot4.json | 8 ++ .../components/GUIor4.json | 8 ++ .../components/GUIor_4.json | 8 ++ .../components/GUIram2.json | 8 ++ .../components/GUIram4.json | 8 ++ .../components/GUIsel2_4.json | 8 ++ .../components/GUIsel3_4.json | 8 ++ .../components/GUIxor.json | 8 ++ .../components/am2901/GUIAm2901.json | 8 ++ .../am2901/GUIAm2901ALUFuncDecode.json | 8 ++ .../am2901/GUIAm2901ALUInclDecode.json | 8 ++ ...ALUInclSourceDecodeInclFunctionDecode.json | 8 ++ .../components/am2901/GUIAm2901ALUOneBit.json | 8 ++ .../am2901/GUIAm2901DestDecode.json | 8 ++ .../components/am2901/GUIAm2901QReg.json | 8 ++ .../am2901/GUIAm2901SourceDecode.json | 8 ++ .../ui/examples/ComponenetSerializer.java | 11 +++ .../SimpleRectangularSubmodelComponent.java | 1 + .../ui/serializing/CodeSnippetSupplier.java | 30 ++----- .../SubmodelComponentDeserializer.java | 5 +- .../serializing/SubmodelComponentParams.java | 4 +- .../DefaultOutlineRendererProvider.java | 26 ++++++ .../CenteredTextSymbolRendererProvider.java | 57 +++++++++++++ .../DefaultSymbolRendererProvider.java | 31 +++++++ ...RectangularLikeSymbolRendererProvider.java | 83 +++++++++++++++++++ .../serializing/standardSnippetIDMapping.json | 2 + 39 files changed, 453 insertions(+), 29 deletions(-) create mode 100644 net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/snippets/outlinerenderers/DefaultOutlineRendererProvider.java create mode 100644 net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/snippets/symbolrenderers/CenteredTextSymbolRendererProvider.java create mode 100644 net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/snippets/symbolrenderers/DefaultSymbolRendererProvider.java create mode 100644 net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/snippets/symbolrenderers/SimpleRectangularLikeSymbolRendererProvider.java diff --git a/net.mograsim.logic.ui.am2900/components/GUI_rsLatch.json b/net.mograsim.logic.ui.am2900/components/GUI_rsLatch.json index 4431f34a..35ebc03d 100644 --- a/net.mograsim.logic.ui.am2900/components/GUI_rsLatch.json +++ b/net.mograsim.logic.ui.am2900/components/GUI_rsLatch.json @@ -206,5 +206,13 @@ mograsim version: 0.1.3 "path": [] } ] + }, + "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer", + "symbolRendererParams": { + "centerText": "_rsLatch", + "horizontalComponentCenter": 17.5, + "centerTextHeight": 5, + "pinLabelHeight": 3.5, + "pinLabelMargin": 0.5 } } \ No newline at end of file diff --git a/net.mograsim.logic.ui.am2900/components/GUIand.json b/net.mograsim.logic.ui.am2900/components/GUIand.json index 0687592a..d717447e 100644 --- a/net.mograsim.logic.ui.am2900/components/GUIand.json +++ b/net.mograsim.logic.ui.am2900/components/GUIand.json @@ -131,5 +131,13 @@ mograsim version: 0.1.3 } } ] + }, + "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer", + "symbolRendererParams": { + "centerText": "and", + "horizontalComponentCenter": 17.5, + "centerTextHeight": 5, + "pinLabelHeight": 3.5, + "pinLabelMargin": 0.5 } } \ No newline at end of file diff --git a/net.mograsim.logic.ui.am2900/components/GUIand41.json b/net.mograsim.logic.ui.am2900/components/GUIand41.json index cb1608a5..2e9d9531 100644 --- a/net.mograsim.logic.ui.am2900/components/GUIand41.json +++ b/net.mograsim.logic.ui.am2900/components/GUIand41.json @@ -309,5 +309,13 @@ mograsim version: 0.1.3 "path": [] } ] + }, + "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer", + "symbolRendererParams": { + "centerText": "and41", + "horizontalComponentCenter": 17.5, + "centerTextHeight": 5, + "pinLabelHeight": 3.5, + "pinLabelMargin": 0.5 } } \ No newline at end of file diff --git a/net.mograsim.logic.ui.am2900/components/GUIandor414.json b/net.mograsim.logic.ui.am2900/components/GUIandor414.json index d585785b..0a9f2645 100644 --- a/net.mograsim.logic.ui.am2900/components/GUIandor414.json +++ b/net.mograsim.logic.ui.am2900/components/GUIandor414.json @@ -473,5 +473,13 @@ mograsim version: 0.1.3 ] } ] + }, + "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer", + "symbolRendererParams": { + "centerText": "andor414", + "horizontalComponentCenter": 17.5, + "centerTextHeight": 5, + "pinLabelHeight": 3.5, + "pinLabelMargin": 0.5 } } \ No newline at end of file diff --git a/net.mograsim.logic.ui.am2900/components/GUIdemux2.json b/net.mograsim.logic.ui.am2900/components/GUIdemux2.json index 04df7d07..07bf5ada 100644 --- a/net.mograsim.logic.ui.am2900/components/GUIdemux2.json +++ b/net.mograsim.logic.ui.am2900/components/GUIdemux2.json @@ -485,5 +485,13 @@ mograsim version: 0.1.3 } } ] + }, + "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer", + "symbolRendererParams": { + "centerText": "demux2", + "horizontalComponentCenter": 17.5, + "centerTextHeight": 5, + "pinLabelHeight": 3.5, + "pinLabelMargin": 0.5 } } \ No newline at end of file diff --git a/net.mograsim.logic.ui.am2900/components/GUIdff.json b/net.mograsim.logic.ui.am2900/components/GUIdff.json index df4e0a1e..4902e6c8 100644 --- a/net.mograsim.logic.ui.am2900/components/GUIdff.json +++ b/net.mograsim.logic.ui.am2900/components/GUIdff.json @@ -308,5 +308,13 @@ mograsim version: 0.1.3 } } ] + }, + "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer", + "symbolRendererParams": { + "centerText": "dff", + "horizontalComponentCenter": 17.5, + "centerTextHeight": 5, + "pinLabelHeight": 3.5, + "pinLabelMargin": 0.5 } } \ No newline at end of file diff --git a/net.mograsim.logic.ui.am2900/components/GUIdlatch.json b/net.mograsim.logic.ui.am2900/components/GUIdlatch.json index 84e635f8..a5c6b432 100644 --- a/net.mograsim.logic.ui.am2900/components/GUIdlatch.json +++ b/net.mograsim.logic.ui.am2900/components/GUIdlatch.json @@ -221,5 +221,13 @@ mograsim version: 0.1.3 } } ] + }, + "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer", + "symbolRendererParams": { + "centerText": "dlatch", + "horizontalComponentCenter": 17.5, + "centerTextHeight": 5, + "pinLabelHeight": 3.5, + "pinLabelMargin": 0.5 } } \ No newline at end of file diff --git a/net.mograsim.logic.ui.am2900/components/GUIdlatch4.json b/net.mograsim.logic.ui.am2900/components/GUIdlatch4.json index 2458b250..8dddd05f 100644 --- a/net.mograsim.logic.ui.am2900/components/GUIdlatch4.json +++ b/net.mograsim.logic.ui.am2900/components/GUIdlatch4.json @@ -309,5 +309,13 @@ mograsim version: 0.1.3 "path": [] } ] + }, + "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer", + "symbolRendererParams": { + "centerText": "dlatch4", + "horizontalComponentCenter": 17.5, + "centerTextHeight": 5, + "pinLabelHeight": 3.5, + "pinLabelMargin": 0.5 } } \ No newline at end of file diff --git a/net.mograsim.logic.ui.am2900/components/GUIfulladder.json b/net.mograsim.logic.ui.am2900/components/GUIfulladder.json index d7396280..34cc7ea4 100644 --- a/net.mograsim.logic.ui.am2900/components/GUIfulladder.json +++ b/net.mograsim.logic.ui.am2900/components/GUIfulladder.json @@ -173,5 +173,13 @@ mograsim version: 0.1.3 } } ] + }, + "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer", + "symbolRendererParams": { + "centerText": "fulladder", + "horizontalComponentCenter": 17.5, + "centerTextHeight": 5, + "pinLabelHeight": 3.5, + "pinLabelMargin": 0.5 } } \ No newline at end of file diff --git a/net.mograsim.logic.ui.am2900/components/GUIhalfadder.json b/net.mograsim.logic.ui.am2900/components/GUIhalfadder.json index 5cffb3db..36885ac5 100644 --- a/net.mograsim.logic.ui.am2900/components/GUIhalfadder.json +++ b/net.mograsim.logic.ui.am2900/components/GUIhalfadder.json @@ -298,5 +298,13 @@ mograsim version: 0.1.3 "path": [] } ] + }, + "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer", + "symbolRendererParams": { + "centerText": "halfadder", + "horizontalComponentCenter": 17.5, + "centerTextHeight": 5, + "pinLabelHeight": 3.5, + "pinLabelMargin": 0.5 } } \ No newline at end of file diff --git a/net.mograsim.logic.ui.am2900/components/GUImux1.json b/net.mograsim.logic.ui.am2900/components/GUImux1.json index c3412266..90e90132 100644 --- a/net.mograsim.logic.ui.am2900/components/GUImux1.json +++ b/net.mograsim.logic.ui.am2900/components/GUImux1.json @@ -212,5 +212,13 @@ mograsim version: 0.1.3 } } ] + }, + "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer", + "symbolRendererParams": { + "centerText": "mux1", + "horizontalComponentCenter": 17.5, + "centerTextHeight": 5, + "pinLabelHeight": 3.5, + "pinLabelMargin": 0.5 } } \ No newline at end of file diff --git a/net.mograsim.logic.ui.am2900/components/GUImux1_4.json b/net.mograsim.logic.ui.am2900/components/GUImux1_4.json index 35f9c2f9..d4f23ba1 100644 --- a/net.mograsim.logic.ui.am2900/components/GUImux1_4.json +++ b/net.mograsim.logic.ui.am2900/components/GUImux1_4.json @@ -449,5 +449,13 @@ mograsim version: 0.1.3 } } ] + }, + "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer", + "symbolRendererParams": { + "centerText": "mux1_4", + "horizontalComponentCenter": 17.5, + "centerTextHeight": 5, + "pinLabelHeight": 3.5, + "pinLabelMargin": 0.5 } } \ No newline at end of file diff --git a/net.mograsim.logic.ui.am2900/components/GUInand3.json b/net.mograsim.logic.ui.am2900/components/GUInand3.json index 7177e919..be950652 100644 --- a/net.mograsim.logic.ui.am2900/components/GUInand3.json +++ b/net.mograsim.logic.ui.am2900/components/GUInand3.json @@ -188,5 +188,13 @@ mograsim version: 0.1.3 "path": [] } ] + }, + "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer", + "symbolRendererParams": { + "centerText": "nand3", + "horizontalComponentCenter": 17.5, + "centerTextHeight": 5, + "pinLabelHeight": 3.5, + "pinLabelMargin": 0.5 } } \ No newline at end of file diff --git a/net.mograsim.logic.ui.am2900/components/GUInot4.json b/net.mograsim.logic.ui.am2900/components/GUInot4.json index 5df0c822..ff9a8da3 100644 --- a/net.mograsim.logic.ui.am2900/components/GUInot4.json +++ b/net.mograsim.logic.ui.am2900/components/GUInot4.json @@ -354,5 +354,13 @@ mograsim version: 0.1.3 "path": [] } ] + }, + "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer", + "symbolRendererParams": { + "centerText": "not4", + "horizontalComponentCenter": 17.5, + "centerTextHeight": 5, + "pinLabelHeight": 3.5, + "pinLabelMargin": 0.5 } } \ No newline at end of file diff --git a/net.mograsim.logic.ui.am2900/components/GUIor4.json b/net.mograsim.logic.ui.am2900/components/GUIor4.json index 9eb72165..92e54aa4 100644 --- a/net.mograsim.logic.ui.am2900/components/GUIor4.json +++ b/net.mograsim.logic.ui.am2900/components/GUIor4.json @@ -498,5 +498,13 @@ mograsim version: 0.1.3 } } ] + }, + "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer", + "symbolRendererParams": { + "centerText": "or4", + "horizontalComponentCenter": 17.5, + "centerTextHeight": 5, + "pinLabelHeight": 3.5, + "pinLabelMargin": 0.5 } } \ No newline at end of file diff --git a/net.mograsim.logic.ui.am2900/components/GUIor_4.json b/net.mograsim.logic.ui.am2900/components/GUIor_4.json index 06aa13f7..53ad0d69 100644 --- a/net.mograsim.logic.ui.am2900/components/GUIor_4.json +++ b/net.mograsim.logic.ui.am2900/components/GUIor_4.json @@ -814,5 +814,13 @@ mograsim version: 0.1.3 "path": [] } ] + }, + "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer", + "symbolRendererParams": { + "centerText": "or_4", + "horizontalComponentCenter": 17.5, + "centerTextHeight": 5, + "pinLabelHeight": 3.5, + "pinLabelMargin": 0.5 } } \ No newline at end of file diff --git a/net.mograsim.logic.ui.am2900/components/GUIram2.json b/net.mograsim.logic.ui.am2900/components/GUIram2.json index c1d00ea9..dd051675 100644 --- a/net.mograsim.logic.ui.am2900/components/GUIram2.json +++ b/net.mograsim.logic.ui.am2900/components/GUIram2.json @@ -2770,5 +2770,13 @@ mograsim version: 0.1.3 ] } ] + }, + "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer", + "symbolRendererParams": { + "centerText": "ram2", + "horizontalComponentCenter": 17.5, + "centerTextHeight": 5, + "pinLabelHeight": 3.5, + "pinLabelMargin": 0.5 } } \ No newline at end of file diff --git a/net.mograsim.logic.ui.am2900/components/GUIram4.json b/net.mograsim.logic.ui.am2900/components/GUIram4.json index 87c28929..16f912e2 100644 --- a/net.mograsim.logic.ui.am2900/components/GUIram4.json +++ b/net.mograsim.logic.ui.am2900/components/GUIram4.json @@ -3142,5 +3142,13 @@ mograsim version: 0.1.3 ] } ] + }, + "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer", + "symbolRendererParams": { + "centerText": "ram4", + "horizontalComponentCenter": 17.5, + "centerTextHeight": 5, + "pinLabelHeight": 3.5, + "pinLabelMargin": 0.5 } } \ No newline at end of file diff --git a/net.mograsim.logic.ui.am2900/components/GUIsel2_4.json b/net.mograsim.logic.ui.am2900/components/GUIsel2_4.json index b3845c41..6fa6d3af 100644 --- a/net.mograsim.logic.ui.am2900/components/GUIsel2_4.json +++ b/net.mograsim.logic.ui.am2900/components/GUIsel2_4.json @@ -782,5 +782,13 @@ mograsim version: 0.1.3 "path": [] } ] + }, + "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer", + "symbolRendererParams": { + "centerText": "sel2_4", + "horizontalComponentCenter": 17.5, + "centerTextHeight": 5, + "pinLabelHeight": 3.5, + "pinLabelMargin": 0.5 } } \ No newline at end of file diff --git a/net.mograsim.logic.ui.am2900/components/GUIsel3_4.json b/net.mograsim.logic.ui.am2900/components/GUIsel3_4.json index fdcbfafa..e5b5d461 100644 --- a/net.mograsim.logic.ui.am2900/components/GUIsel3_4.json +++ b/net.mograsim.logic.ui.am2900/components/GUIsel3_4.json @@ -853,5 +853,13 @@ mograsim version: 0.1.3 "path": [] } ] + }, + "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer", + "symbolRendererParams": { + "centerText": "sel3_4", + "horizontalComponentCenter": 17.5, + "centerTextHeight": 5, + "pinLabelHeight": 3.5, + "pinLabelMargin": 0.5 } } \ No newline at end of file diff --git a/net.mograsim.logic.ui.am2900/components/GUIxor.json b/net.mograsim.logic.ui.am2900/components/GUIxor.json index 6b74a5c6..001f5542 100644 --- a/net.mograsim.logic.ui.am2900/components/GUIxor.json +++ b/net.mograsim.logic.ui.am2900/components/GUIxor.json @@ -248,5 +248,13 @@ mograsim version: 0.1.3 } } ] + }, + "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer", + "symbolRendererParams": { + "centerText": "xor", + "horizontalComponentCenter": 17.5, + "centerTextHeight": 5, + "pinLabelHeight": 3.5, + "pinLabelMargin": 0.5 } } \ No newline at end of file diff --git a/net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901.json b/net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901.json index d773d7bd..9fc9e8d4 100644 --- a/net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901.json +++ b/net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901.json @@ -3179,5 +3179,13 @@ mograsim version: 0.1.3 "path": [] } ] + }, + "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer", + "symbolRendererParams": { + "centerText": "Am2901", + "horizontalComponentCenter": 17.5, + "centerTextHeight": 5, + "pinLabelHeight": 3.5, + "pinLabelMargin": 0.5 } } \ No newline at end of file diff --git a/net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901ALUFuncDecode.json b/net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901ALUFuncDecode.json index cf9f5a6e..b30dcdd2 100644 --- a/net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901ALUFuncDecode.json +++ b/net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901ALUFuncDecode.json @@ -651,5 +651,13 @@ mograsim version: 0.1.3 "path": [] } ] + }, + "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer", + "symbolRendererParams": { + "centerText": "Am2901ALUFuncDecode", + "horizontalComponentCenter": 17.5, + "centerTextHeight": 5, + "pinLabelHeight": 3.5, + "pinLabelMargin": 0.5 } } \ No newline at end of file diff --git a/net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901ALUInclDecode.json b/net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901ALUInclDecode.json index 1984f630..39aac796 100644 --- a/net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901ALUInclDecode.json +++ b/net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901ALUInclDecode.json @@ -1415,5 +1415,13 @@ mograsim version: 0.1.3 } } ] + }, + "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer", + "symbolRendererParams": { + "centerText": "Am2901ALUInclDecode", + "horizontalComponentCenter": 17.5, + "centerTextHeight": 5, + "pinLabelHeight": 3.5, + "pinLabelMargin": 0.5 } } \ No newline at end of file diff --git a/net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901ALUInclSourceDecodeInclFunctionDecode.json b/net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901ALUInclSourceDecodeInclFunctionDecode.json index 3481904b..6c9e6d35 100644 --- a/net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901ALUInclSourceDecodeInclFunctionDecode.json +++ b/net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901ALUInclSourceDecodeInclFunctionDecode.json @@ -1293,5 +1293,13 @@ mograsim version: 0.1.3 ] } ] + }, + "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer", + "symbolRendererParams": { + "centerText": "Am2901ALUInclSourceDecodeInclFunctionDecode", + "horizontalComponentCenter": 17.5, + "centerTextHeight": 5, + "pinLabelHeight": 3.5, + "pinLabelMargin": 0.5 } } \ No newline at end of file diff --git a/net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901ALUOneBit.json b/net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901ALUOneBit.json index 84f1a124..5c6215db 100644 --- a/net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901ALUOneBit.json +++ b/net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901ALUOneBit.json @@ -499,5 +499,13 @@ mograsim version: 0.1.3 "path": [] } ] + }, + "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer", + "symbolRendererParams": { + "centerText": "Am2901ALUOneBit", + "horizontalComponentCenter": 17.5, + "centerTextHeight": 5, + "pinLabelHeight": 3.5, + "pinLabelMargin": 0.5 } } \ No newline at end of file diff --git a/net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901DestDecode.json b/net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901DestDecode.json index 20dbfb08..621fccd3 100644 --- a/net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901DestDecode.json +++ b/net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901DestDecode.json @@ -994,5 +994,13 @@ mograsim version: 0.1.3 "path": [] } ] + }, + "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer", + "symbolRendererParams": { + "centerText": "Am2901DestDecode", + "horizontalComponentCenter": 17.5, + "centerTextHeight": 5, + "pinLabelHeight": 3.5, + "pinLabelMargin": 0.5 } } \ No newline at end of file diff --git a/net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901QReg.json b/net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901QReg.json index b2772259..6bc113d5 100644 --- a/net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901QReg.json +++ b/net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901QReg.json @@ -388,5 +388,13 @@ mograsim version: 0.1.3 "path": [] } ] + }, + "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer", + "symbolRendererParams": { + "centerText": "Am2901QReg", + "horizontalComponentCenter": 17.5, + "centerTextHeight": 5, + "pinLabelHeight": 3.5, + "pinLabelMargin": 0.5 } } \ No newline at end of file diff --git a/net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901SourceDecode.json b/net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901SourceDecode.json index e72cc9fb..33b3ff10 100644 --- a/net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901SourceDecode.json +++ b/net.mograsim.logic.ui.am2900/components/am2901/GUIAm2901SourceDecode.json @@ -1033,5 +1033,13 @@ mograsim version: 0.1.3 "path": [] } ] + }, + "symbolRendererSnippetID": "SimpleRectangularLikeSymbolRenderer", + "symbolRendererParams": { + "centerText": "Am2901SourceDecode", + "horizontalComponentCenter": 17.5, + "centerTextHeight": 5, + "pinLabelHeight": 3.5, + "pinLabelMargin": 0.5 } } \ No newline at end of file diff --git a/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/examples/ComponenetSerializer.java b/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/examples/ComponenetSerializer.java index 4c7b5d9f..397592e1 100644 --- a/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/examples/ComponenetSerializer.java +++ b/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/examples/ComponenetSerializer.java @@ -3,6 +3,8 @@ package net.mograsim.logic.ui.examples; import java.io.IOException; import java.util.function.Function; +import com.google.gson.JsonObject; + import net.mograsim.logic.ui.model.ViewModelModifiable; import net.mograsim.logic.ui.model.components.GUIComponent; import net.mograsim.logic.ui.model.components.mi.nandbased.GUI_rsLatch; @@ -57,6 +59,15 @@ public class ComponenetSerializer for (SubmodelComponent comp : components) { SubmodelComponentParams params = comp.calculateParams(getIdentifier); + JsonObject symbolRendererParams = new JsonObject(); + symbolRendererParams.addProperty("centerText", comp.getClass().getSimpleName().substring(3)); // cut away the "GUI" part + symbolRendererParams.addProperty("horizontalComponentCenter", comp.getWidth() / 2); + // use the defaults from SimpleRectangularSubmodelComponent + symbolRendererParams.addProperty("centerTextHeight", 5); + symbolRendererParams.addProperty("pinLabelHeight", 3.5); + symbolRendererParams.addProperty("pinLabelMargin", .5); + params.symbolRendererSnippetID = "SimpleRectangularLikeSymbolRenderer"; + params.symbolRendererParams = symbolRendererParams; JsonHandler.writeJson(params, "components/" + comp.getClass().getName().substring("net.mograsim.logic.ui.model.components.mi.nandbased.".length()).replace('.', '/') + ".json"); diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/submodels/SimpleRectangularSubmodelComponent.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/submodels/SimpleRectangularSubmodelComponent.java index 65114b6b..2bc062e9 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/submodels/SimpleRectangularSubmodelComponent.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/submodels/SimpleRectangularSubmodelComponent.java @@ -93,6 +93,7 @@ public class SimpleRectangularSubmodelComponent extends SubmodelComponent @Override protected void renderSymbol(GeneralGC gc, Rectangle visibleRegion) { + // TODO code duplication: see SimpleRectagularLikeSymbolRendererProvider Font oldFont = gc.getFont(); gc.setFont(new Font(oldFont.getName(), labelFontHeight, oldFont.getStyle())); Point textExtent = gc.textExtent(label); diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/CodeSnippetSupplier.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/CodeSnippetSupplier.java index 62014ca0..8c13e96a 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/CodeSnippetSupplier.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/CodeSnippetSupplier.java @@ -7,14 +7,11 @@ import java.util.Map; import com.google.gson.JsonElement; -import net.haspamelodica.swt.helper.swtobjectwrappers.Point; -import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle; import net.mograsim.logic.ui.serializing.snippets.Renderer; import net.mograsim.logic.ui.serializing.snippets.RendererProvider; +import net.mograsim.logic.ui.serializing.snippets.outlinerenderers.DefaultOutlineRendererProvider; +import net.mograsim.logic.ui.serializing.snippets.symbolrenderers.DefaultSymbolRendererProvider; import net.mograsim.logic.ui.util.JsonHandler; -import net.mograsim.preferences.ColorDefinition; -import net.mograsim.preferences.ColorManager; -import net.mograsim.preferences.Preferences; public class CodeSnippetSupplier { @@ -27,24 +24,8 @@ public class CodeSnippetSupplier private static final RendererProvider defaultSymbolRendererProvider; static { - // TODO this code does not belong here - defaultOutlineRendererProvider = (comp, params) -> (gc, visReg) -> - { - ColorDefinition fg = Preferences.current().getColorDefinition("net.mograsim.logic.ui.color.foreground"); - if (fg != null) - gc.setForeground(ColorManager.current().toColor(fg)); - gc.drawRectangle(comp.getBounds()); - }; - defaultSymbolRendererProvider = (comp, params) -> (gc, visReg) -> - { - ColorDefinition fg = Preferences.current().getColorDefinition("net.mograsim.logic.ui.color.text"); - if (fg != null) - gc.setForeground(ColorManager.current().toColor(fg)); - String id = "TODO";// TODO add an ID of sorts to DeserializedSubmodelComponent - Point idSize = gc.textExtent(id); - Rectangle bounds = comp.getBounds(); - gc.drawText(id, bounds.x + (bounds.width - idSize.x) / 2, bounds.y + (bounds.height - idSize.y) / 2, true); - }; + defaultOutlineRendererProvider = new DefaultOutlineRendererProvider(); + defaultSymbolRendererProvider = new DefaultSymbolRendererProvider(); } static @@ -105,12 +86,13 @@ public class CodeSnippetSupplier return specializedCode; } } + System.err.println("Couldn't load snippet " + id + "; using default"); return defaultSnippet; } private static void tryLoadSnippetClass(String snippetClassName) { - tryInvokeStaticInitializer(snippetClassName, "Error getting snippet code for component class: %s: %s\n"); + tryInvokeStaticInitializer(snippetClassName, "Error getting snippet class: %s: %s\n"); } public static void tryInvokeStaticInitializer(String className, String errorMessageFormat) diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/SubmodelComponentDeserializer.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/SubmodelComponentDeserializer.java index ffb120db..e997ad28 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/SubmodelComponentDeserializer.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/SubmodelComponentDeserializer.java @@ -62,9 +62,8 @@ public final class SubmodelComponentDeserializer DeserializedSubmodelComponent comp = new DeserializedSubmodelComponent(model); comp.setSubmodelScale(params.submodel.innerScale); comp.setOutlineRenderer( - CodeSnippetSupplier.createOutlineRenderer(params.outlineRendererSnippetClass, comp, params.outlineRendererParams)); - comp.setSymbolRenderer( - CodeSnippetSupplier.createSymbolRenderer(params.symbolRendererSnippetClass, comp, params.symbolRendererParams)); + CodeSnippetSupplier.createOutlineRenderer(params.outlineRendererSnippetID, comp, params.outlineRendererParams)); + comp.setSymbolRenderer(CodeSnippetSupplier.createSymbolRenderer(params.symbolRendererSnippetID, comp, params.symbolRendererParams)); // TODO high level states comp.setSize(params.width, params.height); for (InterfacePinParams iPinParams : params.interfacePins) diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/SubmodelComponentParams.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/SubmodelComponentParams.java index a1f2c823..e2a0e482 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/SubmodelComponentParams.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/SubmodelComponentParams.java @@ -19,10 +19,10 @@ public class SubmodelComponentParams public SubmodelParameters submodel; // functionality that needs to be expressed in Java code - public String outlineRendererSnippetClass; + public String outlineRendererSnippetID; public JsonElement outlineRendererParams; - public String symbolRendererSnippetClass; + public String symbolRendererSnippetID; public JsonElement symbolRendererParams; public static class InterfacePinParams diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/snippets/outlinerenderers/DefaultOutlineRendererProvider.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/snippets/outlinerenderers/DefaultOutlineRendererProvider.java new file mode 100644 index 00000000..b236aa8c --- /dev/null +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/snippets/outlinerenderers/DefaultOutlineRendererProvider.java @@ -0,0 +1,26 @@ +package net.mograsim.logic.ui.serializing.snippets.outlinerenderers; + +import com.google.gson.JsonElement; + +import net.mograsim.logic.ui.serializing.DeserializedSubmodelComponent; +import net.mograsim.logic.ui.serializing.snippets.Renderer; +import net.mograsim.logic.ui.serializing.snippets.RendererProvider; +import net.mograsim.preferences.ColorDefinition; +import net.mograsim.preferences.ColorManager; +import net.mograsim.preferences.Preferences; + +public class DefaultOutlineRendererProvider implements RendererProvider +{ + @Override + public Renderer create(DeserializedSubmodelComponent component, JsonElement params) + { + return (gc, visReg) -> + { + ColorDefinition fg = Preferences.current().getColorDefinition("net.mograsim.logic.ui.color.foreground"); + if (fg != null) + gc.setForeground(ColorManager.current().toColor(fg)); + gc.drawRectangle(component.getBounds()); + }; + + } +} \ No newline at end of file diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/snippets/symbolrenderers/CenteredTextSymbolRendererProvider.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/snippets/symbolrenderers/CenteredTextSymbolRendererProvider.java new file mode 100644 index 00000000..de1551bd --- /dev/null +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/snippets/symbolrenderers/CenteredTextSymbolRendererProvider.java @@ -0,0 +1,57 @@ +package net.mograsim.logic.ui.serializing.snippets.symbolrenderers; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; + +import net.haspamelodica.swt.helper.swtobjectwrappers.Font; +import net.haspamelodica.swt.helper.swtobjectwrappers.Point; +import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle; +import net.mograsim.logic.ui.serializing.CodeSnippetSupplier; +import net.mograsim.logic.ui.serializing.DeserializedSubmodelComponent; +import net.mograsim.logic.ui.serializing.snippets.Renderer; +import net.mograsim.logic.ui.serializing.snippets.RendererProvider; +import net.mograsim.preferences.ColorDefinition; +import net.mograsim.preferences.ColorManager; +import net.mograsim.preferences.Preferences; + +/** + * Renders a text ("text") with a given font height ("height") in the center of the component.
+ * Parameter format: + * + *
+ * {
+ *   "text": [String]
+ *   "height": [int]
+ * }
+ * 
+ * + * @author Daniel Kirschten + */ +public class CenteredTextSymbolRendererProvider implements RendererProvider +{ + @Override + public Renderer create(DeserializedSubmodelComponent component, JsonElement params) + { + JsonObject asJsonObject = params.getAsJsonObject(); + String text = asJsonObject.getAsJsonPrimitive("text").getAsString(); + int fontHeight = asJsonObject.getAsJsonPrimitive("height").getAsInt(); + return (gc, visReg) -> + { + Font oldFont = gc.getFont(); + gc.setFont(new Font(oldFont.getName(), fontHeight, oldFont.getStyle())); + ColorDefinition fg = Preferences.current().getColorDefinition("net.mograsim.logic.ui.color.text"); + if (fg != null) + gc.setForeground(ColorManager.current().toColor(fg)); + Point idSize = gc.textExtent(text); + Rectangle bounds = component.getBounds(); + gc.drawText(text, bounds.x + (bounds.width - idSize.x) / 2, bounds.y + (bounds.height - idSize.y) / 2, true); + gc.setFont(oldFont); + }; + } + + static + { + CodeSnippetSupplier.setSymbolRendererProvider(CenteredTextSymbolRendererProvider.class.getCanonicalName(), + new CenteredTextSymbolRendererProvider()); + } +} \ No newline at end of file diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/snippets/symbolrenderers/DefaultSymbolRendererProvider.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/snippets/symbolrenderers/DefaultSymbolRendererProvider.java new file mode 100644 index 00000000..4d445d67 --- /dev/null +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/snippets/symbolrenderers/DefaultSymbolRendererProvider.java @@ -0,0 +1,31 @@ +package net.mograsim.logic.ui.serializing.snippets.symbolrenderers; + +import com.google.gson.JsonElement; + +import net.haspamelodica.swt.helper.swtobjectwrappers.Point; +import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle; +import net.mograsim.logic.ui.serializing.DeserializedSubmodelComponent; +import net.mograsim.logic.ui.serializing.snippets.Renderer; +import net.mograsim.logic.ui.serializing.snippets.RendererProvider; +import net.mograsim.preferences.ColorDefinition; +import net.mograsim.preferences.ColorManager; +import net.mograsim.preferences.Preferences; + +public class DefaultSymbolRendererProvider implements RendererProvider +{ + private static final String id = ""; + + @Override + public Renderer create(DeserializedSubmodelComponent component, JsonElement params) + { + return (gc, visReg) -> + { + ColorDefinition fg = Preferences.current().getColorDefinition("net.mograsim.logic.ui.color.text"); + if (fg != null) + gc.setForeground(ColorManager.current().toColor(fg)); + Point idSize = gc.textExtent(id); + Rectangle bounds = component.getBounds(); + gc.drawText(id, bounds.x + (bounds.width - idSize.x) / 2, bounds.y + (bounds.height - idSize.y) / 2, true); + }; + } +} \ No newline at end of file diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/snippets/symbolrenderers/SimpleRectangularLikeSymbolRendererProvider.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/snippets/symbolrenderers/SimpleRectangularLikeSymbolRendererProvider.java new file mode 100644 index 00000000..a47c47fc --- /dev/null +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/snippets/symbolrenderers/SimpleRectangularLikeSymbolRendererProvider.java @@ -0,0 +1,83 @@ +package net.mograsim.logic.ui.serializing.snippets.symbolrenderers; + +import java.util.Map.Entry; + +import org.eclipse.swt.graphics.Color; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; + +import net.haspamelodica.swt.helper.swtobjectwrappers.Font; +import net.haspamelodica.swt.helper.swtobjectwrappers.Point; +import net.mograsim.logic.ui.model.wires.Pin; +import net.mograsim.logic.ui.serializing.CodeSnippetSupplier; +import net.mograsim.logic.ui.serializing.DeserializedSubmodelComponent; +import net.mograsim.logic.ui.serializing.snippets.Renderer; +import net.mograsim.logic.ui.serializing.snippets.RendererProvider; +import net.mograsim.preferences.Preferences; + +/** + * Renders a text ("centerText") with a given font height ("centerTextHeight") in the center of the component and + * draws a label for each pin with a given font height ("pinLabelHeight"). The labels of pins to the left of a given x + * coordinate ("horizontalComponentCenter") are drawn to the right of the respective pin; labels of pins to the right are drawn + * left. A margin ("pinLabelMargin") is applied for pin label drawing.
+ * Parameter format: + * + *
+ * {
+ *   "centerText": [String]
+ *   "centerTextHeight": [double]
+ *   "horizontalComponentCenter": [double]
+ *   "pinLabelHeight": [double]
+ *   "pinLabelMargin": [double]
+ * }
+ * 
+ * + * @author Daniel Kirschten + */ +public class SimpleRectangularLikeSymbolRendererProvider implements RendererProvider +{ + @Override + public Renderer create(DeserializedSubmodelComponent component, JsonElement params) + { + JsonObject asJsonObject = params.getAsJsonObject(); + String centerText = asJsonObject.getAsJsonPrimitive("centerText").getAsString(); + double centerTextHeight = asJsonObject.getAsJsonPrimitive("centerTextHeight").getAsDouble(); + double horizontalComponentCenter = asJsonObject.getAsJsonPrimitive("horizontalComponentCenter").getAsDouble(); + double pinLabelHeight = asJsonObject.getAsJsonPrimitive("pinLabelHeight").getAsDouble(); + double pinLabelMargin = asJsonObject.getAsJsonPrimitive("pinLabelMargin").getAsDouble(); + return (gc, visReg) -> + { + double posX = component.getPosX(); + double posY = component.getPosY(); + double width = component.getWidth(); + double height = component.getHeight(); + + Font oldFont = gc.getFont(); + gc.setFont(new Font(oldFont.getName(), centerTextHeight, oldFont.getStyle())); + Point textExtent = gc.textExtent(centerText); + Color textColor = Preferences.current().getColor("net.mograsim.logic.ui.color.text"); + if (textColor != null) + gc.setForeground(textColor); + gc.drawText(centerText, posX + (width - textExtent.x) / 2, posY + (height - textExtent.y) / 2, true); + gc.setFont(new Font(oldFont.getName(), pinLabelHeight, oldFont.getStyle())); + for (Entry pinEntry : component.getPins().entrySet()) + { + String pinName = pinEntry.getKey(); + Pin pin = pinEntry.getValue(); + double pinX = pin.getRelX(); + double pinY = posY + pin.getRelY(); + textExtent = gc.textExtent(pinName); + gc.drawText(pinName, posX + pinX + (pinX > horizontalComponentCenter ? -textExtent.x - pinLabelMargin : pinLabelMargin), + pinY - textExtent.y / 2, true); + } + gc.setFont(oldFont); + }; + } + + static + { + CodeSnippetSupplier.setSymbolRendererProvider(SimpleRectangularLikeSymbolRendererProvider.class.getCanonicalName(), + new SimpleRectangularLikeSymbolRendererProvider()); + } +} \ No newline at end of file diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/standardSnippetIDMapping.json b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/standardSnippetIDMapping.json index 82249515..850d54cd 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/standardSnippetIDMapping.json +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/serializing/standardSnippetIDMapping.json @@ -1,3 +1,5 @@ mograsim version: 0.1.3 { + "CenteredTextSymbolRenderer": "net.mograsim.logic.ui.serializing.snippets.symbolrenderers.CenteredTextSymbolRendererProvider", + "SimpleRectangularLikeSymbolRenderer": "net.mograsim.logic.ui.serializing.snippets.symbolrenderers.SimpleRectangularLikeSymbolRendererProvider" } \ No newline at end of file -- 2.17.1