use of gov.sandia.n2a.eqset.MPart in project n2a by frothga.
the class ChangeVariable method apply.
public static void apply(List<String> path, String nameBefore, String nameAfter, MNode savedTree) {
NodeBase parent = NodeBase.locateNode(path);
if (parent == null)
throw new CannotRedoException();
NodeVariable nodeBefore = (NodeVariable) parent.child(nameBefore);
if (nodeBefore == null)
throw new CannotRedoException();
PanelModel mep = PanelModel.instance;
JTree tree = mep.panelEquations.tree;
FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
FontMetrics fm = nodeBefore.getFontMetrics(tree);
NodeVariable nodeAfter;
if (nameBefore.equals(nameAfter)) {
nodeAfter = nodeBefore;
// Same as valueAfter. Sub-tree is not relevant here.
nodeAfter.source.set(savedTree.get());
} else {
// Update database
MPart mparent = parent.source;
mparent.clear(nameBefore);
mparent.set(nameAfter, "").merge(savedTree);
MPart newPart = (MPart) mparent.child(nameAfter);
MPart oldPart = (MPart) mparent.child(nameBefore);
// Update GUI
nodeAfter = (NodeVariable) parent.child(nameAfter);
if (oldPart == null) {
if (nodeAfter == null) {
nodeAfter = nodeBefore;
nodeAfter.source = newPart;
} else {
model.removeNodeFromParent(nodeBefore);
}
} else {
if (nodeAfter == null) {
int index = parent.getIndex(nodeBefore);
nodeAfter = new NodeVariable(newPart);
model.insertNodeIntoUnfiltered(nodeAfter, parent, index);
}
nodeBefore.build();
nodeBefore.findConnections();
if (nodeBefore.visible(model.filterLevel))
model.nodeStructureChanged(nodeBefore);
else
parent.hide(nodeBefore, model, true);
}
}
nodeAfter.build();
nodeAfter.findConnections();
nodeAfter.updateColumnWidths(fm);
parent.updateTabStops(fm);
parent.allNodesChanged(model);
TreeNode[] nodePath = nodeAfter.getPath();
mep.panelEquations.updateOrder(nodePath);
mep.panelEquations.updateVisibility(nodePath);
}
use of gov.sandia.n2a.eqset.MPart in project n2a by frothga.
the class ChangeVariableToInherit method redo.
public void redo() {
super.redo();
NodePart parent = (NodePart) NodeBase.locateNode(path);
if (parent == null)
throw new CannotRedoException();
// Update database
MPart mparent = parent.source;
mparent.clear(treeBefore.key());
mparent.set("$inherit", valueAfter);
// Update GUI
PanelModel mep = PanelModel.instance;
JTree tree = mep.panelEquations.tree;
FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
parent.build();
parent.findConnections();
parent.filter(model.filterLevel);
model.nodeStructureChanged(parent);
TreeNode[] nodePath = parent.child("$inherit").getPath();
mep.panelEquations.updateOrder(nodePath);
mep.panelEquations.updateVisibility(nodePath);
}
use of gov.sandia.n2a.eqset.MPart in project n2a by frothga.
the class PanelEquationTree method loadRootFromDB.
public void loadRootFromDB(MNode doc) {
if (record == doc)
return;
if (record != null) {
tree.stopEditing();
// Save tree state for current record, but only if it's better than the previously-saved state.
if (focusCache.get(record) == null || tree.getSelectionPath() != null)
focusCache.put(record, new StoredPath(tree));
}
record = doc;
try {
root = new NodePart(new MPart((MPersistent) record));
root.build();
root.findConnections();
// triggers repaint, but may be too slow
model.setRoot(root);
updateLock();
// next call to repaintSouth() will repaint everything
needsFullRepaint = true;
StoredPath sp = focusCache.get(record);
if (sp == null) {
tree.expandRow(0);
tree.setSelectionRow(0);
} else {
sp.restore(tree);
}
} catch (Exception e) {
System.err.println("Exception while parsing model: " + e);
e.printStackTrace();
}
}
use of gov.sandia.n2a.eqset.MPart in project n2a by frothga.
the class ExportJob method addSynapse.
public Synapse addSynapse(MPart source, boolean electrical) {
Synapse s = new Synapse(source, electrical);
int index = synapses.indexOf(s);
if (index >= 0)
s = synapses.get(index);
else
synapses.add(s);
// Check for chained synapse (embedded input)
MPart A = (MPart) source.child("A");
if (A == null || A.size() == 0)
return s;
Synapse s2 = new Synapse(s.id, A);
index = synapses.indexOf(s2);
if (index >= 0)
s2 = synapses.get(index);
else
synapses.add(s2);
return s2;
}
use of gov.sandia.n2a.eqset.MPart in project n2a by frothga.
the class ExportJob method process.
public void process(MPart source) {
if (source.get("$metadata", "backend.lems.part").isEmpty()) {
for (EquationSet p : equations.parts) topLevelPart((MPart) p.source);
} else {
topLevelPart(source);
}
for (IonChannel ic : channels) ic.append();
for (Synapse s : synapses) s.append();
// Collate
Element root = doc.createElement("neuroml");
root.setAttribute("id", modelName);
root.setAttribute("xmlns", "http://www.neuroml.org/schema/neuroml2");
root.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
root.setAttribute("xsi:schemaLocation", "http://www.neuroml.org/schema/neuroml2 ../Schemas/NeuroML2/NeuroML_v2beta4.xsd");
sequencer.append(root, elements);
doc.appendChild(root);
}
Aggregations