-
Notifications
You must be signed in to change notification settings - Fork 6
/
TDCustomFormat.FCMacro
235 lines (201 loc) · 8.17 KB
/
TDCustomFormat.FCMacro
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
"""
Custom Format Macro for the TechDraw Workbench
Select dimensions and click the macro in order to customize the format shown.
The Macro includes the most common (and available as Unicode!) characters
used in technical drawings.
"""
__Name__ = 'TDCustomFormat'
__Comment__ = 'Change the format of dimensions'
__Author__ = 'Sebastian Bachmann'
__Version__ = '1.0'
__Date__ = '2020-05-07'
__License__ = 'MIT'
__Web__ = 'https://github.com/reox/FreeCAD_Macros'
__Wiki__ = ''
__Icon__ = 'icons/CustomFormat.svg'
__Help__ = 'Select dimension(s) and run the macro'
__Status__ = 'Stable'
__Requires__ = '>=0.19.18234; py3 only'
__Communication__ = 'https://github.com/reox/FreeCAD_Macros/issues'
# Copyright (c) 2019, Sebastian Bachmann <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# Is a shim provided by FreeCAD
from PySide.QtGui import (
QMainWindow,
QDialog,
QLineEdit,
QPushButton,
QGridLayout,
QLabel,
QGroupBox,
QSpacerItem,
)
class Form(QDialog):
_defaultformat = "%.5g"
# See also https://en.wikipedia.org/wiki/Geometric_dimensioning_and_tolerancing#Symbols
# https://github.com/hikikomori82/osifont
# https://de.wikipedia.org/wiki/Unicodeblock_Verschiedene_technische_Zeichen
symbols = {
'GD&&T': {
'\u23e4': 'Straightness',
'\u23e5': 'Flatness',
'\u25cb': 'Circularity',
'\u232d': 'Cylindricity',
'\u2225': 'Parallelism',
'\u27c2': 'Perpendicularity',
'\u2220': 'Angularity',
'\u2312': 'Profile of a line',
'\u2313': 'Profile of a surface',
'\u2197': 'Circular runout',
'\u2330': 'Total runout',
'\u2316': 'Position',
'\u25ce': 'Concentricity',
'\u232f': 'Symmetry',
},
'Modifiers': {
'\u24b6': 'derived geometry element', # A, not in osifont
'\u24b8': 'Minimax (Tschebyschew)', # C, not in osifont
'\u24ba': 'Hull condition', # E
'\u24bb': 'Free state', # F
'\u24bc': 'Least square geomtry element', # G, not in osifont
'\u24c1': 'Least material condition (LMC)', # L
'\u24c2': 'Maximum material condition (MMC)', # M
'\u24c3': 'least inscribed geometry element', # N, not in osifont
'\u24c5': 'Projected tolerance zone', # P
'\u24c7': 'Reciprocity condition', # R, not in osifont
'\u24c8': 'Regardless of feature size (RFS)', # S
'\u24c9': 'Tangent plane', # T
'\u24ca': 'Unequal Bilateral', # U
'\u24cd': 'most inscribed geomtry element', # X, not in osifont
},
'Radius && Diameter': {
'R': 'Radius',
'\u2300': 'Diameter',
'SR': 'Radius of sphere',
'S\u2300': 'Diameter of sphere',
'\u25a1': 'Square',
},
'Angles': {
'\u00b0': 'Degree',
'\u2032': '(Arc) Minute',
'\u2033': '(Arc) Second',
'\u2034': '(Arc) Tertie',
},
'Other': {
'\u2332': 'Taper',
'\u2333': 'Slope',
'\u2334': 'Counterbore',
'\u2335': 'Countersink',
'\u00b1': 'Plus - Minus',
'\u2104': 'Centerline',
'\u2194': 'Left/right arrow',
'\u21a7': 'Downward arrow',
'\u00d7': 'Multiplication sign',
},
'Greek Letters': {
'\u0394': 'Capital delta',
'\u03a3': 'Capital sigma',
'\u03a9': 'Capital omega',
'\u03bc': 'Small mu',
'\u03c3': 'Small sigma',
'\u03c6': 'Small phi',
'\u2375': 'Small omega',
}
}
previewnumber = 23.123456789
stylesheet = 'font-family: osifont; font-size:24px;'
columns = 5
def __init__(self, parent=None):
super(Form, self).__init__(parent)
self.setWindowTitle("Format Symbols")
layout = QGridLayout()
for n, (grp, items) in enumerate(self.symbols.items()):
box = QGroupBox(grp)
local_layout = QGridLayout()
box.setLayout(local_layout)
for i, (sym, desc) in enumerate(items.items()):
btn = QPushButton(sym)
btn.setStyleSheet(self.stylesheet)
btn.setToolTip(desc)
btn.clicked.connect(self.addSymbol)
btn.setMinimumHeight(36)
local_layout.addWidget(btn, i // self.columns, i % self.columns)
# Fill up row
if i < self.columns:
for x in range(i, self.columns):
# FIXME
# local_layout.addItem(QSpacerItem(btn.width(), btn.height()), x // self.columns, x % self.columns)
pass
layout.addWidget(box, n, 0, 1, self.columns)
tot_lines = len(self.symbols)
self.formatspec = QLineEdit(self.defaultformat)
self.formatspec.textChanged.connect(self.preview)
layout.addWidget(QLabel("Format:", self), tot_lines + 1, 0)
layout.addWidget(self.formatspec, tot_lines + 1, 1, 1, 2)
reset = QPushButton("Reset")
reset.clicked.connect(self.reset)
layout.addWidget(reset, tot_lines + 1, 3)
layout.addWidget(QLabel("Preview:"), tot_lines + 2, 0)
self.previewlabel = QLabel("")
self.previewlabel.setStyleSheet(self.stylesheet)
layout.addWidget(self.previewlabel, tot_lines + 2, 1)
ok = QPushButton("OK")
ok.clicked.connect(self.write)
abort = QPushButton("Abort")
abort.clicked.connect(self.exit)
layout.addWidget(ok, tot_lines + 3, 2)
layout.addWidget(abort, tot_lines + 3, 3)
self.setLayout(layout)
self.preview()
# Move to the beginning, usually we want to insert here...
self.formatspec.setCursorPosition(0)
def addSymbol(self):
self.formatspec.insert(self.sender().text())
def write(self):
for sel in FreeCADGui.Selection.getSelection():
if hasattr(sel, "FormatSpec"):
# assume it is a Dimension...
sel.FormatSpec = self.formatspec.text()
sel.recompute()
elif hasattr(sel, "Text"):
# Looks like a Balloon type feature
sel.Text = self.formatspec.text()
sel.recompute()
self.close()
@property
def defaultformat(self):
if len(FreeCADGui.Selection.getSelection()) != 1:
return self._defaultformat
sel = FreeCADGui.Selection.getSelection()[0]
if hasattr(sel, "FormatSpec"):
# assume it is a Dimension...
return sel.FormatSpec
elif hasattr(sel, "Text"):
# Looks like a Balloon type feature
return sel.Text
return self._defaultformat
def preview(self):
self.previewlabel.setText(self.formatspec.text() % (self.previewnumber))
def reset(self):
self.formatspec.setText(self.defaultformat)
def exit(self, event):
self.close()
if __name__ == '__main__':
form = Form()
form.show()