-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommands.py
305 lines (249 loc) · 10.5 KB
/
commands.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
"""commands used in Cables workbench
"""
import os
import FreeCAD
import FreeCADGui
from FreeCAD import Gui
import Part
import wireutils
import archCable
import archCableBox
import archCableConnector
import archCableLightPoint
import wireFlex
import cableProfile
import cableMaterial
import cableHelper
_dir = os.path.dirname(__file__)
iconPath = os.path.join(_dir, "Resources/icons")
CMD_NEW_WIRE_ICON = os.path.join(iconPath, "cmdNewWire.svg")
CMD_ADD_VERTEX_ICON = os.path.join(iconPath, "cmdAddVertex.svg")
CMD_DEL_VERTEX_ICON = os.path.join(iconPath, "cmdDelVertex.svg")
CMD_ATT_VERTEX_ICON = os.path.join(iconPath, "cmdAttVertex.svg")
CMD_RM_ATT_VERTEX_ICON = os.path.join(iconPath, "cmdRmAttVertex.svg")
CMD_CABLE_ICON = os.path.join(iconPath, "cmdNewCable.svg")
CMD_CABLEBOX_ICON = os.path.join(iconPath, "cmdNewCableBox.svg")
CMD_CABLECONNECTOR_ICON = os.path.join(iconPath, "cmdNewCableConnector.svg")
CMD_CABLEPROFILE_ICON = os.path.join(iconPath, "cmdNewCableProfile.svg")
CMD_CABLEMATERIAL_ICON = os.path.join(iconPath, "cmdNewCableMaterial.svg")
CMD_CABLELIGHTPOINT_ICON = os.path.join(iconPath, "cmdNewCableLightPoint.svg")
CMD_HELPERPOINT_ICON = os.path.join(iconPath, "cmdNewHelperPoint.svg")
CMD_HELPERLINE_ICON = os.path.join(iconPath, "cmdNewHelperLine.svg")
class newWireFlexCommand:
"""Creates a WireFlex based on selected vertexes or objects
"""
def Activated(self):
sel = wireutils.processGuiSelection(False, Part.Vertex, None)
wireFlex.make_wireflex(sel)
FreeCAD.ActiveDocument.recompute()
def IsActive(self):
return Gui.ActiveDocument is not None
def GetResources(self):
return {'Pixmap': CMD_NEW_WIRE_ICON,
'MenuText': "New Wire Flex",
'ToolTip': "It creates a new line based on selected " +
"vertexes/objects. At least two vertexes/objects have to be " +
"selected first"}
class addVertexCommand:
"""Creates a new vertex in the middle of selected WireFlex edge
"""
def Activated(self):
sel = wireutils.processGuiSelection(True, Part.Edge, wireFlex.WireFlex)
wireutils.addPointToWire(sel)
FreeCAD.ActiveDocument.recompute()
def IsActive(self):
return Gui.ActiveDocument is not None
def GetResources(self):
return {'Pixmap': CMD_ADD_VERTEX_ICON,
'MenuText': "Add Vertex",
'ToolTip': "It adds a new vertex to selected edge of " +
"Wire Flex"}
class delVertexCommand:
"""Deletes selected vertex from WireFlex
"""
def Activated(self):
sel = wireutils.processGuiSelection(True, Part.Vertex,
wireFlex.WireFlex)
wireutils.delPointFromWire(sel)
FreeCAD.ActiveDocument.recompute()
def IsActive(self):
return Gui.ActiveDocument is not None
def GetResources(self):
return {'Pixmap': CMD_DEL_VERTEX_ICON,
'MenuText': "Delete Vertex",
'ToolTip': "It deletes selected vertex from Wire Flex"}
class assignAttachmentCommand:
"""Makes an attachment of selected WireFlex vertex to external vertex
or object
"""
def Activated(self):
sel = wireutils.processGuiSelection(False, Part.Vertex,
wireFlex.WireFlex)
wireutils.assignPointAttachment(sel)
FreeCAD.ActiveDocument.recompute()
def IsActive(self):
return Gui.ActiveDocument is not None
def GetResources(self):
return {'Pixmap': CMD_ATT_VERTEX_ICON,
'MenuText': "Attach Vertex",
'ToolTip': "It attaches a Wire Flex vertex to external " +
"vertex or object. Select Wire Flex vertex first then " +
"ext. vertex (or entire object)"}
class removeAttachmentCommand:
"""Removes attachment from selected WireFlex vertex
"""
def Activated(self):
sel = wireutils.processGuiSelection(True, Part.Vertex,
wireFlex.WireFlex)
wireutils.removePointAttachment(sel)
FreeCAD.ActiveDocument.recompute()
def IsActive(self):
return Gui.ActiveDocument is not None
def GetResources(self):
return {'Pixmap': CMD_RM_ATT_VERTEX_ICON,
'MenuText': "Remove Vertex Attachment",
'ToolTip': "It removes an attachment of external " +
"vertex or object from selected Wire Flex vertex"}
class newCableCommand:
def Activated(self):
sel_obj = Gui.Selection.getSelection()
if len(sel_obj) > 1:
archCable.makeCable(sel_obj[0], sel_obj[1])
else:
archCable.makeCable(sel_obj[0])
FreeCAD.ActiveDocument.recompute()
def IsActive(self):
return Gui.ActiveDocument is not None
def GetResources(self):
return {'Pixmap': CMD_CABLE_ICON,
'MenuText': "Add New Cable",
'ToolTip': "It adds a new cable object from Wire Flex and " +
"profile. Select Wire Flex object first then a profile"}
class newCableBoxCommand:
def Activated(self):
sel_obj = Gui.Selection.getCompleteSelection()
if len(sel_obj) > 0:
pos_vect = sel_obj[0].PickedPoints[0]
pl = FreeCAD.Placement()
pl.Base = pos_vect
archCableBox.makeCableBox(placement=pl)
else:
archCableBox.makeCableBox()
FreeCAD.ActiveDocument.recompute()
def IsActive(self):
return Gui.ActiveDocument is not None
def GetResources(self):
return {'Pixmap': CMD_CABLEBOX_ICON,
'MenuText': "Add New Cable Box",
'ToolTip': "It adds a new cable box object. Select any " +
"point in 3D view first, then add box"}
class newCableConnectorCommand:
def Activated(self):
sel_obj = Gui.Selection.getCompleteSelection()
if len(sel_obj) > 0:
pos_vect = sel_obj[0].PickedPoints[0]
pl = FreeCAD.Placement()
pl.Base = pos_vect
archCableConnector.makeCableConnector(placement=pl)
else:
archCableConnector.makeCableConnector()
FreeCAD.ActiveDocument.recompute()
def IsActive(self):
return Gui.ActiveDocument is not None
def GetResources(self):
return {'Pixmap': CMD_CABLECONNECTOR_ICON,
'MenuText': "Add New Cable Connector",
'ToolTip': "It adds a new cable connector object. Select" +
"any point in 3D view first, then add connector"}
class newProfileCommand:
def Activated(self):
#cableProfile.makeCableProfile()
panel = cableProfile.TaskPanelProfile()
FreeCADGui.Control.showDialog(panel)
FreeCAD.ActiveDocument.recompute()
def IsActive(self):
return Gui.ActiveDocument is not None
def GetResources(self):
return {'Pixmap': CMD_CABLEPROFILE_ICON,
'MenuText': "Add New Cable Profile",
'ToolTip': "It adds a new cable profile"}
class newMaterialCommand:
def Activated(self):
cableMaterial.makeCableMaterials()
FreeCAD.ActiveDocument.recompute()
def IsActive(self):
return Gui.ActiveDocument is not None
def GetResources(self):
return {'Pixmap': CMD_CABLEMATERIAL_ICON,
'MenuText': "Add New Cable Materials",
'ToolTip': "It adds new multimaterials for cables"}
class newCableLightPoint:
def Activated(self):
sel_obj = Gui.Selection.getCompleteSelection()
if len(sel_obj) > 0:
pos_vect = sel_obj[0].PickedPoints[0]
pl = FreeCAD.Placement()
pl.Base = pos_vect
archCableLightPoint.makeCableLightPoint(placement=pl)
else:
archCableLightPoint.makeCableLightPoint()
FreeCAD.ActiveDocument.recompute()
def IsActive(self):
return Gui.ActiveDocument is not None
def GetResources(self):
return {'Pixmap': CMD_CABLELIGHTPOINT_ICON,
'MenuText': "Add New Cable Light Point",
'ToolTip': "It adds a new light point for cable. Select" +
"any point in 3D view first, then add light point"}
class newHelperPoint:
def Activated(self):
sel_obj = Gui.Selection.getCompleteSelection()
if len(sel_obj) > 0:
pos_vect = sel_obj[0].PickedPoints[0]
pl = FreeCAD.Placement()
pl.Base = pos_vect
cableHelper.makeHelperPoint(placement=pl)
else:
cableHelper.makeHelperPoint()
FreeCAD.ActiveDocument.recompute()
def IsActive(self):
return Gui.ActiveDocument is not None
def GetResources(self):
return {'Pixmap': CMD_HELPERPOINT_ICON,
'MenuText': "Add New Helper Point",
'ToolTip': "It adds a new helper point to which a " +
"cable or other element can be attached"}
class newHelperLine:
def Activated(self):
sel_obj = Gui.Selection.getCompleteSelection()
if len(sel_obj) > 1:
p1 = sel_obj[0].PickedPoints[0]
p2 = sel_obj[1].PickedPoints[0]
cableHelper.makeHelperLine(p1, p2)
elif len(sel_obj) == 1:
p1 = sel_obj[0].PickedPoints[0]
cableHelper.makeHelperLine(p1)
else:
cableHelper.makeHelperLine()
FreeCAD.ActiveDocument.recompute()
def IsActive(self):
return Gui.ActiveDocument is not None
def GetResources(self):
return {'Pixmap': CMD_HELPERLINE_ICON,
'MenuText': "Add New Helper Line",
'ToolTip': "It adds a new helper line to which a " +
"cable or other element can be attached. Select at " +
"least one point first"}
Gui.addCommand('Cables_NewWireFlex', newWireFlexCommand())
Gui.addCommand('Cables_AddVertex', addVertexCommand())
Gui.addCommand('Cables_DelVertex', delVertexCommand())
Gui.addCommand('Cables_AttachVertex', assignAttachmentCommand())
Gui.addCommand('Cables_RemoveVertex', removeAttachmentCommand())
Gui.addCommand('Cables_NewCable', newCableCommand())
Gui.addCommand('Cables_NewCableBox', newCableBoxCommand())
Gui.addCommand('Cables_NewCableConnector', newCableConnectorCommand())
Gui.addCommand('Cables_NewProfile', newProfileCommand())
Gui.addCommand('Cables_NewMaterial', newMaterialCommand())
Gui.addCommand('Cables_NewCableLightPoint', newCableLightPoint())
Gui.addCommand('Cables_NewHelperPoint', newHelperPoint())
Gui.addCommand('Cables_NewHelperLine', newHelperLine())