topologicpy 0.4.37__py3-none-any.whl → 0.4.38__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- topologicpy/Plotly.py +33 -24
- topologicpy/Topology.py +583 -603
- topologicpy/__init__.py +1 -1
- {topologicpy-0.4.37.dist-info → topologicpy-0.4.38.dist-info}/METADATA +1 -1
- {topologicpy-0.4.37.dist-info → topologicpy-0.4.38.dist-info}/RECORD +8 -8
- {topologicpy-0.4.37.dist-info → topologicpy-0.4.38.dist-info}/LICENSE +0 -0
- {topologicpy-0.4.37.dist-info → topologicpy-0.4.38.dist-info}/WHEEL +0 -0
- {topologicpy-0.4.37.dist-info → topologicpy-0.4.38.dist-info}/top_level.txt +0 -0
topologicpy/Topology.py
CHANGED
|
@@ -1517,122 +1517,359 @@ class Topology():
|
|
|
1517
1517
|
The list of imported topologies. If the list only contains one element, it returns that element.
|
|
1518
1518
|
|
|
1519
1519
|
"""
|
|
1520
|
+
|
|
1520
1521
|
from topologicpy.Dictionary import Dictionary
|
|
1522
|
+
from topologicpy.Context import Context
|
|
1523
|
+
from topologicpy.Vertex import Vertex
|
|
1524
|
+
from topologicpy.Edge import Edge
|
|
1525
|
+
from topologicpy.Wire import Wire
|
|
1526
|
+
from topologicpy.Face import Face
|
|
1527
|
+
from topologicpy.Shell import Shell
|
|
1528
|
+
from topologicpy.Cell import Cell
|
|
1529
|
+
from topologicpy.CellComplex import CellComplex
|
|
1530
|
+
from topologicpy.Cluster import Cluster
|
|
1531
|
+
from topologicpy.Aperture import Aperture
|
|
1521
1532
|
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1533
|
+
|
|
1534
|
+
def getUUID(topology, uuidKey="uuid"):
|
|
1535
|
+
d = Topology.Dictionary(topology)
|
|
1536
|
+
if d == None:
|
|
1537
|
+
uuidOne = str(uuid.uuid1())
|
|
1538
|
+
d = Dictionary.ByKeyValue(uuidKey, uuidOne)
|
|
1539
|
+
elif uuidKey not in Dictionary.Keys(d):
|
|
1540
|
+
uuidOne = str(uuid.uuid1())
|
|
1541
|
+
d = Dictionary.SetValueAtKey(d, uuidKey, uuidOne)
|
|
1542
|
+
topology = Topology.SetDictionary(topology, d)
|
|
1543
|
+
else:
|
|
1544
|
+
uuidOne = Dictionary.ValueAtKey(d, uuidKey)
|
|
1545
|
+
return uuidOne
|
|
1546
|
+
|
|
1547
|
+
def find_json_item(json_list, key, value):
|
|
1548
|
+
for item in json_list:
|
|
1549
|
+
if key in item and item[key] == value:
|
|
1550
|
+
return item
|
|
1539
1551
|
return None
|
|
1540
1552
|
|
|
1541
|
-
def
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
if
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1553
|
+
def buildAperture(j_aperture):
|
|
1554
|
+
j_vertices = []
|
|
1555
|
+
j_edges = []
|
|
1556
|
+
j_wires = []
|
|
1557
|
+
j_faces = []
|
|
1558
|
+
j_shells = []
|
|
1559
|
+
j_cells = []
|
|
1560
|
+
j_cellComplexes = []
|
|
1561
|
+
for jsonItem in j_aperture:
|
|
1562
|
+
topology_type = jsonItem['type']
|
|
1563
|
+
if topology_type.lower() == "vertex":
|
|
1564
|
+
j_vertices.append(jsonItem)
|
|
1565
|
+
elif topology_type.lower() == "edge":
|
|
1566
|
+
j_edges.append(jsonItem)
|
|
1567
|
+
elif topology_type.lower() == "wire":
|
|
1568
|
+
j_wires.append(jsonItem)
|
|
1569
|
+
elif topology_type.lower() == "face":
|
|
1570
|
+
j_faces.append(jsonItem)
|
|
1571
|
+
elif topology_type.lower() == "shell":
|
|
1572
|
+
j_shells.append(jsonItem)
|
|
1573
|
+
elif topology_type.lower() == "cell":
|
|
1574
|
+
j_cells.append(jsonItem)
|
|
1575
|
+
elif topology_type.lower() == "cellcomplex":
|
|
1576
|
+
j_cellComplexes.append(jsonItem)
|
|
1577
|
+
|
|
1578
|
+
vertices = [buildVertex(j_v) for j_v in j_vertices]
|
|
1579
|
+
edges = [buildEdge(j_e, j_vertices, uuidKey="uuid") for j_e in j_edges]
|
|
1580
|
+
wires = [buildWire(j_w, j_edges, j_vertices, uuidKey="uuid") for j_w in j_wires]
|
|
1581
|
+
faces = [buildFace(j_f, j_wires, j_edges, j_vertices, uuidKey="uuid") for j_f in j_faces]
|
|
1582
|
+
shells = [buildShell(j_s, j_faces, j_wires, j_edges, j_vertices, uuidKey="uuid") for j_s in j_shells]
|
|
1583
|
+
cells = [buildCell(j_c, j_shells, j_faces, j_wires, j_edges, j_vertices, uuidKey="uuid") for j_c in j_cells]
|
|
1584
|
+
cellComplexes = [buildCellComplex(j_cc, j_cells, j_shells, j_faces, j_wires, j_edges, j_vertices, uuidKey="uuid") for j_cc in j_cellComplexes]
|
|
1585
|
+
if len(cellComplexes) > 0:
|
|
1586
|
+
everything = cellComplexes
|
|
1587
|
+
elif len(cells) > 0:
|
|
1588
|
+
everything = cells
|
|
1589
|
+
elif len(shells) > 0:
|
|
1590
|
+
everything = shells
|
|
1591
|
+
elif len(faces) > 0:
|
|
1592
|
+
everything = faces
|
|
1593
|
+
elif len(wires) > 0:
|
|
1594
|
+
everything = wires
|
|
1595
|
+
elif len(edges) > 0:
|
|
1596
|
+
everything = edges
|
|
1597
|
+
elif len(vertices) > 0:
|
|
1598
|
+
everything = vertices
|
|
1599
|
+
else:
|
|
1600
|
+
return None
|
|
1601
|
+
if len(everything) == 1:
|
|
1602
|
+
aperture = everything[0]
|
|
1603
|
+
else:
|
|
1604
|
+
aperture = Topology.SelfMerge(Cluster.ByTopologies(everything))
|
|
1605
|
+
return aperture
|
|
1606
|
+
|
|
1607
|
+
def buildVertex(json_item):
|
|
1608
|
+
x, y, z = json_item['coordinates']
|
|
1609
|
+
d = json_item['dictionary']
|
|
1610
|
+
v = Vertex.ByCoordinates(x,y,z)
|
|
1611
|
+
v = Topology.SetDictionary(v, Dictionary.ByPythonDictionary(d))
|
|
1612
|
+
apertures = [buildAperture(j_ap) for j_ap in json_item['apertures']]
|
|
1613
|
+
context = Context.ByTopologyParameters(v, u=0.5, v=0.5, w=0.5)
|
|
1614
|
+
for ap in apertures:
|
|
1615
|
+
_ = Aperture.ByTopologyContext(ap, context)
|
|
1562
1616
|
return v
|
|
1563
1617
|
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1618
|
+
def buildEdge(json_item, j_vertices, uuidKey="uuid"):
|
|
1619
|
+
edge_vertices = json_item['vertices']
|
|
1620
|
+
vertices = []
|
|
1621
|
+
for j_v in edge_vertices:
|
|
1622
|
+
vertices.append(buildVertex(find_json_item(j_vertices, uuidKey, j_v)))
|
|
1623
|
+
e = Edge.ByVertices(vertices)
|
|
1624
|
+
d = json_item['dictionary']
|
|
1625
|
+
e = Topology.SetDictionary(e, Dictionary.ByPythonDictionary(d))
|
|
1626
|
+
apertures = [buildAperture(j_ap) for j_ap in json_item['apertures']]
|
|
1627
|
+
context = Context.ByTopologyParameters(e, u=0.5, v=0.5, w=0.5)
|
|
1628
|
+
for ap in apertures:
|
|
1629
|
+
_ = Aperture.ByTopologyContext(ap, context)
|
|
1630
|
+
return e
|
|
1631
|
+
|
|
1632
|
+
def buildWire(json_item, j_edges, j_vertices, uuidKey="uuid"):
|
|
1633
|
+
wire_edges = json_item['edges']
|
|
1634
|
+
edges = []
|
|
1635
|
+
for j_e in wire_edges:
|
|
1636
|
+
edges.append(buildEdge(find_json_item(j_edges, uuidKey, j_e), j_vertices, uuidKey=uuidKey))
|
|
1637
|
+
w = Wire.ByEdges(edges)
|
|
1638
|
+
d = json_item['dictionary']
|
|
1639
|
+
w = Topology.SetDictionary(w, Dictionary.ByPythonDictionary(d))
|
|
1640
|
+
apertures = [buildAperture(j_ap) for j_ap in json_item['apertures']]
|
|
1641
|
+
context = Context.ByTopologyParameters(w, u=0.5, v=0.5, w=0.5)
|
|
1642
|
+
for ap in apertures:
|
|
1643
|
+
_ = Aperture.ByTopologyContext(ap, context)
|
|
1644
|
+
return w
|
|
1645
|
+
|
|
1646
|
+
def buildFace(json_item, j_wires, j_edges, j_vertices, uuidKey="uuid"):
|
|
1647
|
+
face_wires = json_item['wires']
|
|
1648
|
+
wires = []
|
|
1649
|
+
external_boundary = buildWire(find_json_item(j_wires, uuidKey, face_wires[0]), j_edges, j_vertices, uuidKey=uuidKey)
|
|
1650
|
+
internal_boundaries = []
|
|
1651
|
+
for j_w in face_wires[1:]:
|
|
1652
|
+
ib = buildWire(find_json_item(j_wires, uuidKey, j_w),j_edges, j_vertices, uuidKey=uuidKey)
|
|
1653
|
+
internal_boundaries.append(ib)
|
|
1654
|
+
f = Face.ByWire(external_boundary)
|
|
1655
|
+
if Face.Area(f) < 0:
|
|
1656
|
+
f = Face.ByWires(Wire.Invert(external_boundary), internal_boundaries)
|
|
1657
|
+
else:
|
|
1658
|
+
f = Face.ByWires(external_boundary, internal_boundaries)
|
|
1659
|
+
d = json_item['dictionary']
|
|
1660
|
+
f = Topology.SetDictionary(f, Dictionary.ByPythonDictionary(d))
|
|
1661
|
+
apertures = [buildAperture(j_ap) for j_ap in json_item['apertures']]
|
|
1662
|
+
context = Context.ByTopologyParameters(f, u=0.5, v=0.5, w=0.5)
|
|
1663
|
+
for ap in apertures:
|
|
1664
|
+
_ = Aperture.ByTopologyContext(ap, context)
|
|
1665
|
+
return f
|
|
1666
|
+
|
|
1667
|
+
def buildShell(json_item, j_faces, j_wires, j_edges, j_vertices, uuidKey="uuid"):
|
|
1668
|
+
shell_faces = json_item['faces']
|
|
1669
|
+
faces = []
|
|
1670
|
+
for j_f in shell_faces:
|
|
1671
|
+
faces.append(buildFace(find_json_item(j_faces, uuidKey, j_f), j_wires, j_edges, j_vertices, uuidKey=uuidKey))
|
|
1672
|
+
s = Shell.ByFaces(faces)
|
|
1673
|
+
d = json_item['dictionary']
|
|
1674
|
+
s = Topology.SetDictionary(s, Dictionary.ByPythonDictionary(d))
|
|
1675
|
+
apertures = [buildAperture(j_ap) for j_ap in json_item['apertures']]
|
|
1676
|
+
context = Context.ByTopologyParameters(s, u=0.5, v=0.5, w=0.5)
|
|
1677
|
+
for ap in apertures:
|
|
1678
|
+
_ = Aperture.ByTopologyContext(ap, context)
|
|
1679
|
+
return s
|
|
1680
|
+
|
|
1681
|
+
def buildCell(json_item, j_shells, j_faces, j_wires, j_edges, j_vertices, uuidKey="uuid"):
|
|
1682
|
+
cell_shells = json_item['shells']
|
|
1683
|
+
shells = []
|
|
1684
|
+
external_boundary = buildShell(find_json_item(j_shells, uuidKey, cell_shells[0]), j_faces, j_wires, j_edges, j_vertices, uuidKey=uuidKey)
|
|
1685
|
+
internal_boundaries = []
|
|
1686
|
+
for j_s in cell_shells[1:]:
|
|
1687
|
+
internal_boundaries.append(buildShell(find_json_item(j_shells, uuidKey, j_s), j_faces, j_wires, j_edges, j_vertices, uuidKey=uuidKey))
|
|
1688
|
+
c = Cell.ByShell(external_boundary)
|
|
1689
|
+
for ib in internal_boundaries:
|
|
1690
|
+
ib_c = Cell.ByShell(ib)
|
|
1691
|
+
c = Topology.Difference(c, ib_c)
|
|
1692
|
+
d = json_item['dictionary']
|
|
1693
|
+
c = Topology.SetDictionary(c, Dictionary.ByPythonDictionary(d))
|
|
1694
|
+
apertures = [buildAperture(j_ap) for j_ap in json_item['apertures']]
|
|
1695
|
+
context = Context.ByTopologyParameters(c, u=0.5, v=0.5, w=0.5)
|
|
1696
|
+
for ap in apertures:
|
|
1697
|
+
_ = Aperture.ByTopologyContext(ap, context)
|
|
1698
|
+
return c
|
|
1699
|
+
|
|
1700
|
+
def buildCellComplex(json_item, j_cells, j_shells, j_faces, j_wires, j_edges, j_vertices, uuidKey="uuid"):
|
|
1701
|
+
cc_cells = json_item['cells']
|
|
1702
|
+
cells = []
|
|
1703
|
+
for j_c in cc_cells:
|
|
1704
|
+
cells.append(buildCell(find_json_item(j_cells, uuidKey, j_c), j_shells, j_faces, j_wires, j_edges, j_vertices, uuidKey=uuidKey))
|
|
1705
|
+
cc = CellComplex.ByCells(cells)
|
|
1706
|
+
d = json_item['dictionary']
|
|
1707
|
+
cc = Topology.SetDictionary(cc, Dictionary.ByPythonDictionary(d))
|
|
1708
|
+
apertures = [buildAperture(j_ap) for j_ap in json_item['apertures']]
|
|
1709
|
+
context = Context.ByTopologyParameters(cc, u=0.5, v=0.5, w=0.5)
|
|
1710
|
+
for ap in apertures:
|
|
1711
|
+
_ = Aperture.ByTopologyContext(ap, context)
|
|
1712
|
+
return cc
|
|
1713
|
+
|
|
1714
|
+
def addAperturesUUID(topology, uuidKey="uuid"):
|
|
1715
|
+
topology_apertures = [Aperture.ApertureTopology(ap) for ap in Topology.Apertures(topology)]
|
|
1716
|
+
apertures_uuid = []
|
|
1717
|
+
for top_a in topology_apertures:
|
|
1718
|
+
uuid = getUUID(top_a, uuidKey=uuidKey)
|
|
1719
|
+
apertures_uuid.append(uuid)
|
|
1720
|
+
d = Topology.Dictionary(topology)
|
|
1721
|
+
d = Dictionary.SetValueAtKey(d, 'apertures', apertures_uuid)
|
|
1722
|
+
topology = Topology.SetDictionary(topology, d)
|
|
1723
|
+
s = Topology.InternalVertex(topology)
|
|
1724
|
+
s = Topology.SetDictionary(s, d)
|
|
1725
|
+
return topology, s, topology_apertures
|
|
1726
|
+
|
|
1727
|
+
def findAperture(uuid, apertures, uuidKey="uuid"):
|
|
1728
|
+
for ap in apertures:
|
|
1729
|
+
d = Topology.Dictionary(ap)
|
|
1730
|
+
ap_uuid = Dictionary.ValueAtKey(d, uuidKey)
|
|
1731
|
+
if uuid == ap_uuid:
|
|
1732
|
+
return ap
|
|
1567
1733
|
return None
|
|
1568
|
-
|
|
1734
|
+
|
|
1735
|
+
def setApertures(topology, allApertures, uuidKey="uuid"):
|
|
1736
|
+
apertures = []
|
|
1737
|
+
d = Topology.Dictionary(topology)
|
|
1738
|
+
apertures_uuid = Dictionary.ValueAtKey(d, 'apertures')
|
|
1739
|
+
if not isinstance(apertures_uuid, list):
|
|
1740
|
+
apertures_uuid = [apertures_uuid]
|
|
1741
|
+
for ap_uuid in apertures_uuid:
|
|
1742
|
+
ap = findAperture(ap_uuid, allApertures, uuidKey=uuidKey)
|
|
1743
|
+
if ap != None:
|
|
1744
|
+
apertures.append(ap)
|
|
1745
|
+
context = Context.ByTopologyParameters(topology, u=0.5, v=0.5, w=0.5)
|
|
1746
|
+
for ap in apertures:
|
|
1747
|
+
_ = Aperture.ByTopologyContext(ap, context)
|
|
1748
|
+
return topology
|
|
1749
|
+
|
|
1750
|
+
|
|
1569
1751
|
jsondata = json.loads(string)
|
|
1570
1752
|
if not isinstance(jsondata, list):
|
|
1571
1753
|
jsondata = [jsondata]
|
|
1754
|
+
|
|
1755
|
+
j_vertices = []
|
|
1756
|
+
j_edges = []
|
|
1757
|
+
j_wires = []
|
|
1758
|
+
j_faces = []
|
|
1759
|
+
j_shells = []
|
|
1760
|
+
j_cells = []
|
|
1761
|
+
j_cellComplexes = []
|
|
1762
|
+
|
|
1763
|
+
vertices = []
|
|
1764
|
+
edges = []
|
|
1765
|
+
wires = []
|
|
1766
|
+
faces = []
|
|
1767
|
+
shells = []
|
|
1768
|
+
cells = []
|
|
1769
|
+
cellComplexes = []
|
|
1770
|
+
|
|
1572
1771
|
for jsonItem in jsondata:
|
|
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
|
-
|
|
1772
|
+
topology_type = jsonItem['type']
|
|
1773
|
+
if topology_type.lower() == "vertex":
|
|
1774
|
+
j_vertices.append(jsonItem)
|
|
1775
|
+
elif topology_type.lower() == "edge":
|
|
1776
|
+
j_edges.append(jsonItem)
|
|
1777
|
+
elif topology_type.lower() == "wire":
|
|
1778
|
+
j_wires.append(jsonItem)
|
|
1779
|
+
elif topology_type.lower() == "face":
|
|
1780
|
+
j_faces.append(jsonItem)
|
|
1781
|
+
elif topology_type.lower() == "shell":
|
|
1782
|
+
j_shells.append(jsonItem)
|
|
1783
|
+
elif topology_type.lower() == "cell":
|
|
1784
|
+
j_cells.append(jsonItem)
|
|
1785
|
+
elif topology_type.lower() == "cellcomplex":
|
|
1786
|
+
j_cellComplexes.append(jsonItem)
|
|
1787
|
+
|
|
1788
|
+
vertices = [buildVertex(j_v) for j_v in j_vertices]
|
|
1789
|
+
vertex_selectors = []
|
|
1790
|
+
all_vertex_apertures = []
|
|
1791
|
+
for v in vertices:
|
|
1792
|
+
v, s, vertex_apertures = addAperturesUUID(v, uuidKey="uuid")
|
|
1793
|
+
all_vertex_apertures += vertex_apertures
|
|
1794
|
+
vertex_selectors.append(s)
|
|
1795
|
+
|
|
1796
|
+
edges = [buildEdge(j_e, j_vertices, uuidKey="uuid") for j_e in j_edges]
|
|
1797
|
+
edge_selectors = []
|
|
1798
|
+
all_edge_apertures = []
|
|
1799
|
+
for e in edges:
|
|
1800
|
+
e, s, edge_apertures = addAperturesUUID(e, uuidKey="uuid")
|
|
1801
|
+
all_edge_apertures += edge_apertures
|
|
1802
|
+
edge_selectors.append(s)
|
|
1803
|
+
|
|
1804
|
+
wires = [buildWire(j_w, j_edges, j_vertices, uuidKey="uuid") for j_w in j_wires]
|
|
1805
|
+
wire_selectors = []
|
|
1806
|
+
all_wire_apertures = []
|
|
1807
|
+
for w in wires:
|
|
1808
|
+
w, s, wire_apertures = addAperturesUUID(w, uuidKey="uuid")
|
|
1809
|
+
all_wire_apertures += wire_apertures
|
|
1810
|
+
wire_selectors.append(s)
|
|
1811
|
+
|
|
1812
|
+
faces = [buildFace(j_f, j_wires, j_edges, j_vertices, uuidKey="uuid") for j_f in j_faces]
|
|
1813
|
+
face_selectors = []
|
|
1814
|
+
all_face_apertures = []
|
|
1815
|
+
for f in faces:
|
|
1816
|
+
f, s, face_apertures = addAperturesUUID(f, uuidKey="uuid")
|
|
1817
|
+
all_face_apertures += face_apertures
|
|
1818
|
+
face_selectors.append(s)
|
|
1819
|
+
|
|
1820
|
+
shells = [buildShell(j_s, j_faces, j_wires, j_edges, j_vertices, uuidKey="uuid") for j_s in j_shells]
|
|
1821
|
+
shell_selectors = []
|
|
1822
|
+
all_shell_apertures = []
|
|
1823
|
+
for sh in shells:
|
|
1824
|
+
sh, s, shell_apertures = addAperturesUUID(sh, uuidKey="uuid")
|
|
1825
|
+
all_shell_apertures += shell_apertures
|
|
1826
|
+
shell_selectors.append(s)
|
|
1827
|
+
|
|
1828
|
+
cells = [buildCell(j_c, j_shells, j_faces, j_wires, j_edges, j_vertices, uuidKey="uuid") for j_c in j_cells]
|
|
1829
|
+
cell_selectors = []
|
|
1830
|
+
all_cell_apertures = []
|
|
1831
|
+
for c in cells:
|
|
1832
|
+
c, s, cell_apertures = addAperturesUUID(c, uuidKey="uuid")
|
|
1833
|
+
all_cell_apertures += cell_apertures
|
|
1834
|
+
cell_selectors.append(s)
|
|
1835
|
+
|
|
1836
|
+
cellComplexes = [buildCellComplex(j_cc, j_cells, j_shells, j_faces, j_wires, j_edges, j_vertices, uuidKey="uuid") for j_cc in j_cellComplexes]
|
|
1837
|
+
cellComplex_selectors = []
|
|
1838
|
+
all_cellComplex_apertures = []
|
|
1839
|
+
for cc in cellComplexes:
|
|
1840
|
+
cc, s, cellComplex_apertures = addAperturesUUID(cc, uuidKey="uuid")
|
|
1841
|
+
all_cellComplex_apertures += cellComplex_apertures
|
|
1842
|
+
cellComplex_selectors.append(s)
|
|
1843
|
+
|
|
1844
|
+
everything = vertices+edges+wires+faces+shells+cells+cellComplexes
|
|
1845
|
+
toplevelTopologies = []
|
|
1846
|
+
for ev in everything:
|
|
1847
|
+
d = Topology.Dictionary(ev)
|
|
1848
|
+
if Dictionary.ValueAtKey(d,'toplevel') == True:
|
|
1849
|
+
toplevelTopologies.append(ev)
|
|
1850
|
+
|
|
1851
|
+
for tp in toplevelTopologies:
|
|
1852
|
+
_ = Topology.TransferDictionariesBySelectors(tp, vertex_selectors, tranVertices=True, tolerance=tolerance)
|
|
1853
|
+
_ = Topology.TransferDictionariesBySelectors(tp, edge_selectors, tranEdges=True, tolerance=tolerance)
|
|
1854
|
+
_ = Topology.TransferDictionariesBySelectors(tp, face_selectors, tranFaces=True, tolerance=tolerance)
|
|
1855
|
+
_ = Topology.TransferDictionariesBySelectors(tp, cell_selectors, tranCells=True, tolerance=tolerance)
|
|
1856
|
+
tp_vertices = Topology.Vertices(tp)
|
|
1857
|
+
for tp_vertex in tp_vertices:
|
|
1858
|
+
tp_vertex = setApertures(tp_vertex, all_vertex_apertures, uuidKey="uuid")
|
|
1859
|
+
tp_edges = Topology.Edges(tp)
|
|
1860
|
+
for tp_edge in tp_edges:
|
|
1861
|
+
tp_edge = setApertures(tp_edge, all_edge_apertures, uuidKey="uuid")
|
|
1862
|
+
tp_faces = Topology.Faces(tp)
|
|
1863
|
+
for tp_face in tp_faces:
|
|
1864
|
+
tp_face = setApertures(tp_face, all_face_apertures, uuidKey="uuid")
|
|
1865
|
+
tp_cells = Topology.Cells(tp)
|
|
1866
|
+
for tp_cell in tp_cells:
|
|
1867
|
+
tp_cell = setApertures(tp_cell, all_cell_apertures, uuidKey="uuid")
|
|
1868
|
+
|
|
1869
|
+
if len(toplevelTopologies) == 1:
|
|
1870
|
+
return toplevelTopologies[0]
|
|
1634
1871
|
else:
|
|
1635
|
-
return
|
|
1872
|
+
return toplevelTopologies
|
|
1636
1873
|
|
|
1637
1874
|
@staticmethod
|
|
1638
1875
|
def ByJSONPath(path, tolerance=0.0001):
|
|
@@ -1662,165 +1899,6 @@ class Topology():
|
|
|
1662
1899
|
return None
|
|
1663
1900
|
return Topology.ByJSONFile(file=file, tolerance=tolerance)
|
|
1664
1901
|
|
|
1665
|
-
@staticmethod
|
|
1666
|
-
def ByImportedJSONMK1(path, tolerance=0.0001):
|
|
1667
|
-
"""
|
|
1668
|
-
DEPRECATED. DO NOT USE. Instead use Topology.ByJSONPath or Topology.ByJSONFile
|
|
1669
|
-
Imports the topology from a JSON file.
|
|
1670
|
-
|
|
1671
|
-
Parameters
|
|
1672
|
-
----------
|
|
1673
|
-
path : str
|
|
1674
|
-
The file path to the json file.
|
|
1675
|
-
tolerance : float , optional
|
|
1676
|
-
The desired tolerance. The default is 0.0001.
|
|
1677
|
-
|
|
1678
|
-
Returns
|
|
1679
|
-
-------
|
|
1680
|
-
list
|
|
1681
|
-
The list of imported topologies.
|
|
1682
|
-
|
|
1683
|
-
"""
|
|
1684
|
-
print("Topology.ByImportedJSONMK1 - WARNING: This method is DEPRECATED. DO NOT USE. Instead use Topology.ByJSONPathMK1 or Topology.ByJSONFileMK1")
|
|
1685
|
-
return Topology.ByJSONPath(path=path, tolerance=tolerance)
|
|
1686
|
-
|
|
1687
|
-
@staticmethod
|
|
1688
|
-
def ByImportedJSONMK2(path, tolerance=0.0001):
|
|
1689
|
-
"""
|
|
1690
|
-
Imports the topology from a JSON file.
|
|
1691
|
-
|
|
1692
|
-
Parameters
|
|
1693
|
-
----------
|
|
1694
|
-
path : str
|
|
1695
|
-
The file path to the json file.
|
|
1696
|
-
tolerance : float , optional
|
|
1697
|
-
The desired tolerance. The default is 0.0001.
|
|
1698
|
-
|
|
1699
|
-
Returns
|
|
1700
|
-
-------
|
|
1701
|
-
list
|
|
1702
|
-
The list of imported topologies.
|
|
1703
|
-
|
|
1704
|
-
"""
|
|
1705
|
-
from topologicpy.Dictionary import Dictionary
|
|
1706
|
-
def getApertures(apertureList, folderPath):
|
|
1707
|
-
returnApertures = []
|
|
1708
|
-
for item in apertureList:
|
|
1709
|
-
brepFileName = item['brep']
|
|
1710
|
-
breppath = os.path.join(folderPath, brepFileName+".brep")
|
|
1711
|
-
brepFile = open(breppath)
|
|
1712
|
-
if brepFile:
|
|
1713
|
-
brepString = brepFile.read()
|
|
1714
|
-
aperture = Topology.ByBREPString(brepString)
|
|
1715
|
-
brepFile.close()
|
|
1716
|
-
dictionary = item['dictionary']
|
|
1717
|
-
keys = list(dictionary.keys())
|
|
1718
|
-
values = []
|
|
1719
|
-
for key in keys:
|
|
1720
|
-
values.append(dictionary[key])
|
|
1721
|
-
topDictionary = Dictionary.ByKeysValues(keys, values)
|
|
1722
|
-
if len(keys) > 0:
|
|
1723
|
-
_ = aperture.SetDictionary(topDictionary)
|
|
1724
|
-
returnApertures.append(aperture)
|
|
1725
|
-
return returnApertures
|
|
1726
|
-
|
|
1727
|
-
def processApertures(subTopologies, apertures, exclusive, tolerance):
|
|
1728
|
-
usedTopologies = []
|
|
1729
|
-
for subTopology in subTopologies:
|
|
1730
|
-
usedTopologies.append(0)
|
|
1731
|
-
ap = 1
|
|
1732
|
-
for aperture in apertures:
|
|
1733
|
-
apCenter = Topology.InternalVertex(aperture, tolerance)
|
|
1734
|
-
for i in range(len(subTopologies)):
|
|
1735
|
-
subTopology = subTopologies[i]
|
|
1736
|
-
if exclusive == True and usedTopologies[i] == 1:
|
|
1737
|
-
continue
|
|
1738
|
-
if topologic.VertexUtility.Distance(apCenter, subTopology) < tolerance:
|
|
1739
|
-
context = topologic.Context.ByTopologyParameters(subTopology, 0.5, 0.5, 0.5)
|
|
1740
|
-
_ = topologic.Aperture.ByTopologyContext(aperture, context)
|
|
1741
|
-
if exclusive == True:
|
|
1742
|
-
usedTopologies[i] = 1
|
|
1743
|
-
ap = ap + 1
|
|
1744
|
-
return None
|
|
1745
|
-
|
|
1746
|
-
def assignDictionary(dictionary):
|
|
1747
|
-
selector = dictionary['selector']
|
|
1748
|
-
pydict = dictionary['dictionary']
|
|
1749
|
-
v = topologic.Vertex.ByCoordinates(selector[0], selector[1], selector[2])
|
|
1750
|
-
d = Dictionary.ByPythonDictionary(pydict)
|
|
1751
|
-
_ = v.SetDictionary(d)
|
|
1752
|
-
return v
|
|
1753
|
-
|
|
1754
|
-
topology = None
|
|
1755
|
-
jsonFile = open(path)
|
|
1756
|
-
folderPath = os.path.dirname(path)
|
|
1757
|
-
if jsonFile:
|
|
1758
|
-
topologies = []
|
|
1759
|
-
jsondata = json.load(jsonFile)
|
|
1760
|
-
for jsonItem in jsondata:
|
|
1761
|
-
brepFileName = jsonItem['brep']
|
|
1762
|
-
breppath = os.path.join(folderPath, brepFileName+".brep")
|
|
1763
|
-
brepFile = open(breppath)
|
|
1764
|
-
if brepFile:
|
|
1765
|
-
brepString = brepFile.read()
|
|
1766
|
-
topology = Topology.ByBREPString(brepString)
|
|
1767
|
-
brepFile.close()
|
|
1768
|
-
dictionary = jsonItem['dictionary']
|
|
1769
|
-
topDictionary = Dictionary.ByPythonDictionary(dictionary)
|
|
1770
|
-
_ = topology.SetDictionary(topDictionary)
|
|
1771
|
-
cellApertures = getApertures(jsonItem['cellApertures'], folderPath)
|
|
1772
|
-
cells = []
|
|
1773
|
-
try:
|
|
1774
|
-
_ = topology.Cells(None, cells)
|
|
1775
|
-
except:
|
|
1776
|
-
pass
|
|
1777
|
-
processApertures(cells, cellApertures, False, 0.001)
|
|
1778
|
-
faceApertures = getApertures(jsonItem['faceApertures'], folderPath)
|
|
1779
|
-
faces = []
|
|
1780
|
-
try:
|
|
1781
|
-
_ = topology.Faces(None, faces)
|
|
1782
|
-
except:
|
|
1783
|
-
pass
|
|
1784
|
-
processApertures(faces, faceApertures, False, 0.001)
|
|
1785
|
-
edgeApertures = getApertures(jsonItem['edgeApertures'], folderPath)
|
|
1786
|
-
edges = []
|
|
1787
|
-
try:
|
|
1788
|
-
_ = topology.Edges(None, edges)
|
|
1789
|
-
except:
|
|
1790
|
-
pass
|
|
1791
|
-
processApertures(edges, edgeApertures, False, 0.001)
|
|
1792
|
-
vertexApertures = getApertures(jsonItem['vertexApertures'], folderPath)
|
|
1793
|
-
vertices = []
|
|
1794
|
-
try:
|
|
1795
|
-
_ = topology.Vertices(None, vertices)
|
|
1796
|
-
except:
|
|
1797
|
-
pass
|
|
1798
|
-
processApertures(vertices, vertexApertures, False, 0.001)
|
|
1799
|
-
cellDataList = jsonItem['cellDictionaries']
|
|
1800
|
-
cellSelectors = []
|
|
1801
|
-
for cellDataItem in cellDataList:
|
|
1802
|
-
cellSelectors.append(assignDictionary(cellDataItem))
|
|
1803
|
-
Topology.TransferDictionariesBySelectors(topology, cellSelectors, tranVertices=False, tranEdges=False, tranFaces=False, tranCells=True, tolerance=tolerance)
|
|
1804
|
-
faceDataList = jsonItem['faceDictionaries']
|
|
1805
|
-
faceSelectors = []
|
|
1806
|
-
for faceDataItem in faceDataList:
|
|
1807
|
-
faceSelectors.append(assignDictionary(faceDataItem))
|
|
1808
|
-
Topology.TransferDictionariesBySelectors(topology, faceSelectors, tranVertices=False, tranEdges=False, tranFaces=True, tranCells=False, tolerance=tolerance)
|
|
1809
|
-
edgeDataList = jsonItem['edgeDictionaries']
|
|
1810
|
-
edgeSelectors = []
|
|
1811
|
-
for edgeDataItem in edgeDataList:
|
|
1812
|
-
edgeSelectors.append(assignDictionary(edgeDataItem))
|
|
1813
|
-
Topology.TransferDictionariesBySelectors(topology, edgeSelectors, tranVertices=False, tranEdges=True, tranFaces=False, tranCells=False, tolerance=tolerance)
|
|
1814
|
-
vertexDataList = jsonItem['vertexDictionaries']
|
|
1815
|
-
vertexSelectors = []
|
|
1816
|
-
for vertexDataItem in vertexDataList:
|
|
1817
|
-
vertexSelectors.append(assignDictionary(vertexDataItem))
|
|
1818
|
-
Topology.TransferDictionariesBySelectors(topology, vertexSelectors, tranVertices=True, tranEdges=False, tranFaces=False, tranCells=False, tolerance=tolerance)
|
|
1819
|
-
topologies.append(topology)
|
|
1820
|
-
return topologies
|
|
1821
|
-
print("Topology.ByImportedJSONMK2 - Error: the input file is not a valid file. Returning None.")
|
|
1822
|
-
return None
|
|
1823
|
-
|
|
1824
1902
|
@staticmethod
|
|
1825
1903
|
def ByOBJString(string, transposeAxes = True, progressBar=False, renderer="notebook", tolerance=0.0001):
|
|
1826
1904
|
"""
|
|
@@ -2878,7 +2956,7 @@ class Topology():
|
|
|
2878
2956
|
return ''
|
|
2879
2957
|
'''
|
|
2880
2958
|
@staticmethod
|
|
2881
|
-
def ExportToJSON(topologies, path,
|
|
2959
|
+
def ExportToJSON(topologies, path, overwrite=False):
|
|
2882
2960
|
"""
|
|
2883
2961
|
Exports the input list of topologies to a JSON file.
|
|
2884
2962
|
|
|
@@ -2888,12 +2966,8 @@ class Topology():
|
|
|
2888
2966
|
The input list of topologies.
|
|
2889
2967
|
path : str
|
|
2890
2968
|
The path to the JSON file.
|
|
2891
|
-
version : int , optional
|
|
2892
|
-
The OCCT BRep version to use. Options are 1,2,or 3. The default is 3.
|
|
2893
2969
|
overwrite : bool , optional
|
|
2894
2970
|
If set to True the ouptut file will overwrite any pre-existing file. Otherwise, it won't. The default is False.
|
|
2895
|
-
tolerance : float , optional
|
|
2896
|
-
The desired tolerance. The default is 0.0001.
|
|
2897
2971
|
|
|
2898
2972
|
Returns
|
|
2899
2973
|
-------
|
|
@@ -2918,12 +2992,20 @@ class Topology():
|
|
|
2918
2992
|
except:
|
|
2919
2993
|
raise Exception("Error: Could not create a new file at the following location: "+path)
|
|
2920
2994
|
if (f):
|
|
2921
|
-
jsondata = json.loads(Topology.JSONString(topologies
|
|
2922
|
-
|
|
2923
|
-
|
|
2995
|
+
jsondata = json.loads(Topology.JSONString(topologies))
|
|
2996
|
+
if jsondata != None:
|
|
2997
|
+
json.dump(jsondata, f, indent=4, sort_keys=True)
|
|
2998
|
+
f.close()
|
|
2999
|
+
return True
|
|
3000
|
+
else:
|
|
3001
|
+
f.close()
|
|
3002
|
+
return False
|
|
3003
|
+
return False
|
|
3004
|
+
|
|
3005
|
+
|
|
2924
3006
|
|
|
2925
3007
|
@staticmethod
|
|
2926
|
-
def JSONString(topologies
|
|
3008
|
+
def JSONString(topologies):
|
|
2927
3009
|
"""
|
|
2928
3010
|
Exports the input list of topologies to a JSON string
|
|
2929
3011
|
|
|
@@ -2931,12 +3013,6 @@ class Topology():
|
|
|
2931
3013
|
----------
|
|
2932
3014
|
topologies : list or topologic.Topology
|
|
2933
3015
|
The input list of topologies or a single topology.
|
|
2934
|
-
path : str
|
|
2935
|
-
The path to the JSON file.
|
|
2936
|
-
version : int , optional
|
|
2937
|
-
The OCCT BRep version to use. Options are 1,2,or 3. The default is 3.
|
|
2938
|
-
tolerance : float , optional
|
|
2939
|
-
The desired tolerance. The default is 0.0001.
|
|
2940
3016
|
|
|
2941
3017
|
Returns
|
|
2942
3018
|
-------
|
|
@@ -2945,329 +3021,234 @@ class Topology():
|
|
|
2945
3021
|
|
|
2946
3022
|
"""
|
|
2947
3023
|
|
|
3024
|
+
from topologicpy.Vertex import Vertex
|
|
3025
|
+
from topologicpy.Edge import Edge
|
|
3026
|
+
from topologicpy.Face import Face
|
|
3027
|
+
from topologicpy.Cell import Cell
|
|
2948
3028
|
from topologicpy.Dictionary import Dictionary
|
|
2949
3029
|
|
|
2950
|
-
def
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
cellApertures.append(anAperture)
|
|
2964
|
-
cellDictionary = Dictionary.PythonDictionary(Topology.Dictionary(aCell))
|
|
2965
|
-
if len(cellDictionary.keys()) > 0:
|
|
2966
|
-
cellDictionaries.append(cellDictionary)
|
|
2967
|
-
iv = topologic.CellUtility.InternalVertex(aCell, tolerance)
|
|
2968
|
-
cellSelectors.append([iv.X(), iv.Y(), iv.Z()])
|
|
2969
|
-
return [cellApertures, cellDictionaries, cellSelectors]
|
|
2970
|
-
|
|
2971
|
-
def faceAperturesAndDictionaries(topology, tolerance=0.0001):
|
|
2972
|
-
faces = []
|
|
2973
|
-
try:
|
|
2974
|
-
_ = topology.Faces(None, faces)
|
|
2975
|
-
except:
|
|
2976
|
-
return [[],[],[]]
|
|
2977
|
-
faceApertures = []
|
|
2978
|
-
faceDictionaries = []
|
|
2979
|
-
faceSelectors = []
|
|
2980
|
-
for aFace in faces:
|
|
2981
|
-
tempApertures = []
|
|
2982
|
-
_ = aFace.Apertures(tempApertures)
|
|
2983
|
-
for anAperture in tempApertures:
|
|
2984
|
-
faceApertures.append(anAperture)
|
|
2985
|
-
faceDictionary = Dictionary.PythonDictionary(Topology.Dictionary(aFace))
|
|
2986
|
-
if len(faceDictionary.keys()) > 0:
|
|
2987
|
-
faceDictionaries.append(faceDictionary)
|
|
2988
|
-
iv = topologic.FaceUtility.InternalVertex(aFace, tolerance)
|
|
2989
|
-
faceSelectors.append([iv.X(), iv.Y(), iv.Z()])
|
|
2990
|
-
return [faceApertures, faceDictionaries, faceSelectors]
|
|
2991
|
-
|
|
2992
|
-
def edgeAperturesAndDictionaries(topology):
|
|
2993
|
-
edges = []
|
|
2994
|
-
try:
|
|
2995
|
-
_ = topology.Edges(None, edges)
|
|
2996
|
-
except:
|
|
2997
|
-
return [[],[],[]]
|
|
2998
|
-
edgeApertures = []
|
|
2999
|
-
edgeDictionaries = []
|
|
3000
|
-
edgeSelectors = []
|
|
3001
|
-
for anEdge in edges:
|
|
3002
|
-
tempApertures = []
|
|
3003
|
-
_ = anEdge.Apertures(tempApertures)
|
|
3004
|
-
for anAperture in tempApertures:
|
|
3005
|
-
edgeApertures.append(anAperture)
|
|
3006
|
-
edgeDictionary = Dictionary.PythonDictionary(Topology.Dictionary(anEdge))
|
|
3007
|
-
if len(edgeDictionary.keys()) > 0:
|
|
3008
|
-
edgeDictionaries.append(edgeDictionary)
|
|
3009
|
-
iv = topologic.EdgeUtility.PointAtParameter(anEdge, 0.5)
|
|
3010
|
-
edgeSelectors.append([iv.X(), iv.Y(), iv.Z()])
|
|
3011
|
-
return [edgeApertures, edgeDictionaries, edgeSelectors]
|
|
3012
|
-
|
|
3013
|
-
def vertexAperturesAndDictionaries(topology):
|
|
3014
|
-
vertices = []
|
|
3015
|
-
try:
|
|
3016
|
-
_ = topology.Vertices(None, vertices)
|
|
3017
|
-
except:
|
|
3018
|
-
return [[],[],[]]
|
|
3019
|
-
vertexApertures = []
|
|
3020
|
-
vertexDictionaries = []
|
|
3021
|
-
vertexSelectors = []
|
|
3022
|
-
for aVertex in vertices:
|
|
3023
|
-
tempApertures = []
|
|
3024
|
-
_ = aVertex.Apertures(tempApertures)
|
|
3025
|
-
for anAperture in tempApertures:
|
|
3026
|
-
vertexApertures.append(anAperture)
|
|
3027
|
-
vertexDictionary = Dictionary.PythonDictionary(Topology.Dictionary(aVertex))
|
|
3028
|
-
if len(vertexDictionary.keys()) > 0:
|
|
3029
|
-
vertexDictionaries.append(vertexDictionary)
|
|
3030
|
-
vertexSelectors.append([aVertex.X(), aVertex.Y(), aVertex.Z()])
|
|
3031
|
-
return [vertexApertures, vertexDictionaries, vertexSelectors]
|
|
3032
|
-
|
|
3033
|
-
def apertureDicts(apertureList):
|
|
3034
|
-
apertureDicts = []
|
|
3035
|
-
for anAperture in apertureList:
|
|
3036
|
-
apertureData = {}
|
|
3037
|
-
apertureData['brep'] = Topology.BREPString(Aperture.Topology(anAperture))
|
|
3038
|
-
apertureData['dictionary'] = Dictionary.PythonDictionary(Topology.Dictionary(anAperture))
|
|
3039
|
-
apertureDicts.append(apertureData)
|
|
3040
|
-
return apertureDicts
|
|
3041
|
-
|
|
3042
|
-
def subTopologyDicts(dicts, selectors):
|
|
3043
|
-
returnDicts = []
|
|
3044
|
-
for i in range(len(dicts)):
|
|
3045
|
-
data = {}
|
|
3046
|
-
data['dictionary'] = dicts[i]
|
|
3047
|
-
data['selector'] = selectors[i]
|
|
3048
|
-
returnDicts.append(data)
|
|
3049
|
-
return returnDicts
|
|
3050
|
-
|
|
3051
|
-
def getTopologyData(topology, version=3, tolerance=0.0001):
|
|
3030
|
+
def getUUID(topology, uuidKey="uuid"):
|
|
3031
|
+
d = Topology.Dictionary(topology)
|
|
3032
|
+
if d == None:
|
|
3033
|
+
print("Dictionary is None for", topology)
|
|
3034
|
+
if uuidKey not in Dictionary.Keys(d):
|
|
3035
|
+
uuidOne = str(uuid.uuid1())
|
|
3036
|
+
d = Dictionary.SetValueAtKey(d, uuidKey, uuidOne)
|
|
3037
|
+
topology = Topology.SetDictionary(topology, d)
|
|
3038
|
+
else:
|
|
3039
|
+
uuidOne = Dictionary.ValueAtKey(d, uuidKey)
|
|
3040
|
+
return uuidOne
|
|
3041
|
+
|
|
3042
|
+
def getVertex(topology, uuidKey="uuid"):
|
|
3052
3043
|
returnDict = {}
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
returnDict['
|
|
3056
|
-
returnDict['
|
|
3057
|
-
|
|
3058
|
-
faceApertures, faceDictionaries, faceSelectors = faceAperturesAndDictionaries(topology, tolerance=tolerance)
|
|
3059
|
-
edgeApertures, edgeDictionaries, edgeSelectors = edgeAperturesAndDictionaries(topology)
|
|
3060
|
-
vertexApertures, vertexDictionaries, vertexSelectors = vertexAperturesAndDictionaries(topology)
|
|
3061
|
-
returnDict['cellApertures'] = apertureDicts(cellApertures)
|
|
3062
|
-
returnDict['faceApertures'] = apertureDicts(faceApertures)
|
|
3063
|
-
returnDict['edgeApertures'] = apertureDicts(edgeApertures)
|
|
3064
|
-
returnDict['vertexApertures'] = apertureDicts(vertexApertures)
|
|
3065
|
-
returnDict['cellDictionaries'] = subTopologyDicts(cellDictionaries, cellSelectors)
|
|
3066
|
-
returnDict['faceDictionaries'] = subTopologyDicts(faceDictionaries, faceSelectors)
|
|
3067
|
-
returnDict['edgeDictionaries'] = subTopologyDicts(edgeDictionaries, edgeSelectors)
|
|
3068
|
-
returnDict['vertexDictionaries'] = subTopologyDicts(vertexDictionaries, vertexSelectors)
|
|
3044
|
+
uuidOne = getUUID(topology, uuidKey=uuidKey)
|
|
3045
|
+
returnDict['type'] = "Vertex"
|
|
3046
|
+
returnDict['uuid'] = uuidOne
|
|
3047
|
+
returnDict['coordinates'] = [Vertex.X(topology), Vertex.Y(topology), Vertex.Z(topology)]
|
|
3048
|
+
returnDict['dictionary'] = Dictionary.PythonDictionary(Topology.Dictionary(topology))
|
|
3069
3049
|
return returnDict
|
|
3070
3050
|
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
@staticmethod
|
|
3081
|
-
def ExportToJSONMK2(topologies, folderPath, fileName, version=3, overwrite=False, tolerance=0.0001):
|
|
3082
|
-
"""
|
|
3083
|
-
Export the input list of topologies to a JSON file
|
|
3084
|
-
|
|
3085
|
-
Parameters
|
|
3086
|
-
----------
|
|
3087
|
-
topologies : list
|
|
3088
|
-
The input list of topologies.
|
|
3089
|
-
folderPath : list
|
|
3090
|
-
The path to the folder containing the json file and brep files.
|
|
3091
|
-
fileName : str
|
|
3092
|
-
The name of the JSON file.
|
|
3093
|
-
version : int , optional
|
|
3094
|
-
The OCCT BRep version to use. Options are 1,2,or 3. The default is 3.
|
|
3095
|
-
overwrite : bool , optional
|
|
3096
|
-
If set to True, any existing file will be overwritten. The default is False.
|
|
3097
|
-
tolerance : float , optional
|
|
3098
|
-
The desired tolerance. The default is 0.0001.
|
|
3051
|
+
def getEdge(topology, uuidKey="uuid"):
|
|
3052
|
+
returnDict = {}
|
|
3053
|
+
uuidOne = getUUID(topology, uuidKey=uuidKey)
|
|
3054
|
+
returnDict['type'] = "Edge"
|
|
3055
|
+
returnDict['uuid'] = uuidOne
|
|
3056
|
+
returnDict['vertices'] = [getUUID(v, uuidKey=uuidKey) for v in Edge.Vertices(topology)]
|
|
3057
|
+
returnDict['dictionary'] = Dictionary.PythonDictionary(Topology.Dictionary(topology))
|
|
3058
|
+
return returnDict
|
|
3099
3059
|
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3060
|
+
def getWire(topology, uuidKey="uuid"):
|
|
3061
|
+
returnDict = {}
|
|
3062
|
+
uuidOne = getUUID(topology, uuidKey="uuid")
|
|
3063
|
+
returnDict['type'] = "Wire"
|
|
3064
|
+
returnDict['uuid'] = uuidOne
|
|
3065
|
+
returnDict['edges'] = [getUUID(e, uuidKey=uuidKey) for e in Topology.Edges(topology)]
|
|
3066
|
+
returnDict['dictionary'] = Dictionary.PythonDictionary(Topology.Dictionary(topology))
|
|
3067
|
+
return returnDict
|
|
3104
3068
|
|
|
3105
|
-
""
|
|
3069
|
+
def getFace(topology, uuidKey="uuid"):
|
|
3070
|
+
apertures = [Aperture.ApertureTopology(ap) for ap in Topology.Apertures(topology)]
|
|
3071
|
+
returnDict = {}
|
|
3072
|
+
uuidOne = getUUID(topology, uuidKey=uuidKey)
|
|
3073
|
+
returnDict['type'] = "Face"
|
|
3074
|
+
returnDict['uuid'] = uuidOne
|
|
3075
|
+
wires = []
|
|
3076
|
+
external_boundary = Face.ExternalBoundary(topology)
|
|
3077
|
+
wires.append(getUUID(Face.ExternalBoundary(topology), uuidKey=uuidKey))
|
|
3078
|
+
internal_boundaries = [getUUID(ib, uuidKey=uuidKey) for ib in Face.InternalBoundaries(topology)]
|
|
3079
|
+
wires += internal_boundaries
|
|
3080
|
+
returnDict['wires'] = wires
|
|
3081
|
+
dictionary = Dictionary.PythonDictionary(Topology.Dictionary(topology))
|
|
3082
|
+
returnDict['dictionary'] = dictionary
|
|
3083
|
+
return returnDict
|
|
3106
3084
|
|
|
3107
|
-
|
|
3085
|
+
def getShell(topology, uuidKey="uuid"):
|
|
3086
|
+
returnDict = {}
|
|
3087
|
+
uuidOne = getUUID(topology, uuidKey=uuidKey)
|
|
3088
|
+
returnDict['type'] = "Shell"
|
|
3089
|
+
returnDict['uuid'] = uuidOne
|
|
3090
|
+
returnDict['faces'] = [getUUID(f, uuidKey=uuidKey) for f in Topology.Faces(topology)]
|
|
3091
|
+
returnDict['dictionary'] = Dictionary.PythonDictionary(Topology.Dictionary(topology))
|
|
3092
|
+
return returnDict
|
|
3108
3093
|
|
|
3109
|
-
def
|
|
3110
|
-
if topology.Type() <= 32:
|
|
3111
|
-
return [[],[],[]]
|
|
3112
|
-
cells = []
|
|
3113
|
-
try:
|
|
3114
|
-
_ = topology.Cells(None, cells)
|
|
3115
|
-
except:
|
|
3116
|
-
return [[],[],[]]
|
|
3117
|
-
cellApertures = []
|
|
3118
|
-
cellDictionaries = []
|
|
3119
|
-
cellSelectors = []
|
|
3120
|
-
for aCell in cells:
|
|
3121
|
-
tempApertures = []
|
|
3122
|
-
_ = aCell.Apertures(tempApertures)
|
|
3123
|
-
for anAperture in tempApertures:
|
|
3124
|
-
cellApertures.append(anAperture)
|
|
3125
|
-
cellDictionary = Dictionary.PythonDictionary(Topology.Dictionary(aCell))
|
|
3126
|
-
if len(cellDictionary.keys()) > 0:
|
|
3127
|
-
cellDictionaries.append(cellDictionary)
|
|
3128
|
-
iv = topologic.CellUtility.InternalVertex(aCell, tolerance)
|
|
3129
|
-
cellSelectors.append([iv.X(), iv.Y(), iv.Z()])
|
|
3130
|
-
return [cellApertures, cellDictionaries, cellSelectors]
|
|
3131
|
-
|
|
3132
|
-
def faceAperturesAndDictionaries(topology, tolerance=0.0001):
|
|
3133
|
-
if topology.Type() <= 8:
|
|
3134
|
-
return [[],[],[]]
|
|
3135
|
-
faces = []
|
|
3136
|
-
try:
|
|
3137
|
-
_ = topology.Faces(None, faces)
|
|
3138
|
-
except:
|
|
3139
|
-
return [[],[],[]]
|
|
3140
|
-
faceApertures = []
|
|
3141
|
-
faceDictionaries = []
|
|
3142
|
-
faceSelectors = []
|
|
3143
|
-
for aFace in faces:
|
|
3144
|
-
tempApertures = []
|
|
3145
|
-
_ = aFace.Apertures(tempApertures)
|
|
3146
|
-
for anAperture in tempApertures:
|
|
3147
|
-
faceApertures.append(anAperture)
|
|
3148
|
-
faceDictionary = Dictionary.PythonDictionary(Topology.Dictionary(aFace))
|
|
3149
|
-
if len(faceDictionary.keys()) > 0:
|
|
3150
|
-
faceDictionaries.append(faceDictionary)
|
|
3151
|
-
iv = topologic.FaceUtility.InternalVertex(aFace, tolerance)
|
|
3152
|
-
faceSelectors.append([iv.X(), iv.Y(), iv.Z()])
|
|
3153
|
-
return [faceApertures, faceDictionaries, faceSelectors]
|
|
3154
|
-
|
|
3155
|
-
def edgeAperturesAndDictionaries(topology):
|
|
3156
|
-
if topology.Type() <= 2:
|
|
3157
|
-
return [[],[],[]]
|
|
3158
|
-
edges = []
|
|
3159
|
-
try:
|
|
3160
|
-
_ = topology.Edges(None, edges)
|
|
3161
|
-
except:
|
|
3162
|
-
return [[],[],[]]
|
|
3163
|
-
edgeApertures = []
|
|
3164
|
-
edgeDictionaries = []
|
|
3165
|
-
edgeSelectors = []
|
|
3166
|
-
for anEdge in edges:
|
|
3167
|
-
tempApertures = []
|
|
3168
|
-
_ = anEdge.Apertures(tempApertures)
|
|
3169
|
-
for anAperture in tempApertures:
|
|
3170
|
-
edgeApertures.append(anAperture)
|
|
3171
|
-
edgeDictionary = Dictionary.PythonDictionary(Topology.Dictionary(anEdge))
|
|
3172
|
-
if len(edgeDictionary.keys()) > 0:
|
|
3173
|
-
edgeDictionaries.append(edgeDictionary)
|
|
3174
|
-
iv = topologic.EdgeUtility.PointAtParameter(anEdge, 0.5)
|
|
3175
|
-
edgeSelectors.append([iv.X(), iv.Y(), iv.Z()])
|
|
3176
|
-
return [edgeApertures, edgeDictionaries, edgeSelectors]
|
|
3177
|
-
|
|
3178
|
-
def vertexAperturesAndDictionaries(topology):
|
|
3179
|
-
if topology.Type() <= 1:
|
|
3180
|
-
return [[],[],[]]
|
|
3181
|
-
vertices = []
|
|
3182
|
-
try:
|
|
3183
|
-
_ = topology.Vertices(None, vertices)
|
|
3184
|
-
except:
|
|
3185
|
-
return [[],[],[]]
|
|
3186
|
-
vertexApertures = []
|
|
3187
|
-
vertexDictionaries = []
|
|
3188
|
-
vertexSelectors = []
|
|
3189
|
-
for aVertex in vertices:
|
|
3190
|
-
tempApertures = []
|
|
3191
|
-
_ = aVertex.Apertures(tempApertures)
|
|
3192
|
-
for anAperture in tempApertures:
|
|
3193
|
-
vertexApertures.append(anAperture)
|
|
3194
|
-
vertexDictionary = Dictionary.PythonDictionary(Topology.Dictionary(aVertex))
|
|
3195
|
-
if len(vertexDictionary.keys()) > 0:
|
|
3196
|
-
vertexDictionaries.append(vertexDictionary)
|
|
3197
|
-
vertexSelectors.append([aVertex.X(), aVertex.Y(), aVertex.Z()])
|
|
3198
|
-
return [vertexApertures, vertexDictionaries, vertexSelectors]
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
def apertureDicts(apertureList, brepName, folderPath, version=3):
|
|
3202
|
-
apertureDicts = []
|
|
3203
|
-
for index, anAperture in enumerate(apertureList):
|
|
3204
|
-
apertureName = brepName+"_aperture_"+str(index+1).zfill(5)
|
|
3205
|
-
breppath = os.path.join(folderPath, apertureName+".brep")
|
|
3206
|
-
brepFile = open(breppath, "w")
|
|
3207
|
-
brepFile.write(Topology.BREPString(anAperture, version=version))
|
|
3208
|
-
brepFile.close()
|
|
3209
|
-
apertureData = {}
|
|
3210
|
-
apertureData['brep'] = apertureName
|
|
3211
|
-
apertureData['dictionary'] = Dictionary.PythonDictionary(Topology.Dictionary(anAperture))
|
|
3212
|
-
apertureDicts.append(apertureData)
|
|
3213
|
-
return apertureDicts
|
|
3214
|
-
|
|
3215
|
-
def subTopologyDicts(dicts, selectors):
|
|
3216
|
-
returnDicts = []
|
|
3217
|
-
for i in range(len(dicts)):
|
|
3218
|
-
data = {}
|
|
3219
|
-
data['dictionary'] = dicts[i]
|
|
3220
|
-
data['selector'] = selectors[i]
|
|
3221
|
-
returnDicts.append(data)
|
|
3222
|
-
return returnDicts
|
|
3223
|
-
|
|
3224
|
-
def getTopologyData(topology, brepName, folderPath, version=3, tolerance=0.0001):
|
|
3094
|
+
def getCell(topology, uuidKey="uuid"):
|
|
3225
3095
|
returnDict = {}
|
|
3096
|
+
uuidOne = getUUID(topology, uuidKey=uuidKey)
|
|
3097
|
+
returnDict['type'] = "Cell"
|
|
3098
|
+
returnDict['uuid'] = uuidOne
|
|
3099
|
+
shells = []
|
|
3100
|
+
external_boundary = Cell.ExternalBoundary(topology)
|
|
3101
|
+
shells.append(getUUID(external_boundary, uuidKey=uuidKey))
|
|
3102
|
+
internal_boundaries = [getUUID(ib, uuidKey=uuidKey) for ib in Cell.InternalBoundaries(topology)]
|
|
3103
|
+
shells += internal_boundaries
|
|
3104
|
+
returnDict['shells'] = shells
|
|
3226
3105
|
dictionary = Dictionary.PythonDictionary(Topology.Dictionary(topology))
|
|
3227
|
-
returnDict['brep'] = brepName
|
|
3228
3106
|
returnDict['dictionary'] = dictionary
|
|
3229
|
-
cellApertures, cellDictionaries, cellSelectors = cellAperturesAndDictionaries(topology, tolerance=tolerance)
|
|
3230
|
-
faceApertures, faceDictionaries, faceSelectors = faceAperturesAndDictionaries(topology, tolerance=tolerance)
|
|
3231
|
-
edgeApertures, edgeDictionaries, edgeSelectors = edgeAperturesAndDictionaries(topology)
|
|
3232
|
-
vertexApertures, vertexDictionaries, vertexSelectors = vertexAperturesAndDictionaries(topology)
|
|
3233
|
-
returnDict['cellApertures'] = apertureDicts(cellApertures, brepName, folderPath, version)
|
|
3234
|
-
returnDict['faceApertures'] = apertureDicts(faceApertures, brepName, folderPath, version)
|
|
3235
|
-
returnDict['edgeApertures'] = apertureDicts(edgeApertures, brepName, folderPath, version)
|
|
3236
|
-
returnDict['vertexApertures'] = apertureDicts(vertexApertures, brepName, folderPath, version)
|
|
3237
|
-
returnDict['cellDictionaries'] = subTopologyDicts(cellDictionaries, cellSelectors)
|
|
3238
|
-
returnDict['faceDictionaries'] = subTopologyDicts(faceDictionaries, faceSelectors)
|
|
3239
|
-
returnDict['edgeDictionaries'] = subTopologyDicts(edgeDictionaries, edgeSelectors)
|
|
3240
|
-
returnDict['vertexDictionaries'] = subTopologyDicts(vertexDictionaries, vertexSelectors)
|
|
3241
3107
|
return returnDict
|
|
3242
|
-
|
|
3243
|
-
|
|
3108
|
+
|
|
3109
|
+
def getCellComplex(topology, uuidKey="uuid"):
|
|
3110
|
+
returnDict = {}
|
|
3111
|
+
uuidOne = getUUID(topology, uuidKey=uuidKey)
|
|
3112
|
+
returnDict['type'] = "CellComplex"
|
|
3113
|
+
returnDict['uuid'] = uuidOne
|
|
3114
|
+
returnDict['cells'] = [getUUID(c, uuidKey=uuidKey) for c in Topology.Cells(topology)]
|
|
3115
|
+
returnDict['dictionary'] = Dictionary.PythonDictionary(Topology.Dictionary(topology))
|
|
3116
|
+
return returnDict
|
|
3117
|
+
|
|
3118
|
+
|
|
3119
|
+
def getApertureData(topology, topLevel="False", uuidKey="uuid"):
|
|
3120
|
+
json_data = []
|
|
3121
|
+
if isinstance(topology, topologic.Vertex):
|
|
3122
|
+
d = getVertex(topology, uuidKey=uuidKey)
|
|
3123
|
+
elif isinstance(topology, topologic.Edge):
|
|
3124
|
+
d = getEdge(topology, uuidKey=uuidKey)
|
|
3125
|
+
elif isinstance(topology, topologic.Wire):
|
|
3126
|
+
d = getWire(topology, uuidKey=uuidKey)
|
|
3127
|
+
elif isinstance(topology, topologic.Face):
|
|
3128
|
+
d = getFace(topology, uuidKey=uuidKey)
|
|
3129
|
+
elif isinstance(topology, topologic.Shell):
|
|
3130
|
+
d = getShell(topology, uuidKey=uuidKey)
|
|
3131
|
+
elif isinstance(topology, topologic.Cell):
|
|
3132
|
+
d = getCell(topology, uuidKey=uuidKey)
|
|
3133
|
+
elif isinstance(topology, topologic.CellComplex):
|
|
3134
|
+
d = getCellComplex(topology, uuidKey=uuidKey)
|
|
3135
|
+
d['dictionary']['toplevel'] = topLevel
|
|
3136
|
+
json_data += getSubTopologyData(topology, uuidKey=uuidKey)
|
|
3137
|
+
apertures = [Aperture.ApertureTopology(ap) for ap in Topology.Apertures(topology)]
|
|
3138
|
+
aperture_data = []
|
|
3139
|
+
for ap in apertures:
|
|
3140
|
+
aperture_data.append(getApertureData(ap, topLevel=False, uuidKey=uuidKey))
|
|
3141
|
+
d['apertures'] = aperture_data
|
|
3142
|
+
json_data.append(d)
|
|
3143
|
+
return json_data
|
|
3144
|
+
|
|
3145
|
+
def getSubTopologyData(topology, uuidKey="uuid"):
|
|
3146
|
+
json_data = []
|
|
3147
|
+
vertices = Topology.Vertices(topology)
|
|
3148
|
+
for v in vertices:
|
|
3149
|
+
d = getVertex(v, uuidKey=uuidKey)
|
|
3150
|
+
d['dictionary']['toplevel'] = False
|
|
3151
|
+
apertures = [Aperture.ApertureTopology(ap) for ap in Topology.Apertures(v)]
|
|
3152
|
+
aperture_data = []
|
|
3153
|
+
for ap in apertures:
|
|
3154
|
+
aperture_data.append(getApertureData(ap, topLevel=False, uuidKey=uuidKey))
|
|
3155
|
+
d['apertures'] = aperture_data
|
|
3156
|
+
json_data.append(d)
|
|
3157
|
+
edges = Topology.Edges(topology)
|
|
3158
|
+
for e in edges:
|
|
3159
|
+
d = getEdge(e, uuidKey=uuidKey)
|
|
3160
|
+
d['dictionary']['toplevel'] = False
|
|
3161
|
+
apertures = [Aperture.ApertureTopology(ap) for ap in Topology.Apertures(e)]
|
|
3162
|
+
aperture_data = []
|
|
3163
|
+
for ap in apertures:
|
|
3164
|
+
aperture_data.append(getApertureData(ap, topLevel=False, uuidKey=uuidKey))
|
|
3165
|
+
d['apertures'] = aperture_data
|
|
3166
|
+
json_data.append(d)
|
|
3167
|
+
wires = Topology.Wires(topology)
|
|
3168
|
+
for w in wires:
|
|
3169
|
+
d = getWire(w, uuidKey=uuidKey)
|
|
3170
|
+
d['dictionary']['toplevel'] = False
|
|
3171
|
+
apertures = [Aperture.ApertureTopology(ap) for ap in Topology.Apertures(w)]
|
|
3172
|
+
aperture_data = []
|
|
3173
|
+
for ap in apertures:
|
|
3174
|
+
aperture_data.append(getApertureData(ap, topLevel=False, uuidKey=uuidKey))
|
|
3175
|
+
d['apertures'] = aperture_data
|
|
3176
|
+
json_data.append(d)
|
|
3177
|
+
faces = Topology.Faces(topology)
|
|
3178
|
+
for f in faces:
|
|
3179
|
+
d = getFace(f, uuidKey=uuidKey)
|
|
3180
|
+
d['dictionary']['toplevel'] = False
|
|
3181
|
+
apertures = [Aperture.ApertureTopology(ap) for ap in Topology.Apertures(f)]
|
|
3182
|
+
aperture_data = []
|
|
3183
|
+
for ap in apertures:
|
|
3184
|
+
aperture_data.append(getApertureData(ap, topLevel=False, uuidKey=uuidKey))
|
|
3185
|
+
d['apertures'] = aperture_data
|
|
3186
|
+
json_data.append(d)
|
|
3187
|
+
shells = Topology.Shells(topology)
|
|
3188
|
+
for s in shells:
|
|
3189
|
+
d = getShell(s, uuidKey=uuidKey)
|
|
3190
|
+
d['dictionary']['toplevel'] = False
|
|
3191
|
+
apertures = [Aperture.ApertureTopology(ap) for ap in Topology.Apertures(s)]
|
|
3192
|
+
aperture_data = []
|
|
3193
|
+
for ap in apertures:
|
|
3194
|
+
aperture_data.append(getApertureData(ap, topLevel=False, uuidKey=uuidKey))
|
|
3195
|
+
d['apertures'] = aperture_data
|
|
3196
|
+
json_data.append(d)
|
|
3197
|
+
cells = Topology.Cells(topology)
|
|
3198
|
+
for c in cells:
|
|
3199
|
+
d = getCell(c, uuidKey=uuidKey)
|
|
3200
|
+
d['dictionary']['toplevel'] = False
|
|
3201
|
+
apertures = [Aperture.ApertureTopology(ap) for ap in Topology.Apertures(c)]
|
|
3202
|
+
aperture_data = []
|
|
3203
|
+
for ap in apertures:
|
|
3204
|
+
aperture_data.append(getApertureData(ap, topLevel=False, uuidKey=uuidKey))
|
|
3205
|
+
d['apertures'] = aperture_data
|
|
3206
|
+
json_data.append(d)
|
|
3207
|
+
cellComplexes = Topology.CellComplexes(topology)
|
|
3208
|
+
for cc in cellComplexes:
|
|
3209
|
+
d = getCellComplex(cc, uuidKey=uuidKey)
|
|
3210
|
+
d['dictionary']['toplevel'] = False
|
|
3211
|
+
apertures = [Aperture.ApertureTopology(ap) for ap in Topology.Apertures(cc)]
|
|
3212
|
+
aperture_data = []
|
|
3213
|
+
for ap in apertures:
|
|
3214
|
+
aperture_data.append(getApertureData(ap, topLevel=False, uuidKey=uuidKey))
|
|
3215
|
+
d['apertures'] = aperture_data
|
|
3216
|
+
json_data.append(d)
|
|
3217
|
+
return json_data
|
|
3218
|
+
|
|
3219
|
+
def getJSONData(topology, topLevel=False, uuidKey="uuid"):
|
|
3220
|
+
json_data = []
|
|
3221
|
+
if isinstance(topology, topologic.Vertex):
|
|
3222
|
+
d = getVertex(topology, uuidKey=uuidKey)
|
|
3223
|
+
elif isinstance(topology, topologic.Edge):
|
|
3224
|
+
d = getEdge(topology, uuidKey=uuidKey)
|
|
3225
|
+
elif isinstance(topology, topologic.Wire):
|
|
3226
|
+
d = getWire(topology, uuidKey=uuidKey)
|
|
3227
|
+
elif isinstance(topology, topologic.Face):
|
|
3228
|
+
d = getFace(topology, uuidKey=uuidKey)
|
|
3229
|
+
elif isinstance(topology, topologic.Shell):
|
|
3230
|
+
d = getShell(topology, uuidKey=uuidKey)
|
|
3231
|
+
elif isinstance(topology, topologic.Cell):
|
|
3232
|
+
d = getCell(topology, uuidKey=uuidKey)
|
|
3233
|
+
elif isinstance(topology, topologic.CellComplex):
|
|
3234
|
+
d = getCellComplex(topology, uuidKey=uuidKey)
|
|
3235
|
+
d['dictionary']['toplevel'] = topLevel
|
|
3236
|
+
json_data += getSubTopologyData(topology, uuidKey=uuidKey)
|
|
3237
|
+
apertures = [Aperture.ApertureTopology(ap) for ap in Topology.Apertures(topology)]
|
|
3238
|
+
aperture_data = []
|
|
3239
|
+
for ap in apertures:
|
|
3240
|
+
aperture_data.append(getApertureData(ap, topLevel=False, uuidKey=uuidKey))
|
|
3241
|
+
d['apertures'] = aperture_data
|
|
3242
|
+
json_data.append(d)
|
|
3243
|
+
return json_data
|
|
3244
|
+
json_data = []
|
|
3245
|
+
if not isinstance(topologies, list):
|
|
3244
3246
|
topologies = [topologies]
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
jsonpath = os.path.join(folderPath, fileName)
|
|
3251
|
-
try:
|
|
3252
|
-
if overwrite == True:
|
|
3253
|
-
jsonFile = open(jsonpath, "w")
|
|
3254
|
-
else:
|
|
3255
|
-
jsonFile = open(jsonpath, "x") # Try to create a new File
|
|
3256
|
-
except:
|
|
3257
|
-
raise Exception("Error: Could not create a new file at the following location: "+jsonpath)
|
|
3258
|
-
if (jsonpath):
|
|
3259
|
-
jsondata = []
|
|
3260
|
-
for index, topology in enumerate(topologies):
|
|
3261
|
-
brepName = "topology_"+str(index+1).zfill(5)
|
|
3262
|
-
breppath = os.path.join(folderPath, brepName+".brep")
|
|
3263
|
-
brepFile = open(breppath, "w")
|
|
3264
|
-
brepFile.write(Topology.BREPString(topology, version=version))
|
|
3265
|
-
brepFile.close()
|
|
3266
|
-
jsondata.append(getTopologyData(topology, brepName, folderPath, version=version, tolerance=tolerance))
|
|
3267
|
-
json.dump(jsondata, jsonFile, indent=4, sort_keys=True)
|
|
3268
|
-
jsonFile.close()
|
|
3269
|
-
return True
|
|
3270
|
-
return False
|
|
3247
|
+
topologies = [x for x in topologies if isinstance(x, topologic.Topology)]
|
|
3248
|
+
for topology in topologies:
|
|
3249
|
+
json_data += getJSONData(topology, topLevel=True, uuidKey="uuid")
|
|
3250
|
+
json_string = json.dumps(json_data, indent=4, sort_keys=False)
|
|
3251
|
+
return json_string
|
|
3271
3252
|
|
|
3272
3253
|
@staticmethod
|
|
3273
3254
|
def OBJString(topology, transposeAxes=True):
|
|
@@ -3656,40 +3637,39 @@ class Topology():
|
|
|
3656
3637
|
A vertex guaranteed to be inside the input topology.
|
|
3657
3638
|
|
|
3658
3639
|
"""
|
|
3640
|
+
from topologicpy.Vertex import Vertex
|
|
3641
|
+
from topologicpy.Edge import Edge
|
|
3642
|
+
from topologicpy.Face import Face
|
|
3643
|
+
from topologicpy.Cell import Cell
|
|
3659
3644
|
if not isinstance(topology, topologic.Topology):
|
|
3660
3645
|
print("Topology.InternalVertex - Error: the input topology is not a valid topology. Returning None.")
|
|
3661
3646
|
return None
|
|
3662
3647
|
vst = None
|
|
3663
3648
|
classType = topology.Type()
|
|
3664
3649
|
if classType == 64: #CellComplex
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
tempCell = tempCells[0]
|
|
3668
|
-
vst = topologic.CellUtility.InternalVertex(tempCell, tolerance)
|
|
3650
|
+
tempCell = Topology.Cells(topology)[0]
|
|
3651
|
+
vst = Cell.InternalVertex(tempCell, tolerance)
|
|
3669
3652
|
elif classType == 32: #Cell
|
|
3670
|
-
vst =
|
|
3653
|
+
vst = Cell.InternalVertex(topology, tolerance)
|
|
3671
3654
|
elif classType == 16: #Shell
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
tempFace = tempFaces[0]
|
|
3675
|
-
vst = topologic.FaceUtility.InternalVertex(tempFace, tolerance)
|
|
3655
|
+
tempFace = Topology.Faces(topology)[0]
|
|
3656
|
+
vst = Face.InternalVertex(tempFace, tolerance)
|
|
3676
3657
|
elif classType == 8: #Face
|
|
3677
|
-
vst =
|
|
3658
|
+
vst = Face.InternalVertex(topology, tolerance)
|
|
3678
3659
|
elif classType == 4: #Wire
|
|
3679
3660
|
if topology.IsClosed():
|
|
3680
3661
|
internalBoundaries = []
|
|
3681
3662
|
tempFace = topologic.Face.ByExternalInternalBoundaries(topology, internalBoundaries)
|
|
3682
|
-
vst =
|
|
3663
|
+
vst = Face.InternalVertex(tempFace, tolerance)
|
|
3683
3664
|
else:
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
vst = topologic.EdgeUtility.PointAtParameter(tempEdges[0], 0.5)
|
|
3665
|
+
tempEdge = Topology.Edges(topology)[0]
|
|
3666
|
+
vst = Edge.VertexByParameter(tempEdge, 0.5)
|
|
3687
3667
|
elif classType == 2: #Edge
|
|
3688
|
-
vst =
|
|
3668
|
+
vst = Edge.VertexByParameter(topology, 0.5)
|
|
3689
3669
|
elif classType == 1: #Vertex
|
|
3690
3670
|
vst = topology
|
|
3691
3671
|
else:
|
|
3692
|
-
vst =
|
|
3672
|
+
vst = Topology.Centroid(topology)
|
|
3693
3673
|
return vst
|
|
3694
3674
|
|
|
3695
3675
|
@staticmethod
|