]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Merge changes I78c3a258,I7bf72f04
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 11 Sep 2019 21:41:46 +0000 (21:41 +0000)
committerGerrit Code Review <gerrit2@simantics>
Wed, 11 Sep 2019 21:41:46 +0000 (21:41 +0000)
* changes:
  Handle componentless parent nodes of UCs in synchronization
  Added logging for history archive import failure cases

23 files changed:
bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/EnumerationVariableModifier3.java
bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/GetEnumerationValue.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCache.java
bundles/org.simantics.desktop.product/splash.svg
bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/RouteGraph.java
bundles/org.simantics.issues.common/src/org/simantics/issues/common/AllActiveIssues.java
bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/handler/RunActiveValidations.java
bundles/org.simantics.modeling.ontology/graph/ModelingViewpoint.pgraph
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/ComponentTypeViewer.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/ComponentTypeViewerData.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagram/style/IssueDecorationStyle.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/OpenDiagramFromComponentAdapter.java
bundles/org.simantics.modeling/scl/Simantics/Simulation.scl
bundles/org.simantics.modeling/src/org/simantics/modeling/SCLScenegraph.java
bundles/org.simantics.modeling/src/org/simantics/modeling/rules/MappedModelingRules.java
bundles/org.simantics.modeling/src/org/simantics/modeling/userComponent/ComponentTypeCommands.java
bundles/org.simantics.scenegraph.profile/src/org/simantics/scenegraph/profile/common/ObserverGroupListener.java
bundles/org.simantics.scl.db/src/org/simantics/scl/db/SCLFunctions.java
bundles/org.simantics.selectionview/src/org/simantics/selectionview/function/All.java
features/org.simantics.sdk.feature/feature.xml
releng/org.simantics.sdk.build.targetdefinition/simantics.target
releng/org.simantics.sdk.build.targetdefinition/simantics.tpd
releng/org.simantics.sdk.repository/pom.xml

index 32bd28c17f789f1658a271a5e064807c4932f833..52b5012d72b504a3a1f64757dcc50fc66081a36b 100644 (file)
@@ -13,10 +13,12 @@ package org.simantics.browsing.ui.graph.impl;
 
 import java.util.List;
 
+import org.simantics.browsing.ui.common.modifiers.EnumerationValue;
 import org.simantics.browsing.ui.content.Labeler.EnumerationModifier;
 import org.simantics.databoard.Bindings;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.RequestProcessor;
+import org.simantics.db.Resource;
 import org.simantics.db.Session;
 import org.simantics.db.VirtualGraph;
 import org.simantics.db.WriteGraph;
@@ -53,6 +55,10 @@ public class EnumerationVariableModifier3 implements EnumerationModifier {
            return processor.syncRequest(new Read<String>() {
                 @Override
                 public String perform(ReadGraph graph) throws DatabaseException {
+                    EnumerationValue<Resource> ev = graph.syncRequest(new GetEnumerationValue(variable.getParent(graph).getRepresents(graph)));
+                    if(ev != null) {
+                        return ev.getEnumeratedValue().getName();
+                    }
           //           System.err.println(variable.getURI(graph));
                        return variable.getValue(graph);//variable.getPossiblePropertyValue(graph, Variables.LABEL);
                 }
index c246e7bd9091f5142014ccc37acf53d8250e0372..0f9d119aca3400a7cd6fbb32ff866514c0de50a8 100644 (file)
@@ -42,6 +42,14 @@ public class GetEnumerationValue extends ResourceRead<EnumerationValue<Resource>
         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);
+        if(label != null)
+            return label;
+        return safeName(graph, resource);
+    }
+
     public static EnumerationValue<Resource> enumerate(ReadGraph graph, Resource resource) throws DatabaseException {
         Layer0 l0 = Layer0.getInstance(graph);
         Set<Resource> types = graph.getTypes(resource);
@@ -61,7 +69,7 @@ public class GetEnumerationValue extends ResourceRead<EnumerationValue<Resource>
                     Collection<Resource> values = graph.getObjects(type, l0.ConsistsOf);
                     List<EnumeratedValue<Resource>> result = new ArrayList<EnumeratedValue<Resource>>(values.size());
                     for (Resource value : values) {
-                        result.add(new EnumeratedValue<Resource>(safeName(graph, value), value));
+                        result.add(new EnumeratedValue<Resource>(getEnumerationValueName(graph, value), value));
                     }
                     Enumeration<Resource> enumeration = new Enumeration<Resource>(result);
                     return new EnumerationValue<Resource>(enumeration, enumeration.find(resource));
index 06882a48943e711e502d725108ee2f0e4147f213..de942b90f8611c3fd01227c0acf6f7740e74dc4e 100644 (file)
@@ -19,7 +19,7 @@ import org.simantics.db.request.Read;
 
 public class QueryCache extends QueryCacheBase {
 
-    private static final boolean SINGLE = false;
+    private static final boolean SINGLE = true;
 
     public QueryCache(QuerySupport querySupport, int threads) {
         super(querySupport, threads);
index ff75c9a67b96167f0f1bf6a0a356698d25b71547..5a0d20984c06a44a2577b8037269a2aa4007c7c5 100644 (file)
          id="tspan6235"
          x="4.0821486"
          y="291.79337"
-         style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:5.64444447px;font-family:'The Real Font';-inkscape-font-specification:'The Real Font';fill:#ffffff;fill-opacity:1;stroke-width:0.26458335px">1.40.0</tspan></text>
+         style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:5.64444447px;font-family:'The Real Font';-inkscape-font-specification:'The Real Font';fill:#ffffff;fill-opacity:1;stroke-width:0.26458335px">1.41.0</tspan></text>
     <circle
        style="opacity:0.92900002;fill:#5d6b91;fill-opacity:1;stroke:none;stroke-width:1.27400005;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;filter:url(#filter6809)"
        id="path6231"
index 62d3de68fae5f110a6b08eb80dcc7558ca34df80..249399d0a8b5b7b6c875c68d8464fda198961160 100644 (file)
  *******************************************************************************/
 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();
index 006e779d47cb105311e11bf66906ca2c1c4de85a..1bb292851111226453f0e0a3f187d6893a570e60 100644 (file)
@@ -47,7 +47,7 @@ public class AllActiveIssues extends ResourceRead<Set<Resource>> {
             result.addAll(graph.syncRequest(new AllModelIssues(model, false)));
         }
 
-        List<Resource> libraries = SCLFunctions.evaluateDB("Simantics/SharedOntologies", "getSharedOntologies", Tuple0.INSTANCE); 
+        List<Resource> libraries = SCLFunctions.evaluateGraph("Simantics/SharedOntologies", "getSharedOntologies", graph, Tuple0.INSTANCE); 
 
         for (Resource library : libraries) {
             result.addAll(graph.syncRequest(new AllModelIssues(library, false)));
index efdba04d0ee07fecb12bbb814628989ef6ec434e..f6121ce19ec6179d824a98ffed7a5493cf4a2a3e 100644 (file)
@@ -69,7 +69,7 @@ public class RunActiveValidations extends AbstractHandler {
     public static void run() throws DatabaseException {
         Resource model = Simantics.getSession().syncRequest(new PossibleActiveModel(Simantics.getProjectResource()));
         if(model != null)
-            run(null);
+            run(model);
     }
 
     public static void run(Resource model) {
index 98b7aa98120c69217aba16c8a9cf709a98bccbf0..b97753e5fc5c920061de1be78cd1f8b7adde20d9 100644 (file)
@@ -457,6 +457,13 @@ MOD.Contributions.ActivateModel : VP.ActionContribution
     VP.ActionContribution.HasNodeType SIMU.Model
     VP.ActionContribution.HasAction ACTIONS.ActivateModel
 
+MOD.Contributions.ActivateExperiment : VP.ActionContribution
+    L0.HasLabel "Activate"
+    VP.ActionContribution.HasImage SILK.bullet_go
+    VP.ActionContribution.HasCategory VP.EditActionCategory
+    VP.ActionContribution.HasNodeType SIMU.Experiment
+    VP.ActionContribution.HasAction ACTIONS.ActivateExperiment
+
 MOD.Contributions.Help : VP.ActionContribution
     L0.HasLabel "Help"
     VP.ActionContribution.HasImage SILK.help
@@ -727,6 +734,8 @@ ACTIONS.NewSheetBook
   @MOD.sclAction "createSpreadsheetBookAction"
 ACTIONS.ActivateModel
   @MOD.sclAction "activateModelAction"
+ACTIONS.ActivateExperiment
+  @MOD.sclAction "activateExperimentAction"
 ACTIONS.MigrateComponentType : ACT.Action
 ACTIONS.CompilePGraphs : ACT.Action
 //ACTIONS.MigrateMasterTypical : ACT.Action
index 75c60d24cd28d27190c382fba285def14f1f46a6..38f24b4f7ddb53d8d7b6b3dafc84403c35042533 100644 (file)
@@ -34,6 +34,7 @@ import org.osgi.framework.BundleContext;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
 import org.simantics.Simantics;
+import org.simantics.browsing.ui.graph.impl.GetEnumerationValue;
 import org.simantics.databoard.Bindings;
 import org.simantics.databoard.binding.Binding;
 import org.simantics.databoard.binding.error.BindingException;
@@ -42,6 +43,7 @@ import org.simantics.databoard.type.NumberType;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.common.NamedResource;
+import org.simantics.db.common.request.IsEnumeratedValue;
 import org.simantics.db.common.request.UniqueRead;
 import org.simantics.db.common.utils.NameUtils;
 import org.simantics.db.exception.DatabaseException;
@@ -201,6 +203,8 @@ public class ComponentTypeViewer {
                                 expression = graph.getPossibleRelatedValue(assertion, L0.SCLValue_expression, Bindings.STRING);
                                 if(expression != null) {
                                        defaultValue = "=" + expression; //$NON-NLS-1$
+                                } else if (graph.sync(new IsEnumeratedValue(assertion))) {
+                                    defaultValue = GetEnumerationValue.getEnumerationValueName(graph, assertion);
                                 } else {
                                        Datatype dt = getPossibleDatatype(graph, assertion);
                                        if (dt == null)
index ea10d6d8d4e44d700cf6cc789b97ca49ed9e6e6c..01c799d45832b824835b1a477c20c3ecd3dfce16 100644 (file)
@@ -1,8 +1,11 @@
 package org.simantics.modeling.ui.componentTypeEditor;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
 import java.util.regex.Matcher;
@@ -33,6 +36,7 @@ import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.forms.widgets.Form;
 import org.eclipse.ui.forms.widgets.FormToolkit;
 import org.simantics.Simantics;
+import org.simantics.databoard.Bindings;
 import org.simantics.databoard.type.NumberType;
 import org.simantics.databoard.units.internal.library.UnitLibrary;
 import org.simantics.databoard.util.Limit;
@@ -40,15 +44,20 @@ import org.simantics.databoard.util.Range;
 import org.simantics.databoard.util.RangeException;
 import org.simantics.db.RequestProcessor;
 import org.simantics.db.Resource;
+import org.simantics.db.Statement;
 import org.simantics.db.WriteGraph;
 import org.simantics.db.common.NamedResource;
+import org.simantics.db.common.request.IndexRoot;
 import org.simantics.db.common.request.WriteRequest;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.function.DbConsumer;
+import org.simantics.db.layer0.QueryIndexUtils;
+import org.simantics.db.layer0.util.Layer0Utils;
 import org.simantics.layer0.Layer0;
 import org.simantics.modeling.userComponent.ComponentTypeCommands;
 import org.simantics.scl.runtime.function.Function2;
 import org.simantics.scl.runtime.function.Function4;
+import org.simantics.utils.datastructures.Pair;
 import org.simantics.utils.threads.ThreadUtils;
 import org.simantics.utils.ui.ErrorLogger;
 
@@ -246,12 +255,47 @@ public class ComponentTypeViewerData {
                 if (propertyInfo.immutable)
                     return;
 
+                
                 Simantics.getSession().async(new WriteRequest() {
                     @Override
                     public void perform(WriteGraph graph)
                             throws DatabaseException {
                         graph.markUndoPoint();
-                        ComponentTypeCommands.editType(graph, componentType, propertyInfo.resource, convertDefaultValue, newValue);
+
+                        String newValue2 = newValue;
+
+                        Resource possibleGraphType = null;
+                        Resource root = graph.syncRequest(new IndexRoot(componentType));
+
+                        Resource L0Res = graph.getResource("http://www.simantics.org/Layer0-1.1");
+                        Layer0 L0 = Layer0.getInstance(graph);
+
+                        Collection<Resource> graphTypes1 = QueryIndexUtils.searchByTypeAndName(graph, L0Res, L0.ValueType, newValue);
+                        Collection<Resource> graphTypes2 = QueryIndexUtils.searchByTypeAndName(graph, root, L0.ValueType, newValue);
+
+                        Collection<Resource> graphTypes = new HashSet<>(graphTypes1);
+                        graphTypes.addAll(graphTypes2);
+
+                        Set<Pair<Resource, String>> candidates = new HashSet<>();
+                        for (Resource graphType : graphTypes) {
+                            Collection<Statement> stms = graph.getAssertedStatements(graphType, L0.HasValueType);
+                            if(stms.size() == 1) {
+                                // Only accept valueType if it asserts HasValueType with the same name
+                                String hasValueType = graph.getValue(stms.iterator().next().getObject(), Bindings.STRING);
+                                if (hasValueType.equals(newValue)) {
+                                    candidates.add(new Pair<>(graphType, hasValueType));
+                                }
+                            }
+                        }
+
+                        // We support only graph types with unique name at this point. Later we could implement UI to let the user to select from multiple graph types.
+                        if (candidates.size() == 1) {
+                            Pair<Resource, String> result = candidates.iterator().next();
+                            possibleGraphType = result.first;
+                            newValue2 = result.second;
+                        }
+
+                        ComponentTypeCommands.editType(graph, componentType, propertyInfo.resource, convertDefaultValue, newValue2, possibleGraphType);
                         if (range != null) ComponentTypeCommands.setRange(graph, componentType, propertyInfo.resource, range);
                     }
                 });
index d473ff46df044a4db03b1bb694fb23e5bbf3ca3c..68210f9e263f5c48e51eb10bbbc30f0324b85244 100644 (file)
 package org.simantics.modeling.ui.diagram.style;
 
 import java.awt.geom.AffineTransform;
+import java.awt.geom.Point2D;
 import java.awt.geom.Rectangle2D;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -25,9 +28,13 @@ import org.simantics.db.common.procedure.adapter.TransientCacheListener;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.variable.Variable;
 import org.simantics.db.layer0.variable.Variables;
+import org.simantics.diagram.connection.RouteGraph;
 import org.simantics.diagram.elements.DecorationSVGNode;
 import org.simantics.diagram.elements.SVGNode;
+import org.simantics.diagram.handler.Paster;
+import org.simantics.diagram.handler.Paster.RouteLine;
 import org.simantics.diagram.profile.StyleBase;
+import org.simantics.diagram.stubs.DiagramResource;
 import org.simantics.diagram.synchronization.graph.DiagramGraphUtil;
 import org.simantics.issues.Severity;
 import org.simantics.issues.common.IssueResourcesContexts;
@@ -36,10 +43,13 @@ import org.simantics.modeling.ModelingResources;
 import org.simantics.modeling.ui.Activator;
 import org.simantics.modeling.ui.diagram.style.IssueDecorationStyle.IssueResult;
 import org.simantics.scenegraph.INode;
+import org.simantics.scenegraph.g2d.nodes.ConnectionNode;
 import org.simantics.scenegraph.g2d.nodes.Decoration;
+import org.simantics.scenegraph.g2d.nodes.connection.RouteGraphNode;
 import org.simantics.scenegraph.profile.EvaluationContext;
 import org.simantics.scenegraph.profile.common.ProfileVariables;
 import org.simantics.scenegraph.utils.NodeUtil;
+import org.simantics.structural.stubs.StructuralResource2;
 import org.simantics.utils.datastructures.map.Tuple;
 
 
@@ -74,7 +84,6 @@ public class IssueDecorationStyle extends StyleBase<IssueResult> {
             return null;
 
         List<Resource> contexts = getContexts(graph, element);
-        AffineTransform transform = DiagramGraphUtil.getAffineTransform(graph, element);
         Map<Severity, List<Resource>> issuesBySeverity = graph.syncRequest(new ListModelIssuesBySeverity(model, true, true, Severity.NOTE),
                 TransientCacheListener.<Map<Severity, List<Resource>>>instance());
 
@@ -82,14 +91,43 @@ public class IssueDecorationStyle extends StyleBase<IssueResult> {
             List<Resource> issues = issuesBySeverity.get(severity);
             if (issues != null) {
                 Set<Resource> issueContexts = graph.syncRequest(new IssueResourcesContexts(issues));
-                if (!Collections.disjoint(issueContexts, contexts))
-                    return new IssueResult(severity, transform);
+                if (!Collections.disjoint(issueContexts, contexts)) {
+                    return new IssueResult(severity, getIdentifier(graph, runtimeDiagram, element));
+                }
             }
         }
 
         return null;
     }
 
+    private static Object getIdentifier(ReadGraph graph, Resource runtimeDiagram, Resource element) throws DatabaseException {
+        DiagramResource DIA = DiagramResource.getInstance(graph);
+        StructuralResource2 STR = StructuralResource2.getInstance(graph);
+        if (graph.isInstanceOf(element, DIA.RouteGraphConnection)) {
+            Collection<Resource> connectors = graph.getObjects(element, DIA.HasConnector);
+            Collection<Resource> routeNodes = graph.getObjects(element, DIA.HasInteriorRouteNode);
+
+            // This is needed to make this query result change every time the underlying element changes visually.
+            Set<Object> identifier = new HashSet<Object>(connectors.size() + routeNodes.size());
+
+            for (Resource connector : connectors) {
+                for (Resource connectedTo : graph.getObjects(connector, STR.Connects)) {
+                    if (!connectedTo.equals(element)) {
+                        AffineTransform at = DiagramGraphUtil.getDynamicAffineTransform(graph, runtimeDiagram, connectedTo, DIA.HasDynamicTransform, false);
+                        identifier.add(at);
+                    }
+                }
+            }
+            for (Resource routeLine : routeNodes) {
+                RouteLine rl = Paster.readRouteLine(graph, routeLine);
+                identifier.add(rl);
+            }
+            return identifier;
+        } else {
+            return DiagramGraphUtil.getAffineTransform(graph, element);
+        }
+    }
+
     @Override
     public void applyStyleForNode(EvaluationContext observer, INode node, IssueResult result) {
         if (result == null) {
@@ -117,6 +155,18 @@ public class IssueDecorationStyle extends StyleBase<IssueResult> {
     protected AffineTransform getDecorationPosition(INode node) {
        Rectangle2D bounds = NodeUtil.getLocalBounds(node, Decoration.class);
 
+        if (node instanceof ConnectionNode) {
+            for (INode child : ((ConnectionNode)node).getSortedNodes()) {
+                if (child instanceof RouteGraphNode) {
+                    RouteGraphNode rgn = (RouteGraphNode) child;
+                    RouteGraph rg = rgn.getRouteGraph();
+                    Point2D nearest = rg.findNearestPoint(bounds.getCenterX(), bounds.getCenterY());
+                    if (nearest != null) {
+                        return AffineTransform.getTranslateInstance(nearest.getX(), nearest.getY());
+                    }
+                }
+            }
+        }
         double tx = bounds.getX();
         double ty = bounds.getY();
         return AffineTransform.getTranslateInstance(tx, ty);
@@ -148,8 +198,8 @@ public class IssueDecorationStyle extends StyleBase<IssueResult> {
      * element moves.
      */
     public static class IssueResult extends Tuple {
-        public IssueResult(Severity severity, AffineTransform transform) {
-            super(severity, transform);
+        public IssueResult(Severity severity, Object identifier) {
+            super(severity, identifier);
         }
         public Severity getSeverity() {
             return (Severity) getField(0);
index d5071303e4924b22a3f812f05b312141d03a5ed1..6be9f72f92d2939dfafefb7284a36ca2d9d0d87e 100644 (file)
@@ -63,6 +63,15 @@ public class OpenDiagramFromComponentAdapter extends AbstractResourceEditorAdapt
         super(Messages.OpenDiagramFromComponentAdapter_OpenDiagramContainingComponent, Activator.SYMBOL_ICON);
     }
 
+    protected String getEditorId(ReadGraph g, Resource diagram) throws DatabaseException {
+        ModelingResources MOD = ModelingResources.getInstance(g);
+        String preferredEditorId = g.getPossibleRelatedValue(diagram, MOD.PreferredDiagramEditorID);
+        if(preferredEditorId != null)
+            return preferredEditorId;
+        else
+            return EDITOR_ID;
+    }
+
     @Override
     public boolean canHandle(ReadGraph graph, Object input) throws DatabaseException {
         Pair<Resource, String> p = tryGetResource(graph, input);
@@ -153,6 +162,8 @@ public class OpenDiagramFromComponentAdapter extends AbstractResourceEditorAdapt
             Resource composite = g.getSingleObject(component, l0.PartOf);
             Resource diagram = ComponentUtils.getPossibleCompositeDiagram(g, composite);
 
+            String editorId = getEditorId(g, composite);
+
             if (LOGGER.isDebugEnabled()) {
                 LOGGER.debug(getClass().getSimpleName() + ".findDiagram: component: " + NameUtils.getURIOrSafeNameInternal(g, component)); //$NON-NLS-1$
                 LOGGER.debug(getClass().getSimpleName() + ".findDiagram: composite: " + NameUtils.getURIOrSafeNameInternal(g, composite)); //$NON-NLS-1$
@@ -213,7 +224,7 @@ public class OpenDiagramFromComponentAdapter extends AbstractResourceEditorAdapt
                 // Prevent diagram from opening if there's nothing to select
                 // on the diagram based on the received input.
                 if (!selectedObjects.isEmpty())
-                    result.add( NavigateToTarget.editorActivator(EDITOR_ID, diagram, indexRoot, rvi, editorActivationCallback(selectedObjects)) );
+                    result.add( NavigateToTarget.editorActivator(editorId, diagram, indexRoot, rvi, editorActivationCallback(selectedObjects)) );
             } else {
                 final MapSet<NamedResource, Resource> referencingDiagrams = listReferenceDiagrams(g, referenceElements);
                 final Set<NamedResource> diagrams = referencingDiagrams.getKeys();
@@ -238,7 +249,7 @@ public class OpenDiagramFromComponentAdapter extends AbstractResourceEditorAdapt
                     RVI rvi = getDiagramCompositeRvi(g, singleDiagram.getResource());
                     if (rvi != null) {
                         Collection<Resource> selectedObjects = referencingDiagrams.getValues(singleDiagram);
-                        result.add( NavigateToTarget.editorActivator(EDITOR_ID, singleDiagram.getResource(), indexRoot, rvi, editorActivationCallback(selectedObjects)) );
+                        result.add( NavigateToTarget.editorActivator(editorId, singleDiagram.getResource(), indexRoot, rvi, editorActivationCallback(selectedObjects)) );
                     }
                     break;
 
@@ -254,7 +265,7 @@ public class OpenDiagramFromComponentAdapter extends AbstractResourceEditorAdapt
                         if (selected != null) {
                             Collection<Resource> selectedObjects = referencingDiagrams.getValues(selected);
                             RVI drvi = diagramToRvi.get(selected);
-                            NavigateToTarget.editorActivator(EDITOR_ID, selected.getResource(), indexRoot, drvi, editorActivationCallback(selectedObjects)).run();
+                            NavigateToTarget.editorActivator(editorId, selected.getResource(), indexRoot, drvi, editorActivationCallback(selectedObjects)).run();
                         }
                     });
                     break;
index 2a721ee21d69f873b024b9506466f262d64490d5..e61b161ad18b2b54186a17498379228d2a274b38 100644 (file)
@@ -13,6 +13,11 @@ importJava "org.simantics.simulation.experiment.ExperimentUtil" where
     createExperimentRun :: Resource -> <WriteGraph> Resource
     createExperimentRunWithType :: Resource -> Resource -> <WriteGraph> Resource
     activateRun :: Resource -> <WriteGraph> ()
+
+activateExperimentAction :: Resource -> <Proc> ()
+activateExperimentAction experiment = do
+  syncWrite (\() -> activateExperiment experiment)
+  ()
     
 importJava "org.simantics.simulation.experiment.IExperiment" where
     data IExperiment
index 40a5265852fa79083df1781db24a563df95d4532..fad803ce41a4a84bdb11991a06f73e0bdc3a3451 100644 (file)
@@ -85,6 +85,7 @@ import org.slf4j.LoggerFactory;
 import org.w3c.dom.DOMImplementation;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
+import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
 public class SCLScenegraph {
@@ -916,10 +917,21 @@ public class SCLScenegraph {
             } else if (!(node instanceof RouteGraphNode) && !(node instanceof LinkNode)){
                try {
                        Element doc = renderSVGNode(svgGenerator, (IG2DNode)node);
-                       if (doc.getElementsByTagName("g").getLength() == 0)
+                       NodeList gList = doc.getElementsByTagName("g");
+                       if (gList.getLength() == 0)
                                return;
+                       boolean hasContent = false;
+                       for (int i = 0; i < gList.getLength(); i++) {
+                           Node gNode = gList.item(i);
+                           if (gNode.hasChildNodes()) {
+                               hasContent = true;
+                               break;
+                           }
+                       }
+                       if (!hasContent)
+                           return;
                        String svg = printSVGDocument(doc);
-                       parentBuilder.append(MAIN_SECTION, "<g>");
+                       parentBuilder.append(MAIN_SECTION, "<g class=\"" +node.getSimpleClassName() +"\">");
                        parentBuilder.append(MAIN_SECTION, svg);
                        parentBuilder.append(MAIN_SECTION, "\n</g>");
                } catch (Exception e) {
index 21a435f4ab134aa26d920d93241e113badce0487..99e8648615ec04225d7a8f0805dd29030173829e 100644 (file)
@@ -158,7 +158,7 @@ public class MappedModelingRules extends AbstractModelingRules {
                             // This is a lifted flag in a structural configuration.
                             mappedConnectionPoints.add(new CPTerminal(terminal.component, isLiftedAs));
                         } else {
-                            // Do nothing, because the flag is not connected
+                            mappedConnectionPoints.add(terminal);
                         }
                     }
                 } else if (cp instanceof CPConnection) {
index 74ae599e3797f6a06d9c07f2c9ed6bc7d4789843..9cf93fac5ce83d9067b99d7ebbb7e0da6a272f63 100644 (file)
@@ -11,6 +11,7 @@
  *******************************************************************************/
 package org.simantics.modeling.userComponent;
 
+import java.util.Collections;
 import java.util.Map;
 
 import org.simantics.databoard.Bindings;
@@ -27,11 +28,13 @@ import org.simantics.db.Resource;
 import org.simantics.db.Statement;
 import org.simantics.db.WriteGraph;
 import org.simantics.db.common.CommentMetadata;
+import org.simantics.db.common.request.EnumerationMap;
+import org.simantics.db.common.request.IsEnumeratedValue;
 import org.simantics.db.common.request.UnaryRead;
 import org.simantics.db.common.utils.NameUtils;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.exception.ServiceException;
-import org.simantics.db.layer0.request.ModelInstances;
+import org.simantics.db.layer0.QueryIndexUtils;
 import org.simantics.db.layer0.util.Layer0Utils;
 import org.simantics.layer0.Layer0;
 import org.simantics.modeling.ModelingResources;
@@ -42,6 +45,7 @@ import org.simantics.scl.runtime.tuple.Tuple3;
 import org.simantics.selectionview.SelectionViewResources;
 import org.simantics.structural.stubs.StructuralResource2;
 import org.simantics.structural2.utils.StructuralUtils;
+import org.simantics.utils.strings.AlphanumComparator;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -199,6 +203,11 @@ public class ComponentTypeCommands {
 
     public static void setRequiredType(WriteGraph g, Resource componentType, Resource property,
             String requiredType) throws DatabaseException {
+        setRequiredType(g, componentType, property, requiredType, null);
+    }
+
+    public static void setRequiredType(WriteGraph g, Resource componentType, Resource property,
+            String requiredType, Resource possibleType) throws DatabaseException {
         Layer0 L0 = Layer0.getInstance(g);
         g.claimLiteral(property, L0.RequiresValueType, requiredType);
 
@@ -211,17 +220,34 @@ public class ComponentTypeCommands {
             }
         }
 
+        // We assert the range of the property only if we are given a dedicated graph value type
+        if(g.hasStatement(property, L0.HasRange))
+            g.deny(property, L0.HasRange);
+
+        if(possibleType != null) {
+            // We have a dedicated graph type for this SCL value type
+            if(g.hasStatement(possibleType, L0.Enumeration)) {
+                // This value type is an enumeration - let's constrain the range of this predicate to match the enumeration type only
+                g.claim(property, L0.HasRange, possibleType);
+            }
+        }
+
         CommentMetadata cm = g.getMetadata(CommentMetadata.class);
         g.addMetadata(cm.add("Set required type "+ requiredType + " for component/annotation " + property));
     }
     
     public static void editType(WriteGraph graph, Resource componentType, Resource property, boolean convertDefaultValue, String newValue) throws DatabaseException {
-        ComponentTypeCommands.setRequiredType(graph, componentType, property, newValue);
+        editType(graph, componentType, property, convertDefaultValue, newValue, null);
+    }
+
+    public static void editType(WriteGraph graph, Resource componentType, Resource property, boolean convertDefaultValue, String newValue, Resource possibleType) throws DatabaseException {
+        ComponentTypeCommands.setRequiredType(graph, componentType, property, newValue, possibleType);
         if (convertDefaultValue) {
-            ComponentTypeCommands.convertDefaultValue(graph, componentType, property, newValue);
-            Map<String, Resource> instances = graph.sync(new ModelInstances(componentType, componentType));
-            for(Resource instance : instances.values()) {
-                ComponentTypeCommands.convertInstantiatedValue(graph, instance, property, newValue);
+            ComponentTypeCommands.convertDefaultValue(graph, componentType, property, newValue, possibleType);
+            for (Resource indexRoot : Layer0Utils.listIndexRoots(graph)) {
+                for(Resource instance : QueryIndexUtils.searchByTypeShallow(graph, indexRoot, componentType)) {
+                    ComponentTypeCommands.convertInstantiatedValue(graph, instance, property, newValue, componentType);
+                }
             }
         }
     }
@@ -270,11 +296,29 @@ public class ComponentTypeCommands {
                     " in " + NameUtils.getSafeName(g, type) + ".");
             return;
         }
+
+        Layer0 L0 = Layer0.getInstance(g);
+        Resource range = g.getPossibleObject(relation, L0.HasRange);
+        if (range != null) {
+            if(g.hasStatement(range, L0.Enumeration)) {
+                Map<String,Resource> values = g.syncRequest(new EnumerationMap(range));
+                Resource value = values.get(valueText);
+                if (value != null) {
+                    for(Resource assertion : g.getObjects(type, L0.Asserts)) {
+                        Resource p = g.getSingleObject(assertion, L0.HasPredicate);
+                        if (p.equals(relation)) {
+                            g.deny(assertion, L0.HasObject, object);
+                            g.claim(assertion, L0.HasObject, value);
+                        }
+                    }
+                }
+                return;
+            }
+        }
         
         if(valueText.length() > 0 && valueText.charAt(0) == '=') {
                
                String expression = valueText.substring(1);
-               Layer0 L0 = Layer0.getInstance(g);
                ModelingResources MOD = ModelingResources.getInstance(g);
                if(!g.isInstanceOf(object, MOD.SCLValue)) {
                        Resource assertion = g.getSingleObject(object, L0.HasObjectInverse);
@@ -288,7 +332,6 @@ public class ComponentTypeCommands {
             
         } else {
                
-               Layer0 L0 = Layer0.getInstance(g);
                ModelingResources MOD = ModelingResources.getInstance(g);
                if(g.isInstanceOf(object, MOD.SCLValue)) {
                        Resource assertion = g.getSingleObject(object, L0.HasObjectInverse);
@@ -421,6 +464,22 @@ public class ComponentTypeCommands {
 
     public static void convertDefaultValue(WriteGraph g,
             Resource type, Resource relation, String newSCLType) throws DatabaseException {
+        convertDefaultValue(g, type, relation, newSCLType, null);
+    }
+
+    private static Resource findAssertionWithPO(ReadGraph graph, Resource possibleType, Resource predicate, Resource object) throws DatabaseException {
+           Layer0 L0 = Layer0.getInstance(graph);
+        for(Resource assertion : graph.getObjects(possibleType, L0.Asserts)) {
+            Resource p = graph.getSingleObject(assertion, L0.HasPredicate);
+            Resource o = graph.getSingleObject(assertion, L0.HasObject);
+            if(predicate.equals(p) && object.equals(o))
+                return assertion;
+        }
+        return null;
+    }
+
+    public static void convertDefaultValue(WriteGraph g,
+            Resource type, Resource relation, String newSCLType, Resource possibleType) throws DatabaseException {
         Resource object = getAssertedObject(g, type, relation);
         if(object == null) {
             LOGGER.warn("Didn't find assertion for " + NameUtils.getSafeName(g, relation) + 
@@ -428,27 +487,72 @@ public class ComponentTypeCommands {
             return;
         }
 
+        Layer0 L0 = Layer0.getInstance(g);
+        if(possibleType != null) {
+            if(g.hasStatement(possibleType, L0.Enumeration)) {
+                if(!g.isInstanceOf(object, possibleType)) {
+                    Map<String, Resource> enumMap = g.syncRequest(new EnumerationMap(possibleType));
+                    String firstKey = Collections.min(enumMap.keySet(), AlphanumComparator.COMPARATOR);
+                    Resource defaultValue = enumMap.get(firstKey);
+
+                    if (defaultValue != null) {
+                        Resource assertion = findAssertionWithPO(g, type, relation, object);
+                        if(assertion != null) {
+                            g.deny(assertion, L0.HasObject);
+                            g.claim(assertion, L0.HasObject, defaultValue);
+                            return;
+                        } else {
+                            Layer0Utils.assert_(g, type, relation, defaultValue);
+                            return;
+                        }
+                    }
+                } else {
+                       return;
+                }
+            }
+        }
+
         Tuple tuple = getDatatypeValueAndBinding(g, object, newSCLType);
         if (tuple == null)
             return;
 
-        Layer0 L0 = Layer0.getInstance(g);
+        if(g.sync(new IsEnumeratedValue(object))) {
+            Resource assertion = findAssertionWithPO(g, type, relation, object);
+            object = g.newResource();
+            g.claim(object, L0.InstanceOf, L0.Literal);
+            if(assertion != null) {
+                g.deny(assertion, L0.HasObject);
+                g.claim(assertion, L0.HasObject, object);
+            }
+        }
+
         g.claimLiteral(object, L0.HasDataType, L0.DataType, tuple.get(0), Bindings.getBindingUnchecked(Datatype.class));
         g.claimLiteral(object, L0.HasValueType, g.<String>getRelatedValue(relation, L0.RequiresValueType, Bindings.STRING), Bindings.STRING);
         g.claimValue(object, tuple.get(1), (Binding)tuple.get(2));
 
     }
 
-    public static void convertInstantiatedValue(WriteGraph g, Resource instance, Resource relation, String newSCLType)
+    public static void convertInstantiatedValue(WriteGraph g, Resource instance, Resource relation, String newSCLType) throws DatabaseException {
+       convertInstantiatedValue(g, instance, relation, newSCLType, null);
+    }
+
+    public static void convertInstantiatedValue(WriteGraph g, Resource instance, Resource relation, String newSCLType, Resource possibleType)
             throws DatabaseException {
 
         Statement stm = g.getPossibleStatement(instance, relation);
         if(stm != null && !stm.isAsserted(instance)) {
 
+            Layer0 L0 = Layer0.getInstance(g);
             Resource object = stm.getObject();
 
+            if(g.sync(new IsEnumeratedValue(object))) {
+                if(!g.isInstanceOf(object, possibleType)) {
+                    g.deny(instance, relation);
+                }
+                return;
+            }
+
             // We can only convert literals
-            Layer0 L0 = Layer0.getInstance(g);
             if(!g.isInstanceOf(object, L0.Literal)) return;
 
             Tuple tuple = getDatatypeValueAndBinding(g, object, newSCLType);
index 497b401a2a1d502ce00e352fe1301cef66c244ae..31295b9b692f60178c422ad7dda719089d87b76c 100644 (file)
@@ -66,7 +66,7 @@ public class ObserverGroupListener implements SetListener<Resource> {
             return true;
         else if (object == null)
             return false;
-        else if (ObserverGroupListener.class != object.getClass())
+        else if (getClass() != object.getClass())
             return false;
         ObserverGroupListener other = (ObserverGroupListener)object;
         return observer.equals(other.observer) && group.equals(other.group) && style.equals(other.style);
index d8f83e05f5b2f231bc5dcd14bf27bf93ff85ffdc..09022d543c1aba3e9101028c88ed939b72759963 100644 (file)
@@ -123,7 +123,7 @@ public class SCLFunctions {
     }
 
     private static <T> T evaluate(RuntimeModule rm, String function, Object ... args) throws ValueNotFound {
-        return evaluate(resolveFunction(rm, function));
+        return evaluate(resolveFunction(rm, function), args);
     }
 
     public static <T> T evaluate(String module, String function, Object ... args) throws ValueNotFound {
@@ -151,7 +151,7 @@ public class SCLFunctions {
         }
     }
     
-    public static <T> T evaluateGraph(String module, String function, Object graph, Object ... args) throws DatabaseException {
+    public static <T> T evaluateGraph(String module, String function, ReadGraph graph, Object ... args) throws DatabaseException {
         final SCLContext context = SCLContext.getCurrent();
         SCLContext.push(context);
         Object oldGraph = context.put(GRAPH, graph);
@@ -163,7 +163,7 @@ public class SCLFunctions {
         }
     }
 
-    public static void runWithGraph(Object graph, Runnable r) {
+    public static void runWithGraph(ReadGraph graph, Runnable r) {
         final SCLContext context = SCLContext.getCurrent();
         SCLContext.push(context);
         Object oldGraph = context.put(GRAPH, graph);
index 79541b06134deb344a5f6f71c4dda854edcfc145..d26d86682874a15e61551de5cfcd66907ec975b4 100644 (file)
@@ -2,6 +2,7 @@ package org.simantics.selectionview.function;
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Map;
 import java.util.function.Consumer;
 
@@ -13,6 +14,7 @@ import org.eclipse.swt.widgets.FontDialog;
 import org.simantics.Simantics;
 import org.simantics.browsing.ui.NodeContext;
 import org.simantics.browsing.ui.content.Labeler.DialogModifier;
+import org.simantics.browsing.ui.graph.impl.GetEnumerationValue;
 import org.simantics.common.format.Formatter;
 import org.simantics.databoard.Bindings;
 import org.simantics.databoard.Datatypes;
@@ -62,6 +64,7 @@ import org.simantics.ui.fonts.Fonts;
 import org.simantics.ui.selection.WorkbenchSelectionElement;
 import org.simantics.ui.selection.WorkbenchSelectionUtils;
 import org.simantics.utils.datastructures.collections.CollectionUtils;
+import org.simantics.utils.strings.AlphanumComparator;
 import org.simantics.utils.ui.AdaptionUtils;
 import org.simantics.utils.ui.ErrorLogger;
 import org.simantics.utils.ui.ISelectionUtils;
@@ -198,7 +201,9 @@ public class All {
                        Resource parameterResource = parameter.getRepresents(graph);
                        if(graph.sync(new IsEnumeratedValue(parameterResource))) {
                                Map<String, Resource> map = graph.sync(new InstanceEnumerationMap(parameterResource));
-                               return new ArrayList<String>(map.keySet());
+                               ArrayList<String> values = new ArrayList<>(map.keySet());
+                               Collections.sort(values, AlphanumComparator.COMPARATOR);
+                               return values;
                        } else if(graph.isInstanceOf(parameterResource, L0.Boolean)) {
                                return CollectionUtils.toList("true", "false");
                        }
@@ -463,6 +468,14 @@ public class All {
                                        value = formatterFunction.apply(property.getValue(graph));
                                }
                        }
+
+                       Resource possibleValue = context.getParent(graph).getPossibleRepresents(graph);
+                       if(possibleValue != null) {
+                               if(graph.syncRequest(new IsEnumeratedValue(possibleValue))) {
+                                       return GetEnumerationValue.getEnumerationValueName(graph, possibleValue);
+                               }
+                       }
+
                        if(value == null) {
 
                                Variant variant = property.getVariantValue(graph);
@@ -518,8 +531,14 @@ public class All {
                                String parsedLabel = (String)_value;
                                Object value = parsedLabel;
 
+                               boolean isEnumeration = false;
+                               Resource possibleValue = context.getParent(graph).getPossibleRepresents(graph);
+                               if(possibleValue != null) {
+                                       isEnumeration = graph.syncRequest(new IsEnumeratedValue(possibleValue));
+                               }
+
                                Datatype type = context.getParent(graph).getPossibleDatatype(graph);
-                               if (type != null) {
+                               if (type != null && !isEnumeration) {
 
                                        Binding binding = Bindings.getBinding(type);
 
index c0cedff2f92007299a7674007295f346af6c261b..000f176e92059efcd38836fd58a5f946530b9ca8 100644 (file)
@@ -13,7 +13,7 @@
 <feature
       id="org.simantics.sdk"
       label="Simantics SDK"
-      version="1.40.0.qualifier"
+      version="1.41.0.qualifier"
       provider-name="VTT Technical Research Centre of Finland">
 
    <description url="http://www.example.com/description">
index ec1814d1d0cd6d440d4631a8f82745eac5105499..58faa0f92e1cdcbd3a652f9d62a23794c3e5f1f3 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <?pde?>
 <!-- generated with https://github.com/mbarbero/fr.obeo.releng.targetplatform -->
-<target name="Simantics 1.40.0" sequenceNumber="1560983842">
+<target name="Simantics 1.41.0" sequenceNumber="1560983842">
   <locations>
     <location includeMode="slicer" includeAllPlatforms="true" includeSource="true" includeConfigurePhase="false" type="InstallableUnit">
       <unit id="com.google.guava" version="21.0.0.v20170206-1425"/>
index eeb2e54b8a05bc907d33a9c9c453487a4034f285..9c17094145f862c9eb6b27fd4393532a1731eefc 100644 (file)
@@ -1,4 +1,4 @@
-target "Simantics 1.40.0"
+target "Simantics 1.41.0"
 
 with source allEnvironments
 
index 4902ca06d807458b624546fc7649187fa25bc314..8aa8e170bde33c762b1ef7bc24c40fa7b253f947 100644 (file)
@@ -2,7 +2,7 @@
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <artifactId>org.simantics.sdk.repository</artifactId>
-       <version>1.40.0-SNAPSHOT</version>
+       <version>1.41.0-SNAPSHOT</version>
        <packaging>eclipse-repository</packaging>
 
        <parent>