aboutsummaryrefslogtreecommitdiff
path: root/scripts/artv2/components/base_components/joint_mover.py
blob: 6fc92b95e3a74ebdc8a67ff45b2ebd63bbc53bac (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
# -*- coding: utf-8 -*-
"""
:author:
    Jeremy Ernst
:description:
    This module contains a class that represents a joint mover object. A joint mover object is meant to be instantiated
    in the __init__ of the base_component class. Nothing should inherit from the JointMover class.

    The main methods a JointMover handles are: adding the joint mover file, renaming movers, setting up the hierarchy,
    locking or unlocking movers, retrieving mover-related data, and other joint mover specific operations.

"""

import os
import pymel.core as pm

import artv2.utilities.general_utilities as utils
import artv2.utilities.joint_mover_utilities as dev_utils
import artv2.utilities.component_utilities as component_utils
import artv2.utilities.error_utilities as errors
import artv2.tools.system.logger.output_logger as logger
from artv2.components.base_components.aim_helper import AimHelper


class JointMover(object):
    """
    Class for creating and working with a joint mover rig, which is a simplified rig used to aid in the creation and
    placement of a skeleton, keeping it clean and consistent. The JointMover is instantiated by a component and is
    passed that component's network_node.
    """

    def __init__(self, path, metanode):
        """
        :param path: Path to joint mover file.
        :param metanode: This is the network node from a component, like a leg or torso. It contains all of the
        metadata
        """

        self.logger = logger.OutputLogger(self.__class__.__name__)
        self._path = path
        self._metanode = pm.PyNode(metanode)
        self.aim_helper = AimHelper(self._metanode)

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    def add_joint_mover(self):
        """
        Adds the joint mover maya ascii file to the maya scene.
        """

        tools_directory = utils.return_settings()[0]
        joint_mover_path = utils.path_join(tools_directory, self._path)

        self.logger.info("{0}.add_joint_mover: Importing joint mover file for {1}"
                         "".format(self.__class__.__name__, self.metanode.componentName.get()))
        if not os.path.exists(joint_mover_path):
            self.logger.warning("{0}.add_joint_mover: The specified file does not exist: {1}"
                                "".format(self.__class__.__name__, joint_mover_path))
            errors.raise_error("The specified joint mover file does not exist: {0}".format(joint_mover_path))
            return

        else:
            nodes = utils.import_file(joint_mover_path, return_nodes=True)
            joints = utils.filter_nodes(nodes, filter_by="joint")
            root_joint = utils.get_root_joint_of_component(joints)
            for joint in utils.convert_to_pynodes(joints):
                joint.overrideEnabled.set(1)
                joint.overrideDisplayType.set(2)

            self.create_joint_mover_controls(root_joint)

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    def create_joint_mover_controls(self, root_joint):
        """
        Creates the joint mover controls on the joints that come in from the ascii file.

        :param root_joint: Root joint of the hierarchy from the joint mover ascii file.
        """

        self.logger.info("{0}.create_joint_mover_controls: Creating controls for the guide joints on {1}."
                         "".format(self.__class__.__name__, self.metanode.componentName.get()))
        created_movers = dev_utils.create_movers_from_joints(self.metanode.componentName.get(), root_joint)
        dev_utils.mark_joint_movers(created_movers, self.metanode.componentName.get(),
                                    self.metanode.prefix.get(), self.metanode.suffix.get())
        dev_utils.drive_joints_with_movers(created_movers, self.metanode.componentName.get())

        self._connect_movers_to_metanode(created_movers)

        movers = self.get_movers()
        for each in [movers.get("global"), movers.get("offset")]:
            for mover in each:
                component_utils.setup_global_scale(mover)
        self._lock_joint_movers(lock_children=True)

        containers = self.get_containers()
        pm.lockNode(containers[2], lock=True, lockUnpublished=True)
        pm.lockNode(containers[1], lock=True, lockUnpublished=False)
        pm.lockNode(containers[0], lock=True, lockUnpublished=False)

        self.select_top_mover()

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    def get_containers(self):
        """
        Get and return the containers that our joint mover controls and utility nodes are contained in.

        :return: PyNodes of containers that our joint mover controls and utility nodes reside in.
        """

        guide_container = pm.container(q=True, findContainer=[self.return_top_mover_grp()])
        top_container = pm.container(q=True, findContainer=[guide_container])
        utils_container = top_container.utils_container.connections()[0]

        return [top_container, guide_container, utils_container]

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    def get_created_joints(self):
        """
        Finds and returns the joints created by this JointMover.

        :return: string array of joint names
        """

        movers = self.get_movers()
        offset_movers = movers.get("offset")
        joints = []
        for offset in offset_movers:

            if offset.build_joint.get() is True:
                joints.append(offset.created_joint.get())
        return joints

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    def get_driven_joints(self):
        """
        Return the joint mover joints currently driven by the movers (these are not the same as the created joints).

        :return: List of PyNodes representing the joint mover joints.
        """

        movers = self.get_movers()
        offset_movers = movers.get("offset")
        joints = []
        for offset in offset_movers:
            joints.append(offset.connected_joint.connections()[0])
        return joints

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    def get_movers(self):
        """
        Finds and returns the joint mover control objects created by the JointMover.

        :return: Dictionary of joint movers with the keys: global and offset.
        """

        global_movers, offset_movers = [], []
        for attr in [["global_movers", global_movers], ["offset_movers", offset_movers]]:
            if self.metanode.hasAttr(attr[0]):
                connections = self.metanode.attr(attr[0]).connections()
                if connections is not None:
                    attr[1].extend(connections)

        movers = {"global": global_movers, "offset": offset_movers}
        return movers

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    def _lock_joint_movers(self, lock=True, lock_children=False):
        """
        Method for locking down the joint mover nodes so they cannot be deleted (or unlocking them).

        :param lock: Whether to lock or unlock the nodes.
        :param lock_children: Whether to lock all children of the nodes, whether they are movers or not.
        :type lock: bool
        :type lock_children: bool
        """

        joint_movers = self.get_movers()
        for mover_type in joint_movers:
            movers = joint_movers.get(mover_type)

            container = pm.container(q=True, findContainer=[mover for mover in movers])
            if container is not None:
                container.unlock()

            for mover in movers:
                pm.lockNode(mover, lock=lock)

                if lock_children:
                    pm.select(mover, hi=True)
                    children = pm.ls(sl=True)
                    for child in children:
                        pm.lockNode(child, lock=lock)

            if container is not None:
                container.lock()

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    def remove_movers(self):
        """
        Remove the generated joint mover controls from the driven joints (as well as any associated containers, nodes).
        """

        self.logger.info("{0}.remove_movers: Removing movers for {1}".format(self.__class__.__name__,
                                                                             self.metanode.componentName.get()))

        current_state = self.metanode.pinned.get()
        if not current_state:
            self.toggle_pin_component()

        self._lock_joint_movers(lock=False, lock_children=True)
        mover_data = self.get_movers()

        containers = self.get_containers()
        for container in containers:
            container.unlock()

        utility_nodes = containers[2].getNodeList()
        for node in utility_nodes:
            node.unlock()
            pm.delete(node)

        for mover_type in mover_data:
            movers = mover_data.get(mover_type)
            for mover in movers:
                if pm.objExists(mover):
                    pm.delete(mover)

        top_grp = self.return_top_mover_grp()
        children = top_grp.getChildren()
        top_grp.unlock()
        for child in children:
            child.unlock()
        pm.delete(top_grp)

        joints = containers[1].getNodeList()
        containers[1].removeNode(joints)

        for joint in joints:
            if joint.hasAttr("otherType"):
                original_name = joint.attr("otherType").get()
                utils.rename_object(joint, original_name)

        for container in containers:
            if pm.objExists(container):
                pm.delete(container)

        if current_state is False:
            utils.set_attribute(self.metanode, "pinned", False)

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    def rename_movers(self, old_prefix, old_suffix):
        """
        Renames joint movers with the new component prefix and/or suffix.

        :param str old_prefix: The old prefix to search/replace
        :param str old_suffix:  The old suffix to search/replace
        """
        self.logger.info("{0}.rename_movers: Renaming movers for {1}".format(self.__class__.__name__,
                                                                             self.metanode.componentName.get()))

        prefix = self.metanode.prefix.get()
        suffix = self.metanode.suffix.get()

        mover_grp = self.metanode.mover_grp.connections()[0]
        pm.select(mover_grp, hi=True)
        selection = pm.ls(sl=True, long=True)
        rename_nodes = self._find_nodes_to_rename(selection, old_prefix, old_suffix)
        rename_data = []
        for each in rename_nodes:
            if each[0].hasAttr("created_joint"):
                original_name = each[0].created_joint.get()
                current_name = utils.strip_name(original_name, old_prefix, None, old_suffix)
                utils.set_attribute(each[0], "created_joint", prefix + current_name + suffix, "string")
                self.logger.debug("original name: {0}, prefix: {1}, current_name: {2}, suffix: {3}".format(
                    original_name, prefix, current_name, suffix))
                rename_data.append([original_name, prefix + current_name + suffix])

                guide_joint = each[0].connected_joint.connections()[0]
                utils.rename_object(guide_joint, self.metanode.componentName.get() + "_" + current_name)

            utils.rename_object(each[0], each[1])
        self._rename_dependent_attrs(rename_data)

        pm.select(clear=True)

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    def return_top_mover_grp(self):
        """
        Finds the top-most global mover group and returns it.

        :return: string name of the top-most global mover group.
        """

        top_mover_grp = self.metanode.mover_grp.connections()[0]
        if not pm.objExists(top_mover_grp):
            self.logger.error("{0}.return_top_mover_grp: {1} does not exist. This should never be the case!"
                              "".format(self.__class__.__name__, top_mover_grp))
            errors.raise_error("{0} does not exist! This should not be the case!".format(top_mover_grp))
        return top_mover_grp

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    def set_mover_parent(self, parent):
        """
        Parents the top-most group in the joint mover file under the given parent joint's global mover.

        :param str parent: Name of parent joint.
        """

        self.logger.info("{0}.set_mover_parent: Setting the mover parent to {1} for {2}"
                         "".format(self.__class__.__name__, parent, self.metanode.componentName.get()))

        parent_mover = component_utils.find_associated_mover_from_joint(parent)
        top_mover = self.return_top_mover_grp()

        parent_constraint = top_mover.translateX.connections(type="parentConstraint", exactType=True)
        scale_constraint = top_mover.scaleX.connections(type="scaleConstraint", exactType=True)

        if parent_constraint:
            if pm.objExists(parent_constraint[0]):
                parent_constraint[0].unlock()
                pm.delete(parent_constraint[0])
        if scale_constraint:
            if pm.objExists(scale_constraint[0]):
                scale_constraint[0].unlock()
                pm.delete(scale_constraint[0])

        if pm.objExists(parent_mover):
            new_parent_constraint = pm.parentConstraint(parent_mover, top_mover, mo=True)
            new_scale_constraint = pm.scaleConstraint(parent_mover, top_mover, mo=True)

            new_parent_constraint.lock()
            new_scale_constraint.lock()

        else:
            self.logger.warning("{0}.set_mover_parent: Could not parent {1} to {2}. {2} does not exist."
                                "".format(self.__class__.__name__, top_mover, parent_mover))
            errors.raise_error("Could not parent {0} to {1}. {1} does not exist.".format(top_mover, parent_mover))
            return

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    def toggle_build_joint(self, joint, mover, build=True):
        """
        Toggles the visibility of the given joint and associated movers, as well as setting the build state.

        :param joint: The guide joint (PyNode) to toggle visiblity on.
        :param mover: The offset mover (PyNode) to set the build state on and toggle visibility on.
        :param build: The boolean value of whether to build the joint or not.
        """

        self.logger.info("{0}.toggle_build_joint: Toggling {1} to build={2}.".format(self.__class__.__name__, joint,
                                                                                     build))
        alert_user = None
        created_joint = mover.created_joint.get()
        issues = component_utils.check_for_children(created_joint)
        if issues:
            alert_user = component_utils.fix_dependencies(issues)

        self._lock_joint_movers(False, True)
        mover.build_joint.set(build)
        if build:
            utils.set_attribute(joint, "drawStyle", 0)
        if not build:
            utils.set_attribute(joint, "drawStyle", 2)

        global_mover = mover.nodeName().rpartition("_offset")[0]
        asset = self.metanode.asset.connections()[0]
        if pm.objExists(global_mover):
            mover_node = pm.PyNode(global_mover)
            if asset.hasAttr("global_mover_visibility"):
                if asset.global_mover_visibility.get():
                    mover_node.getShape().visibility.set(build)
            else:
                mover_node.getShape().visibility.set(build)

        if mover:
            if asset.hasAttr("offset_mover_visibility"):
                if asset.offset_mover_visibility.get():
                    mover.getShape().visibility.set(build)
            else:
                mover.getShape().visibility.set(build)

        self._lock_joint_movers(lock_children=True)
        return alert_user

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    def toggle_pin_component(self):
        """
        Toggles whether the component is pinned, meaning if pinned, the component is unaffected by any transforms of
        its parent.
        """

        current_state = self.metanode.pinned.get()
        self.logger.info("{0}.toggle_pin_component: Setting component pinning to {1} for {2}"
                         "".format(self.__class__.__name__, not current_state, self.metanode.componentName.get()))

        if current_state:
            utils.set_attribute(self.metanode, "pinned", False)
            parent = self.metanode.parentComponentBone.get()
            if parent:
                self.set_mover_parent(parent)

        else:
            utils.set_attribute(self.metanode, "pinned", True)
            top_mover = self.return_top_mover_grp()
            parent_constraint = top_mover.translateX.connections(type="parentConstraint", exactType=True)
            scale_constraint = top_mover.scaleX.connections(type="scaleConstraint", exactType=True)
            if parent_constraint:
                if pm.objExists(parent_constraint[0]):
                    parent_constraint[0].unlock()
                    pm.delete(parent_constraint[0])
            if scale_constraint:
                if pm.objExists(scale_constraint[0]):
                    scale_constraint[0].unlock()
                    pm.delete(scale_constraint[0])

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    def bake_offsets(self):
        """
        Ensures that the global movers are aligned with the offset movers, so that the offsets are once again zeroed
        out. This function runs twice to account for aim mode, which changes the orientation of an offset mover (on a
        group above) when a global mover is moved. The second run cleans up the orientation offsets that were added due
        to this.
        """

        self.logger.info("{0}.bake_offsets: Baking offsets on {1}.".format(self.__class__.__name__,
                                                                           self.metanode.componentName.get()))

        pm.undoInfo(openChunk=True)
        for _ in range(2):
            movers = self.get_movers()
            offset_movers = movers.get("offset")
            position_data, locators = [], []

            for offset in offset_movers:
                connected_joint = offset.connected_joint.connections()[0]
                if not connected_joint.twistJoint.get():
                    locator = pm.spaceLocator()
                    locators.append(locator)
                    pm.delete(pm.parentConstraint(offset, locator))
                    global_mover = str(offset.rpartition("_offset")[0])
                    position_data.append([global_mover, locator])
            self._reset_movers(offset_movers)

            constraints = []
            for data in position_data:
                global_mover = data[0]
                locator = data[1]
                if pm.objExists(global_mover):
                    mover = pm.PyNode(global_mover)
                    constraints.append(pm.parentConstraint(locator, mover))

            pm.delete(constraints)
            pm.delete(locators)
        pm.undoInfo(closeChunk=True)

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    def reset_movers(self, mover_type):
        """
        Resets the joint movers to their default transform values.

        :param str mover_type: Valid options are "all", "offset", "global".
        """

        self.logger.info("{0}.reset_movers: Resetting movers for {1}".format(self.__class__.__name__,
                                                                             self.metanode.componentName.get()))

        movers = self.get_movers()

        pm.undoInfo(openChunk=True)
        if mover_type == "all":
            self._reset_movers(movers.get("offset"))
            self._reset_movers(movers.get("global"))
        if mover_type == "offset":
            self._reset_movers(movers.get("offset"))
        if mover_type == "global":
            self._reset_movers(movers.get("global"))
        pm.undoInfo(closeChunk=True)

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    def copy_transforms(self, template=False):
        """
        Copies the translate, rotate, and scale values of the joint mover control and stores them to a file on disk.
        """

        self.logger.info("{0}.copy_transforms: Copying {1}'s mover transforms."
                         "".format(self.__class__.__name__, self.metanode.componentName.get()))

        movers = self.get_movers()
        all_movers = movers.get("offset")
        all_movers.extend(movers.get("global"))
        all_movers.append(self.metanode.mover_grp.connections()[0])

        transform_data = {}
        attributes = ["translateX", "translateY", "translateZ", "rotateX", "rotateY", "rotateZ", "scaleX", "scaleY",
                      "scaleZ"]

        for mover in all_movers:
            self.logger.debug("{0}.copy_transforms: mover = {1}".format(self.__class__.__name__, mover))
            attribute_data = {}
            for each in attributes:
                self.logger.debug("{0}.copy_transforms: attribute = {1}".format(self.__class__.__name__, each))
                if mover.attr(each).isKeyable():
                    attribute_data[each] = mover.attr(each).get()

            inst = component_utils.get_component_instance(self.metanode)
            basename = utils.strip_name(mover.nodeName(), inst.prefix, inst.network_node.baseName.get(), inst.suffix)
            self.logger.debug("{0}.copy_transforms: dict entry= {1}, {2}".format(self.__class__.__name__, basename,
                                                                                 attribute_data))
            if not template:
                transform_data[basename] = attribute_data
                utils.create_clipboard("artv2JMxForms", transform_data)
            else:
                transform_data[mover.nodeName()] = attribute_data

        return transform_data

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    def paste_transforms(self, mirror=False, template=False, data=None):
        """
        Opens the file on disk that has clipboard data for copied transforms, and sets any applicable data on the joint
        mover controls.

        :param mirror: Whether to mirror the values when pasting.
        :param template: Whether this is being called from loading a template.
        :param data: (optional) data of transforms to paste rather than using clipboard.
        """

        self.logger.info("{0}.paste_transforms: Pasting mover transforms from clipboard onto {1}'s movers."
                         "".format(self.__class__.__name__, self.metanode.componentName.get()))

        if not template:
            clipboard = utils.retrieve_clipboard("artv2JMxForms")
            data = utils.read_clipboard(clipboard)

        pm.undoInfo(openChunk=True)
        if data is not None:
            inst = component_utils.get_component_instance(self.metanode)

            for key in data:
                self.logger.debug("{0}.paste_transforms: {1}".format(self.__class__.__name__, key))
                if not template:
                    mover_name = inst.prefix + inst.network_node.baseName.get() + inst.suffix + key
                else:
                    mover_name = key
                self.logger.debug("{0}.paste_transforms: constructed mover name = {1}".format(self.__class__.__name__,
                                                                                              mover_name))

                if pm.objExists(mover_name):
                    self._paste_transforms(mover_name, data, key, mirror)
            del inst
            pm.undoInfo(closeChunk=True)

        else:
            self.logger.warning("{0}.paste_transforms: No clipboard exists.".format(self.__class__.__name__))
            errors.raise_error("No clipboard exists!")

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    def _paste_transforms(self, mover_name, data, key, mirror):

        inst = component_utils.get_component_instance(self.metanode)

        self.logger.debug("{0}.paste_transforms: Constructed mover ({1}) exists."
                          "".format(self.__class__.__name__, mover_name))
        mover_node = pm.PyNode(mover_name)
        attribute_data = data.get(key)
        self.logger.debug("{0}.paste_transforms: attribute data for mover = {1}"
                          "".format(self.__class__.__name__, attribute_data))
        for each in attribute_data:
            attr_value = attribute_data.get(each)
            self.logger.debug("{0}.paste_transforms: {1} value is {2}".format(self.__class__.__name__, each,
                                                                              attr_value))
            if mover_node.attr(each).isKeyable():
                if mirror:
                    multiplier = inst.mirror_table.get(each)
                    if not multiplier:
                        multiplier = 1
                    self.logger.debug("{0}.paste_transforms: Setting {1}.{2} to {3}"
                                      "".format(self.__class__.__name__, mover_name, each,
                                                attr_value * multiplier))
                    mover_node.attr(each).set(attr_value * multiplier)
                else:
                    self.logger.debug("{0}.paste_transforms: Setting {1}.{2} to {3}"
                                      "".format(self.__class__.__name__, mover_name, each, attr_value))
                    mover_node.attr(each).set(attr_value)
        del inst

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    def mirror_transforms(self):
        """
        Mirrors joint mover transforms to the owning component's mirror (if it has one).

        example usage:
            .. code-block:: python

                asset = rig_asset.ART_RigAsset()
                leg = leg.BipedLeg(prefix="l")
                mirror = leg.create_mirror(prefix="r", suffix="", parent="root")
                leg.joint_mover.mirror_transforms()

        """
        pm.undoInfo(openChunk=True)
        if self.metanode.has_mirror.get():
            mirror = self.metanode.mirror_component.connections()[0]
            self.logger.info("{0}.mirror_transforms: Mirroring {1}'s transforms to {2}."
                             "".format(self.__class__.__name__, self.metanode.componentName.get(), mirror))

            mirror_inst = component_utils.get_component_instance(mirror)
            source_inst = component_utils.get_component_instance(self.metanode)
            self.copy_transforms()

            current_state = mirror_inst.joint_mover.metanode.pinned.get()
            if not current_state:
                mirror_inst.joint_mover.toggle_pin_component()

            mirror_inst.joint_mover.paste_transforms(mirror=True)
            component_utils.mirror_top_mover_grp(source_inst, mirror_inst)
            mirror_inst.joint_mover.toggle_pin_component()
        pm.undoInfo(closeChunk=True)

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    def toggle_visibility(self, state):
        """
        Toggles visibility of joint mover nodes.
        """

        guide_container = self.get_containers()[1]
        nodes = guide_container.getNodeList()
        self.metanode.movers_visible.set(state)

        for node in nodes:
            if node.getParent() is None:
                utils.set_attribute(node, "visibility", state)

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    def toggle_global_visibility(self, state):
        """
        Toggles the visibility of the global movers' shape nodes whose joints are set to be built.

        :param state: The visibility value to set on the global mover shapes.
        """

        movers = self.get_movers()
        global_movers = movers.get("global")

        for mover in global_movers:
            offset_name = "{0}_offset".format(mover.nodeName())
            if pm.objExists(offset_name):
                offset_node = pm.PyNode(offset_name)
                if offset_node.build_joint.get():
                    shape = mover.getShape()
                    shape.visibility.set(state)

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    def toggle_offset_visibility(self, state):
        """
        Toggles the visibility of the offset movers' shape nodes whose joints are set to be built.

        :param state: The visibility value to set on the offset mover shapes.
        """

        movers = self.get_movers()
        offset_movers = movers.get("offset")

        for mover in offset_movers:
            if mover.build_joint.get():
                shape = mover.getShape()
                shape.visibility.set(state)

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    def select_top_mover(self):
        """
        Selects the top-most joint mover control for this component.
        """

        pynode = pm.PyNode(self.metanode.mover_grp.connections()[0])
        mover = component_utils.get_top_level_mover(pynode)
        pm.select(mover.fullPath())
        pm.setToolTo("moveSuperContext")

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    def _find_nodes_to_rename(self, nodes, old_prefix, old_suffix):
        """
        Given a list of nodes, find only the transforms and rename them.

        :param nodes: A list of PyNodes
        :param old_prefix: The old prefix.
        :param old_suffix:  The old suffix.
        :return: Return a list of nodes(PyNodes) to rename, with their new name (str): [[node1, newName], [node2,
                    newName]]

        """

        unique_name = self.metanode.componentName.get()
        base_name = self.metanode.baseName.get()

        rename_nodes = []
        for node in nodes:
            types = pm.nodeType(node.name(), inherited=True)
            if "transform" in types:
                if base_name in node.name():
                    tail = utils.strip_name(node.name(), old_prefix, base_name, old_suffix)
                    new_name = unique_name + tail
                    self.logger.debug("{0}._find_nodes_to_rename: tail: {1}, new_name: {2}, node: {3}".format(
                        self.__class__.__name__, tail, new_name, node.name()))
                    rename_nodes.append([node, new_name])

        return rename_nodes

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    def _connect_movers_to_metanode(self, nodes):
        """
        Connect the joint mover controls to the owning component's metanode.

        :param nodes: a list of joint mover controls (PyNodes)
        """

        for key in nodes:
            mover_nodes = nodes.get(key)
            for node in mover_nodes:
                if node.hasAttr("isMoverGrp"):
                    self.metanode.mover_grp.connect(node.owning_component)

                if node.hasAttr("isMover"):
                    mover_type = node.moverType.get()
                    mover_types = {"global": "global_movers", "offset": "offset_movers"}
                    for each in mover_types:
                        if mover_type == each:
                            self.metanode.attr(mover_types.get(each)).connect(node.owning_component)

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    @staticmethod
    def set_mover_values(value_data):
        """
        Sets values on the joint mover controls.

        :param value_data: The values to set on the controls. It should be formatted like the dictionary generated
                by the get_mover_values method.

        """

        for mover in value_data:
            mover_node = pm.PyNode(mover)
            attribute_data = value_data.get(mover)
            for attribute in attribute_data:
                attribute_value = attribute_data.get(attribute)
                if pm.objExists(mover_node):
                    if mover_node.hasAttr(attribute):
                        mover_node.attr(attribute).set(attribute_value)

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    @staticmethod
    def _rename_dependent_attrs(renamed_nodes):
        """
        Renames the parentComponentBone attribute on any components that had a bone that was renamed.

        :param renamed_nodes: List of PyNodes and their new names. Used to check if the parentComponentBone attribute
                value is in that list, and if so, will then rename the attribute value for parentComponentBone.

        """

        components = component_utils.return_all_components()
        for component in components:
            parent_joint_name = component.parentComponentBone.get()
            for each in renamed_nodes:
                if each[0] == parent_joint_name:
                    utils.set_attribute(component, "parentComponentBone", each[1], "string")

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    @staticmethod
    def _reset_movers(movers):

        attributes = ["translateX", "translateY", "translateZ", "rotateX", "rotateY", "rotateZ", "scaleX", "scaleY",
                      "scaleZ"]
        default_values = {"translateX": 0, "translateY": 0, "translateZ": 0, "rotateX": 0, "rotateY": 0, "rotateZ": 0,
                          "scaleX": 1, "scaleY": 1, "scaleZ": 1}

        for mover in movers:
            for each in attributes:
                if mover.attr(each).isKeyable():
                    default_value = default_values.get(each)
                    mover.attr(each).set(default_value)

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    @property
    def metanode(self):
        """
        This property holds the metanode that is passed in from our component using the joint mover.

        :return: Returns the metanode from our component as a pynode.
        """
        return self._metanode

    @metanode.setter
    def metanode(self, new_value):

        self._metanode = pm.PyNode(new_value)