Merge remote-tracking branch 'origin/master'
Showing
1 changed file
with
143 additions
and
36 deletions
| ... | @@ -2604,6 +2604,138 @@ class ImageGenerationWorker(QThread): | ... | @@ -2604,6 +2604,138 @@ class ImageGenerationWorker(QThread): |
| 2604 | # ============================================================================ | 2604 | # ============================================================================ |
| 2605 | # 珠宝设计功能模块 | 2605 | # 珠宝设计功能模块 |
| 2606 | # ============================================================================ | 2606 | # ============================================================================ |
| 2607 | DEFAULT_JEWELRY_LIBRARY = { | ||
| 2608 | "主石形状": [ | ||
| 2609 | "圆形", | ||
| 2610 | "椭圆形", | ||
| 2611 | "梨形", | ||
| 2612 | "马眼形", | ||
| 2613 | "子弹形(Baguette 子弹刻面)", | ||
| 2614 | "垫形", | ||
| 2615 | "公主方形", | ||
| 2616 | "祖母绿形", | ||
| 2617 | "心形", | ||
| 2618 | "风筝形", | ||
| 2619 | "棺材形(Coffin Cut)", | ||
| 2620 | "菱形(Rhombus)", | ||
| 2621 | "正六边形", | ||
| 2622 | "四叶草形", | ||
| 2623 | "梯方形(Tapered Step)", | ||
| 2624 | "阿斯切形", | ||
| 2625 | "平底刻面风格" | ||
| 2626 | ], | ||
| 2627 | |||
| 2628 | "主石材质": [ | ||
| 2629 | "莫桑石", | ||
| 2630 | "钻石", | ||
| 2631 | "黑发晶", | ||
| 2632 | "蓝宝石", | ||
| 2633 | "红宝石", | ||
| 2634 | "粉蓝宝石", | ||
| 2635 | "绿碧玺", | ||
| 2636 | "黄水晶(天然包体)", | ||
| 2637 | "月光石", | ||
| 2638 | "摩根石", | ||
| 2639 | "海蓝宝", | ||
| 2640 | "天然白玉髓", | ||
| 2641 | "金绿宝石(猫眼)" | ||
| 2642 | ], | ||
| 2643 | |||
| 2644 | "金属": [ | ||
| 2645 | "14K黄金", | ||
| 2646 | "14K白金", | ||
| 2647 | "14K玫瑰金", | ||
| 2648 | "18K黄金", | ||
| 2649 | "18K白金", | ||
| 2650 | "18K玫瑰金", | ||
| 2651 | "双色金(白金+黄金)", | ||
| 2652 | "950铂金", | ||
| 2653 | "925银镀铑", | ||
| 2654 | "钛金属", | ||
| 2655 | "定制复古做旧金" | ||
| 2656 | ], | ||
| 2657 | |||
| 2658 | "花头形式": [ | ||
| 2659 | "全halo光环", | ||
| 2660 | "半halo光环", | ||
| 2661 | "双层halo", | ||
| 2662 | "花卉风格光环", | ||
| 2663 | "围圈雕刻光环", | ||
| 2664 | "围圈密钉镶", | ||
| 2665 | "经典圆形光环", | ||
| 2666 | "几何六边形光环", | ||
| 2667 | "非对称光环", | ||
| 2668 | "三石花头(cluster 结构)", | ||
| 2669 | "五石花头", | ||
| 2670 | "cluster堆砌花头(大小堆/不规则)", | ||
| 2671 | "双石结构(Two-stone)", | ||
| 2672 | "单石无光环(爪镶/包镶)", | ||
| 2673 | "花头侧面结构", | ||
| 2674 | "高耸花头(Cathedral halo)" | ||
| 2675 | ], | ||
| 2676 | |||
| 2677 | "戒臂结构": [ | ||
| 2678 | "直臂", | ||
| 2679 | "xox扭臂(交叉扭绞)", | ||
| 2680 | ">O< 戒臂结构", | ||
| 2681 | "<O> 戒臂结构", | ||
| 2682 | "V字戒臂", | ||
| 2683 | "交叉戒臂", | ||
| 2684 | "overlap重叠戒臂", | ||
| 2685 | "wave波浪戒臂", | ||
| 2686 | "刀锋臂", | ||
| 2687 | "大教堂戒臂(高肩设计)", | ||
| 2688 | "三股编织戒臂", | ||
| 2689 | "分裂戒臂(split shank)", | ||
| 2690 | "戒臂夹层", | ||
| 2691 | "小夹层戒臂(如莲花夹层设计)", | ||
| 2692 | "不对称戒臂" | ||
| 2693 | ], | ||
| 2694 | |||
| 2695 | "戒臂处理": [ | ||
| 2696 | "密钉镶戒臂", | ||
| 2697 | "微密钉镶", | ||
| 2698 | "镶石虎爪镶/逼镶", | ||
| 2699 | "抛光平滑戒臂", | ||
| 2700 | "珠边戒臂(milgrain)", | ||
| 2701 | "光金戒臂", | ||
| 2702 | "雕刻镂空花丝", | ||
| 2703 | "浮雕雕刻(凸雕)", | ||
| 2704 | "凹刻雕刻(内刻)", | ||
| 2705 | "几何雕刻纹理", | ||
| 2706 | "复古米粒边装饰(milgrain)", | ||
| 2707 | "编织纹理戒臂", | ||
| 2708 | "穿孔镂空细节", | ||
| 2709 | "锤纹处理" | ||
| 2710 | ], | ||
| 2711 | |||
| 2712 | "辅石镶嵌": [ | ||
| 2713 | "三石结构", | ||
| 2714 | "五石结构", | ||
| 2715 | "cluster自由堆砌侧石", | ||
| 2716 | "大小堆组合", | ||
| 2717 | "共爪镶侧钻", | ||
| 2718 | "包镶侧钻", | ||
| 2719 | "轨道镶", | ||
| 2720 | "槽镶" | ||
| 2721 | ], | ||
| 2722 | |||
| 2723 | "特殊元素": [ | ||
| 2724 | "花朵元素", | ||
| 2725 | "月亮元素", | ||
| 2726 | "星星元素", | ||
| 2727 | "日月星组合", | ||
| 2728 | "凯尔特结", | ||
| 2729 | "叶子图案", | ||
| 2730 | "自然植物藤蔓纹理", | ||
| 2731 | "蝴蝶结元素", | ||
| 2732 | "装饰艺术几何元素", | ||
| 2733 | "复古花纹", | ||
| 2734 | "哥特式结构元素" | ||
| 2735 | ] | ||
| 2736 | } | ||
| 2737 | |||
| 2738 | |||
| 2607 | 2739 | ||
| 2608 | class JewelryLibraryManager: | 2740 | class JewelryLibraryManager: |
| 2609 | """珠宝词库管理器""" | 2741 | """珠宝词库管理器""" |
| ... | @@ -2635,35 +2767,14 @@ class JewelryLibraryManager: | ... | @@ -2635,35 +2767,14 @@ class JewelryLibraryManager: |
| 2635 | return library | 2767 | return library |
| 2636 | except Exception as e: | 2768 | except Exception as e: |
| 2637 | self.logger.error(f"珠宝词库加载失败: {e},使用默认词库") | 2769 | self.logger.error(f"珠宝词库加载失败: {e},使用默认词库") |
| 2638 | return self._load_default_library() | 2770 | return DEFAULT_JEWELRY_LIBRARY.copy() |
| 2639 | else: | 2771 | else: |
| 2640 | # 首次使用,创建默认词库 | 2772 | # 首次使用,创建默认词库 |
| 2641 | self.logger.info("未找到珠宝词库文件,创建默认词库") | 2773 | self.logger.info("未找到珠宝词库文件,创建默认词库") |
| 2642 | library = self._load_default_library() | 2774 | library = DEFAULT_JEWELRY_LIBRARY.copy() |
| 2643 | self.save_library(library) | 2775 | self.save_library(library) |
| 2644 | return library | 2776 | return library |
| 2645 | 2777 | ||
| 2646 | def _load_default_library(self) -> Dict[str, List[str]]: | ||
| 2647 | """从文件加载默认词库""" | ||
| 2648 | try: | ||
| 2649 | with open(self.default_library_path, 'r', encoding='utf-8') as f: | ||
| 2650 | library = json.load(f) | ||
| 2651 | self.logger.info(f"默认词库加载成功: {self.default_library_path}") | ||
| 2652 | return library | ||
| 2653 | except Exception as e: | ||
| 2654 | self.logger.error(f"默认词库加载失败: {e}") | ||
| 2655 | # 如果默认词库文件也不存在,返回一个最小的词库 | ||
| 2656 | return { | ||
| 2657 | "主石形状": ["圆形", "椭圆形"], | ||
| 2658 | "主石材质": ["钻石", "莫桑石"], | ||
| 2659 | "金属": ["14K黄金", "18K白金"], | ||
| 2660 | "花头形式": ["经典圆形光环"], | ||
| 2661 | "戒臂结构": ["直臂"], | ||
| 2662 | "戒臂处理": ["抛光平滑戒臂"], | ||
| 2663 | "辅石镶嵌": ["三石结构"], | ||
| 2664 | "特殊元素": [] | ||
| 2665 | } | ||
| 2666 | |||
| 2667 | def _migrate_library_if_needed(self, library: Dict[str, List[str]]) -> Dict[str, List[str]]: | 2778 | def _migrate_library_if_needed(self, library: Dict[str, List[str]]) -> Dict[str, List[str]]: |
| 2668 | """检查并执行数据迁移""" | 2779 | """检查并执行数据迁移""" |
| 2669 | # 如果存在旧的"主石"字段,需要拆分 | 2780 | # 如果存在旧的"主石"字段,需要拆分 |
| ... | @@ -2687,9 +2798,8 @@ class JewelryLibraryManager: | ... | @@ -2687,9 +2798,8 @@ class JewelryLibraryManager: |
| 2687 | materials.append(material) | 2798 | materials.append(material) |
| 2688 | 2799 | ||
| 2689 | # 更新词库 | 2800 | # 更新词库 |
| 2690 | default_library = self._load_default_library() | 2801 | library["主石形状"] = shapes if shapes else DEFAULT_JEWELRY_LIBRARY["主石形状"] |
| 2691 | library["主石形状"] = shapes if shapes else default_library["主石形状"] | 2802 | library["主石材质"] = materials if materials else DEFAULT_JEWELRY_LIBRARY["主石材质"] |
| 2692 | library["主石材质"] = materials if materials else default_library["主石材质"] | ||
| 2693 | 2803 | ||
| 2694 | # 保留旧字段作为备份 | 2804 | # 保留旧字段作为备份 |
| 2695 | # library.pop("主石", None) # 可以选择是否移除 | 2805 | # library.pop("主石", None) # 可以选择是否移除 |
| ... | @@ -2702,9 +2812,8 @@ class JewelryLibraryManager: | ... | @@ -2702,9 +2812,8 @@ class JewelryLibraryManager: |
| 2702 | 2812 | ||
| 2703 | def _extract_shape(self, item: str) -> Optional[str]: | 2813 | def _extract_shape(self, item: str) -> Optional[str]: |
| 2704 | """从主石描述中提取形状""" | 2814 | """从主石描述中提取形状""" |
| 2705 | # 从默认词库文件获取形状列表,确保同步 | 2815 | # 直接从 DEFAULT_JEWELRY_LIBRARY 获取形状列表,确保同步 |
| 2706 | default_library = self._load_default_library() | 2816 | shapes = DEFAULT_JEWELRY_LIBRARY.get("主石形状", []) |
| 2707 | shapes = default_library.get("主石形状", []) | ||
| 2708 | for shape in shapes: | 2817 | for shape in shapes: |
| 2709 | # 处理带括号的形状(如"子弹形(Baguette 子弹刻面)") | 2818 | # 处理带括号的形状(如"子弹形(Baguette 子弹刻面)") |
| 2710 | if "(" in shape: | 2819 | if "(" in shape: |
| ... | @@ -2717,9 +2826,8 @@ class JewelryLibraryManager: | ... | @@ -2717,9 +2826,8 @@ class JewelryLibraryManager: |
| 2717 | 2826 | ||
| 2718 | def _extract_material(self, item: str) -> Optional[str]: | 2827 | def _extract_material(self, item: str) -> Optional[str]: |
| 2719 | """从主石描述中提取材质""" | 2828 | """从主石描述中提取材质""" |
| 2720 | # 从默认词库文件获取形状列表,确保同步 | 2829 | # 直接从 DEFAULT_JEWELRY_LIBRARY 获取形状列表,确保同步 |
| 2721 | default_library = self._load_default_library() | 2830 | shapes = DEFAULT_JEWELRY_LIBRARY.get("主石形状", []) |
| 2722 | shapes = default_library.get("主石形状", []) | ||
| 2723 | for shape in shapes: | 2831 | for shape in shapes: |
| 2724 | # 处理带括号的形状(如"子弹形(Baguette 子弹刻面)") | 2832 | # 处理带括号的形状(如"子弹形(Baguette 子弹刻面)") |
| 2725 | shape_base = shape.split("(")[0] if "(" in shape else shape | 2833 | shape_base = shape.split("(")[0] if "(" in shape else shape |
| ... | @@ -2786,9 +2894,8 @@ class JewelryLibraryManager: | ... | @@ -2786,9 +2894,8 @@ class JewelryLibraryManager: |
| 2786 | Args: | 2894 | Args: |
| 2787 | category: 类别名称 | 2895 | category: 类别名称 |
| 2788 | """ | 2896 | """ |
| 2789 | default_library = self._load_default_library() | 2897 | if category in DEFAULT_JEWELRY_LIBRARY: |
| 2790 | if category in default_library: | 2898 | self.library[category] = DEFAULT_JEWELRY_LIBRARY[category].copy() |
| 2791 | self.library[category] = default_library[category].copy() | ||
| 2792 | self.save_library() | 2899 | self.save_library() |
| 2793 | self.logger.info(f"恢复默认词库: {category}") | 2900 | self.logger.info(f"恢复默认词库: {category}") |
| 2794 | else: | 2901 | else: |
| ... | @@ -2796,7 +2903,7 @@ class JewelryLibraryManager: | ... | @@ -2796,7 +2903,7 @@ class JewelryLibraryManager: |
| 2796 | 2903 | ||
| 2797 | def reset_all(self): | 2904 | def reset_all(self): |
| 2798 | """恢复所有类别的默认词库""" | 2905 | """恢复所有类别的默认词库""" |
| 2799 | self.library = self._load_default_library() | 2906 | self.library = DEFAULT_JEWELRY_LIBRARY.copy() |
| 2800 | self.save_library() | 2907 | self.save_library() |
| 2801 | self.logger.info("恢复所有默认词库") | 2908 | self.logger.info("恢复所有默认词库") |
| 2802 | 2909 | ... | ... |
-
Please register or sign in to post a comment