File size: 103,616 Bytes
985c397
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
/***************************************************************************
 *   Copyright (c) 2021 edi                                                *
 *                                                                         *
 *   This file is part of the FreeCAD CAx development system.              *
 *                                                                         *
 *   This library is free software; you can redistribute it and/or         *
 *   modify it under the terms of the GNU Library General Public           *
 *   License as published by the Free Software Foundation; either          *
 *   version 2 of the License, or (at your option) any later version.      *
 *                                                                         *
 *   This library  is distributed in the hope that it will be useful,      *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU Library General Public License for more details.                  *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this library; see the file COPYING.LIB. If not,    *
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
 *   Suite 330, Boston, MA  02111-1307, USA                                *
 *                                                                         *
 ***************************************************************************/

# include <QApplication>
# include <QMessageBox>
# include <cmath>
# include <sstream>
# include <BRepGProp.hxx>
# include <GProp_GProps.hxx>


# include <App/Document.h>
# include <App/DocumentObject.h>
# include <Base/Console.h>
# include <Base/Type.h>
# include <Base/Tools.h>
# include <Gui/Action.h>
# include <Gui/Application.h>
# include <Gui/BitmapFactory.h>
# include <Gui/Command.h>
# include <Gui/Control.h>
# include <Gui/MainWindow.h>
# include <Gui/Selection/Selection.h>
# include <Gui/Selection/SelectionObject.h>

# include <Mod/TechDraw/App/Cosmetic.h>
# include <Mod/TechDraw/App/DrawViewBalloon.h>
# include <Mod/TechDraw/App/DrawViewDimension.h>
# include <Mod/TechDraw/App/DrawPage.h>
# include <Mod/TechDraw/App/DrawUtil.h>
# include <Mod/TechDraw/App/DrawViewPart.h>
# include <Mod/TechDraw/App/Preferences.h>
# include <Mod/TechDraw/App/LineGroup.h>

#include "DlgTemplateField.h"
#include "DrawGuiUtil.h"
#include "TaskCustomizeFormat.h"
#include "TaskSelectLineAttributes.h"
#include "CommandExtensionDims.h"


using namespace TechDrawGui;
using namespace TechDraw;

namespace TechDrawGui {
    //internal structures and sort functions
    struct dimVertex {
        // save a dimension defining vertex and its point
        std::string name;
        Base::Vector3d point;
    };

    struct {
        bool operator()(dimVertex a, dimVertex b) const { return a.point.x < b.point.x; }
    } sortX;

    struct {
        bool operator()(dimVertex a, dimVertex b) const { return a.point.y < b.point.y; }
    } sortY;

    //internal helper functions
    void _selectDimensionAttributes(Gui::Command* cmd);
    std::vector<TechDraw::DrawViewDimension*>_getDimensions(std::vector<Gui::SelectionObject> selection, std::string needDimType);
    std::vector<dimVertex> _getVertexInfo(TechDraw::DrawViewPart* objFeat,
        std::vector<std::string> subNames);
    TechDraw::DrawViewDimension* _createLinDimension(
        TechDraw::DrawViewPart* objFeat,
        std::string startVertex,
        std::string endVertex,
        std::string dimType);
    bool _checkSelection(Gui::Command* cmd,
        std::vector<Gui::SelectionObject>& selection,
        std::string message);
    bool _checkSelAndObj(Gui::Command* cmd,
        std::vector<Gui::SelectionObject>& selection,
        TechDraw::DrawViewPart*& objFeat,
        std::string message);
    bool _checkSelObjAndSubs(Gui::Command* cmd,
        std::vector<Gui::SelectionObject>& selection,
        TechDraw::DrawViewPart*& objFeat,
        std::string message);
}

//===========================================================================
// TechDraw_ExtensionInsertDiameter
//===========================================================================
void execInsertPrefixChar(Gui::Command* cmd, const std::string& prefixFormat) {
    // insert a prefix character into the format specifier
    std::vector<Gui::SelectionObject> selection;
    if (!_checkSelection(cmd, selection, QObject::tr("TechDraw Insert Prefix").toStdString())) {
        return;
    }

    std::string prefixText(prefixFormat);
    if (prefixFormat.find("%s") != std::string::npos) {
        DlgTemplateField ui(Gui::getMainWindow());
        ui.setFieldName(QObject::tr("Repeat count").toStdString());
        ui.setFieldContent("1");
        if (ui.exec() != QDialog::Accepted) {
            return;
        }

        QString numberFromDialog = ui.getFieldContent();
        QString qPrefixText = QStringLiteral("%1× ").arg(numberFromDialog);
        prefixText = qPrefixText.toStdString();
    }
    size_t prefixSize = prefixText.capacity();

    Gui::Command::openCommand(QObject::tr("Insert Prefix").toStdString().c_str());
    for (auto selected : selection) {
        auto object = selected.getObject();
        if (object->isDerivedFrom<TechDraw::DrawViewDimension>()) {
            auto dim = static_cast<TechDraw::DrawViewDimension*>(selected.getObject());
            std::string formatSpec = dim->FormatSpec.getStrValue();
            formatSpec.reserve(formatSpec.capacity() + prefixSize);
            formatSpec.insert(0, prefixText);
            dim->FormatSpec.setValue(formatSpec);
        }
    }
    Gui::Command::commitCommand();
}

DEF_STD_CMD_A(CmdTechDrawExtensionInsertDiameter)

CmdTechDrawExtensionInsertDiameter::CmdTechDrawExtensionInsertDiameter()
    : Command("TechDraw_ExtensionInsertDiameter")
{
    sAppModule      = "TechDraw";
    sGroup          = QT_TR_NOOP("TechDraw");
    sMenuText       = QT_TR_NOOP("Insert '⌀' Prefix");
    sToolTipText    = QT_TR_NOOP("Inserts a '⌀' symbol at the beginning of the dimension");
    sWhatsThis      = "TechDraw_ExtensionInsertDiameter";
    sStatusTip      = sMenuText;
    sPixmap         = "TechDraw_ExtensionInsertDiameter";
}

void CmdTechDrawExtensionInsertDiameter::activated(int iMsg)
{
    Q_UNUSED(iMsg);
    execInsertPrefixChar(this, "⌀");
}

bool CmdTechDrawExtensionInsertDiameter::isActive()
{
    bool havePage = DrawGuiUtil::needPage(this);
    bool haveView = DrawGuiUtil::needView(this);
    return (havePage && haveView);
}

//===========================================================================
// TechDraw_ExtensionInsertSquare
//===========================================================================

DEF_STD_CMD_A(CmdTechDrawExtensionInsertSquare)

CmdTechDrawExtensionInsertSquare::CmdTechDrawExtensionInsertSquare()
    : Command("TechDraw_ExtensionInsertSquare")
{
    sAppModule      = "TechDraw";
    sGroup          = QT_TR_NOOP("TechDraw");
    sMenuText       = QT_TR_NOOP("Insert '□' Prefix");
    sToolTipText    = QT_TR_NOOP("Inserts a '□' symbol at the beginning of the dimension");
    sWhatsThis      = "TechDraw_ExtensionInsertSquare";
    sStatusTip      = sMenuText;
    sPixmap         = "TechDraw_ExtensionInsertSquare";
}

void CmdTechDrawExtensionInsertSquare::activated(int iMsg)
{
    Q_UNUSED(iMsg);
    execInsertPrefixChar(this, "□");    //□ white square U+25A1
}

bool CmdTechDrawExtensionInsertSquare::isActive()
{
    bool havePage = DrawGuiUtil::needPage(this);
    bool haveView = DrawGuiUtil::needView(this);
    return (havePage && haveView);
}

//===========================================================================
// TechDraw_ExtensionInsertRepetition
//===========================================================================

DEF_STD_CMD_A(CmdTechDrawExtensionInsertRepetition)

CmdTechDrawExtensionInsertRepetition::CmdTechDrawExtensionInsertRepetition()
    : Command("TechDraw_ExtensionInsertRepetition")
{
    sAppModule      = "TechDraw";
    sGroup          = QT_TR_NOOP("TechDraw");
    sMenuText       = QT_TR_NOOP("Insert 'n×' Prefix");
    sToolTipText    = QT_TR_NOOP("Inserts a repeated feature count at the beginning of the dimension");
    sWhatsThis      = "TechDraw_ExtensionInsertRepetition";
    sStatusTip      = sMenuText;
    sPixmap         = "TechDraw_ExtensionInsertRepetition";
}

void CmdTechDrawExtensionInsertRepetition::activated(int iMsg)
{
    Q_UNUSED(iMsg);

    execInsertPrefixChar(this, "%s× "); //× Multiplication sign U+00D7
}

bool CmdTechDrawExtensionInsertRepetition::isActive()
{
    bool havePage = DrawGuiUtil::needPage(this);
    bool haveView = DrawGuiUtil::needView(this);
    return (havePage && haveView);
}

//===========================================================================
// TechDraw_ExtensionRemovePrefixChar
//===========================================================================

void execRemovePrefixChar(Gui::Command* cmd) {
    // remove a prefix character from the format specifier
    std::vector<Gui::SelectionObject> selection;
    if (!_checkSelection(cmd, selection, QT_TRANSLATE_NOOP("Command","TechDraw Remove Prefix"))) {
        return;
    }

    Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Remove Prefix"));
    for (auto selected : selection)
    {
        auto object = selected.getObject();
        if (object->isDerivedFrom<TechDraw::DrawViewDimension>()) {
            auto dim = static_cast<TechDraw::DrawViewDimension*>(selected.getObject());
            std::string formatSpec = dim->FormatSpec.getStrValue();
            int pos = formatSpec.find("%.");
            if (pos != 0)
            {
                formatSpec = formatSpec.substr(pos);
                dim->FormatSpec.setValue(formatSpec);
            }
        }
    }
    Gui::Command::commitCommand();
}

DEF_STD_CMD_A(CmdTechDrawExtensionRemovePrefixChar)

CmdTechDrawExtensionRemovePrefixChar::CmdTechDrawExtensionRemovePrefixChar()
    : Command("TechDraw_ExtensionRemovePrefixChar")
{
    sAppModule      = "TechDraw";
    sGroup          = QT_TR_NOOP("TechDraw");
    sMenuText       = QT_TR_NOOP("Remove Prefix");
    sToolTipText    = QT_TR_NOOP("Removes the prefix symbols at the beginning of the dimension");
    sWhatsThis      = "TechDraw_ExtensionRemovePrefixChar";
    sStatusTip      = sMenuText;
    sPixmap         = "TechDraw_ExtensionRemovePrefixChar";
}

void CmdTechDrawExtensionRemovePrefixChar::activated(int iMsg)
{
    Q_UNUSED(iMsg);
    execRemovePrefixChar(this);
}

bool CmdTechDrawExtensionRemovePrefixChar::isActive()
{
    bool havePage = DrawGuiUtil::needPage(this);
    bool haveView = DrawGuiUtil::needView(this);
    return (havePage && haveView);
}

//===========================================================================
// TechDraw_ExtensionInsertPrefixGroup
//===========================================================================

DEF_STD_CMD_ACL(CmdTechDrawExtensionInsertPrefixGroup)

CmdTechDrawExtensionInsertPrefixGroup::CmdTechDrawExtensionInsertPrefixGroup()
    : Command("TechDraw_ExtensionInsertPrefixGroup")
{
    sAppModule      = "TechDraw";
    sGroup          = QT_TR_NOOP("TechDraw");
    sMenuText       = QT_TR_NOOP("Insert '⌀' Prefix");
    sToolTipText    = QT_TR_NOOP("Inserts a '⌀' symbol at the beginning of the dimension text");
    sWhatsThis      = "TechDraw_ExtensionInsertPrefixGroup";
    sStatusTip      = sMenuText;
}

void CmdTechDrawExtensionInsertPrefixGroup::activated(int iMsg)
{
    //    Base::Console().message("CMD::ExtensionLinePPGroup - activated(%d)\n", iMsg);
    Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog();
    if (dlg) {
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task in progress"),
            QObject::tr("Close active task dialog and try again"));
        return;
    }

    Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
    pcAction->setIcon(pcAction->actions().at(iMsg)->icon());
    switch (iMsg) {
    case 0:                 //insert "⌀" as prefix
        execInsertPrefixChar(this, "⌀");
        break;
    case 1:                 //insert "□" as prefix
        execInsertPrefixChar(this, "□");
        break;
    case 2:                 //insert "n×" as prefix
        execInsertPrefixChar(this, "%s× ");
        break;
    case 3:                 //remove prefix characters
        execRemovePrefixChar(this);
        break;
    default:
        Base::Console().message("CMD::CVGrp - invalid iMsg: %d\n", iMsg);
    };
}

Gui::Action* CmdTechDrawExtensionInsertPrefixGroup::createAction()
{
    Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow());
    pcAction->setDropDownMenu(true);
    applyCommandData(this->className(), pcAction);

    QAction* p1 = pcAction->addAction(QString());
    p1->setIcon(Gui::BitmapFactory().iconFromTheme("TechDraw_ExtensionInsertDiameter"));
    p1->setObjectName(QStringLiteral("TechDraw_ExtensionInsertDiameter"));
    p1->setWhatsThis(QStringLiteral("TechDraw_ExtensionInsertDiameter"));
    QAction* p2 = pcAction->addAction(QString());
    p2->setIcon(Gui::BitmapFactory().iconFromTheme("TechDraw_ExtensionInsertSquare"));
    p2->setObjectName(QStringLiteral("TechDraw_ExtensionInsertSquare"));
    p2->setWhatsThis(QStringLiteral("TechDraw_ExtensionInsertSquare"));
    QAction* p3 = pcAction->addAction(QString());
    p3->setIcon(Gui::BitmapFactory().iconFromTheme("TechDraw_ExtensionInsertRepetition"));
    p3->setObjectName(QStringLiteral("TechDraw_ExtensionInsertRepetition"));
    p3->setWhatsThis(QStringLiteral("TechDraw_ExtensionInsertRepetition"));
    QAction* p4 = pcAction->addAction(QString());
    p4->setIcon(Gui::BitmapFactory().iconFromTheme("TechDraw_ExtensionRemovePrefixChar"));
    p4->setObjectName(QStringLiteral("TechDraw_ExtensionRemovePrefixChar"));
    p4->setWhatsThis(QStringLiteral("TechDraw_ExtensionRemovePrefixChar"));

    _pcAction = pcAction;
    languageChange();

    pcAction->setIcon(p1->icon());
    int defaultId = 0;
    pcAction->setProperty("defaultAction", QVariant(defaultId));

    return pcAction;
}

void CmdTechDrawExtensionInsertPrefixGroup::languageChange()
{
    Command::languageChange();

    if (!_pcAction)
        return;
    Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
    QList<QAction*> a = pcAction->actions();

    QAction* arc1 = a[0];
    arc1->setText(QApplication::translate("CmdTechDrawExtensionInsertDiameter", "Insert '⌀' Prefix"));
    arc1->setToolTip(QApplication::translate("CmdTechDrawExtensionInsertDiameter",
"Inserts a '⌀' symbol at the beginning of the dimension"));
    arc1->setStatusTip(arc1->text());
    QAction* arc2 = a[1];
    arc2->setText(QApplication::translate("CmdTechDrawExtensionInsertSquare", "Insert '□' Prefix"));
    arc2->setToolTip(QApplication::translate("CmdTechDrawExtensionInsertSquare",
"Inserts a '□' symbol at the beginning of the dimension"));
    arc2->setStatusTip(arc2->text());
    QAction* arc3 = a[2];
    arc3->setText(QApplication::translate("CmdTechDrawExtensionInsertRepetition", "Insert 'n×' Prefix"));
    arc3->setToolTip(QApplication::translate("CmdTechDrawExtensionInsertRepetition",
"Inserts a repeated feature count at the beginning of the dimension"));
    arc3->setStatusTip(arc3->text());
    QAction* arc4 = a[3];
    arc4->setText(QApplication::translate("TechDraw_ExtensionremovePrefixChar", "Remove Prefix"));
    arc4->setToolTip(QApplication::translate("TechDraw_ExtensionremovePrefixChar",
"Removes the prefix symbols at the beginning of the dimension"));
    arc4->setStatusTip(arc4->text());
}

bool CmdTechDrawExtensionInsertPrefixGroup::isActive()
{
    bool havePage = DrawGuiUtil::needPage(this);
    bool haveView = DrawGuiUtil::needView(this, true);
    return (havePage && haveView);
}

//===========================================================================
// TechDraw_ExtensionIncreaseDecimal
//===========================================================================

void execIncreaseDecreaseDecimal(Gui::Command* cmd, int delta) {
    // increase or decrease number of decimal places of a measure
    std::vector<Gui::SelectionObject> selection;
    if (!_checkSelection(cmd, selection, QT_TRANSLATE_NOOP("QObject","TechDraw Increase/Decrease Decimal"))) {
        return;
    }

    Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Increase/Decrease Decimal"));
    std::string numStr;
    for (auto selected : selection) {
        auto object = selected.getObject();
        if (object->isDerivedFrom<TechDraw::DrawViewDimension>()) {
            auto dim = static_cast<TechDraw::DrawViewDimension*>(selected.getObject());
            std::string formatSpec = dim->FormatSpec.getStrValue();
            std::string searchStr("%.");
            int numFound = formatSpec.find(searchStr) + 2;
            numStr = formatSpec[numFound];
            int numInt = std::stoi(numStr, nullptr);
            numInt = numInt + delta;
            if (numInt >= 0 && numInt <= 9) {
                numStr = std::to_string(numInt);
                formatSpec.replace(numFound, 1, numStr);
                dim->FormatSpec.setValue(formatSpec);
            }
        }
    }
    Gui::Command::commitCommand();
}

DEF_STD_CMD_A(CmdTechDrawExtensionIncreaseDecimal)

CmdTechDrawExtensionIncreaseDecimal::CmdTechDrawExtensionIncreaseDecimal()
    : Command("TechDraw_ExtensionIncreaseDecimal")
{
    sAppModule      = "TechDraw";
    sGroup          = QT_TR_NOOP("TechDraw");
    sMenuText       = QT_TR_NOOP("Increase Decimal Places");
    sToolTipText    = QT_TR_NOOP("Increases the number of decimal places of the dimension");
    sWhatsThis      = "TechDraw_ExtensionIncreaseDecimal";
    sStatusTip      = sMenuText;
    sPixmap         = "TechDraw_ExtensionIncreaseDecimal";
}

void CmdTechDrawExtensionIncreaseDecimal::activated(int iMsg)
{
    Q_UNUSED(iMsg);
    execIncreaseDecreaseDecimal(this, 1);
}

bool CmdTechDrawExtensionIncreaseDecimal::isActive()
{
    bool havePage = DrawGuiUtil::needPage(this);
    bool haveView = DrawGuiUtil::needView(this);
    return (havePage && haveView);
}

//===========================================================================
// TechDraw_ExtensionDecreaseDecimal
//===========================================================================

DEF_STD_CMD_A(CmdTechDrawExtensionDecreaseDecimal)

CmdTechDrawExtensionDecreaseDecimal::CmdTechDrawExtensionDecreaseDecimal()
    : Command("TechDraw_ExtensionDecreaseDecimal")
{
    sAppModule      = "TechDraw";
    sGroup          = QT_TR_NOOP("TechDraw");
    sMenuText       = QT_TR_NOOP("Decrease Decimal Places");
    sToolTipText    = QT_TR_NOOP("Decreases the number of decimal places of the dimension");
    sWhatsThis      = "TechDraw_ExtensionDecreaseDecimal";
    sStatusTip      = sMenuText;
    sPixmap         = "TechDraw_ExtensionDecreaseDecimal";
}

void CmdTechDrawExtensionDecreaseDecimal::activated(int iMsg)
{
    Q_UNUSED(iMsg);
    execIncreaseDecreaseDecimal(this, -1);
}

bool CmdTechDrawExtensionDecreaseDecimal::isActive()
{
    bool havePage = DrawGuiUtil::needPage(this);
    bool haveView = DrawGuiUtil::needView(this);
    return (havePage && haveView);
}

//===========================================================================
// TechDraw_ExtensionIncreaseDecreaseGroup
//===========================================================================

DEF_STD_CMD_ACL(CmdTechDrawExtensionIncreaseDecreaseGroup)

CmdTechDrawExtensionIncreaseDecreaseGroup::CmdTechDrawExtensionIncreaseDecreaseGroup()
    : Command("TechDraw_ExtensionIncreaseDecreaseGroup")
{
    sAppModule      = "TechDraw";
    sGroup          = QT_TR_NOOP("TechDraw");
    sMenuText       = QT_TR_NOOP("Increase Decimal Places");
    sToolTipText    = QT_TR_NOOP("Increases the number of decimal places of the dimension");
    sWhatsThis      = "TechDraw_ExtensionIncreaseDecreaseGroup";
    sStatusTip      = sMenuText;
}

void CmdTechDrawExtensionIncreaseDecreaseGroup::activated(int iMsg)
{
    //    Base::Console().message("CMD::ExtensionIncreaseDecreaseGroup - activated(%d)\n", iMsg);
    Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog();
    if (dlg) {
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task in progress"),
            QObject::tr("Close active task dialog and try again"));
        return;
    }

    Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
    pcAction->setIcon(pcAction->actions().at(iMsg)->icon());
    switch (iMsg) {
    case 0:                 //increase decimal places
        execIncreaseDecreaseDecimal(this, 1);
        break;
    case 1:                 //decrease decimal places
        execIncreaseDecreaseDecimal(this, -1);
        break;
    default:
        Base::Console().message("CMD::CVGrp - invalid iMsg: %d\n", iMsg);
    };
}

Gui::Action* CmdTechDrawExtensionIncreaseDecreaseGroup::createAction()
{
    Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow());
    pcAction->setDropDownMenu(true);
    applyCommandData(this->className(), pcAction);

    QAction* p1 = pcAction->addAction(QString());
    p1->setIcon(Gui::BitmapFactory().iconFromTheme("TechDraw_ExtensionIncreaseDecimal"));
    p1->setObjectName(QStringLiteral("TechDraw_ExtensionIncreaseDecimal"));
    p1->setWhatsThis(QStringLiteral("TechDraw_ExtensionIncreaseDecimal"));
    QAction* p2 = pcAction->addAction(QString());
    p2->setIcon(Gui::BitmapFactory().iconFromTheme("TechDraw_ExtensionDecreaseDecimal"));
    p2->setObjectName(QStringLiteral("TechDraw_ExtensionDecreaseDecimal"));
    p2->setWhatsThis(QStringLiteral("TechDraw_ExtensionDecreaseDecimal"));

    _pcAction = pcAction;
    languageChange();

    pcAction->setIcon(p1->icon());
    int defaultId = 0;
    pcAction->setProperty("defaultAction", QVariant(defaultId));

    return pcAction;
}

void CmdTechDrawExtensionIncreaseDecreaseGroup::languageChange()
{
    Command::languageChange();

    if (!_pcAction)
        return;
    Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
    QList<QAction*> a = pcAction->actions();

    QAction* arc1 = a[0];
    arc1->setText(QApplication::translate("CmdTechDrawExtensionIncreaseDecimal", "Increase Decimal Places"));
    arc1->setToolTip(QApplication::translate("CmdTechDrawExtensionIncreaseDecimal",
"Increases the number of decimal places of the dimension"));
    arc1->setStatusTip(arc1->text());
    QAction* arc2 = a[1];
    arc2->setText(QApplication::translate("CmdTechDrawExtensionDecreaseDecimal", "Decrease Decimal Places"));
    arc2->setToolTip(QApplication::translate("CmdTechDrawExtensionDecreaseDecimal",
"Decreases the number of decimal places of the dimension"));
    arc2->setStatusTip(arc2->text());
}

bool CmdTechDrawExtensionIncreaseDecreaseGroup::isActive()
{
    bool havePage = DrawGuiUtil::needPage(this);
    bool haveView = DrawGuiUtil::needView(this, true);
    return (havePage && haveView);
}

//===========================================================================
// TechDraw_ExtensionPosHorizChainDimension
//===========================================================================

void execPosHorizChainDimension(Gui::Command* cmd) {
    // position a horizontal dimension chain
    std::vector<Gui::SelectionObject> selection;
    if (!_checkSelection(cmd, selection, QT_TRANSLATE_NOOP("QObject","TechDraw PosHorizChainDimension"))) {
        return;
    }

    Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Position Horizontal Chain Dimension"));
    std::vector<TechDraw::DrawViewDimension*> validDimension;
    validDimension = _getDimensions(selection, "DistanceX");
    if (validDimension.empty()) {
        QMessageBox::warning(Gui::getMainWindow(),
            QObject::tr("TechDraw PosHorizChainDimension"),
            QObject::tr("No horizontal dimensions selected"));
        return;
    }
    float yMaster = validDimension[0]->Y.getValue();
    for (auto dim : validDimension) {
        dim->Y.setValue(yMaster);
        pointPair pp = dim->getLinearPoints();
        Base::Vector3d p1 = pp.first();
        Base::Vector3d p2 = pp.second();
        dim->X.setValue((p1.x + p2.x) / 2.0);
    }
    Gui::Command::commitCommand();
}

DEF_STD_CMD_A(CmdTechDrawExtensionPosHorizChainDimension)

CmdTechDrawExtensionPosHorizChainDimension::CmdTechDrawExtensionPosHorizChainDimension()
    : Command("TechDraw_ExtensionPosHorizChainDimension")
{
    sAppModule      = "TechDraw";
    sGroup          = QT_TR_NOOP("TechDraw");
    sMenuText       = QT_TR_NOOP("Align Chain Dimensions Horizontally");
    sToolTipText    = QT_TR_NOOP("Aligns the horizontal dimensions to create a chain dimension:<br>\
- Select two or more horizontal dimensions<br>\
- The first dimension defines the position<br>\
- Click this tool");
    sWhatsThis      = "TechDraw_ExtensionPosHorizChainDimension";
    sStatusTip      = sMenuText;
    sPixmap         = "TechDraw_ExtensionPosHorizChainDimension";
}

void CmdTechDrawExtensionPosHorizChainDimension::activated(int iMsg)
{
    Q_UNUSED(iMsg);
    execPosHorizChainDimension(this);
}

bool CmdTechDrawExtensionPosHorizChainDimension::isActive()
{
    bool havePage = DrawGuiUtil::needPage(this);
    bool haveView = DrawGuiUtil::needView(this);
    return (havePage && haveView);
}

//===========================================================================
// TechDraw_ExtensionPosVertChainDimension
//===========================================================================

void execPosVertChainDimension(Gui::Command* cmd) {
    // position a vertical dimension chain
    std::vector<Gui::SelectionObject> selection;
    if (!_checkSelection(cmd, selection, QT_TRANSLATE_NOOP("QObject","TechDraw PosVertChainDimension"))) {
        return;
    }

    Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Position Vert Chain Dimension"));
    std::vector<TechDraw::DrawViewDimension*> validDimension;
    validDimension = _getDimensions(selection, "DistanceY");
    if (validDimension.empty()) {
        QMessageBox::warning(Gui::getMainWindow(),
            QObject::tr("TechDraw PosVertChainDimension"),
            QObject::tr("No vertical dimensions selected"));
        return;
    }
    float xMaster = validDimension[0]->X.getValue();
    double fontSize = Preferences::dimFontSizeMM();
    for (auto dim : validDimension) {
        dim->X.setValue(xMaster);
        pointPair pp = dim->getLinearPoints();
        Base::Vector3d p1 = pp.first();
        Base::Vector3d p2 = pp.second();
        dim->Y.setValue((p1.y + p2.y) / -2.0 + 0.5 * fontSize);
    }
    Gui::Command::commitCommand();
}

DEF_STD_CMD_A(CmdTechDrawExtensionPosVertChainDimension)

CmdTechDrawExtensionPosVertChainDimension::CmdTechDrawExtensionPosVertChainDimension()
    : Command("TechDraw_ExtensionPosVertChainDimension")
{
    sAppModule      = "TechDraw";
    sGroup          = QT_TR_NOOP("TechDraw");
    sMenuText       = QT_TR_NOOP("Align Chain Dimensions Vertically");
    sToolTipText    = QT_TR_NOOP("Aligns the vertical dimensions to create a chain dimension:<br>\
- Select two or more vertical dimensions<br>\
- The first dimension defines the position<br>\
- Click this tool");
    sWhatsThis      = "TechDraw_ExtensionPosVertChainDimension";
    sStatusTip      = sMenuText;
    sPixmap         = "TechDraw_ExtensionPosVertChainDimension";
}

void CmdTechDrawExtensionPosVertChainDimension::activated(int iMsg)
{
    Q_UNUSED(iMsg);
    execPosVertChainDimension(this);
}

bool CmdTechDrawExtensionPosVertChainDimension::isActive()
{
    bool havePage = DrawGuiUtil::needPage(this);
    bool haveView = DrawGuiUtil::needView(this);
    return (havePage && haveView);
}

//===========================================================================
// TechDraw_ExtensionPosObliqueChainDimension
//===========================================================================

void execPosObliqueChainDimension(Gui::Command* cmd) {
    // position an oblique dimension chain
    std::vector<Gui::SelectionObject> selection;
    if (!_checkSelection(cmd, selection, QT_TRANSLATE_NOOP("QObject","TechDraw PosObliqueChainDimension"))) {
        return;
    }

    Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Position Oblique Chain Dimension"));
    std::vector<TechDraw::DrawViewDimension*> validDimension;
    validDimension = _getDimensions(selection, "Distance");
    if (validDimension.empty()) {
        QMessageBox::warning(Gui::getMainWindow(),
            QObject::tr("TechDraw PosObliqueChainDimension"),
            QObject::tr("No oblique dimensions selected"));
        return;
    }
    float xMaster = validDimension[0]->X.getValue();
    float yMaster = validDimension[0]->Y.getValue();
    Base::Vector3d pMaster(xMaster, yMaster, 0.0);
    pointPair pp = validDimension[0]->getLinearPoints();
    Base::Vector3d dirMaster = pp.second() - pp.first();
    dirMaster.y = -dirMaster.y;
    for (auto dim : validDimension) {
        float xDim = dim->X.getValue();
        float yDim = dim->Y.getValue();
        Base::Vector3d pDim(xDim, yDim, 0.0);
        Base::Vector3d p3 = DrawUtil::getTrianglePoint(pMaster, dirMaster, pDim);
        dim->X.setValue(p3.x);
        dim->Y.setValue(p3.y);
    }
    Gui::Command::commitCommand();
}

DEF_STD_CMD_A(CmdTechDrawExtensionPosObliqueChainDimension)

CmdTechDrawExtensionPosObliqueChainDimension::CmdTechDrawExtensionPosObliqueChainDimension()
    : Command("TechDraw_ExtensionPosObliqueChainDimension")
{
    sAppModule      = "TechDraw";
    sGroup          = QT_TR_NOOP("TechDraw");
    sMenuText       = QT_TR_NOOP("Align Oblique Chain Dimensions");
    sToolTipText    = QT_TR_NOOP("Aligns the oblique dimensions to create a chain dimension:<br>\
- Select two or more parallel oblique dimensions<br>\
- The first dimension defines the position<br>\
- Click this tool");
    sWhatsThis      = "TechDraw_ExtensionPosObliqueChainDimension";
    sStatusTip      = sMenuText;
    sPixmap         = "TechDraw_ExtensionPosObliqueChainDimension";
}

void CmdTechDrawExtensionPosObliqueChainDimension::activated(int iMsg)
{
    Q_UNUSED(iMsg);
    execPosObliqueChainDimension(this);
    ///Base::Console().message("TechDraw_ExtensionPosObliqueChainDimension started\n");
}

bool CmdTechDrawExtensionPosObliqueChainDimension::isActive()
{
    bool havePage = DrawGuiUtil::needPage(this);
    bool haveView = DrawGuiUtil::needView(this);
    return (havePage && haveView);
}

//===========================================================================
// TechDraw_ExtensionPosChainDimensionGroup
//===========================================================================

DEF_STD_CMD_ACL(CmdTechDrawExtensionPosChainDimensionGroup)

CmdTechDrawExtensionPosChainDimensionGroup::CmdTechDrawExtensionPosChainDimensionGroup()
    : Command("TechDraw_ExtensionPosChainDimensionGroup")
{
    sAppModule      = "TechDraw";
    sGroup          = QT_TR_NOOP("TechDraw");
    sMenuText       = QT_TR_NOOP("Align Horizontal Chain Dimensions");
    sToolTipText    = QT_TR_NOOP("Aligns the horizontal dimensions to create a chain dimension:<br>\
- Select two or more horizontal dimensions<br>\
- The first dimension defines the position<br>\
- Click this tool");
    sWhatsThis      = "TechDraw_ExtensionPosChainDimensionGroup";
    sStatusTip      = sMenuText;
}

void CmdTechDrawExtensionPosChainDimensionGroup::activated(int iMsg)
{
    //    Base::Console().message("CMD::ExtensionPosChainDimensionGroup - activated(%d)\n", iMsg);
    Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog();
    if (dlg) {
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task in progress"),
            QObject::tr("Close active task dialog and try again"));
        return;
    }

    Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
    pcAction->setIcon(pcAction->actions().at(iMsg)->icon());
    switch (iMsg) {
    case 0:                 //position horizontal chain dimensions
        execPosHorizChainDimension(this);
        break;
    case 1:                 //position vertical chain dimensions
        execPosVertChainDimension(this);
        break;
    case 2:                 //position oblique chain dimensions
        execPosObliqueChainDimension(this);
        break;
    default:
        Base::Console().message("CMD::CVGrp - invalid iMsg: %d\n", iMsg);
    };
}

Gui::Action* CmdTechDrawExtensionPosChainDimensionGroup::createAction()
{
    Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow());
    pcAction->setDropDownMenu(true);
    applyCommandData(this->className(), pcAction);

    QAction* p1 = pcAction->addAction(QString());
    p1->setIcon(Gui::BitmapFactory().iconFromTheme("TechDraw_ExtensionPosHorizChainDimension"));
    p1->setObjectName(QStringLiteral("TechDraw_ExtensionPosHorizChainDimension"));
    p1->setWhatsThis(QStringLiteral("TechDraw_ExtensionPosHorizChainDimension"));
    QAction* p2 = pcAction->addAction(QString());
    p2->setIcon(Gui::BitmapFactory().iconFromTheme("TechDraw_ExtensionPosVertChainDimension"));
    p2->setObjectName(QStringLiteral("TechDraw_ExtensionPosVertChainDimension"));
    p2->setWhatsThis(QStringLiteral("sion"));
    QAction* p3 = pcAction->addAction(QString());
    p3->setIcon(Gui::BitmapFactory().iconFromTheme("TechDraw_ExtensionPosObliqueChainDimension"));
    p3->setObjectName(QStringLiteral("TechDraw_ExtensionPosObliqueChainDimension"));
    p3->setWhatsThis(QStringLiteral("TechDraw_ExtensionPosObliqueChainDimension"));

    _pcAction = pcAction;
    languageChange();

    pcAction->setIcon(p1->icon());
    int defaultId = 0;
    pcAction->setProperty("defaultAction", QVariant(defaultId));

    return pcAction;
}

void CmdTechDrawExtensionPosChainDimensionGroup::languageChange()
{
    Command::languageChange();

    if (!_pcAction)
        return;
    Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
    QList<QAction*> a = pcAction->actions();

    QAction* arc1 = a[0];
    arc1->setText(QApplication::translate("CmdTechDrawExtensionPosHorizChainDimension", "Position Horizontal Chain Dimensions"));
    arc1->setToolTip(QApplication::translate("CmdTechDrawExtensionPosHorizChainDimension",
"Aligns the horizontal dimensions to create a chain dimension:<br>\
- Select two or more horizontal dimensions<br>\
- The first dimension defines the position<br>\
- Click this tool"));
    arc1->setStatusTip(arc1->text());
    QAction* arc2 = a[1];
    arc2->setText(QApplication::translate("CmdTechDrawExtensionPosVertChainDimension", "Position Vertical Chain Dimensions"));
    arc2->setToolTip(QApplication::translate("CmdTechDrawExtensionPosVertChainDimension",
"Aligns the vertical dimensions to create a chain dimension:<br>\
- Select two or more vertical dimensions<br>\
- The first dimension defines the position<br>\
- Click this tool"));
    arc2->setStatusTip(arc2->text());
    QAction* arc3 = a[2];
    arc3->setText(QApplication::translate("CmdTechDrawExtensionPosObliqueChainDimension", "Position Oblique Chain Dimensions"));
    arc3->setToolTip(QApplication::translate("CmdTechDrawExtensionPosObliqueChainDimension",
"Aligns the oblique dimensions to create a chain dimension:<br>\
- Select two or more parallel oblique dimensions<br>\
- The first dimension defines the position<br>\
- Click this tool"));
    arc3->setStatusTip(arc3->text());
}

bool CmdTechDrawExtensionPosChainDimensionGroup::isActive()
{
    bool havePage = DrawGuiUtil::needPage(this);
    bool haveView = DrawGuiUtil::needView(this, true);
    return (havePage && haveView);
}

//===========================================================================
// TechDraw_ExtensionCascadeHorizDimension
//===========================================================================

void execCascadeHorizDimension(Gui::Command* cmd) {
    // cascade horizontal dimensions
    std::vector<Gui::SelectionObject> selection;
    if (!_checkSelection(cmd, selection, QT_TRANSLATE_NOOP("QObject","TechDraw CascadeHorizDimension"))) {
        return;
    }

    Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Cascade Horizontal Dimension"));
    std::vector<TechDraw::DrawViewDimension*> validDimension;
    validDimension = _getDimensions(selection, "DistanceX");
    if (validDimension.empty()) {
        QMessageBox::warning(Gui::getMainWindow(),
            QObject::tr("TechDraw CascadeHorizDimension"),
            QObject::tr("No horizontal dimensions selected"));
        return;
    }
    float yMaster = validDimension[0]->Y.getValue();
    float dimDistance = activeDimAttributes.getCascadeSpacing();
    if (std::signbit(yMaster))
        dimDistance = -dimDistance;
    for (auto dim : validDimension) {
        dim->Y.setValue(yMaster);
        pointPair pp = dim->getLinearPoints();
        Base::Vector3d p1 = pp.first();
        Base::Vector3d p2 = pp.second();
        dim->X.setValue((p1.x + p2.x) / 2.0);
        yMaster = yMaster + dimDistance;
    }
    Gui::Command::commitCommand();
}

DEF_STD_CMD_A(CmdTechDrawExtensionCascadeHorizDimension)

CmdTechDrawExtensionCascadeHorizDimension::CmdTechDrawExtensionCascadeHorizDimension()
    : Command("TechDraw_ExtensionCascadeHorizDimension")
{
    sAppModule      = "TechDraw";
    sGroup          = QT_TR_NOOP("TechDraw");
    sMenuText       = QT_TR_NOOP("Cascade Horizontal Dimensions");
    sToolTipText    = QT_TR_NOOP("Evenly spaces the selected horizontal dimensions:<br>\
- Specify the cascade spacing (optional)<br>\
- Select two or more horizontal dimensions<br>\
- The first dimension defines the position<br>\
- Click this tool");
    sWhatsThis      = "TechDraw_ExtensionCascadeHorizDimension";
    sStatusTip      = sMenuText;
    sPixmap         = "TechDraw_ExtensionCascadeHorizDimension";
}

void CmdTechDrawExtensionCascadeHorizDimension::activated(int iMsg)
{
    Q_UNUSED(iMsg);
    execCascadeHorizDimension(this);
}

bool CmdTechDrawExtensionCascadeHorizDimension::isActive()
{
    bool havePage = DrawGuiUtil::needPage(this);
    bool haveView = DrawGuiUtil::needView(this);
    return (havePage && haveView);
}

//===========================================================================
// TechDraw_ExtensionCascadeVertDimension
//===========================================================================

void execCascadeVertDimension(Gui::Command* cmd) {
    // cascade vertical dimensions
    std::vector<Gui::SelectionObject> selection;
    if (!_checkSelection(cmd, selection, QT_TRANSLATE_NOOP("QObject","TechDraw CascadeVertDimension"))) {
        return;
    }

    Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Cascade Vertical Dimension"));
    std::vector<TechDraw::DrawViewDimension*> validDimension;
    validDimension = _getDimensions(selection, "DistanceY");
    if (validDimension.empty()) {
        QMessageBox::warning(Gui::getMainWindow(),
            QObject::tr("TechDraw CascadeVertDimension"),
            QObject::tr("No vertical dimensions selected"));
        return;
    }
    float xMaster = validDimension[0]->X.getValue();
    float dimDistance = activeDimAttributes.getCascadeSpacing();
    if (std::signbit(xMaster))
        dimDistance = -dimDistance;
    double fontSize = Preferences::dimFontSizeMM();
    for (auto dim : validDimension) {
        dim->X.setValue(xMaster);
        pointPair pp = dim->getLinearPoints();
        Base::Vector3d p1 = pp.first();
        Base::Vector3d p2 = pp.second();
        dim->Y.setValue((p1.y + p2.y) / -2.0 + 0.5 * fontSize);
        xMaster = xMaster + dimDistance;
    }
    Gui::Command::commitCommand();
}

DEF_STD_CMD_A(CmdTechDrawExtensionCascadeVertDimension)

CmdTechDrawExtensionCascadeVertDimension::CmdTechDrawExtensionCascadeVertDimension()
    : Command("TechDraw_ExtensionCascadeVertDimension")
{
    sAppModule      = "TechDraw";
    sGroup          = QT_TR_NOOP("TechDraw");
    sMenuText       = QT_TR_NOOP("Cascade Vertical Dimensions");
    sToolTipText    = QT_TR_NOOP("Evenly spaces the selected vertical dimensions:<br>\
- Specify the cascade spacing (optional)<br>\
- Select two or more vertical dimensions<br>\
- The first dimension defines the position<br>\
- Click this tool");
    sWhatsThis      = "TechDraw_ExtensionCascadeVertDimension";
    sStatusTip      = sMenuText;
    sPixmap         = "TechDraw_ExtensionCascadeVertDimension";
}

void CmdTechDrawExtensionCascadeVertDimension::activated(int iMsg)
{
    Q_UNUSED(iMsg);
    execCascadeVertDimension(this);
}

bool CmdTechDrawExtensionCascadeVertDimension::isActive()
{
    bool havePage = DrawGuiUtil::needPage(this);
    bool haveView = DrawGuiUtil::needView(this);
    return (havePage && haveView);
}

//===========================================================================
// TechDraw_ExtensionCascadeObliqueDimension
//===========================================================================

void execCascadeObliqueDimension(Gui::Command* cmd) {
    // cascade oblique dimensions
    std::vector<Gui::SelectionObject> selection;
    if (!_checkSelection(cmd, selection, QT_TRANSLATE_NOOP("QObject","TechDraw CascadeObliqueDimension"))) {
        return;
    }

    Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Cascade Oblique Dimension"));
    std::vector<TechDraw::DrawViewDimension*> validDimension;
    validDimension = _getDimensions(selection, "Distance");
    if (validDimension.empty()) {
        QMessageBox::warning(Gui::getMainWindow(),
            QObject::tr("TechDraw CascadeObliqueDimension"),
            QObject::tr("No oblique dimensions selected"));
        return;
    }
    float xMaster = validDimension[0]->X.getValue();
    float yMaster = validDimension[0]->Y.getValue();
    Base::Vector3d pMaster(xMaster, yMaster, 0.0);
    pointPair pp = validDimension[0]->getLinearPoints();
    Base::Vector3d dirMaster = pp.second() - pp.first();
    dirMaster.y = -dirMaster.y;
    Base::Vector3d origin(0.0, 0.0, 0.0);
    Base::Vector3d ipDelta = DrawUtil::getTrianglePoint(pMaster, dirMaster, origin);
    float dimDistance = activeDimAttributes.getCascadeSpacing();
    Base::Vector3d delta = ipDelta.Normalize() * dimDistance;
    int i = 0;
    for (auto dim : validDimension) {
        float xDim = dim->X.getValue();
        float yDim = dim->Y.getValue();
        Base::Vector3d pDim(xDim, yDim, 0.0);
        Base::Vector3d p3 = DrawUtil::getTrianglePoint(pMaster, dirMaster, pDim);
        p3 = p3 + delta * i;
        dim->X.setValue(p3.x);
        dim->Y.setValue(p3.y);
        i = i + 1;
    }
    Gui::Command::commitCommand();
}

DEF_STD_CMD_A(CmdTechDrawExtensionCascadeObliqueDimension)

CmdTechDrawExtensionCascadeObliqueDimension::CmdTechDrawExtensionCascadeObliqueDimension()
    : Command("TechDraw_ExtensionCascadeObliqueDimension")
{
    sAppModule      = "TechDraw";
    sGroup          = QT_TR_NOOP("TechDraw");
    sMenuText       = QT_TR_NOOP("Cascade Oblique Dimensions");
    sToolTipText    = QT_TR_NOOP("Evenly spaces the selected oblique dimensions:<br>\
- Specify the cascade spacing (optional)<br>\
- Select two or more parallel oblique dimensions<br>\
- The first dimension defines the position<br>\
- Click this tool");
    sWhatsThis      = "TechDraw_ExtensionCascadeObliqueDimension";
    sStatusTip      = sMenuText;
    sPixmap         = "TechDraw_ExtensionCascadeObliqueDimension";
}

void CmdTechDrawExtensionCascadeObliqueDimension::activated(int iMsg)
{
    Q_UNUSED(iMsg);
    execCascadeObliqueDimension(this);
    ///Base::Console().message("TechDraw_ExtensionPosObliqueChainDimension started\n");
}

bool CmdTechDrawExtensionCascadeObliqueDimension::isActive()
{
    bool havePage = DrawGuiUtil::needPage(this);
    bool haveView = DrawGuiUtil::needView(this);
    return (havePage && haveView);
}

//===========================================================================
// TechDraw_ExtensionCascadeDimensionGroup
//===========================================================================

DEF_STD_CMD_ACL(CmdTechDrawExtensionCascadeDimensionGroup)

CmdTechDrawExtensionCascadeDimensionGroup::CmdTechDrawExtensionCascadeDimensionGroup()
    : Command("TechDraw_ExtensionCascadeDimensionGroup")
{
    sAppModule      = "TechDraw";
    sGroup          = QT_TR_NOOP("TechDraw");
    sMenuText       = QT_TR_NOOP("Cascade Horizontal Dimensions");
    sToolTipText    = QT_TR_NOOP("Evenly spaces the selected horizontal dimensions:<br>\
- Specify the cascade spacing (optional)<br>\
- Select two or more horizontal dimensions<br>\
- The first dimension defines the position<br>\
- Click this tool");
    sWhatsThis      = "TechDraw_ExtensionCascadeDimensionGroup";
    sStatusTip      = sMenuText;
}

void CmdTechDrawExtensionCascadeDimensionGroup::activated(int iMsg)
{
    //    Base::Console().message("CMD::ExtensionCascadeDimansionGroup - activated(%d)\n", iMsg);
    Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog();
    if (dlg) {
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task in progress"),
            QObject::tr("Close active task dialog and try again"));
        return;
    }

    Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
    pcAction->setIcon(pcAction->actions().at(iMsg)->icon());
    switch (iMsg) {
    case 0:                 //cascade horizontal dimensions
        execCascadeHorizDimension(this);
        break;
    case 1:                 //cascade vertical dimensions
        execCascadeVertDimension(this);
        break;
    case 2:                 //cascade oblique dimensions
        execCascadeObliqueDimension(this);
        break;
    default:
        Base::Console().message("CMD::CVGrp - invalid iMsg: %d\n", iMsg);
    };
}

Gui::Action* CmdTechDrawExtensionCascadeDimensionGroup::createAction()
{
    Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow());
    pcAction->setDropDownMenu(true);
    applyCommandData(this->className(), pcAction);

    QAction* p1 = pcAction->addAction(QString());
    p1->setIcon(Gui::BitmapFactory().iconFromTheme("TechDraw_ExtensionCascadeHorizDimension"));
    p1->setObjectName(QStringLiteral("TechDraw_ExtensionCascadeHorizDimension"));
    p1->setWhatsThis(QStringLiteral("TechDraw_ExtensionCascadeHorizDimension"));
    QAction* p2 = pcAction->addAction(QString());
    p2->setIcon(Gui::BitmapFactory().iconFromTheme("TechDraw_ExtensionCascadeVertDimension"));
    p2->setObjectName(QStringLiteral("TechDraw_ExtensionCascadeVertDimension"));
    p2->setWhatsThis(QStringLiteral("TechDraw_ExtensionCascadeVertDimension"));
    QAction* p3 = pcAction->addAction(QString());
    p3->setIcon(Gui::BitmapFactory().iconFromTheme("TechDraw_ExtensionCascadeObliqueDimension"));
    p3->setObjectName(QStringLiteral("TechDraw_ExtensionCascadeObliqueDimension"));
    p3->setWhatsThis(QStringLiteral("TechDraw_ExtensionCascadeObliqueDimension"));

    _pcAction = pcAction;
    languageChange();

    pcAction->setIcon(p1->icon());
    int defaultId = 0;
    pcAction->setProperty("defaultAction", QVariant(defaultId));

    return pcAction;
}

void CmdTechDrawExtensionCascadeDimensionGroup::languageChange()
{
    Command::languageChange();

    if (!_pcAction)
        return;
    Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
    QList<QAction*> a = pcAction->actions();

    QAction* arc1 = a[0];
    arc1->setText(QApplication::translate("CmdTechDrawExtensionCascadeHorizDimension", "Cascade Horizontal Dimensions"));
    arc1->setToolTip(QApplication::translate("CmdTechDrawExtensionCascadeHorizDimension",
"Evenly spaces the selected horizontal dimensions:<br>\
- Specify the cascade spacing (optional)<br>\
- Select two or more horizontal dimensions<br>\
- The first dimension defines the position<br>\
- Click this tool"));
    arc1->setStatusTip(arc1->text());
    QAction* arc2 = a[1];
    arc2->setText(QApplication::translate("CmdTechDrawExtensionCascadeVertDimension", "Cascade Vertical Dimensions"));
    arc2->setToolTip(QApplication::translate("CmdTechDrawExtensionCascadeVertDimension",
"Evenly spaces the selected vertical dimensions:<br>\
- Specify the cascade spacing (optional)<br>\
- Select two or more vertical dimensions<br>\
- The first dimension defines the position<br>\
- Click this tool"));
    arc2->setStatusTip(arc2->text());
    QAction* arc3 = a[2];
    arc3->setText(QApplication::translate("CmdTechDrawExtensionCascadeObliqueDimension", "Cascade Oblique Dimensions"));
    arc3->setToolTip(QApplication::translate("CmdTechDrawExtensionCascadeObliqueDimension",
"Evenly spaces the selected oblique dimensions:<br>\
- Specify the cascade spacing (optional)<br>\
- Select two or more parallel oblique dimensions<br>\
- The first dimension defines the position<br>\
- Click this tool"));
    arc3->setStatusTip(arc3->text());
}

bool CmdTechDrawExtensionCascadeDimensionGroup::isActive()
{
    bool havePage = DrawGuiUtil::needPage(this);
    bool haveView = DrawGuiUtil::needView(this, true);
    return (havePage && haveView);
}

//===========================================================================
// TechDraw_ExtensionCreateHorizChainDimension
//===========================================================================

void execCreateHorizChainDimension(Gui::Command* cmd) {
    //create a horizontal chain dimension
    std::vector<Gui::SelectionObject> selection;
    TechDraw::DrawViewPart* objFeat;
    if (!_checkSelObjAndSubs(cmd, selection, objFeat, QT_TRANSLATE_NOOP("QObject","TechDraw Create Horizontal Chain Dimension"))) {
        return;
    }

    Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create Horizontal Chain Dimension"));
    const std::vector<std::string> subNames = selection[0].getSubNames();
    std::vector<dimVertex> allVertexes;
    allVertexes = _getVertexInfo(objFeat, subNames);
    if (!allVertexes.empty() && allVertexes.size() > 1) {
        std::sort(allVertexes.begin(), allVertexes.end(), sortX);
        float yMaster = 0.0;
        for (long unsigned int n = 0; n < allVertexes.size() - 1; n++) {
            TechDraw::DrawViewDimension* dim;
            dim = _createLinDimension(objFeat, allVertexes[n].name, allVertexes[n + 1].name, "DistanceX");
            TechDraw::pointPair pp = dim->getLinearPoints();
            Base::Vector3d mid = (pp.first() + pp.second()) / 2.0;
            dim->X.setValue(mid.x);
            if (n == 0)
                yMaster = -mid.y;
            dim->Y.setValue(yMaster);
        }
    }
    objFeat->refreshCEGeoms();
    objFeat->requestPaint();
    cmd->getSelection().clearSelection();
    Gui::Command::commitCommand();
}

DEF_STD_CMD_A(CmdTechDrawExtensionCreateHorizChainDimension)

CmdTechDrawExtensionCreateHorizChainDimension::CmdTechDrawExtensionCreateHorizChainDimension()
    : Command("TechDraw_ExtensionCreateHorizChainDimension")
{
    sAppModule      = "TechDraw";
    sGroup          = QT_TR_NOOP("TechDraw");
    sMenuText       = QT_TR_NOOP("Horizontal Chain Dimension");
    sToolTipText    = QT_TR_NOOP("Inserts a sequence of aligned horizontal dimensions to at least "
            "three selected vertices");
    sWhatsThis      = "TechDraw_ExtensionCreateHorizChainDimension";
    sStatusTip      = sMenuText;
    sPixmap         = "TechDraw_ExtensionCreateHorizChainDimension";
}

void CmdTechDrawExtensionCreateHorizChainDimension::activated(int iMsg)
{
    Q_UNUSED(iMsg);
    execCreateHorizChainDimension(this);
    //execSortieren(this);
}

bool CmdTechDrawExtensionCreateHorizChainDimension::isActive()
{
    bool havePage = DrawGuiUtil::needPage(this);
    bool haveView = DrawGuiUtil::needView(this);
    return (havePage && haveView);
}

//===========================================================================
// TechDraw_ExtensionCreateVertChainDimension
//===========================================================================

void execCreateVertChainDimension(Gui::Command* cmd) {
    //create a vertical chain dimension
    std::vector<Gui::SelectionObject> selection;
    TechDraw::DrawViewPart* objFeat;
    if (!_checkSelObjAndSubs(cmd, selection, objFeat, QT_TRANSLATE_NOOP("QObject","TechDraw Create Vertical Chain Dimension"))) {
        return;
    }

    Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create Vert Chain dimension"));
    const std::vector<std::string> subNames = selection[0].getSubNames();
    std::vector<dimVertex> allVertexes;
    allVertexes = _getVertexInfo(objFeat, subNames);
    if (!allVertexes.empty() && allVertexes.size() > 1) {
        std::sort(allVertexes.begin(), allVertexes.end(), sortY);
        float xMaster = 0.0;
        double fontSize = Preferences::dimFontSizeMM();
        for (long unsigned int n = 0; n < allVertexes.size() - 1; n++) {
            TechDraw::DrawViewDimension* dim;
            dim = _createLinDimension(objFeat, allVertexes[n].name, allVertexes[n + 1].name, "DistanceY");
            TechDraw::pointPair pp = dim->getLinearPoints();
            Base::Vector3d mid = (pp.first() + pp.second()) / 2.0;
            if (n == 0)
                xMaster = mid.x;
            dim->X.setValue(xMaster);
            dim->Y.setValue(-mid.y + 0.5 * fontSize);
        }
    }
    objFeat->refreshCEGeoms();
    objFeat->requestPaint();
    cmd->getSelection().clearSelection();
    Gui::Command::commitCommand();
}

DEF_STD_CMD_A(CmdTechDrawExtensionCreateVertChainDimension)

CmdTechDrawExtensionCreateVertChainDimension::CmdTechDrawExtensionCreateVertChainDimension()
    : Command("TechDraw_ExtensionCreateVertChainDimension")
{
    sAppModule      = "TechDraw";
    sGroup          = QT_TR_NOOP("TechDraw");
    sMenuText       = QT_TR_NOOP("Vertical Chain Dimension");
    sToolTipText    = QT_TR_NOOP("Inserts a sequence of aligned vertical dimensions to at least "
            "three selected vertices");
    sWhatsThis      = "TechDraw_ExtensionCreateVertChainDimension";
    sStatusTip      = sMenuText;
    sPixmap         = "TechDraw_ExtensionCreateVertChainDimension";
}

void CmdTechDrawExtensionCreateVertChainDimension::activated(int iMsg)
{
    Q_UNUSED(iMsg);
    execCreateVertChainDimension(this);
}

bool CmdTechDrawExtensionCreateVertChainDimension::isActive()
{
    bool havePage = DrawGuiUtil::needPage(this);
    bool haveView = DrawGuiUtil::needView(this);
    return (havePage && haveView);
}

//===========================================================================
// TechDraw_ExtensionCreateObliqueChainDimension
//===========================================================================

void execCreateObliqueChainDimension(Gui::Command* cmd) {
    // create an oblique chain dimension
    std::vector<Gui::SelectionObject> selection;
    TechDraw::DrawViewPart* objFeat;
    if (!_checkSelObjAndSubs(cmd, selection, objFeat, QT_TRANSLATE_NOOP("QObject","TechDraw Create Oblique Chain Dimension"))){
        return;
    }

    Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create oblique chain dimension"));

    std::vector<TechDraw::ReferenceEntry> refs;
    for (auto& subName : selection[0].getSubNames()) {
        refs.push_back(ReferenceEntry(objFeat, subName));
    }

    auto dims = makeObliqueChainDimension(refs);
    if(dims.empty()){
        Gui::Command::abortCommand();
    }
    else {
        objFeat->refreshCEGeoms();
        objFeat->requestPaint();
        cmd->getSelection().clearSelection();
        Gui::Command::commitCommand();
    }
}

std::vector<DrawViewDimension*> TechDrawGui::makeObliqueChainDimension(std::vector<TechDraw::ReferenceEntry> refs)
{
    if (refs.empty()) {
        return {};
    }

    std::vector<std::string> subNames;
    auto* objFeat = static_cast<DrawViewPart*>(refs[0].getObject());
    for (auto& ref : refs) {
        subNames.push_back(ref.getSubName());
    }
    std::vector<DrawViewDimension*> dims;

    std::vector<dimVertex> allVertexes, carrierVertexes;
    allVertexes = _getVertexInfo(objFeat, subNames);
    if (!allVertexes.empty() && allVertexes.size() > 1) {
        Base::Vector3d pMaster = allVertexes[0].point;
        Base::Vector3d dirMaster = pMaster - allVertexes[1].point;
        Base::Vector3d origin(0.0, 0.0, 0.0);
        Base::Vector3d delta = DrawUtil::getTrianglePoint(pMaster, dirMaster, origin);
        float dimDistance = activeDimAttributes.getCascadeSpacing();
        delta = delta.Normalize() * dimDistance;
        for (dimVertex& oldVertex : allVertexes) {
            Base::Vector3d nextPoint = DrawUtil::getTrianglePoint(pMaster, dirMaster, oldVertex.point);
            // nextPoint.y = -nextPoint.y;
            // oldVertex.point.y = -oldVertex.point.y;
            if ((oldVertex.point - nextPoint).Length() > 0.01) {
                Base::Vector3d cvPoint = CosmeticVertex::makeCanonicalPointInverted(objFeat, nextPoint);
                std::string vertTag = objFeat->addCosmeticVertex(cvPoint, false);
                int vertNumber = objFeat->add1CVToGV(vertTag);
                std::stringstream ss;
                ss << "Vertex" << vertNumber;
                dimVertex newVertex;
                newVertex.name = ss.str();
                newVertex.point = nextPoint;
                carrierVertexes.push_back(newVertex);
                Base::Vector3d oldCanon = CosmeticVertex::makeCanonicalPointInverted(objFeat, oldVertex.point);
                std::string edgeTag = objFeat->addCosmeticEdge(oldCanon, cvPoint);
                auto edge = objFeat->getCosmeticEdge(edgeTag);
                edge->m_format.setStyle(1);
                edge->m_format.setLineNumber(1);
                edge->m_format.setWidth(TechDraw::LineGroup::getDefaultWidth("Thin"));
                edge->m_format.setColor(Base::Color(0.0f, 0.0f, 0.0f));
            }
            else
                carrierVertexes.push_back(oldVertex);
        }
        std::sort(carrierVertexes.begin(), carrierVertexes.end(), sortX);
        double fontSize = Preferences::dimFontSizeMM();
        for (long unsigned int n = 0; n < allVertexes.size() - 1; n++) {
            TechDraw::DrawViewDimension* dim;
            dim = _createLinDimension(objFeat, carrierVertexes[n].name, carrierVertexes[n + 1].name, "Distance");
            TechDraw::pointPair pp = dim->getLinearPoints();
            Base::Vector3d mid = (pp.first() + pp.second()) / 2.0 + delta;
            dim->X.setValue(mid.x);
            dim->Y.setValue(-mid.y + 0.5 * fontSize);
            dims.push_back(dim);
        }
    }

    return dims;
}

DEF_STD_CMD_A(CmdTechDrawExtensionCreateObliqueChainDimension)

CmdTechDrawExtensionCreateObliqueChainDimension::CmdTechDrawExtensionCreateObliqueChainDimension()
    : Command("TechDraw_ExtensionCreateObliqueChainDimension")
{
    sAppModule      = "TechDraw";
    sGroup          = QT_TR_NOOP("TechDraw");
    sMenuText       = QT_TR_NOOP("Oblique Chain Dimension");
    sToolTipText    = QT_TR_NOOP("Inserts a sequence of aligned oblique dimensions to at least "
            "three selected vertices, where the first two define the direction");
    sWhatsThis      = "TechDraw_ExtensionCreateObliqueChainDimension";
    sStatusTip      = sMenuText;
    sPixmap         = "TechDraw_ExtensionCreateObliqueChainDimension";
}

void CmdTechDrawExtensionCreateObliqueChainDimension::activated(int iMsg)
{
    Q_UNUSED(iMsg);
    execCreateObliqueChainDimension(this);
}

bool CmdTechDrawExtensionCreateObliqueChainDimension::isActive()
{
    bool havePage = DrawGuiUtil::needPage(this);
    bool haveView = DrawGuiUtil::needView(this);
    return (havePage && haveView);
}

//===========================================================================
// TechDraw_ExtensionCreateChainDimensionGroup
//===========================================================================

DEF_STD_CMD_ACL(CmdTechDrawExtensionCreateChainDimensionGroup)

CmdTechDrawExtensionCreateChainDimensionGroup::CmdTechDrawExtensionCreateChainDimensionGroup()
    : Command("TechDraw_ExtensionCreateChainDimensionGroup")
{
    sAppModule      = "TechDraw";
    sGroup          = QT_TR_NOOP("TechDraw");
    sMenuText       = QT_TR_NOOP("Horizontal Chain Dimension");
    sToolTipText    = QT_TR_NOOP("Inserts a sequence of aligned horizontal dimensions to at least "
            "three selected vertices, where the first two define the direction");
    sWhatsThis      = "TechDraw_ExtensionCreateChainDimensionGroup";
    sStatusTip      = sMenuText;
}

void CmdTechDrawExtensionCreateChainDimensionGroup::activated(int iMsg)
{
    //    Base::Console().message("CMD::ExtensionCascadeDimansionGroup - activated(%d)\n", iMsg);
    Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog();
    if (dlg) {
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task in progress"),
            QObject::tr("Close active task dialog and try again"));
        return;
    }

    Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
    pcAction->setIcon(pcAction->actions().at(iMsg)->icon());
    switch (iMsg) {
    case 0:                 //create horizontal chain dimensions
        execCreateHorizChainDimension(this);
        break;
    case 1:                 //create vertical chain dimensions
        execCreateVertChainDimension(this);
        break;
    case 2:                 //create oblique chain dimensions
        execCreateObliqueChainDimension(this);
        break;
    default:
        Base::Console().message("CMD::CVGrp - invalid iMsg: %d\n", iMsg);
    };
}

Gui::Action* CmdTechDrawExtensionCreateChainDimensionGroup::createAction()
{
    Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow());
    pcAction->setDropDownMenu(true);
    applyCommandData(this->className(), pcAction);

    QAction* p1 = pcAction->addAction(QString());
    p1->setIcon(Gui::BitmapFactory().iconFromTheme("TechDraw_ExtensionCreateHorizChainDimension"));
    p1->setObjectName(QStringLiteral("TechDraw_ExtensionCreateHorizChainDimension"));
    p1->setWhatsThis(QStringLiteral("TechDraw_ExtensionCreateHorizChainDimension"));
    QAction* p2 = pcAction->addAction(QString());
    p2->setIcon(Gui::BitmapFactory().iconFromTheme("TechDraw_ExtensionCreateVertChainDimension"));
    p2->setObjectName(QStringLiteral("TechDraw_ExtensionCreateVertChainDimension"));
    p2->setWhatsThis(QStringLiteral("TechDraw_ExtensionCreateVertChainDimension"));
    QAction* p3 = pcAction->addAction(QString());
    p3->setIcon(Gui::BitmapFactory().iconFromTheme("TechDraw_ExtensionCreateObliqueChainDimension"));
    p3->setObjectName(QStringLiteral("TechDraw_ExtensionCreateObliqueChainDimension"));
    p3->setWhatsThis(QStringLiteral("TechDraw_ExtensionCreateObliqueChainDimension"));

    _pcAction = pcAction;
    languageChange();

    pcAction->setIcon(p1->icon());
    int defaultId = 0;
    pcAction->setProperty("defaultAction", QVariant(defaultId));

    return pcAction;
}

void CmdTechDrawExtensionCreateChainDimensionGroup::languageChange()
{
    Command::languageChange();

    if (!_pcAction)
        return;
    Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
    QList<QAction*> a = pcAction->actions();

    QAction* arc1 = a[0];
    arc1->setText(QApplication::translate("CmdTechDrawExtensionCreateHorizChainDimension", "Horizontal Chain Dimension"));
    arc1->setToolTip(QApplication::translate("CmdTechDrawExtensionCreateHorizChainDimension",
"Inserts a sequence of aligned horizontal dimensions to at least three selected vertices, where the first two define the direction"));
    arc1->setStatusTip(arc1->text());
    QAction* arc2 = a[1];
    arc2->setText(QApplication::translate("CmdTechDrawExtensionCreateVertChainDimension", "Vertical Chain Dimension"));
    arc2->setToolTip(QApplication::translate("CmdTechDrawExtensionCreateVertChainDimension",
"Inserts a sequence of aligned vertical dimensions to at least three selected vertices, where the first two define the direction"));
    arc2->setStatusTip(arc2->text());
    QAction* arc3 = a[2];
    arc3->setText(QApplication::translate("CmdTechDrawExtensionCreateObliqueChainDimension", "Oblique Chain Dimension"));
    arc3->setToolTip(QApplication::translate("CmdTechDrawExtensionCreateObliqueChainDimension",
"Inserts a sequence of aligned oblique dimensions to at least three selected vertices, where the first two define the direction"));
    arc3->setStatusTip(arc3->text());
}

bool CmdTechDrawExtensionCreateChainDimensionGroup::isActive()
{
    bool havePage = DrawGuiUtil::needPage(this);
    bool haveView = DrawGuiUtil::needView(this, true);
    return (havePage && haveView);
}

//===========================================================================
// TechDraw_ExtensionCreateHorizCoordDimension
//===========================================================================

void execCreateHorizCoordDimension(Gui::Command* cmd) {
    //create horizontal coordinate dimensions
    std::vector<Gui::SelectionObject> selection;
    TechDraw::DrawViewPart* objFeat;
    if (!_checkSelObjAndSubs(cmd, selection, objFeat, QT_TRANSLATE_NOOP("QObject","TechDraw Create Horizontal Coordinate Dimension"))) {
        return;
    }

    Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create Horizontal Coord Dimension"));
    const std::vector<std::string> subNames = selection[0].getSubNames();
    std::vector<dimVertex> allVertexes;
    allVertexes = _getVertexInfo(objFeat, subNames);
    if (!allVertexes.empty() && allVertexes.size() > 1) {
        dimVertex firstVertex = allVertexes[0];
        dimVertex secondVertex = allVertexes[1];
        std::sort(allVertexes.begin(), allVertexes.end(), sortX);
        if (firstVertex.point.x > secondVertex.point.x) {
            std::reverse(allVertexes.begin(), allVertexes.end());
        }
        float dimDistance = activeDimAttributes.getCascadeSpacing();
        float yMaster = allVertexes[0].point.y - dimDistance;
        if (std::signbit(yMaster))
            dimDistance = -dimDistance;
        for (long unsigned int n = 0; n < allVertexes.size() - 1; n++) {
            TechDraw::DrawViewDimension* dim;
            dim = _createLinDimension(objFeat, allVertexes[0].name, allVertexes[n + 1].name, "DistanceX");
            TechDraw::pointPair pp = dim->getLinearPoints();
            Base::Vector3d mid = (pp.first() + pp.second()) / 2.0;
            dim->X.setValue(mid.x);
            dim->Y.setValue(-yMaster - dimDistance * n);
        }
    }
    objFeat->refreshCEGeoms();
    objFeat->requestPaint();
    cmd->getSelection().clearSelection();
    Gui::Command::commitCommand();
}

DEF_STD_CMD_A(CmdTechDrawExtensionCreateHorizCoordDimension)

CmdTechDrawExtensionCreateHorizCoordDimension::CmdTechDrawExtensionCreateHorizCoordDimension()
    : Command("TechDraw_ExtensionCreateHorizCoordDimension")
{
    sAppModule      = "TechDraw";
    sGroup          = QT_TR_NOOP("TechDraw");
    sMenuText       = QT_TR_NOOP("Horizontal Coordinate Dimension");
    sToolTipText    = QT_TR_NOOP("Adds evenly spaced horizontal dimensions between 3 or more vertices aligned to a shared baseline");
    sWhatsThis      = "TechDraw_ExtensionCreateHorizCoordDimension";
    sStatusTip      = sMenuText;
    sPixmap         = "TechDraw_ExtensionCreateHorizCoordDimension";
}

void CmdTechDrawExtensionCreateHorizCoordDimension::activated(int iMsg)
{
    Q_UNUSED(iMsg);
    execCreateHorizCoordDimension(this);
}

bool CmdTechDrawExtensionCreateHorizCoordDimension::isActive()
{
    bool havePage = DrawGuiUtil::needPage(this);
    bool haveView = DrawGuiUtil::needView(this);
    return (havePage && haveView);
}

//===========================================================================
// TechDraw_ExtensionCreateVertCoordDimension
//===========================================================================

void execCreateVertCoordDimension(Gui::Command* cmd) {
    //create vertical coordinate dimensions
    std::vector<Gui::SelectionObject> selection;
    TechDraw::DrawViewPart* objFeat;
    if (!_checkSelObjAndSubs(cmd, selection, objFeat, QT_TRANSLATE_NOOP("QObject","TechDraw Create Vertical Coord dimension"))) {
        return;
    }
    Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create vert coord dimension"));
    const std::vector<std::string> subNames = selection[0].getSubNames();
    std::vector<dimVertex> allVertexes;
    allVertexes = _getVertexInfo(objFeat, subNames);
    if (!allVertexes.empty() && allVertexes.size() > 1) {
        dimVertex firstVertex = allVertexes[0];
        dimVertex secondVertex = allVertexes[1];
        std::sort(allVertexes.begin(), allVertexes.end(), sortY);
        if (firstVertex.point.y > secondVertex.point.y) {
            std::reverse(allVertexes.begin(), allVertexes.end());
        }
        float dimDistance = activeDimAttributes.getCascadeSpacing();
        float xMaster = allVertexes[0].point.x + dimDistance;
        if (std::signbit(xMaster))
            dimDistance = -dimDistance;
        double fontSize = Preferences::dimFontSizeMM();
        for (long unsigned int n = 0; n < allVertexes.size() - 1; n++) {
            TechDraw::DrawViewDimension* dim;
            dim = _createLinDimension(objFeat, allVertexes[0].name, allVertexes[n + 1].name, "DistanceY");
            TechDraw::pointPair pp = dim->getLinearPoints();
            Base::Vector3d mid = (pp.first() + pp.second()) / 2.0;
            dim->X.setValue(xMaster + dimDistance * n);
            dim->Y.setValue(-mid.y + 0.5 * fontSize);
        }
    }
    objFeat->refreshCEGeoms();
    objFeat->requestPaint();
    cmd->getSelection().clearSelection();
    Gui::Command::commitCommand();
}

DEF_STD_CMD_A(CmdTechDrawExtensionCreateVertCoordDimension)

CmdTechDrawExtensionCreateVertCoordDimension::CmdTechDrawExtensionCreateVertCoordDimension()
    : Command("TechDraw_ExtensionCreateVertCoordDimension")
{
    sAppModule      = "TechDraw";
    sGroup          = QT_TR_NOOP("TechDraw");
    sMenuText       = QT_TR_NOOP("Vertical Coordinate Dimension");
    sToolTipText    = QT_TR_NOOP("Adds evenly spaced vertical dimensions between 3 or more vertices aligned to a shared baseline");
    sWhatsThis      = "TechDraw_ExtensionCreateVertCoordDimension";
    sStatusTip      = sMenuText;
    sPixmap         = "TechDraw_ExtensionCreateVertCoordDimension";
}

void CmdTechDrawExtensionCreateVertCoordDimension::activated(int iMsg)
{
    Q_UNUSED(iMsg);
    execCreateVertCoordDimension(this);
}

bool CmdTechDrawExtensionCreateVertCoordDimension::isActive()
{
    bool havePage = DrawGuiUtil::needPage(this);
    bool haveView = DrawGuiUtil::needView(this);
    return (havePage && haveView);
}

//===========================================================================
// TechDraw_ExtensionCreateObliqueCoordDimension
//===========================================================================

void execCreateObliqueCoordDimension(Gui::Command* cmd) {
    //create oblique coordinate dimensions
    std::vector<Gui::SelectionObject> selection;
    TechDraw::DrawViewPart* objFeat{nullptr};
    if (!_checkSelObjAndSubs(cmd, selection, objFeat, QT_TRANSLATE_NOOP("QObject","TechDraw Create Oblique Coord Dimension"))) {
        return;
    }

    Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create oblique coord dimension"));

    std::vector<TechDraw::ReferenceEntry> refs;
    for (auto& subName : selection[0].getSubNames()) {
        refs.push_back(ReferenceEntry(objFeat, subName));
    }

    auto dims = makeObliqueCoordDimension(refs);
    if (dims.empty()) {
        Gui::Command::abortCommand();
    }
    else {
        objFeat->refreshCEGeoms();
        objFeat->requestPaint();
        cmd->getSelection().clearSelection();
        Gui::Command::commitCommand();
    }
}

std::vector<DrawViewDimension*> TechDrawGui::makeObliqueCoordDimension(std::vector<TechDraw::ReferenceEntry> refs)
{
    if (refs.empty()) {
        return {};
    }

    std::vector<std::string> subNames;
    auto* objFeat = static_cast<DrawViewPart*>(refs[0].getObject());
    for (auto& ref : refs) {
        subNames.push_back(ref.getSubName());
    }
    std::vector<DrawViewDimension*> dims;

    std::vector<dimVertex> allVertexes, carrierVertexes;
    allVertexes = _getVertexInfo(objFeat, subNames);
    if (!allVertexes.empty() && allVertexes.size() > 1) {
        Base::Vector3d pMaster = allVertexes[0].point;
        Base::Vector3d dirMaster = pMaster - allVertexes[1].point;
        Base::Vector3d origin(0.0, 0.0, 0.0);
        Base::Vector3d delta = DrawUtil::getTrianglePoint(pMaster, dirMaster, origin);
        float dimDistance = activeDimAttributes.getCascadeSpacing();
        delta = delta.Normalize() * dimDistance;
        for (dimVertex& oldVertex : allVertexes) {
            Base::Vector3d nextPoint = DrawUtil::getTrianglePoint(pMaster, dirMaster, oldVertex.point);
            if ((oldVertex.point - nextPoint).Length() > 0.01) {
                Base::Vector3d cvPoint = CosmeticVertex::makeCanonicalPointInverted(objFeat, nextPoint);
                std::string vertTag = objFeat->addCosmeticVertex(cvPoint, false);
                int vertNumber = objFeat->add1CVToGV(vertTag);
                std::stringstream ss;
                ss << "Vertex" << vertNumber;
                dimVertex newVertex;
                newVertex.name = ss.str();
                newVertex.point = nextPoint;
                carrierVertexes.push_back(newVertex);
                Base::Vector3d oldCanon = CosmeticVertex::makeCanonicalPointInverted(objFeat, oldVertex.point);
                std::string edgeTag = objFeat->addCosmeticEdge(oldCanon, cvPoint);
                auto edge = objFeat->getCosmeticEdge(edgeTag);
                edge->m_format.setStyle(1);
                edge->m_format.setLineNumber(1);
                edge->m_format.setWidth(TechDraw::LineGroup::getDefaultWidth("Thin"));
                edge->m_format.setColor(Base::Color(0.0, 0.0, 0.0));
            }
            else {
                carrierVertexes.push_back(oldVertex);
            }
        }
        dimVertex firstVertex = carrierVertexes[0];
        dimVertex secondVertex = carrierVertexes[1];
        std::sort(carrierVertexes.begin(), carrierVertexes.end(), sortX);
        if (firstVertex.point.x > secondVertex.point.x) {
            std::reverse(carrierVertexes.begin(), carrierVertexes.end());
        }
        double fontSize = Preferences::dimFontSizeMM();
        for (long unsigned int n = 0; n < allVertexes.size() - 1; n++) {
            TechDraw::DrawViewDimension* dim;
            dim = _createLinDimension(objFeat, carrierVertexes[0].name, carrierVertexes[n + 1].name, "Distance");
            TechDraw::pointPair pp = dim->getLinearPoints();
            Base::Vector3d mid = (pp.first() + pp.second()) / 2.0 + delta * (n + 1);
            dim->X.setValue(mid.x);
            dim->Y.setValue(-mid.y + 0.5 * fontSize);
            dims.push_back(dim);
        }
    }

    return dims;
}

DEF_STD_CMD_A(CmdTechDrawExtensionCreateObliqueCoordDimension)

CmdTechDrawExtensionCreateObliqueCoordDimension::CmdTechDrawExtensionCreateObliqueCoordDimension()
    : Command("TechDraw_ExtensionCreateObliqueCoordDimension")
{
    sAppModule      = "TechDraw";
    sGroup          = QT_TR_NOOP("TechDraw");
    sMenuText       = QT_TR_NOOP("Oblique Coordinate Dimension");
    sToolTipText    = QT_TR_NOOP("Adds evenly spaced oblique dimensions between 3 or more vertices aligned to a shared baseline");
    sWhatsThis      = "TechDraw_ExtensionCreateObliqueCoordDimension";
    sStatusTip      = sMenuText;
    sPixmap         = "TechDraw_ExtensionCreateObliqueCoordDimension";
}

void CmdTechDrawExtensionCreateObliqueCoordDimension::activated(int iMsg)
{
    Q_UNUSED(iMsg);
    execCreateObliqueCoordDimension(this);
}

bool CmdTechDrawExtensionCreateObliqueCoordDimension::isActive()
{
    bool havePage = DrawGuiUtil::needPage(this);
    bool haveView = DrawGuiUtil::needView(this);
    return (havePage && haveView);
}

//===========================================================================
// TechDraw_ExtensionCreateCoordDimensionGroup
//===========================================================================

DEF_STD_CMD_ACL(CmdTechDrawExtensionCreateCoordDimensionGroup)

CmdTechDrawExtensionCreateCoordDimensionGroup::CmdTechDrawExtensionCreateCoordDimensionGroup()
    : Command("TechDraw_ExtensionCreateCoordDimensionGroup")
{
    sAppModule      = "TechDraw";
    sGroup          = QT_TR_NOOP("TechDraw");
    sMenuText       = QT_TR_NOOP("Horizontal Coordinate Dimension");
    sToolTipText    = QT_TR_NOOP("Adds evenly spaced horizontal dimensions between 3 or more vertices aligned to a shared baseline");
    sWhatsThis      = "TechDraw_ExtensionCreateCoordDimensionGroup";
    sStatusTip      = sMenuText;
}

void CmdTechDrawExtensionCreateCoordDimensionGroup::activated(int iMsg)
{
    //    Base::Console().message("CMD::ExtensionCascadeDimansionGroup - activated(%d)\n", iMsg);
    Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog();
    if (dlg) {
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task in progress"),
            QObject::tr("Close active task dialog and try again"));
        return;
    }

    Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
    pcAction->setIcon(pcAction->actions().at(iMsg)->icon());
    switch (iMsg) {
    case 0:                 //create horizontal coordinate dimensions
        execCreateHorizCoordDimension(this);
        break;
    case 1:                 //create vertical coordinate dimensions
        execCreateVertCoordDimension(this);
        break;
    case 2:                 //create oblique coordinate dimensions
        execCreateObliqueCoordDimension(this);
        break;
    default:
        Base::Console().message("CMD::CVGrp - invalid iMsg: %d\n", iMsg);
    };
}

Gui::Action* CmdTechDrawExtensionCreateCoordDimensionGroup::createAction()
{
    Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow());
    pcAction->setDropDownMenu(true);
    applyCommandData(this->className(), pcAction);

    QAction* p1 = pcAction->addAction(QString());
    p1->setIcon(Gui::BitmapFactory().iconFromTheme("TechDraw_ExtensionCreateHorizCoordDimension"));
    p1->setObjectName(QStringLiteral("TechDraw_ExtensionCreateHorizCoordDimension"));
    p1->setWhatsThis(QStringLiteral("TechDraw_ExtensionCreateHorizCoordDimension"));
    QAction* p2 = pcAction->addAction(QString());
    p2->setIcon(Gui::BitmapFactory().iconFromTheme("TechDraw_ExtensionCreateVertCoordDimension"));
    p2->setObjectName(QStringLiteral("TechDraw_ExtensionCreateVertCoordDimension"));
    p2->setWhatsThis(QStringLiteral("TechDraw_ExtensionCreateVertCoordDimension"));
    QAction* p3 = pcAction->addAction(QString());
    p3->setIcon(Gui::BitmapFactory().iconFromTheme("TechDraw_ExtensionCreateObliqueCoordDimension"));
    p3->setObjectName(QStringLiteral("TechDraw_ExtensionCreateObliqueCoordDimension"));
    p3->setWhatsThis(QStringLiteral("TechDraw_ExtensionCreateObliqueCoordDimension"));

    _pcAction = pcAction;
    languageChange();

    pcAction->setIcon(p1->icon());
    int defaultId = 0;
    pcAction->setProperty("defaultAction", QVariant(defaultId));

    return pcAction;
}

void CmdTechDrawExtensionCreateCoordDimensionGroup::languageChange()
{
    Command::languageChange();

    if (!_pcAction)
        return;
    Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
    QList<QAction*> a = pcAction->actions();

    QAction* arc1 = a[0];
    arc1->setText(QApplication::translate("CmdTechDrawExtensionCreateHorizCoordDimension", "Horizontal Coordinate Dimension"));
    arc1->setToolTip(QApplication::translate("CmdTechDrawExtensionCreateHorizCoordDimension",
"Adds evenly spaced horizontal dimensions between 3 or more vertices aligned to a shared baseline"));
    arc1->setStatusTip(arc1->text());
    QAction* arc2 = a[1];
    arc2->setText(QApplication::translate("CmdTechDrawExtensionCreateVertCoordDimension", "Vertical Coordinate Dimension"));
    arc2->setToolTip(QApplication::translate("CmdTechDrawExtensionCreateVertCoordDimension",
"Adds evenly spaced vertical dimensions between 3 or more vertices aligned to a shared baseline"));
    arc2->setStatusTip(arc2->text());
    QAction* arc3 = a[2];
    arc3->setText(QApplication::translate("CmdTechDrawExtensionCreateObliqueCoordDimension", "Oblique Coordinate Dimension"));
    arc3->setToolTip(QApplication::translate("CmdTechDrawExtensionCreateObliqueCoordDimension",
"Adds evenly spaced oblique dimensions between 3 or more vertices aligned to a shared baseline"));
    arc3->setStatusTip(arc3->text());
}

bool CmdTechDrawExtensionCreateCoordDimensionGroup::isActive()
{
    bool havePage = DrawGuiUtil::needPage(this);
    bool haveView = DrawGuiUtil::needView(this, true);
    return (havePage && haveView);
}

//===========================================================================
// TechDraw_ExtensionCreateHorizChamferDimension
//===========================================================================

void execCreateHorizChamferDimension(Gui::Command* cmd) {
    //create a horizontal chamfer dimension
    std::vector<Gui::SelectionObject> selection;
    TechDraw::DrawViewPart* objFeat;
    if (!_checkSelObjAndSubs(cmd, selection, objFeat, QT_TRANSLATE_NOOP("QObject","TechDraw Create Horizontal Chamfer Dimension"))) {
        return;
    }

    Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create Horizontal Chamfer Dimension"));
    const std::vector<std::string> subNames = selection[0].getSubNames();
    std::vector<dimVertex> allVertexes;
    allVertexes = _getVertexInfo(objFeat, subNames);
    if (!allVertexes.empty() && allVertexes.size() > 1) {
        TechDraw::DrawViewDimension* dim;
        dim = _createLinDimension(objFeat, allVertexes[0].name, allVertexes[1].name, "DistanceX");
        float yMax = std::max(abs(allVertexes[0].point.y), abs(allVertexes[1].point.y)) + 7.0;
        if (std::signbit(allVertexes[0].point.y))
            yMax = -yMax;
        TechDraw::pointPair pp = dim->getLinearPoints();
        Base::Vector3d mid = (pp.first() + pp.second()) / 2.0;
        dim->X.setValue(mid.x);
        dim->Y.setValue(-yMax);
        float dx = allVertexes[0].point.x - allVertexes[1].point.x;
        float dy = allVertexes[0].point.y - allVertexes[1].point.y;
        float alpha = std::round(Base::toDegrees(std::abs<float>(std::atan(dy / dx))));
        std::string sAlpha = std::to_string((int)alpha);
        std::string formatSpec = dim->FormatSpec.getStrValue();
        formatSpec = formatSpec + " x" + sAlpha + "°";
        dim->FormatSpec.setValue(formatSpec);
        objFeat->requestPaint();
        cmd->getSelection().clearSelection();
    }
    Gui::Command::commitCommand();
}

DEF_STD_CMD_A(CmdTechDrawExtensionCreateHorizChamferDimension)

CmdTechDrawExtensionCreateHorizChamferDimension::CmdTechDrawExtensionCreateHorizChamferDimension()
    : Command("TechDraw_ExtensionCreateHorizChamferDimension")
{
    sAppModule      = "TechDraw";
    sGroup          = QT_TR_NOOP("TechDraw");
    sMenuText       = QT_TR_NOOP("Horizontal Chamfer Dimension");
    sToolTipText    = QT_TR_NOOP("Inserts a horizontal size and angle dimension for a chamfer from 2 selected vertices");
    sWhatsThis      = "TechDraw_ExtensionCreateHorizChamferDimension";
    sStatusTip      = sMenuText;
    sPixmap         = "TechDraw_ExtensionCreateHorizChamferDimension";
}

void CmdTechDrawExtensionCreateHorizChamferDimension::activated(int iMsg)
{
    Q_UNUSED(iMsg);
    execCreateHorizChamferDimension(this);
}

bool CmdTechDrawExtensionCreateHorizChamferDimension::isActive()
{
    bool havePage = DrawGuiUtil::needPage(this);
    bool haveView = DrawGuiUtil::needView(this);
    return (havePage && haveView);
}

//===========================================================================
// TechDraw_ExtensionCreateVertChamferDimension
//===========================================================================

void execCreateVertChamferDimension(Gui::Command* cmd) {
    //create a vertical chamfer dimension
    std::vector<Gui::SelectionObject> selection;
    TechDraw::DrawViewPart* objFeat;
    if (!_checkSelObjAndSubs(cmd, selection, objFeat, QT_TRANSLATE_NOOP("QObject","TechDraw Create Vertical Chamfer Dimension"))) {
        return;
    }

    Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create Vert Chamfer Dimension"));
    const std::vector<std::string> subNames = selection[0].getSubNames();
    std::vector<dimVertex> allVertexes;
    allVertexes = _getVertexInfo(objFeat, subNames);
    if (!allVertexes.empty() && allVertexes.size() > 1) {
        TechDraw::DrawViewDimension* dim;
        dim = _createLinDimension(objFeat, allVertexes[0].name, allVertexes[1].name, "DistanceY");
        float xMax = std::max(abs(allVertexes[0].point.x), abs(allVertexes[1].point.x)) + 7.0;
        if (std::signbit(allVertexes[0].point.x))
            xMax = -xMax;
        TechDraw::pointPair pp = dim->getLinearPoints();
        Base::Vector3d mid = (pp.first() + pp.second()) / 2.0;
        dim->X.setValue(xMax);
        dim->Y.setValue(-mid.y);
        float dx = allVertexes[0].point.x - allVertexes[1].point.x;
        float dy = allVertexes[0].point.y - allVertexes[1].point.y;
        float alpha = std::round(Base::toDegrees(std::abs<float>(std::atan(dx / dy))));
        std::string sAlpha = std::to_string((int)alpha);
        std::string formatSpec = dim->FormatSpec.getStrValue();
        formatSpec = formatSpec + " x" + sAlpha + "°";
        dim->FormatSpec.setValue(formatSpec);
        objFeat->requestPaint();
        cmd->getSelection().clearSelection();
    }
    Gui::Command::commitCommand();
}

DEF_STD_CMD_A(CmdTechDrawExtensionCreateVertChamferDimension)

CmdTechDrawExtensionCreateVertChamferDimension::CmdTechDrawExtensionCreateVertChamferDimension()
    : Command("TechDraw_ExtensionCreateVertChamferDimension")
{
    sAppModule      = "TechDraw";
    sGroup          = QT_TR_NOOP("TechDraw");
    sMenuText       = QT_TR_NOOP("Vertical Chamfer Dimension");
    sToolTipText    = QT_TR_NOOP("Inserts a vertical size and angle dimension for a chamfer from 2 selected vertices");
    sWhatsThis      = "TechDraw_ExtensionCreateVertChamferDimension";
    sStatusTip      = sMenuText;
    sPixmap         = "TechDraw_ExtensionCreateVertChamferDimension";
}

void CmdTechDrawExtensionCreateVertChamferDimension::activated(int iMsg)
{
    Q_UNUSED(iMsg);
    execCreateVertChamferDimension(this);
}

bool CmdTechDrawExtensionCreateVertChamferDimension::isActive()
{
    bool havePage = DrawGuiUtil::needPage(this);
    bool haveView = DrawGuiUtil::needView(this);
    return (havePage && haveView);
}

//===========================================================================
// TechDraw_ExtensionChamferDimensionGroup
//===========================================================================

DEF_STD_CMD_ACL(CmdTechDrawExtensionChamferDimensionGroup)

CmdTechDrawExtensionChamferDimensionGroup::CmdTechDrawExtensionChamferDimensionGroup()
    : Command("TechDraw_ExtensionChamferDimensionGroup")
{
    sAppModule      = "TechDraw";
    sGroup          = QT_TR_NOOP("TechDraw");
    sMenuText       = QT_TR_NOOP("Horizontal Chamfer Dimension");
    sToolTipText    = QT_TR_NOOP("Inserts a horizontal size and angle dimension for a chamfer from 2 selected vertices");
    sWhatsThis      = "TechDraw_ExtensionChamferDimensionGroup";
    sStatusTip      = sMenuText;
}

void CmdTechDrawExtensionChamferDimensionGroup::activated(int iMsg)
{
    //    Base::Console().message("CMD::ExtensionIncreaseDecreaseGroup - activated(%d)\n", iMsg);
    Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog();
    if (dlg) {
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task in progress"),
            QObject::tr("Close active task dialog and try again"));
        return;
    }

    Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
    pcAction->setIcon(pcAction->actions().at(iMsg)->icon());
    switch (iMsg) {
    case 0:                 //create a horizontal chamfer dimension
        execCreateHorizChamferDimension(this);
        break;
    case 1:                 //create a vertical chamfer dimension
        execCreateVertChamferDimension(this);
        break;
    default:
        Base::Console().message("CMD::CVGrp - invalid iMsg: %d\n", iMsg);
    };
}

Gui::Action* CmdTechDrawExtensionChamferDimensionGroup::createAction()
{
    Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow());
    pcAction->setDropDownMenu(true);
    applyCommandData(this->className(), pcAction);

    QAction* p1 = pcAction->addAction(QString());
    p1->setIcon(Gui::BitmapFactory().iconFromTheme("TechDraw_ExtensionCreateHorizChamferDimension"));
    p1->setObjectName(QStringLiteral("TechDraw_ExtensionCreateHorizChamferDimension"));
    p1->setWhatsThis(QStringLiteral("TechDraw_ExtensionCreateHorizChamferDimension"));
    QAction* p2 = pcAction->addAction(QString());
    p2->setIcon(Gui::BitmapFactory().iconFromTheme("TechDraw_ExtensionCreateVertChamferDimension"));
    p2->setObjectName(QStringLiteral("TechDraw_ExtensionCreateVertChamferDimension"));
    p2->setWhatsThis(QStringLiteral("TechDraw_ExtensionCreateVertChamferDimension"));

    _pcAction = pcAction;
    languageChange();

    pcAction->setIcon(p1->icon());
    int defaultId = 0;
    pcAction->setProperty("defaultAction", QVariant(defaultId));

    return pcAction;
}

void CmdTechDrawExtensionChamferDimensionGroup::languageChange()
{
    Command::languageChange();

    if (!_pcAction)
        return;
    Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
    QList<QAction*> a = pcAction->actions();

    QAction* arc1 = a[0];
    arc1->setText(QApplication::translate("CmdTechDrawExtensionCreateHorizChamferDimension", "Horizontal Chamfer Dimension"));
    arc1->setToolTip(QApplication::translate("CmdTechDrawExtensionCreateHorizChamferDimension",
"Inserts a horizontal size and angle dimension for a chamfer from 2 selected vertices"));
    arc1->setStatusTip(arc1->text());
    QAction* arc2 = a[1];
    arc2->setText(QApplication::translate("CmdTechDrawExtensionCreateVertChamferDimension", "Vertical Chamfer Dimension"));
    arc2->setToolTip(QApplication::translate("CmdTechDrawExtensionCreateVertChamferDimension",
"Inserts a vertical size and angle dimension for a chamfer from 2 selected vertices"));
    arc2->setStatusTip(arc2->text());
}

bool CmdTechDrawExtensionChamferDimensionGroup::isActive()
{
    bool havePage = DrawGuiUtil::needPage(this);
    bool haveView = DrawGuiUtil::needView(this, true);
    return (havePage && haveView);
}

//===========================================================================
// TechDraw_ExtensionCreateLengthArc
//===========================================================================

DEF_STD_CMD_A(CmdTechDrawExtensionCreateLengthArc)

CmdTechDrawExtensionCreateLengthArc::CmdTechDrawExtensionCreateLengthArc()
    : Command("TechDraw_ExtensionCreateLengthArc")
{
    sAppModule      = "TechDraw";
    sGroup          = QT_TR_NOOP("TechDraw");
    sMenuText       = QT_TR_NOOP("Arc Length Dimension");
    sToolTipText    = QT_TR_NOOP("Inserts an arc length dimension to the selected arc");
    sWhatsThis      = "TechDraw_ExtensionCreateLengthArc";
    sStatusTip      = sMenuText;
    sPixmap         = "TechDraw_ExtensionCreateLengthArc";
}

void CmdTechDrawExtensionCreateLengthArc::activated(int iMsg) {
    // create arc length dimension
    Q_UNUSED(iMsg);
    std::vector<Gui::SelectionObject> selection;
    TechDraw::DrawViewPart* objFeat;
    if (!_checkSelObjAndSubs(this, selection, objFeat, QT_TRANSLATE_NOOP("QObject","TechDraw Create Arc Length Dimension"))) {
        return;
    }

    Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create Arc Length Dimension"));
    ReferenceEntry ref(objFeat, selection[0].getSubNames()[0]);

    TechDraw::DrawViewDimension* dim = makeArcLengthDimension(ref);

    if (dim) {
        objFeat->refreshCEGeoms();
        objFeat->requestPaint();
        Gui::Command::commitCommand();
    }
    else {
        Gui::Command::abortCommand();
    }
}

bool CmdTechDrawExtensionCreateLengthArc::isActive()
{
    bool havePage = DrawGuiUtil::needPage(this);
    bool haveView = DrawGuiUtil::needView(this);
    return (havePage && haveView);
}

//===========================================================================
// TechDraw_ExtensionCustomizeFormat
//===========================================================================

DEF_STD_CMD_A(CmdTechDrawExtensionCustomizeFormat)

CmdTechDrawExtensionCustomizeFormat::CmdTechDrawExtensionCustomizeFormat()
  : Command("TechDraw_ExtensionCustomizeFormat")
{
    sAppModule      = "TechDraw";
    sGroup          = QT_TR_NOOP("TechDraw");
    sMenuText       = QT_TR_NOOP("Customize Format Label");
    sToolTipText    = QT_TR_NOOP("Customizes the format label of a selected dimension or balloon");
    sWhatsThis      = "TechDraw_ExtensionCustomizeFormat";
    sStatusTip      = sToolTipText;
    sPixmap         = "TechDraw_ExtensionCustomizeFormat";
}

void CmdTechDrawExtensionCustomizeFormat::activated(int iMsg)
{
    Q_UNUSED(iMsg);
    std::vector<Gui::SelectionObject> selected;
    if (!_checkSelection(this, selected, QT_TRANSLATE_NOOP("QObject","TechDraw Customize Format")))
        return;
    auto object = selected[0].getObject();
    if (object->isDerivedFrom<TechDraw::DrawViewDimension>() ||
        object->isDerivedFrom<TechDraw::DrawViewBalloon>())
        Gui::Control().showDialog(new TaskDlgCustomizeFormat(object));
}

bool CmdTechDrawExtensionCustomizeFormat::isActive()
{
    bool havePage = DrawGuiUtil::needPage(this);
    bool haveView = DrawGuiUtil::needView(this);
    return (havePage && haveView);
}

DrawViewDimension* TechDrawGui::makeArcLengthDimension(const ReferenceEntry& ref)
{
    DrawViewDimension* dim = nullptr;
    auto* dvp = static_cast<DrawViewPart*>(ref.getObject());

    int geoId = DrawUtil::getIndexFromName(ref.getSubName());
    BaseGeomPtr geom = dvp->getGeomByIndex(geoId);

    // Find the edge length.
    TechDraw::BaseGeomPtr edge = dvp->getEdge(ref.getSubName());
    if (!edge) {
        return nullptr;
    }
    GProp_GProps edgeProps;
    BRepGProp::LinearProperties(edge->getOCCEdge(), edgeProps);
    double length = edgeProps.Mass() / dvp->getScale();

    Base::Vector3d startPt = edge->getStartPoint();
    Base::Vector3d endPt = edge->getEndPoint();
    startPt.y = -startPt.y;
    endPt.y = -endPt.y;

    std::stringstream startName, endName, formatSpec;
    Base::Vector3d cvPoint = CosmeticVertex::makeCanonicalPoint(dvp, startPt);
    std::string startVertTag = dvp->addCosmeticVertex(cvPoint);
    int startVertNumber = dvp->add1CVToGV(startVertTag);
    startName << "Vertex" << startVertNumber;
    cvPoint = CosmeticVertex::makeCanonicalPoint(dvp, endPt);
    std::string endVertTag = dvp->addCosmeticVertex(cvPoint);
    int endVertNumber = dvp->add1CVToGV(endVertTag);
    endName << "Vertex" << endVertNumber;

    dim = _createLinDimension(dvp, startName.str(), endName.str(), "Distance");
    TechDraw::pointPair pp = dim->getLinearPoints();
    Base::Vector3d mid = (pp.first() + pp.second()) / 2.0;
    dim->X.setValue(mid.x);
    dim->Y.setValue(-mid.y);

    dim->Arbitrary.setValue(true);
    formatSpec << "◠ " << length;
    dim->FormatSpec.setValue(formatSpec.str());

    return dim;
}

namespace TechDrawGui {
    //===========================================================================
    // internal helper routines
    //===========================================================================

    bool _checkSelection(Gui::Command* cmd,
        std::vector<Gui::SelectionObject>& selection,
        std::string message) {
        // check selection of getSelectionEx()
        selection = cmd->getSelection().getSelectionEx();
        if (selection.empty()) {
            QMessageBox::warning(Gui::getMainWindow(),
                QObject::tr(message.c_str()),
                QObject::tr("Selection is empty"));
            return false;
        }
        return true;
    }

    bool _checkSelAndObj(Gui::Command* cmd,
        std::vector<Gui::SelectionObject>& selection,
        TechDraw::DrawViewPart*& objFeat,
        std::string message) {
        // check selection of getSelectionEx() and selection[0].getObject()
        if (_checkSelection(cmd, selection, message)) {
            objFeat = dynamic_cast<TechDraw::DrawViewPart*>(selection[0].getObject());
            if (!objFeat) {
                QMessageBox::warning(Gui::getMainWindow(),
                    QObject::tr(message.c_str()),
                    QObject::tr("No object selected"));
                return false;
            }
        } else {
            // nothing selected
            return false;
        }
        return true;
    }

    bool _checkSelObjAndSubs(Gui::Command* cmd,
        std::vector<Gui::SelectionObject>& selection,
        TechDraw::DrawViewPart*& objFeat,
        std::string message) {
        // check selection of getSelectionEx() and selection[0].getObject()
        if (_checkSelAndObj(cmd, selection, objFeat, message)) {
            auto subs = selection[0].getSubNames();
            if (subs.empty()) {
                QMessageBox::warning(Gui::getMainWindow(),
                    QObject::tr(message.c_str()),
                    QObject::tr("No sub-elements selected"));
                return false;
            }
        } else {
            // nothing selected
            return false;
        }
        return true;
    }

    TechDraw::DrawViewDimension* _createLinDimension(
        TechDraw::DrawViewPart* objFeat,
        std::string startVertex,
        std::string endVertex,
        std::string dimType)
        // create a new linear dimension
    {
        TechDraw::DrawPage* page = objFeat->findParentPage();
        std::string PageName = page->getNameInDocument();
        std::string FeatName = objFeat->getDocument()->getUniqueObjectName("Dimension");
        std::vector<App::DocumentObject*> objs;
        std::vector<std::string> subs;
        objs.push_back(objFeat);
        objs.push_back(objFeat);
        subs.push_back(startVertex);
        subs.push_back(endVertex);
        Gui::Command::doCommand(Gui::Command::Doc, "App.activeDocument().addObject('TechDraw::DrawViewDimension', '%s')", FeatName.c_str());
        Gui::Command::doCommand(Gui::Command::Doc, "App.activeDocument().%s.Type = '%s'", FeatName.c_str(), dimType.c_str());
        auto dim = dynamic_cast<TechDraw::DrawViewDimension*>(objFeat->getDocument()->getObject(FeatName.c_str()));
        if (!dim){
            throw Base::TypeError("CmdTechDrawExtensionCreateLinDimension - dim not found\n");
        }
        dim->References2D.setValues(objs, subs);
        Gui::Command::doCommand(Gui::Command::Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(), FeatName.c_str());

        // Touch the parent feature so the dimension in tree view appears as a child
        objFeat->touch();
        dim->recomputeFeature();
        return dim;
    }

    std::vector<dimVertex> _getVertexInfo(TechDraw::DrawViewPart* objFeat,
        std::vector<std::string> subNames) {
        // get subNames and coordinates of all selected vertexes
        std::vector<dimVertex> vertexes;
        dimVertex nextVertex;
        for (const std::string& name : subNames) {
            std::string geoType = TechDraw::DrawUtil::getGeomTypeFromName(name);
            if (geoType == "Vertex") {
                int geoId = TechDraw::DrawUtil::getIndexFromName(name);
                TechDraw::VertexPtr vert = objFeat->getProjVertexByIndex(geoId);
                nextVertex.name = name;
                nextVertex.point.x = vert->point().x;
                nextVertex.point.y = vert->point().y;
                nextVertex.point.z = 0.0;
                vertexes.push_back(nextVertex);
            }
        }
        return vertexes;
    }

    std::vector<TechDraw::DrawViewDimension*>_getDimensions(std::vector<Gui::SelectionObject> selection, std::string needDimType) {
        // get all selected dimensions of type needDimType
        std::vector<TechDraw::DrawViewDimension*> validDimension;
        for (auto selected : selection) {
            auto object = selected.getObject();
            if (object->isDerivedFrom<TechDraw::DrawViewDimension>()) {
                auto dim = static_cast<TechDraw::DrawViewDimension*>(selected.getObject());
                std::string dimType = dim->Type.getValueAsString();
                if (dimType == needDimType)
                    validDimension.push_back(dim);
            }
        }
        return validDimension;
    }
}

//------------------------------------------------------------------------------
void CreateTechDrawCommandsExtensionDims()
{
    Gui::CommandManager& rcCmdMgr = Gui::Application::Instance->commandManager();

    rcCmdMgr.addCommand(new CmdTechDrawExtensionInsertPrefixGroup());
    rcCmdMgr.addCommand(new CmdTechDrawExtensionInsertDiameter());
    rcCmdMgr.addCommand(new CmdTechDrawExtensionInsertSquare());
    rcCmdMgr.addCommand(new CmdTechDrawExtensionInsertRepetition());
    rcCmdMgr.addCommand(new CmdTechDrawExtensionRemovePrefixChar());
    rcCmdMgr.addCommand(new CmdTechDrawExtensionIncreaseDecreaseGroup());
    rcCmdMgr.addCommand(new CmdTechDrawExtensionIncreaseDecimal());
    rcCmdMgr.addCommand(new CmdTechDrawExtensionDecreaseDecimal());
    rcCmdMgr.addCommand(new CmdTechDrawExtensionPosChainDimensionGroup());
    rcCmdMgr.addCommand(new CmdTechDrawExtensionPosHorizChainDimension());
    rcCmdMgr.addCommand(new CmdTechDrawExtensionPosVertChainDimension());
    rcCmdMgr.addCommand(new CmdTechDrawExtensionPosObliqueChainDimension());
    rcCmdMgr.addCommand(new CmdTechDrawExtensionCascadeDimensionGroup());
    rcCmdMgr.addCommand(new CmdTechDrawExtensionCascadeHorizDimension());
    rcCmdMgr.addCommand(new CmdTechDrawExtensionCascadeVertDimension());
    rcCmdMgr.addCommand(new CmdTechDrawExtensionCascadeObliqueDimension());
    rcCmdMgr.addCommand(new CmdTechDrawExtensionCreateChainDimensionGroup());
    rcCmdMgr.addCommand(new CmdTechDrawExtensionCreateHorizChainDimension());
    rcCmdMgr.addCommand(new CmdTechDrawExtensionCreateVertChainDimension());
    rcCmdMgr.addCommand(new CmdTechDrawExtensionCreateObliqueChainDimension());
    rcCmdMgr.addCommand(new CmdTechDrawExtensionCreateCoordDimensionGroup());
    rcCmdMgr.addCommand(new CmdTechDrawExtensionCreateHorizCoordDimension());
    rcCmdMgr.addCommand(new CmdTechDrawExtensionCreateVertCoordDimension());
    rcCmdMgr.addCommand(new CmdTechDrawExtensionCreateObliqueCoordDimension());
    rcCmdMgr.addCommand(new CmdTechDrawExtensionChamferDimensionGroup());
    rcCmdMgr.addCommand(new CmdTechDrawExtensionCreateHorizChamferDimension());
    rcCmdMgr.addCommand(new CmdTechDrawExtensionCreateVertChamferDimension());
    rcCmdMgr.addCommand(new CmdTechDrawExtensionCreateLengthArc());
    rcCmdMgr.addCommand(new CmdTechDrawExtensionCustomizeFormat());
}