-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathjoin.py
More file actions
302 lines (265 loc) · 15.7 KB
/
Copy pathjoin.py
File metadata and controls
302 lines (265 loc) · 15.7 KB
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# ***************************************************************************
# * *
# * Copyright (c) 2016 execuc *
# * *
# * This file is part of LCInterlocking module. *
# * LCInterlocking module is free software; you can redistribute it and/or*
# * modify it under the terms of the GNU Lesser General Public *
# * License as published by the Free Software Foundation; either *
# * version 2.1 of the License, or (at your option) any later version. *
# * *
# * This module 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 *
# * Lesser General Public License for more details. *
# * *
# * You should have received a copy of the GNU Lesser General Public *
# * License along with this library; if not, write to the Free Software *
# * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, *
# * MA 02110-1301 USA *
# * *
# ***************************************************************************
import Part
import FreeCAD
from panel.tab import TabProperties
import lasercut.flextab as flextab
import lasercut.helper as helper
def get_slot_positions(tab_properties):
slots_list = []
interval_length = tab_properties.y_length / float(tab_properties.tabs_number)
half_tab_number = int(float(tab_properties.tabs_number) / 2.0)
if tab_properties.tabs_number % 2 == 1:
slots_list.append(0.0 + tab_properties.tabs_shift)
for i in range(half_tab_number):
left = float(i+1) * interval_length * tab_properties.interval_ratio
right = float(-i-1) * interval_length * tab_properties.interval_ratio
if tab_properties.interval_ratio != 1.0:
left *= tab_properties.interval_ratio
right *= tab_properties.interval_ratio
slots_list.append(left + tab_properties.tabs_shift)
slots_list.append(right + tab_properties.tabs_shift)
else:
for i in range(half_tab_number):
left = float(i) * interval_length + interval_length / 2.0
right = float(-i) * interval_length - interval_length / 2.0
if tab_properties.interval_ratio != 1.0:
left *= tab_properties.interval_ratio
right *= tab_properties.interval_ratio
slots_list.append(left + tab_properties.tabs_shift)
slots_list.append(right + tab_properties.tabs_shift)
# if tab_properties.y_invert:
# invert_list = []
# for slot in slots_list:
# invert_list.append(-slot)
# slots_list = invert_list
return slots_list
def screw_way_on_plane(material_plane, screw_nut_spec, pos_y):
# horizontal hole
radius = (screw_nut_spec.screw_diameter * 1.2 - material_plane.laser_beam_diameter) / 2.0
cylinder = Part.makeCylinder(radius, material_plane.thickness, FreeCAD.Vector(0, 0, -material_plane.thickness / 2.))
cylinder.rotate(FreeCAD.Vector(0, 0, 0), FreeCAD.Vector(0, 1, 0), 90)
cylinder.translate(FreeCAD.Vector(material_plane.thickness / 2.0, pos_y, 0.))
return cylinder
def screw_way_on_face(material_face, material_plane, screw_nut_spec, pos_y, dog_bone=False):
# horizontal hole
vert_corrected_length = screw_nut_spec.screw_length - material_plane.thickness \
+ material_plane.thickness_tolerance + screw_nut_spec.screw_length_tol
corrected_width = screw_nut_spec.screw_diameter * 1.2 - material_face.laser_beam_diameter
corrected_height = material_face.thickness # + materialFace.tolerance
screw_hole = Part.makeBox(vert_corrected_length, corrected_width, corrected_height,
FreeCAD.Vector(0.,
-corrected_width / 2.0, -corrected_height / 2.0))
if dog_bone:
screw_hole = helper.make_dog_bone_on_limits_on_xy(screw_hole, corrected_height, True)
x_pos = -vert_corrected_length
screw_hole.translate(FreeCAD.Vector(x_pos, pos_y, 0))
# Nut hole
corrected_length = screw_nut_spec.nut_height - material_face.laser_beam_diameter + 0.1
corrected_width = screw_nut_spec.nut_flat_flat - material_face.laser_beam_diameter + 0.1
nut_hole = Part.makeBox(corrected_length, corrected_width, corrected_height,
FreeCAD.Vector(0,
-corrected_width / 2.0, -corrected_height / 2.0))
x_pos = -vert_corrected_length + screw_nut_spec.nut_height + screw_nut_spec.screw_length_tol
nut_hole.translate(FreeCAD.Vector(x_pos, pos_y, 0))
if dog_bone:
nut_hole = helper.make_dog_bone_on_limits_on_xy(nut_hole, corrected_height)
hole = screw_hole.fuse(nut_hole)
return hole
# X (Length)
# |
# |
# |
# |Z (Height)
# ---------------------------> Y (Width)
# X est vers le haut
# Y est aligné sur la face
# Z est devant la camera
def tab_join_create_tab_on_face(material_face, material_plane, width, pos_y, tab_face, dog_bone=False):
y_plus_inside, y_minus_inside = helper.check_limit_y_on_for_tab(tab_face, material_face.thickness, pos_y, width,
material_plane.thickness, material_face)
# X Rien pr l'instant, mais on peut prendre en compte l'epaiseur variante de la piece opposé => length
# Y Ajout d'un Kerf => width
# Z Rien => height
corrected_length = material_plane.thickness
# corrected_width = width + materialFace.laser_beam_diameter
corrected_height = material_face.thickness
corrected_width = width # - materialPlane.laser_beam_diameter
corrected_width_center = corrected_width / 2.0
if y_minus_inside and y_plus_inside:
corrected_width += material_face.laser_beam_diameter
corrected_width_center = corrected_width / 2.0
elif y_minus_inside:
corrected_width += material_face.laser_beam_diameter / 2.0
corrected_width_center = (corrected_width + material_face.laser_beam_diameter / 2.0) / 2.0
elif y_plus_inside:
corrected_width += material_face.laser_beam_diameter / 2.0
corrected_width_center = (corrected_width - material_face.laser_beam_diameter / 2.0) / 2.0
#origin = FreeCAD.Vector(-corrected_length / 2.0, -corrected_width_center, -corrected_height / 2.0)
origin = FreeCAD.Vector(0., -corrected_width_center, -corrected_height / 2.0)
tab = Part.makeBox(corrected_length, corrected_width, corrected_height, origin)
tab.translate(FreeCAD.Vector(0, pos_y, 0))
hole = None
left_hole = None
right_hole = None
if dog_bone:
radius = min(corrected_width, corrected_length) * 2 / 30.
if y_minus_inside:
left_hole = Part.makeCylinder(radius, corrected_height,
FreeCAD.Vector(0, -corrected_width_center + pos_y, -corrected_height / 2.0),
FreeCAD.Vector(0, 0, 1.))
if y_plus_inside:
right_hole = Part.makeCylinder(radius, corrected_height,
FreeCAD.Vector(0, -corrected_width_center + corrected_width + pos_y,
-corrected_height / 2.0),
FreeCAD.Vector(0, 0, 1.))
hole = left_hole
if hole and right_hole:
hole = hole.fuse(right_hole)
elif right_hole:
hole = right_hole
return tab, hole
def make_tab_join(tab, tab_part, other_parts):
slots_pos = get_slot_positions(tab)
did_any_work = False
for i, y in enumerate(slots_pos):
for part_interactor in other_parts:
tab_to_add, tab_dog_bone = tab_join_create_tab_on_face(tab_part.properties, part_interactor.properties,
tab.tabs_width, y, tab, tab.tab_dog_bone)
intersect_test, tab_to_add_transformed = helper.check_intersect(tab_to_add, tab,
part_interactor.properties)
if intersect_test:
did_any_work = True
tab_part.toAdd.append(tab_to_add_transformed)
if tab_dog_bone:
tab_part.toRemove.append(helper.transform_part(tab_dog_bone, tab))
hole = helper.tab_join_create_hole_on_plane(tab, tab.tabs_width, y, tab_part.properties,
part_interactor.properties, tab.dog_bone)
part_interactor.toRemove.append(helper.transform_part(hole, tab))
break
if not did_any_work:
FreeCAD.Console.PrintWarning("Tab on part " + tab_part.get_name() + " did not apply\n")
return
def make_continuous_tab_joins(tab, tab_part, other_parts):
tabs_number = int(tab.tabs_number - 1)
virtual_tab_length = float(tab.y_length / float(int(tabs_number + 1)))
y_pos = - tab.y_length / 2.0
for tab_id in range(int(tabs_number + 1)):
y_pos_center = y_pos + virtual_tab_length / 2.0
# if tab.y_invert:
# y_pos_center = - y_pos_center
left_kerf = False if tab_id == 0 else True
right_kerf = False if tab_id == tabs_number else True
if tab_id % 2 == 0:
for part_interactor in other_parts:
tab_to_add, tab_dog_bone = tab_join_create_tab_on_face(tab_part.properties, part_interactor.properties,
virtual_tab_length, y_pos_center, tab,
tab.tab_dog_bone)
intersect_test, tab_to_add_transformed = helper.check_intersect(tab_to_add, tab,
part_interactor.properties)
if intersect_test:
tab_part.toAdd.append(tab_to_add_transformed)
if tab_dog_bone:
tab_part.toRemove.append(helper.transform_part(tab_dog_bone, tab))
hole = helper.tab_join_create_hole_on_plane(tab, virtual_tab_length, y_pos_center,
tab_part.properties, part_interactor.properties,
tab.dog_bone)
part_interactor.toRemove.append(helper.transform_part(hole, tab))
break
y_pos += virtual_tab_length
return
def make_tslot_tab_join(tab, tab_part, other_parts):
half_tab_distance = (tab.screw_diameter * tab.half_tab_ratio) + tab.tabs_width / 2.0
screw_nut_spec = helper.get_screw_nut_spec(tab.screw_diameter, tab.screw_length)
screw_nut_spec.screw_length_tol = tab.screw_length_tol
slots_pos = get_slot_positions(tab)
for i, y in enumerate(slots_pos):
for part_interactor in other_parts:
left_tab_to_add, left_tab_dog_bone = tab_join_create_tab_on_face(tab_part.properties,
part_interactor.properties,
tab.tabs_width, y - half_tab_distance,
tab, tab.tab_dog_bone)
right_tab_to_add, right_tab_dog_bone = tab_join_create_tab_on_face(tab_part.properties,
part_interactor.properties,
tab.tabs_width, y + half_tab_distance,
tab, tab.tab_dog_bone)
right_intersect_test, right_tab_to_add_transformed = helper.check_intersect(right_tab_to_add, tab,
part_interactor.properties)
left_intersect_test, left_tab_to_add_transformed = helper.check_intersect(left_tab_to_add, tab,
part_interactor.properties)
if right_intersect_test or left_intersect_test:
tab_part.toAdd.append(left_tab_to_add_transformed)
tab_part.toAdd.append(right_tab_to_add_transformed)
if left_tab_dog_bone:
tab_part.toRemove.append(helper.transform_part(left_tab_dog_bone, tab))
if right_tab_dog_bone:
tab_part.toRemove.append(helper.transform_part(right_tab_dog_bone, tab))
left_hole = helper.tab_join_create_hole_on_plane(tab, tab.tabs_width, y - half_tab_distance,
tab_part.properties, part_interactor.properties,
tab.dog_bone)
right_hole = helper.tab_join_create_hole_on_plane(tab, tab.tabs_width, y + half_tab_distance,
tab_part.properties, part_interactor.properties,
tab.dog_bone)
part_interactor.toRemove.append(helper.transform_part(left_hole, tab))
part_interactor.toRemove.append(helper.transform_part(right_hole, tab))
screw_way_hole_face = screw_way_on_face(tab_part.properties, part_interactor.properties,
screw_nut_spec, y, tab.dog_bone)
screw_way_hole_plane = screw_way_on_plane(part_interactor.properties, screw_nut_spec, y)
tab_part.toRemove.append(helper.transform_part(screw_way_hole_face, tab))
part_interactor.toRemove.append(helper.transform_part(screw_way_hole_plane, tab))
break
return
def make_tabs_joins(parts, tabs):
parts_element = []
for part in parts:
mat_element = helper.MaterialElement(part)
parts_element.append(mat_element)
removeParts = {}
#test to improve speed
for tab in tabs:
keyid = str(tab.group_id)
if keyid not in removeParts:
removeParts[keyid] = []
removeParts[keyid].append(tab.freecad_object.Name)
for tab in tabs:
tab_part = None
other_parts = []
keyid = str(tab.group_id)
for part in parts_element:
if part.get_name() == tab.freecad_object.Name:
tab_part = part
# else:
elif part.get_name() not in removeParts[keyid]:
other_parts.append(part)
if tab.tab_type == TabProperties.TYPE_TAB:
make_tab_join(tab, tab_part, other_parts)
elif tab.tab_type == TabProperties.TYPE_T_SLOT:
make_tslot_tab_join(tab, tab_part, other_parts)
elif tab.tab_type == TabProperties.TYPE_CONTINUOUS:
make_continuous_tab_joins(tab, tab_part, other_parts)
elif tab.tab_type == TabProperties.TYPE_FLEX:
flextab.make_flex_tab_join(tab, tab_part, other_parts)
else:
raise ValueError("Unknown tab type")
return parts_element