feat(core): extract CAD/CADPort annotations into flattened DAE variables · modelscript/modelscript@2bf9089 · GitHub
Skip to content

Commit 2bf9089

Browse files
committed
feat(core): extract CAD/CADPort annotations into flattened DAE variables
1 parent 40e7a2c commit 2bf9089

3 files changed

Lines changed: 67 additions & 7 deletions

File tree

‎packages/core/src/compiler/modelica/annotation.ts‎

Lines changed: 16 additions & 0 deletions

‎packages/core/src/compiler/modelica/dae.ts‎

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2094,6 +2094,8 @@ export abstract class ModelicaVariable extends ModelicaPrimaryExpression {
20942094
arrayDimensions: number[] | null;
20952095
/** Clock domain index (undefined = continuous time). */
20962096
clockDomain?: number | undefined;
2097+
/** Extracted CAD / 3D annotations (as raw string or JSON), e.g. "CAD(uri=\"...\")" */
2098+
cadAnnotationString: string | null;
20972099

20982100
constructor(
20992101
name: string,
@@ -2121,6 +2123,7 @@ export abstract class ModelicaVariable extends ModelicaPrimaryExpression {
21212123
this.arrayDimensions = null;
21222124
/** Clock domain index (undefined = continuous time). */
21232125
this.clockDomain = undefined;
2126+
this.cadAnnotationString = null;
21242127
}
21252128

21262129
override get hash(): string {
@@ -2158,7 +2161,8 @@ export class ModelicaBooleanVariable extends ModelicaVariable {
21582161
return this.attributes.get("start") ?? null;
21592162
}
21602163

2161-
override get toJSON(): string {
2164+
override get toJSON(): JSONValue {
2165+
if (this.cadAnnotationString) return { name: this.name, cad: this.cadAnnotationString };
21622166
return this.name;
21632167
}
21642168

@@ -2201,7 +2205,8 @@ export class ModelicaIntegerVariable extends ModelicaVariable {
22012205
return this.attributes.get("start") ?? null;
22022206
}
22032207

2204-
override get toJSON(): string {
2208+
override get toJSON(): JSONValue {
2209+
if (this.cadAnnotationString) return { name: this.name, cad: this.cadAnnotationString };
22052210
return this.name;
22062211
}
22072212

@@ -2256,7 +2261,8 @@ export class ModelicaRealVariable extends ModelicaVariable {
22562261
return this.attributes.get("stateSelect") ?? null;
22572262
}
22582263

2259-
override get toJSON(): string {
2264+
override get toJSON(): JSONValue {
2265+
if (this.cadAnnotationString) return { name: this.name, cad: this.cadAnnotationString };
22602266
return this.name;
22612267
}
22622268

@@ -2299,7 +2305,8 @@ export class ModelicaStringVariable extends ModelicaVariable {
22992305
return this.attributes.get("start") ?? null;
23002306
}
23012307

2302-
override get toJSON(): string {
2308+
override get toJSON(): JSONValue {
2309+
if (this.cadAnnotationString) return { name: this.name, cad: this.cadAnnotationString };
23032310
return this.name;
23042311
}
23052312

@@ -2322,7 +2329,8 @@ export class ModelicaExpressionVariable extends ModelicaVariable {
23222329
return visitor.visitExpressionVariable(this, argument);
23232330
}
23242331

2325-
override get toJSON(): string {
2332+
override get toJSON(): JSONValue {
2333+
if (this.cadAnnotationString) return { name: this.name, cad: this.cadAnnotationString };
23262334
return this.name;
23272335
}
23282336

@@ -2345,7 +2353,8 @@ export class ModelicaClockVariable extends ModelicaVariable {
23452353
return visitor.visitClockVariable(this, argument);
23462354
}
23472355

2348-
override get toJSON(): string {
2356+
override get toJSON(): JSONValue {
2357+
if (this.cadAnnotationString) return { name: this.name, cad: this.cadAnnotationString };
23492358
return this.name;
23502359
}
23512360

@@ -2414,7 +2423,8 @@ export class ModelicaEnumerationVariable extends ModelicaVariable {
24142423
return this.attributes.get("start") ?? null;
24152424
}
24162425

2417-
override get toJSON(): string {
2426+
override get toJSON(): JSONValue {
2427+
if (this.cadAnnotationString) return { name: this.name, cad: this.cadAnnotationString };
24182428
return this.name;
24192429
}
24202430

@@ -4270,6 +4280,7 @@ export class ModelicaDAEPrinter extends ModelicaDAEVisitor<never> {
42704280
variable.expression.accept(this);
42714281
}
42724282
if (variable.description) this.out.write(' "' + variable.description + '"');
4283+
if (variable.cadAnnotationString) this.out.write(" annotation(" + variable.cadAnnotationString + ")");
42734284
this.out.write(";\n");
42744285
}
42754286

‎packages/core/src/compiler/modelica/flattener.ts‎

Lines changed: 33 additions & 0 deletions

0 commit comments

Comments
 (0)