From: Tuukka Lehtonen Date: Fri, 6 Sep 2019 13:29:10 +0000 (+0000) Subject: Merge "Include disconnected flag terminals for connection judgement" X-Git-Tag: v1.43.0~136^2~76 X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=33b30297f751e06e9abac260d31313e2f833fedc;hp=e7d708d6c168ee196f44b1850b4f3e3cb559aa7e Merge "Include disconnected flag terminals for connection judgement" --- diff --git a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/EnumerationVariableModifier3.java b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/EnumerationVariableModifier3.java index 3bd3e7b91..52b5012d7 100644 --- a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/EnumerationVariableModifier3.java +++ b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/EnumerationVariableModifier3.java @@ -57,7 +57,7 @@ public class EnumerationVariableModifier3 implements EnumerationModifier { public String perform(ReadGraph graph) throws DatabaseException { EnumerationValue ev = graph.syncRequest(new GetEnumerationValue(variable.getParent(graph).getRepresents(graph))); if(ev != null) { - return ev.getEnumeratedValue().getName(); + return ev.getEnumeratedValue().getName(); } // System.err.println(variable.getURI(graph)); return variable.getValue(graph);//variable.getPossiblePropertyValue(graph, Variables.LABEL); diff --git a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/GetEnumerationValue.java b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/GetEnumerationValue.java index 9e8adfebe..0f9d119ac 100644 --- a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/GetEnumerationValue.java +++ b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/GetEnumerationValue.java @@ -41,7 +41,7 @@ public class GetEnumerationValue extends ResourceRead public EnumerationValue perform(ReadGraph graph) throws DatabaseException { return enumerate(graph, resource); } - + public static String getEnumerationValueName(ReadGraph graph, Resource resource) throws DatabaseException { Layer0 L0 = Layer0.getInstance(graph); String label = graph.getPossibleRelatedValue(resource, L0.HasLabel, Bindings.STRING); diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/validation/L0Validations.java b/bundles/org.simantics.db.common/src/org/simantics/db/common/validation/L0Validations.java index 99ef91b7a..1ff6e5fbc 100644 --- a/bundles/org.simantics.db.common/src/org/simantics/db/common/validation/L0Validations.java +++ b/bundles/org.simantics.db.common/src/org/simantics/db/common/validation/L0Validations.java @@ -12,7 +12,7 @@ import org.simantics.scl.compiler.types.Type; public class L0Validations { public static String checkValueType(ReadGraph graph, Resource subject, Resource predicate) throws DatabaseException { - + if (subject == null) return null; if (predicate == null) @@ -25,9 +25,34 @@ public class L0Validations { String valueTypeText = graph.getPossibleRelatedValue(predicate, L0.RequiresValueType, Bindings.STRING); if(valueTypeText != null) { Type valueType = CommonDBUtils.getSCLType(graph, subject, valueTypeText); + if(valueType == null) { + Resource range = graph.getPossibleObject(predicate, L0.HasRange); + if(range != null) { + return null; + } else { + StringBuilder sb = new StringBuilder() + .append("The value type ") + .append(valueType) + .append(" of predicate ") + .append(NameUtils.getSafeName(graph, predicate, true)) + .append(" cannot be resolved.") + .append(NameUtils.getSafeName(graph, object, true)) + .append("."); + return sb.toString(); + } + } String valueTypeText2 = graph.getPossibleRelatedValue(object, L0.HasValueType, Bindings.STRING); if(valueTypeText2 != null) { Type valueType2 = CommonDBUtils.getSCLType(graph, subject, valueTypeText2); + if(valueType2 == null) { + StringBuilder sb = new StringBuilder() + .append("The value type ") + .append(valueType2) + .append(" of object ") + .append(NameUtils.getSafeName(graph, object, true)) + .append(" cannot be resolved."); + return sb.toString(); + } if(!valueType.equals(valueType2)) { StringBuilder sb = new StringBuilder() .append("The value type ") @@ -44,9 +69,9 @@ public class L0Validations { } } } - + return null; - + } - + } diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PropertyInfo.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PropertyInfo.java index f3753ce80..4d208b457 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PropertyInfo.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PropertyInfo.java @@ -1,3 +1,14 @@ +/******************************************************************************* + * Copyright (c) 2019 Association for Decentralized Information Management + * in Industry THTH ry. + * 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: + * Semantum Oy - initial API and implementation + *******************************************************************************/ package org.simantics.db.layer0.request; import java.util.Collection; @@ -20,6 +31,7 @@ public class PropertyInfo { public final Resource predicate; public final String name; public final boolean isHasProperty; + public final boolean isFunctional; public final Set classifications; public final VariableBuilder builder; public final Resource literalRange; @@ -30,9 +42,10 @@ public class PropertyInfo { public final Map> subliteralPredicates; public final ValueAccessor valueAccessor; public final boolean hasEnumerationRange; - public PropertyInfo(Resource predicate, String name, boolean isHasProperty, Set classifications, VariableBuilder builder, Resource literalRange, Datatype requiredDatatype, String definedUnit, String requiredValueType, Binding defaultBinding, Map> subliteralPredicates, ValueAccessor valueAccessor, boolean hasEnumerationRange) { + public PropertyInfo(Resource predicate, String name, boolean isFunctional, boolean isHasProperty, Set classifications, VariableBuilder builder, Resource literalRange, Datatype requiredDatatype, String definedUnit, String requiredValueType, Binding defaultBinding, Map> subliteralPredicates, ValueAccessor valueAccessor, boolean hasEnumerationRange) { this.predicate = predicate; this.name = name; + this.isFunctional = isFunctional; this.isHasProperty = isHasProperty; this.classifications = classifications; this.builder = builder; @@ -45,7 +58,7 @@ public class PropertyInfo { this.valueAccessor = valueAccessor; this.hasEnumerationRange = hasEnumerationRange; } - public static PropertyInfo make(ReadGraph graph, Resource predicate, String name, boolean isHasProperty, Set classifications, VariableBuilder builder, Resource literalRange, Datatype requiredDatatype, String definedUnit, String requiredValueType, Map> subliteralPredicates, ValueAccessor valueAccessor, boolean hasEnumerationRange) throws DatabaseException { + public static PropertyInfo make(ReadGraph graph, Resource predicate, String name, boolean isFunctional, boolean isHasProperty, Set classifications, VariableBuilder builder, Resource literalRange, Datatype requiredDatatype, String definedUnit, String requiredValueType, Map> subliteralPredicates, ValueAccessor valueAccessor, boolean hasEnumerationRange) throws DatabaseException { Layer0 L0 = Layer0.getInstance(graph); if(literalRange != null) { @@ -58,7 +71,7 @@ public class PropertyInfo { Binding defaultBinding = requiredDatatype != null ? Bindings.getBinding(requiredDatatype) : null; - return new PropertyInfo(predicate, name, isHasProperty, classifications, builder, literalRange, requiredDatatype, definedUnit, requiredValueType, defaultBinding, subliteralPredicates, valueAccessor, hasEnumerationRange); + return new PropertyInfo(predicate, name, isFunctional, isHasProperty, classifications, builder, literalRange, requiredDatatype, definedUnit, requiredValueType, defaultBinding, subliteralPredicates, valueAccessor, hasEnumerationRange); } public boolean hasClassification(String classification) { @@ -75,6 +88,8 @@ public class PropertyInfo { .append(requiredValueType) .append(", predicate=") .append(predicate) + .append(", isFunctional=") + .append(isFunctional) .append(", isHasProperty=") .append(isHasProperty) .append(", hasEnumerationRange=") diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PropertyInfoRequest.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PropertyInfoRequest.java index 2a181674c..90e63e29f 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PropertyInfoRequest.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PropertyInfoRequest.java @@ -41,6 +41,8 @@ final public class PropertyInfoRequest extends ResourceRead { String name = graph.getPossibleRelatedValue(resource, L0.HasName, Bindings.STRING); if(name != null) name = name.intern(); + boolean isFunctional = graph.isInstanceOf(resource, L0.FunctionalRelation); + Set classifications = graph.sync(new ClassificationsRequest(graph.getPrincipalTypes(resource))); VariableBuilder variableBuilder = graph.getPossibleAdapter(resource, VariableBuilder.class); @@ -88,13 +90,13 @@ final public class PropertyInfoRequest extends ResourceRead { } } - return PropertyInfo.make(graph, resource, name, isHasProperty, classifications, variableBuilder, literalRange, requiredDataType, definedUnit, requiredValueType, map, accessor, hasEnumerationRange); + return PropertyInfo.make(graph, resource, name, isFunctional, isHasProperty, classifications, variableBuilder, literalRange, requiredDataType, definedUnit, requiredValueType, map, accessor, hasEnumerationRange); } } } - return PropertyInfo.make(graph, resource, name, isHasProperty, classifications, variableBuilder, literalRange, requiredDataType, definedUnit, requiredValueType, Collections.>emptyMap(), accessor, hasEnumerationRange); + return PropertyInfo.make(graph, resource, name, isFunctional, isHasProperty, classifications, variableBuilder, literalRange, requiredDataType, definedUnit, requiredValueType, Collections.>emptyMap(), accessor, hasEnumerationRange); } diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Layer0Utils.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Layer0Utils.java index 610c8c8bd..830f7a6bb 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Layer0Utils.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Layer0Utils.java @@ -71,7 +71,6 @@ import org.simantics.db.common.primitiverequest.PossibleRelatedValue; import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener; import org.simantics.db.common.request.DelayedWriteRequest; import org.simantics.db.common.request.ObjectsWithType; -import org.simantics.db.common.request.PossibleChild; import org.simantics.db.common.request.PossibleIndexRoot; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.common.utils.CommonDBUtils; @@ -116,9 +115,7 @@ import org.simantics.graph.representation.PrettyPrintTG; import org.simantics.graph.representation.TransferableGraph1; import org.simantics.layer0.Layer0; import org.simantics.operation.Layer0X; -import org.simantics.scl.compiler.environment.Environments; import org.simantics.scl.compiler.runtime.RuntimeEnvironment; -import org.simantics.scl.compiler.top.SCLExpressionCompilationException; import org.simantics.scl.compiler.types.Type; import org.simantics.scl.osgi.SCLOsgi; import org.simantics.scl.runtime.function.Function; @@ -1382,6 +1379,41 @@ public class Layer0Utils { return result; } + public static Resource possibleObjectForType(ReadGraph graph, Resource type, Resource relation) throws DatabaseException { + PropertyInfo pi = graph.syncRequest(new PropertyInfoRequest(relation)); + return possibleObjectForType(graph, type, relation, pi.isFunctional); + } + + public static Resource possibleObjectForType(ReadGraph graph, Resource type, Resource relation, boolean functional) throws DatabaseException { + if(functional) { + Layer0 L0 = Layer0.getInstance(graph); + Resource result = graph.getPossibleObject(type, relation); + if(result != null) + return result; + for(Resource su : graph.getObjects(L0.Inherits, type)) { + Resource r = possibleObjectForType(graph, su, relation, functional); + if(r != null) { + if(result != null) + return null; + result = r; + } + } + return result; + } else { + Set found = objectsForTypeNonFunctional(graph, type, relation, new HashSet<>()); + return found.size() == 1 ? found.iterator().next() : null; + } + } + + private static Set objectsForTypeNonFunctional(ReadGraph graph, Resource type, Resource relation, Set found) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + found.addAll(graph.getObjects(type, relation)); + for(Resource su : graph.getObjects(L0.Inherits, type)) { + objectsForTypeNonFunctional(graph, su, relation, found); + } + return found; + } + public static Resource getPossiblePredicateByNameFromType(ReadGraph graph, Resource type, String name) throws DatabaseException { Map domain = getDomainOf(graph, type); return domain.get(name); diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphPropertyVariable.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphPropertyVariable.java index ed58556c7..7927614cd 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphPropertyVariable.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphPropertyVariable.java @@ -38,7 +38,7 @@ public class StandardGraphPropertyVariable extends AbstractPropertyVariable { private static final Logger LOGGER = LoggerFactory.getLogger(StandardGraphPropertyVariable.class); protected static final PropertyInfo NO_PROPERTY = new PropertyInfo(null, null, - false, Collections. emptySet(), null, null, null, null, null, null, + false, false, Collections. emptySet(), null, null, null, null, null, null, Collections.> emptyMap(), null, false); diff --git a/bundles/org.simantics.db.testing/META-INF/MANIFEST.MF b/bundles/org.simantics.db.testing/META-INF/MANIFEST.MF index c80729ad8..960ccf009 100644 --- a/bundles/org.simantics.db.testing/META-INF/MANIFEST.MF +++ b/bundles/org.simantics.db.testing/META-INF/MANIFEST.MF @@ -8,17 +8,18 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Require-Bundle: org.simantics.db.layer0;bundle-version="1.1.0", org.simantics.graph.db;bundle-version="1.1.5";visibility:=reexport, org.simantics.project;bundle-version="1.0.1";visibility:=reexport, - org.apache.log4j;bundle-version="1.2.15", org.simantics.db.procore;bundle-version="1.1.1", org.simantics.db.services;bundle-version="1.1.0", org.eclipse.core.runtime;bundle-version="3.6.0", org.simantics.workbench;bundle-version="1.1.0", org.simantics.db.management;bundle-version="1.1.0", + org.simantics.db.indexing;bundle-version="1.1.0", org.simantics;bundle-version="1.0.0";visibility:=reexport, org.simantics.scl.osgi;bundle-version="1.0.4", org.junit;bundle-version="4.12.0", org.simantics.db.server, - org.apache.commons.math3 + org.apache.commons.math3, + org.slf4j.api;bundle-version="1.7.25" Export-Package: org.simantics.db.testing.annotation, org.simantics.db.testing.base, org.simantics.db.testing.cases, diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/SCLScriptTestBase.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/SCLScriptTestBase.java index 26e916fc1..511af6dc3 100644 --- a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/SCLScriptTestBase.java +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/base/SCLScriptTestBase.java @@ -19,21 +19,24 @@ import org.simantics.scl.osgi.SCLOsgi; import org.simantics.scl.osgi.internal.Activator; import org.simantics.scl.osgi.internal.ServiceBasedModuleSourceRepository; import org.simantics.scl.osgi.internal.ServiceBasedTestRepository; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import gnu.trove.map.hash.THashMap; /** * Utilizies {@link TestRepository} for collecting SCL tests from bundles * - * @author Jani - * + * @author Jani Simomaa */ public class SCLScriptTestBase extends FreshDatabaseTest { + private static final Logger LOGGER = LoggerFactory.getLogger(SCLScriptTestBase.class); + private Map testRunnables = new THashMap(); - + @Rule public TestName testName = new TestName(); - + /** * Constructor that initially searches for all SCL test scripts and stores * them into a Map for later access @@ -47,14 +50,14 @@ public class SCLScriptTestBase extends FreshDatabaseTest { testRunnables.put(runnable.getName(), runnable); } } - + /** * Simplest method for running a SCL test */ protected void test() { test(-1); } - + /** * Executes a test case with given timeout as seconds. When time runs out one * can assume a deadlock has happened. The process is killed after the timeout @@ -65,7 +68,7 @@ public class SCLScriptTestBase extends FreshDatabaseTest { protected void test(int timeout) { testImpl(timeout); } - + /** * Executes a test case with given timeout as seconds * @@ -75,45 +78,57 @@ public class SCLScriptTestBase extends FreshDatabaseTest { SCLOsgi.SOURCE_REPOSITORY = new ServiceBasedModuleSourceRepository(Activator.getContext()); SCLOsgi.MODULE_REPOSITORY = new ModuleRepository(SCLOsgi.SOURCE_REPOSITORY); SCLOsgi.TEST_REPOSITORY = new ServiceBasedTestRepository(Activator.getContext()); - + String testName = resolveTestName(); TestRunnable runnable = testRunnables.get(testName); - + if (runnable == null) { + LOGGER.error("SCL Test Suite file (.sts) for test {} cannot be found from test repository.", testName); + return; + } + + long start = System.nanoTime(); if (timeout > -1) { + LOGGER.info("Running test {} with a timeout of {} seconds", testName, timeout); //$NON-NLS-1$ Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { + LOGGER.info("Watchdog will kill this test process because it has been executing for over {} seconds", timeout); //$NON-NLS-1$ String processName = ManagementFactory.getRuntimeMXBean().getName(); - System.out.println("PID: " + processName); + LOGGER.info("Test Process Name: {}", processName); //$NON-NLS-1$ String PID = processName.split("@")[0]; String command = "taskkill /F /PID " + PID; - System.out.println("Command: " + command); + LOGGER.info("Running command to kill test process: {}", command); //$NON-NLS-1$ try { Runtime.getRuntime().exec(command); } catch (IOException e) { - e.printStackTrace(); + LOGGER.error("Failed to kill process that ran over its execution time limit of {} seconds", timeout, e); } } }, timeout*1000); try { runnable.run(); + long end = System.nanoTime(); + LOGGER.info("Completed test {} execution in {} seconds", testName, String.format("%.3f", (end-start)*1e-9)); //$NON-NLS-1$ } catch (Exception e) { - e.printStackTrace(); + LOGGER.error("Failed to run test {} runnable {}", testName, runnable, e); } finally { timer.cancel(); } } else { + LOGGER.info("Running test {} without timeout", testName); //$NON-NLS-1$ try { runnable.run(); + long end = System.nanoTime(); + LOGGER.info("Completed test {} execution in {} seconds", testName, String.format("%.3f", (end-start)*1e-9)); //$NON-NLS-1$ } catch (Exception e) { - e.printStackTrace(); + LOGGER.error("Failed to run test {} runnable {}", testName, runnable, e); } } } - + /** * Resolves the full test name based on the names of classes that extends this * SCLScriptTestBase class.

diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/cases/FreshDatabaseTest.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/cases/FreshDatabaseTest.java index 963b2d9f5..9ad9faf77 100644 --- a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/cases/FreshDatabaseTest.java +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/cases/FreshDatabaseTest.java @@ -1,4 +1,3 @@ -package org.simantics.db.testing.cases; /******************************************************************************* * Copyright (c) 2007, 2010 Association for Decentralized Information Management * in Industry THTH ry. @@ -10,7 +9,7 @@ package org.simantics.db.testing.cases; * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ - +package org.simantics.db.testing.cases; import org.junit.After; import org.junit.Before; @@ -25,20 +24,15 @@ import org.simantics.db.testing.common.Tests; public class FreshDatabaseTest extends TestBase { public void configure(TestSettings settings) { - } @Before public void setUp() throws Exception { - TestBase.printStart(this); TestSettings testSettings = TestSettings.getInstanceUnsafe(); configure(testSettings); -// state = AcornTests.newSimanticsWorkspace(testSettings, null); state = Tests.newSimanticsWorkspace(testSettings, null); - super.setUp(); - } @After diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/cases/FreshWorkspaceTest.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/cases/FreshWorkspaceTest.java index 0de078564..bc4681550 100644 --- a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/cases/FreshWorkspaceTest.java +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/cases/FreshWorkspaceTest.java @@ -8,23 +8,22 @@ import org.simantics.db.testing.common.Tests; import org.simantics.db.testing.impl.Configuration; public class FreshWorkspaceTest extends TestBase { - + public void configure(TestSettings settins) { } - + @Before public void setUp() throws Exception { - TestBase.printStart(this); configure(TestSettings.getInstanceUnsafe()); state = Tests.freshWorkspace(Configuration.get().coreDir, initialWorkspaceFiles); super.setUp(); } - - @After - public void tearDown() throws Exception { - - Tests.shutdown(state); - super.tearDown(); - } + + @After + public void tearDown() throws Exception { + Tests.shutdown(state); + super.tearDown(); + } + } diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/AcornTestHandler.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/AcornTestHandler.java index 5f5da8f2e..e7e1722ac 100644 --- a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/AcornTestHandler.java +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/AcornTestHandler.java @@ -1,6 +1,7 @@ package org.simantics.db.testing.common; import java.io.File; +import java.io.IOException; import java.util.Properties; import org.eclipse.core.runtime.Platform; @@ -10,6 +11,7 @@ import org.simantics.db.Manager; import org.simantics.db.ServerI; import org.simantics.db.Session; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.indexing.DatabaseIndexing; /** * ProCore specific test handler. @@ -33,15 +35,27 @@ public class AcornTestHandler { void initNew() throws DatabaseException { Management m = getManagement(); - if (m.exist()) + if (m.exist()) { m.delete(); + } + deleteIndexes(); m.create(); } void initIfNeccessary() throws DatabaseException { Management m = getManagement(); - if (!m.exist()) + if (!m.exist()) { m.create(); + deleteIndexes(); + } + } + + private void deleteIndexes() throws DatabaseException { + try { + DatabaseIndexing.deleteAllIndexes(); + } catch (IOException e) { + throw new DatabaseException("Failed to delete all existing indexes", e); + } } public Session getSession() throws DatabaseException { diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/TestBase.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/TestBase.java index 1068fc2f5..d08caea4c 100644 --- a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/TestBase.java +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/TestBase.java @@ -27,7 +27,6 @@ import org.simantics.db.Session; import org.simantics.db.WriteGraph; import org.simantics.db.WriteOnlyGraph; import org.simantics.db.common.request.WriteOnlyRequest; -import org.simantics.db.common.utils.Logger; import org.simantics.db.exception.DatabaseException; import org.simantics.db.exception.ServiceNotFoundException; import org.simantics.db.management.SessionContext; @@ -38,14 +37,17 @@ import org.simantics.db.service.LifecycleSupport; import org.simantics.db.testing.impl.Configuration; import org.simantics.layer0.Layer0; import org.simantics.utils.FileUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** - * Base class for Simantics Test Cases. Assumes that ProCore is already running. + * Base class for Simantics Test Cases. + * Assumes that the Simantics database is already running. * * @author Marko Luukkainen - * */ -abstract public class TestBase /*extends TestCase*/ { +public abstract class TestBase { + private static final Logger LOGGER = LoggerFactory.getLogger(TestBase.class); public static final boolean DEBUG = Configuration.get().debug; public static final String ROOT_LIBRARY_URI = "http:/"; private NoExitSecurityManager noExitSecurityManager; @@ -56,7 +58,7 @@ abstract public class TestBase /*extends TestCase*/ { static boolean printStart = true; public static final ArrayList initialWorkspaceFiles = FileUtils.createFileFilter(Platform.getLocation().toFile(), null); public static void printStart(Object t) { - if(printStart) System.out.println("Test is " + t.getClass().getName() /*+ "." + t.getName()*/); + if(printStart) LOGGER.info("Test class is {}", t.getClass().getName()); } protected static void setPrintStart(boolean value) { printStart = value; @@ -270,9 +272,9 @@ abstract public class TestBase /*extends TestCase*/ { try { session.getService(LifecycleSupport.class).close(0, true); } catch (ServiceNotFoundException e) { - Logger.defaultLogError(e); + LOGGER.error("Failed to find LifecycleSupport service", e); } catch (DatabaseException e) { - Logger.defaultLogError(e); + LOGGER.error("Failed to close database", e); } } // if (!Thread.currentThread().equals(thread)) { diff --git a/bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/RouteGraph.java b/bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/RouteGraph.java index 62d3de68f..249399d0a 100644 --- a/bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/RouteGraph.java +++ b/bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/RouteGraph.java @@ -11,13 +11,9 @@ *******************************************************************************/ package org.simantics.diagram.connection; -import gnu.trove.list.array.TDoubleArrayList; -import gnu.trove.map.hash.THashMap; -import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; - import java.awt.geom.Line2D; import java.awt.geom.Path2D; +import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.io.PrintStream; import java.io.Serializable; @@ -34,6 +30,11 @@ import org.simantics.diagram.connection.rendering.arrows.PlainLineEndStyle; import org.simantics.diagram.connection.segments.Segment; import org.simantics.diagram.connection.splitting.SplittedRouteGraph; +import gnu.trove.list.array.TDoubleArrayList; +import gnu.trove.map.hash.THashMap; +import gnu.trove.map.hash.TObjectIntHashMap; +import gnu.trove.set.hash.THashSet; + public class RouteGraph implements Serializable { private static final long serialVersionUID = 2004022454972623908L; @@ -1474,6 +1475,46 @@ public class RouteGraph implements Serializable { routeLine.collectSegments(segments); return segments; } + + public Segment findNearestSegment(double x, double y) { + Segment nearest = null; + double minDistanceSq = Double.MAX_VALUE; + + for (Segment segment : getSegments()) { + RoutePoint p1 = segment.p1; + RoutePoint p2 = segment.p2; + + double distanceSq = Line2D.ptSegDistSq(p1.x, p1.y, p2.x, p2.y, x, y); + if (distanceSq < minDistanceSq) { + minDistanceSq = distanceSq; + nearest = segment; + } + } + return nearest; + } + + public Point2D findNearestPoint(double x, double y) { + Segment nearest = findNearestSegment(x, y); + if (nearest == null) return null; + + RoutePoint p1 = nearest.p1; + RoutePoint p2 = nearest.p2; + + double d = Math.pow(p2.x - p1.x, 2.0) + Math.pow(p2.y - p1.y, 2.0); + + if (d == 0) { + return new Point2D.Double(p1.x, p1.y); + } else { + double u = ((x - p1.x) * (p2.x - p1.x) + (y - p1.y) * (p2.y - p1.y)) / d; + if (u > 1.0) { + return new Point2D.Double(p2.x, p2.y); + } else if (u <= 0.0) { + return new Point2D.Double(p1.x, p1.y); + } else { + return new Point2D.Double(p2.x * u + p1.x * (1.0-u), (p2.y * u + p1.y * (1.0- u))); + } + } + } public Path2D getPath2D() { Path2D result = new Path2D.Double(); diff --git a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/base/PostEventCommand.java b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/base/PostEventCommand.java index 7214bdd1f..24b6e6111 100644 --- a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/base/PostEventCommand.java +++ b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/base/PostEventCommand.java @@ -13,6 +13,7 @@ package org.simantics.document.swt.core.base; import org.simantics.document.server.io.AbstractEventHandler; import org.simantics.document.server.io.CommandContext; +import org.simantics.document.server.io.CommandContextImpl; import org.simantics.document.server.io.CommandContextMutable; import org.simantics.document.swt.core.SWTDocument; @@ -27,6 +28,7 @@ public class PostEventCommand extends AbstractEventCommand { public PostEventCommand(SWTDocument document, AbstractEventHandler handler, CommandContextMutable context, PostEventCommand next) { super(document); + assert(handler != null); this.handler = handler; this.context = context; this.next = next; @@ -34,7 +36,9 @@ public class PostEventCommand extends AbstractEventCommand { @Override public CommandContext handleCommand(CommandContextMutable context) { - document.post(handler, context); + CommandContextMutable mergedContext = new CommandContextImpl().merge(context) + .merge(this.context); + document.post(handler, mergedContext); return context; } diff --git a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/ButtonWidget.java b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/ButtonWidget.java index 72c7c360b..88afe7b2a 100644 --- a/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/ButtonWidget.java +++ b/bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/widget/ButtonWidget.java @@ -75,6 +75,7 @@ public class ButtonWidget extends LeafWidgetManager