Search in sources :

Example 1 with Wire

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

the class R method collectIsopotentialTerminal.

public static void collectIsopotentialTerminal(Terminal ref, IP isopotential, R r) {
    // }
    if (!isopotential.hasTerminal(ref)) {
        isopotential.addTerminal(ref);
    }
    // 遍历所有和ref关联的导线
    List<Terminal> wireAnotherTerms = new ArrayList<Terminal>();
    for (Wire wire : ref.getWires()) {
        if (!wire.isBothBinded()) {
            // toRemove.add(linker);
            continue;
        }
        if (isopotential.getPassedWires().contains(wire) || wire.isBrokenBreak()) {
            continue;
        }
        isopotential.getPassedWires().add(wire);
        Terminal anotherTerm = wire.getAnother(ref);
        if (anotherTerm != null) {
            // System.out.println(str + "R.collectIsopotentialTerminal ()" + wire);
            wireAnotherTerms.add(anotherTerm);
            collectIsopotentialTerminal(anotherTerm, isopotential, r);
        }
    }
    // FIXME 删除只接了一个连接头的导线????
    // wires.removeAll(toRemove);
    // 获取线缆中与ref关联的连接头
    Terminal contacted = ref.getContacted();
    if (contacted != null && !isopotential.getPassedContacted().contains(contacted)) {
        isopotential.getPassedContacted().add(contacted);
        collectIsopotentialTerminal(contacted, isopotential, r);
    }
    // 遍历和ref有电阻关系的电阻
    Map<Terminal, ResisRelation> resisRelationMap = ref.getResisRelationMap();
    Iterator<Entry<Terminal, ResisRelation>> iter = resisRelationMap.entrySet().iterator();
    Terminal key_Terminal = null;
    ResisRelation resisRelation = null;
    while (iter.hasNext()) {
        Map.Entry<Terminal, ResisRelation> entry = iter.next();
        key_Terminal = entry.getKey();
        resisRelation = entry.getValue();
        if (!isopotential.getPassedResis().contains(key_Terminal)) {
            isopotential.getPassedResis().add(key_Terminal);
            if (resisRelation.getValue() == 0 || wireAnotherTerms.contains(key_Terminal)) {
                // 阻值为零,则以ref对应的连接头递归处理   或  此电阻被短接了
                collectIsopotentialTerminal(key_Terminal, isopotential, r);
            } else {
                isopotential.getResisRelationList().add(resisRelation);
                if (r != null) {
                    // 遇到连接头是电阻的一端的,先创建出一个复合电阻对象
                    if (r.resisRelationWithCR.get(resisRelation) != null) {
                        CR cr = r.resisRelationWithCR.get(resisRelation);
                        isopotential.getCRList().add(cr);
                        cr.setIospo2(isopotential);
                    } else {
                        CR cr = new CR(r);
                        // 设置这个复合电阻的所指代的真实电阻
                        cr.addResisRelation(resisRelation);
                        isopotential.getCRList().add(cr);
                        cr.setIospo1(isopotential);
                        r.resisRelationWithCR.put(resisRelation, cr);
                    }
                }
            }
        }
    }
}
Also used : ResisRelation(com.cas.circuit.vo.ResisRelation) Entry(java.util.Map.Entry) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Wire(com.cas.circuit.vo.Wire) Terminal(com.cas.circuit.vo.Terminal) HashMap(java.util.HashMap) Map(java.util.Map) CR(com.cas.circuit.vo.CR)

Example 2 with Wire

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

the class ConnectionController method initXianLanPanel.

/**
 * 初始化线缆面板
 */
public void initXianLanPanel(List<Wire> wires, boolean visible) {
    setContentVisible("xianlanColorsContent", String.valueOf(visible));
    if (!visible) {
        cableLabels = null;
        return;
    }
    Element xianlanColorsContent = findById("xianlanColorsContent");
    if (xianlanColorsContent == null || wires == null) {
        return;
    }
    // 线缆导线排序
    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);
    List<Element> eles = xianlanColorsContent.getElements();
    for (int i = 0; i < eles.size(); i++) {
        removeXianLanItem(i);
    }
    List<String> xianLanStrs = new ArrayList<String>();
    for (int i = 0; i < wires.size(); i++) {
        String xianLanStr = wires.get(i).getPO().getMark();
        xianLanStrs.add(xianLanStr);
        Element ele = createXianLanItem(xianLanStr, wires.get(i).getPO().getColor(), i);
        if (i != 0) {
            ele.stopEffect(EffectEventId.onActive);
        }
    }
    refreshxianlanColorsContent();
    currentCableIndex = 0;
    cableLabels = new String[xianLanStrs.size()];
    xianLanStrs.toArray(cableLabels);
}
Also used : Element(de.lessvoid.nifty.elements.Element) ArrayList(java.util.ArrayList) Wire(com.cas.circuit.vo.Wire) Comparator(java.util.Comparator)

Example 3 with Wire

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

the class ConnectionHandler method onlineOrSaveLinker.

/**
 * 根据linkerInfo处理接线并记录
 */
private void onlineOrSaveLinker(LinkerMsg msg, boolean modifiable) {
    int key = msg.getKey();
    byte linkType = msg.getLinkType();
    ILinker linker = null;
    if (onlineAndSaves.containsKey(key)) {
        linker = onlineAndSaves.get(key);
    } else if (LinkerMsg.WIRE == linkType) {
        linker = new Wire(1, msg.getColor());
        onlineAndSaves.put(key, linker);
    } else if (LinkerMsg.PIPE == linkType) {
        linker = new Pipe(1, msg.getColor());
        onlineAndSaves.put(key, linker);
    } else if (LinkerMsg.CABLE_JACK == linkType || LinkerMsg.CABLE_TERM == linkType) {
        linker = cableMap.get(msg.getCableKey()).clone();
        if (msg.isElecComp()) {
            Cable cable = ((Cable) linker);
            linker = bindSaveTransEvent(msg.getElecCompKey(), cable, modifiable);
            if (linker != null) {
                onlineAndSaves.put(key, linker);
            }
            return;
        }
        onlineAndSaves.put(key, linker);
    }
    connectByLinkerInfo(msg, linker, modifiable);
}
Also used : Cable(com.cas.circuit.vo.Cable) Pipe(com.cas.gas.vo.Pipe) Wire(com.cas.circuit.vo.Wire)

Example 4 with Wire

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

the class ConnectionHandler method refreshViewPort.

public void refreshViewPort(ILinker wireOrPipe) {
    Spatial viewMdl = null;
    if (wireOrPipe instanceof Wire) {
        viewMdl = ConnectionUtil.getWireTerm();
        viewMdl.scale(500);
        viewMdl.move(4.8f, -4, -5);
    } else if (wireOrPipe instanceof Pipe) {
        viewMdl = ConnectionUtil.getPipeTerm();
        viewMdl.scale(300);
        viewMdl.move(4.2f, -3.6f, -5);
    } else if (wireOrPipe instanceof Cable) {
        viewMdl = ConnectionUtil.getJackTerm(null);
        viewMdl.scale(100);
        viewMdl.rotate(FastMath.HALF_PI, FastMath.HALF_PI, 0);
        viewMdl.move(4, -3f, -3);
    }
    viewRoot.detachAllChildren();
    if (wireOrPipe == null) {
        // FilterUtil.getBorderFilter().setEnabled(false);
        if (ui != null) {
            ui.setViewAreaVisible(false);
        }
    } else {
        JmeUtil.changeColor(((Node) viewMdl).getChild("model"), wireOrPipe.getColor());
        viewRoot.attachChild(viewMdl);
        // FilterUtil.getBorderFilter().setEnabled(true);
        if (ui != null) {
            ui.setViewAreaVisible(true);
        }
    }
    viewRoot.updateGeometricState();
}
Also used : Cable(com.cas.circuit.vo.Cable) Spatial(com.jme3.scene.Spatial) Pipe(com.cas.gas.vo.Pipe) Wire(com.cas.circuit.vo.Wire)

Example 5 with Wire

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

the class ConnectionHandler method deleteTmpLinker.

/**
 * 删除临时接线处理
 * @param linker 临时接线对象
 * @param modifiable 可以被当前用户修改的临时接线对象
 * @return
 */
private byte deleteTmpLinker(ILinker linker, boolean modifiable) {
    if (linker == null || linker.isBothBinded() || (linker.getLinkTarget1() == null && linker.getLinkTarget2() == null)) {
        return LinkerMsg.NONE_MSG;
    }
    if (!(linker instanceof Cable) || !((Cable) linker).isSinglePlug()) {
        deleteLinker(linker, modifiable);
        return LinkerMsg.DELETE_LINKER;
    }
    Cable cable = (Cable) linker;
    List<Wire> bindWires = cable.getBindWires();
    if (cable.getBindWires().size() == 0) {
        deleteLinker(linker, modifiable);
        ui.initXianLanPanel(null, false);
        return LinkerMsg.DELETE_LINKER;
    }
    Wire wire = bindWires.get(bindWires.size() - 1);
    cable.getBindWires().remove(wire);
    cable.setPrevWire(wire);
    cable.setNowConnectingWire(wire.getPO().getMark());
    Map<Spatial, ILinkTarget> mdls = wire.getModels();
    for (Spatial linkTerm : mdls.keySet()) {
        JmeUtil.detachModel(linkTerm);
        wire.getModels().remove(linkTerm);
        cable.getModels().remove(linkTerm);
    }
    wire.unbind(wire.getLinkTarget2());
    if (!modifiable) {
        return LinkerMsg.DELETE_SINGLE_TARGET;
    }
    List<Wire> wires = new ArrayList<Wire>(cable.getMark_wire().values());
    for (Wire w : cable.getBindWires()) {
        wires.remove(w);
    }
    if (wires.size() == 0) {
        ui.initXianLanPanel(null, false);
        setLineVisible(false);
    } else {
        ui.initXianLanPanel(wires, true);
        ILinkTarget target = null;
        if (bindWires.size() == 0) {
            target = cable.getLinkTarget1();
        } else {
            Wire currWire = bindWires.get(bindWires.size() - 1);
            target = currWire.getLinkTarget2();
        }
        showLineBetweenLinker(cable);
        Map<Spatial, ILinkTarget> termMdls = cable.getModels();
        for (Entry<Spatial, ILinkTarget> set : termMdls.entrySet()) {
            if (set.getValue().equals(target)) {
                refreshLineBetweenLinker(set.getKey());
                break;
            }
        }
    }
    return LinkerMsg.DELETE_SINGLE_TARGET;
}
Also used : Cable(com.cas.circuit.vo.Cable) Spatial(com.jme3.scene.Spatial) ArrayList(java.util.ArrayList) 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