Skip to content

Commit

Permalink
[CLEANUP] make code pep8 compilant
Browse files Browse the repository at this point in the history
  • Loading branch information
s-leger authored Apr 28, 2017
1 parent 1b66e40 commit e48fae6
Show file tree
Hide file tree
Showing 10 changed files with 458 additions and 478 deletions.
12 changes: 9 additions & 3 deletions archipack_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
class Projection():
def proj_xy(self, t, next=None):
"""
length of projection along crossing line / circle
deformation unit vector for profil in xy axis at line / line intersection
so f(x) = position of point in xy plane
length of projection of sections at crossing line / circle intersections
deformation unit vector for profil in xy axis
so f(x_profile) = position of point in xy plane
"""
if next is None:
return self.normal(t).v.normalized(), 1
Expand All @@ -53,6 +53,12 @@ def proj_z(self, t, dz0, next=None, dz1=0):
so f(y) = position of point in yz plane
"""
return Vector((0, 1)), 1
"""
NOTE (to myself):
In theory this is how it has to be done so sections follow path,
but in real world results are better when sections are z-up.
So return a dumb 1 so f(y) = y
"""
if next is None:
dz = dz0 / self.length
else:
Expand Down
2 changes: 0 additions & 2 deletions archipack_autoboolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
from bpy.types import Operator
from bpy.props import BoolProperty
from mathutils import Vector
# noinspection PyUnresolvedReferences
from . import archipack_reference_point
# noinspection PyUnresolvedReferences


class ARCHIPACK_OT_auto_boolean(Operator):
Expand Down
115 changes: 47 additions & 68 deletions archipack_reference_point.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- coding:utf-8 -*-

# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
Expand All @@ -12,83 +14,82 @@
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110- 1301, USA.
#
# ##### END GPL LICENSE BLOCK #####

# <pep8 compliant>

# ----------------------------------------------------------
# Author: Stephen Leger (s-leger)
#
# ----------------------------------------------------------
# noinspection PyUnresolvedReferences
import bpy
# noinspection PyUnresolvedReferences
from bpy.types import Operator, PropertyGroup, Object, Panel
from bpy.props import FloatVectorProperty, BoolProperty, CollectionProperty
from bpy.props import FloatVectorProperty, CollectionProperty
from mathutils import Vector

class ReferencePointProperty(PropertyGroup):

class archipack_reference_point(PropertyGroup):
location_2d = FloatVectorProperty(
subtype='XYZ',
name = "position 2d",
default=Vector((0,0,0))
name="position 2d",
default=Vector((0, 0, 0))
)
location_3d = FloatVectorProperty(
subtype='XYZ',
name = "position 3d",
default=Vector((0,0,0))
)

name="position 3d",
default=Vector((0, 0, 0))
)


class ARCHIPACK_PT_reference_point(Panel):
bl_idname = "ARCHIPACK_PT_reference_point"
bl_label = "Reference point"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = 'ArchiPack'

def draw(self, context):
o = context.object
props = ARCHIPACK_PT_reference_point.params(o)
if props is None:
return
layout = self.layout
if (o.location-props.location_2d).length < 0.01:
if (o.location - props.location_2d).length < 0.01:
layout.operator('archipack.move_to_3d')
layout.operator('archipack.move_2d_reference_to_cursor')
else:
layout.operator('archipack.move_to_2d')
#layout.operator('archipack.store_2d_reference')


@classmethod
def params(cls, o):
try:
if 'ReferencePointProperty' not in o:
if 'archipack_reference_point' not in o:
return None
else:
return o.ReferencePointProperty[0]
return o.archipack_reference_point[0]
except:
return None

@classmethod
def filter(cls, o):
try:
if 'ReferencePointProperty' not in o:
if 'archipack_reference_point' not in o:
return False
else:
return True
except:
return False

@classmethod
def poll(cls, context):
o = context.object
if o is None:
return False
return cls.filter(o)

# ------------------------------------------------------------------
# Define operator class to create object
# ------------------------------------------------------------------


class ARCHIPACK_OT_reference_point(Operator):
bl_idname = "archipack.reference_point"
bl_label = "Reference point"
Expand All @@ -97,53 +98,45 @@ class ARCHIPACK_OT_reference_point(Operator):
bl_options = {'REGISTER', 'UNDO'}
location_3d = FloatVectorProperty(
subtype='XYZ',
name = "position 3d",
default=Vector((0,0,0))
)
name="position 3d",
default=Vector((0, 0, 0))
)

@classmethod
def poll(cls, context):
return context.active_object is not None
# -----------------------------------------------------
# Draw (create UI interface)
# -----------------------------------------------------
# noinspection PyUnusedLocal

def draw(self, context):
layout = self.layout
row = layout.row()
row.label("Use Properties panel (N) to define parms", icon='INFO')

# -----------------------------------------------------
# Execute
# -----------------------------------------------------

def execute(self, context):
if context.mode == "OBJECT":
x, y, z = context.scene.cursor_location
bpy.ops.object.empty_add(type='ARROWS', radius=0.5, location=Vector((x, y, 0)))
reference_point = context.active_object
reference_point.name = "Reference"
props = reference_point.ReferencePointProperty.add()
props = reference_point.archipack_reference_point.add()
props.location_2d = Vector((x, y, 0))
props.location_3d = self.location_3d
return {'FINISHED'}
else:
self.report({'WARNING'}, "Archipack: Option only valid in Object mode")
return {'CANCELLED'}


class ARCHIPACK_OT_move_to_3d(Operator):
bl_idname = "archipack.move_to_3d"
bl_label = "Move to 3d"
bl_description = "Move point to 3d position"
bl_category = 'Archipack'
bl_options = {'REGISTER', 'UNDO'}

@classmethod
def poll(cls, context):
return context.active_object is not None and ARCHIPACK_PT_reference_point.filter(context.active_object)

# -----------------------------------------------------
# Execute
# -----------------------------------------------------

def execute(self, context):
if context.mode == "OBJECT":
o = context.active_object
Expand All @@ -156,20 +149,18 @@ def execute(self, context):
self.report({'WARNING'}, "Archipack: Option only valid in Object mode")
return {'CANCELLED'}


class ARCHIPACK_OT_move_to_2d(Operator):
bl_idname = "archipack.move_to_2d"
bl_label = "Move to 2d"
bl_description = "Move point to 2d position"
bl_category = 'Archipack'
bl_options = {'REGISTER', 'UNDO'}

@classmethod
def poll(cls, context):
return context.active_object is not None and ARCHIPACK_PT_reference_point.filter(context.active_object)

# -----------------------------------------------------
# Execute
# -----------------------------------------------------
def execute(self, context):
if context.mode == "OBJECT":
o = context.active_object
Expand All @@ -183,20 +174,18 @@ def execute(self, context):
self.report({'WARNING'}, "Archipack: Option only valid in Object mode")
return {'CANCELLED'}


class ARCHIPACK_OT_store_2d_reference(Operator):
bl_idname = "archipack.store_2d_reference"
bl_label = "Set 2d"
bl_description = "Set 2d reference position"
bl_category = 'Archipack'
bl_options = {'REGISTER', 'UNDO'}

@classmethod
def poll(cls, context):
return context.active_object is not None and ARCHIPACK_PT_reference_point.filter(context.active_object)

# -----------------------------------------------------
# Execute
# -----------------------------------------------------
def execute(self, context):
if context.mode == "OBJECT":
o = context.active_object
Expand All @@ -210,21 +199,19 @@ def execute(self, context):
self.report({'WARNING'}, "Archipack: Option only valid in Object mode")
return {'CANCELLED'}


class ARCHIPACK_OT_move_2d_reference_to_cursor(Operator):
bl_idname = "archipack.move_2d_reference_to_cursor"
bl_label = "Change 2d"
bl_description = "Change 2d reference position to cursor location without moving childs"
bl_category = 'Archipack'
bl_options = {'REGISTER', 'UNDO'}

@classmethod
def poll(cls, context):
o = context.active_object
return o is not None and ARCHIPACK_PT_reference_point.filter(o)

# -----------------------------------------------------
# Execute
# -----------------------------------------------------
def execute(self, context):
if context.mode == "OBJECT":
o = context.active_object
Expand All @@ -242,21 +229,19 @@ def execute(self, context):
self.report({'WARNING'}, "Archipack: Option only valid in Object mode")
return {'CANCELLED'}


class ARCHIPACK_OT_parent_to_reference(Operator):
bl_idname = "archipack.parent_to_reference"
bl_label = "Parent"
bl_description = "Make selected object childs of parent reference point"
bl_category = 'Archipack'
bl_options = {'REGISTER', 'UNDO'}

@classmethod
def poll(cls, context):
o = context.active_object
return o is not None and ARCHIPACK_PT_reference_point.filter(o)

# -----------------------------------------------------
# Execute
# -----------------------------------------------------
def execute(self, context):
if context.mode == "OBJECT":
o = context.active_object
Expand All @@ -268,30 +253,24 @@ def execute(self, context):
for child in sel:
rs = child.matrix_world.to_3x3().to_4x4()
loc = itM * child.matrix_world.translation
#matrix_basis = child.matrix_world.copy()
child.parent = None
child.matrix_parent_inverse.identity()
# test
#child.matrix_basis.identity()

child.location = Vector((0,0,0))
child.location = Vector((0, 0, 0))
child.parent = o
child.matrix_world = rs
child.location = loc
#child.matrix_parent_inverse = itM
return {'FINISHED'}
else:
self.report({'WARNING'}, "Archipack: Option only valid in Object mode")
return {'CANCELLED'}

bpy.utils.register_class(ReferencePointProperty)
Object.ReferencePointProperty = CollectionProperty(type=ReferencePointProperty)

bpy.utils.register_class(archipack_reference_point)
Object.archipack_reference_point = CollectionProperty(type=archipack_reference_point)
bpy.utils.register_class(ARCHIPACK_PT_reference_point)
bpy.utils.register_class(ARCHIPACK_OT_reference_point)
bpy.utils.register_class(ARCHIPACK_OT_move_to_3d)
bpy.utils.register_class(ARCHIPACK_OT_move_to_2d)
bpy.utils.register_class(ARCHIPACK_OT_store_2d_reference)
bpy.utils.register_class(ARCHIPACK_OT_move_2d_reference_to_cursor)
bpy.utils.register_class(ARCHIPACK_OT_parent_to_reference)

Loading

0 comments on commit e48fae6

Please sign in to comment.