Search in sources :

Example 1 with MutableProcessLinkSearchMap

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

use of org.openlca.app.editors.graphical.search.MutableProcessLinkSearchMap in project olca-app by GreenDelta.

the class RemoveAllConnectionsAction method run.

@Override
public void run() {
    if (processNodes.size() == 0)
        return;
    ProductSystemNode systemNode = editor.getModel();
    List<Link> links = new ArrayList<>();
    // create new link search to avoid problems with missing entries before
    // ConnectionLink.unlink is called
    List<ProcessLink> pLinks = systemNode.getProductSystem().processLinks;
    MutableProcessLinkSearchMap linkSearch = new MutableProcessLinkSearchMap(pLinks);
    for (ProcessNode processNode : processNodes) {
        List<ProcessLink> processLinks = linkSearch.getLinks(processNode.process.id);
        for (ProcessLink link : processLinks) linkSearch.remove(link);
        for (Link link : processNode.links) if (!links.contains(link))
            links.add(link);
    }
    Command command = new DeleteLinkCommand(links);
    editor.getCommandStack().execute(command);
}
Also used : ProcessLink(org.openlca.core.model.ProcessLink) Command(org.eclipse.gef.commands.Command) DeleteLinkCommand(org.openlca.app.editors.graphical.command.DeleteLinkCommand) ProductSystemNode(org.openlca.app.editors.graphical.model.ProductSystemNode) ArrayList(java.util.ArrayList) ProcessNode(org.openlca.app.editors.graphical.model.ProcessNode) MutableProcessLinkSearchMap(org.openlca.app.editors.graphical.search.MutableProcessLinkSearchMap) DeleteLinkCommand(org.openlca.app.editors.graphical.command.DeleteLinkCommand) Link(org.openlca.app.editors.graphical.model.Link) ProcessLink(org.openlca.core.model.ProcessLink)

Example 3 with MutableProcessLinkSearchMap

use of org.openlca.app.editors.graphical.search.MutableProcessLinkSearchMap in project olca-app by GreenDelta.

the class ProcessExpander method shouldBeVisible.

boolean shouldBeVisible() {
    ProductSystemNode sysNode = node.parent();
    MutableProcessLinkSearchMap linkSearch = sysNode.linkSearch;
    long processId = node.process.id;
    for (ProcessLink link : linkSearch.getLinks(processId)) {
        FlowType type = sysNode.flows.type(link.flowId);
        boolean isProvider = link.providerId == processId;
        if (side == Side.INPUT) {
            if (type == FlowType.PRODUCT_FLOW && !isProvider)
                return true;
            if (type == FlowType.WASTE_FLOW && isProvider)
                return true;
        } else if (side == Side.OUTPUT) {
            if (type == FlowType.PRODUCT_FLOW && isProvider)
                return true;
            if (type == FlowType.WASTE_FLOW && !isProvider)
                return true;
        }
    }
    return false;
}
Also used : ProcessLink(org.openlca.core.model.ProcessLink) MutableProcessLinkSearchMap(org.openlca.app.editors.graphical.search.MutableProcessLinkSearchMap) FlowType(org.openlca.core.model.FlowType)

Example 4 with MutableProcessLinkSearchMap

use of org.openlca.app.editors.graphical.search.MutableProcessLinkSearchMap in project olca-app by GreenDelta.

the class RemoveSupplyChainAction method run.

@Override
public void run() {
    clear();
    ProductSystem system = editor.getModel().getProductSystem();
    long refId = system.referenceProcess.id;
    if (refId == node.process.id) {
        for (ProcessNode node : editor.getModel().getChildren()) if (refId != node.process.id) {
            nodes.add(node);
            connections.addAll(node.links);
        }
        processIds.addAll(system.processes);
        processIds.remove(refId);
        links.addAll(system.processLinks);
    } else {
        linkSearch = new MutableProcessLinkSearchMap(system.processLinks);
        collectSupplyChain(node.process.id);
    }
    if (connections.size() > 0 || nodes.size() > 0 || links.size() > 0 || processIds.size() > 0)
        editor.getCommandStack().execute(new RemoveCommand());
}
Also used : ProductSystem(org.openlca.core.model.ProductSystem) ProcessNode(org.openlca.app.editors.graphical.model.ProcessNode) MutableProcessLinkSearchMap(org.openlca.app.editors.graphical.search.MutableProcessLinkSearchMap)

Aggregations

MutableProcessLinkSearchMap (org.openlca.app.editors.graphical.search.MutableProcessLinkSearchMap)4 ProcessNode (org.openlca.app.editors.graphical.model.ProcessNode)3 ProcessLink (org.openlca.core.model.ProcessLink)3 Link (org.openlca.app.editors.graphical.model.Link)2 ProductSystemNode (org.openlca.app.editors.graphical.model.ProductSystemNode)2 FlowType (org.openlca.core.model.FlowType)2 ArrayList (java.util.ArrayList)1 Command (org.eclipse.gef.commands.Command)1 DeleteLinkCommand (org.openlca.app.editors.graphical.command.DeleteLinkCommand)1 ProductSystem (org.openlca.core.model.ProductSystem)1