Search in sources :

Example 6 with GasPort

use of com.cas.gas.vo.GasPort 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 7 with GasPort

use of com.cas.gas.vo.GasPort in project TeachingInSimulation by ScOrPiOzzy.

the class ElecCompDef method blockRelationRemoved.

public void blockRelationRemoved(BlockRelation relation) {
    relation.setActivated(false);
    GasPort port1 = relation.getPort1();
    GasPort port2 = relation.getPort2();
    port1.getBlockRelationMap().remove(port2);
    port2.getBlockRelationMap().remove(port1);
}
Also used : GasPort(com.cas.gas.vo.GasPort)

Example 8 with GasPort

use of com.cas.gas.vo.GasPort in project TeachingInSimulation by ScOrPiOzzy.

the class ConnectionHandler method checkConnect.

/**
 * 验证是否可以接线
 * @param target 端子、气口
 */
public boolean checkConnect(ILinkTarget target) {
    // 获得当前用户选中导线
    if (currLinker == null) {
        Dispatcher.getIns().getTip().showTip(ITip.ERROR, ConnectionUtil.NO_lINKER);
        return false;
    }
    if (target instanceof Jack && !(currLinker instanceof Cable)) {
        Dispatcher.getIns().getTip().showTip(ITip.ERROR, ConnectionUtil.JUST_CABLE);
        return false;
    }
    // 如果当前手中是线缆,但当前接口不符合当前线缆制式
    if ((target instanceof Jack) && (currLinker instanceof Cable)) {
        Jack jack = (Jack) target;
        if (jack.getPlug() != null) {
            Dispatcher.getIns().getTip().showTip(ITip.ERROR, ConnectionUtil.JACK_ALREADY_IN_USED);
            return false;
        }
        Cable cable = (Cable) currLinker;
        // 如果两个连接头都为null,说明用户选择了线缆还没有连接
        if (cable.getPlug1() == null && cable.getPlug2() == null) {
            if (Util.notEmpty(jack.getPO().getBelongElecComp())) {
                return false;
            }
            return true;
        }
        Format format = jack.getFormat();
        Plug plug1 = cable.getPlug1();
        if (plug1 != null) {
            boolean insert = plug1.isInserted();
            if (!insert) {
                return format.equals(plug1.getFormat());
            }
        }
        Plug plug2 = cable.getPlug2();
        if (plug2 != null) {
            boolean insert = plug2.isInserted();
            if (!insert) {
                if (standardData != null && !checkStandard(target, currLinker)) {
                    Dispatcher.getIns().getTip().showTip(ITip.ERROR, "接线不符合标准存档!");
                    return false;
                }
                return format.equals(plug2.getFormat());
            } else {
                return false;
            }
        } else if (cable.isSinglePlug()) {
            return false;
        }
    } else if ((target instanceof Terminal) && (currLinker instanceof Cable)) {
        Cable cable = (Cable) currLinker;
        Wire wire = cable.getNowConnectingWire();
        if (wire == null) {
            Dispatcher.getIns().getTip().showTip(ITip.ERROR, ConnectionUtil.SELECT_ANY_WIRE_IN_CABLE);
            return false;
        }
        if (wire.isBothBinded()) {
            Dispatcher.getIns().getTip().showTip(ITip.ERROR, ConnectionUtil.WIRE_IN_CABLE_LINKED_ALREADY);
            return false;
        }
        Terminal terminal = (Terminal) target;
        if (terminal.getLinkers().size() == terminal.getNum()) {
            Dispatcher.getIns().getTip().showTip(ITip.ERROR, ConnectionUtil.TERMINAL_LIMITED);
            return false;
        }
        if (standardData != null && !checkStandard(target, currLinker)) {
            Dispatcher.getIns().getTip().showTip(ITip.ERROR, "接线不符合标准存档!");
            return false;
        }
        return true;
    }
    if (target instanceof Terminal && !(currLinker instanceof Wire)) {
        Dispatcher.getIns().getTip().showTip(ITip.ERROR, ConnectionUtil.JUST_WIRE);
        return false;
    }
    if (target instanceof Terminal && (currLinker instanceof Wire)) {
        Terminal terminal = (Terminal) target;
        if (terminal.getLinkers().size() == terminal.getNum()) {
            Dispatcher.getIns().getTip().showTip(ITip.ERROR, ConnectionUtil.TERMINAL_LIMITED);
            return false;
        }
        if (terminal.getLinkers().contains(currLinker)) {
            Dispatcher.getIns().getTip().showTip(ITip.ERROR, ConnectionUtil.SAME_LINKER);
            return false;
        }
    }
    if (target instanceof GasPort && !(currLinker instanceof Pipe)) {
        Dispatcher.getIns().getTip().showTip(ITip.ERROR, ConnectionUtil.JUST_PIPE);
        return false;
    }
    if (target instanceof GasPort && target.getLinkers().size() != 0) {
        Dispatcher.getIns().getTip().showTip(ITip.ERROR, ConnectionUtil.GASPORT_LIMITED);
        return false;
    }
    if (standardData != null && !checkStandard(target, currLinker)) {
        Dispatcher.getIns().getTip().showTip(ITip.ERROR, "接线不符合标准存档!");
        return false;
    }
    Dispatcher.getIns().getTip().showTip(ITip.RIGHT, null);
    return true;
}
Also used : Cable(com.cas.circuit.vo.Cable) GasPort(com.cas.gas.vo.GasPort) Format(com.cas.circuit.vo.Format) Pipe(com.cas.gas.vo.Pipe) Jack(com.cas.circuit.vo.Jack) Wire(com.cas.circuit.vo.Wire) Terminal(com.cas.circuit.vo.Terminal)

Aggregations

GasPort (com.cas.gas.vo.GasPort)8 Jack (com.cas.circuit.vo.Jack)5 Terminal (com.cas.circuit.vo.Terminal)5 Spatial (com.jme3.scene.Spatial)4 Cable (com.cas.circuit.vo.Cable)3 Wire (com.cas.circuit.vo.Wire)3 ArrayList (java.util.ArrayList)3 Pipe (com.cas.gas.vo.Pipe)2 ControlIO (com.cas.circuit.vo.ControlIO)1 ElecCompDef (com.cas.circuit.vo.ElecCompDef)1 Format (com.cas.circuit.vo.Format)1 LightIO (com.cas.circuit.vo.LightIO)1 Magnetism (com.cas.circuit.vo.Magnetism)1 BlockState (com.cas.gas.vo.BlockState)1 ColorRGBA (com.jme3.math.ColorRGBA)1 Node (com.jme3.scene.Node)1 FileNotFoundException (java.io.FileNotFoundException)1 Comparator (java.util.Comparator)1 Callable (java.util.concurrent.Callable)1