Search in sources :

Example 11 with MPart

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

the class ChangePart method apply.

public void apply(String nameBefore, String nameAfter) {
    NodeBase parent = NodeBase.locateNode(path);
    if (parent == null)
        throw new CannotRedoException();
    NodeBase temp = parent.child(nameBefore);
    if (!(temp instanceof NodePart))
        throw new CannotRedoException();
    NodePart nodeBefore = (NodePart) temp;
    // Update the database: move the subtree.
    MPart mparent = parent.source;
    mparent.clear(nameBefore);
    mparent.set(nameAfter, "").merge(savedTree);
    ;
    MPart oldPart = (MPart) mparent.child(nameBefore);
    MPart newPart = (MPart) mparent.child(nameAfter);
    // Update GUI
    PanelModel mep = PanelModel.instance;
    JTree tree = mep.panelEquations.tree;
    FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
    // It's either a NodePart or it's null. Any other case should be blocked by GUI constraints.
    NodePart nodeAfter = (NodePart) 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 NodePart(newPart);
            model.insertNodeIntoUnfiltered(nodeAfter, parent, index);
        }
        nodeBefore.build();
        nodeBefore.findConnections();
        nodeBefore.filter(model.filterLevel);
        if (nodeBefore.visible(model.filterLevel))
            model.nodeStructureChanged(nodeBefore);
        else
            parent.hide(nodeBefore, model, true);
    }
    nodeAfter.build();
    nodeBefore.findConnections();
    nodeAfter.filter(model.filterLevel);
    TreeNode[] nodePath = nodeAfter.getPath();
    mep.panelEquations.updateOrder(nodePath);
    // Will include nodeStructureChanged(), if necessary.
    mep.panelEquations.updateVisibility(nodePath);
}
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) 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 12 with MPart

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

the class ChangeVariableToInherit method undo.

public void undo() {
    super.undo();
    NodePart parent = (NodePart) NodeBase.locateNode(path);
    if (parent == null)
        throw new CannotUndoException();
    // Update the database
    MPart mparent = parent.source;
    mparent.clear("$inherit");
    String nameBefore = treeBefore.key();
    mparent.set(nameBefore, "").merge(treeBefore);
    // Update the GUI
    PanelModel mep = PanelModel.instance;
    JTree tree = mep.panelEquations.tree;
    FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
    parent.build();
    parent.findConnections();
    parent.filter(model.filterLevel);
    if (parent.visible(model.filterLevel))
        model.nodeStructureChanged(parent);
    TreeNode[] nodePath = parent.child(nameBefore).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) CannotUndoException(javax.swing.undo.CannotUndoException) NodePart(gov.sandia.n2a.ui.eq.tree.NodePart) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Example 13 with MPart

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

the class Move method apply.

public static void apply(List<String> path, int indexBefore, int indexAfter, int indexMetadata, boolean createOrder, boolean destroyOrder) {
    NodeBase parent = NodeBase.locateNode(path);
    if (parent == null)
        throw new CannotUndoException();
    PanelModel mep = PanelModel.instance;
    JTree tree = mep.panelEquations.tree;
    FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
    NodeBase moveNode = (NodeBase) parent.getChildAt(indexBefore);
    model.removeNodeFromParent(moveNode);
    NodeBase metadataNode = parent.child("$metadata");
    if (createOrder) {
        if (metadataNode == null) {
            metadataNode = new NodeAnnotations((MPart) parent.source.set("$metadata", ""));
            model.insertNodeIntoUnfiltered(metadataNode, parent, indexMetadata);
        }
        NodeBase orderNode = new NodeAnnotation((MPart) metadataNode.source.set("gui.order", ""));
        model.insertNodeIntoUnfiltered(orderNode, metadataNode, metadataNode.getChildCount());
    }
    if (destroyOrder) {
        NodeBase orderNode = metadataNode.child("gui.order");
        FontMetrics fm = orderNode.getFontMetrics(tree);
        metadataNode.source.clear("gui.order");
        model.removeNodeFromParent(metadataNode.child("gui.order"));
        if (metadataNode.getChildCount() == 0) {
            parent.source.clear("$metadata");
            model.removeNodeFromParent(metadataNode);
        } else {
            metadataNode.updateTabStops(fm);
            metadataNode.allNodesChanged(model);
        }
    }
    model.insertNodeIntoUnfiltered(moveNode, parent, indexAfter);
    TreeNode[] movePath = moveNode.getPath();
    if (!destroyOrder)
        mep.panelEquations.updateOrder(movePath);
    mep.panelEquations.updateVisibility(movePath);
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) PanelModel(gov.sandia.n2a.ui.eq.PanelModel) JTree(javax.swing.JTree) NodeAnnotations(gov.sandia.n2a.ui.eq.tree.NodeAnnotations) MPart(gov.sandia.n2a.eqset.MPart) NodeAnnotation(gov.sandia.n2a.ui.eq.tree.NodeAnnotation) FontMetrics(java.awt.FontMetrics) TreeNode(javax.swing.tree.TreeNode) CannotUndoException(javax.swing.undo.CannotUndoException) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Example 14 with MPart

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

the class ExportJob method getEquations.

public EquationSet getEquations(MPart p) {
    List<String> path = new ArrayList<String>();
    MPart parent = p;
    while (parent != null) {
        path.add(parent.key());
        parent = parent.getParent();
    }
    EquationSet result = equations;
    for (int i = path.size() - 2; i >= 0; i--) {
        String name = path.get(i);
        result = result.findPart(name);
        if (result == null)
            return null;
        if (!result.name.equals(name))
            return null;
    }
    return result;
}
Also used : EquationSet(gov.sandia.n2a.eqset.EquationSet) MPart(gov.sandia.n2a.eqset.MPart) ArrayList(java.util.ArrayList)

Example 15 with MPart

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

the class ExportJob method process.

public void process(MNode source, File destination) {
    try {
        MPart mpart = new MPart((MPersistent) source);
        modelName = source.key();
        equations = new EquationSet(mpart);
        // Make eqset minimally executable ...
        try {
            equations.resolveConnectionBindings();
        }// Still try to finish rest of compilation. Maybe only one or two minor parts were affected.
         catch (Exception e) {
        }
        try {
            equations.addGlobalConstants();
            // $index, $init, $live, $n, $t, $t', $type
            equations.addSpecials();
            equations.fillIntegratedVariables();
            equations.findIntegrated();
            equations.resolveLHS();
            equations.resolveRHS();
            // This could hurt the analysis. It simplifies expressions and substitutes constants, breaking some dependency chains.
            equations.findConstants();
            equations.determineTypes();
            equations.clearVariables();
        }// It may still be possible to complete the export.
         catch (Exception e) {
        }
        analyze(equations);
        DocumentBuilderFactory factoryBuilder = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factoryBuilder.newDocumentBuilder();
        doc = builder.newDocument();
        // Convert top-level N2A part into top-level NeuroML elements
        process(mpart);
        DOMSource dom = new DOMSource(doc);
        StreamResult stream = new StreamResult(new OutputStreamWriter(new FileOutputStream(destination), "UTF-8"));
        TransformerFactory factoryXform = TransformerFactory.newInstance();
        factoryXform.setAttribute("indent-number", 4);
        Transformer xform = factoryXform.newTransformer();
        xform.setOutputProperty(OutputKeys.INDENT, "yes");
        xform.transform(dom, stream);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : EquationSet(gov.sandia.n2a.eqset.EquationSet) MPart(gov.sandia.n2a.eqset.MPart) DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) DocumentBuilder(javax.xml.parsers.DocumentBuilder) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) IncommensurableException(javax.measure.IncommensurableException) UnconvertibleException(javax.measure.UnconvertibleException) ParseException(gov.sandia.n2a.language.ParseException)

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