Skip to content

Commit

Permalink
MeasureIt: code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
NBurn committed Apr 14, 2018
1 parent 41e13ed commit 89dd693
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 30 deletions.
2 changes: 0 additions & 2 deletions measureit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
"category": "3D View"
}

import sys
import os

# ----------------------------------------------
# Import modules
Expand Down
10 changes: 5 additions & 5 deletions measureit/measureit_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def draw_segments(context, myobj, op, region, rv3d):
# --------------------
# Loop
# --------------------
for idx in range(0, op.measureit_num):
for idx in range(op.measureit_num):
ms = op.measureit_segments[idx]
if ovr is False:
fsize = ms.glfont_size
Expand Down Expand Up @@ -557,7 +557,7 @@ def draw_segments(context, myobj, op, region, rv3d):
p_02a = None
p_02b = None
# draw the arc
for i in range(0, int(n_step)):
for i in range(int(n_step)):
p2 = mat_trans2 * mat_rot1 * mat_trans1 * p1
p1_ = (p1[0] + vi[0], p1[1] + vi[1], p1[2] + vi[2])
# First Point
Expand Down Expand Up @@ -606,7 +606,7 @@ def draw_segments(context, myobj, op, region, rv3d):
for face in ms.measureit_faces:
myvertices = []
for v in face.measureit_index:
myvertices.extend([v.glidx])
myvertices.append(v.glidx)

area = get_area_and_paint(myvertices, myobj, obverts, region, rv3d)
tot += area
Expand Down Expand Up @@ -668,7 +668,7 @@ def get_area_and_paint(myvertices, myobj, obverts, region, rv3d):
bm = from_edit_mesh(myobj.data)
myv = []
for v in bm.verts:
myv.extend([v.co])
myv.append(v.co)
tris = mesh_utils.ngon_tessellate(myv, myvertices)

for t in tris:
Expand Down Expand Up @@ -750,7 +750,7 @@ def get_group_sum(myobj, tag):
scale = bpy.context.scene.unit_settings.scale_length
tot = 0.0
obverts = get_mesh_vertices(myobj)
for idx in range(0, mp.measureit_num):
for idx in range(mp.measureit_num):
ms = mp.measureit_segments[idx]
if (ms.gltype == 1 or ms.gltype == 12 or
ms.gltype == 13 or ms.gltype == 14) and ms.gltot != '99' \
Expand Down
34 changes: 17 additions & 17 deletions measureit/measureit_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ def draw(self, context):
row = box.row(True)
row.operator("measureit.expandallsegmentbutton", text="Expand all", icon="ZOOMIN")
row.operator("measureit.collapseallsegmentbutton", text="Collapse all", icon="ZOOMOUT")
for idx in range(0, mp.measureit_num):
for idx in range(mp.measureit_num):
if mp.measureit_segments[idx].glfree is False:
add_item(box, idx, mp.measureit_segments[idx])

Expand All @@ -426,7 +426,7 @@ def draw(self, context):
myobj = context.object
obverts = get_mesh_vertices(myobj)
viewtot = False
for idx in range(0, mp.measureit_num):
for idx in range(mp.measureit_num):
ms = mp.measureit_segments[idx]
if (ms.gltype == 1 or ms.gltype == 12
or ms.gltype == 13 or ms.gltype == 14) and ms.gltot != '99' \
Expand Down Expand Up @@ -472,7 +472,7 @@ def draw(self, context):
box = layout.box()
box.label("Totals", icon='SOLO_ON')
final = 0
for idx in range(0, len(tot)):
for idx in range(len(tot)):
if ac[idx] is True:
final += tot[idx]
tx_dist = format_distance(fmt, units, tot[idx])
Expand Down Expand Up @@ -1030,7 +1030,7 @@ def execute(self, context):
mainobject.MeasureGenerator.add()

mp = mainobject.MeasureGenerator[0]
for x in range(0, len(mylist)):
for x in range(len(mylist)):
# -----------------------
# Only if not exist
# -----------------------
Expand Down Expand Up @@ -1658,7 +1658,7 @@ def execute(self, context):
if context.object is not None:
if 'MeasureGenerator' in context.object:
mp = context.object.MeasureGenerator[0]
for idx in range(0, mp.measureit_num):
for idx in range(mp.measureit_num):
ms = mp.measureit_segments[idx]
ms.gltot = '99'

Expand Down Expand Up @@ -2016,14 +2016,14 @@ def draw_main(context):
if local_view is False:
# Get visible layers
if bpy.context.space_data.lock_camera_and_layers is True:
for x in range(0, 20):
for x in range(20):
if bpy.context.scene.layers[x] is True:
layers.extend([x])
layers.append(x)
else:
# Lock disabled, use view dependent visible layers
for x in range(20):
if bpy.context.space_data.layers[x] is True:
layers.extend([x])
layers.append(x)

# Display selected or all
if scene.measureit_gl_ghost is False or local_view is True:
Expand All @@ -2041,7 +2041,7 @@ def draw_main(context):
if 'MeasureGenerator' in myobj:
if local_view is False:
# verify visible layer
for x in range(0, 20):
for x in range(20):
if myobj.layers[x] is True and x in layers:
op = myobj.MeasureGenerator[0]
draw_segments(context, myobj, op, region, rv3d)
Expand Down Expand Up @@ -2128,7 +2128,7 @@ def get_selected_vertex(myobject):
tv = len(bm.verts)
for v in bm.verts:
if v.select:
mylist.extend([v.index])
mylist.append(v.index)

if flag is True:
bpy.ops.object.editmode_toggle()
Expand Down Expand Up @@ -2162,7 +2162,7 @@ def get_selected_vertex_history(myobject):

bm = from_edit_mesh(myobject.data)
for v in bm.select_history:
mylist.extend([v.index])
mylist.append(v.index)

if flag is True:
bpy.ops.object.editmode_toggle()
Expand Down Expand Up @@ -2193,8 +2193,8 @@ def get_smart_selected(myobject):
bm = from_edit_mesh(myobject.data)
for e in bm.edges:
if e.select is True:
mylist.extend([e.verts[0].index])
mylist.extend([e.verts[1].index])
mylist.append(e.verts[0].index)
mylist.append(e.verts[1].index)

if flag is True:
bpy.ops.object.editmode_toggle()
Expand Down Expand Up @@ -2224,12 +2224,12 @@ def get_selected_faces(myobject):

bm = from_edit_mesh(myobject.data)
for e in bm.faces:
myface = []
myfaces = []
if e.select is True:
for i in range(0, len(e.verts)):
myface.extend([e.verts[i].index])
for i in range(len(e.verts)):
myfaces.append(e.verts[i].index)

mylist.extend([myface])
mylist.extend([myfaces])

if flag is True:
bpy.ops.object.editmode_toggle()
Expand Down
12 changes: 6 additions & 6 deletions measureit/measureit_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ def render_main(self, context, animation=False):
# Get visible layers
layers = []
scene = context.scene
for x in range(0, 20):
for x in range(20):
if scene.layers[x] is True:
layers.extend([x])
layers.append(x)

# Get object list
objlist = context.scene.objects
Expand Down Expand Up @@ -124,8 +124,8 @@ def render_main(self, context, animation=False):
# --------------------------------
# Loop for all tiles
# --------------------------------
for row in range(0, row_num):
for col in range(0, col_num):
for row in range(row_num):
for col in range(col_num):
buffer = bgl.Buffer(bgl.GL_FLOAT, width * height * 4)
bgl.glDisable(bgl.GL_SCISSOR_TEST) # if remove this line, get blender screenshot not image
bgl.glViewport(0, 0, tile_x, tile_y)
Expand Down Expand Up @@ -170,7 +170,7 @@ def render_main(self, context, animation=False):
if myobj.hide is False:
if 'MeasureGenerator' in myobj:
# verify visible layer
for x in range(0, 20):
for x in range(20):
if myobj.layers[x] is True:
if x in layers:
op = myobj.MeasureGenerator[0]
Expand Down Expand Up @@ -216,7 +216,7 @@ def render_main(self, context, animation=False):
# --------------------------------
bgl.glFinish()
bgl.glReadPixels(0, 0, width, height, bgl.GL_RGBA, bgl.GL_FLOAT, buffer) # read image data
for y in range(0, tile_y):
for y in range(tile_y):
# final image pixels position
p1 = (y * width * 4) + (row * tile_y * width * 4) + (col * tile_x * 4)
p2 = p1 + (tile_x * 4)
Expand Down

0 comments on commit 89dd693

Please sign in to comment.