Search in sources :

Example 1 with Link

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

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

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

the class DeleteLinkCommand method undo.

@Override
public void undo() {
    if (links.isEmpty())
        return;
    ProductSystemNode sysNode = links.get(0).outputNode.parent();
    for (Link link : links) {
        sysNode.getProductSystem().processLinks.add(link.processLink);
        sysNode.linkSearch.put(link.processLink);
        link.link();
        link.updateVisibility();
    }
    sysNode.editor.setDirty();
}
Also used : ProductSystemNode(org.openlca.app.editors.graphical.model.ProductSystemNode) Link(org.openlca.app.editors.graphical.model.Link)

Example 4 with Link

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

the class HideShowCommand method execute.

@Override
public void execute() {
    ProcessNode node = model.getProcessNode(process.id);
    if (type == SHOW && node == null) {
        node = new ProcessNode(model.editor, process);
        model.add(node);
        model.editor.createNecessaryLinks(node);
    }
    node.setVisible(type == SHOW);
    for (Link link : node.links) {
        link.updateVisibility();
    }
    node.layout();
    node.parent().editor.setDirty();
}
Also used : ProcessNode(org.openlca.app.editors.graphical.model.ProcessNode) Link(org.openlca.app.editors.graphical.model.Link)

Example 5 with Link

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

Aggregations

Link (org.openlca.app.editors.graphical.model.Link)12 ProcessNode (org.openlca.app.editors.graphical.model.ProcessNode)6 ProductSystemNode (org.openlca.app.editors.graphical.model.ProductSystemNode)6 ProcessLink (org.openlca.core.model.ProcessLink)6 ReconnectLinkCommand (org.openlca.app.editors.graphical.command.ReconnectLinkCommand)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 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