return null;
}
- public String getUniqueName(String prefix) {
- Set<String> names = new HashSet<String>();
+ /**
+ * Get a set of all of the names contained by this node and all its descendants
+ * @param names A set to which the names are added
+ */
+ public void getComponentNames(Set<String> names) {
for (IP3DNode node : getNodes()) {
if (!(node instanceof IP3DVisualNode))
continue;
IP3DVisualNode n = (IP3DVisualNode)node;
names.add(n.getName());
+ if (node instanceof P3DParentNode)
+ ((P3DParentNode<?>) node).getComponentNames(names);
}
- int i = 1;
- while (true) {
- String genName = prefix + "_" + i;
- if (!names.contains(genName))
- return genName;
- i++;
+ }
+
+ /**
+ * Get a unique name in the Plant3D model with a given prefix followed by
+ * an underscore and number.
+ */
+ public String getUniqueName(String prefix) {
+ ParentNode<?> root = getRootNode();
+ if (root instanceof P3DRootNode) {
+ return ((P3DRootNode) root).getUniqueName(prefix);
+ } else {
+ Set<String> names = new HashSet<String>();
+ getComponentNames(names);
+ int i = 1;
+ while (true) {
+ String genName = prefix + "_" + i;
+ if (!names.contains(genName))
+ return genName;
+ i++;
+ }
}
}
throw new NodeException("Cannot set root node orientation");
}
+ /**
+ * Get a unique name in the Plant3D model with a given prefix followed by
+ * an underscore and number.
+ */
public String getUniqueName(String prefix) {
Set<String> names = new HashSet<String>();
for (INode node : getChild()) {
continue;
IP3DVisualNode n = (IP3DVisualNode)node;
names.add(n.getName());
+ if (node instanceof P3DParentNode)
+ ((P3DParentNode<?>) node).getComponentNames(names);
}
int i = 1;
while (true) {