Search in sources :

Example 16 with MPart

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

Example 17 with MPart

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));
}
Also used : MPart(gov.sandia.n2a.eqset.MPart) ChangeAnnotation(gov.sandia.n2a.ui.eq.undo.ChangeAnnotation) FontMetrics(java.awt.FontMetrics) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Example 18 with MPart

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));
}
Also used : ChangeEquation(gov.sandia.n2a.ui.eq.undo.ChangeEquation) MPart(gov.sandia.n2a.eqset.MPart) Variable(gov.sandia.n2a.eqset.Variable) FontMetrics(java.awt.FontMetrics) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Example 19 with MPart

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();
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) JTree(javax.swing.JTree) MPart(gov.sandia.n2a.eqset.MPart) FontMetrics(java.awt.FontMetrics) TreeNode(javax.swing.tree.TreeNode) CannotUndoException(javax.swing.undo.CannotUndoException) NodePart(gov.sandia.n2a.ui.eq.tree.NodePart) PanelEquationTree(gov.sandia.n2a.ui.eq.PanelEquationTree) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Example 20 with MPart

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());
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) PanelModel(gov.sandia.n2a.ui.eq.PanelModel) MPart(gov.sandia.n2a.eqset.MPart) JTree(javax.swing.JTree) CannotRedoException(javax.swing.undo.CannotRedoException) NodeContainer(gov.sandia.n2a.ui.eq.tree.NodeContainer) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Aggregations

MPart (gov.sandia.n2a.eqset.MPart)37 FilteredTreeModel (gov.sandia.n2a.ui.eq.FilteredTreeModel)21 NodeBase (gov.sandia.n2a.ui.eq.tree.NodeBase)20 JTree (javax.swing.JTree)18 PanelModel (gov.sandia.n2a.ui.eq.PanelModel)16 TreeNode (javax.swing.tree.TreeNode)15 FontMetrics (java.awt.FontMetrics)13 NodePart (gov.sandia.n2a.ui.eq.tree.NodePart)10 CannotRedoException (javax.swing.undo.CannotRedoException)10 CannotUndoException (javax.swing.undo.CannotUndoException)9 MNode (gov.sandia.n2a.db.MNode)5 EquationSet (gov.sandia.n2a.eqset.EquationSet)5 NodeVariable (gov.sandia.n2a.ui.eq.tree.NodeVariable)5 Variable (gov.sandia.n2a.eqset.Variable)4 ArrayList (java.util.ArrayList)4 ParseException (gov.sandia.n2a.language.ParseException)3 PanelEquationTree (gov.sandia.n2a.ui.eq.PanelEquationTree)3 NodeAnnotation (gov.sandia.n2a.ui.eq.tree.NodeAnnotation)3 NodeEquation (gov.sandia.n2a.ui.eq.tree.NodeEquation)3 IncommensurableException (javax.measure.IncommensurableException)3