import java.util.function.Function;
import java.util.stream.Collectors;
-import net.mograsim.logic.core.components.gates.AndGate;
-import net.mograsim.logic.core.components.gates.NotGate;
-import net.mograsim.logic.core.components.gates.OrGate;
import net.mograsim.logic.core.timeline.Timeline;
import net.mograsim.logic.core.wires.Wire;
import net.mograsim.logic.core.wires.Wire.ReadEnd;
import net.mograsim.logic.ui.model.ViewModel;
-import net.mograsim.logic.ui.model.components.GUIAndGate;
import net.mograsim.logic.ui.model.components.GUIComponent;
-import net.mograsim.logic.ui.model.components.GUINotGate;
-import net.mograsim.logic.ui.model.components.GUIOrGate;
import net.mograsim.logic.ui.model.components.SubmodelComponent;
import net.mograsim.logic.ui.model.components.SubmodelInterface;
import net.mograsim.logic.ui.model.wires.GUIWire;
import net.mograsim.logic.ui.model.wires.Pin;
import net.mograsim.logic.ui.model.wires.WireCrossPoint;
-import net.mograsim.logic.ui.modeladapter.componentadapters.AtomicAm2901NANDBasedAdapter;
-import net.mograsim.logic.ui.modeladapter.componentadapters.BitDisplayAdapter;
import net.mograsim.logic.ui.modeladapter.componentadapters.ComponentAdapter;
-import net.mograsim.logic.ui.modeladapter.componentadapters.ManualSwitchAdapter;
-import net.mograsim.logic.ui.modeladapter.componentadapters.SimpleGateAdapter;
public class ViewLogicModelAdapter
{
- private final static Map<Class<? extends GUIComponent>, ComponentAdapter<? extends GUIComponent>> componentAdapters;
- static
+ private final static Map<Class<? extends GUIComponent>, ComponentAdapter<? extends GUIComponent>> componentAdapters = new HashMap<>();
+
+ public static void addComponentAdapter(ComponentAdapter<? extends GUIComponent> componentAdapter)
{
- Set<ComponentAdapter<? extends GUIComponent>> componentAdaptersModifiable = new HashSet<>();
- componentAdaptersModifiable.add(new SimpleGateAdapter<>(GUIOrGate.class, OrGate::new));
- componentAdaptersModifiable.add(new SimpleGateAdapter<>(GUIAndGate.class, AndGate::new));
- componentAdaptersModifiable.add(new SimpleGateAdapter<>(GUINotGate.class, (t, p, o, i) -> new NotGate(t, p, i[0], o)));
- componentAdaptersModifiable.add(new ManualSwitchAdapter());
- componentAdaptersModifiable.add(new BitDisplayAdapter());
- componentAdaptersModifiable.add(new AtomicAm2901NANDBasedAdapter());
- // TODO list all adapters here
- componentAdapters = Collections.unmodifiableMap(
- componentAdaptersModifiable.stream().collect(Collectors.toMap(ComponentAdapter::getSupportedClass, Function.identity())));
+ componentAdapters.put(componentAdapter.getSupportedClass(), componentAdapter);
}
public static Timeline convert(ViewModel viewModel, LogicModelParameters params)
if (guiComp instanceof SubmodelComponent)
{
SubmodelComponent guiCompCasted = (SubmodelComponent) guiComp;
- Map<Pin, Pin> supermodelPinsPerSubmodelPin = guiCompCasted.getSupermodelPinsPerSubmodelPin();
- Map<Pin, Wire> externalWiresForSubmodel = supermodelPinsPerSubmodelPin.entrySet().stream()
- .collect(Collectors.toMap(Entry::getKey, e -> logicWiresPerPin.get(e.getValue())));
+ Map<String, Pin> supermodelPins = guiCompCasted.getSupermodelPins();
+ Map<Pin, Wire> externalWiresForSubmodel = supermodelPins.entrySet().stream()
+ .collect(Collectors.toMap(e -> guiCompCasted.getSubmodelPin(e.getKey()), e -> logicWiresPerPin.get(e.getValue())));
convert(guiCompCasted.submodel, params, timeline, externalWiresForSubmodel);
} else if (guiComp instanceof WireCrossPoint)
{
private static Set<Pin> getAllPins(ViewModel viewModel)
{
- return viewModel.getComponents().stream().flatMap(component -> component.getPins().stream()).collect(Collectors.toSet());
+ return viewModel.getComponents().stream().flatMap(component -> component.getPins().values().stream()).collect(Collectors.toSet());
}
private static Map<Pin, Wire> convertWires(Set<Pin> allPins, List<GUIWire> wires, Map<Pin, Wire> externalWires,
if (externalWireCandidate != null)
if (externalWire == null)
externalWire = externalWireCandidate;
+ else if (externalWire.length == externalWireCandidate.length)
+ Wire.fuse(externalWire, externalWireCandidate);
else
- throw new IllegalArgumentException("Two pins to external wires can't be connected directly");
+ throw new IllegalArgumentException(
+ "Two pins to external wires with different logicWidths can't be connected directly");
}
return externalWire == null ? new Wire(timeline, e.getKey().logicWidth, params.wireTravelTime) : externalWire;
}));