Search in sources :

Example 11 with Terminal

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

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

the class CircuitState method attachToBase.

public void attachToBase(Spatial holding, ElecCompDef elecCompDef, ElecCompDef baseDef) {
    // FIXME 加入底座指定位置
    Node parent = baseDef.getSpatial();
    holding.scale(0.04f);
    holding.setLocalTranslation(0, 0, 0);
    parent.attachChild(holding);
    // 2、绑定模型对象
    elecCompDef.bindModel((Node) holding);
    // 3、添加事件
    bindElecCompEvent(elecCompDef);
    // 4、连接元器件与底座对应连接头
    Map<String, Terminal> bases = baseDef.getTerminalMap();
    elecCompDef.getStitchList().forEach(s -> {
        Terminal terminal = bases.get(s.getId());
        s.setContacted(terminal);
        terminal.setContacted(s);
    });
    // 5、绑定底座对象UUID
    String baseUuid = baseDef.getProxy().getUuid();
    elecCompDef.getProxy().setBaseUuid(baseUuid);
    combineMap.put(baseUuid, elecCompDef.getProxy().getUuid());
    // 6、最后将元器件加入列表中
    compList.add(elecCompDef);
}
Also used : Node(com.jme3.scene.Node) Terminal(com.cas.circuit.vo.Terminal)

Example 13 with Terminal

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

the class BaseElectricCompLogic method initialize.

public void initialize(Node elecCompMdl) {
    // XXX for test
    // System.out.println("BaseElectricCompLogic.initialize()" + Thread.currentThread().getName());
    // log.log(Level.INFO, "加载元器件{0},用时{1}", new Object[] { elecComp.getPO().getTagName(), System.currentTimeMillis() });
    this.elecCompMdl = elecCompMdl;
    // 读取元器件铭牌信息
    readNameplateInfo();
    // elecCompMdl = (Node) MdlMapUtil.loadMdlWithAbbr(getElecComp().getDef().getPO().getMdlRef(), app.getAssetManager());
    // elecCompMdl = (Node) parentMdl.getChild(getElecComp().getDef().getPO().getMdlRef());
    // elecCompMdl = (Node) parentMdl.getChild(getElecComp().getPO().getMdlName());
    // elecCompMdl = parentMdl;
    // registerEvent();
    // elecCompMdl.setLocalTranslation(getElecComp().getLocation());
    // elecCompMdl.rotate(getElecComp().getRotation()[0], getElecComp().getRotation()[1], getElecComp().getRotation()[2]);
    // elecCompMdl.setUserData(BaseElectricCompLogic.ELECCOMP_STATE, BaseElectricCompLogic.this);
    Spatial tempSpatial = null;
    // 遍历元气件中所有插座
    Collection<Jack> jacks = getElecComp().getDef().getJackMap().values();
    for (Jack jack : jacks) {
        tempSpatial = getChild(elecCompMdl, jack.getPO().getMdlName(), jack);
        jack.setModel(tempSpatial);
    }
    // 遍历元气件中所有连接头
    Collection<Terminal> terminals = getElecComp().getDef().getTerminalMap().values();
    for (Terminal terminal : terminals) {
        tempSpatial = getChild(elecCompMdl, terminal.getPO().getMdlName(), terminal);
        if (tempSpatial == null) {
            log.warn(elecComp.getDef().getPO().getName() + "未找到模型名为" + terminal.getPO().getMdlName() + "的端子模型!");
            continue;
        }
        terminal.setModel(tempSpatial);
        // FIXME 端子连接数量的标签
        String numStr = ((Node) tempSpatial).getChild(0).getUserData("num");
        if (Util.isNumeric(numStr)) {
            terminal.setNum(Integer.parseInt(numStr));
        } else {
            terminal.setNum(1);
        }
    }
    // 遍历元器件中所有气口
    Collection<GasPort> gasPorts = getElecComp().getDef().getGasPortMap().values();
    for (GasPort gasPort : gasPorts) {
        tempSpatial = getChild(elecCompMdl, gasPort.getPO().getMdlName(), gasPort);
        gasPort.setModel(tempSpatial);
    }
    // TODO 加入元气件按钮开关...
    ElecCompDef compDef = getElecComp().getDef();
    List<Magnetism> magnetisms = compDef.getMagnetisms();
    for (Magnetism magnetism : magnetisms) {
        // 遍历磁环静中所有按钮
        for (ControlIO controlIO : magnetism.getControlIOs()) {
            tempSpatial = getChild(elecCompMdl, controlIO.getPO().getMdlName(), controlIO);
            controlIO.setModel(tempSpatial);
        }
        // 遍历磁环静中所有指示灯
        for (LightIO lightIO : magnetism.getLightIOs()) {
            tempSpatial = getChild(elecCompMdl, lightIO.getPO().getMdlName(), lightIO);
            lightIO.setModel(tempSpatial);
        }
    }
    // 遍历元气件中所有指示灯
    for (LightIO lightIO : compDef.getLightIOs()) {
        tempSpatial = getChild(elecCompMdl, lightIO.getPO().getMdlName(), lightIO);
        lightIO.setModel(tempSpatial);
    }
}
Also used : GasPort(com.cas.gas.vo.GasPort) ElecCompDef(com.cas.circuit.vo.ElecCompDef) ControlIO(com.cas.circuit.vo.ControlIO) Terminal(com.cas.circuit.vo.Terminal) Spatial(com.jme3.scene.Spatial) Magnetism(com.cas.circuit.vo.Magnetism) Jack(com.cas.circuit.vo.Jack) LightIO(com.cas.circuit.vo.LightIO)

Example 14 with Terminal

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

the class ElecCompCPU method sendSignal.

/**
 * @param jackNm 信号发生的插孔名称
 * @param startIndex 具体的针脚号
 * @param endIndex 具体的针脚号
 * @param sign 电压对象
 */
public void sendSignal(String jackNm, String startIndex, String endIndex, CommandSignal sign) {
    synchronized (this) {
        // 判断当前插口是否允许发送指令
        Jack jack = getJackMap().get(jackNm);
        if (jack.isStopSend()) {
            log.warn("无法发送信号!![" + jackNm + "]");
            return;
        }
        Terminal startTerminal = getStitch(jackNm, startIndex);
        Terminal endTerminal = getStitch(jackNm, endIndex);
        String env = EVN_NAME_PRE + jackNm;
        R r = R.getR(env);
        if (r == null) {
            r = R.createSignal(env, startTerminal, endTerminal, 24);
            r.shareVoltage();
        }
        SignalVolt sv = (SignalVolt) r.getVoltage();
        sv.changeCommandSignal(sign);
        r.shareVoltage();
    }
}
Also used : R(com.cas.circuit.util.R) Jack(com.cas.circuit.vo.Jack) Terminal(com.cas.circuit.vo.Terminal)

Example 15 with Terminal

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

the class ElecCompCPU method getStitch.

/**
 * @param jackNm 信号发生的插孔名称
 * @param index 具体的针脚号
 */
public Terminal getStitch(String jackName, String index) {
    Jack jack = getJackMap().get(jackName);
    if (jack == null) {
        System.err.println("没有找到名称为: " + jackName + "的插孔");
    }
    Terminal stitch = jack.getStitch().get(index);
    if (stitch == null) {
        System.err.println(jackName + "插孔中没有找到第: " + index + "跟针脚");
    }
    return stitch;
}
Also used : Jack(com.cas.circuit.vo.Jack) Terminal(com.cas.circuit.vo.Terminal)

Aggregations

Terminal (com.cas.circuit.vo.Terminal)25 Jack (com.cas.circuit.vo.Jack)12 ArrayList (java.util.ArrayList)8 R (com.cas.circuit.util.R)7 Spatial (com.jme3.scene.Spatial)7 ElecCompDef (com.cas.circuit.vo.ElecCompDef)6 Wire (com.cas.circuit.vo.Wire)6 GasPort (com.cas.gas.vo.GasPort)5 Cable (com.cas.circuit.vo.Cable)4 Node (com.jme3.scene.Node)4 Map (java.util.Map)4 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)4 ResisRelation (com.cas.circuit.vo.ResisRelation)3 HashMap (java.util.HashMap)3 MesureResult (com.cas.circuit.util.MesureResult)2 CR (com.cas.circuit.vo.CR)2 ControlIO (com.cas.circuit.vo.ControlIO)2 IP (com.cas.circuit.vo.IP)2 Pipe (com.cas.gas.vo.Pipe)2 ColorRGBA (com.jme3.math.ColorRGBA)2