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