-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlegendKing_plugin.py
More file actions
executable file
·277 lines (229 loc) · 9.95 KB
/
legendKing_plugin.py
File metadata and controls
executable file
·277 lines (229 loc) · 9.95 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
"""Define the AFXForm class to handle scale dialog box events.
Carl Osterwisch, October 2006
"""
__version__ = '0.11.2'
from abaqusGui import *
from abaqusConstants import *
from kernelAccess import session
class myQuery:
"Object used to register/unregister Queries"
def __init__(self, object, subroutine):
"register the query when this object is created"
self.object = object
self.subroutine = subroutine
object.registerQuery(subroutine)
def __del__(self):
"unregister the query when this object is deleted"
self.object.unregisterQuery(self.subroutine)
def __repr__(self):
return 'myQuery {}'.format(self.subroutine.__doc__)
###########################################################################
# Dialog box definition
###########################################################################
class scaleDB(AFXDataDialog):
"""The scale dialog box class
scaleForm will create an instance of this class when the user requests it.
"""
ID_LAST = AFXDataDialog.ID_LAST + 3
ID_REVERSE, ID_RESET, ID_LAST = range(AFXDataDialog.ID_LAST, ID_LAST)
def __init__(self, form):
# Construct the base class.
AFXDataDialog.__init__(self, form, "Legend King",
self.APPLY, DIALOG_ACTIONS_SEPARATOR|DECOR_RESIZE)
self.appendActionButton(text='Reverse', tgt=self, sel=self.ID_REVERSE)
FXMAPFUNC(self, SEL_COMMAND, self.ID_REVERSE, scaleDB.onReverse)
self.appendActionButton(text='Reset', tgt=self, sel=self.ID_RESET)
FXMAPFUNC(self, SEL_COMMAND, self.ID_RESET, scaleDB.onReset)
self.vpNameKw = form.vpNameKw # local reference
mainframe = FXVerticalFrame(self, LAYOUT_FILL_X)
buttonframe = FXHorizontalFrame(mainframe, LAYOUT_FILL_X)
self.max = AFXTextField(p=buttonframe,
ncols=8,
labelText='Max',
tgt=form.maxKw,
opts=LAYOUT_FILL_X | AFXTEXTFIELD_FLOAT)
FXCheckButton(p=buttonframe,
text='Exactly',
tgt=form.maxExactKw)
buttonframe = FXHorizontalFrame(mainframe, LAYOUT_FILL_X)
self.min = AFXTextField(p=buttonframe,
ncols=8,
labelText='Min',
tgt=form.minKw,
opts=LAYOUT_FILL_X | AFXTEXTFIELD_FLOAT)
FXCheckButton(p=buttonframe,
text='Exactly',
tgt=form.minExactKw)
buttonframe = FXHorizontalFrame(mainframe, LAYOUT_FILL_X)
FXRadioButton(buttonframe, 'Linear', form.logKw, LINEAR.getId())
FXRadioButton(buttonframe, 'Log Scale', form.logKw, LOG.getId())
guide = AFXSlider(p=mainframe, tgt=form.guideKw,
opts=AFXSLIDER_HORIZONTAL | AFXSLIDER_INSIDE_BAR | LAYOUT_FILL_X)
guide.setRange(3, 24)
guide.setIncrement(1)
guide.setMinLabelText('Fewer Intervals')
guide.setMaxLabelText('More')
guide.setValue(15)
buttonframe = AFXVerticalAligner(mainframe, LAYOUT_FILL_X, pt=10)
AFXColorButton(p=buttonframe,
text='Color above max',
tgt=form.outsideAboveKw,
opts=LAYOUT_FILL_X)
spectrumCombo = AFXComboBox(p=buttonframe,
ncols=5,
nvis=10,
text='',
tgt=form.spectrumKw,
opts=LAYOUT_FILL_X)
for spectrum in session.spectrums.keys():
spectrumCombo.appendItem(spectrum)
AFXColorButton(p=buttonframe,
text='Color below min',
tgt=form.outsideBelowKw,
opts=LAYOUT_FILL_X)
def show(self):
"Called to display the dialog box"
self.vpNameKw.setValueToDefault() # Forces update in onSessionChanged()
self.primaryVariable = None
self.minmax = None
self.sessionQuery = myQuery(session, self.onSessionChanged)
AFXDataDialog.show(self)
def hide(self):
"Called to remove the dialog box"
self.variableQuery = None
self.sessionQuery = None
self.minmaxQuery = None
AFXDataDialog.hide(self)
def onSessionChanged(self):
"Recalculate settings based on a new session"
if session.currentViewportName == self.vpNameKw.getValue():
return
# If the current viewport changes then the contourQuery needs
# to be updated.
viewport = session.viewports[session.currentViewportName]
self.vpNameKw.setValue(viewport.name)
if hasattr(viewport.displayedObject, 'steps'):
# Seems to be an odb display
plotState = viewport.odbDisplay.display.plotState
self.odbDisplay = viewport.odbDisplay
self.contourOptions = viewport.odbDisplay.contourOptions
self.symbolOptions = viewport.odbDisplay.symbolOptions
self.primaryVariable = '' # force an update
self.variableQuery = myQuery(viewport.odbDisplay,
self.onDisplayChanged)
if SYMBOLS_ON_DEF in plotState or SYMBOLS_ON_UNDEF in plotState:
# Symbol plot
self.minmaxQuery = myQuery(self.symbolOptions,
self.onSymbolChanged)
else:
# Assume contour plot
self.minmaxQuery = myQuery(self.contourOptions,
self.onContourChanged)
else:
# Other display object (xyplot, etc)
self.minmaxQuery = None
def onDisplayChanged(self):
"Changed odbDisplay; recall previous settings"
if not hasattr(self.odbDisplay, 'primaryVariable'):
return
if self.primaryVariable != self.odbDisplay.primaryVariable:
self.primaryVariable = self.odbDisplay.primaryVariable
sendCommand("legendKing.recall(%r)"%self.vpNameKw.getValue())
def onContourChanged(self):
"Set GUI TextField to current min min"
minmax = (self.contourOptions.autoMinValue,
self.contourOptions.autoMaxValue)
if minmax != self.minmax and isinstance(minmax[0], float):
if self.min.getTarget():
self.min.getTarget().setValue(minmax[0])
self.max.getTarget().setValue(minmax[1])
self.minmax = minmax
def onSymbolChanged(self):
"Set GUI TextField to current min min"
minmax = (self.symbolOptions.autoVectorMinValue,
self.symbolOptions.autoVectorMaxValue)
if minmax != self.minmax and isinstance(minmax[0], float):
if self.min.getTarget():
self.min.getTarget().setValue(minmax[0])
self.max.getTarget().setValue(minmax[1])
self.minmax = minmax
def onReverse(self, sender, sel, ptr):
"User requested reverse spectrum colors."
sendCommand("legendKing.reverse_spectrum(%r)"%self.vpNameKw.getValue())
return 1
def onReset(self, sender, sel, ptr):
"User requested return to default settings."
sendCommand("legendKing.restore_defaults(%r)"%self.vpNameKw.getValue())
return 1
###########################################################################
# Form definition
###########################################################################
class scaleForm(AFXForm):
"Class to launch the scale GUI"
def __init__(self, owner):
AFXForm.__init__(self, owner) # Construct the base class.
# color spectrum
contourOptions = AFXGuiCommand(
mode=self,
method='setValues',
objectName='session.viewports[%s].odbDisplay.contourOptions',
registerQuery=TRUE)
self.outsideAboveKw = AFXStringKeyword(
command=contourOptions,
name='outsideLimitsAboveColor',
isRequired=FALSE)
self.outsideBelowKw = AFXStringKeyword(
command=contourOptions,
name='outsideLimitsBelowColor',
isRequired=FALSE)
self.spectrumKw = AFXStringKeyword(
command=contourOptions,
name='spectrum',
isRequired=FALSE)
# setup_scale kernel command
setup_scale = AFXGuiCommand(mode=self,
method='setValues',
objectName='legendKing',
registerQuery=FALSE)
self.maxKw = AFXFloatKeyword(command=setup_scale,
name='maxValue',
isRequired=TRUE,
defaultValue=100.)
self.minKw = AFXFloatKeyword(command=setup_scale,
name='minValue',
isRequired=TRUE,
defaultValue=0.)
self.guideKw = AFXIntKeyword(command=setup_scale,
name='guide',
isRequired=TRUE,
defaultValue=15)
self.vpNameKw = AFXStringKeyword(command=setup_scale,
name='vpName',
isRequired=TRUE,
defaultValue=None)
self.maxExactKw = AFXBoolKeyword(command=setup_scale,
name='maxExact',
defaultValue=OFF,
isRequired=TRUE)
self.minExactKw = AFXBoolKeyword(command=setup_scale,
name='minExact',
defaultValue=OFF,
isRequired=TRUE)
self.logKw = AFXSymConstKeyword(command=setup_scale,
name='log',
defaultValue=LINEAR.getId(),
isRequired=TRUE)
def getFirstDialog(self):
return scaleDB(self)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
toolset = getAFXApp().getAFXMainWindow().getPluginToolset()
toolset.registerGuiMenuButton(
buttonText='&Legend King',
object=scaleForm(toolset),
kernelInitString='import legendKing',
author='Carl Osterwisch',
version=__version__,
applicableModules=['Visualization'],
description='Setup a reasonable legend scale quick and easy.',
helpUrl='https://github.com/costerwi/plugin-legendKing',
)