use of gov.sandia.n2a.eqset.MPart in project n2a by frothga.
the class PartMap method build.
/**
* Scans model database and collects parts which are tagged for neuroml.
* This mapping really ought to be updated every time a tagged part is edited.
* However, in normal use (not during library development) the parts will be read-only,
* so one-time initialization should be sufficient.
*/
public void build() {
for (MNode c : AppData.models) {
// Must directly declare a NeuroML part to be included.
if (c.child("$metadata", "backend.lems.part") == null)
continue;
// Create map using fully-collated part, not just the immediate one.
NameMap map = new NameMap(new MPart((MPersistent) c));
outward.put(map.internal, map);
for (String n : map.neuroml) inward.put(n, map);
}
// Determine which parts can be contained by other parts.
for (NameMap map : outward.values()) {
for (String childName : map.children) {
NameMap childMap = outward.get(childName);
if (childMap != null)
childMap.containers.add(map);
}
}
// Child parts add name mappings for variables visible from their containers.
for (NameMap map : outward.values()) map.inheritContainers(this);
for (NameMap map : outward.values()) map.buildContainerMappings();
}
use of gov.sandia.n2a.eqset.MPart in project n2a by frothga.
the class NodeAnnotation method applyEdit.
@Override
public void applyEdit(JTree tree) {
String input = (String) getUserObject();
if (input.isEmpty()) {
delete(tree, true);
return;
}
String[] parts = input.split("=", 2);
String name = parts[0].trim().replaceAll("[ \\n\\t]", "");
String value;
if (parts.length > 1)
value = parts[1].trim();
else
value = "";
NodeBase parent = (NodeBase) getParent();
String oldName = source.key();
String oldValue = source.get();
if (!name.equals(oldName)) {
// Check if name change is forbidden
if (name.isEmpty()) {
name = oldName;
} else {
MPart mparent = source.getParent();
MPart partAfter = (MPart) mparent.child(name);
if (partAfter != null && partAfter.isFromTopDocument())
name = oldName;
}
}
if (name.equals(oldName) && value.equals(oldValue)) {
FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
FontMetrics fm = getFontMetrics(tree);
parent.updateTabStops(fm);
// Our siblings should not change, because we did not really change. Just repaint in non-edit mode.
model.nodeChanged(this);
return;
}
PanelModel.instance.undoManager.add(new ChangeAnnotation(parent, oldName, oldValue, name, value));
}
use of gov.sandia.n2a.eqset.MPart in project n2a by frothga.
the class NodeEquation method applyEdit.
@Override
public void applyEdit(JTree tree) {
String input = (String) getUserObject();
if (input.isEmpty()) {
delete(tree, true);
return;
}
// There are three possible outcomes of the edit:
// 1) Nothing changed
// 2) The name was not allowed to change
// 3) Arbitrary change
Variable.ParsedValue piecesBefore = new Variable.ParsedValue(source.get() + source.key());
Variable.ParsedValue piecesAfter = new Variable.ParsedValue(input);
NodeVariable parent = (NodeVariable) getParent();
if (!piecesBefore.condition.equals(piecesAfter.condition)) {
MPart partAfter = (MPart) parent.source.child("@" + piecesAfter.condition);
if (// Can't overwrite another top-document node
partAfter != null && partAfter.isFromTopDocument()) {
piecesAfter.condition = piecesBefore.condition;
}
}
if (piecesBefore.equals(piecesAfter)) {
FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
FontMetrics fm = getFontMetrics(tree);
parent.updateTabStops(fm);
parent.allNodesChanged(model);
return;
}
// The fact that we are modifying an existing equation node indicates that the variable (parent) should only contain a combiner.
piecesBefore.combiner = parent.source.get();
if (piecesAfter.combiner.isEmpty())
piecesAfter.combiner = piecesBefore.combiner;
PanelModel.instance.undoManager.add(new ChangeEquation(parent, piecesBefore.condition, piecesBefore.combiner, piecesBefore.expression, piecesAfter.condition, piecesAfter.combiner, piecesAfter.expression));
}
use of gov.sandia.n2a.eqset.MPart in project n2a by frothga.
the class AddAnnotation method destroy.
public static void destroy(List<String> path, boolean canceled, String name, String blockName) {
// Retrieve created node
NodeBase parent = NodeBase.locateNode(path);
if (parent == null)
throw new CannotUndoException();
NodeBase container = parent;
if (parent instanceof NodePart)
container = parent.child(blockName);
NodeBase createdNode = container.child(name);
PanelEquationTree pet = PanelModel.instance.panelEquations;
JTree tree = pet.tree;
FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
FontMetrics fm = createdNode.getFontMetrics(tree);
boolean containerIsVisible = true;
TreeNode[] createdPath = createdNode.getPath();
int index = container.getIndexFiltered(createdNode);
if (canceled)
index--;
MPart block = (MPart) parent.source.child(blockName);
block.clear(name);
if (// There is no overridden value, so this node goes away completely.
block.child(name) == null) {
model.removeNodeFromParent(createdNode);
if (block.size() == 0) {
// commit suicide
parent.source.clear(blockName);
if (parent instanceof NodePart) {
model.removeNodeFromParent(container);
// No need to update order, because we just destroyed $metadata, where order is stored.
// No need to update tab stops in grandparent, because block nodes don't offer any tab stops.
containerIsVisible = false;
}
}
} else // Just exposed an overridden value, so update display.
{
if (// We are always visible, but our parent could disappear.
container.visible(model.filterLevel)) {
createdNode.updateColumnWidths(fm);
} else {
containerIsVisible = false;
}
}
if (containerIsVisible) {
container.updateTabStops(fm);
container.allNodesChanged(model);
}
pet.updateVisibility(createdPath, index);
if (path.size() == 1 && name.equals("lock"))
pet.updateLock();
}
use of gov.sandia.n2a.eqset.MPart in project n2a by frothga.
the class AddAnnotations method create.
public static void create(List<String> path, int index, MNode saved, NodeFactory factory) {
NodeBase parent = NodeBase.locateNode(path);
if (parent == null)
throw new CannotRedoException();
String blockName = saved.key();
NodeBase n = parent.child(blockName);
if (n != null && !(n instanceof NodeContainer))
throw new CannotRedoException();
NodeContainer node = (NodeContainer) n;
MPart block = (MPart) parent.source.childOrCreate(blockName);
block.merge(saved);
PanelModel mep = PanelModel.instance;
JTree tree = mep.panelEquations.tree;
FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
if (node == null) {
node = (NodeContainer) factory.create(block);
model.insertNodeIntoUnfiltered(node, parent, index);
}
// Replaces all nodes, so they are set to require tab initialization.
node.build();
node.filter(model.filterLevel);
mep.panelEquations.updateVisibility(node.getPath());
}
Aggregations