]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.proconf.processeditor/src/fi/vtt/simantics/processeditor/common/PipingTools.java
latest release (0.41), third attempt
[simantics/3d.git] / org.simantics.proconf.processeditor / src / fi / vtt / simantics / processeditor / common / PipingTools.java
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
7  *\r
8  * Contributors:\r
9  *     VTT Technical Research Centre of Finland - initial API and implementation\r
10  *******************************************************************************/\r
11 package fi.vtt.simantics.processeditor.common;\r
12 \r
13 \r
14 public class PipingTools {\r
15 //      private static final boolean DEBUG = true;\r
16 //      \r
17 //\r
18 //    \r
19 //    /**\r
20 //     * Splits straigth by inserting new controlpoint between straight ends.\r
21 //     * @param straight\r
22 //     * @param newPcp\r
23 //     * @throws TransactionException\r
24 //     */\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
28 ////            return;\r
29 ////        }\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
34 ////        \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
40 ////        \r
41 ////        PipeRun pipeRun = getPipeRun(straight);\r
42 ////        if (pipeRun != null) {\r
43 ////            pipeRun.getHasSubnodesSet().remove(straight.getResource());\r
44 ////        }\r
45 ////        insertControlPoint(pipeRun, newPcp, straightStart, straightEnd);\r
46 ////        \r
47 ////    }\r
48 //    \r
49 //\r
50 //\r
51 //    \r
52 //    \r
53 //   \r
54 //    \r
55 //    \r
56 //    public static void getStraightPipeEnds(Straight straight, Point3d end1, Point3d end2) {\r
57 //        getStraightPipeEnds(getPipeRun(straight), straight, end1, end2);\r
58 //    }\r
59 //    \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
67 //        }\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
72 //        \r
73 //        //Point3d startPipe = getLocalPoint(pipeRun,startControlPoint);\r
74 //\r
75 //        \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
87 //            return;\r
88 //        }\r
89 //        \r
90 //        Vector3d dir = new Vector3d(endPipe);\r
91 //        dir.sub(startPipe);\r
92 //        \r
93 //\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
98 //            n.normalize();\r
99 //            n.scale(R);\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
105 //            n.normalize();\r
106 //            n.scale(R);\r
107 //            startPipe.add(n);\r
108 //        }\r
109 //\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
114 //            n.normalize();\r
115 //            n.scale(R);\r
116 //            endPipe.sub(n);\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
121 //            n.normalize();\r
122 //            n.scale(R);\r
123 //            endPipe.sub(n);\r
124 //        }\r
125 //        \r
126 //        end1.x = startPipe.x;\r
127 //        end1.y = startPipe.y;\r
128 //        end1.z = startPipe.z;\r
129 //        \r
130 //        end2.x = endPipe.x;\r
131 //        end2.y = endPipe.y;\r
132 //        end2.z = endPipe.z;\r
133 //        \r
134 //    }\r
135 //    \r
136 //    /**\r
137 //     * Finds direction and ends where inline component, reducer or branch can be moved.\r
138 //     * @param icp\r
139 //     * @param s\r
140 //     * @param e\r
141 //     * @param d\r
142 //     */\r
143 //    public static void getInlineEnds(InlineControlPoint icp, Vector3d s, Vector3d e, Vector3d d) {\r
144 //        \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
154 //        }\r
155 //        Vector3d dir = new Vector3d(end);\r
156 //        dir.sub(start);\r
157 //        Vector3d n = new Vector3d(dir);\r
158 //        n.normalize();\r
159 //        \r
160 //        double offset = icp.getNextComponentOffsetValue();\r
161 //        if (next instanceof InlineControlPoint) {\r
162 //            InlineControlPoint ip = (InlineControlPoint) next;\r
163 //            offset += ip.getPreviousComponentOffsetValue();      \r
164 //        }\r
165 //        else if (next instanceof TurnControlPoint) {\r
166 //            TurnControlPoint tcp = (TurnControlPoint)next;\r
167 //            offset += tcp.getComponentOffsetValue();\r
168 //        }\r
169 //        Vector3d t = new Vector3d(n);\r
170 //        t.scale(offset);\r
171 //        end.sub(t);\r
172 //        \r
173 //        offset = icp.getPreviousComponentOffsetValue();\r
174 //        if (prev instanceof InlineControlPoint) {\r
175 //            InlineControlPoint ip = (InlineControlPoint) prev;\r
176 //            offset += ip.getPreviousComponentOffsetValue();\r
177 //        }\r
178 //        else if (prev instanceof TurnControlPoint) {\r
179 //            TurnControlPoint tcp = (TurnControlPoint)prev;\r
180 //            offset += tcp.getComponentOffsetValue();\r
181 //        }\r
182 //        t = new Vector3d(n);\r
183 //        t.scale(offset);\r
184 //        start.add(t);\r
185 //        \r
186 //        dir= new Vector3d(end);\r
187 //        dir.sub(start);\r
188 //        \r
189 //        s.x = start.x;\r
190 //        s.y = start.y;\r
191 //        s.z = start.z;\r
192 //        \r
193 //        e.x = end.x;\r
194 //        e.y = end.y;\r
195 //        e.z = end.z;\r
196 //        \r
197 //        d.x = dir.x;\r
198 //        d.y = dir.y;\r
199 //        d.z = dir.z;\r
200 //        \r
201 //        System.out.println("PipingTools.getInlineEnds() " + s + " " + e + " " + d);\r
202 //    }\r
203 //    \r
204 //    \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
207 //    }\r
208 //    \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
211 //    }\r
212 //    \r
213 //    \r
214 //    \r
215 \r
216 //    \r
217 //\r
218 //    \r
219 //    \r
220 //    \r
221 //    \r
222 //    \r
223 //    \r
224 \r
225 }