simplex-solver 3.1.0__39-abi3-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- simplex_solver-3.1.0.dist-info/METADATA +90 -0
- simplex_solver-3.1.0.dist-info/RECORD +79 -0
- simplex_solver-3.1.0.dist-info/WHEEL +5 -0
- simplexui/__init__.py +53 -0
- simplexui/_version.py +1 -0
- simplexui/channelBox.py +858 -0
- simplexui/comboCheckDialog.py +343 -0
- simplexui/commands/__init__.py +16 -0
- simplexui/commands/alembicCommon.py +991 -0
- simplexui/commands/applyCorrectives.py +451 -0
- simplexui/commands/correctiveInterface.py +261 -0
- simplexui/commands/expandedExport.py +436 -0
- simplexui/commands/hdf5Convert.py +60 -0
- simplexui/commands/mayaCorrectiveInterface.py +161 -0
- simplexui/commands/mayatonumpy.py +375 -0
- simplexui/commands/mesh.py +1081 -0
- simplexui/commands/numpytoimath.py +319 -0
- simplexui/commands/poseblendlib.py +166 -0
- simplexui/commands/reorderSimplexPoints.py +102 -0
- simplexui/commands/rigidAlign.py +99 -0
- simplexui/commands/smpxBlend.py +629 -0
- simplexui/commands/unsubdivide.py +1227 -0
- simplexui/commands/uvTransfer.py +977 -0
- simplexui/dragFilter.py +299 -0
- simplexui/falloffDialog.py +471 -0
- simplexui/img/ChefHead.png +0 -0
- simplexui/img/frozen.png +0 -0
- simplexui/interface/__init__.py +28 -0
- simplexui/interface/dummyInterface.py +1585 -0
- simplexui/interface/mayaInterface.py +3271 -0
- simplexui/interfaceModel.py +1053 -0
- simplexui/interfaceModelTrees.py +441 -0
- simplexui/items/__init__.py +42 -0
- simplexui/items/accessor.py +213 -0
- simplexui/items/combo.py +852 -0
- simplexui/items/falloff.py +778 -0
- simplexui/items/group.py +297 -0
- simplexui/items/progression.py +743 -0
- simplexui/items/shape.py +443 -0
- simplexui/items/simplex.py +1764 -0
- simplexui/items/slider.py +738 -0
- simplexui/items/stack.py +154 -0
- simplexui/items/traversal.py +966 -0
- simplexui/main.pyw +22 -0
- simplexui/menu/__init__.py +69 -0
- simplexui/menu/dummyPlugins/__init__.py +16 -0
- simplexui/menu/genericPlugins/__init__.py +16 -0
- simplexui/menu/genericPlugins/_builtins.py +268 -0
- simplexui/menu/genericPlugins/checkPossibleCombos.py +45 -0
- simplexui/menu/genericPlugins/exportSplit.py +59 -0
- simplexui/menu/genericPlugins/showFalloffs.py +24 -0
- simplexui/menu/genericPlugins/showTraversals.py +24 -0
- simplexui/menu/genericPlugins/simplexUvTransfer.py +107 -0
- simplexui/menu/genericPlugins/unsubdivide.py +70 -0
- simplexui/menu/mayaPlugins/__init__.py +16 -0
- simplexui/menu/mayaPlugins/exportOther.py +43 -0
- simplexui/menu/mayaPlugins/extractProgressives.py +65 -0
- simplexui/menu/mayaPlugins/freezeCombo.py +245 -0
- simplexui/menu/mayaPlugins/generateShapeIncrementals.py +97 -0
- simplexui/menu/mayaPlugins/importObjs.py +193 -0
- simplexui/menu/mayaPlugins/linearizeTraversal.py +48 -0
- simplexui/menu/mayaPlugins/makeShelfBtn.py +65 -0
- simplexui/menu/mayaPlugins/relaxToSelection.py +75 -0
- simplexui/menu/mayaPlugins/reloadDefinition.py +33 -0
- simplexui/menu/mayaPlugins/snapToNeutral.py +72 -0
- simplexui/menu/mayaPlugins/softSelectToCluster.py +200 -0
- simplexui/menu/mayaPlugins/tweakMix.py +134 -0
- simplexui/menu/mayaPlugins/updateRestShape.py +105 -0
- simplexui/pysimplex.dll.a +0 -0
- simplexui/pysimplex.pyd +0 -0
- simplexui/simplexDialog.py +1454 -0
- simplexui/travCheckDialog.py +397 -0
- simplexui/traversalDialog.py +271 -0
- simplexui/ui/comboCheckDialog.ui +475 -0
- simplexui/ui/falloffDialog.ui +243 -0
- simplexui/ui/simplexDialog.ui +1458 -0
- simplexui/ui/travCheckDialog.ui +488 -0
- simplexui/ui/traversalDialog.ui +532 -0
- simplexui/utils.py +320 -0
|
@@ -0,0 +1,1053 @@
|
|
|
1
|
+
# Copyright 2016, Blur Studio
|
|
2
|
+
#
|
|
3
|
+
# This file is part of Simplex.
|
|
4
|
+
#
|
|
5
|
+
# Simplex is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
#
|
|
10
|
+
# Simplex is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU Lesser General Public License for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU Lesser General Public License
|
|
16
|
+
# along with Simplex. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
|
|
18
|
+
# pylint:disable=missing-docstring,unused-argument,no-self-use,too-many-return-statements
|
|
19
|
+
import re
|
|
20
|
+
from contextlib import contextmanager
|
|
21
|
+
|
|
22
|
+
from .items import (
|
|
23
|
+
Combo,
|
|
24
|
+
ComboPair,
|
|
25
|
+
Group,
|
|
26
|
+
ProgPair,
|
|
27
|
+
Progression,
|
|
28
|
+
Slider,
|
|
29
|
+
Traversal,
|
|
30
|
+
TravPair,
|
|
31
|
+
)
|
|
32
|
+
from Qt import IsPyQt5, IsPySide2
|
|
33
|
+
from Qt.QtCore import QAbstractItemModel, QModelIndex, QSortFilterProxyModel, Qt
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# Hierarchy Helpers
|
|
37
|
+
def coerceIndexToType(indexes, typ):
|
|
38
|
+
"""Get a list of indices of a specific type based on a given index list
|
|
39
|
+
Items containing parents of the type fall down to their children
|
|
40
|
+
Items containing children of the type climb up to their parents
|
|
41
|
+
|
|
42
|
+
Parameters
|
|
43
|
+
----------
|
|
44
|
+
indexes : [QModelIndex, ...]
|
|
45
|
+
A list of indexes to coerce
|
|
46
|
+
typ : Type
|
|
47
|
+
The type to coerce to
|
|
48
|
+
|
|
49
|
+
Returns
|
|
50
|
+
-------
|
|
51
|
+
[QModelIndex, ...]
|
|
52
|
+
The coerced list
|
|
53
|
+
"""
|
|
54
|
+
targetDepth = typ.classDepth
|
|
55
|
+
|
|
56
|
+
children = []
|
|
57
|
+
parents = []
|
|
58
|
+
out = []
|
|
59
|
+
for idx in indexes:
|
|
60
|
+
item = idx.model().itemFromIndex(idx)
|
|
61
|
+
depth = item.classDepth
|
|
62
|
+
if depth < targetDepth:
|
|
63
|
+
parents.append(idx)
|
|
64
|
+
elif depth > targetDepth:
|
|
65
|
+
children.append(idx)
|
|
66
|
+
else:
|
|
67
|
+
out.append(idx)
|
|
68
|
+
|
|
69
|
+
out.extend(coerceIndexToChildType(parents, typ))
|
|
70
|
+
out.extend(coerceIndexToParentType(children, typ))
|
|
71
|
+
out = list(set(out))
|
|
72
|
+
return out
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def coerceIndexToChildType(indexes, typ):
|
|
76
|
+
"""Get a list of indices of a specific type based on a given index list
|
|
77
|
+
Lists containing parents of the type fall down to their children
|
|
78
|
+
|
|
79
|
+
Parameters
|
|
80
|
+
----------
|
|
81
|
+
indexes : [QModelIndex, ...]
|
|
82
|
+
A list of indexes to coerce
|
|
83
|
+
typ : Type
|
|
84
|
+
The type to coerce to
|
|
85
|
+
|
|
86
|
+
Returns
|
|
87
|
+
-------
|
|
88
|
+
[QModelIndex, ...]
|
|
89
|
+
The coerced list
|
|
90
|
+
"""
|
|
91
|
+
targetDepth = typ.classDepth
|
|
92
|
+
out = []
|
|
93
|
+
|
|
94
|
+
for idx in indexes:
|
|
95
|
+
model = idx.model()
|
|
96
|
+
item = idx.model().itemFromIndex(idx)
|
|
97
|
+
if item.classDepth < targetDepth:
|
|
98
|
+
# Too high up, grab children
|
|
99
|
+
queue = [idx]
|
|
100
|
+
depthIdxs = []
|
|
101
|
+
while queue:
|
|
102
|
+
checkIdx = queue.pop()
|
|
103
|
+
checkItem = checkIdx.model().itemFromIndex(checkIdx)
|
|
104
|
+
if checkItem.classDepth < targetDepth:
|
|
105
|
+
for row in range(model.rowCount(checkIdx)):
|
|
106
|
+
queue.append(model.index(row, 0, checkIdx))
|
|
107
|
+
elif checkItem.classDepth == targetDepth:
|
|
108
|
+
depthIdxs.append(checkIdx)
|
|
109
|
+
out.extend(depthIdxs)
|
|
110
|
+
elif item.classDepth == targetDepth:
|
|
111
|
+
out.append(idx)
|
|
112
|
+
|
|
113
|
+
out = list(set(out))
|
|
114
|
+
return out
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def coerceIndexToParentType(indexes, typ):
|
|
118
|
+
"""Get a list of indices of a specific type based on a given index list
|
|
119
|
+
Lists containing children of the type climb up to their parents
|
|
120
|
+
|
|
121
|
+
Parameters
|
|
122
|
+
----------
|
|
123
|
+
indexes : [QModelIndex, ...]
|
|
124
|
+
A list of indexes to coerce
|
|
125
|
+
typ : Type
|
|
126
|
+
The type to coerce to
|
|
127
|
+
|
|
128
|
+
Returns
|
|
129
|
+
-------
|
|
130
|
+
[QModelIndex, ...]
|
|
131
|
+
The coerced list
|
|
132
|
+
"""
|
|
133
|
+
targetDepth = typ.classDepth
|
|
134
|
+
out = []
|
|
135
|
+
for idx in indexes:
|
|
136
|
+
item = idx.model().itemFromIndex(idx)
|
|
137
|
+
depth = item.classDepth
|
|
138
|
+
if depth > targetDepth:
|
|
139
|
+
parIdx = idx
|
|
140
|
+
parItem = parIdx.model().itemFromIndex(parIdx)
|
|
141
|
+
while parItem.classDepth > targetDepth:
|
|
142
|
+
parIdx = parIdx.parent()
|
|
143
|
+
parItem = parIdx.model().itemFromIndex(parIdx)
|
|
144
|
+
if parItem.classDepth == targetDepth:
|
|
145
|
+
out.append(parIdx)
|
|
146
|
+
elif depth == targetDepth:
|
|
147
|
+
out.append(idx)
|
|
148
|
+
|
|
149
|
+
out = list(set(out))
|
|
150
|
+
return out
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def coerceIndexToRoots(indexes):
|
|
154
|
+
"""Get the topmost indexes for each brach in the hierarchy
|
|
155
|
+
|
|
156
|
+
Parameters
|
|
157
|
+
----------
|
|
158
|
+
indexes : [QModelIndex, ...]
|
|
159
|
+
A list of indexes to coerce
|
|
160
|
+
|
|
161
|
+
Returns
|
|
162
|
+
-------
|
|
163
|
+
[QModelIndex, ...]
|
|
164
|
+
The coerced list
|
|
165
|
+
"""
|
|
166
|
+
indexes = [i for i in indexes if i.column() == 0]
|
|
167
|
+
indexes = sorted(
|
|
168
|
+
indexes, key=lambda x: x.model().itemFromIndex(x).classDepth, reverse=True
|
|
169
|
+
)
|
|
170
|
+
# Check each item to see if any of it's ancestors
|
|
171
|
+
# are in the selection list. If not, it's a root
|
|
172
|
+
roots = []
|
|
173
|
+
for idx in indexes:
|
|
174
|
+
par = idx.parent()
|
|
175
|
+
while par.isValid():
|
|
176
|
+
if par in indexes:
|
|
177
|
+
break
|
|
178
|
+
par = par.parent()
|
|
179
|
+
else:
|
|
180
|
+
roots.append(idx)
|
|
181
|
+
|
|
182
|
+
return roots
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
# BASE MODEL
|
|
186
|
+
class ContextModel(QAbstractItemModel):
|
|
187
|
+
"""A sub-class of QAbstractItemModel with built-in contextmanagers
|
|
188
|
+
that handle calling the begin/end signals for adding/removing/moving/resettting
|
|
189
|
+
"""
|
|
190
|
+
|
|
191
|
+
@contextmanager
|
|
192
|
+
def insertItemManager(self, parent, row=-1):
|
|
193
|
+
"""ContextManager for inserting items into the model
|
|
194
|
+
|
|
195
|
+
Parameters
|
|
196
|
+
----------
|
|
197
|
+
parent : object
|
|
198
|
+
The item in the tree that will be the parent
|
|
199
|
+
row : int
|
|
200
|
+
The row to insert into. Pass -1 to append to the list (Default value = -1)
|
|
201
|
+
"""
|
|
202
|
+
parIdx = self.indexFromItem(parent)
|
|
203
|
+
if row == -1:
|
|
204
|
+
row = self.getItemAppendRow(parent)
|
|
205
|
+
self.beginInsertRows(parIdx, row, row)
|
|
206
|
+
try:
|
|
207
|
+
yield
|
|
208
|
+
finally:
|
|
209
|
+
self.endInsertRows()
|
|
210
|
+
|
|
211
|
+
@contextmanager
|
|
212
|
+
def removeItemManager(self, item):
|
|
213
|
+
"""ContextManager for removing items from the model
|
|
214
|
+
|
|
215
|
+
Parameters
|
|
216
|
+
----------
|
|
217
|
+
item : object
|
|
218
|
+
The item to remove from the model
|
|
219
|
+
"""
|
|
220
|
+
idx = self.indexFromItem(item)
|
|
221
|
+
valid = idx.isValid()
|
|
222
|
+
if valid:
|
|
223
|
+
parIdx = idx.parent()
|
|
224
|
+
self.beginRemoveRows(parIdx, idx.row(), idx.row())
|
|
225
|
+
try:
|
|
226
|
+
yield
|
|
227
|
+
finally:
|
|
228
|
+
if valid:
|
|
229
|
+
self.endRemoveRows()
|
|
230
|
+
|
|
231
|
+
@contextmanager
|
|
232
|
+
def moveItemManager(self, item, destPar, destRow=-1):
|
|
233
|
+
"""ContextManager for moving items within the model
|
|
234
|
+
|
|
235
|
+
Parameters
|
|
236
|
+
----------
|
|
237
|
+
item : object
|
|
238
|
+
The item to move in the model
|
|
239
|
+
destPar : object
|
|
240
|
+
The object that will be the new parent
|
|
241
|
+
destRow : int
|
|
242
|
+
The row to move to. Pass -1 to move to the end (Default value = -1)
|
|
243
|
+
"""
|
|
244
|
+
itemIdx = self.indexFromItem(item)
|
|
245
|
+
destParIdx = self.indexFromItem(destPar)
|
|
246
|
+
handled = False
|
|
247
|
+
if itemIdx.isValid() and destParIdx.isValid():
|
|
248
|
+
handled = True
|
|
249
|
+
srcParIdx = itemIdx.parent()
|
|
250
|
+
row = itemIdx.row()
|
|
251
|
+
if destRow == -1:
|
|
252
|
+
destRow = self.getItemAppendRow(destPar)
|
|
253
|
+
self.beginMoveRows(srcParIdx, row, row, destParIdx, destRow)
|
|
254
|
+
try:
|
|
255
|
+
yield
|
|
256
|
+
finally:
|
|
257
|
+
if handled:
|
|
258
|
+
self.endMoveRows()
|
|
259
|
+
|
|
260
|
+
@contextmanager
|
|
261
|
+
def resetModelManager(self):
|
|
262
|
+
"""ContextManager for resetting the entire model"""
|
|
263
|
+
self.beginResetModel()
|
|
264
|
+
try:
|
|
265
|
+
yield
|
|
266
|
+
finally:
|
|
267
|
+
self.endResetModel()
|
|
268
|
+
|
|
269
|
+
def indexFromItem(self, item, column=0):
|
|
270
|
+
"""Return the index for the given item
|
|
271
|
+
|
|
272
|
+
Parameters
|
|
273
|
+
----------
|
|
274
|
+
item : object
|
|
275
|
+
The item to move in the model
|
|
276
|
+
column : int
|
|
277
|
+
The column to get the index for. Defaults to 0
|
|
278
|
+
|
|
279
|
+
Returns
|
|
280
|
+
-------
|
|
281
|
+
QModelIndex
|
|
282
|
+
The index of the item
|
|
283
|
+
"""
|
|
284
|
+
row = self.getItemRow(item)
|
|
285
|
+
if row is None:
|
|
286
|
+
return QModelIndex()
|
|
287
|
+
return self.createIndex(row, column, item)
|
|
288
|
+
|
|
289
|
+
def itemFromIndex(self, index):
|
|
290
|
+
"""Return the item for the given index
|
|
291
|
+
|
|
292
|
+
Parameters
|
|
293
|
+
----------
|
|
294
|
+
index : QModelIndex
|
|
295
|
+
The index to get the item of
|
|
296
|
+
|
|
297
|
+
Returns
|
|
298
|
+
-------
|
|
299
|
+
object
|
|
300
|
+
The item in the tree
|
|
301
|
+
"""
|
|
302
|
+
return index.internalPointer()
|
|
303
|
+
|
|
304
|
+
def itemDataChanged(self, item):
|
|
305
|
+
"""Emit the itemDataChanged signal.
|
|
306
|
+
|
|
307
|
+
This must be done through this interface because, unfortunately, I can't quite figure out how
|
|
308
|
+
to make the empty `roles` list pass properly for Qt5. So I have to change behavior based
|
|
309
|
+
on the Qt backend
|
|
310
|
+
|
|
311
|
+
Parameters
|
|
312
|
+
----------
|
|
313
|
+
item : object
|
|
314
|
+
The object whose data has changed
|
|
315
|
+
"""
|
|
316
|
+
idx = self.indexFromItem(item)
|
|
317
|
+
self.emitDataChanged(idx)
|
|
318
|
+
|
|
319
|
+
def _emitDataChangedQt5(self, index):
|
|
320
|
+
if index.isValid():
|
|
321
|
+
self.dataChanged.emit(index, index, [])
|
|
322
|
+
|
|
323
|
+
def _emitDataChangedQt4(self, index):
|
|
324
|
+
if index.isValid():
|
|
325
|
+
self.dataChanged.emit(index, index)
|
|
326
|
+
|
|
327
|
+
emitDataChanged = (
|
|
328
|
+
_emitDataChangedQt5 if IsPySide2 or IsPyQt5 else _emitDataChangedQt4
|
|
329
|
+
)
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
class SimplexModel(ContextModel):
|
|
333
|
+
"""The base model for all interaction with a simplex system.
|
|
334
|
+
All ui interactions with a simplex system must go through this model
|
|
335
|
+
Any special requirements, or reorganizations of the trees will only
|
|
336
|
+
be implemented as proxy models.
|
|
337
|
+
|
|
338
|
+
There will be little documentation for this class, as all methods
|
|
339
|
+
are virtual overrides of the underlying Qt class
|
|
340
|
+
|
|
341
|
+
Parameters
|
|
342
|
+
----------
|
|
343
|
+
simplex : Simplex
|
|
344
|
+
The Simplex system for this model
|
|
345
|
+
parent : QObject
|
|
346
|
+
The parent for this model
|
|
347
|
+
|
|
348
|
+
"""
|
|
349
|
+
|
|
350
|
+
def __init__(self, simplex, parent):
|
|
351
|
+
super(SimplexModel, self).__init__(parent)
|
|
352
|
+
self.simplex = simplex
|
|
353
|
+
self.simplex.models.append(self)
|
|
354
|
+
|
|
355
|
+
def index(self, row, column, parIndex):
|
|
356
|
+
par = parIndex.internalPointer()
|
|
357
|
+
child = self.getChildItem(par, row)
|
|
358
|
+
if child is None:
|
|
359
|
+
return QModelIndex()
|
|
360
|
+
return self.createIndex(row, column, child)
|
|
361
|
+
|
|
362
|
+
def parent(self, index):
|
|
363
|
+
if not index.isValid():
|
|
364
|
+
return QModelIndex()
|
|
365
|
+
item = index.internalPointer()
|
|
366
|
+
if item is None:
|
|
367
|
+
return QModelIndex()
|
|
368
|
+
par = self.getParentItem(item)
|
|
369
|
+
if par is None:
|
|
370
|
+
return QModelIndex()
|
|
371
|
+
row = self.getItemRow(par)
|
|
372
|
+
if row is None:
|
|
373
|
+
return QModelIndex()
|
|
374
|
+
return self.createIndex(row, 0, par)
|
|
375
|
+
|
|
376
|
+
def rowCount(self, parIndex):
|
|
377
|
+
parent = parIndex.internalPointer()
|
|
378
|
+
ret = self.getItemRowCount(parent)
|
|
379
|
+
return ret
|
|
380
|
+
|
|
381
|
+
def columnCount(self, parIndex):
|
|
382
|
+
return 3
|
|
383
|
+
|
|
384
|
+
def data(self, index, role):
|
|
385
|
+
if not index.isValid():
|
|
386
|
+
return None
|
|
387
|
+
item = index.internalPointer()
|
|
388
|
+
return self.getItemData(item, index.column(), role)
|
|
389
|
+
|
|
390
|
+
def flags(self, index):
|
|
391
|
+
if not index.isValid():
|
|
392
|
+
return Qt.ItemFlag.ItemIsEnabled
|
|
393
|
+
if index.column() == 0:
|
|
394
|
+
item = index.internalPointer()
|
|
395
|
+
if isinstance(item, (Slider, Combo, Traversal)):
|
|
396
|
+
return (
|
|
397
|
+
Qt.ItemFlag.ItemIsEnabled
|
|
398
|
+
| Qt.ItemFlag.ItemIsSelectable
|
|
399
|
+
| Qt.ItemFlag.ItemIsEditable
|
|
400
|
+
| Qt.ItemFlag.ItemIsUserCheckable
|
|
401
|
+
)
|
|
402
|
+
# TODO: make the SHAPES object under a combo or traversal not-editable
|
|
403
|
+
return (
|
|
404
|
+
Qt.ItemFlag.ItemIsEnabled
|
|
405
|
+
| Qt.ItemFlag.ItemIsSelectable
|
|
406
|
+
| Qt.ItemFlag.ItemIsEditable
|
|
407
|
+
)
|
|
408
|
+
|
|
409
|
+
def setData(self, index, value, role=Qt.ItemDataRole.EditRole):
|
|
410
|
+
if not index.isValid():
|
|
411
|
+
return False
|
|
412
|
+
if role == Qt.ItemDataRole.CheckStateRole:
|
|
413
|
+
item = index.internalPointer()
|
|
414
|
+
if index.column() == 0:
|
|
415
|
+
if isinstance(item, (Slider, Combo, Traversal)):
|
|
416
|
+
item.enabled = value == Qt.CheckState.Checked
|
|
417
|
+
return True
|
|
418
|
+
elif role == Qt.ItemDataRole.EditRole:
|
|
419
|
+
item = index.internalPointer()
|
|
420
|
+
if index.column() == 0:
|
|
421
|
+
if isinstance(item, (Group, Slider, Combo, Traversal, ProgPair)):
|
|
422
|
+
item.name = value
|
|
423
|
+
return True
|
|
424
|
+
|
|
425
|
+
elif index.column() == 1:
|
|
426
|
+
if isinstance(item, Slider):
|
|
427
|
+
item.value = value
|
|
428
|
+
elif isinstance(item, ComboPair):
|
|
429
|
+
item.value = value
|
|
430
|
+
elif isinstance(item, TravPair):
|
|
431
|
+
item.value = value
|
|
432
|
+
|
|
433
|
+
elif index.column() == 2:
|
|
434
|
+
if isinstance(item, ProgPair):
|
|
435
|
+
item.value = value
|
|
436
|
+
return False
|
|
437
|
+
|
|
438
|
+
def headerData(self, section, orientation, role):
|
|
439
|
+
if orientation == Qt.Orientation.Horizontal:
|
|
440
|
+
if role == Qt.ItemDataRole.DisplayRole:
|
|
441
|
+
sects = ("Items", "Slide", "Value")
|
|
442
|
+
return sects[section]
|
|
443
|
+
return None
|
|
444
|
+
|
|
445
|
+
# Methods for dealing with items only
|
|
446
|
+
# These will be used to build the indexes
|
|
447
|
+
# and will be public for utility needs
|
|
448
|
+
def getChildItem(self, parent, row):
|
|
449
|
+
if parent is None:
|
|
450
|
+
if row == 0:
|
|
451
|
+
return self.simplex
|
|
452
|
+
else:
|
|
453
|
+
return None
|
|
454
|
+
return parent.treeChild(row)
|
|
455
|
+
|
|
456
|
+
def getItemRow(self, item):
|
|
457
|
+
if item is None:
|
|
458
|
+
return None
|
|
459
|
+
return item.treeRow()
|
|
460
|
+
|
|
461
|
+
def getParentItem(self, item):
|
|
462
|
+
if item is None:
|
|
463
|
+
return None
|
|
464
|
+
return item.treeParent()
|
|
465
|
+
|
|
466
|
+
def getItemRowCount(self, item):
|
|
467
|
+
# Null parent means 1 row that is the simplex object
|
|
468
|
+
if item is None:
|
|
469
|
+
ret = 1
|
|
470
|
+
else:
|
|
471
|
+
ret = item.treeChildCount()
|
|
472
|
+
return ret
|
|
473
|
+
|
|
474
|
+
def getItemData(self, item, column, role):
|
|
475
|
+
if item is None:
|
|
476
|
+
return None
|
|
477
|
+
|
|
478
|
+
if role in (Qt.ItemDataRole.DisplayRole, Qt.ItemDataRole.EditRole):
|
|
479
|
+
return item.treeData(column)
|
|
480
|
+
|
|
481
|
+
elif role == Qt.ItemDataRole.CheckStateRole:
|
|
482
|
+
chk = None
|
|
483
|
+
if column == 0:
|
|
484
|
+
chk = item.treeChecked()
|
|
485
|
+
if chk is not None:
|
|
486
|
+
chk = Qt.CheckState.Checked if chk else Qt.CheckState.Unchecked
|
|
487
|
+
return chk
|
|
488
|
+
elif role == Qt.ItemDataRole.DecorationRole:
|
|
489
|
+
if column == 0:
|
|
490
|
+
return item.icon()
|
|
491
|
+
return None
|
|
492
|
+
|
|
493
|
+
def getItemAppendRow(self, item):
|
|
494
|
+
if isinstance(item, Combo):
|
|
495
|
+
# insert before the special "SHAPES" item
|
|
496
|
+
# getItemRowCount returns len(item.pairs) + 1
|
|
497
|
+
return len(item.pairs)
|
|
498
|
+
return self.getItemRowCount(item)
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
# VIEW MODELS
|
|
502
|
+
class BaseProxyModel(QSortFilterProxyModel):
|
|
503
|
+
"""Holds the common item/index translation code for my filter models
|
|
504
|
+
Again, This is just a concrete implementation of a Qt base class, so
|
|
505
|
+
documentation will be lacking
|
|
506
|
+
"""
|
|
507
|
+
|
|
508
|
+
def __init__(self, model, parent=None):
|
|
509
|
+
super(BaseProxyModel, self).__init__(parent)
|
|
510
|
+
self.setSourceModel(model)
|
|
511
|
+
|
|
512
|
+
def indexFromItem(self, item, column=0):
|
|
513
|
+
sourceModel = self.sourceModel()
|
|
514
|
+
sourceIndex = sourceModel.indexFromItem(item, column)
|
|
515
|
+
return self.mapFromSource(sourceIndex)
|
|
516
|
+
|
|
517
|
+
def itemFromIndex(self, index):
|
|
518
|
+
sourceModel = self.sourceModel()
|
|
519
|
+
sIndex = self.mapToSource(index)
|
|
520
|
+
return sourceModel.itemFromIndex(sIndex)
|
|
521
|
+
|
|
522
|
+
def invalidate(self):
|
|
523
|
+
source = self.sourceModel()
|
|
524
|
+
if isinstance(source, QSortFilterProxyModel):
|
|
525
|
+
source.invalidate()
|
|
526
|
+
super(BaseProxyModel, self).invalidate()
|
|
527
|
+
|
|
528
|
+
def invalidateFilter(self):
|
|
529
|
+
source = self.sourceModel()
|
|
530
|
+
if isinstance(source, QSortFilterProxyModel):
|
|
531
|
+
source.invalidateFilter()
|
|
532
|
+
super(BaseProxyModel, self).invalidateFilter()
|
|
533
|
+
|
|
534
|
+
def filterAcceptsRow(self, sourceRow, sourceParent):
|
|
535
|
+
return True
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
class SliderModel(BaseProxyModel):
|
|
539
|
+
def filterAcceptsRow(self, sourceRow, sourceParent):
|
|
540
|
+
sourceIndex = self.sourceModel().index(sourceRow, 0, sourceParent)
|
|
541
|
+
if sourceIndex.isValid():
|
|
542
|
+
item = self.sourceModel().itemFromIndex(sourceIndex)
|
|
543
|
+
if isinstance(item, Group):
|
|
544
|
+
if item.groupType is not Slider:
|
|
545
|
+
return False
|
|
546
|
+
return super(SliderModel, self).filterAcceptsRow(sourceRow, sourceParent)
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
class ComboModel(BaseProxyModel):
|
|
550
|
+
def filterAcceptsRow(self, sourceRow, sourceParent):
|
|
551
|
+
sourceIndex = self.sourceModel().index(sourceRow, 0, sourceParent)
|
|
552
|
+
if sourceIndex.isValid():
|
|
553
|
+
item = self.sourceModel().itemFromIndex(sourceIndex)
|
|
554
|
+
if isinstance(item, Group):
|
|
555
|
+
if item.groupType is not Combo:
|
|
556
|
+
return False
|
|
557
|
+
return super(ComboModel, self).filterAcceptsRow(sourceRow, sourceParent)
|
|
558
|
+
|
|
559
|
+
|
|
560
|
+
class TraversalModel(BaseProxyModel):
|
|
561
|
+
def filterAcceptsRow(self, sourceRow, sourceParent):
|
|
562
|
+
sourceIndex = self.sourceModel().index(sourceRow, 0, sourceParent)
|
|
563
|
+
if sourceIndex.isValid():
|
|
564
|
+
item = self.sourceModel().itemFromIndex(sourceIndex)
|
|
565
|
+
if isinstance(item, Group):
|
|
566
|
+
if item.groupType is not Traversal:
|
|
567
|
+
return False
|
|
568
|
+
return super(TraversalModel, self).filterAcceptsRow(sourceRow, sourceParent)
|
|
569
|
+
|
|
570
|
+
|
|
571
|
+
# FILTER MODELS
|
|
572
|
+
class SimplexFilterModel(BaseProxyModel):
|
|
573
|
+
"""Filter a model based off of a given string
|
|
574
|
+
Set the `filterString` object property to filter the model
|
|
575
|
+
"""
|
|
576
|
+
|
|
577
|
+
def __init__(self, model, parent=None):
|
|
578
|
+
super(SimplexFilterModel, self).__init__(model, parent)
|
|
579
|
+
self.setSourceModel(model)
|
|
580
|
+
self._filterString = []
|
|
581
|
+
self._filterReg = []
|
|
582
|
+
self.isolateList = []
|
|
583
|
+
|
|
584
|
+
@property
|
|
585
|
+
def filterString(self):
|
|
586
|
+
return " ".join(self._filterString)
|
|
587
|
+
|
|
588
|
+
@filterString.setter
|
|
589
|
+
def filterString(self, val):
|
|
590
|
+
self._filterString = val.split()
|
|
591
|
+
|
|
592
|
+
self._filterReg = []
|
|
593
|
+
for sp in self._filterString:
|
|
594
|
+
if sp[0] == "*":
|
|
595
|
+
self._filterReg.append(re.compile(sp, flags=re.I))
|
|
596
|
+
else:
|
|
597
|
+
self._filterReg.append(re.compile(".*?".join(sp), flags=re.I))
|
|
598
|
+
|
|
599
|
+
def filterAcceptsRow(self, sourceRow, sourceParent):
|
|
600
|
+
column = 0 # always sort by the first column #column = self.filterKeyColumn()
|
|
601
|
+
sourceIndex = self.sourceModel().index(sourceRow, column, sourceParent)
|
|
602
|
+
if sourceIndex.isValid():
|
|
603
|
+
if self.filterString or self.isolateList:
|
|
604
|
+
sourceItem = self.sourceModel().itemFromIndex(sourceIndex)
|
|
605
|
+
if isinstance(
|
|
606
|
+
sourceItem, (ProgPair, Slider, Combo, ComboPair, Progression)
|
|
607
|
+
):
|
|
608
|
+
if not self.checkChildren(sourceItem):
|
|
609
|
+
return False
|
|
610
|
+
|
|
611
|
+
return super(SimplexFilterModel, self).filterAcceptsRow(sourceRow, sourceParent)
|
|
612
|
+
|
|
613
|
+
def matchFilterString(self, itemString):
|
|
614
|
+
if not self._filterString:
|
|
615
|
+
return True
|
|
616
|
+
for reg in self._filterReg:
|
|
617
|
+
if reg.search(itemString):
|
|
618
|
+
return True
|
|
619
|
+
return False
|
|
620
|
+
|
|
621
|
+
def matchIsolation(self, itemString):
|
|
622
|
+
if self.isolateList:
|
|
623
|
+
return itemString in self.isolateList
|
|
624
|
+
return True
|
|
625
|
+
|
|
626
|
+
def checkChildren(self, sourceItem):
|
|
627
|
+
itemString = sourceItem.name
|
|
628
|
+
if self.matchFilterString(itemString) and self.matchIsolation(itemString):
|
|
629
|
+
return True
|
|
630
|
+
|
|
631
|
+
sourceModel = self.sourceModel().sourceModel()
|
|
632
|
+
for row in range(sourceModel.getItemRowCount(sourceItem)):
|
|
633
|
+
childItem = sourceModel.getChildItem(sourceItem, row)
|
|
634
|
+
if childItem is not None:
|
|
635
|
+
return self.checkChildren(childItem)
|
|
636
|
+
|
|
637
|
+
return False
|
|
638
|
+
|
|
639
|
+
|
|
640
|
+
class SliderFilterModel(SimplexFilterModel):
|
|
641
|
+
"""Hide single shapes under a slider"""
|
|
642
|
+
|
|
643
|
+
def __init__(self, model, parent=None):
|
|
644
|
+
super(SliderFilterModel, self).__init__(model, parent)
|
|
645
|
+
self.requires = []
|
|
646
|
+
self.filterRequiresAny = False
|
|
647
|
+
self.filterRequiresAll = False
|
|
648
|
+
|
|
649
|
+
self.doFilter = True
|
|
650
|
+
|
|
651
|
+
def filterAcceptsRow(self, sourceRow, sourceParent):
|
|
652
|
+
# always sort by the first column #column = self.filterKeyColumn()
|
|
653
|
+
column = 0
|
|
654
|
+
sourceIndex = self.sourceModel().index(sourceRow, column, sourceParent)
|
|
655
|
+
if sourceIndex.isValid():
|
|
656
|
+
data = self.sourceModel().itemFromIndex(sourceIndex)
|
|
657
|
+
if self.doFilter:
|
|
658
|
+
if isinstance(data, ProgPair):
|
|
659
|
+
if len(data.prog.pairs) <= 2:
|
|
660
|
+
return False
|
|
661
|
+
elif data.shape.isRest:
|
|
662
|
+
return False
|
|
663
|
+
|
|
664
|
+
if (self.filterRequiresAny or self.filterRequiresAll) and self.requires:
|
|
665
|
+
# Ignore items that aren't part of the required combos, if requested
|
|
666
|
+
if isinstance(data, Slider):
|
|
667
|
+
sliGroups = [[i.slider for i in c.pairs] for c in self.requires]
|
|
668
|
+
if self.filterRequiresAny:
|
|
669
|
+
if not any(data in s for s in sliGroups):
|
|
670
|
+
return False
|
|
671
|
+
elif self.filterRequiresAll:
|
|
672
|
+
if not all(data in s for s in sliGroups):
|
|
673
|
+
return False
|
|
674
|
+
|
|
675
|
+
return super(SliderFilterModel, self).filterAcceptsRow(sourceRow, sourceParent)
|
|
676
|
+
|
|
677
|
+
|
|
678
|
+
class ComboFilterModel(SimplexFilterModel):
|
|
679
|
+
"""Filter by slider when Show Dependent Combos is checked"""
|
|
680
|
+
|
|
681
|
+
def __init__(self, model, parent=None):
|
|
682
|
+
super(ComboFilterModel, self).__init__(model, parent)
|
|
683
|
+
self.requires = []
|
|
684
|
+
self.filterRequiresAll = False
|
|
685
|
+
self.filterRequiresAny = False
|
|
686
|
+
self.filterRequiresOnly = False
|
|
687
|
+
|
|
688
|
+
self.filterShapes = True
|
|
689
|
+
|
|
690
|
+
def filterAcceptsRow(self, sourceRow, sourceParent):
|
|
691
|
+
# always sort by the first column #column = self.filterKeyColumn()
|
|
692
|
+
column = 0
|
|
693
|
+
sourceIndex = self.sourceModel().index(sourceRow, column, sourceParent)
|
|
694
|
+
if sourceIndex.isValid():
|
|
695
|
+
data = self.sourceModel().itemFromIndex(sourceIndex)
|
|
696
|
+
if self.filterShapes:
|
|
697
|
+
# ignore the SHAPE par if there's nothing under there
|
|
698
|
+
if isinstance(data, Progression):
|
|
699
|
+
if len(data.pairs) <= 2:
|
|
700
|
+
return False
|
|
701
|
+
# Ignore shape things if requested
|
|
702
|
+
if isinstance(data, ProgPair):
|
|
703
|
+
if len(data.prog.pairs) <= 2:
|
|
704
|
+
return False
|
|
705
|
+
elif data.shape.isRest:
|
|
706
|
+
return False
|
|
707
|
+
if (
|
|
708
|
+
self.filterRequiresAny
|
|
709
|
+
or self.filterRequiresAll
|
|
710
|
+
or self.filterRequiresOnly
|
|
711
|
+
) and self.requires:
|
|
712
|
+
# Ignore items that don't use the required sliders if requested
|
|
713
|
+
if isinstance(data, Combo):
|
|
714
|
+
sliders = [i.slider for i in data.pairs]
|
|
715
|
+
if self.filterRequiresAll:
|
|
716
|
+
if not all(r in sliders for r in self.requires):
|
|
717
|
+
return False
|
|
718
|
+
elif self.filterRequiresAny:
|
|
719
|
+
if not any(r in sliders for r in self.requires):
|
|
720
|
+
return False
|
|
721
|
+
elif self.filterRequiresOnly:
|
|
722
|
+
if not all(r in self.requires for r in sliders):
|
|
723
|
+
return False
|
|
724
|
+
|
|
725
|
+
return super(ComboFilterModel, self).filterAcceptsRow(sourceRow, sourceParent)
|
|
726
|
+
|
|
727
|
+
|
|
728
|
+
class TraversalFilterModel(SimplexFilterModel):
|
|
729
|
+
"""Hide single shapes under a slider"""
|
|
730
|
+
|
|
731
|
+
def __init__(self, model, parent=None):
|
|
732
|
+
super(TraversalFilterModel, self).__init__(model, parent)
|
|
733
|
+
self.doFilter = True
|
|
734
|
+
|
|
735
|
+
def filterAcceptsRow(self, sourceRow, sourceParent):
|
|
736
|
+
column = 0 # always sort by the first column #column = self.filterKeyColumn()
|
|
737
|
+
sourceIndex = self.sourceModel().index(sourceRow, column, sourceParent)
|
|
738
|
+
if sourceIndex.isValid():
|
|
739
|
+
if self.doFilter:
|
|
740
|
+
data = self.sourceModel().itemFromIndex(sourceIndex)
|
|
741
|
+
if isinstance(data, ProgPair):
|
|
742
|
+
if len(data.prog.pairs) <= 2:
|
|
743
|
+
return False
|
|
744
|
+
elif data.shape.isRest:
|
|
745
|
+
return False
|
|
746
|
+
|
|
747
|
+
return super(TraversalFilterModel, self).filterAcceptsRow(
|
|
748
|
+
sourceRow, sourceParent
|
|
749
|
+
)
|
|
750
|
+
|
|
751
|
+
|
|
752
|
+
# SETTINGS MODELS
|
|
753
|
+
class SliderGroupModel(ContextModel):
|
|
754
|
+
"""A model for displaying Group objects that contain Sliders"""
|
|
755
|
+
|
|
756
|
+
def __init__(self, simplex, parent):
|
|
757
|
+
super(SliderGroupModel, self).__init__(parent)
|
|
758
|
+
self.simplex = simplex
|
|
759
|
+
self.simplex.models.append(self)
|
|
760
|
+
|
|
761
|
+
def getItemRow(self, item):
|
|
762
|
+
try:
|
|
763
|
+
idx = self.simplex.sliderGroups.index(item)
|
|
764
|
+
except ValueError:
|
|
765
|
+
return None
|
|
766
|
+
return idx + 1
|
|
767
|
+
|
|
768
|
+
def getItemAppendRow(self, item):
|
|
769
|
+
return len(self.simplex.sliderGroups) + 1
|
|
770
|
+
|
|
771
|
+
def index(self, row, column=0, parIndex=None):
|
|
772
|
+
parIndex = QModelIndex() if parIndex is None else parIndex
|
|
773
|
+
if row <= 0:
|
|
774
|
+
return self.createIndex(row, column, None)
|
|
775
|
+
try:
|
|
776
|
+
falloff = self.simplex.sliderGroups[row - 1]
|
|
777
|
+
except IndexError:
|
|
778
|
+
return QModelIndex()
|
|
779
|
+
return self.createIndex(row, column, falloff)
|
|
780
|
+
|
|
781
|
+
def parent(self, index):
|
|
782
|
+
return QModelIndex()
|
|
783
|
+
|
|
784
|
+
def rowCount(self, parent):
|
|
785
|
+
return len(self.simplex.sliderGroups) + 1
|
|
786
|
+
|
|
787
|
+
def columnCount(self, parent):
|
|
788
|
+
return 1
|
|
789
|
+
|
|
790
|
+
def data(self, index, role):
|
|
791
|
+
if not index.isValid():
|
|
792
|
+
return None
|
|
793
|
+
group = index.internalPointer()
|
|
794
|
+
if group and role in (Qt.ItemDataRole.DisplayRole, Qt.ItemDataRole.EditRole):
|
|
795
|
+
return group.name
|
|
796
|
+
return None
|
|
797
|
+
|
|
798
|
+
def flags(self, index):
|
|
799
|
+
return Qt.ItemFlag.ItemIsEnabled | Qt.ItemFlag.ItemIsSelectable
|
|
800
|
+
|
|
801
|
+
def itemFromIndex(self, index):
|
|
802
|
+
return index.internalPointer()
|
|
803
|
+
|
|
804
|
+
|
|
805
|
+
class FalloffModel(ContextModel):
|
|
806
|
+
"""A model for displaying Falloff objects connected to Sliders"""
|
|
807
|
+
|
|
808
|
+
def __init__(self, simplex, parent):
|
|
809
|
+
super(FalloffModel, self).__init__(parent)
|
|
810
|
+
self.simplex = simplex
|
|
811
|
+
if self.simplex is not None:
|
|
812
|
+
self.simplex.falloffModels.append(self)
|
|
813
|
+
self.sliders = []
|
|
814
|
+
self._checks = {}
|
|
815
|
+
self.line = ""
|
|
816
|
+
|
|
817
|
+
def setSliders(self, sliders):
|
|
818
|
+
self.beginResetModel()
|
|
819
|
+
self.sliders = sliders
|
|
820
|
+
self._checks = {}
|
|
821
|
+
for slider in self.sliders:
|
|
822
|
+
for fo in slider.prog.falloffs:
|
|
823
|
+
self._checks.setdefault(fo, []).append(slider)
|
|
824
|
+
self.endResetModel()
|
|
825
|
+
self.buildLine()
|
|
826
|
+
|
|
827
|
+
def buildLine(self):
|
|
828
|
+
if not self.sliders:
|
|
829
|
+
self.line = ""
|
|
830
|
+
return
|
|
831
|
+
fulls = []
|
|
832
|
+
partials = []
|
|
833
|
+
for fo in self.simplex.falloffs:
|
|
834
|
+
cs = self._getCheckState(fo)
|
|
835
|
+
if cs == Qt.CheckState.Checked:
|
|
836
|
+
fulls.append(fo.name)
|
|
837
|
+
elif cs == Qt.CheckState.PartiallyChecked:
|
|
838
|
+
partials.append(fo.name)
|
|
839
|
+
if partials:
|
|
840
|
+
title = "{0} <<{1}>>".format(",".join(fulls), ",".join(partials))
|
|
841
|
+
else:
|
|
842
|
+
title = ",".join(fulls)
|
|
843
|
+
self.line = title
|
|
844
|
+
|
|
845
|
+
def getItemRow(self, item):
|
|
846
|
+
try:
|
|
847
|
+
idx = self.simplex.falloffs.index(item)
|
|
848
|
+
except ValueError:
|
|
849
|
+
return None
|
|
850
|
+
except AttributeError:
|
|
851
|
+
return None
|
|
852
|
+
return idx + 1
|
|
853
|
+
|
|
854
|
+
def getItemAppendRow(self, item):
|
|
855
|
+
try:
|
|
856
|
+
return len(self.simplex.falloffs)
|
|
857
|
+
except AttributeError:
|
|
858
|
+
return 0
|
|
859
|
+
|
|
860
|
+
def index(self, row, column=0, parIndex=None):
|
|
861
|
+
parIndex = QModelIndex() if parIndex is None else parIndex
|
|
862
|
+
if row <= 0:
|
|
863
|
+
return self.createIndex(row, column, None)
|
|
864
|
+
try:
|
|
865
|
+
falloff = self.simplex.falloffs[row - 1]
|
|
866
|
+
except IndexError:
|
|
867
|
+
return QModelIndex()
|
|
868
|
+
except AttributeError:
|
|
869
|
+
return QModelIndex()
|
|
870
|
+
return self.createIndex(row, column, falloff)
|
|
871
|
+
|
|
872
|
+
def parent(self, index):
|
|
873
|
+
return QModelIndex()
|
|
874
|
+
|
|
875
|
+
def rowCount(self, parent):
|
|
876
|
+
try:
|
|
877
|
+
return len(self.simplex.falloffs) + 1
|
|
878
|
+
except AttributeError:
|
|
879
|
+
return 0
|
|
880
|
+
|
|
881
|
+
def columnCount(self, parent):
|
|
882
|
+
return 1
|
|
883
|
+
|
|
884
|
+
def _getCheckState(self, fo):
|
|
885
|
+
sli = self._checks.get(fo, [])
|
|
886
|
+
if len(sli) == len(self.sliders):
|
|
887
|
+
return Qt.CheckState.Checked
|
|
888
|
+
elif len(sli) == 0:
|
|
889
|
+
return Qt.CheckState.Unchecked
|
|
890
|
+
return Qt.CheckState.PartiallyChecked
|
|
891
|
+
|
|
892
|
+
def data(self, index, role):
|
|
893
|
+
if not index.isValid():
|
|
894
|
+
return None
|
|
895
|
+
falloff = index.internalPointer()
|
|
896
|
+
if not falloff:
|
|
897
|
+
return None
|
|
898
|
+
|
|
899
|
+
if role in (Qt.ItemDataRole.DisplayRole, Qt.ItemDataRole.EditRole):
|
|
900
|
+
return falloff.name
|
|
901
|
+
elif role == Qt.ItemDataRole.CheckStateRole:
|
|
902
|
+
return self._getCheckState(falloff)
|
|
903
|
+
return None
|
|
904
|
+
|
|
905
|
+
def setData(self, index, value, role):
|
|
906
|
+
if role == Qt.ItemDataRole.CheckStateRole:
|
|
907
|
+
fo = index.internalPointer()
|
|
908
|
+
if not fo:
|
|
909
|
+
return
|
|
910
|
+
if value == Qt.CheckState.Checked:
|
|
911
|
+
for s in self.sliders:
|
|
912
|
+
if fo not in s.prog.falloffs:
|
|
913
|
+
s.prog.addFalloff(fo)
|
|
914
|
+
self._checks.setdefault(fo, []).append(s)
|
|
915
|
+
elif value == Qt.CheckState.Unchecked:
|
|
916
|
+
for s in self.sliders:
|
|
917
|
+
if fo in s.prog.falloffs:
|
|
918
|
+
s.prog.removeFalloff(fo)
|
|
919
|
+
if s in self._checks[fo]:
|
|
920
|
+
self._checks[fo].remove(s)
|
|
921
|
+
self.buildLine()
|
|
922
|
+
self.emitDataChanged(index)
|
|
923
|
+
return True
|
|
924
|
+
return False
|
|
925
|
+
|
|
926
|
+
def flags(self, index):
|
|
927
|
+
return (
|
|
928
|
+
Qt.ItemFlag.ItemIsEnabled
|
|
929
|
+
| Qt.ItemFlag.ItemIsEditable
|
|
930
|
+
| Qt.ItemFlag.ItemIsUserCheckable
|
|
931
|
+
)
|
|
932
|
+
|
|
933
|
+
def itemFromIndex(self, index):
|
|
934
|
+
return index.internalPointer()
|
|
935
|
+
|
|
936
|
+
|
|
937
|
+
class FalloffDataModel(ContextModel):
|
|
938
|
+
"""A model for displaying the data of Falloff objects"""
|
|
939
|
+
|
|
940
|
+
def __init__(self, simplex, parent):
|
|
941
|
+
super(FalloffDataModel, self).__init__(parent)
|
|
942
|
+
self.simplex = simplex
|
|
943
|
+
if self.simplex is not None:
|
|
944
|
+
self.simplex.falloffModels.append(self)
|
|
945
|
+
|
|
946
|
+
def getItemAppendRow(self, item):
|
|
947
|
+
try:
|
|
948
|
+
return len(self.simplex.falloffs)
|
|
949
|
+
except AttributeError:
|
|
950
|
+
return 0
|
|
951
|
+
|
|
952
|
+
def index(self, row, column=0, parIndex=None):
|
|
953
|
+
parIndex = QModelIndex() if parIndex is None else parIndex
|
|
954
|
+
if row < 0:
|
|
955
|
+
return QModelIndex()
|
|
956
|
+
try:
|
|
957
|
+
falloff = self.simplex.falloffs[row]
|
|
958
|
+
except IndexError:
|
|
959
|
+
return QModelIndex()
|
|
960
|
+
except AttributeError:
|
|
961
|
+
return QModelIndex()
|
|
962
|
+
return self.createIndex(row, column, falloff)
|
|
963
|
+
|
|
964
|
+
def parent(self, index):
|
|
965
|
+
return QModelIndex()
|
|
966
|
+
|
|
967
|
+
def rowCount(self, parent):
|
|
968
|
+
try:
|
|
969
|
+
return len(self.simplex.falloffs)
|
|
970
|
+
except AttributeError:
|
|
971
|
+
return 0
|
|
972
|
+
|
|
973
|
+
def columnCount(self, parent):
|
|
974
|
+
return 8
|
|
975
|
+
|
|
976
|
+
def data(self, index, role):
|
|
977
|
+
if not index.isValid():
|
|
978
|
+
return None
|
|
979
|
+
falloff = index.internalPointer()
|
|
980
|
+
if not falloff:
|
|
981
|
+
return None
|
|
982
|
+
|
|
983
|
+
if role in (Qt.ItemDataRole.DisplayRole, Qt.ItemDataRole.EditRole):
|
|
984
|
+
if index.column() == 0:
|
|
985
|
+
return falloff.name
|
|
986
|
+
elif index.column() == 1:
|
|
987
|
+
st = falloff.splitType
|
|
988
|
+
sti = ("planar", "map").index(st.lower())
|
|
989
|
+
return sti
|
|
990
|
+
elif index.column() == 2:
|
|
991
|
+
ax = falloff.axis
|
|
992
|
+
axi = "xyz".index(ax.lower())
|
|
993
|
+
return axi
|
|
994
|
+
elif index.column() == 3:
|
|
995
|
+
return falloff.maxVal
|
|
996
|
+
elif index.column() == 4:
|
|
997
|
+
return falloff.maxHandle
|
|
998
|
+
elif index.column() == 5:
|
|
999
|
+
return falloff.minHandle
|
|
1000
|
+
elif index.column() == 6:
|
|
1001
|
+
return falloff.minVal
|
|
1002
|
+
elif index.column() == 7:
|
|
1003
|
+
return falloff.mapName
|
|
1004
|
+
return None
|
|
1005
|
+
|
|
1006
|
+
def setData(self, index, value, role):
|
|
1007
|
+
if not index.isValid():
|
|
1008
|
+
return False
|
|
1009
|
+
falloff = index.internalPointer()
|
|
1010
|
+
if not falloff:
|
|
1011
|
+
return False
|
|
1012
|
+
if role == Qt.ItemDataRole.EditRole:
|
|
1013
|
+
if index.column() == 0:
|
|
1014
|
+
falloff.name = value
|
|
1015
|
+
elif index.column() == 1:
|
|
1016
|
+
if value in [0, 1]:
|
|
1017
|
+
value = ("planar", "map")[value]
|
|
1018
|
+
falloff.splitType = value
|
|
1019
|
+
elif index.column() == 2:
|
|
1020
|
+
if value in [0, 1, 2]:
|
|
1021
|
+
value = "XYZ"[value]
|
|
1022
|
+
falloff.axis = value
|
|
1023
|
+
elif index.column() == 3:
|
|
1024
|
+
falloff.maxVal = value
|
|
1025
|
+
elif index.column() == 4:
|
|
1026
|
+
falloff.maxHandle = value
|
|
1027
|
+
elif index.column() == 5:
|
|
1028
|
+
falloff.minHandle = value
|
|
1029
|
+
elif index.column() == 6:
|
|
1030
|
+
falloff.minVal = value
|
|
1031
|
+
elif index.column() == 7:
|
|
1032
|
+
falloff.mapName = value
|
|
1033
|
+
return True
|
|
1034
|
+
return False
|
|
1035
|
+
|
|
1036
|
+
def flags(self, index):
|
|
1037
|
+
return (
|
|
1038
|
+
Qt.ItemFlag.ItemIsEnabled
|
|
1039
|
+
| Qt.ItemFlag.ItemIsEditable
|
|
1040
|
+
| Qt.ItemFlag.ItemIsSelectable
|
|
1041
|
+
)
|
|
1042
|
+
|
|
1043
|
+
def itemFromIndex(self, index):
|
|
1044
|
+
return index.internalPointer()
|
|
1045
|
+
|
|
1046
|
+
def getItemRow(self, item):
|
|
1047
|
+
try:
|
|
1048
|
+
idx = self.simplex.falloffs.index(item)
|
|
1049
|
+
except ValueError:
|
|
1050
|
+
return None
|
|
1051
|
+
except AttributeError:
|
|
1052
|
+
return None
|
|
1053
|
+
return idx
|