Skip to content

Commit ff42d61

Browse files
committed
Fixed bad imports
1 parent cb9ba01 commit ff42d61

File tree

9 files changed

+170
-74
lines changed

9 files changed

+170
-74
lines changed

OCCUtils/Iteration.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
This module helps looping through topology
2020
'''
2121
from OCC.BRep import BRep_Tool
22-
from OCCUtils.Topology import WireExplorer, Topo
23-
from OCCUtils.edge import Edge
22+
23+
from Topology import WireExplorer, Topo
24+
from edge import Edge
2425

2526

2627
class EdgePairsFromWire(object):

OCCUtils/Triangulation.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

OCCUtils/base.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@
3838
'''
3939
# occ
4040
from OCC.BRepBuilderAPI import BRepBuilderAPI_Copy
41-
from OCC.BRepGProp import BRepGProp
41+
from OCC.BRepGProp import brepgprop_VolumeProperties, brepgprop_LinearProperties, brepgprop_SurfaceProperties
4242
from OCC.BRepCheck import *
4343
# occ high level
4444
from OCC.Display.SimpleGui import init_display
45-
from OCC.Utils.Construct import *
45+
from Construct import *
4646
# KBE
4747
from types_lut import shape_lut, topo_lut, orient_lut, state_lut, curve_lut, surface_lut
4848
# stdlib
@@ -196,11 +196,11 @@ def system(self):
196196
# todo, type should be abstracted with TopoDS...
197197
_topo_type = self.instance.topo_type
198198
if _topo_type == 'face' or _topo_type == 'shell':
199-
BRepGProp().SurfaceProperties(self.instance, self._system)
199+
brepgprop_SurfaceProperties(self.instance, self._system)
200200
elif _topo_type == 'edge':
201-
BRepGProp().LinearProperties(self.instance, self._system)
201+
brep_gprop_LinearProperties(self.instance, self._system)
202202
elif _topo_type == 'solid':
203-
BRepGProp().VolumeProperties(self.instance, self._system)
203+
brepgprop_VolumeProperties(self.instance, self._system)
204204
return self._system
205205

206206
def centre(self):

OCCUtils/edge.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
from OCC.BRepAdaptor import BRepAdaptor_Curve, BRepAdaptor_HCurve
1919
from OCC.GCPnts import GCPnts_UniformAbscissa
2020
from OCC.Geom import Geom_OffsetCurve, Geom_TrimmedCurve
21-
from OCC.TopExp import TopExp
21+
from OCC.TopExp import topexp
2222
from OCC.TopoDS import TopoDS_Edge, TopoDS_Vertex, TopoDS_Face
2323
from OCC.gp import *
2424
from OCC.GeomLProp import GeomLProp_CurveTool
2525
from OCC.BRepLProp import BRepLProp_CLProps
26-
from OCC.GeomLib import GeomLib
26+
from OCC.GeomLib import geomlib
2727
from OCC.GCPnts import GCPnts_AbscissaPoint
2828
from OCC.GeomAPI import GeomAPI_ProjectPointOnCurve
2929
from OCC.ShapeAnalysis import ShapeAnalysis_Edge
@@ -325,7 +325,7 @@ def extend_by_point(self, pnt, degree=3, beginning=True):
325325
'''
326326
if self.degree > 3:
327327
raise ValueError('to extend you self.curve should be <= 3, is %s' % (self.degree))
328-
return GeomLib().ExtendCurveToPoint(self.curve, pnt, degree, beginning)
328+
return geomlib.ExtendCurveToPoint(self.curve, pnt, degree, beginning)
329329

330330
#===========================================================================
331331
# Curve.
@@ -430,14 +430,14 @@ def __ne__(self, other):
430430

431431
def first_vertex(self):
432432
# TODO: should return Vertex, not TopoDS_Vertex
433-
return TopExp.FirstVertex(self)
433+
return topexp.FirstVertex(self)
434434

435435
def last_vertex(self):
436-
return TopExp.LastVertex(self)
436+
return topexp.LastVertex(self)
437437

438438
def common_vertex(self, edge):
439439
vert = TopoDS_Vertex()
440-
if TopExp.CommonVertex(self, edge, vert):
440+
if topexp.CommonVertex(self, edge, vert):
441441
return vert
442442
else:
443443
return False

OCCUtils/face.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@
2222
from OCC.GeomAPI import GeomAPI_ProjectPointOnSurf
2323
from OCC.GeomLib import GeomLib_IsPlanarSurface
2424
from OCC.TopAbs import TopAbs_IN
25-
from OCC.TopExp import TopExp
25+
from OCC.TopExp import topexp
2626
from OCC.TopoDS import *
2727
from OCC.GeomLProp import GeomLProp_SLProps
2828
from OCC.BRepCheck import BRepCheck_Face
29-
from OCC.BRepTools import BRepTools, BRepTools_UVBounds
29+
from OCC.BRepTools import breptools_UVBounds
3030
from OCC.BRepAdaptor import BRepAdaptor_Surface, BRepAdaptor_HSurface
3131
from OCC.ShapeAnalysis import ShapeAnalysis_Surface
3232
from OCC.IntTools import IntTools_FaceFace
3333
from OCC.ShapeAnalysis import ShapeAnalysis_Surface
34-
from OCC.GeomProjLib import GeomProjLib
34+
from OCC.GeomProjLib import geomprojlib
3535
from OCC.Adaptor3d import Adaptor3d_IsoCurve
3636

3737
from base import Display, KbeObject, GlobalProperties
@@ -77,7 +77,7 @@ def curvature(self, u, v):
7777

7878
_domain = self.instance.domain()
7979
if u in _domain or v in _domain:
80-
print '<<<CORRECTING DOMAIN...>>>'
80+
print('<<<CORRECTING DOMAIN...>>>')
8181
div = 1000
8282
delta_u, delta_v = (_domain[0] - _domain[1])/div, (_domain[2] - _domain[3])/div
8383

@@ -207,14 +207,18 @@ def intersect_curve(self, crv):
207207

208208
class Face(KbeObject, TopoDS_Face):
209209
"""high level surface API
210-
object is a Face iff part of a Solid
210+
object is a Face if part of a Solid
211211
otherwise the same methods do apply, apart from the topology obviously
212212
"""
213213
def __init__(self, face):
214214
'''
215215
'''
216216
KbeObject.__init__(self, name='face')
217-
TopoDS_Face.__init__(self, face)
217+
# TopoDS_Face inheritance
218+
TopoDS_Face.__init__(self)
219+
self.TShape(face.TShape())
220+
self.Location(face.Location())
221+
self.Orientation(face.Orientation())
218222

219223
# cooperative classes
220224
self.DiffGeom = DiffGeomSurface(self)
@@ -268,7 +272,7 @@ def domain(self):
268272
'''the u,v domain of the curve
269273
:return: UMin, UMax, VMin, VMax
270274
'''
271-
return BRepTools_UVBounds(self)
275+
return breptools_UVBounds(self)
272276

273277
def mid_point(self):
274278
"""
@@ -358,10 +362,10 @@ def is_trimmed(self):
358362
and implies that the surface is trimmed
359363
"""
360364
_round = lambda x: round(x, 3)
361-
a = map(_round, BRepTools_UVBounds(self))
365+
a = map(_round, breptools_UVBounds(self))
362366
b = map(_round, self.adaptor.Surface().Surface().GetObject().Bounds())
363367
if a != b:
364-
print 'a,b', a, b
368+
print('a,b', a, b)
365369
return True
366370
return False
367371

@@ -443,11 +447,11 @@ def project_curve(self, other):
443447
issubclass(other, Geom_Curve)):
444448
if isinstance(other, TopoDS_Edge):
445449
# convert edge to curve
446-
first, last = TopExp.FirstVertex(other), TopExp.LastVertex(other)
450+
first, last = topexp.FirstVertex(other), topexp.LastVertex(other)
447451
lbound, ubound = BRep_Tool().Parameter(first, other), BRep_Tool().Parameter(last, other)
448452
other = BRep_Tool.Curve(other, lbound, ubound).GetObject()
449453

450-
return GeomProjLib().Project(other, self.surface_handle)
454+
return geomprojlib.Project(other, self.surface_handle)
451455

452456
def project_edge(self, edg):
453457
if hasattr(edg, 'adaptor'):
@@ -479,3 +483,5 @@ def __str__(self):
479483
from OCC.BRepPrimAPI import BRepPrimAPI_MakeSphere
480484
sph = BRepPrimAPI_MakeSphere(1, 1).Face()
481485
fc = Face(sph)
486+
print(fc.is_trimmed())
487+
print(fc.is_planar())

OCCUtils/solid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def shells(self):
5858
def color(self, color):
5959
'''color all the faces
6060
'''
61-
raise NotImplementedError
61+
raise NotImplementedError
6262

6363
@property
6464
def tesselation(self, angle):

OCCUtils/types_lut.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
'''
2020
from OCC.BRepCheck import *
2121
from OCC.GeomAbs import *
22-
from OCC.TopoDS import *
22+
from OCC.TopoDS import topods
2323
from OCC.TopAbs import *
2424
from OCC.Geom import *
2525

@@ -29,15 +29,15 @@ class ShapeToTopology(object):
2929
looks up the topology type and returns the corresponding topological entity
3030
'''
3131
def __init__(self):
32-
self.tds = TopoDS()
33-
self.topoTypes = {TopAbs_VERTEX: self.tds.vertex,
34-
TopAbs_EDGE: self.tds.edge,
35-
TopAbs_FACE: self.tds.face,
36-
TopAbs_WIRE: self.tds.wire,
37-
TopAbs_SHELL: self.tds.shell,
38-
TopAbs_SOLID: self.tds.solid,
39-
TopAbs_COMPOUND: self.tds.compound,
40-
TopAbs_COMPSOLID: self.tds.compsolid,
32+
self.tds = topods()
33+
self.topoTypes = {TopAbs_VERTEX: self.tds.Vertex,
34+
TopAbs_EDGE: self.tds.Edge,
35+
TopAbs_FACE: self.tds.Face,
36+
TopAbs_WIRE: self.tds.Wire,
37+
TopAbs_SHELL: self.tds.Shell,
38+
TopAbs_SOLID: self.tds.Solid,
39+
TopAbs_COMPOUND: self.tds.Compound,
40+
TopAbs_COMPSOLID: self.tds.CompSolid,
4141
}
4242

4343
def __call__(self, shape):

OCCUtils/vertex.py

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
##Copyright 2008-2013 Jelle Feringa (jelleferinga@gmail.com)
2+
##
3+
##This file is part of pythonOCC.
4+
##
5+
##pythonOCC is free software: you can redistribute it and/or modify
6+
##it under the terms of the GNU Lesser General Public License as published by
7+
##the Free Software Foundation, either version 3 of the License, or
8+
##(at your option) any later version.
9+
##
10+
##pythonOCC is distributed in the hope that it will be useful,
11+
##but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
##MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
##GNU Lesser General Public License for more details.
14+
##
15+
##You should have received a copy of the GNU Lesser General Public License
16+
##along with pythonOCC. If not, see <http://www.gnu.org/licenses/>
17+
18+
from OCC.gp import gp_Pnt, gp_Vec, gp_Dir, gp_XYZ, gp_Pnt2d
19+
from OCC.TopoDS import TopoDS_Vertex
20+
from OCC.ShapeBuild import ShapeBuild_ReShape
21+
22+
from base import KbeObject
23+
from Construct import make_vertex
24+
from Common import vertex2pnt
25+
26+
27+
class Vertex(KbeObject, TopoDS_Vertex):
28+
"""
29+
wraps gp_Pnt
30+
"""
31+
_n = 0
32+
33+
def __init__(self, x, y, z):
34+
"""Constructor for KbeVertex"""
35+
KbeObject.__init__(self, name='Vertex #{0}'.format(self._n))
36+
37+
self._n += 1 # should be a property of KbeObject
38+
self._pnt = gp_Pnt(x, y, z)
39+
self._vertex = make_vertex(self._pnt)
40+
TopoDS_Vertex.__init__(self, self._vertex)
41+
42+
def _update(self):
43+
"""
44+
45+
"""
46+
# TODO: perhaps should take an argument until which topological level
47+
# topological entities bound to the vertex should be updated too...
48+
reshape = ShapeBuild_ReShape()
49+
reshape.Replace(self._vertex, make_vertex(self._pnt))
50+
51+
@staticmethod
52+
def from_vertex(cls, pnt):
53+
Vertex.from_pnt(vertex2pnt(pnt))
54+
55+
@staticmethod
56+
def from_pnt(cls, pnt):
57+
x, y, z = pnt.Coord()
58+
return cls(x, y, z)
59+
60+
@classmethod
61+
def from_vec(cls):
62+
raise NotImplementedError
63+
64+
@property
65+
def x(self):
66+
return self._pnt.X()
67+
68+
@x.setter
69+
def x(self, val):
70+
self._pnt.SetX(val)
71+
self._update()
72+
73+
@property
74+
def y(self):
75+
return self._pnt.Y()
76+
77+
@y.setter
78+
def y(self, val):
79+
self._pnt.SetY(val)
80+
self._update()
81+
82+
@property
83+
def z(self):
84+
return self._pnt.Z()
85+
86+
@z.setter
87+
def z(self, val):
88+
self._pnt.SetZ(val)
89+
self._update()
90+
91+
@property
92+
def xyz(self):
93+
return self._pnt.Coord()
94+
95+
@xyz.setter
96+
def xyz(self, *val):
97+
self._pnt.SetXYZ(*val)
98+
self._update()
99+
100+
def __repr__(self):
101+
return self.name
102+
103+
@property
104+
def as_vec(self):
105+
'''returns a gp_Vec version of self'''
106+
return gp_Vec(*self._pnt.Coord())
107+
108+
@property
109+
def as_dir(self):
110+
'''returns a gp_Dir version of self'''
111+
return gp_Dir(*self._pnt.Coord())
112+
113+
@property
114+
def as_xyz(self):
115+
'''returns a gp_XYZ version of self'''
116+
return gp_XYZ(*self._pnt.Coord())
117+
118+
@property
119+
def as_pnt(self):
120+
return self._pnt
121+
122+
@property
123+
def as_2d(self):
124+
'''returns a gp_Pnt2d version of self'''
125+
return gp_Pnt2d(*self._pnt.Coord()[:2])

OCCUtils/wire.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
##You should have received a copy of the GNU Lesser General Public License
1818
##along with pythonOCC. If not, see <http://www.gnu.org/licenses/>
1919

20-
from OCC.TopoDS import TopoDS_Wire, TopoDS_wire
20+
from OCC.TopoDS import TopoDS_Wire
2121

2222
from base import KbeObject
2323

24+
2425
class Wire(KbeObject, TopoDS_Wire):
2526
def __init__(self, wire):
2627
'''
2728
'''
28-
assert isinstance(wire, TopoDS_wire), 'need a TopoDS_Wire, got a %s' % wire.__class__
29+
assert isinstance(wire, TopoDS_Wire), 'need a TopoDS_Wire, got a %s' % wire.__class__
2930
KbeObject.__init__(self, 'wire')
3031
TopoDS_Wire.__init__(self, wire)

0 commit comments

Comments
 (0)