From: lempinen Date: Thu, 3 May 2012 13:05:47 +0000 (+0000) Subject: Add FMU libraries to build, synchronize result reading. (refs #3414) X-Git-Tag: simantics-1.6~6^2~16 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=084895c42b113c951ad82f2f5163e081b6dc6703;p=simantics%2Fsysdyn.git Add FMU libraries to build, synchronize result reading. (refs #3414) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@24864 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ui/build.properties b/org.simantics.sysdyn.ui/build.properties index 8658bc35..d7ad83c2 100644 --- a/org.simantics.sysdyn.ui/build.properties +++ b/org.simantics.sysdyn.ui/build.properties @@ -16,6 +16,4 @@ bin.includes = META-INF/,\ plugin.xml,\ adapters.xml,\ icons/,\ - doc/,\ - cheatsheet/,\ splash.bmp diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynResult.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynResult.java index f081908e..3b3ead10 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynResult.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynResult.java @@ -50,207 +50,209 @@ import org.simantics.modelica.data.SimulationResult; */ public class SysdynResult { - protected RecordAccessor accessor; - protected String resultName; + protected RecordAccessor accessor; + protected String resultName; - /** - * Create an empty result - */ - public SysdynResult() { + /** + * Create an empty result + */ + public SysdynResult() { - } + } - /** - * Create a sysdynresult accessor using a {@link SimulationResult} - * @param result - */ - public SysdynResult(SimulationResult result) { - if(result != null) - setResult(result); - } - - /** - * Create a sysdynresult accessor using a {@link SimulationResult} - * @param result - * @param resultName Name of the result (seen in visualization) - */ - public SysdynResult(SimulationResult result, String resultName) { - this.resultName = resultName; - if(result != null) - setResult(result); - } + /** + * Create a sysdynresult accessor using a {@link SimulationResult} + * @param result + */ + public SysdynResult(SimulationResult result) { + if(result != null) + setResult(result); + } - /** - * Open result from a file - * - * @param result Name of the result (seen in visualization) - * @param path file path - */ - public SysdynResult(String result, String path) { - this.resultName = result; - File file = new File(path); - try { - BinaryVariant bv = (BinaryVariant)Accessors.openAccessor(file); - BinaryRecord br = bv.getContentAccessor(); - accessor = br; - } catch (AccessorConstructionException e) { - e.printStackTrace(); - } - } + /** + * Create a sysdynresult accessor using a {@link SimulationResult} + * @param result + * @param resultName Name of the result (seen in visualization) + */ + public SysdynResult(SimulationResult result, String resultName) { + this.resultName = resultName; + if(result != null) + setResult(result); + } - /** - * Get the {@link RecordAccessor} of this result - * @return {@link RecordAccessor} for this result - */ - public Accessor getAccessor() { - return accessor; - } + /** + * Open result from a file + * + * @param result Name of the result (seen in visualization) + * @param path file path + */ + public SysdynResult(String result, String path) { + this.resultName = result; + File file = new File(path); + try { + BinaryVariant bv = (BinaryVariant)Accessors.openAccessor(file); + BinaryRecord br = bv.getContentAccessor(); + accessor = br; + } catch (AccessorConstructionException e) { + e.printStackTrace(); + } + } - /** - * Create a {@link RecordAccessor} for this result based on a {@link SimulationResult} - * @param result {@link SimulationResult} - */ - public void setResult(SimulationResult result) { - try { - // Create Memory Historian - Datatype recordingSessionType = Datatypes.getDatatype("RecordingSession"); - RecordBinding sessionBinding = (RecordBinding) Bindings.getBinding( recordingSessionType ); - RecordBinding recordingBinding = (RecordBinding) Bindings.getBinding( Recording.class ); - Object session = sessionBinding.createDefault(); - accessor = (JavaRecord) Accessors.getAccessor( sessionBinding, session ); - MapAccessor recordings = accessor.getFieldAccessor("recordings"); + /** + * Get the {@link RecordAccessor} of this result + * @return {@link RecordAccessor} for this result + */ + public Accessor getAccessor() { + return accessor; + } - // There is a recording for each variable - List datasets = result.getVariableDataSets(); + /** + * Create a {@link RecordAccessor} for this result based on a {@link SimulationResult} + * @param result {@link SimulationResult} + */ + public void setResult(SimulationResult result) { + try { + // Create Memory Historian + Datatype recordingSessionType = Datatypes.getDatatype("RecordingSession"); + RecordBinding sessionBinding = (RecordBinding) Bindings.getBinding( recordingSessionType ); + RecordBinding recordingBinding = (RecordBinding) Bindings.getBinding( Recording.class ); + Object session = sessionBinding.createDefault(); + accessor = (JavaRecord) Accessors.getAccessor( sessionBinding, session ); + MapAccessor recordings = accessor.getFieldAccessor("recordings"); - // Add variables - for(DataSet ds : datasets){ - // Add recording to session - Recording recording = createRecording(ds); - recordings.put(Bindings.VARIANT, recording.nodeId, Bindings.VARIANT, new Variant(recordingBinding, recording)); - } + // There is a recording for each variable + List datasets = result.getVariableDataSets(); - // Add initial values - for(DataSet ds : result.getInitialValueDataSets()){ - Variant nodeId = Variant.ofInstance( ds.name ); - if (recordings.containsKey(Bindings.VARIANT, nodeId)) continue; - // Add recording to session - Recording recording = createRecording(ds); - recordings.put(Bindings.VARIANT, recording.nodeId, Bindings.VARIANT, new Variant(recordingBinding, recording)); - } + // Add variables + for(DataSet ds : datasets){ + // Add recording to session + Recording recording = createRecording(ds); + recordings.put(Bindings.VARIANT, recording.nodeId, Bindings.VARIANT, new Variant(recordingBinding, recording)); + } - } catch (Exception e) { - e.printStackTrace(); - } - } + // Add initial values + for(DataSet ds : result.getInitialValueDataSets()){ + Variant nodeId = Variant.ofInstance( ds.name ); + if (recordings.containsKey(Bindings.VARIANT, nodeId)) continue; + // Add recording to session + Recording recording = createRecording(ds); + recordings.put(Bindings.VARIANT, recording.nodeId, Bindings.VARIANT, new Variant(recordingBinding, recording)); + } - /** - * Create a recording for a variable to this result's {@link RecordAccessor} - * @param ds {@link DataSet} for the variable - * @return {@link Recording} - * @throws BindingException - */ - @SuppressWarnings("unchecked") - Recording createRecording(DataSet ds) throws BindingException { - RecordBinding recordingBinding = (RecordBinding) Bindings.getBindingUnchecked( Recording.class ); - Recording recording = (Recording) recordingBinding.createDefault(); - recording.nodeId = Variant.ofInstance( ds.name ); - recording.labels.put("en", ds.name); + } catch (Exception e) { + e.printStackTrace(); + } + } - // Create one segment - TreeMap segment = new TreeMap(); - recording.segments = new TreeMap[] { segment }; + /** + * Create a recording for a variable to this result's {@link RecordAccessor} + * @param ds {@link DataSet} for the variable + * @return {@link Recording} + * @throws BindingException + */ + @SuppressWarnings("unchecked") + Recording createRecording(DataSet ds) throws BindingException { + RecordBinding recordingBinding = (RecordBinding) Bindings.getBindingUnchecked( Recording.class ); + Recording recording = (Recording) recordingBinding.createDefault(); + recording.nodeId = Variant.ofInstance( ds.name ); + recording.labels.put("en", ds.name); - int length = ds.values.length; - for (int i=0; i segment = new TreeMap(); + recording.segments = new TreeMap[] { segment }; - /** - * Save current {@link RecordAccessor} to a {@link File} - * - * @param file {@link File} where the {@link RecordAccessor} is saved - */ - public void saveToFile(File file) { - if(accessor == null) return; - try { - Binding binding; - Object value; - if (accessor instanceof JavaRecord) { - // Get binding and value from memory - JavaRecord jr = (JavaRecord) accessor; - binding = jr.getBinding(); - value = jr.getObject(); - } else { - // Read value from another file - binding = Bindings.getBinding( accessor.type() ); - value = accessor.getValue(binding); - } + int length = ds.values.length; + for (int i=0; i labels; - public @Arguments({TreeMap.class, Double.class, Double.class}) TreeMap[] segments; - } + } - /** - * Get dataset for a named variable - * @param variable The name of the variable - * @return {@link SysdynDataSet} - */ - public SysdynDataSet getDataSet(String variable) { - if(accessor != null) { - try { - ChildReference ref = ChildReference.compile( - new NameReference("recordings"), - new KeyReference( Bindings.VARIANT, Variant.ofInstance(variable) ), - new ComponentReference(), - new NameReference("segments"), - new IndexReference(0) - ); + /** + * Class representing a recording for a variable + * @author Teemu Lempinen + * + */ + public static class Recording { + public Variant nodeId; + public @Arguments({String.class, String.class}) TreeMap labels; + public @Arguments({TreeMap.class, Double.class, Double.class}) TreeMap[] segments; + } - MapAccessor ma = accessor.getComponent( ref ); - int size = ma.size(); - Double[] times = new Double[size]; - Double[] values = new Double[size]; + /** + * Get dataset for a named variable + * @param variable The name of the variable + * @return {@link SysdynDataSet} + */ + public SysdynDataSet getDataSet(String variable) { + if(accessor != null) { + synchronized(accessor) { + try { + ChildReference ref = ChildReference.compile( + new NameReference("recordings"), + new KeyReference( Bindings.VARIANT, Variant.ofInstance(variable) ), + new ComponentReference(), + new NameReference("segments"), + new IndexReference(0) + ); - ma.getAll(Bindings.DOUBLE, Bindings.DOUBLE, times, values); + MapAccessor ma = accessor.getComponent( ref ); + int size = ma.size(); + Double[] times = new Double[size]; + Double[] values = new Double[size]; - double[] times_ = new double[size]; - double[] values_ = new double[size]; - for (int i=0; i