/* * Copyright (c) 2014 Paul Scherrer Institute. All rights reserved. */ package ch.psi.mxsc; import ch.psi.pshell.device.Device; import ch.psi.pshell.device.DeviceBase; import ch.psi.pshell.imaging.DimensionDouble; import ch.psi.pshell.imaging.PointDouble; import ch.psi.utils.swing.MainFrame; import java.awt.Color; import java.awt.Graphics2D; import java.awt.Rectangle; import java.io.IOException; import java.util.ArrayList; /** * */ public class BasePlate extends DeviceBase { final static PointDouble[] pucksPosition = new PointDouble[]{ new PointDouble(0, 75), new PointDouble(0, 150), new PointDouble(64.95, 187.5), new PointDouble(129.9, 150), new PointDouble(64.95, 112.5), new PointDouble(64.95, 37.5), new PointDouble(129.9, 75), new PointDouble(194.85, 37.5), new PointDouble(194.85, -37.5), new PointDouble(129.9, 0), new PointDouble(64.95, -37.5), new PointDouble(129.9, -75), new PointDouble(129.9, -150), new PointDouble(64.95, -187.5), new PointDouble(64.95, -112.5), new PointDouble(0, -75), new PointDouble(0, -150), new PointDouble(-64.95, -187.5), new PointDouble(-129.9, -150), new PointDouble(-64.95, -112.5), new PointDouble(-64.95, -37.5), new PointDouble(-129.9, -75), new PointDouble(-194.85, -37.5), new PointDouble(-194.85, 37.5), new PointDouble(-129.9, 0), new PointDouble(-64.95, 37.5), new PointDouble(-129.9, 75), new PointDouble(-129.9, 150), new PointDouble(-64.95, 187.5), new PointDouble(-64.95, 112.5) }; 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); BasePlate() { super("BasePlate", new BasePlateConfig()); ArrayList pucks = new ArrayList<>(); for (int i = 0; i < numberOfPucks; i++) { new Puck(this, i); } getPucks()[0].setSelected(true); } @Override protected void doInitialize() throws IOException, InterruptedException { super.doInitialize(); } @Override public BasePlateConfig getConfig() { return (BasePlateConfig) super.getConfig(); } public Puck[] getPucks() { ArrayList ret = new ArrayList<>(); for (Device d : getChildren()) { ret.add((Puck) d); } return ret.toArray(new Puck[0]); } Puck getSelectedPuck(){ for (Puck p:getPucks()){ if (p.isSelected()){ return p; } } return null; } Sample getSelectedSample(){ Puck puck = getSelectedPuck(); if (puck != null){ for (Sample s: puck.getSamples()){ if (s.isSelected()){ return s; } } } return null; } Sample getLoadedSample(){ for (Puck p:getPucks()){ for (Sample s: p.getSamples()){ if (s.isLoaded()){ return s; } } } return null; } void resetLoadedSample(){ for (Puck p:getPucks()){ for (Sample s: p.getSamples()){ s.setLoaded(false); } } } DimensionDouble getSize(){ return size; } public int getNumberOfPucks() { return numberOfPucks; } public PointDouble getPuckPosition(Puck puck) { return pucksPosition[puck.index]; } Rectangle plotRect = new Rectangle(0, 0, 0, 0); public Rectangle getPlotRect() { return plotRect; } Color getBorderColor() { //return new Color(32,32,32); return MainFrame.isDark() ? new Color(32,32,32) : Color.DARK_GRAY; } Color getColor() { return MainFrame.isDark() ? new Color(67,71,73) /*new Color(65,81,109)*/ : new Color(200, 204, 213); } boolean drawContour; void draw(Graphics2D g, Rectangle plotRect, boolean drawSamples, boolean drawIds, boolean drawContour) { this.plotRect = plotRect; this.drawContour = drawContour; if (drawContour){ g.setColor(getColor()); g.fillOval((int)(plotRect.width*0.05), (int)(plotRect.height * 0.05), (int)(plotRect.width*0.90), (int)(plotRect.height*0.90)); g.setColor(getBorderColor()); g.drawOval((int)(plotRect.width*0.05), (int)(plotRect.height * 0.05), (int)(plotRect.width*0.90), (int)(plotRect.height*0.90)); } for (Puck puck : getPucks()) { puck.draw(g, null, drawSamples, drawIds, this) ; } } public void loadSample(Sample sample) throws Exception{ Sample loaded = getLoadedSample(); if (loaded !=null){ throw new Exception("Sample already loaded: " + loaded); } if (sample!=null){ resetLoadedSample(); //TODO sample.setLoaded(true); } } public void unloadSample(Sample sample) throws Exception{ if (sample!=null){ //TODO resetLoadedSample(); } } public void loadSample() throws Exception{ loadSample(getSelectedSample()); } public void unloadSample() throws Exception{ unloadSample (getLoadedSample()); } }