Skip to content

Commit

Permalink
Merge pull request #38 from s-leger/preset_menu
Browse files Browse the repository at this point in the history
Release 1.2.5
  • Loading branch information
s-leger authored Jun 24, 2017
2 parents 17741fb + 4dab4de commit 5678a59
Show file tree
Hide file tree
Showing 42 changed files with 3,467 additions and 836 deletions.
28 changes: 14 additions & 14 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
'author': 's-leger',
'license': 'GPL',
'deps': 'shapely',
'version': (1, 2, 4),
'version': (1, 2, 5),
'blender': (2, 7, 8),
'location': 'View3D > Tools > Create > Archipack',
'warning': '',
Expand Down Expand Up @@ -464,7 +464,7 @@ def poll(self, context):

def draw(self, context):
global icons_collection

addon_updater_ops.check_for_update_background(context)

icons = icons_collection["main"]
Expand Down Expand Up @@ -533,20 +533,20 @@ def draw(self, context):
).ceiling = True

addon_updater_ops.update_notice_box_ui(self, context)

# row = box.row(align=True)
# row.operator("archipack.roof", icon='CURVE_DATA')

# toolkit
# row = box.row(align=True)
# row.operator("archipack.myobject")

row = box.row(align=True)
row.operator("archipack.floor_preset_menu",
text="Floor",
icon_value=icons["floor"].icon_id
).preset_operator = "archipack.floor"

# ----------------------------------------------------
# ALT + A menu
# ----------------------------------------------------
Expand All @@ -557,7 +557,7 @@ def draw_menu(self, context):
icons = icons_collection["main"]
layout = self.layout
layout.operator_context = 'INVOKE_REGION_WIN'

layout.operator("archipack.wall2",
text="Wall",
icon_value=icons["wall"].icon_id
Expand Down Expand Up @@ -593,24 +593,23 @@ class ARCHIPACK_create_menu(Menu):
bl_idname = 'ARCHIPACK_create_menu'

def draw(self, context):
layout = self.layout
draw_menu(self, context)


def menu_func(self, context):
layout = self.layout
layout.separator()
global icons_collection
icons = icons_collection["main"]

# either draw sub menu or right at end of this one
if context.user_preferences.addons[__name__].preferences.create_submenu:
layout.operator_context = 'INVOKE_REGION_WIN'
layout.menu("ARCHIPACK_create_menu", icon_value=icons["archipack"].icon_id)
else:
draw_menu(self, context)


# ----------------------------------------------------
# Datablock to store global addon variables
# ----------------------------------------------------
Expand Down Expand Up @@ -665,7 +664,7 @@ def register():
update_panel(None, bpy.context)
bpy.utils.register_class(ARCHIPACK_create_menu)
bpy.types.INFO_MT_mesh_add.append(menu_func)

addon_updater_ops.register(bl_info)
# bpy.utils.register_module(__name__)

Expand All @@ -674,7 +673,7 @@ def unregister():
global icons_collection
bpy.types.INFO_MT_mesh_add.remove(menu_func)
bpy.utils.unregister_class(ARCHIPACK_create_menu)

bpy.utils.unregister_class(TOOLS_PT_Archipack_PolyLib)
bpy.utils.unregister_class(TOOLS_PT_Archipack_Tools)
bpy.utils.unregister_class(TOOLS_PT_Archipack_Create)
Expand Down Expand Up @@ -714,3 +713,4 @@ def unregister():

if __name__ == "__main__":
register()

2 changes: 1 addition & 1 deletion addon_updater_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ def register(bl_info):

# Optional, consider turning off for production or allow as an option
# This will print out additional debugging info to the console
updater.verbose = True # make False for production default
updater.verbose = False # make False for production default

# Optional, customize where the addon updater processing subfolder is,
# essentially a staging folder used by the updater on its own
Expand Down
132 changes: 87 additions & 45 deletions archipack_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,16 @@
# ----------------------------------------------------------
from mathutils import Vector, Matrix
from math import sin, cos, pi, atan2, sqrt, acos
import bpy
# allow to draw parts with gl for debug puropses
from .archipack_gl import GlBaseLine


class Projection():
class Projection(GlBaseLine):

def __init__(self):
GlBaseLine.__init__(self)

def proj_xy(self, t, next=None):
"""
length of projection of sections at crossing line / circle intersections
Expand Down Expand Up @@ -99,6 +106,7 @@ def __init__(self, p=None, v=None, p0=None, p1=None):
Will convert any into Vector 2d
both optionnals
"""
Projection.__init__(self)
if p is not None and v is not None:
self.p = Vector(p).to_2d()
self.v = Vector(v).to_2d()
Expand Down Expand Up @@ -183,13 +191,9 @@ def cross_z(self):
def cross(self):
return Vector((self.v.y, -self.v.x))

@property
def pts(self):
return [self.p0, self.p1]

def signed_angle(self, u, v):
"""
signed angle between two vectors
signed angle between two vectors range [-pi, pi]
"""
return atan2(u.x * v.y - u.y * v.x, u.x * v.x + u.y * v.y)

Expand All @@ -200,7 +204,7 @@ def delta_angle(self, last):
"""
if last is None:
return self.angle
return self.signed_angle(last.straight(1).v, self.straight(0).v)
return self.signed_angle(last.straight(1, 1).v, self.straight(1, 0).v)

def normal(self, t=0):
"""
Expand Down Expand Up @@ -287,12 +291,19 @@ def tangeant(self, t, da, radius):
def straight(self, length, t=1):
return Line(self.lerp(t), self.v.normalized() * length)

def rotate(self, da):
cs = cos(da)
sn = sin(da)
x, y = self.v
self.v.x = x * cs - y * sn
self.v.y = x * sn + y * cs
def translate(self, dp):
self.p += dp

def rotate(self, a):
"""
Rotate segment ccw arroud p0
"""
ca = cos(a)
sa = sin(a)
self.v = Matrix([
[ca, -sa],
[sa, ca]
]) * self.v
return self

def scale(self, length):
Expand All @@ -302,12 +313,12 @@ def scale(self, length):
def tangeant_unit_vector(self, t):
return self.v.normalized()

def draw(self, context):
def as_curve(self, context):
"""
Draw Line with open gl in screen space
aka: coords are in pixels
"""
return NotImplementedError
raise NotImplementedError

def make_offset(self, offset, last=None):
"""
Expand All @@ -319,7 +330,7 @@ def make_offset(self, offset, last=None):
if last is None:
return line

if type(last).__name__ == 'Arc':
if hasattr(last, "r"):
res, d, t = line.point_sur_segment(last.c)
c = (last.r * last.r) - (d * d)
print("t:%s" % t)
Expand Down Expand Up @@ -369,9 +380,14 @@ def make_offset(self, offset, last=None):

return line

@property
def pts(self):
return [self.p0.to_3d(), self.p1.to_3d()]


class Circle(Projection):
def __init__(self, c, radius):
Projection.__init__(self)
self.r = radius
self.r2 = radius * radius
self.c = c
Expand Down Expand Up @@ -399,6 +415,9 @@ def intersect(self, line):
else:
return True, line.lerp(t1), t1

def translate(self, dp):
self.c += dp


class Arc(Circle):
"""
Expand Down Expand Up @@ -450,9 +469,9 @@ def delta_angle(self, last):
"""
if last is None:
return self.a0
return self.signed_angle(last.straight(1).v, self.straight(0).v)
return self.signed_angle(last.straight(1, 1).v, self.straight(1, 0).v)

def rot_scale_matrix(self, u, v):
def scale_rot_matrix(self, u, v):
"""
given vector u and v (from and to p0 p1)
apply scale factor to radius and
Expand All @@ -467,8 +486,8 @@ def rot_scale_matrix(self, u, v):
ca = scale * cos(a)
sa = scale * sin(a)
return scale, Matrix([
[ca, sa],
[-sa, ca]
[ca, -sa],
[sa, ca]
])

@property
Expand All @@ -493,11 +512,11 @@ def p0(self, p0):
"""
u = self.p0 - self.p1
v = p0 - self.p1
scale, tM = self.rot_scale_matrix(u, v)
self.c = self.p1 + tM * (self.c - self.p1)
scale, rM = self.scale_rot_matrix(u, v)
self.c = self.p1 + rM * (self.c - self.p1)
self.r *= scale
self.r2 = self.r * self.r
dp = self.p0 - self.c
dp = p0 - self.c
self.a0 = atan2(dp.y, dp.x)

@p1.setter
Expand All @@ -506,13 +525,15 @@ def p1(self, p1):
rotate and scale arc so it intersect p0 p1
da is not affected
"""
u = self.p1 - self.p0
v = p1 - self.p0
scale, tM = self.rot_scale_matrix(u, v)
self.c = self.p0 + tM * (self.c - self.p0)
p0 = self.p0
u = self.p1 - p0
v = p1 - p0

scale, rM = self.scale_rot_matrix(u, v)
self.c = p0 + rM * (self.c - p0)
self.r *= scale
self.r2 = self.r * self.r
dp = self.p0 - self.c
dp = p0 - self.c
self.a0 = atan2(dp.y, dp.x)

@property
Expand Down Expand Up @@ -607,8 +628,7 @@ def straight(self, length, t=1):
Return a tangeant Line
Counterpart on Line also return a Line
"""
s = self.tangeant(t, length)
return s
return self.tangeant(t, length)

def point_sur_segment(self, pt):
"""
Expand All @@ -624,26 +644,22 @@ def point_sur_segment(self, pt):
t = (a - self.a0) / self.da
return t > 0 and t < 1, d, t

def rotate(self, da):
def rotate(self, a):
"""
Rotate center so we rotate arround start
Rotate center so we rotate ccw arround p0
"""
cs = cos(da)
sn = sin(da)
ca = cos(a)
sa = sin(a)
rM = Matrix([
[cs, sn],
[-sn, cs]
[ca, -sa],
[sa, ca]
])
self.c = rM * (self.p0 - self.c)
p0 = self.p0
self.c = p0 + rM * (self.c - p0)
dp = p0 - self.c
self.a0 = atan2(dp.y, dp.x)
return self

def draw(self, context):
"""
Draw 2d arc with open gl in screen space
aka: coords are in pixels
"""
raise NotImplementedError

# make offset for line / arc, arc / arc
def make_offset(self, offset, last=None):

Expand All @@ -652,7 +668,7 @@ def make_offset(self, offset, last=None):
if last is None:
return line

if type(last).__name__ == 'Line':
if hasattr(last, "v"):
# intersect line / arc
# 1 line -> 2 arc
res, d, t = last.point_sur_segment(line.c)
Expand Down Expand Up @@ -728,6 +744,32 @@ def make_offset(self, offset, last=None):
line.da = self.signed_angle(u, v)
return line

# DEBUG
@property
def pts(self):
n_pts = max(1, int(round(abs(self.da) / pi * 30, 0)))
t_step = 1 / n_pts
return [self.lerp(i * t_step).to_3d() for i in range(n_pts + 1)]

def as_curve(self, context):
"""
Draw 2d arc with open gl in screen space
aka: coords are in pixels
"""
curve = bpy.data.curves.new('ARC', type='CURVE')
curve.dimensions = '2D'
spline = curve.splines.new('POLY')
spline.use_endpoint_u = False
spline.use_cyclic_u = False
pts = self.pts
spline.points.add(len(pts) - 1)
for i, p in enumerate(pts):
x, y = p
spline.points[i].co = (x, y, 0, 1)
curve_obj = bpy.data.objects.new('ARC', curve)
context.scene.objects.link(curve_obj)
curve_obj.select = True


class Line3d(Line):
"""
Expand Down
Loading

0 comments on commit 5678a59

Please sign in to comment.