]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Add FMU libraries to build, synchronize result reading. (refs #3414)
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 3 May 2012 13:05:47 +0000 (13:05 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 3 May 2012 13:05:47 +0000 (13:05 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@24864 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/build.properties
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynResult.java

index 8658bc3595b00f567778d373e37a5261a31e5139..d7ad83c2a663ee937201de732212515dbb8b5668 100644 (file)
@@ -16,6 +16,4 @@ bin.includes = META-INF/,\
                plugin.xml,\\r
                adapters.xml,\\r
                icons/,\\r
-               doc/,\\r
-               cheatsheet/,\\r
                splash.bmp\r
index f081908e03ff207ef104922825679823c371c817..3b3ead1081e8470fe7a98dcaccc9c6a2cc95623a 100644 (file)
@@ -50,207 +50,209 @@ import org.simantics.modelica.data.SimulationResult;
  */\r
 public class SysdynResult {\r
 \r
-    protected RecordAccessor accessor;\r
-    protected String resultName;\r
+       protected RecordAccessor accessor;\r
+       protected String resultName;\r
 \r
-    /**\r
-     * Create an empty result\r
-     */\r
-    public SysdynResult() {\r
+       /**\r
+        * Create an empty result\r
+        */\r
+       public SysdynResult() {\r
 \r
-    }\r
+       }\r
 \r
-    /**\r
-     * Create a sysdynresult accessor using a {@link SimulationResult}\r
-     * @param result\r
-     */\r
-    public SysdynResult(SimulationResult result) {\r
-        if(result != null)\r
-            setResult(result);\r
-    }\r
-    \r
-    /**\r
-     * Create a sysdynresult accessor using a {@link SimulationResult}\r
-     * @param result\r
-     * @param resultName Name of the result (seen in visualization)\r
-     */\r
-    public SysdynResult(SimulationResult result, String resultName) {\r
-        this.resultName = resultName;\r
-        if(result != null)\r
-            setResult(result);\r
-    }\r
+       /**\r
+        * Create a sysdynresult accessor using a {@link SimulationResult}\r
+        * @param result\r
+        */\r
+       public SysdynResult(SimulationResult result) {\r
+               if(result != null)\r
+                       setResult(result);\r
+       }\r
 \r
-    /**\r
-     * Open result from a file\r
-     * \r
-     * @param result Name of the result (seen in visualization)\r
-     * @param path file path\r
-     */\r
-    public SysdynResult(String result, String path) {\r
-        this.resultName = result;\r
-        File file = new File(path);\r
-        try {\r
-            BinaryVariant bv = (BinaryVariant)Accessors.openAccessor(file);\r
-            BinaryRecord br = bv.getContentAccessor();\r
-            accessor = br;\r
-        } catch (AccessorConstructionException e) {\r
-            e.printStackTrace();\r
-        } \r
-    }\r
+       /**\r
+        * Create a sysdynresult accessor using a {@link SimulationResult}\r
+        * @param result\r
+        * @param resultName Name of the result (seen in visualization)\r
+        */\r
+       public SysdynResult(SimulationResult result, String resultName) {\r
+               this.resultName = resultName;\r
+               if(result != null)\r
+                       setResult(result);\r
+       }\r
 \r
-    /**\r
-     * Get the {@link RecordAccessor} of this result\r
-     * @return {@link RecordAccessor} for this result\r
-     */\r
-    public Accessor getAccessor() {\r
-        return accessor;\r
-    }\r
+       /**\r
+        * Open result from a file\r
+        * \r
+        * @param result Name of the result (seen in visualization)\r
+        * @param path file path\r
+        */\r
+       public SysdynResult(String result, String path) {\r
+               this.resultName = result;\r
+               File file = new File(path);\r
+               try {\r
+                       BinaryVariant bv = (BinaryVariant)Accessors.openAccessor(file);\r
+                       BinaryRecord br = bv.getContentAccessor();\r
+                       accessor = br;\r
+               } catch (AccessorConstructionException e) {\r
+                       e.printStackTrace();\r
+               } \r
+       }\r
 \r
-    /**\r
-     * Create a {@link RecordAccessor} for this result based on a {@link SimulationResult}\r
-     * @param result {@link SimulationResult}\r
-     */\r
-    public void setResult(SimulationResult result) {\r
-        try {\r
-            // Create Memory Historian\r
-            Datatype recordingSessionType = Datatypes.getDatatype("RecordingSession");\r
-            RecordBinding sessionBinding = (RecordBinding) Bindings.getBinding( recordingSessionType );\r
-            RecordBinding recordingBinding = (RecordBinding) Bindings.getBinding( Recording.class );\r
-            Object session = sessionBinding.createDefault();  \r
-            accessor = (JavaRecord) Accessors.getAccessor( sessionBinding, session );\r
-            MapAccessor recordings = accessor.getFieldAccessor("recordings");\r
+       /**\r
+        * Get the {@link RecordAccessor} of this result\r
+        * @return {@link RecordAccessor} for this result\r
+        */\r
+       public Accessor getAccessor() {\r
+               return accessor;\r
+       }\r
 \r
-            // There is a recording for each variable\r
-            List<DataSet> datasets = result.getVariableDataSets();\r
+       /**\r
+        * Create a {@link RecordAccessor} for this result based on a {@link SimulationResult}\r
+        * @param result {@link SimulationResult}\r
+        */\r
+       public void setResult(SimulationResult result) {\r
+               try {\r
+                       // Create Memory Historian\r
+                       Datatype recordingSessionType = Datatypes.getDatatype("RecordingSession");\r
+                       RecordBinding sessionBinding = (RecordBinding) Bindings.getBinding( recordingSessionType );\r
+                       RecordBinding recordingBinding = (RecordBinding) Bindings.getBinding( Recording.class );\r
+                       Object session = sessionBinding.createDefault();  \r
+                       accessor = (JavaRecord) Accessors.getAccessor( sessionBinding, session );\r
+                       MapAccessor recordings = accessor.getFieldAccessor("recordings");\r
 \r
-            // Add variables\r
-            for(DataSet ds : datasets){\r
-                // Add recording to session\r
-                Recording recording = createRecording(ds);\r
-                recordings.put(Bindings.VARIANT, recording.nodeId, Bindings.VARIANT, new Variant(recordingBinding, recording));\r
-            }\r
+                       // There is a recording for each variable\r
+                       List<DataSet> datasets = result.getVariableDataSets();\r
 \r
-            // Add initial values\r
-            for(DataSet ds : result.getInitialValueDataSets()){\r
-                Variant nodeId = Variant.ofInstance( ds.name );\r
-                if (recordings.containsKey(Bindings.VARIANT, nodeId)) continue;\r
-                // Add recording to session\r
-                Recording recording = createRecording(ds);\r
-                recordings.put(Bindings.VARIANT, recording.nodeId, Bindings.VARIANT, new Variant(recordingBinding, recording));\r
-            }\r
+                       // Add variables\r
+                       for(DataSet ds : datasets){\r
+                               // Add recording to session\r
+                               Recording recording = createRecording(ds);\r
+                               recordings.put(Bindings.VARIANT, recording.nodeId, Bindings.VARIANT, new Variant(recordingBinding, recording));\r
+                       }\r
 \r
-        } catch (Exception e) {\r
-            e.printStackTrace();\r
-        } \r
-    }\r
+                       // Add initial values\r
+                       for(DataSet ds : result.getInitialValueDataSets()){\r
+                               Variant nodeId = Variant.ofInstance( ds.name );\r
+                               if (recordings.containsKey(Bindings.VARIANT, nodeId)) continue;\r
+                               // Add recording to session\r
+                               Recording recording = createRecording(ds);\r
+                               recordings.put(Bindings.VARIANT, recording.nodeId, Bindings.VARIANT, new Variant(recordingBinding, recording));\r
+                       }\r
 \r
-    /**\r
-     * Create a recording for a variable to this result's {@link RecordAccessor} \r
-     * @param ds {@link DataSet} for the variable\r
-     * @return {@link Recording}\r
-     * @throws BindingException\r
-     */\r
-    @SuppressWarnings("unchecked")\r
-    Recording createRecording(DataSet ds) throws BindingException {\r
-        RecordBinding recordingBinding = (RecordBinding) Bindings.getBindingUnchecked( Recording.class );\r
-        Recording recording = (Recording) recordingBinding.createDefault();                 \r
-        recording.nodeId = Variant.ofInstance( ds.name );\r
-        recording.labels.put("en", ds.name);\r
+               } catch (Exception e) {\r
+                       e.printStackTrace();\r
+               } \r
+       }\r
 \r
-        // Create one segment\r
-        TreeMap<Double, Double> segment = new TreeMap<Double, Double>();\r
-        recording.segments = new TreeMap[] { segment };\r
+       /**\r
+        * Create a recording for a variable to this result's {@link RecordAccessor} \r
+        * @param ds {@link DataSet} for the variable\r
+        * @return {@link Recording}\r
+        * @throws BindingException\r
+        */\r
+       @SuppressWarnings("unchecked")\r
+       Recording createRecording(DataSet ds) throws BindingException {\r
+               RecordBinding recordingBinding = (RecordBinding) Bindings.getBindingUnchecked( Recording.class );\r
+               Recording recording = (Recording) recordingBinding.createDefault();                 \r
+               recording.nodeId = Variant.ofInstance( ds.name );\r
+               recording.labels.put("en", ds.name);\r
 \r
-        int length = ds.values.length;\r
-        for (int i=0; i<length; i++) {\r
-            double time = ds.times[i];\r
-            double value = ds.values[i];\r
-            segment.put(time, value);                      \r
-        }\r
-        return recording;\r
-    }\r
+               // Create one segment\r
+               TreeMap<Double, Double> segment = new TreeMap<Double, Double>();\r
+               recording.segments = new TreeMap[] { segment };\r
 \r
-    /**\r
-     * Save current {@link RecordAccessor} to a {@link File}\r
-     * \r
-     * @param file {@link File} where the {@link RecordAccessor} is saved\r
-     */\r
-    public void saveToFile(File file) {\r
-        if(accessor == null) return;\r
-        try {\r
-            Binding binding;\r
-            Object value;\r
-            if (accessor instanceof JavaRecord) {\r
-                // Get binding and value from memory\r
-                JavaRecord jr = (JavaRecord) accessor;\r
-                binding = jr.getBinding();\r
-                value = jr.getObject();\r
-            } else {\r
-                // Read value from another file\r
-                binding = Bindings.getBinding( accessor.type() );\r
-                value = accessor.getValue(binding);\r
-            }\r
+               int length = ds.values.length;\r
+               for (int i=0; i<length; i++) {\r
+                       double time = ds.times[i];\r
+                       double value = ds.values[i];\r
+                       segment.put(time, value);                      \r
+               }\r
+               return recording;\r
+       }\r
 \r
-            // Write to file\r
-            Files.createFile(file, binding, value);\r
-        } catch (IOException e) {\r
-            e.printStackTrace();\r
-        } catch (AccessorException e) {\r
-            e.printStackTrace();\r
-        }\r
+       /**\r
+        * Save current {@link RecordAccessor} to a {@link File}\r
+        * \r
+        * @param file {@link File} where the {@link RecordAccessor} is saved\r
+        */\r
+       public void saveToFile(File file) {\r
+               if(accessor == null) return;\r
+               try {\r
+                       Binding binding;\r
+                       Object value;\r
+                       if (accessor instanceof JavaRecord) {\r
+                               // Get binding and value from memory\r
+                               JavaRecord jr = (JavaRecord) accessor;\r
+                               binding = jr.getBinding();\r
+                               value = jr.getObject();\r
+                       } else {\r
+                               // Read value from another file\r
+                               binding = Bindings.getBinding( accessor.type() );\r
+                               value = accessor.getValue(binding);\r
+                       }\r
 \r
-    }\r
+                       // Write to file\r
+                       Files.createFile(file, binding, value);\r
+               } catch (IOException e) {\r
+                       e.printStackTrace();\r
+               } catch (AccessorException e) {\r
+                       e.printStackTrace();\r
+               }\r
 \r
-    /**\r
-     * Class representing a recording for a variable\r
-     * @author Teemu Lempinen\r
-     *\r
-     */\r
-    public static class Recording {\r
-        public Variant nodeId;\r
-        public @Arguments({String.class, String.class}) TreeMap<String, String> labels;\r
-        public @Arguments({TreeMap.class, Double.class, Double.class}) TreeMap<Double, Double>[] segments;\r
-    }\r
+       }\r
 \r
-    /**\r
-     * Get dataset for a named variable\r
-     * @param variable The name of the variable\r
-     * @return {@link SysdynDataSet}\r
-     */\r
-    public SysdynDataSet getDataSet(String variable) {\r
-        if(accessor != null) {\r
-            try {\r
-                ChildReference ref = ChildReference.compile(\r
-                        new NameReference("recordings"),\r
-                        new KeyReference( Bindings.VARIANT, Variant.ofInstance(variable) ),\r
-                        new ComponentReference(),\r
-                        new NameReference("segments"),\r
-                        new IndexReference(0)\r
-                );\r
+       /**\r
+        * Class representing a recording for a variable\r
+        * @author Teemu Lempinen\r
+        *\r
+        */\r
+       public static class Recording {\r
+               public Variant nodeId;\r
+               public @Arguments({String.class, String.class}) TreeMap<String, String> labels;\r
+               public @Arguments({TreeMap.class, Double.class, Double.class}) TreeMap<Double, Double>[] segments;\r
+       }\r
 \r
-                MapAccessor ma = accessor.getComponent( ref );\r
-                int size = ma.size();\r
-                Double[] times = new Double[size];\r
-                Double[] values = new Double[size];\r
+       /**\r
+        * Get dataset for a named variable\r
+        * @param variable The name of the variable\r
+        * @return {@link SysdynDataSet}\r
+        */\r
+       public SysdynDataSet getDataSet(String variable) {\r
+               if(accessor != null) {\r
+                       synchronized(accessor) {\r
+                               try {\r
+                                       ChildReference ref = ChildReference.compile(\r
+                                                       new NameReference("recordings"),\r
+                                                       new KeyReference( Bindings.VARIANT, Variant.ofInstance(variable) ),\r
+                                                       new ComponentReference(),\r
+                                                       new NameReference("segments"),\r
+                                                       new IndexReference(0)\r
+                                                       );\r
 \r
-                ma.getAll(Bindings.DOUBLE, Bindings.DOUBLE, times, values);\r
+                                       MapAccessor ma = accessor.getComponent( ref );\r
+                                       int size = ma.size();\r
+                                       Double[] times = new Double[size];\r
+                                       Double[] values = new Double[size];\r
 \r
-                double[] times_ = new double[size];\r
-                double[] values_ = new double[size];\r
-                for (int i=0; i<size; i++) {\r
-                    times_[i] = (times[i]!=null ? times[i] : 0);\r
-                    values_[i] = (values[i]!=null ? values[i] : 0);\r
-                }\r
+                                       ma.getAll(Bindings.DOUBLE, Bindings.DOUBLE, times, values);\r
 \r
-                return new SysdynDataSet(variable, resultName, times_, values_);\r
+                                       double[] times_ = new double[size];\r
+                                       double[] values_ = new double[size];\r
+                                       for (int i=0; i<size; i++) {\r
+                                               times_[i] = (times[i]!=null ? times[i] : 0);\r
+                                               values_[i] = (values[i]!=null ? values[i] : 0);\r
+                                       }\r
 \r
-            } catch (AccessorConstructionException e) {\r
-                // Variable was not found\r
-            } catch (AccessorException e) {\r
-                // Unable to read data from file\r
-                e.printStackTrace();\r
-            }\r
-        }\r
-        return null;\r
-    }\r
+                                       return new SysdynDataSet(variable, resultName, times_, values_);\r
+\r
+                               } catch (AccessorConstructionException e) {\r
+                                       // Variable was not found\r
+                               } catch (AccessorException e) {\r
+                                       // Unable to read data from file\r
+                                       e.printStackTrace();\r
+                               }\r
+                       }\r
+               }\r
+               return null;\r
+       }\r
 }\r