Skip to content

Commit 3896190

Browse files
committed
fix: nc alignment points support
1 parent ab54854 commit 3896190

File tree

2 files changed

+64
-8
lines changed

2 files changed

+64
-8
lines changed

Diff for: src/renderer/lib/nc/parser/nccst.d.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ export type CommandCstChildren = {
5454
incrementalMode?: IncrementalModeCstNode[];
5555
zeroSet?: ZeroSetCstNode[];
5656
headerEnd?: HeaderEndCstNode[];
57+
selectVisionTool?: SelectVisionToolCstNode[];
58+
singlePointVisionOffset?: SinglePointVisionOffsetCstNode[];
59+
multiPointVisionOffset?: MultiPointVisionOffsetCstNode[];
60+
cancelVisionOffset?: CancelVisionOffsetCstNode[];
61+
visionCorrectedSingleHole?: VisionCorrectedSingleHoleCstNode[];
62+
visionAutoCalibration?: VisionAutoCalibrationCstNode[];
5763
};
5864

5965
export interface UnitsCstNode extends CstNode {
@@ -598,7 +604,7 @@ export interface SinglePointVisionOffsetCstNode extends CstNode {
598604

599605
export type SinglePointVisionOffsetCstChildren = {
600606
G35: IToken[];
601-
coordinate?: CoordinateCstNode[];
607+
coordinate: CoordinateCstNode[];
602608
};
603609

604610
export interface MultiPointVisionOffsetCstNode extends CstNode {

Diff for: src/renderer/lib/nc/parser/parser.ts

+57-7
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,14 @@ class NCParser extends CstParser {
166166
incrementalMode!: ParserMethod<unknown[], CstNode>
167167
zeroSet!: ParserMethod<unknown[], CstNode>
168168
headerEnd!: ParserMethod<unknown[], CstNode>
169+
selectVisionTool!: ParserMethod<unknown[], CstNode>
170+
singlePointVisionOffset!: ParserMethod<unknown[], CstNode>
171+
multiPointVisionOffset!: ParserMethod<unknown[], CstNode>
172+
cancelVisionOffset!: ParserMethod<unknown[], CstNode>
173+
visionCorrectedSingleHole!: ParserMethod<unknown[], CstNode>
174+
visionAutoCalibration!: ParserMethod<unknown[], CstNode>
175+
176+
169177

170178
constructor() {
171179
super(multiModeLexerDefinition, {
@@ -220,6 +228,12 @@ class NCParser extends CstParser {
220228
{ ALT: (): CstNode => this.SUBRULE(this.incrementalMode) },
221229
{ ALT: (): CstNode => this.SUBRULE(this.zeroSet) },
222230
{ ALT: (): CstNode => this.SUBRULE(this.headerEnd) },
231+
{ ALT: (): CstNode => this.SUBRULE(this.selectVisionTool) },
232+
{ ALT: (): CstNode => this.SUBRULE(this.singlePointVisionOffset) },
233+
{ ALT: (): CstNode => this.SUBRULE(this.multiPointVisionOffset) },
234+
{ ALT: (): CstNode => this.SUBRULE(this.cancelVisionOffset) },
235+
{ ALT: (): CstNode => this.SUBRULE(this.visionCorrectedSingleHole) },
236+
{ ALT: (): CstNode => this.SUBRULE(this.visionAutoCalibration) },
223237

224238
])
225239
})
@@ -564,9 +578,7 @@ class NCParser extends CstParser {
564578

565579
this.RULE("singlePointVisionOffset", () => {
566580
this.CONSUME(DefaultTokens.G35)
567-
this.OPTION(() => {
568-
this.SUBRULE(this.coordinate)
569-
})
581+
this.SUBRULE(this.coordinate)
570582
})
571583

572584
this.RULE("multiPointVisionOffset", () => {
@@ -595,7 +607,7 @@ class NCParser extends CstParser {
595607
export const parser = new NCParser()
596608
export const productions: Record<string, Rule> = parser.getGAstProductions();
597609

598-
const GENERATEDTS = false
610+
const GENERATEDTS = true
599611
if (GENERATEDTS) {
600612
const dtsString = generateCstDts(productions);
601613
console.log(dtsString)
@@ -1325,7 +1337,17 @@ export class NCToShapesVisitor extends BaseCstVisitor {
13251337
}
13261338

13271339
singlePointVisionOffset(ctx: Cst.SinglePointVisionOffsetCstChildren): void {
1328-
if (ctx.coordinate) this.visit(ctx.coordinate)
1340+
this.state.previousX = this.state.x
1341+
this.state.previousY = this.state.y
1342+
const { x, y } = this.visit(ctx.coordinate) as PossiblePoints
1343+
if (this.state.coordinateMode === Constants.ABSOLUTE) {
1344+
if (x !== undefined) this.state.x = x
1345+
if (y !== undefined) this.state.y = y
1346+
} else {
1347+
if (x !== undefined) this.state.x += x
1348+
if (y !== undefined) this.state.y += y
1349+
}
1350+
13291351
this.result.push(new Shapes.DatumLine({
13301352
xs: this.state.previousX,
13311353
ys: this.state.previousY,
@@ -1344,6 +1366,16 @@ export class NCToShapesVisitor extends BaseCstVisitor {
13441366
}
13451367

13461368
multiPointVisionOffset(ctx: Cst.MultiPointVisionOffsetCstChildren): void {
1369+
this.state.previousX = this.state.x
1370+
this.state.previousY = this.state.y
1371+
const { x, y } = this.visit(ctx.coordinate) as PossiblePoints
1372+
if (this.state.coordinateMode === Constants.ABSOLUTE) {
1373+
if (x !== undefined) this.state.x = x
1374+
if (y !== undefined) this.state.y = y
1375+
} else {
1376+
if (x !== undefined) this.state.x += x
1377+
if (y !== undefined) this.state.y += y
1378+
}
13471379
if (ctx.coordinate) this.visit(ctx.coordinate)
13481380
this.result.push(new Shapes.DatumLine({
13491381
xs: this.state.previousX,
@@ -1367,7 +1399,16 @@ export class NCToShapesVisitor extends BaseCstVisitor {
13671399
}
13681400

13691401
visionCorrectedSingleHole(ctx: Cst.VisionCorrectedSingleHoleCstChildren): void {
1370-
if (ctx.coordinate) this.visit(ctx.coordinate)
1402+
this.state.previousX = this.state.x
1403+
this.state.previousY = this.state.y
1404+
const { x, y } = this.visit(ctx.coordinate) as PossiblePoints
1405+
if (this.state.coordinateMode === Constants.ABSOLUTE) {
1406+
if (x !== undefined) this.state.x = x
1407+
if (y !== undefined) this.state.y = y
1408+
} else {
1409+
if (x !== undefined) this.state.x += x
1410+
if (y !== undefined) this.state.y += y
1411+
}
13711412
this.result.push(new Shapes.DatumLine({
13721413
xs: this.state.previousX,
13731414
ys: this.state.previousY,
@@ -1386,7 +1427,16 @@ export class NCToShapesVisitor extends BaseCstVisitor {
13861427
}
13871428

13881429
visionAutoCalibration(ctx: Cst.VisionAutoCalibrationCstChildren): void {
1389-
if (ctx.coordinate) this.visit(ctx.coordinate)
1430+
this.state.previousX = this.state.x
1431+
this.state.previousY = this.state.y
1432+
const { x, y } = this.visit(ctx.coordinate) as PossiblePoints
1433+
if (this.state.coordinateMode === Constants.ABSOLUTE) {
1434+
if (x !== undefined) this.state.x = x
1435+
if (y !== undefined) this.state.y = y
1436+
} else {
1437+
if (x !== undefined) this.state.x += x
1438+
if (y !== undefined) this.state.y += y
1439+
}
13901440
this.result.push(new Shapes.DatumLine({
13911441
xs: this.state.previousX,
13921442
ys: this.state.previousY,

0 commit comments

Comments
 (0)