Search in sources :

Example 6 with FlowType

use of org.openlca.core.model.FlowType in project olca-app by GreenDelta.

the class CreateLinkCommand method getProcessLink.

private ProcessLink getProcessLink() {
    if (processLink == null)
        processLink = new ProcessLink();
    processLink.flowId = flowId;
    ProductSystemNode sysNode = sysNode();
    if (sysNode == null)
        return processLink;
    FlowType type = sysNode.flows.type(flowId);
    if (input != null) {
        var p = input.parent().process;
        if (type == FlowType.PRODUCT_FLOW) {
            processLink.processId = p.id;
            processLink.exchangeId = input.exchange.id;
        } else if (type == FlowType.WASTE_FLOW) {
            processLink.providerId = p.id;
            processLink.setProviderType(p.type);
        }
    }
    if (output != null) {
        var p = output.parent().process;
        if (type == FlowType.PRODUCT_FLOW) {
            processLink.providerId = p.id;
            processLink.setProviderType(p.type);
        } else if (type == FlowType.WASTE_FLOW) {
            processLink.processId = p.id;
            processLink.exchangeId = output.exchange.id;
        }
    }
    return processLink;
}
Also used : ProcessLink(org.openlca.core.model.ProcessLink) ProductSystemNode(org.openlca.app.editors.graphical.model.ProductSystemNode) FlowType(org.openlca.core.model.FlowType)

Example 7 with FlowType

use of org.openlca.core.model.FlowType in project olca-app by GreenDelta.

the class JsonRefCollector method buildFlows.

private List<FlowRef> buildFlows(ZipFile zip) {
    List<FlowRef> flowRefs = new ArrayList<>();
    for (ZipEntry e : flowEntries) {
        JsonObject obj = unpack(e, zip);
        if (obj == null)
            continue;
        String id = Json.getString(obj, "@id");
        if (id == null)
            continue;
        FlowRef ref = new FlowRef();
        ref.flow = new FlowDescriptor();
        ref.flow.refId = id;
        ref.flow.name = Json.getString(obj, "name");
        ref.flow.flowType = Json.getEnum(obj, "flowType", FlowType.class);
        // the category
        String catID = Json.getRefId(obj, "category");
        ref.flowCategory = categoryPaths.get(catID);
        // find the reference flow property
        String propID = null;
        JsonArray props = Json.getArray(obj, "flowProperties");
        if (props != null) {
            for (JsonElement elem : props) {
                if (!elem.isJsonObject())
                    continue;
                JsonObject prop = elem.getAsJsonObject();
                boolean isRef = Json.getBool(prop, "referenceFlowProperty", false);
                if (!isRef)
                    continue;
                propID = Json.getRefId(prop, "flowProperty");
                break;
            }
        }
        if (propID != null) {
            ref.property = new FlowPropertyDescriptor();
            ref.property.refId = propID;
            ref.property.name = propertyNames.get(propID);
            String unitID = propertyUnits.get(propID);
            if (unitID != null) {
                ref.unit = new UnitDescriptor();
                ref.unit.refId = unitID;
                ref.unit.name = unitNames.get(unitID);
            }
        }
        flowRefs.add(ref);
    }
    return flowRefs;
}
Also used : FlowDescriptor(org.openlca.core.model.descriptors.FlowDescriptor) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) FlowPropertyDescriptor(org.openlca.core.model.descriptors.FlowPropertyDescriptor) JsonArray(com.google.gson.JsonArray) FlowRef(org.openlca.io.maps.FlowRef) JsonElement(com.google.gson.JsonElement) UnitDescriptor(org.openlca.core.model.descriptors.UnitDescriptor) FlowType(org.openlca.core.model.FlowType)

Example 8 with FlowType

use of org.openlca.core.model.FlowType in project olca-app by GreenDelta.

the class AvoidedCheck method setChecked.

@Override
protected void setChecked(Exchange e, boolean value) {
    if (e.isAvoided == value || !canModify(e))
        return;
    e.isAvoided = value;
    if (!value)
        e.defaultProviderId = 0;
    FlowType type = e.flow.flowType;
    if (type == FlowType.PRODUCT_FLOW)
        e.isInput = value;
    if (type == FlowType.WASTE_FLOW)
        e.isInput = !value;
    editor.setDirty(true);
}
Also used : FlowType(org.openlca.core.model.FlowType)

Example 9 with FlowType

use of org.openlca.core.model.FlowType in project olca-app by GreenDelta.

the class ProductSystemInfoPage method getRefCandidates.

private List<Exchange> getRefCandidates(Process p) {
    if (p == null)
        return Collections.emptyList();
    List<Exchange> candidates = new ArrayList<>();
    for (Exchange e : p.exchanges) {
        if (e.flow == null)
            continue;
        FlowType type = e.flow.flowType;
        if (e.isInput && type == FlowType.WASTE_FLOW)
            candidates.add(e);
        else if (!e.isInput && type == FlowType.PRODUCT_FLOW)
            candidates.add(e);
    }
    Collections.sort(candidates, (e1, e2) -> Strings.compare(Labels.name(e1.flow), Labels.name(e2.flow)));
    return candidates;
}
Also used : Exchange(org.openlca.core.model.Exchange) ArrayList(java.util.ArrayList) FlowType(org.openlca.core.model.FlowType)

Aggregations

FlowType (org.openlca.core.model.FlowType)9 ProcessLink (org.openlca.core.model.ProcessLink)5 ArrayList (java.util.ArrayList)2 Link (org.openlca.app.editors.graphical.model.Link)2 ProductSystemNode (org.openlca.app.editors.graphical.model.ProductSystemNode)2 MutableProcessLinkSearchMap (org.openlca.app.editors.graphical.search.MutableProcessLinkSearchMap)2 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 ZipEntry (java.util.zip.ZipEntry)1 ProcessNode (org.openlca.app.editors.graphical.model.ProcessNode)1 Exchange (org.openlca.core.model.Exchange)1 Process (org.openlca.core.model.Process)1 ProductSystem (org.openlca.core.model.ProductSystem)1 FlowDescriptor (org.openlca.core.model.descriptors.FlowDescriptor)1 FlowPropertyDescriptor (org.openlca.core.model.descriptors.FlowPropertyDescriptor)1 UnitDescriptor (org.openlca.core.model.descriptors.UnitDescriptor)1 FlowRef (org.openlca.io.maps.FlowRef)1