-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathframing.py
More file actions
386 lines (260 loc) · 9.39 KB
/
framing.py
File metadata and controls
386 lines (260 loc) · 9.39 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
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
import math
import FreeCAD
import FreeCADGui
import Draft
import Part
import plate
import os
import stud
# def makeStud(name):
# newstud = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", name )
# Stud(newstud)
# ViewProviderStud(newstud.ViewObject)
# return newstud
mod_name = "stickframe"
def makePlate(name):
newplate = plate.Plate_Command()
return newplate
def makeFloorJoist(name):
pass
def makeCeilingJoist(name):
pass
def makeRafter(name):
pass
def makeFloorPanel(name):
pass
################################
## Intermediate Constructions ##
################################
def bottomWallPlates(selectedline):
starterplate = self.makePlate("BottomPlate")
# totalplates = math.ceil ( selectedline.length/starterplate.length )
# lastplatelength = selectedline.length % starterplate.length
starterplate.Placement.Base = selectedLine.Start
starterplate.Placement.Rotation = getLineAngle(selectedLine)
pass
def topWallPlates(selectedLine):
pass
def startingStudCorner(selectedLine):
pass
def endingStudCorner(selectedLine):
pass
def nailers():
pass
def fillerStuds():
pass
def populateStuds( sketchinstance, studtype ):
print ( sketchinstance.Name )
print ( studtype )
sketch_name = FreeCAD.ActiveDocument.getObject( sketchinstance.Name )
edges = sketchinstance.Shape.Edges
print ( edges )
points = []
studs = []
for vertex in sketchinstance.Shape.Vertexes:
points.append(vertex.Point)
for edge in edges:
newstud = stud.makeStud( studtype )
newstud.Length = edge.Length
idx = edges.index(edge) + 1
if ( edge.Vertexes[0].Point in points ):
# print ( edge.Vertexes[0].Point )
# print (points.index( edge.Vertexes[0].Point ) )
vert1 = "Vertex" + str ( points.index( edge.Vertexes[0].Point ) + 1 )
vert2 = "Vertex" + str ( points.index( edge.Vertexes[1].Point ) + 1 )
#print ("========")
#print ( edge.Vertexes[0].Point )
#print ( edge.Vertexes[1].Point )
#print ( "-------" )
fvert = edge.firstVertex().Point
lvert = edge.lastVertex().Point
# if ( (fvert.x > lvert.x) or (fvert.y > lvert.y) ):
#
# print ("Inverted mapping")
# newstud.Support = [(sketch_instance,vert2),(sketch_instance,vert1)]
# else:
newstud.Support = [(sketchinstance,vert1),(sketchinstance,vert2)]
expression = sketchinstance.Name + ".Shape.Edge" + str(idx) + ".Length"
newstud.setExpression( 'Length', expression)
# reversed line fix ???
if ( idx == 0 ):
cut_truss = FreeCAD.ActiveDocument.addObject("Part::Chamfer","cut_truss")
cut_truss.Base = newstud
ridge_angle = newstud.Shape.Face1.Placement.Rotation.toEuler()[2]
#
edgeAngle = degrees ( vert1.Point.getAngle ( vert2.Point ) )
a = 3.5
A = 180 - ridge_angle
B = 90
C = 180 - A - B
b = a·sin(B)/sin(A)
c = a·sin(C)/sin(A)
__fillets__ = []
__fillets__.append((3,b,c))
cut_truss.Edges = __fillets__
newcollar.Shape = collar
# if ( idx == 1 ):
#offset center post
# newstud.AttachmentOffset = FreeCAD.Placement(FreeCAD.Vector(0,44.45,0),FreeCAD.Rotation(FreeCAD.Vector(0,0,1),0))
# if( idx == 2 ) :
# pass
newstud.MapMode = 'OZX'
studs.append( newstud )
return studs
################################
## Utility methods ###
################################
def isItemSelected():
selection = FreeCADGui.Selection.getSelectionEx()
if selection:
return True
return False
def getIconImage( toolname ):
# image_path = "/" + framing.mod_name + '/icons/stud.png'
image_path = '/stickframe/icons/' + toolname + ".png"
global_path = FreeCAD.getHomePath()+"Mod"
user_path = FreeCAD.getUserAppDataDir()+"Mod"
icon_path = ""
if os.path.exists(user_path + image_path):
icon_path = user_path + image_path
elif os.path.exists(global_path + image_path):
icon_path = global_path + image_path
return icon_path
def defaultAttachment( framing_member ):
if isItemSelected():
selection = FreeCADGui.Selection.getSelectionEx()
obj = selection[0].SubElementNames
edge_name = obj[0]
edge_obj = FreeCADGui.Selection.getSelection()[0]
edge_shp = FreeCADGui.Selection.getSelection()[0].Shape
edge_elt = FreeCADGui.Selection.getSelection ()[0].Shape.Edge1
if isinstance( edge_shp, Part.Wire ):
#Check if a single edge
print ( "number of edges = " + str(edge_shp.Edges.__len__() ) )
if edge_shp.Edges.__len__() == 1:
print( "Adding single item to single edge")
framing_member.Length = edge_elt.Length
FreeCAD.ActiveDocument.getObject(framing_member.Name).Support = [(edge_obj,'Vertex1'),(edge_obj,edge_name)]
FreeCAD.ActiveDocument.getObject(framing_member.Name).MapMode = 'OXY'
print("item selected part.wire:", obj[0] )
if edge_shp.Edges.__len__() > 1:
print( "Multiple edges found")
return False
return True
#def multiEdgeAttachments( primary_framing_member, secondary_framing_member ):
#need to add a generic make for each framing member, os on odd even can just call add() or make()
# or can I construct a call using a string like - make +"Wall" + "()"
print ( primary_framing_member )
# pri_module_ = __import__( primary_framing_member )
#sec_module_ = __import__( secondary_framing_member )
# pri_instance = pri_module_
# pri_class_ = getattr( pri_instance, "Wall_Command" )
# pri_class_.Activated( pri_instance )
print( "Adding walls to all edges" )
if isItemSelected():
selection = FreeCADGui.Selection.getSelectionEx()
obj = selection[0].SubElementNames
edge_name = obj[0]
edge_obj = FreeCADGui.Selection.getSelection()[0]
edge_shp = FreeCADGui.Selection.getSelection()[0].Shape
edge_count = edge_shp.Edges.__len__()
for edge in edge_shp.Edges:
#edge_name = "Edge" + str(edge_shp.Edges.index(edge) + 1 )
edge_name = "Edge1"
#GET THIS EDGES VERTEX MAPPED TO SHAP VERTEXES.
if isinstance( edge_shp, Part.Wire ):
if edge_count > 1 and math.fmod ( edge_count,2) == 0:
#add wall
newwall = wall.makeWall()
#attach wall to cirrent edge
vert1name, vert2name = matchVertexes( edge_shp, edge )
FreeCAD.ActiveDocument.getObject(newwall.Name).Support = [(edge,vert1name),(edge,edge_name)]
FreeCAD.ActiveDocument.getObject(partobj.Name).MapMode = 'OXY'
if edge_count > 1 and math.fmod ( edge_count,2) == 1:
#add simple wall
newwall = simplewall.makeSimpleWall()
#attach wall to current edge
vert1name, vert2name = matchVertexes( edge_shp, edge )
FreeCAD.ActiveDocument.getObject(newwall.Name).Support = [(edge,vert1name),(edge,edge_name)]
FreeCAD.ActiveDocument.getObject(partobj.Name).MapMode = 'OXY'
def matchVertexes( shape, edge ):
points = []
for vertex in shape.Vertexes:
points.append(vertex.Point)
fvert = edge.Vertexes[0].Point
lvert = edge.Vertexes[1].Point
if ( edge.Vertexes[0].Point in points ):
point1name = "Vertex" + str( points.index(fvert) + 1 )
if ( edge.Vertexes[1].Point in points ):
point2name = "Vertex" + str( points.index(lvert) + 1 )
return point1name,point2name
def getSelectedObject():
# selection = FreeCADGui.Selection.getSelectionEx()
selection = FreeCADGui.Selection.getSelection()
# object = selection[0].Object
object = selection[0]
return object
def getSelectedElement():
selection = FreeCADGui.Selection.getSelectionEx()
element = selection[0].SubObjects[0]
return element
def getSelectedPlacement():
selection = FreeCADGui.Selection.getSelectionEx()
object = selection[0]
selectedPlacement = object.Placement
return selectedPlacement
def getSelectedDirection():
pass
def getFaceDirection(selectedPlane, drawpointer=False):
"""
Given a Face make a line, return a vector with the direction.
"""
com = selectedPlane.CenterOfMass
# find the surface u,v parameter of a point on the surface edge
# using the CenterOfMass of the face
u, v = selectedPlane.Surface.parameter(com)
normal = selectedPlane.normalAt(u, v) # use u,v to find normal vector
x1 = selectedPlane.CenterOfMass
normal.multiply(100)
x2 = x1 + normal
if drawpointer:
myline = Draft.makeLine(x1, x2)
myline.ViewObject.EndArrow = True
myline.ViewObject.ArrowType = "Arrow"
myline.ViewObject.ArrowSize = ".5 in"
# add a line with an arrow to indicate direction
return normal.normalize()
def getLineAngle(selectedline):
"""
Given a line return a rotatation.
"""
print(selectedline.Name)
print(selectedline.Placement)
verts = selectedline.Shape.Vertexes
point1 = verts[0]
point2 = verts[1]
Y1 = point1.Y
Y2 = point2.Y
X1 = point1.X
X2 = point2.X
slope = (Y2-Y1) / (X2-X1)
radians = math.atan2(Y2-Y1, X2-X1)
angle = math.degrees(radians)
# print "\t", Y2, " - ", Y1
# print "M =\t ----------"
# print "\t", X2, " - ", X1
# print "\n"
# print "Slope: ", slope
# print "Angle in Radians: ", radians
print("Angle in Degrees: ", angle)
axis = selectedline.Placement.Base
rotation = FreeCAD.Rotation(FreeCAD.Vector(0, 0, 1), angle)
# print rotation
return rotation
class _ViewProviderFraming():
def __init__(self, vobj, icon='/icons/studwallnailer.png'):
self.iconpath = __dir__ + icon
self.Object = vobj.Object
vobj.Proxy = self
def getIcon(self):
return self.iconpath