refersTo = graph.getSingleObject(dep, sr.HasTail);\r
referenceName = (String) graph.getPossibleRelatedValue(refersTo, b.HasName);\r
moduleRepresentation = graph.getPossibleResource(variable.substring(0, variable.lastIndexOf("/")));\r
- Resource parent = graph.getSingleObject(moduleRepresentation, b.PartOf);\r
- module = graph.getSingleObject(moduleRepresentation, b.Represents);\r
+ Resource parent = graph.getPossibleObject(moduleRepresentation, b.PartOf);\r
String parentURI = graph.getURI(parent);\r
String modelURI = diagram.getHint((DiagramModelHints.KEY_DIAGRAM_MODEL_URI));\r
- if(parentURI.equals(modelURI))\r
+ module = graph.getPossibleObject(moduleRepresentation, b.Represents);\r
+ if(parentURI.equals(modelURI) || module == null)\r
moduleName = "";\r
else {\r
moduleName = (String) graph.getPossibleRelatedValue(module, b.HasName);\r
}\r
\r
String inputReference = null;\r
- if (module != null && refersTo != null) {\r
+ if (moduleName != null && refersTo != null) {\r
inputReference = moduleName + "." + referenceName;\r
}\r
if (inputReference == null) {\r
Resource model = Variables.getModel(graph, this);\r
Resource configuration = graph.getPossibleObject(model, b.HasConfiguration);\r
SysdynModel sm = SysdynModelManager.getInstance(graph.getSession()).getModel(graph, configuration);\r
- SysdynResult sr = new SysdynResult(sm.getSimulationResult());\r
+ SysdynResult sr = sm.getSysdynResult();\r
String rvi = Variables.getRVI(graph, this);\r
System.out.println("HistoryVariable rvi='" + rvi + "'");\r
rvi = rvi.substring(1).replace("/", ".");\r
\r
import java.awt.Frame;\r
import java.util.ArrayList;\r
+import java.util.Collection;\r
import java.util.List;\r
import java.util.Set;\r
\r
import org.jfree.chart.plot.XYPlot;\r
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;\r
import org.jfree.data.xy.AbstractXYDataset;\r
-import org.simantics.databoard.Bindings;\r
-import org.simantics.databoard.accessor.Accessor;\r
-import org.simantics.databoard.accessor.error.AccessorException;\r
-import org.simantics.databoard.binding.error.RuntimeBindingConstructionException;\r
import org.simantics.db.Builtins;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.modeling.ModelingUtils;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.manager.SysdynDataSet;\r
+import org.simantics.sysdyn.manager.SysdynModel;\r
+import org.simantics.sysdyn.manager.SysdynModelManager;\r
+import org.simantics.sysdyn.manager.SysdynResult;\r
import org.simantics.ui.SimanticsUI;\r
import org.simantics.utils.ui.ISelectionUtils;\r
import org.simantics.utils.ui.jface.ActiveSelectionProvider;\r
return;\r
if(selection instanceof IStructuredSelection) {\r
Set<Resource> ress = ISelectionUtils.filterSetSelection(selection, Resource.class);\r
- List<Resource> runtimes = ISelectionUtils.getPossibleKeys(selection, SelectionHints.KEY_VARIABLE_RESOURCE, Resource.class);\r
- if(runtimes.isEmpty())\r
- return;\r
- Resource runtime = runtimes.get(0);\r
+ List<Resource> runtimes = ISelectionUtils.getPossibleKeys(selection, SelectionHints.KEY_VARIABLE_RESOURCE, Resource.class);\r
+ if(runtimes.isEmpty())\r
+ return;\r
+ Resource runtime = runtimes.get(0);\r
setSelection(ress.toArray(Resource.NONE), runtime);\r
} \r
}\r
}\r
\r
public void updateView() {\r
- \r
+\r
Session session = SimanticsUI.peekSession();\r
if (session == null)\r
return;\r
\r
final ArrayList<SysdynDataSet> datasets = new ArrayList<SysdynDataSet>();\r
for(Resource resource : resources) {\r
- SysdynDataSet set = load(g, resource, runtime);\r
- if(set == null) {\r
- return;\r
- }\r
- datasets.add(set);\r
+// SysdynDataSet set = load(g, resource, runtime);\r
+// if(set == null) {\r
+// return;\r
+// }\r
+// datasets.add(set);\r
+ Collection<SysdynDataSet> activeDataSets = loadAllActive(g, resource, runtime);\r
+ if(activeDataSets != null && !activeDataSets.isEmpty())\r
+ datasets.addAll(activeDataSets);\r
}
\r
SwingUtilities.invokeLater(new Runnable() {\r
});\r
}\r
\r
+ /*\r
protected SysdynDataSet load(ReadGraph g, Resource element, Resource runtime) throws DatabaseException {\r
\r
Builtins b = g.getBuiltins();\r
- \r
+\r
SysdynResource sr = SysdynResource.getInstance(g);\r
\r
DiagramResource dr = DiagramResource.getInstance(g);\r
- \r
+\r
if(runtime == null) return null;\r
Resource resource = ModelingUtils.getPossibleElementCorrespondendence(g, element);\r
if(resource == null || !g.isInstanceOf(resource, sr.Variable)) return null;\r
\r
String variableURI = g.getPossibleRelatedValue(runtime, dr.HasVariable);\r
- \r
+\r
System.out.println("load dataset for '"+ g.getPossibleRelatedValue(resource, b.HasName) + "'in composite '" + variableURI + "'");\r
Variable compositeVariable = Variables.getVariable(g, variableURI);\r
Variable item = compositeVariable.browsePossible(g, resource);\r
if(item == null) return null;\r
- \r
+\r
System.out.println("load dataset for '" + item.getURI(g) + "'");\r
- \r
+\r
Accessor accessor = item.getInterface(g, Accessor.class);\r
if(accessor == null) return null;\r
try {\r
return null;\r
\r
}\r
+ */\r
\r
@Override\r
public void setFocus() {\r
panel.requestFocus(); \r
}\r
\r
+ protected Collection<SysdynDataSet> loadAllActive(ReadGraph g, Resource element, Resource runtime) throws DatabaseException {\r
+\r
+ ArrayList<SysdynDataSet> dataSets = new ArrayList<SysdynDataSet>();\r
+ Builtins b = g.getBuiltins();\r
+\r
+ SysdynResource sr = SysdynResource.getInstance(g);\r
+\r
+ DiagramResource dr = DiagramResource.getInstance(g);\r
+\r
+ if(runtime == null) return null;\r
+ Resource resource = ModelingUtils.getPossibleElementCorrespondendence(g, element);\r
+ if(resource == null || !g.isInstanceOf(resource, sr.Variable)) return null;\r
+\r
+ String variableURI = g.getPossibleRelatedValue(runtime, dr.HasVariable);\r
+\r
+ System.out.println("load dataset for '"+ g.getPossibleRelatedValue(resource, b.HasName) + "'in composite '" + variableURI + "'");\r
+ Variable compositeVariable = Variables.getVariable(g, variableURI);\r
+ Variable item = compositeVariable.browsePossible(g, resource);\r
+ if(item == null) return null;\r
+\r
+ String rvi = Variables.getRVI(g, item);\r
+ System.out.println("HistoryVariable rvi='" + rvi + "'");\r
+\r
+ System.out.println("load dataset for '" + item.getURI(g) + "'");\r
+\r
+ Resource model = Variables.getModel(g, item);\r
+ Resource configuration = g.getPossibleObject(model, b.HasConfiguration);\r
+ SysdynModel sm = SysdynModelManager.getInstance(g.getSession()).getModel(g, configuration);\r
+\r
+ Collection<SysdynResult> activeResults = sm.getActiveResults(g);\r
+ for(SysdynResult sysdynResult : activeResults) {\r
+ SysdynDataSet sds = sysdynResult.getDataSet(rvi.substring(1).replace("/", "."));\r
+ if(sds != null)\r
+ dataSets.add(sds);\r
+ }\r
+ return dataSets;\r
+\r
+ }\r
+\r
}\r
Runnable modificationListener;\r
Resource experiment;\r
SysdynModel sysdynModel;\r
- SysdynResult result;\r
\r
public SysdynExperiment(Resource experiment, Resource model) {\r
super(model);\r
public void saveState() {\r
// TODO Auto-generated method stub\r
System.out.println("saveState");\r
- if(sysdynModel.getSimulationResult() == null) return;\r
+ if(sysdynModel.getSysdynResult() == null) return;\r
\r
try {\r
session.syncRequest(new WriteRequest() {\r
b.PartOf, model,\r
sr.HasResultFile, file.getAbsolutePath());\r
graph.claim(experiment, sr.HasResult, res);\r
- result.saveToFile(file);\r
+ sysdynModel.getSysdynResult().saveToFile(file);\r
}\r
});\r
session.getService(LifecycleSupport.class).save();\r
System.out.println("init");\r
changeState(ExperimentState.STOPPED);\r
this.session = g.getSession();\r
- result = new SysdynResult();\r
\r
session.asyncRequest(new ReadRequest() {\r
\r
public void run(ReadGraph graph) throws DatabaseException {\r
final Resource configuration = graph.getPossibleObject(model, graph.getBuiltins().HasConfiguration);\r
sysdynModel = SysdynModelManager.getInstance(session).getModel(graph, configuration);\r
- sysdynModel.addResultListener(new Runnable() {\r
- \r
- @Override\r
- public void run() {\r
- result.setResult(sysdynModel.getSimulationResult());\r
- }\r
- });\r
- \r
toggleActivation(graph, true);\r
}\r
});\r
Configuration configuration;\r
Set<Configuration> modules = new HashSet<Configuration>();\r
SimulationResult result;\r
+ SysdynResult sysdynResult;\r
\r
CopyOnWriteArrayList<Runnable> modificationListeners =\r
new CopyOnWriteArrayList<Runnable>();\r
} catch(DatabaseException e) {\r
e.printStackTrace();\r
}\r
+ sysdynResult = new SysdynResult();\r
+ sysdynResult.setResult(new SimulationResult());\r
}\r
\r
\r
writer.toString(), \r
monitor,\r
configuration.startTime,\r
- configuration.stopTime); \r
+ configuration.stopTime); \r
+ sysdynResult.setResult(result);\r
} catch(Exception e) {\r
e.printStackTrace();\r
result = null;\r
public SimulationResult getSimulationResult() {\r
return result;\r
}\r
+ \r
+ public SysdynResult getSysdynResult() {\r
+ return sysdynResult;\r
+ }\r
\r
public void addResultListener(Runnable listener) {\r
synchronized(resultListeners) {\r
e.printStackTrace();\r
}\r
\r
- if(getSimulationResult() != null)\r
- results.add(0, new SysdynResult(getSimulationResult()));\r
+ if(getSysdynResult() != null)\r
+ results.add(0, getSysdynResult() );\r
\r
\r
\r
import org.simantics.modelica.data.SimulationResult;\r
\r
public class SysdynResult {\r
- \r
+\r
RecordingSession recordingSession;\r
RecordAccessor accessor;\r
String resultName;\r
}\r
\r
public SysdynResult(String result, String path) {\r
- System.out.println("sysdynresult " + result + " " + path);\r
this.resultName = result;\r
File file = new File(path);\r
try {\r
BinaryVariant bv = (BinaryVariant)Accessors.openAccessor(file);\r
BinaryRecord br = bv.getValueAccessor();\r
accessor = br;\r
- } catch (AccessorConstructionException e) {\r
+ } catch (AccessorConstructionException e) {\r
e.printStackTrace();\r
} \r
}\r
try { \r
Binding stringBinding = StringBindingDefault.INSTANCE;\r
Binding recordBinding = Bindings.getBinding( Recording.class );\r
- \r
+\r
recordingSession = new RecordingSession();\r
recordingSession.recordings = new TreeMap<Variant, Variant>();\r
MutableVariant timeVariableId = new MutableVariant();\r
timeVariableId.setValue(stringBinding, "timeVariableId");\r
recordingSession.timeVariableId = timeVariableId;\r
- \r
+\r
\r
\r
for(DataSet ds : result.getVariableDataSets()){\r
} catch (Exception e) {\r
e.printStackTrace();\r
} \r
+\r
+ if(recordingSession == null) return;\r
+\r
+\r
+ try {\r
+ Binding recordBinding = Bindings.getBinding( RecordingSession.class );\r
+ if(accessor == null) {\r
+ accessor = (JavaRecord)Accessors.getAccessor(recordBinding, recordingSession);\r
+ } else {\r
+ accessor.setValue(recordBinding, recordingSession);\r
+ }\r
+ } catch (AccessorConstructionException e) {\r
+ e.printStackTrace();\r
+ } catch (BindingConstructionException e) {\r
+ e.printStackTrace();\r
+ } catch (AccessorException e) {\r
+ e.printStackTrace();\r
+ }\r
+\r
}\r
\r
public void saveToFile(File file) {\r
} catch (BindingException e) {\r
e.printStackTrace();\r
}\r
- \r
+\r
}\r
\r
\r
public static class NodeId {\r
public String nodeId;\r
}\r
- \r
+\r
public SysdynDataSet getDataSet(String variable) {\r
- if(accessor == null && recordingSession != null) {\r
- try {\r
- Binding recordBinding = Bindings.getBinding( RecordingSession.class );\r
- accessor = (JavaRecord)Accessors.getAccessor(recordBinding, recordingSession);\r
- } catch (AccessorConstructionException e) {\r
- e.printStackTrace();\r
- } catch (BindingConstructionException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
- \r
if(accessor != null) {\r
MapAccessor ma;\r
try {\r
VariantAccessor va = ma.getValueAccessor( MutableVariantBinding.INSTANCE, tmpVariant);\r
Accessor valueAccessor = va.getValueAccessor();\r
rec = (Recording)valueAccessor.getValue( Bindings.getBinding(Recording.class));\r
- \r
+\r
va = ma.getValueAccessor( MutableVariantBinding.INSTANCE, tmpVariant2);\r
valueAccessor = va.getValueAccessor();\r
time = (Recording)valueAccessor.getValue( Bindings.getBinding(Recording.class));\r