def remove_object(self, fbx_object): """Remove FbxObject or FbxNode to cache """ if not isinstance(fbx_object, (fbx.FbxObject)): raise bfCore.BfError( "object to remove must be instance of FbxObject or subclass. ({})" .format(fbx_object)) # get unique id object_id = fbx_object.GetUniqueID() # check if this object is in the cached if object_id not in self.id_data: raise bfCore.BfError("Object not cached, cannot remove: {}".format( fbx_object.GetName())) # destroy property cache property_cache = self.property_caches.pop(object_id) # destroy dummy object dummy_object = self.id_dummy_objects.pop(object_id) # del dummy_object # destroy BfIdData object bf_id_object = self.id_objects.pop(object_id) # del bf_id_object # destroy id and cache fbx_object = self.id_data.pop(object_id) # self.id_list.pop(object_id) self.id_list.remove(object_id) return True
def create_object(self, fbx_cls, name=None): """Create fbx object and add to cache TODO use class id object instead? ie FbxClassId.Create(...) TODO create property cache for new object """ # check user input if not issubclass(fbx_cls, fbx.FbxObject): raise bfCore.BfError( "Fbx class must be subclass of FbxObject: {}".format(fbx_cls)) # validate name if name is None: name = str(fbx_cls.__name__) name = bfFbxUtils.get_unique_name(name, self._scene) # create object fbx_object = fbx_cls.Create(self._fbx_manager, name) # connect object to scene self._scene.ConnectSrcObject(fbx_object) # add object to cache self.add_object(fbx_object) return fbx_object
def set_value(self, value): if self.VALUE_TYPE is not None: if not isinstance(value, self.VALUE_TYPE): raise bfCore.BfError("Value must be of type {} not {}".format( self.VALUE_TYPE, type(value))) self._value = value
def mapToSource(self, proxy_index): """ TODO """ if not proxy_index.isValid(): return Qt.QtCore.QModelIndex() # raise bfCore.BFbxError("Cannot map invalid index to source") if self.is_scene_index(proxy_index, reject_dummys=False): proxy_path = bpQtCore.IndexPath(proxy_index) if proxy_path.key() not in self._proxy_to_source_map: raise bfCore.BfError( "Failed to map scene index to source: {}".format( proxy_index)) source_path = self._proxy_to_source_map[proxy_path.key()] source_index = source_path.get(self.sourceModel()) return source_index elif self.is_property_index(proxy_index): property_key = self.get_property_key(proxy_index) if property_key not in self._proxy_to_source_property_map: return Qt.QtCore.QModelIndex() source_path = self._proxy_to_source_property_map[property_key] # find source index from property model property_model = self.get_property_model(proxy_index) source_index = source_path.get(property_model) return source_index else: raise bfCore.BfError( "Failed to map to source: {}".format(proxy_index))
def get_root(self): parent = self._parent while parent is not None: # if isinstance(parent, BFbxPropertyRoot): if parent.is_root(): return parent parent = parent.getParent() raise bfCore.BfError("Unable to find property root")
def get_property_key(self, index): if not self.is_property_index(index): raise bfCore.BfError( "Cannot create key for non-property index: {}".format(index)) id_object = index.internalPointer() key = "{}_{}".format(id_object.fbx_object_id(), id_object.value()) return key
def Set(self, value): if value in self.ENUM_VALUES: enum_index = self.ENUM_VALUES.index(value) elif value in self.ENUM_NAMES: enum_index = self.ENUM_NAMES.index(value) else: raise bfCore.BfError( "value not recognized, must be either fbx.eEuler enum or name: {}".format(value)) res = self._cast_property.Set(enum_index) return res
def get_child(self, child_index): if child_index >= self.child_count(): raise bfCore.BfError( "Child index out of range: {} ({}.{})".format( child_index, self.fbx_object().GetName(), self.fbx_property().GetName() ) ) return self._children[child_index]
def mapFromSource(self, source_index): """ if source_index belongs to scene model, then return super else if source index belongs to a property_model, then get object_id to find corresponding property mappings TODO checks """ if not source_index.isValid(): return Qt.QtCore.QModelIndex() # raise bfCore.BFbxError("Cannot map invalid index from source") # return Qt.QtCore.QModelIndex() if self.is_scene_index(source_index, reject_dummys=False): source_path = bpQtCore.IndexPath(source_index) if source_path.key() not in self._source_to_proxy_map: raise bfCore.BfError( "Failed to map scene index from source: {}".format( source_index)) proxy_path = self._source_to_proxy_map[source_path.key()] proxy_index = proxy_path.get(self) return proxy_index elif self.is_property_index(source_index): property_key = self.get_property_key(source_index) proxy_index = self._proxy_property_indices[property_key] return proxy_index else: raise bfCore.BfError( "Failed to map from source: {}".format(source_index))
def add_object(self, fbx_object): """Add FbxObject or FbxNode to cache """ if not isinstance(fbx_object, (fbx.FbxObject)): raise bfCore.BfError( "Cannot add object to cache, must be instance of FbxObject or subclass. ({})" .format(fbx_object)) # get unique id object_id = fbx_object.GetUniqueID() # check if this object is already cached if object_id in self.id_data: raise bfCore.BfError("Object already cached: {}".format( fbx_object.GetName())) # append id data self.id_data[object_id] = fbx_object self.id_list.append(object_id) # create BfIdData object id_object = BfIdData(object_id) self.id_objects[object_id] = id_object # create dummy object dummy_object = BfIdDummyData(object_id) self.id_dummy_objects[object_id] = dummy_object # create property cache property_cache = bfPropertyQtCache.BFbxPropertyCache(fbx_object) self.property_caches[object_id] = property_cache # create connection id object id_con_object = BfIdConData(object_id) self.id_con_objects[object_id] = id_con_object return True
def get_object(self, object_id): """Get cached FbxObject for specified uid """ if isinstance(object_id, (BfIdData, BfIdDummyData)): object_id = object_id.value() if object_id not in self.id_data: raise bfCore.BfError("No id found: {}".format(object_id)) # return None return self.id_data[object_id]
def AddInput(self, input_object): """ """ if input_object is None: return if not self.IsValid(): raise Exception("Class is not valid, cannot add input") if not isinstance( input_object, self.REFERENCE_TYPES ): raise bfCore.BfError( "Input object must be of type: {}, not: {}".format( self.REFERENCE_TYPES, type(input_object) ) ) # self._property.ConnectSrcObject(value) # check destination is not already connected if self._property.IsConnectedDstObject( input_object ): # TODO is an error neccesary? raise bfCore.BfError( "Input object already connected: {}".format( input_object.GetName()) ) # connect destination to property self._property.ConnectSrcObject(input_object) return True
def RemoveInput(self, input_object): # check destination is not already connected if not self._property.IsConnectedDstObject( input_object ): # TODO format message depending on object type raise bfCore.BfError( "Input object is not connected: {}".format( input_object.GetName()) ) # disconnect self._property.DisonnectSrcObject(input_object) return True
def get_fbx_object(self, value): """TODO checks """ if isinstance(value, Qt.QtCore.QModelIndex): object_id = self.get_fbx_object_id(value) else: object_id = value if object_id not in self._scene_cache.id_data: raise bfCore.BfError( "Object ID not found: {}".format(object_id) ) fbx_object = self._scene_cache.id_data[object_id] return fbx_object
def __init__(self, parent=None): super(BfConnectionWidgetBase, self).__init__(parent=parent) # self._name_filter_model = bpQtCore.BpSortFilterProxyModel() if self.CONNECTION_MODEL is None: raise bfCore.BfError( "Cannot instance connection widget base class") else: self._connection_model = self.CONNECTION_MODEL() # create widgets self.create_widgets() self.create_menus() self.create_view() self.connect_menus() # self.connect_widgets() self.create_layout()
def Set(self, value): """Disconnect old object from property and connect new object. """ if not isinstance( value, self.REFERENCE_TYPES ): raise bfCore.BfError( "Input value must be of type: {}, not: {}".format( self.REFERENCE_TYPES, type(value) ) ) # disconnect existing input node self._property.DisconnectAllSrcObject() # connect new destination if value is None: return self._property.ConnectSrcObject(value)
def get_fbx_object_pixmap(fbx_object, scale=None, scale_via_icon=True): """TODO use brType property to get name key Note: scaling via QIcon seems to give nicer results than QPixmap.scaled() """ # type_name = brutils.get_br_type_name( # fbx_object, err=False, verbose=False # ) if isinstance(fbx_object, fbx.FbxClassId): type_name = fbx_object.GetName() elif isinstance(fbx_object, fbx.FbxObject): type_name = fbx_object.ClassId.GetName() elif inspect.isclass(fbx_object): type_name = fbx_object.__name__ else: raise bfCore.BfError("Object not recognised: {}".format(fbx_object)) if type_name in RESOURCES.keys(): resource = RESOURCES[type_name] else: resource = RESOURCES["DEFAULT"] pixmap = Qt.QtGui.QPixmap(resource) if scale is not None: if scale_via_icon: icon = Qt.QtGui.QIcon(pixmap) pixmap = icon.pixmap(*scale) else: pixmap = pixmap.scaled(*scale) return pixmap
def log(cls, msg, err=False): if err: raise bfCore.BfError(msg) else: print msg