Search in sources :

Example 1 with IContent

use of com.cas.sim.tis.view.control.IContent 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 IContent

use of com.cas.sim.tis.view.control.IContent in project TeachingInSimulation by ScOrPiOzzy.

the class CircuitState method bindWireEvent.

private void bindWireEvent(Geometry wireMdl, final Wire wire) {
    addListener(wireMdl, new MouseEventAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            for (Wire w : wireList) {
                Spatial mdl = w.getSpatial();
                HintControl control = mdl.getControl(HintControl.class);
                boolean enable = w == wire;
                if (control != null) {
                    mdl.removeControl(control);
                } else if (enable) {
                    control = new HintControl();
                    mdl.addControl(control);
                }
            }
            super.mouseClicked(e);
        }

        @Override
        public void mouseRightClicked(MouseEvent e) {
            // 选中显示导线菜单
            IContent content = SpringUtil.getBean(PageController.class).getIContent();
            if (content instanceof TypicalCase3D) {
                Platform.runLater(() -> {
                    ((TypicalCase3D) content).showPopupMenu(wire);
                });
            }
            super.mouseRightClicked(e);
        }
    });
}
Also used : MouseEvent(com.cas.sim.tis.app.event.MouseEvent) Spatial(com.jme3.scene.Spatial) IContent(com.cas.sim.tis.view.control.IContent) MouseEventAdapter(com.cas.sim.tis.app.event.MouseEventAdapter) HintControl(com.cas.sim.tis.app.control.HintControl) Wire(com.cas.circuit.vo.Wire) TypicalCase3D(com.cas.sim.tis.view.control.imp.jme.TypicalCase3D)

Example 3 with IContent

use of com.cas.sim.tis.view.control.IContent in project TeachingInSimulation by ScOrPiOzzy.

the class TypicalCaseState method initializeLocal.

@Override
protected void initializeLocal() {
    // 布置场景
    arrangementScene();
    // 添加操作模式State
    cameraState = new SceneCameraState();
    stateManager.attach(cameraState);
    // 绑定事件
    bindEvents();
    // 默认新建案例
    IContent content = SpringUtil.getBean(PageController.class).getIContent();
    if (content instanceof TypicalCase3D) {
        ((TypicalCase3D) content).setupCase(new TypicalCase());
    }
    // 结束加载界面
    Platform.runLater(() -> SpringUtil.getBean(PageController.class).hideLoading());
}
Also used : PageController(com.cas.sim.tis.view.controller.PageController) IContent(com.cas.sim.tis.view.control.IContent) TypicalCase(com.cas.sim.tis.entity.TypicalCase) TypicalCase3D(com.cas.sim.tis.view.control.imp.jme.TypicalCase3D)

Aggregations

IContent (com.cas.sim.tis.view.control.IContent)3 TypicalCase3D (com.cas.sim.tis.view.control.imp.jme.TypicalCase3D)3 MouseEvent (com.cas.sim.tis.app.event.MouseEvent)2 MouseEventAdapter (com.cas.sim.tis.app.event.MouseEventAdapter)2 ControlIO (com.cas.circuit.vo.ControlIO)1 Wire (com.cas.circuit.vo.Wire)1 HintControl (com.cas.sim.tis.app.control.HintControl)1 TypicalCase (com.cas.sim.tis.entity.TypicalCase)1 PageController (com.cas.sim.tis.view.controller.PageController)1 Spatial (com.jme3.scene.Spatial)1