forked from oddtopus/dodo
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCUtils.py
More file actions
256 lines (199 loc) · 7.28 KB
/
CUtils.py
File metadata and controls
256 lines (199 loc) · 7.28 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
# SPDX-License-Identifier: LGPL-3.0-or-later
__license__ = "LGPL 3"
# import FreeCAD modules
import FreeCAD
import FreeCADGui
from quetzal_config import addCommand
QT_TRANSLATE_NOOP = FreeCAD.Qt.QT_TRANSLATE_NOOP
# ---------------------------------------------------------------------------
# The command classes
# ---------------------------------------------------------------------------
class queryModel:
def IsActive(self):
if FreeCAD.ActiveDocument is None:
return False
else:
return True
def Activated(self):
import uForms
form = uForms.QueryForm(FreeCADGui.Selection)
def GetResources(self):
return {
"Pixmap": "Quetzal_QueryModel",
"Accel": "Q,M",
"MenuText": QT_TRANSLATE_NOOP("Quetzal_QueryModel", "Query the model"),
"ToolTip": QT_TRANSLATE_NOOP("Quetzal_QueryModel", "Click objects to print infos"),
}
class moveWorkPlane:
"""
Tool to set the DraftWorkingPlane according existing geometry of
the model.
The normal of plane is set:
* 1st according the selected face,
* then according the plane defined by a curved edge,
* at last according the plane defined by two straight edges.
The origin is set:
* 1st according the selected vertex,
* then according the center of curvature of a curved edge,
* at last according the intersection of two straight edges.
"""
def IsActive(self):
if FreeCAD.ActiveDocument is None:
return False
else:
return True
def Activated(self):
import uCmd
uCmd.setWP()
def GetResources(self):
return {
"Pixmap": "Quetzal_MoveWorkPlane",
"Accel": "A,W",
"MenuText": QT_TRANSLATE_NOOP("Quetzal_MoveWorkPlane", "Align workplane"),
"ToolTip": QT_TRANSLATE_NOOP(
"Quetzal_MoveWorkPlane",
"Moves and rotates the drafting workplane with points, edges and faces",
),
}
class rotateWorkPlane:
def IsActive(self):
if FreeCAD.ActiveDocument is None:
return False
else:
return True
def Activated(self):
import uForms
form = uForms.rotWPForm()
def GetResources(self):
return {
"Accel": "R,W",
"Pixmap": "Quetzal_RotateWorkPlane",
"MenuText": QT_TRANSLATE_NOOP("Quetzal_RotateWorkPlane", "Rotate workplane"),
"ToolTip": QT_TRANSLATE_NOOP(
"Quetzal_RotateWorkPlane", "Spin the Draft working plane about one of its axes"
),
}
class offsetWorkPlane:
def IsActive(self):
if FreeCAD.ActiveDocument is None:
return False
else:
return True
def Activated(self):
if hasattr(FreeCAD, "DraftWorkingPlane") and hasattr(FreeCADGui, "Snapper"):
import uCmd
s = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").GetInt("gridSize")
sc = [float(x * s) for x in [1, 1, 0.2]]
arrow = uCmd.arrow(FreeCAD.DraftWorkingPlane.getPlacement(), scale=sc, offset=s)
from PySide.QtGui import QInputDialog as qid
translate = FreeCAD.Qt.translate
offset = qid.getInt(
None,
translate("Quetzal_OffsetWorkPlane", "Offset Work Plane"),
translate("Quetzal_OffsetWorkPlane", "Offset: "),
)
if offset[1] > 0:
uCmd.offsetWP(offset[0])
# FreeCADGui.ActiveDocument.ActiveView.getSceneGraph().removeChild(arrow.node)
arrow.closeArrow()
def GetResources(self):
return {
"Pixmap": "Quetzal_OffsetWorkPlane",
"Accel": "O,W",
"MenuText": QT_TRANSLATE_NOOP("Quetzal_OffsetWorkPlane", "Offset workplane"),
"ToolTip": QT_TRANSLATE_NOOP(
"Quetzal_OffsetWorkPlane", "Shifts the WP along its normal."
),
}
class hackedL:
def IsActive(self):
if FreeCAD.ActiveDocument is None:
return False
else:
return True
def Activated(self):
import uCmd
form = uCmd.hackedLine()
def GetResources(self):
return {
"Pixmap": "Quetzal_HackedLine",
"Accel": "H,L",
"MenuText": QT_TRANSLATE_NOOP("Quetzal_HackedLine", "Draw a Draft wire"),
"ToolTip": QT_TRANSLATE_NOOP(
"Quetzal_HackedLine",
"WP is re-positioned at each point. Possible to spin and offset it.",
),
}
class moveHandle:
def IsActive(self):
if FreeCAD.ActiveDocument is None:
return False
else:
return True
def Activated(self):
import uCmd
FreeCADGui.Control.showDialog(uCmd.handleDialog())
# form = uCmd.handleDialog()
def GetResources(self):
return {
"Pixmap": "Quetzal_MoveHandle",
"Accel": "M,H",
"MenuText": QT_TRANSLATE_NOOP("Quetzal_MoveHandle", "Move objects"),
"ToolTip": QT_TRANSLATE_NOOP(
"Quetzal_MoveHandle", "Move quickly objects inside viewport"
),
}
class dpCalc:
def IsActive(self):
if FreeCAD.ActiveDocument is None:
return False
else:
return True
def Activated(self):
import uForms
FreeCADGui.Control.showDialog(uForms.dpCalcDialog())
def GetResources(self):
return {
"Pixmap": "Quetzal_PressureLossCalculator",
"MenuText": QT_TRANSLATE_NOOP(
"Quetzal_PressureLossCalculator", "Pressure loss calculator"
),
"ToolTip": QT_TRANSLATE_NOOP(
"Quetzal_PressureLossCalculator",
"Calculate pressure loss in 'pypes' using ChEDL libraries.\n"
"See __doc__ of the module for further information.",
),
}
class selectSolids:
def IsActive(self):
if FreeCAD.ActiveDocument is None:
return False
else:
return True
def Activated(self):
from fCmd import getSolids
if FreeCADGui.Selection.getSelection():
allDoc = False
else:
allDoc = True
getSolids(allDoc)
def GetResources(self):
return {
"Pixmap": "Quetzal_SelectSolids",
"MenuText": QT_TRANSLATE_NOOP("Quetzal_SelectSolids", "Select solids"),
"ToolTip": QT_TRANSLATE_NOOP(
"Quetzal_SelectSolids",
"Grab all solids or those partially selected\n to export in .step format",
),
}
# ---------------------------------------------------------------------------
# Adds the commands to the FreeCAD command manager
# ---------------------------------------------------------------------------
addCommand("Quetzal_QueryModel", queryModel())
addCommand("Quetzal_MoveWorkPlane", moveWorkPlane())
addCommand("Quetzal_RotateWorkPlane", rotateWorkPlane())
addCommand("Quetzal_OffsetWorkPlane", offsetWorkPlane())
addCommand("Quetzal_HackedLine", hackedL())
addCommand("Quetzal_MoveHandle", moveHandle())
addCommand("Quetzal_PressureLossCalculator", dpCalc())
addCommand("Quetzal_SelectSolids", selectSolids())