X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.plant3d%2Fsrc%2Forg%2Fsimantics%2Fplant3d%2Fscenegraph%2FPipeRun.java;h=86f649aa136e49b6d0f7ac00cf956fb7de9e4392;hb=9f84331c9967c88e0e5550ce91f2b7e364a5cb6d;hp=36710e4fee17d16a5c10bed8f16b0059a38485e8;hpb=b93886889422a3111b05a6944b3bcb2cdd8c416a;p=simantics%2F3d.git diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/PipeRun.java b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/PipeRun.java index 36710e4f..86f649aa 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/PipeRun.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/PipeRun.java @@ -1,10 +1,14 @@ package org.simantics.plant3d.scenegraph; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Objects; import org.simantics.g3d.math.MathTools; import org.simantics.g3d.property.annotations.GetPropertyValue; @@ -43,7 +47,7 @@ public class PipeRun extends P3DParentNode { @Override public Collection getActors() { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } @Override @@ -51,15 +55,19 @@ public class PipeRun extends P3DParentNode { } + @SuppressWarnings("deprecation") @RelatedGetValue(Plant3D.URIs.HasTurnRadius) @GetPropertyValue(value=Plant3D.URIs.HasTurnRadius, name = "Elbow radius") public double getTurnRadius() { return turnRadius[0]; } + @SuppressWarnings("deprecation") @RelatedSetValue(Plant3D.URIs.HasTurnRadius) @SetPropertyValue(Plant3D.URIs.HasTurnRadius) public void setTurnRadius(double turnRadius) { + if (this.turnRadius[0] == turnRadius) + return; this.turnRadius[0] = turnRadius; firePropertyChanged(Plant3D.URIs.HasTurnRadius); firePropertyChanged(Plant3D.URIs.HasTurnRadiusArray); @@ -74,7 +82,7 @@ public class PipeRun extends P3DParentNode { @RelatedSetValue(Plant3D.URIs.HasTurnRadiusArray) @SetPropertyValue(Plant3D.URIs.HasTurnRadiusArray) public void setTurnRadiusArray(double[] turnRadiusArray) { - if (turnRadiusArray == null || turnRadiusArray.length == 0) + if (turnRadiusArray == null || turnRadiusArray.length == 0 || Arrays.equals(this.turnRadius, turnRadiusArray)) return; this.turnRadius = turnRadiusArray; firePropertyChanged(Plant3D.URIs.HasTurnRadiusArray); @@ -89,7 +97,10 @@ public class PipeRun extends P3DParentNode { @RelatedSetValue(Plant3D.URIs.HasPipeDiameter) @SetPropertyValue(Plant3D.URIs.HasPipeDiameter) public void setPipeDiameter(double pipeDiameter) { - this.pipeDiameter = pipeDiameter; + if (Objects.equals(this.pipeDiameter, pipeDiameter)) + return; + + this.pipeDiameter = pipeDiameter; firePropertyChanged(Plant3D.URIs.HasPipeDiameter); } @@ -108,8 +119,22 @@ public class PipeRun extends P3DParentNode { } @RelatedElementsRem(Plant3D.URIs.children) + public void _remChild(PipelineComponent node) { + //since we do not now, if DB remove is actually remove or detach, we have to use detach. NodeMap will handle Component removals. + deattachNode(Plant3D.URIs.children, node); + } + public void remChild(PipelineComponent node) { - removeNode(Plant3D.URIs.children, node); + removeNode(Plant3D.URIs.children, node); + } + + @Override + public void remove() { + // since we do not now, if DB remove is actually remove or detach, we have to use detach. NodeMap will handle Component removals. + Collection comps = getChild(); + for (PipelineComponent c : comps) + c.deattach(); + super.remove(); } @@ -156,6 +181,86 @@ public class PipeRun extends P3DParentNode { return true; } + public boolean canMerge(PipeRun other) { + return MathTools.equals(pipeDiameter,other.pipeDiameter); + } + + /** + * Merges contents of PipeRun r2 to this PipeRun. Note: does not connect boundary components! + * @param r2 + */ + public void merge(PipeRun r2) { + Map turnIndexMap = null; + if (!this.equalSpecs(r2)) { + if (!this.canMerge(r2)) + throw new IllegalArgumentException("PipeRuns cannot be merged"); + // Merge turn radii. + turnIndexMap = new HashMap<>(); + List mergedTurnRadius = new ArrayList<>(); + for (double t : this.getTurnRadiusArray()) { + mergedTurnRadius.add(t); + } + for (int i2 = 0; i2 < r2.getTurnRadiusArray().length; i2++) { + double t2 = r2.getTurnRadiusArray()[i2]; + boolean found = false; + for (int i = 0; i < mergedTurnRadius.size(); i++) { + if (MathTools.equals(mergedTurnRadius.get(i), t2)) { + turnIndexMap.put(i2, i); + found = true; + break; + } + } + if (!found) { + turnIndexMap.put(i2, mergedTurnRadius.size()); + mergedTurnRadius.add(t2); + } + } + for (PipeControlPoint pcp : r2.getControlPoints()) { + PipelineComponent comp = pcp.getPipelineComponent(); + if (comp instanceof TurnComponent) { + + } + } + if (mergedTurnRadius.size() > this.getTurnRadiusArray().length) { + double arr[] = new double[mergedTurnRadius.size()]; + for (int i = 0; i < mergedTurnRadius.size(); i++) { + arr[i] = mergedTurnRadius.get(i); + } + this.setTurnRadiusArray(arr); + } + } + // Move components and control points + Collection pcps = r2.getControlPoints(); + for (PipeControlPoint pcp : pcps) { + r2.deattachChild(pcp); + this.addChild(pcp); + PipelineComponent component = pcp.getPipelineComponent(); + if (component != null) { + if (!(component instanceof Nozzle)) { + component.deattach(); + this.addChild(component); + } else { + Nozzle n = (Nozzle)component; + n.setPipeRun(this); + } + } + } + // Use new turn radii indexes + if (turnIndexMap != null) { + for (PipeControlPoint pcp : pcps) { + PipelineComponent component = pcp.getPipelineComponent(); + if (component instanceof TurnComponent) { + TurnComponent tc = (TurnComponent)component; + if (tc.getTurnRadiusIndex() == null || tc.getTurnRadiusIndex() < 0) + continue; + tc.setTurnRadiusIndex(turnIndexMap.get(tc.getTurnRadiusIndex())); + } + } + } + r2.remove(); + + } + private class ComponentComparator implements Comparator { @Override public int compare(PipelineComponent o1, PipelineComponent o2) {