forked from tpaviot/pythonocc-utils
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvertex.py
More file actions
126 lines (101 loc) · 3.19 KB
/
vertex.py
File metadata and controls
126 lines (101 loc) · 3.19 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
114
115
116
117
118
119
120
121
122
123
124
125
126
##Copyright 2008-2013 Jelle Feringa (jelleferinga@gmail.com)
##
##This file is part of pythonOCC.
##
##pythonOCC 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 3 of the License, or
##(at your option) any later version.
##
##pythonOCC 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 pythonOCC. If not, see <http://www.gnu.org/licenses/>
from OCC.gp import gp_Pnt, gp_Vec, gp_Dir, gp_XYZ, gp_Pnt2d
from OCC.TopoDS import TopoDS_Vertex
from OCC.ShapeBuild import ShapeBuild_ReShape
from base import KbeObject
from Construct import make_vertex
from Common import vertex2pnt
class Vertex(TopoDS_Vertex, KbeObject):
"""
wraps gp_Pnt
"""
_n = 0
def __init__(self, x, y, z):
super(Vertex, self).__init__()
"""Constructor for KbeVertex"""
KbeObject.__init__(self, name='Vertex #{0}'.format(self._n))
self._n += 1 # should be a property of KbeObject
self._pnt = gp_Pnt(x, y, z)
self._vertex = make_vertex(self._pnt)
TopoDS_Vertex.__init__(self, self._vertex)
def _update(self):
"""
"""
# TODO: perhaps should take an argument until which topological level
# topological entities bound to the vertex should be updated too...
reshape = ShapeBuild_ReShape()
reshape.Replace(self._vertex, make_vertex(self._pnt))
@staticmethod
def from_vertex(cls, vertex):
return Vertex.from_pnt(vertex2pnt(vertex))
@staticmethod
def from_pnt(cls, pnt):
x, y, z = pnt.Coord()
return cls(x, y, z)
@classmethod
def from_vec(cls):
raise NotImplementedError
@property
def x(self):
return self._pnt.X()
@x.setter
def x(self, val):
self._pnt.SetX(val)
self._update()
@property
def y(self):
return self._pnt.Y()
@y.setter
def y(self, val):
self._pnt.SetY(val)
self._update()
@property
def z(self):
return self._pnt.Z()
@z.setter
def z(self, val):
self._pnt.SetZ(val)
self._update()
@property
def xyz(self):
return self._pnt.Coord()
@xyz.setter
def xyz(self, *val):
self._pnt.SetXYZ(*val)
self._update()
def __repr__(self):
return self.name
@property
def as_vec(self):
'''returns a gp_Vec version of self'''
return gp_Vec(*self._pnt.Coord())
@property
def as_dir(self):
'''returns a gp_Dir version of self'''
return gp_Dir(*self._pnt.Coord())
@property
def as_xyz(self):
'''returns a gp_XYZ version of self'''
return gp_XYZ(*self._pnt.Coord())
@property
def as_pnt(self):
return self._pnt
@property
def as_2d(self):
'''returns a gp_Pnt2d version of self'''
return gp_Pnt2d(*self._pnt.Coord()[:2])