]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Merge "Fix change comparison expressions in mapping rules" into release/1.43.0
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Tue, 19 May 2020 11:16:59 +0000 (11:16 +0000)
committerGerrit Code Review <gerrit2@simantics>
Tue, 19 May 2020 11:16:59 +0000 (11:16 +0000)
bundles/org.simantics.diagram/src/org/simantics/diagram/profile/Updater.java
bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java
bundles/org.simantics.g2d/src/org/simantics/g2d/participant/OrientationRestorer.java
bundles/org.simantics.g2d/src/org/simantics/g2d/participant/TimeParticipant.java
bundles/org.simantics.history/src/org/simantics/history/csv/CSVFormatter.java
bundles/org.simantics.structural2/src/org/simantics/structural2/queries/GetComponentLocation.java

index 44ec7618e2fee64577f350633c778316428ae144..2e79ef2160808332339bd79d72d97d4edec14fca 100644 (file)
@@ -60,11 +60,11 @@ class Updater implements Runnable {
        }
        
        public void register(INode node) {
-               // We use ths size of this map to determine whether updates are needed, this is done in AWT thread
+               // We use the size of this map to determine whether updates are needed, this is done in AWT thread
                synchronized(requesters) {
                        if(requesters.size() == 0) {
                                if(state.compareAndSet(false, true)) {
-                                       ThreadUtils.getNonBlockingWorkExecutor().scheduleAtFixedRate(this, 0, 500, TimeUnit.MILLISECONDS);
+                                       ThreadUtils.getNonBlockingWorkExecutor().scheduleWithFixedDelay(this, 0, 500, TimeUnit.MILLISECONDS);
                                }
                        }
                        ICanvasContext context = DiagramNodeUtil.getPossibleCanvasContext((G2DNode)node);
index d5a727ffae324f3219af714288bce219aa58f2ec..8dea97ad118da8235b185d56b0e0ce539d9d7f0a 100644 (file)
@@ -164,8 +164,8 @@ public class Functions {
                         StandardAssertedGraphPropertyVariable ass = (StandardAssertedGraphPropertyVariable)property;
                         if("dataDefinitions".equals(ass.property.name) || "commands".equals(ass.property.name)  || "pollingFunction".equals(ass.property.name)) {
                                storePropertyValueAndExceptions(graph, parent, ass.property.name, property, map);
+                            continue;
                         }
-                        continue;
                     }
                     Resource predicate = property.getPossiblePredicateResource(graph);
                     if(predicate != null) {
@@ -297,8 +297,8 @@ public class Functions {
                         StandardAssertedGraphPropertyVariable ass = (StandardAssertedGraphPropertyVariable)property;
                         if("dataDefinitions".equals(ass.property.name) || "commands".equals(ass.property.name)  || "pollingFunction".equals(ass.property.name)) {
                             result.add(ass.property.name);
+                            continue;
                         }
-                        continue;
                     }
                     Resource predicate = property.getPossiblePredicateResource(graph);
                     if(predicate != null) {
index f2a420b1221910c1f54e1dba891ad8417bfcc449..aafedcc09f78b902775a50e8ec76903b486f1b94 100644 (file)
@@ -88,7 +88,7 @@ public class OrientationRestorer extends AbstractCanvasParticipant {
 //        long delay = 1000 / 25; this sounds quite frequent
         long delay = 1000 / 10;
         lastTrigger = System.currentTimeMillis();
-        timer.scheduleAtFixedRate(task, delay, delay, TimeUnit.MILLISECONDS);
+        timer.scheduleWithFixedDelay(task, delay, delay, TimeUnit.MILLISECONDS);
     }
 
     @HintListener(Class = Hints.class, Field = "KEY_CANVAS_BOUNDS")
index 9103dfd638539d6c9e9ad5d93b2e4c1e067614b3..7eb4f4c379a14a2b8ced71fbe5b6841cda93b321 100644 (file)
@@ -207,7 +207,7 @@ public class TimeParticipant extends AbstractCanvasParticipant {
             return;
 
         long interval = getInterval();
-        future = ThreadUtils.getNonBlockingWorkExecutor().scheduleAtFixedRate(onTimer, DEFAULT_INTERVAL, interval, TimeUnit.MILLISECONDS);
+        future = ThreadUtils.getNonBlockingWorkExecutor().scheduleWithFixedDelay(onTimer, DEFAULT_INTERVAL, interval, TimeUnit.MILLISECONDS);
     }
 
     private void cancelTimer() {
index 6cc7a2a6f09a9bf50e1c7f27eeb74651180e1df2..b04e0dd37b37e34d0398855a451cd93cb534d6ff 100644 (file)
@@ -38,6 +38,23 @@ import org.simantics.history.util.ValueBand;
  */
 public class CSVFormatter {
 
+       /**
+        * This is the tolerance used to decide whether or not the last data point of
+        * the exported items is included in the exported material or not. If
+        * <code>0 <= (t - t(lastDataPoint) < {@value #RESAMPLING_END_TIMESTAMP_INCLUSION_TOLERANCE}</code>
+        * is true, then the last exported data point will be
+        * <code>lastDataPoint</code>, with timestamp <code>t(lastDataPoint)</code> even
+        * if <code>t > t(lastDataPoint)</code>.
+        * 
+        * <p>
+        * This works around problems where floating point inaccuracy causes a data
+        * point to be left out from the the export when it would be fair for the user
+        * to expect the data to be exported would contain a point with time stamp
+        * <code>9.999999999999996</code> when sampling with time-step <code>1.0</code>
+        * starting from time <code>0.0</code>.
+        */
+       private static final double RESAMPLING_END_TIMESTAMP_INCLUSION_TOLERANCE = 1e-13;
+
        List<Item> items = new ArrayList<Item>();
        double from = -Double.MAX_VALUE;
        double end  =  Double.MAX_VALUE;
@@ -329,6 +346,13 @@ public class CSVFormatter {
                        BigDecimal bigTime = new BigDecimal(String.valueOf(time));
                        BigDecimal bigTimeStep = new BigDecimal(String.valueOf(timeStep));
 
+                       // Loop kill-switch for the case where timeStep > 0
+                       boolean breakAfterNextWrite = false;
+
+//                     System.out.println("time:     " + time);
+//                     System.out.println("timeStep: " + timeStep);
+//                     System.out.println("_end:     " + Double.toString(_end));
+
                        for (Item i : items) i.iter.gotoTime(time);
                        do {
                                if ( monitor!=null && monitor.isCanceled() ) return;
@@ -394,10 +418,26 @@ public class CSVFormatter {
 
                                sb.append( lineFeed );
 
-                   // Read next values, and the following times
-                   if ( timeStep>0.0 ) {
-                       bigTime = bigTime.add(bigTimeStep);
-                       time = bigTime.doubleValue();
+                               if (breakAfterNextWrite)
+                                       break;
+
+                               // Read next values, and the following times
+                               if ( timeStep>0.0 ) {
+                                       bigTime = bigTime.add(bigTimeStep);
+                                       time = bigTime.doubleValue();
+
+                                       // gitlab #529: prevent last data point from getting dropped
+                                       // due to small imprecisions in re-sampling mode.
+                                       double diff = time - _end;
+                                       if (diff > 0 && diff <= RESAMPLING_END_TIMESTAMP_INCLUSION_TOLERANCE) {
+                                               time = _end;
+                                               breakAfterNextWrite = true;
+                                               // Take floating point inaccuracy into account when re-sampling
+                                               // to prevent the last data point from being left out if there
+                                               // is small-enough imprecision in the last data point time stamp
+                                               // to be considered negligible compared to expected stepped time.
+                                       }
+
                    } else {
                        // Get smallest end time that is larger than current time
                        Double nextTime = null;
@@ -420,6 +460,7 @@ public class CSVFormatter {
                        if(contains(i, time)) hasMore = true;
                }
                
+               //System.out.println("hasMore @ " + time + " (" + bigTime + ") = " + hasMore);
                if(!hasMore) break;
                
                } while (time<=_end);
index df6e1598c2649312442e3acae4c7186b4bc329c3..e109f59e89538b3574f2abe73c67b39355674a56 100644 (file)
@@ -66,10 +66,16 @@ public class GetComponentLocation extends UnaryRead<Variable, ComponentLocation>
         Variable firstRepresentedParent = findFirstParentWithRepresentation(graph, parameter, STR);
         if (firstRepresentedParent == null)
             return null;
-        Resource realParentComposite = graph.getPossibleObject(firstRepresentedParent.getRepresents(graph), L0.PartOf);
-        if (realParentComposite == null)
-            return null;
-        isInsideStructure = graph.hasStatement(realParentComposite, STR.Defines);
+        Resource representedParent = firstRepresentedParent.getRepresents(graph);
+        Resource representedParentType = graph.getPossibleType(representedParent, STR.Component);
+        if (representedParentType != null && graph.isInstanceOf(representedParentType, STR.ProceduralComponentType)) {
+            isInsideStructure = !parameter.equals(firstRepresentedParent);
+        } else {
+            Resource realParentComposite = graph.getPossibleObject(representedParent, L0.PartOf);
+            if (realParentComposite == null)
+                return null;
+            isInsideStructure = graph.hasStatement(realParentComposite, STR.Defines);
+        }
 
         Variable firstParentComposite = findFirstParentComposite(graph, firstRepresentedParent, STR);
         if (firstParentComposite != null) {