/******************************************************************************* * Copyright (c) 2007 VTT Technical Research Centre of Finland and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ package org.simantics.processeditor.common; public class PipingTools { // private static final boolean DEBUG = true; // // // // /** // * Splits straigth by inserting new controlpoint between straight ends. // * @param straight // * @param newPcp // * @throws TransactionException // */ //// public static void insertControlPoint(Straight straight, PipeControlPoint newPcp) throws TransactionException { //// if (straight == null || newPcp == null) { //// ErrorLogger.defaultLogError("Routing pipe, cannot make branch: straight or control point is null", null); //// return; //// } //// PipeControlPoint scp = straight.getHasControlPoint(); //// PipeControlPoint straightStart = (PipeControlPoint)StubFactory.getStubForResource(straight.getClass().getClassLoader(),scp.getPreviousPoint().getResource()); //// PipeControlPoint straightEnd = (PipeControlPoint)StubFactory.getStubForResource(straight.getClass().getClassLoader(),scp.getNext().getResource()); //// if (DEBUG) System.out.println("PipingTools inserting control point between " + straightStart.getResource() + " " + straightEnd.getResource() + " straight " + straight.getResource()); //// //// // remove the straight pipe //// PipeControlPoint temp = PipeControlPointFactory.instantiate(newPcp.getGraph()); //// //straight.setHasNextControlPoint(temp); //// //straight.setHasPreviousControlPoint(temp); //// straight.setHasControlPoint(temp); //// //// PipeRun pipeRun = getPipeRun(straight); //// if (pipeRun != null) { //// pipeRun.getHasSubnodesSet().remove(straight.getResource()); //// } //// insertControlPoint(pipeRun, newPcp, straightStart, straightEnd); //// //// } // // // // // // // // // public static void getStraightPipeEnds(Straight straight, Point3d end1, Point3d end2) { // getStraightPipeEnds(getPipeRun(straight), straight, end1, end2); // } // // public static void getStraightPipeEnds(PipeRun pipeRun,Straight straight, Point3d end1, Point3d end2) { // if (DEBUG) System.out.println("PipingTools.getStraightPipeEnds() " + straight.getResource()); // PipeControlPoint scp = straight.getHasControlPoint(); // PipeControlPoint startControlPoint = (PipeControlPoint)StubFactory.getStubForResource(straight.getClass().getClassLoader(),scp.getPrevious().getResource()); // PipeControlPoint endControlPoint = (PipeControlPoint)StubFactory.getStubForResource(straight.getClass().getClassLoader(),scp.getNext().getResource()); // if (startControlPoint == null || endControlPoint == null) { // ErrorLogger.defaultLogError("Pipe ends null", new NullPointerException()); // } // // start and end position of the pipe // // positions may be linked to other components, like nozzles // // and then their coordinates are in component's local coordinates // // which must be transformed into pipeRun's local coordinates // // //Point3d startPipe = getLocalPoint(pipeRun,startControlPoint); // // // //Point3d endPipe = getLocalPoint(pipeRun, endControlPoint); // Point3d startPipe = G3DTools.getPoint(startControlPoint.getLocalPosition()); // Point3d endPipe = G3DTools.getPoint(endControlPoint.getLocalPosition()); // if (startPipe == null || endPipe == null) { // end1.x = Double.NaN; // end1.y = Double.NaN; // end1.z = Double.NaN; // end2.x = Double.NaN; // end2.y = Double.NaN; // end2.z = Double.NaN; // if (DEBUG) System.out.println("no positions"); // return; // } // // Vector3d dir = new Vector3d(endPipe); // dir.sub(startPipe); // // // if (startControlPoint instanceof TurnControlPoint) { // TurnControlPoint t = (TurnControlPoint)startControlPoint; // double R = t.getComponentOffsetValue(); // Vector3d n = new Vector3d(dir); // n.normalize(); // n.scale(R); // startPipe.add(n); // } else if (startControlPoint instanceof InlineControlPoint && !(startControlPoint instanceof BranchControlPoint)) { // InlineControlPoint t = (InlineControlPoint)startControlPoint; // double R = t.getNextComponentOffsetValue(); // Vector3d n = new Vector3d(dir); // n.normalize(); // n.scale(R); // startPipe.add(n); // } // // if (endControlPoint instanceof TurnControlPoint) { // TurnControlPoint t = (TurnControlPoint)endControlPoint; // double R = t.getComponentOffsetValue(); // Vector3d n = new Vector3d(dir); // n.normalize(); // n.scale(R); // endPipe.sub(n); // } else if (endControlPoint instanceof InlineControlPoint && !(endControlPoint instanceof BranchControlPoint)) { // InlineControlPoint t = (InlineControlPoint)endControlPoint; // double R = t.getPreviousComponentOffsetValue(); // Vector3d n = new Vector3d(dir); // n.normalize(); // n.scale(R); // endPipe.sub(n); // } // // end1.x = startPipe.x; // end1.y = startPipe.y; // end1.z = startPipe.z; // // end2.x = endPipe.x; // end2.y = endPipe.y; // end2.z = endPipe.z; // // } // // /** // * Finds direction and ends where inline component, reducer or branch can be moved. // * @param icp // * @param s // * @param e // * @param d // */ // public static void getInlineEnds(InlineControlPoint icp, Vector3d s, Vector3d e, Vector3d d) { // // PipeControlPoint next = (PipeControlPoint)StubFactory.getStubForResource(icp.getClass().getClassLoader(), icp.getNext().getResource()); // PipeControlPoint prev = (PipeControlPoint)StubFactory.getStubForResource(icp.getClass().getClassLoader(), icp.getPrevious().getResource()); // Vector3d start = G3DTools.getVector(prev.getLocalPosition()); // Vector3d end = G3DTools.getVector(next.getLocalPosition()); // if (icp.getResource().isInstanceOf(GlobalIdMap.get(PSK3DModelingOntologyMapping.SIZE_CHANGE_CONTROL_POINT))) { // SizeChangeControlPoint sccp = SizeChangeControlPointFactory.create(icp.getResource()); // Vector3d tDir = new Vector3d(G3DTools.getVector(sccp.getLocalPosition())); // Vector3d offset = getSizeChangeOffsetVector(sccp, tDir); // end.sub(offset); // } // Vector3d dir = new Vector3d(end); // dir.sub(start); // Vector3d n = new Vector3d(dir); // n.normalize(); // // double offset = icp.getNextComponentOffsetValue(); // if (next instanceof InlineControlPoint) { // InlineControlPoint ip = (InlineControlPoint) next; // offset += ip.getPreviousComponentOffsetValue(); // } // else if (next instanceof TurnControlPoint) { // TurnControlPoint tcp = (TurnControlPoint)next; // offset += tcp.getComponentOffsetValue(); // } // Vector3d t = new Vector3d(n); // t.scale(offset); // end.sub(t); // // offset = icp.getPreviousComponentOffsetValue(); // if (prev instanceof InlineControlPoint) { // InlineControlPoint ip = (InlineControlPoint) prev; // offset += ip.getPreviousComponentOffsetValue(); // } // else if (prev instanceof TurnControlPoint) { // TurnControlPoint tcp = (TurnControlPoint)prev; // offset += tcp.getComponentOffsetValue(); // } // t = new Vector3d(n); // t.scale(offset); // start.add(t); // // dir= new Vector3d(end); // dir.sub(start); // // s.x = start.x; // s.y = start.y; // s.z = start.z; // // e.x = end.x; // e.y = end.y; // e.z = end.z; // // d.x = dir.x; // d.y = dir.y; // d.z = dir.z; // // System.out.println("PipingTools.getInlineEnds() " + s + " " + e + " " + d); // } // // // public static void setSame(fi.vtt.simantics.layer0.stubs.Double d1, fi.vtt.simantics.layer0.stubs.Double d2) { // d1.getResource().createRelation(d2.getResource(), GlobalIdMap.get(PSK3DModelingOntologyMapping.IS_SAME_VALUE)); // } // // public static void setHalf(fi.vtt.simantics.layer0.stubs.Double d1, fi.vtt.simantics.layer0.stubs.Double d2) { // d1.getResource().createRelation(d2.getResource(), GlobalIdMap.get(PSK3DModelingOntologyMapping.IS_HALF_OF_THE_VALUE)); // } // // // // // // // // // // // }