use of java.awt.geom.Point2D in project JMRI by JMRI.
the class LayoutEditorAuxTools method updateBlockConnectivity.
/**
* Updates the block connectivity (block boundaries) for a Layout Editor
* panel after changes may have been made.
*/
private void updateBlockConnectivity() {
int sz = cList.size();
boolean[] found = new boolean[sz];
for (int i = 0; i < sz; i++) {
found[i] = false;
}
LayoutBlock blk1 = null;
LayoutBlock blk2 = null;
LayoutConnectivity c = null;
Point2D p1;
Point2D p2;
// Check for block boundaries at positionable points.
if (layoutEditor.pointList.size() > 0) {
TrackSegment ts1 = null;
TrackSegment ts2 = null;
for (PositionablePoint p : layoutEditor.pointList) {
if (p.getType() == PositionablePoint.ANCHOR) {
// within PositionablePoints, only ANCHOR points can be block boundaries
ts1 = p.getConnect1();
ts2 = p.getConnect2();
if ((ts1 != null) && (ts2 != null)) {
blk1 = ts1.getLayoutBlock();
blk2 = ts2.getLayoutBlock();
if ((blk1 != null) && (blk2 != null) && (blk1 != blk2)) {
// this is a block boundary, create a LayoutConnectivity
c = new LayoutConnectivity(blk1, blk2);
// determine direction from block 1 to block 2
if (ts1.getConnect1() == p) {
p1 = layoutEditor.getCoords(ts1.getConnect2(), ts1.getType2());
} else {
p1 = layoutEditor.getCoords(ts1.getConnect1(), ts1.getType1());
}
if (ts2.getConnect1() == p) {
p2 = layoutEditor.getCoords(ts2.getConnect2(), ts2.getType2());
} else {
p2 = layoutEditor.getCoords(ts2.getConnect1(), ts2.getType1());
}
c.setDirection(computeDirection(p1, p2));
// save Connections
c.setConnections(ts1, ts2, LayoutTrack.TRACK, p);
// add to list, if not already present
checkConnectivity(c, found);
}
}
} else if (p.getType() == PositionablePoint.EDGE_CONNECTOR) {
//Need to find a way to compute the direction for this for a split over the panel
ts1 = p.getConnect1();
ts2 = p.getConnect2();
if ((ts1 != null) && (ts2 != null)) {
blk1 = ts1.getLayoutBlock();
blk2 = ts2.getLayoutBlock();
if ((blk1 != null) && (blk2 != null) && (blk1 != blk2)) {
// this is a block boundary, create a LayoutConnectivity
c = new LayoutConnectivity(blk1, blk2);
// determine direction from block 1 to block 2
if (ts1.getConnect1() == p) {
p1 = layoutEditor.getCoords(ts1.getConnect2(), ts1.getType2());
} else {
p1 = layoutEditor.getCoords(ts1.getConnect1(), ts1.getType1());
}
//In this instance work out the direction of the first track relative to the positionable poin.
c.setDirection(computeDirection(p1, p.getCoords()));
// save Connections
c.setConnections(ts1, ts2, LayoutTrack.TRACK, p);
// add to list, if not already present
checkConnectivity(c, found);
}
}
}
}
}
// Check for block boundaries at layout turnouts and level crossings
if (layoutEditor.trackList.size() > 0) {
LayoutTurnout lt = null;
int type = 0;
LevelXing lx = null;
LayoutSlip ls = null;
for (TrackSegment ts : layoutEditor.trackList) {
// ensure that block is assigned
blk1 = ts.getLayoutBlock();
if (blk1 != null) {
// check first connection for turnout or level crossing
if ((ts.getType1() >= LayoutTrack.TURNOUT_A) && (ts.getType1() <= LayoutTrack.LEVEL_XING_D)) {
// have connection to turnout or level crossing
if (ts.getType1() <= LayoutTrack.TURNOUT_D) {
// have connection to a turnout, is block different
lt = (LayoutTurnout) ts.getConnect1();
type = ts.getType1();
blk2 = lt.getLayoutBlock();
if (lt.getTurnoutType() > LayoutTurnout.WYE_TURNOUT) {
// not RH, LH, or WYE turnout - other blocks possible
if ((type == LayoutTrack.TURNOUT_B) && (lt.getLayoutBlockB() != null)) {
blk2 = lt.getLayoutBlockB();
}
if ((type == LayoutTrack.TURNOUT_C) && (lt.getLayoutBlockC() != null)) {
blk2 = lt.getLayoutBlockC();
}
if ((type == LayoutTrack.TURNOUT_D) && (lt.getLayoutBlockD() != null)) {
blk2 = lt.getLayoutBlockD();
}
}
if ((blk2 != null) && (blk1 != blk2)) {
// have a block boundary, create a LayoutConnectivity
c = new LayoutConnectivity(blk1, blk2);
c.setConnections(ts, lt, type, null);
c.setDirection(computeDirection(layoutEditor.getCoords(ts.getConnect2(), ts.getType2()), layoutEditor.getCoords(ts.getConnect1(), type)));
// add to list
checkConnectivity(c, found);
}
} else {
// have connection to a level crossing
lx = (LevelXing) ts.getConnect1();
type = ts.getType1();
if ((type == LayoutTrack.LEVEL_XING_A) || (type == LayoutTrack.LEVEL_XING_C)) {
blk2 = lx.getLayoutBlockAC();
} else {
blk2 = lx.getLayoutBlockBD();
}
if ((blk2 != null) && (blk1 != blk2)) {
// have a block boundary, create a LayoutConnectivity
c = new LayoutConnectivity(blk1, blk2);
c.setConnections(ts, lx, type, null);
c.setDirection(computeDirection(layoutEditor.getCoords(ts.getConnect2(), ts.getType2()), layoutEditor.getCoords(ts.getConnect1(), type)));
// add to list
checkConnectivity(c, found);
}
}
} else if ((ts.getType1() >= LayoutTrack.SLIP_A) && (ts.getType1() <= LayoutTrack.SLIP_D)) {
// have connection to a slip crossing
ls = (LayoutSlip) ts.getConnect1();
type = ts.getType1();
blk2 = ls.getLayoutBlock();
if ((blk2 != null) && (blk1 != blk2)) {
// have a block boundary, create a LayoutConnectivity
c = new LayoutConnectivity(blk1, blk2);
c.setConnections(ts, ls, type, null);
c.setDirection(computeDirection(layoutEditor.getCoords(ts.getConnect2(), ts.getType2()), layoutEditor.getCoords(ts.getConnect1(), type)));
// add to list
checkConnectivity(c, found);
}
}
// check second connection for turnout or level crossing
if ((ts.getType2() >= LayoutTrack.TURNOUT_A) && (ts.getType2() <= LayoutTrack.LEVEL_XING_D)) {
// have connection to turnout or level crossing
if (ts.getType2() <= LayoutTrack.TURNOUT_D) {
// have connection to a turnout
lt = (LayoutTurnout) ts.getConnect2();
type = ts.getType2();
blk2 = lt.getLayoutBlock();
if (lt.getTurnoutType() > LayoutTurnout.WYE_TURNOUT) {
// not RH, LH, or WYE turnout - other blocks possible
if ((type == LayoutTrack.TURNOUT_B) && (lt.getLayoutBlockB() != null)) {
blk2 = lt.getLayoutBlockB();
}
if ((type == LayoutTrack.TURNOUT_C) && (lt.getLayoutBlockC() != null)) {
blk2 = lt.getLayoutBlockC();
}
if ((type == LayoutTrack.TURNOUT_D) && (lt.getLayoutBlockD() != null)) {
blk2 = lt.getLayoutBlockD();
}
}
if ((blk2 != null) && (blk1 != blk2)) {
// have a block boundary, create a LayoutConnectivity
c = new LayoutConnectivity(blk1, blk2);
c.setConnections(ts, lt, type, null);
c.setDirection(computeDirection(layoutEditor.getCoords(ts.getConnect1(), ts.getType1()), layoutEditor.getCoords(ts.getConnect2(), type)));
// add to list
checkConnectivity(c, found);
}
} else {
// have connection to a level crossing
lx = (LevelXing) ts.getConnect2();
type = ts.getType2();
if ((type == LayoutTrack.LEVEL_XING_A) || (type == LayoutTrack.LEVEL_XING_C)) {
blk2 = lx.getLayoutBlockAC();
} else {
blk2 = lx.getLayoutBlockBD();
}
if ((blk2 != null) && (blk1 != blk2)) {
// have a block boundary, create a LayoutConnectivity
c = new LayoutConnectivity(blk1, blk2);
c.setConnections(ts, lx, type, null);
c.setDirection(computeDirection(layoutEditor.getCoords(ts.getConnect1(), ts.getType1()), layoutEditor.getCoords(ts.getConnect2(), type)));
// add to list
checkConnectivity(c, found);
}
}
} else if ((ts.getType2() >= LayoutTrack.SLIP_A) && (ts.getType2() <= LayoutTrack.SLIP_D)) {
// have connection to a slip crossing
ls = (LayoutSlip) ts.getConnect2();
type = ts.getType2();
blk2 = ls.getLayoutBlock();
if ((blk2 != null) && (blk1 != blk2)) {
// have a block boundary, create a LayoutConnectivity
c = new LayoutConnectivity(blk1, blk2);
c.setConnections(ts, ls, type, null);
c.setDirection(computeDirection(layoutEditor.getCoords(ts.getConnect1(), ts.getType1()), layoutEditor.getCoords(ts.getConnect2(), type)));
// add to list
checkConnectivity(c, found);
}
} else if (ts.getType2() != LayoutTrack.POS_POINT) {
log.warn("Did not decode ts.getType2() of {} (A)", ts.getType2());
}
}
}
}
// check for block boundaries internal to crossover turnouts
if (layoutEditor.turnoutList.size() > 0) {
for (LayoutTurnout lt : layoutEditor.turnoutList) {
// check for layout turnout
if ((lt.getTurnoutType() >= LayoutTurnout.DOUBLE_XOVER) && (lt.getLayoutBlock() != null)) {
// have a crossover turnout with at least one block, check for multiple blocks
if ((lt.getLayoutBlockB() != null) || (lt.getLayoutBlockC() != null) || (lt.getLayoutBlockD() != null)) {
// have multiple blocks and therefore internal block boundaries
if ((lt.getLayoutBlockB() != null) && (lt.getLayoutBlock() != lt.getLayoutBlockB())) {
// have a AB block boundary, create a LayoutConnectivity
c = new LayoutConnectivity(lt.getLayoutBlock(), lt.getLayoutBlockB());
c.setXoverBoundary(lt, LayoutConnectivity.XOVER_BOUNDARY_AB);
c.setDirection(computeDirection(lt.getCoordsA(), lt.getCoordsB()));
checkConnectivity(c, found);
}
if ((lt.getTurnoutType() != LayoutTurnout.LH_XOVER) && (lt.getLayoutBlockC() != null) && (lt.getLayoutBlock() != lt.getLayoutBlockC())) {
// have a AC block boundary, create a LayoutConnectivity
c = new LayoutConnectivity(lt.getLayoutBlock(), lt.getLayoutBlockC());
c.setXoverBoundary(lt, LayoutConnectivity.XOVER_BOUNDARY_AC);
c.setDirection(computeDirection(lt.getCoordsA(), lt.getCoordsC()));
checkConnectivity(c, found);
}
if ((lt.getLayoutBlockC() != null) && (lt.getLayoutBlockD() != null) && (lt.getLayoutBlockC() != lt.getLayoutBlockD())) {
// have a CD block boundary, create a LayoutConnectivity
c = new LayoutConnectivity(lt.getLayoutBlockC(), lt.getLayoutBlockD());
c.setXoverBoundary(lt, LayoutConnectivity.XOVER_BOUNDARY_CD);
c.setDirection(computeDirection(lt.getCoordsC(), lt.getCoordsD()));
checkConnectivity(c, found);
}
if ((lt.getTurnoutType() != LayoutTurnout.RH_XOVER) && (lt.getLayoutBlockB() != null) && (lt.getLayoutBlockD() != null) && (lt.getLayoutBlockB() != lt.getLayoutBlockD())) {
// have a BD block boundary, create a LayoutConnectivity
c = new LayoutConnectivity(lt.getLayoutBlockB(), lt.getLayoutBlockD());
c.setXoverBoundary(lt, LayoutConnectivity.XOVER_BOUNDARY_BD);
c.setDirection(computeDirection(lt.getCoordsB(), lt.getCoordsD()));
checkConnectivity(c, found);
}
}
}
}
}
// delete any LayoutConnectivity objects no longer needed
for (int i = sz - 1; i >= 0; i--) {
if (!found[i]) {
// djd debugging - message to list connectivity being removed
// LayoutConnectivity xx = (LayoutConnectivity)cList.get(i);
// log.error(" Deleting Layout Connectivity - "+xx.getBlock1().getID()+", "+
// xx.getBlock2().getID());
// end debugging
cList.remove(i);
}
}
blockConnectivityChanged = false;
}
use of java.awt.geom.Point2D in project JMRI by JMRI.
the class LayoutSlip method getCoordsForConnectionType.
public Point2D getCoordsForConnectionType(int connectionType) {
Point2D result = center;
double circleRadius = controlPointSize * layoutEditor.getTurnoutCircleSize();
switch(connectionType) {
case SLIP_A:
result = getCoordsA();
break;
case SLIP_B:
result = getCoordsB();
break;
case SLIP_C:
result = getCoordsC();
break;
case SLIP_D:
result = getCoordsD();
break;
case SLIP_CENTER:
break;
case SLIP_LEFT:
Point2D leftCenter = MathUtil.midPoint(getCoordsA(), getCoordsB());
double leftFract = circleRadius / center.distance(leftCenter);
result = MathUtil.lerp(center, leftCenter, leftFract);
break;
case SLIP_RIGHT:
Point2D rightCenter = MathUtil.midPoint(getCoordsC(), getCoordsD());
double rightFract = circleRadius / center.distance(rightCenter);
result = MathUtil.lerp(center, rightCenter, rightFract);
break;
default:
//I18IN
log.error("Invalid connection type " + connectionType);
}
return result;
}
use of java.awt.geom.Point2D in project JMRI by JMRI.
the class LayoutSlip method drawControls.
// draw(Graphics2D g2)
public void drawControls(Graphics2D g2) {
// drawHidden left/right turnout control circles
Point2D leftCircleCenter = getCoordsForConnectionType(SLIP_LEFT);
g2.draw(layoutEditor.trackControlCircleAt(leftCircleCenter));
Point2D rightCircleCenter = getCoordsForConnectionType(SLIP_RIGHT);
g2.draw(layoutEditor.trackControlCircleAt(rightCircleCenter));
}
use of java.awt.geom.Point2D in project JMRI by JMRI.
the class LayoutSlipXml method store.
/**
* Default implementation for storing the contents of a LayoutSlip
*
* @param o Object to store, of type LayoutSlip
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
LayoutSlip p = (LayoutSlip) o;
Element element = new Element("layoutSlip");
// include attributes
element.setAttribute("ident", p.getName());
element.setAttribute("slipType", "" + p.getSlipType());
if (p.getBlockName().length() > 0) {
element.setAttribute("blockname", p.getBlockName());
}
if (p.getConnectA() != null) {
element.setAttribute("connectaname", ((TrackSegment) p.getConnectA()).getID());
}
if (p.getConnectB() != null) {
element.setAttribute("connectbname", ((TrackSegment) p.getConnectB()).getID());
}
if (p.getConnectC() != null) {
element.setAttribute("connectcname", ((TrackSegment) p.getConnectC()).getID());
}
if (p.getConnectD() != null) {
element.setAttribute("connectdname", ((TrackSegment) p.getConnectD()).getID());
}
if (p.getSignalA1Name().length() > 0) {
element.addContent(new Element("signala1name").addContent(p.getSignalA1Name()));
}
if (p.getSignalB1Name().length() > 0) {
element.addContent(new Element("signalb1name").addContent(p.getSignalB1Name()));
}
if (p.getSignalC1Name().length() > 0) {
element.addContent(new Element("signalc1name").addContent(p.getSignalC1Name()));
}
if (p.getSignalD1Name().length() > 0) {
element.addContent(new Element("signald1name").addContent(p.getSignalD1Name()));
}
if (p.getSignalA2Name().length() > 0) {
element.addContent(new Element("signala2name").addContent(p.getSignalA2Name()));
}
if (p.getSignalB2Name().length() > 0) {
element.addContent(new Element("signalb2name").addContent(p.getSignalB2Name()));
}
if (p.getSignalC2Name().length() > 0) {
element.addContent(new Element("signalc2name").addContent(p.getSignalC2Name()));
}
if (p.getSignalD2Name().length() > 0) {
element.addContent(new Element("signald2name").addContent(p.getSignalD2Name()));
}
Point2D coords = p.getCoordsCenter();
element.setAttribute("xcen", "" + coords.getX());
element.setAttribute("ycen", "" + coords.getY());
coords = p.getCoordsA();
element.setAttribute("xa", "" + coords.getX());
element.setAttribute("ya", "" + coords.getY());
coords = p.getCoordsB();
element.setAttribute("xb", "" + coords.getX());
element.setAttribute("yb", "" + coords.getY());
if (p.getSignalAMastName().length() > 0) {
element.addContent(new Element("signalAMast").addContent(p.getSignalAMastName()));
}
if (p.getSignalBMastName().length() > 0) {
element.addContent(new Element("signalBMast").addContent(p.getSignalBMastName()));
}
if (p.getSignalCMastName().length() > 0) {
element.addContent(new Element("signalCMast").addContent(p.getSignalCMastName()));
}
if (p.getSignalDMastName().length() > 0) {
element.addContent(new Element("signalDMast").addContent(p.getSignalDMastName()));
}
if (p.getSensorAName().length() > 0) {
element.addContent(new Element("sensorA").addContent(p.getSensorAName()));
}
if (p.getSensorBName().length() > 0) {
element.addContent(new Element("sensorB").addContent(p.getSensorBName()));
}
if (p.getSensorCName().length() > 0) {
element.addContent(new Element("sensorC").addContent(p.getSensorCName()));
}
if (p.getSensorDName().length() > 0) {
element.addContent(new Element("sensorD").addContent(p.getSensorDName()));
}
if (p.getTurnoutName().length() > 0) {
element.addContent(new Element("turnout").addContent(p.getTurnoutName()));
}
if (p.getTurnoutBName().length() > 0) {
element.addContent(new Element("turnoutB").addContent(p.getTurnoutBName()));
}
Element states = new Element("states");
Element state = new Element("A-C");
state.addContent(new Element("turnout").addContent("" + p.getTurnoutState(LayoutSlip.STATE_AC)));
state.addContent(new Element("turnoutB").addContent("" + p.getTurnoutBState(LayoutSlip.STATE_AC)));
states.addContent(state);
state = new Element("A-D");
state.addContent(new Element("turnout").addContent("" + p.getTurnoutState(LayoutSlip.STATE_AD)));
state.addContent(new Element("turnoutB").addContent("" + p.getTurnoutBState(LayoutSlip.STATE_AD)));
states.addContent(state);
state = new Element("B-D");
state.addContent(new Element("turnout").addContent("" + p.getTurnoutState(LayoutSlip.STATE_BD)));
state.addContent(new Element("turnoutB").addContent("" + p.getTurnoutBState(LayoutSlip.STATE_BD)));
states.addContent(state);
if (p.getSlipType() == LayoutSlip.DOUBLE_SLIP) {
state = new Element("B-C");
state.addContent(new Element("turnout").addContent("" + p.getTurnoutState(LayoutSlip.STATE_BC)));
state.addContent(new Element("turnoutB").addContent("" + p.getTurnoutBState(LayoutSlip.STATE_BC)));
states.addContent(state);
}
element.addContent(states);
element.setAttribute("class", getClass().getName());
return element;
}
use of java.awt.geom.Point2D in project JMRI by JMRI.
the class LevelXingXml method store.
/**
* Default implementation for storing the contents of a LevelXing
*
* @param o Object to store, of type LevelXing
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
LevelXing p = (LevelXing) o;
Element element = new Element("levelxing");
// include attributes
element.setAttribute("ident", p.getID());
if (p.getBlockNameAC().length() > 0) {
element.setAttribute("blocknameac", p.getBlockNameAC());
}
if (p.getBlockNameBD().length() > 0) {
element.setAttribute("blocknamebd", p.getBlockNameBD());
}
if (p.getConnectA() != null) {
element.setAttribute("connectaname", ((TrackSegment) p.getConnectA()).getID());
}
if (p.getConnectB() != null) {
element.setAttribute("connectbname", ((TrackSegment) p.getConnectB()).getID());
}
if (p.getConnectC() != null) {
element.setAttribute("connectcname", ((TrackSegment) p.getConnectC()).getID());
}
if (p.getConnectD() != null) {
element.setAttribute("connectdname", ((TrackSegment) p.getConnectD()).getID());
}
if (p.getSignalAName().length() > 0) {
element.setAttribute("signalaname", p.getSignalAName());
}
if (p.getSignalBName().length() > 0) {
element.setAttribute("signalbname", p.getSignalBName());
}
if (p.getSignalCName().length() > 0) {
element.setAttribute("signalcname", p.getSignalCName());
}
if (p.getSignalDName().length() > 0) {
element.setAttribute("signaldname", p.getSignalDName());
}
Point2D coords = p.getCoordsCenter();
element.setAttribute("xcen", "" + coords.getX());
element.setAttribute("ycen", "" + coords.getY());
coords = p.getCoordsA();
element.setAttribute("xa", "" + coords.getX());
element.setAttribute("ya", "" + coords.getY());
coords = p.getCoordsB();
element.setAttribute("xb", "" + coords.getX());
element.setAttribute("yb", "" + coords.getY());
if (p.getSignalAMastName().length() > 0) {
element.addContent(new Element("signalAMast").addContent(p.getSignalAMastName()));
}
if (p.getSignalBMastName().length() > 0) {
element.addContent(new Element("signalBMast").addContent(p.getSignalBMastName()));
}
if (p.getSignalCMastName().length() > 0) {
element.addContent(new Element("signalCMast").addContent(p.getSignalCMastName()));
}
if (p.getSignalDMastName().length() > 0) {
element.addContent(new Element("signalDMast").addContent(p.getSignalDMastName()));
}
if (p.getSensorAName().length() > 0) {
element.addContent(new Element("sensorA").addContent(p.getSensorAName()));
}
if (p.getSensorBName().length() > 0) {
element.addContent(new Element("sensorB").addContent(p.getSensorBName()));
}
if (p.getSensorCName().length() > 0) {
element.addContent(new Element("sensorC").addContent(p.getSensorCName()));
}
if (p.getSensorDName().length() > 0) {
element.addContent(new Element("sensorD").addContent(p.getSensorDName()));
}
element.setAttribute("class", getClass().getName());
return element;
}
Aggregations