Search in sources :

Example 6 with Terminal

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

the class ValveLogicEx method onReceivedLocal.

@Override
protected void onReceivedLocal(Terminal terminal) {
    if (ya2_c1.getStitch().containsValue(terminal)) {
        Terminal term1 = ya2_c1.getStitch().get("1");
        Terminal term2 = ya2_c1.getStitch().get("2");
        boolean matchVolt = R.matchRequiredVolt(Voltage.IS_DC, term1, term2, 24, 2) != null;
        if (matchVolt) {
            // 切换状态 A
            if (!ya2_c2_effect && !ya2_c1_effect) {
                changeBlockState("YA2_Break", "YA2_Link");
            }
            ya2_c1_effect = true;
        } else {
            ya2_c1_effect = false;
        }
    } else if (ya2_c2.getStitch().containsValue(terminal)) {
        Terminal term1 = ya2_c2.getStitch().get("1");
        Terminal term2 = ya2_c2.getStitch().get("2");
        boolean matchVolt = R.matchRequiredVolt(Voltage.IS_DC, term1, term2, 24, 2) != null;
        if (matchVolt) {
            // 切换状态 B
            if (!ya2_c2_effect && !ya2_c1_effect) {
                changeBlockState("YA2_Link", "YA2_Break");
            }
            ya2_c2_effect = true;
        } else {
            ya2_c2_effect = false;
        }
    }
    if (ya4_c1.getStitch().containsValue(terminal)) {
        Terminal term1 = ya4_c1.getStitch().get("1");
        Terminal term2 = ya4_c1.getStitch().get("2");
        boolean matchVolt = R.matchRequiredVolt(Voltage.IS_DC, term1, term2, 24, 2) != null;
        if (matchVolt) {
            // 切换状态 A
            if (!ya4_c2_effect && !ya4_c1_effect) {
                changeBlockState("YA4_Break", "YA4_Link");
            }
            ya4_c1_effect = true;
        } else {
            ya4_c1_effect = false;
        }
    } else if (ya4_c2.getStitch().containsValue(terminal)) {
        Terminal term1 = ya4_c2.getStitch().get("1");
        Terminal term2 = ya4_c2.getStitch().get("2");
        boolean matchVolt = R.matchRequiredVolt(Voltage.IS_DC, term1, term2, 24, 2) != null;
        if (matchVolt) {
            // 切换状态 B
            if (!ya4_c2_effect && !ya4_c1_effect) {
                changeBlockState("YA4_Link", "YA4_Break");
            }
            ya4_c2_effect = true;
        } else {
            ya4_c2_effect = false;
        }
    }
    super.onReceivedLocal(terminal);
}
Also used : Terminal(com.cas.circuit.vo.Terminal)

Example 7 with Terminal

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

the class ConnectionHandler method resetLinks.

private void resetLinks(ILinkTarget termOrPort) {
    if (termOrPort == null) /* || termOrPort.getPO() == null */
    {
        return;
    }
    // 获得当前端子/气口的接入轴方向
    List<ILinker> linkers = termOrPort.getLinkers();
    List<Spatial> termMdls = new ArrayList<Spatial>();
    for (ILinker linker : linkers) {
        termMdls.addAll(linker.getLinkMdlByTarget(termOrPort));
        if (termOrPort instanceof Jack) {
            Jack jack = (Jack) termOrPort;
            ConnectionUtil.rotateJack(termMdls, jack.getRotation(), jack.getPO().getJackDirection());
        } else if (termOrPort instanceof Terminal) {
            ConnectionUtil.moveTerms(termMdls, (Terminal) termOrPort);
        } else if (termOrPort instanceof GasPort) {
            ConnectionUtil.rotatePipe(termMdls, (GasPort) termOrPort);
        }
    }
}
Also used : GasPort(com.cas.gas.vo.GasPort) Spatial(com.jme3.scene.Spatial) ArrayList(java.util.ArrayList) Jack(com.cas.circuit.vo.Jack) Terminal(com.cas.circuit.vo.Terminal)

Example 8 with Terminal

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

the class ConnectionHandler method connectByLinkerInfo.

/**
 * 联机状态下接线
 * @param linkerInfo 接线消息
 * @param wireOrPipe
 * @param modifiable
 */
private void connectByLinkerInfo(LinkerMsg linkerInfo, ILinker wireOrPipe, boolean modifiable) {
    ElecComp elecComp = eleCompMap.get(linkerInfo.getElecCompKey());
    if (elecComp == null) {
        log.info("未找到指定元器件的定义信息:" + linkerInfo.getElecCompKey());
        return;
    }
    ElecCompDef def = elecComp.getDef();
    byte linkType = linkerInfo.getLinkType();
    String targetKey = linkerInfo.getTargetKey();
    ILinkTarget termOrPort = null;
    if (LinkerMsg.WIRE == linkType || LinkerMsg.CABLE_TERM == linkType) {
        termOrPort = def.getTerminalMap().get(targetKey);
    } else if (LinkerMsg.PIPE == linkType) {
        termOrPort = def.getGasPortMap().get(targetKey);
    } else if (LinkerMsg.CABLE_JACK == linkType) {
        termOrPort = def.getJackMap().get(targetKey);
    }
    if (wireOrPipe instanceof Cable && termOrPort instanceof Terminal) {
        ((Cable) wireOrPipe).setNowConnectingWire(linkerInfo.getWireMark());
        ((Cable) wireOrPipe).getNowConnectingWire().setWireNum(linkerInfo.getNumMark());
    }
    wireOrPipe.setWireNum(linkerInfo.getNumMark());
    Spatial model = connect(wireOrPipe, termOrPort, true);
    if (currSaveLinker != null) {
        wireOrPipe = currSaveLinker;
    }
    // 接线头添加鼠标监听事件
    addMouseEvent(model, new LinkerEventAdapter(new LinkerEventHandler(wireOrPipe, this, modifiable)));
    // 记录准备存档的信息
    if (modifiable) {
        linkerData.addLinker(wireOrPipe, termOrPort, (String) model.getUserData("WireMark"));
    }
}
Also used : Cable(com.cas.circuit.vo.Cable) ElecCompDef(com.cas.circuit.vo.ElecCompDef) Spatial(com.jme3.scene.Spatial) LinkerEventHandler(com.cas.circuit.event.LinkerEventHandler) ElecComp(com.cas.circuit.vo.ElecComp) Terminal(com.cas.circuit.vo.Terminal) LinkerEventAdapter(com.cas.circuit.event.LinkerEventAdapter)

Example 9 with Terminal

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

the class ConnectionHandler method bindWireOrPipe.

/**
 * 绑定端点
 * @param termOrPort 点击接线的端点信息对象,或者气口信息对象
 */
private void bindWireOrPipe(ILinkTarget termOrPort, Spatial mdl) {
    setHighLightLinker(selected, false);
    if (currLinker instanceof Cable && termOrPort instanceof Terminal) {
        Cable cable = ((Cable) currLinker);
        // 如果当前绑定为线缆上的导线
        cable.bindTerm(termOrPort, mdl);
        // 接完线 显示号码管对话框
        ui.setNumDialogueVisible(true);
        modifyLinker = currLinker;
        List<Wire> wires = new ArrayList<Wire>(cable.getMark_wire().values());
        // 线缆导线排序
        for (Wire w : cable.getBindWires()) {
            wires.remove(w);
        }
        Comparator<Wire> comparator = new Comparator<Wire>() {

            @Override
            public int compare(Wire wire1, Wire wire2) {
                return wire1.getPO().getStitch1().compareTo(wire2.getPO().getStitch1());
            }
        };
        Collections.sort(wires, comparator);
        if (wires.size() == 0) {
            cable.setNowConnectingWire(null);
        } else {
            cable.setNowConnectingWire(wires.get(0).getPO().getMark());
        }
    } else {
        // 其他普通情况绑定
        currLinker.bind(termOrPort);
        if (currLinker.isBothBinded() && currLinker instanceof Wire) {
            // 接完线 显示号码管对话框
            ui.setNumDialogueVisible(true);
            modifyLinker = currLinker;
        }
    }
    currLinker.getModels().put(mdl, termOrPort);
    // 显示或隐藏与鼠标连接的直线
    setLineVisible(true);
    if (!currLinker.isBothBinded()) {
        return;
    }
    setLineVisible(false);
    ui.initXianLanPanel(null, false);
    // 取消接线完成的元器件高亮
    if (currLinker instanceof Cable && ((Cable) currLinker).isElecComp()) {
        Map<Spatial, ILinkTarget> models = currLinker.getModels();
        for (Spatial spatial : models.keySet()) {
            // JmeUtil.setMaterialEffect(Dispatcher.getIns().getMainApp(), HightLightType.GLOW, spatial, ColorConsts.TRANSDUCERS, false);
            JmeUtil.setSpatialHighLight(spatial, ColorRGBA.BlackNoAlpha);
        }
    }
    if (termOrPort instanceof Terminal) {
        if (currLinker instanceof Cable) {
            Cable cable = new Cable();
            currLinker = cable;
        } else {
            Wire wire = new Wire(1, color);
            currLinker = wire;
        }
    } else if (termOrPort instanceof GasPort) {
        Pipe pipe = new Pipe(1, color);
        currLinker = pipe;
    } else if (termOrPort instanceof Jack) {
        Cable cable = new Cable();
        currLinker = cable;
    }
}
Also used : Cable(com.cas.circuit.vo.Cable) GasPort(com.cas.gas.vo.GasPort) ArrayList(java.util.ArrayList) Pipe(com.cas.gas.vo.Pipe) Wire(com.cas.circuit.vo.Wire) Terminal(com.cas.circuit.vo.Terminal) Comparator(java.util.Comparator) Spatial(com.jme3.scene.Spatial) Jack(com.cas.circuit.vo.Jack)

Example 10 with Terminal

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

the class ConnectionHandler method connect.

/**
 * 接线处理
 * @param wireOrPipe 导线、气管
 * @param termOrPort 端子、气口
 */
private Spatial connect(ILinker wireOrPipe, ILinkTarget termOrPort, boolean readSav) {
    // 旋转端子上包括新增接线头在内的若干个接线头
    Spatial model = null;
    ColorRGBA color = null;
    if (termOrPort instanceof Terminal) {
        model = ConnectionUtil.getWireTerm();
        if (wireOrPipe instanceof Cable) {
            Cable cable = (Cable) wireOrPipe;
            Wire wire = cable.getNowConnectingWire();
            model.setUserData("WireMark", wire.getPO().getMark());
            // 添加已经接上端子的导线
            cable.getBindWires().add(wire);
            // 除去已经连接的导线
            if (!readSav) {
                List<Wire> wires = new ArrayList<Wire>(cable.getMark_wire().values());
                for (Wire w : cable.getBindWires()) {
                    wires.remove(w);
                }
                ui.initXianLanPanel(wires, true);
            }
            color = wire.getColor();
        } else {
            color = wireOrPipe.getColor();
            currSaveLinker = null;
        }
    } else if (termOrPort instanceof GasPort) {
        model = ConnectionUtil.getPipeTerm();
        color = wireOrPipe.getColor();
        currSaveLinker = null;
    } else if (termOrPort instanceof Jack) {
        Jack jack = (Jack) termOrPort;
        model = ConnectionUtil.getJackTerm(jack.getFormat());
        Cable cable = (Cable) jack.getLinkers().get(0);
        cable = cable.clone();
        if (readSav) {
            cable = (Cable) wireOrPipe;
        }
        color = cable.getColor();
        currSaveLinker = null;
        // 通过jack获得当前的接线线缆
        if (((Cable) wireOrPipe).getPlug1() == null && ((Cable) wireOrPipe).getPlug2() == null) {
            if (readSav) {
                wireOrPipe = cable;
                currSaveLinker = wireOrPipe;
            } else {
                currLinker = cable;
            }
        }
        // 如果是单连接头线缆,则显示导线面板
        if (cable.isSinglePlug() && !readSav) {
            List<Wire> wires = new ArrayList<Wire>(cable.getMark_wire().values());
            ui.initXianLanPanel(wires, true);
            cable.setNowConnectingWire(wires.get(0).getPO().getMark());
        }
    }
    // 添加新的接线头到端子上
    Node target = (Node) termOrPort.getModel();
    final Node parent = target.getParent();
    Spatial screw = target.getChild("screw");
    if (screw != null) {
        model.setLocalTranslation(JmeUtil.getTransLation(screw, parent));
    } else {
        model.setLocalTranslation(target.getLocalTranslation());
    }
    // 修改连接头颜色
    JmeUtil.changeColor(((Node) model).getChild("model"), color);
    model.setUserData("Color", color);
    // 获得端子模型的父节点
    if (JmeUtil.isJMEThread()) {
        ((Node) parent).attachChild(model);
    } else {
        final Spatial finalModel = model;
        try {
            app.enqueue(new Callable<Void>() {

                @Override
                public Void call() {
                    // 根据当前选中
                    ((Node) parent).attachChild(finalModel);
                    return null;
                }
            }).get();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
    // 绑定端子
    if (readSav) {
        if (wireOrPipe instanceof Cable && termOrPort instanceof Terminal) {
            ((Cable) wireOrPipe).bindTerm(termOrPort, model);
            wireOrPipe.getModels().put(model, termOrPort);
            Wire wire = ((Cable) wireOrPipe).getNowConnectingWire();
            modifyWireNum(wire, wire.getWireNum());
        } else {
            wireOrPipe.bind(termOrPort);
            wireOrPipe.getModels().put(model, termOrPort);
            if (wireOrPipe.isBothBinded() && wireOrPipe instanceof Wire) {
                modifyWireNum(wireOrPipe, wireOrPipe.getWireNum());
            }
        }
    } else {
        bindWireOrPipe(termOrPort, model);
    }
    resetLinks(termOrPort);
    return model;
}
Also used : Cable(com.cas.circuit.vo.Cable) GasPort(com.cas.gas.vo.GasPort) ColorRGBA(com.jme3.math.ColorRGBA) Spatial(com.jme3.scene.Spatial) Node(com.jme3.scene.Node) ArrayList(java.util.ArrayList) Wire(com.cas.circuit.vo.Wire) Jack(com.cas.circuit.vo.Jack) Terminal(com.cas.circuit.vo.Terminal) Callable(java.util.concurrent.Callable) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

Terminal (com.cas.circuit.vo.Terminal)25 Jack (com.cas.circuit.vo.Jack)12 ArrayList (java.util.ArrayList)8 R (com.cas.circuit.util.R)7 Spatial (com.jme3.scene.Spatial)7 ElecCompDef (com.cas.circuit.vo.ElecCompDef)6 Wire (com.cas.circuit.vo.Wire)6 GasPort (com.cas.gas.vo.GasPort)5 Cable (com.cas.circuit.vo.Cable)4 Node (com.jme3.scene.Node)4 Map (java.util.Map)4 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)4 ResisRelation (com.cas.circuit.vo.ResisRelation)3 HashMap (java.util.HashMap)3 MesureResult (com.cas.circuit.util.MesureResult)2 CR (com.cas.circuit.vo.CR)2 ControlIO (com.cas.circuit.vo.ControlIO)2 IP (com.cas.circuit.vo.IP)2 Pipe (com.cas.gas.vo.Pipe)2 ColorRGBA (com.jme3.math.ColorRGBA)2