-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrawing.js
More file actions
1280 lines (1075 loc) · 44.1 KB
/
drawing.js
File metadata and controls
1280 lines (1075 loc) · 44.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Shutter Drawing Module
*
* Renders professional architectural-quality diagrams onto HTML canvas elements.
* Designed to match the Rockler Shutter Design Wizard PDF aesthetic.
*
* Exports: drawElevation, drawCrossSection (for wizard.js preview)
* drawFrontElevation, drawSideView, drawRailDetails, drawLouverDetails (for PDF)
*/
const ShutterDrawing = (() => {
// ── Color palette (Rockler PDF-inspired) ──────────────────────────────
const COLORS = {
woodFill: '#f0e4c8', // warm cream/tan wood fill
woodStroke: '#8b7355', // medium brown outline
louverFill: '#f5edd8', // slightly lighter cream for louvers
louverStroke: '#8b7355', // same brown for louver outlines
dimension: '#000000', // black for dimension text
dimLine: '#000000', // black for dimension lines
pin: '#000000', // black for pin holes (unfilled circles)
background: '#ffffff', // white background
detailCircle: '#000000', // black for zoom circle borders
arrow: '#000000', // black for arrows
};
// ── Dimension line helpers ──────────────────────────────────────────
/**
* Draw a horizontal dimension line with arrows/ticks and label.
* @param {CanvasRenderingContext2D} ctx
* @param {number} x1 - Start x
* @param {number} x2 - End x
* @param {number} y - Y position
* @param {string} label - Dimension text
* @param {string} side - 'above' or 'below' (label placement)
*/
function drawDimArrowH(ctx, x1, x2, y, label, side = 'above') {
ctx.save();
ctx.strokeStyle = COLORS.dimLine;
ctx.fillStyle = COLORS.dimension;
ctx.lineWidth = 1;
const arrowSize = 6;
const tickLen = 8;
// Main line
ctx.beginPath();
ctx.moveTo(x1, y);
ctx.lineTo(x2, y);
ctx.stroke();
// Left arrow/tick
ctx.beginPath();
ctx.moveTo(x1, y - tickLen / 2);
ctx.lineTo(x1, y + tickLen / 2);
ctx.stroke();
// Arrow head pointing left
ctx.beginPath();
ctx.moveTo(x1, y);
ctx.lineTo(x1 + arrowSize, y - arrowSize / 2);
ctx.lineTo(x1 + arrowSize, y + arrowSize / 2);
ctx.closePath();
ctx.fill();
// Right arrow/tick
ctx.beginPath();
ctx.moveTo(x2, y - tickLen / 2);
ctx.lineTo(x2, y + tickLen / 2);
ctx.stroke();
// Arrow head pointing right
ctx.beginPath();
ctx.moveTo(x2, y);
ctx.lineTo(x2 - arrowSize, y - arrowSize / 2);
ctx.lineTo(x2 - arrowSize, y + arrowSize / 2);
ctx.closePath();
ctx.fill();
// Label
ctx.font = 'bold 14px Arial, sans-serif';
ctx.textAlign = 'center';
ctx.textBaseline = side === 'above' ? 'bottom' : 'top';
const labelY = side === 'above' ? y - 6 : y + 6;
ctx.fillText(label, (x1 + x2) / 2, labelY);
ctx.restore();
}
/**
* Draw a vertical dimension line with arrows/ticks and label.
* @param {CanvasRenderingContext2D} ctx
* @param {number} y1 - Start y (top)
* @param {number} y2 - End y (bottom)
* @param {number} x - X position
* @param {string} label - Dimension text
* @param {string} side - 'left' or 'right' (label placement)
*/
function drawDimArrowV(ctx, y1, y2, x, label, side = 'left') {
ctx.save();
ctx.strokeStyle = COLORS.dimLine;
ctx.fillStyle = COLORS.dimension;
ctx.lineWidth = 1;
const arrowSize = 6;
const tickLen = 8;
// Main line
ctx.beginPath();
ctx.moveTo(x, y1);
ctx.lineTo(x, y2);
ctx.stroke();
// Top arrow/tick
ctx.beginPath();
ctx.moveTo(x - tickLen / 2, y1);
ctx.lineTo(x + tickLen / 2, y1);
ctx.stroke();
// Arrow head pointing up
ctx.beginPath();
ctx.moveTo(x, y1);
ctx.lineTo(x - arrowSize / 2, y1 + arrowSize);
ctx.lineTo(x + arrowSize / 2, y1 + arrowSize);
ctx.closePath();
ctx.fill();
// Bottom arrow/tick
ctx.beginPath();
ctx.moveTo(x - tickLen / 2, y2);
ctx.lineTo(x + tickLen / 2, y2);
ctx.stroke();
// Arrow head pointing down
ctx.beginPath();
ctx.moveTo(x, y2);
ctx.lineTo(x - arrowSize / 2, y2 - arrowSize);
ctx.lineTo(x + arrowSize / 2, y2 - arrowSize);
ctx.closePath();
ctx.fill();
// Label (rotated)
ctx.font = 'bold 14px Arial, sans-serif';
ctx.textAlign = 'center';
ctx.textBaseline = side === 'left' ? 'bottom' : 'top';
ctx.translate(x, (y1 + y2) / 2);
ctx.rotate(-Math.PI / 2);
const labelOffset = side === 'left' ? -8 : 8;
ctx.fillText(label, 0, labelOffset);
ctx.restore();
}
/**
* Draw a zoom/detail circle border.
*/
function drawZoomCircle(ctx, cx, cy, radius) {
ctx.save();
ctx.strokeStyle = COLORS.detailCircle;
ctx.lineWidth = 2;
ctx.beginPath();
ctx.arc(cx, cy, radius, 0, Math.PI * 2);
ctx.stroke();
ctx.restore();
}
/**
* Draw extension lines from element to dimension line.
*/
function drawExtensionLines(ctx, x1, y1, x2, y2) {
ctx.save();
ctx.strokeStyle = COLORS.dimLine;
ctx.lineWidth = 0.5;
ctx.setLineDash([4, 2]);
ctx.beginPath();
ctx.moveTo(x1, y1);
ctx.lineTo(x2, y2);
ctx.stroke();
ctx.restore();
}
/**
* Draw an arrow pointing in a direction with label.
*/
function drawLabelArrow(ctx, x, y, direction, label) {
ctx.save();
ctx.fillStyle = COLORS.arrow;
ctx.strokeStyle = COLORS.arrow;
ctx.lineWidth = 1.5;
const arrowLen = 30;
const arrowHead = 8;
let dx = 0, dy = 0;
if (direction === 'left') dx = -1;
else if (direction === 'right') dx = 1;
else if (direction === 'up') dy = -1;
else if (direction === 'down') dy = 1;
const endX = x + dx * arrowLen;
const endY = y + dy * arrowLen;
// Arrow line
ctx.beginPath();
ctx.moveTo(x, y);
ctx.lineTo(endX, endY);
ctx.stroke();
// Arrow head
ctx.beginPath();
if (dx !== 0) {
ctx.moveTo(endX, endY);
ctx.lineTo(endX - dx * arrowHead, endY - arrowHead / 2);
ctx.lineTo(endX - dx * arrowHead, endY + arrowHead / 2);
} else {
ctx.moveTo(endX, endY);
ctx.lineTo(endX - arrowHead / 2, endY - dy * arrowHead);
ctx.lineTo(endX + arrowHead / 2, endY - dy * arrowHead);
}
ctx.closePath();
ctx.fill();
// Label
ctx.font = 'bold 12px Arial, sans-serif';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
const labelX = x - dx * 20;
const labelY = y - dy * 20;
ctx.fillText(label, labelX, labelY);
ctx.restore();
}
// ── Front Elevation (for PDF - enhanced) ──────────────────────────────
/**
* Draw the front elevation of a single shutter panel (PDF quality).
* Canvas size: 1000x1400
*/
function drawFrontElevation(canvas, plan) {
const ctx = canvas.getContext('2d');
const geo = plan.geometry;
const cfg = plan.config;
const isMovable = cfg.louverType !== 'fixed';
// Clear canvas
ctx.fillStyle = COLORS.background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Margins for dimension lines
const margin = { top: 120, bottom: 120, left: 150, right: 180 };
const availW = canvas.width - margin.left - margin.right;
const availH = canvas.height - margin.top - margin.bottom;
// Scale to fit
const scaleX = availW / cfg.panelWidth;
const scaleY = availH / cfg.panelHeight;
const scale = Math.min(scaleX, scaleY);
const drawW = cfg.panelWidth * scale;
const drawH = cfg.panelHeight * scale;
const ox = margin.left + (availW - drawW) / 2; // origin x
const oy = margin.top + (availH - drawH) / 2; // origin y
// Helper: draw a filled rect in panel coords
function panelRect(x, y, w, h, fillColor, strokeColor) {
ctx.fillStyle = fillColor;
ctx.strokeStyle = strokeColor;
ctx.lineWidth = 2;
ctx.fillRect(ox + x * scale, oy + y * scale, w * scale, h * scale);
ctx.strokeRect(ox + x * scale, oy + y * scale, w * scale, h * scale);
}
// Draw stiles (left and right)
panelRect(0, 0, geo.stileWidth, cfg.panelHeight, COLORS.woodFill, COLORS.woodStroke);
panelRect(cfg.panelWidth - geo.stileWidth, 0, geo.stileWidth, cfg.panelHeight, COLORS.woodFill, COLORS.woodStroke);
// Draw top rail
panelRect(geo.stileWidth, 0, cfg.panelWidth - 2 * geo.stileWidth, geo.topRailHeight, COLORS.woodFill, COLORS.woodStroke);
// Draw bottom rail
panelRect(geo.stileWidth, cfg.panelHeight - geo.bottomRailHeight, cfg.panelWidth - 2 * geo.stileWidth, geo.bottomRailHeight, COLORS.woodFill, COLORS.woodStroke);
// Draw middle rail if present
if (geo.middleRail) {
const topSectionEnd = geo.topClearance + (geo.topSectionLouvers - 1) * geo.louverSpacing;
const mrY = topSectionEnd + geo.louverSpacing / 2;
panelRect(geo.stileWidth, mrY, cfg.panelWidth - 2 * geo.stileWidth, geo.middleRail.width, COLORS.woodFill, COLORS.woodStroke);
}
// Draw louvers as clean horizontal lines (like Rockler PDFs)
ctx.strokeStyle = COLORS.woodStroke;
ctx.lineWidth = 1.5;
const louverX = geo.stileWidth;
const louverEndX = cfg.panelWidth - geo.stileWidth;
for (let i = 0; i < geo.pinPositions.length; i++) {
const pinY = geo.pinPositions[i];
ctx.beginPath();
ctx.moveTo(ox + louverX * scale, oy + pinY * scale);
ctx.lineTo(ox + louverEndX * scale, oy + pinY * scale);
ctx.stroke();
// Pin holes as small unfilled circles
ctx.strokeStyle = COLORS.pin;
ctx.lineWidth = 1;
const pinR = 3;
// Left pin
ctx.beginPath();
ctx.arc(ox + louverX * scale, oy + pinY * scale, pinR, 0, Math.PI * 2);
ctx.stroke();
// Right pin
ctx.beginPath();
ctx.arc(ox + louverEndX * scale, oy + pinY * scale, pinR, 0, Math.PI * 2);
ctx.stroke();
ctx.strokeStyle = COLORS.woodStroke;
ctx.lineWidth = 1.5;
}
// ── Dimension lines ──
// Panel width (top)
const dimTopY = oy - 50;
drawExtensionLines(ctx, ox, oy, ox, dimTopY + 5);
drawExtensionLines(ctx, ox + drawW, oy, ox + drawW, dimTopY + 5);
drawDimArrowH(ctx, ox, ox + drawW, dimTopY, ShutterCalc.frac(cfg.panelWidth), 'above');
// Rail length (below panel width)
const railDimY = oy - 25;
const railStartX = ox + geo.stileWidth * scale;
const railEndX = ox + (cfg.panelWidth - geo.stileWidth) * scale;
drawDimArrowH(ctx, railStartX, railEndX, railDimY, ShutterCalc.frac(geo.railLength), 'below');
// Panel height (left side)
const dimLeftX = ox - 50;
drawExtensionLines(ctx, ox, oy, dimLeftX + 5, oy);
drawExtensionLines(ctx, ox, oy + drawH, dimLeftX + 5, oy + drawH);
drawDimArrowV(ctx, oy, oy + drawH, dimLeftX, ShutterCalc.frac(cfg.panelHeight), 'left');
// Top rail height (right side, top)
const dimRightX = ox + drawW + 40;
const topRailEndY = oy + geo.topRailHeight * scale;
drawExtensionLines(ctx, ox + drawW, oy, dimRightX - 5, oy);
drawExtensionLines(ctx, ox + drawW, topRailEndY, dimRightX - 5, topRailEndY);
drawDimArrowV(ctx, oy, topRailEndY, dimRightX, ShutterCalc.frac(geo.topRailHeight), 'right');
// "FULL WIDTH" label for top rail
ctx.save();
ctx.font = '11px Arial, sans-serif';
ctx.fillStyle = COLORS.dimension;
ctx.textAlign = 'left';
ctx.fillText('FULL WIDTH', dimRightX + 15, (oy + topRailEndY) / 2 + 4);
ctx.restore();
// For movable: show front-face rail height
if (isMovable && geo.rabbetDepth) {
const frontFaceHeight = geo.topRailHeight - geo.rabbetDepth;
ctx.save();
ctx.font = '10px Arial, sans-serif';
ctx.fillStyle = COLORS.dimension;
ctx.textAlign = 'left';
ctx.fillText(`(${ShutterCalc.frac(frontFaceHeight)} front face)`, dimRightX + 15, (oy + topRailEndY) / 2 + 18);
ctx.restore();
}
// Bottom rail height (right side, bottom)
const bottomRailStartY = oy + (cfg.panelHeight - geo.bottomRailHeight) * scale;
const bottomRailEndY = oy + drawH;
drawExtensionLines(ctx, ox + drawW, bottomRailStartY, dimRightX - 5, bottomRailStartY);
drawExtensionLines(ctx, ox + drawW, bottomRailEndY, dimRightX - 5, bottomRailEndY);
drawDimArrowV(ctx, bottomRailStartY, bottomRailEndY, dimRightX, ShutterCalc.frac(geo.bottomRailHeight), 'right');
// "FULL WIDTH" label for bottom rail
ctx.save();
ctx.font = '11px Arial, sans-serif';
ctx.fillStyle = COLORS.dimension;
ctx.textAlign = 'left';
ctx.fillText('FULL WIDTH', dimRightX + 15, (bottomRailStartY + bottomRailEndY) / 2 + 4);
ctx.restore();
// For movable: show front-face rail height
if (isMovable && geo.rabbetDepth) {
const frontFaceHeight = geo.bottomRailHeight - geo.rabbetDepth;
ctx.save();
ctx.font = '10px Arial, sans-serif';
ctx.fillStyle = COLORS.dimension;
ctx.textAlign = 'left';
ctx.fillText(`(${ShutterCalc.frac(frontFaceHeight)} front face)`, dimRightX + 15, (bottomRailStartY + bottomRailEndY) / 2 + 18);
ctx.restore();
}
// Stile width (bottom)
const stileWidthY = oy + drawH + 30;
const stileEndX = ox + geo.stileWidth * scale;
drawExtensionLines(ctx, ox, oy + drawH, ox, stileWidthY - 5);
drawExtensionLines(ctx, stileEndX, oy + drawH, stileEndX, stileWidthY - 5);
drawDimArrowH(ctx, ox, stileEndX, stileWidthY, ShutterCalc.frac(geo.stileWidth), 'below');
// Louver count (left side, mid-panel)
const louverCountX = ox - 100;
const firstPinY = oy + geo.pinPositions[0] * scale;
const lastPinY = oy + geo.pinPositions[geo.pinPositions.length - 1] * scale;
ctx.save();
ctx.font = 'bold 14px Arial, sans-serif';
ctx.fillStyle = COLORS.dimension;
ctx.textAlign = 'center';
ctx.translate(louverCountX, (firstPinY + lastPinY) / 2);
ctx.rotate(-Math.PI / 2);
ctx.fillText(`${geo.numLouvers} LOUVERS`, 0, 0);
ctx.restore();
// Top clearance dimension (left, from top of stile to first louver)
const topClearDimX = ox - 25;
drawDimArrowV(ctx, oy, firstPinY, topClearDimX, ShutterCalc.frac(geo.topClearance), 'left');
// Bottom clearance dimension (left, from last louver to bottom of stile)
drawDimArrowV(ctx, lastPinY, oy + drawH, topClearDimX, ShutterCalc.frac(geo.bottomClearance), 'left');
// Louver spacing (right side, between first two louvers if >1 louver)
if (geo.pinPositions.length >= 2) {
const spacing1Y = oy + geo.pinPositions[0] * scale;
const spacing2Y = oy + geo.pinPositions[1] * scale;
const spacingDimX = ox + drawW + 100;
drawDimArrowV(ctx, spacing1Y, spacing2Y, spacingDimX, ShutterCalc.frac(geo.louverSpacing), 'right');
ctx.save();
ctx.font = '10px Arial, sans-serif';
ctx.fillStyle = COLORS.dimension;
ctx.textAlign = 'left';
ctx.fillText('SPACING', spacingDimX + 15, (spacing1Y + spacing2Y) / 2 + 4);
ctx.restore();
}
// "FRONT VIEW" label centered below
ctx.save();
ctx.font = 'bold 18px Arial, sans-serif';
ctx.fillStyle = COLORS.dimension;
ctx.textAlign = 'center';
ctx.fillText('FRONT VIEW', canvas.width / 2, oy + drawH + 80);
ctx.restore();
}
// ── Side View (for PDF page 3) ──────────────────────────────────────
/**
* Draw the side/cross-section view of a shutter panel (PDF quality).
* Shows the stile from the side with louvers protruding at angles.
* Canvas size: 400x1400
*/
function drawSideView(canvas, plan) {
const ctx = canvas.getContext('2d');
const geo = plan.geometry;
const cfg = plan.config;
// Clear canvas
ctx.fillStyle = COLORS.background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Margins
const margin = { top: 100, bottom: 100, left: 80, right: 100 };
const availH = canvas.height - margin.top - margin.bottom;
// Scale to fit height
const scale = availH / cfg.panelHeight;
const drawH = cfg.panelHeight * scale;
const ox = canvas.width / 2; // center horizontally
const oy = margin.top;
// Stile dimensions
const stileThickness = cfg.stockThickness * scale;
const stileWidth = stileThickness; // Side view shows thickness
// Draw stile as tall narrow rectangle
ctx.fillStyle = COLORS.woodFill;
ctx.strokeStyle = COLORS.woodStroke;
ctx.lineWidth = 2;
ctx.fillRect(ox - stileWidth / 2, oy, stileWidth, drawH);
ctx.strokeRect(ox - stileWidth / 2, oy, stileWidth, drawH);
// Draw louvers protruding at slight angles
const louverLen = geo.louverWidth * scale * 1.5; // Visual length for side view
const louverThick = geo.louverThickness * scale * 2; // Visual thickness
ctx.fillStyle = COLORS.louverFill;
ctx.strokeStyle = COLORS.louverStroke;
ctx.lineWidth = 1.5;
for (let i = 0; i < geo.pinPositions.length; i++) {
const pinY = oy + geo.pinPositions[i] * scale;
// Draw louver at ~20 degree angle (tilted toward front)
ctx.save();
ctx.translate(ox - stileWidth / 2, pinY);
ctx.rotate(-Math.PI / 9); // ~20 degrees
ctx.beginPath();
ctx.moveTo(0, -louverThick / 2);
ctx.lineTo(-louverLen, -louverThick / 2);
ctx.lineTo(-louverLen, louverThick / 2);
ctx.lineTo(0, louverThick / 2);
ctx.closePath();
ctx.fill();
ctx.stroke();
ctx.restore();
}
// Stock thickness dimension at top
const thickDimY = oy - 30;
drawDimArrowH(ctx, ox - stileWidth / 2, ox + stileWidth / 2, thickDimY, ShutterCalc.frac(cfg.stockThickness), 'above');
// Louver spacing dimension (right side)
if (geo.pinPositions.length >= 2) {
const y1 = oy + geo.pinPositions[0] * scale;
const y2 = oy + geo.pinPositions[1] * scale;
const spacingX = ox + stileWidth / 2 + 40;
drawDimArrowV(ctx, y1, y2, spacingX, ShutterCalc.frac(geo.louverSpacing), 'right');
}
// "FRONT" label with arrow pointing to front face
const frontX = ox - stileWidth / 2 - 50;
const frontY = oy + drawH / 3;
drawLabelArrow(ctx, frontX, frontY, 'right', 'FRONT');
// "SIDE VIEW (CROSS SECTION)" label at bottom
ctx.save();
ctx.font = 'bold 14px Arial, sans-serif';
ctx.fillStyle = COLORS.dimension;
ctx.textAlign = 'center';
ctx.fillText('SIDE VIEW', canvas.width / 2, oy + drawH + 50);
ctx.fillText('(CROSS SECTION)', canvas.width / 2, oy + drawH + 68);
ctx.restore();
}
// ── Rail Detail Circles (for PDF page 3) ────────────────────────────
/**
* Draw a zoomed detail circle showing rail-to-stile connection.
* @param {HTMLCanvasElement} canvas - Canvas element
* @param {Object} plan - Plan object
* @param {string} which - 'top' or 'bottom'
* Canvas size: 500x500
*/
function drawRailDetails(canvas, plan, which) {
const ctx = canvas.getContext('2d');
const geo = plan.geometry;
const cfg = plan.config;
const isMovable = cfg.louverType !== 'fixed';
// Clear canvas
ctx.fillStyle = COLORS.background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
const cx = canvas.width / 2;
const cy = canvas.height / 2;
const radius = Math.min(canvas.width, canvas.height) / 2 - 30;
// Draw zoom circle
drawZoomCircle(ctx, cx, cy, radius);
// Clip to circle for inner drawing
ctx.save();
ctx.beginPath();
ctx.arc(cx, cy, radius - 2, 0, Math.PI * 2);
ctx.clip();
// Scale for detail view
const detailScale = 40; // pixels per inch
// Rail dimensions
const railHeight = which === 'top' ? geo.topRailHeight : geo.bottomRailHeight;
const railFrontFace = railHeight - (isMovable ? geo.rabbetDepth : 0);
// Draw stile (vertical bar on right side)
const stileW = cfg.stockThickness * detailScale;
const stileH = radius * 1.5;
const stileX = cx + 30;
const stileY = cy - stileH / 2;
ctx.fillStyle = COLORS.woodFill;
ctx.strokeStyle = COLORS.woodStroke;
ctx.lineWidth = 2;
ctx.fillRect(stileX, stileY, stileW, stileH);
ctx.strokeRect(stileX, stileY, stileW, stileH);
// Draw rail (horizontal bar from left, butting against stile)
const railW = radius;
const railH = railHeight * detailScale;
const railX = cx - radius + 40;
const railY = cy - railH / 2;
ctx.fillStyle = COLORS.woodFill;
ctx.strokeStyle = COLORS.woodStroke;
ctx.lineWidth = 2;
ctx.fillRect(railX, railY, railW, railH);
ctx.strokeRect(railX, railY, railW, railH);
// Draw rabbet step (if movable)
if (isMovable && geo.rabbetDepth > 0) {
const rabbetH = geo.rabbetDepth * detailScale;
const rabbetY = which === 'top' ? railY + railH - rabbetH : railY;
ctx.fillStyle = COLORS.background;
ctx.fillRect(railX + railW - 20, rabbetY, 20, rabbetH);
ctx.strokeStyle = COLORS.woodStroke;
ctx.lineWidth = 1;
ctx.strokeRect(railX + railW - 20, rabbetY, 20, rabbetH);
}
// Pin hole
const pinY = cy;
const pinX = stileX + stileW / 2;
ctx.strokeStyle = COLORS.pin;
ctx.lineWidth = 1.5;
ctx.beginPath();
ctx.arc(pinX, pinY, 4, 0, Math.PI * 2);
ctx.stroke();
ctx.restore(); // Remove clip
// Dimension labels outside circle
// Full rail width dimension
const fullWidthDimY = cy + radius + 25;
ctx.save();
ctx.font = '12px Arial, sans-serif';
ctx.fillStyle = COLORS.dimension;
ctx.textAlign = 'center';
ctx.fillText(`Full Width: ${ShutterCalc.frac(railHeight)}`, cx, fullWidthDimY);
ctx.restore();
// Front face dimension (if movable)
if (isMovable && geo.rabbetDepth > 0) {
ctx.save();
ctx.font = '11px Arial, sans-serif';
ctx.fillStyle = COLORS.dimension;
ctx.textAlign = 'center';
ctx.fillText(`Front Face: ${ShutterCalc.frac(railFrontFace)}`, cx, fullWidthDimY + 16);
ctx.fillText(`Rabbet: ${ShutterCalc.frac(geo.rabbetDepth)}`, cx, fullWidthDimY + 32);
ctx.restore();
}
// Rail label
ctx.save();
ctx.font = 'bold 14px Arial, sans-serif';
ctx.fillStyle = COLORS.dimension;
ctx.textAlign = 'center';
ctx.fillText(which === 'top' ? 'TOP RAIL' : 'BOTTOM RAIL', cx, cy - radius - 15);
ctx.restore();
// "FRONT" label with arrow
drawLabelArrow(ctx, cx - radius + 20, cy - radius + 50, 'down', 'FRONT');
}
// ── Louver Details (for PDF page 4) ─────────────────────────────────
/**
* Draw composite louver detail page with multiple views.
* Canvas size: 1000x1400
*/
function drawLouverDetails(canvas, plan) {
const ctx = canvas.getContext('2d');
const geo = plan.geometry;
const cfg = plan.config;
const isMovable = cfg.louverType !== 'fixed';
// Clear canvas
ctx.fillStyle = COLORS.background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
// ── Section 1: Louver top view (full length) ──
// Upper area of canvas
const topViewY = 100;
const topViewCenterX = canvas.width / 2;
// Scale for louver length to fit
const louverScale = Math.min(700 / geo.louverLength, 30);
const louverDrawLen = geo.louverLength * louverScale;
const louverDrawW = geo.louverWidth * louverScale;
// Draw louver as elongated rectangle (top view)
ctx.fillStyle = COLORS.louverFill;
ctx.strokeStyle = COLORS.louverStroke;
ctx.lineWidth = 2;
ctx.fillRect(topViewCenterX - louverDrawLen / 2, topViewY, louverDrawLen, louverDrawW);
ctx.strokeRect(topViewCenterX - louverDrawLen / 2, topViewY, louverDrawLen, louverDrawW);
// Pin holes at ends
ctx.strokeStyle = COLORS.pin;
ctx.lineWidth = 1.5;
const pinOffset = 15;
// Left pin
ctx.beginPath();
ctx.arc(topViewCenterX - louverDrawLen / 2 + pinOffset, topViewY + louverDrawW / 2, 4, 0, Math.PI * 2);
ctx.stroke();
// Right pin
ctx.beginPath();
ctx.arc(topViewCenterX + louverDrawLen / 2 - pinOffset, topViewY + louverDrawW / 2, 4, 0, Math.PI * 2);
ctx.stroke();
// Length dimension
const lenDimY = topViewY - 25;
drawDimArrowH(ctx, topViewCenterX - louverDrawLen / 2, topViewCenterX + louverDrawLen / 2, lenDimY, ShutterCalc.frac(geo.louverLength), 'above');
// "LOUVER - TOP VIEW" label
ctx.save();
ctx.font = 'bold 14px Arial, sans-serif';
ctx.fillStyle = COLORS.dimension;
ctx.textAlign = 'center';
ctx.fillText('LOUVER - TOP VIEW', topViewCenterX, topViewY + louverDrawW + 30);
ctx.restore();
// ── Section 2: Louver profile (end view cross-section) ──
// Right side of canvas
const profileX = canvas.width - 180;
const profileY = 350;
const profileScale = 60; // pixels per inch
const profileW = geo.louverWidth * profileScale;
const profileH = geo.louverThickness * profileScale;
// Draw louver profile (elliptical/rounded ends)
ctx.fillStyle = COLORS.louverFill;
ctx.strokeStyle = COLORS.louverStroke;
ctx.lineWidth = 2;
ctx.beginPath();
ctx.ellipse(profileX, profileY, profileW / 2, profileH / 2, 0, 0, Math.PI * 2);
ctx.fill();
ctx.stroke();
// Pin hole in center
ctx.strokeStyle = COLORS.pin;
ctx.lineWidth = 1.5;
ctx.beginPath();
ctx.arc(profileX, profileY, 3, 0, Math.PI * 2);
ctx.stroke();
// Width dimension
drawDimArrowH(ctx, profileX - profileW / 2, profileX + profileW / 2, profileY + profileH / 2 + 25, ShutterCalc.frac(geo.louverWidth), 'below');
// Thickness dimension
drawDimArrowV(ctx, profileY - profileH / 2, profileY + profileH / 2, profileX + profileW / 2 + 25, ShutterCalc.frac(geo.louverThickness), 'right');
// "END VIEW" label
ctx.save();
ctx.font = 'bold 12px Arial, sans-serif';
ctx.fillStyle = COLORS.dimension;
ctx.textAlign = 'center';
ctx.fillText('END VIEW', profileX, profileY + profileH / 2 + 60);
ctx.restore();
// ── Section 3: Top view detail - stile/rail joint ──
// Lower-left area
const jointX = 180;
const jointY = 550;
const jointScale = 35;
// Draw stile (horizontal in top view)
const jStileW = geo.stileWidth * jointScale;
const jStileH = cfg.stockThickness * jointScale;
ctx.fillStyle = COLORS.woodFill;
ctx.strokeStyle = COLORS.woodStroke;
ctx.lineWidth = 2;
ctx.fillRect(jointX - jStileW / 2, jointY - jStileH / 2, jStileW, jStileH * 2);
ctx.strokeRect(jointX - jStileW / 2, jointY - jStileH / 2, jStileW, jStileH * 2);
// Draw rail butting against stile
const jRailW = 100;
ctx.fillRect(jointX + jStileW / 2, jointY - jStileH / 2, jRailW, jStileH);
ctx.strokeRect(jointX + jStileW / 2, jointY - jStileH / 2, jRailW, jStileH);
// Stock thickness dimension
drawDimArrowV(ctx, jointY - jStileH / 2, jointY + jStileH / 2, jointX - jStileW / 2 - 30, ShutterCalc.frac(cfg.stockThickness), 'left');
// "TOP VIEW - JOINT" label
ctx.save();
ctx.font = 'bold 12px Arial, sans-serif';
ctx.fillStyle = COLORS.dimension;
ctx.textAlign = 'center';
ctx.fillText('TOP VIEW - STILE/RAIL JOINT', jointX + 50, jointY + jStileH + 40);
ctx.restore();
// ── Section 4: Stile jig alignment detail ──
// Lower-right area with zoom circle
const jigCx = canvas.width - 250;
const jigCy = 700;
const jigRadius = 120;
drawZoomCircle(ctx, jigCx, jigCy, jigRadius);
// Draw stile inside circle
ctx.save();
ctx.beginPath();
ctx.arc(jigCx, jigCy, jigRadius - 2, 0, Math.PI * 2);
ctx.clip();
const jigScale = 25;
const jigStileW = geo.stileWidth * jigScale;
const jigStileH = jigRadius * 1.5;
ctx.fillStyle = COLORS.woodFill;
ctx.strokeStyle = COLORS.woodStroke;
ctx.lineWidth = 2;
ctx.fillRect(jigCx - jigStileW / 2, jigCy - jigStileH / 2, jigStileW, jigStileH);
ctx.strokeRect(jigCx - jigStileW / 2, jigCy - jigStileH / 2, jigStileW, jigStileH);
// First pin hole
const firstPinY = jigCy - jigStileH / 2 + geo.topClearance * jigScale * 0.5;
ctx.strokeStyle = COLORS.pin;
ctx.lineWidth = 1.5;
ctx.beginPath();
ctx.arc(jigCx, firstPinY, 4, 0, Math.PI * 2);
ctx.stroke();
ctx.restore();
// First pin clearance dimension
ctx.save();
ctx.font = '11px Arial, sans-serif';
ctx.fillStyle = COLORS.dimension;
ctx.textAlign = 'center';
ctx.fillText(`First pin: ${ShutterCalc.frac(geo.topClearance)} from top`, jigCx, jigCy + jigRadius + 25);
ctx.restore();
// "STILE JIG ALIGNMENT" label
ctx.save();
ctx.font = 'bold 12px Arial, sans-serif';
ctx.fillStyle = COLORS.dimension;
ctx.textAlign = 'center';
ctx.fillText('STILE JIG ALIGNMENT', jigCx, jigCy - jigRadius - 15);
ctx.restore();
// ── Section 5: Control arm (for movable types) ──
if (isMovable && geo.controlArmLength) {
const armY = 950;
const armCenterX = canvas.width / 2;
const armScale = Math.min(600 / geo.controlArmLength, 25);
const armDrawLen = geo.controlArmLength * armScale;
const armDrawW = 12;
// Draw control arm
ctx.fillStyle = '#c0a080';
ctx.strokeStyle = COLORS.woodStroke;
ctx.lineWidth = 2;
ctx.fillRect(armCenterX - armDrawLen / 2, armY, armDrawLen, armDrawW);
ctx.strokeRect(armCenterX - armDrawLen / 2, armY, armDrawLen, armDrawW);
// Clip positions (small rectangles along arm)
const clipSpacing = geo.louverSpacing * armScale;
const numClips = Math.floor(armDrawLen / clipSpacing);
ctx.fillStyle = '#888888';
for (let i = 0; i <= numClips; i++) {
const clipX = armCenterX - armDrawLen / 2 + i * clipSpacing + 5;
if (clipX < armCenterX + armDrawLen / 2 - 10) {
ctx.fillRect(clipX, armY + armDrawW - 4, 8, 4);
}
}
// Length dimension
drawDimArrowH(ctx, armCenterX - armDrawLen / 2, armCenterX + armDrawLen / 2, armY - 25, ShutterCalc.frac(geo.controlArmLength), 'above');
// Label
ctx.save();
ctx.font = 'bold 12px Arial, sans-serif';
ctx.fillStyle = COLORS.dimension;
ctx.textAlign = 'center';
const armTypeLabel = cfg.louverType === 'movable-hidden' ? 'HIDDEN CONTROL ARM' : 'FRONT CONTROL ARM';
ctx.fillText(armTypeLabel, armCenterX, armY + armDrawW + 30);
ctx.restore();
// Overhang note
if (geo.controlArmOverhang) {
ctx.save();
ctx.font = '11px Arial, sans-serif';
ctx.fillStyle = COLORS.dimension;
ctx.textAlign = 'center';
ctx.fillText(`(includes ${ShutterCalc.frac(geo.controlArmOverhang)} overhang)`, armCenterX, armY + armDrawW + 48);
ctx.restore();
}
}
// ── Section 6: Mouse hole dimensions (for front arm types) ──
if (cfg.louverType === 'movable-front' && geo.mouseHole) {
const mhX = 180;
const mhY = 850;
const mhScale = 50;
// Draw stile section with mouse hole
const mhStileW = 80;
const mhStileH = 100;
ctx.fillStyle = COLORS.woodFill;
ctx.strokeStyle = COLORS.woodStroke;
ctx.lineWidth = 2;
ctx.fillRect(mhX - mhStileW / 2, mhY, mhStileW, mhStileH);
ctx.strokeRect(mhX - mhStileW / 2, mhY, mhStileW, mhStileH);
// Mouse hole cutout
const holeW = geo.mouseHole.length * mhScale;
const holeH = geo.mouseHole.width * mhScale;
ctx.fillStyle = COLORS.background;
ctx.fillRect(mhX - holeW / 2, mhY + 20, holeW, holeH);
ctx.strokeRect(mhX - holeW / 2, mhY + 20, holeW, holeH);
// Mouse hole dimensions label
ctx.save();
ctx.font = '11px Arial, sans-serif';
ctx.fillStyle = COLORS.dimension;
ctx.textAlign = 'center';
ctx.fillText('MOUSE HOLE', mhX, mhY + mhStileH + 25);
ctx.fillText(`${ShutterCalc.frac(geo.mouseHole.length)}L x ${ShutterCalc.frac(geo.mouseHole.width)}W x ${ShutterCalc.frac(geo.mouseHole.depth)}D`, mhX, mhY + mhStileH + 42);
ctx.restore();
}
// ── Page title ──
ctx.save();
ctx.font = 'bold 20px Arial, sans-serif';
ctx.fillStyle = COLORS.dimension;
ctx.textAlign = 'center';
ctx.fillText('LOUVER & ASSEMBLY DETAILS', canvas.width / 2, 50);
ctx.restore();
}
// ── Original drawElevation (for wizard.js preview - smaller canvas) ──
/**
* Draw the front elevation of a single shutter panel (preview size).
* This is the original function signature for wizard.js compatibility.
*/
function drawElevation(canvas, plan) {
const ctx = canvas.getContext('2d');
const geo = plan.geometry;
const cfg = plan.config;
// Compute scale to fit canvas with margins
const margin = { top: 50, bottom: 60, left: 80, right: 80 };
const availW = canvas.width - margin.left - margin.right;
const availH = canvas.height - margin.top - margin.bottom;
const scaleX = availW / cfg.panelWidth;
const scaleY = availH / cfg.panelHeight;
const scale = Math.min(scaleX, scaleY);
const drawW = cfg.panelWidth * scale;
const drawH = cfg.panelHeight * scale;
const ox = margin.left + (availW - drawW) / 2; // origin x
const oy = margin.top + (availH - drawH) / 2; // origin y
// Clear
ctx.fillStyle = COLORS.background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Title
ctx.fillStyle = COLORS.dimension;
ctx.font = 'bold 14px sans-serif';
ctx.textAlign = 'center';
ctx.fillText('Front Elevation (not to scale)', canvas.width / 2, 20);
// Helper: draw a filled rect in panel coords
function panelRect(x, y, w, h, fillColor, strokeColor) {
ctx.fillStyle = fillColor;
ctx.strokeStyle = strokeColor;
ctx.lineWidth = 1;
ctx.fillRect(ox + x * scale, oy + y * scale, w * scale, h * scale);
ctx.strokeRect(ox + x * scale, oy + y * scale, w * scale, h * scale);
}
// Draw stiles
panelRect(0, 0, geo.stileWidth, cfg.panelHeight, COLORS.woodFill, COLORS.woodStroke);
panelRect(cfg.panelWidth - geo.stileWidth, 0, geo.stileWidth, cfg.panelHeight, COLORS.woodFill, COLORS.woodStroke);
// Draw top rail
panelRect(geo.stileWidth, 0, cfg.panelWidth - 2 * geo.stileWidth, geo.topRailHeight, COLORS.woodFill, COLORS.woodStroke);
// Draw bottom rail
panelRect(geo.stileWidth, cfg.panelHeight - geo.bottomRailHeight, cfg.panelWidth - 2 * geo.stileWidth, geo.bottomRailHeight, COLORS.woodFill, COLORS.woodStroke);
// Draw middle rail if present
if (geo.middleRail) {
const topSectionEnd = geo.topClearance + (geo.topSectionLouvers - 1) * geo.louverSpacing;
const mrY = topSectionEnd + geo.louverSpacing / 2;
panelRect(geo.stileWidth, mrY, cfg.panelWidth - 2 * geo.stileWidth, geo.middleRail.width, COLORS.woodFill, COLORS.woodStroke);
// Label
ctx.fillStyle = COLORS.dimension;
ctx.font = '10px sans-serif';
ctx.textAlign = 'center';
ctx.fillText('Middle Rail', ox + drawW / 2, oy + (mrY + geo.middleRail.width / 2) * scale + 3);
}
// Draw louvers as clean horizontal lines
const louverX = geo.stileWidth;
const louverEndX = cfg.panelWidth - geo.stileWidth;
ctx.strokeStyle = COLORS.louverStroke;
ctx.lineWidth = 1;