From 4dae79a3cac3ba304275b76e8106f4368880446c Mon Sep 17 00:00:00 2001 From: Alexandre Gobbo Date: Fri, 27 Apr 2018 15:28:46 +0200 Subject: [PATCH] --- src/main/java/ch/psi/mxsc/BasePlate.java | 12 +- src/main/java/ch/psi/mxsc/HexiposiPanel.java | 7 +- src/main/java/ch/psi/mxsc/MainPanel.java | 3 +- src/main/java/ch/psi/mxsc/Puck.java | 366 +++++++++++-------- src/main/java/ch/psi/mxsc/Sample.java | 10 +- 5 files changed, 236 insertions(+), 162 deletions(-) diff --git a/src/main/java/ch/psi/mxsc/BasePlate.java b/src/main/java/ch/psi/mxsc/BasePlate.java index 52fbde2..e132973 100644 --- a/src/main/java/ch/psi/mxsc/BasePlate.java +++ b/src/main/java/ch/psi/mxsc/BasePlate.java @@ -57,7 +57,7 @@ public class BasePlate extends DeviceBase { }; final static int numberOfPucks = pucksPosition.length; //final static DimensionDouble size = new DimensionDouble(580.0, 580.0); - final static DimensionDouble size = new DimensionDouble(580.0, 580.0); + final static DimensionDouble size = new DimensionDouble(470.0, 470.0); BasePlate() { super("BasePlate", new BasePlateConfig()); @@ -156,11 +156,16 @@ public class BasePlate extends DeviceBase { Rectangle plotRect = new Rectangle(0, 0, 0, 0); - + Rectangle boundingBox; + public Rectangle getPlotRect() { return plotRect; } + public Rectangle getBoundingBox() { + return boundingBox; + } + Color getBorderColor(boolean drawBackground) { //return new Color(32,32,32); if (drawBackground){ @@ -174,6 +179,7 @@ public class BasePlate extends DeviceBase { } boolean drawContour; + enum DrawMode{ fill, @@ -207,7 +213,7 @@ public class BasePlate extends DeviceBase { } this.plotRect = plotRect; this.drawContour = drawContour; - Rectangle 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)); + 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)); if (img!=null){ img = Utils.stretch(img, boundingBox.width, boundingBox.height); g.drawImage(img, boundingBox.x, boundingBox.y, null); diff --git a/src/main/java/ch/psi/mxsc/HexiposiPanel.java b/src/main/java/ch/psi/mxsc/HexiposiPanel.java index b08a71e..1c44fbc 100644 --- a/src/main/java/ch/psi/mxsc/HexiposiPanel.java +++ b/src/main/java/ch/psi/mxsc/HexiposiPanel.java @@ -31,7 +31,12 @@ public class HexiposiPanel extends DevicePanel { ledD.setColor("D".equals(value) ? COLOR_ON: COLOR_OFF); ledE.setColor("E".equals(value) ? COLOR_ON: COLOR_OFF); ledF.setColor("F".equals(value) ? COLOR_ON: COLOR_OFF); - textPosition.setText((value==null) ? " " : (value+" ").substring(0, 1)); + if ((value==null) || (value.toString().trim().isEmpty()) || (value.toString().equalsIgnoreCase("Unknown"))){ + textPosition.setText(""); + } else { + textPosition.setText((value.toString()).substring(0, 1)); + } + repaint(); } diff --git a/src/main/java/ch/psi/mxsc/MainPanel.java b/src/main/java/ch/psi/mxsc/MainPanel.java index af5bdf7..57ed55b 100644 --- a/src/main/java/ch/psi/mxsc/MainPanel.java +++ b/src/main/java/ch/psi/mxsc/MainPanel.java @@ -668,7 +668,8 @@ public class MainPanel extends Panel { private void buttonExpertActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonExpertActionPerformed try{ - getContext().getPluginManager().loadInitializePlugin(getContext().getSetup().expandPath("{plugins}/Expert.java")); + this.showRenderer("img"); + //getContext().getPluginManager().loadInitializePlugin(getContext().getSetup().expandPath("{plugins}/Expert.java")); } catch (Exception ex) { showException(ex); } diff --git a/src/main/java/ch/psi/mxsc/Puck.java b/src/main/java/ch/psi/mxsc/Puck.java index 324578d..dbeb40f 100644 --- a/src/main/java/ch/psi/mxsc/Puck.java +++ b/src/main/java/ch/psi/mxsc/Puck.java @@ -23,82 +23,99 @@ import java.util.ArrayList; * */ public class Puck extends DeviceBase { + final static PointDouble[] samplesPosition = new PointDouble[]{ - new PointDouble(0, 24.24), - new PointDouble(23.05360995, 7.490571944), - new PointDouble(14.24791452, -19.61057194), - new PointDouble(-14.24791452, -19.61057194), - new PointDouble(-23.05360995, 7.490571944), - new PointDouble(0, 52.52), - new PointDouble(28.39445573, 44.18263554), - new PointDouble(47.7738724, 21.81759648), - new PointDouble(51.98542213, -7.474375306), - new PointDouble(39.69196765, -34.39328575), - new PointDouble(14.79659389, -50.39257097), - new PointDouble(-14.79659389, -50.39257097), - new PointDouble(-39.69196765, -34.39328575), - new PointDouble(-51.98542213, -7.474375306), - new PointDouble(-47.7738724, 21.81759648), - new PointDouble(-28.39445573, 44.18263554) - }; - - static final Character[] SEGMENTS = new Character[]{ 'A', 'A', - 'F', 'F','F','F','F', - 'E', 'E','E','E','E', - 'D', 'D','D','D','D', - 'C', 'C','C','C','C', - 'B', 'B','B','B','B', - 'A', 'A', 'A'}; - static final int[] NUMBERS = new int[] { 1, 2, - 5, 4, 3, 1, 2, - 5, 4, 3, 1, 2, - 5, 4, 3, 1, 2, - 5, 4, 3, 1, 2, - 5, 4, 3, 1, 2, - 5, 4, 3}; - static final int[] ADDRESSES = new int[] { 6, 7, - 5, 4, 3, 1, 2, - 20, 19, 18, 16, 17, - 15, 14, 13, 11, 12, - 30, 29, 28, 26, 27, - 25, 24, 23, 21, 22, - 10, 9, 8}; - - final static PointDouble referencePosition = new PointDouble(0.0, -66.9 - 0.2); - final static Double referenceSize = 6.2 + 0.2; - - final int numberOfSamples = samplesPosition.length; - + new PointDouble(0, 24.24), + new PointDouble(23.05360995, 7.490571944), + new PointDouble(14.24791452, -19.61057194), + new PointDouble(-14.24791452, -19.61057194), + new PointDouble(-23.05360995, 7.490571944), + new PointDouble(0, 52.52), + new PointDouble(28.39445573, 44.18263554), + new PointDouble(47.7738724, 21.81759648), + new PointDouble(51.98542213, -7.474375306), + new PointDouble(39.69196765, -34.39328575), + new PointDouble(14.79659389, -50.39257097), + new PointDouble(-14.79659389, -50.39257097), + new PointDouble(-39.69196765, -34.39328575), + new PointDouble(-51.98542213, -7.474375306), + new PointDouble(-47.7738724, 21.81759648), + new PointDouble(-28.39445573, 44.18263554) + }; + + static final Character[] SEGMENTS = new Character[]{'A', 'A', + 'F', 'F', 'F', 'F', 'F', + 'E', 'E', 'E', 'E', 'E', + 'D', 'D', 'D', 'D', 'D', + 'C', 'C', 'C', 'C', 'C', + 'B', 'B', 'B', 'B', 'B', + 'A', 'A', 'A'}; + static final int[] NUMBERS = new int[]{1, 2, + 5, 4, 3, 1, 2, + 5, 4, 3, 1, 2, + 5, 4, 3, 1, 2, + 5, 4, 3, 1, 2, + 5, 4, 3, 1, 2, + 5, 4, 3}; + static final int[] ADDRESSES = new int[]{6, 7, + 5, 4, 3, 1, 2, + 20, 19, 18, 16, 17, + 15, 14, 13, 11, 12, + 30, 29, 28, 26, 27, + 25, 24, 23, 21, 22, + 10, 9, 8}; + + static final double[] ANGLES = new double[]{ + 0.00, 0.00, 19.11, 40.89, 30.00, + 60.00, 60.00, 79.11, 100.89, 90.00, + 120.00, 120.00, 139.11, 160.89, 150.00, + 180.00, 180.00, 199.11, 220.89, 210.00, + 240.00, 240.00, 259.11, 280.89, 270.00, + 300.00, 300.00, 319.11, 340.89, 330.00}; + + final static PointDouble referencePosition = new PointDouble(0.0, -66.9 - 0.2); + final static Double referenceSize = 6.2 + 0.2; + final static PointDouble ledUnipuckPosition = new PointDouble(0.0, 0.0); + final static PointDouble ledMinispinePosition = new PointDouble(0.0, -36.0); + final static Double unipuckLedSize = 10.0; + final static Double minispineLedSize = 8.0; + final static PointDouble labelPositionWithImage = new PointDouble(0.0, 36.0); + public double getAngle() { + return ANGLES[index]; + } + + final int numberOfSamples = samplesPosition.length; + final int index; Character segment; final int address; - final int number; - + final int number; + final double angle; + Puck(BasePlate basePlate, int index) { //super(String.valueOf(index+1)); - super(SEGMENTS[index] + "" + NUMBERS[index]); + super(SEGMENTS[index] + "" + NUMBERS[index]); this.setParent(basePlate); this.index = index; - this.segment = SEGMENTS[index]; - this.number = NUMBERS[index]; - this.address = ADDRESSES[index]; - for (int i =0; i< numberOfSamples; i++){ - new Sample(this, i); + this.segment = SEGMENTS[index]; + this.number = NUMBERS[index]; + this.address = ADDRESSES[index]; + this.angle = getAngle(); + for (int i = 0; i < numberOfSamples; i++) { + new Sample(this, i); } - } + } public BasePlate getBasePlate() { return (BasePlate) getParent(); } - - DimensionDouble getSize(){ + + DimensionDouble getSize() { return new DimensionDouble(67.0, 67.0); } - - - + public Sample[] getSamples() { ArrayList ret = new ArrayList<>(); for (Device d : getChildren()) { @@ -107,11 +124,53 @@ public class Puck extends DeviceBase { return ret.toArray(new Sample[0]); } + public PointDouble getRotatedPosition(PointDouble ref) { + double rotation = - angle * Math.PI / 180.0; + double x = ref.x * Math.cos(rotation) - ref.y * Math.sin(rotation); + double y = ref.y * Math.cos(rotation) + ref.x * Math.sin(rotation); + return new PointDouble(x,y ); + } + public PointDouble getSamplePosition(Sample sample) { + //PointDouble ref = samplesPosition[sample.index]; + //return getRotatedPosition(ref); return samplesPosition[sample.index]; } + + public Point getDrawUnipuckLedPosition(){ + PointDouble ref = ledUnipuckPosition; + return getDrawPosition(ref); + } - public boolean isSegmentSelected(){ + public Point getDrawMinispineLedPosition(){ + PointDouble ref = ledMinispinePosition; + return getDrawPosition(ref); + } + + + int getUnipuckLedSize() { + return getDrawSize(unipuckLedSize) ; + } + + int getMinispineLedSize() { + return getDrawSize(minispineLedSize) ; + } + + int getDrawSize(double refSize) { + return (int) ((refSize / getSize().getWidth()) * getDrawSize()) ; + } + + Point getDrawPosition(PointDouble refPosition) { + Point puckCenter = getDrawPosition(); + int puckDrawSize = getDrawSize(); + DimensionDouble puckSize = getSize(); + PointDouble pos = getRotatedPosition(refPosition); + return new Point( (int) ((pos.x / puckSize.getWidth())* puckDrawSize/2 + puckCenter.x) , + (int) ((pos.y / puckSize.getHeight())* puckDrawSize/2 + puckCenter.y) ); + } + + + public boolean isSegmentSelected() { /* switch(Integer.valueOf(Controller.getInstance().getHexaposiPosition())){ case 1: return getSegment()=='A'; @@ -124,11 +183,11 @@ public class Puck extends DeviceBase { } catch(Exception ex){ } return false; -*/ + */ return ("" + getSegment()).equalsIgnoreCase(Controller.getInstance().getHexiposiPosition()); } - - public boolean isHighlithted(){ + + public boolean isHighlithted() { return isSelected() || isSegmentSelected(); } @@ -145,19 +204,19 @@ public class Puck extends DeviceBase { public void setId(String value) { id = value; } - - public char getSegment(){ + + public char getSegment() { return segment; } - + public int getNumber() { return number; } public int getAddress() { return address; - } - + } + boolean enabled; public boolean isEnabled() { @@ -167,20 +226,22 @@ public class Puck extends DeviceBase { public void setEnabled(boolean value) { enabled = value; } - - public enum Detection{ + + public enum Detection { Empty, Present, Offline, Error } - + Detection detection = Detection.Error; + public Detection getDetection() { return detection; } - + boolean detectionError; + public boolean isDetectionError() { return detectionError; } @@ -192,18 +253,18 @@ public class Puck extends DeviceBase { } public void setSelected(boolean value) { - if (value != selected){ - if (value == true){ - for (Device d : getParent().getChildren()){ - if (d instanceof Puck){ - ((Puck)d).selected = false; + if (value != selected) { + if (value == true) { + for (Device d : getParent().getChildren()) { + if (d instanceof Puck) { + ((Puck) d).selected = false; } } - } - for (Sample sample: getSamples()) { + } + for (Sample sample : getSamples()) { sample.selected = false; } - selected = value; + selected = value; } } @@ -213,7 +274,7 @@ public class Puck extends DeviceBase { Color getColor() { Color ret = Color.LIGHT_GRAY; - switch (detection){ + switch (detection) { case Empty: ret = isHighlithted() ? new Color(224, 224, 224) : Color.LIGHT_GRAY; break; @@ -226,7 +287,7 @@ public class Puck extends DeviceBase { case Offline: ret = isHighlithted() ? new Color(250, 255, 48) : new Color(253, 194, 41); //ret = isHighlithted() ? new Color(230, 142, 40) : new Color(216, 159, 93); - break; + break; } return ret; @@ -234,15 +295,15 @@ public class Puck extends DeviceBase { int getDrawSize() { //Single puck plot - if (plotRect != null){ + if (plotRect != null) { return Math.min(plotRect.width, plotRect.height); } //All pucks - Rectangle plotRect = getBasePlate().getPlotRect(); - int ret = Math.min( - (int)((getSize().getWidth() / getBasePlate().getSize().getWidth()) * plotRect.width), - (int)((getSize().getHeight() / getBasePlate().getSize().getHeight()) * plotRect.height) - ); + Rectangle plotRect = getBasePlate().getBoundingBox(); + int ret = Math.min( + (int) ((getSize().getWidth() / getBasePlate().getSize().getWidth()) * plotRect.width), + (int) ((getSize().getHeight() / getBasePlate().getSize().getHeight()) * plotRect.height) + ); if (isHighlithted()) { ret += 2; } @@ -251,122 +312,129 @@ public class Puck extends DeviceBase { Point getDrawPosition() { //Single puck plot - if (plotRect != null){ - return new Point((int)plotRect.getCenterX(), (int)plotRect.getCenterY()); + if (plotRect != null) { + return new Point((int) plotRect.getCenterX(), (int) plotRect.getCenterY()); } //All pucks - Rectangle plotRect = getBasePlate().getPlotRect(); + Rectangle plotRect = getBasePlate().getBoundingBox(); DimensionDouble plateSize = getBasePlate().getSize(); PointDouble pos = getBasePlate().getPuckPosition(this); - return new Point( (int) ((pos.x / plateSize.getWidth())*plotRect.width + plotRect.getCenterX()) , - (int) ((pos.y / plateSize.getHeight())*plotRect.height + plotRect.getCenterY()) + return new Point((int) ((pos.x / plateSize.getWidth()) * plotRect.width + plotRect.getCenterX()), + (int) ((pos.y / plateSize.getHeight()) * plotRect.height + plotRect.getCenterY()) ); } Color getLabelColor(boolean drawBackground) { - return drawBackground ? (isHighlithted() ? Color.BLACK : new Color(92, 92, 92)) : (isHighlithted() ? new Color (0,255,0) : new Color (0,162,0)); - + return drawBackground ? (isHighlithted() ? Color.BLACK : new Color(92, 92, 92)) : (isHighlithted() ? new Color(0, 255, 0) : new Color(0, 162, 0)); + } - + Font getLabelFont() { - if (plotRect != null){ + if (plotRect != null) { return new Font("Times New Roman", Font.BOLD, 18); - } + } return new Font("Times New Roman", Font.BOLD, 10); - } + } Font getIdFont() { - if (plotRect != null){ + if (plotRect != null) { return new Font("Times New Roman", Font.PLAIN, 12); - } + } return new Font("Times New Roman", Font.PLAIN, 9); - } - - Point getLabelPosition(String text, Graphics g) { - Point center = getDrawPosition(); - Dimension textSize = SwingUtils.getTextSize(text, g.getFontMetrics()); - return new Point(center.x - textSize.width / 2, center.y + (g.getFontMetrics().getAscent()/2)); } + Point getLabelDrawPosition(String text, Graphics g, boolean drawBackground) { + Point pos = drawBackground ? getDrawPosition() : getDrawPosition(labelPositionWithImage); + Dimension textSize = SwingUtils.getTextSize(text, g.getFontMetrics()); + return new Point(pos.x - textSize.width / 2, pos.y + (g.getFontMetrics().getAscent() / 2)); + } + Color getBorderColor(boolean drawBackground) { - if (drawBackground){ + if (drawBackground) { /*if (!isEnabled()){ return Color.GRAY; - } else */ - if (isHighlithted()){ - return new Color(0,0,0); - } + } else */ + if (isHighlithted()) { + return new Color(0, 0, 0); + } return Color.GRAY; } - return isHighlithted() ? new Color(0,208,0) : new Color(0,128,0); - } - - int getBorderWidth(boolean drawBackground) { - return drawBackground ? isHighlithted() ? 2 : 1: isHighlithted() ? 2 : 1 ; - } - - int getReferenceDrawSize() { - return (int)((referenceSize / getSize().getWidth()) * getDrawSize()); + return isHighlithted() ? new Color(0, 208, 0) : new Color(0, 128, 0); + } + + int getBorderWidth(boolean drawBackground) { + return drawBackground ? isHighlithted() ? 2 : 1 : isHighlithted() ? 2 : 1; + } + + int getReferenceDrawSize() { + return getDrawSize(referenceSize) ; } - Point getReferenceDrawPosition() { - Point puckCenter = getDrawPosition(); - int puckDrawSize = getDrawSize(); - DimensionDouble puckSize = getSize(); - int size = getReferenceDrawSize(); - return new Point( (int) ((referencePosition.x / puckSize.getWidth())* puckDrawSize/2 + puckCenter.x) , - (int) ((referencePosition.y / puckSize.getHeight())* puckDrawSize/2 + puckCenter.y) ); - } - - + return getDrawPosition(new PointDouble(0, -67.0)); + + } + Rectangle plotRect; - void draw (Graphics2D g, Rectangle plotRect, boolean drawSamples, boolean drawId, boolean drawBackground, BasePlate enclosingPlate){ + + void draw(Graphics2D g, Rectangle plotRect, boolean drawSamples, boolean drawId, boolean drawBackground, BasePlate enclosingPlate) { this.plotRect = plotRect; Point position = getDrawPosition(); int size = getDrawSize(); - if (drawBackground){ + if (drawBackground) { g.setColor(getColor()); g.fillOval(position.x - size / 2, position.y - size / 2, size, size); } g.setColor(getBorderColor(drawBackground)); - g.setStroke(new BasicStroke(getBorderWidth(drawBackground))); + g.setStroke(new BasicStroke(getBorderWidth(drawBackground))); g.drawOval(position.x - size / 2, position.y - size / 2, size, size); g.setStroke(new BasicStroke(1f)); - if (drawSamples){ + if (drawSamples) { //Draw samples - for (Sample sample: getSamples()) { + for (Sample sample : getSamples()) { sample.draw(g, drawBackground); } } - + //Draw reference - Color refColor = MainFrame.isDark() ? Color.DARK_GRAY : new Color(214,217,223); - if ((enclosingPlate!=null) && enclosingPlate.drawContour){ + Color refColor = MainFrame.isDark() ? Color.DARK_GRAY : new Color(214, 217, 223); + if ((enclosingPlate != null) && enclosingPlate.drawContour) { refColor = enclosingPlate.getColor(); - } + } - g.setColor(refColor); - position = getReferenceDrawPosition(); - size = getReferenceDrawSize(); if (drawBackground){ - g.fillArc(position.x - size / 2, position.y - size / 2, size, size, 180, 180); + g.setColor(refColor); + position = getReferenceDrawPosition(); + size = getReferenceDrawSize(); + //size+=1; + g.fillArc(position.x - size / 2, position.y - size / 2 , size, size, (int) (180 + angle), 180); + g.setColor(getBorderColor(drawBackground)); + g.drawArc(position.x - size / 2, position.y - size / 2 , size, size, (int) (180 + angle), 180); + } else { + Point pu = getDrawUnipuckLedPosition(); + Point pm = getDrawMinispineLedPosition(); + int unipuckSize = getUnipuckLedSize(); + int minispineSize = getMinispineLedSize(); + g.setColor(getBorderColor(drawBackground)); + g.drawOval(pu.x - unipuckSize / 2, pu.y - unipuckSize / 2, unipuckSize, unipuckSize); + g.drawOval(pm.x - minispineSize / 2, pm.y - minispineSize / 2, minispineSize, minispineSize); } //Draw text String text = getName(); //String.valueOf(getIndex() + 1); - Point labelPosition = getLabelPosition(text, g); + Point labelPosition = getLabelDrawPosition(text, g, drawBackground); g.setColor(getLabelColor(drawBackground)); g.setFont(getLabelFont()); - g.drawString(text, labelPosition.x, labelPosition.y); - if (drawId){ + g.drawString(text, labelPosition.x, labelPosition.y); + if (drawId) { String id = getId(); - if (id!=null) { + if (id != null) { labelPosition.setLocation(labelPosition.x, labelPosition.y - 6); g.setFont(getIdFont()); - Dimension textSize = SwingUtils.getTextSize(id, g.getFontMetrics()); + Dimension textSize = SwingUtils.getTextSize(id, g.getFontMetrics()); g.drawString(id, getDrawPosition().x - textSize.width/2 , getDrawPosition().y + 10 ); } } } + } diff --git a/src/main/java/ch/psi/mxsc/Sample.java b/src/main/java/ch/psi/mxsc/Sample.java index dcbd8b0..f970443 100644 --- a/src/main/java/ch/psi/mxsc/Sample.java +++ b/src/main/java/ch/psi/mxsc/Sample.java @@ -119,7 +119,7 @@ public class Sample extends DeviceBase { } int getNormalDrawSize() { - return (int)((getSize().getWidth() / getPuck().getSize().getWidth()) * getPuck().getDrawSize()); + return getPuck().getDrawSize(getSize().getWidth() ); } int getDrawSize() { int ret = getNormalDrawSize(); @@ -130,13 +130,7 @@ public class Sample extends DeviceBase { } Point getDrawPosition() { - Point puckCenter = getPuck().getDrawPosition(); - int puckDrawSize = getPuck().getDrawSize(); - DimensionDouble puckSize = getPuck().getSize(); - int size = getDrawSize(); - PointDouble pos = getPuck().getSamplePosition(this); - return new Point( (int) ((pos.x / puckSize.getWidth())* puckDrawSize/2 + puckCenter.x) , - (int) ((pos.y / puckSize.getHeight())* puckDrawSize/2 + puckCenter.y) ); + return getPuck().getDrawPosition(getPuck().getSamplePosition(this)); }