Skip to content

Commit

Permalink
GUI: update object substitution logic
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesTaelman committed Mar 28, 2016
1 parent 0df6366 commit bbccea2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 99 deletions.
113 changes: 22 additions & 91 deletions src/main/java/axoloti/Patch.java
Original file line number Diff line number Diff line change
Expand Up @@ -2234,100 +2234,29 @@ public boolean IsLocked() {
}

public AxoObjectInstanceAbstract ChangeObjectInstanceType(AxoObjectInstanceAbstract obj, AxoObjectAbstract objType) {
/*
if (obj.getType() == objType) {
return;
}*/
String n = obj.getInstanceName();
obj.setInstanceName(n + "____tmp");

// if (obj.getType().id.equals(objType.id)) return;
// TODO: preserve presets and modulations
// TODO: copy attributes tooo!
Map<String, ParameterInstance> params = new TreeMap<String, ParameterInstance>();
for (ParameterInstance p : obj.getParameterInstances()) {
params.put(p.getName(), p);
}
Map<String, AttributeInstance> attrs = new TreeMap<String, AttributeInstance>();
for (AttributeInstance a : obj.getAttributeInstances()) {
attrs.put(a.getName(), a);
}
Map<String, InletInstance> inlets = new TreeMap<String, InletInstance>();
for (InletInstance il : obj.GetInletInstances()) {
inlets.put(il.GetLabel(), il);
}
Map<String, OutletInstance> outlets = new TreeMap<String, OutletInstance>();
for (OutletInstance ol : obj.GetOutletInstances()) {
outlets.put(ol.GetLabel(), ol);
}

// check if instancename was standard name (objname_1 etc)
String newname;
String[] ss = n.split("_");
boolean hasNumeralSuffix = false;
try {
if ((ss.length > 1) && (Integer.toString(Integer.parseInt(ss[ss.length - 1]))).equals(ss[ss.length - 1])) {
hasNumeralSuffix = true;
}
} catch (NumberFormatException e) {
return obj;
}
if ((hasNumeralSuffix) && (obj.typeName.equals(n.substring(0, n.length() - ss[ss.length - 1].length() - 1)))) {
// find free index
int i = 1;
String n2 = objType.getDefaultInstanceName() + "_";
while (GetObjectInstance(n2 + i) != null) {
i++;
}
newname = n2 + i;
} else {
// preserve instancename
newname = n;
if (!(obj instanceof AxoObjectInstance)) {
return obj;
}
AxoObjectInstanceAbstract newObj = AddObjectInstance(objType, obj.getLocation());

for (ParameterInstance p : newObj.getParameterInstances()) {
ParameterInstance p1 = params.get(p.getName());
if (p1 != null) {
p.CopyValueFrom(p1);
}
}
for (AttributeInstance a : newObj.getAttributeInstances()) {
AttributeInstance a1 = attrs.get(a.getName());
if (a1 != null) {
a.CopyValueFrom(a1);
}
}
for (OutletInstance ol : newObj.GetOutletInstances()) {
OutletInstance ol1 = outlets.get(ol.GetLabel());
if (ol1 != null) {
Net n1 = GetNet(ol1);
if (n1 != null && n1.dest != null) {
ArrayList<InletInstance> dests = new ArrayList<InletInstance>(n1.dest);
for (InletInstance i : dests) {
AddConnection(i, ol);
}
}
}
}

for (InletInstance il : newObj.GetInletInstances()) {
InletInstance il1 = inlets.get(il.GetLabel());
if (il1 != null) {
Net n1 = GetNet(il1);
if (n1 != null && n1.source != null) {
ArrayList<OutletInstance> srcs = new ArrayList<OutletInstance>(n1.source);
for (OutletInstance o : srcs) {
AddConnection(il, o);
}
}
}
}

this.delete(obj);
newObj.setInstanceName(newname);
newObj.SetSelected(true);
SetDirty();
return newObj;
String n = obj.getInstanceName();
obj.setInstanceName(n + "____tmp");
AxoObjectInstanceAbstract obj1 = AddObjectInstance(objType, obj.getLocation());
if ((obj1 instanceof AxoObjectInstance) && (obj instanceof AxoObjectInstance)) {
AxoObjectInstance new_obj = (AxoObjectInstance) obj1;
AxoObjectInstance old_obj = (AxoObjectInstance) obj;
new_obj.outletInstances = old_obj.outletInstances;
new_obj.inletInstances = old_obj.inletInstances;
new_obj.parameterInstances = old_obj.parameterInstances;
new_obj.attributeInstances = old_obj.attributeInstances;
new_obj.PostConstructor();
}
delete(obj);
obj1.setName(n);
obj1.PostConstructor();
obj1.repaint();
return obj1;
}

void invalidate() {
Expand All @@ -2352,7 +2281,9 @@ public void PromoteOverloading() {
for (AxoObjectInstanceAbstract o : objectinstances) {
if (!ProcessedInstances.contains(o.getInstanceName())) {
ProcessedInstances.add(o.getInstanceName());
if (o.isTypeWasAmbiguous()) {
o.PromoteToOverloadedObj();
}
p = true;
break;
}
Expand Down
14 changes: 6 additions & 8 deletions src/main/java/axoloti/object/AxoObjectInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public class AxoObjectInstance extends AxoObjectInstanceAbstract implements Obje
@ElementList(entry = "spinner", type = AttributeInstanceSpinner.class, inline = true, required = false),
@ElementList(entry = "file", type = AttributeInstanceSDFile.class, inline = true, required = false),
@ElementList(entry = "text", type = AttributeInstanceTextEditor.class, inline = true, required = false)})
ArrayList<AttributeInstance> attributeInstances;
public ArrayList<AttributeInstance> attributeInstances;
public ArrayList<DisplayInstance> displayInstances;
LabelComponent IndexLabel;

Expand Down Expand Up @@ -313,9 +313,8 @@ public void mouseExited(MouseEvent e) {
Net n = getPatch().GetNet(inlinp);
if (n != null) {
n.connectInlet(inlin);
getPatch().disconnect(inlinp);
}
getPatch().disconnect(inlinp);
inletInstances.remove(inlinp);
}
inletInstances.add(inlin);
inlin.setAlignmentX(LEFT_ALIGNMENT);
Expand All @@ -334,9 +333,8 @@ public void mouseExited(MouseEvent e) {
Net n = getPatch().GetNet(oinp);
if (n != null) {
n.connectOutlet(oin);
getPatch().disconnect(oinp);
}
getPatch().disconnect(oinp);
outletInstances.remove(oinp);
}
outletInstances.add(oin);
oin.setAlignmentX(RIGHT_ALIGNMENT);
Expand Down Expand Up @@ -797,7 +795,7 @@ public void PromoteToOverloadedObj() {
return;
}
if (candidates.isEmpty()) {
Logger.getLogger(AxoObjectInstance.class.getName()).log(Level.SEVERE, "could not resolve any candidates{0}", id);
Logger.getLogger(AxoObjectInstance.class.getName()).log(Level.SEVERE, "could not resolve any candidates {0}", id);
}
if (candidates.size() == 1) {
return;
Expand Down Expand Up @@ -853,10 +851,10 @@ public void PromoteToOverloadedObj() {
return;
}
if (selected != getType()) {
//Logger.getLogger(AxoObjectInstance.class.getName()).log(Level.INFO,"promoting " + this + " to " + selected);
Logger.getLogger(AxoObjectInstance.class.getName()).log(Level.INFO,"promoting " + this + " to " + selected);
patch.ChangeObjectInstanceType(this, selected);
} else {
//Logger.getLogger(AxoObjectInstance.class.getName()).log(Level.INFO,"no promotion");
Logger.getLogger(AxoObjectInstance.class.getName()).log(Level.INFO,"no promotion for {0}", typeName);
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/axoloti/object/AxoObjectInstanceAbstract.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public String getInstanceName() {

public void setType(AxoObjectAbstract type) {
this.type = type;
typeUUID = type.getUUID();
}

public void setInstanceName(String InstanceName) {
Expand Down Expand Up @@ -608,4 +609,8 @@ public void ObjectModified(Object src) {
public ArrayList<SDFileReference> GetDependendSDFiles() {
return null;
}

public boolean isTypeWasAmbiguous() {
return typeWasAmbiguous;
}
}

0 comments on commit bbccea2

Please sign in to comment.