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 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965
|
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013-2019 CERN
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <advanced_config.h>
#include <board.h>
#include <board_design_settings.h>
#include <pcb_track.h>
#include <pcb_group.h>
#include <footprint.h>
#include <pad.h>
#include <pcb_shape.h>
#include <string_utils.h>
#include <zone.h>
#include <pcb_reference_image.h>
#include <pcb_text.h>
#include <pcb_textbox.h>
#include <pcb_table.h>
#include <pcb_tablecell.h>
#include <pcb_marker.h>
#include <pcb_dimension.h>
#include <pcb_target.h>
#include <layer_ids.h>
#include <lset.h>
#include <pcb_painter.h>
#include <pcb_display_options.h>
#include <project/net_settings.h>
#include <settings/color_settings.h>
#include <settings/common_settings.h>
#include <settings/settings_manager.h>
#include <settings/cvpcb_settings.h>
#include <pcbnew_settings.h>
#include <footprint_editor_settings.h>
#include <convert_basic_shapes_to_polygon.h>
#include <gal/graphics_abstraction_layer.h>
#include <callback_gal.h>
#include <geometry/geometry_utils.h>
#include <geometry/shape_line_chain.h>
#include <geometry/shape_rect.h>
#include <geometry/shape_segment.h>
#include <geometry/shape_simple.h>
#include <geometry/shape_circle.h>
#include <bezier_curves.h>
#include <kiface_base.h>
#include <gr_text.h>
#include <pgm_base.h>
using namespace KIGFX;
PCBNEW_SETTINGS* pcbconfig()
{
return dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() );
}
// Helpers for display options existing in Cvpcb and Pcbnew
// Note, when running Cvpcb, pcbconfig() returns nullptr and viewer_settings()
// returns the viewer options existing to Cvpcb and Pcbnew
PCB_VIEWERS_SETTINGS_BASE* PCB_PAINTER::viewer_settings()
{
switch( m_frameType )
{
case FRAME_PCB_EDITOR:
case FRAME_PCB_DISPLAY3D:
default:
return Pgm().GetSettingsManager().GetAppSettings<PCBNEW_SETTINGS>( "pcbnew" );
case FRAME_FOOTPRINT_EDITOR:
case FRAME_FOOTPRINT_WIZARD:
return Pgm().GetSettingsManager().GetAppSettings<FOOTPRINT_EDITOR_SETTINGS>( "fpedit" );
case FRAME_FOOTPRINT_VIEWER:
case FRAME_FOOTPRINT_CHOOSER:
case FRAME_FOOTPRINT_PREVIEW:
case FRAME_CVPCB:
case FRAME_CVPCB_DISPLAY:
return Pgm().GetSettingsManager().GetAppSettings<CVPCB_SETTINGS>( "cvpcb" );
}
}
PCB_RENDER_SETTINGS::PCB_RENDER_SETTINGS()
{
m_backgroundColor = COLOR4D( 0.0, 0.0, 0.0, 1.0 );
m_ZoneDisplayMode = ZONE_DISPLAY_MODE::SHOW_FILLED;
m_netColorMode = NET_COLOR_MODE::RATSNEST;
m_ContrastModeDisplay = HIGH_CONTRAST_MODE::NORMAL;
m_trackOpacity = 1.0;
m_viaOpacity = 1.0;
m_padOpacity = 1.0;
m_zoneOpacity = 1.0;
m_imageOpacity = 1.0;
m_filledShapeOpacity = 1.0;
m_ForcePadSketchModeOn = false;
m_PadEditModePad = nullptr;
SetDashLengthRatio( 12 ); // From ISO 128-2
SetGapLengthRatio( 3 ); // From ISO 128-2
m_ForceShowFieldsWhenFPSelected = true;
update();
}
void PCB_RENDER_SETTINGS::LoadColors( const COLOR_SETTINGS* aSettings )
{
SetBackgroundColor( aSettings->GetColor( LAYER_PCB_BACKGROUND ) );
// Init board layers colors:
for( int i = 0; i < PCB_LAYER_ID_COUNT; i++ )
{
m_layerColors[i] = aSettings->GetColor( i );
// Guard: if the alpha channel is too small, the layer is not visible.
if( m_layerColors[i].a < 0.2 )
m_layerColors[i].a = 0.2;
}
// Init specific graphic layers colors:
for( int i = GAL_LAYER_ID_START; i < GAL_LAYER_ID_END; i++ )
m_layerColors[i] = aSettings->GetColor( i );
// Colors for layers that aren't theme-able
m_layerColors[LAYER_PAD_PLATEDHOLES] = aSettings->GetColor( LAYER_PCB_BACKGROUND );
m_layerColors[LAYER_PAD_NETNAMES] = aSettings->GetColor( NETNAMES_LAYER_ID_START );
// Netnames for copper layers
const COLOR4D lightLabel = aSettings->GetColor( NETNAMES_LAYER_ID_START );
const COLOR4D darkLabel = lightLabel.Inverted();
for( PCB_LAYER_ID layer : LSET::AllCuMask().CuStack() )
{
if( m_layerColors[layer].GetBrightness() > 0.5 )
m_layerColors[GetNetnameLayer( layer )] = darkLabel;
else
m_layerColors[GetNetnameLayer( layer )] = lightLabel;
}
if( PgmOrNull() ) // can be null if used without project (i.e. from python script)
m_hiContrastFactor = 1.0f - Pgm().GetCommonSettings()->m_Appearance.hicontrast_dimming_factor;
else
m_hiContrastFactor = 1.0f - 0.8f; // default value
update();
}
void PCB_RENDER_SETTINGS::LoadDisplayOptions( const PCB_DISPLAY_OPTIONS& aOptions )
{
m_hiContrastEnabled = aOptions.m_ContrastModeDisplay != HIGH_CONTRAST_MODE::NORMAL;
m_ZoneDisplayMode = aOptions.m_ZoneDisplayMode;
m_ContrastModeDisplay = aOptions.m_ContrastModeDisplay;
m_netColorMode = aOptions.m_NetColorMode;
m_trackOpacity = aOptions.m_TrackOpacity;
m_viaOpacity = aOptions.m_ViaOpacity;
m_padOpacity = aOptions.m_PadOpacity;
m_zoneOpacity = aOptions.m_ZoneOpacity;
m_imageOpacity = aOptions.m_ImageOpacity;
m_filledShapeOpacity = aOptions.m_FilledShapeOpacity;
}
COLOR4D PCB_RENDER_SETTINGS::GetColor( const VIEW_ITEM* aItem, int aLayer ) const
{
return GetColor( dynamic_cast<const BOARD_ITEM*>( aItem ), aLayer );
}
COLOR4D PCB_RENDER_SETTINGS::GetColor( const BOARD_ITEM* aItem, int aLayer ) const
{
int netCode = -1;
int originalLayer = aLayer;
// Marker shadows
if( aLayer == LAYER_MARKER_SHADOWS )
return m_backgroundColor.WithAlpha( 0.6 );
// SMD pads use the copper netname layer
if( aLayer == LAYER_PAD_FR_NETNAMES )
aLayer = GetNetnameLayer( F_Cu );
else if( aLayer == LAYER_PAD_BK_NETNAMES )
aLayer = GetNetnameLayer( B_Cu );
if( IsHoleLayer( aLayer ) && m_isPrinting )
{
// Careful that we don't end up with the same colour for the annular ring and the hole
// when printing in B&W.
const PAD* pad = dynamic_cast<const PAD*>( aItem );
const PCB_VIA* via = dynamic_cast<const PCB_VIA*>( aItem );
int holeLayer = aLayer;
int annularRingLayer = UNDEFINED_LAYER;
// TODO(JE) padstacks -- this won't work, we don't know what the annular ring layer is
// Inserting F_Cu here for now.
if( pad && pad->GetAttribute() == PAD_ATTRIB::PTH )
annularRingLayer = F_Cu;
else if( via )
annularRingLayer = F_Cu;
if( annularRingLayer != UNDEFINED_LAYER )
{
auto it = m_layerColors.find( holeLayer );
auto it2 = m_layerColors.find( annularRingLayer );
if( it != m_layerColors.end() && it2 != m_layerColors.end() && it->second == it2->second )
aLayer = LAYER_PCB_BACKGROUND;
}
}
// Zones should pull from the copper layer
if( aItem && aItem->Type() == PCB_ZONE_T )
{
if( IsZoneFillLayer( aLayer ) )
aLayer = aLayer - LAYER_ZONE_START;
}
// Pad and via copper and clearance outlines take their color from the copper layer
if( IsPadCopperLayer( aLayer ) )
aLayer = aLayer - LAYER_PAD_COPPER_START;
else if( IsViaCopperLayer( aLayer ) )
aLayer = aLayer - LAYER_VIA_COPPER_START;
else if( IsClearanceLayer( aLayer ) )
aLayer = aLayer - LAYER_CLEARANCE_START;
// Use via "golden copper" hole color for pad hole walls for contrast
else if( aLayer == LAYER_PAD_HOLEWALLS )
aLayer = LAYER_VIA_HOLES;
// Show via mask layers if appropriate
if( aLayer == LAYER_VIA_THROUGH && !m_isPrinting )
{
if( aItem && aItem->GetBoard() )
{
LSET visibleLayers = aItem->GetBoard()->GetVisibleLayers()
& aItem->GetBoard()->GetEnabledLayers()
& aItem->GetLayerSet();
if( GetActiveLayer() == F_Mask && visibleLayers.test( F_Mask ) )
aLayer = F_Mask;
else if( GetActiveLayer() == B_Mask && visibleLayers.test( B_Mask ) )
aLayer = B_Mask;
else if( ( visibleLayers & LSET::AllCuMask() ).none() )
{
if( visibleLayers.any() )
aLayer = visibleLayers.Seq().back();
}
}
}
// Normal path: get the layer base color
auto it = m_layerColors.find( aLayer );
COLOR4D color = it == m_layerColors.end() ? COLOR4D::WHITE : it->second;
if( !aItem )
return color;
// Selection disambiguation
if( aItem->IsBrightened() )
return color.Brightened( m_selectFactor ).WithAlpha( 0.8 );
// Normal selection
if( aItem->IsSelected() )
{
// Selection for tables is done with a background wash, so pass in nullptr to GetColor()
// so we just get the "normal" (un-selected/un-brightened) color for the borders.
if( aItem->Type() != PCB_TABLE_T && aItem->Type() != PCB_TABLECELL_T )
{
auto it_selected = m_layerColorsSel.find( aLayer );
color = it_selected == m_layerColorsSel.end() ? color.Brightened( 0.8 ) : it_selected->second;
}
}
// Some graphic objects are BOARD_CONNECTED_ITEM, but they are seen here as
// actually board connected objects only if on a copper layer
const BOARD_CONNECTED_ITEM* conItem =
aItem->IsConnected() && aItem->IsOnCopperLayer()
? static_cast<const BOARD_CONNECTED_ITEM*>( aItem )
: nullptr;
// Try to obtain the netcode for the aItem
if( conItem )
netCode = conItem->GetNetCode();
bool highlighted = m_highlightEnabled && m_highlightNetcodes.count( netCode );
bool selected = aItem->IsSelected();
// Apply net color overrides
if( conItem && m_netColorMode == NET_COLOR_MODE::ALL && IsCopperLayer( aLayer ) )
{
COLOR4D netColor = COLOR4D::UNSPECIFIED;
auto ii = m_netColors.find( netCode );
if( ii != m_netColors.end() )
netColor = ii->second;
if( netColor == COLOR4D::UNSPECIFIED )
{
const NETCLASS* nc = conItem->GetEffectiveNetClass();
if( nc->HasPcbColor() )
netColor = nc->GetPcbColor();
}
if( netColor == COLOR4D::UNSPECIFIED )
netColor = color;
if( selected )
{
// Selection brightening overrides highlighting
netColor.Brighten( m_selectFactor );
}
else if( m_highlightEnabled )
{
// Highlight brightens objects on all layers and darkens everything else for contrast
if( highlighted )
netColor.Brighten( m_highlightFactor );
else
netColor.Darken( 1.0 - m_highlightFactor );
}
color = netColor;
}
else if( !selected && m_highlightEnabled )
{
// Single net highlight mode
if( m_highlightNetcodes.contains( netCode ) )
{
auto it_hi = m_layerColorsHi.find( aLayer );
color = it_hi == m_layerColorsHi.end() ? color.Brightened( m_highlightFactor ) : it_hi->second;
}
else
{
auto it_dark = m_layerColorsDark.find( aLayer );
color = it_dark == m_layerColorsDark.end() ? color.Darkened( 1.0 - m_highlightFactor ) : it_dark->second;
}
}
// Apply high-contrast dimming
if( m_hiContrastEnabled && m_highContrastLayers.size() && !highlighted && !selected )
{
PCB_LAYER_ID primary = GetPrimaryHighContrastLayer();
bool isActive = m_highContrastLayers.count( aLayer );
bool hide = false;
switch( originalLayer )
{
// TODO(JE) not sure if this is needed
case LAYER_PADS:
{
const PAD* pad = static_cast<const PAD*>( aItem );
if( pad->IsOnLayer( primary ) && !pad->FlashLayer( primary ) )
{
isActive = false;
if( IsCopperLayer( primary ) )
hide = true;
}
if( m_PadEditModePad && pad != m_PadEditModePad )
isActive = false;
break;
}
case LAYER_VIA_BBLIND:
case LAYER_VIA_MICROVIA:
{
const PCB_VIA* via = static_cast<const PCB_VIA*>( aItem );
// Target graphic is active if the via crosses the primary layer
if( via->GetLayerSet().test( primary ) == 0 )
{
isActive = false;
hide = true;
}
break;
}
case LAYER_VIA_THROUGH:
{
const PCB_VIA* via = static_cast<const PCB_VIA*>( aItem );
if( !via->FlashLayer( primary ) )
{
isActive = false;
if( IsCopperLayer( primary ) )
hide = true;
}
break;
}
case LAYER_PAD_PLATEDHOLES:
case LAYER_PAD_HOLEWALLS:
case LAYER_NON_PLATEDHOLES:
// Pad holes are active is any physical layer is active
if( LSET::PhysicalLayersMask().test( primary ) == 0 )
isActive = false;
break;
case LAYER_VIA_HOLES:
case LAYER_VIA_HOLEWALLS:
{
const PCB_VIA* via = static_cast<const PCB_VIA*>( aItem );
if( via->GetViaType() == VIATYPE::THROUGH )
{
// A through via's hole is active if any physical layer is active
if( LSET::PhysicalLayersMask().test( primary ) == 0 )
isActive = false;
}
else
{
// A blind/buried or micro via's hole is active if it crosses the primary layer
if( via->GetLayerSet().test( primary ) == 0 )
isActive = false;
}
break;
}
case LAYER_DRC_ERROR:
case LAYER_DRC_WARNING:
case LAYER_DRC_EXCLUSION:
isActive = true;
break;
default:
break;
}
if( !isActive )
{
// Graphics on Edge_Cuts layer are not fully dimmed or hidden because they are
// useful when working on another layer
// We could use a dim factor = m_hiContrastFactor, but to have a sufficient
// contrast whenever m_hiContrastFactor value, we clamp the factor to 0.3f
// (arbitray choice after tests)
float dim_factor_Edge_Cuts = std::max( m_hiContrastFactor, 0.3f );
if( m_ContrastModeDisplay == HIGH_CONTRAST_MODE::HIDDEN
|| IsNetnameLayer( aLayer )
|| hide )
{
if( originalLayer == Edge_Cuts )
{
it = m_layerColors.find( LAYER_PCB_BACKGROUND );
if( it != m_layerColors.end() )
color = color.Mix( it->second, dim_factor_Edge_Cuts );
else
color = color.Mix( COLOR4D::BLACK, dim_factor_Edge_Cuts );
}
else
color = COLOR4D::CLEAR;
}
else
{
it = m_layerColors.find( LAYER_PCB_BACKGROUND );
COLOR4D backgroundColor = it == m_layerColors.end() ? COLOR4D::BLACK : it->second;
if( originalLayer == Edge_Cuts )
color = color.Mix( backgroundColor, dim_factor_Edge_Cuts );
else
color = color.Mix( backgroundColor, m_hiContrastFactor );
// Reference images can't have their color mixed so just reduce the opacity a bit
// so they show through less
if( aItem->Type() == PCB_REFERENCE_IMAGE_T )
color.a *= m_hiContrastFactor;
}
}
}
else if( originalLayer == LAYER_VIA_BBLIND || originalLayer == LAYER_VIA_MICROVIA )
{
const PCB_VIA* via = static_cast<const PCB_VIA*>( aItem );
const BOARD* board = via->GetBoard();
LSET visibleLayers = board->GetVisibleLayers() & board->GetEnabledLayers();
// Target graphic is visible if the via crosses a visible layer
if( ( via->GetLayerSet() & visibleLayers ).none() )
color = COLOR4D::CLEAR;
}
// Apply per-type opacity overrides
if( aItem->Type() == PCB_TRACE_T || aItem->Type() == PCB_ARC_T )
color.a *= m_trackOpacity;
else if( aItem->Type() == PCB_VIA_T )
color.a *= m_viaOpacity;
else if( aItem->Type() == PCB_PAD_T )
color.a *= m_padOpacity;
else if( aItem->Type() == PCB_ZONE_T && static_cast<const ZONE*>( aItem )->IsTeardropArea() )
color.a *= m_trackOpacity;
else if( aItem->Type() == PCB_ZONE_T )
color.a *= m_zoneOpacity;
else if( aItem->Type() == PCB_REFERENCE_IMAGE_T )
color.a *= m_imageOpacity;
else if( aItem->Type() == PCB_SHAPE_T && static_cast<const PCB_SHAPE*>( aItem )->IsFilled() )
color.a *= m_filledShapeOpacity;
else if( aItem->Type() == PCB_SHAPE_T && aItem->IsOnCopperLayer() )
color.a *= m_trackOpacity;
if( aItem->GetForcedTransparency() > 0.0 )
color = color.WithAlpha( color.a * ( 1.0 - aItem->GetForcedTransparency() ) );
// No special modifiers enabled
return color;
}
bool PCB_RENDER_SETTINGS::GetShowPageLimits() const
{
return pcbconfig() && pcbconfig()->m_ShowPageLimits;
}
PCB_PAINTER::PCB_PAINTER( GAL* aGal, FRAME_T aFrameType ) :
PAINTER( aGal ),
m_frameType( aFrameType ),
m_maxError( ARC_HIGH_DEF ),
m_holePlatingThickness( 0 ),
m_lockedShadowMargin( 0 )
{
}
int PCB_PAINTER::getLineThickness( int aActualThickness ) const
{
// if items have 0 thickness, draw them with the outline
// width, otherwise respect the set value (which, no matter
// how small will produce something)
if( aActualThickness == 0 )
return m_pcbSettings.m_outlineWidth;
return aActualThickness;
}
PAD_DRILL_SHAPE PCB_PAINTER::getDrillShape( const PAD* aPad ) const
{
return aPad->GetDrillShape();
}
SHAPE_SEGMENT PCB_PAINTER::getPadHoleShape( const PAD* aPad ) const
{
SHAPE_SEGMENT segm = *aPad->GetEffectiveHoleShape().get();
return segm;
}
int PCB_PAINTER::getViaDrillSize( const PCB_VIA* aVia ) const
{
return aVia->GetDrillValue();
}
bool PCB_PAINTER::Draw( const VIEW_ITEM* aItem, int aLayer )
{
if( !aItem->IsBOARD_ITEM() )
return false;
const BOARD_ITEM* item = static_cast<const BOARD_ITEM*>( aItem );
if( const BOARD* board = item->GetBoard() )
{
BOARD_DESIGN_SETTINGS& bds = board->GetDesignSettings();
m_maxError = bds.m_MaxError;
m_holePlatingThickness = bds.GetHolePlatingThickness();
m_lockedShadowMargin = bds.GetLineThickness( F_SilkS ) * 4;
if( item->GetParentFootprint() && !board->IsFootprintHolder() )
{
FOOTPRINT* parentFP = item->GetParentFootprint();
// Never draw footprint reference images on board
if( item->Type() == PCB_REFERENCE_IMAGE_T )
{
return false;
}
else if( item->GetLayerSet().count() > 1 )
{
// For multi-layer objects, exclude only those layers that are private
if( IsPcbLayer( aLayer ) && parentFP->GetPrivateLayers().test( aLayer ) )
return false;
}
else if( item->GetLayerSet().count() == 1 )
{
// For single-layer objects, exclude all layers including ancillary layers
// such as holes, netnames, etc.
PCB_LAYER_ID singleLayer = item->GetLayerSet().ExtractLayer();
if( parentFP->GetPrivateLayers().test( singleLayer ) )
return false;
}
}
}
else
{
m_maxError = ARC_HIGH_DEF;
m_holePlatingThickness = 0;
}
// the "cast" applied in here clarifies which overloaded draw() is called
switch( item->Type() )
{
case PCB_TRACE_T:
draw( static_cast<const PCB_TRACK*>( item ), aLayer );
break;
case PCB_ARC_T:
draw( static_cast<const PCB_ARC*>( item ), aLayer );
break;
case PCB_VIA_T:
draw( static_cast<const PCB_VIA*>( item ), aLayer );
break;
case PCB_PAD_T:
draw( static_cast<const PAD*>( item ), aLayer );
break;
case PCB_SHAPE_T:
draw( static_cast<const PCB_SHAPE*>( item ), aLayer );
break;
case PCB_REFERENCE_IMAGE_T:
draw( static_cast<const PCB_REFERENCE_IMAGE*>( item ), aLayer );
break;
case PCB_FIELD_T:
draw( static_cast<const PCB_FIELD*>( item ), aLayer );
break;
case PCB_TEXT_T:
draw( static_cast<const PCB_TEXT*>( item ), aLayer );
break;
case PCB_TEXTBOX_T:
draw( static_cast<const PCB_TEXTBOX*>( item ), aLayer );
break;
case PCB_TABLE_T:
draw( static_cast<const PCB_TABLE*>( item ), aLayer );
break;
case PCB_FOOTPRINT_T:
draw( static_cast<const FOOTPRINT*>( item ), aLayer );
break;
case PCB_GROUP_T:
draw( static_cast<const PCB_GROUP*>( item ), aLayer );
break;
case PCB_ZONE_T:
draw( static_cast<const ZONE*>( item ), aLayer );
break;
case PCB_DIM_ALIGNED_T:
case PCB_DIM_CENTER_T:
case PCB_DIM_RADIAL_T:
case PCB_DIM_ORTHOGONAL_T:
case PCB_DIM_LEADER_T:
draw( static_cast<const PCB_DIMENSION_BASE*>( item ), aLayer );
break;
case PCB_TARGET_T:
draw( static_cast<const PCB_TARGET*>( item ) );
break;
case PCB_MARKER_T:
draw( static_cast<const PCB_MARKER*>( item ), aLayer );
break;
default:
// Painter does not know how to draw the object
return false;
}
// Draw bounding boxes after drawing objects so they can be seen.
if( m_pcbSettings.GetDrawBoundingBoxes() )
{
// Show bounding boxes of painted objects for debugging.
BOX2I box = item->GetBoundingBox();
m_gal->SetIsFill( false );
m_gal->SetIsStroke( true );
if( item->Type() == PCB_FOOTPRINT_T )
{
m_gal->SetStrokeColor( item->IsSelected() ? COLOR4D( 1.0, 0.2, 0.2, 1 ) :
COLOR4D( MAGENTA ) );
}
else
{
m_gal->SetStrokeColor( item->IsSelected() ? COLOR4D( 1.0, 0.2, 0.2, 1 ) :
COLOR4D( 0.4, 0.4, 0.4, 1 ) );
}
m_gal->SetLineWidth( 1 );
m_gal->DrawRectangle( box.GetOrigin(), box.GetEnd() );
if( item->Type() == PCB_FOOTPRINT_T )
{
m_gal->SetStrokeColor( item->IsSelected() ? COLOR4D( 1.0, 0.2, 0.2, 1 ) :
COLOR4D( CYAN ) );
const FOOTPRINT* fp = static_cast<const FOOTPRINT*>( item );
if( fp )
{
const SHAPE_POLY_SET& convex = fp->GetBoundingHull();
m_gal->DrawPolyline( convex.COutline( 0 ) );
}
}
}
return true;
}
void PCB_PAINTER::draw( const PCB_TRACK* aTrack, int aLayer )
{
VECTOR2I start( aTrack->GetStart() );
VECTOR2I end( aTrack->GetEnd() );
int track_width = aTrack->GetWidth();
COLOR4D color = m_pcbSettings.GetColor( aTrack, aLayer );
if( IsNetnameLayer( aLayer ) )
{
if( !pcbconfig() || pcbconfig()->m_Display.m_NetNames < 2 )
return;
if( aTrack->GetNetCode() <= NETINFO_LIST::UNCONNECTED )
return;
SHAPE_SEGMENT trackShape( { aTrack->GetStart(), aTrack->GetEnd() }, aTrack->GetWidth() );
renderNetNameForSegment( trackShape, color, aTrack->GetDisplayNetname() );
return;
}
else if( IsCopperLayer( aLayer ) || IsSolderMaskLayer( aLayer )
|| aLayer == LAYER_LOCKED_ITEM_SHADOW )
{
// Draw a regular track
bool outline_mode = pcbconfig()
&& !pcbconfig()->m_Display.m_DisplayPcbTrackFill
&& aLayer != LAYER_LOCKED_ITEM_SHADOW;
m_gal->SetStrokeColor( color );
m_gal->SetFillColor( color );
m_gal->SetIsStroke( outline_mode );
m_gal->SetIsFill( not outline_mode );
m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
if( IsSolderMaskLayer( aLayer ) )
track_width = track_width + aTrack->GetSolderMaskExpansion() * 2;
if( aLayer == LAYER_LOCKED_ITEM_SHADOW )
track_width = track_width + m_lockedShadowMargin;
m_gal->DrawSegment( start, end, track_width );
}
// Clearance lines
if( IsClearanceLayer( aLayer ) && pcbconfig()
&& pcbconfig()->m_Display.m_TrackClearance == SHOW_WITH_VIA_ALWAYS
&& !m_pcbSettings.m_isPrinting )
{
const PCB_LAYER_ID copperLayerForClearance = ToLAYER_ID( aLayer - LAYER_CLEARANCE_START );
int clearance = aTrack->GetOwnClearance( copperLayerForClearance );
m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
m_gal->SetIsFill( false );
m_gal->SetIsStroke( true );
m_gal->SetStrokeColor( color );
m_gal->DrawSegment( start, end, track_width + clearance * 2 );
}
}
void PCB_PAINTER::renderNetNameForSegment( const SHAPE_SEGMENT& aSeg, const COLOR4D& aColor,
const wxString& aNetName ) const
{
// When drawing netnames, clip the track to the viewport
BOX2D viewport;
VECTOR2D screenSize = m_gal->GetScreenPixelSize();
const MATRIX3x3D& matrix = m_gal->GetScreenWorldMatrix();
viewport.SetOrigin( VECTOR2D( matrix * VECTOR2D( 0, 0 ) ) );
viewport.SetEnd( VECTOR2D( matrix * screenSize ) );
viewport.Normalize();
int num_char = aNetName.size();
// Check if the track is long enough to have a netname displayed
int seg_minlength = aSeg.GetWidth() * num_char;
SEG::ecoord seg_minlength_sq = (SEG::ecoord)seg_minlength * seg_minlength;
if( aSeg.GetSeg().SquaredLength() < seg_minlength_sq )
return;
double textSize = aSeg.GetWidth();
double penWidth = textSize / 12.0;
EDA_ANGLE textOrientation;
int num_names = 1;
VECTOR2I start = aSeg.GetSeg().A;
VECTOR2I end = aSeg.GetSeg().B;
VECTOR2D segV = end - start;
if( end.y == start.y ) // horizontal
{
textOrientation = ANGLE_HORIZONTAL;
num_names = std::max( num_names, KiROUND( aSeg.GetSeg().Length() / viewport.GetWidth() ) );
}
else if( end.x == start.x ) // vertical
{
textOrientation = ANGLE_VERTICAL;
num_names = std::max( num_names, KiROUND( aSeg.GetSeg().Length() / viewport.GetHeight() ) );
}
else
{
textOrientation = -EDA_ANGLE( segV );
textOrientation.Normalize90();
double min_size = std::min( viewport.GetWidth(), viewport.GetHeight() );
num_names = std::max( num_names, KiROUND( aSeg.GetSeg().Length() / ( M_SQRT2 * min_size ) ) );
}
m_gal->SetIsStroke( true );
m_gal->SetIsFill( false );
m_gal->SetStrokeColor( aColor );
m_gal->SetLineWidth( penWidth );
m_gal->SetFontBold( false );
m_gal->SetFontItalic( false );
m_gal->SetFontUnderlined( false );
m_gal->SetTextMirrored( false );
m_gal->SetGlyphSize( VECTOR2D( textSize * 0.55, textSize * 0.55 ) );
m_gal->SetHorizontalJustify( GR_TEXT_H_ALIGN_CENTER );
m_gal->SetVerticalJustify( GR_TEXT_V_ALIGN_CENTER );
int divisions = num_names + 1;
for( int ii = 1; ii < divisions; ++ii )
{
VECTOR2I textPosition = start + segV * ( (double) ii / divisions );
if( viewport.Contains( textPosition ) )
m_gal->BitmapText( aNetName, textPosition, textOrientation );
}
}
void PCB_PAINTER::draw( const PCB_ARC* aArc, int aLayer )
{
VECTOR2D center( aArc->GetCenter() );
int width = aArc->GetWidth();
COLOR4D color = m_pcbSettings.GetColor( aArc, aLayer );
double radius = aArc->GetRadius();
EDA_ANGLE start_angle = aArc->GetArcAngleStart();
EDA_ANGLE angle = aArc->GetAngle();
if( IsNetnameLayer( aLayer ) )
{
// Ummm, yeah. Anyone fancy implementing text on a path?
return;
}
else if( IsCopperLayer( aLayer ) || IsSolderMaskLayer( aLayer )
|| aLayer == LAYER_LOCKED_ITEM_SHADOW )
{
// Draw a regular track
bool outline_mode = pcbconfig()
&& !pcbconfig()->m_Display.m_DisplayPcbTrackFill
&& aLayer != LAYER_LOCKED_ITEM_SHADOW;
m_gal->SetStrokeColor( color );
m_gal->SetFillColor( color );
m_gal->SetIsStroke( outline_mode );
m_gal->SetIsFill( not outline_mode );
m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
if( IsSolderMaskLayer( aLayer ) )
width = width + aArc->GetSolderMaskExpansion() * 2;
if( aLayer == LAYER_LOCKED_ITEM_SHADOW )
width = width + m_lockedShadowMargin;
m_gal->DrawArcSegment( center, radius, start_angle, angle, width, m_maxError );
}
// Clearance lines
if( IsClearanceLayer( aLayer ) && pcbconfig()
&& pcbconfig()->m_Display.m_TrackClearance == SHOW_WITH_VIA_ALWAYS
&& !m_pcbSettings.m_isPrinting )
{
/*
* Showing the clearance area is not obvious for optionally-flashed pads and vias, so we
* choose to not display clearance lines at all on non-copper active layers. We follow
* the same rule for tracks to be consistent (even though they don't have the same issue).
*/
const PCB_LAYER_ID activeLayer = m_pcbSettings.GetActiveLayer();
const BOARD& board = *aArc->GetBoard();
if( IsCopperLayer( activeLayer ) && board.GetVisibleLayers().test( activeLayer ) )
{
int clearance = aArc->GetOwnClearance( activeLayer );
m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
m_gal->SetIsFill( false );
m_gal->SetIsStroke( true );
m_gal->SetStrokeColor( color );
m_gal->DrawArcSegment( center, radius, start_angle, angle, width + clearance * 2,
m_maxError );
}
}
// Debug only: enable this code only to test the TransformArcToPolygon function
// and display the polygon outline created by it.
// arcs on F_Cu are approximated with ERROR_INSIDE, others with ERROR_OUTSIDE
#if 0
SHAPE_POLY_SET cornerBuffer;
ERROR_LOC errorloc = aLayer == F_Cu ? ERROR_LOC::ERROR_INSIDE : ERROR_LOC::ERROR_OUTSIDE;
TransformArcToPolygon( cornerBuffer, aArc->GetStart(), aArc->GetMid(), aArc->GetEnd(), width,
m_maxError, errorloc );
m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
m_gal->SetIsFill( false );
m_gal->SetIsStroke( true );
m_gal->SetStrokeColor( COLOR4D( 0, 0, 1.0, 1.0 ) );
m_gal->DrawPolygon( cornerBuffer );
#endif
// Debug only: enable this code only to test the SHAPE_ARC::ConvertToPolyline function
// and display the polyline created by it.
#if 0
SHAPE_ARC arc( aArc->GetCenter(), aArc->GetStart(), aArc->GetAngle(), aArc->GetWidth() );
SHAPE_LINE_CHAIN arcSpine = arc.ConvertToPolyline( m_maxError );
m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
m_gal->SetIsFill( false );
m_gal->SetIsStroke( true );
m_gal->SetStrokeColor( COLOR4D( 0.3, 0.2, 0.5, 1.0 ) );
for( int idx = 1; idx < arcSpine.PointCount(); idx++ )
m_gal->DrawSegment( arcSpine.CPoint( idx-1 ), arcSpine.CPoint( idx ), aArc->GetWidth() );
#endif
}
void PCB_PAINTER::draw( const PCB_VIA* aVia, int aLayer )
{
const BOARD* board = aVia->GetBoard();
COLOR4D color = m_pcbSettings.GetColor( aVia, aLayer );
VECTOR2D center( aVia->GetStart() );
if( color == COLOR4D::CLEAR )
return;
const int copperLayer = IsViaCopperLayer( aLayer ) ? aLayer - LAYER_VIA_COPPER_START : aLayer;
PCB_LAYER_ID currentLayer = ToLAYER_ID( copperLayer );
PCB_LAYER_ID layerTop, layerBottom;
aVia->LayerPair( &layerTop, &layerBottom );
// Blind/buried vias (and microvias) will use different hole and label rendering
bool isBlindBuried = aVia->GetViaType() == VIATYPE::BLIND_BURIED
|| ( aVia->GetViaType() == VIATYPE::MICROVIA
&& ( layerTop != F_Cu || layerBottom != B_Cu ) );
// Draw description layer
if( IsNetnameLayer( aLayer ) )
{
VECTOR2D position( center );
// Is anything that we can display enabled (netname and/or layers ids)?
bool showNets = pcbconfig() && pcbconfig()->m_Display.m_NetNames != 0
&& !aVia->GetNetname().empty();
bool showLayers = aVia->GetViaType() != VIATYPE::THROUGH;
if( !showNets && !showLayers )
return;
double maxSize = PCB_RENDER_SETTINGS::MAX_FONT_SIZE;
double size = aVia->GetWidth( currentLayer );
// Font size limits
if( size > maxSize )
size = maxSize;
m_gal->Save();
m_gal->Translate( position );
// Default font settings
m_gal->ResetTextAttributes();
m_gal->SetHorizontalJustify( GR_TEXT_H_ALIGN_CENTER );
m_gal->SetVerticalJustify( GR_TEXT_V_ALIGN_CENTER );
m_gal->SetFontBold( false );
m_gal->SetFontItalic( false );
m_gal->SetFontUnderlined( false );
m_gal->SetTextMirrored( false );
m_gal->SetStrokeColor( m_pcbSettings.GetColor( aVia, aLayer ) );
m_gal->SetIsStroke( true );
m_gal->SetIsFill( false );
// Set the text position via position. if only one text, it is on the via position
// For 2 lines, the netname is slightly below the center, and the layer IDs above
// the netname
VECTOR2D textpos( 0.0, 0.0 );
wxString netname = aVia->GetDisplayNetname();
PCB_LAYER_ID topLayerId = aVia->TopLayer();
PCB_LAYER_ID bottomLayerId = aVia->BottomLayer();
int topLayer; // The via top layer number (from 1 to copper layer count)
int bottomLayer; // The via bottom layer number (from 1 to copper layer count)
switch( topLayerId )
{
case F_Cu: topLayer = 1; break;
case B_Cu: topLayer = board->GetCopperLayerCount(); break;
default: topLayer = (topLayerId - B_Cu)/2 + 1; break;
}
switch( bottomLayerId )
{
case F_Cu: bottomLayer = 1; break;
case B_Cu: bottomLayer = board->GetCopperLayerCount(); break;
default: bottomLayer = (bottomLayerId - B_Cu)/2 + 1; break;
}
wxString layerIds;
#if wxUSE_UNICODE_WCHAR
layerIds << std::to_wstring( topLayer ) << L'-' << std::to_wstring( bottomLayer );
#else
layerIds << std::to_string( topLayer ) << '-' << std::to_string( bottomLayer );
#endif
// a good size is set room for at least 6 chars, to be able to print 2 lines of text,
// or at least 3 chars for only the netname
// (The layerIds string has 5 chars max)
int minCharCnt = showLayers ? 6 : 3;
// approximate the size of netname and layerIds text:
double tsize = 1.5 * size / std::max( PrintableCharCount( netname ), minCharCnt );
tsize = std::min( tsize, size );
// Use a smaller text size to handle interline, pen size..
tsize *= 0.75;
VECTOR2D namesize( tsize, tsize );
// For 2 lines, adjust the text pos (move it a small amount to the bottom)
if( showLayers && showNets )
textpos.y += ( tsize * 1.3 )/ 2;
m_gal->SetGlyphSize( namesize );
m_gal->SetLineWidth( namesize.x / 10.0 );
if( showNets )
m_gal->BitmapText( netname, textpos, ANGLE_HORIZONTAL );
if( showLayers )
{
if( showNets )
textpos.y -= tsize * 1.3;
m_gal->BitmapText( layerIds, textpos, ANGLE_HORIZONTAL );
}
m_gal->Restore();
return;
}
bool outline_mode = pcbconfig() && !pcbconfig()->m_Display.m_DisplayViaFill;
m_gal->SetStrokeColor( color );
m_gal->SetFillColor( color );
m_gal->SetIsStroke( true );
m_gal->SetIsFill( false );
if( outline_mode )
m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
if( aLayer == LAYER_VIA_HOLEWALLS )
{
double thickness =
m_holePlatingThickness * ADVANCED_CFG::GetCfg().m_HoleWallPaintingMultiplier;
double radius = ( getViaDrillSize( aVia ) / 2.0 ) + thickness;
if( !outline_mode )
{
m_gal->SetLineWidth( thickness );
radius -= thickness / 2.0;
}
// Underpaint the hole so that there aren't artifacts at its edge
m_gal->SetIsFill( true );
m_gal->DrawCircle( center, radius );
}
else if( aLayer == LAYER_VIA_HOLES )
{
double radius = getViaDrillSize( aVia ) / 2.0;
m_gal->SetIsStroke( false );
m_gal->SetIsFill( true );
if( isBlindBuried && !m_pcbSettings.IsPrinting() )
{
m_gal->SetIsStroke( false );
m_gal->SetIsFill( true );
m_gal->SetFillColor( m_pcbSettings.GetColor( aVia, layerTop ) );
m_gal->DrawArc( center, radius, EDA_ANGLE( 180, DEGREES_T ),
EDA_ANGLE( 180, DEGREES_T ) );
m_gal->SetFillColor( m_pcbSettings.GetColor( aVia, layerBottom ) );
m_gal->DrawArc( center, radius, EDA_ANGLE( 0, DEGREES_T ),
EDA_ANGLE( 180, DEGREES_T ) );
}
else
{
m_gal->DrawCircle( center, radius );
}
}
else if( ( aLayer == F_Mask && aVia->IsOnLayer( F_Mask ) )
|| ( aLayer == B_Mask && aVia->IsOnLayer( B_Mask ) ) )
{
int margin = board->GetDesignSettings().m_SolderMaskExpansion;
m_gal->SetIsFill( true );
m_gal->SetIsStroke( false );
m_gal->SetLineWidth( margin );
m_gal->DrawCircle( center, aVia->GetWidth( currentLayer ) / 2.0 + margin );
}
else if( m_pcbSettings.IsPrinting() || IsCopperLayer( currentLayer ) )
{
int annular_width = ( aVia->GetWidth( currentLayer ) - getViaDrillSize( aVia ) ) / 2.0;
double radius = aVia->GetWidth( currentLayer ) / 2.0;
bool draw = false;
if( m_pcbSettings.IsPrinting() )
{
draw = aVia->FlashLayer( m_pcbSettings.GetPrintLayers() );
}
else if( aVia->IsSelected() )
{
draw = true;
}
else if( aVia->FlashLayer( board->GetVisibleLayers() & board->GetEnabledLayers() ) )
{
draw = true;
}
if( !aVia->FlashLayer( currentLayer ) )
draw = false;
if( !outline_mode )
{
m_gal->SetLineWidth( annular_width );
radius -= annular_width / 2.0;
}
if( draw )
m_gal->DrawCircle( center, radius );
}
else if( aLayer == LAYER_LOCKED_ITEM_SHADOW ) // draw a ring around the via
{
m_gal->SetLineWidth( m_lockedShadowMargin );
m_gal->DrawCircle( center,
( aVia->GetWidth( currentLayer ) + m_lockedShadowMargin ) / 2.0 );
}
// Clearance lines
if( IsClearanceLayer( aLayer ) && pcbconfig()
&& pcbconfig()->m_Display.m_TrackClearance == SHOW_WITH_VIA_ALWAYS
&& !m_pcbSettings.m_isPrinting )
{
const PCB_LAYER_ID copperLayerForClearance = ToLAYER_ID( aLayer - LAYER_CLEARANCE_START );
double radius;
if( aVia->FlashLayer( copperLayerForClearance ) )
radius = aVia->GetWidth( copperLayerForClearance ) / 2.0;
else
radius = getViaDrillSize( aVia ) / 2.0 + m_holePlatingThickness;
m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
m_gal->SetIsFill( false );
m_gal->SetIsStroke( true );
m_gal->SetStrokeColor( color );
m_gal->DrawCircle( center, radius + aVia->GetOwnClearance( copperLayerForClearance ) );
}
}
void PCB_PAINTER::draw( const PAD* aPad, int aLayer )
{
COLOR4D color = m_pcbSettings.GetColor( aPad, aLayer );
const int copperLayer = IsPadCopperLayer( aLayer ) ? aLayer - LAYER_PAD_COPPER_START : aLayer;
PCB_LAYER_ID pcbLayer = static_cast<PCB_LAYER_ID>( copperLayer );
if( IsNetnameLayer( aLayer ) )
{
PCBNEW_SETTINGS::DISPLAY_OPTIONS* displayOpts = pcbconfig() ? &pcbconfig()->m_Display : nullptr;
wxString netname;
wxString padNumber;
if( viewer_settings()->m_ViewersDisplay.m_DisplayPadNumbers )
{
padNumber = UnescapeString( aPad->GetNumber() );
if( dynamic_cast<CVPCB_SETTINGS*>( viewer_settings() ) )
netname = aPad->GetPinFunction();
}
if( displayOpts && !dynamic_cast<CVPCB_SETTINGS*>( viewer_settings() ) )
{
if( displayOpts->m_NetNames == 1 || displayOpts->m_NetNames == 3 )
netname = aPad->GetDisplayNetname();
if( aPad->IsNoConnectPad() )
netname = wxT( "x" );
else if( aPad->IsFreePad() )
netname = wxT( "*" );
}
if( netname.IsEmpty() && padNumber.IsEmpty() )
return;
BOX2I padBBox = aPad->GetBoundingBox();
VECTOR2D position = padBBox.Centre();
VECTOR2D padsize = VECTOR2D( padBBox.GetSize() );
if( aPad->IsEntered() )
{
FOOTPRINT* fp = aPad->GetParentFootprint();
// Find the number box
for( const BOARD_ITEM* aItem : fp->GraphicalItems() )
{
if( aItem->Type() == PCB_SHAPE_T )
{
const PCB_SHAPE* shape = static_cast<const PCB_SHAPE*>( aItem );
if( shape->IsProxyItem() && shape->GetShape() == SHAPE_T::RECTANGLE )
{
position = shape->GetCenter();
padsize = shape->GetBotRight() - shape->GetTopLeft();
// We normally draw a bit outside the pad, but this will be somewhat
// unexpected when the user has drawn a box.
padsize *= 0.9;
break;
}
}
}
}
else if( aPad->GetShape( pcbLayer ) == PAD_SHAPE::CUSTOM )
{
// See if we have a number box
for( const std::shared_ptr<PCB_SHAPE>& primitive : aPad->GetPrimitives( pcbLayer ) )
{
if( primitive->IsProxyItem() && primitive->GetShape() == SHAPE_T::RECTANGLE )
{
position = primitive->GetCenter();
RotatePoint( position, aPad->GetOrientation() );
position += aPad->ShapePos( pcbLayer );
padsize.x = abs( primitive->GetBotRight().x - primitive->GetTopLeft().x );
padsize.y = abs( primitive->GetBotRight().y - primitive->GetTopLeft().y );
// We normally draw a bit outside the pad, but this will be somewhat
// unexpected when the user has drawn a box.
padsize *= 0.9;
break;
}
}
}
if( aPad->GetShape( pcbLayer ) != PAD_SHAPE::CUSTOM )
{
// Don't allow a 45° rotation to bloat a pad's bounding box unnecessarily
double limit = std::min( aPad->GetSize( pcbLayer ).x,
aPad->GetSize( pcbLayer ).y ) * 1.1;
if( padsize.x > limit && padsize.y > limit )
{
padsize.x = limit;
padsize.y = limit;
}
}
double maxSize = PCB_RENDER_SETTINGS::MAX_FONT_SIZE;
double size = padsize.y;
m_gal->Save();
m_gal->Translate( position );
// Keep the size ratio for the font, but make it smaller
if( padsize.x < ( padsize.y * 0.95 ) )
{
m_gal->Rotate( -ANGLE_90.AsRadians() );
size = padsize.x;
std::swap( padsize.x, padsize.y );
}
// Font size limits
if( size > maxSize )
size = maxSize;
// Default font settings
m_gal->ResetTextAttributes();
m_gal->SetHorizontalJustify( GR_TEXT_H_ALIGN_CENTER );
m_gal->SetVerticalJustify( GR_TEXT_V_ALIGN_CENTER );
m_gal->SetFontBold( false );
m_gal->SetFontItalic( false );
m_gal->SetFontUnderlined( false );
m_gal->SetTextMirrored( false );
m_gal->SetStrokeColor( m_pcbSettings.GetColor( aPad, aLayer ) );
m_gal->SetIsStroke( true );
m_gal->SetIsFill( false );
// We have already translated the GAL to be centered at the center of the pad's
// bounding box
VECTOR2I textpos( 0, 0 );
// Divide the space, to display both pad numbers and netnames and set the Y text
// offset position to display 2 lines
int Y_offset_numpad = 0;
int Y_offset_netname = 0;
if( !netname.IsEmpty() && !padNumber.IsEmpty() )
{
// The magic numbers are defined experimentally for a better look.
size = size / 2.5;
Y_offset_netname = size / 1.4; // netname size is usually smaller than num pad
// so the offset can be smaller
Y_offset_numpad = size / 1.7;
}
// We are using different fonts to display names, depending on the graphic
// engine (OpenGL or Cairo).
// Xscale_for_stroked_font adjust the text X size for cairo (stroke fonts) engine
const double Xscale_for_stroked_font = 0.9;
if( !netname.IsEmpty() )
{
// approximate the size of net name text:
// We use a size for at least 5 chars, to give a good look even for short names
// (like VCC, GND...)
double tsize = 1.5 * padsize.x / std::max( PrintableCharCount( netname )+1, 5 );
tsize = std::min( tsize, size );
// Use a smaller text size to handle interline, pen size...
tsize *= 0.85;
// Round and oval pads have less room to display the net name than other
// (i.e RECT) shapes, so reduce the text size for these shapes
if( aPad->GetShape( pcbLayer ) == PAD_SHAPE::CIRCLE
|| aPad->GetShape( pcbLayer ) == PAD_SHAPE::OVAL )
{
tsize *= 0.9;
}
VECTOR2D namesize( tsize*Xscale_for_stroked_font, tsize );
textpos.y = std::min( tsize * 1.4, double( Y_offset_netname ) );
m_gal->SetGlyphSize( namesize );
m_gal->SetLineWidth( namesize.x / 6.0 );
m_gal->SetFontBold( true );
m_gal->BitmapText( netname, textpos, ANGLE_HORIZONTAL );
}
if( !padNumber.IsEmpty() )
{
// approximate the size of the pad number text:
// We use a size for at least 3 chars, to give a good look even for short numbers
double tsize = 1.5 * padsize.x / std::max( PrintableCharCount( padNumber ), 3 );
tsize = std::min( tsize, size );
// Use a smaller text size to handle interline, pen size...
tsize *= 0.85;
tsize = std::min( tsize, size );
VECTOR2D numsize( tsize*Xscale_for_stroked_font, tsize );
textpos.y = -Y_offset_numpad;
m_gal->SetGlyphSize( numsize );
m_gal->SetLineWidth( numsize.x / 6.0 );
m_gal->SetFontBold( true );
m_gal->BitmapText( padNumber, textpos, ANGLE_HORIZONTAL );
}
m_gal->Restore();
return;
}
else if( aLayer == LAYER_PAD_HOLEWALLS )
{
m_gal->SetIsFill( true );
m_gal->SetIsStroke( false );
double widthFactor = ADVANCED_CFG::GetCfg().m_HoleWallPaintingMultiplier;
double lineWidth = widthFactor * m_holePlatingThickness;
// Prevent the hole wall from being drawn too thin (at least two pixels)
// or too thick (cap at the size of the pad )
lineWidth = std::max( lineWidth, 2.0 / m_gal->GetWorldScale() );
lineWidth = std::min( lineWidth, aPad->GetSizeX() / 2.0 );
lineWidth = std::min( lineWidth, aPad->GetSizeY() / 2.0 );
m_gal->SetFillColor( color );
std::shared_ptr<SHAPE_SEGMENT> slot = aPad->GetEffectiveHoleShape();
int holeSize = slot->GetWidth() + ( 2 * lineWidth );
if( slot->GetSeg().A == slot->GetSeg().B ) // Circular hole
m_gal->DrawCircle( slot->GetSeg().A, KiROUND( holeSize / 2.0 ) );
else
m_gal->DrawSegment( slot->GetSeg().A, slot->GetSeg().B, holeSize );
return;
}
bool outline_mode = !viewer_settings()->m_ViewersDisplay.m_DisplayPadFill;
if( m_pcbSettings.m_ForcePadSketchModeOn )
outline_mode = true;
if( outline_mode )
{
// Outline mode
m_gal->SetIsFill( false );
m_gal->SetIsStroke( true );
m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
m_gal->SetStrokeColor( color );
}
else
{
// Filled mode
m_gal->SetIsFill( true );
m_gal->SetIsStroke( false );
m_gal->SetFillColor( color );
}
bool drawShape = false;
if( aLayer == LAYER_PAD_PLATEDHOLES || aLayer == LAYER_NON_PLATEDHOLES )
{
SHAPE_SEGMENT slot = getPadHoleShape( aPad );
if( slot.GetSeg().A == slot.GetSeg().B ) // Circular hole
m_gal->DrawCircle( slot.GetSeg().A, slot.GetWidth() / 2.0 );
else
m_gal->DrawSegment( slot.GetSeg().A, slot.GetSeg().B, slot.GetWidth() );
}
else if( m_pcbSettings.IsPrinting() )
{
drawShape = aPad->FlashLayer( m_pcbSettings.GetPrintLayers() );
}
else if( ( aLayer < PCB_LAYER_ID_COUNT || IsPadCopperLayer( aLayer ) )
&& aPad->FlashLayer( pcbLayer ) )
{
drawShape = true;
}
else if( aPad->IsSelected() )
{
drawShape = true;
outline_mode = true;
}
if( outline_mode )
{
// Outline mode
m_gal->SetIsFill( false );
m_gal->SetIsStroke( true );
m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
m_gal->SetStrokeColor( color );
}
if( drawShape )
{
VECTOR2I pad_size = aPad->GetSize( pcbLayer );
VECTOR2I margin;
switch( aLayer )
{
case F_Mask:
case B_Mask:
margin.x = margin.y = aPad->GetSolderMaskExpansion( pcbLayer );
break;
case F_Paste:
case B_Paste:
margin = aPad->GetSolderPasteMargin( pcbLayer );
break;
default:
margin.x = margin.y = 0;
break;
}
std::unique_ptr<PAD> dummyPad;
std::shared_ptr<SHAPE_COMPOUND> shapes;
// Drawing components of compound shapes in outline mode produces a mess.
bool simpleShapes = !outline_mode;
if( simpleShapes )
{
if( ( margin.x != margin.y && aPad->GetShape( pcbLayer ) != PAD_SHAPE::CUSTOM )
|| ( aPad->GetShape( pcbLayer ) == PAD_SHAPE::ROUNDRECT
&& ( margin.x < 0 || margin.y < 0 ) ) )
{
// Our algorithms below (polygon inflation in particular) can't handle differential
// inflation along separate axes. So for those cases we build a dummy pad instead,
// and inflate it.
// Margin is added to both sides. If the total margin is larger than the pad
// then don't display this layer
if( pad_size.x + 2 * margin.x <= 0 || pad_size.y + 2 * margin.y <= 0 )
return;
dummyPad.reset( static_cast<PAD*>( aPad->Duplicate() ) );
if( dummyPad->GetParentGroup() )
dummyPad->GetParentGroup()->RemoveItem( dummyPad.get() );
int initial_radius = dummyPad->GetRoundRectCornerRadius( pcbLayer );
dummyPad->SetSize( pcbLayer, pad_size + margin + margin );
if( dummyPad->GetShape( pcbLayer ) == PAD_SHAPE::ROUNDRECT )
{
// To keep the right margin around the corners, we need to modify the corner radius.
// We must have only one radius correction, so use the smallest absolute margin.
int radius_margin = std::max( margin.x, margin.y ); // radius_margin is < 0
dummyPad->SetRoundRectCornerRadius(
pcbLayer, std::max( initial_radius + radius_margin, 0 ) );
}
shapes = std::dynamic_pointer_cast<SHAPE_COMPOUND>(
dummyPad->GetEffectiveShape( pcbLayer ) );
margin.x = margin.y = 0;
}
else
{
shapes = std::dynamic_pointer_cast<SHAPE_COMPOUND>(
aPad->GetEffectiveShape( pcbLayer ) );
}
// The dynamic cast above will fail if the pad returned the hole shape or a null shape
// instead of a SHAPE_COMPOUND, which happens if we're on a copper layer and the pad has
// no shape on that layer.
if( !shapes )
return;
if( aPad->GetShape( pcbLayer ) == PAD_SHAPE::CUSTOM && ( margin.x || margin.y ) )
{
// We can't draw as shapes because we don't know which edges are internal and which
// are external (so we don't know when to apply the margin and when not to).
simpleShapes = false;
}
for( const SHAPE* shape : shapes->Shapes() )
{
if( !simpleShapes )
break;
switch( shape->Type() )
{
case SH_SEGMENT:
case SH_CIRCLE:
case SH_RECT:
case SH_SIMPLE:
// OK so far
break;
default:
// Not OK
simpleShapes = false;
break;
}
}
}
const auto drawOneSimpleShape = [&]( const SHAPE& aShape )
{
switch( aShape.Type() )
{
case SH_SEGMENT:
{
const SHAPE_SEGMENT& seg = (const SHAPE_SEGMENT&) aShape;
int effectiveWidth = seg.GetWidth() + 2 * margin.x;
if( effectiveWidth > 0 )
m_gal->DrawSegment( seg.GetSeg().A, seg.GetSeg().B, effectiveWidth );
break;
}
case SH_CIRCLE:
{
const SHAPE_CIRCLE& circle = (const SHAPE_CIRCLE&) aShape;
int effectiveRadius = circle.GetRadius() + margin.x;
if( effectiveRadius > 0 )
m_gal->DrawCircle( circle.GetCenter(), effectiveRadius );
break;
}
case SH_RECT:
{
const SHAPE_RECT& r = (const SHAPE_RECT&) aShape;
VECTOR2I pos = r.GetPosition();
VECTOR2I effectiveMargin = margin;
if( effectiveMargin.x < 0 )
{
// A negative margin just produces a smaller rect.
VECTOR2I effectiveSize = r.GetSize() + effectiveMargin;
if( effectiveSize.x > 0 && effectiveSize.y > 0 )
m_gal->DrawRectangle( pos - effectiveMargin, pos + effectiveSize );
}
else if( effectiveMargin.x > 0 )
{
// A positive margin produces a larger rect, but with rounded corners
m_gal->DrawRectangle( r.GetPosition(), r.GetPosition() + r.GetSize() );
// Use segments to produce the margin with rounded corners
m_gal->DrawSegment( pos,
pos + VECTOR2I( r.GetWidth(), 0 ),
effectiveMargin.x * 2 );
m_gal->DrawSegment( pos + VECTOR2I( r.GetWidth(), 0 ),
pos + r.GetSize(),
effectiveMargin.x * 2 );
m_gal->DrawSegment( pos + r.GetSize(),
pos + VECTOR2I( 0, r.GetHeight() ),
effectiveMargin.x * 2 );
m_gal->DrawSegment( pos + VECTOR2I( 0, r.GetHeight() ),
pos,
effectiveMargin.x * 2 );
}
else
{
m_gal->DrawRectangle( r.GetPosition(), r.GetPosition() + r.GetSize() );
}
break;
}
case SH_SIMPLE:
{
const SHAPE_SIMPLE& poly = static_cast<const SHAPE_SIMPLE&>( aShape );
if( poly.PointCount() < 2 ) // Careful of empty pads
break;
if( margin.x < 0 ) // The poly shape must be deflated
{
SHAPE_POLY_SET outline;
outline.NewOutline();
for( int ii = 0; ii < poly.PointCount(); ++ii )
outline.Append( poly.CPoint( ii ) );
outline.Deflate( -margin.x, CORNER_STRATEGY::CHAMFER_ALL_CORNERS, m_maxError );
m_gal->DrawPolygon( outline );
}
else
{
m_gal->DrawPolygon( poly.Vertices() );
}
// Now add on a rounded margin (using segments) if the margin > 0
if( margin.x > 0 )
{
for( size_t ii = 0; ii < poly.GetSegmentCount(); ++ii )
{
SEG seg = poly.GetSegment( ii );
m_gal->DrawSegment( seg.A, seg.B, margin.x * 2 );
}
}
break;
}
default:
// Better not get here; we already pre-flighted the shapes...
break;
}
};
if( simpleShapes )
{
for( const SHAPE* shape : shapes->Shapes() )
{
drawOneSimpleShape( *shape );
}
}
else
{
// This is expensive. Avoid if possible.
SHAPE_POLY_SET polySet;
aPad->TransformShapeToPolygon( polySet, ToLAYER_ID( aLayer ), margin.x, m_maxError,
ERROR_INSIDE );
m_gal->DrawPolygon( polySet );
}
}
if( IsClearanceLayer( aLayer )
&& ( ( pcbconfig() && pcbconfig()->m_Display.m_PadClearance ) || !pcbconfig() )
&& !m_pcbSettings.m_isPrinting )
{
const PCB_LAYER_ID copperLayerForClearance = ToLAYER_ID( aLayer - LAYER_CLEARANCE_START );
if( aPad->GetAttribute() == PAD_ATTRIB::NPTH )
color = m_pcbSettings.GetLayerColor( LAYER_NON_PLATEDHOLES );
m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
m_gal->SetIsStroke( true );
m_gal->SetIsFill( false );
m_gal->SetStrokeColor( color );
const int clearance = aPad->GetOwnClearance( copperLayerForClearance );
if( aPad->FlashLayer( copperLayerForClearance ) && clearance > 0 )
{
auto shape = std::dynamic_pointer_cast<SHAPE_COMPOUND>(
aPad->GetEffectiveShape( pcbLayer ) );
if( shape && shape->Size() == 1 && shape->Shapes()[0]->Type() == SH_SEGMENT )
{
const SHAPE_SEGMENT* seg = (SHAPE_SEGMENT*) shape->Shapes()[0];
m_gal->DrawSegment( seg->GetSeg().A, seg->GetSeg().B,
seg->GetWidth() + 2 * clearance );
}
else if( shape && shape->Size() == 1 && shape->Shapes()[0]->Type() == SH_CIRCLE )
{
const SHAPE_CIRCLE* circle = (SHAPE_CIRCLE*) shape->Shapes()[0];
m_gal->DrawCircle( circle->GetCenter(), circle->GetRadius() + clearance );
}
else
{
SHAPE_POLY_SET polySet;
// Use ERROR_INSIDE because it avoids Clipper and is therefore much faster.
aPad->TransformShapeToPolygon( polySet, copperLayerForClearance, clearance,
m_maxError, ERROR_INSIDE );
if( polySet.Outline( 0 ).PointCount() > 2 ) // Careful of empty pads
m_gal->DrawPolygon( polySet );
}
}
else if( aPad->GetEffectiveHoleShape() && clearance > 0 )
{
std::shared_ptr<SHAPE_SEGMENT> slot = aPad->GetEffectiveHoleShape();
m_gal->DrawSegment( slot->GetSeg().A, slot->GetSeg().B,
slot->GetWidth() + 2 * clearance );
}
}
}
void PCB_PAINTER::draw( const PCB_SHAPE* aShape, int aLayer )
{
COLOR4D color = m_pcbSettings.GetColor( aShape, aLayer );
bool outline_mode = !viewer_settings()->m_ViewersDisplay.m_DisplayGraphicsFill;
int thickness = getLineThickness( aShape->GetWidth() );
LINE_STYLE lineStyle = aShape->GetStroke().GetLineStyle();
if( lineStyle == LINE_STYLE::DEFAULT )
lineStyle = LINE_STYLE::SOLID;
if( IsSolderMaskLayer( aLayer )
&& aShape->HasSolderMask()
&& IsExternalCopperLayer( aShape->GetLayer() ) )
{
lineStyle = LINE_STYLE::SOLID;
thickness += aShape->GetSolderMaskExpansion() * 2;
}
if( IsNetnameLayer( aLayer ) )
{
// Net names are shown only in board editor:
if( m_frameType != FRAME_T::FRAME_PCB_EDITOR )
return;
if( !pcbconfig() || pcbconfig()->m_Display.m_NetNames < 2 )
return;
if( aShape->GetNetCode() <= NETINFO_LIST::UNCONNECTED )
return;
const wxString& netname = aShape->GetDisplayNetname();
if( netname.IsEmpty() )
return;
if( aShape->GetShape() == SHAPE_T::SEGMENT )
{
SHAPE_SEGMENT seg( { aShape->GetStart(), aShape->GetEnd() }, aShape->GetWidth() );
renderNetNameForSegment( seg, color, netname );
return;
}
// TODO: Maybe use some of the pad code?
return;
}
if( aLayer == LAYER_LOCKED_ITEM_SHADOW )
{
color = m_pcbSettings.GetColor( aShape, aLayer );
thickness = thickness + m_lockedShadowMargin;
// Note: on LAYER_LOCKED_ITEM_SHADOW always draw shadow shapes as continuous lines
// otherwise the look is very strange and ugly
lineStyle = LINE_STYLE::SOLID;
}
if( outline_mode )
{
m_gal->SetIsFill( false );
m_gal->SetIsStroke( true );
m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
}
m_gal->SetFillColor( color );
m_gal->SetStrokeColor( color );
if( lineStyle == LINE_STYLE::SOLID || aShape->IsFilled() )
{
switch( aShape->GetShape() )
{
case SHAPE_T::SEGMENT:
if( aShape->IsProxyItem() )
{
std::vector<VECTOR2I> pts;
VECTOR2I offset = ( aShape->GetEnd() - aShape->GetStart() ).Perpendicular();
offset = offset.Resize( thickness / 2 );
pts.push_back( aShape->GetStart() + offset );
pts.push_back( aShape->GetStart() - offset );
pts.push_back( aShape->GetEnd() - offset );
pts.push_back( aShape->GetEnd() + offset );
m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
m_gal->DrawLine( pts[0], pts[1] );
m_gal->DrawLine( pts[1], pts[2] );
m_gal->DrawLine( pts[2], pts[3] );
m_gal->DrawLine( pts[3], pts[0] );
m_gal->DrawLine( ( pts[0] + pts[1] ) / 2, ( pts[1] + pts[2] ) / 2 );
m_gal->DrawLine( ( pts[1] + pts[2] ) / 2, ( pts[2] + pts[3] ) / 2 );
m_gal->DrawLine( ( pts[2] + pts[3] ) / 2, ( pts[3] + pts[0] ) / 2 );
m_gal->DrawLine( ( pts[3] + pts[0] ) / 2, ( pts[0] + pts[1] ) / 2 );
}
else if( outline_mode )
{
m_gal->DrawSegment( aShape->GetStart(), aShape->GetEnd(), thickness );
}
else if( lineStyle == LINE_STYLE::SOLID )
{
m_gal->SetIsFill( true );
m_gal->SetIsStroke( false );
m_gal->DrawSegment( aShape->GetStart(), aShape->GetEnd(), thickness );
}
break;
case SHAPE_T::RECTANGLE:
{
std::vector<VECTOR2I> pts = aShape->GetRectCorners();
if( aShape->IsProxyItem() )
{
m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
m_gal->DrawLine( pts[0], pts[1] );
m_gal->DrawLine( pts[1], pts[2] );
m_gal->DrawLine( pts[2], pts[3] );
m_gal->DrawLine( pts[3], pts[0] );
m_gal->DrawLine( pts[0], pts[2] );
m_gal->DrawLine( pts[1], pts[3] );
}
else if( outline_mode )
{
m_gal->DrawSegment( pts[0], pts[1], thickness );
m_gal->DrawSegment( pts[1], pts[2], thickness );
m_gal->DrawSegment( pts[2], pts[3], thickness );
m_gal->DrawSegment( pts[3], pts[0], thickness );
}
else
{
m_gal->SetIsFill( true );
m_gal->SetIsStroke( false );
if( lineStyle == LINE_STYLE::SOLID && thickness > 0 )
{
m_gal->DrawSegment( pts[0], pts[1], thickness );
m_gal->DrawSegment( pts[1], pts[2], thickness );
m_gal->DrawSegment( pts[2], pts[3], thickness );
m_gal->DrawSegment( pts[3], pts[0], thickness );
}
if( aShape->IsFilled() )
{
SHAPE_POLY_SET poly;
poly.NewOutline();
for( const VECTOR2I& pt : pts )
poly.Append( pt );
if( thickness < 0 )
{
poly.Inflate( thickness / 2, CORNER_STRATEGY::ROUND_ALL_CORNERS,
m_maxError );
}
m_gal->DrawPolygon( poly );
}
}
break;
}
case SHAPE_T::ARC:
{
EDA_ANGLE startAngle;
EDA_ANGLE endAngle;
aShape->CalcArcAngles( startAngle, endAngle );
if( outline_mode )
{
m_gal->DrawArcSegment( aShape->GetCenter(), aShape->GetRadius(), startAngle,
endAngle - startAngle, thickness, m_maxError );
}
else if( lineStyle == LINE_STYLE::SOLID )
{
m_gal->SetIsFill( true );
m_gal->SetIsStroke( false );
m_gal->DrawArcSegment( aShape->GetCenter(), aShape->GetRadius(), startAngle,
endAngle - startAngle, thickness, m_maxError );
}
break;
}
case SHAPE_T::CIRCLE:
if( outline_mode )
{
m_gal->DrawCircle( aShape->GetStart(), aShape->GetRadius() - thickness / 2 );
m_gal->DrawCircle( aShape->GetStart(), aShape->GetRadius() + thickness / 2 );
}
else
{
m_gal->SetIsFill( aShape->IsFilled() );
m_gal->SetIsStroke( lineStyle == LINE_STYLE::SOLID && thickness > 0 );
m_gal->SetLineWidth( thickness );
int radius = aShape->GetRadius();
if( lineStyle == LINE_STYLE::SOLID && thickness > 0 )
{
m_gal->DrawCircle( aShape->GetStart(), radius );
}
else if( aShape->IsFilled() )
{
if( thickness < 0 )
{
radius += thickness / 2;
radius = std::max( radius, 0 );
}
m_gal->DrawCircle( aShape->GetStart(), radius );
}
}
break;
case SHAPE_T::POLY:
{
SHAPE_POLY_SET& shape = const_cast<PCB_SHAPE*>( aShape )->GetPolyShape();
if( shape.OutlineCount() == 0 )
break;
if( outline_mode )
{
for( int ii = 0; ii < shape.OutlineCount(); ++ii )
m_gal->DrawSegmentChain( shape.Outline( ii ), thickness );
}
else
{
m_gal->SetIsFill( true );
m_gal->SetIsStroke( false );
if( lineStyle == LINE_STYLE::SOLID && thickness > 0 )
{
for( int ii = 0; ii < shape.OutlineCount(); ++ii )
m_gal->DrawSegmentChain( shape.Outline( ii ), thickness );
}
if( aShape->IsFilled() )
{
if( thickness < 0 )
{
SHAPE_POLY_SET deflated_shape = shape;
deflated_shape.Inflate( thickness / 2, CORNER_STRATEGY::ROUND_ALL_CORNERS,
m_maxError );
m_gal->DrawPolygon( deflated_shape );
}
else
{
// On Opengl, a not convex filled polygon is usually drawn by using
// triangles as primitives. CacheTriangulation() can create basic triangle
// primitives to draw the polygon solid shape on Opengl. GLU tessellation
// is much slower, so currently we are using our tessellation.
if( m_gal->IsOpenGlEngine() && !shape.IsTriangulationUpToDate() )
shape.CacheTriangulation( true, true );
m_gal->DrawPolygon( shape );
}
}
}
break;
}
case SHAPE_T::BEZIER:
if( outline_mode )
{
std::vector<VECTOR2D> output;
std::vector<VECTOR2D> pointCtrl;
pointCtrl.push_back( aShape->GetStart() );
pointCtrl.push_back( aShape->GetBezierC1() );
pointCtrl.push_back( aShape->GetBezierC2() );
pointCtrl.push_back( aShape->GetEnd() );
BEZIER_POLY converter( pointCtrl );
converter.GetPoly( output, m_maxError );
m_gal->DrawSegmentChain( aShape->GetBezierPoints(), thickness );
}
else
{
m_gal->SetIsFill( aShape->IsFilled() );
m_gal->SetIsStroke( lineStyle == LINE_STYLE::SOLID && thickness > 0 );
m_gal->SetLineWidth( thickness );
if( aShape->GetBezierPoints().size() > 2 )
{
m_gal->DrawPolygon( aShape->GetBezierPoints() );
}
else
{
m_gal->DrawCurve( VECTOR2D( aShape->GetStart() ),
VECTOR2D( aShape->GetBezierC1() ),
VECTOR2D( aShape->GetBezierC2() ),
VECTOR2D( aShape->GetEnd() ), m_maxError );
}
}
break;
case SHAPE_T::UNDEFINED:
break;
}
}
if( lineStyle != LINE_STYLE::SOLID )
{
if( !outline_mode )
{
m_gal->SetIsFill( true );
m_gal->SetIsStroke( false );
}
std::vector<SHAPE*> shapes = aShape->MakeEffectiveShapes( true );
for( SHAPE* shape : shapes )
{
STROKE_PARAMS::Stroke( shape, lineStyle, getLineThickness( aShape->GetWidth() ),
&m_pcbSettings,
[&]( const VECTOR2I& a, const VECTOR2I& b )
{
m_gal->DrawSegment( a, b, thickness );
} );
}
for( SHAPE* shape : shapes )
delete shape;
}
}
void PCB_PAINTER::strokeText( const wxString& aText, const VECTOR2I& aPosition,
const TEXT_ATTRIBUTES& aAttrs, const KIFONT::METRICS& aFontMetrics )
{
KIFONT::FONT* font = aAttrs.m_Font;
if( !font )
font = KIFONT::FONT::GetFont( wxEmptyString, aAttrs.m_Bold, aAttrs.m_Italic );
m_gal->SetIsFill( font->IsOutline() );
m_gal->SetIsStroke( font->IsStroke() );
VECTOR2I pos( aPosition );
VECTOR2I fudge( KiROUND( 0.16 * aAttrs.m_StrokeWidth ), 0 );
RotatePoint( fudge, aAttrs.m_Angle );
if( ( aAttrs.m_Halign == GR_TEXT_H_ALIGN_LEFT && !aAttrs.m_Mirrored )
|| ( aAttrs.m_Halign == GR_TEXT_H_ALIGN_RIGHT && aAttrs.m_Mirrored ) )
{
pos -= fudge;
}
else if( ( aAttrs.m_Halign == GR_TEXT_H_ALIGN_RIGHT && !aAttrs.m_Mirrored )
|| ( aAttrs.m_Halign == GR_TEXT_H_ALIGN_LEFT && aAttrs.m_Mirrored ) )
{
pos += fudge;
}
font->Draw( m_gal, aText, pos, aAttrs, aFontMetrics );
}
void PCB_PAINTER::draw( const PCB_REFERENCE_IMAGE* aBitmap, int aLayer )
{
m_gal->Save();
const REFERENCE_IMAGE& refImg = aBitmap->GetReferenceImage();
m_gal->Translate( refImg.GetPosition() );
// When the image scale factor is not 1.0, we need to modify the actual as the image scale
// factor is similar to a local zoom
const double img_scale = refImg.GetImageScale();
if( img_scale != 1.0 )
m_gal->Scale( VECTOR2D( img_scale, img_scale ) );
if( aBitmap->IsSelected() || aBitmap->IsBrightened() )
{
COLOR4D color = m_pcbSettings.GetColor( aBitmap, LAYER_ANCHOR );
m_gal->SetIsStroke( true );
m_gal->SetStrokeColor( color );
m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth * 2.0f );
m_gal->SetIsFill( false );
// Draws a bounding box.
VECTOR2D bm_size( refImg.GetSize() );
// bm_size is the actual image size in UI.
// but m_gal scale was previously set to img_scale
// so recalculate size relative to this image size.
bm_size.x /= img_scale;
bm_size.y /= img_scale;
VECTOR2D origin( -bm_size.x / 2.0, -bm_size.y / 2.0 );
VECTOR2D end = origin + bm_size;
m_gal->DrawRectangle( origin, end );
// Hard code reference images as opaque when selected. Otherwise cached layers will
// not be rendered under the selected image because cached layers are rendered after
// non-cached layers (e.g. bitmaps), which will have a closer Z order.
m_gal->DrawBitmap( refImg.GetImage(), 1.0 );
}
else
m_gal->DrawBitmap( refImg.GetImage(),
m_pcbSettings.GetColor( aBitmap, aBitmap->GetLayer() ).a );
m_gal->Restore();
}
void PCB_PAINTER::draw( const PCB_FIELD* aField, int aLayer )
{
if( aField->IsVisible() )
draw( static_cast<const PCB_TEXT*>( aField ), aLayer );
}
void PCB_PAINTER::draw( const PCB_TEXT* aText, int aLayer )
{
wxString resolvedText( aText->GetShownText( true ) );
if( resolvedText.Length() == 0 )
return;
if( aLayer == LAYER_LOCKED_ITEM_SHADOW ) // happens only if locked
{
const COLOR4D color = m_pcbSettings.GetColor( aText, aLayer );
m_gal->SetIsFill( true );
m_gal->SetIsStroke( true );
m_gal->SetFillColor( color );
m_gal->SetStrokeColor( color );
m_gal->SetLineWidth( m_lockedShadowMargin );
SHAPE_POLY_SET poly;
aText->TransformShapeToPolygon( poly, aText->GetLayer(), 0, m_maxError, ERROR_OUTSIDE );
m_gal->DrawPolygon( poly );
return;
}
const KIFONT::METRICS& metrics = aText->GetFontMetrics();
TEXT_ATTRIBUTES attrs = aText->GetAttributes();
const COLOR4D& color = m_pcbSettings.GetColor( aText, aLayer );
bool outline_mode = !viewer_settings()->m_ViewersDisplay.m_DisplayTextFill;
KIFONT::FONT* font = aText->GetFont();
if( !font )
{
font = KIFONT::FONT::GetFont( m_pcbSettings.GetDefaultFont(), aText->IsBold(),
aText->IsItalic() );
}
m_gal->SetStrokeColor( color );
m_gal->SetFillColor( color );
attrs.m_Angle = aText->GetDrawRotation();
if( aText->IsKnockout() )
{
SHAPE_POLY_SET finalPoly;
aText->TransformTextToPolySet( finalPoly, 0, m_maxError, ERROR_INSIDE );
finalPoly.Fracture();
m_gal->SetIsStroke( false );
m_gal->SetIsFill( true );
m_gal->DrawPolygon( finalPoly );
}
else
{
if( outline_mode )
attrs.m_StrokeWidth = m_pcbSettings.m_outlineWidth;
else
attrs.m_StrokeWidth = getLineThickness( aText->GetEffectiveTextPenWidth() );
if( m_gal->IsFlippedX() && !aText->IsSideSpecific() )
{
// We do not want to change the mirroring for this kind of text
// on the mirrored canvas
// (not mirrored is draw not mirrored and mirrored is draw mirrored)
// So we need to recalculate the text position to keep it at the same position
// on the canvas
VECTOR2I textPos = aText->GetTextPos();
VECTOR2I textWidth = VECTOR2I( aText->GetTextBox().GetWidth(), 0 );
if( aText->GetHorizJustify() == GR_TEXT_H_ALIGN_RIGHT )
textWidth.x = -textWidth.x;
else if( aText->GetHorizJustify() == GR_TEXT_H_ALIGN_CENTER )
textWidth.x = 0;
RotatePoint( textWidth, VECTOR2I( 0, 0 ), aText->GetDrawRotation() );
if( attrs.m_Mirrored )
textPos -= textWidth;
else
textPos += textWidth;
attrs.m_Mirrored = !attrs.m_Mirrored;
strokeText( resolvedText, textPos, attrs, metrics );
return;
}
std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = nullptr;
if( font->IsOutline() )
cache = aText->GetRenderCache( font, resolvedText );
if( cache )
{
m_gal->SetLineWidth( attrs.m_StrokeWidth );
m_gal->DrawGlyphs( *cache );
}
else
{
strokeText( resolvedText, aText->GetTextPos(), attrs, metrics );
}
}
// Draw the umbilical line for texts in footprints
FOOTPRINT* fp_parent = aText->GetParentFootprint();
if( fp_parent && aText->IsSelected() )
{
m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
m_gal->SetStrokeColor( m_pcbSettings.GetColor( nullptr, LAYER_ANCHOR ) );
m_gal->DrawLine( aText->GetTextPos(), fp_parent->GetPosition() );
}
}
void PCB_PAINTER::draw( const PCB_TEXTBOX* aTextBox, int aLayer )
{
if( aTextBox->Type() == PCB_TABLECELL_T )
{
const PCB_TABLECELL* cell = static_cast<const PCB_TABLECELL*>( aTextBox );
if( cell->GetColSpan() == 0 || cell->GetRowSpan() == 0 )
return;
}
COLOR4D color = m_pcbSettings.GetColor( aTextBox, aLayer );
int thickness = getLineThickness( aTextBox->GetWidth() );
LINE_STYLE lineStyle = aTextBox->GetStroke().GetLineStyle();
wxString resolvedText( aTextBox->GetShownText( true ) );
KIFONT::FONT* font = aTextBox->GetFont();
if( !font )
{
font = KIFONT::FONT::GetFont( m_pcbSettings.GetDefaultFont(), aTextBox->IsBold(),
aTextBox->IsItalic() );
}
if( aLayer == LAYER_LOCKED_ITEM_SHADOW ) // happens only if locked
{
const COLOR4D sh_color = m_pcbSettings.GetColor( aTextBox, aLayer );
m_gal->SetIsFill( true );
m_gal->SetIsStroke( false );
m_gal->SetFillColor( sh_color );
m_gal->SetStrokeColor( sh_color );
// Draw the box with a larger thickness than box thickness to show
// the shadow mask
std::vector<VECTOR2I> pts = aTextBox->GetCorners();
int line_thickness = std::max( thickness*3, pcbIUScale.mmToIU( 0.2 ) );
std::deque<VECTOR2D> dpts;
for( const VECTOR2I& pt : pts )
dpts.push_back( VECTOR2D( pt ) );
dpts.push_back( VECTOR2D( pts[0] ) );
m_gal->SetIsStroke( true );
m_gal->SetLineWidth( line_thickness );
m_gal->DrawPolygon( dpts );
}
m_gal->SetFillColor( color );
m_gal->SetStrokeColor( color );
m_gal->SetIsFill( true );
m_gal->SetIsStroke( false );
if( aTextBox->Type() != PCB_TABLECELL_T && aTextBox->IsBorderEnabled() )
{
if( lineStyle <= LINE_STYLE::FIRST_TYPE )
{
if( thickness > 0 )
{
std::vector<VECTOR2I> pts = aTextBox->GetCorners();
for( size_t ii = 0; ii < pts.size(); ++ii )
m_gal->DrawSegment( pts[ii], pts[( ii + 1 ) % pts.size()], thickness );
}
}
else
{
std::vector<SHAPE*> shapes = aTextBox->MakeEffectiveShapes( true );
for( SHAPE* shape : shapes )
{
STROKE_PARAMS::Stroke( shape, lineStyle, thickness, &m_pcbSettings,
[&]( const VECTOR2I& a, const VECTOR2I& b )
{
m_gal->DrawSegment( a, b, thickness );
} );
}
for( SHAPE* shape : shapes )
delete shape;
}
}
if( aLayer == LAYER_LOCKED_ITEM_SHADOW )
{
// For now, the textbox is a filled shape.
// so the text drawn on LAYER_LOCKED_ITEM_SHADOW with a thick width is disabled
// If enabled, the thick text position must be offsetted to be exactly on the
// initial text, which is not easy, depending on its rotation and justification.
#if 0
const COLOR4D sh_color = m_pcbSettings.GetColor( aTextBox, aLayer );
m_gal->SetFillColor( sh_color );
m_gal->SetStrokeColor( sh_color );
attrs.m_StrokeWidth += m_lockedShadowMargin;
#else
return;
#endif
}
if( resolvedText.Length() == 0 )
return;
const KIFONT::METRICS& metrics = aTextBox->GetFontMetrics();
TEXT_ATTRIBUTES attrs = aTextBox->GetAttributes();
attrs.m_StrokeWidth = getLineThickness( aTextBox->GetEffectiveTextPenWidth() );
if( m_gal->IsFlippedX() && !aTextBox->IsSideSpecific() )
{
attrs.m_Mirrored = !attrs.m_Mirrored;
strokeText( resolvedText, aTextBox->GetDrawPos( true ), attrs, metrics );
return;
}
std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = nullptr;
if( font->IsOutline() )
cache = aTextBox->GetRenderCache( font, resolvedText );
if( cache )
{
m_gal->SetLineWidth( attrs.m_StrokeWidth );
m_gal->DrawGlyphs( *cache );
}
else
{
strokeText( resolvedText, aTextBox->GetDrawPos(), attrs, metrics );
}
}
void PCB_PAINTER::draw( const PCB_TABLE* aTable, int aLayer )
{
if( aTable->GetCells().empty() )
return;
for( PCB_TABLECELL* cell : aTable->GetCells() )
{
if( cell->GetColSpan() > 0 || cell->GetRowSpan() > 0 )
draw( static_cast<PCB_TEXTBOX*>( cell ), aLayer );
}
COLOR4D color = m_pcbSettings.GetColor( aTable, aLayer );
aTable->DrawBorders(
[&]( const VECTOR2I& ptA, const VECTOR2I& ptB, const STROKE_PARAMS& stroke )
{
int lineWidth = getLineThickness( stroke.GetWidth() );
LINE_STYLE lineStyle = stroke.GetLineStyle();
m_gal->SetIsFill( false );
m_gal->SetIsStroke( true );
m_gal->SetStrokeColor( color );
m_gal->SetLineWidth( lineWidth );
if( lineStyle <= LINE_STYLE::FIRST_TYPE )
{
m_gal->DrawLine( ptA, ptB );
}
else
{
SHAPE_SEGMENT seg( ptA, ptB );
STROKE_PARAMS::Stroke( &seg, lineStyle, lineWidth, &m_pcbSettings,
[&]( VECTOR2I a, VECTOR2I b )
{
// DrawLine has problem with 0 length lines so enforce minimum
if( a == b )
m_gal->DrawLine( a+1, b );
else
m_gal->DrawLine( a, b );
} );
}
} );
// Highlight selected tablecells with a background wash.
for( PCB_TABLECELL* cell : aTable->GetCells() )
{
if( aTable->IsSelected() || cell->IsSelected() )
{
std::vector<VECTOR2I> corners = cell->GetCorners();
std::deque<VECTOR2D> pts;
pts.insert( pts.end(), corners.begin(), corners.end() );
m_gal->SetFillColor( color.WithAlpha( 0.5 ) );
m_gal->SetIsFill( true );
m_gal->SetIsStroke( false );
m_gal->DrawPolygon( pts );
}
}
}
void PCB_PAINTER::draw( const FOOTPRINT* aFootprint, int aLayer )
{
if( aLayer == LAYER_ANCHOR )
{
const COLOR4D color = m_pcbSettings.GetColor( aFootprint, aLayer );
// Keep the size and width constant, not related to the scale because the anchor
// is just a marker on screen
double anchorSize = 5.0 / m_gal->GetWorldScale(); // 5 pixels size
double anchorThickness = 1.0 / m_gal->GetWorldScale(); // 1 pixels width
// Draw anchor
m_gal->SetIsFill( false );
m_gal->SetIsStroke( true );
m_gal->SetStrokeColor( color );
m_gal->SetLineWidth( anchorThickness );
VECTOR2D center = aFootprint->GetPosition();
m_gal->DrawLine( center - VECTOR2D( anchorSize, 0 ), center + VECTOR2D( anchorSize, 0 ) );
m_gal->DrawLine( center - VECTOR2D( 0, anchorSize ), center + VECTOR2D( 0, anchorSize ) );
}
if( aLayer == LAYER_LOCKED_ITEM_SHADOW && m_frameType == FRAME_PCB_EDITOR ) // happens only if locked
{
const COLOR4D color = m_pcbSettings.GetColor( aFootprint, aLayer );
m_gal->SetIsFill( true );
m_gal->SetIsStroke( false );
m_gal->SetFillColor( color );
#if 0 // GetBoundingHull() can be very slow, especially for logos imported from graphics
const SHAPE_POLY_SET& poly = aFootprint->GetBoundingHull();
m_gal->DrawPolygon( poly );
#else
BOX2I bbox = aFootprint->GetBoundingBox( false );
VECTOR2I topLeft = bbox.GetPosition();
VECTOR2I botRight = bbox.GetPosition() + bbox.GetSize();
m_gal->DrawRectangle( topLeft, botRight );
// Use segments to produce a margin with rounded corners
m_gal->DrawSegment( topLeft, VECTOR2I( botRight.x, topLeft.y ), m_lockedShadowMargin );
m_gal->DrawSegment( VECTOR2I( botRight.x, topLeft.y ), botRight, m_lockedShadowMargin );
m_gal->DrawSegment( botRight, VECTOR2I( topLeft.x, botRight.y ), m_lockedShadowMargin );
m_gal->DrawSegment( VECTOR2I( topLeft.x, botRight.y ), topLeft, m_lockedShadowMargin );
#endif
}
if( aLayer == LAYER_CONFLICTS_SHADOW )
{
const SHAPE_POLY_SET& frontpoly = aFootprint->GetCourtyard( F_CrtYd );
const SHAPE_POLY_SET& backpoly = aFootprint->GetCourtyard( B_CrtYd );
const COLOR4D color = m_pcbSettings.GetColor( aFootprint, aLayer );
m_gal->SetIsFill( true );
m_gal->SetIsStroke( false );
m_gal->SetFillColor( color );
if( frontpoly.OutlineCount() > 0 )
m_gal->DrawPolygon( frontpoly );
if( backpoly.OutlineCount() > 0 )
m_gal->DrawPolygon( backpoly );
}
}
void PCB_PAINTER::draw( const PCB_GROUP* aGroup, int aLayer )
{
if( aLayer == LAYER_ANCHOR )
{
if( aGroup->IsSelected() && !( aGroup->GetParent() && aGroup->GetParent()->IsSelected() ) )
{
// Selected on our own; draw enclosing box
}
else if( aGroup->IsEntered() )
{
// Entered group; draw enclosing box
}
else
{
// Neither selected nor entered; draw nothing at the group level (ie: only draw
// its members)
return;
}
const COLOR4D color = m_pcbSettings.GetColor( aGroup, LAYER_ANCHOR );
m_gal->SetStrokeColor( color );
m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth * 2.0f );
BOX2I bbox = aGroup->GetBoundingBox();
VECTOR2I topLeft = bbox.GetPosition();
VECTOR2I width = VECTOR2I( bbox.GetWidth(), 0 );
VECTOR2I height = VECTOR2I( 0, bbox.GetHeight() );
m_gal->DrawLine( topLeft, topLeft + width );
m_gal->DrawLine( topLeft + width, topLeft + width + height );
m_gal->DrawLine( topLeft + width + height, topLeft + height );
m_gal->DrawLine( topLeft + height, topLeft );
wxString name = aGroup->GetName();
if( name.IsEmpty() )
return;
int ptSize = 12;
int scaledSize = abs( KiROUND( m_gal->GetScreenWorldMatrix().GetScale().x * ptSize ) );
int unscaledSize = pcbIUScale.MilsToIU( ptSize );
// Scale by zoom a bit, but not too much
int textSize = ( scaledSize + ( unscaledSize * 2 ) ) / 3;
VECTOR2I textOffset = VECTOR2I( width.x / 2, -KiROUND( textSize * 0.5 ) );
VECTOR2I titleHeight = VECTOR2I( 0, KiROUND( textSize * 2.0 ) );
if( PrintableCharCount( name ) * textSize < bbox.GetWidth() )
{
m_gal->DrawLine( topLeft, topLeft - titleHeight );
m_gal->DrawLine( topLeft - titleHeight, topLeft + width - titleHeight );
m_gal->DrawLine( topLeft + width - titleHeight, topLeft + width );
TEXT_ATTRIBUTES attrs;
attrs.m_Italic = true;
attrs.m_Halign = GR_TEXT_H_ALIGN_CENTER;
attrs.m_Valign = GR_TEXT_V_ALIGN_BOTTOM;
attrs.m_Size = VECTOR2I( textSize, textSize );
attrs.m_StrokeWidth = GetPenSizeForNormal( textSize );
KIFONT::FONT::GetFont()->Draw( m_gal, aGroup->GetName(), topLeft + textOffset, attrs,
aGroup->GetFontMetrics() );
}
}
}
void PCB_PAINTER::draw( const ZONE* aZone, int aLayer )
{
if( aLayer == LAYER_CONFLICTS_SHADOW )
{
COLOR4D color = m_pcbSettings.GetColor( aZone, aLayer );
m_gal->SetIsFill( true );
m_gal->SetIsStroke( false );
m_gal->SetFillColor( color );
m_gal->DrawPolygon( aZone->Outline()->Outline( 0 ) );
return;
}
/*
* aLayer will be the virtual zone layer (LAYER_ZONE_START, ... in GAL_LAYER_ID)
* This is used for draw ordering in the GAL.
* The color for the zone comes from the associated copper layer ( aLayer - LAYER_ZONE_START )
* and the visibility comes from the combination of that copper layer and LAYER_ZONES
*/
PCB_LAYER_ID layer;
if( IsZoneFillLayer( aLayer ) )
layer = ToLAYER_ID( aLayer - LAYER_ZONE_START );
else
layer = ToLAYER_ID( aLayer );
if( !aZone->IsOnLayer( layer ) )
return;
COLOR4D color = m_pcbSettings.GetColor( aZone, layer );
std::deque<VECTOR2D> corners;
ZONE_DISPLAY_MODE displayMode = m_pcbSettings.m_ZoneDisplayMode;
if( aZone->IsTeardropArea() )
displayMode = ZONE_DISPLAY_MODE::SHOW_FILLED;
// Draw the outline
if( !IsZoneFillLayer( aLayer ) )
{
const SHAPE_POLY_SET* outline = aZone->Outline();
bool allowDrawOutline = aZone->GetHatchStyle() != ZONE_BORDER_DISPLAY_STYLE::INVISIBLE_BORDER;
if( allowDrawOutline && !m_pcbSettings.m_isPrinting && outline && outline->OutlineCount() > 0 )
{
m_gal->SetStrokeColor( color.a > 0.0 ? color.WithAlpha( 1.0 ) : color );
m_gal->SetIsFill( false );
m_gal->SetIsStroke( true );
m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
// Draw each contour (main contour and holes)
/*
* m_gal->DrawPolygon( *outline );
* should be enough, but currently does not work to draw holes contours in a complex
* polygon so each contour is draw as a simple polygon
*/
// Draw the main contour(s?)
for( int ii = 0; ii < outline->OutlineCount(); ++ii )
{
m_gal->DrawPolyline( outline->COutline( ii ) );
// Draw holes
int holes_count = outline->HoleCount( ii );
for( int jj = 0; jj < holes_count; ++jj )
m_gal->DrawPolyline( outline->CHole( ii, jj ) );
}
// Draw hatch lines
for( const SEG& hatchLine : aZone->GetHatchLines() )
m_gal->DrawLine( hatchLine.A, hatchLine.B );
}
}
// Draw the filling
if( IsZoneFillLayer( aLayer )
&& ( displayMode == ZONE_DISPLAY_MODE::SHOW_FILLED
|| displayMode == ZONE_DISPLAY_MODE::SHOW_FRACTURE_BORDERS
|| displayMode == ZONE_DISPLAY_MODE::SHOW_TRIANGULATION ) )
{
const std::shared_ptr<SHAPE_POLY_SET>& polySet = aZone->GetFilledPolysList( layer );
if( polySet->OutlineCount() == 0 ) // Nothing to draw
return;
m_gal->SetStrokeColor( color );
m_gal->SetFillColor( color );
m_gal->SetLineWidth( 0 );
if( displayMode == ZONE_DISPLAY_MODE::SHOW_FILLED )
{
m_gal->SetIsFill( true );
m_gal->SetIsStroke( false );
}
else
{
m_gal->SetIsFill( false );
m_gal->SetIsStroke( true );
}
// On Opengl, a not convex filled polygon is usually drawn by using triangles
// as primitives. CacheTriangulation() can create basic triangle primitives to
// draw the polygon solid shape on Opengl. GLU tessellation is much slower,
// so currently we are using our tessellation.
if( m_gal->IsOpenGlEngine() && !polySet->IsTriangulationUpToDate() )
polySet->CacheTriangulation( true, true );
m_gal->DrawPolygon( *polySet, displayMode == ZONE_DISPLAY_MODE::SHOW_TRIANGULATION );
}
}
void PCB_PAINTER::draw( const PCB_DIMENSION_BASE* aDimension, int aLayer )
{
const COLOR4D& color = m_pcbSettings.GetColor( aDimension, aLayer );
m_gal->SetStrokeColor( color );
m_gal->SetFillColor( color );
m_gal->SetIsFill( false );
m_gal->SetIsStroke( true );
bool outline_mode = !viewer_settings()->m_ViewersDisplay.m_DisplayGraphicsFill;
if( outline_mode )
m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
else
m_gal->SetLineWidth( getLineThickness( aDimension->GetLineThickness() ) );
// Draw dimension shapes
// TODO(JE) lift this out
for( const std::shared_ptr<SHAPE>& shape : aDimension->GetShapes() )
{
switch( shape->Type() )
{
case SH_SEGMENT:
{
const SEG& seg = static_cast<const SHAPE_SEGMENT*>( shape.get() )->GetSeg();
m_gal->DrawLine( seg.A, seg.B );
break;
}
case SH_CIRCLE:
{
int radius = static_cast<const SHAPE_CIRCLE*>( shape.get() )->GetRadius();
m_gal->DrawCircle( shape->Centre(), radius );
break;
}
default:
break;
}
}
// Draw text
wxString resolvedText = aDimension->GetShownText( true );
TEXT_ATTRIBUTES attrs = aDimension->GetAttributes();
if( m_gal->IsFlippedX() && !aDimension->IsSideSpecific() )
attrs.m_Mirrored = !attrs.m_Mirrored;
if( outline_mode )
attrs.m_StrokeWidth = m_pcbSettings.m_outlineWidth;
else
attrs.m_StrokeWidth = getLineThickness( aDimension->GetEffectiveTextPenWidth() );
std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = nullptr;
if( aDimension->GetFont() && aDimension->GetFont()->IsOutline() )
cache = aDimension->GetRenderCache( aDimension->GetFont(), resolvedText );
if( cache )
{
for( const std::unique_ptr<KIFONT::GLYPH>& glyph : *cache )
m_gal->DrawGlyph( *glyph.get() );
}
else
{
strokeText( resolvedText, aDimension->GetTextPos(), attrs, aDimension->GetFontMetrics() );
}
}
void PCB_PAINTER::draw( const PCB_TARGET* aTarget )
{
const COLOR4D& strokeColor = m_pcbSettings.GetColor( aTarget, aTarget->GetLayer() );
VECTOR2D position( aTarget->GetPosition() );
double size, radius;
m_gal->SetLineWidth( getLineThickness( aTarget->GetWidth() ) );
m_gal->SetStrokeColor( strokeColor );
m_gal->SetIsFill( false );
m_gal->SetIsStroke( true );
m_gal->Save();
m_gal->Translate( position );
if( aTarget->GetShape() )
{
// shape x
m_gal->Rotate( M_PI / 4.0 );
size = 2.0 * aTarget->GetSize() / 3.0;
radius = aTarget->GetSize() / 2.0;
}
else
{
// shape +
size = aTarget->GetSize() / 2.0;
radius = aTarget->GetSize() / 3.0;
}
m_gal->DrawLine( VECTOR2D( -size, 0.0 ), VECTOR2D( size, 0.0 ) );
m_gal->DrawLine( VECTOR2D( 0.0, -size ), VECTOR2D( 0.0, size ) );
m_gal->DrawCircle( VECTOR2D( 0.0, 0.0 ), radius );
m_gal->Restore();
}
void PCB_PAINTER::draw( const PCB_MARKER* aMarker, int aLayer )
{
switch( aLayer )
{
case LAYER_MARKER_SHADOWS:
case LAYER_DRC_ERROR:
case LAYER_DRC_WARNING:
{
bool isShadow = aLayer == LAYER_MARKER_SHADOWS;
// Don't paint invisible markers.
// It would be nice to do this through layer dependencies but we can't do an "or" there today
if( aMarker->GetBoard()
&& !aMarker->GetBoard()->IsElementVisible( aMarker->GetColorLayer() ) )
return;
const_cast<PCB_MARKER*>( aMarker )->SetZoom( 1.0 / sqrt( m_gal->GetZoomFactor() ) );
SHAPE_LINE_CHAIN polygon;
aMarker->ShapeToPolygon( polygon );
COLOR4D color = m_pcbSettings.GetColor( aMarker, isShadow ? LAYER_MARKER_SHADOWS
: aMarker->GetColorLayer() );
m_gal->Save();
m_gal->Translate( aMarker->GetPosition() );
if( isShadow )
{
m_gal->SetStrokeColor( color );
m_gal->SetIsStroke( true );
m_gal->SetLineWidth( aMarker->MarkerScale() );
}
else
{
m_gal->SetFillColor( color );
m_gal->SetIsFill( true );
}
m_gal->DrawPolygon( polygon );
m_gal->Restore();
return;
}
case LAYER_DRC_SHAPE1:
case LAYER_DRC_SHAPE2:
{
if( !aMarker->IsBrightened() )
return;
int arc_to_seg_error = gerbIUScale.mmToIU( 0.005 ); // Allow 5 microns
m_gal->SetLineWidth( aMarker->MarkerScale() );
for( auto& shape :
aLayer == LAYER_DRC_SHAPE1 ? aMarker->GetShapes1() : aMarker->GetShapes2() )
{
m_gal->SetIsFill( shape.IsFilled() );
m_gal->SetIsStroke( aLayer == LAYER_DRC_SHAPE1 ? true : false );
m_gal->SetStrokeColor( shape.GetLineColor() );
m_gal->SetFillColor( shape.GetFillColor() );
switch( shape.GetShape() )
{
case SHAPE_T::SEGMENT:
m_gal->DrawSegment( shape.GetStart(), shape.GetEnd(), shape.GetWidth() );
break;
case SHAPE_T::ARC:
{
EDA_ANGLE startAngle, endAngle;
shape.CalcArcAngles( startAngle, endAngle );
m_gal->DrawArcSegment( shape.GetCenter(), shape.GetRadius(), startAngle,
shape.GetArcAngle(), shape.GetWidth(), arc_to_seg_error );
break;
}
default: break;
}
}
}
}
}
const double PCB_RENDER_SETTINGS::MAX_FONT_SIZE = pcbIUScale.mmToIU( 10.0 );
|