Search in sources :

Example 1 with MouseEventAdapter

use of com.cas.sim.tis.app.event.MouseEventAdapter 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 MouseEventAdapter

use of com.cas.sim.tis.app.event.MouseEventAdapter 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 MouseEventAdapter

use of com.cas.sim.tis.app.event.MouseEventAdapter in project TeachingInSimulation by ScOrPiOzzy.

the class ElecCompState method setElecComp.

@JmeThread
public void setElecComp(ElecComp elecComp) {
    // clean up
    cleanRoot();
    // 加载模型(认知模块使用AnimPath的model)
    Spatial model = loadAsset(new ModelKey(elecComp.getAnimPath()));
    // PBR能在系统中被照亮
    // MikktspaceTangentGenerator.generate(model);
    // 将模型放大100倍
    model.scale(100);
    root.attachChild(model);
    // 
    // 获取相应元器件
    ElecCompDef elecCompDef = SpringUtil.getBean(ElecCompAction.class).parse(elecComp.getCfgPath());
    // 找出元器件外壳模型名称
    loadShell(elecCompDef.getParam(ElecCompDef.PARAM_KEY_SHELL));
    // FIXME 这里应更为精准地设置为元器件模型。
    elecCompDef.bindModel(root);
    // 添加事件
    Map<Spatial, String> nameMap = collectName(elecCompDef);
    nameMap.entrySet().forEach(e -> addListener(e.getKey(), new MouseEventAdapter() {

        @Override
        public void mouseClicked(MouseEvent evt) {
            if (!pickEnable) {
                return;
            }
            // FilterUtil.showOutlineEffect(evt.getSpatial());
            System.out.println("ElecCompState.setElecComp(...).new MouseEventAdapter() {...}.mouseClicked()");
            Vector3f point = cam.getScreenCoordinates(evt.getContactPoint());
            Platform.runLater(() -> ui.showName(e.getValue(), point.getX(), point.getY()));
        }
    }));
    explode0();
}
Also used : ModelKey(com.jme3.asset.ModelKey) ElecCompDef(com.cas.circuit.vo.ElecCompDef) ElecCompAction(com.cas.sim.tis.action.ElecCompAction) MouseEvent(com.cas.sim.tis.app.event.MouseEvent) Spatial(com.jme3.scene.Spatial) MouseEventAdapter(com.cas.sim.tis.app.event.MouseEventAdapter) Vector3f(com.jme3.math.Vector3f) JmeThread(com.cas.sim.tis.anno.JmeThread)

Example 4 with MouseEventAdapter

use of com.cas.sim.tis.app.event.MouseEventAdapter in project TeachingInSimulation by ScOrPiOzzy.

the class TypicalCaseState method bindEvents.

private void bindEvents() {
    listener = new TypicalCaseListener(this);
    listener.registerWithInput(inputManager);
    addListener(desktop, new MouseEventAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (elecComp == null) {
                return;
            }
            // moved_before_putdown = false;
            putDown();
            super.mouseClicked(e);
        }

        @Override
        public void mouseRightClicked(MouseEvent e) {
            if (holding == null) {
                return;
            }
            holding.removeFromParent();
            holding = null;
            elecComp = null;
            cameraState.setZoomEnable(true);
            super.mouseRightClicked(e);
        }
    });
}
Also used : TypicalCaseListener(com.cas.sim.tis.app.listener.TypicalCaseListener) MouseEvent(com.cas.sim.tis.app.event.MouseEvent) MouseEventAdapter(com.cas.sim.tis.app.event.MouseEventAdapter)

Aggregations

MouseEvent (com.cas.sim.tis.app.event.MouseEvent)4 MouseEventAdapter (com.cas.sim.tis.app.event.MouseEventAdapter)4 IContent (com.cas.sim.tis.view.control.IContent)2 TypicalCase3D (com.cas.sim.tis.view.control.imp.jme.TypicalCase3D)2 Spatial (com.jme3.scene.Spatial)2 ControlIO (com.cas.circuit.vo.ControlIO)1 ElecCompDef (com.cas.circuit.vo.ElecCompDef)1 Wire (com.cas.circuit.vo.Wire)1 ElecCompAction (com.cas.sim.tis.action.ElecCompAction)1 JmeThread (com.cas.sim.tis.anno.JmeThread)1 HintControl (com.cas.sim.tis.app.control.HintControl)1 TypicalCaseListener (com.cas.sim.tis.app.listener.TypicalCaseListener)1 ModelKey (com.jme3.asset.ModelKey)1 Vector3f (com.jme3.math.Vector3f)1