Search in sources :

Example 11 with Cable

use of com.cas.circuit.vo.Cable in project TeachingInSimulation by ScOrPiOzzy.

the class ConnectionHandler method setCurrLinker.

/**
 * 设置当前用户选择的导线或者气管
 * @param wireOrPipe
 */
public void setCurrLinker(int connectType, ColorRGBA color) {
    this.color = color;
    if (ConnectionUtil.CONNECT_WIRE == connectType) {
        currLinker = new Wire(1, color);
    } else if (ConnectionUtil.CONNECT_PIPE == connectType) {
        currLinker = new Pipe(1, color);
    } else if (ConnectionUtil.CONNECT_CABLE == connectType) {
        currLinker = new Cable();
    } else {
        currLinker = null;
    }
    refreshViewPort(currLinker);
}
Also used : Cable(com.cas.circuit.vo.Cable) Pipe(com.cas.gas.vo.Pipe) Wire(com.cas.circuit.vo.Wire)

Example 12 with Cable

use of com.cas.circuit.vo.Cable in project TeachingInSimulation by ScOrPiOzzy.

the class ConnectionHandler method modifyWireNum.

private void modifyWireNum(ILinker linker, String wireNum) {
    if (Util.isEmpty(wireNum)) {
        return;
    }
    if (linker instanceof Cable && ((Cable) linker).getBindWires().size() != 0) {
        List<Wire> bindWires = ((Cable) linker).getBindWires();
        linker = bindWires.get(bindWires.size() - 1);
    }
    for (Spatial model : linker.getModels().keySet()) {
        Spatial parent = ((Node) model).getChild("Label");
        if (parent == null) {
            continue;
        }
        for (Spatial bitmapText : ((Node) parent).getChildren()) {
            if (bitmapText instanceof BitmapText) {
                ((BitmapText) bitmapText).setText(wireNum.toUpperCase());
                // //					有的号码三个英文字母  塞不下  所以过大的 做一下压缩
                // float lineWidth = ((BitmapText) bitmapText).getLineWidth();
                // if (lineWidth > 80) {
                // bitmapText.scale(80f / lineWidth, 1, 1);
                // } else {
                bitmapText.setLocalScale(bitmapText.getLocalScale().y);
            // }
            }
        }
    }
}
Also used : Cable(com.cas.circuit.vo.Cable) BitmapText(com.jme3.font.BitmapText) Spatial(com.jme3.scene.Spatial) Node(com.jme3.scene.Node) Wire(com.cas.circuit.vo.Wire)

Example 13 with Cable

use of com.cas.circuit.vo.Cable in project TeachingInSimulation by ScOrPiOzzy.

the class ConnectionHandler method deleteLinker.

private void deleteLinker(ILinker linker, boolean modifiable) {
    if (linker == null) {
        return;
    }
    // 去除模型高亮选中效果
    setHighLightLinker(linker, false);
    // 重新整理端子上的接线头
    ILinkTarget term1 = linker.getLinkTarget1();
    ILinkTarget term2 = linker.getLinkTarget2();
    // 删除线缆上的导线绑定模型
    Map<Spatial, ILinkTarget> models = linker.getModels();
    if (linker instanceof Cable && ((Cable) linker).isElecComp()) {
        for (Entry<String, Wire> set : ((Cable) linker).getMark_wire().entrySet()) {
            Map<Spatial, ILinkTarget> mdls = set.getValue().getModels();
            for (Spatial linkTerm : mdls.keySet()) {
                JmeUtil.detachModel(linkTerm);
            }
        }
        if (term2 != null) {
            JmeUtil.detachModel(linker.getLinkMdlByTarget(term2).get(0));
        }
        if (modifiable) {
            // 给模型未接线状态(只有传感器接线才会受到影响)
            for (Spatial linkMdl : models.keySet()) {
                JmeUtil.setSpatialHighLight(linkMdl, ColorConsts.TRANSDUCERS);
            }
        }
    } else {
        for (Spatial linkTerm : models.keySet()) {
            JmeUtil.detachModel(linkTerm);
        }
    }
    // 记录准备存档的信息
    linkerData.removeLinker(linker);
    linker.unbind();
    resetLinks(term1);
    resetLinks(term2);
    setLineVisible(false);
    if (currLinker instanceof Wire) {
        Wire wire = new Wire(1, color);
        currLinker = wire;
    } else if (currLinker instanceof Pipe) {
        Pipe pipe = new Pipe(1, color);
        currLinker = pipe;
    } else if (currLinker instanceof Cable) {
        Cable cable = new Cable();
        currLinker = cable;
    }
}
Also used : Cable(com.cas.circuit.vo.Cable) Spatial(com.jme3.scene.Spatial) Pipe(com.cas.gas.vo.Pipe) Wire(com.cas.circuit.vo.Wire)

Example 14 with Cable

use of com.cas.circuit.vo.Cable in project TeachingInSimulation by ScOrPiOzzy.

the class ConnectionHandler method offlineConnect.

/**
 * 单机练习模式下接线
 * @param termOrPort 端子、气口
 */
public LinkerMsg offlineConnect(ILinkTarget termOrPort) {
    // 获得当前用户选中导线
    ILinker wireOrPipe = currLinker;
    Spatial model = connect(wireOrPipe, termOrPort, false);
    // 线缆会在连接时对当前连接对象做一些处理,所以此处要重新获得一次
    if (wireOrPipe instanceof Cable && ((Cable) wireOrPipe).getPlug1() == null && ((Cable) wireOrPipe).getPlug2() == null) {
        wireOrPipe = currLinker;
    }
    initLinkerLine(wireOrPipe, model);
    // 接线头添加鼠标监听事件
    addMouseEvent(model, new LinkerEventAdapter(new LinkerEventHandler(wireOrPipe, this, true)));
    return linkerData.addLinker(wireOrPipe, termOrPort, (String) model.getUserData("WireMark"));
}
Also used : Cable(com.cas.circuit.vo.Cable) Spatial(com.jme3.scene.Spatial) LinkerEventHandler(com.cas.circuit.event.LinkerEventHandler) LinkerEventAdapter(com.cas.circuit.event.LinkerEventAdapter)

Example 15 with Cable

use of com.cas.circuit.vo.Cable 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)17 Wire (com.cas.circuit.vo.Wire)13 Spatial (com.jme3.scene.Spatial)8 Pipe (com.cas.gas.vo.Pipe)7 Jack (com.cas.circuit.vo.Jack)4 Terminal (com.cas.circuit.vo.Terminal)4 ArrayList (java.util.ArrayList)4 LinkerMsg (com.cas.circuit.msg.LinkerMsg)3 GasPort (com.cas.gas.vo.GasPort)3 LinkerEventAdapter (com.cas.circuit.event.LinkerEventAdapter)2 LinkerEventHandler (com.cas.circuit.event.LinkerEventHandler)2 Node (com.jme3.scene.Node)2 ElecComp (com.cas.circuit.vo.ElecComp)1 ElecCompDef (com.cas.circuit.vo.ElecCompDef)1 Format (com.cas.circuit.vo.Format)1 BitmapText (com.jme3.font.BitmapText)1 ColorRGBA (com.jme3.math.ColorRGBA)1 Element (de.lessvoid.nifty.elements.Element)1 FileNotFoundException (java.io.FileNotFoundException)1 Comparator (java.util.Comparator)1