use of com.cas.sim.tis.action.ElecCompAction 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);
}
});
}
Aggregations