use of com.cas.sim.tis.app.event.MouseEventAdapter in project TeachingInSimulation by ScOrPiOzzy.
the class CircuitState method bindElecCompEvent.
private void bindElecCompEvent(ElecCompDef def) {
// 1、连接头监听事件
def.getTerminalList().forEach(t -> addListener(t.getSpatial(), new MouseEventAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (state == null || state == State.Ending) {
connectPre(def, t);
// 设置接线状态为开始
state = State.Starting;
} else if (state == State.Mid) {
//
connectEnding(def, t);
state = State.Ending;
} else if (state == State.Ending) {
// do nothing
}
}
}));
// 2、插孔监听事件
def.getJackList().forEach(j -> addListener(j.getSpatial(), new MouseEventAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
System.out.println(j.getName());
}
}));
// 3、按钮监听事件
def.getMagnetismList().forEach(m -> {
for (ControlIO c : m.getControlIOList()) {
if (c.getType().indexOf(CfgConst.SWITCH_CTRL_INPUT) == -1) {
continue;
}
if (ControlIO.INTERACT_ROTATE.equals(c.getInteract())) {
addListener(c.getSpatial(), new MouseEventAdapter() {
@Override
public void mouseWheel(MouseEvent e) {
c.switchStateChanged(e.getWheel());
c.playMotion();
}
});
} else if (ControlIO.INTERACT_PRESS.equals(c.getInteract())) {
addListener(c.getSpatial(), new MouseEventAdapter() {
@Override
public void mousePressed(MouseEvent e) {
c.switchStateChanged(null);
c.playMotion();
}
@Override
public void mouseReleased(MouseEvent e) {
c.switchStateChanged(null);
c.playMotion();
}
});
} else {
addListener(c.getSpatial(), new MouseEventAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
c.switchStateChanged(null);
c.playMotion();
}
});
}
}
});
// 4、元器件本身的监听事件
addListener(def.getSpatial(), new MouseEventAdapter() {
@Override
public void mouseRightClicked(MouseEvent e) {
super.mouseRightClicked(e);
IContent content = SpringUtil.getBean(PageController.class).getIContent();
if (content instanceof TypicalCase3D) {
Platform.runLater(() -> {
((TypicalCase3D) content).showPopupMenu(def);
});
}
}
});
// 5、若当前为底座添加监听事件
if (ElecComp.COMBINE_BUTTOM == def.getElecComp().getCombine()) {
addListener(def.getSpatial(), new MouseEventAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// 判断当前底座是否已经被占用
if (StringUtils.isEmpty(combineMap.get(def.getProxy().getUuid()))) {
TypicalCaseState caseState = stateManager.getState(TypicalCaseState.class);
caseState.putDownOnBase(def);
super.mouseClicked(e);
}
}
});
}
}
use of com.cas.sim.tis.app.event.MouseEventAdapter in project TeachingInSimulation by ScOrPiOzzy.
the class CircuitState method bindWireEvent.
private void bindWireEvent(Geometry wireMdl, final Wire wire) {
addListener(wireMdl, new MouseEventAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
for (Wire w : wireList) {
Spatial mdl = w.getSpatial();
HintControl control = mdl.getControl(HintControl.class);
boolean enable = w == wire;
if (control != null) {
mdl.removeControl(control);
} else if (enable) {
control = new HintControl();
mdl.addControl(control);
}
}
super.mouseClicked(e);
}
@Override
public void mouseRightClicked(MouseEvent e) {
// 选中显示导线菜单
IContent content = SpringUtil.getBean(PageController.class).getIContent();
if (content instanceof TypicalCase3D) {
Platform.runLater(() -> {
((TypicalCase3D) content).showPopupMenu(wire);
});
}
super.mouseRightClicked(e);
}
});
}
use of com.cas.sim.tis.app.event.MouseEventAdapter 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.sim.tis.app.event.MouseEventAdapter in project TeachingInSimulation by ScOrPiOzzy.
the class TypicalCaseState method bindEvents.
private void bindEvents() {
listener = new TypicalCaseListener(this);
listener.registerWithInput(inputManager);
addListener(desktop, new MouseEventAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (elecComp == null) {
return;
}
// moved_before_putdown = false;
putDown();
super.mouseClicked(e);
}
@Override
public void mouseRightClicked(MouseEvent e) {
if (holding == null) {
return;
}
holding.removeFromParent();
holding = null;
elecComp = null;
cameraState.setZoomEnable(true);
super.mouseRightClicked(e);
}
});
}
Aggregations