-
Notifications
You must be signed in to change notification settings - Fork 1
/
matcher_sup.py
89 lines (76 loc) · 3.01 KB
/
matcher_sup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import MaxPlus
from PySide import QtGui
#creation du separator
class HSeparator(QtGui.QFrame):
def __init__(self):
super(HSeparator, self).__init__()
self.setFrameShape(QtGui.QFrame.HLine)
self.setFrameShadow(QtGui.QFrame.Sunken)
#creation de notre fenetre avec pyside
class MatcherUI(QtGui.QWidget):
def __init__(self):
super(MatcherUI, self).__init__()
self.setWindowTitle("Matcher")
self.resize(230, 180)
self.layout = QtGui.QVBoxLayout(self)
label = QtGui.QLabel("Match attributes\nbetween objects")
separator = HSeparator()
self.name = QtGui.QCheckBox("Name")
self.color = QtGui.QCheckBox("Color")
self.position = QtGui.QCheckBox("Position")
self.rotation = QtGui.QCheckBox("Rotation")
self.ref = QtGui.QCheckBox("Ref")
separator2 = HSeparator()
self.button = QtGui.QPushButton("Apply")
self.layout.addWidget(label)
self.layout.addWidget(separator)
self.layout.addWidget(self.name)
self.layout.addWidget(self.color)
self.layout.addWidget(self.position)
self.layout.addWidget(self.rotation)
self.layout.addWidget(self.ref)
self.layout.addWidget(separator2)
self.layout.addWidget(self.button)
class Matcher(object):
ui = None
objects = None
def __init__(self, objects):
self.ui = MatcherUI()
self.objects = objects
self.ui.button.clicked.connect(self.apply)
def apply(self):
self.objects = [n for n in MaxPlus.SelectionManager.GetNodes()]
if len(self.objects)%2:
print "La selection doit etre paire"
return
else:
mid = len(self.objects) / 2
right = self.objects[:mid]
left = self.objects[mid:]
for n in left:
target = right[left.index(n)]
if self.ui.ref.checkState():
self.match_ref(n, target)
if self.ui.name.checkState():
self.match_name(n, target)
if self.ui.color.checkState():
self.match_color(n, target)
if self.ui.position.checkState():
self.match_position(n, target)
if self.ui.rotation.checkState():
self.match_rotation(n, target)
def match_name(self, obj, trg):
obj.SetName(trg.Name)
def match_color(self, obj, trg):
obj.SetWireColor(trg.GetWireColor())
def match_position(self, obj, trg):
obj.SetWorldPosition(trg.GetWorldPosition())
def match_rotation(self, obj, trg):
pos = obj.GetWorldPosition()
obj.SetWorldTM(trg.GetWorldTM())
obj.SetWorldPosition(pos)
def match_ref(self, obj, trg):
obj.SetObjectRef(trg.GetObjectRef())
fenetre = Matcher([n for n in MaxPlus.SelectionManager.GetNodes()])
MaxPlus.AttachQWidgetToMax(fenetre.ui)
fenetre.ui.show()