Search in sources :

Example 1 with Magnetism

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

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

the class VS10N051CLogic method initialize.

@Override
public void initialize(Node elecCompMdl) {
    super.initialize(elecCompMdl);
    List<Magnetism> magnetisms = elecComp.getDef().getMagnetisms();
    for (Magnetism magnetism : magnetisms) {
        List<ControlIO> controlIOs = magnetism.getControlIOs();
        for (ControlIO controlIO : controlIOs) {
            button = controlIO;
            break;
        }
    }
    // 添加碰撞监听control
    control = new VS10N051CControl(button);
    elecCompMdl.addControl(control);
}
Also used : VS10N051CControl(com.cas.circuit.control.VS10N051CControl) ControlIO(com.cas.circuit.vo.ControlIO) Magnetism(com.cas.circuit.vo.Magnetism)

Example 3 with Magnetism

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

the class SensorLogic method initialize.

@Override
public void initialize(Node elecCompMdl) {
    super.initialize(elecCompMdl);
    Magnetism magnetism = elecComp.getDef().getMagnetisms().iterator().next();
    if (magnetism == null) {
        log.error("传感器配置有问题");
    }
    sensorIO = magnetism.getSensorIOs().iterator().next();
    if (sensorIO == null) {
        log.error("传感器配置有问题");
    }
    elecCompMdl.addControl(this);
    try {
        start = elecCompMdl.getChild("start");
        end = elecCompMdl.getChild("end");
        Vector3f origin = start.getWorldTranslation();
        Vector3f goal = end.getWorldTranslation();
        // spatial.getUserData("limit");
        limit = FastMath.abs(goal.distance(origin));
        // 标准化方向,保证与射线碰撞点的距离计算正确
        Vector3f direction = goal.add(origin.negate()).normalize();
        ray = new Ray(origin, direction);
        ray.setLimit(limit);
    // // FIXME 创建Line
    // Line line = new Line(origin, goal);
    // line.setLineWidth(1);
    // final Geometry geometry = new Geometry("Line", line);
    // JmeUtil.setTranslucent(geometry, true);
    // Material material = new Material(Dispatcher.getIns().getMainApp().getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
    // material.setColor("Color", ColorRGBA.Green);
    // geometry.setMaterial(material);
    // Dispatcher.getIns().getMainApp().enqueue(new Runnable() {
    // @Override
    // public void run() {
    // rootNode.attachChild(geometry);
    // }
    // });
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}
Also used : Vector3f(com.jme3.math.Vector3f) Magnetism(com.cas.circuit.vo.Magnetism) Ray(com.jme3.math.Ray) IOException(java.io.IOException)

Aggregations

Magnetism (com.cas.circuit.vo.Magnetism)3 ControlIO (com.cas.circuit.vo.ControlIO)2 VS10N051CControl (com.cas.circuit.control.VS10N051CControl)1 ElecCompDef (com.cas.circuit.vo.ElecCompDef)1 Jack (com.cas.circuit.vo.Jack)1 LightIO (com.cas.circuit.vo.LightIO)1 Terminal (com.cas.circuit.vo.Terminal)1 GasPort (com.cas.gas.vo.GasPort)1 Ray (com.jme3.math.Ray)1 Vector3f (com.jme3.math.Vector3f)1 Spatial (com.jme3.scene.Spatial)1 IOException (java.io.IOException)1