2017-12-22 23:00:23 +01:00
|
|
|
/// <reference path="./moduleView.ts" />
|
2018-01-04 23:03:50 +01:00
|
|
|
/// <reference path="./motorView.ts" />
|
2017-12-18 22:04:17 +01:00
|
|
|
|
|
|
|
namespace pxsim.visuals {
|
2018-01-04 23:03:50 +01:00
|
|
|
export class LargeMotorView extends MotorView implements LayoutElement {
|
2017-12-18 22:04:17 +01:00
|
|
|
|
|
|
|
constructor(port: number) {
|
2018-01-04 23:03:50 +01:00
|
|
|
super(LARGE_MOTOR_SVG, "large-motor", NodeType.LargeMotor, port, "hole");
|
2017-12-18 22:04:17 +01:00
|
|
|
}
|
|
|
|
|
2018-01-04 23:03:50 +01:00
|
|
|
private syncedMotor: MotorNode;
|
|
|
|
private syncedLabelG: SVGGElement;
|
|
|
|
|
2017-12-18 22:04:17 +01:00
|
|
|
updateState() {
|
2017-12-28 20:17:18 +01:00
|
|
|
super.updateState();
|
2017-12-18 22:04:17 +01:00
|
|
|
const motorState = ev3board().getMotors()[this.port];
|
|
|
|
if (!motorState) return;
|
|
|
|
|
2018-01-04 23:03:50 +01:00
|
|
|
const syncedMotor = motorState.getSynchedMotor();
|
2018-01-04 23:09:10 +01:00
|
|
|
if ((syncedMotor || this.syncedMotor) && syncedMotor != this.syncedMotor) {
|
2018-01-04 23:03:50 +01:00
|
|
|
this.syncedMotor = syncedMotor;
|
2018-01-05 19:54:42 +01:00
|
|
|
if (this.syncedMotor) {
|
|
|
|
this.showSyncedLabel(motorState, syncedMotor);
|
|
|
|
} else if (this.syncedLabelG) {
|
|
|
|
this.syncedLabelG.parentNode.removeChild(this.syncedLabelG);
|
|
|
|
}
|
2018-04-10 20:50:58 +02:00
|
|
|
this.setMotorLabel(motorState.getSpeed(), true);
|
2018-01-04 23:03:50 +01:00
|
|
|
}
|
2018-04-10 20:50:58 +02:00
|
|
|
this.setMotorLabel(motorState.getSpeed());
|
2018-01-04 23:03:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private showSyncedLabel(motorNode: MotorNode, syncedMotor: MotorNode) {
|
|
|
|
const a = String.fromCharCode('A'.charCodeAt(0) + motorNode.port);
|
|
|
|
const b = String.fromCharCode('A'.charCodeAt(0) + syncedMotor.port);
|
|
|
|
|
|
|
|
this.syncedLabelG = pxsim.svg.child(this.element, 'g', {'transform': 'scale(0.5)'}) as SVGGElement;
|
|
|
|
pxsim.svg.child(this.syncedLabelG, 'rect', {'rx': 15, 'ry': 15, 'x': 0, 'y': 0, 'width': 84, 'height': 34, 'fill': '#A8A9A8'});
|
|
|
|
pxsim.svg.child(this.syncedLabelG, 'circle', {'cx': 17, 'cy': 17, 'r': 15, 'fill': 'white'});
|
2018-01-09 21:04:37 +01:00
|
|
|
const leftLabel = pxsim.svg.child(this.syncedLabelG, 'text', {'transform': 'translate(11, 22)', 'class': 'no-drag', 'style': 'isolation: isolate;font-size: 16px;fill: #A8A9A8;font-family: ArialMT, Arial'});
|
2018-01-04 23:03:50 +01:00
|
|
|
leftLabel.textContent = a;
|
|
|
|
|
|
|
|
pxsim.svg.child(this.syncedLabelG, 'rect', {'rx': 0, 'ry': 0, 'x': 37, 'y': 12, 'width': 10, 'height': 3, 'fill': '#ffffff'});
|
|
|
|
pxsim.svg.child(this.syncedLabelG, 'rect', {'rx': 0, 'ry': 0, 'x': 37, 'y': 18, 'width': 10, 'height': 3, 'fill': '#ffffff'});
|
|
|
|
|
|
|
|
pxsim.svg.child(this.syncedLabelG, 'circle', {'cx': 67, 'cy': 17, 'r': 15, 'fill': 'white'});
|
2018-01-09 21:04:37 +01:00
|
|
|
const rightLabel = pxsim.svg.child(this.syncedLabelG, 'text', {'transform': 'translate(61, 22)', 'class': 'no-drag', 'style': 'isolation: isolate;font-size: 16px;fill: #A8A9A8;font-family: ArialMT, Arial'});
|
2018-01-04 23:03:50 +01:00
|
|
|
rightLabel.textContent = b;
|
2017-12-18 22:04:17 +01:00
|
|
|
}
|
|
|
|
|
2018-01-04 23:03:50 +01:00
|
|
|
protected renderMotorAngle(holeEl: Element, angle: number) {
|
2018-01-12 22:50:09 +01:00
|
|
|
const width = 35.92;
|
|
|
|
const height = 35.9;
|
|
|
|
const transform = `translate(45.000000, 1.000000) rotate(${angle} ${width / 2} ${height / 2})`;
|
2017-12-18 22:04:17 +01:00
|
|
|
holeEl.setAttribute("transform", transform);
|
|
|
|
}
|
|
|
|
|
|
|
|
getWiringRatio() {
|
2017-12-27 23:48:15 +01:00
|
|
|
return 0.37;
|
2017-12-18 22:04:17 +01:00
|
|
|
}
|
2018-04-10 20:50:58 +02:00
|
|
|
|
|
|
|
protected positionMotorLabel() {
|
|
|
|
const hasSyncedLabel = this.syncedMotor;
|
|
|
|
this.motorLabelGroup.setAttribute('transform', `translate(${hasSyncedLabel ? '15 35' : '25 15'})`);
|
|
|
|
this.motorLabel.style.fontSize = '13px';
|
|
|
|
}
|
2017-12-18 22:04:17 +01:00
|
|
|
}
|
|
|
|
}
|