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,966 @@
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
19
+ from Qt.QtGui import QColor
20
+ from ..utils import nested
21
+ from .accessor import SimplexAccessor
22
+ from .combo import Combo
23
+ from .group import Group
24
+ from .progression import Progression
25
+ from .slider import Slider
26
+ from .stack import stackable
27
+
28
+
29
+ class TravPair(SimplexAccessor):
30
+ """ """
31
+
32
+ classDepth = 4
33
+
34
+ def __init__(self, slider, value):
35
+ simplex = slider.simplex
36
+ super(TravPair, self).__init__(simplex)
37
+ self.slider = slider
38
+ self._value = float(value)
39
+ self.minValue = -1.0
40
+ self.maxValue = 1.0
41
+ self._tickDelta = 0.0
42
+ self.travPoint = None
43
+ self.expanded = {}
44
+
45
+ def valueTick(self, ticks, mul):
46
+ """ """
47
+ self._tickDelta += self.dragStep * ticks * mul
48
+ if (self._tickDelta + self.value) <= self.slider.minValue:
49
+ self._tickDelta = self.slider.minValue - self.value
50
+ if self.value != self.slider.minValue:
51
+ self.value = self.slider.minValue
52
+ self._tickDelta = 0.0
53
+ elif (self._tickDelta + self.value) >= self.slider.maxValue:
54
+ self._tickDelta = self.slider.maxValue - self.value
55
+ if self.value != self.slider.maxValue:
56
+ self._tickDelta = 0.0
57
+ self.value = self.slider.maxValue
58
+ elif abs(self._tickDelta + self.value) <= 1.0e-5:
59
+ if self.value != 0.0:
60
+ self._tickDelta = 0.0
61
+ self.value = 0.0
62
+
63
+ @property
64
+ def models(self):
65
+ """ """
66
+ return self.simplex.models
67
+
68
+ @property
69
+ def name(self):
70
+ """ """
71
+ return self.slider.name
72
+
73
+ @property
74
+ def value(self):
75
+ """ """
76
+ return self._value
77
+
78
+ @value.setter
79
+ @stackable
80
+ def value(self, val):
81
+ """ """
82
+ self._value = val
83
+ for model in self.models:
84
+ model.itemDataChanged(self)
85
+
86
+ def buildDefinition(self, simpDict, legacy):
87
+ """ """
88
+ sIdx = self.slider.buildDefinition(simpDict, legacy)
89
+ return sIdx, self.value
90
+
91
+ def treeRow(self):
92
+ """ """
93
+ return self.travPoint.pairs.index(self)
94
+
95
+ def treeParent(self):
96
+ """ """
97
+ return self.travPoint
98
+
99
+ def treeData(self, column):
100
+ """ """
101
+ if column == 0:
102
+ return self.name
103
+ if column == 1:
104
+ return self.value
105
+ return None
106
+
107
+ @stackable
108
+ def remove(self):
109
+ """ """
110
+ mgrs = [model.removeItemManager(self) for model in self.models]
111
+ with nested(*mgrs):
112
+ self.travPoint.pairs.remove(self)
113
+ self.travPoint = None
114
+
115
+ @stackable
116
+ def delete(self):
117
+ """ """
118
+ self.travPoint.traversal.removePairs([self])
119
+
120
+ @staticmethod
121
+ def removeAll(pairs):
122
+ """ """
123
+ travs = list({p.travPoint.traversal for p in pairs})
124
+ for trav in travs:
125
+ trav.removePairs(pairs)
126
+
127
+
128
+ class TravPoint(SimplexAccessor):
129
+ """ """
130
+
131
+ classDepth = 3
132
+
133
+ def __init__(self, pairs, row):
134
+ if not pairs:
135
+ raise ValueError("Pairs must be provided for a TravPoint")
136
+ simplex = pairs[0].slider.simplex
137
+ super(TravPoint, self).__init__(simplex)
138
+
139
+ self.pairs = pairs
140
+ for pair in pairs:
141
+ pair.travPoint = self
142
+ self.row = row
143
+ self.traversal = None
144
+ self.expanded = {}
145
+
146
+ def sliders(self):
147
+ """ """
148
+ return [i.slider for i in self.pairs]
149
+
150
+ @staticmethod
151
+ def _wideCeiling(val, eps=0.001):
152
+ """ """
153
+ if val > eps:
154
+ return 1.0
155
+ elif val < -eps:
156
+ return -1.0
157
+ return 0.0
158
+
159
+ @stackable
160
+ def addPair(self, pair):
161
+ """
162
+
163
+ Parameters
164
+ ----------
165
+ pair :
166
+
167
+
168
+ Returns
169
+ -------
170
+
171
+ """
172
+ mgrs = [model.insertItemManager(self) for model in self.models]
173
+ with nested(*mgrs):
174
+ self.pairs.append(pair)
175
+ pair.travPoint = self
176
+
177
+ def removePair(self, pair):
178
+ """
179
+
180
+ Parameters
181
+ ----------
182
+ pair :
183
+
184
+
185
+ Returns
186
+ -------
187
+
188
+ """
189
+ pair.remove()
190
+
191
+ def addSlider(self, slider, val=None):
192
+ """
193
+
194
+ Parameters
195
+ ----------
196
+ slider :
197
+
198
+ val :
199
+ (Default value = None)
200
+
201
+ Returns
202
+ -------
203
+
204
+ """
205
+ val = val if val is not None else slider.value
206
+ val = self._wideCeiling(val)
207
+ sliders = self.sliders()
208
+ try:
209
+ idx = sliders.index(slider)
210
+ except ValueError:
211
+ self.addPair(TravPair(slider, val))
212
+ else:
213
+ self.pairs[idx].value = val
214
+
215
+ def addItem(self, item):
216
+ """
217
+
218
+ Parameters
219
+ ----------
220
+ item :
221
+
222
+
223
+ Returns
224
+ -------
225
+
226
+ """
227
+ if isinstance(item, Slider):
228
+ self.addSlider(item)
229
+ elif isinstance(item, Combo):
230
+ for cp in item.pairs:
231
+ self.addSlider(cp.slider, cp.value)
232
+
233
+ @property
234
+ def name(self):
235
+ """ """
236
+ return "START" if self.row == 0 else "END"
237
+
238
+ def treeData(self, column):
239
+ """
240
+
241
+ Parameters
242
+ ----------
243
+ column :
244
+
245
+
246
+ Returns
247
+ -------
248
+
249
+ """
250
+ if column == 0:
251
+ return self.name
252
+ return None
253
+
254
+ def treeChild(self, row):
255
+ """
256
+
257
+ Parameters
258
+ ----------
259
+ row :
260
+
261
+
262
+ Returns
263
+ -------
264
+
265
+ """
266
+ return self.pairs[row]
267
+
268
+ def treeRow(self):
269
+ """ """
270
+ return self.row
271
+
272
+ def treeParent(self):
273
+ """ """
274
+ return self.traversal
275
+
276
+ def treeChildCount(self):
277
+ """ """
278
+ return len(self.pairs)
279
+
280
+ def buildDefinition(self, simpDict, legacy):
281
+ """
282
+
283
+ Parameters
284
+ ----------
285
+ simpDict :
286
+
287
+ legacy :
288
+
289
+
290
+ Returns
291
+ -------
292
+
293
+ """
294
+ return [p.buildDefinition(simpDict, legacy) for p in self.pairs]
295
+
296
+ def getInputVector(self):
297
+ """get the input to the solver that would fully activate this point of the traversal
298
+
299
+ parameters
300
+ ----------
301
+
302
+ returns
303
+ -------
304
+ : [float, ...]
305
+ the ordered slider values
306
+
307
+ """
308
+ invec = [0.0] * len(self.simplex.sliders)
309
+ for cp in self.pairs:
310
+ invec[self.simplex.sliders.index(cp.slider)] = cp.value
311
+ return invec
312
+
313
+
314
+ class Traversal(SimplexAccessor):
315
+ """Traversals control a Progression based on any 2 points in the Solver space.
316
+
317
+ Traversals only make sense with intermediate shapes in the progression of the sliders
318
+ that control it.
319
+
320
+ Traversals should never have a shape at 100%. That shape should be handled by a Combo
321
+
322
+ First: A "point in solver space" just means a list of slider/value pairs.
323
+ The Slider/Value pairs that make a up a Combo are just a "Point in solver space" as well.
324
+ So technically Combos could be thought of as a special-case of Traversals. Combos control
325
+ a progression between the "Rest Point" where all sliders are at 0, and the Combo point
326
+
327
+ Outside of the context of Traversals, I just call solver space points "Combos", because
328
+ I don't need to be crazy specific like I do here.
329
+
330
+ The initial use-case for Traversals was dealing with eye combo shapes with incremental
331
+ Progressions. The eyeLookDown and the eyeClosed shapes both pull the upper lid down a great
332
+ deal, and the eyeClosed was a 4-shape progression. So, when transitioning from eyeLookDown
333
+ to eyeLookDown+eyeClosed, the deltas for all the progressive shapes were being triggered as
334
+ the combo was coming on, causing major wobbles in the eyelid. So we needed shapes that
335
+ countered those incrementals, but *only* on the transition from eyeLookDown to
336
+ eyeLookDown+eyeClosed (NOT on the transition from eyeClosed to eyeLookDown+eyeClosed)
337
+
338
+ Early setups used floating Combos, but those have linearinterpolation, and I wanted a
339
+ cleaner solution. That solution is the Traversal
340
+
341
+ Parameters
342
+ ----------
343
+ name : str
344
+ The name of this Combo
345
+ simplex : Simplex
346
+ The parent Simplex system
347
+ startPoint : TravPoint
348
+ A set of Slider/Value pairs where the Traversal solves to 0
349
+ endPoint : TravPoint
350
+ A set of Slider/Value pairs where the Traversal solves to 1
351
+ prog : Progression
352
+ The Progression that this Combo controls
353
+ group : Group
354
+ The Group to create this combo in
355
+ color : QColor
356
+ The color of this item in the UI
357
+
358
+ Returns
359
+ -------
360
+
361
+ """
362
+
363
+ classDepth = 2
364
+
365
+ def __init__(
366
+ self,
367
+ name,
368
+ simplex,
369
+ startPoint,
370
+ endPoint,
371
+ prog,
372
+ group,
373
+ color=None,
374
+ ):
375
+ super(Traversal, self).__init__(simplex)
376
+ color = QColor(128, 128, 128) if color is None else color
377
+ with self.stack.store(self):
378
+ if group.groupType is not type(self):
379
+ raise ValueError(
380
+ "Cannot add this Traversal to a group of a different type"
381
+ )
382
+ self._name = name
383
+ self.startPoint = startPoint
384
+ self.endPoint = endPoint
385
+ self.prog = prog
386
+ self._buildIdx = None
387
+ self.expanded = {}
388
+ self._enabled = True
389
+ self.color = color
390
+
391
+ mgrs = [model.insertItemManager(group) for model in self.models]
392
+ with nested(*mgrs):
393
+ self.group = group
394
+ self.startPoint.traversal = self
395
+ self.endPoint.traversal = self
396
+ self.prog.controller = self
397
+ self.group.items.append(self)
398
+ self.simplex.traversals.append(self)
399
+
400
+ @classmethod
401
+ def createTraversal(cls, name, simplex, startPairs, endPairs, group=None, count=4):
402
+ """Create a Traversal between two lists of pairs
403
+
404
+ Parameters
405
+ ----------
406
+ name : str
407
+ The name of this Combo
408
+ simplex : Simplex
409
+ The parent Simplex system
410
+ startPairs : [(Slider
411
+ A list of Slider/Value pairs to make the startPoint
412
+ endPairs : [(Slider
413
+ A list of Slider/Value pairs to make the endPoint
414
+ group : Group
415
+ The Group to create this combo in (Default value = None)
416
+ count : int
417
+ The number of incrementals to create (including the 100%) (Default value = 4)
418
+
419
+ Returns
420
+ -------
421
+
422
+ """
423
+ if simplex.restShape is None:
424
+ raise RuntimeError("Simplex system is missing rest shape")
425
+
426
+ if group is None:
427
+ gname = "TRAVERSALS"
428
+ matches = [i for i in simplex.traversalGroups if i.name == gname]
429
+ if matches:
430
+ group = matches[0]
431
+ else:
432
+ group = Group(gname, simplex, Traversal)
433
+
434
+ startPairs = [TravPair(p[0], p[1]) for p in startPairs]
435
+ endPairs = [TravPair(p[0], p[1]) for p in endPairs]
436
+
437
+ startPoint = TravPoint(startPairs, 0)
438
+ endPoint = TravPoint(endPairs, 1)
439
+
440
+ prog = Progression(name, simplex)
441
+ trav = cls(name, simplex, startPoint, endPoint, prog, group)
442
+
443
+ for c in reversed(list(range(count))):
444
+ val = (100 * (c + 1)) // count
445
+ pp = prog.createShape("{0}_{1}".format(name, val), val / 100.0)
446
+ simplex.DCC.zeroShape(pp.shape)
447
+ return trav
448
+
449
+ @property
450
+ def enabled(self):
451
+ """Get whether this Traversal is evaluated in the solver"""
452
+ return self._enabled
453
+
454
+ @enabled.setter
455
+ @stackable
456
+ def enabled(self, value):
457
+ """Set whether this Traversal is evaluated in the solver
458
+
459
+ Parameters
460
+ ----------
461
+ value :
462
+
463
+
464
+ Returns
465
+ -------
466
+
467
+ """
468
+ self._enabled = value
469
+ for model in self.models:
470
+ model.itemDataChanged(self)
471
+
472
+ @property
473
+ def name(self):
474
+ """Get the name of a Traversal"""
475
+ return self._name
476
+
477
+ @name.setter
478
+ @stackable
479
+ def name(self, value):
480
+ """Set the name of a Traversal
481
+
482
+ Parameters
483
+ ----------
484
+ value :
485
+
486
+
487
+ Returns
488
+ -------
489
+
490
+ """
491
+ self._name = value
492
+ self.prog.name = value
493
+ # self.DCC.renameTraversal(self, value)
494
+ # for model in self.models:
495
+ # model.itemDataChanged(self)
496
+
497
+ def treeChild(self, row):
498
+ """
499
+
500
+ Parameters
501
+ ----------
502
+ row :
503
+
504
+
505
+ Returns
506
+ -------
507
+
508
+ """
509
+ if row == 0:
510
+ return self.startPoint
511
+ elif row == 1:
512
+ return self.endPoint
513
+ elif row == 2:
514
+ return self.prog
515
+ return None
516
+
517
+ def treeRow(self):
518
+ """ """
519
+ return self.group.items.index(self)
520
+
521
+ def treeParent(self):
522
+ """ """
523
+ return self.group
524
+
525
+ def treeChildCount(self):
526
+ """ """
527
+ return 3
528
+
529
+ def treeChecked(self):
530
+ """ """
531
+ return self.enabled
532
+
533
+ def allSliders(self):
534
+ """Get the list of all Sliders that control this Traversal
535
+
536
+ Parameters
537
+ ----------
538
+
539
+ Returns
540
+ -------
541
+ : [Slider, ...]
542
+ The list of all Sliders that control this Traversal
543
+
544
+ """
545
+ startSliders = [p.slider for p in self.startPoint.pairs]
546
+ endSliders = [
547
+ p.slider for p in self.endPoint.pairs if p.slider not in startSliders
548
+ ]
549
+ return startSliders + endSliders
550
+
551
+ def dynamicSliders(self):
552
+ """Get a list of sliders that have different values at the start and end"""
553
+ return [sli for sli, rng in self.ranges() if rng[0] != rng[1]]
554
+
555
+ def staticSliders(self):
556
+ """Get a list of sliders that have the same values at the start and end"""
557
+ return [sli for sli, rng in self.ranges() if rng[0] == rng[1]]
558
+
559
+ def ranges(self):
560
+ """Get the range per Slider for this Traversal
561
+
562
+ Parameters
563
+ ----------
564
+
565
+ Returns
566
+ -------
567
+ : type
568
+ (dict): A {Slider: range} dict
569
+
570
+ """
571
+ startDict = {p.slider: p.value for p in self.startPoint.pairs}
572
+ endDict = {p.slider: p.value for p in self.endPoint.pairs}
573
+ allSliders = startDict.keys() | endDict.keys()
574
+
575
+ rangeDict = {}
576
+ for sli in allSliders:
577
+ rangeDict[sli] = (startDict.get(sli, 0.0), endDict.get(sli, 0.0))
578
+ return rangeDict
579
+
580
+ @staticmethod
581
+ def buildTraversalName(ranges):
582
+ """Given the range dict (like from Traversal.ranges()) come up with a name
583
+
584
+ Parameters
585
+ ----------
586
+ ranges : dict
587
+ A {Slider: range} dict
588
+
589
+ Returns
590
+ -------
591
+ : str
592
+ The suggested Traversal name
593
+
594
+ """
595
+ static, dynamic = [], []
596
+ for sli, rng in ranges.items():
597
+ if rng[0] == rng[1]:
598
+ static.append(sli)
599
+ else:
600
+ dynamic.append(sli)
601
+
602
+ parts = []
603
+ for grp in static, dynamic:
604
+ for slider in sorted(grp, key=lambda x: x.name):
605
+ prefix = None
606
+ start, end = ranges[slider]
607
+ if start == end:
608
+ # prefix = 'St' # St for Static
609
+ if start == 0:
610
+ continue
611
+ shp = slider.prog.getShapeAtValue(start)
612
+ if shp is None:
613
+ continue
614
+ name = shp.strippedName()
615
+ else:
616
+ prefix = "Dy" # Dy for Dynamic
617
+ if start == 0:
618
+ shp = slider.prog.getShapeAtValue(end)
619
+ if shp is None:
620
+ continue
621
+ name = shp.strippedName()
622
+ elif end == 0:
623
+ shp = slider.prog.getShapeAtValue(start)
624
+ if shp is None:
625
+ continue
626
+ name = shp.strippedName()
627
+ else:
628
+ name = slider.name
629
+
630
+ if prefix is not None:
631
+ parts.append(prefix)
632
+ parts.append(name)
633
+
634
+ return "Tv_" + "_".join(parts)
635
+
636
+ def controllerNameLinks(self):
637
+ """ """
638
+ surr = "_{0}_".format(self.name)
639
+ return ["_{0}_".format(sli) in surr for sli in self.allSliders()]
640
+
641
+ def nameLinks(self):
642
+ """
643
+
644
+ Parameters
645
+ ----------
646
+
647
+ Returns
648
+ -------
649
+ : type
650
+ progression depends on this traversal's name
651
+
652
+ """
653
+ # In this case, these names will *NOT* have the possibility of
654
+ # a pos/neg name. Only the traversal name, and possibly a percentage
655
+ shapeNames = []
656
+ shapes = [i.shape for i in self.prog.pairs]
657
+ for s in shapes:
658
+ x = s.name.rsplit("_", 1)
659
+ if len(x) == 2:
660
+ base, sfx = x
661
+ x = base if sfx.isdigit() else s.name
662
+ shapeNames.append(x)
663
+ return [i == self.name for i in shapeNames]
664
+
665
+ @stackable
666
+ def createShape(self, shapeName=None, tVal=None):
667
+ """Create a shape and add it to a progression
668
+
669
+ Parameters
670
+ ----------
671
+ shapeName : str or None
672
+ The name of the shape to create.
673
+ If None, give it a default name
674
+ tVal : float or None
675
+ The progression value to set for the new Shape.
676
+ If None, it gets a "smart" default value
677
+
678
+ Returns
679
+ -------
680
+
681
+ """
682
+ pp, idx = self.prog.newProgPair(shapeName, tVal)
683
+ mgrs = [model.insertItemManager(self.prog, idx) for model in self.models]
684
+ with nested(*mgrs):
685
+ pp.prog = self.prog
686
+ self.prog.pairs.insert(idx, pp)
687
+ return pp
688
+
689
+ @classmethod
690
+ def loadV2(cls, simplex, progs, data):
691
+ """Load the data from a version2 formatted json dictionary
692
+
693
+ Parameters
694
+ ----------
695
+ simplex : Simplex
696
+ The Simplex system that's being built
697
+ progs : [Progression
698
+ The progressions that have already been built
699
+ data : dict
700
+ The chunk of the json dict used to build this object
701
+
702
+ Returns
703
+ -------
704
+ : Traversal
705
+ The specified Traversal
706
+
707
+ """
708
+ name = data["name"]
709
+ prog = progs[data["prog"]]
710
+ group = simplex.groups[data.get("group", 2)]
711
+ color = QColor(*data.get("color", (0, 0, 0)))
712
+
713
+ rangeDict = {} # slider: [startVal, endVal]
714
+
715
+ pFlip = -1.0 if data["progressFlip"] else 1.0
716
+ pcIdx = data["progressControl"]
717
+ if data["progressType"].lower() == "slider":
718
+ sli = simplex.sliders[pcIdx]
719
+ rangeDict[sli] = (0.0, pFlip)
720
+ else:
721
+ cmb = simplex.combos[pcIdx]
722
+ for cp in cmb.pairs:
723
+ rangeDict[cp.slider] = (0.0, cp.value)
724
+
725
+ mFlip = -1.0 if data["multiplierFlip"] else 1.0
726
+ mcIdx = data["multiplierControl"]
727
+ if data["multiplierType"].lower() == "slider":
728
+ sli = simplex.sliders[mcIdx]
729
+ rangeDict[sli] = (mFlip, mFlip)
730
+ else:
731
+ cmb = simplex.combos[mcIdx]
732
+ for cp in cmb.pairs:
733
+ rangeDict[cp.slider] = (cp.value, cp.value)
734
+
735
+ ssli = sorted((rangeDict.items()), key=lambda x: x[0].name)
736
+ startPairs, endPairs = [], []
737
+ for slider, (startVal, endVal) in ssli:
738
+ startPairs.append(TravPair(slider, startVal))
739
+ endPairs.append(TravPair(slider, endVal))
740
+
741
+ startPoint = TravPoint(startPairs, 0)
742
+ endPoint = TravPoint(endPairs, 1)
743
+
744
+ return cls(name, simplex, startPoint, endPoint, prog, group, color)
745
+
746
+ @classmethod
747
+ def loadV3(cls, simplex, progs, data):
748
+ """Load the data from a version3 formatted json dictionary
749
+
750
+ Parameters
751
+ ----------
752
+ simplex : Simplex
753
+ The Simplex system that's being built
754
+ progs : [Progression
755
+ The progressions that have already been built
756
+ data : dict
757
+ The chunk of the json dict used to build this object
758
+
759
+ Returns
760
+ -------
761
+ : Traversal
762
+ The specified Traversal
763
+
764
+ """
765
+ name = data["name"]
766
+ prog = progs[data["prog"]]
767
+ group = simplex.groups[data.get("group", 2)]
768
+ color = QColor(*data.get("color", (0, 0, 0)))
769
+
770
+ startDict = dict(data["start"])
771
+ endDict = dict(data["end"])
772
+ sliIdxs = sorted(startDict.keys() | endDict.keys())
773
+ startPairs, endPairs = [], []
774
+ for idx in sliIdxs:
775
+ startPairs.append(TravPair(simplex.sliders[idx], startDict.get(idx, 0.0)))
776
+ endPairs.append(TravPair(simplex.sliders[idx], endDict.get(idx, 0.0)))
777
+ startPoint = TravPoint(startPairs, 0)
778
+ endPoint = TravPoint(endPairs, 1)
779
+
780
+ return cls(name, simplex, startPoint, endPoint, prog, group, color)
781
+
782
+ def buildDefinition(self, simpDict, legacy):
783
+ """Output a dictionary definition of this object
784
+
785
+ Parameters
786
+ ----------
787
+ simpDict : dict
788
+ The dictionary that is being built
789
+ legacy : bool
790
+ Whether to write out the legacy definition, or the newer one
791
+ This is ignored for Traversals. There is no legacy definition
792
+
793
+ Returns
794
+ -------
795
+
796
+ """
797
+ if self._buildIdx is None:
798
+ self._buildIdx = len(simpDict["traversals"])
799
+ x = {
800
+ "name": self.name,
801
+ "prog": self.prog.buildDefinition(simpDict, legacy),
802
+ "start": self.startPoint.buildDefinition(simpDict, legacy),
803
+ "end": self.endPoint.buildDefinition(simpDict, legacy),
804
+ "group": self.group.buildDefinition(simpDict, legacy),
805
+ "color": self.color.getRgb()[:3],
806
+ "enabled": self._enabled,
807
+ }
808
+ simpDict.setdefault("traversals", []).append(x)
809
+ return self._buildIdx
810
+
811
+ def clearBuildIndex(self):
812
+ """Clear the build index of this object
813
+
814
+ The buildIndex is stored when building a definition dictionary
815
+ that keeps track of its index for later referencing
816
+
817
+ Parameters
818
+ ----------
819
+
820
+ Returns
821
+ -------
822
+
823
+ """
824
+ self._buildIdx = None
825
+ self.prog.clearBuildIndex()
826
+ self.group.clearBuildIndex()
827
+
828
+ @stackable
829
+ def delete(self):
830
+ """Delete a traversal and any shapes it contains"""
831
+ mgrs = [model.removeItemManager(self) for model in self.models]
832
+ with nested(*mgrs):
833
+ g = self.group
834
+ if self not in g.items:
835
+ return # Can happen when deleting multiple groups
836
+ g.items.remove(self)
837
+ self.group = None
838
+ self.simplex.traversals.remove(self)
839
+
840
+ pairs = self.prog.pairs[:] # gotta make a copy
841
+ for pp in pairs:
842
+ if not pp.shape.isRest:
843
+ self.simplex.shapes.remove(pp.shape)
844
+ self.DCC.deleteShape(pp.shape)
845
+
846
+ def extractShape(self, shape, live=True, offset=10.0):
847
+ """Extract a shape from a Traversal progression
848
+
849
+ Parameters
850
+ ----------
851
+ shape :
852
+
853
+ live :
854
+ (Default value = True)
855
+ offset :
856
+ (Default value = 10.0)
857
+
858
+ Returns
859
+ -------
860
+
861
+ """
862
+ return self.DCC.extractTraversalShape(self, shape, live, offset)
863
+
864
+ def addSlider(self, slider):
865
+ """Add a slider to both the startPoint and endPoint of this Traversal
866
+
867
+ Parameters
868
+ ----------
869
+ slider : Slider
870
+ The slider to add
871
+
872
+ Returns
873
+ -------
874
+
875
+ """
876
+ self.startPoint.addSlider(slider, val=0.0)
877
+ self.endPoint.addSlider(slider)
878
+
879
+ def removePairs(self, pairs):
880
+ """Remove the given pairs from both the startPoint and endPoint of this Traversal
881
+
882
+ Parameters
883
+ ----------
884
+ pairs : [TravPair
885
+ The pairs to remove
886
+
887
+ Returns
888
+ -------
889
+
890
+ """
891
+ # Get only the pairs that are a part of this traversal
892
+ sPairs = [i for i in self.startPoint.pairs if i in pairs]
893
+ ePairs = [i for i in self.endPoint.pairs if i in pairs]
894
+ pairs = sPairs + ePairs
895
+
896
+ # Get all the pairs that use the selected sliders
897
+ sliders = {p.slider for p in pairs}
898
+ sPairs = [i for i in self.startPoint.pairs if i.slider in sliders]
899
+ ePairs = [i for i in self.endPoint.pairs if i.slider in sliders]
900
+
901
+ # do the removal
902
+ for pair in sPairs:
903
+ pair.remove()
904
+
905
+ for pair in ePairs:
906
+ pair.remove()
907
+
908
+ @staticmethod
909
+ def traversalAlreadyExists(simplex, sliders, ranges):
910
+ """In a given simplex syste, check if a traversal exists
911
+ with the given sliders and ranges
912
+ """
913
+ chk = dict(zip(sliders, ranges))
914
+ for trav in simplex.traversals:
915
+ if chk == trav.ranges():
916
+ return trav
917
+ return None
918
+
919
+ @staticmethod
920
+ def getCount(sliders, ranges):
921
+ """Get the count of shapes to create for a traversal with the given
922
+ sliders and ranges. It's the max number of shapes on a given side of 0
923
+ """
924
+ counts = []
925
+ for sli, rng in zip(sliders, ranges):
926
+ if rng[0] == rng[1]:
927
+ continue
928
+ vals = sli.prog.getValues()
929
+ if max(rng) == 0:
930
+ count = len([v for v in vals if v < 0])
931
+ else:
932
+ count = len([v for v in vals if v > 0])
933
+ counts.append(count)
934
+ if not counts:
935
+ return 0
936
+ return max(counts)
937
+
938
+ def getInputVector(self, value):
939
+ """Get the input to the Solver that would set this traversal to
940
+ the given value
941
+
942
+ Parameters
943
+ ----------
944
+ value : float
945
+ The value to set the traversal to
946
+
947
+ Returns
948
+ -------
949
+ : [float, ...]
950
+ The ordered slider values
951
+
952
+ """
953
+ indexBySlider = {slider: idx for idx, slider in enumerate(self.simplex.sliders)}
954
+
955
+ fullStart = [0.0] * len(self.simplex.sliders)
956
+ for pair in self.startPoint.pairs:
957
+ fullStart[indexBySlider[pair.slider]] = pair.value
958
+
959
+ fullEnd = [0.0] * len(self.simplex.sliders)
960
+ for pair in self.endPoint.pairs:
961
+ fullEnd[indexBySlider[pair.slider]] = pair.value
962
+
963
+ def _lerp(s, e, v):
964
+ return s * (1 - v) + e * v
965
+
966
+ return [_lerp(fs, fe, value) for fs, fe in zip(fullStart, fullEnd)]