X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.processeditor%2Fsrc%2Forg%2Fsimantics%2Fprocesseditor%2Fcommon%2FPathUtils.java;fp=org.simantics.processeditor%2Fsrc%2Forg%2Fsimantics%2Fprocesseditor%2Fcommon%2FPathUtils.java;h=0000000000000000000000000000000000000000;hb=6b6fcff5d6c326feef07ccf8401f97911778fffe;hp=8807ddfd2e7954d2cbc6c80546ddafb82feeb923;hpb=504c111db40d78f4913badddd126b283b5504dbb;p=simantics%2F3d.git diff --git a/org.simantics.processeditor/src/org/simantics/processeditor/common/PathUtils.java b/org.simantics.processeditor/src/org/simantics/processeditor/common/PathUtils.java deleted file mode 100644 index 8807ddfd..00000000 --- a/org.simantics.processeditor/src/org/simantics/processeditor/common/PathUtils.java +++ /dev/null @@ -1,145 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007- VTT Technical Research Centre of Finland. - * 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; - -import java.util.ArrayList; -import java.util.Collection; - -import org.simantics.db.Graph; -import org.simantics.db.Resource; -import org.simantics.layer0.utils.EntityFactory; -import org.simantics.layer0.utils.IEntity; -import org.simantics.layer0.utils.viewpoints.TraversalPath; -import org.simantics.proconf.browsing.GraphExplorer; -import org.simantics.utils.datastructures.Pair; - - - - - -public class PathUtils { - - public static void createPath(java.util.List samplePath, TraversalPath path, Resource sampleInstance, Resource sampleSource, GraphExplorer oe) { -// while (tNode != null) { -// long[] path = tNode.getPath(); -// for (int i = 0; i < path.length; i++) { -// samplePath.add(i, path[i]); -// } -// samplePath.add(path.length,tNode.getCoreId()); -// tNode = oe.getTreeParent(tNode); -// } - while (path != null) { - Resource predicate = path.getPredicate(); - Resource obj = path.getResource(); - if (predicate != null) { - samplePath.add(0,predicate); - path = path.getTail(); - } else { - // there is no relation and so this has to be root - path = null; - } - samplePath.add(1,obj); - - } - - if (!sampleInstance.equals(samplePath.get(0)) || !sampleSource.equals(samplePath.get(samplePath.size()-1))) { - String s = ""; - for (int i = 0; i < samplePath.size(); i++) { - s += samplePath.get(i) + " "; - } - throw new RuntimeException("Path from " + sampleInstance + " to " - + sampleSource + " is broken: " + s); - } - -// String s = ""; -// for (int i = 0; i < samplePath.size(); i++) { -// s += samplePath.get(i) + " "; -// } -// System.out.println("Path from " + sampleInstance + " to " + sampleSource + " is: " + s); - samplePath.remove(0); - } - - - - /** - * Finds similar path in cloned resource - * TODO : this isn't correct way to do this; - * Rigth way would be finding mapping between two clones - * and then find the similar resource - * (Viewpoint used to create clone is required) - * - * @param path - * @param begin - * @return - */ - public static IEntity findSimilar(java.util.List path, IEntity begin) { - if (path.size() == 0) - return begin; - if (path.size() == 1) - return null; - Graph g = begin.getGraph(); - java.util.List tPath = new ArrayList(); - tPath.addAll(path); - - Resource p = tPath.get(0); // predicate (relation) - Resource o = tPath.get(1); // object - tPath.remove(0); - tPath.remove(0); - - IEntity predicate = EntityFactory.create(g, p); - - - Collection possibleObjects = begin.getRelatedObjects(predicate); - if (possibleObjects.size() == 0) - return null; - if (possibleObjects.size() == 1) - return findSimilar(tPath, possibleObjects.iterator().next()); - else { - IEntity object = EntityFactory.create(g, o); - Collection objectTypes = object.getTypes(); - java.util.List> list = new ArrayList>(); - for (IEntity possible : possibleObjects) { - boolean matchTypes = true; - for (IEntity type : objectTypes) { - if(!possible.isInstanceOf(type)) { - matchTypes = false; - break; - } - - } - if (matchTypes) { - IEntity r = findSimilar(tPath,possible); - if (r != null) - list.add(new Pair(possible,r)); - //return r; - } - } - if (list.size() == 0) - return null; - if (list.size() == 1) - return list.get(0).second; - else { - // uses names of objects to detect similarities - String name = object.getName(); - if (name != null) { - for (Pair possible : list) { - String otherName = possible.first.getName(); - //System.out.println(name + " : " + otherName); - if (otherName != null && name.compareTo(otherName) == 0) - return possible.second; - } - } - } - } - - return null; - } -}