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)
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 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))