import { Component, OnInit } from '@angular/core';
|
import { FileLoaderService } from '../file-loader.service';
|
|
@Component({
|
selector: 'app-g-code-tologato',
|
template: `
|
<mat-form-field>
|
<mat-label>Betű kódja</mat-label>
|
<textarea matInput [(ngModel)]="sourceCode" (change)="updateGeneratedCode()"></textarea>
|
</mat-form-field>
|
|
<mat-form-field>
|
<mat-label>Eltolás X tengelyen (mm)</mat-label>
|
<input matInput type="number" [(ngModel)]="shiftX" (change)="updateGeneratedCode()">
|
</mat-form-field>
|
|
<mat-form-field>
|
<mat-label>Eltolás Y tengelyen (mm)</mat-label>
|
<input matInput type="number" [(ngModel)]="shiftY" (change)="updateGeneratedCode()">
|
</mat-form-field>
|
|
<div class="card-container">
|
<button class="card card-small" tabindex="0">
|
<svg class="material-icons" xmlns="http://www.w3.org/2000/svg" width="24" height="24"
|
viewBox="0 0 24 24">
|
<path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
|
</svg>
|
<span>New Component</span>
|
</button>
|
</div>
|
|
<!-- Terminal -->
|
<div class="terminal">
|
<pre>{{generatedCode}}</pre>
|
</div>
|
`,
|
styleUrls: ['./g-code-shifter.component.scss']
|
})
|
export class GCodeShifter implements OnInit {
|
|
sourceCode = 'G0 X27.8800 Y-42.3326 Z11.0580\n' +
|
'G1 Z-0.2000 F100\n' +
|
'G1 X24.9039 F600\n' +
|
'X25.2185 Y-41.9290 \n' +
|
'X27.2279 Y-40.0988 \n' +
|
'X27.6354 Y-39.5355 \n' +
|
'G3 X27.7442 Y-37.9830 I-1.5579 J0.8893 \n' +
|
'G3 X26.5839 Y-37.0242 I-1.5317 J-0.6721\n' +
|
'G3 X24.8808 Y-37.2086 I-0.6004 J-2.4118\n' +
|
'G3 X24.0106 Y-38.7088 I0.9643 J-1.5617\n' +
|
'G1 X24.7726 Y-38.7850 \n' +
|
'X24.8564 Y-38.2781 \n' +
|
'G2 X25.3733 Y-37.7000 I0.9756 J-0.3522 \n' +
|
'G2 X26.7096 Y-37.8067 I0.5761 J-1.2061\n' +
|
'G2 X27.0601 Y-38.9488 I-0.6304 J-0.8183\n' +
|
'G2 X26.5436 Y-39.7796 I-2.0272 J0.6843\n' +
|
'G1 X25.4232 Y-40.8058 \n' +
|
'G3 X24.1552 Y-42.1199 I3.3619 J-4.5124 \n' +
|
'G3 X23.8666 Y-43.0438 I1.3896 J-0.9411\n' +
|
'G1 X27.8800 \n' +
|
' Y-42.3326 \n' +
|
'G0 Z11.0580\n';
|
|
shiftX = 2;
|
shiftY = 2;
|
|
generatedCode = '';
|
|
|
constructor(public fileLoader: FileLoaderService) {}
|
|
updateGeneratedCode() {
|
const myregexp = /(X|Y)([\-0-9]+(?:.[0-9]+)?)/ig;
|
this.generatedCode = this.sourceCode.replace(myregexp, (match, axis, value) => {
|
if (axis === 'X') {
|
return axis + this.transformX(parseFloat(value)).toFixed(4);
|
}
|
|
return axis + this.transformY(parseFloat(value)).toFixed(4);
|
});
|
|
}
|
|
private transformX(x: number): number {
|
return x + this.shiftX;
|
}
|
|
private transformY(y: number): number {
|
return y + this.shiftY;
|
}
|
|
ngOnInit(): void {
|
this.updateGeneratedCode();
|
}
|
}
|