Search in sources :

Example 1 with ElecCompDef

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

the class R method shareVoltage.

public void shareVoltage() {
    // 记录当前电路中涉及的连接头lastCircuitTerminal
    List<Terminal> lastCircuitTerminal = new ArrayList<Terminal>();
    for (IP ip : allIsopoList) {
        addNonRepeatListAll(lastCircuitTerminal, ip.getTerminals());
    // lastCircuitTerminal.addAll(ip.getTerminals());
    }
    int count = 0;
    // 真实的分压操作
    while (shareVoltageLocal()) {
        count++;
        if (count > 10) {
            // 防止死循环
            System.out.println("死循环啦");
            break;
        }
    }
    if (startIP == null || endIP == null) {
        return;
    }
    // 找出分压后当前电路中的连接头thisCircuitTerminal
    List<ElecCompDef> elecCompList = new ArrayList<ElecCompDef>();
    List<Terminal> thisCircuitTerminal = new ArrayList<Terminal>();
    for (IP ip : allIsopoList) {
        addNonRepeatListAll(thisCircuitTerminal, ip.getTerminals());
        // thisCircuitTerminal.addAll(ip.getTerminals());
        // 找出所走到的连接头所属元器件,因为有些元器件如:开关电源,可算是一个电源的,当满足输入电压后,将输出电压
        findElecComp(elecCompList, ip.getTerminals(), true);
    }
    // 过滤出电路没有走到的连接头,这些lastCircuitTerminal连接头即将清除电压
    lastCircuitTerminal.removeAll(thisCircuitTerminal);
    // 找出要被清理电压的连接头所属的元器件,因为有些元器件如:开关电源,可算是一个电源的将无法输出电压
    findElecComp(elecCompList, lastCircuitTerminal, false);
    // System.out.println("shareVoltage这些连接头 本次电路中没有走到" + lastCircuitTerminal);
    // 即将清除电压
    IP ip = null;
    for (Terminal terminal : lastCircuitTerminal) {
        // 当前电源的两个输出端,及与输出端子处于同电位的,【不】清除电压
        if (!startIP.hasTerminal(terminal) && !endIP.hasTerminal(terminal)) {
            ip = terminal.getIsopotential(voltage.getEnv());
            if (ip != null) {
                ip.detory();
            }
            terminal.removeVolt(voltage.getEnv());
        }
    }
    for (ElecCompDef elecCompDef : elecCompList) {
        if (elecCompDef != null) {
            elecCompDef.doMagnetism();
        }
    }
}
Also used : ElecCompDef(com.cas.circuit.vo.ElecCompDef) IP(com.cas.circuit.vo.IP) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Terminal(com.cas.circuit.vo.Terminal)

Example 2 with ElecCompDef

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

the class JaxbTest method testName.

@Test
public void testName() throws Exception {
    File file = new File("src/main/resources/config/");
    // File[] subFiles = file.listFiles();
    // for (int i = 0; i < subFiles.length; i++) {
    // File xml = subFiles[i];
    // if(xml.getName().endsWith("xml")) {
    // ElecCompDef eleccomp = JaxbUtil.converyToJavaBean(new String(Files.readAllBytes(xml.toPath())), ElecCompDef.class);
    // System.out.println(JaxbUtil.convertToXml(eleccomp));
    // eleccomp.build();
    // }
    // }
    ElecCompDef eleccomp = JaxbUtil.converyToJavaBean(new String(Files.readAllBytes(new File(file, "DZ47-63C16.xml").toPath())), ElecCompDef.class);
    System.out.println(JaxbUtil.convertToXml(eleccomp));
    // Archive archive = JaxbUtil.converyToJavaBean(new File(file, "Test.xml").toURI().toURL(), Archive.class);
    Archive archive = JaxbUtil.converyToJavaBean(new URL("http://192.168.1.123:8082/archives/Test.xml"), Archive.class);
    Assert.assertNotNull(archive);
    System.out.println(archive);
}
Also used : ElecCompDef(com.cas.circuit.vo.ElecCompDef) Archive(com.cas.circuit.vo.Archive) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Example 3 with ElecCompDef

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

the class FX3UPLCLogic method initialize.

@Override
public void initialize(Node elecCompMdl) {
    super.initialize(elecCompMdl);
    assist = new FX3UPLCLogicAssist(this);
    ElecCompDef elecCompDef = elecComp.getDef();
    term_SS = elecCompDef.getTerminal("S/S");
    term_24V = elecCompDef.getTerminal("24V");
    if (term_24V == null) {
        term_24V = elecCompDef.getTerminal("24V_1");
    }
    if (term_24V == null) {
        term_24V = elecCompDef.getTerminal("24V_2");
    }
    term_0V = elecCompDef.getTerminal("0V");
    if (term_0V == null) {
        term_0V = elecCompDef.getTerminal("0V_1");
    }
    if (term_0V == null) {
        term_0V = elecCompDef.getTerminal("0V_2");
    }
    // Jack jack = elecCompDef.getJackMap().get("RS-485");
    sda = elecCompDef.getTerminal("SDA");
    sdb = elecCompDef.getTerminal("SDB");
    rda = elecCompDef.getTerminal("RDA");
    rdb = elecCompDef.getTerminal("RDB");
    SIGNAL_EVN = "PLC" + hashCode();
    // opc中设备名对应的并非工作站,而是针对具体某一个PLC元器件,所以opc相关信息写入
    // 1、引用的PLC模型的userdata中,elecCompMdl.getUserdata("device")。注意:并不是elecCompMdl.getChild(0).getUserData("device")。
    // 2、在应用PLC元器件配置文件的文本域中,elecComp.getProperty("deivce");
    final String deviceName = elecComp.getProperty("device");
    if (Util.isEmpty(deviceName)) {
        throw new RuntimeException("需要给" + elecComp + "声明opc中的device");
    }
    this.deviceName = deviceName;
    try {
        client = new OPCClientImpl(InetAddress.getLocalHost().getHostAddress());
        client.setDeviceName(deviceName);
        client.addOPCSignalVisitor(this);
    } catch (UnknownHostException e) {
        log.error(e.getMessage(), e);
    }
    initialize = true;
}
Also used : ElecCompDef(com.cas.circuit.vo.ElecCompDef) UnknownHostException(java.net.UnknownHostException) OPCClientImpl(com.cas.opc.OPCClientImpl)

Example 4 with ElecCompDef

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

the class ConnectionHandler method connectByLinkerInfo.

/**
 * 联机状态下接线
 * @param linkerInfo 接线消息
 * @param wireOrPipe
 * @param modifiable
 */
private void connectByLinkerInfo(LinkerMsg linkerInfo, ILinker wireOrPipe, boolean modifiable) {
    ElecComp elecComp = eleCompMap.get(linkerInfo.getElecCompKey());
    if (elecComp == null) {
        log.info("未找到指定元器件的定义信息:" + linkerInfo.getElecCompKey());
        return;
    }
    ElecCompDef def = elecComp.getDef();
    byte linkType = linkerInfo.getLinkType();
    String targetKey = linkerInfo.getTargetKey();
    ILinkTarget termOrPort = null;
    if (LinkerMsg.WIRE == linkType || LinkerMsg.CABLE_TERM == linkType) {
        termOrPort = def.getTerminalMap().get(targetKey);
    } else if (LinkerMsg.PIPE == linkType) {
        termOrPort = def.getGasPortMap().get(targetKey);
    } else if (LinkerMsg.CABLE_JACK == linkType) {
        termOrPort = def.getJackMap().get(targetKey);
    }
    if (wireOrPipe instanceof Cable && termOrPort instanceof Terminal) {
        ((Cable) wireOrPipe).setNowConnectingWire(linkerInfo.getWireMark());
        ((Cable) wireOrPipe).getNowConnectingWire().setWireNum(linkerInfo.getNumMark());
    }
    wireOrPipe.setWireNum(linkerInfo.getNumMark());
    Spatial model = connect(wireOrPipe, termOrPort, true);
    if (currSaveLinker != null) {
        wireOrPipe = currSaveLinker;
    }
    // 接线头添加鼠标监听事件
    addMouseEvent(model, new LinkerEventAdapter(new LinkerEventHandler(wireOrPipe, this, modifiable)));
    // 记录准备存档的信息
    if (modifiable) {
        linkerData.addLinker(wireOrPipe, termOrPort, (String) model.getUserData("WireMark"));
    }
}
Also used : Cable(com.cas.circuit.vo.Cable) ElecCompDef(com.cas.circuit.vo.ElecCompDef) Spatial(com.jme3.scene.Spatial) LinkerEventHandler(com.cas.circuit.event.LinkerEventHandler) ElecComp(com.cas.circuit.vo.ElecComp) Terminal(com.cas.circuit.vo.Terminal) LinkerEventAdapter(com.cas.circuit.event.LinkerEventAdapter)

Example 5 with ElecCompDef

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

the class ConnectionHandler method bindSaveTransEvent.

private Cable bindSaveTransEvent(String elecCompKey, Cable cable, boolean modifiable) {
    ElecComp elecComp = eleCompMap.get(elecCompKey);
    if (elecComp == null) {
        System.err.println("找不到elecCompKey : " + elecCompKey);
        return null;
    // throw new RuntimeException("找不到elecCompKey : " + elecCompKey);
    }
    ElecCompDef def = elecComp.getDef();
    def.buildCompLogic();
    Node elecCompMdl = (Node) parent.getChild(elecComp.getPO().getMdlName());
    JmeUtil.setSpatialHighLight(elecCompMdl, ColorRGBA.BlackNoAlpha);
    // MouseEventState.cleanEvent(elecCompMdl);
    elecCompMdl.setUserData("MouseEvent", null);
    Jack jack = def.getJackMap().values().iterator().next();
    TransducersHandler handler = new TransducersHandler(this, elecComp, jack, modifiable);
    cable.bind(jack);
    cable.setElecComp(true);
    cable.getModels().put(elecCompMdl, jack);
    if (modifiable) {
        linkerData.addLinker(cable, jack, null);
    }
    handler.setCable(cable);
    addMouseEvent(elecCompMdl, new TransducersAdapter(handler));
    return cable;
}
Also used : TransducersHandler(com.cas.circuit.event.TransducersHandler) ElecCompDef(com.cas.circuit.vo.ElecCompDef) TransducersAdapter(com.cas.circuit.event.TransducersAdapter) Node(com.jme3.scene.Node) ElecComp(com.cas.circuit.vo.ElecComp) Jack(com.cas.circuit.vo.Jack)

Aggregations

ElecCompDef (com.cas.circuit.vo.ElecCompDef)19 Terminal (com.cas.circuit.vo.Terminal)7 Spatial (com.jme3.scene.Spatial)6 Jack (com.cas.circuit.vo.Jack)5 ElecCompAction (com.cas.sim.tis.action.ElecCompAction)5 URL (java.net.URL)5 ArrayList (java.util.ArrayList)5 Wire (com.cas.circuit.vo.Wire)4 Archive (com.cas.circuit.vo.Archive)3 ControlIO (com.cas.circuit.vo.ControlIO)3 TagNameControl (com.cas.sim.tis.app.control.TagNameControl)3 WireNumberControl (com.cas.sim.tis.app.control.WireNumberControl)3 MouseEvent (com.cas.sim.tis.app.event.MouseEvent)3 MouseEventAdapter (com.cas.sim.tis.app.event.MouseEventAdapter)3 ElecComp (com.cas.sim.tis.entity.ElecComp)3 ModelKey (com.jme3.asset.ModelKey)3 BitmapText (com.jme3.font.BitmapText)3 Node (com.jme3.scene.Node)3 CfgConst (com.cas.circuit.CfgConst)2 CR (com.cas.circuit.vo.CR)2