This commit is contained in:
gac-S_Changer
2017-02-10 16:34:00 +01:00
parent 4ccd5f6ca1
commit 69e745730d
13 changed files with 1382 additions and 1038 deletions

View File

@@ -0,0 +1,147 @@
/*
* 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 java.awt.Color;
import java.awt.Dimension;
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<Puck> pucks = new ArrayList<>();
for (int i = 0; i < numberOfPucks; i++) {
Puck puck = new Puck();
puck.index = i;
puck.basePlate = this;
this.addChild(puck);
}
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<Puck> 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;
}
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;
}
void draw(Graphics2D g, Rectangle plotRect, boolean drawSamples, boolean drawIds, boolean drawContour) {
this.plotRect = plotRect;
g.setColor(Color.BLACK);
if (drawContour){
//int size = Math.min(plotRect.width, plotRect.height);
//g.drawOval((int)(plotRect.getCenterX() - size/2),(int)(plotRect.getCenterY() - size/2), size, size);
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) ;
}
}
}