Пример #1
0
    def update_uuid(self, column, id_value):
        if not Kid.is_quuid(
                id_value):  # Test if value is QUuid object instance
            id_value = Kid.create_id(id_value)

        # Re-Set QUuid from valid QUuid if string is invalid Id
        if column == Kg.REF:
            self.reference = id_value
            self.style_valid()

        elif column == Kg.ID:
            self.preset_id = id_value
            self.style_regular()

        return id_value
Пример #2
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
Пример #3
0
    def _paste_top_level(self, items: List[KnechtItem], current_src_index: QModelIndex,
                         src_model: KnechtModel, referenced_items: List[KnechtItem],
                         different_origin: bool, view_origin, move_undo_chain):
        """ Create top level items with new Id's and add referenced items as necessary """
        # Remove references when pasting to top level
        items = [i for i in items if i.userType != Kg.reference]

        for item in items:
            if move_undo_chain:
                continue

            if src_model.id_mgr.get_preset_from_id(item.preset_id):
                # Create new preset_id if id already exists
                item.setData(Kg.ID, Kid.create_id(), role=Qt.EditRole)

                # Rename if pasting to same tree
                if not different_origin:
                    item.update_name()
                else:
                    match = self.editor.match.index(item.data(Kg.NAME), Kg.NAME)
                    if match:
                        item.update_name()

        ordered_item_ls = self.editor.util.reorder_item_order_data(referenced_items + items, current_src_index)
        self.editor.create_top_level_rows(ordered_item_ls, undo_cmd_chain_override=move_undo_chain)
Пример #4
0
 def _create_top_level_item(root_item: KnechtItem, template: KnechtItem) -> KnechtItem:
     item = template
     item = item.copy()
     item.setData(Kg.ORDER, f'{root_item.childCount():03d}')
     if template == ItemTemplates.separator:
         return item
     item.setData(Kg.ID, Kid.create_id())
     return item
Пример #5
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
Пример #6
0
    def get_id(self, uuid, str_id) -> QUuid:
        stored_uuid = self.item_ids.get(str_id)

        if stored_uuid:
            return stored_uuid

        return Kid.create_id(
            uuid
        )  # Returns QUuid from valid uuid string or new uuid if None or invalid str
Пример #7
0
    def store_id(self, uuid, str_id) -> QUuid:
        if str_id not in self.item_ids:
            uuid = Kid.create_id(
                uuid
            )  # Returns QUuid from valid uuid string or new uuid if None or invalid str
            self.item_ids[str_id] = uuid
            return uuid

        return self.item_ids[str_id]
Пример #8
0
    def convert_to_reference(self) -> bool:
        """ Do not call this if the item is inside a model! """

        # Update reference
        _id = Kid.create_id(self.preset_id)
        self.reference = _id
        self.setData(Kg.ID, '')
        self.setData(Kg.REF, _id)

        # Delete Preset ID
        self.preset_id = None

        return True
Пример #9
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'))
Пример #10
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
Пример #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)
Пример #12
0
    def __init__(self, data: KnData):
        self.data = data

        self.id_gen = KnechtUuidGenerator()
        self.root_item = KnechtItem()
Пример #13
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
Пример #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))