Search in sources :

Example 1 with TermTeam

use of com.cas.circuit.TermTeam in project TeachingInSimulation by ScOrPiOzzy.

the class ElecCompDef method afterUnmarshal.

public void afterUnmarshal(Unmarshaller u, Object parent) {
    jackMap = jackList.stream().collect(Collectors.toMap(Jack::getId, data -> data));
    terminalMap = terminalList.stream().collect(Collectors.toMap(Terminal::getId, data -> data));
    stitchMap = stitchList.stream().collect(Collectors.toMap(Stitch::getId, data -> data));
    resisStatesMap = resisStateList.stream().collect(Collectors.toMap(ResisState::getId, data -> data));
    // 
    termAndStich.putAll(terminalMap);
    termAndStich.putAll(stitchMap);
    jackList.stream().forEach(jack -> termAndStich.putAll(jack.getStitchList().stream().collect(Collectors.toMap(Terminal::getId, Function.identity(), (key1, key2) -> key2, HashMap::new))));
    magnetismList.stream().forEach(mag -> {
        mag.getVoltageIOList().forEach(io -> {
            Terminal term1 = getTerminal(io.getTerm1Id());
            Terminal term2 = getTerminal(io.getTerm2Id());
            if (term1 == null) {
                throw new NullPointerException(name + "里的" + io.getTerm1Id() + "端子没找到");
            } else {
                term1.getVoltIOs().add(io);
                io.setTerm1(term1);
            }
            if (term2 == null) {
                throw new NullPointerException(name + "里的" + io.getTerm2Id() + "端子没找到");
            } else {
                term2.getVoltIOs().add(io);
                io.setTerm2(term2);
            }
        });
    });
    resisStateList.stream().forEach(state -> {
        state.getResisRelationList().forEach(resis -> {
            resis.setTerm1(getTerminal(resis.getTerm1Id()));
            resis.setTerm2(getTerminal(resis.getTerm2Id()));
            if (state.getIsDef() == null) {
                System.out.println("ElecCompDef.build()");
            }
            if (state.getIsDef()) {
                resisRelationAdded(resis);
            }
        });
    });
    terminalList.forEach(t -> t.setElecComp(this));
    // 将所有连接头进行分类
    // Key:分类的名称, List<Terminal>一组的连接头
    Map<String, List<Terminal>> groupTerminals = termAndStich.values().stream().filter(t -> t.getTeam() != null).collect(Collectors.groupingBy(Terminal::getTeam));
    groupTerminals.entrySet().forEach(e -> new TermTeam(e.getKey(), e.getValue()));
    paramMap = params.stream().collect(Collectors.toMap(Param::getKey, Param::getValue));
    // ------------------
    if (logic == null) {
        logic = new BaseElectricCompLogic();
    }
    logic.setElecComp(this);
    logic.initialize();
}
Also used : XmlElementWrapper(javax.xml.bind.annotation.XmlElementWrapper) ElecCompProxy(com.cas.circuit.vo.archive.ElecCompProxy) HashMap(java.util.HashMap) Function(java.util.function.Function) ArrayList(java.util.ArrayList) R(com.cas.circuit.util.R) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Node(com.jme3.scene.Node) BaseElectricCompLogic(com.cas.circuit.BaseElectricCompLogic) ElecComp(com.cas.sim.tis.entity.ElecComp) Map(java.util.Map) XmlJavaTypeAdapter(javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter) MesureResult(com.cas.circuit.util.MesureResult) Nonnull(javax.annotation.Nonnull) ElecCompCPU(com.cas.circuit.ElecCompCPU) XmlAccessorType(javax.xml.bind.annotation.XmlAccessorType) XmlAttribute(javax.xml.bind.annotation.XmlAttribute) Unmarshaller(javax.xml.bind.Unmarshaller) ZeroOneBooleanAdapter(com.sun.tools.internal.xjc.runtime.ZeroOneBooleanAdapter) Set(java.util.Set) XmlRootElement(javax.xml.bind.annotation.XmlRootElement) Collectors(java.util.stream.Collectors) XmlAccessType(javax.xml.bind.annotation.XmlAccessType) List(java.util.List) CompLogicAdapter(com.cas.circuit.xml.adapter.CompLogicAdapter) XmlElement(javax.xml.bind.annotation.XmlElement) TermTeam(com.cas.circuit.TermTeam) TermTeam(com.cas.circuit.TermTeam) BaseElectricCompLogic(com.cas.circuit.BaseElectricCompLogic) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with TermTeam

use of com.cas.circuit.TermTeam in project TeachingInSimulation by ScOrPiOzzy.

the class ElecCompDef method onAllChildAdded.

@Override
protected void onAllChildAdded() {
    super.onAllChildAdded();
    // 搜集所有的连接头和针脚
    // 搜集连接头
    termAndStich.putAll(terminalMap);
    // 搜集所有的针脚
    Map<String, Terminal> stitchMap = null;
    Iterator<Entry<String, Terminal>> it = null;
    Entry<String, Terminal> entry = null;
    for (BaseVO<?> baseVO : children) {
        if (baseVO instanceof Jack) {
            stitchMap = ((Jack) baseVO).getStitch();
            it = stitchMap.entrySet().iterator();
            while (it.hasNext()) {
                entry = it.next();
                termAndStich.put(entry.getValue().getLocalKey(), entry.getValue());
            }
        }
    }
    for (Magnetism mag : magnetisms) {
        for (VoltageIO voltIO : mag.getVoltageIOs()) {
            Terminal term1 = getTerminal(voltIO.getPO().getTerm1Id());
            Terminal term2 = getTerminal(voltIO.getPO().getTerm2Id());
            if (term1 == null) {
                throw new NullPointerException(po.getName() + "里的" + voltIO.getPO().getTerm1Id() + "端子没找到");
            } else {
                term1.getVoltIOs().add(voltIO);
                voltIO.setTerm1(term1);
            }
            if (term2 == null) {
                throw new NullPointerException(po.getName() + "里的" + voltIO.getPO().getTerm2Id() + "端子没找到");
            } else {
                term2.getVoltIOs().add(voltIO);
                voltIO.setTerm2(term2);
            }
        }
    }
    for (ResisState resisState : resisStates) {
        for (BaseVO<?> baseVO : resisState.getChildren()) {
            ResisRelation resis = (ResisRelation) baseVO;
            resis.setTerm1(getTerminal(resis.getPO().getTerm1Id()));
            resis.setTerm2(getTerminal(resis.getPO().getTerm2Id()));
            if (resisState.isDef()) {
                resisRelationAdded(resis);
            }
        }
    }
    // 
    Map<String, List<Terminal>> teamTerminalMap = new LinkedHashMap<String, List<Terminal>>();
    String teamName = null;
    for (Terminal terminal : termAndStich.values()) {
        teamName = terminal.getPO().getTeam();
        if (Util.notEmpty(teamName)) {
            if (!teamTerminalMap.containsKey(teamName)) {
                teamTerminalMap.put(teamName, new ArrayList<Terminal>());
            }
            teamTerminalMap.get(teamName).add(terminal);
        }
    }
    for (Entry<String, List<Terminal>> entry2 : teamTerminalMap.entrySet()) {
        new TermTeam(teamName, entry2.getValue());
    }
    for (BlockState blockState : blockStates) {
        for (BaseVO<?> baseVO : blockState.getChildren()) {
            BlockRelation block = (BlockRelation) baseVO;
            block.setPort1(getGasPort(block.getPO().getPortId1()));
            block.setPort2(getGasPort(block.getPO().getPortId2()));
            if (blockState.isDef()) {
                blockRelationAdded(block);
            }
        }
    }
}
Also used : TermTeam(com.cas.circuit.TermTeam) LinkedHashMap(java.util.LinkedHashMap) Entry(java.util.Map.Entry) BlockState(com.cas.gas.vo.BlockState) ArrayList(java.util.ArrayList) List(java.util.List) BlockRelation(com.cas.gas.vo.BlockRelation)

Aggregations

TermTeam (com.cas.circuit.TermTeam)2 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 BaseElectricCompLogic (com.cas.circuit.BaseElectricCompLogic)1 ElecCompCPU (com.cas.circuit.ElecCompCPU)1 MesureResult (com.cas.circuit.util.MesureResult)1 R (com.cas.circuit.util.R)1 ElecCompProxy (com.cas.circuit.vo.archive.ElecCompProxy)1 CompLogicAdapter (com.cas.circuit.xml.adapter.CompLogicAdapter)1 BlockRelation (com.cas.gas.vo.BlockRelation)1 BlockState (com.cas.gas.vo.BlockState)1 ElecComp (com.cas.sim.tis.entity.ElecComp)1 Node (com.jme3.scene.Node)1 ZeroOneBooleanAdapter (com.sun.tools.internal.xjc.runtime.ZeroOneBooleanAdapter)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1