def update_info(self):
        """
        Updates the current widget
        """

        current_selection = artellapipe.TagsMgr().get_current_selection()

        if not artellapipe.TagsMgr().current_selection_has_metadata_node():
            self._curr_info_lbl.setText(
                'Selected object "{0}" has not valid metadata info!'.format(
                    current_selection))
            self._new_tagger_node_btn.setText(
                'Create Tag Data node for "{0}"?'.format(current_selection))
            return

        if not artellapipe.TagsMgr(
        ).check_if_current_selected_metadata_node_has_valid_info():
            self._curr_info_lbl.setText(
                'Object "{0}" has not valid Tag Data information!'.format(
                    current_selection))
            return

        self._curr_info_lbl.setText(
            'Object "{0}" valid Tag Data information!'.format(
                current_selection))
    def create_new_tag_data_node_for_current_selection(self, asset_type=None):
        """
        Creates a new tag data node with the info af all available editors
        :param asset_type: str or None (optional)
        """

        current_selection = artellapipe.TagsMgr().get_current_selection()

        if not current_selection or current_selection == artellapipe.TagsMgr().TagDefinitions.SCENE_SELECTION_NAME \
                or not tp.Dcc.object_exists(current_selection):
            current_selection = tp.Dcc.selected_nodes()
            if current_selection:
                current_selection = current_selection[0]
            else:
                current_selection = artellapipe.TagsMgr(
                ).get_current_selection()

        if not artellapipe.TagsMgr().current_selection_has_metadata_node():
            if current_selection != artellapipe.TagsMgr(
            ).TagDefinitions.SCENE_SELECTION_NAME:
                new_tag_data_node = tp.Dcc.create_node(
                    node_type='network',
                    node_name=artellapipe.TagsMgr(
                    ).TagDefinitions.TAG_DATA_NODE_NAME)
                self._fill_new_tag_data_node(new_tag_data_node,
                                             current_selection)

                for editor in self._editors:
                    editor.fill_tag_node(new_tag_data_node)

                # if asset_type is not None and new_tag_data_node:
                #     attr_exists = tp.Dcc.attribute_exists(node=new_tag_data_node, attribute_name='types')
                #     if not attr_exists:
                #         tp.Dcc.add_string_attribute(node=new_tag_data_node, attribute_name='types')
                #     if asset_type == 'Props' or asset_type == 'props':
                #         tp.Dcc.set_string_attribute_value(
                #         node=new_tag_data_node, attribute_name='types', attribute_value='prop')
                #     elif asset_type == 'Background Elements' or asset_type == 'background elements':
                #         tp.Dcc.set_string_attribute_value(
                #         node=new_tag_data_node, attribute_name='types', attribute_value='background_element')
                #     elif asset_type == 'Character' or asset_type == 'character':
                #         tp.Dcc.set_string_attribute_value(
                #         node=new_tag_data_node, attribute_name='types', attribute_value='character')
                #     elif asset_type == 'Light Rig' or asset_type == 'light rig':
                #         tp.Dcc.set_string_attribute_value(
                #         node=new_tag_data_node, attribute_name='types', attribute_value='light_rig')
                #     tp.Dcc.lock_attribute(node=new_tag_data_node, attribute_name='types')

            else:
                new_tag_data_node = tp.Dcc.create_node(
                    node_type='network',
                    node_name=artellapipe.TagsMgr(
                    ).TagDefinitions.TAG_DATA_SCENE_NAME)
                tp.Dcc.clear_selection()

        if current_selection == artellapipe.TagsMgr(
        ).TagDefinitions.SCENE_SELECTION_NAME:
            tp.Dcc.clear_selection()
        else:
            tp.Dcc.select_object(current_selection)
    def update_tag_buttons_state(self, sel=None):
        """
        Updates the type tag attribute of the tag data node
        :param name: str, name of the type tag to add/remove
        """

        tag_data_node = artellapipe.TagsMgr().get_tag_data_node_from_current_selection(sel)
        if tag_data_node is None:
            return

        self.set_tag_widgets_state(False)

        attr_exists = tp.Dcc.attribute_exists(node=tag_data_node, attribute_name='types')
        if attr_exists:
            types = tp.Dcc.get_attribute_value(node=tag_data_node, attribute_name='types')
            if types is not None and types != '':
                types = types.split()
                for t in types:
                    for i in range(self._type_grid.columnCount()):
                        for j in range(self._type_grid.rowCount()):
                            container_w = self._type_grid.cellWidget(j, i)
                            if container_w is not None:
                                tag_w = container_w.containedWidget
                                tag_name = tag_w.get_name()
                                if tag_name == t:
                                    tag_w._btn.blockSignals(True)
                                    tag_w._btn.setChecked(True)
                                    tag_w._btn.blockSignals(False)
    def update_tag_buttons_state(self, sel=None):
        """
        Updates the state of the tag buttons in the editor
        :param sel: variant
        """

        tag_data_node = artellapipe.TagsMgr(
        ).get_tag_data_node_from_current_selection(sel)
        if tag_data_node is None or not tp.Dcc.object_exists(tag_data_node):
            return

        attr_exists = tp.Dcc.attribute_exists(node=tag_data_node,
                                              attribute_name='proxy')
        if attr_exists:
            proxy_group = tp.Dcc.list_connections(node=tag_data_node,
                                                  attribute_name='proxy')
            if proxy_group:
                proxy_group = proxy_group[0]
            if proxy_group is not None and tp.Dcc.object_exists(proxy_group):
                self._low_line.setText(proxy_group)

        attr_exists = tp.Dcc.attribute_exists(node=tag_data_node,
                                              attribute_name='hires')
        if attr_exists:
            hires_group = tp.Dcc.list_connections(node=tag_data_node,
                                                  attribute_name='hires')
            if hires_group:
                hires_group = hires_group[0]
            if hires_group is not None and tp.Dcc.object_exists(hires_group):
                self._high_line.setText(hires_group)
def get_control(node, rig_control):
    """
    Returns main control of the current asset
    :return: str
    """

    tag_node = artellapipe.TagsMgr().get_tag_node(project=artellapipe.solstice,
                                                  node=node)
    if not tag_node:
        return None
    asset_node = tag_node.get_asset_node()
    if not asset_node:
        LOGGER.warning(
            'Tag Data node: {} is not linked to any asset! Aborting operation ...'
            .format(tag_node))
        return
    node_to_apply_xform = asset_node.node
    attrs = tp.Dcc.list_user_attributes(node_to_apply_xform)
    if attrs and type(attrs) == list:
        if rig_control not in attrs:
            all_children = tp.Dcc.list_children(node)
            for child in all_children:
                if child.endswith(rig_control):
                    return child
        else:
            root_ctrl = tp.Dcc.get_attribute_value(node_to_apply_xform,
                                                   attribute_name=rig_control)
            if not tp.Dcc.object_exists(root_ctrl):
                LOGGER.warning(
                    'Control "{}" does not exists in current scene! Aborting operation...'
                    .format(root_ctrl))
                return None
            return root_ctrl

    return None
    def _update_ui(self):
        """
        If a valid Maya object is selected, tagger tabs is show or hide otherwise
        """

        if artellapipe.TagsMgr().current_selection_has_metadata_node():
            self._stack.slide_in_index(1)
        else:
            self._stack.slide_in_index(0)
    def initialize(self):
        self._type_grid.clear()

        tag_types = artellapipe.TagsMgr().get_tag_types()
        if not tag_types:
            LOGGER.warning('No Tag Types defined in current project!')
            return

        for tag_type in tag_types:
            tag_widget = TaggerTypeWidget(type_title=tag_type)
            tag_widget._btn.toggled.connect(partial(self.update_data, tag_widget.get_name()))
            self._type_grid.add_widget_first_empty_cell(tag_widget)
    def _on_selection_changed(self, *args, **kwargs):
        """
        Internal callback function that is called each time the user changes scene selection
        """

        sel = artellapipe.TagsMgr().get_current_selection()

        self._update_current_info()
        self._update_ui()
        for editor in self._editors:
            editor.reset()
            editor.update_tag_buttons_state(sel)
    def _update_current_info(self):
        """
        Internal callback function that updates the widget that is showed in the Artella Tagger UI
        :return:
        """

        current_selection = artellapipe.TagsMgr().get_current_selection()

        self._breadcrumb.set([current_selection])

        self._tagger_info.update_info()

        if not artellapipe.TagsMgr().current_selection_has_metadata_node():
            self._curr_info_image.setPixmap(self._error_pixmap)
            return
        if not artellapipe.TagsMgr(
        ).check_if_current_selected_metadata_node_has_valid_info():
            self._curr_info_image.setPixmap(self._warning_pixmap)
            return

        self._curr_info_image.setPixmap(self._ok_pixmap)
    def update_data(self, data=None, *args, **kwargs):
        """
        Update the data in the tag data node that is managed by this editor
        :param data: variant
        """

        sel = kwargs.pop('sel', None)

        tag_data_node = artellapipe.TagsMgr().get_tag_data_node_from_current_selection(sel)
        if tag_data_node is None:
            return

        self.fill_tag_node(tag_data_node, data=data, *args, **kwargs)

        self.dataUpdated.emit()
    def update_tag_buttons_state(self, sel=None):
        """
        Updates the selection tag attribute of the tag data node
        :param name: str, name of the selection tag to add/remove
        """

        tag_data_node = artellapipe.TagsMgr(
        ).get_tag_data_node_from_current_selection(sel)
        if tag_data_node is None:
            return

        attr_exists = tp.Dcc.attribute_exists(node=tag_data_node,
                                              attribute_name='shaders')
        if attr_exists:
            pass
    def remove_tag_data_node(self):
        """
        Removes the tag data node associated to the current selected Maya object
        """

        tag_data_node = artellapipe.TagsMgr(
        ).get_tag_data_node_from_current_selection()
        if tag_data_node is None:
            return
        tp.Dcc.delete_object(tag_data_node)
        self._update_ui()
        self._update_current_info()

        for editor in self._editors:
            editor.update_tag_buttons_state()
            editor.update_data()
Exemple #13
0
    def update_tag_buttons_state(self, sel=None):
        """
        Updates the selection tag attribute of the tag data node
        :param name: str, name of the selection tag to add/remove
        """

        tag_data_node = artellapipe.TagsMgr(
        ).get_tag_data_node_from_current_selection(sel)
        if tag_data_node is None:
            return

        attr_exists = tp.Dcc.attribute_exists(node=tag_data_node,
                                              attribute_name='name')
        if attr_exists:
            name = tp.Dcc.get_attribute_value(node=tag_data_node,
                                              attribute_name='name')
            if name is not None and name != '':
                self._name_line.setText(name)
    def fill_tag_node(self, tag_data_node, *args, **kwargs):
        """
        Fills given tag node with the data managed by this editor
        :param tag_data_node: str
        """

        sel = kwargs.pop('sel', None)

        tag_data_node = artellapipe.TagsMgr(
        ).get_tag_data_node_from_current_selection(sel)
        if tag_data_node is None:
            return

        attr_exists = tp.Dcc.attribute_exists(node=tag_data_node,
                                              attribute_name='shaders')
        if not attr_exists:
            tp.Dcc.add_string_attribute(node=tag_data_node,
                                        attribute_name='shaders')

        asset_groups = tp.Dcc.list_nodes(node_name='*_grp',
                                         node_type='transform')
        if not asset_groups or len(asset_groups) <= 0:
            return

        # all_shading_groups = list()
        # json_data = dict()
        # for grp in asset_groups:
        #     json_data[grp] = dict()
        #     children = cmds.listRelatives(grp, type='transform', allDescendents=True, fullPath=True)
        #     for child in children:
        #         child_shapes = cmds.listRelatives(child, shapes=True, fullPath=True)
        #         for shape in child_shapes:
        #             json_data[grp][shape] = dict()
        #             shading_groups = cmds.listConnections(shape, type='shadingEngine')
        #             for shading_grp in shading_groups:
        #                 shading_grp_mat = cmds.ls(cmds.listConnections(shading_grp), materials=True)
        #                 json_data[grp][shape][shading_grp] = shading_grp_mat

        # cmds.setAttr(tag_data_node + '.description', lock=False)
        # cmds.setAttr(tag_data_node + '.description', self._description_text.toPlainText(), type='string')
        # cmds.setAttr(tag_data_node + '.description', lock=True)
        self.dataUpdated.emit()
    def ui(self):
        super(TaggerInfoWidget, self).ui()

        frame = QFrame()
        frame.setFrameShadow(QFrame.Sunken)
        frame.setFrameShape(QFrame.StyledPanel)
        frame_layout = QVBoxLayout()
        frame_layout.setContentsMargins(5, 5, 5, 5)
        frame_layout.setSpacing(5)
        frame.setLayout(frame_layout)

        self._curr_info_lbl = QLabel('')
        self._curr_info_lbl.setAlignment(Qt.AlignCenter)

        self._new_tagger_node_btn = QPushButton(
            'Create Tag Data node for "{0}"?'.format(
                artellapipe.TagsMgr().get_current_selection()))
        self._new_tagger_node_btn.setIcon(tpDcc.ResourcesMgr().icon('tag_add'))

        self.main_layout.addWidget(frame)
        frame_layout.addWidget(self._curr_info_lbl)
        frame_layout.addLayout(dividers.DividerLayout())
        frame_layout.addWidget(self._new_tagger_node_btn)
    def _fill_new_tag_data_node(self, tag_data_node, current_selection):
        """
        Fills given tag data node with proper data
        :param tag_data_node:
        :param tag_data_node:
        """

        tp.Dcc.add_string_attribute(node=tag_data_node,
                                    attribute_name=artellapipe.TagsMgr().
                                    TagDefinitions.TAG_TYPE_ATTRIBUTE_NAME)
        tp.Dcc.set_string_attribute_value(
            node=tag_data_node,
            attribute_name=artellapipe.TagsMgr(
            ).TagDefinitions.TAG_TYPE_ATTRIBUTE_NAME,
            attribute_value=self._project.tag_type_id)
        tp.Dcc.unkeyable_attribute(node=tag_data_node,
                                   attribute_name=artellapipe.TagsMgr().
                                   TagDefinitions.TAG_TYPE_ATTRIBUTE_NAME)
        tp.Dcc.hide_attribute(node=tag_data_node,
                              attribute_name=artellapipe.TagsMgr().
                              TagDefinitions.TAG_TYPE_ATTRIBUTE_NAME)
        tp.Dcc.lock_attribute(node=tag_data_node,
                              attribute_name=artellapipe.TagsMgr().
                              TagDefinitions.TAG_TYPE_ATTRIBUTE_NAME)
        tp.Dcc.add_message_attribute(node=tag_data_node,
                                     attribute_name=artellapipe.TagsMgr().
                                     TagDefinitions.NODE_ATTRIBUTE_NAME)

        if current_selection:
            if not tp.Dcc.attribute_exists(
                    node=current_selection,
                    attribute_name=artellapipe.TagsMgr(
                    ).TagDefinitions.TAG_DATA_ATTRIBUTE_NAME):
                tp.Dcc.add_message_attribute(
                    node=current_selection,
                    attribute_name=artellapipe.TagsMgr(
                    ).TagDefinitions.TAG_DATA_ATTRIBUTE_NAME)
            tp.Dcc.unlock_attribute(node=current_selection,
                                    attribute_name=artellapipe.TagsMgr().
                                    TagDefinitions.TAG_DATA_ATTRIBUTE_NAME)
            tp.Dcc.unlock_attribute(node=tag_data_node,
                                    attribute_name=artellapipe.TagsMgr().
                                    TagDefinitions.NODE_ATTRIBUTE_NAME)
            tp.Dcc.connect_attribute(
                tag_data_node,
                artellapipe.TagsMgr().TagDefinitions.NODE_ATTRIBUTE_NAME,
                current_selection,
                artellapipe.TagsMgr().TagDefinitions.TAG_DATA_ATTRIBUTE_NAME)
            tp.Dcc.lock_attribute(node=current_selection,
                                  attribute_name=artellapipe.TagsMgr().
                                  TagDefinitions.TAG_DATA_ATTRIBUTE_NAME)
            tp.Dcc.lock_attribute(node=tag_data_node,
                                  attribute_name=artellapipe.TagsMgr().
                                  TagDefinitions.NODE_ATTRIBUTE_NAME)
            tp.Dcc.select_object(current_selection)
    def update_hires_group(tag_data=None):
        """
        Updates the current hires group
        :param tag_data: str
        :return:
        """

        current_selection = artellapipe.TagsMgr().get_current_selection()

        if not tag_data:
            tag_data_node = artellapipe.TagsMgr(
            ).get_tag_data_node_from_current_selection()
            if tag_data_node is None or not tp.Dcc.object_exists(
                    tag_data_node):
                return
        else:
            if not tp.Dcc.object_exists(tag_data):
                LOGGER.error(
                    'Tag Data {} does not exists in current scene!'.format(
                        tag_data))
                return False
            tag_data_node = tag_data

        attr_exists = tp.Dcc.attribute_exists(node=tag_data_node,
                                              attribute_name='hires')
        if not attr_exists:
            tp.Dcc.add_message_attribute(node=tag_data_node,
                                         attribute_name='hires')

        sel_name = tp.Dcc.node_long_name(node=current_selection)

        # Check hires group connection
        hires_path = None
        if tp.Dcc.object_exists(sel_name):
            name = sel_name.split('|')[-1]
            hires_name = '{}_hires_grp'.format(name)
            children = tp.Dcc.list_relatives(node=sel_name,
                                             all_hierarchy=True,
                                             full_path=True,
                                             relative_type='transform')
            if not children:
                LOGGER.error('Hires Group not found!')
                return False
            for obj in children:
                base_name = obj.split('|')[-1]
                if base_name == hires_name:
                    if hires_path is None:
                        hires_path = obj
                    else:
                        LOGGER.error(
                            'Multiple hires groups in the asset. Asset only can have one hires group: {}'
                            .format(hires_name))
                        return False
        if hires_path is None or not tp.Dcc.object_exists(hires_path):
            LOGGER.error('Hires Group not found!')
            return False
        try:
            tp.Dcc.unlock_attribute(node=tag_data_node, attribute_name='hires')
            tp.Dcc.connect_attribute(hires_path,
                                     'message',
                                     tag_data_node,
                                     'hires',
                                     force=True)
        except Exception:
            pass

        tp.Dcc.lock_attribute(tag_data_node, 'hires')

        return True
    def ui(self):
        super(ArtellaTaggerWidget, self).ui()

        self.resize(300, 300)

        self._error_pixmap = tp.ResourcesMgr().pixmap('error',
                                                      category='icons').scaled(
                                                          QSize(24, 24))
        self._warning_pixmap = tp.ResourcesMgr().pixmap(
            'warning', category='icons').scaled(QSize(24, 24))
        self._ok_pixmap = tp.ResourcesMgr().pixmap('ok',
                                                   category='icons').scaled(
                                                       QSize(24, 24))

        top_layout = QHBoxLayout()
        top_layout.setContentsMargins(2, 2, 2, 2)
        top_layout.setSpacing(5)
        self.main_layout.addLayout(top_layout)
        select_tag_data_btn = QPushButton('Select Tag Data')
        select_tag_data_btn.setMinimumWidth(125)
        select_tag_data_btn.setIcon(tp.ResourcesMgr().icon('tag'))
        remove_tag_data_btn = QPushButton('Remove Tag Data')
        remove_tag_data_btn.setMinimumWidth(125)
        remove_tag_data_btn.setIcon(tp.ResourcesMgr().icon('tag_remove'))
        top_layout.addItem(
            QSpacerItem(10, 0, QSizePolicy.Expanding, QSizePolicy.Preferred))
        # export_tag_data_btn = QPushButton('Export Tag Data')
        # export_tag_data_btn.setEnabled(False)
        # import_tag_data_btn = QPushButton('Import Tag Data')
        # import_tag_data_btn.setEnabled(False)
        top_layout.addWidget(select_tag_data_btn)
        top_layout.addWidget(remove_tag_data_btn)
        # top_layout.addWidget(export_tag_data_btn)
        # top_layout.addWidget(import_tag_data_btn)
        top_layout.addItem(
            QSpacerItem(10, 0, QSizePolicy.Expanding, QSizePolicy.Preferred))

        self.main_layout.addLayout(dividers.DividerLayout())

        # ======================================================================================

        breadcrumb_layout = QHBoxLayout()
        breadcrumb_layout.setContentsMargins(2, 2, 2, 2)
        breadcrumb_layout.setSpacing(2)
        self._breadcrumb = breadcrumb.BreadcrumbFrame()
        self._curr_info_image = QLabel()
        self._curr_info_image.setAlignment(Qt.AlignCenter)
        self._curr_info_image.setPixmap(self._error_pixmap)
        breadcrumb_layout.addWidget(self._curr_info_image)
        breadcrumb_layout.addWidget(self._breadcrumb)
        self.main_layout.addLayout(breadcrumb_layout)

        # ======================================================================================

        self._stack = stack.SlidingStackedWidget()
        self.main_layout.addWidget(self._stack)

        # ======================================================================================

        self._tagger_info = taggerinfo.TaggerInfoWidget()
        self._tagger_info.setSizePolicy(QSizePolicy.Expanding,
                                        QSizePolicy.Expanding)
        self._stack.addWidget(self._tagger_info)

        # ======================================================================================

        editors_widget = QWidget()
        editors_layout = QVBoxLayout()
        editors_layout.setContentsMargins(2, 2, 2, 2)
        editors_layout.setSpacing(2)
        editors_widget.setLayout(editors_layout)

        self._tag_types_menu_layout = QHBoxLayout()
        self._tag_types_menu_layout.setContentsMargins(0, 0, 0, 0)
        self._tag_types_menu_layout.setSpacing(0)
        self._tag_types_menu_layout.setAlignment(Qt.AlignTop)
        editors_layout.addLayout(self._tag_types_menu_layout)
        self._tag_types_btn_grp = QButtonGroup(self)
        self._tag_types_btn_grp.setExclusive(True)
        editors_layout.addLayout(self._tag_types_menu_layout)
        self._editors_stack = stack.SlidingStackedWidget()
        editors_layout.addWidget(self._editors_stack)

        self._stack.addWidget(editors_widget)

        # ================================================================================

        self._tagger_info.createTagNode.connect(
            self._on_create_new_tag_data_node_for_current_selection)
        select_tag_data_btn.clicked.connect(
            artellapipe.TagsMgr().select_tag_data_node)
        remove_tag_data_btn.clicked.connect(self._on_remove_tag_data_node)