use of gov.sandia.n2a.db.MNode in project n2a by frothga.
the class ImportNeuroML method addModel.
public void addModel(MNode m, MNode models, UndoManager um) {
String key = m.key();
models.clear(key);
// model files frequently repeat equations that should be inherited.
for (MNode c : m) {
String inherit = "";
if (c.key().equals("$inherit")) {
inherit = c.get().replace("\"", "");
} else if (c.child("$inherit") != null) {
inherit = c.get("$inherit").replace("\"", "");
}
MNode d = models.child(inherit);
if (d != null)
addModel(d, models, um);
}
AddDoc add = new AddDoc(key, m);
add.wasShowing = false;
um.add(add);
}
use of gov.sandia.n2a.db.MNode in project n2a by frothga.
the class PartMap method exportMap.
/**
* Finds the closest parent of the given part (which may be the part itself) which
* has an entry in this part map, and return the associated name map.
* Assumes entire heritage resides in the main database.
*/
public NameMap exportMap(MNode part) {
String key = part.key();
NameMap map = outward.get(key);
if (map != null)
return map;
// Assume single inheritance
String inherit = part.get("$inherit").replace("\"", "");
if (!inherit.isEmpty()) {
MNode parent = AppData.models.child(inherit);
if (parent != null)
return exportMap(parent);
}
return new NameMap(key);
}
use of gov.sandia.n2a.db.MNode 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.db.MNode in project n2a by frothga.
the class EquationSet method addGlobalConstants.
public void addGlobalConstants() throws ParseException {
String key = AppData.state.get("General", "constants");
MNode constants = AppData.models.child(key);
if (constants == null)
return;
for (MNode c : constants) {
String value = c.get();
if (value.isEmpty())
continue;
Variable v = new Variable(c.key(), 0);
if (add(v)) {
v.addAttribute("constant");
EquationEntry e = new EquationEntry(v, "");
e.expression = Operator.parse(value);
v.add(e);
}
}
}
use of gov.sandia.n2a.db.MNode in project n2a by frothga.
the class MPart method merge.
/**
* Ensures that the minimal number of override nodes are created.
* Processes $inherit first, so that as other children are set, they are recognized as matching
* an inherited value when that is the case.
*/
public synchronized void merge(MNode that) {
set(that.get());
// Process $inherit first
MNode thatInherit = that.child("$inherit");
if (thatInherit != null) {
MPart inherit = (MPart) child("$inherit");
boolean existing = inherit != null;
if (!existing)
inherit = (MPart) set("$inherit", "");
// under $inherit first, then set the node itself in a way that avoids calling getIDs().
for (MNode thatInheritChild : thatInherit) {
String index = thatInheritChild.key();
MNode c = inherit.child(index);
if (c == null)
c = inherit.set(index, "");
c.merge(thatInheritChild);
}
String thatInheritValue = thatInherit.get();
if (!thatInheritValue.isEmpty()) {
// This is a copy of set() with appropriate modifications
String thisInheritValue = inherit.source.get();
if (!thisInheritValue.equals(thatInheritValue)) {
boolean couldReset = inherit.original.get().equals(thatInheritValue);
if (!couldReset)
inherit.override();
inherit.source.set(thatInheritValue);
if (couldReset)
inherit.clearPath();
if (existing)
purge(inherit, null);
expand();
}
}
}
// Then the rest of the children
for (MNode thatChild : that) {
if (thatChild == thatInherit)
continue;
String index = thatChild.key();
MNode c = child(index);
// ensure a target child node exists
if (c == null)
c = set(index, "");
c.merge(thatChild);
}
}
Aggregations