+++ /dev/null
-package net.mograsim.logic.model.model.components.atomic;
-
-import org.eclipse.swt.SWT;
-
-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.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.LogicCoreAdapter;
-import net.mograsim.logic.model.modeladapter.componentadapters.MergerAdapter;
-import net.mograsim.logic.model.serializing.IdentifyParams;
-import net.mograsim.logic.model.serializing.IndirectModelComponentCreator;
-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;
- private static final double heightPerPin = 10;
-
- public final int logicWidth;
- private final Pin outputPin;
-
- private final ReadEnd[] inputEnds;
- private ReadEnd outputEnd;
-
- public ModelMerger(LogicModelModifiable model, int logicWidth)
- {
- this(model, logicWidth, null);
- }
-
- public ModelMerger(LogicModelModifiable model, int logicWidth, String 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(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
- public void render(GeneralGC gc, Rectangle visibleRegion)
- {
- double posX = getPosX();
- double posY = getPosY();
-
- ColorDefinition c = BitVectorFormatter.formatAsColor(outputEnd);
- if (c != null)
- gc.setForeground(ColorManager.current().toColor(c));
- gc.setLineWidth(
- Preferences.current().getDouble("net.mograsim.logic.model.linewidth.wire." + (logicWidth == 1 ? "singlebit" : "multibit")));
- double outLineY = posY + (logicWidth - 1) * heightPerPin / 2;
- gc.drawLine(posX + width / 2, outLineY, posX + width, outLineY);
- gc.setLineWidth(Preferences.current().getDouble("net.mograsim.logic.model.linewidth.wire.singlebit"));
- double inputHeight = posY;
- for (int i = 0; i < logicWidth; i++, inputHeight += 10)
- {
- c = BitVectorFormatter.formatAsColor(inputEnds[i]);
- if (c != null)
- gc.setForeground(ColorManager.current().toColor(c));
- gc.drawLine(posX, inputHeight, posX + width / 2, inputHeight);
- }
- gc.setForeground(Preferences.current().getColor("net.mograsim.logic.model.color.foreground"));
- int oldLineCap = gc.getLineCap();
- int lineJoin = gc.getLineJoin();
- // TODO find better "replacement" for JOIN_BEVEL
- // TODO it looks weird that the vertical line is thinner than the single multibit wire.
- gc.setLineCap(lineJoin == SWT.JOIN_MITER ? SWT.CAP_SQUARE : lineJoin == SWT.JOIN_ROUND ? SWT.CAP_ROUND : SWT.CAP_SQUARE);
- gc.drawLine(posX + width / 2, posY, posX + width / 2, posY + heightPerPin * (logicWidth - 1));
- gc.setLineWidth(Preferences.current().getDouble("net.mograsim.logic.model.linewidth.default"));
- 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 "Splitter";
- }
-
- @Override
- public SplitterParams getParamsForSerializing(IdentifyParams idParams)
- {
- SplitterParams splitterParams = new SplitterParams();
- splitterParams.logicWidth = logicWidth;
- splitterParams.orientation = Orientation.LEFT;
- return splitterParams;
- }
-
- public void setCoreModelBinding(ReadEnd[] inputEnds, ReadEnd outputEnd)
- {
- System.arraycopy(inputEnds, 0, this.inputEnds, 0, logicWidth);
- this.outputEnd = outputEnd;
- }
-
- public Pin getOutputPin()
- {
- return outputPin;
- }
-
- static
- {
- LogicCoreAdapter.addComponentAdapter(new MergerAdapter());
- IndirectModelComponentCreator.setComponentSupplier(ModelMerger.class.getCanonicalName(),
- (m, p, n) -> new ModelMerger(m, p.getAsInt(), n));
- }
-}
\ No newline at end of file
+++ /dev/null
-package net.mograsim.logic.model.modeladapter.componentadapters;
-
-import java.util.Map;
-
-import net.mograsim.logic.core.timeline.Timeline;
-import net.mograsim.logic.core.wires.CoreWire;
-import net.mograsim.logic.core.wires.CoreWire.ReadEnd;
-import net.mograsim.logic.model.model.components.atomic.ModelMerger;
-import net.mograsim.logic.model.model.wires.Pin;
-import net.mograsim.logic.model.modeladapter.CoreModelParameters;
-
-public class MergerAdapter implements ComponentAdapter<ModelMerger>
-{
- @Override
- public Class<ModelMerger> getSupportedClass()
- {
- return ModelMerger.class;
- }
-
- @Override
- public void createAndLinkComponent(Timeline timeline, CoreModelParameters params, ModelMerger modelComponent,
- Map<Pin, CoreWire> logicWiresPerPin)
- {
- CoreWire output = logicWiresPerPin.get(modelComponent.getPin("O"));
- ReadEnd[] inputEnds = new ReadEnd[modelComponent.logicWidth];
- for (int i = 0; i < modelComponent.logicWidth; i++)
- {
- CoreWire input = logicWiresPerPin.get(modelComponent.getPin("I" + (modelComponent.logicWidth - 1 - i)));
- CoreWire.fuse(input, output, 0, i);
- inputEnds[i] = input.createReadOnlyEnd();
- }
- modelComponent.setCoreModelBinding(inputEnds, output.createReadOnlyEnd());
- }
-}
\ No newline at end of file