-
Notifications
You must be signed in to change notification settings - Fork 49
/
archipack_slab.py
1674 lines (1410 loc) · 54.1 KB
/
archipack_slab.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding:utf-8 -*-
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# 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.
#
# ##### END GPL LICENSE BLOCK #####
# <pep8 compliant>
# ----------------------------------------------------------
# Author: Stephen Leger (s-leger)
#
# ----------------------------------------------------------
# noinspection PyUnresolvedReferences
import bpy
# noinspection PyUnresolvedReferences
from bpy.types import Operator, PropertyGroup, Mesh, Panel
from bpy.props import (
FloatProperty, BoolProperty, IntProperty,
StringProperty, EnumProperty,
CollectionProperty
)
import bmesh
from mathutils import Vector, Matrix
from mathutils.geometry import interpolate_bezier
from math import sin, cos, pi, atan2
from .archipack_manipulator import Manipulable, archipack_manipulator
from .archipack_object import ArchipackCreateTool, ArchipackObject
from .archipack_2d import Line, Arc
from .archipack_cutter import (
CutAblePolygon, CutAbleGenerator,
ArchipackCutter,
ArchipackCutterPart
)
from .archipack_dimension import DimensionProvider
from .archipack_curveman import ArchipackCurveManager
class Slab():
def __init__(self):
# self.colour_inactive = (1, 1, 1, 1)
pass
def set_offset(self, offset, last=None):
"""
Offset line and compute intersection point
between segments
"""
self.line = self.make_offset(offset, last)
def straight_slab(self, a0, length):
s = self.straight(length).rotate(a0)
return StraightSlab(s.p, s.v)
def curved_slab(self, a0, da, radius):
n = self.normal(1).rotate(a0).scale(radius)
if da < 0:
n.v = -n.v
a0 = n.angle
c = n.p - n.v
return CurvedSlab(c, radius, a0, da)
class StraightSlab(Slab, Line):
def __init__(self, p, v):
Line.__init__(self, p, v)
Slab.__init__(self)
class CurvedSlab(Slab, Arc):
def __init__(self, c, radius, a0, da):
Arc.__init__(self, c, radius, a0, da)
Slab.__init__(self)
class SlabGenerator(CutAblePolygon, CutAbleGenerator):
def __init__(self, d):
self.d = d
self.parts = d.parts
self.segs = []
self.holes = []
self.convex = True
self.xsize = 0
def add_part(self, part):
if len(self.segs) < 1:
s = None
else:
s = self.segs[-1]
# start a new slab
if s is None:
if part.type == 'S_SEG':
p = Vector((0, 0))
v = part.length * Vector((cos(part.a0), sin(part.a0)))
s = StraightSlab(p, v)
elif part.type == 'C_SEG':
c = -part.radius * Vector((cos(part.a0), sin(part.a0)))
s = CurvedSlab(c, part.radius, part.a0, part.da)
else:
if part.type == 'S_SEG':
s = s.straight_slab(part.a0, part.length)
elif part.type == 'C_SEG':
s = s.curved_slab(part.a0, part.da, part.radius)
self.segs.append(s)
self.last_type = part.type
def set_offset(self, offset):
last = None
for i, seg in enumerate(self.segs):
seg.set_offset(offset + self.parts[i].offset, last)
last = seg.line
def close(self, offset):
# Make last segment implicit closing one
part = self.parts[-1]
w = self.segs[-1]
dp = self.segs[0].p0 - self.segs[-1].p0
if "C_" in part.type:
dw = (w.p1 - w.p0)
w.r = part.radius / dw.length * dp.length
# angle pt - p0 - angle p0 p1
da = atan2(dp.y, dp.x) - atan2(dw.y, dw.x)
a0 = w.a0 + da
if a0 > pi:
a0 -= 2 * pi
if a0 < -pi:
a0 += 2 * pi
w.a0 = a0
else:
w.v = dp
if len(self.segs) > 1:
w.line = w.make_offset(offset + part.offset, self.segs[-2].line)
p1 = self.segs[0].line.p1
self.segs[0].line = self.segs[0].make_offset(offset + self.parts[0].offset, w.line)
self.segs[0].line.p1 = p1
def locate_manipulators(self):
"""
setup manipulators
"""
for i, f in enumerate(self.segs):
part = self.parts[i]
manipulators = part.manipulators
p0 = f.p0.to_3d()
p1 = f.p1.to_3d()
# angle from last to current segment
if i > 0:
v0 = self.segs[i - 1].straight(-1, 1).v.to_3d()
v1 = f.straight(1, 0).v.to_3d()
manipulators[0].set_pts([p0, v0, v1])
if type(f).__name__ == "StraightSlab":
# segment length
manipulators[1].type_key = 'SIZE'
manipulators[1].prop1_name = "length"
manipulators[1].set_pts([p0, p1, (1, 0, 0)])
else:
# segment radius + angle
v0 = (f.p0 - f.c).to_3d()
v1 = (f.p1 - f.c).to_3d()
manipulators[1].type_key = 'ARC_ANGLE_RADIUS'
manipulators[1].prop1_name = "da"
manipulators[1].prop2_name = "radius"
manipulators[1].set_pts([f.c.to_3d(), v0, v1])
# snap manipulator, dont change index !
manipulators[2].set_pts([p0, p1, (1, 0, 0)])
# dumb segment id
manipulators[3].set_pts([p0, p1, (1, 0, 0)])
# Dimensions points
self.d.add_dimension_point(part.uid, p0)
def get_verts(self, verts):
verts.extend([s.p0.to_3d() for s in self.segs])
def rotate(self, idx_from, a):
"""
apply rotation to all following segs
"""
self.segs[idx_from].rotate(a)
ca = cos(a)
sa = sin(a)
rM = Matrix([
[ca, -sa],
[sa, ca]
])
# rotation center
p0 = self.segs[idx_from].p0
for i in range(idx_from + 1, len(self.segs)):
seg = self.segs[i]
# rotate seg
seg.rotate(a)
# rotate delta from rotation center to segment start
dp = rM * (seg.p0 - p0)
seg.translate(dp)
def translate(self, idx_from, dp):
"""
apply translation to all following segs
"""
self.segs[idx_from].p1 += dp
for i in range(idx_from + 1, len(self.segs)):
self.segs[i].translate(dp)
def draw(self, context):
"""
draw generator using gl
"""
for seg in self.segs:
seg.draw(context, render=False)
def limits(self):
x_size = [s.p0.x for s in self.segs]
self.xsize = max(x_size) - min(x_size)
def cut(self, context, o):
"""
either external or holes cuts
"""
# use offset segs as base
self.as_lines(step_angle=0.0502)
self.limits()
for b in o.children:
d = archipack_slab_cutter.datablock(b)
if d is not None:
g = d.ensure_direction()
g.change_coordsys(b.matrix_world, o.matrix_world)
self.slice(g)
def slab(self, context, o, d):
verts = []
self.get_verts(verts)
if len(verts) > 2:
# ensure verts are CCW
if d.is_cw(verts):
verts = list(reversed(verts))
bm = bmesh.new()
for v in verts:
bm.verts.new(v)
bm.verts.ensure_lookup_table()
for i in range(1, len(verts)):
bm.edges.new((bm.verts[i - 1], bm.verts[i]))
bm.edges.new((bm.verts[-1], bm.verts[0]))
bm.edges.ensure_lookup_table()
bmesh.ops.contextual_create(bm, geom=bm.edges)
self.cut_holes(bm, self)
bmesh.ops.dissolve_limit(bm,
angle_limit=0.01,
use_dissolve_boundaries=False,
verts=bm.verts,
edges=bm.edges,
delimit=1)
bm.to_mesh(o.data)
bm.free()
# geom = bm.faces[:]
# verts = bm.verts[:]
# bmesh.ops.solidify(bm, geom=geom, thickness=d.z)
# merge with object
# bmed.bmesh_join(context, o, [bm], normal_update=True)
bpy.ops.object.mode_set(mode='OBJECT')
def update(self, context):
self.update(context)
def update_manipulators(self, context):
self.update(context, manipulable_refresh=True)
def update_path(self, context):
self.update_path(context)
materials_enum = (
('0', 'Ceiling', '', 0),
('1', 'White', '', 1),
('2', 'Concrete', '', 2),
('3', 'Wood', '', 3),
('4', 'Metal', '', 4),
('5', 'Glass', '', 5)
)
class archipack_slab_material(PropertyGroup):
index = EnumProperty(
items=materials_enum,
default='4',
update=update
)
def find_in_selection(self, context):
"""
find witch selected object this instance belongs to
provide support for "copy to selected"
"""
selected = [o for o in context.selected_objects]
for o in selected:
props = archipack_slab.datablock(o)
if props:
for part in props.rail_mat:
if part == self:
return props
return None
def update(self, context):
props = self.find_in_selection(context)
if props is not None:
props.update(context)
class archipack_slab_child(PropertyGroup):
"""
Store child fences to be able to sync
"""
child_name = StringProperty()
idx = IntProperty()
def get_child(self, context):
d = None
child = context.scene.objects.get(self.child_name)
if child is not None and child.data is not None:
if 'archipack_fence' in child.data:
d = child.data.archipack_fence[0]
return child, d
def update_type(self, context):
d = self.find_in_selection(context)
if d is not None and d.auto_update:
d.auto_update = False
# find part index
idx = 0
for i, part in enumerate(d.parts):
if part == self:
idx = i
break
part = d.parts[idx]
a0 = 0
if idx > 0:
g = d.get_generator()
w0 = g.segs[idx - 1]
a0 = w0.straight(1).angle
if "C_" in self.type:
w = w0.straight_slab(part.a0, part.length)
else:
w = w0.curved_slab(part.a0, part.da, part.radius)
else:
if "C_" in self.type:
p = Vector((0, 0))
v = self.length * Vector((cos(self.a0), sin(self.a0)))
w = StraightSlab(p, v)
a0 = pi / 2
else:
c = -self.radius * Vector((cos(self.a0), sin(self.a0)))
w = CurvedSlab(c, self.radius, self.a0, pi)
# w0 - w - w1
if idx + 1 == d.n_parts:
dp = - w.p0
else:
dp = w.p1 - w.p0
if "C_" in self.type:
part.radius = 0.5 * dp.length
part.da = pi
a0 = atan2(dp.y, dp.x) - pi / 2 - a0
else:
part.length = dp.length
a0 = atan2(dp.y, dp.x) - a0
if a0 > pi:
a0 -= 2 * pi
if a0 < -pi:
a0 += 2 * pi
part.a0 = a0
if idx + 1 < d.n_parts:
# adjust rotation of next part
part1 = d.parts[idx + 1]
if "C_" in part.type:
a0 = part1.a0 - pi / 2
else:
a0 = part1.a0 + w.straight(1).angle - atan2(dp.y, dp.x)
if a0 > pi:
a0 -= 2 * pi
if a0 < -pi:
a0 += 2 * pi
part1.a0 = a0
d.auto_update = True
class ArchipackSegment():
"""
A single manipulable polyline like segment
polyline like segment line or arc based
@TODO: share this base class with
stair, wall, fence, slab
"""
type = EnumProperty(
items=(
('S_SEG', 'Straight', '', 0),
('C_SEG', 'Curved', '', 1),
),
default='S_SEG',
update=update_type
)
length = FloatProperty(
name="Length",
min=0.001,
default=2.0,
update=update
)
radius = FloatProperty(
name="Radius",
min=0.5,
default=0.7,
update=update
)
da = FloatProperty(
name="Angle",
min=-pi,
max=pi,
default=pi / 2,
subtype='ANGLE', unit='ROTATION',
update=update
)
a0 = FloatProperty(
name="Start angle",
min=-2 * pi,
max=2 * pi,
default=0,
subtype='ANGLE', unit='ROTATION',
update=update
)
offset = FloatProperty(
name="Offset",
description="Add to current segment offset",
default=0,
unit='LENGTH', subtype='DISTANCE',
update=update
)
linked_idx = IntProperty(default=-1)
# @TODO:
# flag to handle wall's x_offset
# when set add wall offset value to segment offset
# pay attention at allowing per wall segment offset
manipulators = CollectionProperty(type=archipack_manipulator)
def find_in_selection(self, context):
raise NotImplementedError
def update(self, context, manipulable_refresh=False):
props = self.find_in_selection(context)
if props is not None:
props.update(context, manipulable_refresh)
def draw_insert(self, context, layout, index):
"""
May implement draw for insert / remove segment operators
"""
pass
def draw(self, context, layout, index):
box = layout.box()
box.prop(self, "type", text=str(index + 1))
self.draw_insert(context, box, index)
if self.type in ['C_SEG']:
box.prop(self, "radius")
box.prop(self, "da")
else:
box.prop(self, "length")
box.prop(self, "a0")
class archipack_slab_part(ArchipackSegment, PropertyGroup):
# DimensionProvider related
uid = IntProperty(default=0)
def draw_insert(self, context, layout, index):
row = layout.row(align=True)
row.operator("archipack.slab_insert", text="Split").index = index
row.operator("archipack.slab_balcony", text="Balcony").index = index
if index > 0:
row.operator("archipack.slab_remove", text="Remove").index = index
def find_in_selection(self, context):
"""
find witch selected object this instance belongs to
provide support for "copy to selected"
"""
selected = [o for o in context.selected_objects]
for o in selected:
props = archipack_slab.datablock(o)
if props:
for part in props.parts:
if part == self:
return props
return None
class archipack_slab(ArchipackObject, ArchipackCurveManager, Manipulable, DimensionProvider, PropertyGroup):
# boundary
n_parts = IntProperty(
name="Parts",
min=1,
default=1,
update=update_manipulators
)
parts = CollectionProperty(type=archipack_slab_part)
closed = BoolProperty(
default=True,
name="Close",
options={'SKIP_SAVE'},
update=update_manipulators
)
# UI layout related
parts_expand = BoolProperty(
options={'SKIP_SAVE'},
default=False
)
x_offset = FloatProperty(
name="Offset",
default=0.0, precision=2, step=1,
unit='LENGTH', subtype='DISTANCE',
update=update
)
z = FloatProperty(
name="Thickness",
default=0.3, precision=2, step=1,
unit='LENGTH', subtype='DISTANCE',
update=update
)
auto_synch = BoolProperty(
name="Auto-Synch",
description="Keep wall in synch when editing",
default=True,
update=update_manipulators
)
childs = CollectionProperty(type=archipack_slab_child)
# Flag to prevent mesh update while making bulk changes over variables
auto_update = BoolProperty(
options={'SKIP_SAVE'},
default=True,
update=update_manipulators
)
def get_generator(self):
g = SlabGenerator(self)
for part in self.parts:
# type, radius, da, length
g.add_part(part)
g.set_offset(self.x_offset)
g.close(self.x_offset)
g.locate_manipulators()
# here segs are without offset
# seg.line contains offset
return g
def new_part(self, where, type, length, radius, offset, a0, da):
idx = len(self.parts)
p = self.parts.add()
p.type = type
p.length = length
p.offset = offset
p.da = da
p.a0 = a0
self.n_parts += 1
self.parts.move(idx, where + 1)
return p
def insert_part(self, context, where):
self.manipulable_disable(context)
self.auto_update = False
# the part we do split
part_0 = self.parts[where]
part_0.length /= 2
part_0.da /= 2
self.new_part(
where,
part_0.type,
part_0.length,
part_0.radius,
part_0.offset,
0,
part_0.da)
for c in self.childs:
if c.idx > where:
c.idx += 1
self.setup_manipulators()
self.auto_update = True
def insert_balcony(self, context, where):
self.manipulable_disable(context)
self.auto_update = False
# the part we do split
part_0 = self.parts[where]
part_0.length /= 3
part_0.da /= 3
# store here to keep a valid ref
type = part_0.type
length = part_0.length
radius = part_0.radius
offset = part_0.offset
da = part_0.da
# 1st part 90deg
self.new_part(where, "S_SEG", 1.5, 0, 0, -pi / 2, da)
# 2nd part -90deg
self.new_part(where + 1, type, length, radius + 1.5, 0, pi / 2, da)
# 3th part -90deg
self.new_part(where + 2, "S_SEG", 1.5, 0, 0, pi / 2, da)
# 4th part -90deg
self.new_part(where + 3, type, length, radius, offset, -pi / 2, da)
self.setup_manipulators()
for c in self.childs:
if c.idx > where:
c.idx += 4
self.auto_update = True
g = self.get_generator()
o = context.active_object
bpy.ops.archipack.fence(auto_manipulate=False)
c = context.active_object
c.select = True
c.data.archipack_fence[0].n_parts = 3
c.select = False
# link to o
c.location = Vector((0, 0, 0))
c.parent = o
c.location = g.segs[where + 1].p0.to_3d()
self.add_child(c.name, where + 1)
# c.matrix_world.translation = g.segs[where].p1.to_3d()
o.select = True
context.scene.objects.active = o
self.relocate_childs(context, o, g)
def add_part(self, context, length):
self.manipulable_disable(context)
self.auto_update = False
p = self.parts.add()
p.length = length
self.n_parts += 1
self.setup_manipulators()
self.auto_update = True
return p
def add_child(self, name, idx):
c = self.childs.add()
c.child_name = name
c.idx = idx
def setup_childs(self, o, g):
"""
Store childs
call after a boolean oop
"""
# print("setup_childs")
self.childs.clear()
itM = o.matrix_world.inverted()
dmax = 0.2
for c in o.children:
if (c.data and 'archipack_fence' in c.data):
pt = (itM * c.matrix_world.translation).to_2d()
for idx, seg in enumerate(g.segs):
# may be optimized with a bound check
res, d, t = seg.point_sur_segment(pt)
# p1
# |-- x
# p0
dist = abs(t) * seg.length
if dist < dmax and abs(d) < dmax:
# print("%s %s %s %s" % (idx, dist, d, c.name))
self.add_child(c.name, idx)
# synch wall
# store index of segments with p0 match
if self.auto_synch:
if o.parent is not None:
for i, part in enumerate(self.parts):
part.linked_idx = -1
# find first child wall
d = None
for c in o.parent.children:
if c.data and "archipack_wall2" in c.data:
d = c.data.archipack_wall2[0]
break
if d is not None:
og = d.get_generator()
j = 0
for i, part in enumerate(self.parts):
ji = j
while ji < d.n_parts + 1:
if (g.segs[i].p0 - og.segs[ji].p0).length < 0.005:
j = ji + 1
part.linked_idx = ji
# print("link: %s to %s" % (i, ji))
break
ji += 1
def relocate_childs(self, context, o, g):
"""
Move and resize childs after edition
"""
# print("relocate_childs")
# Wall child syncro
# must store - idx of shared segs
# -> store this in parts provide 1:1 map
# share type: full, start only, end only
# -> may compute on the fly with idx stored
# when full segment does match
# -update type, radius, length, a0, and da
# when start only does match
# -update type, radius, a0
# when end only does match
# -compute length/radius
# @TODO:
# handle p0 and p1 changes right in Generator (archipack_2d)
# and retrieve params from there
if self.auto_synch:
if o.parent is not None:
wall = None
for child in o.parent.children:
if child.data and "archipack_wall2" in child.data:
wall = child
break
if wall is not None:
d = wall.data.archipack_wall2[0]
d.auto_update = False
w = d.get_generator()
last_idx = -1
# update og from g
for i, part in enumerate(self.parts):
idx = part.linked_idx
seg = g.segs[i]
if i + 1 < self.n_parts:
next_idx = self.parts[i + 1].linked_idx
elif d.closed:
next_idx = self.parts[0].linked_idx
else:
next_idx = -1
if idx > -1:
# start and shared: update rotation
a = seg.angle - w.segs[idx].angle
if abs(a) > 0.00001:
w.rotate(idx, a)
if last_idx > -1:
w.segs[last_idx].p1 = seg.p0
if next_idx > -1:
if (idx + 1 == next_idx) or (next_idx == 0 and i + 1 == self.n_parts):
# shared: should move last point
# and apply to next segments
# this is overriden for common segs
# but translate non common ones
dp = seg.p1 - w.segs[idx].p1
w.translate(idx, dp)
# shared: transfert type too
if "C_" in part.type:
d.parts[idx].type = 'C_WALL'
w.segs[idx] = CurvedSlab(seg.c, seg.r, seg.a0, seg.da)
else:
d.parts[idx].type = 'S_WALL'
w.segs[idx] = StraightSlab(seg.p.copy(), seg.v.copy())
last_idx = -1
elif next_idx > -1:
# only last is shared
# note: on next run will be part of start
last_idx = next_idx - 1
# update d from og
last_seg = None
for i, seg in enumerate(w.segs):
d.parts[i].a0 = seg.delta_angle(last_seg)
last_seg = seg
if "C_" in d.parts[i].type:
d.parts[i].radius = seg.r
d.parts[i].da = seg.da
else:
d.parts[i].length = max(0.01, seg.length)
wall.select = True
context.scene.objects.active = wall
d.auto_update = True
wall.select = False
o.select = True
context.scene.objects.active = o
wall.matrix_world = Matrix([
[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, d.z_offset],
[0, 0, 0, 1],
]) * o.matrix_world
tM = o.matrix_world
for child in self.childs:
c, d = child.get_child(context)
if c is None:
continue
a = g.segs[child.idx].angle
x, y = g.segs[child.idx].p0
sa = sin(a)
ca = cos(a)
if d is not None:
c.select = True
# auto_update need object to be active to
# setup manipulators on the right object
context.scene.objects.active = c
d.auto_update = False
for i, part in enumerate(d.parts):
if "C_" in self.parts[i + child.idx].type:
part.type = "C_FENCE"
else:
part.type = "S_FENCE"
part.a0 = self.parts[i + child.idx].a0
part.da = self.parts[i + child.idx].da
part.length = self.parts[i + child.idx].length
part.radius = self.parts[i + child.idx].radius
d.parts[0].a0 = pi / 2
d.auto_update = True
c.select = False
context.scene.objects.active = o
# preTranslate
c.matrix_world = tM * Matrix([
[sa, ca, 0, x],
[-ca, sa, 0, y],
[0, 0, 1, 0],
[0, 0, 0, 1]
])
def remove_part(self, context, where):
self.manipulable_disable(context)
self.auto_update = False
# preserve shape
# using generator
if where > 0:
g = self.get_generator()
w = g.segs[where - 1]
w.p1 = g.segs[where].p1
if where + 1 < self.n_parts:
self.parts[where + 1].a0 = g.segs[where + 1].delta_angle(w)
part = self.parts[where - 1]
if "C_" in part.type:
part.radius = w.r
else:
part.length = w.length
if where > 1:
part.a0 = w.delta_angle(g.segs[where - 2])
else:
part.a0 = w.straight(1, 0).angle
for c in self.childs:
if c.idx >= where:
c.idx -= 1
self.parts.remove(where)
self.n_parts -= 1
# fix snap manipulators index
self.setup_manipulators()
self.auto_update = True
def update_parts(self, o, update_childs=False):
# remove rows
# NOTE:
# n_parts+1
# as last one is end point of last segment or closing one
row_change = False
for i in range(len(self.parts), self.n_parts, -1):
row_change = True
self.parts.remove(i - 1)
# add rows
for i in range(len(self.parts), self.n_parts):
row_change = True
self.parts.add()
for p in self.parts:
if p.uid == 0:
self.create_uid(p)
self.setup_manipulators()
g = self.get_generator()
if o is not None and (row_change or update_childs):
self.setup_childs(o, g)
return g
def setup_manipulators(self):
if len(self.manipulators) < 1:
s = self.manipulators.add()
s.type_key = "SIZE"
s.prop1_name = "z"
s.normal = Vector((0, 1, 0))
for i in range(self.n_parts):
p = self.parts[i]
n_manips = len(p.manipulators)
if n_manips < 1:
s = p.manipulators.add()
s.type_key = "ANGLE"
s.prop1_name = "a0"
p.manipulators[0].type_key = 'ANGLE'
if n_manips < 2:
s = p.manipulators.add()
s.type_key = "SIZE"
s.prop1_name = "length"
if n_manips < 3:
s = p.manipulators.add()
s.type_key = 'WALL_SNAP'
s.prop1_name = str(i)
s.prop2_name = 'z'
if n_manips < 4: