-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathtest_pythonocc_backend.py
More file actions
113 lines (83 loc) · 3.28 KB
/
Copy pathtest_pythonocc_backend.py
File metadata and controls
113 lines (83 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
"""
Smoke test for the experimental PythonOCCBackend.
Place this file in the root of the TopologicPy repository and run:
python test_pythonocc_backend.py
This is not intended to run the full TopologicPy test suite. It only checks
that the new Core backend delegation path works for a small set of basic
operations.
"""
from topologicpy.Core import Core
from topologicpy.PythonOCCBackend import PythonOCCBackend
# Switch TopologicPy to the experimental pythonOCC backend.
Core.SetBackend(PythonOCCBackend())
from topologicpy.Vertex import Vertex
from topologicpy.Edge import Edge
from topologicpy.Wire import Wire
from topologicpy.Face import Face
from topologicpy.Graph import Graph
from topologicpy.Topology import Topology
from topologicpy.Dictionary import Dictionary
def section(title):
print("\n" + "=" * 80)
print(title)
print("=" * 80)
section("Backend")
print("Backend:", type(Core.Backend()).__name__)
print("Namespaces:", Core.Namespaces())
section("Vertex")
v1 = Vertex.ByCoordinates(0, 0, 0)
v2 = Vertex.ByCoordinates(1, 0, 0)
v3 = Vertex.ByCoordinates(1, 1, 0)
v4 = Vertex.ByCoordinates(0, 1, 0)
print("v1:", v1)
print("v1 is Vertex:", Topology.IsInstance(v1, "Vertex"))
print("v1 coordinates:", Vertex.Coordinates(v1))
print("v2 coordinates:", Vertex.Coordinates(v2))
section("Edge")
e1 = Edge.ByStartVertexEndVertex(v1, v2)
e2 = Edge.ByStartVertexEndVertex(v2, v3)
e3 = Edge.ByStartVertexEndVertex(v3, v4)
e4 = Edge.ByStartVertexEndVertex(v4, v1)
print("e1:", e1)
print("e1 is Edge:", Topology.IsInstance(e1, "Edge"))
print("e1 start:", Edge.StartVertex(e1))
print("e1 end:", Edge.EndVertex(e1))
print("e1 length:", Edge.Length(e1))
section("Wire")
w = Wire.ByEdges([e1, e2, e3, e4])
print("wire:", w)
print("wire is Wire:", Topology.IsInstance(w, "Wire"))
print("wire edges:", Wire.Edges(w))
print("wire vertices:", Topology.Vertices(w))
section("Face")
f = Face.ByWire(w)
print("face:", f)
print("face is Face:", Topology.IsInstance(f, "Face"))
print("face external boundary:", Face.ExternalBoundary(f))
print("face edges:", Face.Edges(f))
section("Dictionary")
d = Dictionary.ByKeysValues(["name", "value"], ["test edge", 42])
e1 = Topology.SetDictionary(e1, d)
ed = Topology.Dictionary(e1)
print("edge dictionary:", ed)
print("edge dictionary keys:", Dictionary.Keys(ed))
print("edge name:", Dictionary.ValueAtKey(ed, "name"))
print("edge value:", Dictionary.ValueAtKey(ed, "value"))
section("Graph")
g = Graph.ByVerticesEdges([v1, v2, v3, v4], [e1, e2, e3, e4])
print("graph:", g)
print("graph is Graph:", Topology.IsInstance(g, "Graph"))
print("graph vertices:", Graph.Vertices(g))
print("graph edges:", Graph.Edges(g))
print("adjacent vertices to v1:", Graph.AdjacentVertices(g, v1))
section("Direct Core instance calls")
print("Core.InstanceCall(v1, 'X'):", Core.InstanceCall(v1, "X"))
print("Core.InstanceCall(v1, 'Y'):", Core.InstanceCall(v1, "Y"))
print("Core.InstanceCall(v1, 'Z'):", Core.InstanceCall(v1, "Z"))
print("Core.InstanceCall(e1, 'StartVertex'):", Core.InstanceCall(e1, "StartVertex"))
print("Core.InstanceCall(e1, 'EndVertex'):", Core.InstanceCall(e1, "EndVertex"))
vertices = []
Core.InstanceCall(e1, "Vertices", None, vertices)
print("Core.InstanceCall(e1, 'Vertices', None, vertices):", vertices)
section("Completed")
print("PythonOCCBackend smoke test completed.")