X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.model%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Fmodel%2FViewModelModifiable.java;h=97993a7d579516343aae5ecd2f7cf6b348bac935;hb=fb382c02950cbff4cdb769819799bb4afafe7b6e;hp=79304ec329ede5e71ac6c0aa06c395943db26a29;hpb=47ea68ed5c444dd14864412639f6a6fd60ab8a0f;p=Mograsim.git diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/ViewModelModifiable.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/ViewModelModifiable.java index 79304ec3..97993a7d 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/ViewModelModifiable.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/ViewModelModifiable.java @@ -5,12 +5,22 @@ import java.util.Set; import net.mograsim.logic.model.model.components.GUIComponent; import net.mograsim.logic.model.model.wires.GUIWire; +//TODO a ViewModel is modifiable without casting to ViewModelModifiable via GUIWire::destroy and GUIComponent::destroy public class ViewModelModifiable extends ViewModel { public String getDefaultComponentName(GUIComponent component) { Set componentNames = getComponentsByName().keySet(); - String nameBase = component.getClass().getSimpleName() + '#'; + // TODO get the ID of component + // The following does not work because this method is called in the constructor of DeserializedSubmodelComponent at a time where + // idForSerializingOverride is not yet set +// String componentID = null; +// if (component instanceof DeserializedSubmodelComponent) +// componentID = ((DeserializedSubmodelComponent) component).idForSerializingOverride; +// if (componentID == null) +// componentID = component.getClass().getSimpleName(); + String componentID = component.getClass().getSimpleName(); + String nameBase = componentID + '#'; for (int i = 0;; i++) { String nameCandidate = nameBase + i; @@ -19,6 +29,17 @@ public class ViewModelModifiable extends ViewModel } } + public String getDefaultWireName() + { + Set wireNames = getWiresByName().keySet(); + for (int i = 0;; i++) + { + String nameCandidate = "unnamedWire#" + i; + if (!wireNames.contains(nameCandidate)) + return nameCandidate; + } + } + @Override public void componentCreated(GUIComponent component) {