File size: 91,480 Bytes
985c397 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 | # SPDX-License-Identifier: LGPL-2.1-or-later
# ***************************************************************************
# * *
# * Copyright (c) 2011 Yorik van Havre <yorik@uncreated.net> *
# * *
# * This file is part of FreeCAD. *
# * *
# * FreeCAD is free software: you can redistribute it and/or modify it *
# * under the terms of the GNU Lesser General Public License as *
# * published by the Free Software Foundation, either version 2.1 of the *
# * License, or (at your option) any later version. *
# * *
# * FreeCAD 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 *
# * Lesser General Public License for more details. *
# * *
# * You should have received a copy of the GNU Lesser General Public *
# * License along with FreeCAD. If not, see *
# * <https://www.gnu.org/licenses/>. *
# * *
# ***************************************************************************
__title__ = "FreeCAD Wall"
__author__ = "Yorik van Havre"
__url__ = "https://www.freecad.org"
## @package ArchWall
# \ingroup ARCH
# \brief The Wall object and tools
#
# This module provides tools to build Wall objects. Walls are simple objects,
# usually vertical, typically obtained by giving a thickness to a base line,
# then extruding it vertically.
"""This module provides tools to build Wall objects. Walls are simple
objects, usually vertical, typically obtained by giving a thickness to a base
line, then extruding it vertically.
Examples
--------
TODO put examples here.
"""
import math
import FreeCAD
import ArchCommands
import ArchComponent
import ArchSketchObject
import Draft
import DraftVecUtils
from FreeCAD import Vector
from draftutils import params
if FreeCAD.GuiUp:
from PySide import QtCore, QtGui
from PySide.QtCore import QT_TRANSLATE_NOOP
import FreeCADGui
import draftguitools.gui_trackers as DraftTrackers
from draftutils.translate import translate
else:
# \cond
def translate(ctxt, txt):
return txt
def QT_TRANSLATE_NOOP(ctxt, txt):
return txt
# \endcond
def mergeShapes(w1, w2):
"""Not currently implemented.
Return a Shape built on two walls that share same properties and have a
coincident endpoint.
"""
if not areSameWallTypes([w1, w2]):
return None
if (not hasattr(w1.Base, "Shape")) or (not hasattr(w2.Base, "Shape")):
return None
if w1.Base.Shape.Faces or w2.Base.Shape.Faces:
return None
# TODO fix this
return None
eds = w1.Base.Shape.Edges + w2.Base.Shape.Edges
import DraftGeomUtils
w = DraftGeomUtils.findWires(eds)
if len(w) == 1:
# print("found common wire")
normal, length, width, height = w1.Proxy.getDefaultValues(w1)
print(w[0].Edges)
sh = w1.Proxy.getBase(w1, w[0], normal, width, height)
print(sh)
return sh
return None
def areSameWallTypes(walls):
"""Check if a list of walls have the same height, width and alignment.
Parameters
----------
walls: list of <ArchComponent.Component>
Returns
-------
bool
True if the walls have the same height, width and alignment, False if
otherwise.
"""
for att in ["Width", "Height", "Align"]:
value = None
for w in walls:
if not hasattr(w, att):
return False
if not value:
value = getattr(w, att)
else:
if type(value) == float:
if round(value, Draft.precision()) != round(getattr(w, att), Draft.precision()):
return False
else:
if value != getattr(w, att):
return False
return True
class _Wall(ArchComponent.Component):
"""The Wall object.
Turns a <App::FeaturePython> into a wall object, then uses a
<Part::Feature> to create the wall's shape.
Walls are simple objects, usually vertical, typically obtained by giving a
thickness to a base line, then extruding it vertically.
Parameters
----------
obj: <App::FeaturePython>
The object to turn into a wall. Note that this is not the object that
forms the basis for the new wall's shape. That is given later.
"""
def __init__(self, obj):
ArchComponent.Component.__init__(self, obj)
self.Type = "Wall"
self.setProperties(obj)
obj.IfcType = "Wall"
def setProperties(self, obj):
"""Give the wall its wall specific properties, such as its alignment.
You can learn more about properties here:
https://wiki.freecad.org/property
parameters
----------
obj: <part::featurepython>
The object to turn into a wall.
"""
lp = obj.PropertiesList
if not "Length" in lp:
obj.addProperty(
"App::PropertyLength",
"Length",
"Wall",
QT_TRANSLATE_NOOP(
"App::Property",
"The length of this wall. Read-only if this wall is not based on an unconstrained sketch with a single edge, or on a Draft Wire with a single edge. Refer to wiki for details how length is deduced.",
),
locked=True,
)
if not "Width" in lp:
obj.addProperty(
"App::PropertyLength",
"Width",
"Wall",
QT_TRANSLATE_NOOP(
"App::Property",
"The width of this wall. Not used if this wall is based on a face. Disabled and ignored if Base object (ArchSketch) provides the information.",
),
locked=True,
)
# To be combined into Width when PropertyLengthList is available
if not "OverrideWidth" in lp:
obj.addProperty(
"App::PropertyFloatList",
"OverrideWidth",
"Wall",
QT_TRANSLATE_NOOP(
"App::Property",
"This overrides Width attribute to set width of each segment of wall. Disabled and ignored if Base object (ArchSketch) provides Widths information, with getWidths() method (If a value is zero, the value of 'Width' will be followed). [ENHANCEMENT by ArchSketch] GUI 'Edit Wall Segment Width' Tool is provided in external SketchArch Add-on to let users to set the values interactively. 'Toponaming-Tolerant' if ArchSketch is used in Base (and SketchArch Add-on is installed). Warning : Not 'Toponaming-Tolerant' if just Sketch is used.",
),
locked=True,
) # see DraftGeomUtils.offsetwire()
if not "OverrideAlign" in lp:
obj.addProperty(
"App::PropertyStringList",
"OverrideAlign",
"Wall",
QT_TRANSLATE_NOOP(
"App::Property",
"This overrides Align attribute to set align of each segment of wall. Disabled and ignored if Base object (ArchSketch) provides Aligns information, with getAligns() method (If a value is not 'Left, Right, Center', the value of 'Align' will be followed). [ENHANCEMENT by ArchSketch] GUI 'Edit Wall Segment Align' Tool is provided in external SketchArch Add-on to let users to set the values interactively. 'Toponaming-Tolerant' if ArchSketch is used in Base (and SketchArch Add-on is installed). Warning : Not 'Toponaming-Tolerant' if just Sketch is used.",
),
locked=True,
) # see DraftGeomUtils.offsetwire()
if not "OverrideOffset" in lp:
obj.addProperty(
"App::PropertyFloatList",
"OverrideOffset",
"Wall",
QT_TRANSLATE_NOOP(
"App::Property",
"This overrides Offset attribute to set offset of each segment of wall. Disabled and ignored if Base object (ArchSketch) provides Offsets information, with getOffsets() method (If a value is zero, the value of 'Offset' will be followed). [ENHANCED by ArchSketch] GUI 'Edit Wall Segment Offset' Tool is provided in external Add-on ('SketchArch') to let users to select the edges interactively. 'Toponaming-Tolerant' if ArchSketch is used in Base (and SketchArch Add-on is installed). Warning : Not 'Toponaming-Tolerant' if just Sketch is used. Property is ignored if Base ArchSketch provided the selected edges. ",
),
locked=True,
) # see DraftGeomUtils.offsetwire()
if not "Height" in lp:
obj.addProperty(
"App::PropertyLength",
"Height",
"Wall",
QT_TRANSLATE_NOOP(
"App::Property",
"The height of this wall. Keep 0 for automatic. Not used if this wall is based on a solid",
),
locked=True,
)
if not "Area" in lp:
obj.addProperty(
"App::PropertyArea",
"Area",
"Wall",
QT_TRANSLATE_NOOP(
"App::Property", "The area of this wall as a simple Height * Length calculation"
),
locked=True,
)
obj.setEditorMode("Area", 1)
if not "Align" in lp:
obj.addProperty(
"App::PropertyEnumeration",
"Align",
"Wall",
QT_TRANSLATE_NOOP(
"App::Property",
"The alignment of this wall on its base object, if applicable. Disabled and ignored if Base object (ArchSketch) provides the information.",
),
locked=True,
)
obj.Align = ["Left", "Right", "Center"]
if not "Normal" in lp:
obj.addProperty(
"App::PropertyVector",
"Normal",
"Wall",
QT_TRANSLATE_NOOP(
"App::Property",
"The normal extrusion direction of this object (keep (0,0,0) for automatic normal)",
),
locked=True,
)
if not "Face" in lp:
obj.addProperty(
"App::PropertyInteger",
"Face",
"Wall",
QT_TRANSLATE_NOOP(
"App::Property", "The face number of the base object used to build this wall"
),
locked=True,
)
if not "Offset" in lp:
obj.addProperty(
"App::PropertyDistance",
"Offset",
"Wall",
QT_TRANSLATE_NOOP(
"App::Property",
"The offset between this wall and its baseline (only for left and right alignments). Disabled and ignored if Base object (ArchSketch) provides the information.",
),
locked=True,
)
# See getExtrusionData(), removeSplitters are no longer used
# if not "Refine" in lp:
# obj.addProperty("App::PropertyEnumeration","Refine","Wall",QT_TRANSLATE_NOOP("App::Property","Select whether or not and the method to remove splitter of the Wall. Currently Draft removeSplitter and Part removeSplitter available but may not work on complex sketch."), locked=True)
# obj.Refine = ['No','DraftRemoveSplitter','PartRemoveSplitter']
# TODO - To implement in Arch Component ?
if not "MakeBlocks" in lp:
obj.addProperty(
"App::PropertyBool",
"MakeBlocks",
"Blocks",
QT_TRANSLATE_NOOP("App::Property", "Enable this to make the wall generate blocks"),
locked=True,
)
if not "BlockLength" in lp:
obj.addProperty(
"App::PropertyLength",
"BlockLength",
"Blocks",
QT_TRANSLATE_NOOP("App::Property", "The length of each block"),
locked=True,
)
if not "BlockHeight" in lp:
obj.addProperty(
"App::PropertyLength",
"BlockHeight",
"Blocks",
QT_TRANSLATE_NOOP("App::Property", "The height of each block"),
locked=True,
)
if not "OffsetFirst" in lp:
obj.addProperty(
"App::PropertyLength",
"OffsetFirst",
"Blocks",
QT_TRANSLATE_NOOP(
"App::Property", "The horizontal offset of the first line of blocks"
),
locked=True,
)
if not "OffsetSecond" in lp:
obj.addProperty(
"App::PropertyLength",
"OffsetSecond",
"Blocks",
QT_TRANSLATE_NOOP(
"App::Property", "The horizontal offset of the second line of blocks"
),
locked=True,
)
if not "Joint" in lp:
obj.addProperty(
"App::PropertyLength",
"Joint",
"Blocks",
QT_TRANSLATE_NOOP("App::Property", "The size of the joints between each block"),
locked=True,
)
if not "CountEntire" in lp:
obj.addProperty(
"App::PropertyInteger",
"CountEntire",
"Blocks",
QT_TRANSLATE_NOOP("App::Property", "The number of entire blocks"),
locked=True,
)
obj.setEditorMode("CountEntire", 1)
if not "CountBroken" in lp:
obj.addProperty(
"App::PropertyInteger",
"CountBroken",
"Blocks",
QT_TRANSLATE_NOOP("App::Property", "The number of broken blocks"),
locked=True,
)
obj.setEditorMode("CountBroken", 1)
if not "ArchSketchData" in lp:
obj.addProperty(
"App::PropertyBool",
"ArchSketchData",
"Wall",
QT_TRANSLATE_NOOP(
"App::Property",
"Use Base ArchSketch (if used) data (e.g. widths, aligns, offsets) instead of Wall's properties",
),
locked=True,
)
obj.ArchSketchData = True
if not "ArchSketchEdges" in lp:
obj.addProperty(
"App::PropertyStringList",
"ArchSketchEdges",
"Wall",
QT_TRANSLATE_NOOP(
"App::Property",
"Selected edges (or group of edges) of the base Sketch/ArchSketch, to use in creating the shape of this Arch Wall (instead of using all the Base Sketch/ArchSketch's edges by default). Input are index numbers of edges or groups. Disabled and ignored if Base object (ArchSketch) provides selected edges (as Wall Axis) information, with getWallBaseShapeEdgesInfo() method. [ENHANCEMENT by ArchSketch] GUI 'Edit Wall Segment' Tool is provided in external SketchArch Add-on to let users to (de)select the edges interactively. 'Toponaming-Tolerant' if ArchSketch is used in Base (and SketchArch Add-on is installed). Warning : Not 'Toponaming-Tolerant' if just Sketch is used.",
),
locked=True,
)
if not hasattr(obj, "ArchSketchPropertySet"):
obj.addProperty(
"App::PropertyEnumeration",
"ArchSketchPropertySet",
"Wall",
QT_TRANSLATE_NOOP(
"App::Property",
"Select User Defined PropertySet to use in creating variant shape, layers of the Arch Wall with same ArchSketch ",
),
locked=True,
)
obj.ArchSketchPropertySet = ["Default"]
if not hasattr(self, "ArchSkPropSetPickedUuid"): # 'obj.Proxy', 'self' not works ?
self.ArchSkPropSetPickedUuid = ""
if not hasattr(self, "ArchSkPropSetListPrev"):
self.ArchSkPropSetListPrev = []
self.connectEdges = []
def dumps(self):
dump = super().dumps()
if not isinstance(dump, tuple):
dump = (dump,) # Python Tuple With One Item
dump = dump + (self.ArchSkPropSetPickedUuid, self.ArchSkPropSetListPrev)
return dump
def loads(self, state):
self.Type = "Wall"
if state == None:
return
elif state[0] == "W": # state[1] == 'a', behaviour before 2024.11.28
return
elif state[0] == "Wall":
self.ArchSkPropSetPickedUuid = state[1]
self.ArchSkPropSetListPrev = state[2]
elif state[0] != "Wall": # model before merging super.dumps/loads()
self.ArchSkPropSetPickedUuid = state[0]
self.ArchSkPropSetListPrev = state[1]
def onDocumentRestored(self, obj):
"""Method run when the document is restored. Re-adds the Arch component, and Arch wall properties."""
import DraftGeomUtils
from draftutils.messages import _log
ArchComponent.Component.onDocumentRestored(self, obj)
self.setProperties(obj)
# In V1.0 the handling of wall normals has changed. As a result existing
# walls with their Normal set to [0, 0, 0], based on wires or faces with
# a shape normal pointing towards -Z, would be extruded in that direction
# instead of towards +Z as before. To avoid this their Normal property is
# changed to [0, 0, 1].
if (
FreeCAD.ActiveDocument.getProgramVersion() < "0.22"
and obj.Normal == Vector(0, 0, 0)
and hasattr(obj.Base, "Shape")
and not obj.Base.Shape.Solids
and obj.Face == 0
and not obj.Base.isDerivedFrom("Sketcher::SketchObject")
and DraftGeomUtils.get_shape_normal(obj.Base.Shape) != Vector(0, 0, 1)
):
obj.Normal = Vector(0, 0, 1)
_log(
"v1.0, "
+ obj.Name
+ ", "
+ "changed 'Normal' to [0, 0, 1] to preserve extrusion direction"
)
if (
hasattr(obj, "ArchSketchData")
and obj.ArchSketchData
and Draft.getType(obj.Base) == "ArchSketch"
):
if hasattr(obj, "Width"): # TODO need test?
obj.setEditorMode("Width", ["ReadOnly"])
if hasattr(obj, "Align"):
obj.setEditorMode("Align", ["ReadOnly"])
if hasattr(obj, "Offset"):
obj.setEditorMode("Offset", ["ReadOnly"])
if hasattr(obj, "OverrideWidth"):
obj.setEditorMode("OverrideWidth", ["ReadOnly"])
if hasattr(obj, "OverrideAlign"):
obj.setEditorMode("OverrideAlign", ["ReadOnly"])
if hasattr(obj, "OverrideOffset"):
obj.setEditorMode("OverrideOffset", ["ReadOnly"])
if hasattr(obj, "ArchSketchEdges"):
obj.setEditorMode("ArchSketchEdges", ["ReadOnly"])
if hasattr(obj, "ArchSketchPropertySet"):
obj.setEditorMode("ArchSketchPropertySet", 0)
else:
if hasattr(obj, "Width"):
obj.setEditorMode("Width", 0)
if hasattr(obj, "Align"):
obj.setEditorMode("Align", 0)
if hasattr(obj, "Offset"):
obj.setEditorMode("Offset", 0)
if hasattr(obj, "OverrideWidth"):
obj.setEditorMode("OverrideWidth", 0)
if hasattr(obj, "OverrideAlign"):
obj.setEditorMode("OverrideAlign", 0)
if hasattr(obj, "OverrideOffset"):
obj.setEditorMode("OverrideOffset", 0)
if hasattr(obj, "ArchSketchEdges"):
obj.setEditorMode("ArchSketchEdges", 0)
if hasattr(obj, "ArchSketchPropertySet"):
obj.setEditorMode("ArchSketchPropertySet", ["ReadOnly"])
def execute(self, obj):
"""Method run when the object is recomputed.
Extrude the wall from the Base shape if possible. Processe additions
and subtractions. Assign the resulting shape as the shape of the wall.
Add blocks if the MakeBlocks property is assigned. If the Base shape is
a mesh, just copy the mesh.
"""
if self.clone(obj):
return
# Wall can do without Base, validity to be tested in getExtrusionData()
# Remarked out ensureBase() below
# if not self.ensureBase(obj):
# return
import Part
import DraftGeomUtils
base = None
pl = obj.Placement
# PropertySet support
propSetPickedUuidPrev = self.ArchSkPropSetPickedUuid
propSetListPrev = self.ArchSkPropSetListPrev
propSetSelectedNamePrev = obj.ArchSketchPropertySet
propSetSelectedNameCur = None
propSetListCur = None
if Draft.getType(obj.Base) == "ArchSketch":
baseProxy = obj.Base.Proxy
if hasattr(baseProxy, "getPropertySet"):
# get full list of PropertySet
propSetListCur = baseProxy.getPropertySet(obj.Base)
# get updated name (if any) of the selected PropertySet
propSetSelectedNameCur = baseProxy.getPropertySet(
obj.Base, propSetUuid=propSetPickedUuidPrev
)
if propSetSelectedNameCur: # True if selection is not deleted
if propSetListPrev != propSetListCur:
obj.ArchSketchPropertySet = propSetListCur
obj.ArchSketchPropertySet = propSetSelectedNameCur
self.ArchSkPropSetListPrev = propSetListCur
# elif propSetListPrev == propSetListCur:
# pass #nothing to do in this case
# but if below, though (propSetListPrev == propSetListCur)
elif propSetSelectedNamePrev != propSetSelectedNameCur:
obj.ArchSketchPropertySet = propSetSelectedNameCur
else: # True if selection is deleted
if propSetListCur:
if propSetListPrev != propSetListCur:
obj.ArchSketchPropertySet = propSetListCur
obj.ArchSketchPropertySet = "Default"
# else: # Seems no need ...
# obj.PropertySet = 'Default'
extdata = self.getExtrusionData(obj)
if extdata:
base_faces = extdata[0]
extv = extdata[2].Rotation.multVec(extdata[1])
# Normalize geometry: getExtrusionData can return a single face or a list of faces.
# Normalize it to always be a list to simplify the logic below.
if not isinstance(base_faces, list):
base_faces = [base_faces]
# Determine the fusion strategy: solids should only be fused if the base is a Sketch and
# it is not a multi-layer wall.
should_fuse_solids = False
if obj.Base and obj.Base.isDerivedFrom("Sketcher::SketchObject"):
is_multi_layer = (
hasattr(obj, "Material")
and obj.Material
and hasattr(obj.Material, "Materials")
and obj.Material.Materials
)
if not is_multi_layer:
should_fuse_solids = True
# Generate solids
solids = []
for face in base_faces:
face.Placement = extdata[2].multiply(face.Placement)
solids.append(face.extrude(extv))
# Apply the fusion strategy
if should_fuse_solids:
fused_shape = None
for solid in solids:
fused_shape = fused_shape.fuse(solid) if fused_shape else solid
base = fused_shape
else:
base = Part.makeCompound(solids)
if obj.Base:
if hasattr(obj.Base, "Shape"):
if obj.Base.Shape.isNull():
return
if not obj.Base.Shape.isValid():
if not obj.Base.Shape.Solids:
# let pass invalid objects if they have solids...
return
elif obj.Base.Shape.Solids:
base = Part.Shape(obj.Base.Shape)
# blocks calculation
elif hasattr(obj, "MakeBlocks") and hasattr(self, "basewires"):
if obj.MakeBlocks and self.basewires and extdata and obj.Width and obj.Height:
# print "calculating blocks"
if len(self.basewires) == 1:
blocks = []
n = FreeCAD.Vector(extv)
n.normalize()
cuts1 = []
cuts2 = []
if obj.BlockLength.Value:
for i in range(2):
if i == 0:
offset = obj.OffsetFirst.Value
else:
offset = obj.OffsetSecond.Value
# only 1 wire (first) is supported
# TODO - Can support multiple wires?
# self.basewires was list of list of edges,
# no matter Base is DWire, Sketch or else
# See discussion - https://forum.freecad.org/viewtopic.php?t=86365
baseEdges = self.basewires[0]
for edge in baseEdges:
while offset < (edge.Length - obj.Joint.Value):
if offset:
t = edge.tangentAt(offset)
p = t.cross(n)
p.multiply(1.1 * obj.Width.Value + obj.Offset.Value)
p1 = edge.valueAt(offset).add(p)
p2 = edge.valueAt(offset).add(p.negative())
sh = Part.LineSegment(p1, p2).toShape()
if obj.Joint.Value:
sh = sh.extrude(-t.multiply(obj.Joint.Value))
sh = sh.extrude(n)
if i == 0:
cuts1.append(sh)
else:
cuts2.append(sh)
offset += obj.BlockLength.Value + obj.Joint.Value
offset -= edge.Length
if isinstance(bplates, list):
bplates = bplates[0]
if obj.BlockHeight.Value:
fsize = obj.BlockHeight.Value + obj.Joint.Value
bh = obj.BlockHeight.Value
else:
fsize = obj.Height.Value
bh = obj.Height.Value
bvec = FreeCAD.Vector(n)
bvec.multiply(bh)
svec = FreeCAD.Vector(n)
svec.multiply(fsize)
if cuts1:
plate1 = bplates.cut(cuts1).Faces
else:
plate1 = bplates.Faces
blocks1 = Part.makeCompound([f.extrude(bvec) for f in plate1])
if cuts2:
plate2 = bplates.cut(cuts2).Faces
else:
plate2 = bplates.Faces
blocks2 = Part.makeCompound([f.extrude(bvec) for f in plate2])
interval = extv.Length / (fsize)
entire = int(interval)
rest = interval - entire
for i in range(entire):
if i % 2: # odd
b = Part.Shape(blocks2)
else:
b = Part.Shape(blocks1)
if i:
t = FreeCAD.Vector(svec)
t.multiply(i)
b.translate(t)
blocks.append(b)
if rest:
rest = extv.Length - (entire * fsize)
rvec = FreeCAD.Vector(n)
rvec.multiply(rest)
if entire % 2:
b = Part.makeCompound([f.extrude(rvec) for f in plate2])
else:
b = Part.makeCompound([f.extrude(rvec) for f in plate1])
t = FreeCAD.Vector(svec)
t.multiply(entire)
b.translate(t)
blocks.append(b)
if blocks:
base = Part.makeCompound(blocks)
else:
FreeCAD.Console.PrintWarning(
translate("Arch", "Cannot compute blocks for wall")
+ obj.Label
+ "\n"
)
elif obj.Base.isDerivedFrom("Mesh::Feature"):
if obj.Base.Mesh.isSolid():
if obj.Base.Mesh.countComponents() == 1:
sh = ArchCommands.getShapeFromMesh(obj.Base.Mesh)
if sh.isClosed() and sh.isValid() and sh.Solids and (not sh.isNull()):
base = sh
else:
FreeCAD.Console.PrintWarning(
translate("Arch", "This mesh is an invalid solid") + "\n"
)
obj.Base.ViewObject.show()
if not base:
# FreeCAD.Console.PrintError(translate("Arch","Error: Invalid base object")+"\n")
# return
# walls can be made of only a series of additions and have no base shape
base = Part.Shape()
base = self.processSubShapes(obj, base, pl)
self.applyShape(obj, base, pl)
# Check if there is base, and if width and height is provided or not
# Provide users message below to check the setting of the Wall object
if base.isNull() and (self.noWidths or self.noHeight):
FreeCAD.Console.PrintWarning(
translate(
"Arch",
f"Cannot create or update {obj.Label} as its length, height or width is zero, and there are no solids in its additions",
)
+ "\n"
)
# count blocks
if hasattr(obj, "MakeBlocks"):
if obj.MakeBlocks:
fvol = obj.BlockLength.Value * obj.BlockHeight.Value * obj.Width.Value
if fvol:
# print("base volume:",fvol)
# for s in base.Solids:
# print(abs(s.Volume - fvol))
ents = [s for s in base.Solids if abs(s.Volume - fvol) < 1]
obj.CountEntire = len(ents)
obj.CountBroken = len(base.Solids) - len(ents)
else:
obj.CountEntire = 0
obj.CountBroken = 0
# set the length property
if self.connectEdges:
l = float(0)
for e in self.connectEdges:
l += e.Length
l = l / 2
if self.layersNum:
l = l / self.layersNum
if obj.Length.Value != l:
obj.Length = l
self.oldLength = (
None # delete the stored value to prevent triggering base change below
)
# set the Area property
obj.Area = obj.Length.Value * obj.Height.Value
def onBeforeChange(self, obj, prop):
"""Method called before the object has a property changed.
Specifically, this method is called before the value changes.
If "Length" has changed, record the old length so that .onChanged() can
be sure that the base needs to be changed.
Also call ArchComponent.Component.onBeforeChange().
Parameters
----------
prop: string
The name of the property that has changed.
"""
if prop == "Length":
self.oldLength = obj.Length.Value
ArchComponent.Component.onBeforeChange(self, obj, prop)
def onChanged(self, obj, prop):
"""Method called when the object has a property changed.
If length has changed, extend the length of the Base object, if the
Base object only has a single edge to extend.
Also hide subobjects.
Also call ArchComponent.Component.onChanged().
Parameters
----------
prop: string
The name of the property that has changed.
"""
if prop == "Length":
if (
obj.Base
and obj.Length.Value
and hasattr(self, "oldLength")
and (self.oldLength is not None)
and (self.oldLength != obj.Length.Value)
):
if hasattr(obj.Base, "Shape"):
if len(obj.Base.Shape.Edges) == 1:
import DraftGeomUtils
e = obj.Base.Shape.Edges[0]
if DraftGeomUtils.geomType(e) == "Line":
if e.Length != obj.Length.Value:
v = e.Vertexes[-1].Point.sub(e.Vertexes[0].Point)
v.normalize()
v.multiply(obj.Length.Value)
p2 = e.Vertexes[0].Point.add(v)
if Draft.getType(obj.Base) == "Wire":
# print "modifying p2"
obj.Base.End = p2
elif Draft.getType(obj.Base) in [
"Sketcher::SketchObject",
"ArchSketch",
]:
# obj.Base.recompute() # Fix for the 'GeoId index out range' error. Not required in V1.1.
obj.Base.moveGeometry(
0, 2, obj.Base.Placement.inverse().multVec(p2)
)
else:
FreeCAD.Console.PrintError(
translate(
"Arch",
"Error: Unable to modify the base object of this wall",
)
+ "\n"
)
if prop == "ArchSketchPropertySet" and Draft.getType(obj.Base) == "ArchSketch":
baseProxy = obj.Base.Proxy
if hasattr(baseProxy, "getPropertySet"):
uuid = baseProxy.getPropertySet(obj, propSetName=obj.ArchSketchPropertySet)
self.ArchSkPropSetPickedUuid = uuid
if (
hasattr(obj, "ArchSketchData")
and obj.ArchSketchData
and Draft.getType(obj.Base) == "ArchSketch"
):
if hasattr(obj, "Width"):
obj.setEditorMode("Width", ["ReadOnly"])
if hasattr(obj, "Align"):
obj.setEditorMode("Align", ["ReadOnly"])
if hasattr(obj, "Offset"):
obj.setEditorMode("Offset", ["ReadOnly"])
if hasattr(obj, "OverrideWidth"):
obj.setEditorMode("OverrideWidth", ["ReadOnly"])
if hasattr(obj, "OverrideAlign"):
obj.setEditorMode("OverrideAlign", ["ReadOnly"])
if hasattr(obj, "OverrideOffset"):
obj.setEditorMode("OverrideOffset", ["ReadOnly"])
if hasattr(obj, "ArchSketchEdges"):
obj.setEditorMode("ArchSketchEdges", ["ReadOnly"])
if hasattr(obj, "ArchSketchPropertySet"):
obj.setEditorMode("ArchSketchPropertySet", 0)
else:
if hasattr(obj, "Width"):
obj.setEditorMode("Width", 0)
if hasattr(obj, "Align"):
obj.setEditorMode("Align", 0)
if hasattr(obj, "Offset"):
obj.setEditorMode("Offset", 0)
if hasattr(obj, "OverrideWidth"):
obj.setEditorMode("OverrideWidth", 0)
if hasattr(obj, "OverrideAlign"):
obj.setEditorMode("OverrideAlign", 0)
if hasattr(obj, "OverrideOffset"):
obj.setEditorMode("OverrideOffset", 0)
if hasattr(obj, "ArchSketchEdges"):
obj.setEditorMode("ArchSketchEdges", 0)
if hasattr(obj, "ArchSketchPropertySet"):
obj.setEditorMode("ArchSketchPropertySet", ["ReadOnly"])
self.hideSubobjects(obj, prop)
ArchComponent.Component.onChanged(self, obj, prop)
def getFootprint(self, obj):
"""Get the faces that make up the base/foot of the wall.
Returns
-------
list of <Part.Face>
The faces that make up the foot of the wall.
"""
faces = []
if obj.Shape:
for f in obj.Shape.Faces:
if f.normalAt(0, 0).getAngle(FreeCAD.Vector(0, 0, -1)) < 0.01:
if abs(abs(f.CenterOfMass.z) - abs(obj.Shape.BoundBox.ZMin)) < 0.001:
faces.append(f)
return faces
def getExtrusionData(self, obj):
"""Get data needed to extrude the wall from a base object.
take the Base object, and find a base face to extrude
out, a vector to define the extrusion direction and distance.
Rebase the base face to the (0,0,0) origin.
Return the base face, rebased, with the extrusion vector, and the
<Base.Placement> needed to return the face back to its original
position.
Returns
-------
tuple of (<Part.Face>, <Base.Vector>, <Base.Placement>)
Tuple containing the base face, the vector for extrusion, and the
placement needed to move the face back from the (0,0,0) origin.
"""
import Part
import DraftGeomUtils
import ArchSketchObject
propSetUuid = self.ArchSkPropSetPickedUuid
# If ArchComponent.Component.getExtrusionData() can successfully get
# extrusion data, just use that.
data = ArchComponent.Component.getExtrusionData(self, obj)
if data:
if not isinstance(data[0], list):
# multifuses not considered here
return data
length = obj.Length.Value
# TODO currently layers were not supported when len(basewires) > 0 ##( or 1 ? )
self.noWidths = False
self.noHeight = False
width = 0
# Get width of each edge segment from Base Objects if they store it
# (Adding support in SketchFeaturePython, DWire...)
widths = [] # [] or None are both False
if (
hasattr(obj, "ArchSketchData")
and obj.ArchSketchData
and Draft.getType(obj.Base) == "ArchSketch"
):
if hasattr(obj.Base, "Proxy"): # TODO Any need to test ?
if hasattr(obj.Base.Proxy, "getWidths"):
# Return a list of Width corresponding to indexes of sorted
# edges of Sketch.
widths = obj.Base.Proxy.getWidths(obj.Base, propSetUuid=propSetUuid)
# Get width of each edge/wall segment from ArchWall.OverrideWidth if
# Base Object does not provide it
if not widths:
if obj.OverrideWidth:
if obj.Base and obj.Base.isDerivedFrom("Sketcher::SketchObject"):
# If Base Object is ordinary Sketch (or when ArchSketch.getWidth() not implemented yet):-
# sort the width list in OverrrideWidth to correspond to indexes of sorted edges of Sketch
try:
import ArchSketchObject
except Exception:
print("ArchSketchObject add-on module is not installed yet")
try:
widths = ArchSketchObject.sortSketchWidth(
obj.Base, obj.OverrideWidth, obj.ArchSketchEdges
)
except Exception:
widths = obj.OverrideWidth
else:
# If Base Object is not Sketch, but e.g. DWire, the width
# list in OverrrideWidth just correspond to sequential
# order of edges
widths = obj.OverrideWidth
elif obj.Width:
widths = [obj.Width.Value]
else:
## having no width is valid for walls so the user doesn't need to be warned
## it just disables extrusions and return none
## print ("Width & OverrideWidth & base.getWidths() should not be all 0 or None or [] empty list ")
#
# Having no width is valid for walls for a few cases, e.g.-
# - it has Base with solid
# - it has Additions
# A message could be provided in the Report panel for users
# to note if this is intended, then ignore extrusion afterwards,
# i.e. return None.
# Also should check Height.
self.noWidths = True
# return None
# Set 'default' width - for filling in any item in the list == 0 or None
if obj.Width.Value:
width = obj.Width.Value
else:
width = 200 # 'Default' width value
# Check height
height = obj.Height.Value
if not height:
height = self.getParentHeight(obj)
if not height:
self.noHeight = True
# Check width and height is provided or not
if self.noWidths or self.noHeight:
return None
# Get align of each edge segment from Base Objects if they store it.
# (Adding support in SketchFeaturePython, DWire...)
aligns = []
if (
hasattr(obj, "ArchSketchData")
and obj.ArchSketchData
and Draft.getType(obj.Base) == "ArchSketch"
):
if hasattr(obj.Base, "Proxy"):
if hasattr(obj.Base.Proxy, "getAligns"):
# Return a list of Align corresponds to indexes of sorted
# edges of Sketch.
aligns = obj.Base.Proxy.getAligns(obj.Base, propSetUuid=propSetUuid)
# Get align of each edge/wall segment from ArchWall.OverrideAlign if
# Base Object does not provide it
if not aligns:
if obj.OverrideAlign:
if obj.Base and obj.Base.isDerivedFrom("Sketcher::SketchObject"):
# If Base Object is ordinary Sketch (or when
# ArchSketch.getAligns() not implemented yet):- sort the
# align list in OverrideAlign to correspond to indexes of
# sorted edges of Sketch
try:
import ArchSketchObject
except Exception:
print("ArchSketchObject add-on module is not installed yet")
try:
aligns = ArchSketchObject.sortSketchAlign(
obj.Base, obj.OverrideAlign, obj.ArchSketchEdges
)
except Exception:
aligns = obj.OverrideAlign
else:
# If Base Object is not Sketch, but e.g. DWire, the align
# list in OverrideAlign just correspond to sequential order
# of edges
aligns = obj.OverrideAlign
else:
aligns = [obj.Align]
# set 'default' align - for filling in any item in the list == 0 or None
align = obj.Align # or aligns[0]
# Get offset of each edge segment from Base Objects if they store it
# (Adding support in SketchFeaturePython, DWire...)
offsets = [] # [] or None are both False
if (
hasattr(obj, "ArchSketchData")
and obj.ArchSketchData
and Draft.getType(obj.Base) == "ArchSketch"
):
if hasattr(obj.Base, "Proxy"):
if hasattr(obj.Base.Proxy, "getOffsets"):
# Return a list of Offset corresponding to indexes of sorted
# edges of Sketch.
offsets = obj.Base.Proxy.getOffsets(obj.Base, propSetUuid=propSetUuid)
# Get offset of each edge/wall segment from ArchWall.OverrideOffset if
# Base Object does not provide it
if not offsets:
if obj.OverrideOffset:
if obj.Base and obj.Base.isDerivedFrom("Sketcher::SketchObject"):
# If Base Object is ordinary Sketch (or when ArchSketch.getOffsets() not implemented yet):-
# sort the offset list in OverrideOffset to correspond to indexes of sorted edges of Sketch
if hasattr(ArchSketchObject, "sortSketchOffset"):
offsets = ArchSketchObject.sortSketchOffset(
obj.Base, obj.OverrideOffset, obj.ArchSketchEdges
)
else:
offsets = obj.OverrideOffset
else:
# If Base Object is not Sketch, but e.g. DWire, the width
# list in OverrrideWidth just correspond to sequential
# order of edges
offsets = obj.OverrideOffset
elif obj.Offset:
offsets = [obj.Offset.Value]
# Set 'default' offset - for filling in any item in the list == 0 or None
offset = obj.Offset.Value # could be 0
if obj.Normal == Vector(0, 0, 0):
if obj.Base and hasattr(obj.Base, "Shape"):
normal = DraftGeomUtils.get_shape_normal(obj.Base.Shape)
if normal is None:
normal = Vector(0, 0, 1)
else:
normal = Vector(0, 0, 1)
else:
normal = Vector(obj.Normal)
base = None
placement = None
self.basewires = None
# build wall layers
layers = []
if hasattr(obj, "Material"):
if obj.Material:
if hasattr(obj.Material, "Materials"):
thicknesses = [abs(t) for t in obj.Material.Thicknesses]
# multimaterials
varwidth = 0
restwidth = width - sum(thicknesses)
if restwidth > 0:
varwidth = [t for t in thicknesses if t == 0]
if varwidth:
varwidth = restwidth / len(varwidth)
for t in obj.Material.Thicknesses:
if t:
layers.append(t)
elif varwidth:
layers.append(varwidth)
# Check if there is obj.Base and its validity to proceed
if self.ensureBase(obj):
if hasattr(obj.Base, "Shape"):
if obj.Base.Shape:
if obj.Base.Shape.Solids:
return None
# If the user has defined a specific face of the Base
# object to build the wall from, extrude from that face,
# and return the extrusion moved to (0,0,0), normal of the
# face, and placement to move the extrusion back to its
# original position.
elif obj.Face > 0:
if len(obj.Base.Shape.Faces) >= obj.Face:
face = obj.Base.Shape.Faces[obj.Face - 1]
if obj.Normal != Vector(0, 0, 0):
normal = face.normalAt(0, 0)
if normal.getAngle(Vector(0, 0, 1)) > math.pi / 4:
normal.multiply(width)
base = face.extrude(normal)
if obj.Align == "Center":
base.translate(normal.negative().multiply(0.5))
elif obj.Align == "Right":
base.translate(normal.negative())
else:
normal.multiply(height)
base = face.extrude(normal)
base, placement = self.rebase(base)
return (base, normal, placement)
# If the Base has faces, but no specific one has been
# selected, rebase the faces and continue.
elif obj.Base.Shape.Faces:
if not DraftGeomUtils.isCoplanar(obj.Base.Shape.Faces):
return None
else:
base, placement = self.rebase(obj.Base.Shape)
elif (
hasattr(obj.Base, "Proxy")
and obj.ArchSketchData
and hasattr(obj.Base.Proxy, "getWallBaseShapeEdgesInfo")
):
wallBaseShapeEdgesInfo = obj.Base.Proxy.getWallBaseShapeEdgesInfo(
obj.Base, propSetUuid=propSetUuid
)
# get wall edges (not wires); use original edges if getWallBaseShapeEdgesInfo() provided none
if wallBaseShapeEdgesInfo:
self.basewires = wallBaseShapeEdgesInfo.get(
"wallAxis"
) # 'wallEdges' # widths, aligns, offsets?
# Sort Sketch edges consistently with below procedures
# without using Sketch.Shape.Edges - found the latter order
# in some corner case != getSortedClusters()
elif obj.Base.isDerivedFrom("Sketcher::SketchObject"):
self.basewires = []
skGeom = obj.Base.GeometryFacadeList
skGeomEdges = []
skPlacement = obj.Base.Placement # Get Sketch's placement to restore later
# Get ArchSketch edges to construct ArchWall
# No need to test obj.ArchSketchData ...
for ig, geom in enumerate(skGeom):
# Construction mode edges should be ignored if
# ArchSketchEdges, otherwise, ArchSketchEdges data
# needs to take out those in Construction before
# using as parameters.
if (not obj.ArchSketchEdges and not geom.Construction) or str(
ig
) in obj.ArchSketchEdges:
# support Line, Arc, Circle, Ellipse for Sketch
# as Base at the moment
if isinstance(
geom.Geometry,
(Part.LineSegment, Part.Circle, Part.ArcOfCircle, Part.Ellipse),
):
skGeomEdgesI = geom.Geometry.toShape()
skGeomEdges.append(skGeomEdgesI)
for cluster in Part.getSortedClusters(skGeomEdges):
clusterTransformed = []
for edge in cluster:
# TODO 2023.11.26: Multiplication order should be switched?
# So far 'no problem' as 'edge.placement' is always '0,0,0' ?
edge.Placement = edge.Placement.multiply(
skPlacement
) ## TODO add attribute to skip Transform...
clusterTransformed.append(edge)
# Only use cluster of edges rather than turning into wire
self.basewires.append(clusterTransformed)
# Use Sketch's Normal for all edges/wires generated
# from sketch for consistency. Discussion on checking
# normal of sketch.Placement vs
# sketch.getGlobalPlacement() -
# https://forum.freecad.org/viewtopic.php?f=22&t=39341&p=334275#p334275
# normal = obj.Base.Placement.Rotation.multVec(FreeCAD.Vector(0,0,1))
normal = obj.Base.getGlobalPlacement().Rotation.multVec(
FreeCAD.Vector(0, 0, 1)
)
else: # For all objects except Sketch, single edge or more
# See discussion - https://forum.freecad.org/viewtopic.php?t=86365
# See discussion - https://forum.freecad.org/viewtopic.php?t=82207&start=10
# self.basewires = obj.Base.Shape.Wires
#
# Now, adopt approach same as for Sketch
self.basewires = []
clusters = Part.getSortedClusters(obj.Base.Shape.Edges)
self.basewires = clusters
# Previously :
# Found case that after sorting below, direction of
# edges sorted are not as 'expected' thus resulted in
# bug - e.g. a Dwire with edges/vertexes in clockwise
# order, 1st vertex is Forward as expected. After
# sorting below, edges sorted still in clockwise order
# - no problem, but 1st vertex of each edge become
# Reverse rather than Forward.
# See FC discussion -
# https://forum.freecad.org/viewtopic.php?f=23&t=48275&p=413745#p413745
# self.basewires = []
# for cluster in Part.getSortedClusters(obj.Base.Shape.Edges):
# for c in Part.sortEdges(cluster):
# self.basewires.append(Part.Wire(c))
# if not sketch, e.g. Dwire, can have wire which is 3d
# so not on the placement's working plane - below
# applied to Sketch not applicable here
# normal = obj.Base.getGlobalPlacement().Rotation.multVec(FreeCAD.Vector(0,0,1))
# normal = obj.Base.Placement.Rotation.multVec(FreeCAD.Vector(0,0,1))
if self.basewires:
if (len(self.basewires) == 1) and layers:
self.basewires = [self.basewires[0] for l in layers]
self.layersNum = len(layers)
else:
self.layersNum = 0
layeroffset = 0
baseface = None
self.connectEdges = []
for i, wire in enumerate(self.basewires):
# Check number of edges per 'wire' and get the 1st edge
if isinstance(wire, Part.Wire):
edgeNum = len(wire.Edges)
e = wire.Edges[0]
elif isinstance(wire[0], Part.Edge):
edgeNum = len(wire)
e = wire[0]
for n in range(
0, edgeNum, 1
): # why these not work - range(edgeNum), range(0,edgeNum) ...
# Fill the aligns list with ArchWall's default
# align entry and with same number of items as
# number of edges
try:
if aligns[n] not in ["Left", "Right", "Center"]:
aligns[n] = align
except Exception:
aligns.append(align)
# Fill the widths List with ArchWall's default
# width entry and with same number of items as
# number of edges
try:
if not widths[n]:
widths[n] = width
except Exception:
widths.append(width)
# Fill the offsets List with ArchWall's default
# offset entry and with same number of items as
# number of edges
try:
if not offsets[n]:
offsets[n] = offset
except Exception:
offsets.append(offset)
# Get a direction vector orthogonal to both the
# normal of the face/sketch and the direction the
# wire was drawn in. IE: along the width direction
# of the wall.
if isinstance(e.Curve, (Part.Circle, Part.Ellipse)):
dvec = e.Vertexes[0].Point.sub(e.Curve.Center)
else:
dvec = DraftGeomUtils.vec(e).cross(normal)
if not DraftVecUtils.isNull(dvec):
dvec.normalize()
face = None
curAligns = aligns[0]
# off = obj.Offset.Value # off is no longer used
if curAligns == "Left":
if layers:
curWidth = []
for n in range(edgeNum):
curWidth.append(abs(layers[i]))
# off = off+layeroffset # off is no longer used
offsets = [x + layeroffset for x in offsets]
dvec.multiply(curWidth[0])
layeroffset += abs(curWidth[0])
else:
curWidth = widths
dvec.multiply(width)
# Now DraftGeomUtils.offsetWire() support
# similar effect as ArchWall Offset
#
# if off:
# dvec2 = DraftVecUtils.scaleTo(dvec,off)
# wire = DraftGeomUtils.offsetWire(wire,dvec2)
# Get the 'offseted' wire taking into account
# of Width and Align of each edge, and overall
# Offset
wNe2 = DraftGeomUtils.offsetWire(
wire,
dvec,
bind=False,
occ=False,
widthList=curWidth,
offsetMode=None,
alignList=aligns,
normal=normal,
basewireOffset=offsets,
wireNedge=True,
)
# Get the 'base' wire taking into account of
# width and align of each edge
wNe1 = DraftGeomUtils.offsetWire(
wire,
dvec,
bind=False,
occ=False,
widthList=curWidth,
offsetMode="BasewireMode",
alignList=aligns,
normal=normal,
basewireOffset=offsets,
wireNedge=True,
)
elif curAligns == "Right":
dvec = dvec.negative()
if layers:
curWidth = []
for n in range(edgeNum):
curWidth.append(abs(layers[i]))
# off = off+layeroffset # off is no longer used
offsets = [x + layeroffset for x in offsets]
dvec.multiply(curWidth[0])
layeroffset += abs(curWidth[0])
else:
curWidth = widths
dvec.multiply(width)
# Now DraftGeomUtils.offsetWire() support similar effect as ArchWall Offset
#
# if off:
# dvec2 = DraftVecUtils.scaleTo(dvec,off)
# wire = DraftGeomUtils.offsetWire(wire,dvec2)
wNe2 = DraftGeomUtils.offsetWire(
wire,
dvec,
bind=False,
occ=False,
widthList=curWidth,
offsetMode=None,
alignList=aligns,
normal=normal,
basewireOffset=offsets,
wireNedge=True,
)
wNe1 = DraftGeomUtils.offsetWire(
wire,
dvec,
bind=False,
occ=False,
widthList=curWidth,
offsetMode="BasewireMode",
alignList=aligns,
normal=normal,
basewireOffset=offsets,
wireNedge=True,
)
elif curAligns == "Center":
if layers:
# TODO Current, the order of layers follow
# "Right" align. Option for the order of
# layers follow "Left" align should be
# provided for users.
dvec = dvec.negative()
totalwidth = sum([abs(l) for l in layers])
off = totalwidth / 2 - layeroffset
# TODO To consider offset per edge?
#
# Offset follows direction of align "Right".
# Needs to be reversed in this case.
off = -off
# d1 = Vector(dvec).multiply(off)
curWidth = []
alignListC = []
offsetListC = []
for n in range(edgeNum):
curWidth.append(abs(layers[i]))
alignListC.append("Right") # ("Left")
offsetListC.append(off)
# wNe1 = DraftGeomUtils.offsetWire(wire, d1, wireNedge=True)
# See https://github.com/FreeCAD/FreeCAD/issues/25485#issuecomment-3566734050
# d1 may be Vector (0,0,0), offsetWire()
# in draftgeoutils\offsets.py:-
# v1 = App.Vector(dvec).normalize() return
# error. Provide widthList, alignList etc.
# so no need to run above code to deduce
# v1 in offsetWire()
wNe1 = DraftGeomUtils.offsetWire(
wire,
dvec,
widthList=curWidth,
offsetMode="BasewireMode",
alignList=alignListC,
normal=normal,
basewireOffset=offsetListC,
wireNedge=True,
)
wNe2 = DraftGeomUtils.offsetWire(
wire,
dvec,
widthList=curWidth,
offsetMode=None,
alignList=alignListC,
normal=normal,
basewireOffset=offsetListC,
wireNedge=True,
)
layeroffset += abs(curWidth[0])
else:
dvec.multiply(width)
wNe2 = DraftGeomUtils.offsetWire(
wire,
dvec,
bind=False,
occ=False,
widthList=widths,
offsetMode=None,
alignList=aligns,
normal=normal,
basewireOffset=offsets,
wireNedge=True,
)
wNe1 = DraftGeomUtils.offsetWire(
wire,
dvec,
bind=False,
occ=False,
widthList=widths,
offsetMode="BasewireMode",
alignList=aligns,
normal=normal,
basewireOffset=offsets,
wireNedge=True,
)
w2 = wNe2[0]
w1 = wNe1[0]
face = DraftGeomUtils.bind(w1, w2, per_segment=True)
cEdgesF2 = wNe2[1]
cEdges2 = wNe2[2]
oEdges2 = wNe2[3]
cEdgesF1 = wNe1[1]
cEdges1 = wNe1[2]
oEdges1 = wNe1[3]
self.connectEdges.extend(cEdges2)
self.connectEdges.extend(cEdges1)
del widths[0:edgeNum]
del aligns[0:edgeNum]
del offsets[0:edgeNum]
if face:
if layers and (layers[i] < 0):
# layers with negative values are not drawn
continue
if baseface:
# To allow exportIFC.py to work properly on
# sketch, which use only 1st face / wire,
# do not fuse baseface here So for a sketch
# with multiple wires, each returns
# individual face (rather than fusing
# together) for exportIFC.py to work
# properly
# "ArchWall - Based on Sketch Issues" - https://forum.freecad.org/viewtopic.php?f=39&t=31235
# "Bug #2408: [PartDesign] .fuse is splitting edges it should not"
# - https://forum.freecad.org/viewtopic.php?f=10&t=20349&p=346237#p346237
# - bugtracker - https://freecad.org/tracker/view.php?id=2408
# Try Part.Shell before removeSplitter
# - https://forum.freecad.org/viewtopic.php?f=10&t=20349&start=10
# - 1st finding : if a rectangle + 1 line, can't removesSplitter properly...
# - 2nd finding : if 2 faces do not touch, can't form a shell; then, subsequently for remaining faces even though touch each faces, can't form a shell
baseface.append(face)
# The above make Refine methods below (in else) useless, regardless removeSpitters yet to be improved for cases do not work well
""" Whether layers or not, all baseface.append(face) """
else:
baseface = [face]
""" Whether layers or not, all baseface = [face] """
if baseface:
base, placement = self.rebase(baseface)
# Build Wall from scratch if there is no obj.Base or even obj.Base is not valid
else:
base, placement = self.build_base_from_scratch(obj)
if base and placement:
normal.normalize()
extrusion = normal.multiply(height)
if placement.Rotation.Angle > 0:
extrusion = placement.inverse().Rotation.multVec(extrusion)
return (base, extrusion, placement)
return None
def calc_endpoints(self, obj):
"""Returns the global start and end points of a baseless wall's centerline."""
# The wall's shape is centered, so its endpoints in local coordinates
# are at (-Length/2, 0, 0) and (+Length/2, 0, 0).
p1_local = FreeCAD.Vector(-obj.Length.Value / 2, 0, 0)
p2_local = FreeCAD.Vector(obj.Length.Value / 2, 0, 0)
# Transform these local points into global coordinates using the wall's placement.
p1_global = obj.Placement.multVec(p1_local)
p2_global = obj.Placement.multVec(p2_local)
return [p1_global, p2_global]
def set_from_endpoints(self, obj, pts):
"""Sets the Length and Placement of a baseless wall from two global points."""
if len(pts) < 2:
return
p1 = pts[0]
p2 = pts[1]
# Recalculate the wall's properties based on the new endpoints
new_length = p1.distanceToPoint(p2)
new_midpoint = (p1 + p2) * 0.5
new_direction = (p2 - p1).normalize()
# Calculate the rotation required to align the local X-axis with the new direction
new_rotation = FreeCAD.Rotation(FreeCAD.Vector(1, 0, 0), new_direction)
# Apply the new properties to the wall object
obj.Length = new_length
obj.Placement.Base = new_midpoint
obj.Placement.Rotation = new_rotation
def handleComponentRemoval(self, obj, subobject):
"""
Overrides the default component removal to implement smart debasing
when the Base object is being removed.
"""
import Arch
from PySide import QtGui
# Check if the component being removed is this wall's Base
if hasattr(obj, "Base") and obj.Base == subobject:
if Arch.is_debasable(obj):
# This is a valid, single-line wall. Perform a clean debase.
Arch.debaseWall(obj)
else:
# This is a complex wall. Behavior depends on GUI availability.
if FreeCAD.GuiUp:
# --- GUI Path: Warn the user and ask for confirmation. ---
from PySide import QtGui
msg_box = QtGui.QMessageBox()
msg_box.setWindowTitle(translate("ArchComponent", "Unsupported Base"))
msg_box.setText(
translate(
"ArchComponent", "The base of this wall is not a single straight line."
)
)
msg_box.setInformativeText(
translate(
"ArchComponent",
"Removing the base of this complex wall will alter its shape and reset its position.\n\n"
"Do you want to proceed?",
)
)
msg_box.setStandardButtons(QtGui.QMessageBox.Yes | QtGui.QMessageBox.Cancel)
msg_box.setDefaultButton(QtGui.QMessageBox.Cancel)
if msg_box.exec_() == QtGui.QMessageBox.Yes:
# User confirmed, perform the standard removal
super(_Wall, self).handleComponentRemoval(obj, subobject)
else:
# --- Headless Path: Do not perform the destructive action. Print a warning. ---
FreeCAD.Console.PrintWarning(
f"Skipping removal of complex base for wall '{obj.Label}'. "
"This interactive action is not supported in headless mode.\n"
)
else:
# If it's not the base (e.g., an Addition), use the default behavior
# from the parent Component class.
super(_Wall, self).handleComponentRemoval(obj, subobject)
def get_width(self, obj, widths=True):
"""Returns a width and a list of widths for this wall.
If widths is False, only the main width is returned"""
import ArchSketchObject
# Set 'default' width - for filling in any item in the list == 0 or None
if obj.Width.Value:
width = obj.Width.Value
else:
width = 200 # 'Default' width value
if not widths:
return width
lwidths = []
if (
hasattr(obj, "ArchSketchData")
and obj.ArchSketchData
and Draft.getType(obj.Base) == "ArchSketch"
):
if hasattr(obj.Base, "Proxy"):
if hasattr(obj.Base.Proxy, "getWidths"):
lwidths = obj.Base.Proxy.getWidths(
obj.Base, propSetUuid=self.ArchSkPropSetPickedUuid
)
if not lwidths:
if obj.OverrideWidth:
if obj.Base and obj.Base.isDerivedFrom("Sketcher::SketchObject"):
lwidths = ArchSketchObject.sortSketchWidth(
obj.Base, obj.OverrideWidth, obj.ArchSketchEdges
)
else:
lwidths = obj.OverrideWidth
elif obj.Width:
lwidths = [obj.Width.Value]
else:
return None
return width, lwidths
def get_layers(self, obj):
"""Returns a list of layers"""
layers = []
width = self.get_width(obj, widths=False)
if hasattr(obj, "Material"):
if obj.Material:
if hasattr(obj.Material, "Materials"):
thicknesses = [abs(t) for t in obj.Material.Thicknesses]
restwidth = width - sum(thicknesses)
varwidth = 0
if restwidth > 0:
varwidth = [t for t in thicknesses if t == 0]
if varwidth:
varwidth = restwidth / len(varwidth)
for t in obj.Material.Thicknesses:
if t:
layers.append(t)
elif varwidth:
layers.append(varwidth)
return layers
def build_base_from_scratch(self, obj):
"""Generate the 2D profile for extruding a baseless Arch Wall.
This function creates the rectangular face or faces that form the wall's cross-section,
which is then used by the caller for extrusion. It handles both single- and multi-layer wall
configurations.
Parameters
----------
obj : FreeCAD.DocumentObject
The wall object being built. Its Length, Align, and layer
properties are used.
Returns
-------
tuple of (list of Part.Face, FreeCAD.Placement)
A tuple containing two elements:
1. A list of one or more Part.Face objects representing the cross-section.
2. An identity Placement, as the geometry is in local coordinates.
Notes
-----
The geometry follows the convention where `Align='Left'` offsets the wall in the negative-Y
direction (the geometric right).
"""
import Part
def _create_face_from_coords(half_length, y_min, y_max):
"""Creates a rectangular Part.Face centered on the X-axis, defined by Y coordinates."""
bottom_left = Vector(-half_length, y_min, 0)
bottom_right = Vector(half_length, y_min, 0)
top_right = Vector(half_length, y_max, 0)
top_left = Vector(-half_length, y_max, 0)
return Part.Face(
Part.makePolygon([bottom_left, bottom_right, top_right, top_left, bottom_left])
)
layers = self.get_layers(obj)
width = self.get_width(obj, widths=False)
align = obj.Align
# Use a small default for zero dimensions to ensure a valid shape can be created.
safe_length = obj.Length.Value or 0.5
if not layers:
safe_width = width or 0.5
layers = [safe_width] # Treat a single-layer wall as a multi-layer wall with one layer.
# --- Calculate and Create Geometry ---
base_faces = []
# The total width is needed to calculate the starting offset for alignment.
totalwidth = sum([abs(layer) for layer in layers])
# The offset acts as a cursor, tracking the current position along the Y-axis.
offset = 0
if align == "Center":
offset = -totalwidth / 2
elif align == "Left":
# Per convention, 'Left' is on the geometric right (-Y direction).
offset = -totalwidth
# Loop through all layers and create a face for each.
for layer in layers:
# A negative layer value is not drawn, so its geometry is skipped.
if layer > 0:
half_length = safe_length / 2
layer_y_min = offset
layer_y_max = offset + layer
face = _create_face_from_coords(half_length, layer_y_min, layer_y_max)
base_faces.append(face)
# The offset is always increased by the absolute thickness of the layer.
offset += abs(layer)
placement = FreeCAD.Placement()
return base_faces, placement
class _ViewProviderWall(ArchComponent.ViewProviderComponent):
"""The view provider for the wall object.
Parameters
----------
vobj: <Gui.ViewProviderDocumentObject>
The view provider to turn into a wall view provider.
"""
def __init__(self, vobj):
ArchComponent.ViewProviderComponent.__init__(self, vobj)
vobj.ShapeColor = ArchCommands.getDefaultColor("Wall")
def getIcon(self):
"""Return the path to the appropriate icon.
If a clone, return the cloned wall icon path. Otherwise return the
Arch wall icon.
Returns
-------
str
Path to the appropriate icon .svg file.
"""
import Arch_rc
if hasattr(self, "Object"):
if self.Object.CloneOf:
return ":/icons/Arch_Wall_Clone.svg"
elif (not self.Object.Base) and self.Object.Additions:
return ":/icons/Arch_Wall_Tree_Assembly.svg"
return ":/icons/Arch_Wall_Tree.svg"
def attach(self, vobj):
"""Add display modes' data to the coin scenegraph.
Add each display mode as a coin node, whose parent is this view
provider.
Each display mode's node includes the data needed to display the object
in that mode. This might include colors of faces, or the draw style of
lines. This data is stored as additional coin nodes which are children
of the display mode node.
Add the textures used in the Footprint display mode.
"""
self.Object = vobj.Object
from pivy import coin
tex = coin.SoTexture2()
image = Draft.loadTexture(Draft.svgpatterns()["simple"][1], 128)
if not image is None:
tex.image = image
texcoords = coin.SoTextureCoordinatePlane()
s = params.get_param_arch("patternScale")
texcoords.directionS.setValue(s, 0, 0)
texcoords.directionT.setValue(0, s, 0)
self.fcoords = coin.SoCoordinate3()
self.fset = coin.SoIndexedFaceSet()
sep = coin.SoSeparator()
sep.addChild(tex)
sep.addChild(texcoords)
sep.addChild(self.fcoords)
sep.addChild(self.fset)
vobj.RootNode.addChild(sep)
ArchComponent.ViewProviderComponent.attach(self, vobj)
def updateData(self, obj, prop):
"""Method called when the host object has a property changed.
If the host object's Placement, Shape, or Material has changed, and the
host object has a Material assigned, give the shape the color and
transparency of the Material.
Parameters
----------
obj: <App::FeaturePython>
The host object that has changed.
prop: string
The name of the property that has changed.
"""
if prop in ["Placement", "Shape", "Material"]:
if obj.ViewObject.DisplayMode == "Footprint":
obj.ViewObject.Proxy.setDisplayMode("Footprint")
if hasattr(obj, "Material"):
if obj.Material and obj.Shape:
if hasattr(obj.Material, "Materials"):
activematerials = [
obj.Material.Materials[i]
for i in range(len(obj.Material.Materials))
if obj.Material.Thicknesses[i] >= 0
]
if len(activematerials) == len(obj.Shape.Solids):
cols = []
for i, mat in enumerate(activematerials):
c = obj.ViewObject.ShapeColor
c = (c[0], c[1], c[2], 1.0 - obj.ViewObject.Transparency / 100.0)
if "DiffuseColor" in mat.Material:
if "(" in mat.Material["DiffuseColor"]:
c = tuple(
[
float(f)
for f in mat.Material["DiffuseColor"]
.strip("()")
.split(",")
]
)
if "Transparency" in mat.Material:
c = (
c[0],
c[1],
c[2],
1.0 - float(mat.Material["Transparency"]),
)
cols.extend([c for j in range(len(obj.Shape.Solids[i].Faces))])
obj.ViewObject.DiffuseColor = cols
ArchComponent.ViewProviderComponent.updateData(self, obj, prop)
if len(obj.ViewObject.DiffuseColor) > 1:
# force-reset colors if changed
obj.ViewObject.DiffuseColor = obj.ViewObject.DiffuseColor
def getDisplayModes(self, vobj):
"""Define the display modes unique to the Arch Wall.
Define mode Footprint, which only displays the footprint of the wall.
Also add the display modes of the Arch Component.
Returns
-------
list of str
List containing the names of the new display modes.
"""
modes = ArchComponent.ViewProviderComponent.getDisplayModes(self, vobj) + ["Footprint"]
return modes
def setDisplayMode(self, mode):
"""Method called when the display mode changes.
Called when the display mode changes, this method can be used to set
data that wasn't available when .attach() was called.
When Footprint is set as display mode, find the faces that make up the
footprint of the wall, and give them a lined texture. Then display
the wall as a wireframe.
Then pass the displaymode onto Arch Component's .setDisplayMode().
Parameters
----------
mode: str
The name of the display mode the view provider has switched to.
Returns
-------
str:
The name of the display mode the view provider has switched to.
"""
self.fset.coordIndex.deleteValues(0)
self.fcoords.point.deleteValues(0)
if mode == "Footprint":
if hasattr(self, "Object"):
faces = self.Object.Proxy.getFootprint(self.Object)
if faces:
verts = []
fdata = []
idx = 0
for face in faces:
tri = face.tessellate(1)
for v in tri[0]:
verts.append([v.x, v.y, v.z])
for f in tri[1]:
fdata.extend([f[0] + idx, f[1] + idx, f[2] + idx, -1])
idx += len(tri[0])
self.fcoords.point.setValues(verts)
self.fset.coordIndex.setValues(0, len(fdata), fdata)
return "Wireframe"
return ArchComponent.ViewProviderComponent.setDisplayMode(self, mode)
def setupContextMenu(self, vobj, menu):
if FreeCADGui.activeWorkbench().name() != "BIMWorkbench":
return
super().contextMenuAddEdit(menu)
actionFlipDirection = QtGui.QAction(
QtGui.QIcon(":/icons/Arch_Wall_Tree.svg"), translate("Arch", "Flip Direction"), menu
)
QtCore.QObject.connect(
actionFlipDirection, QtCore.SIGNAL("triggered()"), self.flipDirection
)
menu.addAction(actionFlipDirection)
super().contextMenuAddToggleSubcomponents(menu)
def flipDirection(self):
if hasattr(self, "Object") and self.Object:
obj = self.Object
if obj.Align == "Left":
obj.Align = "Right"
FreeCAD.ActiveDocument.recompute()
elif obj.Align == "Right":
obj.Align = "Left"
FreeCAD.ActiveDocument.recompute()
|