diff --git a/nbactions.xml b/nbactions.xml index 827cc3d..c9e50c7 100644 --- a/nbactions.xml +++ b/nbactions.xml @@ -1,46 +1,46 @@ - - - - run - - jar - - - process-classes - org.codehaus.mojo:exec-maven-plugin:1.2.1:exec - - - -classpath %classpath ch.psi.pshell.ui.App -p=ch.psi.mxsc.MainPanel -home=C:\dev\pshell\home -r - java - - - - debug - - jar - - - process-classes - org.codehaus.mojo:exec-maven-plugin:1.2.1:exec - - - -Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath ch.psi.pshell.ui.App -p=ch.psi.mxsc.MainPanel -home=C:\dev\pshell\home -r - java - true - - - - profile - - jar - - - process-classes - org.codehaus.mojo:exec-maven-plugin:1.2.1:exec - - - -classpath %classpath ch.psi.pshell.ui.App -p=ch.psi.mxsc.MainPanel -home=C:\dev\pshell\home -r - java - - - + + + + run + + jar + + + process-classes + org.codehaus.mojo:exec-maven-plugin:1.2.1:exec + + + -classpath %classpath ch.psi.pshell.ui.App -p=ch.psi.mxsc.MainPanel -home=C:\dev\pshell\home -r + java + + + + debug + + jar + + + process-classes + org.codehaus.mojo:exec-maven-plugin:1.2.1:exec + + + -Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath ch.psi.pshell.ui.App -p=ch.psi.mxsc.MainPanel -home=D:\dev\pshell\home -r + java + true + + + + profile + + jar + + + process-classes + org.codehaus.mojo:exec-maven-plugin:1.2.1:exec + + + -classpath %classpath ch.psi.pshell.ui.App -p=ch.psi.mxsc.MainPanel -home=C:\dev\pshell\home -r + java + + + diff --git a/pom.xml b/pom.xml index 2b34ce9..127b26b 100644 --- a/pom.xml +++ b/pom.xml @@ -1,80 +1,80 @@ - - - 4.0.0 - ch.psi - MXSC - 1.19.0 - jar - - - ${project.groupId} - pshell - ${project.version} - - - org.zeromq - jeromq - 0.5.3 - - - - UTF-8 - 11 - 11 - - - - - jcenter - jcenter - https://jcenter.bintray.com/ - - - bintray-hltools - bintray - https://dl.bintray.com/paulscherrerinstitute/hltools - - - imagej - imagej - http://maven.imagej.net/content/repositories/public - - - libs-snapshots-local - libs-snapshots-local - https://artifacts.psi.ch/artifactory/libs-snapshots-local/ - - - scijava-pub - scijava-pub - https://maven.scijava.org/content/repositories/public/ - - - scijava - scijava - https://maven.scijava.org/ - - - releases - releases - https://artifacts.psi.ch/artifactory/releases - - - MXSC - - - - - - org.apache.maven.plugins - maven-jar-plugin - 2.3.1 - - ../../config/mxsc/plugins - - - - + + + 4.0.0 + ch.psi + MXSC + 1.21.0 + jar + + + ${project.groupId} + pshell + ${project.version} + + + org.zeromq + jeromq + 0.5.3 + + + + UTF-8 + 11 + 11 + + + + + jcenter + jcenter + https://jcenter.bintray.com/ + + + bintray-hltools + bintray + https://dl.bintray.com/paulscherrerinstitute/hltools + + + imagej + imagej + http://maven.imagej.net/content/repositories/public + + + libs-snapshots-local + libs-snapshots-local + https://artifacts.psi.ch/artifactory/libs-snapshots-local/ + + + scijava-pub + scijava-pub + https://maven.scijava.org/content/repositories/public/ + + + scijava + scijava + https://maven.scijava.org/ + + + releases + releases + https://artifacts.psi.ch/artifactory/releases + + + MXSC + + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.3.1 + + ../pshell/home/plugins + + + + \ No newline at end of file diff --git a/src/main/java/ch/psi/mxsc/BasePlateGraphics.java b/src/main/java/ch/psi/mxsc/BasePlateGraphics.java index 2b79514..16775ef 100644 --- a/src/main/java/ch/psi/mxsc/BasePlateGraphics.java +++ b/src/main/java/ch/psi/mxsc/BasePlateGraphics.java @@ -2,10 +2,12 @@ package ch.psi.mxsc; import ch.psi.pshell.imaging.Utils; import ch.psi.utils.swing.MainFrame; +import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics2D; import java.awt.Point; import java.awt.Rectangle; +import java.awt.Stroke; import java.awt.geom.Ellipse2D; import java.awt.image.BufferedImage; import java.util.ArrayList; @@ -60,6 +62,17 @@ public class BasePlateGraphics { top, bottom } + + Rectangle imageRoi; + + public void setImageRoi( Rectangle roi){ + this.imageRoi = roi; + } + + Point detection; + public void setDetection( Point detection){ + this.detection = detection; + } void draw(Graphics2D g, Rectangle plotRect, boolean drawSamples, boolean drawIds, boolean drawContour, DrawMode mode, BufferedImage img) { if (mode != DrawMode.fill){ @@ -85,7 +98,19 @@ public class BasePlateGraphics { this.plotRect = plotRect; this.drawContour = drawContour; boundingBox = new Rectangle((int)(plotRect.x+plotRect.width*0.05), (int)(plotRect.y+plotRect.height * 0.05), (int)(plotRect.width*0.90), (int)(plotRect.height*0.90)); + int center_x=0, center_y=0; if (img!=null){ + Point detection = this.detection; + if (imageRoi!=null){ + img = img.getSubimage(imageRoi.x, imageRoi.y, imageRoi.width, imageRoi.height); + if (detection!=null){ + //detection = new Point(detection.x-imageRoi.x, detection.y-imageRoi.y); + center_x = detection.x * boundingBox.width / img.getWidth() + boundingBox.x; + center_y = detection.y * boundingBox.height / img.getHeight() + boundingBox.y; + center_x -= imageRoi.x * boundingBox.width / img.getWidth(); + center_y -= imageRoi.y * boundingBox.height / img.getHeight(); + } + } img = Utils.stretch(img, boundingBox.width, boundingBox.height); g.setClip(new Ellipse2D.Float(boundingBox.x, boundingBox.y, boundingBox.width, boundingBox.height)); g.drawImage(img, boundingBox.x, boundingBox.y, null); @@ -104,6 +129,16 @@ public class BasePlateGraphics { for (PuckGraphics pg : puckGraphics) { pg.draw(g, null, drawSamples, drawIds, drawBackground) ; } + if (img!=null){ + if (detection!=null){ + int size=15; + g.setColor(new Color(86, 193, 255)); + g.setStroke(new BasicStroke(2f)); + g.drawLine(center_x-size, center_y, center_x+size, center_y); + g.drawLine(center_x, center_y-size, center_x, center_y+size); + //g.drawOval(center_x-size, center_y-size, 2*size, 2*size); + } + } } diff --git a/src/main/java/ch/psi/mxsc/Controller.java b/src/main/java/ch/psi/mxsc/Controller.java index ef597ea..e92ebaf 100644 --- a/src/main/java/ch/psi/mxsc/Controller.java +++ b/src/main/java/ch/psi/mxsc/Controller.java @@ -56,7 +56,6 @@ public class Controller { final BasePlate basePlate; RoomTemperatureBasePlate roomTemperatureBasePlate; static /*Panel*/ MainPanel mainFrame; - Device hexiposi; Device barcode_reader; Device barcode_reader_puck; Device puck_detection; @@ -305,12 +304,6 @@ public class Controller { } } - final DeviceListener hexiposiListener = new DeviceAdapter() { - @Override - public void onValueChanged(Device device, Object value, Object former) { - updateView(); - } - }; final DeviceListener barcodeReaderListener = new DeviceAdapter() { @Override @@ -346,22 +339,6 @@ public class Controller { }; void updateDevices() { - if (hexiposi != null) { - hexiposi.removeListener(hexiposiListener); - } - if (barcode_reader != null) { - hexiposi.removeListener(barcodeReaderListener); - } - if (puck_detection != null) { - hexiposi.removeListener(puckDetectionListener); - } - hexiposi = (Device) getMainFrame().getDevice("hexiposi"); - if (hexiposi != null) { - hexiposi.addListener(hexiposiListener); - } else { - Logger.getLogger(Controller.class.getName()).log(Level.SEVERE, "No hexiposi detected."); - } - mainFrame.hexiposiPanel.setDevice(hexiposi); barcode_reader = (Device) getDevice("barcode_reader"); if (barcode_reader != null) { barcode_reader.addListener(barcodeReaderListener); @@ -429,16 +406,8 @@ public class Controller { updateView(); } - public String getHexiposiPosition() { - try { - return (String) ((ReadbackDevice) hexiposi).getReadback().take(); - } catch (Exception ex) { - return null; - } - } - public boolean isSelectedPuck(Puck puck) { - return ("" + puck.getSegment()).equalsIgnoreCase(getHexiposiPosition()); + return puck.isSegmentSelected(); } public List getSelectedPucks() { @@ -773,7 +742,7 @@ public class Controller { Puck.Detection[] detection = basePlate.getDetection(); for (int i = 0; i < Controller.NUMBER_OF_PUCKS; i++) { Puck puck = basePlate.getPucks()[i]; - //Only manage pucks for current hexiposi position + if (isSelectedPuck(puck)) { boolean detectedPuckInserted = (currentDetection[i] != Puck.Detection.Present) && (detection[i] == Puck.Detection.Present); boolean detectedPuckRemoved = (currentDetection[i] != Puck.Detection.Empty) && (detection[i] == Puck.Detection.Empty); diff --git a/src/main/java/ch/psi/mxsc/MainPanel.form b/src/main/java/ch/psi/mxsc/MainPanel.form index 3cc1d67..bccb809 100644 --- a/src/main/java/ch/psi/mxsc/MainPanel.form +++ b/src/main/java/ch/psi/mxsc/MainPanel.form @@ -1,6 +1,10 @@
+ + + + @@ -31,7 +35,7 @@ - + @@ -89,14 +93,14 @@ - - - + + + - - - - + + + + @@ -278,12 +282,12 @@ - - - - + + + + - + @@ -291,29 +295,29 @@ - + - + - + - + - + - + - + - + @@ -333,41 +337,66 @@ - - - - - + + + + + + + - + - - - - + + + + + + + + - - - - - - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - @@ -384,12 +413,12 @@ - + - + @@ -408,6 +437,10 @@ + + + + @@ -416,7 +449,9 @@ - + + + @@ -1004,9 +1039,9 @@ - + - + @@ -1170,7 +1205,7 @@ - + diff --git a/src/main/java/ch/psi/mxsc/MainPanel.java b/src/main/java/ch/psi/mxsc/MainPanel.java index 4a0e301..8b6ef69 100644 --- a/src/main/java/ch/psi/mxsc/MainPanel.java +++ b/src/main/java/ch/psi/mxsc/MainPanel.java @@ -7,6 +7,9 @@ import ch.psi.mxsc.BasePlatePanel.SelectionMode; import ch.psi.pshell.core.Plugin; import ch.psi.pshell.device.Device; import ch.psi.pshell.device.DeviceAdapter; +import ch.psi.pshell.device.DeviceBase; +import ch.psi.pshell.device.DeviceListener; +import ch.psi.pshell.imaging.PointDouble; import ch.psi.pshell.imaging.Renderer; import ch.psi.pshell.imaging.RendererMode; import ch.psi.pshell.imaging.Source; @@ -28,11 +31,14 @@ import java.awt.Dialog; import java.awt.Dimension; import java.awt.GridBagLayout; import java.awt.Image; +import java.awt.Point; +import java.awt.Rectangle; import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.io.File; +import java.lang.reflect.Array; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -416,7 +422,11 @@ public class MainPanel extends Panel { updateMode(((Device) getDevice("robot")).take()); } catch (Exception ex) { this.getLogger().log(Level.SEVERE, null, ex); - } + } + + DeviceBase dev = (DeviceBase) this.getDevice("cover_detection"); + dev.addListener(cover_detection_listener); + setPuckDatamatrix(null); setSampleDatamatrix(null); setBackgroundUpdate(true); @@ -578,6 +588,21 @@ public class MainPanel extends Panel { } void updateCameraView() { + try{ + if (buttonCamera.isSelected()){ + int center_x = ((Number)this.eval("cover_detection.config.center_x", true)).intValue(); + int center_y = ((Number)this.eval("cover_detection.config.center_y", true)).intValue(); + int diam_dewar = ((Number)this.eval("cover_detection.config.diameter_dewar", true)).intValue(); + double dewar_wall = ((Number)this.eval("cover_detection.config.dewar_wall", true)).doubleValue(); + int diam =(int) (dewar_wall * diam_dewar); + Rectangle roi = new Rectangle(center_x-diam/2,center_y - diam/2, diam, diam ); + basePlatePanel.basePlateGraphics.setImageRoi(roi); + } + } catch (Exception ex){ + if (getState().isInitialized()){ + getLogger().log(Level.SEVERE, null, ex); + } + } Source source = buttonCamera.isSelected() ? (Source) this.getDevice("img") : null; basePlatePanel.setCameraView(source); } @@ -683,20 +708,20 @@ public class MainPanel extends Panel { buttonCalibrateImage.setVisible(expert); buttonCalibrateCover.setVisible(expert); devicesPanel.setActive(expert); - panelViewType.setVisible(expert); + //panelViewType.setVisible(expert); panelDetection.setVisible(expert && !isRt()); - buttonDetectCover.setVisible(expert); buttonConfig.setVisible(expert); Puck.setDisplayDetectionError(expert); if (checkExpert.isSelected() != expert) { checkExpert.setSelected(expert); } - if (expert == false) { - buttonCamera.setSelected(false); - buttonDrawing.setSelected(true); - updateViewType(); - } + //if (expert == false) { + // buttonCamera.setSelected(true); + // buttonDrawing.setSelected(false); + // updateViewType(); + //} + if (current != expert) { onModeChange(expert); } @@ -935,6 +960,24 @@ public class MainPanel extends Panel { } } + DeviceListener cover_detection_listener = new DeviceAdapter() { + @Override + public void onCacheChanged(Device device, Object value, Object former, long timestamp, boolean valueChange) { + Point mm = null; + Point det = null; + try{ + mm = new Point(Array.getInt(value, 4), Array.getInt(value, 5)); + det = new Point(Array.getInt(value, 0), Array.getInt(value, 1)); + basePlatePanel.basePlateGraphics.setDetection(det); + } catch (Exception ex){ + } + Point aux = mm; + SwingUtilities.invokeLater(()->{ + textCoverDet.setText((aux==null) ? "" :aux.x + ", " + aux.y); + }); + } + }; + /** * This method is called from within the constructor to initialize the form. @@ -945,6 +988,7 @@ public class MainPanel extends Panel { // //GEN-BEGIN:initComponents private void initComponents() { + buttonGroup1 = new javax.swing.ButtonGroup(); panelTop = new javax.swing.JPanel(); basePlatePanel = new ch.psi.mxsc.BasePlatePanel(); panelLegend = new javax.swing.JPanel(); @@ -959,11 +1003,13 @@ public class MainPanel extends Panel { ledLidControlActive5 = new ch.psi.pshell.swing.Led(); jLabel23 = new javax.swing.JLabel(); panelDetection = new javax.swing.JPanel(); - buttonClearDet = new javax.swing.JButton(); - buttonPuckDet = new javax.swing.JButton(); + buttonCalibrationPanel = new javax.swing.JButton(); + buttonDetectionCalibrate = new javax.swing.JButton(); panelHexiposi = new javax.swing.JPanel(); - hexiposiPanel = new ch.psi.mxsc.HexiposiPanel(); - buttonDetectCover = new javax.swing.JButton(); + jLabel1 = new javax.swing.JLabel(); + textCoverDet = new javax.swing.JTextField(); + jLabel2 = new javax.swing.JLabel(); + textCoverMove = new javax.swing.JTextField(); panelViewType = new javax.swing.JPanel(); buttonCamera = new javax.swing.JToggleButton(); buttonDrawing = new javax.swing.JToggleButton(); @@ -1112,17 +1158,17 @@ public class MainPanel extends Panel { panelDetection.setBorder(javax.swing.BorderFactory.createTitledBorder("Detection")); - buttonClearDet.setText("Clear"); - buttonClearDet.addActionListener(new java.awt.event.ActionListener() { + buttonCalibrationPanel.setText("Panel"); + buttonCalibrationPanel.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonClearDetActionPerformed(evt); + buttonCalibrationPanelActionPerformed(evt); } }); - buttonPuckDet.setText("Start"); - buttonPuckDet.addActionListener(new java.awt.event.ActionListener() { + buttonDetectionCalibrate.setText("Calibrate"); + buttonDetectionCalibrate.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonPuckDetActionPerformed(evt); + buttonDetectionCalibrateActionPerformed(evt); } }); @@ -1131,55 +1177,75 @@ public class MainPanel extends Panel { panelDetectionLayout.setHorizontalGroup( panelDetectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(panelDetectionLayout.createSequentialGroup() - .addContainerGap(26, Short.MAX_VALUE) - .addGroup(panelDetectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(buttonClearDet, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(buttonPuckDet, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap(26, Short.MAX_VALUE)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(panelDetectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) + .addComponent(buttonDetectionCalibrate) + .addComponent(buttonCalibrationPanel)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); + + panelDetectionLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonCalibrationPanel, buttonDetectionCalibrate}); + panelDetectionLayout.setVerticalGroup( panelDetectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelDetectionLayout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(buttonPuckDet) + .addComponent(buttonDetectionCalibrate) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(buttonClearDet) + .addComponent(buttonCalibrationPanel) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); panelHexiposi.setBorder(javax.swing.BorderFactory.createTitledBorder("Cover")); panelHexiposi.setPreferredSize(new java.awt.Dimension(112, 153)); - buttonDetectCover.setText("Image"); - buttonDetectCover.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonDetectCoverActionPerformed(evt); - } - }); + jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jLabel1.setText("Detection:"); + + textCoverDet.setEditable(false); + textCoverDet.setHorizontalAlignment(javax.swing.JTextField.CENTER); + textCoverDet.setDisabledTextColor(new java.awt.Color(0, 0, 0)); + textCoverDet.setEnabled(false); + + jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jLabel2.setText("Last Move:"); + + textCoverMove.setEditable(false); + textCoverMove.setHorizontalAlignment(javax.swing.JTextField.CENTER); + textCoverMove.setDisabledTextColor(new java.awt.Color(0, 0, 0)); + textCoverMove.setEnabled(false); javax.swing.GroupLayout panelHexiposiLayout = new javax.swing.GroupLayout(panelHexiposi); panelHexiposi.setLayout(panelHexiposiLayout); panelHexiposiLayout.setHorizontalGroup( panelHexiposiLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelHexiposiLayout.createSequentialGroup() - .addContainerGap(14, Short.MAX_VALUE) - .addGroup(panelHexiposiLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(buttonDetectCover) - .addComponent(hexiposiPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addContainerGap(15, Short.MAX_VALUE)) + .addGroup(panelHexiposiLayout.createSequentialGroup() + .addContainerGap() + .addGroup(panelHexiposiLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(textCoverDet) + .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(textCoverMove, javax.swing.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE)) + .addContainerGap()) ); panelHexiposiLayout.setVerticalGroup( panelHexiposiLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(panelHexiposiLayout.createSequentialGroup() - .addContainerGap(18, Short.MAX_VALUE) - .addComponent(hexiposiPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 13, Short.MAX_VALUE) - .addComponent(buttonDetectCover) - .addContainerGap()) + .addContainerGap() + .addComponent(jLabel1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(textCoverDet, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(18, 18, 18) + .addComponent(jLabel2) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(textCoverMove, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap(18, Short.MAX_VALUE)) ); panelViewType.setBorder(javax.swing.BorderFactory.createTitledBorder("View")); + buttonGroup1.add(buttonCamera); + buttonCamera.setSelected(true); buttonCamera.setText("Image"); buttonCamera.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { @@ -1187,7 +1253,7 @@ public class MainPanel extends Panel { } }); - buttonDrawing.setSelected(true); + buttonGroup1.add(buttonDrawing); buttonDrawing.setText("Design"); buttonDrawing.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { @@ -1200,11 +1266,11 @@ public class MainPanel extends Panel { panelViewTypeLayout.setHorizontalGroup( panelViewTypeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelViewTypeLayout.createSequentialGroup() - .addContainerGap(21, Short.MAX_VALUE) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(panelViewTypeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) .addComponent(buttonDrawing) .addComponent(buttonCamera)) - .addContainerGap(21, Short.MAX_VALUE)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); panelViewTypeLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonCamera, buttonDrawing}); @@ -1225,18 +1291,15 @@ public class MainPanel extends Panel { basePlatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, basePlatePanelLayout.createSequentialGroup() .addContainerGap() - .addGroup(basePlatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(panelDetection, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(panelLegend, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 234, Short.MAX_VALUE) - .addGroup(basePlatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(panelHexiposi, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(panelViewType, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(basePlatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(panelLegend, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(panelDetection, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 255, Short.MAX_VALUE) + .addGroup(basePlatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(panelHexiposi, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(panelViewType, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap()) ); - - basePlatePanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {panelDetection, panelViewType}); - basePlatePanelLayout.setVerticalGroup( basePlatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, basePlatePanelLayout.createSequentialGroup() @@ -1660,9 +1723,9 @@ public class MainPanel extends Panel { .addGroup(panelDevicesLayout.createSequentialGroup() .addGap(0, 0, 0) .addComponent(devicesPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 25, Short.MAX_VALUE) .addComponent(panelExpert, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(27, Short.MAX_VALUE)) + .addContainerGap(26, Short.MAX_VALUE)) ); panelDevicesLayout.setVerticalGroup( panelDevicesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -1747,7 +1810,7 @@ public class MainPanel extends Panel { panelSamplesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(panelSamplesLayout.createSequentialGroup() .addGap(0, 0, 0) - .addComponent(panelTableSamples) + .addComponent(panelTableSamples, javax.swing.GroupLayout.DEFAULT_SIZE, 676, Short.MAX_VALUE) .addGap(0, 0, 0)) ); panelSamplesLayout.setVerticalGroup( @@ -1861,7 +1924,7 @@ public class MainPanel extends Panel { .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addComponent(panelTop, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGap(0, 0, 0) - .addComponent(panelBottom, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE) + .addComponent(panelBottom, javax.swing.GroupLayout.DEFAULT_SIZE, 79, Short.MAX_VALUE) .addGap(1, 1, 1)) ); }// //GEN-END:initComponents @@ -1887,41 +1950,21 @@ public class MainPanel extends Panel { JComponent dlgDetTextComp; JComponent dlgDetRendererComp; - private void buttonPuckDetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonPuckDetActionPerformed + private void buttonDetectionCalibrateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDetectionCalibrateActionPerformed try { - /* - if ((dlgDetPlot == null) || (!dlgDetPlot.isShowing())){ - dlgDetPlotComp = new ch.psi.pshell.plot.LinePlotJFree(); - ((ch.psi.pshell.plot.LinePlotJFree) dlgDetPlotComp).setTitle(""); - dlgDetPlot = SwingUtils.showDialog(getTopLevel(), "Puck Detection", new Dimension(600,400), dlgDetPlotComp); - } - if ((dlgDetText == null)|| (!dlgDetText.isShowing())){ - dlgDetTextComp = new javax.swing.JTextArea(); - ((javax.swing.JTextArea)dlgDetTextComp).setEditable(false); - dlgDetText = SwingUtils.showDialog(getTopLevel(), "Puck Detection", new Dimension(600,400), dlgDetTextComp); - } - */ - if (!App.isDetached()) { - if ((dlgDetRenderer == null) || (!dlgDetRenderer.isShowing())) { - dlgDetRendererComp = new Renderer(); - ((Renderer) dlgDetRendererComp).setMode(RendererMode.Fit); - dlgDetRenderer = SwingUtils.showDialog(getTopLevel(), "Puck Detection", new Dimension(600, 400), dlgDetRendererComp); - } - } - Controller.getInstance().imageDetectPucks(dlgDetPlotComp, dlgDetRendererComp, dlgDetTextComp); - + this.runAsync("imgproc/NewCoverCalibration", this, false); } catch (Exception ex) { showException(ex); } - }//GEN-LAST:event_buttonPuckDetActionPerformed + }//GEN-LAST:event_buttonDetectionCalibrateActionPerformed - private void buttonClearDetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonClearDetActionPerformed + private void buttonCalibrationPanelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCalibrationPanelActionPerformed try { - Controller.getInstance().clearImageDetection(); + this.evalAsync("cover_detection.set_renderer(show_panel(img))", true); } catch (Exception ex) { showException(ex); } - }//GEN-LAST:event_buttonClearDetActionPerformed + }//GEN-LAST:event_buttonCalibrationPanelActionPerformed private void checkExpertActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkExpertActionPerformed @@ -1973,23 +2016,6 @@ public class MainPanel extends Panel { execute("imgproc/CameraCalibration", null, false, true); }//GEN-LAST:event_buttonCalibrateImageActionPerformed - private void buttonDetectCoverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDetectCoverActionPerformed - try { - execute("cover_detection_debug=True"); - runAsync("imgproc/CoverDetection", null, false).handle((ret, ex) -> { - execute("cover_detection_debug=False", true); - if (ex != null) { - showException((Exception) ex); - } else { - showMessage("Return", String.valueOf(ret)); - } - return ret; - }); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonDetectCoverActionPerformed - private void buttonCalibrateCoverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCalibrateCoverActionPerformed onExpertCommand(null); execute("imgproc/CoverDetectionCalibration", null, false, true); @@ -2033,24 +2059,25 @@ public class MainPanel extends Panel { private javax.swing.JToggleButton btViewRT; private javax.swing.JButton buttonCalibrateCover; private javax.swing.JButton buttonCalibrateImage; + private javax.swing.JButton buttonCalibrationPanel; private javax.swing.JToggleButton buttonCamera; - private javax.swing.JButton buttonClearDet; private javax.swing.JButton buttonConfig; - private javax.swing.JButton buttonDetectCover; + private javax.swing.JButton buttonDetectionCalibrate; private javax.swing.JToggleButton buttonDrawing; private javax.swing.JButton buttonExpertCommands; - private javax.swing.JButton buttonPuckDet; + private javax.swing.ButtonGroup buttonGroup1; private javax.swing.JButton buttonRecovery; private javax.swing.JButton buttonRelease; private javax.swing.JCheckBox checkExpert; private ch.psi.mxsc.DevicesPanel devicesPanel; private javax.swing.Box.Filler filler1; - ch.psi.mxsc.HexiposiPanel hexiposiPanel; + private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel13; private javax.swing.JLabel jLabel15; private javax.swing.JLabel jLabel16; private javax.swing.JLabel jLabel19; + private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel20; private javax.swing.JLabel jLabel23; private javax.swing.JLabel jLabel24; @@ -2104,6 +2131,8 @@ public class MainPanel extends Panel { private javax.swing.JProgressBar progressLN2; private javax.swing.JTable tablePucks; private javax.swing.JTable tableSamples; + private javax.swing.JTextField textCoverDet; + private javax.swing.JTextField textCoverMove; private javax.swing.JTextField textPuckDatamatrix; private javax.swing.JTextField textSampleDatamatrix; // End of variables declaration//GEN-END:variables diff --git a/src/main/java/ch/psi/mxsc/Puck.java b/src/main/java/ch/psi/mxsc/Puck.java index a4226b1..f199840 100644 --- a/src/main/java/ch/psi/mxsc/Puck.java +++ b/src/main/java/ch/psi/mxsc/Puck.java @@ -332,20 +332,7 @@ public class Puck extends DeviceBase { public boolean isSegmentSelected() { - /* - switch(Integer.valueOf(Controller.getInstance().getHexaposiPosition())){ - case 1: return getSegment()=='A'; - case 2: return getSegment()=='B'; - case 3: return getSegment()=='C'; - case 4: return getSegment()=='D'; - case 5: return getSegment()=='E'; - case 6: return getSegment()=='F'; - } - } catch(Exception ex){ - } return false; - */ - return ("" + getSegment()).equalsIgnoreCase(Controller.getInstance().getHexiposiPosition()); } public int getIndex() {