wt-huatu 1.3.4 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Readme.md CHANGED
@@ -1,12 +1,11 @@
1
- <div style="text-align:center;">
2
- <svg data-v-ab95988f="" version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="-5.45 -5.6 10.9 11.2" width="141.70000000000002" height="145.6"><polyline points="-2.250,5.0 -4.850,5.0 -4.850,-5.0 -2.250,-5.0 -2.250,-1.180 2.250,-1.180 2.250,-5.0 4.850,-5.0 4.850,5.0 2.250,5.0 2.250,1.180 -2.250,1.180 -2.250,3.180" fill="#0b4d4233" stroke="currentColor" stroke-width="0.4"></polyline><circle cx="-2.250" cy="5.0" r="0.40" fill="black"></circle><circle cx="-2.250" cy="1.180" r="0.40" fill="black"></circle><circle cx="-2.250" cy="3.180" r="0.40" fill="red"></circle></svg>
3
- </div>
1
+
2
+ ![wt-huatu logo](https://raw.githubusercontent.com/littlefattie/wt-huatu/main/imgs/wt-huatu-logo.svg)
4
3
 
5
4
  `wt-huatu`, is a Drawing Library to draw something mathematically, logically, hierarchically and programmatically.
6
5
 
7
- For quick and fruitful info, please go to the official site: [https://wt-huatu.org](https://wt-huatu.org).
6
+ For quick and fruitful info, please go to the official site: [https://github.com/littlefattie/wt-huatu](https://github.com/littlefattie/wt-huatu).
8
7
 
9
- It is written in `Typescript`, can be used as a library, to be integrated into your project. For example, you can embed it into a customized markdown renderer to use it as some text-to-image renderer. Or it can be used as some drawing tool when using the online editor at [https://wt-huatu.org/editor](https://wt-huatu.org/editor).
8
+ It is written in `Typescript`, can be used as a library, to be integrated into your project. For example, you can embed it into a customized markdown renderer to use it as some text-to-image renderer. Or it can be used as some drawing tool when using the online editor at [https://littlefattie.github.io/wt-huatu-editor/](https://littlefattie.github.io/wt-huatu-editor/).
10
9
 
11
10
  Quick and intuitive explanation. It will convert some text description like this:
12
11
 
@@ -43,11 +42,11 @@ draw:
43
42
  - cA; fill, none; stroke; 1, cc
44
43
  - cB; fill, none; stroke; 1, cc
45
44
  - triABC; fill, yellow; stroke; 1, cc
46
- - circle; pA; 3 ||| fill; grey
47
- - circle; pB; 3 ||| fill; grey
48
- - circle; pC; 3 ||| fill; grey
49
- - circle; pD; 3 ||| fill; grey
50
- - circle; pE; 3 ||| fill; grey
45
+ - circle; pA; 2 ||| fill; grey
46
+ - circle; pB; 2 ||| fill; grey
47
+ - circle; pC; 2 ||| fill; grey
48
+ - circle; pD; 2 ||| fill; grey
49
+ - circle; pE; 2 ||| fill; grey
51
50
  - label; at; pA; w; 20; h; 22; anchor; mr ||| $A$
52
51
  - label; at; pB; w; 20; h; 22; anchor; ml ||| $B$
53
52
  - label; at; pC; w; 20; h; 22; anchor; bm ||| $C$
@@ -57,71 +56,7 @@ draw:
57
56
 
58
57
  to some SVG image like this:
59
58
 
60
- <div style="text-align:center;">
61
- <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="-118.05806756909202 -120.4116135138184 334.17420270727604 221.2116135138184" width="334.174" height="221.212">
62
- <defs>
63
- <style type="text/css">
64
- foreignObject &gt; body { margin: 0; width: 100%; height: 100%; }
65
- .wthuatu-label-box-2b25127a { fill: none; }
66
- .huatu-label-container-2b25127a { width: 100%; height: 100%; padding: 0; display: flex; }
67
- .huatu-label-text-2b25127a { margin: auto 0; text-align: center; max-height: 100%; width: 100%; line-height: 1.0; }
68
- </style>
69
- </defs>
70
- <circle cx="0.000000" cy="0.000000" r="100.000000" fill="none" stroke="currentColor" stroke-width="1.000000"></circle>
71
- <circle cx="98.058068" cy="-19.611614" r="100.000000" fill="none" stroke="currentColor" stroke-width="1.000000"></circle>
72
- <path d="M0.000000,0.000000 L98.058068,-19.611614 L32.044878,-94.726584 z" fill="yellow" stroke="currentColor" stroke-width="1.000000"></path>
73
- <circle cx="0.000000" cy="0.000000" r="3.000000" fill="grey"></circle>
74
- <circle cx="98.058068" cy="-19.611614" r="3.000000" fill="grey"></circle>
75
- <circle cx="32.044878" cy="-94.726584" r="3.000000" fill="grey"></circle>
76
- <circle cx="-98.058068" cy="19.611614" r="3.000000" fill="grey"></circle>
77
- <circle cx="196.116135" cy="-39.223227" r="3.000000" fill="grey"></circle>
78
- <g transform="translate(-20.000000,-11.000000)">
79
- <foreignObject x="0" y="0" width="20" height="22">
80
- <div class="huatu-label-container-2b25127a">
81
- <div class="huatu-label-text-2b25127a">
82
- <span class="katex"><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord mathnormal">A</span></span></span></span>
83
- </div>
84
- </div>
85
- </foreignObject>
86
- </g>
87
- <g transform="translate(0.000000,-11.000000)">
88
- <foreignObject x="98.05806756909202" y="-19.611613513818398" width="20" height="22">
89
- <div class="huatu-label-container-2b25127a">
90
- <div class="huatu-label-text-2b25127a">
91
- <span class="katex"><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord mathnormal" style="margin-right:0.05017em;">B</span></span></span></span>
92
- </div>
93
- </div>
94
- </foreignObject>
95
- </g>
96
- <g transform="translate(-10.000000,-22.000000)">
97
- <foreignObject x="32.044878272377076" y="-94.72658431775389" width="20" height="22">
98
- <div class="huatu-label-container-2b25127a">
99
- <div class="huatu-label-text-2b25127a">
100
- <span class="katex"><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord mathnormal" style="margin-right:0.07153em;">C</span></span></span></span>
101
- </div>
102
- </div>
103
- </foreignObject>
104
- </g>
105
- <g transform="translate(-20.000000,0.000000)">
106
- <foreignObject x="-98.05806756909202" y="19.611613513818384" width="20" height="22">
107
- <div class="huatu-label-container-2b25127a">
108
- <div class="huatu-label-text-2b25127a">
109
- <span class="katex"><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord mathnormal" style="margin-right:0.02778em;">D</span></span></span></span>
110
- </div>
111
- </div>
112
- </foreignObject>
113
- </g>
114
- <g transform="translate(0.000000,-22.000000)">
115
- <foreignObject x="196.11613513818403" y="-39.223227027636796" width="20" height="22">
116
- <div class="huatu-label-container-2b25127a">
117
- <div class="huatu-label-text-2b25127a">
118
- <span class="katex"><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord mathnormal" style="margin-right:0.05764em;">E</span></span></span></span>
119
- </div>
120
- </div>
121
- </foreignObject>
122
- </g>
123
- </svg>
124
- </div>
59
+ ![wt-huatu example of introduction](https://raw.githubusercontent.com/littlefattie/wt-huatu/main/imgs/wt-huatu-ex-intro.svg)
125
60
 
126
61
  There are some examples in the folder `examples`, which are used as the library is developed. They are simply `.yml` files, except some special syntax.
127
62
 
@@ -146,7 +81,7 @@ import {
146
81
  renderYmlInput
147
82
  } from "wt-huatu";
148
83
 
149
- import * as fs from "fs";
84
+ import fs from "fs";
150
85
 
151
86
  // 设计输入
152
87
  // The design input file
@@ -198,26 +133,26 @@ draw:
198
133
 
199
134
  // 用例1:直接生成嵌入svg文件的Html文件(字符串),可直接在浏览器中查看及打印。
200
135
  // Usage 1: Generate the svg-image-embedded html directly, you can browse it in a browser.
201
- const svgHtml1 = renderWtHuatuYml(htDesignInput);
136
+ const svgHtml1 = await renderWtHuatuYml(htDesignInput);
202
137
  fs.writeFileSync("./test-wt-huatu.html", svgHtml1);
203
138
 
204
139
  // 用例2:编译解析后获取完全体结果
205
140
  // Usage 2: Render the input to get a full-functional Object `WtHuatu`
206
- const parsedRes = renderYmlInput(htDesignInput, {});
141
+ const parsedRes = await renderYmlInput(htDesignInput, {});
207
142
  // WtHuatu对象, 可以查看其所有成员变量,以便于进行二次开发
208
143
  // 或者选择性生成全部或部分所设计/定义的图形元素
209
- // The parsed WtHuatu object, you can inspect all the members and call the methods, make secondary developments or intergrate into your own applications
144
+ // The parsed WtHuatu object, you can inspect all the members and call the methods,
145
+ // make secondary developments or intergrate into your own applications,
210
146
  // Or you can use this object to generate part or all the designed drawing elements ever designed
211
- const htObj = parsedRes.huatu!;
147
+ const htObj = parsedRes.huatu;
212
148
  // 从唯一的输出任务(draw)生成svg文件(字符串),可以将此SVG文件保存为单独的文件或者嵌入到
213
149
  // 其他支持SVG格式的图形处理软件中
214
150
  // Output the svg file of the only job `draw`, you can save this to seperate file
215
151
  // Or embed itinto other systems that can handle SVGs.
216
- const svg1 = parsedRes.rendered.find(x => x.jobName === 'draw')!.html;
152
+ const svg1 = parsedRes.rendered.find(x => x.jobName === 'draw').html;
217
153
  // 保存svg到文件
218
154
  // Save to local SVG format image file
219
155
  fs.writeFileSync("./test-wt-huatu.svg", svg1);
220
-
221
156
  ```
222
157
 
223
158
  If you are interested, let's draw!
@@ -1,3 +1,4 @@
1
+ import Point from "../geometry/Point.js";
1
2
  import { WtMath } from "../math/WtMath.js";
2
3
  import { AngDeg } from "../geometry/AngDeg.js";
3
4
  import Line from "../geometry/Line.js";
@@ -52,7 +53,11 @@ export class HuatuComponentPort {
52
53
  };
53
54
  // Some indicator to know whether the two ports (two arrows of the two holding lines) are facing to each other
54
55
  static isTwoPortsFacing = (p1, p2) => {
56
+ const p1f = new Line(p1.anchor, p1.lineAng).getPointByLen(2), d1 = Point.getDistance(p1.anchor, p2.anchor), d2 = Point.getDistance(p1f, p2.anchor);
55
57
  const angDiff = AngDeg.fitAng(p1.lineAng - p2.lineAng);
56
- return (angDiff >= AngDeg.DEG90 && angDiff <= AngDeg.DEG270);
58
+ return (d1 > d2) && (angDiff >= AngDeg.DEG90 && angDiff <= AngDeg.DEG270);
59
+ };
60
+ static isTowPortsParallelBacking = (p1, p2) => {
61
+ return WtMath.isEqual(AngDeg.DEG180, AngDeg.fitAng(p1.lineAng - p2.lineAng));
57
62
  };
58
63
  }
@@ -27,15 +27,19 @@ export class AngDeg {
27
27
  static deg2Ang(deg) {
28
28
  return deg * Math.PI / 180;
29
29
  }
30
- // Move The ang to range of [0, 360), and convert to Angle form
31
- static fitDeg(deg) {
30
+ // Round the Deg into the range of [0, 360)
31
+ static roundDeg(deg) {
32
32
  while (deg >= 360) {
33
33
  deg -= 360;
34
34
  }
35
35
  while (deg < 0) {
36
36
  deg += 360;
37
37
  }
38
- return AngDeg.deg2Ang(deg);
38
+ return deg;
39
+ }
40
+ // Move The deg to range of [0, 360), and convert to Angle form
41
+ static fitDeg(deg) {
42
+ return AngDeg.deg2Ang(AngDeg.roundDeg(deg));
39
43
  }
40
44
  static fitAng(ang) {
41
45
  while (ang >= AngDeg.DEG360) {
package/huatu/Huatu.js CHANGED
@@ -54,6 +54,7 @@ import { HuatuComponentPort } from "../component/HuatuComponentPort.js";
54
54
  import { HuatuCompDrawing } from "./HuatuCompDrawing.js";
55
55
  import { HuatuWire } from "../wire/HuatuWire.js";
56
56
  import { HuatuWireDrawing } from "../wire/HuatuWireDrawing.js";
57
+ import { HuatuNet } from "../wire/HuatuNet.js";
57
58
  import { HuatuAngleMark } from "./HuatuAngleMark.js";
58
59
  import { HuatuDimMark } from "./HuatuDimMark.js";
59
60
  import { genHex } from "../tools/gen-id.js";
@@ -1940,7 +1941,7 @@ export class WtHuatu {
1940
1941
  * Check if the user has given a valid string to specify the marker, if it is a name for "predefined"
1941
1942
  * marker, then the marker will be copied into the in-use collection with the same name. Or it
1942
1943
  * needs to be some marker defined by user manually.
1943
- * @param ptn The defined name or pre-defined name for the Marker user wants to use
1944
+ * @param mkr The defined name or pre-defined name for the Marker user wants to use
1944
1945
  * @returns The Marker or undefined if not found
1945
1946
  */
1946
1947
  checkMarker(mkr) {
@@ -2253,8 +2254,10 @@ export class WtHuatu {
2253
2254
  realOrphans.push(orphan);
2254
2255
  }
2255
2256
  });
2256
- const orphans = realOrphans.map(x => `'${x}'`).join(", ");
2257
- this.warnings.push(`[Resolving Label Style '${name}']: ${orphans} could not be resolved!`);
2257
+ if (realOrphans.length > 0) {
2258
+ const orphans = realOrphans.map(x => `'${x}'`).join(", ");
2259
+ this.warnings.push(`[Resolving Label Style '${name}']: ${orphans} could not be resolved!`);
2260
+ }
2258
2261
  }
2259
2262
  else {
2260
2263
  res = parseStrIntoKeyValuePair(value, optsLabelStyle);
@@ -2289,14 +2292,16 @@ export class WtHuatu {
2289
2292
  lblStyle.color = lsParams.color;
2290
2293
  if (lsParams.fontName)
2291
2294
  lblStyle.font = lsParams.fontName;
2292
- if (lsParams.bold)
2295
+ if (lsParams.bold !== undefined)
2293
2296
  lblStyle.bold = lsParams.bold;
2294
- if (lsParams.italic)
2297
+ if (lsParams.italic !== undefined)
2295
2298
  lblStyle.italic = lsParams.italic;
2296
2299
  if (lsParams.addLine)
2297
2300
  lblStyle.addLine = lsParams.addLine;
2298
2301
  if (lsParams.fontSize)
2299
2302
  lblStyle.fontSize = lsParams.fontSize;
2303
+ if (lsParams.lineHeight)
2304
+ lblStyle.lineHeight = lsParams.lineHeight;
2300
2305
  this.labelStyles.push(lblStyle);
2301
2306
  return [];
2302
2307
  }
@@ -3266,11 +3271,11 @@ export class WtHuatu {
3266
3271
  }
3267
3272
  }
3268
3273
  }
3274
+ // 2. Check if it is a point referencing some shape/path, etc, or purely some point definition
3269
3275
  const tryPointExpr = this.resolvePointFromExpr(def);
3270
3276
  if (tryPointExpr)
3271
3277
  return tryPointExpr;
3272
- // TODO: implement it
3273
- // 2. Check if it is a point referencing some shape/path, etc, or purely some point definition
3278
+ // Return none if no hit
3274
3279
  return undefined;
3275
3280
  }
3276
3281
  parseWireDef(def) {
@@ -3279,15 +3284,8 @@ export class WtHuatu {
3279
3284
  if (!params.from) {
3280
3285
  return `You must provide 'From' terminal to define a wire. '${def}' lacks some!`;
3281
3286
  }
3282
- let net;
3283
3287
  if (!params.to) {
3284
- if (params.net) {
3285
- net = this.nets.find(x => x.name === params.net);
3286
- if (!net) {
3287
- return `No 'To' terminal and the net you refer (${params.net}) doesn't exist`;
3288
- }
3289
- }
3290
- else {
3288
+ if (!params.net) {
3291
3289
  return `No 'To' terminal and no net defined for the wire '${def}'`;
3292
3290
  }
3293
3291
  }
@@ -3300,12 +3298,23 @@ export class WtHuatu {
3300
3298
  if (params.to) {
3301
3299
  termTo = this.resolveWireTerminal(params.to);
3302
3300
  if (!termTo) {
3303
- errMsg.push(`Wire terminal 'To' (${params.to}) cannot resolve to a valid point!`);
3301
+ if (HuatuWire.TO_HV_TYPES.includes((params.type || "auto").toLowerCase())) {
3302
+ const tryXorY = this.resolvePointCoorsExpr(params.to);
3303
+ if (tryXorY === undefined) {
3304
+ errMsg.push(`Please specify X/Y values when you draw a toX or toY wire!`);
3305
+ }
3306
+ else {
3307
+ termTo = tryXorY;
3308
+ }
3309
+ }
3310
+ else {
3311
+ errMsg.push(`Wire terminal 'To' (${params.to}) cannot resolve to a valid point!`);
3312
+ }
3304
3313
  }
3305
3314
  }
3306
3315
  if (errMsg.length > 0)
3307
3316
  return errMsg.join("\n");
3308
- const wire = new HuatuWire(termFrom, termTo, params.type);
3317
+ const wire = new HuatuWire(def, termFrom, termTo, params.type);
3309
3318
  // Check other parameters of that wire
3310
3319
  if (params.color)
3311
3320
  wire.strokeColor = params.color;
@@ -3350,8 +3359,34 @@ export class WtHuatu {
3350
3359
  wire.turnAt = turnAt;
3351
3360
  }
3352
3361
  }
3362
+ if (params.turnLen) {
3363
+ const turnLen = this.resolveVarExpr(params.turnLen);
3364
+ if (turnLen === undefined) {
3365
+ this.warnings.push(`turnLen parameter '${params.turnLen}' of wire def is invalid, it cannot resolve to a number!`);
3366
+ }
3367
+ else {
3368
+ wire.turnLen = turnLen;
3369
+ }
3370
+ }
3353
3371
  if (params.net) {
3354
- // TODO: handle Net
3372
+ let tryNet = this.nets.find(x => x.name === params.net);
3373
+ if (!tryNet) {
3374
+ tryNet = new HuatuNet(this, params.net);
3375
+ this.nets.push(tryNet);
3376
+ }
3377
+ wire.net = tryNet;
3378
+ if (params.netColor && isValidColor(params.netColor)) {
3379
+ wire.net.color = params.netColor;
3380
+ }
3381
+ if (params.netLineWidth) {
3382
+ const netlw = this.resolveVarExpr(params.netLineWidth);
3383
+ if (netlw === undefined || netlw < 0) {
3384
+ this.warnings.push(`net linewidth parameter '${params.netLineWidth}' of wire def is invalid, it cannot resolve to a positive number!`);
3385
+ }
3386
+ else {
3387
+ wire.net.lineWidth = netlw;
3388
+ }
3389
+ }
3355
3390
  }
3356
3391
  if (params.lineWidth) {
3357
3392
  const lw = this.resolveVarExpr(params.lineWidth);
@@ -3377,6 +3412,16 @@ export class WtHuatu {
3377
3412
  if (params.squareJoint) {
3378
3413
  wire.isSquareJoint = true;
3379
3414
  }
3415
+ if (params.endArrow) {
3416
+ let mkr = this.checkMarker(params.endArrow);
3417
+ if (mkr)
3418
+ wire.markerEnd = mkr;
3419
+ }
3420
+ if (params.startArrow) {
3421
+ let mkr = this.checkMarker(params.startArrow);
3422
+ if (mkr)
3423
+ wire.markerStart = mkr;
3424
+ }
3380
3425
  // Resolve Points
3381
3426
  wire.tryResolvePoints();
3382
3427
  return new HuatuWireDrawing(wire, this);
@@ -3518,6 +3563,8 @@ export class WtHuatu {
3518
3563
  conf.noStartArrow = true;
3519
3564
  if (!!params.noEndArrow)
3520
3565
  conf.noEndArrow = true;
3566
+ if (!!params.barLenEqual)
3567
+ conf.barLenEqual = true;
3521
3568
  if (params.barColor)
3522
3569
  conf.barColor = params.barColor;
3523
3570
  if (params.lineColor)
@@ -3702,6 +3749,13 @@ export class WtHuatu {
3702
3749
  // Return the errors when resolving
3703
3750
  return errs;
3704
3751
  }
3752
+ settleNetWires() {
3753
+ // Settle Wires of all the nets
3754
+ this.nets.forEach(n => n.settleWires());
3755
+ }
3756
+ resetNetTrunkDrawStatus() {
3757
+ this.nets.forEach(n => n.resetTrunkDrawnStatus());
3758
+ }
3705
3759
  /**
3706
3760
  * Resolve Layer definition, the input might be a string, or a string list
3707
3761
  * @param name Name of the Layer
@@ -3905,6 +3959,7 @@ export class WtHuatu {
3905
3959
  "block", "layer",
3906
3960
  "component", "wire",
3907
3961
  ];
3962
+ // Resolve drawings
3908
3963
  drawItems.forEach(d => {
3909
3964
  const draw = this.resolveJobDrawingItem(d, allowedTypes);
3910
3965
  if (typeof draw === "string") {
@@ -3926,6 +3981,8 @@ export class WtHuatu {
3926
3981
  job.drawings.push(draw);
3927
3982
  }
3928
3983
  });
3984
+ // Settle Net wires
3985
+ this.settleNetWires();
3929
3986
  // Re-Check ViewBox
3930
3987
  if (!job.viewBox) {
3931
3988
  if (job.huatu.viewBox) {
@@ -3997,14 +4054,12 @@ export class WtHuatu {
3997
4054
  let i = 0;
3998
4055
  while (i < src.length) {
3999
4056
  if (isIvKey(src[i])) {
4000
- if ((i + 1) < src.length) {
4001
- if (!isIvKey(src[i + 1])) {
4002
- ivObj[src[i]] = src[i + 1];
4003
- i += 2;
4004
- }
4005
- else {
4006
- i += 1;
4007
- }
4057
+ if ((i + 1) < src.length && !isIvKey(src[i + 1])) {
4058
+ ivObj[src[i]] = src[i + 1];
4059
+ i += 2;
4060
+ }
4061
+ else {
4062
+ i += 1;
4008
4063
  }
4009
4064
  }
4010
4065
  else {
@@ -4146,7 +4201,7 @@ export class WtHuatu {
4146
4201
  errors.push(`[comp port] Ray Deg expression '${parseRes.body.rayDeg}' cannot be resolved!`);
4147
4202
  }
4148
4203
  else {
4149
- newPort.rayDeg = deg;
4204
+ newPort.rayDeg = AngDeg.roundDeg(deg);
4150
4205
  }
4151
4206
  }
4152
4207
  if (parseRes.body.minHoldLen) {
@@ -45,6 +45,7 @@ export class HuatuDimMark {
45
45
  hasEndBar = true;
46
46
  hasStartArrow = true;
47
47
  hasEndArrow = true;
48
+ barLenEqual = false;
48
49
  cfgBar = {
49
50
  color: "currentColor",
50
51
  width: this.barWidth,
@@ -125,6 +126,8 @@ export class HuatuDimMark {
125
126
  this.hasStartArrow = false;
126
127
  if (!!config.noEndArrow)
127
128
  this.hasEndArrow = false;
129
+ if (!!config.barLenEqual)
130
+ this.barLenEqual = true;
128
131
  // If it is already Hori/Vert, then re-assign type accordingly
129
132
  if (this.isHori)
130
133
  this.type = "hori";
@@ -167,10 +170,12 @@ export class HuatuDimMark {
167
170
  yBarEnd = yFar + k * (this.gap + this.barLength);
168
171
  yMarkPos = yFar + k * (this.gap + this.barLength * this.linePos);
169
172
  if (this.hasStartBar) {
170
- this.barStart = PathLine.fromLineSeg(LineSeg.fromXYs(this.pStart.x, this.pStart.y + k * this.gap, this.pStart.x, yBarEnd));
173
+ let yBarStart = (this.barLenEqual ? yFar : this.pStart.y) + k * this.gap;
174
+ this.barStart = PathLine.fromLineSeg(LineSeg.fromXYs(this.pStart.x, yBarStart, this.pStart.x, yBarEnd));
171
175
  }
172
176
  if (this.hasEndBar) {
173
- this.barEnd = PathLine.fromLineSeg(LineSeg.fromXYs(this.pEnd.x, this.pEnd.y + k * this.gap, this.pEnd.x, yBarEnd));
177
+ let yBarStart = (this.barLenEqual ? yFar : this.pEnd.y) + k * this.gap;
178
+ this.barEnd = PathLine.fromLineSeg(LineSeg.fromXYs(this.pEnd.x, yBarStart, this.pEnd.x, yBarEnd));
174
179
  }
175
180
  lsMark = LineSeg.fromXYs(this.pStart.x, yMarkPos, this.pEnd.x, yMarkPos);
176
181
  pMidMarkLine = lsMark.middle;
@@ -194,10 +199,12 @@ export class HuatuDimMark {
194
199
  xBarEnd = xFar + k * (this.gap + this.barLength);
195
200
  xMarkPos = xFar + k * (this.gap + this.barLength * this.linePos);
196
201
  if (this.hasStartBar) {
197
- this.barStart = PathLine.fromLineSeg(LineSeg.fromXYs(this.pStart.x + k * this.gap, this.pStart.y, xBarEnd, this.pStart.y));
202
+ let xBarStart = (this.barLenEqual ? xFar : this.pStart.x) + k * this.gap;
203
+ this.barStart = PathLine.fromLineSeg(LineSeg.fromXYs(xBarStart, this.pStart.y, xBarEnd, this.pStart.y));
198
204
  }
199
205
  if (this.hasEndBar) {
200
- this.barEnd = PathLine.fromLineSeg(LineSeg.fromXYs(this.pEnd.x + k * this.gap, this.pEnd.y, xBarEnd, this.pEnd.y));
206
+ let xBarStart = (this.barLenEqual ? xFar : this.pEnd.x) + k * this.gap;
207
+ this.barEnd = PathLine.fromLineSeg(LineSeg.fromXYs(xBarStart, this.pEnd.y, xBarEnd, this.pEnd.y));
201
208
  }
202
209
  lsMark = LineSeg.fromXYs(xMarkPos, this.pStart.y, xMarkPos, this.pEnd.y);
203
210
  pMidMarkLine = lsMark.middle;
@@ -214,7 +221,7 @@ export class HuatuDimMark {
214
221
  if (this.hasEndArrow)
215
222
  this.arrowEnd = new PathPolyline(pEndLeft, lsMark.pEnd, pEndRight);
216
223
  }
217
- else if (this.arrowType === "solid") {
224
+ else if (this.arrowType === "solid" || this.arrowType === "empty") {
218
225
  if (this.hasStartArrow)
219
226
  this.arrowStart = new PathPolygon(pStartLeft, lsMark.pStart, pStartRight);
220
227
  if (this.hasEndArrow)
@@ -443,18 +450,22 @@ export class HuatuDimMark {
443
450
  };
444
451
  }
445
452
  }
446
- else if (this.arrowType === "solid") {
453
+ else if (this.arrowType === "solid" || this.arrowType === "empty") {
447
454
  this.cfgArrowFill.color = color || this.cfgLine.color;
448
455
  this.cfgArrowStroke.color = color || this.cfgLine.color;
449
456
  this.cfgArrowStroke.width = this.lineWidth;
450
457
  this.cfgArrowStroke.lineJoin = "round";
451
458
  if (this.arrowStart) {
452
459
  this.arrowStart.stroke = this.cfgArrowStroke;
453
- this.arrowStart.fill = this.cfgArrowFill;
460
+ this.arrowStart.fill = this.arrowType === "empty"
461
+ ? { color: "none" }
462
+ : this.cfgArrowFill;
454
463
  }
455
464
  if (this.arrowEnd) {
456
465
  this.arrowEnd.stroke = this.cfgArrowStroke;
457
- this.arrowEnd.fill = this.cfgArrowFill;
466
+ this.arrowEnd.fill = this.arrowType === "empty"
467
+ ? { color: "none" }
468
+ : this.cfgArrowFill;
458
469
  }
459
470
  }
460
471
  }
@@ -528,6 +539,7 @@ export class HuatuDimMark {
528
539
  ["noEndBar"],
529
540
  ["noStartArrow"],
530
541
  ["noEndArrow"],
542
+ ["barLenEqual"],
531
543
  ["barColor"],
532
544
  ["lineColor"],
533
545
  ["arrow"],
@@ -550,6 +562,7 @@ export class HuatuDimMark {
550
562
  booleans: [
551
563
  "noStartBar", "noEndBar",
552
564
  "noStartArrow", "noEndArrow",
565
+ "barLenEqual",
553
566
  "labelOnLine", "rotateLabel",
554
567
  "showLength"
555
568
  ],
package/huatu/HuatuJob.js CHANGED
@@ -13,6 +13,8 @@ import { WtHuatu } from "./Huatu.js";
13
13
  import { HuatuClipPath } from "./HuatuClipPath.js";
14
14
  import { buildCssHtmlTag } from "../tools/html.js";
15
15
  import { genHex } from "../tools/gen-id.js";
16
+ import { HuatuCompDrawing } from "./HuatuCompDrawing.js";
17
+ import { HuatuWireDrawing } from "../wire/HuatuWireDrawing.js";
16
18
  export class HuatuJob {
17
19
  huatu;
18
20
  name;
@@ -73,6 +75,11 @@ export class HuatuJob {
73
75
  });
74
76
  this.defines.push(element);
75
77
  }
78
+ if (element instanceof HuatuCompDrawing && element.placement.huatu && element.placement.huatu.draw) {
79
+ element.placement.huatu.draw.drawings.forEach(d => {
80
+ this.resolveDefineOfFinalDraw(d);
81
+ });
82
+ }
76
83
  }
77
84
  resolveDefineOfStyle(style) {
78
85
  if (style.fillPattern) {
@@ -160,6 +167,9 @@ export class HuatuJob {
160
167
  else if (draw instanceof HuatuLabel) {
161
168
  this.resolveDefineOfLabel(draw);
162
169
  }
170
+ else if (draw instanceof HuatuWireDrawing) {
171
+ draw.wire.getDrawings().forEach(d => this.resolveDefineOfFinalDraw(d));
172
+ }
163
173
  }
164
174
  // This function will resolve all the "defines" (including path(series) block, symbol, etc.) that this job used
165
175
  resolveDefines() {
@@ -172,8 +182,12 @@ export class HuatuJob {
172
182
  // Assign config
173
183
  globalThis.wtHuatuConfig = config;
174
184
  const printUnused = globalThis.wtHuatuConfig && globalThis.wtHuatuConfig.printUnusedModule;
185
+ // Clean Wire's Nets drawn status
186
+ this.huatu.resetNetTrunkDrawStatus();
175
187
  // Resolve Defines
176
188
  this.resolveDefines();
189
+ // Re-do the reset
190
+ this.huatu.resetNetTrunkDrawStatus();
177
191
  let svg = "";
178
192
  // Title
179
193
  if (this.huatu.title)
@@ -282,7 +282,7 @@ export class HuatuLabel {
282
282
  // It is like point rotating
283
283
  this.anchorX = Math.cos(rd) * ax - Math.sin(rd) * ay;
284
284
  this.anchorY = Math.sin(rd) * ax + Math.cos(rd) * ay;
285
- if (this.textAlign === "center" && ax === 0) {
285
+ if ((this.textAlign === "center" || !this.textAlign) && ax === 0) {
286
286
  // Note: this adjustment is to make sure that the originally centered text would align to
287
287
  // anchoring side
288
288
  if (WtMath.isEqual(this.anchorX, 1)) {