use of gov.sandia.n2a.eqset.MPart in project n2a by frothga.
the class ChangePart method apply.
public void apply(String nameBefore, String nameAfter) {
NodeBase parent = NodeBase.locateNode(path);
if (parent == null)
throw new CannotRedoException();
NodeBase temp = parent.child(nameBefore);
if (!(temp instanceof NodePart))
throw new CannotRedoException();
NodePart nodeBefore = (NodePart) temp;
// Update the database: move the subtree.
MPart mparent = parent.source;
mparent.clear(nameBefore);
mparent.set(nameAfter, "").merge(savedTree);
;
MPart oldPart = (MPart) mparent.child(nameBefore);
MPart newPart = (MPart) mparent.child(nameAfter);
// Update GUI
PanelModel mep = PanelModel.instance;
JTree tree = mep.panelEquations.tree;
FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
// It's either a NodePart or it's null. Any other case should be blocked by GUI constraints.
NodePart nodeAfter = (NodePart) 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 NodePart(newPart);
model.insertNodeIntoUnfiltered(nodeAfter, parent, index);
}
nodeBefore.build();
nodeBefore.findConnections();
nodeBefore.filter(model.filterLevel);
if (nodeBefore.visible(model.filterLevel))
model.nodeStructureChanged(nodeBefore);
else
parent.hide(nodeBefore, model, true);
}
nodeAfter.build();
nodeBefore.findConnections();
nodeAfter.filter(model.filterLevel);
TreeNode[] nodePath = nodeAfter.getPath();
mep.panelEquations.updateOrder(nodePath);
// Will include nodeStructureChanged(), if necessary.
mep.panelEquations.updateVisibility(nodePath);
}
use of gov.sandia.n2a.eqset.MPart in project n2a by frothga.
the class ChangeVariableToInherit method undo.
public void undo() {
super.undo();
NodePart parent = (NodePart) NodeBase.locateNode(path);
if (parent == null)
throw new CannotUndoException();
// Update the database
MPart mparent = parent.source;
mparent.clear("$inherit");
String nameBefore = treeBefore.key();
mparent.set(nameBefore, "").merge(treeBefore);
// Update the GUI
PanelModel mep = PanelModel.instance;
JTree tree = mep.panelEquations.tree;
FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
parent.build();
parent.findConnections();
parent.filter(model.filterLevel);
if (parent.visible(model.filterLevel))
model.nodeStructureChanged(parent);
TreeNode[] nodePath = parent.child(nameBefore).getPath();
mep.panelEquations.updateOrder(nodePath);
mep.panelEquations.updateVisibility(nodePath);
}
use of gov.sandia.n2a.eqset.MPart in project n2a by frothga.
the class Move method apply.
public static void apply(List<String> path, int indexBefore, int indexAfter, int indexMetadata, boolean createOrder, boolean destroyOrder) {
NodeBase parent = NodeBase.locateNode(path);
if (parent == null)
throw new CannotUndoException();
PanelModel mep = PanelModel.instance;
JTree tree = mep.panelEquations.tree;
FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
NodeBase moveNode = (NodeBase) parent.getChildAt(indexBefore);
model.removeNodeFromParent(moveNode);
NodeBase metadataNode = parent.child("$metadata");
if (createOrder) {
if (metadataNode == null) {
metadataNode = new NodeAnnotations((MPart) parent.source.set("$metadata", ""));
model.insertNodeIntoUnfiltered(metadataNode, parent, indexMetadata);
}
NodeBase orderNode = new NodeAnnotation((MPart) metadataNode.source.set("gui.order", ""));
model.insertNodeIntoUnfiltered(orderNode, metadataNode, metadataNode.getChildCount());
}
if (destroyOrder) {
NodeBase orderNode = metadataNode.child("gui.order");
FontMetrics fm = orderNode.getFontMetrics(tree);
metadataNode.source.clear("gui.order");
model.removeNodeFromParent(metadataNode.child("gui.order"));
if (metadataNode.getChildCount() == 0) {
parent.source.clear("$metadata");
model.removeNodeFromParent(metadataNode);
} else {
metadataNode.updateTabStops(fm);
metadataNode.allNodesChanged(model);
}
}
model.insertNodeIntoUnfiltered(moveNode, parent, indexAfter);
TreeNode[] movePath = moveNode.getPath();
if (!destroyOrder)
mep.panelEquations.updateOrder(movePath);
mep.panelEquations.updateVisibility(movePath);
}
use of gov.sandia.n2a.eqset.MPart in project n2a by frothga.
the class ExportJob method getEquations.
public EquationSet getEquations(MPart p) {
List<String> path = new ArrayList<String>();
MPart parent = p;
while (parent != null) {
path.add(parent.key());
parent = parent.getParent();
}
EquationSet result = equations;
for (int i = path.size() - 2; i >= 0; i--) {
String name = path.get(i);
result = result.findPart(name);
if (result == null)
return null;
if (!result.name.equals(name))
return null;
}
return result;
}
use of gov.sandia.n2a.eqset.MPart in project n2a by frothga.
the class ExportJob method process.
public void process(MNode source, File destination) {
try {
MPart mpart = new MPart((MPersistent) source);
modelName = source.key();
equations = new EquationSet(mpart);
// Make eqset minimally executable ...
try {
equations.resolveConnectionBindings();
}// Still try to finish rest of compilation. Maybe only one or two minor parts were affected.
catch (Exception e) {
}
try {
equations.addGlobalConstants();
// $index, $init, $live, $n, $t, $t', $type
equations.addSpecials();
equations.fillIntegratedVariables();
equations.findIntegrated();
equations.resolveLHS();
equations.resolveRHS();
// This could hurt the analysis. It simplifies expressions and substitutes constants, breaking some dependency chains.
equations.findConstants();
equations.determineTypes();
equations.clearVariables();
}// It may still be possible to complete the export.
catch (Exception e) {
}
analyze(equations);
DocumentBuilderFactory factoryBuilder = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factoryBuilder.newDocumentBuilder();
doc = builder.newDocument();
// Convert top-level N2A part into top-level NeuroML elements
process(mpart);
DOMSource dom = new DOMSource(doc);
StreamResult stream = new StreamResult(new OutputStreamWriter(new FileOutputStream(destination), "UTF-8"));
TransformerFactory factoryXform = TransformerFactory.newInstance();
factoryXform.setAttribute("indent-number", 4);
Transformer xform = factoryXform.newTransformer();
xform.setOutputProperty(OutputKeys.INDENT, "yes");
xform.transform(dom, stream);
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations