Пример #1
0
    def setLocation(self, location):
        """Sets the location of the component.

        Args:
            location (str): Location that the component is on.

        Returns:
            bool: True if successful.

        """

        config = Config.getInstance()
        nameTemplate = config.getNameTemplate()
        locations = nameTemplate['locations']

        if location not in locations:
            #logger.warn("'{}' is not a valid location. Valid locations are: {}".format(location, ','.join(locations)))
            return False

        self.location.setValue(location)

        # The new location might cause a name colision.
        # forcing a name refresh will generate a new name if a collision exists
        self.setName(self.getName())

        return True
Пример #2
0
    def __init__(self, debugMode=False):
        super(Builder, self).__init__()
        self._buildElements = []
        self._sceneItemsById = {}

        self.config = Config.getInstance()

        self._debugMode = debugMode
Пример #3
0
    def __init__(self, name, parent=None, flags=None, metaData=None, **kwargs):
        super(Joint, self).__init__(name, parent=parent, flags=flags, metaData=metaData)
        self._radius = 1.0

        if 'radius' in kwargs:
            jointRadius = kwargs['radius']
        else:
            config = Config.getInstance()
            objSettings = config.getObjectSettings()
            jointSettings = objSettings.get('joint', None)
            if jointSettings is None:
                jointRadius = 1.0
            else:
                jointRadius = jointSettings.get('size', 1.0)

        self.setRadius(jointRadius)
Пример #4
0
    def pasteData(self, data, setLocation=True):
        """Paste a copied guide representation.

        Args:
            data (dict): The JSON data object.
            setLocation (bool): Whether to set the location after pasting data.

        Returns:
            bool: True if successful.

        """

        if not setLocation and data['location'] != self.getLocation():
            config = Config.getInstance()
            mirrorMap = config.getNameTemplate()['mirrorMap']
            if mirrorMap[data['location']] != data['location']:
                data = mirrorData(data, 0)
                del data['location']

        self.loadData(data)

        return True
Пример #5
0
    def setShape(self, shape):
        """Sets the shape of the control to the one specified.

        Args:
            shape (str): the desired shape of the control.

        Returns:
            bool: True if successful.

        """

        config = Config.getInstance()
        configShapes = config.getControlShapes()
        if shape not in configShapes.keys():
            raise KeyError(
                "'" + shape +
                "' is not a valid shape in the loaded config of class [" +
                config.__class__.__name__ + "]")

        self.setCurveData(configShapes[shape])

        return True
Пример #6
0
    def pasteSettings(self,
                      pos,
                      mirrored=False,
                      createConnectionsToExistingNodes=True):

        clipboardData = self.__class__._clipboardData

        krakenSystem = BeamSystem.getInstance()
        delta = pos - clipboardData['copyPos']
        self.clearSelection()
        pastedComponents = {}
        nameMapping = {}

        for componentData in clipboardData['components']:
            componentClass = krakenSystem.getComponentClass(
                componentData['class'])
            component = componentClass(parent=self.__rig)
            decoratedName = componentData[
                'name'] + component.getNameDecoration()
            nameMapping[decoratedName] = decoratedName
            if mirrored:
                config = Config.getInstance()
                mirrorMap = config.getNameTemplate()['mirrorMap']
                component.setLocation(mirrorMap[componentData['location']])
                nameMapping[decoratedName] = componentData[
                    'name'] + component.getNameDecoration()
                component.pasteData(componentData, setLocation=False)
            else:
                component.pasteData(componentData, setLocation=True)

            graphPos = component.getGraphPos()
            component.setGraphPos(
                Vec2(graphPos.x + delta.x(), graphPos.y + delta.y()))

            node = KNode(self, component)
            self.addNode(node)
            self.selectNode(node, False)

            # save a dict of the nodes using the orignal names
            pastedComponents[nameMapping[decoratedName]] = component

        # Create Connections
        for connectionData in clipboardData['connections']:
            sourceComponentDecoratedName, outputName = connectionData[
                'source'].split('.')
            targetComponentDecoratedName, inputName = connectionData[
                'target'].split('.')

            sourceComponent = None

            # The connection is either between nodes that were pasted, or from pasted nodes
            # to unpasted nodes. We first check that the source component is in the pasted group
            # else use the node in the graph.
            if sourceComponentDecoratedName in nameMapping:
                sourceComponent = pastedComponents[
                    nameMapping[sourceComponentDecoratedName]]
            else:
                if not createConnectionsToExistingNodes:
                    continue

                # When we support copying/pasting between rigs, then we may not find the source
                # node in the target rig.
                if not self.hasNode(sourceComponentDecoratedName):
                    continue
                node = self.getNode(sourceComponentDecoratedName)
                sourceComponent = node.getComponent()

            targetComponentDecoratedName = nameMapping[
                targetComponentDecoratedName]
            targetComponent = pastedComponents[targetComponentDecoratedName]

            outputPort = sourceComponent.getOutputByName(outputName)
            inputPort = targetComponent.getInputByName(inputName)

            inputPort.setConnection(outputPort)
            self.connectPorts(srcNode=sourceComponent.getDecoratedName(),
                              outputName=outputPort.getName(),
                              tgtNode=targetComponent.getDecoratedName(),
                              inputName=inputPort.getName())
Пример #7
0
    def getBuildName(self):
        """Returns the build name for the object.

        Returns:
            str: Name to be used in the DCC.

        """

        typeNameHierarchy = self.getTypeHierarchyNames()

        config = Config.getInstance()

        # If flag is set on object to use explicit name, return it.
        if config.getExplicitNaming() is True or \
                self.testFlag('EXPLICIT_NAME'):
            return self.getName()

        nameTemplate = config.getNameTemplate()

        # Get the token list for this type of object
        format = None
        for typeName in nameTemplate['formats'].keys():
            if typeName in typeNameHierarchy:
                format = nameTemplate['formats'][typeName]
                break

        if format is None:
            format = nameTemplate['formats']['default']

        objectType = None
        for eachType in typeNameHierarchy:
            if eachType in nameTemplate['types'].keys():
                objectType = eachType
                break

        altType = self.getMetaDataItem("altType")
        if altType is not None and nameTemplate['types'].get(altType,
                                                             None) is not None:
            objectType = altType

        if objectType is None:
            objectType = 'default'

        # Generate a name by concatenating the resolved tokens together.
        builtName = ""
        skipSep = False
        for token in format:

            if token is 'sep':
                if not skipSep:
                    builtName += nameTemplate['separator']

            elif token is 'location':
                parent = self.getParent()
                if parent is None:
                    raise ValueError(
                        "constraint [%s] does not have a parent." %
                        self.getName())
                component = parent.getComponent()
                if component is None:
                    raise ValueError(
                        "constraint [%s] parent [%s] does not have a component."
                        % (self.getName(), parent))
                location = component.getLocation()

                if location not in nameTemplate['locations']:
                    raise ValueError("Invalid location on: " + self.getPath())

                altLocation = self.getMetaDataItem("altLocation")
                if altLocation is not None and altLocation in nameTemplate[
                        'locations']:
                    location = altLocation

                builtName += location

            elif token is 'type':
                builtName += nameTemplate['types'][objectType]

            elif token is 'name':
                builtName += self.getName()

            elif token is 'component':
                if self.getParent() is None:
                    skipSep = True
                    continue

                builtName += self.getParent().getComponent().getName()

            elif token is 'container':
                if self.getContainer() is None:
                    skipSep = True
                    continue

                builtName += self.getContainer().getName()

            else:
                raise ValueError("Unresolvabled token '" + token +
                                 "' used on: " + self.getPath())

        return builtName
Пример #8
0
    def __init__(self, debugMode=False):
        super(Builder, self).__init__()

        self.config = Config.getInstance ()