Search in sources :

Example 1 with ControlIO

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

the class CircuitState method bindElecCompEvent.

private void bindElecCompEvent(ElecCompDef def) {
    // 1、连接头监听事件
    def.getTerminalList().forEach(t -> addListener(t.getSpatial(), new MouseEventAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (state == null || state == State.Ending) {
                connectPre(def, t);
                // 设置接线状态为开始
                state = State.Starting;
            } else if (state == State.Mid) {
                // 
                connectEnding(def, t);
                state = State.Ending;
            } else if (state == State.Ending) {
            // do nothing
            }
        }
    }));
    // 2、插孔监听事件
    def.getJackList().forEach(j -> addListener(j.getSpatial(), new MouseEventAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            System.out.println(j.getName());
        }
    }));
    // 3、按钮监听事件
    def.getMagnetismList().forEach(m -> {
        for (ControlIO c : m.getControlIOList()) {
            if (c.getType().indexOf(CfgConst.SWITCH_CTRL_INPUT) == -1) {
                continue;
            }
            if (ControlIO.INTERACT_ROTATE.equals(c.getInteract())) {
                addListener(c.getSpatial(), new MouseEventAdapter() {

                    @Override
                    public void mouseWheel(MouseEvent e) {
                        c.switchStateChanged(e.getWheel());
                        c.playMotion();
                    }
                });
            } else if (ControlIO.INTERACT_PRESS.equals(c.getInteract())) {
                addListener(c.getSpatial(), new MouseEventAdapter() {

                    @Override
                    public void mousePressed(MouseEvent e) {
                        c.switchStateChanged(null);
                        c.playMotion();
                    }

                    @Override
                    public void mouseReleased(MouseEvent e) {
                        c.switchStateChanged(null);
                        c.playMotion();
                    }
                });
            } else {
                addListener(c.getSpatial(), new MouseEventAdapter() {

                    @Override
                    public void mouseClicked(MouseEvent e) {
                        c.switchStateChanged(null);
                        c.playMotion();
                    }
                });
            }
        }
    });
    // 4、元器件本身的监听事件
    addListener(def.getSpatial(), new MouseEventAdapter() {

        @Override
        public void mouseRightClicked(MouseEvent e) {
            super.mouseRightClicked(e);
            IContent content = SpringUtil.getBean(PageController.class).getIContent();
            if (content instanceof TypicalCase3D) {
                Platform.runLater(() -> {
                    ((TypicalCase3D) content).showPopupMenu(def);
                });
            }
        }
    });
    // 5、若当前为底座添加监听事件
    if (ElecComp.COMBINE_BUTTOM == def.getElecComp().getCombine()) {
        addListener(def.getSpatial(), new MouseEventAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                // 判断当前底座是否已经被占用
                if (StringUtils.isEmpty(combineMap.get(def.getProxy().getUuid()))) {
                    TypicalCaseState caseState = stateManager.getState(TypicalCaseState.class);
                    caseState.putDownOnBase(def);
                    super.mouseClicked(e);
                }
            }
        });
    }
}
Also used : MouseEvent(com.cas.sim.tis.app.event.MouseEvent) IContent(com.cas.sim.tis.view.control.IContent) MouseEventAdapter(com.cas.sim.tis.app.event.MouseEventAdapter) ControlIO(com.cas.circuit.vo.ControlIO) TypicalCase3D(com.cas.sim.tis.view.control.imp.jme.TypicalCase3D)

Example 2 with ControlIO

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

the class BaseElectricCompLogic method initialize.

public void initialize(Node elecCompMdl) {
    // XXX for test
    // System.out.println("BaseElectricCompLogic.initialize()" + Thread.currentThread().getName());
    // log.log(Level.INFO, "加载元器件{0},用时{1}", new Object[] { elecComp.getPO().getTagName(), System.currentTimeMillis() });
    this.elecCompMdl = elecCompMdl;
    // 读取元器件铭牌信息
    readNameplateInfo();
    // elecCompMdl = (Node) MdlMapUtil.loadMdlWithAbbr(getElecComp().getDef().getPO().getMdlRef(), app.getAssetManager());
    // elecCompMdl = (Node) parentMdl.getChild(getElecComp().getDef().getPO().getMdlRef());
    // elecCompMdl = (Node) parentMdl.getChild(getElecComp().getPO().getMdlName());
    // elecCompMdl = parentMdl;
    // registerEvent();
    // elecCompMdl.setLocalTranslation(getElecComp().getLocation());
    // elecCompMdl.rotate(getElecComp().getRotation()[0], getElecComp().getRotation()[1], getElecComp().getRotation()[2]);
    // elecCompMdl.setUserData(BaseElectricCompLogic.ELECCOMP_STATE, BaseElectricCompLogic.this);
    Spatial tempSpatial = null;
    // 遍历元气件中所有插座
    Collection<Jack> jacks = getElecComp().getDef().getJackMap().values();
    for (Jack jack : jacks) {
        tempSpatial = getChild(elecCompMdl, jack.getPO().getMdlName(), jack);
        jack.setModel(tempSpatial);
    }
    // 遍历元气件中所有连接头
    Collection<Terminal> terminals = getElecComp().getDef().getTerminalMap().values();
    for (Terminal terminal : terminals) {
        tempSpatial = getChild(elecCompMdl, terminal.getPO().getMdlName(), terminal);
        if (tempSpatial == null) {
            log.warn(elecComp.getDef().getPO().getName() + "未找到模型名为" + terminal.getPO().getMdlName() + "的端子模型!");
            continue;
        }
        terminal.setModel(tempSpatial);
        // FIXME 端子连接数量的标签
        String numStr = ((Node) tempSpatial).getChild(0).getUserData("num");
        if (Util.isNumeric(numStr)) {
            terminal.setNum(Integer.parseInt(numStr));
        } else {
            terminal.setNum(1);
        }
    }
    // 遍历元器件中所有气口
    Collection<GasPort> gasPorts = getElecComp().getDef().getGasPortMap().values();
    for (GasPort gasPort : gasPorts) {
        tempSpatial = getChild(elecCompMdl, gasPort.getPO().getMdlName(), gasPort);
        gasPort.setModel(tempSpatial);
    }
    // TODO 加入元气件按钮开关...
    ElecCompDef compDef = getElecComp().getDef();
    List<Magnetism> magnetisms = compDef.getMagnetisms();
    for (Magnetism magnetism : magnetisms) {
        // 遍历磁环静中所有按钮
        for (ControlIO controlIO : magnetism.getControlIOs()) {
            tempSpatial = getChild(elecCompMdl, controlIO.getPO().getMdlName(), controlIO);
            controlIO.setModel(tempSpatial);
        }
        // 遍历磁环静中所有指示灯
        for (LightIO lightIO : magnetism.getLightIOs()) {
            tempSpatial = getChild(elecCompMdl, lightIO.getPO().getMdlName(), lightIO);
            lightIO.setModel(tempSpatial);
        }
    }
    // 遍历元气件中所有指示灯
    for (LightIO lightIO : compDef.getLightIOs()) {
        tempSpatial = getChild(elecCompMdl, lightIO.getPO().getMdlName(), lightIO);
        lightIO.setModel(tempSpatial);
    }
}
Also used : GasPort(com.cas.gas.vo.GasPort) ElecCompDef(com.cas.circuit.vo.ElecCompDef) ControlIO(com.cas.circuit.vo.ControlIO) Terminal(com.cas.circuit.vo.Terminal) Spatial(com.jme3.scene.Spatial) Magnetism(com.cas.circuit.vo.Magnetism) Jack(com.cas.circuit.vo.Jack) LightIO(com.cas.circuit.vo.LightIO)

Example 3 with ControlIO

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

the class VS10N051CLogic method initialize.

@Override
public void initialize(Node elecCompMdl) {
    super.initialize(elecCompMdl);
    List<Magnetism> magnetisms = elecComp.getDef().getMagnetisms();
    for (Magnetism magnetism : magnetisms) {
        List<ControlIO> controlIOs = magnetism.getControlIOs();
        for (ControlIO controlIO : controlIOs) {
            button = controlIO;
            break;
        }
    }
    // 添加碰撞监听control
    control = new VS10N051CControl(button);
    elecCompMdl.addControl(control);
}
Also used : VS10N051CControl(com.cas.circuit.control.VS10N051CControl) ControlIO(com.cas.circuit.vo.ControlIO) Magnetism(com.cas.circuit.vo.Magnetism)

Aggregations

ControlIO (com.cas.circuit.vo.ControlIO)3 Magnetism (com.cas.circuit.vo.Magnetism)2 VS10N051CControl (com.cas.circuit.control.VS10N051CControl)1 ElecCompDef (com.cas.circuit.vo.ElecCompDef)1 Jack (com.cas.circuit.vo.Jack)1 LightIO (com.cas.circuit.vo.LightIO)1 Terminal (com.cas.circuit.vo.Terminal)1 GasPort (com.cas.gas.vo.GasPort)1 MouseEvent (com.cas.sim.tis.app.event.MouseEvent)1 MouseEventAdapter (com.cas.sim.tis.app.event.MouseEventAdapter)1 IContent (com.cas.sim.tis.view.control.IContent)1 TypicalCase3D (com.cas.sim.tis.view.control.imp.jme.TypicalCase3D)1 Spatial (com.jme3.scene.Spatial)1