Fixed a bug in Am2900; created dlatch8/80; relayouted some components
[Mograsim.git] / net.mograsim.logic.model / src / net / mograsim / logic / model / model / components / atomic / ModelMerger.java
index c2856e1..6efc9ad 100644 (file)
@@ -6,11 +6,13 @@ import net.haspamelodica.swt.helper.gcs.GeneralGC;
 import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
 import net.mograsim.logic.core.types.BitVectorFormatter;
 import net.mograsim.logic.core.wires.CoreWire.ReadEnd;
-import net.mograsim.logic.model.model.ViewModelModifiable;
+import net.mograsim.logic.model.model.LogicModelModifiable;
 import net.mograsim.logic.model.model.components.ModelComponent;
+import net.mograsim.logic.model.model.components.Orientation;
+import net.mograsim.logic.model.model.components.atomic.ModelSplitter.SplitterParams;
 import net.mograsim.logic.model.model.wires.Pin;
 import net.mograsim.logic.model.model.wires.PinUsage;
-import net.mograsim.logic.model.modeladapter.ViewLogicModelAdapter;
+import net.mograsim.logic.model.modeladapter.LogicCoreAdapter;
 import net.mograsim.logic.model.modeladapter.componentadapters.MergerAdapter;
 import net.mograsim.logic.model.serializing.IdentifyParams;
 import net.mograsim.logic.model.serializing.IndirectModelComponentCreator;
@@ -18,6 +20,7 @@ import net.mograsim.preferences.ColorDefinition;
 import net.mograsim.preferences.ColorManager;
 import net.mograsim.preferences.Preferences;
 
+//TODO delete this legacy class
 public class ModelMerger extends ModelComponent
 {
        private static final double width = 10;
@@ -29,21 +32,23 @@ public class ModelMerger extends ModelComponent
        private final ReadEnd[] inputEnds;
        private ReadEnd outputEnd;
 
-       public ModelMerger(ViewModelModifiable model, int logicWidth)
+       public ModelMerger(LogicModelModifiable model, int logicWidth)
        {
                this(model, logicWidth, null);
        }
 
-       public ModelMerger(ViewModelModifiable model, int logicWidth, String name)
+       public ModelMerger(LogicModelModifiable model, int logicWidth, String name)
        {
-               super(model, name);
+               super(model, name, false);
                this.logicWidth = logicWidth;
                setSize(width, (logicWidth - 1) * heightPerPin);
                double inputHeight = (logicWidth - 1) * heightPerPin;
                for (int i = 0; i < logicWidth; i++, inputHeight -= 10)
-                       addPin(new Pin(this, "I" + i, 1, PinUsage.TRISTATE, 0, inputHeight));
-               addPin(this.outputPin = new Pin(this, "O", logicWidth, PinUsage.TRISTATE, width, (logicWidth - 1) * heightPerPin / 2));
+                       addPin(new Pin(model, this, "O" + i, 1, PinUsage.TRISTATE, 0, inputHeight));
+               addPin(this.outputPin = new Pin(model, this, "I", logicWidth, PinUsage.TRISTATE, width, (logicWidth - 1) * heightPerPin / 2));
                inputEnds = new ReadEnd[logicWidth];
+
+               init();
        }
 
        @Override
@@ -79,19 +84,29 @@ public class ModelMerger extends ModelComponent
                gc.setLineCap(oldLineCap);
        }
 
+       @Override
+       public Pin getPin(String name)
+       {
+               Pin pin = getPinOrNull(name);
+               return pin == null ? getPin(name.replace('O', 'i').replace('I', 'O').replace('i', 'I')) : pin;
+       }
+
        @Override
        public String getIDForSerializing(IdentifyParams idParams)
        {
-               return "Merger";
+               return "Splitter";
        }
 
        @Override
-       public Integer getParamsForSerializing(IdentifyParams idParams)
+       public SplitterParams getParamsForSerializing(IdentifyParams idParams)
        {
-               return logicWidth;
+               SplitterParams splitterParams = new SplitterParams();
+               splitterParams.logicWidth = logicWidth;
+               splitterParams.orientation = Orientation.LEFT;
+               return splitterParams;
        }
 
-       public void setLogicModelBinding(ReadEnd[] inputEnds, ReadEnd outputEnd)
+       public void setCoreModelBinding(ReadEnd[] inputEnds, ReadEnd outputEnd)
        {
                System.arraycopy(inputEnds, 0, this.inputEnds, 0, logicWidth);
                this.outputEnd = outputEnd;
@@ -104,7 +119,7 @@ public class ModelMerger extends ModelComponent
 
        static
        {
-               ViewLogicModelAdapter.addComponentAdapter(new MergerAdapter());
+               LogicCoreAdapter.addComponentAdapter(new MergerAdapter());
                IndirectModelComponentCreator.setComponentSupplier(ModelMerger.class.getCanonicalName(),
                                (m, p, n) -> new ModelMerger(m, p.getAsInt(), n));
        }