Search in sources :

Example 31 with MPart

use of gov.sandia.n2a.eqset.MPart in project n2a by frothga.

the class ChangeVariable method apply.

public static void apply(List<String> path, String nameBefore, String nameAfter, MNode savedTree) {
    NodeBase parent = NodeBase.locateNode(path);
    if (parent == null)
        throw new CannotRedoException();
    NodeVariable nodeBefore = (NodeVariable) parent.child(nameBefore);
    if (nodeBefore == null)
        throw new CannotRedoException();
    PanelModel mep = PanelModel.instance;
    JTree tree = mep.panelEquations.tree;
    FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
    FontMetrics fm = nodeBefore.getFontMetrics(tree);
    NodeVariable nodeAfter;
    if (nameBefore.equals(nameAfter)) {
        nodeAfter = nodeBefore;
        // Same as valueAfter. Sub-tree is not relevant here.
        nodeAfter.source.set(savedTree.get());
    } else {
        // Update database
        MPart mparent = parent.source;
        mparent.clear(nameBefore);
        mparent.set(nameAfter, "").merge(savedTree);
        MPart newPart = (MPart) mparent.child(nameAfter);
        MPart oldPart = (MPart) mparent.child(nameBefore);
        // Update GUI
        nodeAfter = (NodeVariable) 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 NodeVariable(newPart);
                model.insertNodeIntoUnfiltered(nodeAfter, parent, index);
            }
            nodeBefore.build();
            nodeBefore.findConnections();
            if (nodeBefore.visible(model.filterLevel))
                model.nodeStructureChanged(nodeBefore);
            else
                parent.hide(nodeBefore, model, true);
        }
    }
    nodeAfter.build();
    nodeAfter.findConnections();
    nodeAfter.updateColumnWidths(fm);
    parent.updateTabStops(fm);
    parent.allNodesChanged(model);
    TreeNode[] nodePath = nodeAfter.getPath();
    mep.panelEquations.updateOrder(nodePath);
    mep.panelEquations.updateVisibility(nodePath);
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) PanelModel(gov.sandia.n2a.ui.eq.PanelModel) JTree(javax.swing.JTree) MPart(gov.sandia.n2a.eqset.MPart) FontMetrics(java.awt.FontMetrics) TreeNode(javax.swing.tree.TreeNode) CannotRedoException(javax.swing.undo.CannotRedoException) NodeVariable(gov.sandia.n2a.ui.eq.tree.NodeVariable) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Example 32 with MPart

use of gov.sandia.n2a.eqset.MPart in project n2a by frothga.

the class ChangeVariableToInherit method redo.

public void redo() {
    super.redo();
    NodePart parent = (NodePart) NodeBase.locateNode(path);
    if (parent == null)
        throw new CannotRedoException();
    // Update database
    MPart mparent = parent.source;
    mparent.clear(treeBefore.key());
    mparent.set("$inherit", valueAfter);
    // Update GUI
    PanelModel mep = PanelModel.instance;
    JTree tree = mep.panelEquations.tree;
    FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
    parent.build();
    parent.findConnections();
    parent.filter(model.filterLevel);
    model.nodeStructureChanged(parent);
    TreeNode[] nodePath = parent.child("$inherit").getPath();
    mep.panelEquations.updateOrder(nodePath);
    mep.panelEquations.updateVisibility(nodePath);
}
Also used : PanelModel(gov.sandia.n2a.ui.eq.PanelModel) MPart(gov.sandia.n2a.eqset.MPart) JTree(javax.swing.JTree) TreeNode(javax.swing.tree.TreeNode) CannotRedoException(javax.swing.undo.CannotRedoException) NodePart(gov.sandia.n2a.ui.eq.tree.NodePart) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Example 33 with MPart

use of gov.sandia.n2a.eqset.MPart in project n2a by frothga.

the class PanelEquationTree method loadRootFromDB.

public void loadRootFromDB(MNode doc) {
    if (record == doc)
        return;
    if (record != null) {
        tree.stopEditing();
        // Save tree state for current record, but only if it's better than the previously-saved state.
        if (focusCache.get(record) == null || tree.getSelectionPath() != null)
            focusCache.put(record, new StoredPath(tree));
    }
    record = doc;
    try {
        root = new NodePart(new MPart((MPersistent) record));
        root.build();
        root.findConnections();
        // triggers repaint, but may be too slow
        model.setRoot(root);
        updateLock();
        // next call to repaintSouth() will repaint everything
        needsFullRepaint = true;
        StoredPath sp = focusCache.get(record);
        if (sp == null) {
            tree.expandRow(0);
            tree.setSelectionRow(0);
        } else {
            sp.restore(tree);
        }
    } catch (Exception e) {
        System.err.println("Exception while parsing model: " + e);
        e.printStackTrace();
    }
}
Also used : MPart(gov.sandia.n2a.eqset.MPart) NodePart(gov.sandia.n2a.ui.eq.tree.NodePart) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) ExpandVetoException(javax.swing.tree.ExpandVetoException) IOException(java.io.IOException)

Example 34 with MPart

use of gov.sandia.n2a.eqset.MPart in project n2a by frothga.

the class ExportJob method addSynapse.

public Synapse addSynapse(MPart source, boolean electrical) {
    Synapse s = new Synapse(source, electrical);
    int index = synapses.indexOf(s);
    if (index >= 0)
        s = synapses.get(index);
    else
        synapses.add(s);
    // Check for chained synapse (embedded input)
    MPart A = (MPart) source.child("A");
    if (A == null || A.size() == 0)
        return s;
    Synapse s2 = new Synapse(s.id, A);
    index = synapses.indexOf(s2);
    if (index >= 0)
        s2 = synapses.get(index);
    else
        synapses.add(s2);
    return s2;
}
Also used : MPart(gov.sandia.n2a.eqset.MPart)

Example 35 with MPart

use of gov.sandia.n2a.eqset.MPart in project n2a by frothga.

the class ExportJob method process.

public void process(MPart source) {
    if (source.get("$metadata", "backend.lems.part").isEmpty()) {
        for (EquationSet p : equations.parts) topLevelPart((MPart) p.source);
    } else {
        topLevelPart(source);
    }
    for (IonChannel ic : channels) ic.append();
    for (Synapse s : synapses) s.append();
    // Collate
    Element root = doc.createElement("neuroml");
    root.setAttribute("id", modelName);
    root.setAttribute("xmlns", "http://www.neuroml.org/schema/neuroml2");
    root.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
    root.setAttribute("xsi:schemaLocation", "http://www.neuroml.org/schema/neuroml2 ../Schemas/NeuroML2/NeuroML_v2beta4.xsd");
    sequencer.append(root, elements);
    doc.appendChild(root);
}
Also used : EquationSet(gov.sandia.n2a.eqset.EquationSet) MPart(gov.sandia.n2a.eqset.MPart) Element(org.w3c.dom.Element)

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