Skip to content

Commit dcf1435

Browse files
committed
Fixed Edge inheritance issue
1 parent 77fe312 commit dcf1435

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

OCCUtils/edge.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,19 @@ def approximate_on_surface(self):
155155
raise NotImplementedError
156156

157157

158-
class Edge(KbeObject, TopoDS_Edge):
158+
class Edge(TopoDS_Edge, KbeObject):
159159
def __init__(self, edge):
160160
assert isinstance(edge, TopoDS_Edge), 'need a TopoDS_Edge, got a %s' % edge.__class__
161+
assert not edge.IsNull()
162+
super(Edge, self).__init__()
161163
KbeObject.__init__(self, 'edge')
162-
TopoDS_Edge.__init__(self, edge)
164+
# we need to copy the base shape using the following three
165+
# lines
166+
assert self.IsNull()
167+
self.TShape(edge.TShape())
168+
self.Location(edge.Location())
169+
self.Orientation(edge.Orientation())
170+
assert not self.IsNull()
163171

164172
# tracking state
165173
self._local_properties_init = False
@@ -547,3 +555,12 @@ def color(self, *rgb):
547555
'''color descriptor for the curve
548556
'''
549557
raise NotImplementedError
558+
559+
if __name__ == '__main__':
560+
from OCC.BRepPrimAPI import *
561+
from Topology import Topo
562+
b = BRepPrimAPI_MakeBox(10, 20, 30).Shape()
563+
t = Topo(b)
564+
ed = t.edges().next()
565+
my_e = Edge(ed)
566+
print(my_e.tolerance)

test/occutils_test.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@
2323
sys.path.append('../OCCUtils')
2424

2525
from OCC.BRepPrimAPI import BRepPrimAPI_MakeBox
26-
from OCC.TopoDS import TopoDS_Face
26+
from OCC.TopoDS import TopoDS_Face, TopoDS_Edge
2727

2828
from Topology import Topo
29+
from edge import Edge
2930

3031

3132
def get_test_box_shape():
@@ -47,6 +48,15 @@ def test_loop_faces(self):
4748
assert(isinstance(face, TopoDS_Face))
4849
assert(i == 6)
4950

51+
def test_loop_edges(self):
52+
b = get_test_box_shape()
53+
t = Topo(b)
54+
i = 0
55+
for face in t.edges():
56+
i += 1
57+
assert(isinstance(face, TopoDS_Edge))
58+
assert(i == 12)
59+
5060
def test_get_numbers_of_members(self):
5161
b = get_test_box_shape()
5262
t = Topo(b)
@@ -60,9 +70,24 @@ def test_get_numbers_of_members(self):
6070
assert(t.number_of_comp_solids() == 0)
6171

6272

73+
class TestEdge(unittest.TestCase):
74+
def test_creat_edge(self):
75+
# create a box
76+
b = get_test_box_shape()
77+
# take the first edge
78+
t = Topo(b)
79+
edge_0 = t.edges().next() # it's a TopoDS_Edge
80+
assert not edge_0.IsNull()
81+
# then create an edge
82+
my_Edge = Edge(edge_0)
83+
assert not my_Edge.IsNull()
84+
assert my_Edge.tolerance == 1e-06
85+
86+
6387
def suite():
6488
test_suite = unittest.TestSuite()
6589
test_suite.addTest(unittest.makeSuite(TestTopo))
90+
test_suite.addTest(unittest.makeSuite(TestEdge))
6691
return test_suite
6792

6893
if __name__ == "__main__":

0 commit comments

Comments
 (0)