262 lines
7.8 KiB
Java
262 lines
7.8 KiB
Java
/*
|
|
* Copyright (c) 2014 Paul Scherrer Institute. All rights reserved.
|
|
*/
|
|
package ch.psi.mxsc;
|
|
|
|
import ch.psi.mxsc.MainPanel.BasePlateLayout;
|
|
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.io.IOException;
|
|
import java.util.ArrayList;
|
|
|
|
/**
|
|
*
|
|
*/
|
|
public class BasePlate extends DeviceBase {
|
|
|
|
public enum WiringSetup {
|
|
natural,
|
|
sf
|
|
}
|
|
|
|
//TODO: Fix SF only to change address based on BASE_PLATE_LAYOUT
|
|
final static PointDouble[] pucksPosition = (MainPanel.BASE_PLATE_LAYOUT == BasePlateLayout.normal)
|
|
? new PointDouble[]{
|
|
new PointDouble(0, 75),
|
|
new PointDouble(0, 150),
|
|
new PointDouble(-64.95, 112.5),
|
|
new PointDouble(-64.95, 187.5),
|
|
new PointDouble(-129.9, 150),
|
|
new PointDouble(-64.95, 37.5),
|
|
new PointDouble(-129.9, 75),
|
|
new PointDouble(-129.9, 0),
|
|
new PointDouble(-194.85, 37.5),
|
|
new PointDouble(-194.85, -37.5),
|
|
new PointDouble(-64.95, -37.5),
|
|
new PointDouble(-129.9, -75),
|
|
new PointDouble(-64.95, -112.5),
|
|
new PointDouble(-129.9, -150),
|
|
new PointDouble(-64.95, -187.5),
|
|
new PointDouble(0, -75),
|
|
new PointDouble(0, -150),
|
|
new PointDouble(64.95, -112.5),
|
|
new PointDouble(64.95, -187.5),
|
|
new PointDouble(129.9, -150),
|
|
new PointDouble(64.95, -37.5),
|
|
new PointDouble(129.9, -75),
|
|
new PointDouble(129.9, 0),
|
|
new PointDouble(194.85, -37.5),
|
|
new PointDouble(194.85, 37.5),
|
|
new PointDouble(64.95, 37.5),
|
|
new PointDouble(129.9, 75),
|
|
new PointDouble(64.95, 112.5),
|
|
new PointDouble(129.9, 150),
|
|
new PointDouble(64.95, 187.5),}
|
|
: 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(470.0, 470.0);
|
|
|
|
BasePlate() {
|
|
super("BasePlate", new BasePlateConfig());
|
|
ArrayList<Puck> 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<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;
|
|
}
|
|
|
|
Puck.Detection[] getDetection() {
|
|
Puck.Detection[] ret = new Puck.Detection[Controller.NUMBER_OF_PUCKS];
|
|
for (int i = 0; i < ret.length; i++) {
|
|
ret[i] = getPucks()[i].detection;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
Sample getSelectedSample() {
|
|
Puck puck = getSelectedPuck();
|
|
if (puck != null) {
|
|
for (Sample s : puck.getSamples()) {
|
|
if (s.isSelected()) {
|
|
return s;
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
void resetSelection() {
|
|
Puck puck = getSelectedPuck();
|
|
if (puck != null) {
|
|
puck.setSelected(false);
|
|
}
|
|
}
|
|
|
|
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];
|
|
}
|
|
|
|
public Puck getPuckByName(String name) {
|
|
for (Device d : getChildren()) {
|
|
if (d.getName().equals(name)) {
|
|
return (Puck) d;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public Sample getSampleByName(String name) {
|
|
try {
|
|
Puck p = getPuckByName(name.substring(0, 2));
|
|
if (p != null) {
|
|
return p.getSamples()[Integer.valueOf(name.substring(2, name.length())) - 1];
|
|
}
|
|
} catch (Exception ex) {
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public void clearId(String id) {
|
|
for (Device d : getChildren()) {
|
|
if (d instanceof Puck) {
|
|
if ((id == null) || id.equals(((Puck) d).getId())) {
|
|
((Puck) d).setId(null);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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());
|
|
}
|
|
|
|
void onSelectionChanged() {
|
|
Sample sample = getSelectedSample();
|
|
if (sample != null) {
|
|
//setCache(sample.getName());
|
|
setCache(new Object[]{sample.getPuck().segment, sample.getPuck().number, sample.index + 1});
|
|
} else {
|
|
Puck puck = getSelectedPuck();
|
|
if (puck != null) {
|
|
//setCache(puck.getName());
|
|
setCache(new Object[]{puck.segment, puck.number, null});
|
|
} else {
|
|
setCache(null);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|