-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstud.py
More file actions
235 lines (199 loc) · 10.4 KB
/
stud.py
File metadata and controls
235 lines (199 loc) · 10.4 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
import FreeCAD,FreeCADGui,Part, Draft
import os, math
import framing
__title__="FreeCAD Framing"
__author__ = "Paul C. Randall"
__url__ = "http://www.freecad.info"
__command_name__ = "Stud"
__command_group__ = "Members"
def makeStud(name):
newstud = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", name )
Stud(newstud)
ViewProviderStud(newstud.ViewObject)
# newstud.Placement = FreeCAD.Placement( FreeCAD.Vector (38.1, 88.89, 0.0),FreeCAD.Rotation (0.0, 0.0, 0, 0) )
FreeCAD.ActiveDocument.recompute()
return newstud
class Stud_Command:
"""
The Stud_Command class integrates the stud object into the FreeCAD Workbench, StickFrame
It is pre-positioned to sit at the end of a stud plate.
"""
def GetResources(self):
icon_path = framing.getIconImage( "stud" )
return {"MenuText": "Stud",
"ToolTip": "Add a Stud to the Construction",
'Pixmap': str(icon_path)}
def IsActive(self):
if FreeCAD.ActiveDocument == None:
return False
else:
return True
def Activated(self):
newstud = FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Stud")
Stud(newstud)
framing.defaultAttachment( newstud )
# if framing.isItemSelected():
# selection = FreeCADGui.Selection.getSelectionEx()
# obj = selection[0].SubElementNames
# edge_name = obj[0]
# #One Edge
# 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 ):
# #FreeCAD.ActiveDocument.getObject(newstud.Name).Length = edge_elt.Length
# FreeCAD.ActiveDocument.getObject(newstud.Name).Support = [(edge_obj,'Vertex1'),(edge_obj,edge_name)]
# FreeCAD.ActiveDocument.getObject(newstud.Name).MapMode = 'OXY'
# if isinstance( edge_shp, Part.Compound ):
# #FreeCAD.ActiveDocument.getObject(newplate.Name).Length = edge_elt.Length
# FreeCAD.ActiveDocument.getObject(newstud.Name).Support = [(edge_obj,'Vertex1'),(edge_obj,edge_name)]
# FreeCAD.ActiveDocument.getObject(newstud.Name).MapMode = 'OXY'
# newstud.Placement = FreeCAD.Placement( FreeCAD.Vector (38.1, 88.89, 0.0),FreeCAD.Rotation (0.0, 0.0, 0, 1) )
newstud.Placement = FreeCAD.Placement( FreeCAD.Vector (38.1,0,38.1),FreeCAD.Rotation (0.0,0.0, 1, 0) )
# newstud.Placement = FreeCAD.Placement( FreeCAD.Vector (0,0,0),FreeCAD.Rotation (0.0,0.0, 1, 0) )
ViewProviderStud(newstud.ViewObject)
FreeCAD.ActiveDocument.recompute()
FreeCADGui.SendMsgToActiveView("ViewFit")
FreeCADGui.activeDocument().activeView().viewIsometric()
class Stud():
"""
The Stud Class defines the graphical representation of the object and the underlying Shape.
"""
Placement = FreeCAD.Placement
def __init__(self, obj):
precuts = ['92.25 in', '92.625 in', '93 in','96 in', '104.625 in', '116.625 in']
centers = ['15.25 in', '16 in', '18 in', '24 in']
obj.addProperty("App::PropertyLength","Length","Lumber Dimension","The board foot length ( cut length ) dimension").Length = "92.625 in"
obj.addProperty("App::PropertyLength","Width","Lumber Dimension","Lumber Edge Dimension").Width="1.5 in"
obj.addProperty("App::PropertyLength","Height","Lumber Dimension", "Lumber Face Dimension").Height="3.5 in"
obj.addProperty("App::PropertyLength","Centers","Construction Dimensison", "Lumber Face Dimension").Centers="16 in"
obj.addProperty("App::PropertyFloat", "Cost", "Member","Enter the cost of the construction member").Cost = 2.99
obj.addProperty("App::PropertyEnumeration", "Function", "Member", "Where this member is being used").Function = ['Corner', 'Wall', 'Nailer', 'King Stud', 'Jack Stud', 'Cripple Stud']
obj.addProperty("App::PropertyString", "MemberName", "Member","Where this member is being used").MemberName = "Stud"
obj.Proxy = self
obj.addExtension('Part::AttachExtensionPython' )
def onChanged(self, fp, prop):
if prop == "Length" or prop == "Width" or prop == "Height": #and prop > 0:
FreeCAD.ActiveDocument.recompute()
if prop == "Function":
if fp.Function == "Corner":
pass
if fp.Function == "Nailer":
pass
def execute(self,fp):
fp.Shape = Part.makeBox(fp.Length,fp.Height,fp.Width, FreeCAD.Vector(0,0,0),FreeCAD.Vector(1,0,0 ) )
fp.positionBySupport()
class ViewProviderStud:
def __init__(self, obj):
''' Set this object to the proxy object of the actual view provider '''
obj.Proxy = self
def attach(self, obj):
''' Setup the scene sub-graph of the view provider, this method is mandatory '''
return
def updateData(self, fp, prop):
''' If a property of the handled feature has changed we have the chance to handle this here '''
return
def getDisplayModes(self,obj):
''' Return a list of display modes. '''
modes=[]
return modes
def getDefaultDisplayMode(self):
''' Return the name of the default display mode. It must be defined in getDisplayModes. '''
return "Lines"
def setDisplayMode(self,mode):
''' Map the display mode defined in attach with those defined in getDisplayModes.
Since they have the same names nothing needs to be done. This method is optional.
'''
return mode
def onChanged(self, vp, prop):
''' Print the name of the property that has changed '''
pass
def getIcon(self):
''' Return the icon in XMP format which will appear in the tree view. This method is optional
and if not defined a default icon is shown.
'''
return """
/* XPM */
static char * stud_icon_xpm[] = {
"64 64 4 1",
" c #FFFFFF",
". c #000000",
"+ c #E1B313",
"@ c #363636",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ........ ",
" .++++++.. ",
" ..++++++.+. ",
" .+++++++.++. ",
" .++++++..+++. ",
" ..++++++.+++++. ",
" .......@.++++++. ",
" .++++++.+++++++. ",
" .++++++.+++++++. ",
" .++++++.+++++++. ",
" .++++++.+++++++. ",
" .++++++.+++++++. ",
" .++++++.+++++++. ",
" .++++++.+++++++. ",
" .++++++.+++++++. ",
" .++++++.+++++++. ",
" .++++++.+++++++. ",
" .++++++.+++++++. ",
" .++++++.+++++++. ",
" .++++++.+++++++. ",
" .++++++.+++++++. ",
" .++++++.+++++++. ",
" .++++++.+++++++. ",
" .++++++.+++++++. ",
" .++++++.+++++++. ",
" .++++++.+++++++. ",
" .++++++.+++++++. ",
" .++++++.+++++++. ",
" .++++++.+++++++. ",
" .++++++.+++++++. ",
" .++++++.+++++++. ",
" .++++++.+++++++. ",
" .++++++.+++++++. ",
" .++++++.+++++++. ",
" .++++++.+++++++. ",
" .++++++.+++++++. ",
" .++++++.+++++++. ",
" .++++++.+++++++. ",
" .++++++.+++++++. ",
" .++++++.+++++++. ",
" .++++++.+++++++. ",
" .++++++.+++++++. ",
" .++++++.+++++++. ",
" .++++++.+++++++. ",
" .++++++.++++++. ",
" .++++++.+++++. ",
" .++++++.++++. ",
" .++++++.+++. ",
" .++++++.++. ",
" .++++++.+. ",
" .++++++.. ",
" ........ ",
" ",
" ",
" ",
" "};
"""
def __getstate__(self):
''' When saving the document this object gets stored using Python's cPickle module.
Since we have some un-pickable here -- the Coin stuff -- we must define this method
to return a tuple of all pickable objects or None.
'''
return None
def __setstate__(self,state):
''' When restoring the pickled object from document we have the chance to set some
internals here. Since no data were pickled nothing needs to be done here.
'''
return None
FreeCADGui.addCommand('Stud', Stud_Command())