Пример #1
0
 def test_register_will_store_the_given_caller(self):
     """testing if ProgressWindow.register() method will store the given
     name as a key in the ProgressWindow.callers dictionary
     """
     pm = ProgressDialogManager()
     caller = pm.register(100)
     self.assertIn(caller, pm.callers)
Пример #2
0
 def test_register_will_create_the_window_if_it_is_not_created_yet(self):
     """testing if the register method will create the progressWindow if it
     is not created yet
     """
     pm = ProgressDialogManager()
     self.assertFalse(pm.in_progress)
     pm.register(5)
     self.assertTrue(pm.in_progress)
Пример #3
0
def check_uvs():
    """checks uvs with no uv area

    The area of a 2d polygon calculation is based on the answer of Darius Bacon
    in http://stackoverflow.com/questions/451426/how-do-i-calculate-the-surface-area-of-a-2d-polygon
    """

    # skip if this is a representation
    v = staging.get('version')
    if v and Representation.repr_separator in v.take_name:
        return

    def area(p):
        return 0.5 * abs(sum(x0 * y1 - x1 * y0
                             for ((x0, y0), (x1, y1)) in segments(p)))

    def segments(p):
        return zip(p, p[1:] + [p[0]])

    all_meshes = pm.ls(type='mesh')
    mesh_count = len(all_meshes)

    from anima.ui.progress_dialog import ProgressDialogManager
    pdm = ProgressDialogManager()

    if not pm.general.about(batch=1) and mesh_count:
        pdm.use_ui = True

    caller = pdm.register(mesh_count, 'check_uvs()')

    meshes_with_zero_uv_area = []
    for node in all_meshes:
        all_uvs = node.getUVs()
        try:
            for i in range(node.numFaces()):
                uvs = []
                for j in range(node.numPolygonVertices(i)):
                    # uvs.append(node.getPolygonUV(i, j))
                    uv_id = node.getPolygonUVid(i, j)
                    uvs.append((all_uvs[0][uv_id], all_uvs[1][uv_id]))
                if area(uvs) == 0.0:
                    meshes_with_zero_uv_area.append(node)
                    break
        except RuntimeError:
            meshes_with_zero_uv_area.append(node)

        caller.step()

    if len(meshes_with_zero_uv_area):
        pm.select([node.getParent() for node in meshes_with_zero_uv_area])
        raise RuntimeError(
            """There are meshes with no uvs or faces with zero uv area:<br><br>
            %s""" %
            '<br>'.join(
                map(lambda x: x.name(),
                    meshes_with_zero_uv_area[:MAX_NODE_DISPLAY])
            )
        )
Пример #4
0
 def test_end_progress_will_close_dialog_if_there_are_no_callers_left(self):
     """testing if the end_progress method will close the progress dialog
     it there are no callers left
     """
     pm = ProgressDialogManager()
     caller = pm.register(5)
     caller.step()
     self.assertIn(caller, pm.callers)
     pm.end_progress(caller)
     self.assertNotIn(caller, pm.callers)
Пример #5
0
 def test_end_progress_method_removes_the_given_caller_from_list(self):
     """testing if the end_progress method will remove the given caller from
     the callers list
     """
     pm = ProgressDialogManager()
     caller = pm.register(5)
     caller.step()
     self.assertIn(caller, pm.callers)
     pm.end_progress(caller)
     self.assertNotIn(caller, pm.callers)
Пример #6
0
    def test_register_will_return_a_progress_caller_instance(self):
        """testing if the ProgressDialogManager.register() method will return a
        ProgressCaller instance
        """
        pm = ProgressDialogManager()
        caller = pm.register(10)
        self.assertIsInstance(caller, ProgressCaller)

        self.assertEqual(caller.max_steps, 10)
        self.assertEqual(caller.current_step, 0)
Пример #7
0
    def test_step_will_step_the_progress_dialog(self):
        """testing if the step method will call QProgressDialog.setRange()
        properly
        """
        pm = ProgressDialogManager()
        caller = pm.register(5, "test title")
        pm.step(caller, 2)

        self.assertIn("setRange", pm.dialog.call_info)

        # check the values
        self.assertEqual(pm.dialog.call_info["setRange"], [(0, 5), {}])
        self.assertEqual(pm.dialog.call_info["setValue"], [(2,), {}])
Пример #8
0
def check_component_edits_on_references():
    """check if there are component edits on references
    """
    # skip if this is a representation
    v = staging.get('version')
    if v and Representation.repr_separator in v.take_name:
        return

    import maya.cmds
    reference_query = maya.cmds.referenceQuery

    references_with_component_edits = []

    from anima.ui.progress_dialog import ProgressDialogManager
    pdm = ProgressDialogManager()

    all_refs = pm.listReferences(recursive=True)
    ref_count = len(all_refs)

    if not pm.general.about(batch=1) and ref_count:
        pdm.use_ui = True

    caller = pdm.register(
        ref_count,
        'Checking component edits on %i reference nodes' % ref_count
    )

    for ref in all_refs:
        all_edits = reference_query(ref.refNode.name(), es=True)
        # joined_edits = '\n'.join(all_edits)
        # if '.pt[' in joined_edits or '.pnts[' in joined_edits:
        #     references_with_component_edits.append(ref)
        for edit in all_edits:
            if '.pt[' in edit or '.pnts[' in edit:
                references_with_component_edits.append(ref)
                break
        caller.step()

    caller.end_progress()

    if len(references_with_component_edits):
        raise PublishError(
            'There are <b>component edits</b> on the following References:'
            '<br><br>%s<br><br>Please remove them!!!' %
            '<br>'.join(
                map(lambda x: x.refNode.name(),
                    references_with_component_edits[:MAX_NODE_DISPLAY])
            )
        )
Пример #9
0
    def test_step_removes_the_given_caller_if_it_is_at_maximum(self):
        """testing if the step method will automatically remove the caller from
        the list if the caller reached to its maximum
        """
        pm = ProgressDialogManager()
        self.assertFalse(pm.in_progress)
        caller = pm.register(5)
        self.assertTrue(pm.in_progress)
        self.assertEqual(caller.current_step, 0)
        self.assertTrue(pm.in_progress)
        self.assertIn(caller, pm.callers)

        for i in range(5):
            caller.step()

        self.assertNotIn(caller, pm.callers)
        self.assertFalse(pm.in_progress)
Пример #10
0
def check_out_of_space_uvs():
    """checks if there are uvs with u values that are bigger than 10.0
    """

    # skip if this is a representation
    v = staging.get('version')
    if v and Representation.repr_separator in v.take_name:
        return

    all_meshes = pm.ls(type='mesh')
    mesh_count = len(all_meshes)
    nodes_with_out_of_space_uvs = []

    from anima.ui.progress_dialog import ProgressDialogManager
    pdm = ProgressDialogManager()

    if not pm.general.about(batch=1) and mesh_count:
        pdm.use_ui = True

    caller = pdm.register(mesh_count, 'check_out_of_space_uvs()')

    for node in all_meshes:
        u, v = node.getUVs()
        u = sorted(u)
        if u[0] < 0.0 or u[-1] > 10.0 or v[0] < 0.0:
            nodes_with_out_of_space_uvs.append(node)

        caller.step()

    if len(nodes_with_out_of_space_uvs):
        # get transform nodes
        tra_nodes = map(
            lambda x: x.getParent(),
            nodes_with_out_of_space_uvs
        )
        pm.select(tra_nodes)
        raise RuntimeError(
            """There are nodes which have a UV value bigger than <b>10</b>:
            <br><br>%s""" %
            '<br>'.join(
                map(lambda x: x.name(),
                    tra_nodes[:MAX_NODE_DISPLAY])
            )
        )
Пример #11
0
    def test_step_will_increment_the_call_count_of_the_given_caller(self):
        """testing if the step method will increment the step of the caller
        """
        pm = ProgressDialogManager()
        caller = pm.register(100)
        self.assertEqual(caller.current_step, 0)

        pm.step(caller)
        self.assertEqual(caller.current_step, 1)

        pm.step(caller)
        self.assertEqual(caller.current_step, 2)
Пример #12
0
    def test_step_will_set_the_dialog_title(self):
        """testing if the step method will set the dialog title to the stepped
        caller
        """
        pm = ProgressDialogManager()
        test_title1 = "test title 1"
        test_title2 = "test title 2"
        caller1 = pm.register(5, test_title1)
        caller2 = pm.register(5, test_title2)
        pm.step(caller1)
        self.assertEqual(pm.dialog.call_info["setLabelText"], [("%s : " % test_title1,), {}])

        pm.step(caller2)
        self.assertEqual(pm.dialog.call_info["setLabelText"], [("%s : " % test_title2,), {}])
Пример #13
0
    def save_previs_to_shots(self, take_name):
        """exports previs to animation shots
        """
        self.pre_publish_previs()

        shot_tasks = self.scene_shot_tasks
        shot_nodes = self.shot_list
        shots_to_export = []

        for shot_node in shot_nodes:
            for shot_task in shot_tasks:
                for task in shot_task.tasks:
                    if task.type == self.anim_type:
                        shot_number = shot_task.name.split('_')[-1]
                        if shot_node.getShotName() == shot_number:
                            shots_to_export.append([shot_node, task, shot_number])

        from anima.env import mayaEnv
        from stalker import Version
        from anima.ui.progress_dialog import ProgressDialogManager
        pdm = ProgressDialogManager()
        pdm.close()

        m_env = mayaEnv.Maya()

        versions = []
        description = 'Auto Created By Shot Exporter'
        # create versions to save and show in pop-up window
        for shot_info in shots_to_export:
            version = Version(
                task=shot_info[1],
                description=description,
                take_name=take_name,
                created_by=self.logged_in_user
            )
            versions.append(version)

        if len(versions) != len(shots_to_export):
            from stalker.db.session import DBSession
            DBSession.rollback()
            raise RuntimeError('Something is critically wrong. Contact Mehmet ERER.')

        # pop-up a window to show everything will be saved properly before actually doing it
        message = 'Shots will be Saved as Below:\r\n'
        message += '\r'
        index = 0
        for shot_info in shots_to_export:
            v = versions[index]
            message += 'shot[ %s ] -> %s\n' % (shot_info[2], v)
            index += 1
        dialog = pm.confirmDialog(title='Important Warning',
                                  message=message,
                                  button=['OK, Start Saving Shots', 'STOP, wrong paths!'])
        if dialog == 'OK, Start Saving Shots':
            pass
        else:
            from stalker.db.session import DBSession
            DBSession.rollback()
            raise RuntimeError('Process Interrupted by User.')

        previs_version = self.current_version

        errored_shots = []
        ind = 0
        caller = pdm.register(len(shots_to_export), 'Batch Saving Previs Shot Nodes to Animation Shot Tasks...')
        from anima.env.mayaEnv import toolbox
        reload(toolbox)
        from stalker.db.session import DBSession
        for shot_info in shots_to_export:
            shot_task = versions[ind].task.parent
            try:
                # open previs version
                m_env.open(previs_version, force=True, reference_depth=3, skip_update_check=True)

                # clear scene
                except_this_shot = pm.PyNode(shot_info[0].name())
                self.clear_scene(except_this_shot)

                # set frame range before save
                toolbox.Animation.set_range_from_shot()

                # update shot.cut_in and shot.cut_out info
                cut_in = pm.playbackOptions(q=1, min=1)
                cut_out = pm.playbackOptions(q=1, max=1)
                shot_task.cut_in = int(cut_in)
                shot_task.cut_out = int(cut_out)

                # save it
                m_env.save_as(versions[ind])
            except:
                errored_shots.append(shot_info[2])
            else:
                # store information to database
                DBSession.add(shot_task)
                DBSession.add(versions[ind])
                DBSession.commit()
            ind += 1

            caller.step()

        if errored_shots:
            message = 'Shots could not be saved:\r\n'
            message += '\r'
            for shot in errored_shots:
                message += '[ %s ]\n' % shot
            pm.confirmDialog(title='Error', message=message, button='OK')
            DBSession.rollback()
            raise RuntimeError('Some Shots could not be saved. Contact Mehmet ERER.')

        # leave it as empty new file
        pm.newFile(force=True)
        message = 'Previs to Shots\r\n'
        message += '\r'
        message += 'Completed Succesfully.\r\n'
        pm.confirmDialog(title='Info', message=message, button='OK')
Пример #14
0
def check_uv_border_crossing():
    """checks if any of the uv shells are crossing uv borders
    """
    # skip if this is a representation
    v = staging.get('version')
    if v and Representation.repr_separator in v.take_name:
        return

    all_meshes = pm.ls(type='mesh')
    mesh_count = len(all_meshes)

    nodes_with_uvs_crossing_borders = []

    from anima.ui.progress_dialog import ProgressDialogManager
    pdm = ProgressDialogManager()

    if not pm.general.about(batch=1) and mesh_count:
        pdm.use_ui = True

    caller = pdm.register(mesh_count, 'check_out_of_space_uvs()')

    for node in all_meshes:
        all_uvs = node.getUVs()
        uv_shell_ids = node.getUvShellsIds()

        # prepare an empty dict of lists
        uvs_per_shell = {}
        for shell_id in range(uv_shell_ids[1]):
            uvs_per_shell[shell_id] = [[], []]

        for uv_id in range(len(uv_shell_ids[0])):
            u = all_uvs[0][uv_id]
            v = all_uvs[1][uv_id]
            shell_id = uv_shell_ids[0][uv_id]

            uvs_per_shell[shell_id][0].append(u)
            uvs_per_shell[shell_id][1].append(v)

        # now check all uvs per shell
        for shell_id in range(uv_shell_ids[1]):
            us = sorted(uvs_per_shell[shell_id][0])
            vs = sorted(uvs_per_shell[shell_id][1])

            # check first and last u and v values
            if int(us[0]) != int(us[-1]) or int(vs[0]) != int(vs[-1]):
                # they are not equal it is crossing spaces
                nodes_with_uvs_crossing_borders.append(node)
                break

        caller.step()

    if len(nodes_with_uvs_crossing_borders):
        # get transform nodes
        tra_nodes = map(
            lambda x: x.getParent(),
            nodes_with_uvs_crossing_borders
        )
        pm.select(tra_nodes)
        raise RuntimeError(
            """There are nodes with <b>UV-Shells</b> that are crossing
            <b>UV BORDERS</b>:<br><br>%s""" %
            '<br>'.join(
                map(lambda x: x.name(),
                    tra_nodes[:MAX_NODE_DISPLAY])
            )
        )
Пример #15
0
def export_edl():
    """exports edl of animation scenes
    """
    from anima.env.mayaEnv import Maya
    m = Maya()
    current_version = m.get_current_version()

    if not current_version:
        return

    # get sequenceManager1
    sm = pm.PyNode('sequenceManager1')
    seqs = sm.sequences.get()
    if not len(seqs):
        return

    seq1 = seqs[0]

    edl_path = tempfile.gettempdir()
    edl_file_name = '%s_v%03i.edl' % (
        current_version.nice_name,
        current_version.version_number
    )

    edl_file_full_path = os.path.join(edl_path, edl_file_name)

    # convert to MXF
    from anima.ui.progress_dialog import ProgressDialogManager
    pdm = ProgressDialogManager()

    #shots = seq1.shots.get()
    shots = pm.ls(type='shot')
    shot_count = len(shots)

    # before doing a playblast set all shot handles to 48
    for shot in pm.ls(type='shot'):
        if shot.hasAttr('handle'):
            shot.handle.set(48)

    caller = pdm.register(shot_count, title='Converting To MXF')

    # update shot outputs to the correct place first
    # there should be only one shot in the current animation scene
    # if there is more than one shot, the other publisher will already warn the
    # user so the code path will not reach to this point

    # we also should already have a video output created by another publisher
    playblast_file = None
    for output in current_version.outputs:
        extension = os.path.splitext(output.full_path)[-1]
        if extension in ['.mov', '.avi', '.mp4']:
            playblast_file = output
            break

    if not playblast_file:
        return
    shot = shots[0]
    shot.output.set(playblast_file.full_path)

    for i in seq1.metafuze():
        caller.step()

    # create EDL file
    from anima import utils
    mm = utils.MediaManager()
    l = sm.to_edl()
    with open(edl_file_full_path, 'w') as f:
        f.write(l.to_string())

    with open(edl_file_full_path, 'r') as f:
        link = mm.upload_version_output(current_version, f, edl_file_name)

    # add the link to database
    from stalker import db
    db.DBSession.commit()

    # revert the handles to 0
    for shot in pm.ls(type='shot'):
        if shot.hasAttr('handle'):
            shot.handle.set(0)
Пример #16
0
 def setUp(self):
     """set up the test
     """
     pm = ProgressDialogManager()
     # re initialize for each test
     pm.__init__()
Пример #17
0
    def check_referenced_versions(self, pdm=None):
        """Deeply checks all the references in the scene and returns a
        dictionary which has three keys called 'leave', 'update' and 'create'.

        Each of these keys correspond to a value of a list of
        :class:`~stalker.model.version.Version`\ s. Where the list in 'leave'
        key shows the Versions referenced (or deeply referenced) to the
        current scene which doesn't need to be changed.

        The list in 'update' key holds Versions those need to be updated to a
        newer version which are already exist.

        The list in 'create' key holds Version instance which needs to have its
        references to be updated to the never versions thus need a new version
        for them self.

        All the Versions in the list are sorted from the deepest to shallowest
        reference, so processing the list from 0th element to nth will always
        guarantee up to date info for the currently processed Version instance.

        Uses the top level references to get a Stalker Version instance and
        then tracks all the changes from these Version instances.

        :return: dictionary
        """
        if not pdm:
            from anima.ui.progress_dialog import ProgressDialogManager
            pdm = ProgressDialogManager()

        caller = \
            pdm.register(
                3,
                '%s.check_referenced_versions() prepare data' %
                self.__class__.__name__
            )

        # deeply get which file is referencing which other files
        self.deep_version_inputs_update()
        if caller:
            caller.step()

        from anima.env import empty_reference_resolution
        reference_resolution = \
            empty_reference_resolution(root=self.get_referenced_versions())

        if caller:
            caller.step()

        # reverse walk in DFS
        dfs_version_references = []

        version = self.get_current_version()
        if not version:
            return reference_resolution

        for v in version.walk_inputs():
            dfs_version_references.append(v)

        if caller:
            caller.step()

        # pop the first element which is the current scene
        dfs_version_references.pop(0)

        caller.end_progress()

        # register a new caller
        caller = pdm.register(
            len(dfs_version_references),
            '%s.check_referenced_versions()' % self.__class__.__name__
        )

        # iterate back in the list
        for v in reversed(dfs_version_references):
            # check inputs first
            to_be_updated_list = []
            for ref_v in v.inputs:
                if not ref_v.is_latest_published_version():
                    to_be_updated_list.append(ref_v)

            if to_be_updated_list:
                action = 'create'
                # check if there is a new published version of this version
                # that is using all the updated versions of the references
                latest_published_version = v.latest_published_version
                if latest_published_version and \
                        not v.is_latest_published_version():
                    # so there is a new published version
                    # check if its children needs any update
                    # and the updated child versions are already
                    # referenced to the this published version
                    if all([ref_v.latest_published_version
                            in latest_published_version.inputs
                            for ref_v in to_be_updated_list]):
                        # so all new versions are referenced to this published
                        # version, just update to this latest published version
                        action = 'update'
                    else:
                        # not all references are in the inputs
                        # so we need to create a new version as usual
                        # and update the references to the latest versions
                        action = 'create'
            else:
                # nothing needs to be updated,
                # so check if this version has a new version,
                # also there could be no reference under this referenced
                # version
                if v.is_latest_published_version():
                    # do nothing
                    action = 'leave'
                else:
                    # update to latest published version
                    action = 'update'

                # before setting the action check all the inputs in
                # resolution_dictionary, if any of them are update, or create
                # then set this one to 'create'
                if any(rev_v in reference_resolution['update'] or
                       rev_v in reference_resolution['create']
                       for rev_v in v.inputs):
                    action = 'create'

            # so append this v to the related action list
            reference_resolution[action].append(v)

            # from stalker import Version
            # assert isinstance(v, Version)
            caller.step(message=v.nice_name)

        caller.end_progress()

        return reference_resolution