예제 #1
0
    def add_item(self, item: KnechtItem, children: Union[None, List] = None, create_id: bool = False):
        # Create a unique copy
        item = item.copy(True, None)

        # Update Name
        if item.data(Kg.TYPE) == Kg.type_keys[Kg.separator]:
            item.setData(Kg.NAME, '')
        else:
            item.setData(Kg.NAME, f'{item.data(Kg.NAME)}_{self.item_count:03d}')
            self.item_count += 1

        # Create unique item id
        if create_id:
            item.setData(Kg.ID, Kid.create_id())

        # Add children
        for child_item in children or []:
            child_item.setData(Kg.ORDER, f'{item.childCount():03d}', Qt.DisplayRole)
            item.append_item_child(child_item)

        # Get order data
        current_src_index, _ = self.editor.get_current_selection()
        order = self.editor.util.get_order_data(current_src_index)

        self.editor.create_top_level_rows([item], at_row=order)
        return item
예제 #2
0
    def _iterate_scene_children(self,
                                idx: int,
                                node: NodeInfo,
                                parent_item: KnechtItem,
                                use_config: bool = False):
        child_idx = parent_item.childCount()
        parent_item.insertChildren(
            child_idx, 1,
            (f'{idx:03d}', node.name, node.pr_tags, node.trigger_rules))
        node_item = parent_item.child(child_idx)

        # -- Style Schaltgruppen
        if node.pr_tags:
            KnechtItemStyle.style_column(node_item, 'plmxml_item')

        # -- Style visible nodes in Config Display
        if use_config and node.visible:
            node_item.style_bg_green()

        # -- Skip invisible child nodes in Config Display
        if use_config and node.pr_tags and not node.visible:
            node_item.style_recursive()
            return

        for idx, child_node in enumerate(
                self.plmxml.iterate_child_nodes(node)):
            self._iterate_scene_children(idx, child_node, node_item,
                                         use_config)
예제 #3
0
    def insert_child(cls, model: KnechtModel, parent, child: KnechtItem):
        position = child.childNumber()
        model.insertRows(position, 1, parent)
        new_index = model.index(position, 0, parent)

        cls.update_columns(model, new_index, parent, child.data_list())

        return new_index
예제 #4
0
    def create_camera_item(self, name: str, camera_info: dict):
        item = KnechtItem(None, ('', name, '', 'camera_item', '', KnechtUuidGenerator.create_id(),))

        for idx, (k, v) in enumerate(camera_info.items()):
            item.append_item_child(
                KnechtItem(item, (f'{idx:03d}', k, v, '', '', '', KnechtImageCameraInfo.rtt_camera_desc.get(k) or '', ))
                )
        return item
예제 #5
0
 def __init__(self):
     # Helper class to convert and create QUuids
     self.xml_id = KnechtXmlId()
     # Temporary item stores -currently- iterated preset item
     self.__preset_item = None
     # Loaded items temporary root item
     self.root_item = KnechtItem()
     # Store error message
     self.error = str()
예제 #6
0
    def copy_item_to_main_thread(root_item: KnechtItem):
        """ Creates a copy of a loaded root item that lives in the main thread """

        # Create root item that lives in the main thread
        _root_item = KnechtItem()

        # Copy child items from loaded item to the main thread root item
        root_item.copy_children(_root_item)

        return _root_item
예제 #7
0
    def update_reference_uuid(self, node, item: KnechtItem):
        ref_id = node.attrib.get(
            'reference')  # Knecht int Reference Id or Uuid string
        if ref_id:
            ref_uuid = self.get_id(None, ref_id)
        else:
            return

        self.store_id(ref_uuid, ref_id)
        item.reference = ref_uuid
        item.setData(KnechtModelGlobals.REF, ref_uuid)
예제 #8
0
    def create_pr_options(self,
                          pr_iterator: List[KnPr],
                          parent_item: KnechtItem,
                          ignore_pr_family=False):
        for pr in pr_iterator:
            if not ignore_pr_family and pr.family not in self.data.selected_pr_families:
                continue

            pr_item = KnechtItem(parent_item,
                                 (f'{parent_item.childCount():03d}', pr.name,
                                  'on', pr.family, '', '', pr.desc))
            parent_item.append_item_child(pr_item)
예제 #9
0
    def _check_preset(
        self,
        preset: KnechtItem,
        depth: int = 0
    ) -> Union[Tuple[KnechtItem, KnechtItem], Tuple[None, None]]:
        if depth > 10:
            return None, None

        for child in preset.iter_children():
            ref_id = child.reference

            if not isinstance(ref_id, QUuid):
                continue

            if ref_id == self.check_recurring_id:
                return preset, child

            referenced_preset = self.get_preset_from_id(ref_id)

            if referenced_preset:
                depth += 1
                recursive_preset, recursive_child = self._check_preset(
                    referenced_preset, depth)

                if recursive_preset:
                    return recursive_preset, recursive_child

        return None, None
예제 #10
0
    def _collect_single_reference(item, src_model) -> Union[KnechtItem, None]:
        ref_id: QUuid = item.reference

        if ref_id:
            return src_model.id_mgr.get_preset_from_id(ref_id)
        else:
            return KnechtItem()
예제 #11
0
    def create_presets(self):
        root_item = KnechtItem()

        for (src_index,
             item) in self.image_view.editor.iterator.iterate_view():
            if item.data(self.check_column, Qt.CheckStateRole) == Qt.Unchecked:
                continue

            name = item.data(Kg.NAME)
            data = (f'{root_item.childCount():03d}', name, '', 'preset', '',
                    Kid.convert_id(f'{root_item.childCount()}'))
            root_item.insertChildren(root_item.childCount(), 1, data)

        date = datetime.datetime.now().strftime('%Y%m%d')
        project = self._current_project_name.replace(' ', '_')
        self.finished.emit(KnechtModel(root_item),
                           Path(f'{date}_{project}.xml'))
예제 #12
0
    def create_trim(self, trim: KnTrim) -> KnechtItem:
        # -- Create trim line item --
        data = (
            f'{self.root_item.childCount():03d}',  # Order
            trim.model_text,  # Name
            trim.model,  # Value
            'trim_setup',  # Type
            '',  # Ref ID
            self.id_gen.create_id(),  # ID
            f'{trim.market} - {trim.gearbox}'  # Description
        )

        trim_item = KnechtItem(self.root_item, data)
        trim_code_item = KnechtItem(trim_item, ('000', trim.model, 'on'))
        trim_item.append_item_child(trim_code_item)
        self.create_pr_options(trim.iterate_trim_pr(), trim_item)
        return trim_item
예제 #13
0
    def _build_scene_tree(self, use_config: bool):
        scene_root_item = KnechtItem(data=('', 'Name', 'PR-Tags',
                                           'Trigger Rules'))

        for idx, node in enumerate(self.plmxml.iterate_root_nodes()):
            self._iterate_scene_children(idx, node, scene_root_item,
                                         use_config)

        update_scene_tree = UpdateModel(self.scene_tree)
        update_scene_tree.update(KnechtModel(scene_root_item))
예제 #14
0
    def elements_from_item(self, item: KnechtItem):
        element = self._create_element_from_item(item)

        for child in item.iter_children():
            e = self._create_element_from_item(child)

            if e is not None:
                element.append(e)

        return element
예제 #15
0
    def create_fakom_item(self,
                          parent: Union[KnechtItem, None],
                          model,
                          model_desc,
                          color,
                          sib,
                          vos,
                          lum,
                          sib_text,
                          vos_text,
                          lum_text,
                          fakom_type,
                          preset_wizard: bool = False):
        name = f'{model_desc} {color}-{sib}-{vos}-{lum}'
        if preset_wizard:
            name = f'{color}-{sib}-{vos}-{lum}'

        order = 0
        if parent:
            order = parent.childCount()

        data = (f'{order:03d}', f'{name}', model, fakom_type, '',
                self.id_gen.create_id())

        # Create FaKom item
        fa_item = KnechtItem(parent, data)

        if preset_wizard:
            fa_item.fixed_userType = Kg.dialog_item
            if parent:
                parent.append_item_child(fa_item)
            return

        # Create FaKom item content
        color_item = KnechtItem(fa_item, ('000', color, 'on'))
        sib_item = KnechtItem(fa_item,
                              ('001', sib, 'on', 'SIB', '', '', sib_text))
        vos_item = KnechtItem(fa_item,
                              ('002', vos, 'on', 'VOS', '', '', vos_text))
        lum_item = KnechtItem(fa_item,
                              ('003', lum, 'on', 'LUM', '', '', lum_text))

        for i in (color_item, sib_item, vos_item, lum_item):
            fa_item.append_item_child(i)

        return fa_item
예제 #16
0
    def create_package(self,
                       trim: KnTrim,
                       pkg: KnPackage,
                       order: int = 0) -> KnechtItem:
        data = (
            f'{order:03d}',  # Order
            f'{pkg.name} {pkg.desc} {trim.model} {trim.market}',  # Name
            pkg.name,  # Value
            'package',  # Type
            '',  # Ref ID
            self.id_gen.create_id()  # ID
        )
        pkg_item = KnechtItem(None, data)

        for pr in pkg.iterate_pr():
            pr_item = KnechtItem(pkg_item,
                                 (f'{pkg_item.childCount():03d}', pr.name,
                                  'on', pr.family, '', '', pr.desc))
            pkg_item.append_item_child(pr_item)

        return pkg_item
예제 #17
0
 def _add_variant(item: KnechtItem, variants: KnechtVariantList, src_model: KnechtModel) -> None:
     if item.userType == Kg.variant:
         index = src_model.get_index_from_item(item)
         variants.add(index, item.data(Kg.NAME), item.data(Kg.VALUE), item.data(Kg.TYPE))
     elif item.userType == Kg.output_item:
         variants.output_path = item.data(Kg.VALUE)
         LOGGER.debug('Collected output path: %s', item.data(Kg.VALUE))
     elif item.userType == Kg.plmxml_item:
         variants.plm_xml_path = item.data(Kg.VALUE)
         LOGGER.debug('Collected PlmXml path: %s', item.data(Kg.VALUE))
예제 #18
0
    def _build_material_tree(self, use_config: bool = False):
        material_root_item = KnechtItem(data=('', 'Material Name', 'PR-Tags',
                                              'Desc'))

        for idx, (name,
                  target) in enumerate(self.plmxml.look_lib.materials.items()):
            child_idx = material_root_item.childCount()

            material_root_item.insertChildren(child_idx, 1,
                                              (f'{idx:03d}', name, '', ''))
            target_item = material_root_item.child(child_idx)
            KnechtItemStyle.style_column(target_item, 'fakom_option')

            # -- Create Material Variants
            for c_idx, v in enumerate(target.variants):
                # -- Skip invisible variants in Config Display
                if use_config:
                    if v != target.visible_variant:
                        continue
                target_child_idx = target_item.childCount()
                target_item.insertChildren(
                    target_child_idx, 1,
                    (f'{c_idx:03d}', v.name, v.pr_tags, v.desc))
                if use_config:
                    variant_item = target_item.child(target_child_idx)
                    variant_item.style_bg_green()

        update_material_tree = UpdateModel(self.material_tree)
        update_material_tree.update(KnechtModel(material_root_item))
예제 #19
0
    def update_project_view(self, projects: dict):
        """ (Name, ModelYear, 'JobNo) """
        if not projects:
            return

        root_item = KnechtItem(
            None,
            ('', _('Bezeichnung'), _('Modelljahr'), _('Job'), '', _('Id')))

        for num_idx, (_id, project_data) in enumerate(projects.items()):
            data = (f'{num_idx:03d}', *project_data, '', str(_id))
            p_item = KnechtItem(root_item, data)
            KnechtItemStyle.style_column(p_item,
                                         'render_preset',
                                         column=Kg.NAME)
            root_item.append_item_child(p_item)

        update_model = UpdateModel(self.project_view)
        update_model.update(KnechtModel(root_item))

        self.toggle_view_columns(self.details_btn.isChecked())
        self.project_view.setHeaderHidden(False)
예제 #20
0
    def _create_tree_item(self,
                          node,
                          parent_item: KnechtItem = None) -> KnechtItem:
        data = self._data_from_element_attribute(node)

        if parent_item is None:
            child_position = self.root_item.childCount()
            self.root_item.insertChildren(child_position, 1, data)
            parent_item = self.root_item.child(child_position)

            self.xml_id.update_preset_uuid(node, parent_item)
            return parent_item

        position = parent_item.childCount()
        result = parent_item.insertChildren(position, 1, data)

        if not result:
            LOGGER.error('Could not insert child %s %s', position,
                         parent_item.childCount())
            return parent_item

        self.xml_id.update_reference_uuid(node, parent_item.child(position))
        return parent_item
예제 #21
0
    def create_packages(self, trim: KnTrim, parent_item: KnechtItem,
                        filter_pkg_by_pr_family: bool):
        for pkg in trim.iterate_packages():
            if not pkg.child_count():
                continue

            pkg_item = self.create_package(trim, pkg, parent_item.childCount())
            pkg_item.parentItem = parent_item

            keep_package = True
            if not [
                    pr for pr in pkg.iterate_pr()
                    if pr.family in self.data.selected_pr_families
            ]:
                keep_package = False

            if pkg_item.childCount():
                if filter_pkg_by_pr_family and keep_package:
                    # Only create packages that contain at least one PR Family from pr family filter
                    parent_item.append_item_child(pkg_item)
                elif not filter_pkg_by_pr_family:
                    # Create all packages and do not apply any filtering
                    parent_item.append_item_child(pkg_item)
예제 #22
0
    def initializePage(self):
        data = self.wizard.session.data.import_data
        item_creator = KnechtDataToModel(data)

        # -- Populate Preset Tree --
        for trim in data.models:
            if trim.model not in data.selected_models:
                continue

            item_data = (f'{item_creator.root_item.childCount():03d}', trim.model_text, trim.model, 'trim_setup')
            trim_item = KnechtItem(item_creator.root_item, item_data)
            trim_item.fixed_userType = Kg.group_item
            item_creator.create_fakom(trim, is_preset_wizard=True, parent_item=trim_item)
            item_creator.root_item.append_item_child(trim_item)

        fakom_model = KnechtModel(item_creator.root_item)
        for column in (Kg.VALUE, Kg.DESC, Kg.TYPE, Kg.REF, Kg.ID):
            self.fakom_tree.hideColumn(column)
        UpdateModel(self.fakom_tree).update(fakom_model)

        QTimer.singleShot(50, self.load_fakom_selection)

        LOGGER.info('FaKom Wizard Page initialized.')
예제 #23
0
    def create_trim_options(self, trim, text_filter_options=False):
        # -- Create trim line options item --
        data = (f'{self.root_item.childCount():03d}',
                f'{trim.model_text} Options', trim.model, 'options', '',
                self.id_gen.create_id(), f'{trim.market} - {trim.gearbox}')
        options_item = KnechtItem(self.root_item, data)

        if text_filter_options:
            self.create_pr_options(trim.iterate_optional_filtered_pr(),
                                   options_item)
        else:
            self.create_pr_options(trim.iterate_optional_pr(), options_item)

        return options_item
예제 #24
0
    def update_image_view(self, images: dict):
        if not images:
            return

        root_item = KnechtItem(None, ('', _('Name'), _('Priorität'),
                                      _('Erstellt'), '', _('wagenbauteil Id')))

        for num_idx, (img_id, image_data) in enumerate(images.items()):
            """ (name, priority, created, pr_string, opt_id, produced_image_id) """
            name, priority, created, pr_string, opt_id, produced_image_id = image_data
            img_item = KnechtItem(
                root_item,
                (f'{num_idx:03d}', name, priority, created, '', str(opt_id)))
            KnechtItemStyle.style_column(img_item, 'preset', Kg.NAME)
            root_item.append_item_child(img_item)

        update_model = UpdateModel(self.image_view)
        update_model.update(
            KnechtModel(root_item, checkable_columns=[self.check_column]))

        self.toggle_view_columns(self.details_btn.isChecked())
        self.image_view.setHeaderHidden(False)
        self.image_view.check_items([], Kg.NAME, check_all=True)
예제 #25
0
    def _add_camera_variants(item: KnechtItem, variants: KnechtVariantList, src_model: KnechtModel) -> None:
        """ Convert Camera Preset items to camera command variants """
        for child in item.iter_children():
            camera_tag, camera_value = child.data(Kg.NAME), child.data(Kg.VALUE)

            if camera_tag in KnechtImageCameraInfo.rtt_camera_cmds:
                index = src_model.get_index_from_item(child)
                camera_cmd = KnechtImageCameraInfo.rtt_camera_cmds.get(camera_tag)
                camera_value = camera_value.replace(' ', '')

                try:
                    camera_cmd = camera_cmd.format(*camera_value.split(','))
                except Exception as e:
                    LOGGER.warning('Camera Info Tag Value does not match %s\n%s', camera_value, e)

                variants.add(index, camera_tag, camera_cmd, 'camera_command')

                LOGGER.debug('Collecting Camera Command %s: %s', camera_tag, camera_cmd)
예제 #26
0
def create_reset_item(order: int = 0) -> KnechtItem:
    reset_item = KnechtItem(
        None, (f'{order:03d}', 'Reset', '', 'reset', '', Kid.create_id()))
    reset_item.refresh_id_data()

    child_data = [
        ('000', 'reset', 'on', '', '', '',
         'Sollte einen im Modell vorhanden Reset Schalter betätigen'),
        ('001', 'reset', 'off', '', '', '',
         'Sollte einen im Modell vorhanden Reset Schalter betätigen'),
        ('002', 'RTTOGLRT', 'on', '', '', '',
         'Benötigte Optionen müssen nach dem Reset erneut geschaltet werden.'),
    ]

    for data in child_data:
        i = KnechtItem(reset_item, data)
        reset_item.append_item_child(i)

    return reset_item
예제 #27
0
    def _xml_items_loaded(self, root_item: KnechtItem, error: str, file: Path):
        if not root_item.childCount():
            LOGGER.info('Could not load Xml. KnechtXml returned %s', error)
            self.load_aborted.emit(error, file)
            return

        # Transfer root_item to new_model
        new_model = KnechtModel(root_item)

        # Add recent file entry
        if self.create_recent_entries:
            KnechtSettings.add_recent_file(file.as_posix(), 'xml')
            KnechtSettings.app['current_path'] = file.parent.as_posix()

        # Output load info
        self.last_progress_time = time.time() - self.load_start_time

        LOGGER.info(
            f'Xml file {file.name} took {self.last_progress_time:.4}s to parse. {root_item.thread()}'
        )

        # Transfer model
        self.model_loaded.emit(new_model, file)
예제 #28
0
    def add_variant_item(name: str, value: str, order: int=0) -> KnechtItem:
        data = [None for _ in Kg.column_range]
        data[Kg.ORDER], data[Kg.NAME], data[Kg.VALUE] = f'{order:03d}', name, value

        return KnechtItem(data=tuple(data))
예제 #29
0
    def _create_document_from_transfer(self, data):
        self.ui.main_menu.file_menu.load_save_mgr.load_start_time = time.time()
        new_file = Path(create_file_safe_name(f"{data.get('label', '')}_Transfer.xml"))
        preset_ls: List[KnechtVariantList] = data.get('presets', list())

        # -- Create Item Model
        root_item = KnechtItem()
        plmxml_path = preset_ls[0].plm_xml_path

        plmxml_item = self._create_top_level_item(root_item, ItemTemplates.plmxml)
        plmxml_item.setData(Kg.VALUE, plmxml_path)
        plmxml_item.setData(Kg.NAME, Path(plmxml_path).name)

        root_item.append_item_child(plmxml_item)
        sep = self._create_top_level_item(root_item, ItemTemplates.separator)
        root_item.append_item_child(sep)

        preset_item_ls = list()
        for idx, variant_ls in enumerate(preset_ls, start=1):
            variants = variant_ls.variants
            name = variant_ls.preset_name

            model = ''
            if len(variants) > 1:
                model = variants[1].value

            preset_item = self._create_top_level_item(root_item, ItemTemplates.preset)
            preset_item.setData(Kg.NAME, name)
            preset_item.setData(Kg.VALUE, model)
            preset_item.setData(Kg.ID, Kid.create_id())
            plmxml_ref = plmxml_item.copy(new_parent=preset_item)
            plmxml_ref.convert_to_reference()
            preset_item.append_item_child(plmxml_ref)

            for variant in variants:
                pr_item = KnechtItem(preset_item,
                                     (f'{preset_item.childCount():03d}', variant.value, 'on'))
                preset_item.append_item_child(pr_item)

            preset_item_ls.append(preset_item)
            root_item.append_item_child(preset_item)

        # -- Create some sugar template
        sep = self._create_top_level_item(root_item, ItemTemplates.separator)
        root_item.append_item_child(sep)

        #  - Viewsets -
        views = list()
        for shot in ('Shot-05', 'Shot-06'):
            view = self._create_top_level_item(root_item, ItemTemplates.viewset)
            view.setData(Kg.NAME, f'Viewset_{shot}')
            view.child(0).setData(Kg.VALUE, shot)
            root_item.append_item_child(view)
            views.append(view)

        #  - Output -
        out = self._create_top_level_item(root_item, ItemTemplates.output)
        out.setData(Kg.VALUE, os.path.expanduser('~'))
        root_item.append_item_child(out)

        #  - RenderPreset -
        sep = self._create_top_level_item(root_item, ItemTemplates.separator)
        root_item.append_item_child(sep)
        ren = self._create_top_level_item(root_item, ItemTemplates.render)
        ren.setData(Kg.NAME, f"Render_{data.get('label')}")
        out_ref = out.copy(new_parent=ren)
        out_ref.convert_to_reference()
        out_ref.setData(Kg.ORDER, f'{ren.childCount():03d}')
        ren.append_item_child(out_ref)

        for item in views + preset_item_ls:
            ref_item = item.copy()
            ref_item.removeChildren(0, ref_item.childCount())
            ref_item.convert_to_reference()
            ref_item.setData(Kg.ORDER, f'{ren.childCount():03d}')
            ren.append_item_child(ref_item)

        root_item.append_item_child(ren)
        sep = self._create_top_level_item(root_item, ItemTemplates.separator)
        root_item.append_item_child(sep)

        self.model_loaded.emit(KnechtModel(root_item), new_file)
예제 #30
0
    def __init__(self, data: KnData):
        self.data = data

        self.id_gen = KnechtUuidGenerator()
        self.root_item = KnechtItem()