Search in sources :

Example 1 with ElecCompProxy

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

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

the class CircuitState method saveEleccomps.

private void saveEleccomps(Archive archive) {
    compList.forEach(comp -> {
        ElecCompProxy compProxy = comp.getProxy();
        compProxy.setId(comp.getElecComp().getId());
        compProxy.setLocation(comp.getSpatial().getLocalTranslation());
        System.out.println(comp.getSpatial().getLocalRotation());
        compProxy.setRotation(comp.getSpatial().getLocalRotation());
        archive.getCompList().add(compProxy);
    });
}
Also used : ElecCompProxy(com.cas.circuit.vo.archive.ElecCompProxy)

Aggregations

ElecCompProxy (com.cas.circuit.vo.archive.ElecCompProxy)2 CfgConst (com.cas.circuit.CfgConst)1 Archive (com.cas.circuit.vo.Archive)1 ControlIO (com.cas.circuit.vo.ControlIO)1 ElecCompDef (com.cas.circuit.vo.ElecCompDef)1 Jack (com.cas.circuit.vo.Jack)1 Terminal (com.cas.circuit.vo.Terminal)1 Wire (com.cas.circuit.vo.Wire)1 WireProxy (com.cas.circuit.vo.archive.WireProxy)1 ElecCompAction (com.cas.sim.tis.action.ElecCompAction)1 TypicalCaseAction (com.cas.sim.tis.action.TypicalCaseAction)1 HintControl (com.cas.sim.tis.app.control.HintControl)1 TagNameControl (com.cas.sim.tis.app.control.TagNameControl)1 WireNumberControl (com.cas.sim.tis.app.control.WireNumberControl)1 MouseEvent (com.cas.sim.tis.app.event.MouseEvent)1 MouseEventAdapter (com.cas.sim.tis.app.event.MouseEventAdapter)1 ElecComp (com.cas.sim.tis.entity.ElecComp)1 TypicalCase (com.cas.sim.tis.entity.TypicalCase)1 HTTPUtils (com.cas.sim.tis.util.HTTPUtils)1 JmeUtil (com.cas.sim.tis.util.JmeUtil)1