Search in sources :

Example 1 with ElecComp

use of com.cas.sim.tis.entity.ElecComp 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 ElecComp

use of com.cas.sim.tis.entity.ElecComp in project TeachingInSimulation by ScOrPiOzzy.

the class PreparationDetail method openCognition.

private void openCognition(Integer id) {
    ElecComp comp = SpringUtil.getBean(ElecCompAction.class).findElecCompById(id);
    PageController controller = SpringUtil.getBean(PageController.class);
    Recongnize3D content = new Recongnize3D();
    controller.loadContent(content, PageLevel.Level2);
    controller.showLoading();
    controller.setEndHideLoading((v) -> {
        content.setElecComp(comp);
    });
}
Also used : ElecCompAction(com.cas.sim.tis.action.ElecCompAction) Recongnize3D(com.cas.sim.tis.view.control.imp.jme.Recongnize3D) PageController(com.cas.sim.tis.view.controller.PageController) ElecComp(com.cas.sim.tis.entity.ElecComp)

Example 3 with ElecComp

use of com.cas.sim.tis.entity.ElecComp in project TeachingInSimulation by ScOrPiOzzy.

the class CircuitTest method testParseCfg.

@Test
public void testParseCfg() throws Exception {
    ElecCompService service = (ElecCompService) elecCompServiceFactory.getObject();
    // ID:10\11
    // ElecComp elecComp = service.findById(10);
    ElecComp elecComp = service.findBy("model", "CJX2-12");
    String cfgPath = util.getFullPath(elecComp.getCfgPath());
    URL url = new URL(cfgPath);
    ElecCompDef elecCompDef = JaxbUtil.converyToJavaBean(url, ElecCompDef.class);
    System.out.println(elecCompDef);
    System.out.println(JaxbUtil.convertToXml(elecCompDef));
}
Also used : ElecCompDef(com.cas.circuit.vo.ElecCompDef) ElecComp(com.cas.sim.tis.entity.ElecComp) ElecCompService(com.cas.sim.tis.services.ElecCompService) URL(java.net.URL) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with ElecComp

use of com.cas.sim.tis.entity.ElecComp in project TeachingInSimulation by ScOrPiOzzy.

the class ElecCompServiceImpl method findElecCompGroupByType.

@Override
public Map<Integer, List<ElecComp>> findElecCompGroupByType() {
    ElecCompMapper dao = (ElecCompMapper) mapper;
    List<ElecComp> all = dao.selectAll();
    if (all == null) {
        return new HashMap<>();
    }
    return all.stream().collect(Collectors.groupingBy(ElecComp::getType));
}
Also used : ElecCompMapper(com.cas.sim.tis.mapper.ElecCompMapper) HashMap(java.util.HashMap) ElecComp(com.cas.sim.tis.entity.ElecComp)

Example 5 with ElecComp

use of com.cas.sim.tis.entity.ElecComp in project TeachingInSimulation by ScOrPiOzzy.

the class ElecCompServiceImpl method findElecCompByModel.

@Override
public ElecComp findElecCompByModel(String model) {
    ElecCompMapper dao = (ElecCompMapper) mapper;
    Condition condition = new Condition(ElecComp.class);
    Criteria criteria = condition.createCriteria();
    criteria.andEqualTo("model", model);
    List<ElecComp> compList = dao.selectByCondition(condition);
    if (compList.size() == 0) {
        return null;
    } else if (compList.size() > 1) {
        throw new TooManyResultsException();
    }
    return compList.get(0);
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) ElecCompMapper(com.cas.sim.tis.mapper.ElecCompMapper) TooManyResultsException(org.apache.ibatis.exceptions.TooManyResultsException) ElecComp(com.cas.sim.tis.entity.ElecComp) Criteria(tk.mybatis.mapper.entity.Example.Criteria)

Aggregations

ElecComp (com.cas.sim.tis.entity.ElecComp)5 ElecCompDef (com.cas.circuit.vo.ElecCompDef)2 ElecCompAction (com.cas.sim.tis.action.ElecCompAction)2 ElecCompMapper (com.cas.sim.tis.mapper.ElecCompMapper)2 PageController (com.cas.sim.tis.view.controller.PageController)2 CfgConst (com.cas.circuit.CfgConst)1 Archive (com.cas.circuit.vo.Archive)1 ControlIO (com.cas.circuit.vo.ControlIO)1 Jack (com.cas.circuit.vo.Jack)1 Terminal (com.cas.circuit.vo.Terminal)1 Wire (com.cas.circuit.vo.Wire)1 ElecCompProxy (com.cas.circuit.vo.archive.ElecCompProxy)1 WireProxy (com.cas.circuit.vo.archive.WireProxy)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 TypicalCase (com.cas.sim.tis.entity.TypicalCase)1