Search in sources :

Example 11 with ElecCompDef

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

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

the class CircuitState method toggleTagName.

private void toggleTagName() {
    for (ElecCompDef elecCompDef : compList) {
        Spatial elecCompMdl = elecCompDef.getSpatial();
        TagNameControl control = elecCompMdl.getControl(TagNameControl.class);
        if (control == null) {
            BitmapText tag = new BitmapText(tagFont);
            tag.setName(elecCompDef.getProxy().getUuid());
            guiNode.attachChild(tag);
            control = new TagNameControl(cam, tag);
            elecCompMdl.addControl(control);
        }
        control.setTagName(elecCompDef.getProxy().getTagName());
        control.setEnabled(tagVisible);
    }
    for (Wire wire : wireList) {
        Spatial wireMdl = wire.getSpatial();
        WireNumberControl control = wireMdl.getControl(WireNumberControl.class);
        if (control == null) {
            BitmapText tag = new BitmapText(tagFont);
            tag.setLocalScale(0.75f);
            tag.setName(String.format("%s-%s", wire.getProxy().getComp1Uuid(), wire.getProxy().getComp2Uuid()));
            control = new WireNumberControl(cam, guiNode, tag, wire.getProxy().getPointList());
            wireMdl.addControl(control);
        }
        control.setNumber(wire.getProxy().getNumber());
        control.setEnabled(tagVisible);
    }
}
Also used : ElecCompDef(com.cas.circuit.vo.ElecCompDef) BitmapText(com.jme3.font.BitmapText) Spatial(com.jme3.scene.Spatial) TagNameControl(com.cas.sim.tis.app.control.TagNameControl) WireNumberControl(com.cas.sim.tis.app.control.WireNumberControl) Wire(com.cas.circuit.vo.Wire)

Example 13 with ElecCompDef

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

the class CircuitState method cleanup.

@Override
public void cleanup() {
    for (ElecCompDef elecCompDef : compList) {
        detachElecComp(elecCompDef);
    }
    compList.clear();
    for (Wire wire : wireList) {
        detachWire(wire);
    }
    wireList.clear();
    combineMap.clear();
    // 除了desktop,其余模型全部清除
    root.detachAllChildren();
    if (desktop != null) {
        root.attachChild(desktop);
    }
    super.cleanup();
}
Also used : ElecCompDef(com.cas.circuit.vo.ElecCompDef) Wire(com.cas.circuit.vo.Wire)

Example 14 with ElecCompDef

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

the class ElecCompState method setElecComp.

@JmeThread
public void setElecComp(ElecComp elecComp) {
    // clean up
    cleanRoot();
    // 加载模型(认知模块使用AnimPath的model)
    Spatial model = loadAsset(new ModelKey(elecComp.getAnimPath()));
    // PBR能在系统中被照亮
    // MikktspaceTangentGenerator.generate(model);
    // 将模型放大100倍
    model.scale(100);
    root.attachChild(model);
    // 
    // 获取相应元器件
    ElecCompDef elecCompDef = SpringUtil.getBean(ElecCompAction.class).parse(elecComp.getCfgPath());
    // 找出元器件外壳模型名称
    loadShell(elecCompDef.getParam(ElecCompDef.PARAM_KEY_SHELL));
    // FIXME 这里应更为精准地设置为元器件模型。
    elecCompDef.bindModel(root);
    // 添加事件
    Map<Spatial, String> nameMap = collectName(elecCompDef);
    nameMap.entrySet().forEach(e -> addListener(e.getKey(), new MouseEventAdapter() {

        @Override
        public void mouseClicked(MouseEvent evt) {
            if (!pickEnable) {
                return;
            }
            // FilterUtil.showOutlineEffect(evt.getSpatial());
            System.out.println("ElecCompState.setElecComp(...).new MouseEventAdapter() {...}.mouseClicked()");
            Vector3f point = cam.getScreenCoordinates(evt.getContactPoint());
            Platform.runLater(() -> ui.showName(e.getValue(), point.getX(), point.getY()));
        }
    }));
    explode0();
}
Also used : ModelKey(com.jme3.asset.ModelKey) ElecCompDef(com.cas.circuit.vo.ElecCompDef) ElecCompAction(com.cas.sim.tis.action.ElecCompAction) MouseEvent(com.cas.sim.tis.app.event.MouseEvent) Spatial(com.jme3.scene.Spatial) MouseEventAdapter(com.cas.sim.tis.app.event.MouseEventAdapter) Vector3f(com.jme3.math.Vector3f) JmeThread(com.cas.sim.tis.anno.JmeThread)

Example 15 with ElecCompDef

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

the class TypicalCaseState method putDownOnBase.

/**
 * 将元器件放置在指定底座上
 * @param baseDef 指定底座
 */
public void putDownOnBase(ElecCompDef baseDef) {
    if (elecComp == null || ElecComp.COMBINE_TOP != elecComp.getCombine()) {
        return;
    }
    try {
        // 取消Holding的模型对鼠标透明
        JmeUtil.setMouseVisible(holding, true);
        // 1、获取相应元器件
        ElecCompDef elecCompDef = SpringUtil.getBean(ElecCompAction.class).parse(elecComp.getCfgPath());
        elecCompDef.setElecComp(elecComp);
        // 2、判断元器件与底座是否匹配
        Set<String> stitchs = elecCompDef.getStitchMap().keySet();
        Set<String> bases = baseDef.getTerminalMap().keySet();
        if (bases.containsAll(stitchs)) {
            // 3、将元器件模型与元器件对象一起加入电路板中
            circuitState.attachToBase(holding, elecCompDef, baseDef);
            holding = null;
            elecComp = null;
            cameraState.setZoomEnable(true);
        } else {
            Platform.runLater(() -> {
                AlertUtil.showAlert(AlertType.WARNING, MsgUtil.getMessage("alert.warning.base.unmatch"));
            });
            holding.removeFromParent();
        }
    } catch (Exception e) {
        // 删除出错的模型
        holding.removeFromParent();
        LOG.error("初始化元器件{}时出现了一个错误:{}", elecComp.getModel(), e.getMessage());
        e.printStackTrace();
    }
}
Also used : ElecCompDef(com.cas.circuit.vo.ElecCompDef) ElecCompAction(com.cas.sim.tis.action.ElecCompAction)

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