Skip to content

Commit

Permalink
'Refactored by Sourcery'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sourcery AI committed May 13, 2023
1 parent 4aa17e7 commit 4722fdd
Show file tree
Hide file tree
Showing 34 changed files with 102 additions and 180 deletions.
7 changes: 3 additions & 4 deletions examples/core_animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@

def build_shape():
boxshp = BRepPrimAPI_MakeBox(50.0, 50.0, 50.0).Shape()
ais_boxshp = display.DisplayShape(boxshp, update=True)[0]
return ais_boxshp
return display.DisplayShape(boxshp, update=True)[0]


def rotating_cube_1_axis(event=None):
Expand All @@ -44,7 +43,7 @@ def rotating_cube_1_axis(event=None):
angle = 0.0
tA = time.time()
n_rotations = 200
for i in range(n_rotations):
for _ in range(n_rotations):
aCubeTrsf.SetRotation(ax1, angle)
aCubeToploc = TopLoc_Location(aCubeTrsf)
display.Context.SetLocation(ais_boxshp, aCubeToploc)
Expand All @@ -63,7 +62,7 @@ def rotating_cube_2_axis(event=None):
angle = 0.0
tA = time.time()
n_rotations = 200
for i in range(n_rotations):
for _ in range(n_rotations):
a_cube_trsf.SetRotation(ax1, angle)
a_cube_trsf2.SetRotation(ax2, angle)
aCubeToploc = TopLoc_Location(a_cube_trsf * a_cube_trsf2)
Expand Down
4 changes: 2 additions & 2 deletions examples/core_boolean_fuzzy_cut_emmenthaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@


def random_pnt():
x, y, z = [random.uniform(0, 1) for i in range(3)]
x, y, z = [random.uniform(0, 1) for _ in range(3)]
return gp_Pnt(x, y, z)


def random_vec():
x, y, z = [random.uniform(-1, 1) for i in range(3)]
x, y, z = [random.uniform(-1, 1) for _ in range(3)]
return gp_Vec(x, y, z)


Expand Down
3 changes: 1 addition & 2 deletions examples/core_boolean_sewed_shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
def MakeSolidFromShell(shell):
ms = BRepBuilderAPI_MakeSolid()
ms.Add(topods.Shell(shell))
solid = ms.Solid()
return solid
return ms.Solid()


def make_face_from_4_points(pnt1, pnt2, pnt3, pnt4):
Expand Down
4 changes: 2 additions & 2 deletions examples/core_display_activate_manipulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ def createLayout(self):
def show_layer(self):
if self.show_layer_button.isChecked():
self.layer.show()
self.display.FitAll()
else:
self.layer.hide()
self.display.FitAll()

self.display.FitAll()

def activate_manipulator(self):
if self.activate_manip_button.isChecked():
Expand Down
2 changes: 1 addition & 1 deletion examples/core_display_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def print_xy_click(shp, *kwargs):


def compute_bbox(shp, *kwargs):
print("Compute bbox for %s " % shp)
print(f"Compute bbox for {shp} ")
for shape in shp:
bbox = Bnd_Box()
brepbndlib_Add(shape, bbox)
Expand Down
2 changes: 1 addition & 1 deletion examples/core_display_clip_planes.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def disable_clip_plane(event=None):
def animate_translate_clip_plane(event=None):
plane_definition = clip_plane_1.ToPlane() # it's a gp_Pln
h = 0.2
for i in range(100):
for _ in range(100):
plane_definition.Translate(gp_Vec(0.0, 0.0, h))
clip_plane_1.SetEquation(plane_definition)
display.Context.UpdateCurrentViewer()
Expand Down
2 changes: 1 addition & 1 deletion examples/core_display_material_compound_subshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
s = BRepPrimAPI_MakeCylinder(radius, 200).Shape()
delta_x = 0.0
solids = []
for mat in available_materials:
for _ in available_materials:
s2 = translate_shp(s, gp_Vec(delta_x, 0.0, 0.0))
delta_x += 2 * radius + 1.0
solids.append(s2)
Expand Down
19 changes: 9 additions & 10 deletions examples/core_display_point_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,20 @@ def pcd_get_number_of_vertices(pcd_filename):
POINTS 397
DATA ascii
"""
f = open(pcd_filename, "r")
# read 8 lines
for i in range(8):
f.readline()
# the 9th line holds the number of points
number_of_points = int(f.readline().split()[1])
f.close()
with open(pcd_filename, "r") as f:
# read 8 lines
for _ in range(8):
f.readline()
# the 9th line holds the number of points
number_of_points = int(f.readline().split()[1])
return number_of_points


def random_points(event=None):
n_points = 500000
# first, create a set of 1000 points
points_3d = Graphic3d_ArrayOfPoints(n_points)
for idx in range(n_points):
for _ in range(n_points):
x = random.uniform(-50, 50)
y = random.uniform(-50, 50)
z = random.uniform(-50, 50)
Expand All @@ -86,9 +85,9 @@ def bunny(event=None):
# fedd it with vertices
fp = open(pcd_file_name, "r")
# read 11 lines to skip header
for i in range(10):
for _ in range(10):
fp.readline()
for i in range(nbr_of_vertices):
for _ in range(nbr_of_vertices):
line = fp.readline()
x, y, z = map(float, line.split())
pc.AddVertex(x, y, z)
Expand Down
6 changes: 2 additions & 4 deletions examples/core_display_signal_slots.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ def get_occ_viewer():
widgets = app.topLevelWidgets()
for wi in widgets:
if hasattr(wi, "_menus"): # OCC.Display.SimpleGui.MainWindow
viewer = wi.findChild(qtViewer3d, "qt_viewer_3d")
return viewer
return wi.findChild(qtViewer3d, "qt_viewer_3d")


def on_select(shapes):
Expand Down Expand Up @@ -75,8 +74,7 @@ def also_on_select(shapes):
def location_from_vector(x, y, z):
trsf = gp_Trsf()
trsf.SetTranslation(gp_Vec(x, y, z))
loc = TopLoc_Location(trsf)
return loc
return TopLoc_Location(trsf)


cube = BRepPrimAPI_MakeBox(100, 100, 100).Shape()
Expand Down
2 changes: 1 addition & 1 deletion examples/core_geometry_airfoil.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(self, chord, span, profile):
def make_shape(self):
# 1 - retrieve the data from the UIUC airfoil data page
foil_dat_url = (
"http://m-selig.ae.illinois.edu/ads/coord_seligFmt/%s.dat" % self.profile
f"http://m-selig.ae.illinois.edu/ads/coord_seligFmt/{self.profile}.dat"
)
# explicitly tell to not use ssl verification
ssl._create_default_https_context = ssl._create_unverified_context
Expand Down
15 changes: 6 additions & 9 deletions examples/core_geometry_geomplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,20 @@ def make_n_sided(edges, points, continuity=GeomAbs_C0):
for pt in points:
n_sided.Add(pt)
n_sided.Build()
face = n_sided.Face()
return face
return n_sided.Face()


def make_closed_polygon(*args):
poly = BRepBuilderAPI_MakePolygon()
for pt in args:
if isinstance(pt, list) or isinstance(pt, tuple):
if isinstance(pt, (list, tuple)):
for i in pt:
poly.Add(i)
else:
poly.Add(pt)
poly.Build()
poly.Close()
result = poly.Wire()
return result
return poly.Wire()


def geom_plate(event=None):
Expand All @@ -111,7 +109,7 @@ def geom_plate(event=None):
p4 = gp_Pnt(0, 0, 10)
p5 = gp_Pnt(5, 5, 5)
poly = make_closed_polygon([p1, p2, p3, p4])
edges = [i for i in TopologyExplorer(poly).edges()]
edges = list(TopologyExplorer(poly).edges())
face = make_n_sided(edges, [p5])
display.DisplayShape(edges)
display.DisplayShape(make_vertex(p5))
Expand Down Expand Up @@ -244,7 +242,7 @@ def solve_radius(event=None):
for i in (0.1, 0.5, 1.5, 2.0, 3.0, 0.2):
rcs = RadiusConstrainedSurface(display, poly, p5, i)
rcs.solve()
print("Goal: %s radius: %s" % (i, rcs.curr_radius))
print(f"Goal: {i} radius: {rcs.curr_radius}")
time.sleep(0.1)


Expand All @@ -267,8 +265,7 @@ def build_geom_plate(edges):
plate = GeomPlate_MakeApprox(srf, 0.01, 10, 5, 0.01, 0, GeomAbs_C0)

uMin, uMax, vMin, vMax = srf.Bounds()
face = make_face(plate.Surface(), uMin, uMax, vMin, vMax, 1e-6)
return face
return make_face(plate.Surface(), uMin, uMax, vMin, vMax, 1e-6)


def build_curve_network(event=None):
Expand Down
6 changes: 2 additions & 4 deletions examples/core_geometry_medial_axis_offset.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ def boolean_cut(shapeToCutFrom, cuttingShape):

cut = BRepAlgoAPI_Cut(shapeToCutFrom, cuttingShape)

shp = cut.Shape()
return shp
return cut.Shape()


def make_face_to_contour_from():
Expand Down Expand Up @@ -63,8 +62,7 @@ def make_face_to_contour_from():
f = make_face(w1)
w2 = make_wire(e7, e8, e9, e10)
f2 = make_face(w2)
f3 = boolean_cut(f, f2)
return f3
return boolean_cut(f, f2)


def create_offsets(face, nr_of_counters, distance_between_contours):
Expand Down
8 changes: 2 additions & 6 deletions examples/core_geometry_nurbs_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,13 @@

expl = TopologyExplorer(converted_shape)

# loop over faces
fc_idx = 1

for face in expl.faces():
for fc_idx, face in enumerate(expl.faces(), start=1):
print("=== Face %i ===" % fc_idx)
surf = BRepAdaptor_Surface(face, True)
surf_type = surf.GetType()
# check each of the is a BSpline surface
# it should be, since we used the nurbs converter before
if not surf_type == GeomAbs_BSplineSurface:
if surf_type != GeomAbs_BSplineSurface:
raise AssertionError("the face was not converted to a GeomAbs_BSplineSurface")
# get the nurbs
bsrf = surf.BSpline()
Expand Down Expand Up @@ -78,4 +75,3 @@
p = poles.Value(i + 1, j + 1)
print(p.X(), p.Y(), p.Z(), end=" ")
print()
fc_idx += 1
5 changes: 3 additions & 2 deletions examples/core_geometry_oriented_bounding_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ def convert_bnd_to_shape(the_box):
axes.SetLocation(
gp_Pnt(point.XYZ() - x_vec * half_x - y_vec * half_y - z_vec * half_z)
)
box = BRepPrimAPI_MakeBox(axes, 2.0 * half_x, 2.0 * half_y, 2.0 * half_z).Shape()
return box
return BRepPrimAPI_MakeBox(
axes, 2.0 * half_x, 2.0 * half_y, 2.0 * half_z
).Shape()


# compute the oriented bounding box of a point cloud
Expand Down
4 changes: 1 addition & 3 deletions examples/core_geometry_quaternion.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ def frange(start, end=None, inc=None):
L = []
while 1:
next_ = start + len(L) * inc
if inc > 0 and next_ >= end:
break
elif inc < 0 and next_ <= end:
if inc > 0 and next_ >= end or inc < 0 and next_ <= end:
break
L.append(next_)

Expand Down
2 changes: 1 addition & 1 deletion examples/core_geometry_recognize_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def recognize_face(a_face):
if a plane, returns the normal
if a cylinder, returns the radius
"""
if not type(a_face) is TopoDS_Face:
if type(a_face) is not TopoDS_Face:
print("Please hit the 'G' key to switch to face selection mode")
return False
surf = BRepAdaptor_Surface(a_face, True)
Expand Down
17 changes: 9 additions & 8 deletions examples/core_geometry_splinecage.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ def random_color():

def length_from_edge(edg):
curve_adapt = BRepAdaptor_Curve(edg)
length = GCPnts_AbscissaPoint().Length(
curve_adapt, curve_adapt.FirstParameter(), curve_adapt.LastParameter(), 1e-6
return GCPnts_AbscissaPoint().Length(
curve_adapt,
curve_adapt.FirstParameter(),
curve_adapt.LastParameter(),
1e-6,
)
return length


def divide_edge_by_nr_of_points(edg, n_pts):
Expand Down Expand Up @@ -105,7 +107,7 @@ def build_curve_network(event=None, enforce_tangency=True):
root_compound_shape = read_step_file("../assets/models/splinecage.stp")
topology_explorer = TopologyExplorer(root_compound_shape)

tangent_constraint_faces = [f for f in topology_explorer.faces()]
tangent_constraint_faces = list(topology_explorer.faces())

# loop through the imported faces
# associate the length of each of the faces edges to the corresponding face
Expand All @@ -115,12 +117,11 @@ def build_curve_network(event=None, enforce_tangency=True):

# loop through the imported curves, avoiding the imported faces
# when we've got these filtered out, we retrieved the geometry to build the surface from
filtered_edges = [
e
for e in topology_explorer._loop_topo(
filtered_edges = list(
topology_explorer._loop_topo(
TopAbs_EDGE, root_compound_shape, TopAbs_FACE
)
]
)

filtered_length = {}
for e in filtered_edges:
Expand Down
6 changes: 2 additions & 4 deletions examples/core_geometry_surface_from_curves.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ def surface_from_curves():
@param display:
"""
# First spline
array = []
array.append(gp_Pnt(-4, 0, 2))
array = [gp_Pnt(-4, 0, 2)]
array.append(gp_Pnt(-7, 2, 2))
array.append(gp_Pnt(-6, 3, 1))
array.append(gp_Pnt(-4, 3, -1))
Expand All @@ -52,8 +51,7 @@ def surface_from_curves():
SPL1 = GeomAPI_PointsToBSpline(pt_list1).Curve()

# Second spline
a2 = []
a2.append(gp_Pnt(-4, 0, 2))
a2 = [gp_Pnt(-4, 0, 2)]
a2.append(gp_Pnt(-2, 2, 0))
a2.append(gp_Pnt(2, 3, -1))
a2.append(gp_Pnt(3, 7, -2))
Expand Down
12 changes: 4 additions & 8 deletions examples/core_mesh_gmsh.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,14 @@ def mesh_shape(a_topods_shape):
a() = ShapeFromFile("shape.brep");
"""
gmsh_geo_file = open("shape.geo", "w")
gmsh_geo_file.write(gmsh_geo_file_content)
gmsh_geo_file.close()

with open("shape.geo", "w") as gmsh_geo_file:
gmsh_geo_file.write(gmsh_geo_file_content)
# call gmsh
gmsh_success = os.system("gmsh shape.geo -2 -o shape.stl -format stl")
# load the stl file
if gmsh_success != 0 and os.path.isfile("shape.stl"):
return read_stl_file("shape.stl")
else:
print("Be sure gmsh is in your PATH")
sys.exit()
print("Be sure gmsh is in your PATH")
sys.exit()


# First example, a simple torus
Expand Down
Loading

0 comments on commit 4722fdd

Please sign in to comment.