1 /*******************************************************************************
\r
2 * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.
\r
3 * All rights reserved. This program and the accompanying materials
\r
4 * are made available under the terms of the Eclipse Public License v1.0
\r
5 * which accompanies this distribution, and is available at
\r
6 * http://www.eclipse.org/legal/epl-v10.html
\r
9 * VTT Technical Research Centre of Finland - initial API and implementation
\r
10 *******************************************************************************/
\r
11 package org.simantics.processeditor.common;
\r
14 public class PipingTools {
\r
15 // private static final boolean DEBUG = true;
\r
20 // * Splits straigth by inserting new controlpoint between straight ends.
\r
21 // * @param straight
\r
23 // * @throws TransactionException
\r
25 //// public static void insertControlPoint(Straight straight, PipeControlPoint newPcp) throws TransactionException {
\r
26 //// if (straight == null || newPcp == null) {
\r
27 //// ErrorLogger.defaultLogError("Routing pipe, cannot make branch: straight or control point is null", null);
\r
30 //// PipeControlPoint scp = straight.getHasControlPoint();
\r
31 //// PipeControlPoint straightStart = (PipeControlPoint)StubFactory.getStubForResource(straight.getClass().getClassLoader(),scp.getPreviousPoint().getResource());
\r
32 //// PipeControlPoint straightEnd = (PipeControlPoint)StubFactory.getStubForResource(straight.getClass().getClassLoader(),scp.getNext().getResource());
\r
33 //// if (DEBUG) System.out.println("PipingTools inserting control point between " + straightStart.getResource() + " " + straightEnd.getResource() + " straight " + straight.getResource());
\r
35 //// // remove the straight pipe
\r
36 //// PipeControlPoint temp = PipeControlPointFactory.instantiate(newPcp.getGraph());
\r
37 //// //straight.setHasNextControlPoint(temp);
\r
38 //// //straight.setHasPreviousControlPoint(temp);
\r
39 //// straight.setHasControlPoint(temp);
\r
41 //// PipeRun pipeRun = getPipeRun(straight);
\r
42 //// if (pipeRun != null) {
\r
43 //// pipeRun.getHasSubnodesSet().remove(straight.getResource());
\r
45 //// insertControlPoint(pipeRun, newPcp, straightStart, straightEnd);
\r
56 // public static void getStraightPipeEnds(Straight straight, Point3d end1, Point3d end2) {
\r
57 // getStraightPipeEnds(getPipeRun(straight), straight, end1, end2);
\r
60 // public static void getStraightPipeEnds(PipeRun pipeRun,Straight straight, Point3d end1, Point3d end2) {
\r
61 // if (DEBUG) System.out.println("PipingTools.getStraightPipeEnds() " + straight.getResource());
\r
62 // PipeControlPoint scp = straight.getHasControlPoint();
\r
63 // PipeControlPoint startControlPoint = (PipeControlPoint)StubFactory.getStubForResource(straight.getClass().getClassLoader(),scp.getPrevious().getResource());
\r
64 // PipeControlPoint endControlPoint = (PipeControlPoint)StubFactory.getStubForResource(straight.getClass().getClassLoader(),scp.getNext().getResource());
\r
65 // if (startControlPoint == null || endControlPoint == null) {
\r
66 // ErrorLogger.defaultLogError("Pipe ends null", new NullPointerException());
\r
68 // // start and end position of the pipe
\r
69 // // positions may be linked to other components, like nozzles
\r
70 // // and then their coordinates are in component's local coordinates
\r
71 // // which must be transformed into pipeRun's local coordinates
\r
73 // //Point3d startPipe = getLocalPoint(pipeRun,startControlPoint);
\r
76 // //Point3d endPipe = getLocalPoint(pipeRun, endControlPoint);
\r
77 // Point3d startPipe = G3DTools.getPoint(startControlPoint.getLocalPosition());
\r
78 // Point3d endPipe = G3DTools.getPoint(endControlPoint.getLocalPosition());
\r
79 // if (startPipe == null || endPipe == null) {
\r
80 // end1.x = Double.NaN;
\r
81 // end1.y = Double.NaN;
\r
82 // end1.z = Double.NaN;
\r
83 // end2.x = Double.NaN;
\r
84 // end2.y = Double.NaN;
\r
85 // end2.z = Double.NaN;
\r
86 // if (DEBUG) System.out.println("no positions");
\r
90 // Vector3d dir = new Vector3d(endPipe);
\r
91 // dir.sub(startPipe);
\r
94 // if (startControlPoint instanceof TurnControlPoint) {
\r
95 // TurnControlPoint t = (TurnControlPoint)startControlPoint;
\r
96 // double R = t.getComponentOffsetValue();
\r
97 // Vector3d n = new Vector3d(dir);
\r
100 // startPipe.add(n);
\r
101 // } else if (startControlPoint instanceof InlineControlPoint && !(startControlPoint instanceof BranchControlPoint)) {
\r
102 // InlineControlPoint t = (InlineControlPoint)startControlPoint;
\r
103 // double R = t.getNextComponentOffsetValue();
\r
104 // Vector3d n = new Vector3d(dir);
\r
107 // startPipe.add(n);
\r
110 // if (endControlPoint instanceof TurnControlPoint) {
\r
111 // TurnControlPoint t = (TurnControlPoint)endControlPoint;
\r
112 // double R = t.getComponentOffsetValue();
\r
113 // Vector3d n = new Vector3d(dir);
\r
117 // } else if (endControlPoint instanceof InlineControlPoint && !(endControlPoint instanceof BranchControlPoint)) {
\r
118 // InlineControlPoint t = (InlineControlPoint)endControlPoint;
\r
119 // double R = t.getPreviousComponentOffsetValue();
\r
120 // Vector3d n = new Vector3d(dir);
\r
126 // end1.x = startPipe.x;
\r
127 // end1.y = startPipe.y;
\r
128 // end1.z = startPipe.z;
\r
130 // end2.x = endPipe.x;
\r
131 // end2.y = endPipe.y;
\r
132 // end2.z = endPipe.z;
\r
137 // * Finds direction and ends where inline component, reducer or branch can be moved.
\r
143 // public static void getInlineEnds(InlineControlPoint icp, Vector3d s, Vector3d e, Vector3d d) {
\r
145 // PipeControlPoint next = (PipeControlPoint)StubFactory.getStubForResource(icp.getClass().getClassLoader(), icp.getNext().getResource());
\r
146 // PipeControlPoint prev = (PipeControlPoint)StubFactory.getStubForResource(icp.getClass().getClassLoader(), icp.getPrevious().getResource());
\r
147 // Vector3d start = G3DTools.getVector(prev.getLocalPosition());
\r
148 // Vector3d end = G3DTools.getVector(next.getLocalPosition());
\r
149 // if (icp.getResource().isInstanceOf(GlobalIdMap.get(PSK3DModelingOntologyMapping.SIZE_CHANGE_CONTROL_POINT))) {
\r
150 // SizeChangeControlPoint sccp = SizeChangeControlPointFactory.create(icp.getResource());
\r
151 // Vector3d tDir = new Vector3d(G3DTools.getVector(sccp.getLocalPosition()));
\r
152 // Vector3d offset = getSizeChangeOffsetVector(sccp, tDir);
\r
153 // end.sub(offset);
\r
155 // Vector3d dir = new Vector3d(end);
\r
157 // Vector3d n = new Vector3d(dir);
\r
160 // double offset = icp.getNextComponentOffsetValue();
\r
161 // if (next instanceof InlineControlPoint) {
\r
162 // InlineControlPoint ip = (InlineControlPoint) next;
\r
163 // offset += ip.getPreviousComponentOffsetValue();
\r
165 // else if (next instanceof TurnControlPoint) {
\r
166 // TurnControlPoint tcp = (TurnControlPoint)next;
\r
167 // offset += tcp.getComponentOffsetValue();
\r
169 // Vector3d t = new Vector3d(n);
\r
170 // t.scale(offset);
\r
173 // offset = icp.getPreviousComponentOffsetValue();
\r
174 // if (prev instanceof InlineControlPoint) {
\r
175 // InlineControlPoint ip = (InlineControlPoint) prev;
\r
176 // offset += ip.getPreviousComponentOffsetValue();
\r
178 // else if (prev instanceof TurnControlPoint) {
\r
179 // TurnControlPoint tcp = (TurnControlPoint)prev;
\r
180 // offset += tcp.getComponentOffsetValue();
\r
182 // t = new Vector3d(n);
\r
183 // t.scale(offset);
\r
186 // dir= new Vector3d(end);
\r
201 // System.out.println("PipingTools.getInlineEnds() " + s + " " + e + " " + d);
\r
205 // public static void setSame(fi.vtt.simantics.layer0.stubs.Double d1, fi.vtt.simantics.layer0.stubs.Double d2) {
\r
206 // d1.getResource().createRelation(d2.getResource(), GlobalIdMap.get(PSK3DModelingOntologyMapping.IS_SAME_VALUE));
\r
209 // public static void setHalf(fi.vtt.simantics.layer0.stubs.Double d1, fi.vtt.simantics.layer0.stubs.Double d2) {
\r
210 // d1.getResource().createRelation(d2.getResource(), GlobalIdMap.get(PSK3DModelingOntologyMapping.IS_HALF_OF_THE_VALUE));
\r