import net.mograsim.logic.model.editor.states.EditorState;
import net.mograsim.logic.model.model.ViewModelModifiable;
import net.mograsim.logic.model.model.components.GUIComponent;
+import net.mograsim.logic.model.model.components.submodels.SubmodelComponent;
import net.mograsim.logic.model.model.wires.GUIWire;
import net.mograsim.logic.model.model.wires.MovablePin;
import net.mograsim.logic.model.model.wires.Pin;
ViewModelModifiable model = editor.getSubmodel();
Map<String, GUIComponent> compsByName = model.getComponentsByName();
Set<GUIComponent> comps = new HashSet<>(compsByName.values());
- GUIComponent interfaceComp = compsByName.get("_submodelinterface");
+ GUIComponent interfaceComp = compsByName.get(SubmodelComponent.SUBMODEL_INTERFACE_NAME);
comps.remove(interfaceComp);
registerInterfaceComponent(interfaceComp);
comps.forEach(c -> registerComponent(c));
-
- model.getWires().forEach(w -> registerWire(w));
+
+ model.getWiresByName().values().forEach(w -> registerWire(w));
addHandle(cornerHandle = new CornerHandle(editor.toBeEdited));
}
}
Point[] newPath = w.getPath();
int newLength = newPath == null ? 0 : newPath.length;
int diff = oldLength.getAndSet(newLength) - newLength;
- if(diff != 0)
+ if (diff != 0)
{
- if(diff > 0)
+ if (diff > 0)
{
- for(int i = 0; i < diff; i++)
+ for (int i = 0; i < diff; i++)
addWirePointHandle(w);
}
-
+
List<WirePointHandle> wpHandles = pointHandlesPerWire.get(w);
int size = wpHandles.size();
- for(int i = 0; i < size; i++)
+ for (int i = 0; i < size; i++)
{
wpHandles.get(i).setIndex(i);
}
private void addInterfacePinHandle(Pin p)
{
- //The following is not an alternative to the cast, because the new pin is not yet in the map, when the listener is called
- //editor.toBeEdited.getSubmodelMovablePins().get(p.name);
+ // The following is not an alternative to the cast, because the new pin is not yet in the map, when the listener is called
+ // editor.toBeEdited.getSubmodelMovablePins().get(p.name);
MovablePin pM = (MovablePin) p;
InterfacePinHandle h = new InterfacePinHandle(pM, editor.toBeEdited);
handlePerInterfacePin.put(pM, h);
this.wirePointHandles.add(h);
addHandle(h);
}
-
+
void destroyWirePointHandle(GUIWire owner, WirePointHandle h)
{
List<WirePointHandle> handles = pointHandlesPerWire.get(owner);
private void removeWirePointHandles(GUIWire owner)
{
- if(!pointHandlesPerWire.containsKey(owner))
+ if (!pointHandlesPerWire.containsKey(owner))
return;
pointHandlesPerWire.get(owner).forEach(h ->
{
{
return handlePerWire.get(parent);
}
-
+
public Handle getInterfacePinHandle(Pin p)
{
return handlePerInterfacePin.get(p);
{
return Collections.unmodifiableCollection(handlePerPin.values());
}
-
+
/**
* @return An unmodifiable view of all registered {@link InterfacePinHandle}s
*/
{
EditorState entryState = editor.stateManager.getState();
+ // TODO: As soon as wires connected to a component being removed also are removed, change priority
if (!cornerHandle.click(clicked.x, clicked.y, stateMask, entryState))
if (!click(handlePerPin.values(), clicked, entryState, stateMask))
if (!click(handlePerInterfacePin.values(), clicked, entryState, stateMask))
if (!click(getWirePointHandles(), clicked, entryState, stateMask))
if (!click(getWireHandles(), clicked, entryState, stateMask))
if (!click(handlePerComp.values(), clicked, entryState, stateMask))
- entryState.clickedEmpty(clicked, stateMask);
+ entryState.clickedEmpty(clicked, stateMask);
entryState.clicked(clicked, stateMask);
}
- private boolean click(Collection<? extends Handle> handles, Point clicked, EditorState state, int stateMask)
+ private static boolean click(Collection<? extends Handle> handles, Point clicked, EditorState state, int stateMask)
{
for (Handle h : handles)
if (h.click(clicked.x, clicked.y, stateMask, state))