forked from s-leger/archipack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharchipack_door.py
2088 lines (1881 loc) · 73.4 KB
/
archipack_door.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, IntProperty, CollectionProperty,
EnumProperty, BoolProperty, StringProperty
)
from mathutils import Vector
from math import pi, cos, sin
# door component objects (panels, handles ..)
from .bmesh_utils import BmeshEdit as bmed
from .panel import Panel as DoorPanel
from .archipack_handle import create_handle, door_handle_horizontal_01
from .archipack_manipulator import Manipulable
from .archipack_preset import ArchipackPreset, PresetMenuOperator
from .archipack_object import ArchipackObject, ArchipackCreateTool, ArchipackDrawTool
from .archipack_gl import FeedbackPanel
from .archipack_keymaps import Keymaps
from .archipack_dimension import DimensionProvider
SPACING = 0.005
BATTUE = 0.01
BOTTOM_HOLE_MARGIN = 0.001
FRONT_HOLE_MARGIN = 0.1
def update(self, context):
self.update(context)
def update_childs(self, context):
self.update(context, childs_only=True)
class archipack_door_panel(ArchipackObject, PropertyGroup):
x = FloatProperty(
name='Width',
min=0.25,
default=100.0, precision=2,
unit='LENGTH', subtype='DISTANCE',
description='Width'
)
y = FloatProperty(
name='Depth',
min=0.001,
default=0.02, precision=2,
unit='LENGTH', subtype='DISTANCE',
description='depth'
)
z = FloatProperty(
name='Height',
min=0.1,
default=2.0, precision=2,
unit='LENGTH', subtype='DISTANCE',
description='height'
)
direction = IntProperty(
name="Direction",
min=0,
max=1,
description="open direction"
)
model = IntProperty(
name="Model",
min=0,
max=3,
default=0,
description="Model"
)
chanfer = FloatProperty(
name='Bevel',
min=0.001,
default=0.005, precision=3,
unit='LENGTH', subtype='DISTANCE',
description='chanfer'
)
panel_spacing = FloatProperty(
name='Spacing',
min=0.001,
default=0.1, precision=2,
unit='LENGTH', subtype='DISTANCE',
description='distance between panels'
)
panel_bottom = FloatProperty(
name='Bottom',
min=0.0,
default=0.0, precision=2,
unit='LENGTH', subtype='DISTANCE',
description='distance from bottom'
)
panel_border = FloatProperty(
name='Border',
min=0.001,
default=0.2, precision=2,
unit='LENGTH', subtype='DISTANCE',
description='distance from border'
)
panels_x = IntProperty(
name="# h",
min=1,
max=50,
default=1,
description="panels h"
)
panels_y = IntProperty(
name="# v",
min=1,
max=50,
default=1,
description="panels v"
)
panels_distrib = EnumProperty(
name='distribution',
items=(
('REGULAR', 'Regular', '', 0),
('ONE_THIRD', '1/3 2/3', '', 1)
),
default='REGULAR'
)
handle = EnumProperty(
name='Shape',
items=(
('NONE', 'No handle', '', 0),
('BOTH', 'Inside and outside', '', 1)
),
default='BOTH'
)
@property
def symbol_2d(self):
# __ y0
# |__ y1
# x0
y0 = self.x
y1 = 0
x0 = 0
return DoorPanel(
False, # profil closed
[0, 0], # x index
[x0],
[y0, y1],
[0, 0], # material index
closed_path=True, #
side_cap_front=1, # cap index
side_cap_back=0
)
@property
def panels(self):
# subdivide side to weld panels
subdiv_x = self.panels_x - 1
if self.panels_distrib == 'REGULAR':
subdiv_y = self.panels_y - 1
else:
subdiv_y = 2
# __ y0
# |__ y1
# x0 x1
y0 = -self.y
y1 = 0
x0 = 0
x1 = max(0.001, self.panel_border - 0.5 * self.panel_spacing)
side = DoorPanel(
False, # profil closed
[1, 0, 0, 1], # x index
[x0, x1],
[y0, y0, y1, y1],
[0, 1, 1, 1], # material index
closed_path=True, #
subdiv_x=subdiv_x,
subdiv_y=subdiv_y
)
face = None
back = None
if self.model == 1:
# / y2-y3
# __/ y1-y0
# x2 x3
x2 = 0.5 * self.panel_spacing
x3 = x2 + self.chanfer
y2 = y1 + self.chanfer
y3 = y0 - self.chanfer
face = DoorPanel(
False, # profil closed
[0, 1, 2], # x index
[0, x2, x3],
[y1, y1, y2],
[1, 1, 1], # material index
side_cap_front=2, # cap index
closed_path=True
)
back = DoorPanel(
False, # profil closed
[0, 1, 2], # x index
[x3, x2, 0],
[y3, y0, y0],
[0, 0, 0], # material index
side_cap_back=0, # cap index
closed_path=True
)
elif self.model == 2:
# / y2-y3
# ___ _____/ y1-y0
# \ /
# \/ y4-y5
# 0 x2 x4 x5 x6 x3
x2 = 0.5 * self.panel_spacing
x4 = x2 + self.chanfer
x5 = x4 + self.chanfer
x6 = x5 + 4 * self.chanfer
x3 = x6 + self.chanfer
y2 = y1 - self.chanfer
y4 = y1 + self.chanfer
y3 = y0 + self.chanfer
y5 = y0 - self.chanfer
face = DoorPanel(
False, # profil closed
[0, 1, 2, 3, 4, 5], # x index
[0, x2, x4, x5, x6, x3],
[y1, y1, y4, y1, y1, y2],
[1, 1, 1, 1, 1, 1], # material index
side_cap_front=5, # cap index
closed_path=True
)
back = DoorPanel(
False, # profil closed
[0, 1, 2, 3, 4, 5], # x index
[x3, x6, x5, x4, x2, 0],
[y3, y0, y0, y5, y0, y0],
[0, 0, 0, 0, 0, 0], # material index
side_cap_back=0, # cap index
closed_path=True
)
elif self.model == 3:
# _____ y2-y3
# / \ y4-y5
# __/ y1-y0
# 0 x2 x3 x4 x5
x2 = 0.5 * self.panel_spacing
x3 = x2 + self.chanfer
x4 = x3 + 4 * self.chanfer
x5 = x4 + 2 * self.chanfer
y2 = y1 - self.chanfer
y3 = y0 + self.chanfer
y4 = y2 + self.chanfer
y5 = y3 - self.chanfer
face = DoorPanel(
False, # profil closed
[0, 1, 2, 3, 4], # x index
[0, x2, x3, x4, x5],
[y1, y1, y2, y2, y4],
[1, 1, 1, 1, 1], # material index
side_cap_front=4, # cap index
closed_path=True
)
back = DoorPanel(
False, # profil closed
[0, 1, 2, 3, 4], # x index
[x5, x4, x3, x2, 0],
[y5, y3, y3, y0, y0],
[0, 0, 0, 0, 0], # material index
side_cap_back=0, # cap index
closed_path=True
)
else:
side.side_cap_front = 3
side.side_cap_back = 0
return side, face, back
@property
def verts(self):
if self.panels_distrib == 'REGULAR':
subdiv_y = self.panels_y - 1
else:
subdiv_y = 2
radius = Vector((0.8, 0.5, 0))
center = Vector((0, self.z - radius.x, 0))
if self.direction == 0:
pivot = 1
else:
pivot = -1
path_type = 'RECTANGLE'
curve_steps = 16
side, face, back = self.panels
x1 = max(0.001, self.panel_border - 0.5 * self.panel_spacing)
bottom_z = self.panel_bottom
shape_z = [0, bottom_z, bottom_z, 0]
origin = Vector((-pivot * 0.5 * self.x, 0, 0))
offset = Vector((0, 0, 0))
size = Vector((self.x, self.z, 0))
verts = side.vertices(curve_steps, offset, center, origin,
size, radius, 0, pivot, shape_z=shape_z, path_type=path_type)
if face is not None:
p_radius = radius.copy()
p_radius.x -= x1
p_radius.y -= x1
if self.panels_distrib == 'REGULAR':
p_size = Vector(((self.x - 2 * x1) / self.panels_x,
(self.z - 2 * x1 - bottom_z) / self.panels_y, 0))
for i in range(self.panels_x):
for j in range(self.panels_y):
if j < subdiv_y:
shape = 'RECTANGLE'
else:
shape = path_type
offset = Vector(((pivot * 0.5 * self.x) + p_size.x * (i + 0.5) - 0.5 * size.x + x1,
bottom_z + p_size.y * j + x1, 0))
origin = Vector((p_size.x * (i + 0.5) - 0.5 * size.x + x1, bottom_z + p_size.y * j + x1, 0))
verts += face.vertices(curve_steps, offset, center, origin,
p_size, p_radius, 0, 0, shape_z=None, path_type=shape)
if back is not None:
verts += back.vertices(curve_steps, offset, center, origin,
p_size, p_radius, 0, 0, shape_z=None, path_type=shape)
else:
####################################
# Ratio vertical panels 1/3 - 2/3
####################################
p_size = Vector(((self.x - 2 * x1) / self.panels_x, (self.z - 2 * x1 - bottom_z) / 3, 0))
p_size_2x = Vector((p_size.x, p_size.y * 2, 0))
for i in range(self.panels_x):
j = 0
offset = Vector(((pivot * 0.5 * self.x) + p_size.x * (i + 0.5) - 0.5 * size.x + x1,
bottom_z + p_size.y * j + x1, 0))
origin = Vector((p_size.x * (i + 0.5) - 0.5 * size.x + x1, bottom_z + p_size.y * j + x1, 0))
shape = 'RECTANGLE'
face.subdiv_y = 0
verts += face.vertices(curve_steps, offset, center, origin,
p_size, p_radius, 0, 0, shape_z=None, path_type=shape)
if back is not None:
back.subdiv_y = 0
verts += back.vertices(curve_steps, offset, center, origin,
p_size, p_radius, 0, 0, shape_z=None, path_type=shape)
j = 1
offset = Vector(((pivot * 0.5 * self.x) + p_size.x * (i + 0.5) - 0.5 * size.x + x1,
bottom_z + p_size.y * j + x1, 0))
origin = Vector((p_size.x * (i + 0.5) - 0.5 * size.x + x1,
bottom_z + p_size.y * j + x1, 0))
shape = path_type
face.subdiv_y = 1
verts += face.vertices(curve_steps, offset, center, origin,
p_size_2x, p_radius, 0, 0, shape_z=None, path_type=path_type)
if back is not None:
back.subdiv_y = 1
verts += back.vertices(curve_steps, offset, center, origin,
p_size_2x, p_radius, 0, 0, shape_z=None, path_type=path_type)
return verts
@property
def faces(self):
if self.panels_distrib == 'REGULAR':
subdiv_y = self.panels_y - 1
else:
subdiv_y = 2
path_type = 'RECTANGLE'
curve_steps = 16
side, face, back = self.panels
faces = side.faces(curve_steps, path_type=path_type)
faces_offset = side.n_verts(curve_steps, path_type=path_type)
if face is not None:
if self.panels_distrib == 'REGULAR':
for i in range(self.panels_x):
for j in range(self.panels_y):
if j < subdiv_y:
shape = 'RECTANGLE'
else:
shape = path_type
faces += face.faces(curve_steps, path_type=shape, offset=faces_offset)
faces_offset += face.n_verts(curve_steps, path_type=shape)
if back is not None:
faces += back.faces(curve_steps, path_type=shape, offset=faces_offset)
faces_offset += back.n_verts(curve_steps, path_type=shape)
else:
####################################
# Ratio vertical panels 1/3 - 2/3
####################################
for i in range(self.panels_x):
j = 0
shape = 'RECTANGLE'
face.subdiv_y = 0
faces += face.faces(curve_steps, path_type=shape, offset=faces_offset)
faces_offset += face.n_verts(curve_steps, path_type=shape)
if back is not None:
back.subdiv_y = 0
faces += back.faces(curve_steps, path_type=shape, offset=faces_offset)
faces_offset += back.n_verts(curve_steps, path_type=shape)
j = 1
shape = path_type
face.subdiv_y = 1
faces += face.faces(curve_steps, path_type=path_type, offset=faces_offset)
faces_offset += face.n_verts(curve_steps, path_type=path_type)
if back is not None:
back.subdiv_y = 1
faces += back.faces(curve_steps, path_type=path_type, offset=faces_offset)
faces_offset += back.n_verts(curve_steps, path_type=path_type)
return faces
@property
def uvs(self):
if self.panels_distrib == 'REGULAR':
subdiv_y = self.panels_y - 1
else:
subdiv_y = 2
radius = Vector((0.8, 0.5, 0))
center = Vector((0, self.z - radius.x, 0))
if self.direction == 0:
pivot = 1
else:
pivot = -1
path_type = 'RECTANGLE'
curve_steps = 16
side, face, back = self.panels
x1 = max(0.001, self.panel_border - 0.5 * self.panel_spacing)
bottom_z = self.panel_bottom
origin = Vector((-pivot * 0.5 * self.x, 0, 0))
size = Vector((self.x, self.z, 0))
uvs = side.uv(curve_steps, center, origin, size, radius, 0, pivot, 0, self.panel_border, path_type=path_type)
if face is not None:
p_radius = radius.copy()
p_radius.x -= x1
p_radius.y -= x1
if self.panels_distrib == 'REGULAR':
p_size = Vector(((self.x - 2 * x1) / self.panels_x, (self.z - 2 * x1 - bottom_z) / self.panels_y, 0))
for i in range(self.panels_x):
for j in range(self.panels_y):
if j < subdiv_y:
shape = 'RECTANGLE'
else:
shape = path_type
origin = Vector((p_size.x * (i + 0.5) - 0.5 * size.x + x1, bottom_z + p_size.y * j + x1, 0))
uvs += face.uv(curve_steps, center, origin, p_size, p_radius, 0, 0, 0, 0, path_type=shape)
if back is not None:
uvs += back.uv(curve_steps, center, origin,
p_size, p_radius, 0, 0, 0, 0, path_type=shape)
else:
####################################
# Ratio vertical panels 1/3 - 2/3
####################################
p_size = Vector(((self.x - 2 * x1) / self.panels_x, (self.z - 2 * x1 - bottom_z) / 3, 0))
p_size_2x = Vector((p_size.x, p_size.y * 2, 0))
for i in range(self.panels_x):
j = 0
origin = Vector((p_size.x * (i + 0.5) - 0.5 * size.x + x1, bottom_z + p_size.y * j + x1, 0))
shape = 'RECTANGLE'
face.subdiv_y = 0
uvs += face.uv(curve_steps, center, origin, p_size, p_radius, 0, 0, 0, 0, path_type=shape)
if back is not None:
back.subdiv_y = 0
uvs += back.uv(curve_steps, center, origin, p_size, p_radius, 0, 0, 0, 0, path_type=shape)
j = 1
origin = Vector((p_size.x * (i + 0.5) - 0.5 * size.x + x1, bottom_z + p_size.y * j + x1, 0))
shape = path_type
face.subdiv_y = 1
uvs += face.uv(curve_steps, center, origin, p_size_2x, p_radius, 0, 0, 0, 0, path_type=path_type)
if back is not None:
back.subdiv_y = 1
uvs += back.uv(curve_steps, center, origin,
p_size_2x, p_radius, 0, 0, 0, 0, path_type=path_type)
return uvs
@property
def matids(self):
if self.panels_distrib == 'REGULAR':
subdiv_y = self.panels_y - 1
else:
subdiv_y = 2
path_type = 'RECTANGLE'
curve_steps = 16
side, face, back = self.panels
mat = side.mat(curve_steps, 1, 0, path_type=path_type)
if face is not None:
if self.panels_distrib == 'REGULAR':
for i in range(self.panels_x):
for j in range(self.panels_y):
if j < subdiv_y:
shape = 'RECTANGLE'
else:
shape = path_type
mat += face.mat(curve_steps, 1, 1, path_type=shape)
if back is not None:
mat += back.mat(curve_steps, 0, 0, path_type=shape)
else:
####################################
# Ratio vertical panels 1/3 - 2/3
####################################
for i in range(self.panels_x):
j = 0
shape = 'RECTANGLE'
face.subdiv_y = 0
mat += face.mat(curve_steps, 1, 1, path_type=shape)
if back is not None:
back.subdiv_y = 0
mat += back.mat(curve_steps, 0, 0, path_type=shape)
j = 1
shape = path_type
face.subdiv_y = 1
mat += face.mat(curve_steps, 1, 1, path_type=shape)
if back is not None:
back.subdiv_y = 1
mat += back.mat(curve_steps, 0, 0, path_type=shape)
return mat
def find_handle(self, o):
for child in o.children:
if 'archipack_handle' in child:
return child
return None
def update_handle(self, context, o):
handle = self.find_handle(o)
if handle is None:
m = bpy.data.meshes.new("Handle")
handle = create_handle(context, o, m)
verts, faces = door_handle_horizontal_01(self.direction, 1)
b_verts, b_faces = door_handle_horizontal_01(self.direction, 0, offset=len(verts))
b_verts = [(v[0], v[1] - self.y, v[2]) for v in b_verts]
handle_y = 0.07
handle.location = ((1 - self.direction * 2) * (self.x - handle_y), 0, 0.5 * self.z)
bmed.buildmesh(context, handle, verts + b_verts, faces + b_faces)
def remove_handle(self, context, o):
handle = self.find_handle(o)
self.delete_object(context, handle)
def update(self, context):
o = self.find_in_selection(context)
if o is None:
return
bmed.buildmesh(context, o, self.verts, self.faces, matids=self.matids, uvs=self.uvs, weld=True)
if self.handle == 'NONE':
self.remove_handle(context, o)
else:
self.update_handle(context, o)
self.restore_context(context)
class ARCHIPACK_PT_door_panel(Panel):
bl_idname = "ARCHIPACK_PT_door_panel"
bl_label = "Door"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
# bl_context = 'object'
bl_category = 'ArchiPack'
@classmethod
def poll(cls, context):
return archipack_door_panel.filter(context.active_object)
def draw(self, context):
layout = self.layout
layout.operator("archipack.select_parent")
# ------------------------------------------------------------------
# Define operator class to create object
# ------------------------------------------------------------------
class ARCHIPACK_OT_door_panel(Operator):
bl_idname = "archipack.door_panel"
bl_label = "Door model 1"
bl_description = "Door model 1"
bl_category = 'Archipack'
bl_options = {'REGISTER', 'UNDO'}
x = FloatProperty(
name='Width',
min=0.1,
default=0.80, precision=2,
unit='LENGTH', subtype='DISTANCE',
description='Width'
)
z = FloatProperty(
name='Height',
min=0.1,
default=2.0, precision=2,
unit='LENGTH', subtype='DISTANCE',
description='height'
)
y = FloatProperty(
name='Depth',
min=0.001,
default=0.02, precision=2,
unit='LENGTH', subtype='DISTANCE',
description='Depth'
)
direction = IntProperty(
name="Direction",
min=0,
max=1,
description="open direction"
)
model = IntProperty(
name="Model",
min=0,
max=3,
description="panel type"
)
chanfer = FloatProperty(
name='Bevel',
min=0.001,
default=0.005, precision=3,
unit='LENGTH', subtype='DISTANCE',
description='chanfer'
)
panel_spacing = FloatProperty(
name='Spacing',
min=0.001,
default=0.1, precision=2,
unit='LENGTH', subtype='DISTANCE',
description='distance between panels'
)
panel_bottom = FloatProperty(
name='Bottom',
min=0.0,
default=0.0, precision=2,
unit='LENGTH', subtype='DISTANCE',
description='distance from bottom'
)
panel_border = FloatProperty(
name='Border',
min=0.001,
default=0.2, precision=2,
unit='LENGTH', subtype='DISTANCE',
description='distance from border'
)
panels_x = IntProperty(
name="# h",
min=1,
max=50,
default=1,
description="panels h"
)
panels_y = IntProperty(
name="# v",
min=1,
max=50,
default=1,
description="panels v"
)
panels_distrib = EnumProperty(
name='Distribution',
items=(
('REGULAR', 'Regular', '', 0),
('ONE_THIRD', '1/3 2/3', '', 1)
),
default='REGULAR'
)
handle = EnumProperty(
name='Shape',
items=(
('NONE', 'No handle', '', 0),
('BOTH', 'Inside and outside', '', 1)
),
default='BOTH'
)
material = StringProperty(
default=""
)
def draw(self, context):
layout = self.layout
row = layout.row()
row.label("Use Properties panel (N) to define parms", icon='INFO')
def create(self, context):
"""
expose only basic params in operator
use object property for other params
"""
m = bpy.data.meshes.new("Panel")
o = bpy.data.objects.new("Panel", m)
d = m.archipack_door_panel.add()
d.x = self.x
d.y = self.y
d.z = self.z
d.model = self.model
d.direction = self.direction
d.chanfer = self.chanfer
d.panel_border = self.panel_border
d.panel_bottom = self.panel_bottom
d.panel_spacing = self.panel_spacing
d.panels_distrib = self.panels_distrib
d.panels_x = self.panels_x
d.panels_y = self.panels_y
d.handle = self.handle
context.scene.objects.link(o)
o.lock_location[0] = True
o.lock_location[1] = True
o.lock_location[2] = True
o.lock_rotation[0] = True
o.lock_rotation[1] = True
o.lock_scale[0] = True
o.lock_scale[1] = True
o.lock_scale[2] = True
o.select = True
context.scene.objects.active = o
m = o.archipack_material.add()
m.category = "door"
m.material = self.material
d.update(context)
# MaterialUtils.add_door_materials(o)
o.lock_rotation[0] = True
o.lock_rotation[1] = True
return o
def execute(self, context):
if context.mode == "OBJECT":
bpy.ops.object.select_all(action="DESELECT")
o = self.create(context)
o.select = True
context.scene.objects.active = o
return {'FINISHED'}
else:
self.report({'WARNING'}, "Archipack: Option only valid in Object mode")
return {'CANCELLED'}
class ARCHIPACK_OT_select_parent(Operator):
bl_idname = "archipack.select_parent"
bl_label = "Edit parameters"
bl_description = "Edit parameters located on parent"
bl_category = 'Archipack'
bl_options = {'REGISTER', 'UNDO'}
def draw(self, context):
layout = self.layout
row = layout.row()
row.label("Use Properties panel (N) to define parms", icon='INFO')
def execute(self, context):
if context.mode == "OBJECT":
if context.active_object is not None and context.active_object.parent is not None:
bpy.ops.object.select_all(action="DESELECT")
context.active_object.parent.select = True
context.scene.objects.active = context.active_object.parent
return {'FINISHED'}
else:
self.report({'WARNING'}, "Archipack: Option only valid in Object mode")
return {'CANCELLED'}
class archipack_door(ArchipackObject, Manipulable, DimensionProvider, PropertyGroup):
"""
The frame is the door main object
parent parametric object
create/remove/update her own childs
"""
x = FloatProperty(
name='Width',
min=0.25,
default=100.0, precision=2, step=1,
unit='LENGTH', subtype='DISTANCE',
description='Width', update=update,
)
y = FloatProperty(
name='Depth',
min=0.1,
default=0.20, precision=2, step=1,
unit='LENGTH', subtype='DISTANCE',
description='Depth', update=update,
)
z = FloatProperty(
name='Height',
min=0.1,
default=2.0, precision=2, step=1,
unit='LENGTH', subtype='DISTANCE',
description='height', update=update,
)
frame_x = FloatProperty(
name='Width',
min=0,
default=0.1, precision=2, step=1,
unit='LENGTH', subtype='DISTANCE',
description='frame width', update=update,
)
frame_y = FloatProperty(
name='Depth',
default=0.03, precision=2, step=1,
unit='LENGTH', subtype='DISTANCE',
description='frame depth', update=update,
)
direction = IntProperty(
name="Direction",
min=0,
max=1,
description="open direction", update=update,
)
door_y = FloatProperty(
name='Depth',
min=0.001,
default=0.02, precision=2, step=1,
unit='LENGTH', subtype='DISTANCE',
description='depth', update=update,
)
door_offset = FloatProperty(
name='Offset',
min=0,
default=0, precision=2, step=1,
unit='LENGTH', subtype='DISTANCE',
description='offset', update=update,
)
model = IntProperty(
name="Model",
min=0,
max=3,
default=0,
description="Model", update=update,
)
n_panels = IntProperty(
name="Panels",
min=1,
max=2,
default=1,
description="number of panels", update=update
)
chanfer = FloatProperty(
name='Bevel',
min=0.001,
default=0.005, precision=3, step=0.01,
unit='LENGTH', subtype='DISTANCE',
description='chanfer', update=update_childs,
)
panel_spacing = FloatProperty(
name='Spacing',
min=0.001,
default=0.1, precision=2, step=1,
unit='LENGTH', subtype='DISTANCE',
description='distance between panels', update=update_childs,
)
panel_bottom = FloatProperty(
name='Bottom',
min=0.0,
default=0.0, precision=2, step=1,
unit='LENGTH', subtype='DISTANCE',
description='distance from bottom', update=update_childs,
)
panel_border = FloatProperty(
name='Border',
min=0.001,
default=0.2, precision=2, step=1,
unit='LENGTH', subtype='DISTANCE',
description='distance from border', update=update_childs,
)
panels_x = IntProperty(
name="# h",
min=1,
max=50,
default=1,
description="panels h", update=update_childs,
)
panels_y = IntProperty(
name="# v",
min=1,
max=50,
default=1,
description="panels v", update=update_childs,
)
panels_distrib = EnumProperty(
name='Distribution',
items=(
('REGULAR', 'Regular', '', 0),
('ONE_THIRD', '1/3 2/3', '', 1)
),
default='REGULAR', update=update_childs,
)
handle = EnumProperty(
name='Handle',
items=(
('NONE', 'No handle', '', 0),
('BOTH', 'Inside and outside', '', 1)
),
default='BOTH', update=update_childs,
)
hole_margin = FloatProperty(
name='Hole margin',
min=0.0,
default=0.1, precision=2, step=1,
unit='LENGTH', subtype='DISTANCE',
description='how much hole surround wall'
)
flip = BoolProperty(
default=False,
update=update,
description='flip outside and outside material of hole'
)
z_offset = FloatProperty(
name="Hole depth z",
unit='LENGTH', subtype='DISTANCE',
description='Depth of hole under the door',
default=0.1, precision=2, step=1,
update=update
)
auto_update = BoolProperty(
options={'SKIP_SAVE'},
default=True,
update=update
)
@property
def frame(self):
x0 = 0
x1 = -BATTUE
x2 = -self.frame_x
y0 = max(0.25 * self.door_y + 0.0005, self.y / 2 + self.frame_y)
y1 = max(y0 - 0.5 * self.door_y - self.door_offset, -y0 + 0.001)
y2 = -y0
y3 = 0
if self.frame_y > 0:
# when frame_y > 0
# the shape of frame change
# _____ y0
# |___ |_ y1
# | | y5
# x x | y3
# ___| | y4
# |_______| y2
#
# x2 x3 x1 x0
y4 = y2 + self.frame_y
y5 = y0 - self.frame_y
x3 = x0 - self.frame_y
return DoorPanel(
True, # closed
[0, 0, 3, 3, 0, 0, 1, 1, 2, 2], # x index
[x2, x1, x0, x3],
[y2, y4, y4, y5, y5, y0, y0, y1, y1, y2],
[0, 0, 1, 1, 1, 1, 1, 1, 0, 0], # material index
closed_path=False
)
else:
# Frames inside wall
#
# _____ y0
# | |___ y1
# x | y3
# | |