From ab6aaecc97a94b4e1776804557b7f9f3d82ca67c Mon Sep 17 00:00:00 2001 From: Alexandre Gobbo Date: Fri, 29 Aug 2014 16:18:10 +0200 Subject: [PATCH] Added visualization to Fdaq --- fda.ui.application/pom.xml | 2 +- fda.ui.module/pom.xml | 2 +- .../ui/cdump/CdumpExecutionTopComponent.form | 122 +++++++++++++-- .../ui/cdump/CdumpExecutionTopComponent.java | 147 +++++++++++++++--- .../core/windows/view/ui/Bundle.properties | 4 +- .../ch/psi/fda/ui/cdump/Bundle.properties | 3 + pom.xml | 2 +- 7 files changed, 244 insertions(+), 38 deletions(-) diff --git a/fda.ui.application/pom.xml b/fda.ui.application/pom.xml index ad0781c..ab14bae 100644 --- a/fda.ui.application/pom.xml +++ b/fda.ui.application/pom.xml @@ -5,7 +5,7 @@ ch.psi fda.ui - 3.1.3 + 3.1.4 fda.ui.application diff --git a/fda.ui.module/pom.xml b/fda.ui.module/pom.xml index 60060d6..744f514 100644 --- a/fda.ui.module/pom.xml +++ b/fda.ui.module/pom.xml @@ -4,7 +4,7 @@ fda.ui ch.psi - 3.1.3 + 3.1.4 fda.ui.module diff --git a/fda.ui.module/src/main/java/ch/psi/fda/ui/cdump/CdumpExecutionTopComponent.form b/fda.ui.module/src/main/java/ch/psi/fda/ui/cdump/CdumpExecutionTopComponent.form index 9eeb9e0..5f6cedc 100644 --- a/fda.ui.module/src/main/java/ch/psi/fda/ui/cdump/CdumpExecutionTopComponent.form +++ b/fda.ui.module/src/main/java/ch/psi/fda/ui/cdump/CdumpExecutionTopComponent.form @@ -32,7 +32,7 @@ - + @@ -62,7 +62,7 @@ - + @@ -106,14 +106,34 @@ - - + + + + + + + + + - + + + + + + + + + + + + + + + - - + @@ -121,15 +141,32 @@ - + - - - + + + + + + + + + + + + + + + + + + + + + + - - - + @@ -166,6 +203,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/fda.ui.module/src/main/java/ch/psi/fda/ui/cdump/CdumpExecutionTopComponent.java b/fda.ui.module/src/main/java/ch/psi/fda/ui/cdump/CdumpExecutionTopComponent.java index 7e671b7..a0d9e75 100644 --- a/fda.ui.module/src/main/java/ch/psi/fda/ui/cdump/CdumpExecutionTopComponent.java +++ b/fda.ui.module/src/main/java/ch/psi/fda/ui/cdump/CdumpExecutionTopComponent.java @@ -21,14 +21,21 @@ import ch.psi.fda.cdump.Cdump; import ch.psi.fda.cdump.CdumpConfiguration; import ch.psi.fda.fdaq.Fdaq; import ch.psi.fda.fdaq.FdaqConfiguration; +import ch.psi.fda.model.v1.Visualization; import ch.psi.fda.serializer.SerializerTXT; +import ch.psi.fda.ui.ee.PlotVisualizerTopComponent; import ch.psi.fda.ui.preferences.api.Preferences; +import ch.psi.fda.ui.visualizer.Visualizer; +import ch.psi.fda.vdescriptor.LinePlot; +import ch.psi.fda.vdescriptor.VDescriptor; +import ch.psi.fda.vdescriptor.XYSeries; import ch.psi.jcae.ChannelService; import ch.psi.jcae.impl.DefaultChannelService; import com.google.common.eventbus.AsyncEventBus; import com.google.common.eventbus.EventBus; import java.io.File; import java.util.Date; +import java.util.List; import java.util.concurrent.Executors; import java.util.logging.Level; import java.util.logging.Logger; @@ -86,6 +93,11 @@ public final class CdumpExecutionTopComponent extends TopComponent { jLabel4 = new javax.swing.JLabel(); jTextField2 = new javax.swing.JTextField(); jButton2 = new javax.swing.JButton(); + jLabel5 = new javax.swing.JLabel(); + jLabel6 = new javax.swing.JLabel(); + comboNumberPoints = new javax.swing.JComboBox(); + comboSubsampling = new javax.swing.JComboBox(); + checkPlot = new javax.swing.JCheckBox(); jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(Cdump.SAMPLING_RATES)); @@ -115,6 +127,26 @@ public final class CdumpExecutionTopComponent extends TopComponent { } }); + org.openide.awt.Mnemonics.setLocalizedText(jLabel5, org.openide.util.NbBundle.getMessage(CdumpExecutionTopComponent.class, "CdumpExecutionTopComponent.jLabel5.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(jLabel6, org.openide.util.NbBundle.getMessage(CdumpExecutionTopComponent.class, "CdumpExecutionTopComponent.jLabel6.text")); // NOI18N + + comboNumberPoints.setEditable(true); + comboNumberPoints.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "100", "200", "500", "1000", "2000", "5000", "10000" })); + comboNumberPoints.setSelectedIndex(3); + + comboSubsampling.setEditable(true); + comboSubsampling.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "10", "100", "1000", "10000" })); + comboSubsampling.setSelectedIndex(2); + + checkPlot.setSelected(true); + org.openide.awt.Mnemonics.setLocalizedText(checkPlot, org.openide.util.NbBundle.getMessage(CdumpExecutionTopComponent.class, "CdumpExecutionTopComponent.checkPlot.text")); // NOI18N + checkPlot.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + checkPlotActionPerformed(evt); + } + }); + javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( @@ -124,24 +156,50 @@ public final class CdumpExecutionTopComponent extends TopComponent { .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel3) .addGroup(jPanel1Layout.createSequentialGroup() - .addComponent(jLabel4) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addComponent(jLabel4) + .addGap(18, 18, 18) + .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(jButton2)) .addGap(18, 18, 18) - .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addComponent(jButton2)) - .addContainerGap(113, Short.MAX_VALUE)) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addGap(21, 21, 21) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.LEADING)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(comboNumberPoints, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(comboSubsampling, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addComponent(checkPlot)))) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() - .addComponent(jLabel3) + .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel4) - .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jButton2) - .addContainerGap(90, Short.MAX_VALUE)) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel4) + .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(18, 18, 18) + .addComponent(jButton2)) + .addGroup(jPanel1Layout.createSequentialGroup() + .addComponent(checkPlot) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel6) + .addComponent(comboNumberPoints, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel5) + .addComponent(comboSubsampling, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))) + .addContainerGap(68, Short.MAX_VALUE)) ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); @@ -160,7 +218,7 @@ public final class CdumpExecutionTopComponent extends TopComponent { .addComponent(jComboBox1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 173, Short.MAX_VALUE))) .addComponent(jButton1)) - .addContainerGap(108, Short.MAX_VALUE)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); layout.setVerticalGroup( @@ -259,7 +317,16 @@ public final class CdumpExecutionTopComponent extends TopComponent { } }//GEN-LAST:event_jButton2ActionPerformed + private void checkPlotActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkPlotActionPerformed + // TODO add your handling code here: + comboNumberPoints.setEnabled(checkPlot.isSelected()); + comboSubsampling.setEnabled(checkPlot.isSelected()); + }//GEN-LAST:event_checkPlotActionPerformed + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JCheckBox checkPlot; + private javax.swing.JComboBox comboNumberPoints; + private javax.swing.JComboBox comboSubsampling; private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JComboBox jComboBox1; @@ -267,6 +334,8 @@ public final class CdumpExecutionTopComponent extends TopComponent { private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; + private javax.swing.JLabel jLabel5; + private javax.swing.JLabel jLabel6; private javax.swing.JPanel jPanel1; private javax.swing.JTextField jTextField1; private javax.swing.JTextField jTextField2; @@ -382,8 +451,31 @@ public final class CdumpExecutionTopComponent extends TopComponent { } } - public void startAcquisitionFdaq() { + final boolean showPlot = checkPlot.isSelected(); + final int itemCount = Integer.valueOf(comboNumberPoints.getSelectedItem().toString()); + final int subsamplingFactor = Integer.valueOf(comboSubsampling.getSelectedItem().toString()); + + final PlotVisualizerTopComponent tc = PlotVisualizerTopComponent.findInstance(); + new Thread(new Runnable() { + + @Override + public void run() { + try{ + acquireFdaq(tc, showPlot, itemCount, subsamplingFactor); + } + catch (Exception ex){ + Logger.getLogger(CdumpExecutionTopComponent.class.getName()).log(Level.WARNING,null,ex); + } + } + }).start(); + if (showPlot){ + tc.requestVisible(); + } + } + + + public void acquireFdaq(PlotVisualizerTopComponent tc, boolean showPlot, int itemCount, int subsamplingFactor) { Preferences p = Lookup.getDefault().lookup(Preferences.class); // TODO currently only the hardcoded configurations are supported // The ch.psi.fda.fdaq.config.file configuration file is not set base on FDA_HOME ... @@ -391,7 +483,7 @@ public final class CdumpExecutionTopComponent extends TopComponent { FdaqConfiguration configuration = new FdaqConfiguration(); EventBus bus = new AsyncEventBus(Executors.newSingleThreadExecutor()); - fdaqService = new Fdaq(bus, configuration); + fdaqService = new Fdaq(bus, configuration); String fname = jTextField2.getText(); AcquisitionConfiguration config = ch.psi.fda.ui.ee.Configuration.getInstance().getConfiguration(); @@ -412,13 +504,30 @@ public final class CdumpExecutionTopComponent extends TopComponent { } catch (InterruptedException e) { e.printStackTrace(); } - + Logger.getLogger(CdumpExecutionTopComponent.class.getName()).log(Level.INFO, "Start fdaq acquisition"); - fdaqService.acquire(); + + if (showPlot) { + VDescriptor vd = new VDescriptor(); + //LinePlot lineplot = new LinePlot(); + for (String plot: new String[]{"ain1","ain2","ain3","ain4","enc1"}){ + LinePlot lineplot = new LinePlot(plot); + XYSeries series = new XYSeries("counter", plot); + series.setMaxItemCount(itemCount); + lineplot.getData().add(series); + vd.getPlots().add(lineplot); + } + //vd.getPlots().add(lineplot); + String linePlotImpl=Lookup.getDefault().lookup(Preferences.class).getLinePlotImpl(); + Visualizer visualizer = new Visualizer(vd,linePlotImpl); + visualizer.setSubsampling(subsamplingFactor); + bus.register(visualizer); + tc.updatePanel(visualizer.getPlotPanels()); + } + + fdaqService.acquire(); - - - + // // Calculate data file location/name // String fname = jTextField2.getText(); diff --git a/fda.ui.module/src/main/nbm-branding/modules/org-netbeans-core-windows.jar/org/netbeans/core/windows/view/ui/Bundle.properties b/fda.ui.module/src/main/nbm-branding/modules/org-netbeans-core-windows.jar/org/netbeans/core/windows/view/ui/Bundle.properties index 16dd92f..e89484f 100644 --- a/fda.ui.module/src/main/nbm-branding/modules/org-netbeans-core-windows.jar/org/netbeans/core/windows/view/ui/Bundle.properties +++ b/fda.ui.module/src/main/nbm-branding/modules/org-netbeans-core-windows.jar/org/netbeans/core/windows/view/ui/Bundle.properties @@ -1,2 +1,2 @@ -CTL_MainWindow_Title=FDA 3.1.3 -CTL_MainWindow_Title_No_Project=FDA 3.1.3 +CTL_MainWindow_Title=FDA 3.1.4 +CTL_MainWindow_Title_No_Project=FDA 3.1.4 diff --git a/fda.ui.module/src/main/resources/ch/psi/fda/ui/cdump/Bundle.properties b/fda.ui.module/src/main/resources/ch/psi/fda/ui/cdump/Bundle.properties index 8418d47..381e277 100644 --- a/fda.ui.module/src/main/resources/ch/psi/fda/ui/cdump/Bundle.properties +++ b/fda.ui.module/src/main/resources/ch/psi/fda/ui/cdump/Bundle.properties @@ -14,3 +14,6 @@ CdumpExecutionTopComponent.jLabel3.text=Fdaq Testing CdumpExecutionTopComponent.jLabel4.text=Scan Name CdumpExecutionTopComponent.jTextField2.text= CdumpExecutionTopComponent.jButton2.text=Start +CdumpExecutionTopComponent.jLabel5.text=Subsampling Factor: +CdumpExecutionTopComponent.jLabel6.text=Number of Points: +CdumpExecutionTopComponent.checkPlot.text=Show Plot diff --git a/pom.xml b/pom.xml index 5503da6..4da9778 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ ch.psi fda.ui - 3.1.3 + 3.1.4 pom ch.psi.fda.ui.parent