use of com.cas.circuit.vo.Wire in project TeachingInSimulation by ScOrPiOzzy.
the class ConnectionHandler method checkConnect.
/**
* 验证是否可以接线
* @param target 端子、气口
*/
public boolean checkConnect(ILinkTarget target) {
// 获得当前用户选中导线
if (currLinker == null) {
Dispatcher.getIns().getTip().showTip(ITip.ERROR, ConnectionUtil.NO_lINKER);
return false;
}
if (target instanceof Jack && !(currLinker instanceof Cable)) {
Dispatcher.getIns().getTip().showTip(ITip.ERROR, ConnectionUtil.JUST_CABLE);
return false;
}
// 如果当前手中是线缆,但当前接口不符合当前线缆制式
if ((target instanceof Jack) && (currLinker instanceof Cable)) {
Jack jack = (Jack) target;
if (jack.getPlug() != null) {
Dispatcher.getIns().getTip().showTip(ITip.ERROR, ConnectionUtil.JACK_ALREADY_IN_USED);
return false;
}
Cable cable = (Cable) currLinker;
// 如果两个连接头都为null,说明用户选择了线缆还没有连接
if (cable.getPlug1() == null && cable.getPlug2() == null) {
if (Util.notEmpty(jack.getPO().getBelongElecComp())) {
return false;
}
return true;
}
Format format = jack.getFormat();
Plug plug1 = cable.getPlug1();
if (plug1 != null) {
boolean insert = plug1.isInserted();
if (!insert) {
return format.equals(plug1.getFormat());
}
}
Plug plug2 = cable.getPlug2();
if (plug2 != null) {
boolean insert = plug2.isInserted();
if (!insert) {
if (standardData != null && !checkStandard(target, currLinker)) {
Dispatcher.getIns().getTip().showTip(ITip.ERROR, "接线不符合标准存档!");
return false;
}
return format.equals(plug2.getFormat());
} else {
return false;
}
} else if (cable.isSinglePlug()) {
return false;
}
} else if ((target instanceof Terminal) && (currLinker instanceof Cable)) {
Cable cable = (Cable) currLinker;
Wire wire = cable.getNowConnectingWire();
if (wire == null) {
Dispatcher.getIns().getTip().showTip(ITip.ERROR, ConnectionUtil.SELECT_ANY_WIRE_IN_CABLE);
return false;
}
if (wire.isBothBinded()) {
Dispatcher.getIns().getTip().showTip(ITip.ERROR, ConnectionUtil.WIRE_IN_CABLE_LINKED_ALREADY);
return false;
}
Terminal terminal = (Terminal) target;
if (terminal.getLinkers().size() == terminal.getNum()) {
Dispatcher.getIns().getTip().showTip(ITip.ERROR, ConnectionUtil.TERMINAL_LIMITED);
return false;
}
if (standardData != null && !checkStandard(target, currLinker)) {
Dispatcher.getIns().getTip().showTip(ITip.ERROR, "接线不符合标准存档!");
return false;
}
return true;
}
if (target instanceof Terminal && !(currLinker instanceof Wire)) {
Dispatcher.getIns().getTip().showTip(ITip.ERROR, ConnectionUtil.JUST_WIRE);
return false;
}
if (target instanceof Terminal && (currLinker instanceof Wire)) {
Terminal terminal = (Terminal) target;
if (terminal.getLinkers().size() == terminal.getNum()) {
Dispatcher.getIns().getTip().showTip(ITip.ERROR, ConnectionUtil.TERMINAL_LIMITED);
return false;
}
if (terminal.getLinkers().contains(currLinker)) {
Dispatcher.getIns().getTip().showTip(ITip.ERROR, ConnectionUtil.SAME_LINKER);
return false;
}
}
if (target instanceof GasPort && !(currLinker instanceof Pipe)) {
Dispatcher.getIns().getTip().showTip(ITip.ERROR, ConnectionUtil.JUST_PIPE);
return false;
}
if (target instanceof GasPort && target.getLinkers().size() != 0) {
Dispatcher.getIns().getTip().showTip(ITip.ERROR, ConnectionUtil.GASPORT_LIMITED);
return false;
}
if (standardData != null && !checkStandard(target, currLinker)) {
Dispatcher.getIns().getTip().showTip(ITip.ERROR, "接线不符合标准存档!");
return false;
}
Dispatcher.getIns().getTip().showTip(ITip.RIGHT, null);
return true;
}
use of com.cas.circuit.vo.Wire in project TeachingInSimulation by ScOrPiOzzy.
the class LinkerData method addLinker.
// /**
// * 所负责工作站
// */
// private byte stationInCharge;
public LinkerMsg addLinker(ILinker linker, ILinkTarget target, String wireMark) {
// 封装LinkerInfo
LinkerMsg linkInfo = new LinkerMsg();
if (linker instanceof Wire) {
linkInfo.setLinkType(LinkerMsg.WIRE);
} else if (linker instanceof Pipe) {
linkInfo.setLinkType(LinkerMsg.PIPE);
} else if (linker instanceof Cable) {
if (target instanceof Jack) {
linkInfo.setLinkType(LinkerMsg.CABLE_JACK);
linkInfo.setElecComp(((Cable) linker).isElecComp());
} else {
linkInfo.setLinkType(LinkerMsg.CABLE_TERM);
// A、B、C
linkInfo.setWireMark(wireMark);
}
linkInfo.setCableKey(((Cable) linker).getPO().getId());
}
linkInfo.setKey(linker.hashCode());
linkInfo.setColor(linker.getColor());
linkInfo.setElecCompKey(target.getElecCompKey());
linkInfo.setTargetKey(target.getTargetKey());
// 线号
linkInfo.setNumMark(linker.getWireNum());
linkerMapForSave.put(linker.hashCode() + "_" + target.hashCode(), linkInfo);
return linkInfo;
}
use of com.cas.circuit.vo.Wire in project TeachingInSimulation by ScOrPiOzzy.
the class LinkerData method modifyWireNum.
public List<LinkerMsg> modifyWireNum(ILinker linker, String wireNum) {
int hashCode = linker.hashCode();
// 因为连线时的判断所以此处线缆必然是特殊线缆
if (linker instanceof Cable) {
Cable cable = (Cable) linker;
List<Wire> bindWires = cable.getBindWires();
// 最近Bind的导线
linker = bindWires.get(bindWires.size() - 1);
}
List<LinkerMsg> msgs = new ArrayList<LinkerMsg>();
ILinkTarget target1 = linker.getLinkTarget1();
modifyTargetWireNum(msgs, hashCode, target1, wireNum);
ILinkTarget target2 = linker.getLinkTarget2();
modifyTargetWireNum(msgs, hashCode, target2, wireNum);
return msgs;
}
Aggregations