Search in sources :

Example 1 with ProductSystemNode

use of org.openlca.app.editors.graphical.model.ProductSystemNode in project olca-app by GreenDelta.

the class GraphEditor method expand.

/**
 * Expands all process nodes in the graphical editor.
 */
public void expand() {
    model = new ProductSystemNode(this);
    var system = getProductSystem();
    // create the process nodes
    var ref = system.referenceProcess;
    for (var id : system.processes) {
        if (id == null)
            continue;
        // was already added
        if (ref != null && ref.id == id)
            continue;
        var node = ProcessNode.create(this, id);
        if (node != null) {
            model.add(node);
        }
    }
    // set the viewer content and expand the nodes
    var viewer = getGraphicalViewer();
    if (viewer == null)
        return;
    viewer.deselectAll();
    viewer.setContents(model);
    for (var node : model.getChildren()) {
        node.expandLeft();
        node.expandRight();
    }
    getCommandStack().execute(new LayoutCommand(this, LayoutType.TREE_LAYOUT));
}
Also used : LayoutCommand(org.openlca.app.editors.graphical.command.LayoutCommand) ProductSystemNode(org.openlca.app.editors.graphical.model.ProductSystemNode)

Example 2 with ProductSystemNode

use of org.openlca.app.editors.graphical.model.ProductSystemNode in project olca-app by GreenDelta.

the class GraphEditor method createNecessaryLinks.

public void createNecessaryLinks(ProcessNode node) {
    MutableProcessLinkSearchMap linkSearch = node.parent().linkSearch;
    ProductSystemNode sysNode = node.parent();
    long id = node.process.id;
    for (ProcessLink pLink : linkSearch.getLinks(id)) {
        boolean isProvider = pLink.providerId == id;
        long otherID = isProvider ? pLink.processId : pLink.providerId;
        ProcessNode otherNode = model.getProcessNode(otherID);
        if (otherNode == null)
            continue;
        ProcessNode outNode = null;
        ProcessNode inNode = null;
        FlowType type = sysNode.flows.type(pLink.flowId);
        if (type == FlowType.PRODUCT_FLOW) {
            outNode = isProvider ? node : otherNode;
            inNode = isProvider ? otherNode : node;
        } else if (type == FlowType.WASTE_FLOW) {
            outNode = isProvider ? otherNode : node;
            inNode = isProvider ? node : otherNode;
        }
        if (outNode == null)
            continue;
        if (!outNode.isExpandedRight() && !inNode.isExpandedLeft())
            continue;
        Link link = new Link();
        link.outputNode = outNode;
        link.inputNode = inNode;
        link.processLink = pLink;
        link.link();
    }
}
Also used : ProcessLink(org.openlca.core.model.ProcessLink) ProductSystemNode(org.openlca.app.editors.graphical.model.ProductSystemNode) ProcessNode(org.openlca.app.editors.graphical.model.ProcessNode) MutableProcessLinkSearchMap(org.openlca.app.editors.graphical.search.MutableProcessLinkSearchMap) FlowType(org.openlca.core.model.FlowType) Link(org.openlca.app.editors.graphical.model.Link) ProcessLink(org.openlca.core.model.ProcessLink)

Example 3 with ProductSystemNode

use of org.openlca.app.editors.graphical.model.ProductSystemNode in project olca-app by GreenDelta.

the class ReconnectLinkCommand method execute.

@Override
public void execute() {
    ProductSystemNode systemNode = sourceNode.parent();
    oldLink.unlink();
    systemNode.getProductSystem().processLinks.remove(oldLink.processLink);
    systemNode.linkSearch.remove(oldLink.processLink);
    var processLink = new ProcessLink();
    processLink.providerId = sourceNode.process.id;
    processLink.setProviderType(sourceNode.process.type);
    processLink.flowId = oldLink.processLink.flowId;
    processLink.processId = targetNode.parent().process.id;
    processLink.exchangeId = targetNode.exchange.id;
    systemNode.getProductSystem().processLinks.add(processLink);
    systemNode.linkSearch.put(processLink);
    link = new Link();
    link.outputNode = sourceNode;
    link.inputNode = targetNode.parent();
    link.processLink = processLink;
    link.link();
    systemNode.editor.setDirty();
}
Also used : ProcessLink(org.openlca.core.model.ProcessLink) ProductSystemNode(org.openlca.app.editors.graphical.model.ProductSystemNode) Link(org.openlca.app.editors.graphical.model.Link) ProcessLink(org.openlca.core.model.ProcessLink)

Example 4 with ProductSystemNode

use of org.openlca.app.editors.graphical.model.ProductSystemNode in project olca-app by GreenDelta.

the class TreeLayout method layout.

public void layout(ProductSystemNode productSystemNode) {
    this.linkSearch = productSystemNode.linkSearch;
    prepare(productSystemNode);
    List<Node> nodes = new ArrayList<>();
    Node mainNode = build(productSystemNode.getProductSystem());
    mainNode.sort();
    nodes.add(mainNode);
    for (ProcessNode processNode : productSystemNode.getChildren()) {
        if (containing.get(processNode.process.id) != null)
            continue;
        Node node = new Node();
        node.processId = processNode.process.id;
        build(productSystemNode.getProductSystem(), new Node[] { node });
        node.sort();
        nodes.add(node);
    }
    int additionalHeight = 0;
    for (Node node : nodes) {
        int newAdditionalHeight = 0;
        locations.clear();
        applyLayout(node, 0, node.getLeftDepth());
        int minimumX = Integer.MAX_VALUE;
        int maximumX = Integer.MIN_VALUE;
        int minimumY = Integer.MAX_VALUE;
        int maximumY = Integer.MIN_VALUE;
        for (Point p : locations.keySet()) {
            if (p.x < minimumX)
                minimumX = p.x;
            if (p.x > maximumX)
                maximumX = p.x;
            if (p.y < minimumY)
                minimumY = p.y;
            if (p.y > maximumY)
                maximumY = p.y;
        }
        Map<Long, ProcessNode> processNodes = new HashMap<>();
        for (ProcessNode processNode : productSystemNode.getChildren()) processNodes.put(processNode.process.id, processNode);
        for (int x = minimumX; x <= maximumX; x++) {
            widths.put(x, 0);
            for (int y = minimumY; y <= maximumY; y++) {
                Long processId = locations.get(new Point(x, y));
                if (processId == null)
                    continue;
                ProcessNode pn = processNodes.get(processId);
                if (pn == null)
                    continue;
                Dimension size = pn.getSize();
                if (size == null)
                    continue;
                int width = Math.max(widths.get(x), size.width);
                widths.put(x, width);
            }
        }
        for (int y = minimumY; y <= maximumY; y++) {
            heights.put(y, 0);
            for (int x = minimumX; x <= maximumX; x++) {
                Long processId = locations.get(new Point(x, y));
                if (processId == null)
                    continue;
                ProcessNode pn = processNodes.get(processId);
                if (pn == null)
                    continue;
                Dimension size = pn.getSize();
                if (size == null)
                    continue;
                int height = Math.max(heights.get(y), size.height);
                heights.put(y, height);
            }
        }
        int xPosition = LayoutManager.H_SPACE;
        for (int x = minimumX; x <= maximumX; x++) {
            if (x > minimumX && widths.get(x - 1) > 0)
                xPosition += widths.get(x - 1) + LayoutManager.H_SPACE;
            int yPosition = LayoutManager.V_SPACE;
            for (int y = minimumY; y <= maximumY; y++) {
                Long processId = locations.get(new Point(x, y));
                if (y > minimumY && heights.get(y - 1) > 0)
                    yPosition += heights.get(y - 1) + LayoutManager.V_SPACE;
                if (processId == null)
                    continue;
                ProcessNode processNode = processNodes.get(processId);
                if (processNode == null)
                    continue;
                Dimension size = processNode.getSize();
                if (size == null)
                    continue;
                processNode.setBox(new Rectangle(xPosition, yPosition + additionalHeight, size.width, size.height));
                newAdditionalHeight = Math.max(newAdditionalHeight, yPosition + additionalHeight + size.height);
            }
        }
        additionalHeight = newAdditionalHeight + LayoutManager.V_SPACE;
    }
    containing.clear();
    widths.clear();
    heights.clear();
    locations.clear();
}
Also used : HashMap(java.util.HashMap) ProcessNode(org.openlca.app.editors.graphical.model.ProcessNode) ProductSystemNode(org.openlca.app.editors.graphical.model.ProductSystemNode) ArrayList(java.util.ArrayList) ProcessNode(org.openlca.app.editors.graphical.model.ProcessNode) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point) Dimension(org.eclipse.draw2d.geometry.Dimension) Point(org.eclipse.draw2d.geometry.Point)

Example 5 with ProductSystemNode

use of org.openlca.app.editors.graphical.model.ProductSystemNode in project olca-app by GreenDelta.

the class CreateLinkCommand method undo.

@Override
public void undo() {
    ProductSystemNode sys = sysNode();
    ProductSystem system = sys.getProductSystem();
    link.unlink();
    system.processLinks.remove(processLink);
    sys.linkSearch.remove(processLink);
    sys.editor.setDirty();
}
Also used : ProductSystemNode(org.openlca.app.editors.graphical.model.ProductSystemNode) ProductSystem(org.openlca.core.model.ProductSystem)

Aggregations

ProductSystemNode (org.openlca.app.editors.graphical.model.ProductSystemNode)21 Link (org.openlca.app.editors.graphical.model.Link)6 ProcessLink (org.openlca.core.model.ProcessLink)6 ProcessNode (org.openlca.app.editors.graphical.model.ProcessNode)5 ProductSystem (org.openlca.core.model.ProductSystem)5 ArrayList (java.util.ArrayList)3 Command (org.eclipse.gef.commands.Command)2 LayoutCommand (org.openlca.app.editors.graphical.command.LayoutCommand)2 ExchangeNode (org.openlca.app.editors.graphical.model.ExchangeNode)2 MutableProcessLinkSearchMap (org.openlca.app.editors.graphical.search.MutableProcessLinkSearchMap)2 FlowType (org.openlca.core.model.FlowType)2 HashMap (java.util.HashMap)1 Dimension (org.eclipse.draw2d.geometry.Dimension)1 Point (org.eclipse.draw2d.geometry.Point)1 Rectangle (org.eclipse.draw2d.geometry.Rectangle)1 KeyHandler (org.eclipse.gef.KeyHandler)1 ScalableRootEditPart (org.eclipse.gef.editparts.ScalableRootEditPart)1 IAction (org.eclipse.jface.action.IAction)1 DeleteLinkCommand (org.openlca.app.editors.graphical.command.DeleteLinkCommand)1 MassCreationCommand (org.openlca.app.editors.graphical.command.MassCreationCommand)1