<commit_before>"""Kraken - builders module.

Classes:
Builder -- Base builder object to build objects in DCC.

"""


from kraken.core.kraken_system import KrakenSystem
from kraken.core.configs.config import Config
from kraken.core.profiler import Profiler

from kraken.core.objects.components.component import Component
from kraken.core.objects.constraints.pose_constraint import PoseConstraint


class Builder(object):
    """Builder object for building objects in DCC's. Sub-class per DCC in a
    plugin."""


    def __init__(self, debugMode = False):
        super(Builder, self).__init__()
        self._buildElements = []

        self.config = Config.getInstance()

        self._debugMode = debugMode


    # ====================
    # Object registration
    # ====================
    def _registerSceneItemPair(self, kSceneItem, dccSceneItem):
        """Registers a pairing between the kraken scene item and the dcc scene item
        for querying later.

        Args:
            kSceneItem (object): kraken scene item that you want to pair.
            dccSceneItem (object): dcc scene item that you want to pair.

        Returns:
            bool: True if successful.

        """

        pairing = {
                   'src': kSceneItem,
                   'tgt': dccSceneItem
                  }

        self._buildElements.append(pairing)

        return True


    def getDCCSceneItem(self, kSceneItem):
        """Given a kSceneItem, returns the built dcc scene item.

        Args:
            kSceneItem (object): kSceneItem to base the search.

        Returns:
            object: The DCC Scene Item that corresponds to the given scene item

        """

        for builtElement in self._buildElements:
            if builtElement['src'] == kSceneItem:
                return builtElement['tgt']

        return None


    # ========================
    # SceneItem Build Methods
    # ========================
    def buildContainer(self, kSceneItem, buildName):
        """Builds a container / namespace object.

        Args:
            kSceneItem (object): kSceneItem that represents a container to be built.
            buildName (string): The name to use on the built object.

        Returns:
            object: DCC Scene Item that is created.

        """

        return None


    def buildLayer(self, kSceneItem, buildName):
        """Builds a layer object.

        Args:
            kSceneItem (object): kSceneItem that represents a layer to be built.
            buildName (string): The name to use on the built object.

        Returns:
            object: DCC Scene Item that is created.

        """

        return None


    def buildHierarchyGroup(self, kSceneItem, buildName):
        """Builds a hierarchy group object.

        Args:
            kSceneItem (object): kSceneItem that represents a group to be built.
            buildName (string): The name to use on the built object.

        Returns:
            object: DCC Scene Item that is created.

        """

        return None


    def buildGroup(self, kSceneItem, buildName):
        """Builds a group object.

        Args:
            kSceneItem (object): kSceneItem that represents a group to be built.
            buildName (string): The name to use on the built object.

        Returns:
            object: DCC Scene Item that is created.

        """

        return None


    def buildJoint(self, kSceneItem, buildName):
        """Builds a joint object.

        Args:
            kSceneItem (object): kSceneItem that represents a joint to be built.
            buildName (string): The name to use on the built object.

        Returns:
            object: DCC Scene Item that is created.

        """

        return None


    def buildLocator(self, kSceneItem, buildName):
        """Builds a locator / null object.

        Args:
            kSceneItem (object): kSceneItem that represents a locator / null to be built.
            buildName (string): The name to use on the built object.

        Returns:
            object: DCC Scene Item that is created.

        """

        return None


    def buildCurve(self, kSceneItem, buildName):
        """Builds a Curve object.

        Args:
            kSceneItem (object): kSceneItem that represents a curve to be built.
            buildName (string): The name to use on the built object.

        Returns:
            object: DCC Scene Item that is created.

        """

        return None


    def buildControl(self, kSceneItem, buildName):
        """Builds a Control object.

        Args:
            kSceneItem (object): kSceneItem that represents a control to be built.
            buildName (string): The name to use on the built object.

        Returns:
            object: DCC Scene Item that is created.

        """

        return None


    # ========================
    # Attribute Build Methods
    # ========================
    def buildBoolAttribute(self, kAttribute):
        """Builds a Bool attribute.

        Args:
            kAttribute (object): kAttribute that represents a string attribute to be built.

        Returns:
            object: True if successful.

        """

        return True


    def buildScalarAttribute(self, kAttribute):
        """Builds a Float attribute.

        Args:
            kAttribute (object): kAttribute that represents a string attribute to be built.

        Returns:
            bool: True if successful.

        """

        return True


    def buildIntegerAttribute(self, kAttribute):
        """Builds a Integer attribute.

        Args:
            kAttribute (object): kAttribute that represents a string attribute to be built.

        Returns:
            bool: True if successful.

        """

        return True


    def buildStringAttribute(self, kAttribute):
        """Builds a String attribute.

        Args:
            kAttribute (object): kAttribute that represents a string attribute to be built.

        Returns:
            bool: True if successful.

        """

        return True


    def buildAttributeGroup(self, kAttributeGroup):
        """Builds attribute groups on the DCC object.

        Args:
            kAttributeGroup (SceneObject): kraken object to build the attribute group on.

        Returns:
            bool: True if successful.

        """

        return True


    def connectAttribute(self, kAttribute):
        """Connects the driver attribute to this one.

        Args:
            kAttribute (object): attribute to connect.

        Returns:
            bool: True if successful.

        """

        return True


    # =========================
    # Constraint Build Methods
    # =========================
    def buildOrientationConstraint(self, kConstraint):
        """Builds an orientation constraint represented by the kConstraint.

        Args:
            kConstraint (object): kraken constraint object to build.

        Returns:
            object: DCC Scene Item that was created.

        """

        constraineeDCCSceneItem = self.getDCCSceneItem(kConstraint.getConstrainee())
        dccSceneItem = None # Add constraint object here.
        self._registerSceneItemPair(kConstraint, dccSceneItem)

        return dccSceneItem


    def buildPoseConstraint(self, kConstraint):
        """Builds an pose constraint represented by the kConstraint.

        Args:
            kConstraint (object): kraken constraint object to build.

        Returns:
            bool: True if successful.

        """

        constraineeDCCSceneItem = self.getDCCSceneItem(kConstraint.getConstrainee())
        dccSceneItem = None # Add constraint object here.
        self._registerSceneItemPair(kConstraint, dccSceneItem)

        return dccSceneItem


    def buildPositionConstraint(self, kConstraint):
        """Builds an position constraint represented by the kConstraint.

        Args:
            kConstraint (object): kraken constraint object to build.

        Returns:
            bool: True if successful.

        """

        constraineeDCCSceneItem = self.getDCCSceneItem(kConstraint.getConstrainee())
        dccSceneItem = None # Add constraint object here.
        self._registerSceneItemPair(kConstraint, dccSceneItem)

        return dccSceneItem


    def buildScaleConstraint(self, kConstraint):
        """Builds an scale constraint represented by the kConstraint.

        Args:
            kConstraint (object): kraken constraint object to build.

        Returns:
            bool: True if successful.

        """

        constraineeDCCSceneItem = self.getDCCSceneItem(kConstraint.getConstrainee())
        dccSceneItem = None # Add constraint object here.
        self._registerSceneItemPair(kConstraint, dccSceneItem)

        return dccSceneItem


    # ========================
    # Component Build Methods
    # ========================
    def buildXfoConnection(self, componentInput):
        """Builds the constraint between the target and connection target.

        Args:
            componentInput (object): kraken component input to build connections for.

        Returns:
            bool: True if successful.

        """

        if componentInput.isConnected() is False:
            return False

        connection = componentInput.getConnection()
        connectionTarget = connection.getTarget()
        inputTarget = componentInput.getTarget()

        if connection.getDataType().endswith('[]'):
            if componentInput.getIndex() > len(connection.getTarget()) - 1:

                inputParent = componentInput.getParent()
                inputParentDecoration = inputParent.getNameDecoration()
                fullInputName = inputParent.getName() + inputParentDecoration + "." + componentInput.getName()

                raise Exception(fullInputName + " index ("
                                + str(componentInput.getIndex()) + ") is out of range ("
                                + str(len(connection.getTarget()) - 1) + ")!")

            connectionTarget = connection.getTarget()[componentInput.getIndex()]
        else:
            connectionTarget = connection.getTarget()

        constraint = PoseConstraint('_'.join([inputTarget.getName(), 'To', connectionTarget.getName()]))
        constraint.setMaintainOffset(True)
        constraint.setConstrainee(inputTarget)
        constraint.addConstrainer(connectionTarget)

        dccSceneItem = self.buildPoseConstraint(constraint)
        self._registerSceneItemPair(componentInput, dccSceneItem)

        return True


    def buildAttributeConnection(self, componentInput):
        """Builds the link between the target and connection target.

        Args:
            componentInput (object): kraken connection to build.

        Returns:
            bool: True if successful.

        """

        # Implemented in DCC Plugins.

        return True


    # =========================
    # Operator Builder Methods<commit_msg>There should be no offset between an output xfo from one component and the connected input of another.  If there is, the component author made a mistake, so add a check here eventually to report any offsets.  Need to check existing components when implementing this change to make sure there are no mistakes.<commit_after>"""Kraken - builders module.

Classes:
Builder -- Base builder object to build objects in DCC.

"""


from kraken.core.kraken_system import KrakenSystem
from kraken.core.configs.config import Config
from kraken.core.profiler import Profiler

from kraken.core.objects.components.component import Component
from kraken.core.objects.constraints.pose_constraint import PoseConstraint


class Builder(object):
    """Builder object for building objects in DCC's. Sub-class per DCC in a
    plugin."""


    def __init__(self, debugMode = False):
        super(Builder, self).__init__()
        self._buildElements = []

        self.config = Config.getInstance()

        self._debugMode = debugMode


    # ====================
    # Object registration
    # ====================
    def _registerSceneItemPair(self, kSceneItem, dccSceneItem):
        """Registers a pairing between the kraken scene item and the dcc scene item
        for querying later.

        Args:
            kSceneItem (object): kraken scene item that you want to pair.
            dccSceneItem (object): dcc scene item that you want to pair.

        Returns:
            bool: True if successful.

        """

        pairing = {
                   'src': kSceneItem,
                   'tgt': dccSceneItem
                  }

        self._buildElements.append(pairing)

        return True


    def getDCCSceneItem(self, kSceneItem):
        """Given a kSceneItem, returns the built dcc scene item.

        Args:
            kSceneItem (object): kSceneItem to base the search.

        Returns:
            object: The DCC Scene Item that corresponds to the given scene item

        """

        for builtElement in self._buildElements:
            if builtElement['src'] == kSceneItem:
                return builtElement['tgt']

        return None


    # ========================
    # SceneItem Build Methods
    # ========================
    def buildContainer(self, kSceneItem, buildName):
        """Builds a container / namespace object.

        Args:
            kSceneItem (object): kSceneItem that represents a container to be built.
            buildName (string): The name to use on the built object.

        Returns:
            object: DCC Scene Item that is created.

        """

        return None


    def buildLayer(self, kSceneItem, buildName):
        """Builds a layer object.

        Args:
            kSceneItem (object): kSceneItem that represents a layer to be built.
            buildName (string): The name to use on the built object.

        Returns:
            object: DCC Scene Item that is created.

        """

        return None


    def buildHierarchyGroup(self, kSceneItem, buildName):
        """Builds a hierarchy group object.

        Args:
            kSceneItem (object): kSceneItem that represents a group to be built.
            buildName (string): The name to use on the built object.

        Returns:
            object: DCC Scene Item that is created.

        """

        return None


    def buildGroup(self, kSceneItem, buildName):
        """Builds a group object.

        Args:
            kSceneItem (object): kSceneItem that represents a group to be built.
            buildName (string): The name to use on the built object.

        Returns:
            object: DCC Scene Item that is created.

        """

        return None


    def buildJoint(self, kSceneItem, buildName):
        """Builds a joint object.

        Args:
            kSceneItem (object): kSceneItem that represents a joint to be built.
            buildName (string): The name to use on the built object.

        Returns:
            object: DCC Scene Item that is created.

        """

        return None


    def buildLocator(self, kSceneItem, buildName):
        """Builds a locator / null object.

        Args:
            kSceneItem (object): kSceneItem that represents a locator / null to be built.
            buildName (string): The name to use on the built object.

        Returns:
            object: DCC Scene Item that is created.

        """

        return None


    def buildCurve(self, kSceneItem, buildName):
        """Builds a Curve object.

        Args:
            kSceneItem (object): kSceneItem that represents a curve to be built.
            buildName (string): The name to use on the built object.

        Returns:
            object: DCC Scene Item that is created.

        """

        return None


    def buildControl(self, kSceneItem, buildName):
        """Builds a Control object.

        Args:
            kSceneItem (object): kSceneItem that represents a control to be built.
            buildName (string): The name to use on the built object.

        Returns:
            object: DCC Scene Item that is created.

        """

        return None


    # ========================
    # Attribute Build Methods
    # ========================
    def buildBoolAttribute(self, kAttribute):
        """Builds a Bool attribute.

        Args:
            kAttribute (object): kAttribute that represents a string attribute to be built.

        Returns:
            object: True if successful.

        """

        return True


    def buildScalarAttribute(self, kAttribute):
        """Builds a Float attribute.

        Args:
            kAttribute (object): kAttribute that represents a string attribute to be built.

        Returns:
            bool: True if successful.

        """

        return True


    def buildIntegerAttribute(self, kAttribute):
        """Builds a Integer attribute.

        Args:
            kAttribute (object): kAttribute that represents a string attribute to be built.

        Returns:
            bool: True if successful.

        """

        return True


    def buildStringAttribute(self, kAttribute):
        """Builds a String attribute.

        Args:
            kAttribute (object): kAttribute that represents a string attribute to be built.

        Returns:
            bool: True if successful.

        """

        return True


    def buildAttributeGroup(self, kAttributeGroup):
        """Builds attribute groups on the DCC object.

        Args:
            kAttributeGroup (SceneObject): kraken object to build the attribute group on.

        Returns:
            bool: True if successful.

        """

        return True


    def connectAttribute(self, kAttribute):
        """Connects the driver attribute to this one.

        Args:
            kAttribute (object): attribute to connect.

        Returns:
            bool: True if successful.

        """

        return True


    # =========================
    # Constraint Build Methods
    # =========================
    def buildOrientationConstraint(self, kConstraint):
        """Builds an orientation constraint represented by the kConstraint.

        Args:
            kConstraint (object): kraken constraint object to build.

        Returns:
            object: DCC Scene Item that was created.

        """

        constraineeDCCSceneItem = self.getDCCSceneItem(kConstraint.getConstrainee())
        dccSceneItem = None # Add constraint object here.
        self._registerSceneItemPair(kConstraint, dccSceneItem)

        return dccSceneItem


    def buildPoseConstraint(self, kConstraint):
        """Builds an pose constraint represented by the kConstraint.

        Args:
            kConstraint (object): kraken constraint object to build.

        Returns:
            bool: True if successful.

        """

        constraineeDCCSceneItem = self.getDCCSceneItem(kConstraint.getConstrainee())
        dccSceneItem = None # Add constraint object here.
        self._registerSceneItemPair(kConstraint, dccSceneItem)

        return dccSceneItem


    def buildPositionConstraint(self, kConstraint):
        """Builds an position constraint represented by the kConstraint.

        Args:
            kConstraint (object): kraken constraint object to build.

        Returns:
            bool: True if successful.

        """

        constraineeDCCSceneItem = self.getDCCSceneItem(kConstraint.getConstrainee())
        dccSceneItem = None # Add constraint object here.
        self._registerSceneItemPair(kConstraint, dccSceneItem)

        return dccSceneItem


    def buildScaleConstraint(self, kConstraint):
        """Builds an scale constraint represented by the kConstraint.

        Args:
            kConstraint (object): kraken constraint object to build.

        Returns:
            bool: True if successful.

        """

        constraineeDCCSceneItem = self.getDCCSceneItem(kConstraint.getConstrainee())
        dccSceneItem = None # Add constraint object here.
        self._registerSceneItemPair(kConstraint, dccSceneItem)

        return dccSceneItem


    # ========================
    # Component Build Methods
    # ========================
    def buildXfoConnection(self, componentInput):
        """Builds the constraint between the target and connection target.

        Args:
            componentInput (object): kraken component input to build connections for.

        Returns:
            bool: True if successful.

        """

        if componentInput.isConnected() is False:
            return False

        connection = componentInput.getConnection()
        connectionTarget = connection.getTarget()
        inputTarget = componentInput.getTarget()

        if connection.getDataType().endswith('[]'):
            if componentInput.getIndex() > len(connection.getTarget()) - 1:

                inputParent = componentInput.getParent()
                inputParentDecoration = inputParent.getNameDecoration()
                fullInputName = inputParent.getName() + inputParentDecoration + "." + componentInput.getName()

                raise Exception(fullInputName + " index ("
                                + str(componentInput.getIndex()) + ") is out of range ("
                                + str(len(connection.getTarget()) - 1) + ")!")

            connectionTarget = connection.getTarget()[componentInput.getIndex()]
        else:
            connectionTarget = connection.getTarget()

        # There should be no offset between an output xfo from one component and the connected input of another
        # If connected, they should be exactly the same.
        constraint = inputTarget.constrainTo(connectionTarget, maintainOffset=False, addToConstraintList=False)

        dccSceneItem = self.buildPoseConstraint(constraint)
        self._registerSceneItemPair(componentInput, dccSceneItem)

        return True


    def buildAttributeConnection(self, componentInput):
        """Builds the link between the target and connection target.

        Args:
            componentInput (object): kraken connection to build.

        Returns:
            bool: True if successful.

        """

        # Implemented in DCC Plugins.

        return True


    # =========================
    # Operator Builder Methods
{'fraction_non_alphanumeric': 0.09221099887766554, 'fraction_numerical': 0.00017957351290684624, 'mean_word_length': 2.1247019217281524, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2202739', 'n_tokens_mistral': 5616, 'n_tokens_neox': 5220, 'n_words': 1880}