Search in sources :

Example 1 with ElecComp

use of com.cas.circuit.vo.ElecComp 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 2 with ElecComp

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

the class ConnectionHandler method bindSaveTransEvent.

private Cable bindSaveTransEvent(String elecCompKey, Cable cable, boolean modifiable) {
    ElecComp elecComp = eleCompMap.get(elecCompKey);
    if (elecComp == null) {
        System.err.println("找不到elecCompKey : " + elecCompKey);
        return null;
    // throw new RuntimeException("找不到elecCompKey : " + elecCompKey);
    }
    ElecCompDef def = elecComp.getDef();
    def.buildCompLogic();
    Node elecCompMdl = (Node) parent.getChild(elecComp.getPO().getMdlName());
    JmeUtil.setSpatialHighLight(elecCompMdl, ColorRGBA.BlackNoAlpha);
    // MouseEventState.cleanEvent(elecCompMdl);
    elecCompMdl.setUserData("MouseEvent", null);
    Jack jack = def.getJackMap().values().iterator().next();
    TransducersHandler handler = new TransducersHandler(this, elecComp, jack, modifiable);
    cable.bind(jack);
    cable.setElecComp(true);
    cable.getModels().put(elecCompMdl, jack);
    if (modifiable) {
        linkerData.addLinker(cable, jack, null);
    }
    handler.setCable(cable);
    addMouseEvent(elecCompMdl, new TransducersAdapter(handler));
    return cable;
}
Also used : TransducersHandler(com.cas.circuit.event.TransducersHandler) ElecCompDef(com.cas.circuit.vo.ElecCompDef) TransducersAdapter(com.cas.circuit.event.TransducersAdapter) Node(com.jme3.scene.Node) ElecComp(com.cas.circuit.vo.ElecComp) Jack(com.cas.circuit.vo.Jack)

Aggregations

ElecComp (com.cas.circuit.vo.ElecComp)2 ElecCompDef (com.cas.circuit.vo.ElecCompDef)2 LinkerEventAdapter (com.cas.circuit.event.LinkerEventAdapter)1 LinkerEventHandler (com.cas.circuit.event.LinkerEventHandler)1 TransducersAdapter (com.cas.circuit.event.TransducersAdapter)1 TransducersHandler (com.cas.circuit.event.TransducersHandler)1 Cable (com.cas.circuit.vo.Cable)1 Jack (com.cas.circuit.vo.Jack)1 Terminal (com.cas.circuit.vo.Terminal)1 Node (com.jme3.scene.Node)1 Spatial (com.jme3.scene.Spatial)1