Manage {config} token in -setp option

This commit is contained in:
2018-08-23 09:53:19 +02:00
parent 52a8daf5c0
commit 810740ddca
12 changed files with 624 additions and 534 deletions

View File

@@ -3,8 +3,8 @@
*/
package ch.psi.mxsc;
import ch.psi.mxsc.BasePlate.DrawMode;
import ch.psi.mxsc.BasePlate.SelectionMode;
import ch.psi.mxsc.BasePlateGraphics.DrawMode;
import ch.psi.pshell.device.Device;
import ch.psi.pshell.imaging.Data;
import ch.psi.pshell.imaging.ImageListener;
import ch.psi.pshell.imaging.Source;
@@ -32,6 +32,8 @@ public class BasePlatePanel extends DevicePanel {
JPopupMenu samplePopupMenu;
JMenuItem menuLoadSample;
JMenuItem menuUnloadSample;
BasePlateGraphics basePlateGraphics;
PuckGraphics puckGraphics;
boolean TOGGLE_SELECTION = false;
/**
@@ -65,6 +67,16 @@ public class BasePlatePanel extends DevicePanel {
public BasePlate getDevice() {
return (BasePlate) super.getDevice();
}
@Override
public void setDevice(Device device){
super.setDevice(device);
if (mode==Mode.puck){
basePlateGraphics = null;
} else {
basePlateGraphics = (device==null) ? null : new BasePlateGraphics((BasePlate)device);
}
}
Mode mode = Mode.horizontal;
@@ -85,6 +97,20 @@ public class BasePlatePanel extends DevicePanel {
repaint();
}
enum SelectionMode{
Samples,
Pucks,
None
}
SelectionMode selectionMode = SelectionMode.None;
public SelectionMode getSelectionMode() {
return selectionMode;
}
public void setSelectionMode(SelectionMode selectionMode) {
this.selectionMode = selectionMode;
}
/**
* This method is called from within the constructor to initialize the form. WARNING: Do NOT
@@ -114,6 +140,17 @@ public class BasePlatePanel extends DevicePanel {
Rectangle platePlotRect;
Rectangle puckPlotRect;
Source source;
void createPuckGraphics(){
Puck selectedPuck = getDevice().getSelectedPuck();
if (selectedPuck==null){
puckGraphics=null;
} else {
if ((puckGraphics==null) || (puckGraphics.puck!= selectedPuck)){
puckGraphics = new PuckGraphics(selectedPuck, null);
}
}
}
@Override
public void paint(Graphics g) {
@@ -123,7 +160,7 @@ public class BasePlatePanel extends DevicePanel {
Dimension size = getSize();
if ((size.width > 40) && (size.height > 40)) {
int border = 0;
int borderPuck = 20;
int borderPuck = 0;
Rectangle plotRect = new Rectangle(border, border, size.width - 2 * border, size.height - 2 * border);
Puck selectedPuck = getDevice().getSelectedPuck();
platePlotRect = null;
@@ -133,38 +170,42 @@ public class BasePlatePanel extends DevicePanel {
case single:
platePlotRect = plotRect;
puckPlotRect = null;
getDevice().draw(g2d, platePlotRect, (img==null), false, true, DrawMode.center, img);
basePlateGraphics.draw(g2d, platePlotRect, (img==null), false, true, DrawMode.center, img);
break;
case horizontal:
platePlotRect = new Rectangle(plotRect.x, plotRect.y, plotRect.width / 2, plotRect.height);
getDevice().draw(g2d, platePlotRect, false, true, true, DrawMode.fill, null);
basePlateGraphics.draw(g2d, platePlotRect, false, true, true, DrawMode.fill, null);
if (selectedPuck!=null){
puckPlotRect = new Rectangle(plotRect.x + plotRect.width / 2 + borderPuck, plotRect.y + borderPuck, plotRect.width / 2 - 2 * borderPuck, plotRect.height - 2 * borderPuck);
selectedPuck.draw(g2d, puckPlotRect, true, false, true, null);
createPuckGraphics();
puckGraphics.draw(g2d, puckPlotRect, true, false, true);
}
break;
case vertical:
platePlotRect = new Rectangle(plotRect.x, plotRect.y, plotRect.width, plotRect.height / 2);
getDevice().draw(g2d, platePlotRect, false, true, true, DrawMode.fill, null);
basePlateGraphics.draw(g2d, platePlotRect, false, true, true, DrawMode.fill, null);
if (selectedPuck!=null){
puckPlotRect = new Rectangle(plotRect.x + borderPuck, plotRect.y + plotRect.height / 2 + borderPuck, plotRect.width - 2 * borderPuck, plotRect.height / 2 - 2 * borderPuck);
selectedPuck.draw(g2d, puckPlotRect, true, false, true, null);
createPuckGraphics();
puckGraphics.draw(g2d, puckPlotRect, true, false, true);
}
break;
case overlapped:
//getDevice().draw(g2d, plotRect, false, true);
platePlotRect = new Rectangle(plotRect.x - ((int) (plotRect.width * 0.14)), plotRect.y - ((int) (plotRect.height * 0.14)), (int) (plotRect.width * 1.28), (int) (plotRect.height * 1.28));
getDevice().draw(g2d, platePlotRect, false, true, false, DrawMode.fill, null);
basePlateGraphics.draw(g2d, platePlotRect, false, true, false, DrawMode.fill, null);
if (selectedPuck!=null){
int overlappedSize = (int) (1.5 * selectedPuck.getDrawSize());
createPuckGraphics();
int overlappedSize = (int) (1.5 * puckGraphics.getDrawSize());
puckPlotRect = new Rectangle((int) (plotRect.getCenterX() - overlappedSize / 2), (int) (plotRect.getCenterY() - overlappedSize / 2), overlappedSize, overlappedSize);
selectedPuck.draw(g2d, puckPlotRect, true, false, true, null);
puckGraphics.draw(g2d, puckPlotRect, true, false, true);
}
break;
case puck:
if (selectedPuck!=null){
puckPlotRect = new Rectangle(plotRect.x + borderPuck, plotRect.y + borderPuck, plotRect.width - 2 * borderPuck, plotRect.height - 2 * borderPuck);
selectedPuck.draw(g2d, puckPlotRect, true, true, true, null);
createPuckGraphics();
puckGraphics.draw(g2d, puckPlotRect, true, true, true);
}
break;
}
@@ -273,12 +314,21 @@ public class BasePlatePanel extends DevicePanel {
Sample getSample(int x, int y) {
Point p = new Point(x, y);
for (Puck puck : getDevice().getPucks()){
if (puck.isSelected() || (mode==Mode.single)){
for (Sample sample :puck.getSamples()){
if (sample.getDrawPosition().distance(p) <= (sample.getDrawSize() / 2)) {
return sample;
}
if (puckGraphics!=null){
for (SampleGraphics sample :puckGraphics.sampleGraphics){
if (sample.getDrawPosition().distance(p) <= (sample.getDrawSize() / 2)) {
return sample.sample;
}
}
}
if (basePlateGraphics!=null){
for (PuckGraphics puck : basePlateGraphics.puckGraphics){
if ((mode==Mode.single) || puck.puck.isSelected()){
for (SampleGraphics sample :puck.sampleGraphics){
if (sample.getDrawPosition().distance(p) <= (sample.getDrawSize() / 2)) {
return sample.sample;
}
}
}
}
}
@@ -289,10 +339,20 @@ public class BasePlatePanel extends DevicePanel {
Puck getPuck(int x, int y) {
Point p = new Point(x, y);
for (Puck puck : getDevice().getPucks()){
if (puck.getDrawPosition().distance(p) <= (puck.getDrawSize() / 2)) {
return puck;
}
if (puckGraphics!=null){
if (puckGraphics.getDrawPosition().distance(p) <= (puckGraphics.getDrawSize() / 2)) {
return puckGraphics.puck;
}
}
if (mode == Mode.puck){
return getDevice().getSelectedPuck(); //Won't de-select it by clicking outside
}
if (basePlateGraphics!=null){
for (PuckGraphics puck : basePlateGraphics.puckGraphics){
if (puck.getDrawPosition().distance(p) <= (puck.getDrawSize() / 2)) {
return puck.puck;
}
}
}
return null;
}
@@ -303,7 +363,7 @@ public class BasePlatePanel extends DevicePanel {
}
void selectSample(Sample sample){
if (getDevice().getSelectionMode()==SelectionMode.Samples){
if (getSelectionMode()==SelectionMode.Samples){
sample.setSelected(true);
repaint();
Controller.getInstance().onSamplePressed(sample);
@@ -311,7 +371,7 @@ public class BasePlatePanel extends DevicePanel {
}
void onSamplePressed(MouseEvent e, Sample sample){
if (getDevice().getSelectionMode()==SelectionMode.Samples){
if (getSelectionMode()==SelectionMode.Samples){
if (TOGGLE_SELECTION){
sample.toggleSelected(true);
} else {
@@ -319,7 +379,7 @@ public class BasePlatePanel extends DevicePanel {
}
repaint();
Controller.getInstance().onSamplePressed(sample);
} else if (getDevice().getSelectionMode()==SelectionMode.Pucks){
} else if (getSelectionMode()==SelectionMode.Pucks){
onPuckPressed(e, sample.getPuck());
}
}
@@ -344,7 +404,7 @@ public class BasePlatePanel extends DevicePanel {
}
void selectPuck(Puck puck){
if (getDevice().getSelectionMode()!=SelectionMode.None){
if (getSelectionMode()!=SelectionMode.None){
puck.setSelected(true);
repaint();
Controller.getInstance().onPuckPressed(puck);
@@ -352,7 +412,7 @@ public class BasePlatePanel extends DevicePanel {
}
void onPuckPressed(MouseEvent e, Puck puck){
if (getDevice().getSelectionMode()!=SelectionMode.None){
if (getSelectionMode()!=SelectionMode.None){
if (TOGGLE_SELECTION){
puck.toggleSelected(true);
} else {