Search in sources :

Example 6 with Wire

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

the class ConnectionHandler method bindWireOrPipe.

/**
 * 绑定端点
 * @param termOrPort 点击接线的端点信息对象,或者气口信息对象
 */
private void bindWireOrPipe(ILinkTarget termOrPort, Spatial mdl) {
    setHighLightLinker(selected, false);
    if (currLinker instanceof Cable && termOrPort instanceof Terminal) {
        Cable cable = ((Cable) currLinker);
        // 如果当前绑定为线缆上的导线
        cable.bindTerm(termOrPort, mdl);
        // 接完线 显示号码管对话框
        ui.setNumDialogueVisible(true);
        modifyLinker = currLinker;
        List<Wire> wires = new ArrayList<Wire>(cable.getMark_wire().values());
        // 线缆导线排序
        for (Wire w : cable.getBindWires()) {
            wires.remove(w);
        }
        Comparator<Wire> comparator = new Comparator<Wire>() {

            @Override
            public int compare(Wire wire1, Wire wire2) {
                return wire1.getPO().getStitch1().compareTo(wire2.getPO().getStitch1());
            }
        };
        Collections.sort(wires, comparator);
        if (wires.size() == 0) {
            cable.setNowConnectingWire(null);
        } else {
            cable.setNowConnectingWire(wires.get(0).getPO().getMark());
        }
    } else {
        // 其他普通情况绑定
        currLinker.bind(termOrPort);
        if (currLinker.isBothBinded() && currLinker instanceof Wire) {
            // 接完线 显示号码管对话框
            ui.setNumDialogueVisible(true);
            modifyLinker = currLinker;
        }
    }
    currLinker.getModels().put(mdl, termOrPort);
    // 显示或隐藏与鼠标连接的直线
    setLineVisible(true);
    if (!currLinker.isBothBinded()) {
        return;
    }
    setLineVisible(false);
    ui.initXianLanPanel(null, false);
    // 取消接线完成的元器件高亮
    if (currLinker instanceof Cable && ((Cable) currLinker).isElecComp()) {
        Map<Spatial, ILinkTarget> models = currLinker.getModels();
        for (Spatial spatial : models.keySet()) {
            // JmeUtil.setMaterialEffect(Dispatcher.getIns().getMainApp(), HightLightType.GLOW, spatial, ColorConsts.TRANSDUCERS, false);
            JmeUtil.setSpatialHighLight(spatial, ColorRGBA.BlackNoAlpha);
        }
    }
    if (termOrPort instanceof Terminal) {
        if (currLinker instanceof Cable) {
            Cable cable = new Cable();
            currLinker = cable;
        } else {
            Wire wire = new Wire(1, color);
            currLinker = wire;
        }
    } else if (termOrPort instanceof GasPort) {
        Pipe pipe = new Pipe(1, color);
        currLinker = pipe;
    } else if (termOrPort instanceof Jack) {
        Cable cable = new Cable();
        currLinker = cable;
    }
}
Also used : Cable(com.cas.circuit.vo.Cable) GasPort(com.cas.gas.vo.GasPort) ArrayList(java.util.ArrayList) Pipe(com.cas.gas.vo.Pipe) Wire(com.cas.circuit.vo.Wire) Terminal(com.cas.circuit.vo.Terminal) Comparator(java.util.Comparator) Spatial(com.jme3.scene.Spatial) Jack(com.cas.circuit.vo.Jack)

Example 7 with Wire

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

the class ConnectionHandler method connect.

/**
 * 接线处理
 * @param wireOrPipe 导线、气管
 * @param termOrPort 端子、气口
 */
private Spatial connect(ILinker wireOrPipe, ILinkTarget termOrPort, boolean readSav) {
    // 旋转端子上包括新增接线头在内的若干个接线头
    Spatial model = null;
    ColorRGBA color = null;
    if (termOrPort instanceof Terminal) {
        model = ConnectionUtil.getWireTerm();
        if (wireOrPipe instanceof Cable) {
            Cable cable = (Cable) wireOrPipe;
            Wire wire = cable.getNowConnectingWire();
            model.setUserData("WireMark", wire.getPO().getMark());
            // 添加已经接上端子的导线
            cable.getBindWires().add(wire);
            // 除去已经连接的导线
            if (!readSav) {
                List<Wire> wires = new ArrayList<Wire>(cable.getMark_wire().values());
                for (Wire w : cable.getBindWires()) {
                    wires.remove(w);
                }
                ui.initXianLanPanel(wires, true);
            }
            color = wire.getColor();
        } else {
            color = wireOrPipe.getColor();
            currSaveLinker = null;
        }
    } else if (termOrPort instanceof GasPort) {
        model = ConnectionUtil.getPipeTerm();
        color = wireOrPipe.getColor();
        currSaveLinker = null;
    } else if (termOrPort instanceof Jack) {
        Jack jack = (Jack) termOrPort;
        model = ConnectionUtil.getJackTerm(jack.getFormat());
        Cable cable = (Cable) jack.getLinkers().get(0);
        cable = cable.clone();
        if (readSav) {
            cable = (Cable) wireOrPipe;
        }
        color = cable.getColor();
        currSaveLinker = null;
        // 通过jack获得当前的接线线缆
        if (((Cable) wireOrPipe).getPlug1() == null && ((Cable) wireOrPipe).getPlug2() == null) {
            if (readSav) {
                wireOrPipe = cable;
                currSaveLinker = wireOrPipe;
            } else {
                currLinker = cable;
            }
        }
        // 如果是单连接头线缆,则显示导线面板
        if (cable.isSinglePlug() && !readSav) {
            List<Wire> wires = new ArrayList<Wire>(cable.getMark_wire().values());
            ui.initXianLanPanel(wires, true);
            cable.setNowConnectingWire(wires.get(0).getPO().getMark());
        }
    }
    // 添加新的接线头到端子上
    Node target = (Node) termOrPort.getModel();
    final Node parent = target.getParent();
    Spatial screw = target.getChild("screw");
    if (screw != null) {
        model.setLocalTranslation(JmeUtil.getTransLation(screw, parent));
    } else {
        model.setLocalTranslation(target.getLocalTranslation());
    }
    // 修改连接头颜色
    JmeUtil.changeColor(((Node) model).getChild("model"), color);
    model.setUserData("Color", color);
    // 获得端子模型的父节点
    if (JmeUtil.isJMEThread()) {
        ((Node) parent).attachChild(model);
    } else {
        final Spatial finalModel = model;
        try {
            app.enqueue(new Callable<Void>() {

                @Override
                public Void call() {
                    // 根据当前选中
                    ((Node) parent).attachChild(finalModel);
                    return null;
                }
            }).get();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
    // 绑定端子
    if (readSav) {
        if (wireOrPipe instanceof Cable && termOrPort instanceof Terminal) {
            ((Cable) wireOrPipe).bindTerm(termOrPort, model);
            wireOrPipe.getModels().put(model, termOrPort);
            Wire wire = ((Cable) wireOrPipe).getNowConnectingWire();
            modifyWireNum(wire, wire.getWireNum());
        } else {
            wireOrPipe.bind(termOrPort);
            wireOrPipe.getModels().put(model, termOrPort);
            if (wireOrPipe.isBothBinded() && wireOrPipe instanceof Wire) {
                modifyWireNum(wireOrPipe, wireOrPipe.getWireNum());
            }
        }
    } else {
        bindWireOrPipe(termOrPort, model);
    }
    resetLinks(termOrPort);
    return model;
}
Also used : Cable(com.cas.circuit.vo.Cable) GasPort(com.cas.gas.vo.GasPort) ColorRGBA(com.jme3.math.ColorRGBA) Spatial(com.jme3.scene.Spatial) Node(com.jme3.scene.Node) ArrayList(java.util.ArrayList) Wire(com.cas.circuit.vo.Wire) Jack(com.cas.circuit.vo.Jack) Terminal(com.cas.circuit.vo.Terminal) Callable(java.util.concurrent.Callable) FileNotFoundException(java.io.FileNotFoundException)

Example 8 with Wire

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

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

the class CircuitState method connectPre.

// 点击连接头、开始接线之前的准备工作
private void connectPre(ElecCompDef def, Terminal t) {
    // 创建一个节点,存放当前一根导线的模型
    tmpWireNode = new Node();
    // 将导线模型添加到root节点中以显示
    rootWireNode.attachChild(tmpWireNode);
    // 创建一个导线逻辑对象
    wire = new Wire();
    // 导线颜色和线宽
    wire.getProxy().setColor(color);
    wire.getProxy().setWidth(width);
    // 导线一头连接在当前连接头上
    wire.bind(t);
    // FIXME 导线连接的位置,多跟导线的情况下错开
    Vector3f dest = t.getSpatial().getWorldTranslation().clone();
    // 获取导线连接的方向
    dir = def.getSpatial().getLocalRotation().mult(t.getDirection());
    midAxis = roll90.mult(dir);
    // 钱三段导线
    // 
    startLine1 = new Line(dest, dest);
    startLine2 = new Line(dest, dest);
    startLine3 = new Line(dest, dest);
    tmpWireNode.attachChild(JmeUtil.createLineGeo(assetManager, startLine1, color));
    tmpWireNode.attachChild(JmeUtil.createLineGeo(assetManager, startLine2, color));
    tmpWireNode.attachChild(JmeUtil.createLineGeo(assetManager, startLine3, color));
}
Also used : Line(com.jme3.scene.shape.Line) Node(com.jme3.scene.Node) Vector3f(com.jme3.math.Vector3f) Wire(com.cas.circuit.vo.Wire)

Example 10 with Wire

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

the class LinkerData method removeLinker.

public void removeLinker(ILinker linker) {
    int hashCode = linker.hashCode();
    ILinkTarget target1 = linker.getLinkTarget1();
    removeTarget(hashCode, target1);
    ILinkTarget target2 = linker.getLinkTarget2();
    removeTarget(hashCode, target2);
    if (linker instanceof Cable && ((Cable) linker).isSinglePlug()) {
        for (Wire wire : ((Cable) linker).getMark_wire().values()) {
            target1 = wire.getLinkTarget1();
            removeTarget(hashCode, target1);
            target2 = wire.getLinkTarget2();
            removeTarget(hashCode, target2);
        }
    }
}
Also used : Cable(com.cas.circuit.vo.Cable) Wire(com.cas.circuit.vo.Wire)

Aggregations

Wire (com.cas.circuit.vo.Wire)23 Cable (com.cas.circuit.vo.Cable)13 Spatial (com.jme3.scene.Spatial)9 ArrayList (java.util.ArrayList)9 Pipe (com.cas.gas.vo.Pipe)7 Terminal (com.cas.circuit.vo.Terminal)6 Jack (com.cas.circuit.vo.Jack)5 LinkerMsg (com.cas.circuit.msg.LinkerMsg)4 Node (com.jme3.scene.Node)4 ElecCompDef (com.cas.circuit.vo.ElecCompDef)3 GasPort (com.cas.gas.vo.GasPort)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ResisRelation (com.cas.circuit.vo.ResisRelation)2 HintControl (com.cas.sim.tis.app.control.HintControl)2 TagNameControl (com.cas.sim.tis.app.control.TagNameControl)2 WireNumberControl (com.cas.sim.tis.app.control.WireNumberControl)2 MouseEvent (com.cas.sim.tis.app.event.MouseEvent)2 MouseEventAdapter (com.cas.sim.tis.app.event.MouseEventAdapter)2 IContent (com.cas.sim.tis.view.control.IContent)2