[Bf-extensions-cvs] [88aac47] dxf_import: Big PEP8 cleanup.
Bastien Montagne
noreply at git.blender.org
Fri Aug 15 12:38:32 CEST 2014
Commit: 88aac474bfa2537d4094708925392ca8bcdd0817
Author: Bastien Montagne
Date: Fri Aug 15 12:12:10 2014 +0200
Branches: dxf_import
https://developer.blender.org/rBA88aac474bfa2537d4094708925392ca8bcdd0817
Big PEP8 cleanup.
===================================================================
M io_import_dxf/__init__.py
M io_import_dxf/dxfimport/convert.py
M io_import_dxf/dxfimport/do.py
M io_import_dxf/dxfimport/fake_entities.py
M io_import_dxf/dxfimport/groupsort.py
M io_import_dxf/dxfimport/is_.py
M io_import_dxf/dxfimport/line_merger.py
M io_import_dxf/transverse_mercator.py
===================================================================
diff --git a/io_import_dxf/__init__.py b/io_import_dxf/__init__.py
index d206fa0..a4a46d2 100644
--- a/io_import_dxf/__init__.py
+++ b/io_import_dxf/__init__.py
@@ -20,6 +20,8 @@
#
# ##### END GPL LICENSE BLOCK #####
+# <pep8 compliant>
+
import bpy
import os
from bpy.props import StringProperty, BoolProperty, EnumProperty, IntProperty, FloatProperty
diff --git a/io_import_dxf/dxfimport/convert.py b/io_import_dxf/dxfimport/convert.py
index 8635900..7c97ad1 100644
--- a/io_import_dxf/dxfimport/convert.py
+++ b/io_import_dxf/dxfimport/convert.py
@@ -20,6 +20,8 @@
#
# ##### END GPL LICENSE BLOCK #####
+# <pep8 compliant>
+
import itertools
from . import is_
from .fake_entities import ArcEntity
@@ -30,7 +32,7 @@ from copy import deepcopy
class ShortVec(Vector):
def __str__(self):
- return "Vec"+str((round(self.x, 2), round(self.y, 2), round(self.z, 2)))
+ return "Vec" + str((round(self.x, 2), round(self.y, 2), round(self.z, 2)))
def __repr__(self):
return self.__str__()
@@ -46,7 +48,7 @@ def bspline_to_cubic(do, en, curve, errors=None):
"""
def clean_knots():
start = knots[:degree + 1]
- end = knots[-degree - 1:]
+ end = knots[-degree - 1:]
if start.count(start[0]) < degree + 1:
maxa = max(start)
@@ -65,7 +67,7 @@ def bspline_to_cubic(do, en, curve, errors=None):
if uip == ui:
print("zero!")
return 0
- return (t - ui)/(uip - ui)
+ return (t - ui) / (uip - ui)
new_spline = spline.copy()
for pp in range(p, 1, -1):
@@ -105,9 +107,10 @@ def bspline_to_cubic(do, en, curve, errors=None):
# the ugly truth
if len(spline) % 3 == 0:
spline.append([spline[-1]])
- errors.add("Cubic spline: Something went wrong with knot insertion.")
+ errors.add("Cubic spline: Something went wrong with knot insertion")
return spline
+
def quad_to_cube(spline):
"""
spline: list of (x,y,z)-tuples)
@@ -116,10 +119,10 @@ def quad_to_cube(spline):
s = []
for i, p in enumerate(spline):
if i % 2 == 1:
- before = Vector(spline[i-1])
- after = Vector(spline[(i+1)%len(spline)])
- s.append(before+2/3*(Vector(p)-before))
- s.append(after +2/3*(Vector(p)-after ))
+ before = Vector(spline[i - 1])
+ after = Vector(spline[(i + 1) % len(spline)])
+ s.append(before + 2 / 3 * (Vector(p) - before))
+ s.append(after + 2 / 3 * (Vector(p) - after))
else:
s.append(p)
@@ -140,18 +143,18 @@ def bulge_to_arc(point, next, bulge):
rot = Matrix(((0, -1, 0), (1, 0, 0), (0, 0, 1)))
section = next - point
- section_length = section.length/2
- direction = -bulge/abs(bulge)
+ section_length = section.length / 2
+ direction = -bulge / abs(bulge)
correction = 1
sagitta_len = section_length * abs(bulge)
- radius = (sagitta_len**2 + section_length**2) / (2*sagitta_len)
+ radius = (sagitta_len**2 + section_length**2) / (2 * sagitta_len)
if sagitta_len < radius:
cosagitta_len = radius - sagitta_len
else:
cosagitta_len = sagitta_len - radius
direction *= -1
correction *= -1
- center = point + section/2 + section.normalized() * cosagitta_len * rot * direction
+ center = point + section / 2 + section.normalized() * cosagitta_len * rot * direction
cp = point - center
cn = next - center
cr = cp.to_3d().cross(cn.to_3d()) * correction
@@ -183,7 +186,7 @@ def bulgepoly_to_cubic(do, lwpolyline):
la = last.to_3d()
po = point.to_3d()
section = point - last
- cubic_bezier = [la, la + section * 1/3, la + section * 2/3, po]
+ cubic_bezier = [la, la + section * 1 / 3, la + section * 2 / 3, po]
return cubic_bezier
points = lwpolyline.points
@@ -209,7 +212,7 @@ def bulgepoly_to_lenlist(lwpolyline):
if bulge != 0 and seglen != 0:
arc = bulge_to_arc(last, point, bulge)
if arc.startangle > arc.endangle:
- arc.endangle += 2*pi
+ arc.endangle += 2 * pi
angle = arc.endangle - arc.startangle
lenlist.append(abs(arc.radius * angle))
else:
@@ -236,7 +239,7 @@ def extrusion_to_matrix(entity):
def arbitrary_x_axis(extrusion_normal):
world_y = Vector((0, 1, 0))
world_z = Vector((0, 0, 1))
- if abs(extrusion_normal[0]) < 1/64 and abs(extrusion_normal[1]) < 1/64:
+ if abs(extrusion_normal[0]) < 1 / 64 and abs(extrusion_normal[1]) < 1 / 64:
a_x = world_y.cross(extrusion_normal)
else:
a_x = world_z.cross(extrusion_normal)
@@ -259,7 +262,7 @@ def split_by_width(entity):
def __eq__(self, other):
return self.w1 == other.w1 and self.w2 == other.w2 and self.w1 == self.w2
-
+
if is_.varying_width(entity):
entities = []
en_template = deepcopy(entity)
@@ -283,7 +286,6 @@ def split_by_width(entity):
if not entity.is_closed:
entities.pop(-1)
return entities
-
+
else:
return [entity]
-
diff --git a/io_import_dxf/dxfimport/do.py b/io_import_dxf/dxfimport/do.py
index bdff2bc..09dcadd 100644
--- a/io_import_dxf/dxfimport/do.py
+++ b/io_import_dxf/dxfimport/do.py
@@ -2,6 +2,8 @@
# Author: Lukas Treyer
# License: GPL
+# <pep8 compliant>
+
import bpy
import os
import re
@@ -34,7 +36,7 @@ def transform(p1, p2, c1, c2, c3):
if p1.srs != p2.srs:
return proj_transform(p1, p2, c1, c2, c3)
else:
- return (c1, c2, c3) # no, the parentheses are not redundant (as proposed by PyCharm)
+ return (c1, c2, c3)
elif type(p2) is TransverseMercator:
wgs84 = Proj(init="EPSG:4326")
if p1.srs != wgs84.srs:
@@ -42,13 +44,13 @@ def transform(p1, p2, c1, c2, c3):
else:
t1, t2, t3 = c2, c1, c3 # mind c2, c1 inversion
tm1, tm2 = p2.fromGeographic(t1, t2)
- return (tm1, tm2, t3) # no, the parentheses are not redundant (as proposed by PyCharm)
+ return (tm1, tm2, t3)
else:
if p1.spherical:
t1, t2 = p2.fromGeographic(c2, c1) # mind c2, c1 inversion
- return (t1, t2, c3) # no, the parentheses are not redundant (as proposed by PyCharm)
+ return (t1, t2, c3)
else:
- return (c1, c2, c3) # no, the parentheses are not redundant (as proposed by PyCharm)
+ return (c1, c2, c3)
def float_len(f):
@@ -58,6 +60,7 @@ def float_len(f):
else:
return len(s[2:])
+
class Indicator:
spherical = False
euclidean = False
@@ -70,10 +73,18 @@ class Indicator:
else:
raise AttributeError("Indication must be 'spherical' or 'planar'.")
+
class Do:
+ __slots__ = (
+ "dwg", "combination", "known_blocks", "import_text", "import_light", "export_acis", "merge_lines",
+ "do_bounding_boxes", "acis_files", "errors", "block_representation", "recenter", "did_group_instance",
+ "objects_before", "pDXF", "pScene", "thickness_and_width", "but_group_by_att", "current_scene",
+ "dxf_unit_scale",
+ )
+
def __init__(self, dxf_filename, c=BY_LAYER, import_text=True, import_light=True, export_acis=True,
merge_lines=True, do_bbox=True, block_rep=LINKED_OBJECTS, recenter=False, pDXF=None, pScene=None,
- thicknessWidth=True, but_group_by_att=True, dxf_unit_scale=1.0):
+ thicknessWidth=True, but_group_by_att=True, dxf_unit_scale=1.0):
self.dwg = dxfgrabber.readfile(dxf_filename, {"assure_3d_coords": True})
self.combination = c
self.known_blocks = {}
@@ -143,7 +154,6 @@ class Do:
else:
return Vector((co[0], co[1], co[2] if len(co) == 3 else 0))
-
def georeference(self, scene, center):
if "latitude" not in scene and "longitude" not in scene:
if type(self.pScene) is TransverseMercator:
@@ -157,7 +167,6 @@ class Do:
scene['longitude'] = latlon[1]
scene['altitude'] = latlon[2]
-
""" GEOMETRY DXF TYPES TO BLENDER CURVES FILTERS"""
# type(self, dxf entity, blender curve data)
@@ -170,17 +179,17 @@ class Do:
spl = curve.splines.new('BEZIER')
spl.use_cyclic_u = True
b = spl.bezier_points
- b.add(count-1)
+ b.add(count - 1)
for i, j in enumerate(range(1, len(points), 3)):
- b[i].handle_left = self.proj(points[j-1])
+ b[i].handle_left = self.proj(points[j - 1])
b[i].co = self.proj(points[j])
- b[i].handle_right = self.proj(points[j+1])
+ b[i].handle_right = self.proj(points[j + 1])
def _cubic_bezier_open(self, points, curve):
- count = (len(points)-1)/3 + 1
+ count = (len(points) - 1) / 3 + 1
spl = curve.splines.new('BEZIER')
b = spl.bezier_points
- b.add(count-1)
+ b.add(count - 1)
b[0].co = self.proj(points[0])
b[0].handle_left = self.proj(points[0])
@@ -190,17 +199,16 @@ class Do:
b[-1].handle_right = self.proj(points[-1])
b[-1].handle_left = self.proj(points[-2])
-
- for i,j in enumerate(range(3,len(points)-2, 3), 1):
- b[i].handle_left = self.proj(points[j-1])
+ for i, j in enumerate(range(3, len(points) - 2, 3), 1):
+ b[i].handle_left = self.proj(points[j - 1])
b[i].co = self.proj(points[j])
- b[i].handle_right = self.proj(points[j+1])
+ b[i].handle_right = self.proj(points[j + 1])
def _cubic_bezier(self, points, curve, is_closed):
- """ points: control points; list of (x,y,z) tuples
- curve: Blender curve data of type "CURVE" (object.data) where the bezier should be
- added to
- is_closed: True / False to indicate if the curve is open or closed
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list