Search in sources :

Example 1 with Format

use of com.cas.circuit.vo.Format 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;
}
Also used : Cable(com.cas.circuit.vo.Cable) GasPort(com.cas.gas.vo.GasPort) Format(com.cas.circuit.vo.Format) Pipe(com.cas.gas.vo.Pipe) Jack(com.cas.circuit.vo.Jack) Wire(com.cas.circuit.vo.Wire) Terminal(com.cas.circuit.vo.Terminal)

Aggregations

Cable (com.cas.circuit.vo.Cable)1 Format (com.cas.circuit.vo.Format)1 Jack (com.cas.circuit.vo.Jack)1 Terminal (com.cas.circuit.vo.Terminal)1 Wire (com.cas.circuit.vo.Wire)1 GasPort (com.cas.gas.vo.GasPort)1 Pipe (com.cas.gas.vo.Pipe)1