<commit_before>from medic.core import testerBase
from maya import OpenMaya


class LockedNormal(testerBase.TesterBase):
    Name = "LockedNormal"
    Description = "vertex(s) which has locked normal"
    Fixable = True

    def __init__(self):
        super(LockedNormal, self).__init__()

    def Match(self, node):
        return node.object().hasFn(OpenMaya.MFn.kMesh)

    def Test(self, node):
        it = None
        mesh = None
        try:
            it = OpenMaya.MItMeshVertex(node.object())
            mesh = OpenMaya.MFnMesh(node.object())
        except:
            return (False, None)

        result = False

        comp = OpenMaya.MFnSingleIndexedComponent()
        comp_obj = comp.create(OpenMaya.MFn.kMeshVertComponent)

        while (not it.isDone()):
            normal_indices = OpenMaya.MIntArray()
            it.getNormalIndices(normal_indices)

            for i in range(normal_indices.length()):
                if mesh.isNormalLocked(normal_indices[i]):
                    result = True
                    comp.addElement(it.index())
                    break

            it.next()

        return (result, comp_obj if result else None)

    def Fix(self, node, component, parameterParser):
        if node.dg().isFromReferencedFile():
            return False

        target_normal_indices = OpenMaya.MIntArray()

        mesh = OpenMaya.MFnMesh(node.object())
        it = OpenMaya.MItMeshVertex(node.getPath(), component)
        while (not it.isDone()):
            normal_indices = OpenMaya.MIntArray()
            it.getNormalIndices(normal_indices)

            for i in range(normal_indices.length()):
                target_normal_indices.append(normal_indices[i])
            it.next()

        mesh.unlockVertexNormals(target_normal_indices)

        return True

<commit_msg>fix lockedNormal, use MItMeshPolygon instead of MItMeshVertex, fix Fix() fucntion<commit_after>from medic.core import testerBase
from maya import OpenMaya


class LockedNormal(testerBase.TesterBase):
    Name = "LockedNormal"
    Description = "vertex(s) which has locked normal"
    Fixable = True

    def __init__(self):
        super(LockedNormal, self).__init__()

    def Match(self, node):
        return node.object().hasFn(OpenMaya.MFn.kMesh)

    def Test(self, node):
        it = None
        mesh = None
        try:
            it = OpenMaya.MItMeshPolygon(node.object())
            mesh = OpenMaya.MFnMesh(node.object())
        except:
            return (False, None)

        vertices = OpenMaya.MIntArray()

        while (not it.isDone()):
            for i in range(it.polygonVertexCount()):
                vi = it.vertexIndex(i)
                if vi in vertices:
                    continue

                ni = it.normalIndex(i)
                if mesh.isNormalLocked(ni):
                    vertices.append(vi)

            it.next()

        if vertices.length() > 0:
            comp = OpenMaya.MFnSingleIndexedComponent()
            comp_obj = comp.create(OpenMaya.MFn.kMeshVertComponent)
            comp.addElements(vertices)
            return (True, comp_obj)

        return (False, None)

    def Fix(self, node, component, parameterParser):
        if node.dg().isFromReferencedFile():
            return False

        mesh = OpenMaya.MFnMesh(node.object())

        vertices = OpenMaya.MIntArray()
        ver_comp = OpenMaya.MFnSingleIndexedComponent(component)
        ver_comp.getElements(vertices)

        mesh.unlockVertexNormals(vertices)

        return True


{'fraction_non_alphanumeric': 0.0943769426391636, 'fraction_numerical': 0.00028256569652444194, 'mean_word_length': 2.0809399477806787, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5097245', 'n_tokens_mistral': 1045, 'n_tokens_neox': 1004, 'n_words': 215}