Search in sources :

Example 6 with ElecCompDef

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

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

the class CircuitState method readEleccomps.

private void readEleccomps(@Nonnull List<ElecCompProxy> compProxyList) {
    ElecCompAction action = SpringUtil.getBean(ElecCompAction.class);
    // 一、开始加载元器件
    compProxyList.forEach(proxyComp -> {
        // 1、根据元器件型号(model字段),查找数据库中的元器件实体对象
        ElecComp elecComp = action.findElecCompById(proxyComp.getId());
        if (elecComp == null) {
            LOG.warn("没有找到ID号为{}的元器件", proxyComp.getId());
        }
        // 2、加载模型,同时设置好坐标与旋转
        Future<Node> task = app.enqueue((Callable<Node>) () -> {
            Node node = (Node) loadAsset(new ModelKey(elecComp.getMdlPath()));
            // 设置transform信息:location、rotation
            node.setLocalTranslation(proxyComp.getLocation());
            node.setLocalRotation(proxyComp.getRotation());
            node.scale(25);
            return node;
        });
        Node compMdl = null;
        try {
            compMdl = task.get();
        } catch (Exception e) {
            LOG.error("无法加载元器件模型{}:{}", elecComp.getMdlPath(), e);
            throw new RuntimeException(e);
        }
        // 3、初始化元器件逻辑对象
        URL cfgUrl = SpringUtil.getBean(HTTPUtils.class).getUrl(elecComp.getCfgPath());
        ElecCompDef def = JaxbUtil.converyToJavaBean(cfgUrl, ElecCompDef.class);
        def.setProxy(proxyComp);
        def.setElecComp(elecComp);
        if (ElecComp.COMBINE_TOP == elecComp.getCombine()) {
            // 获得底座,底座的排序一定在元器件之前
            Map<String, ElecCompDef> compMap = compList.stream().collect(Collectors.toMap(x -> x.getProxy().getUuid(), x -> x));
            ElecCompDef baseDef = compMap.get(proxyComp.getBaseUuid());
            attachToBase(compMdl, def, baseDef);
        } else {
            // 加入电路板中
            attachToCircuit(compMdl, def);
        }
    });
}
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) ElecCompAction(com.cas.sim.tis.action.ElecCompAction) ModelKey(com.jme3.asset.ModelKey) ElecCompDef(com.cas.circuit.vo.ElecCompDef) Node(com.jme3.scene.Node) ElecComp(com.cas.sim.tis.entity.ElecComp) URL(java.net.URL) HTTPUtils(com.cas.sim.tis.util.HTTPUtils)

Example 8 with ElecCompDef

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

the class TypicalCaseState method putDown.

/**
 * 将一个元器件放置在电路板上
 */
@JmeThread
public void putDown() {
    // 取消Holding的模型对鼠标透明
    JmeUtil.setMouseVisible(holding, true);
    try {
        if (ElecComp.COMBINE_TOP == elecComp.getCombine()) {
            // 需要底座的元器件不可直接加入电路板
            Platform.runLater(() -> {
                AlertUtil.showAlert(AlertType.WARNING, MsgUtil.getMessage("alert.warning.base.need"));
            });
            holding.removeFromParent();
        } else {
            // 1、获取相应元器件
            ElecCompDef elecCompDef = SpringUtil.getBean(ElecCompAction.class).parse(elecComp.getCfgPath());
            elecCompDef.setElecComp(elecComp);
            // 2、将元器件模型与元器件对象一起加入电路板中
            circuitState.attachToCircuit(holding, elecCompDef);
        }
    } catch (Exception e) {
        // 删除出错的模型
        holding.removeFromParent();
        LOG.error("初始化元器件{}时出现了一个错误:{}", elecComp.getModel(), e.getMessage());
        e.printStackTrace();
    } finally {
        holding = null;
        elecComp = null;
        cameraState.setZoomEnable(true);
    }
}
Also used : ElecCompDef(com.cas.circuit.vo.ElecCompDef) ElecCompAction(com.cas.sim.tis.action.ElecCompAction) JmeThread(com.cas.sim.tis.anno.JmeThread)

Example 9 with ElecCompDef

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

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

the class BasicTest method testParseCfgLocal.

@Test
public void testParseCfgLocal() throws Exception {
    URL url = new URL("http://192.168.1.19:8082/configurations/Accontactor/CJX2-1210.xml");
    // URL url = new URL("file:///C:/Users/Administrator/Documents/New%20folder/Accontactor/CJX2-1210.xml");
    ElecCompDef eleccomp = JaxbUtil.converyToJavaBean(url, ElecCompDef.class);
    System.out.println(eleccomp);
}
Also used : ElecCompDef(com.cas.circuit.vo.ElecCompDef) URL(java.net.URL) Test(org.junit.Test)

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