/* ========================
* JSynoptic : a free Synoptic editor
* ========================
*
* Project Info: http://jsynoptic.sourceforge.net/index.html
*
* This program is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* (C) Copyright 2001-2005, by :
* Corporate:
* EADS Astrium SAS
* EADS CRC
* Individual:
* Claude Cazenave
*
* $Id: SwitchBox2Pos.java,v 1.2 2008/10/24 15:49:11 ogor Exp $
*
* Changes
* -------
* 08 sept 2008 : Initial public release (RO);
*
*/
package jsynoptic.plugins.circuit.switches;
import jsynoptic.plugins.circuit.CircuitGate;
import jsynoptic.plugins.circuit.CircuitPlugin;
import simtools.diagram.gate.Gate;
import simtools.shapes.AbstractShape;
/**
*
* A 2-POS switch box is composed of 3 gates:<br>
*
* <code>
* _<br>
* | | J02<br>
* J01 |/ | <br>
* |_| J03<br>
* <br>
*
*</code>
* The 2-POS switch box is defined by following rules:
* <br>
* <ul>
* <li> If (POS1): J01 and J02 are connected
* <li> If (POS2): J01 and J03 are connected
* </ul>
*
* @author zxpletran007
*
*/
public class SwitchBox2Pos extends SwitchBox{
private static final long serialVersionUID = 1984180592937848978L;
protected final static int POS_1 = 1;
protected final static int POS_2 = 2;
// Gates
protected CircuitGate j01;
protected CircuitGate j02;
protected CircuitGate j03;
/**
* @param ox
* @param oy
* @param diameter
*/
public SwitchBox2Pos(int ox, int oy, int width, int height) {
super(ox, oy, width, height, POS_1, 1, 2);
// Add gates
addGate(j01 = new CircuitGate(this, Gate.WEST, "J01", true));
addGate(j02 = new CircuitGate(this, Gate.EAST, "J02", true));
addGate(j03 = new CircuitGate(this, Gate.EAST, "J03", true));
}
/*
* (non-Javadoc)
*
* @see simtools.shapes.AbstractShape#cloneShape()
*/
protected AbstractShape cloneShape() {
SwitchBox2Pos res = (SwitchBox2Pos) super.cloneShape();
res.j01 = (CircuitGate)j01.cloneGate(res);
res.addGate(res.j01);
res.j02 = (CircuitGate)j02.cloneGate(res);
res.addGate(res.j02);
res.j03 = (CircuitGate)j03.cloneGate(res);
res.addGate(res.j03);
return res;
}
/* (non-Javadoc)
* @see simtools.shapes.AbstractShape#getShapeName()
*/
public String getShapeName(){
return CircuitPlugin.resources.getString("SwitchBox2Pos");
}
/* (non-Javadoc)
* @see net.eads.astrium.jsynoptic.cuircuit.Switch#getTargetGate(jsynoptic.plugins.circuit.Gate)
*/
protected CircuitGate getTargetGate(CircuitGate sourceGate) {
CircuitGate res = null;
if (sourceGate == j01){
if (currentPosition == POS_1){
res = j02;
} else {
res = j03;
}
} else if (sourceGate == j02){
if (currentPosition == POS_1){
res = j01;
}
} else if (sourceGate == j03){
if (currentPosition == POS_2){
res = j01;
}
}
return res;
}
protected boolean isValidPosition(int position) {
return (position == POS_1) || (position == POS_2);
}
/* (non-Javadoc)
* @see jsynoptic.plugins.circuit.SwitchShape#updateSwitchInnerConnections(int)
*/
protected void updateSwitchInnerConnections(){
super.updateSwitchInnerConnections();
if (isValidPosition(currentPosition)){ // add middle connections
try{
if (currentPosition == POS_1){
switchInnerConnections.add(new BoxSwitchMiddleConnector(0,0));
} else if (currentPosition == POS_2){
switchInnerConnections.add(new BoxSwitchMiddleConnector(0,1));
}
}catch (InvalidSwitchConnection e){
e.printStackTrace();
}
}
}
}