def setCurrentConfig(self, index=None): if index is None: index = self.configsWidget.currentIndex() else: self.configsWidget.setCurrentIndex(index) if index == 0: Config.makeCurrent() else: ks = KrakenSystem.getInstance() configs = ks.getConfigClassNames() configClass = ks.getConfigClass(configs[index-1]) configClass.makeCurrent()
def setCurrentConfig(self, index=None): if index is None: index = self.configsWidget.currentIndex() else: self.configsWidget.setCurrentIndex(index) if index == 0: Config.makeCurrent() else: ks = KrakenSystem.getInstance() configs = ks.getConfigClassNames() configClass = ks.getConfigClass(configs[index - 1]) configClass.makeCurrent()
def __init__(self, debugMode = False): super(Builder, self).__init__() self._buildElements = [] self.config = Config.getInstance() self._debugMode = debugMode
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
def __init__(self, debugMode=False): super(Builder, self).__init__() self._buildElements = [] self.config = Config.getInstance() self._debugMode = debugMode
def __init__(self, name, parent=None, shape="null"): """Initializes control object. Arguments: name -- String, Name of the constraint. parent -- Object, parent object of this object. """ super(Control, self).__init__(name, parent=parent) config = Config.getInstance() configShapes = config.getControlShapes() if shape not in configShapes.keys(): raise KeyError("'" + shape + "' is not a valid shape in the loaded config.") self.setCurveData(configShapes[shape])
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
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)
def pasteData(self, data, setLocation=True): """Paste a copied guide representation. Arguments: data -- object, The JSON data object. Return: 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
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
def getBuildName(self): """Returns the build name for the object. Return: String, 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 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': if self.isTypeOf('Component'): location = self.getLocation() else: location = self.getComponent().getLocation() if location not in nameTemplate['locations']: raise ValueError("Invalid location on: " + self.getPath()) builtName += location elif token is 'type': if objectType == 'Locator' and self.testFlag('inputObject'): objectType = 'ComponentInput' elif objectType == 'Locator' and self.testFlag('outputObject'): objectType = 'ComponentOutput' builtName += nameTemplate['types'][objectType] elif token is 'name': builtName += self.getName() elif token is 'component': if self.getComponent() is None: skipSep = True continue builtName += self.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
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("operator [%s] does not have a parent." % self.getName()) location = parent.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().getName() elif token is 'container': if self.getContainer() is None: skipSep = True continue builtName += self.getContainer().getName() elif token is 'solverName': if self.isTypeOf("KLOperator"): builtName += self.solverTypeName else: builtName += self.canvasPresetPath.rpartition('.')[-1] elif token is 'solverSource': if self.isTypeOf("KLOperator"): builtName += self.extension else: builtName += re.sub( "[\W\d]", "", self.canvasPresetPath.rpartition('.')[0]) else: raise ValueError("Unresolvabled token '" + token + "' used on: " + self.getPath()) return builtName
def getBuildName(self): """Returns the build name for the object. Return: String, 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 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": if self.isTypeOf("Component"): location = self.getLocation() else: location = self.getComponent().getLocation() if location not in nameTemplate["locations"]: raise ValueError("Invalid location on: " + self.getPath()) builtName += location elif token is "type": if objectType == "Locator" and self.testFlag("inputObject"): objectType = "ComponentInput" elif objectType == "Locator" and self.testFlag("outputObject"): objectType = "ComponentOutput" builtName += nameTemplate["types"][objectType] elif token is "name": builtName += self.getName() elif token is "component": if self.getComponent() is None: skipSep = True continue builtName += self.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
def pasteSettings(self, pos, mirrored=False, createConnectionsToExistingNodes=True): clipboardData = self.__class__._clipboardData krakenSystem = KrakenSystem.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 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() )
def saveRig(self, saveAs=False): """Saves the current rig to disc. Args: saveAs (Boolean): Determines if this was a save as call or just a normal save. Returns: String: Path to the saved file. """ try: self.window().setCursor(QtCore.Qt.WaitCursor) filePath = self.openedFile if saveAs is True or not filePath or not os.path.isdir( os.path.dirname(filePath)): settings = self.window().getSettings() settings.beginGroup('Files') lastFilePath = settings.value( "lastFilePath", os.path.join(GetKrakenPath(), self.guideRig.getName())) settings.endGroup() filePathDir = os.path.dirname(lastFilePath) if not os.path.isdir(filePathDir): filePathDir = GetKrakenPath() fileDialog = QtWidgets.QFileDialog(self) fileDialog.setOption(QtWidgets.QFileDialog.DontUseNativeDialog, on=True) fileDialog.setWindowTitle('Save Rig Preset As') fileDialog.setDirectory(os.path.abspath(filePathDir)) fileDialog.setAcceptMode(QtWidgets.QFileDialog.AcceptSave) fileDialog.setNameFilter('Kraken Rig (*.krg)') fileDialog.setDefaultSuffix('krg') if fileDialog.exec_() == QtWidgets.QFileDialog.Accepted: filePath = fileDialog.selectedFiles()[0] else: return False self.synchGuideRig() # Backdrop Meta Data graphView = self.getGraphView() backdropNodes = graphView.getNodesOfType('KBackdrop') backdropData = [x.getData() for x in backdropNodes] # ===================== # Add Meta Data to rig # ===================== self.guideRig.setMetaDataItem('backdrops', backdropData) currConfig = Config.getInstance() if currConfig.getModulePath( ) == "kraken.core.configs.config.Config": self.guideRig.setMetaDataItem('config', "Default Config") else: self.guideRig.setMetaDataItem('config', currConfig.getModulePath()) # Write rig file try: self.guideRig.writeRigDefinitionFile(filePath) settings = self.window().getSettings() settings.beginGroup('Files') settings.setValue("lastFilePath", filePath) settings.endGroup() self.openedFile = filePath logger.inform('Saved Rig file: ' + filePath) except: logger.exception('Error Saving Rig File') return False return filePath finally: self.window().setCursor(QtCore.Qt.ArrowCursor)
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 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': if self.isTypeOf('Component'): location = self.getLocation() else: location = self.getComponent().getLocation() if location not in nameTemplate['locations']: raise ValueError("Invalid location on: " + self.getPath()) builtName += location elif token is 'type': if objectType == 'Locator' and self.testFlag('inputObject'): objectType = 'ComponentInput' elif objectType == 'Locator' and self.testFlag('outputObject'): objectType = 'ComponentOutput' builtName += nameTemplate['types'][objectType] elif token is 'name': builtName += self.getName() elif token is 'component': if self.getComponent() is None: skipSep = True continue builtName += self.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
def pasteSettings(self, pos, mirrored=False, createConnectionsToExistingNodes=True): clipboardData = self.__class__._clipboardData krakenSystem = KrakenSystem.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 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())