From 9f3dcbe7dfeb11f976b8f5755d5f10fd4e0c77f7 Mon Sep 17 00:00:00 2001 From: niemisto Date: Tue, 26 Jan 2010 19:37:15 +0000 Subject: [PATCH] added trend view and automatic simulation git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@13654 ac1ea38d-2e2b-0410-8846-a27921b304fc --- org.simantics.sysdyn.ui/META-INF/MANIFEST.MF | 5 +- org.simantics.sysdyn.ui/plugin.xml | 7 + .../ui/project/SysdynPerspectiveFactory.java | 1 + .../simantics/sysdyn/ui/trend/TrendView.java | 188 ++++++++++++++++++ 4 files changed, 200 insertions(+), 1 deletion(-) create mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendView.java diff --git a/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF b/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF index 0933d0c5..5dbc6465 100644 --- a/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF +++ b/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF @@ -18,6 +18,9 @@ Require-Bundle: org.simantics.h2d;bundle-version="1.0.0", org.simantics.project;bundle-version="1.0.0", org.apache.log4j;bundle-version="1.2.15", org.eclipse.jface.text;bundle-version="3.5.0", - org.eclipse.ui.editors;bundle-version="3.5.0" + org.eclipse.ui.editors;bundle-version="3.5.0", + org.jfree.jchart;bundle-version="1.0.13", + org.jfree.jcommon;bundle-version="1.0.16", + org.simantics.modelica;bundle-version="1.0.0" Bundle-Activator: org.simantics.sysdyn.ui.Activator Bundle-ActivationPolicy: lazy diff --git a/org.simantics.sysdyn.ui/plugin.xml b/org.simantics.sysdyn.ui/plugin.xml index 1c9024bd..5aca244f 100644 --- a/org.simantics.sysdyn.ui/plugin.xml +++ b/org.simantics.sysdyn.ui/plugin.xml @@ -43,6 +43,13 @@ name="Equation View" restorable="true"> + + diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynPerspectiveFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynPerspectiveFactory.java index 9f6b2570..3ae01916 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynPerspectiveFactory.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynPerspectiveFactory.java @@ -16,6 +16,7 @@ public class SysdynPerspectiveFactory implements IPerspectiveFactory { IFolderLayout bottom = layout.createFolder("bottom", IPageLayout.BOTTOM, 0.75f, editorArea); bottom.addView("org.simantics.sysdyn.ui.equation.view"); + bottom.addView("org.simantics.sysdyn.ui.trend.view"); } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendView.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendView.java new file mode 100644 index 00000000..8b5b685b --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendView.java @@ -0,0 +1,188 @@ +package org.simantics.sysdyn.ui.trend; + +import java.awt.Frame; +import java.io.IOException; + +import javax.swing.SwingUtilities; + +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.awt.SWT_AWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.ISelectionListener; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.part.ViewPart; +import org.jfree.chart.ChartPanel; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.axis.NumberAxis; +import org.jfree.chart.plot.XYPlot; +import org.jfree.chart.renderer.xy.XYSplineRenderer; +import org.jfree.data.xy.AbstractXYDataset; +import org.simantics.db.Builtins; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.modelica.data.DataSet; +import org.simantics.modelica.data.SimulationResult; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.manager.SysdynModel; +import org.simantics.sysdyn.manager.SysdynModelManager; +import org.simantics.sysdyn.representation.IElement; +import org.simantics.sysdyn.representation.Variable; +import org.simantics.ui.SimanticsUI; +import org.simantics.utils.ui.jface.ActiveSelectionProvider; + +public class TrendView extends ViewPart { + + Frame frame; + ChartPanel panel; + SysdynDataset sysdynDataset = new SysdynDataset(); + + class SysdynDataset extends AbstractXYDataset { + + DataSet[] sets = new DataSet[0]; + + public void setDatasets(DataSet[] sets) { + this.sets = sets; + fireDatasetChanged(); + } + + @Override + public Number getY(int series, int item) { + return sets[series].values[item]; + } + + @Override + public Number getX(int series, int item) { + return sets[series].times[item]; + } + + @Override + public int getItemCount(int series) { + return sets[series].times.length; + } + + @Override + public Comparable getSeriesKey(int series) { + return sets[series].name; + } + + @Override + public int getSeriesCount() { + return sets.length; + } + + } + + @Override + public void createPartControl(Composite parent) { + final ActiveSelectionProvider selectionProvider = new ActiveSelectionProvider(); + getSite().setSelectionProvider(selectionProvider); + + final Composite composite = new Composite(parent, + SWT.NO_BACKGROUND | SWT.EMBEDDED); + frame = SWT_AWT.new_Frame(composite); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + XYPlot plot = new XYPlot( + sysdynDataset, + new NumberAxis("x"), + new NumberAxis("time"), + new XYSplineRenderer() + ); + + JFreeChart chart = new JFreeChart(plot); + panel = new ChartPanel(chart); + frame.add(panel); + + panel.requestFocus(); + } + + }); + + getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(new ISelectionListener() { + + @Override + public void selectionChanged(IWorkbenchPart part, ISelection selection) { + if(selection instanceof IStructuredSelection) { + Object[] els = ((IStructuredSelection) selection).toArray(); + Resource[] resources = new Resource[els.length]; + for(int i=0;i