예제 #1
0
    def add_items(self, items, by_selection=False):
        """
        Add items to model with needed data
        Args:
            items(list): collection of item data

        Returns:
            None
        """

        self.beginResetModel()

        child_icon = "mouse-pointer" if by_selection else "file-o"

        # Add the items sorted by label
        sorter = (lambda x: x["label"])

        for item in sorted(items, key=sorter):

            asset_item = models.Item()
            asset_item.update(item)
            asset_item["icon"] = "folder"

            # Add namespace children
            namespaces = item["namespaces"]
            namespace_nodes = item["nodesByNamespace"]
            namespace_selection = item["selectByNamespace"]

            for namespace in sorted(namespaces):
                child = models.Item()
                child.update(item)
                child.update({
                    "label":
                    (namespace if namespace != ":" else "(no namespace)"),
                    "subset":
                    item["subsets"][namespace],
                    "namespace":
                    namespace,
                    "looks":
                    item["looks"],
                    "nodes":
                    namespace_nodes[namespace],
                    "selectBack":
                    namespace_selection[namespace],
                    "icon":
                    child_icon
                })
                asset_item.add_child(child)

            self.add_child(asset_item)

        self.endResetModel()
예제 #2
0
    def add_items(self, items):

        self.beginResetModel()

        # Collect the assets per look name (from the items of the AssetModel)
        look_subsets = defaultdict(list)
        for asset_item in items:
            asset = asset_item["asset"]
            for look in asset_item["loadedLooks"]:
                key = (look["name"], look["ident"])
                look_subsets[key].append(asset)

        for (subset, ident), assets in sorted(look_subsets.iteritems()):

            # Define nice label without "look" prefix for readability
            label = subset if not subset.startswith("look") else subset[4:]

            item_node = models.Item()
            item_node["label"] = label
            item_node["subset"] = subset
            item_node["ident"] = ident

            # Store the assets that have this subset available
            item_node["assets"] = assets

            self.add_child(item_node)

        self.endResetModel()
예제 #3
0
    def __init__(self, parent=None):
        super(FocusModel, self).__init__(parent=parent)
        self._feature = None
        self._side_icons = [
            lib.icon("bullseye", color=SIDE_COLOR[SIDE_A]),
            lib.icon("bullseye", color=SIDE_COLOR[SIDE_B]),
        ]

        node_a = models.Item({"side": SIDE_A})
        node_b = models.Item({"side": SIDE_B})

        self.nodes = {
            SIDE_A: node_a,
            SIDE_B: node_b,
        }
        self.add_child(node_a)
        self.add_child(node_b)
예제 #4
0
    def add_items(self, items):
        """
        Add items to model with needed data
        Args:
            items(list): collection of item data

        Returns:
            None
        """

        self.beginResetModel()

        # Add the items sorted by label
        sorter = lambda x: x["label"]

        for item in sorted(items, key=sorter):

            asset_item = models.Item()
            asset_item.update(item)
            asset_item["icon"] = "folder"

            # Add namespace children
            namespaces = item["namespaces"]
            for namespace in sorted(namespaces):
                child = models.Item()
                child.update(item)
                child.update({
                    "label":
                    (namespace if namespace != ":" else "(no namespace)"),
                    "namespace":
                    namespace,
                    "looks":
                    item["looks"],
                    "icon":
                    "folder-o"
                })
                asset_item.add_child(child)

            self.add_child(asset_item)

        self.endResetModel()
예제 #5
0
    def add_items(self, items):
        """Add items to model with needed data

        An item exists of:
            {
                "subset": 'name of subset',
                "asset": asset_document
            }

        Args:
            items(list): collection of item data

        Returns:
            None
        """

        self.beginResetModel()

        # Collect the assets per look name (from the items of the AssetModel)
        look_subsets = defaultdict(list)
        for asset_item in items:
            asset = asset_item["asset"]
            for look in asset_item["looks"]:
                key = look["name"]
                look_subsets[key].append(asset)

        for subset, assets in sorted(look_subsets.iteritems()):

            # Define nice label without "look" prefix for readability
            label = subset if not subset.startswith("look") else subset[4:]

            item_node = models.Item()
            item_node["label"] = label
            item_node["subset"] = subset

            # Amount of matching assets for this look
            item_node["match"] = len(set([_["name"] for _ in assets]))

            # Store the assets that have this subset available
            item_node["assets"] = assets

            self.add_child(item_node)

        self.endResetModel()
예제 #6
0
    def on_selected(self, *args, **kwargs):

        if self._selecting_back or self._selection_freezed:
            return

        selection = list()

        sel = OpenMaya.MGlobal.getActiveSelectionList()
        iter = OpenMaya.MItSelectionList(sel)

        # Loop though iterator objects
        while not iter.isDone():
            try:
                obj = iter.getDependNode()
                dagPath = OpenMaya.MDagPath.getAPathTo(obj)
                fullname = dagPath.fullPathName()
            except RuntimeError:
                pass
            else:
                selection.append(fullname)
            finally:
                iter.next()

        if not selection:
            return

        self.clear()
        self.beginResetModel()

        duplicated_id = set()

        for node in selection:

            asset = asset_by_id(utils.get_id_namespace_loosely(node))
            name = node.rsplit("|", 1)[-1]
            node_id = utils.get_id_loosely(node)
            node_id_status = _identifier.status(node)
            time = _identifier.get_time(node)

            if node_id_status == utils.Identifier.Duplicated:
                duplicated_id.add(node_id)

            namespaced = ":" in name
            namespace, name = name.rsplit(":", 1) if namespaced else ("", name)

            is_referenced = cmds.referenceQuery(node, isNodeReferenced=True)

            node_item = models.Item()
            node_item.update({
                "asset": asset,
                "name": name,
                "Id": node_id,
                "status": node_id_status,
                "time": time,
                "node": node,
                "namespace": namespace,
                "isReferenced": is_referenced,
            })

            self.add_child(node_item)

        self._duplicated_id = duplicated_id

        self.endResetModel()
예제 #7
0
    def add_sequence(self, sequence):
        root_index = QtCore.QModelIndex()
        last = self.rowCount(root_index)

        self.beginInsertRows(root_index, last, last)

        item = models.Item()
        item.update(sequence)

        # Must have
        item["root"] = sequence["root"]
        item["fpattern"] = sequence["fpattern"]
        item["paddingStr"] = sequence["paddingStr"]
        item["frames"] = "%d-%d" % (sequence["start"], sequence["end"])
        # Optional
        item["name"] = sequence.get("name", "")

        # Collect stereo data even user did not specify
        def take_side(fpattern):
            if "Left" in fpattern:
                return "Left", fpattern.replace("Left", "{stereo}")
            elif "Right" in fpattern:
                return "Right", fpattern.replace("Right", "{stereo}")
            else:
                return None, fpattern

        this_side, this_side_p = take_side(item["fpattern"])

        if this_side is not None:
            for row in reversed(range(last)):
                index = self.index(row, column=0, parent=root_index)
                other = index.internalPointer()
                if other.get("stereoSide"):
                    # Paired
                    continue

                other_side, other_side_p = take_side(other["fpattern"])
                if other_side is None:
                    continue

                if this_side != other_side and this_side_p == other_side_p:
                    item["stereoSide"] = this_side
                    item["stereoPattern"] = this_side_p
                    other["stereoSide"] = other_side
                    other["stereoPattern"] = other_side_p
                    break

        html_fpattern = "{dir}{head}{padding}{tail}"

        dir, fname = os.path.split(item["fpattern"])
        head, tail = fname.split(item["paddingStr"], 1)
        padding = item["paddingStr"]

        dir = "<span style=\"color:#666666\">%s/ </span>" % dir
        head = "<span style=\"color:#EEEEEE\">%s</span>" % head
        padding = "<span style=\"color:#666666\">%s</span>" % padding
        tail = "<span style=\"color:#999999\">%s</span>" % tail

        item["fpatternHTML"] = html_fpattern.format(dir=dir,
                                                    head=head,
                                                    padding=padding,
                                                    tail=tail)
        self.add_child(item)

        self.endInsertRows()
예제 #8
0
    def refresh(self):
        model_containers = list()

        host = api.registered_host()
        for container in host.ls():
            if container["loader"] == "ModelLoader":
                model_containers.append(container)

        self.clear()
        self.beginResetModel()

        for container in model_containers:

            subset_id = io.ObjectId(container["subsetId"])
            version_id = io.ObjectId(container["versionId"])
            version = io.find_one({"_id": version_id})
            latest = io.find_one({
                "type": "version",
                "parent": subset_id
            },
                                 sort=[("name", -1)],
                                 projection={"name": True})
            latest_repr = io.find_one({
                "type": "representation",
                "parent": latest["_id"],
                "name": "mayaBinary"
            })

            # Is latest version loaded ?
            is_latest = latest["name"] == version["name"]

            versions = io.find({
                "type": "version",
                "parent": subset_id
            },
                               sort=[("name", -1)])
            for version in versions:
                repr = io.find_one({
                    "type": "representation",
                    "parent": version["_id"],
                    "name": "mayaBinary"
                })

                protected = repr["data"].get("modelProtected")
                if protected is not None:
                    # Get protected list from previous version if not found
                    break
            protected = protected or set()

            namespace = container["namespace"]
            subset_group = container["subsetGroup"]
            subset_item = models.Item()
            subset_item.update({
                "subsetId":
                subset_id,
                "representation":
                latest_repr,
                "namespace":
                namespace,
                "node":
                subset_group,
                "name":
                subset_group.rsplit("|", 1)[-1][len(namespace):],
                "isLatest":
                is_latest,
            })

            members = cmds.sets(container["objectName"], query=True)
            for node in cmds.ls(members,
                                type="transform",
                                referencedNodes=True,
                                long=True):
                meshes = cmds.listRelatives(node,
                                            shapes=True,
                                            noIntermediate=True,
                                            type="mesh")
                if not meshes:
                    continue

                id = utils.get_id(node)
                is_locked = id in protected

                node_item = models.Item()
                node_item.update({
                    "node":
                    node,
                    "name":
                    node.rsplit("|", 1)[-1][len(namespace):],
                    "avalonId":
                    id,
                    "isLocked":
                    is_locked,
                    "isLatest":
                    is_latest,
                    "setLocked":
                    None,
                })

                subset_item.add_child(node_item)

            self.add_child(subset_item)

        self.endResetModel()