use of com.cas.circuit.vo.Wire in project TeachingInSimulation by ScOrPiOzzy.
the class R method collectIsopotentialTerminal.
public static void collectIsopotentialTerminal(Terminal ref, IP isopotential, R r) {
// }
if (!isopotential.hasTerminal(ref)) {
isopotential.addTerminal(ref);
}
// 遍历所有和ref关联的导线
List<Terminal> wireAnotherTerms = new ArrayList<Terminal>();
for (Wire wire : ref.getWires()) {
if (!wire.isBothBinded()) {
// toRemove.add(linker);
continue;
}
if (isopotential.getPassedWires().contains(wire) || wire.isBrokenBreak()) {
continue;
}
isopotential.getPassedWires().add(wire);
Terminal anotherTerm = wire.getAnother(ref);
if (anotherTerm != null) {
// System.out.println(str + "R.collectIsopotentialTerminal ()" + wire);
wireAnotherTerms.add(anotherTerm);
collectIsopotentialTerminal(anotherTerm, isopotential, r);
}
}
// FIXME 删除只接了一个连接头的导线????
// wires.removeAll(toRemove);
// 获取线缆中与ref关联的连接头
Terminal contacted = ref.getContacted();
if (contacted != null && !isopotential.getPassedContacted().contains(contacted)) {
isopotential.getPassedContacted().add(contacted);
collectIsopotentialTerminal(contacted, isopotential, r);
}
// 遍历和ref有电阻关系的电阻
Map<Terminal, ResisRelation> resisRelationMap = ref.getResisRelationMap();
Iterator<Entry<Terminal, ResisRelation>> iter = resisRelationMap.entrySet().iterator();
Terminal key_Terminal = null;
ResisRelation resisRelation = null;
while (iter.hasNext()) {
Map.Entry<Terminal, ResisRelation> entry = iter.next();
key_Terminal = entry.getKey();
resisRelation = entry.getValue();
if (!isopotential.getPassedResis().contains(key_Terminal)) {
isopotential.getPassedResis().add(key_Terminal);
if (resisRelation.getValue() == 0 || wireAnotherTerms.contains(key_Terminal)) {
// 阻值为零,则以ref对应的连接头递归处理 或 此电阻被短接了
collectIsopotentialTerminal(key_Terminal, isopotential, r);
} else {
isopotential.getResisRelationList().add(resisRelation);
if (r != null) {
// 遇到连接头是电阻的一端的,先创建出一个复合电阻对象
if (r.resisRelationWithCR.get(resisRelation) != null) {
CR cr = r.resisRelationWithCR.get(resisRelation);
isopotential.getCRList().add(cr);
cr.setIospo2(isopotential);
} else {
CR cr = new CR(r);
// 设置这个复合电阻的所指代的真实电阻
cr.addResisRelation(resisRelation);
isopotential.getCRList().add(cr);
cr.setIospo1(isopotential);
r.resisRelationWithCR.put(resisRelation, cr);
}
}
}
}
}
}
use of com.cas.circuit.vo.Wire in project TeachingInSimulation by ScOrPiOzzy.
the class ConnectionController method initXianLanPanel.
/**
* 初始化线缆面板
*/
public void initXianLanPanel(List<Wire> wires, boolean visible) {
setContentVisible("xianlanColorsContent", String.valueOf(visible));
if (!visible) {
cableLabels = null;
return;
}
Element xianlanColorsContent = findById("xianlanColorsContent");
if (xianlanColorsContent == null || wires == null) {
return;
}
// 线缆导线排序
Comparator<Wire> comparator = new Comparator<Wire>() {
@Override
public int compare(Wire wire1, Wire wire2) {
return wire1.getPO().getStitch1().compareTo(wire2.getPO().getStitch1());
}
};
Collections.sort(wires, comparator);
List<Element> eles = xianlanColorsContent.getElements();
for (int i = 0; i < eles.size(); i++) {
removeXianLanItem(i);
}
List<String> xianLanStrs = new ArrayList<String>();
for (int i = 0; i < wires.size(); i++) {
String xianLanStr = wires.get(i).getPO().getMark();
xianLanStrs.add(xianLanStr);
Element ele = createXianLanItem(xianLanStr, wires.get(i).getPO().getColor(), i);
if (i != 0) {
ele.stopEffect(EffectEventId.onActive);
}
}
refreshxianlanColorsContent();
currentCableIndex = 0;
cableLabels = new String[xianLanStrs.size()];
xianLanStrs.toArray(cableLabels);
}
use of com.cas.circuit.vo.Wire in project TeachingInSimulation by ScOrPiOzzy.
the class ConnectionHandler method onlineOrSaveLinker.
/**
* 根据linkerInfo处理接线并记录
*/
private void onlineOrSaveLinker(LinkerMsg msg, boolean modifiable) {
int key = msg.getKey();
byte linkType = msg.getLinkType();
ILinker linker = null;
if (onlineAndSaves.containsKey(key)) {
linker = onlineAndSaves.get(key);
} else if (LinkerMsg.WIRE == linkType) {
linker = new Wire(1, msg.getColor());
onlineAndSaves.put(key, linker);
} else if (LinkerMsg.PIPE == linkType) {
linker = new Pipe(1, msg.getColor());
onlineAndSaves.put(key, linker);
} else if (LinkerMsg.CABLE_JACK == linkType || LinkerMsg.CABLE_TERM == linkType) {
linker = cableMap.get(msg.getCableKey()).clone();
if (msg.isElecComp()) {
Cable cable = ((Cable) linker);
linker = bindSaveTransEvent(msg.getElecCompKey(), cable, modifiable);
if (linker != null) {
onlineAndSaves.put(key, linker);
}
return;
}
onlineAndSaves.put(key, linker);
}
connectByLinkerInfo(msg, linker, modifiable);
}
use of com.cas.circuit.vo.Wire in project TeachingInSimulation by ScOrPiOzzy.
the class ConnectionHandler method refreshViewPort.
public void refreshViewPort(ILinker wireOrPipe) {
Spatial viewMdl = null;
if (wireOrPipe instanceof Wire) {
viewMdl = ConnectionUtil.getWireTerm();
viewMdl.scale(500);
viewMdl.move(4.8f, -4, -5);
} else if (wireOrPipe instanceof Pipe) {
viewMdl = ConnectionUtil.getPipeTerm();
viewMdl.scale(300);
viewMdl.move(4.2f, -3.6f, -5);
} else if (wireOrPipe instanceof Cable) {
viewMdl = ConnectionUtil.getJackTerm(null);
viewMdl.scale(100);
viewMdl.rotate(FastMath.HALF_PI, FastMath.HALF_PI, 0);
viewMdl.move(4, -3f, -3);
}
viewRoot.detachAllChildren();
if (wireOrPipe == null) {
// FilterUtil.getBorderFilter().setEnabled(false);
if (ui != null) {
ui.setViewAreaVisible(false);
}
} else {
JmeUtil.changeColor(((Node) viewMdl).getChild("model"), wireOrPipe.getColor());
viewRoot.attachChild(viewMdl);
// FilterUtil.getBorderFilter().setEnabled(true);
if (ui != null) {
ui.setViewAreaVisible(true);
}
}
viewRoot.updateGeometricState();
}
use of com.cas.circuit.vo.Wire in project TeachingInSimulation by ScOrPiOzzy.
the class ConnectionHandler method deleteTmpLinker.
/**
* 删除临时接线处理
* @param linker 临时接线对象
* @param modifiable 可以被当前用户修改的临时接线对象
* @return
*/
private byte deleteTmpLinker(ILinker linker, boolean modifiable) {
if (linker == null || linker.isBothBinded() || (linker.getLinkTarget1() == null && linker.getLinkTarget2() == null)) {
return LinkerMsg.NONE_MSG;
}
if (!(linker instanceof Cable) || !((Cable) linker).isSinglePlug()) {
deleteLinker(linker, modifiable);
return LinkerMsg.DELETE_LINKER;
}
Cable cable = (Cable) linker;
List<Wire> bindWires = cable.getBindWires();
if (cable.getBindWires().size() == 0) {
deleteLinker(linker, modifiable);
ui.initXianLanPanel(null, false);
return LinkerMsg.DELETE_LINKER;
}
Wire wire = bindWires.get(bindWires.size() - 1);
cable.getBindWires().remove(wire);
cable.setPrevWire(wire);
cable.setNowConnectingWire(wire.getPO().getMark());
Map<Spatial, ILinkTarget> mdls = wire.getModels();
for (Spatial linkTerm : mdls.keySet()) {
JmeUtil.detachModel(linkTerm);
wire.getModels().remove(linkTerm);
cable.getModels().remove(linkTerm);
}
wire.unbind(wire.getLinkTarget2());
if (!modifiable) {
return LinkerMsg.DELETE_SINGLE_TARGET;
}
List<Wire> wires = new ArrayList<Wire>(cable.getMark_wire().values());
for (Wire w : cable.getBindWires()) {
wires.remove(w);
}
if (wires.size() == 0) {
ui.initXianLanPanel(null, false);
setLineVisible(false);
} else {
ui.initXianLanPanel(wires, true);
ILinkTarget target = null;
if (bindWires.size() == 0) {
target = cable.getLinkTarget1();
} else {
Wire currWire = bindWires.get(bindWires.size() - 1);
target = currWire.getLinkTarget2();
}
showLineBetweenLinker(cable);
Map<Spatial, ILinkTarget> termMdls = cable.getModels();
for (Entry<Spatial, ILinkTarget> set : termMdls.entrySet()) {
if (set.getValue().equals(target)) {
refreshLineBetweenLinker(set.getKey());
break;
}
}
}
return LinkerMsg.DELETE_SINGLE_TARGET;
}
Aggregations