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));
}
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();
}
}
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();
}
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();
}
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();
}
Aggregations