Search in sources :

Example 1 with ProcessNode

use of org.openlca.app.editors.graphical.model.ProcessNode 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 2 with ProcessNode

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

the class LayoutCommand method execute.

@Override
public void execute() {
    for (ProcessNode node : model.getChildren()) {
        if (node.figure.isVisible()) {
            oldConstraints.put(node.figure, node.figure.getBounds().getCopy());
        }
    }
    layoutManager.layout(model.figure, type);
    model.editor.setDirty();
}
Also used : ProcessNode(org.openlca.app.editors.graphical.model.ProcessNode)

Example 3 with ProcessNode

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

the class MassCreationCommand method addNode.

private void addNode(RootDescriptor process) {
    if (sysNode.getProcessNode(process.id) != null)
        return;
    ProcessNode node = new ProcessNode(sysNode.editor, process);
    sysNode.getProductSystem().processes.add(process.id);
    sysNode.add(node);
    createdNodes.add(node);
}
Also used : ProcessNode(org.openlca.app.editors.graphical.model.ProcessNode)

Example 4 with ProcessNode

use of org.openlca.app.editors.graphical.model.ProcessNode 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 ProcessNode

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

the class CreateProcessCommand method execute.

@Override
public void execute() {
    model.getProductSystem().processes.add(process.id);
    model.add(new ProcessNode(model.editor, process));
    if (model.editor.getOutline() != null)
        model.editor.getOutline().refresh();
    model.editor.setDirty();
}
Also used : ProcessNode(org.openlca.app.editors.graphical.model.ProcessNode)

Aggregations

ProcessNode (org.openlca.app.editors.graphical.model.ProcessNode)19 Link (org.openlca.app.editors.graphical.model.Link)6 Rectangle (org.eclipse.draw2d.geometry.Rectangle)5 ProductSystemNode (org.openlca.app.editors.graphical.model.ProductSystemNode)5 ProcessLink (org.openlca.core.model.ProcessLink)5 ArrayList (java.util.ArrayList)3 MutableProcessLinkSearchMap (org.openlca.app.editors.graphical.search.MutableProcessLinkSearchMap)3 HashMap (java.util.HashMap)2 Dimension (org.eclipse.draw2d.geometry.Dimension)2 Point (org.eclipse.draw2d.geometry.Point)2 Command (org.eclipse.gef.commands.Command)2 RootDescriptor (org.openlca.core.model.descriptors.RootDescriptor)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 DND (org.eclipse.swt.dnd.DND)1 DropTarget (org.eclipse.swt.dnd.DropTarget)1 DropTargetAdapter (org.eclipse.swt.dnd.DropTargetAdapter)1 DropTargetEvent (org.eclipse.swt.dnd.DropTargetEvent)1 ModelTransfer (org.openlca.app.components.ModelTransfer)1 ChangeStateCommand (org.openlca.app.editors.graphical.command.ChangeStateCommand)1 DeleteLinkCommand (org.openlca.app.editors.graphical.command.DeleteLinkCommand)1