package net.mograsim.logic.model.modeladapter;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
private static void convert(ViewModel viewModel, LogicModelParameters params, Timeline timeline, Map<Pin, Wire> externalWires)
{
- Map<Pin, Wire> logicWiresPerPin = convertWires(getAllPins(viewModel), viewModel.getWires(), externalWires, params, timeline);
+ Map<Pin, Wire> logicWiresPerPin = convertWires(getAllPins(viewModel), viewModel.getWiresByName().values(), externalWires, params,
+ timeline);
Map<Pin, Wire> logicWiresPerPinUnmodifiable = Collections.unmodifiableMap(logicWiresPerPin);
for (GUIComponent guiComp : viewModel.getComponentsByName().values())
WireCrossPoint guiCompCasted = (WireCrossPoint) guiComp;
guiCompCasted.setLogicModelBinding(logicWiresPerPin.get(guiCompCasted.getPin()).createReadOnlyEnd());
} else if (!(guiComp instanceof SubmodelInterface))// nothing to do for SubmodelInterfaces
- createAndLinkComponent(timeline, params, guiComp, logicWiresPerPinUnmodifiable, componentAdapters.get(guiComp.getClass()));
+ createAndLinkComponent(timeline, params, guiComp, logicWiresPerPinUnmodifiable);
}
}
.collect(Collectors.toSet());
}
- private static Map<Pin, Wire> convertWires(Set<Pin> allPins, List<GUIWire> wires, Map<Pin, Wire> externalWires,
+ private static Map<Pin, Wire> convertWires(Set<Pin> allPins, Collection<GUIWire> wires, Map<Pin, Wire> externalWires,
LogicModelParameters params, Timeline timeline)
{
Map<Pin, Set<Pin>> connectedPinGroups = getConnectedPinGroups(allPins, wires);
if (externalWireCandidate != null)
if (externalWire == null)
externalWire = externalWireCandidate;
- else if (externalWire.length == externalWireCandidate.length)
+ else if (externalWire.width == externalWireCandidate.width)
Wire.fuse(externalWire, externalWireCandidate);
else
throw new IllegalArgumentException(
return logicWiresPerPin;
}
- private static void setGUIWiresLogicModelBinding(List<GUIWire> wires, Map<Pin, Wire> logicWiresPerPin)
+ private static void setGUIWiresLogicModelBinding(Collection<GUIWire> wires, Map<Pin, Wire> logicWiresPerPin)
{
Map<Wire, ReadEnd> guiWireSharedReadEnd = logicWiresPerPin.values().stream().distinct()
.collect(Collectors.toMap(Function.identity(), Wire::createReadOnlyEnd));
guiWire.setLogicModelBinding(guiWireSharedReadEnd.get(logicWiresPerPin.get(guiWire.getPin1())));
}
- private static Map<Pin, Set<Pin>> getConnectedPinGroups(Set<Pin> allPins, List<GUIWire> wires)
+ private static Map<Pin, Set<Pin>> getConnectedPinGroups(Set<Pin> allPins, Collection<GUIWire> wires)
{
Map<Pin, Set<Pin>> connectedPinsPerPin = new HashMap<>();
@SuppressWarnings("unchecked")
private static <G extends GUIComponent> void createAndLinkComponent(Timeline timeline, LogicModelParameters params,
- GUIComponent guiComponent, Map<Pin, Wire> logicWiresPerPin, ComponentAdapter<G> adapter)
+ GUIComponent guiComponent, Map<Pin, Wire> logicWiresPerPin)
{
+ Class<?> cls = guiComponent.getClass();
+ ComponentAdapter<? super G> adapter = null;
+ while (cls != GUIComponent.class && adapter == null)
+ {
+ adapter = (ComponentAdapter<? super G>) componentAdapters.get(cls);
+ cls = cls.getSuperclass();
+ }
if (adapter == null)
throw new IllegalArgumentException("Unknown component class: " + guiComponent.getClass());
adapter.createAndLinkComponent(timeline, params, (G) guiComponent, logicWiresPerPin);