Search in sources :

Example 1 with WireProxy

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

the class CircuitState method readWires.

private void readWires(@Nonnull List<WireProxy> wireProxyList) {
    Map<String, ElecCompDef> compMap = compList.stream().collect(Collectors.toMap(x -> x.getProxy().getUuid(), x -> x));
    wireProxyList.forEach(proxy -> {
        ElecCompDef taggedComp1 = compMap.get(proxy.getComp1Uuid());
        Terminal term1 = taggedComp1.getTerminal(proxy.getTernimal1Id());
        ElecCompDef taggedComp2 = compMap.get(proxy.getComp2Uuid());
        Terminal term2 = taggedComp2.getTerminal(proxy.getTernimal2Id());
        Wire wire = new Wire();
        wire.setProxy(proxy);
        wire.bind(term1);
        wire.bind(term2);
        Future<Geometry> task = app.enqueue((Callable<Geometry>) () -> {
            Geometry wireMdl = JmeUtil.createCylinderLine(assetManager, proxy.getPointList(), proxy.getWidth(), proxy.getColor());
            return wireMdl;
        });
        Geometry wireMdl = null;
        try {
            wireMdl = task.get();
        } catch (Exception e) {
            LOG.error("无法加载导线模型:{}", e);
            throw new RuntimeException(e);
        }
        attachToCircuit(wireMdl, wire);
    });
}
Also used : BitmapFont(com.jme3.font.BitmapFont) URL(java.net.URL) ElecCompDef(com.cas.circuit.vo.ElecCompDef) TypicalCase(com.cas.sim.tis.entity.TypicalCase) MouseEventAdapter(com.cas.sim.tis.app.event.MouseEventAdapter) MouseAxisTrigger(com.jme3.input.controls.MouseAxisTrigger) Node(com.jme3.scene.Node) Future(java.util.concurrent.Future) ElecCompAction(com.cas.sim.tis.action.ElecCompAction) ElecComp(com.cas.sim.tis.entity.ElecComp) Map(java.util.Map) WireNumberControl(com.cas.sim.tis.app.control.WireNumberControl) WireProxy(com.cas.circuit.vo.archive.WireProxy) Archive(com.cas.circuit.vo.Archive) TagNameControl(com.cas.sim.tis.app.control.TagNameControl) AnalogListener(com.jme3.input.controls.AnalogListener) IContent(com.cas.sim.tis.view.control.IContent) PageController(com.cas.sim.tis.view.controller.PageController) TypicalCaseAction(com.cas.sim.tis.action.TypicalCaseAction) Set(java.util.Set) ActionListener(com.jme3.input.controls.ActionListener) CollisionResult(com.jme3.collision.CollisionResult) Collectors(java.util.stream.Collectors) Platform(javafx.application.Platform) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Jack(com.cas.circuit.vo.Jack) Geometry(com.jme3.scene.Geometry) ControlIO(com.cas.circuit.vo.ControlIO) HintControl(com.cas.sim.tis.app.control.HintControl) Terminal(com.cas.circuit.vo.Terminal) ElecCompProxy(com.cas.circuit.vo.archive.ElecCompProxy) JmeUtil(com.cas.sim.tis.util.JmeUtil) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) TypicalCase3D(com.cas.sim.tis.view.control.imp.jme.TypicalCase3D) MouseButtonTrigger(com.jme3.input.controls.MouseButtonTrigger) MouseInput(com.jme3.input.MouseInput) FastMath(com.jme3.math.FastMath) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Spatial(com.jme3.scene.Spatial) Line(com.jme3.scene.shape.Line) SpringUtil(com.cas.sim.tis.util.SpringUtil) MouseEvent(com.cas.sim.tis.app.event.MouseEvent) Nonnull(javax.annotation.Nonnull) CfgConst(com.cas.circuit.CfgConst) Vector3f(com.jme3.math.Vector3f) Wire(com.cas.circuit.vo.Wire) CullHint(com.jme3.scene.Spatial.CullHint) Quaternion(com.jme3.math.Quaternion) HTTPUtils(com.cas.sim.tis.util.HTTPUtils) JaxbUtil(com.cas.sim.tis.xml.util.JaxbUtil) ModelKey(com.jme3.asset.ModelKey) ColorRGBA(com.jme3.math.ColorRGBA) StringUtils(org.springframework.util.StringUtils) BitmapText(com.jme3.font.BitmapText) Geometry(com.jme3.scene.Geometry) ElecCompDef(com.cas.circuit.vo.ElecCompDef) Wire(com.cas.circuit.vo.Wire) Terminal(com.cas.circuit.vo.Terminal)

Example 2 with WireProxy

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

the class CircuitState method saveWires.

private void saveWires(Archive archive) {
    wireList.forEach(wire -> {
        WireProxy wireProxy = wire.getProxy();
        wireProxy.setNumber(wire.getWireNum());
        wireProxy.setComp1Uuid(wire.getTerm1().getElecComp().getProxy().getUuid());
        wireProxy.setTernimal1Id(wire.getTerm1().getId());
        wireProxy.setComp2Uuid(wire.getTerm2().getElecComp().getProxy().getUuid());
        wireProxy.setTernimal2Id(wire.getTerm2().getId());
        // 
        archive.getWireList().add(wireProxy);
    });
}
Also used : WireProxy(com.cas.circuit.vo.archive.WireProxy)

Example 3 with WireProxy

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

the class TypicalCase3D method showPopupMenu.

public void showPopupMenu(Wire wire) {
    ContextMenu menu = null;
    WireProxy proxy = wire.getProxy();
    String key = String.format("%s%s-%s%s", proxy.getComp1Uuid(), proxy.getTernimal1Id(), proxy.getComp2Uuid(), proxy.getTernimal2Id());
    if (menus.containsKey(key)) {
        menu = menus.get(key);
    } else {
        MenuItem tag = new MenuItem(MsgUtil.getMessage("typical.case.wire.num"));
        tag.setOnAction(e -> {
            TextInputDialog steamIdDialog = new TextInputDialog(proxy.getNumber());
            steamIdDialog.setTitle(MsgUtil.getMessage("typical.case.wire.num"));
            steamIdDialog.setHeaderText(null);
            steamIdDialog.getEditor().textProperty().addListener((b, o, n) -> {
                Pattern pat = Pattern.compile(REGEX_CHINESE);
                Matcher mat = pat.matcher(n);
                if (mat.find()) {
                    steamIdDialog.getEditor().setText(o);
                }
            });
            steamIdDialog.setContentText(MsgUtil.getMessage("typical.case.prompt.input.wire.num"));
            steamIdDialog.showAndWait().ifPresent(number -> {
                wire.getProxy().setNumber(number);
                CircuitState state = jmeApp.getStateManager().getState(CircuitState.class);
                if (state == null) {
                    return;
                }
                state.setTagNameChanged(true);
            });
        });
        MenuItem del = new MenuItem(MsgUtil.getMessage("button.delete"));
        del.setOnAction(e -> {
            CircuitState state = jmeApp.getStateManager().getState(CircuitState.class);
            if (state == null) {
                return;
            }
            boolean enable = state.detachFromCircuit(wire);
            if (enable) {
                menus.remove(key);
            } else {
                AlertUtil.showAlert(AlertType.WARNING, MsgUtil.getMessage("alert.warning.wiring"));
            }
        });
        menu = new ContextMenu(tag, del);
    }
    Point anchor = MouseInfo.getPointerInfo().getLocation();
    menu.show(GUIState.getStage(), anchor.x, anchor.y);
}
Also used : WireProxy(com.cas.circuit.vo.archive.WireProxy) CircuitState(com.cas.sim.tis.app.state.CircuitState) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ContextMenu(javafx.scene.control.ContextMenu) MenuItem(javafx.scene.control.MenuItem) Point(java.awt.Point) TextInputDialog(javafx.scene.control.TextInputDialog)

Aggregations

WireProxy (com.cas.circuit.vo.archive.WireProxy)3 CfgConst (com.cas.circuit.CfgConst)1 Archive (com.cas.circuit.vo.Archive)1 ControlIO (com.cas.circuit.vo.ControlIO)1 ElecCompDef (com.cas.circuit.vo.ElecCompDef)1 Jack (com.cas.circuit.vo.Jack)1 Terminal (com.cas.circuit.vo.Terminal)1 Wire (com.cas.circuit.vo.Wire)1 ElecCompProxy (com.cas.circuit.vo.archive.ElecCompProxy)1 ElecCompAction (com.cas.sim.tis.action.ElecCompAction)1 TypicalCaseAction (com.cas.sim.tis.action.TypicalCaseAction)1 HintControl (com.cas.sim.tis.app.control.HintControl)1 TagNameControl (com.cas.sim.tis.app.control.TagNameControl)1 WireNumberControl (com.cas.sim.tis.app.control.WireNumberControl)1 MouseEvent (com.cas.sim.tis.app.event.MouseEvent)1 MouseEventAdapter (com.cas.sim.tis.app.event.MouseEventAdapter)1 CircuitState (com.cas.sim.tis.app.state.CircuitState)1 ElecComp (com.cas.sim.tis.entity.ElecComp)1 TypicalCase (com.cas.sim.tis.entity.TypicalCase)1 HTTPUtils (com.cas.sim.tis.util.HTTPUtils)1