def _loadComponents(self, componentsJson): """Loads components from a JSON dict. Args: componentsJson (dict): Dictionary of components to load. """ Profiler.getInstance().push("__loadComponents") beamSystem = BeamSystem.getInstance() for componentData in componentsJson: # trim off the class name to get the module path. modulePath = '.'.join(componentData['class'].split('.')[:-1]) if modulePath is not "": try: importlib.import_module(modulePath) except: print "Warning: Error finding module path: " + modulePath continue componentClass = beamSystem.getComponentClass(componentData['class']) if 'name' in componentData: component = componentClass(name=componentData['name'], parent=self) else: component = componentClass(parent=self) component.loadData(componentData) Profiler.getInstance().pop()
def loadRigDefinition(self, jsonData): """Load a rig definition from a JSON structure. Args: jsonData (dict): JSON data containing the rig definition. Returns: bool: True if successful. """ Profiler.getInstance().push("loadRigDefinition:" + self.getName()) beamSystem = BeamSystem.getInstance() if 'name' in jsonData: self.setName(jsonData['name']) if 'components' in jsonData: self._loadComponents(jsonData['components']) if 'connections' in jsonData: self._makeConnections(jsonData['connections']) if 'metaData' in jsonData: for k, v in jsonData['metaData'].iteritems(): self.setMetaDataItem(k, v) if 'guideData' in jsonData: self.setMetaDataItem('guideData', jsonData['guideData']) Profiler.getInstance().pop()
def createLayout(self): self.menuLayout = QtWidgets.QHBoxLayout() self.menuLayout.setContentsMargins(0, 0, 0, 0) self.menuLayout.setSpacing(0) # Menu self.menuBar = QtWidgets.QMenuBar() # File Menu self.fileMenu = self.menuBar.addMenu('&File') self.newAction = self.fileMenu.addAction('&New') self.newAction.setShortcut('Ctrl+N') self.newAction.setObjectName("newAction") # Edit Menu self.editMenu = self.menuBar.addMenu('&Edit') # Build Menu self.buildMenu = self.menuBar.addMenu('&Build') self.buildGuideAction = self.buildMenu.addAction('Build &Guide') self.buildGuideAction.setShortcut('Ctrl+G') self.buildGuideAction.setObjectName("buildGuideAction") self.buildRigAction = self.buildMenu.addAction('Build &Rig') self.buildRigAction.setShortcut('Ctrl+B') self.buildRigAction.setObjectName("buildRigAction") # Config Widget self.configsParent = QtWidgets.QFrame(self) self.configsParent.setObjectName('configParent') self.configsParent.setFrameStyle(QtWidgets.QFrame.NoFrame) self.configsParent.setMinimumWidth(160) self.configsLayout = QtWidgets.QVBoxLayout() self.configsLayout.setContentsMargins(0, 0, 0, 0) self.configsLayout.setSpacing(0) self.configsWidget = QtWidgets.QComboBox() self.configsWidget.setAutoFillBackground(True) self.configsWidget.setObjectName('configWidget') self.configsWidget.setMinimumWidth(160) self.configsWidget.addItem('Default Config', userData='Default Config') self.configsLayout.addWidget(self.configsWidget) self.configsParent.setLayout(self.configsLayout) configs = BeamSystem.getInstance().getConfigClassNames() for config in configs: self.configsWidget.addItem(config.split('.')[-1], userData=config) self.rigNameLabel = RigNameLabel('Rig Name:') self.menuLayout.addWidget(self.menuBar, 3) self.menuLayout.addWidget(self.configsParent, 0) self.setLayout(self.menuLayout)
def setCurrentConfig(self, index=None): if index is None: index = self.configsWidget.currentIndex() else: self.configsWidget.setCurrentIndex(index) if index == 0: Config.makeCurrent() else: bs = BeamSystem.getInstance() configs = bs.getConfigClassNames() configClass = bs.getConfigClass(configs[index - 1]) configClass.makeCurrent()
def generateData (self): print "ComponentTreeWidget.generateData" self.bs = BeamSystem.getInstance () isSuccessful = self.bs.loadComponentModules () print self.bs.getComponentClassNames () print "isSuccessful ",isSuccessful componentClassNames = [] for componentClassName in sorted (self.bs.getComponentClassNames ()): cmpCls = self.bs.getComponentClass (componentClassName) if cmpCls.getComponentType () != 'Guide': continue componentClassNames.append (componentClassName) print "generateData", componentClassNames self._data = {'subDirs': {}, 'components': {}} for classItem in componentClassNames: nameSplit = classItem.rsplit('.', 1) className = nameSplit[-1] path = nameSplit[0].split('.') path.pop(len(path) - 1) parent = None for i, part in enumerate(path): if i == 0: if part not in self._data['subDirs'].keys(): self._data['subDirs'][part] = {'subDirs': {}, 'components': {}} parent = self._data['subDirs'][part] continue if part in parent['subDirs'].keys(): parent = parent['subDirs'][part] continue parent['subDirs'][part] = {'subDirs': {}, 'components': {}} parent = parent['subDirs'][part] parent['components'][className] = classItem print self._data return isSuccessful
def dropEvent(self, event): textParts = event.mimeData().text().split(':') print "dropEvent.textParts :%s" % (textParts) if textParts[0] == 'BeamComponent': componentClassName = textParts[1] # Add a component to the rig placed at the given position. dropPosition = self.mapToScene(event.pos()) # construct the node and add it to the graph. beamSystem = BeamSystem.getInstance() componentClass = beamSystem.getComponentClass(componentClassName) component = componentClass(parent=self.getRig()) component.setGraphPos(Vec2(dropPosition.x(), dropPosition.y())) node = KNode(self, component) self.addNode(node) self.selectNode(node, clearSelection=True, emitSignal=False) event.acceptProposedAction() else: super(GraphView, self).dropEvent(event)
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())
data['forearmXfo'] = forearmXfo data['wristXfo'] = wristXfo data['upVXfo'] = upVXfo data['bicepLen'] = bicepLen data['forearmLen'] = forearmLen return data @classmethod def getComponentType(cls): return 'Guide' @classmethod def getRigComponentClass(cls): return ArmComponentRig class ArmComponentRig(ArmComponent): """Arm Component Rig""" def __init__(self, name='arm', parent=None): Profiler.getInstance().push("Construct Arm Rig Component:" + name) super(ArmComponentRig, self).__init__(name, parent) #import rigging.beam.core.beam_system #reload(rigging.beam.core.beam_system) from rigging.beam.core.beam_system import BeamSystem bs = BeamSystem.getInstance() bs.registerComponent(ArmComponentGuide) bs.registerComponent(ArmComponentRig)
def showEvent(self, event): beamSystem = BeamSystem.getInstance()