/******************************************************************************* * 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.proconf.g3d.actions; import org.simantics.db.Resource; import org.simantics.proconf.g3d.base.ConstraintDetector; /** * Temporary class to handle "Automatic" constraints for translation * TODO : create extension point / extension that can provide constraints * TODO : how to override previously added constraints ? * * @author Marko Luukkainen * */ public class TranslateActionConstraints { public static void addConstraints(Resource translated[], ConstraintDetector detector) { detector.clearConstraints(); // these must be provided through extension point ! // if (isElbow(translated)) { // addElbowConstraints(translated, detector); // } else if (isPipeControlPoint(translated)) { // addPipeControlPointConstraints(translated, detector); // } else if (isEndComponent(translated)) { // addEndComponentConstraints(translated, detector); // } } /* * These methods must be inserted into extension */ // private static boolean isElbow(Resource translated[]) { // for (Resource r : translated) { // if (!r.isInstanceOf(GlobalIdMap.get(PSK3DModelingOntologyMapping.ELBOW))) { // return false; // } // } // return true; // } // // private static boolean isEndComponent(Resource translated[]) { // for (Resource r : translated) { // if (!r.isInstanceOf(GlobalIdMap.get(PSK3DModelingOntologyMapping.END_COMPONENT))) { // return false; // } // } // return true; // } // // private static boolean isPipeControlPoint(Resource translated[]) { // for (Resource r : translated) { // if (!r.isInstanceOf(GlobalIdMap.get(PSK3DModelingOntologyMapping.PIPE_CONTROL_POINT))) { // return false; // } // } // return true; // } // // private static void addElbowConstraints(Resource translated[], ConstraintDetector detector) { // Set res = new HashSet(); // // add all controlpoints connected to every elbow's controlpoint // for (Resource r : translated) { // Elbow elbow = ElbowFactory.create(r); // PipeControlPoint p = elbow.getHasControlPoint(); // PipeControlPoint next = PipingTools.findNextEnd(p); // PipeControlPoint previous = PipingTools.findPreviousEnd(p); // if (next != null) // res.add(next.getResource()); // if (previous != null) // res.add(previous.getResource()); // // } // // remove all controlpoints that are elbows' controlpoints // for (Resource r : translated) { // Elbow elbow = ElbowFactory.create(r); // res.remove(elbow.getHasControlPoint().getResource()); // } // for (Resource r : res) { // PipeControlPoint p = PipeControlPointFactory.create(r); // detector.addContraintPoint(GraphicsNodeTools.getPoint(p.getLocalPosition())); // } // } // // private static void addEndComponentConstraints(Resource translated[], ConstraintDetector detector) { // Set res = new HashSet(); // // add all controlpoints connected to every elbow's controlpoint // for (Resource r : translated) { // EndComponent elbow = EndComponentFactory.create(r); // PipeControlPoint p = elbow.getHasControlPoint(); // PipeControlPoint next = PipingTools.findNextEnd(p); // PipeControlPoint previous = PipingTools.findPreviousEnd(p); // if (next != null) // res.add(next.getResource()); // if (previous != null) // res.add(previous.getResource()); // // } // // remove all controlpoints that are elbows' controlpoints // for (Resource r : translated) { // EndComponent elbow = EndComponentFactory.create(r); // res.remove(elbow.getHasControlPoint().getResource()); // } // for (Resource r : res) { // PipeControlPoint p = PipeControlPointFactory.create(r); // detector.addContraintPoint(GraphicsNodeTools.getPoint(p.getLocalPosition())); // } // } // // // private static void addPipeControlPointConstraints(Resource translated[], ConstraintDetector detector) { // Set res = new HashSet(); // // add all controlpoints connected to every elbow's controlpoint // for (Resource r : translated) { // PipeControlPoint p = PipeControlPointFactory.create(r); // PipeControlPoint next = PipingTools.findNextEnd(p); // PipeControlPoint previous = PipingTools.findPreviousEnd(p); // if (next != null) // res.add(next.getResource()); // if (previous != null) // res.add(previous.getResource()); // // } // // remove all controlpoints that are elbows' controlpoints // for (Resource r : translated) { // res.remove(r); // } // for (Resource r : res) { // PipeControlPoint p = PipeControlPointFactory.create(r); // detector.addContraintPoint(GraphicsNodeTools.getPoint(p.getLocalPosition())); // } // } }