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.
Files changed (79) hide show
  1. simplex_solver-3.1.0.dist-info/METADATA +90 -0
  2. simplex_solver-3.1.0.dist-info/RECORD +79 -0
  3. simplex_solver-3.1.0.dist-info/WHEEL +5 -0
  4. simplexui/__init__.py +53 -0
  5. simplexui/_version.py +1 -0
  6. simplexui/channelBox.py +858 -0
  7. simplexui/comboCheckDialog.py +343 -0
  8. simplexui/commands/__init__.py +16 -0
  9. simplexui/commands/alembicCommon.py +991 -0
  10. simplexui/commands/applyCorrectives.py +451 -0
  11. simplexui/commands/correctiveInterface.py +261 -0
  12. simplexui/commands/expandedExport.py +436 -0
  13. simplexui/commands/hdf5Convert.py +60 -0
  14. simplexui/commands/mayaCorrectiveInterface.py +161 -0
  15. simplexui/commands/mayatonumpy.py +375 -0
  16. simplexui/commands/mesh.py +1081 -0
  17. simplexui/commands/numpytoimath.py +319 -0
  18. simplexui/commands/poseblendlib.py +166 -0
  19. simplexui/commands/reorderSimplexPoints.py +102 -0
  20. simplexui/commands/rigidAlign.py +99 -0
  21. simplexui/commands/smpxBlend.py +629 -0
  22. simplexui/commands/unsubdivide.py +1227 -0
  23. simplexui/commands/uvTransfer.py +977 -0
  24. simplexui/dragFilter.py +299 -0
  25. simplexui/falloffDialog.py +471 -0
  26. simplexui/img/ChefHead.png +0 -0
  27. simplexui/img/frozen.png +0 -0
  28. simplexui/interface/__init__.py +28 -0
  29. simplexui/interface/dummyInterface.py +1585 -0
  30. simplexui/interface/mayaInterface.py +3271 -0
  31. simplexui/interfaceModel.py +1053 -0
  32. simplexui/interfaceModelTrees.py +441 -0
  33. simplexui/items/__init__.py +42 -0
  34. simplexui/items/accessor.py +213 -0
  35. simplexui/items/combo.py +852 -0
  36. simplexui/items/falloff.py +778 -0
  37. simplexui/items/group.py +297 -0
  38. simplexui/items/progression.py +743 -0
  39. simplexui/items/shape.py +443 -0
  40. simplexui/items/simplex.py +1764 -0
  41. simplexui/items/slider.py +738 -0
  42. simplexui/items/stack.py +154 -0
  43. simplexui/items/traversal.py +966 -0
  44. simplexui/main.pyw +22 -0
  45. simplexui/menu/__init__.py +69 -0
  46. simplexui/menu/dummyPlugins/__init__.py +16 -0
  47. simplexui/menu/genericPlugins/__init__.py +16 -0
  48. simplexui/menu/genericPlugins/_builtins.py +268 -0
  49. simplexui/menu/genericPlugins/checkPossibleCombos.py +45 -0
  50. simplexui/menu/genericPlugins/exportSplit.py +59 -0
  51. simplexui/menu/genericPlugins/showFalloffs.py +24 -0
  52. simplexui/menu/genericPlugins/showTraversals.py +24 -0
  53. simplexui/menu/genericPlugins/simplexUvTransfer.py +107 -0
  54. simplexui/menu/genericPlugins/unsubdivide.py +70 -0
  55. simplexui/menu/mayaPlugins/__init__.py +16 -0
  56. simplexui/menu/mayaPlugins/exportOther.py +43 -0
  57. simplexui/menu/mayaPlugins/extractProgressives.py +65 -0
  58. simplexui/menu/mayaPlugins/freezeCombo.py +245 -0
  59. simplexui/menu/mayaPlugins/generateShapeIncrementals.py +97 -0
  60. simplexui/menu/mayaPlugins/importObjs.py +193 -0
  61. simplexui/menu/mayaPlugins/linearizeTraversal.py +48 -0
  62. simplexui/menu/mayaPlugins/makeShelfBtn.py +65 -0
  63. simplexui/menu/mayaPlugins/relaxToSelection.py +75 -0
  64. simplexui/menu/mayaPlugins/reloadDefinition.py +33 -0
  65. simplexui/menu/mayaPlugins/snapToNeutral.py +72 -0
  66. simplexui/menu/mayaPlugins/softSelectToCluster.py +200 -0
  67. simplexui/menu/mayaPlugins/tweakMix.py +134 -0
  68. simplexui/menu/mayaPlugins/updateRestShape.py +105 -0
  69. simplexui/pysimplex.dll.a +0 -0
  70. simplexui/pysimplex.pyd +0 -0
  71. simplexui/simplexDialog.py +1454 -0
  72. simplexui/travCheckDialog.py +397 -0
  73. simplexui/traversalDialog.py +271 -0
  74. simplexui/ui/comboCheckDialog.ui +475 -0
  75. simplexui/ui/falloffDialog.ui +243 -0
  76. simplexui/ui/simplexDialog.ui +1458 -0
  77. simplexui/ui/travCheckDialog.ui +488 -0
  78. simplexui/ui/traversalDialog.ui +532 -0
  79. simplexui/utils.py +320 -0
@@ -0,0 +1,1454 @@
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
+
19
+ # Ignore a bunch of linter warnings that show up because of my choice of abstraction
20
+ # pylint: disable=unused-argument,too-many-public-methods,relative-import
21
+ # pylint: disable=too-many-statements,no-self-use,missing-docstring
22
+ import json
23
+ import os
24
+ import re
25
+ import sys
26
+ import weakref
27
+ from contextlib import contextmanager
28
+
29
+ from .comboCheckDialog import ComboCheckDialog
30
+ from .falloffDialog import FalloffDialog
31
+ from .interface import DCC
32
+ from .interfaceModel import (
33
+ ComboFilterModel,
34
+ ComboModel,
35
+ SimplexModel,
36
+ SliderFilterModel,
37
+ SliderModel,
38
+ coerceIndexToChildType,
39
+ coerceIndexToParentType,
40
+ coerceIndexToRoots,
41
+ )
42
+ from .interfaceModelTrees import ComboTree, SliderTree
43
+ from .items import Combo, Group, ProgPair, Simplex, Slider, Stack
44
+ from .menu import buildToolMenu, loadPlugins
45
+
46
+ # This module imports QT from PyQt4, PySide or PySide2
47
+ # Depending on what's available
48
+ from Qt import QtCompat
49
+ from Qt.QtCore import Qt, Signal
50
+ from Qt.QtGui import QStandardItemModel
51
+ from Qt.QtWidgets import QApplication, QInputDialog, QMessageBox, QProgressDialog
52
+ from .traversalDialog import TraversalDialog
53
+ from .utils import getNextName, getUiFile, makeUnique, naturalSortKey, Prefs
54
+
55
+ if os.environ.get("SIMPLEX_AT_BLUR") == "true":
56
+ # If we're at blur, use our main window subclass
57
+ from blurdev.gui import Window
58
+ else:
59
+ from Qt.QtWidgets import QMainWindow as Window
60
+
61
+ NAME_CHECK = re.compile(r"[A-Za-z][\w.]*")
62
+
63
+ # If the decorated method is a slot for some Qt Signal
64
+ # and the method signature is *NOT* the same as the
65
+ # signal signature, you must double decorate the method like:
66
+ #
67
+ # @Slot(**signature)
68
+ # @stackable
69
+ # def method(**signature)
70
+
71
+
72
+ @contextmanager
73
+ def signalsBlocked(item):
74
+ """Context manager to block the qt signals on an item"""
75
+ item.blockSignals(True)
76
+ try:
77
+ yield
78
+ finally:
79
+ item.blockSignals(False)
80
+
81
+
82
+ class SimplexDialog(Window):
83
+ """The main ui for simplex
84
+
85
+ Parameters
86
+ ----------
87
+ parent : QWidget
88
+ The parent for this window
89
+ dispatch : Dispatch
90
+ An object that translates DCC events into
91
+ Qt Signals that the Simplex Ui can understand
92
+
93
+ """
94
+
95
+ simplexLoaded = Signal()
96
+ openedDialogs = []
97
+
98
+ def __init__(self, parent=None, dispatch=None):
99
+ super(SimplexDialog, self).__init__(parent)
100
+
101
+ uiPath = getUiFile(__file__)
102
+ QtCompat.loadUi(uiPath, self)
103
+
104
+ # Custom widgets aren't working properly, so I bring them in manually
105
+ self.uiSliderTREE = SliderTree(self.uiMainShapesGRP)
106
+ self.uiSliderTREE.setDragEnabled(False)
107
+ self.uiSliderTREE.setDragDropMode(SliderTree.NoDragDrop)
108
+ self.uiSliderTREE.setSelectionMode(SliderTree.ExtendedSelection)
109
+ self.uiSliderTREE.dragFilter.dragPressed.connect(self.dragStart)
110
+ self.uiSliderTREE.dragFilter.dragReleased.connect(self.dragStop)
111
+
112
+ self.uiSliderLAY.addWidget(self.uiSliderTREE)
113
+
114
+ self.uiComboTREE = ComboTree(self.uiComboShapesGRP)
115
+ self.uiComboTREE.setDragEnabled(False)
116
+ self.uiComboTREE.setDragDropMode(ComboTree.NoDragDrop)
117
+ self.uiComboTREE.setSelectionMode(ComboTree.ExtendedSelection)
118
+ self.uiComboTREE.dragFilter.dragPressed.connect(self.dragStart)
119
+ self.uiComboTREE.dragFilter.dragReleased.connect(self.dragStop)
120
+ self.uiComboLAY.addWidget(self.uiComboTREE)
121
+
122
+ self._sliderMenu = None
123
+ self._comboMenu = None
124
+ self._currentObject = None
125
+ self._currentObjectName = None
126
+
127
+ # Connect the combo boxes and spinners to the data model
128
+ # TODO: Figure out how to deal with the type/axis "enum" cboxes
129
+ # see: http://doc.qt.io/qt-5/qtwidgets-itemviews-combowidgetmapper-example.html
130
+ """
131
+ self._falloffMapper = QDataWidgetMapper()
132
+ self.uiShapeFalloffCBOX.currentIndexChanged.connect(self._falloffMapper.setCurrentIndex)
133
+ """
134
+
135
+ # Make sure to connect the dispatcher to the undo control
136
+ # but only keep a weakref to it
137
+ self.dispatch = None
138
+ if dispatch is not None:
139
+ self.dispatch = weakref.ref(dispatch)
140
+ dispatch.undo.connect(self.handleUndo)
141
+ dispatch.redo.connect(self.handleUndo)
142
+ dispatch.beforeNew.connect(self.newScene)
143
+ dispatch.beforeOpen.connect(self.newScene)
144
+
145
+ self.simplex = None
146
+
147
+ self._itemMap = {}
148
+ self._sliderTreeMap = {}
149
+ self._comboTreeMap = {}
150
+
151
+ self._sliderDrag = None
152
+ self._comboDrag = None
153
+
154
+ self.uiSliderExitIsolateBTN.hide()
155
+ self.uiComboExitIsolateBTN.hide()
156
+
157
+ self._makeConnections()
158
+
159
+ self._toolPlugins, self._contextPlugins = loadPlugins()
160
+ buildToolMenu(self, self._toolPlugins)
161
+ self.uiSliderTREE.setPlugins(self._contextPlugins)
162
+ self.uiComboTREE.setPlugins(self._contextPlugins)
163
+
164
+ if DCC.program == "dummy":
165
+ # self.getSelectedObject()
166
+ self.uiObjectGRP.setEnabled(False)
167
+ self.uiSystemGRP.setEnabled(False)
168
+
169
+ self.uiClearSelectedObjectBTN.hide()
170
+ self.uiMainShapesGRP.setEnabled(False)
171
+ self.uiComboShapesGRP.setEnabled(False)
172
+ self.uiConnectionGroupWID.setEnabled(False)
173
+ self.loadSettings()
174
+ self._sliderMul = 2.0 if self.uiDoubleSliderRangeACT.isChecked() else 1.0
175
+
176
+ self.travDialog = TraversalDialog(self)
177
+ self.falloffDialog = FalloffDialog(self)
178
+ # self.showTraversalDialog()
179
+ type(self).openedDialogs.append(weakref.ref(self))
180
+
181
+ @classmethod
182
+ def lastOpenedDialog(cls):
183
+ """Returns the last currently opened dialog that still exists"""
184
+ for dlgRef in reversed(cls.openedDialogs):
185
+ dlg = dlgRef()
186
+ if dlg is not None:
187
+ return dlg
188
+ return None
189
+
190
+ def showTraversalDialog(self):
191
+ """Display the traversal dialog"""
192
+ self.travDialog.show()
193
+ self.travDialog.setGeometry(30, 30, 400, 400)
194
+
195
+ def showFalloffDialog(self):
196
+ """Display the Falloff Dialog"""
197
+ self.falloffDialog.show()
198
+ pp = self.falloffDialog.pos()
199
+ x, y = pp.x(), pp.y()
200
+ if x < 0 or y < 0:
201
+ self.falloffDialog.move(max(x, 0), max(y, 0))
202
+
203
+ def dragStart(self):
204
+ """Slot for handling the start of a MMB Drag event"""
205
+ if self.simplex is not None:
206
+ self.simplex.DCC.undoOpen()
207
+
208
+ def dragStop(self):
209
+ """Slot for handling the end of a MMB Drag event"""
210
+ if self.simplex is not None:
211
+ self.simplex.DCC.undoClose()
212
+
213
+ def storeSettings(self):
214
+ """Store the state of the UI for the next run"""
215
+ pref = Prefs()
216
+ pref.recordProperty("geometry", self.saveGeometry())
217
+ pref.save()
218
+
219
+ def loadSettings(self):
220
+ """Load the state of the UI from a previous run"""
221
+ pref = Prefs()
222
+ geo = pref.restoreProperty("geometry", None)
223
+ if geo is not None:
224
+ self.restoreGeometry(geo)
225
+
226
+ def closeEvent(self, event):
227
+ """Handle the close event"""
228
+ self.storeSettings()
229
+ self.deleteLater()
230
+
231
+ # Undo/Redo
232
+ def newScene(self):
233
+ """Call this before a new scene is created. Usually called from the stack"""
234
+ self.clearSelectedObject()
235
+
236
+ def handleUndo(self):
237
+ """Call this after an undo/redo action. Usually called from the stack"""
238
+ rev = self.simplex.DCC.getRevision()
239
+ data = self.simplex.stack.getRevision(rev)
240
+ if data is not None:
241
+ self.setSystem(data)
242
+ self.uiSliderTREE.setItemExpansion()
243
+ self.uiComboTREE.setItemExpansion()
244
+
245
+ def currentSystemChanged(self, idx):
246
+ """Slot called when the current system changes"""
247
+ if idx == -1:
248
+ self.setSystem(None)
249
+ return
250
+ name = str(self.uiCurrentSystemCBOX.currentText())
251
+ if not name:
252
+ self.setSystem(None)
253
+ return
254
+ if self.simplex is not None:
255
+ if self.simplex.name == name:
256
+ return # Do nothing
257
+
258
+ pBar = QProgressDialog("Loading from Mesh", "Cancel", 0, 100, self)
259
+ system = Simplex.buildSystemFromMesh(
260
+ self._currentObject, name, sliderMul=self._sliderMul, pBar=pBar
261
+ )
262
+ self.setSystem(system)
263
+ pBar.close()
264
+
265
+ def setSystem(self, system):
266
+ """Set the system on this UI
267
+
268
+ Parameters
269
+ ----------
270
+ system : Simplex
271
+ The Simplex system to load into this UI
272
+ """
273
+ if system == self.simplex:
274
+ return
275
+
276
+ if self.simplex is not None:
277
+ # disconnect the previous stuff
278
+ sliderSelModel = self.uiSliderTREE.selectionModel()
279
+ sliderSelModel.selectionChanged.disconnect(self.unifySliderSelection)
280
+ sliderSelModel.selectionChanged.disconnect(self.populateComboRequirements)
281
+ sliderSelModel.selectionChanged.disconnect(self.autoSetSliders)
282
+
283
+ comboSelModel = self.uiComboTREE.selectionModel()
284
+ comboSelModel.selectionChanged.disconnect(self.unifyComboSelection)
285
+ comboSelModel.selectionChanged.disconnect(self.populateSliderRequirements)
286
+ comboSelModel.selectionChanged.disconnect(self.autoSetComboSliders)
287
+
288
+ oldStack = self.simplex.stack
289
+ else:
290
+ oldStack = Stack()
291
+
292
+ if system is None:
293
+ # self.toolActions.simplex = None
294
+ self.uiSliderTREE.setModel(QStandardItemModel())
295
+ self.uiComboTREE.setModel(QStandardItemModel())
296
+ self.simplex = system
297
+ self.uiMainShapesGRP.setEnabled(False)
298
+ self.uiComboShapesGRP.setEnabled(False)
299
+ self.uiConnectionGroupWID.setEnabled(False)
300
+ self.falloffDialog.loadSimplex()
301
+ self.simplexLoaded.emit()
302
+ return
303
+
304
+ # set and connect the new stuff
305
+ self.simplex = system
306
+ self.simplex.models = []
307
+ self.simplex.falloffModels = []
308
+ self.simplex.stack = oldStack
309
+
310
+ # self.toolActions.simplex = self.simplex
311
+
312
+ simplexModel = SimplexModel(self.simplex, None)
313
+
314
+ sliderModel = SliderModel(simplexModel, None)
315
+ sliderProxModel = SliderFilterModel(sliderModel)
316
+ self.uiSliderTREE.setModel(sliderProxModel)
317
+ sliderSelModel = self.uiSliderTREE.selectionModel()
318
+ sliderSelModel.selectionChanged.connect(self.unifySliderSelection)
319
+ sliderSelModel.selectionChanged.connect(self.populateComboRequirements)
320
+ sliderSelModel.selectionChanged.connect(self.autoSetSliders)
321
+
322
+ comboModel = ComboModel(simplexModel, None)
323
+ comboProxModel = ComboFilterModel(comboModel)
324
+ self.uiComboTREE.setModel(comboProxModel)
325
+ comboSelModel = self.uiComboTREE.selectionModel()
326
+ comboSelModel.selectionChanged.connect(self.unifyComboSelection)
327
+ comboSelModel.selectionChanged.connect(self.populateSliderRequirements)
328
+ comboSelModel.selectionChanged.connect(self.autoSetComboSliders)
329
+
330
+ self.falloffDialog.loadSimplex()
331
+
332
+ # Make sure the UI is up and running
333
+ self.enableComboRequirements()
334
+ self.enableSliderRequirements()
335
+ self.uiMainShapesGRP.setEnabled(True)
336
+ self.uiComboShapesGRP.setEnabled(True)
337
+ self.uiConnectionGroupWID.setEnabled(True)
338
+
339
+ self.setSimplexLegacy()
340
+ self.simplexLoaded.emit()
341
+
342
+ # UI Setup
343
+ def _makeConnections(self):
344
+ """Make all the ui connections"""
345
+ # Setup Trees!
346
+ self.uiSliderTREE.setColumnWidth(1, 50)
347
+ self.uiSliderTREE.setColumnWidth(2, 20)
348
+ self.uiSliderFilterLINE.textChanged.connect(self.sliderStringFilter)
349
+ self.uiSliderFilterClearBTN.clicked.connect(self.uiSliderFilterLINE.clear)
350
+ self.uiSliderFilterClearBTN.clicked.connect(self.sliderStringFilter)
351
+
352
+ self.uiComboTREE.setColumnWidth(1, 50)
353
+ self.uiComboTREE.setColumnWidth(2, 20)
354
+ self.uiComboFilterLINE.textChanged.connect(self.comboStringFilter)
355
+ self.uiComboFilterClearBTN.clicked.connect(self.uiComboFilterLINE.clear)
356
+ self.uiComboFilterClearBTN.clicked.connect(self.comboStringFilter)
357
+
358
+ # combo dependency filter setup
359
+ self.uiComboDependGRP.toggled.connect(self.enableComboRequirements)
360
+ self.uiComboDependAllRDO.toggled.connect(self.enableComboRequirements)
361
+ self.uiComboDependAnyRDO.toggled.connect(self.enableComboRequirements)
362
+ self.uiComboDependOnlyRDO.toggled.connect(self.enableComboRequirements)
363
+ self.uiComboDependLockCHK.toggled.connect(self.setLockComboRequirement)
364
+
365
+ # slider dependency filter setup
366
+ self.uiSliderDependGRP.toggled.connect(self.enableSliderRequirements)
367
+ self.uiSliderDependAllRDO.toggled.connect(self.enableSliderRequirements)
368
+ self.uiSliderDependAnyRDO.toggled.connect(self.enableSliderRequirements)
369
+ self.uiSliderDependLockCHK.toggled.connect(self.setLockSliderRequirements)
370
+
371
+ # Bottom Left Corner Buttons
372
+ self.uiZeroAllBTN.clicked.connect(self.zeroAllSliders)
373
+ self.uiZeroSelectedBTN.clicked.connect(self.zeroSelectedSliders)
374
+ self.uiSelectCtrlBTN.clicked.connect(self.selectCtrl)
375
+
376
+ # Top Left Corner Buttons
377
+ self.uiNewGroupBTN.clicked.connect(self.newSliderGroup)
378
+ self.uiNewSliderBTN.clicked.connect(self.newSlider)
379
+ self.uiNewShapeBTN.clicked.connect(self.newSliderShape)
380
+ self.uiSliderDeleteBTN.clicked.connect(self.sliderTreeDelete)
381
+
382
+ # Top Right Corner Buttons
383
+ self.uiDeleteComboBTN.clicked.connect(self.comboTreeDelete)
384
+ self.uiNewComboActiveBTN.clicked.connect(self.newActiveCombo)
385
+ self.uiNewComboSelectBTN.clicked.connect(self.newSelectedCombo)
386
+ self.uiNewComboShapeBTN.clicked.connect(self.newComboShape)
387
+ self.uiNewComboGroupBTN.clicked.connect(self.newComboGroup)
388
+
389
+ # Bottom right corner buttons
390
+ self.uiSetSliderValsBTN.clicked.connect(self.setSliderVals)
391
+ self.uiSelectSlidersBTN.clicked.connect(self.selectSliders)
392
+
393
+ # System level
394
+ self.uiCurrentObjectTXT.editingFinished.connect(self.currentObjectChanged)
395
+ self.uiGetSelectedObjectBTN.clicked.connect(self.getSelectedObject)
396
+ self.uiClearSelectedObjectBTN.clicked.connect(self.clearSelectedObject)
397
+
398
+ self.uiNewSystemBTN.clicked.connect(self.newSystem)
399
+ self.uiRenameSystemBTN.clicked.connect(self.renameSystem)
400
+ self.uiCurrentSystemCBOX.currentIndexChanged[int].connect(
401
+ self.currentSystemChanged
402
+ )
403
+
404
+ # Extraction/connection
405
+ self.uiShapeExtractBTN.clicked.connect(self.shapeExtract)
406
+ self.uiShapeConnectBTN.clicked.connect(self.shapeConnect)
407
+ self.uiShapeConnectSceneBTN.clicked.connect(self.shapeConnectScene)
408
+
409
+ # File Menu
410
+ self.uiImportACT.triggered.connect(self.importSystemFromFile)
411
+ self.uiExportACT.triggered.connect(self.exportSystemTemplate)
412
+
413
+ # Edit Menu
414
+ self.uiHideRedundantACT.toggled.connect(self.hideRedundant)
415
+ self.uiDoubleSliderRangeACT.toggled.connect(self.setSliderRange)
416
+
417
+ # Isolation
418
+ self.uiSliderExitIsolateBTN.clicked.connect(self.sliderTreeExitIsolate)
419
+ self.uiComboExitIsolateBTN.clicked.connect(self.comboTreeExitIsolate)
420
+
421
+ self.uiLegacyJsonACT.toggled.connect(self.setSimplexLegacy)
422
+
423
+ # Helpers
424
+ def getSelectedItems(self, tree, typ=None):
425
+ """Convenience function to get the selected system items
426
+
427
+ Parameters
428
+ ----------
429
+ tree : QTreeView
430
+ The tree to get selected items from
431
+ typ : Type
432
+ The type of objects to return
433
+
434
+ Returns
435
+ -------
436
+ [object, ...]
437
+ A list of selected items
438
+ """
439
+ sel = tree.selectedIndexes()
440
+ sel = [i for i in sel if i.column() == 0]
441
+ model = tree.model()
442
+ items = [model.itemFromIndex(i) for i in sel]
443
+ if typ is not None:
444
+ items = [i for i in items if isinstance(i, typ)]
445
+ return items
446
+
447
+ def getCurrentObject(self):
448
+ """Convenience function to get the current object loaded into the UI"""
449
+ return self._currentObject
450
+
451
+ # Setup Trees!
452
+ def sliderStringFilter(self):
453
+ """Set the filter for the slider tree"""
454
+ filterString = str(self.uiSliderFilterLINE.text())
455
+ sliderModel = self.uiSliderTREE.model()
456
+ sliderModel.filterString = str(filterString)
457
+ sliderModel.invalidateFilter()
458
+
459
+ def comboStringFilter(self):
460
+ """Set the filter for the combo tree"""
461
+ filterString = str(self.uiComboFilterLINE.text())
462
+ comboModel = self.uiComboTREE.model()
463
+ comboModel.filterString = str(filterString)
464
+ comboModel.invalidateFilter()
465
+
466
+ # selection setup
467
+ def unifySliderSelection(self):
468
+ """Clear the selection of the combo tree when
469
+ an item on the slider tree is selected
470
+ """
471
+ mods = QApplication.keyboardModifiers()
472
+ if not mods & (
473
+ Qt.KeyboardModifier.ControlModifier | Qt.KeyboardModifier.ShiftModifier
474
+ ):
475
+ comboSelModel = self.uiComboTREE.selectionModel()
476
+ if not comboSelModel:
477
+ return
478
+
479
+ with signalsBlocked(comboSelModel):
480
+ comboSelModel.clearSelection()
481
+ self.uiComboTREE.viewport().update()
482
+
483
+ def unifyComboSelection(self):
484
+ """Clear the selection of the slider tree when
485
+ an item on the combo tree is selected
486
+ """
487
+ mods = QApplication.keyboardModifiers()
488
+ if not mods & (
489
+ Qt.KeyboardModifier.ControlModifier | Qt.KeyboardModifier.ShiftModifier
490
+ ):
491
+ sliderSelModel = self.uiSliderTREE.selectionModel()
492
+ if not sliderSelModel:
493
+ return
494
+ with signalsBlocked(sliderSelModel):
495
+ sliderSelModel.clearSelection()
496
+ self.uiSliderTREE.viewport().update()
497
+
498
+ # dependency setup
499
+ def setLockComboRequirement(self):
500
+ """Refresh the combo selection filter with the new filterLock state"""
501
+ comboModel = self.uiComboTREE.model()
502
+ if not comboModel:
503
+ return
504
+ self.populateComboRequirements()
505
+
506
+ def populateComboRequirements(self):
507
+ """Let the combo tree know the requirements from the slider tree"""
508
+ items = self.uiSliderTREE.getSelectedItems(Slider)
509
+ comboModel = self.uiComboTREE.model()
510
+ locked = self.uiComboDependLockCHK.isChecked()
511
+ if not locked:
512
+ comboModel.requires = items
513
+ if (
514
+ comboModel.filterRequiresAll
515
+ or comboModel.filterRequiresAny
516
+ or comboModel.filterRequiresOnly
517
+ ):
518
+ comboModel.invalidateFilter()
519
+
520
+ def enableComboRequirements(self):
521
+ """Set the requirements for the combo filter model"""
522
+ comboModel = self.uiComboTREE.model()
523
+ if not comboModel:
524
+ return
525
+ depCheck = self.uiComboDependGRP.isChecked()
526
+ comboModel.filterRequiresAll = self.uiComboDependAllRDO.isChecked() and depCheck
527
+ comboModel.filterRequiresAny = self.uiComboDependAnyRDO.isChecked() and depCheck
528
+ comboModel.filterRequiresOnly = (
529
+ self.uiComboDependOnlyRDO.isChecked() and depCheck
530
+ )
531
+ comboModel.invalidateFilter()
532
+
533
+ def populateSliderRequirements(self):
534
+ """Let the slider tree know the requirements from the combo tree"""
535
+ items = self.uiComboTREE.getSelectedItems(Combo)
536
+ sliderModel = self.uiSliderTREE.model()
537
+ locked = self.uiSliderDependLockCHK.isChecked()
538
+ if not locked:
539
+ sliderModel.requires = items
540
+ if sliderModel.filterRequiresAny or sliderModel.filterRequiresAll:
541
+ sliderModel.invalidateFilter()
542
+
543
+ def setLockSliderRequirements(self):
544
+ """Refresh the combo selection filter with the new filterLock state"""
545
+ sliderModel = self.uiSliderTREE.model()
546
+ if not sliderModel:
547
+ return
548
+ self.populateSliderRequirements()
549
+
550
+ def enableSliderRequirements(self):
551
+ sliderModel = self.uiSliderTREE.model()
552
+ if not sliderModel:
553
+ return
554
+
555
+ depCheck = self.uiSliderDependGRP.isChecked()
556
+ sliderModel.filterRequiresAny = (
557
+ self.uiSliderDependAnyRDO.isChecked() and depCheck
558
+ )
559
+ sliderModel.filterRequiresAll = (
560
+ self.uiSliderDependAllRDO.isChecked() and depCheck
561
+ )
562
+ sliderModel.invalidateFilter()
563
+
564
+ # Bottom Left Corner Buttons
565
+ def zeroAllSliders(self):
566
+ """Slot to Zero all Sliders in Slider UI panel"""
567
+ if self.simplex is None:
568
+ return
569
+ sliders = self.simplex.sliders
570
+ weights = [0.0] * len(sliders)
571
+ self.simplex.setSlidersWeights(sliders, weights)
572
+ self.uiSliderTREE.repaint()
573
+
574
+ def zeroSelectedSliders(self):
575
+ """Slot to Zero the selected sliders in the UI panel"""
576
+ if self.simplex is None:
577
+ return
578
+ items = self.uiSliderTREE.getSelectedItems(Slider)
579
+ values = [0.0] * len(items)
580
+ self.simplex.setSlidersWeights(items, values)
581
+ self.uiSliderTREE.repaint()
582
+
583
+ def selectCtrl(self):
584
+ """Select the Control object in the DCC"""
585
+ if self.simplex is None:
586
+ return
587
+ self.simplex.DCC.selectCtrl()
588
+
589
+ def autoSetSliders(self):
590
+ """Automatically set any selected sliders to 1.0"""
591
+ if self.simplex is None:
592
+ return
593
+ if not self.uiAutoSetSlidersCHK.isChecked():
594
+ return
595
+ sel = set(self.uiSliderTREE.getSelectedItems(Slider))
596
+ sliders = self.simplex.sliders
597
+
598
+ weights = [0.0] * len(sliders)
599
+ for i, slider in enumerate(sliders):
600
+ if slider in sel:
601
+ weights[i] = 1.0
602
+ self.simplex.setSlidersWeights(sliders, weights)
603
+ self.uiSliderTREE.repaint()
604
+
605
+ def _getAName(self, tpe, default=None, taken=(), uniqueAccept=False):
606
+ """uniqueAccept forces the user to provide and accept a unique name
607
+ If the user enters a non-unique name, the name is uniquified, and the
608
+ dialog is re-shown with the unique name as the default suggestion
609
+ """
610
+ tpe = tpe.lower()
611
+ uTpe = tpe[0].upper() + tpe[1:]
612
+
613
+ unique = False
614
+ default = getNextName(default, taken)
615
+ while not unique:
616
+ eMsg = "Enter a name for the new {0}".format(tpe)
617
+ newName, good = QInputDialog.getText(
618
+ self, "New {0}".format(uTpe), eMsg, text=default
619
+ )
620
+ if not good:
621
+ return None
622
+ if len(newName) < 3:
623
+ message = "Please use names longer than 2 letters"
624
+ QMessageBox.warning(self, "Warning", message)
625
+ return None
626
+ if not NAME_CHECK.match(newName):
627
+ message = "{0} name can only contain letters and numbers, and cannot start with a number"
628
+ message = message.format(uTpe)
629
+ QMessageBox.warning(self, "Warning", message)
630
+ return None
631
+
632
+ unqName = getNextName(newName, taken)
633
+ unique = (unqName == newName) or uniqueAccept
634
+ default = unqName
635
+
636
+ return default
637
+
638
+ # Top Left Corner Buttons
639
+ def newSliderGroup(self):
640
+ """Slot to Create a new slider group"""
641
+ if self.simplex is None:
642
+ return
643
+
644
+ newName = self._getAName("group", default="Group")
645
+ if newName is None:
646
+ return
647
+
648
+ Group.createGroup(str(newName), self.simplex, groupType=Slider)
649
+ # self.uiSliderTREE.model().invalidateFilter()
650
+ # self.uiComboTREE.model().invalidateFilter()
651
+
652
+ def newSlider(self):
653
+ """Slot to create a new slider"""
654
+ if self.simplex is None:
655
+ return
656
+
657
+ newName = self._getAName("slider")
658
+ if newName is None:
659
+ return
660
+
661
+ idxs = self.uiSliderTREE.getSelectedIndexes()
662
+ groups = coerceIndexToParentType(idxs, Group)
663
+ group = groups[0].model().itemFromIndex(groups[0]) if groups else None
664
+
665
+ Slider.createSlider(str(newName), self.simplex, group=group)
666
+
667
+ def newSliderShape(self):
668
+ """Slot to create a new Shape in a Slider's progression"""
669
+ pars = self.uiSliderTREE.getSelectedItems(Slider)
670
+ if not pars:
671
+ return
672
+ parItem = pars[0]
673
+ parItem.createShape()
674
+ self.uiSliderTREE.model().invalidateFilter()
675
+
676
+ def sliderTreeDelete(self):
677
+ """Delete some objects in the slider tree"""
678
+ idxs = self.uiSliderTREE.getSelectedIndexes()
679
+ roots = coerceIndexToRoots(idxs)
680
+ if not roots:
681
+ QMessageBox.warning(self, "Warning", "Nothing Selected in Slider tree")
682
+ return
683
+ roots = makeUnique([i.model().itemFromIndex(i) for i in roots])
684
+ for r in roots:
685
+ if isinstance(r, Simplex):
686
+ QMessageBox.warning(
687
+ self, "Warning", "Cannot delete a simplex system this way"
688
+ )
689
+ return
690
+
691
+ for r in roots:
692
+ r.delete()
693
+ self.uiSliderTREE.model().invalidateFilter()
694
+
695
+ # Top Right Corner Buttons
696
+ def comboTreeDelete(self):
697
+ """Delete some objects in the Combo tree"""
698
+ idxs = self.uiComboTREE.getSelectedIndexes()
699
+ roots = coerceIndexToRoots(idxs)
700
+ if not roots:
701
+ QMessageBox.warning(self, "Warning", "Nothing Selected in Combo tree")
702
+ return
703
+ roots = makeUnique([i.model().itemFromIndex(i) for i in roots])
704
+ for r in roots:
705
+ if isinstance(r, Simplex):
706
+ QMessageBox.warning(
707
+ self, "Warning", "Cannot delete a simplex system this way"
708
+ )
709
+ return
710
+
711
+ for r in roots:
712
+ r.delete()
713
+ self.uiComboTREE.model().invalidateFilter()
714
+
715
+ def _newCombo(self, sliders, values):
716
+ if len(sliders) < 2:
717
+ message = "A combo must use at least 2 sliders"
718
+ QMessageBox.warning(self, "Warning", message)
719
+ return
720
+
721
+ ccd = ComboCheckDialog(sliders, values=values, mode="create", parent=self)
722
+ ccd.move(self.pos())
723
+ ccd.exec_()
724
+
725
+ def newActiveCombo(self):
726
+ """Create a combo based on the UI Sliders that are currently nonzero"""
727
+ if self.simplex is None:
728
+ return
729
+ sliders = []
730
+ values = {}
731
+ for s in self.simplex.sliders:
732
+ if s.value != 0.0:
733
+ sliders.append(s)
734
+ values[s] = [s.value]
735
+ self._newCombo(sliders, values)
736
+
737
+ def newSelectedCombo(self):
738
+ """Create a combo based on the currently selected UI sliders"""
739
+ if self.simplex is None:
740
+ return
741
+ sliders = self.uiSliderTREE.getSelectedItems(Slider)
742
+ values = {s: [1.0] for s in sliders}
743
+ self._newCombo(sliders, values)
744
+
745
+ def newComboShape(self):
746
+ """Create a new shape in the Combo's progression"""
747
+ parIdxs = self.uiComboTREE.getSelectedIndexes()
748
+ pars = coerceIndexToParentType(parIdxs, Combo)
749
+ if not pars:
750
+ return
751
+
752
+ parItem = pars[0].model().itemFromIndex(pars[0]) if pars else None
753
+ parItem.createShape()
754
+ self.uiComboTREE.model().invalidateFilter()
755
+
756
+ def newComboGroup(self):
757
+ """Create a new group for organizing combos"""
758
+ if self.simplex is None:
759
+ return
760
+
761
+ newName = self._getAName("group", default="Group")
762
+ if newName is None:
763
+ return
764
+
765
+ Group.createGroup(str(newName), self.simplex, groupType=Combo)
766
+ # self.uiComboTREE.model().invalidateFilter()
767
+ # self.uiSliderTREE.model().invalidateFilter()
768
+
769
+ # Bottom right corner buttons
770
+ def setSliderVals(self):
771
+ """Set all slider values to those stored in the currently selected Combos"""
772
+ if self.simplex is None:
773
+ return
774
+ combos = self.uiComboTREE.getSelectedItems(Combo)
775
+ # maybe coerce to type instead??
776
+ self.zeroAllSliders()
777
+ values = []
778
+ sliders = []
779
+ for combo in combos:
780
+ for pair in combo.pairs:
781
+ if pair.slider in sliders:
782
+ continue
783
+ sliders.append(pair.slider)
784
+ values.append(pair.value)
785
+ self.simplex.setSlidersWeights(sliders, values)
786
+ self.uiSliderTREE.repaint()
787
+
788
+ def selectSliders(self):
789
+ """Select the sliders that are contained in the currently selected Combos"""
790
+ combos = self.uiComboTREE.getSelectedItems(Combo)
791
+ sliders = []
792
+ for combo in combos:
793
+ for pair in combo.pairs:
794
+ sliders.append(pair.slider)
795
+ self.uiSliderTREE.setItemSelection(sliders)
796
+
797
+ def autoSetComboSliders(self):
798
+ """Automatically set the DCC Slider values to activate the currently selected Combos"""
799
+ if self.simplex is None:
800
+ return
801
+ if not self.uiAutoSetCombosCHK.isChecked():
802
+ return
803
+ sel = set(self.uiComboTREE.getSelectedItems(Combo))
804
+ sv = {}
805
+ for combo in self.simplex.combos:
806
+ isSel = combo in sel
807
+ for pair in combo.pairs:
808
+ curVal = sv.get(pair.slider, 0.0)
809
+ newVal = pair.value if isSel else 0.0
810
+ if abs(newVal) >= abs(curVal):
811
+ sv[pair.slider] = newVal
812
+
813
+ sliders, weights = list(zip(*list(sv.items())))
814
+ self.simplex.setSlidersWeights(sliders, weights)
815
+ self.uiSliderTREE.repaint()
816
+
817
+ # Extraction/connection
818
+ def shapeConnectScene(self):
819
+ """Connect any selected meshes into the system based on the name"""
820
+ if self.simplex is None:
821
+ return
822
+ # make a dict of name:object
823
+ sel = DCC.getSelectedObjects()
824
+ selDict = {}
825
+ for s in sel:
826
+ name = DCC.getObjectName(s)
827
+ if name.endswith("_Extract"):
828
+ nn = name.rsplit("_Extract", 1)[0]
829
+ selDict[nn] = s
830
+
831
+ pairDict = {}
832
+ for p in self.simplex.progs:
833
+ for pp in p.pairs:
834
+ pairDict[pp.shape.name] = pp
835
+
836
+ # get all common names
837
+ common = selDict.keys() & pairDict.keys()
838
+
839
+ # get those items
840
+ pairs = [pairDict[i] for i in common]
841
+
842
+ # Set up the progress bar
843
+ pBar = QProgressDialog("Connecting Shapes", "Cancel", 0, 100, self)
844
+ pBar.setMaximum(len(pairs))
845
+
846
+ # Do the extractions
847
+ for pair in pairs:
848
+ c = pair.prog.controller
849
+ c.connectShape(pair.shape, delete=True)
850
+
851
+ # ProgressBar
852
+ pBar.setValue(pBar.value() + 1)
853
+ pBar.setLabelText("Connecting:\n{0}".format(pair.shape.name))
854
+ QApplication.processEvents()
855
+ if pBar.wasCanceled():
856
+ return
857
+
858
+ pBar.close()
859
+
860
+ def sliderShapeExtract(self):
861
+ """Create meshes that are possibly live-connected to the shapes"""
862
+ sliderIdxs = self.uiSliderTREE.getSelectedIndexes()
863
+ return self.shapeIndexExtract(sliderIdxs)
864
+
865
+ def comboShapeExtract(self):
866
+ """Create meshes that are possibly live-connected to the shapes"""
867
+ comboIdxs = self.uiComboTREE.getSelectedIndexes()
868
+ return self.shapeIndexExtract(comboIdxs)
869
+
870
+ def shapeExtract(self):
871
+ """Create meshes that are possibly live-connected to the shapes"""
872
+ sliderIdxs = self.uiSliderTREE.getSelectedIndexes()
873
+ comboIdxs = self.uiComboTREE.getSelectedIndexes()
874
+ return self.shapeIndexExtract(sliderIdxs + comboIdxs)
875
+
876
+ def shapeExport(self):
877
+ """Export meshes"""
878
+ sliderIdxs = self.uiSliderTREE.getSelectedIndexes()
879
+ comboIdxs = self.uiComboTREE.getSelectedIndexes()
880
+ return self.shapeIndexExport(sliderIdxs + comboIdxs)
881
+
882
+ def shapeIndexExport(self, indexes):
883
+ """Export meshes
884
+
885
+ Parameters
886
+ ----------
887
+ indexes : [QModelIndex, ...]
888
+ A list of indexes to extract
889
+ """
890
+ # Importing this here to keep people from getting confused
891
+ # You should use self._fileDialog which does compatibility
892
+ # stuff for file saving. Since I'm looking for a folder here
893
+ # I don't need to do that
894
+ from Qt.QtWidgets import QFileDialog
895
+
896
+ if self.simplex is None:
897
+ return
898
+
899
+ pref = Prefs()
900
+ defaultPath = str(
901
+ pref.restoreProperty("systemExportFolder", os.path.join(os.path.expanduser("~")))
902
+ )
903
+ outfld = QFileDialog.getExistingDirectory(
904
+ self, "Pick Export Folder", defaultPath
905
+ )
906
+ if not outfld:
907
+ return
908
+
909
+ pref.recordProperty("systemExportFolder", outfld)
910
+ pref.save()
911
+
912
+ pairs = coerceIndexToChildType(indexes, ProgPair)
913
+ pairs = [i.model().itemFromIndex(i) for i in pairs]
914
+ pairs = makeUnique([i for i in pairs if not i.shape.isRest])
915
+ pairs.sort(key=lambda x: naturalSortKey(x.shape.name))
916
+
917
+ # Set up the progress bar
918
+ pBar = QProgressDialog("Exporting Shapes", "Cancel", 0, 100, self)
919
+ pBar.setMaximum(len(pairs))
920
+
921
+ extension = '.abc'
922
+ # Do the extractions
923
+ for pair in pairs:
924
+ c = pair.prog.controller
925
+ extracted = c.extractShape(pair.shape, live=False)
926
+ path = os.path.join(outfld, c.name + extension)
927
+ if os.path.exists(path):
928
+ os.remove(path)
929
+
930
+ self.simplex.DCC.exportMesh(extracted, path)
931
+ self.simplex.DCC.deleteObj(extracted)
932
+
933
+ # ProgressBar
934
+ pBar.setValue(pBar.value() + 1)
935
+ pBar.setLabelText("Extracting:\n{0}".format(pair.shape.name))
936
+ QApplication.processEvents()
937
+ if pBar.wasCanceled():
938
+ return
939
+
940
+ pBar.close()
941
+
942
+ def shapeIndexExtract(self, indexes, live=None):
943
+ """Create meshes that are possibly live-connected to the shapes
944
+
945
+ Parameters
946
+ ----------
947
+ indexes : [QModelIndex, ...]
948
+ A list of indexes to extract
949
+ live : bool or None
950
+ Whether the connection is live. If None, check the UI properties
951
+ """
952
+ if live is None:
953
+ live = self.uiLiveShapeConnectionACT.isChecked()
954
+
955
+ pairs = coerceIndexToChildType(indexes, ProgPair)
956
+ pairs = [i.model().itemFromIndex(i) for i in pairs]
957
+ pairs = makeUnique([i for i in pairs if not i.shape.isRest])
958
+ pairs.sort(key=lambda x: naturalSortKey(x.shape.name))
959
+
960
+ # Set up the progress bar
961
+ pBar = QProgressDialog("Extracting Shapes", "Cancel", 0, 100, self)
962
+ pBar.setMaximum(len(pairs))
963
+
964
+ # Do the extractions
965
+ offset = 10
966
+ extracted = []
967
+ for pair in pairs:
968
+ c = pair.prog.controller
969
+ ext = c.extractShape(pair.shape, live=live, offset=offset)
970
+ extracted.append(ext)
971
+ offset += 5
972
+
973
+ # ProgressBar
974
+ pBar.setValue(pBar.value() + 1)
975
+ pBar.setLabelText("Extracting:\n{0}".format(pair.shape.name))
976
+ QApplication.processEvents()
977
+ if pBar.wasCanceled():
978
+ return extracted
979
+
980
+ pBar.close()
981
+ return extracted
982
+
983
+ def shapeConnect(self):
984
+ """Match any selected Shapes to DCC meshes based on their names, then delete the Meshes"""
985
+ sliderIdxs = self.uiSliderTREE.getSelectedIndexes()
986
+ comboIdxs = self.uiComboTREE.getSelectedIndexes()
987
+ self.shapeConnectIndexes(sliderIdxs + comboIdxs)
988
+
989
+ def shapeConnectIndexes(self, indexes):
990
+ """Match the provided shapes to DCC meshes based on their names, then delete the Meshes
991
+
992
+ Parameters
993
+ ----------
994
+ indexes : list of QModelIndex
995
+ A list of selected model indexes
996
+ """
997
+ pairs = coerceIndexToChildType(indexes, ProgPair)
998
+ pairs = [i.model().itemFromIndex(i) for i in pairs]
999
+ pairs = makeUnique([i for i in pairs if not i.shape.isRest])
1000
+
1001
+ # Set up the progress bar
1002
+ pBar = QProgressDialog("Connecting Shapes", "Cancel", 0, 100, self)
1003
+ pBar.setMaximum(len(pairs))
1004
+
1005
+ # Do the extractions
1006
+ for pair in pairs:
1007
+ c = pair.prog.controller
1008
+ c.connectShape(pair.shape, delete=True)
1009
+
1010
+ # ProgressBar
1011
+ pBar.setValue(pBar.value() + 1)
1012
+ pBar.setLabelText("Extracting:\n{0}".format(pair.shape.name))
1013
+ QApplication.processEvents()
1014
+ if pBar.wasCanceled():
1015
+ return
1016
+
1017
+ pBar.close()
1018
+
1019
+ def shapeMatch(self):
1020
+ """Match any selected Shapes to A selected DCC mesh"""
1021
+ sliderIdxs = self.uiSliderTREE.getSelectedIndexes()
1022
+ comboIdxs = self.uiComboTREE.getSelectedIndexes()
1023
+ self.shapeMatchIndexes(sliderIdxs + comboIdxs)
1024
+
1025
+ def shapeMatchIndexes(self, indexes):
1026
+ """Match any provided shapes to A selected DCC mesh
1027
+
1028
+ Parameters
1029
+ ----------
1030
+ indexes : list of QModelIndex
1031
+ A list of selected model indexes
1032
+ """
1033
+ # make a dict of name:object
1034
+ sel = DCC.getSelectedObjects()
1035
+ if not sel:
1036
+ return
1037
+ mesh = sel[0]
1038
+
1039
+ pairs = coerceIndexToChildType(indexes, ProgPair)
1040
+ pairs = [i.model().itemFromIndex(i) for i in pairs]
1041
+ pairs = makeUnique([i for i in pairs if not i.shape.isRest])
1042
+
1043
+ # Set up the progress bar
1044
+ pBar = QProgressDialog("Matching Shapes", "Cancel", 0, 100, self)
1045
+ pBar.setMaximum(len(pairs))
1046
+
1047
+ # Do the extractions
1048
+ for pair in pairs:
1049
+ c = pair.prog.controller
1050
+ c.connectShape(pair.shape, mesh=mesh)
1051
+
1052
+ # ProgressBar
1053
+ pBar.setValue(pBar.value() + 1)
1054
+ pBar.setLabelText("Matching:\n{0}".format(pair.shape.name))
1055
+ QApplication.processEvents()
1056
+ if pBar.wasCanceled():
1057
+ return
1058
+
1059
+ pBar.close()
1060
+
1061
+ def shapeClear(self):
1062
+ """Match all selected shapes to the rest"""
1063
+ sliderIdxs = self.uiSliderTREE.getSelectedIndexes()
1064
+ comboIdxs = self.uiComboTREE.getSelectedIndexes()
1065
+ self.shapeClearIndexes(sliderIdxs + comboIdxs)
1066
+
1067
+ def shapeClearIndexes(self, indexes):
1068
+ """Match all provided shapes to the rest
1069
+
1070
+ Parameters
1071
+ ----------
1072
+ indexes : list of QModelIndex
1073
+ A list of selected model indexes
1074
+ """
1075
+ pairs = coerceIndexToChildType(indexes, ProgPair)
1076
+ pairs = [i.model().itemFromIndex(i) for i in pairs]
1077
+ pairs = makeUnique([i for i in pairs if not i.shape.isRest])
1078
+
1079
+ for pair in pairs:
1080
+ pair.shape.zeroShape()
1081
+
1082
+ # System level
1083
+ def loadObject(self, thing):
1084
+ """Load a DCC mesh into the UI
1085
+
1086
+ Parameters
1087
+ ----------
1088
+ thing : object
1089
+ The DCC mesh to load into the UI
1090
+ """
1091
+ if thing is None:
1092
+ return
1093
+
1094
+ self.uiClearSelectedObjectBTN.show()
1095
+ self.uiCurrentSystemCBOX.clear()
1096
+ objName = DCC.getObjectName(thing)
1097
+ self._currentObject = thing
1098
+ self._currentObjectName = objName
1099
+ self.uiCurrentObjectTXT.setText(objName)
1100
+
1101
+ ops = DCC.getSimplexOperatorsOnObject(self._currentObject)
1102
+
1103
+ for op in ops:
1104
+ js = DCC.getSimplexString(op)
1105
+ if not js:
1106
+ continue
1107
+ d = json.loads(js)
1108
+ name = d["systemName"]
1109
+ self.uiCurrentSystemCBOX.addItem(name, (self._currentObject, name))
1110
+
1111
+ def currentObjectChanged(self):
1112
+ """Slot called when the current DCC object is changed"""
1113
+ name = str(self.uiCurrentObjectTXT.text())
1114
+ if self._currentObjectName == name:
1115
+ return
1116
+ if not name:
1117
+ return
1118
+
1119
+ newObject = DCC.getObjectByName(name)
1120
+ if not newObject:
1121
+ return
1122
+
1123
+ self.loadObject(newObject)
1124
+
1125
+ def getSelectedObject(self):
1126
+ """Load the first selected DCC object into the UI"""
1127
+ sel = DCC.getSelectedObjects()
1128
+ if not sel:
1129
+ return
1130
+ newObj = sel[0]
1131
+ if not newObj:
1132
+ return
1133
+ self.loadObject(newObj)
1134
+
1135
+ def clearSelectedObject(self):
1136
+ """Unload the current DCC object from the UI"""
1137
+ self.uiClearSelectedObjectBTN.hide()
1138
+ self.uiCurrentSystemCBOX.clear()
1139
+ self._currentObject = None
1140
+ self._currentObjectName = None
1141
+ self.uiCurrentObjectTXT.setText("")
1142
+ self.setSystem(None)
1143
+ # Clear the current system
1144
+
1145
+ def newSystem(self):
1146
+ """Create a new system on the current DCC Object"""
1147
+ if self._currentObject is None:
1148
+ QMessageBox.warning(self, "Warning", "Must have a current object selection")
1149
+ return
1150
+
1151
+ newName = self._getAName("system")
1152
+ if newName is None:
1153
+ return
1154
+
1155
+ newSystem = Simplex.buildEmptySystem(
1156
+ self._currentObject, newName, sliderMul=self._sliderMul
1157
+ )
1158
+ with signalsBlocked(self.uiCurrentSystemCBOX):
1159
+ self.uiCurrentSystemCBOX.addItem(newName)
1160
+ self.uiCurrentSystemCBOX.setCurrentIndex(
1161
+ self.uiCurrentSystemCBOX.count() - 1
1162
+ )
1163
+ self.setSystem(newSystem)
1164
+
1165
+ def renameSystem(self):
1166
+ """Rename the current Simplex system"""
1167
+ if self.simplex is None:
1168
+ return
1169
+
1170
+ sysNames = [
1171
+ str(self.uiCurrentSystemCBOX.itemText(i))
1172
+ for i in range(self.uiCurrentSystemCBOX.count())
1173
+ ]
1174
+ newName = self._getAName("system", taken=sysNames)
1175
+ if newName is None:
1176
+ return
1177
+
1178
+ self.simplex.name = newName
1179
+ idx = self.uiCurrentSystemCBOX.currentIndex()
1180
+ self.uiCurrentSystemCBOX.setItemText(idx, newName)
1181
+
1182
+ self.currentSystemChanged(idx)
1183
+
1184
+ def setSimplexLegacy(self):
1185
+ """Slot to toggle the legacy behavior of the current Simplex system"""
1186
+ if self.simplex is not None:
1187
+ self.simplex.setLegacy(self.uiLegacyJsonACT.isChecked())
1188
+ self.simplex.DCC.incrementRevision()
1189
+
1190
+ # File Menu
1191
+ def importSystemFromFile(self):
1192
+ """Open a File Dialog to load a simplex system from a file.
1193
+ Systems can be in either .smpx, or .json formats
1194
+ """
1195
+ if self._currentObject is None:
1196
+ impTypes = ["smpx"]
1197
+ else:
1198
+ impTypes = ["smpx", "json"]
1199
+
1200
+ pref = Prefs()
1201
+ defaultPath = str(
1202
+ pref.restoreProperty("systemImport", os.path.join(os.path.expanduser("~")))
1203
+ )
1204
+ path = self._fileDialog("Import Template", defaultPath, impTypes, save=False)
1205
+ if not path:
1206
+ return
1207
+ pref.recordProperty("systemImport", os.path.dirname(path))
1208
+ pref.save()
1209
+
1210
+ self.loadFile(path)
1211
+
1212
+ def loadFile(self, path):
1213
+ pBar = QProgressDialog("Loading Shapes", "Cancel", 0, 100, self)
1214
+ pBar.show()
1215
+ QApplication.processEvents()
1216
+
1217
+ # TODO: Come up with a better list of possibilites for loading
1218
+ # simplex files, and make the appropriate methods on the Simplex
1219
+ if path.endswith(".smpx"):
1220
+ newSystem = Simplex.buildSystemFromSmpx(
1221
+ path, self._currentObject, sliderMul=self._sliderMul, pBar=pBar
1222
+ )
1223
+ if newSystem is None:
1224
+ QMessageBox.warning(
1225
+ self,
1226
+ "Point Count Mismatch",
1227
+ "The .smpx file point count does not match the current object",
1228
+ )
1229
+ pBar.close()
1230
+ return
1231
+
1232
+ elif path.endswith(".json"):
1233
+ newSystem = Simplex.buildSystemFromJson(
1234
+ path, self._currentObject, sliderMul=self._sliderMul, pBar=pBar
1235
+ )
1236
+ else:
1237
+ QMessageBox.warning(self, "Bad Filepath", "Path type not recognized")
1238
+ return
1239
+
1240
+ with signalsBlocked(self.uiCurrentSystemCBOX):
1241
+ self.loadObject(newSystem.DCC.mesh)
1242
+ idx = self.uiCurrentSystemCBOX.findText(self._currentObjectName)
1243
+ if idx >= 0:
1244
+ self.uiCurrentSystemCBOX.setCurrentIndex(idx)
1245
+ else:
1246
+ self.uiCurrentSystemCBOX.addItem(newSystem.name)
1247
+ self.uiCurrentSystemCBOX.setCurrentIndex(
1248
+ self.uiCurrentSystemCBOX.count() - 1
1249
+ )
1250
+
1251
+ self.setSystem(newSystem)
1252
+ pBar.close()
1253
+ self.simplex.DCC.checkForErrors(self)
1254
+
1255
+ def _fileDialog(self, title, initPath, filters, save=True):
1256
+ """Convenience function for displaying File Dialogs"""
1257
+ filters = ["{0} (*.{0})".format(f) for f in filters]
1258
+ if not save:
1259
+ filters += ["All files (*.*)"]
1260
+ filters = ";;".join(filters)
1261
+
1262
+ if save:
1263
+ path, _ = QtCompat.QFileDialog.getSaveFileName(
1264
+ self, title, initPath, filters
1265
+ )
1266
+ else:
1267
+ path, _ = QtCompat.QFileDialog.getOpenFileName(
1268
+ self, title, initPath, filters
1269
+ )
1270
+
1271
+ if not path:
1272
+ return ""
1273
+
1274
+ if not save and not os.path.exists(path):
1275
+ return ""
1276
+
1277
+ return path
1278
+
1279
+ def exportSystemTemplate(self):
1280
+ """Open a file dialog and export a system to the chosen path"""
1281
+ if self._currentObject is None:
1282
+ QMessageBox.warning(self, "Warning", "Must have a current object selection")
1283
+ return
1284
+
1285
+ pref = Prefs()
1286
+ defaultPath = str(
1287
+ pref.restoreProperty("systemExport", os.path.join(os.path.expanduser("~")))
1288
+ )
1289
+ path = self._fileDialog(
1290
+ "Export Template", defaultPath, ["smpx", "json"], save=True
1291
+ )
1292
+ if not path:
1293
+ return
1294
+ pref.recordProperty("systemExport", os.path.dirname(path))
1295
+ pref.save()
1296
+
1297
+ if self.simplex is None:
1298
+ QMessageBox.warning(self, "Warning", "No simplex loaded")
1299
+ return
1300
+
1301
+ if path.endswith(".smpx"):
1302
+ pBar = QProgressDialog("Exporting smpx File", "Cancel", 0, 100, self)
1303
+ pBar.show()
1304
+ self.simplex.exportAbc(path, pBar)
1305
+ pBar.close()
1306
+ elif path.endswith(".json"):
1307
+ dump = self.simplex.dump()
1308
+ with open(path, "w") as f:
1309
+ f.write(dump)
1310
+
1311
+ # Slider Settings
1312
+ def setSelectedSliderGroups(self, group):
1313
+ """Set the group for the selected Sliders
1314
+
1315
+ Parameters
1316
+ ----------
1317
+ group : Group
1318
+ The group that will take the selected Sliders
1319
+ """
1320
+ if not group:
1321
+ return
1322
+ sliders = self.uiSliderTREE.getSelectedItems(Slider)
1323
+ group.take(sliders)
1324
+ self.uiSliderTREE.viewport().update()
1325
+
1326
+ def setSelectedSliderFalloff(self, falloff, state):
1327
+ """Set the Falloffs for the selected Sliders
1328
+
1329
+ Parameters
1330
+ ----------
1331
+ falloff : Falloff
1332
+ The falloff to set on the selected sliders
1333
+ state : bool
1334
+ Whether to add or remove this falloff from the selection
1335
+ """
1336
+ if not falloff:
1337
+ return
1338
+ sliders = self.uiSliderTREE.getSelectedItems(Slider)
1339
+ for s in sliders:
1340
+ if state == Qt.CheckState.Checked:
1341
+ s.prog.addFalloff(falloff)
1342
+ else:
1343
+ s.prog.removeFalloff(falloff)
1344
+ self.uiSliderTREE.viewport().update()
1345
+
1346
+ def setSelectedSliderInterp(self, interp):
1347
+ """Set the interpolation for the selected sliders
1348
+
1349
+ Parameters
1350
+ ----------
1351
+ interp : str
1352
+ The interpolation to set on the selection.
1353
+ Could be 'linear', 'spline', or 'splitSpline'
1354
+ """
1355
+ sliders = self.uiSliderTREE.getSelectedItems(Slider)
1356
+ for s in sliders:
1357
+ s.prog.interp = interp
1358
+
1359
+ # Combo Settings
1360
+ def setSelectedComboGroups(self, group):
1361
+ """Set the group for the selected Combos
1362
+
1363
+ Parameters
1364
+ ----------
1365
+ group : Group
1366
+ The group that will take the selected Combos
1367
+ """
1368
+ if not group:
1369
+ return
1370
+ combos = self.uiComboTREE.getSelectedItems(Combo)
1371
+ group.take(combos)
1372
+ self.uiComboTREE.viewport().update()
1373
+
1374
+ def setSelectedComboSolveType(self, stVal):
1375
+ """Set the solve type for the selected combos
1376
+
1377
+ Parameters
1378
+ ----------
1379
+ stVal : str
1380
+ The solve type to set for the combos.
1381
+ See Combo.solveTypes for a list
1382
+ """
1383
+ combos = self.uiComboTREE.getSelectedItems(Combo)
1384
+ for c in combos:
1385
+ c.solveType = stVal
1386
+
1387
+ # Edit Menu
1388
+ def hideRedundant(self):
1389
+ """Hide redundant items from the Slider and Combo trees based on a user preference"""
1390
+ check = self.uiHideRedundantACT.isChecked()
1391
+ comboModel = self.uiComboTREE.model()
1392
+ comboModel.filterShapes = check
1393
+ comboModel.invalidateFilter()
1394
+ sliderModel = self.uiSliderTREE.model()
1395
+ sliderModel.doFilter = check
1396
+ sliderModel.invalidateFilter()
1397
+
1398
+ def setSliderRange(self):
1399
+ """Double the range for the sliders *IN THE DCC ONLY* based on a user preference"""
1400
+ self._sliderMul = 2.0 if self.uiDoubleSliderRangeACT.isChecked() else 1.0
1401
+ if self.simplex is None:
1402
+ return
1403
+ self.simplex.DCC.sliderMul = self._sliderMul
1404
+ self.simplex.DCC.setSlidersRange(self.simplex.sliders)
1405
+
1406
+ # Isolation
1407
+ def isSliderIsolate(self):
1408
+ """Check if the slider tree is currently isolated"""
1409
+ model = self.uiSliderTREE.model()
1410
+ if model:
1411
+ return bool(model.isolateList)
1412
+ return False
1413
+
1414
+ def sliderIsolateSelected(self):
1415
+ """Isolate the selected Sliders in the Slider Tree"""
1416
+ self.uiSliderTREE.isolateSelected()
1417
+ self.uiSliderExitIsolateBTN.show()
1418
+
1419
+ def sliderTreeExitIsolate(self):
1420
+ """Disable isolation mode in the Slider Tree"""
1421
+ self.uiSliderTREE.exitIsolate()
1422
+ self.uiSliderExitIsolateBTN.hide()
1423
+
1424
+ def isComboIsolate(self):
1425
+ """Check if the combo tree is currently isolated"""
1426
+ model = self.uiComboTREE.model()
1427
+ if model:
1428
+ return bool(model.isolateList)
1429
+ return False
1430
+
1431
+ def comboIsolateSelected(self):
1432
+ """Isolate the selected Combos in the Combo Tree"""
1433
+ self.uiComboTREE.isolateSelected()
1434
+ self.uiComboExitIsolateBTN.show()
1435
+
1436
+ def comboTreeExitIsolate(self):
1437
+ """Disable isolation mode in the Combo Tree"""
1438
+ self.uiComboTREE.exitIsolate()
1439
+ self.uiComboExitIsolateBTN.hide()
1440
+
1441
+
1442
+ def _test():
1443
+ app = QApplication(sys.argv)
1444
+ path = r"C:\Users\tfox\Documents\GitHub\Simplex\scripts\SimplexUI\build\HeadMaleStandard_High_Unsplit.smpx"
1445
+ d = SimplexDialog()
1446
+ newSystem = Simplex.buildSystemFromSmpx(path, d.getCurrentObject(), sliderMul=1.0)
1447
+ d.setSystem(newSystem)
1448
+
1449
+ d.show()
1450
+ sys.exit(app.exec_())
1451
+
1452
+
1453
+ if __name__ == "__main__":
1454
+ _test()