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
    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
Beispiel #3
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)
Beispiel #4
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
Beispiel #5
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
Beispiel #6
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
Beispiel #7
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
Beispiel #8
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)
Beispiel #9
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)
Beispiel #10
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)
Beispiel #11
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)
Beispiel #12
0
class KnechtDataToModel:
    progress_signal = None

    def __init__(self, data: KnData):
        self.data = data

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

    def _show_progress(self, msg: str):
        if self.progress_signal is None:
            return
        self.progress_signal.emit(msg)

    def create_root_item(self):
        self.create_items()
        LOGGER.debug('Created %s items from ExcelData.',
                     self.root_item.childCount())
        return self.root_item

    def create_items(self):
        progress_idx = 0

        for trim in self.data.models:
            model = trim.model

            if model not in self.data.selected_models:
                continue

            progress_idx += 1
            self._show_progress(
                _('Erstelle Model {} {:02d}/{:02d}...').format(
                    model, progress_idx, len(self.data.selected_models)))

            # -- Create Trim line item --
            if self.data.read_trim:
                trim_item = self.create_trim(trim)
                self.root_item.append_item_child(trim_item)

            # -- Create options --
            if self.data.read_options:
                # Filter rows matching E
                options_item = self.create_trim_options(
                    trim, self.data.options_text_filter)
                self.root_item.append_item_child(options_item)

            # -- Create packages --
            if self.data.read_packages:
                self.create_packages(trim, self.root_item,
                                     self.data.pr_fam_filter_packages)

            if self.data.read_fakom:
                self.create_fakom(trim)

    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

    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

    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

    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)

    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)

    def create_fakom(self,
                     trim: KnTrim,
                     is_preset_wizard: bool = False,
                     parent_item: KnechtItem = None):
        model_short_desc = shorten_model_name(trim.model_text)

        # Create lists of List[KnPr] for SIB/VOS/LUM families
        sib_pr_ls = [
            pr for pr in trim.iterate_available_pr()
            if pr.family.casefold() == 'sib'
        ]
        sib_pr_codes = [pr.name for pr in sib_pr_ls]
        lum_pr_ls = [
            pr for pr in trim.iterate_available_pr()
            if pr.family.casefold() == 'lum'
        ]
        vos_pr_ls = [
            pr for pr in trim.iterate_available_pr()
            if pr.family.casefold() == 'vos'
        ]

        if not parent_item:
            parent_item = self.root_item

        for color, sib_set in self.data.fakom.iterate_colors():
            valid_sib_set = sib_set.intersection(sib_pr_codes)
            if not valid_sib_set:
                continue

            fa_parent, grp_item = parent_item, parent_item

            if is_preset_wizard:
                grp_item = KnechtItem(parent_item,
                                      (f'{parent_item.childCount():03d}',
                                       color, '', 'fakom_option'))
                grp_item.fixed_userType = Kg.group_item
                parent_item.append_item_child(grp_item)

            # --- Iterate SIB Codes ---
            for sib_pr in sib_pr_ls:
                if sib_pr.name not in valid_sib_set:
                    # Skip seat covers not matching
                    continue

                if is_preset_wizard:
                    sib_grp_item = KnechtItem(grp_item,
                                              (f'{grp_item.childCount():03d}',
                                               sib_pr.name, '', 'options'))
                    sib_grp_item.fixed_userType = Kg.group_item
                    grp_item.append_item_child(sib_grp_item)
                    fa_parent = sib_grp_item

                # --- Iterate VOS Codes ---
                for vos_pr in vos_pr_ls:

                    # --- Iterate LUM Codes ---
                    for lum_pr in lum_pr_ls:

                        # Determine if all options belong to standard equipment L
                        fakom_type = 'fakom_option'
                        if not {sib_pr.value, vos_pr.value, lum_pr.value
                                }.difference('L'):
                            fakom_type = 'fakom_setup'

                        fa_item = self.create_fakom_item(
                            fa_parent, trim.model, model_short_desc, color,
                            sib_pr.name, vos_pr.name, lum_pr.name, sib_pr.desc,
                            vos_pr.desc, lum_pr.desc, fakom_type,
                            is_preset_wizard)
                        if is_preset_wizard:
                            continue
                        fa_parent.append_item_child(fa_item)

    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
Beispiel #13
0
    def create_fakom(self,
                     trim: KnTrim,
                     is_preset_wizard: bool = False,
                     parent_item: KnechtItem = None):
        model_short_desc = shorten_model_name(trim.model_text)

        # Create lists of List[KnPr] for SIB/VOS/LUM families
        sib_pr_ls = [
            pr for pr in trim.iterate_available_pr()
            if pr.family.casefold() == 'sib'
        ]
        sib_pr_codes = [pr.name for pr in sib_pr_ls]
        lum_pr_ls = [
            pr for pr in trim.iterate_available_pr()
            if pr.family.casefold() == 'lum'
        ]
        vos_pr_ls = [
            pr for pr in trim.iterate_available_pr()
            if pr.family.casefold() == 'vos'
        ]

        if not parent_item:
            parent_item = self.root_item

        for color, sib_set in self.data.fakom.iterate_colors():
            valid_sib_set = sib_set.intersection(sib_pr_codes)
            if not valid_sib_set:
                continue

            fa_parent, grp_item = parent_item, parent_item

            if is_preset_wizard:
                grp_item = KnechtItem(parent_item,
                                      (f'{parent_item.childCount():03d}',
                                       color, '', 'fakom_option'))
                grp_item.fixed_userType = Kg.group_item
                parent_item.append_item_child(grp_item)

            # --- Iterate SIB Codes ---
            for sib_pr in sib_pr_ls:
                if sib_pr.name not in valid_sib_set:
                    # Skip seat covers not matching
                    continue

                if is_preset_wizard:
                    sib_grp_item = KnechtItem(grp_item,
                                              (f'{grp_item.childCount():03d}',
                                               sib_pr.name, '', 'options'))
                    sib_grp_item.fixed_userType = Kg.group_item
                    grp_item.append_item_child(sib_grp_item)
                    fa_parent = sib_grp_item

                # --- Iterate VOS Codes ---
                for vos_pr in vos_pr_ls:

                    # --- Iterate LUM Codes ---
                    for lum_pr in lum_pr_ls:

                        # Determine if all options belong to standard equipment L
                        fakom_type = 'fakom_option'
                        if not {sib_pr.value, vos_pr.value, lum_pr.value
                                }.difference('L'):
                            fakom_type = 'fakom_setup'

                        fa_item = self.create_fakom_item(
                            fa_parent, trim.model, model_short_desc, color,
                            sib_pr.name, vos_pr.name, lum_pr.name, sib_pr.desc,
                            vos_pr.desc, lum_pr.desc, fakom_type,
                            is_preset_wizard)
                        if is_preset_wizard:
                            continue
                        fa_parent.append_item_child(fa_item)
Beispiel #14
0
    def collect_result(self):
        kn_data = self.session.data.import_data
        converter = KnechtDataToModel(kn_data)
        trim_items = dict()

        # --- Create Trim Setups ---
        for model_code in self.session.data.fakom_selection.keys():
            trim = self._get_trim_from_models(kn_data.models, model_code)
            trim_items[model_code] = dict()
            trim_item = converter.create_trim(trim)
            trim_item.refresh_id_data()
            trim_items[model_code]['trim_setup'] = trim_item
            trim_items[model_code][
                'trim_option'] = converter.create_trim_options(
                    trim, kn_data.options_text_filter)
            trim_items[model_code]['packages'] = list()
            trim_items[model_code]['fakom'] = dict()

        # -- Create FaKom Items --
        for preset_page in self.session.iterate_preset_pages():
            fakom_ls = preset_page.fakom.split('-')
            if len(fakom_ls) < 4:
                continue
            trim = self._get_trim_from_models(kn_data.models,
                                              preset_page.model)

            # Create lists of List[KnPr] for SIB/VOS/LUM families
            sib_pr_ls = [
                pr for pr in trim.iterate_available_pr()
                if pr.family.casefold() == 'sib'
            ]
            lum_pr_ls = [
                pr for pr in trim.iterate_available_pr()
                if pr.family.casefold() == 'lum'
            ]
            vos_pr_ls = [
                pr for pr in trim.iterate_available_pr()
                if pr.family.casefold() == 'vos'
            ]

            fa, sib, vos, lum = fakom_ls
            LOGGER.debug('Creating Fakom Item %s %s %s %s', fa, sib, vos, lum)
            sib_pr = self._get_pr_from_list(sib_pr_ls, sib)
            vos_pr = self._get_pr_from_list(vos_pr_ls, vos)
            lum_pr = self._get_pr_from_list(lum_pr_ls, lum)

            fakom_type = 'fakom_option'
            if not {sib_pr.value, vos_pr.value, lum_pr.value}.difference('L'):
                fakom_type = 'fakom_setup'

            fa_item = converter.create_fakom_item(None, trim.model,
                                                  trim.model_text, fa, sib,
                                                  vos, lum, sib_pr.desc,
                                                  vos_pr.desc, lum_pr.desc,
                                                  fakom_type, False)
            fa_item.refresh_id_data()
            trim_items[preset_page.model]['fakom'][preset_page.fakom] = fa_item

        # --- Prepare presets ---
        preset_items = list()
        for preset_page in self.session.iterate_preset_pages():
            # -- Create Preset item --
            preset_item = KnechtItem(
                None, ('000', preset_page.subTitle(), '',
                       Kg.type_keys[Kg.preset], '', Kid.create_id()))
            # -- Add reference to trim setup --
            trim_ref = trim_items[preset_page.model]['trim_setup'].copy(
                copy_children=False)
            trim_ref.convert_to_reference()
            trim_ref.setData(0, '000')
            preset_item.append_item_child(trim_ref)

            # -- Add reference to fakom item --
            fa_ref = trim_items[preset_page.model]['fakom'][
                preset_page.fakom].copy(copy_children=False)
            fa_ref.convert_to_reference()
            fa_ref.setData(0, '001')
            preset_item.append_item_child(fa_ref)

            # -- Collect preset content --
            for _, pr_item in preset_page.preset_tree.editor.iterator.iterate_view(
            ):
                if pr_item.userType == Kg.variant:
                    # --- Add PR-option ---
                    pr_item_copy = pr_item.copy()
                    pr_item_copy.setData(0, f'{preset_item.childCount():03d}')
                    preset_item.append_item_child(pr_item_copy)
                else:
                    # --- Add package reference ---
                    pkg_ref = pr_item.copy(copy_children=False)
                    pkg_ref.convert_to_reference()
                    pkg_ref.setData(0, f'{preset_item.childCount():03d}')
                    preset_item.append_item_child(pkg_ref)
                    # --- Add package ---
                    trim_items[preset_page.model]['packages'].append(
                        pr_item.copy())

            preset_items.append(preset_item)

        # --- Create trim, package and fakom items ---
        root_item = KnechtItem()

        for model_code in self.session.data.fakom_selection.keys():
            # -- Add trim setup --
            trim_item = trim_items[model_code]['trim_setup']
            trim_item.setData(Kg.ORDER, f'{root_item.childCount():03d}')
            root_item.append_item_child(trim_item)

            # -- Add trim options --
            trim_options = trim_items[model_code]['trim_option']
            trim_options.setData(Kg.ORDER, f'{root_item.childCount():03d}')
            root_item.append_item_child(trim_options)

            # -- Add Packages --
            for pkg_item in trim_items[model_code]['packages']:
                pkg_item.setData(Kg.ORDER, f'{root_item.childCount():03d}')
                root_item.append_item_child(pkg_item)

            # -- Add FaKom Items --
            for fa_item in trim_items[model_code]['fakom'].values():
                fa_item.setData(Kg.ORDER, f'{root_item.childCount():03d}')
                root_item.append_item_child(fa_item)

            # -- Add separator --
            root_item.append_item_child(
                KnechtItem(
                    None,
                    (f'{root_item.childCount():03d}', '', '', 'separator')))

        # -- Create default Reset --
        reset_item = create_reset_item(root_item.childCount())
        root_item.append_item_child(reset_item)

        # -- Add separator --
        root_item.append_item_child(
            KnechtItem(None,
                       (f'{root_item.childCount():03d}', '', '', 'separator')))

        # --- Create Preset items ---
        for preset_item in preset_items:
            preset_item.setData(Kg.ORDER, f'{root_item.childCount():03d}')
            root_item.append_item_child(preset_item)

        UpdateModel(self.result_tree).update(KnechtModel(root_item))