Renamed ViewModel to LogicModel
[Mograsim.git] / net.mograsim.logic.model / src / net / mograsim / logic / model / model / LogicModelModifiable.java
1 package net.mograsim.logic.model.model;
2
3 import java.util.Set;
4
5 import net.mograsim.logic.model.model.components.ModelComponent;
6 import net.mograsim.logic.model.model.wires.ModelWire;
7
8 public class LogicModelModifiable extends LogicModel
9 {
10         public String getDefaultComponentName(ModelComponent component)
11         {
12                 Set<String> componentNames = getComponentsByName().keySet();
13                 // TODO get the ID of component
14                 // The following does not work because this method is called in the constructor of DeserializedSubmodelComponent at a time where
15                 // idForSerializingOverride is not yet set
16 //              String componentID = null;
17 //              if (component instanceof DeserializedSubmodelComponent)
18 //                      componentID = ((DeserializedSubmodelComponent) component).idForSerializingOverride;
19 //              if (componentID == null)
20 //                      componentID = component.getClass().getSimpleName();
21                 String componentID = component.getClass().getSimpleName();
22                 String nameBase = componentID + '#';
23                 for (int i = 0;; i++)
24                 {
25                         String nameCandidate = nameBase + i;
26                         if (!componentNames.contains(nameCandidate))
27                                 return nameCandidate;
28                 }
29         }
30
31         public String getDefaultWireName()
32         {
33                 Set<String> wireNames = getWiresByName().keySet();
34                 for (int i = 0;; i++)
35                 {
36                         String nameCandidate = "unnamedWire#" + i;
37                         if (!wireNames.contains(nameCandidate))
38                                 return nameCandidate;
39                 }
40         }
41
42         @Override
43         public void componentCreated(ModelComponent component, Runnable destroyed)
44         {
45                 super.componentCreated(component, destroyed);
46         }
47
48         @Override
49         public void destroyComponent(ModelComponent component)
50         {
51                 super.destroyComponent(component);
52         }
53
54         @Override
55         public void wireCreated(ModelWire wire, Runnable destroyed)
56         {
57                 super.wireCreated(wire, destroyed);
58         }
59
60         @Override
61         public void destroyWire(ModelWire wire)
62         {
63                 super.destroyWire(wire);
64         }
65 }