projects
/
Mograsim.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Renamed core components to have the common prefix Core
[Mograsim.git]
/
net.mograsim.logic.model
/
src
/
net
/
mograsim
/
logic
/
model
/
modeladapter
/
ViewLogicModelAdapter.java
diff --git
a/net.mograsim.logic.model/src/net/mograsim/logic/model/modeladapter/ViewLogicModelAdapter.java
b/net.mograsim.logic.model/src/net/mograsim/logic/model/modeladapter/ViewLogicModelAdapter.java
index
16b52ee
..
8c337cd
100644
(file)
--- a/
net.mograsim.logic.model/src/net/mograsim/logic/model/modeladapter/ViewLogicModelAdapter.java
+++ b/
net.mograsim.logic.model/src/net/mograsim/logic/model/modeladapter/ViewLogicModelAdapter.java
@@
-1,9
+1,9
@@
package net.mograsim.logic.model.modeladapter;
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.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;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
@@
-11,8
+11,8
@@
import java.util.function.Function;
import java.util.stream.Collectors;
import net.mograsim.logic.core.timeline.Timeline;
import java.util.stream.Collectors;
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.core.wires.
Core
Wire;
+import net.mograsim.logic.core.wires.
Core
Wire.ReadEnd;
import net.mograsim.logic.model.model.ViewModel;
import net.mograsim.logic.model.model.components.GUIComponent;
import net.mograsim.logic.model.model.components.submodels.SubmodelComponent;
import net.mograsim.logic.model.model.ViewModel;
import net.mograsim.logic.model.model.components.GUIComponent;
import net.mograsim.logic.model.model.components.submodels.SubmodelComponent;
@@
-41,10
+41,11
@@
public class ViewLogicModelAdapter
return timeline;
}
return timeline;
}
- private static void convert(ViewModel viewModel, LogicModelParameters params, Timeline timeline, Map<Pin, Wire> externalWires)
+ private static void convert(ViewModel viewModel, LogicModelParameters params, Timeline timeline, Map<Pin,
Core
Wire> externalWires)
{
{
- Map<Pin, Wire> logicWiresPerPin = convertWires(getAllPins(viewModel), viewModel.getWires(), externalWires, params, timeline);
- Map<Pin, Wire> logicWiresPerPinUnmodifiable = Collections.unmodifiableMap(logicWiresPerPin);
+ Map<Pin, CoreWire> logicWiresPerPin = convertWires(getAllPins(viewModel), viewModel.getWiresByName().values(), externalWires, params,
+ timeline);
+ Map<Pin, CoreWire> logicWiresPerPinUnmodifiable = Collections.unmodifiableMap(logicWiresPerPin);
for (GUIComponent guiComp : viewModel.getComponentsByName().values())
{
for (GUIComponent guiComp : viewModel.getComponentsByName().values())
{
@@
-52,7
+53,7
@@
public class ViewLogicModelAdapter
{
SubmodelComponent guiCompCasted = (SubmodelComponent) guiComp;
Map<String, Pin> supermodelPins = guiCompCasted.getSupermodelPins();
{
SubmodelComponent guiCompCasted = (SubmodelComponent) guiComp;
Map<String, Pin> supermodelPins = guiCompCasted.getSupermodelPins();
- Map<Pin, Wire> externalWiresForSubmodel = supermodelPins.entrySet().stream()
+ Map<Pin,
Core
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)
.collect(Collectors.toMap(e -> guiCompCasted.getSubmodelPin(e.getKey()), e -> logicWiresPerPin.get(e.getValue())));
convert(guiCompCasted.submodel, params, timeline, externalWiresForSubmodel);
} else if (guiComp instanceof WireCrossPoint)
@@
-60,7
+61,7
@@
public class ViewLogicModelAdapter
WireCrossPoint guiCompCasted = (WireCrossPoint) guiComp;
guiCompCasted.setLogicModelBinding(logicWiresPerPin.get(guiCompCasted.getPin()).createReadOnlyEnd());
} else if (!(guiComp instanceof SubmodelInterface))// nothing to do for SubmodelInterfaces
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);
}
}
}
}
@@
-70,50
+71,50
@@
public class ViewLogicModelAdapter
.collect(Collectors.toSet());
}
.collect(Collectors.toSet());
}
- private static Map<Pin,
Wire> convertWires(Set<Pin> allPins, List<GUIWire> wires, Map<Pin,
Wire> externalWires,
+ private static Map<Pin,
CoreWire> convertWires(Set<Pin> allPins, Collection<GUIWire> wires, Map<Pin, Core
Wire> externalWires,
LogicModelParameters params, Timeline timeline)
{
Map<Pin, Set<Pin>> connectedPinGroups = getConnectedPinGroups(allPins, wires);
LogicModelParameters params, Timeline timeline)
{
Map<Pin, Set<Pin>> connectedPinGroups = getConnectedPinGroups(allPins, wires);
- Map<Pin, Wire> logicWiresPerPin = createLogicWires(params, timeline, connectedPinGroups, externalWires);
+ Map<Pin,
Core
Wire> logicWiresPerPin = createLogicWires(params, timeline, connectedPinGroups, externalWires);
setGUIWiresLogicModelBinding(wires, logicWiresPerPin);
return logicWiresPerPin;
}
setGUIWiresLogicModelBinding(wires, logicWiresPerPin);
return logicWiresPerPin;
}
- private static Map<Pin, Wire> createLogicWires(LogicModelParameters params, Timeline timeline, Map<Pin, Set<Pin>> connectedPinGroups,
- Map<Pin, Wire> externalWires)
+ private static Map<Pin,
Core
Wire> createLogicWires(LogicModelParameters params, Timeline timeline, Map<Pin, Set<Pin>> connectedPinGroups,
+ Map<Pin,
Core
Wire> externalWires)
{
{
- Map<Pin, Wire> logicWiresPerPin = new HashMap<>();
- Map<Set<Pin>, Wire> logicWiresPerPinGroup = new HashMap<>();
+ Map<Pin,
Core
Wire> logicWiresPerPin = new HashMap<>();
+ Map<Set<Pin>,
Core
Wire> logicWiresPerPinGroup = new HashMap<>();
for (Entry<Pin, Set<Pin>> e : connectedPinGroups.entrySet())
logicWiresPerPin.put(e.getKey(), logicWiresPerPinGroup.computeIfAbsent(e.getValue(), set ->
{
for (Entry<Pin, Set<Pin>> e : connectedPinGroups.entrySet())
logicWiresPerPin.put(e.getKey(), logicWiresPerPinGroup.computeIfAbsent(e.getValue(), set ->
{
- Wire externalWire = null;
+
Core
Wire externalWire = null;
for (Pin p : set)
{
for (Pin p : set)
{
- Wire externalWireCandidate = externalWires.get(p);
+
Core
Wire externalWireCandidate = externalWires.get(p);
if (externalWireCandidate != null)
if (externalWire == null)
externalWire = externalWireCandidate;
if (externalWireCandidate != null)
if (externalWire == null)
externalWire = externalWireCandidate;
- else if (externalWire.
length == externalWireCandidate.leng
th)
- Wire.fuse(externalWire, externalWireCandidate);
+ else if (externalWire.
width == externalWireCandidate.wid
th)
+
Core
Wire.fuse(externalWire, externalWireCandidate);
else
throw new IllegalArgumentException(
"Two pins to external wires with different logicWidths can't be connected directly");
}
else
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;
+ return externalWire == null ? new
Core
Wire(timeline, e.getKey().logicWidth, params.wireTravelTime) : externalWire;
}));
return logicWiresPerPin;
}
}));
return logicWiresPerPin;
}
- private static void setGUIWiresLogicModelBinding(
List<GUIWire> wires, Map<Pin,
Wire> logicWiresPerPin)
+ private static void setGUIWiresLogicModelBinding(
Collection<GUIWire> wires, Map<Pin, Core
Wire> logicWiresPerPin)
{
{
- Map<Wire, ReadEnd> guiWireSharedReadEnd = logicWiresPerPin.values().stream().distinct()
- .collect(Collectors.toMap(Function.identity(), Wire::createReadOnlyEnd));
+ Map<
Core
Wire, ReadEnd> guiWireSharedReadEnd = logicWiresPerPin.values().stream().distinct()
+ .collect(Collectors.toMap(Function.identity(),
Core
Wire::createReadOnlyEnd));
for (GUIWire guiWire : wires)
guiWire.setLogicModelBinding(guiWireSharedReadEnd.get(logicWiresPerPin.get(guiWire.getPin1())));
}
for (GUIWire guiWire : wires)
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<>();
{
Map<Pin, Set<Pin>> connectedPinsPerPin = new HashMap<>();
@@
-143,8
+144,15
@@
public class ViewLogicModelAdapter
@SuppressWarnings("unchecked")
private static <G extends GUIComponent> void createAndLinkComponent(Timeline timeline, LogicModelParameters params,
@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,
CoreWire> 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);
if (adapter == null)
throw new IllegalArgumentException("Unknown component class: " + guiComponent.getClass());
adapter.createAndLinkComponent(timeline, params, (G) guiComponent, logicWiresPerPin);