]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.history/src/org/simantics/history/impl/CollectorImpl.java
Manually "cherry-picked" changes from ae2e31aa to release/1.35.2.1
[simantics/platform.git] / bundles / org.simantics.history / src / org / simantics / history / impl / CollectorImpl.java
index 87062a9dabecae759aa0f5dffd442a496af156e5..c202f733ca6af88c284351de3cfadea3eee9899d 100644 (file)
@@ -87,6 +87,15 @@ public class CollectorImpl implements Collector {
        
        /** True when all items are open */
        boolean itemsOpen = true;
        
        /** True when all items are open */
        boolean itemsOpen = true;
+
+       /** True when history collection will write data to disk */
+       boolean enabled = true;
+
+       /**
+        * Transient info only set in {@link #beginStep(NumberBinding, Object)} based on
+        * {@link #enabled}
+        */
+       private transient boolean stepEnabled = true;
        
        public FlushPolicy flushPolicy = FlushPolicy.FlushOnEveryStep;
        
        
        public FlushPolicy flushPolicy = FlushPolicy.FlushOnEveryStep;
        
@@ -122,7 +131,16 @@ public class CollectorImpl implements Collector {
                this.history = history;
                this.state = (CollectorState) previousState.clone();
        }
                this.history = history;
                this.state = (CollectorState) previousState.clone();
        }
-       
+
+       public void setEnabled(boolean enabled) {
+               this.enabled = enabled;
+       }
+
+       @Override
+       public boolean isEnabled() {
+               return enabled;
+       }
+
        @Override
        public synchronized void addItem(Bean item) throws HistoryException {
                try {
        @Override
        public synchronized void addItem(Bean item) throws HistoryException {
                try {
@@ -494,13 +512,20 @@ public class CollectorImpl implements Collector {
        
        @Override
        public void beginStep(NumberBinding binding, Object time) throws HistoryException {
        
        @Override
        public void beginStep(NumberBinding binding, Object time) throws HistoryException {
-               openAllItems();
+               stepEnabled = enabled;
                updateDt(binding, time);
                state.time.setValue(binding, time);
                updateDt(binding, time);
                state.time.setValue(binding, time);
+               if (enabled) {
+                       openAllItems();
+               }
        }
 
        @Override
        public void setValue(String id, Binding binding, Object value) throws HistoryException {
        }
 
        @Override
        public void setValue(String id, Binding binding, Object value) throws HistoryException {
+               // Short-circuit calls when collection not enabled
+               if (!stepEnabled)
+                       return;
+
                VariableState vs = state.values.get( id );
                if (vs == null) {
                        vs = new VariableState();
                VariableState vs = state.values.get( id );
                if (vs == null) {
                        vs = new VariableState();
@@ -554,6 +579,8 @@ public class CollectorImpl implements Collector {
 
        @Override
        public void endStep() throws HistoryException {
 
        @Override
        public void endStep() throws HistoryException {
+               if (!stepEnabled)
+                       return;
                // Write values to streams
                for (ActiveStream i : items)
                {
                // Write values to streams
                for (ActiveStream i : items)
                {
@@ -815,11 +842,20 @@ public class CollectorImpl implements Collector {
 
                        /// Extend existing band
                        // Extend endTime value
 
                        /// Extend existing band
                        // Extend endTime value
-                       if (!i.hasEndTime) {
-                               i.current.setTime( time.getBinding(), time.getValue() );
-                       } else {
-                               i.current.setEndTime( time.getBinding(), time.getValue() );
+
+                       // This ensures that a value band's end time isn't the same
+                       // as the next band's start time which makes it possible to
+                       // know what are the timestamps between which the item value
+                       // changed from a to b. This allows us to more correctly render
+                       // steps and sloped lines accoring to the actual data.
+                       if (!i.itemState.ooDeadband || isMinMaxFormat) {
+                               if (!i.hasEndTime) {
+                                       i.current.setTime( time.getBinding(), time.getValue() );
+                               } else {
+                                       i.current.setEndTime( time.getBinding(), time.getValue() );
+                               }
                        }
                        }
+
                        if (i.itemState.ooDeadband || isMinMaxFormat) {
                                if (isValidValue) {
                                        // Set last value
                        if (i.itemState.ooDeadband || isMinMaxFormat) {
                                if (isValidValue) {
                                        // Set last value