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);
});
}
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);
}
});
}
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);
}
}
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);
}
}
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);
}
Aggregations