Search in sources :

Example 31 with MNode

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);
}
Also used : MNode(gov.sandia.n2a.db.MNode) AddDoc(gov.sandia.n2a.ui.eq.undo.AddDoc)

Example 32 with MNode

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);
}
Also used : MNode(gov.sandia.n2a.db.MNode)

Example 33 with MNode

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();
}
Also used : MPart(gov.sandia.n2a.eqset.MPart) MPersistent(gov.sandia.n2a.db.MPersistent) MNode(gov.sandia.n2a.db.MNode)

Example 34 with MNode

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);
        }
    }
}
Also used : AccessVariable(gov.sandia.n2a.language.AccessVariable) MNode(gov.sandia.n2a.db.MNode)

Example 35 with MNode

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);
    }
}
Also used : MNode(gov.sandia.n2a.db.MNode)

Aggregations

MNode (gov.sandia.n2a.db.MNode)63 Node (org.w3c.dom.Node)11 NameMap (gov.sandia.n2a.backend.neuroml.PartMap.NameMap)9 MVolatile (gov.sandia.n2a.db.MVolatile)5 MPart (gov.sandia.n2a.eqset.MPart)5 ArrayList (java.util.ArrayList)5 PanelModel (gov.sandia.n2a.ui.eq.PanelModel)4 MPersistent (gov.sandia.n2a.db.MPersistent)3 EquationSet (gov.sandia.n2a.eqset.EquationSet)3 Variable (gov.sandia.n2a.eqset.Variable)3 AccessVariable (gov.sandia.n2a.language.AccessVariable)3 PanelReference (gov.sandia.n2a.ui.ref.PanelReference)3 Element (org.w3c.dom.Element)3 NamedNodeMap (org.w3c.dom.NamedNodeMap)3 MDoc (gov.sandia.n2a.db.MDoc)2 ParseException (gov.sandia.n2a.language.ParseException)2 AddDoc (gov.sandia.n2a.ui.eq.undo.AddDoc)2 IOException (java.io.IOException)2 TreeMap (java.util.TreeMap)2 IncommensurableException (javax.measure.IncommensurableException)2