From a9d1de7747702e5f261c62710f360b79d55015fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=80=AA=E6=97=8C=E5=93=B2?= <1448976235@qq.com> Date: Mon, 7 Jul 2025 03:01:09 +0800 Subject: [PATCH] Add beartype and ragflow-sdk packages; update simplecadapi version - Introduced beartype version 0.18.5 with its source and wheel details. - Added ragflow-sdk version 0.19.1, including dependencies on beartype and requests. - Updated simplecadapi version from 0.1.2 to 1.0.0. - Included ragflow-sdk in dev dependencies for testing purposes. --- docs/api/chamfer_rsolid.md | 26 +- docs/api/cut_rsolid.md | 26 +- docs/api/extrude_rsolid.md | 22 +- docs/api/fillet_rsolid.md | 30 +- docs/api/helical_sweep_rsolid.md | 20 +- docs/api/intersect_rsolid.md | 28 +- docs/api/linear_pattern_rsolidlist.md | 22 +- docs/api/loft_rsolid.md | 28 +- docs/api/make_angle_arc_redge.md | 18 +- docs/api/make_angle_arc_rwire.md | 18 +- docs/api/make_box_rsolid.md | 22 +- docs/api/make_circle_redge.md | 14 +- docs/api/make_circle_rface.md | 14 +- docs/api/make_circle_rwire.md | 10 +- docs/api/make_cylinder_rsolid.md | 22 +- docs/api/make_face_from_wire_rface.md | 22 +- docs/api/make_helix_redge.md | 14 +- docs/api/make_helix_rwire.md | 14 +- docs/api/make_line_redge.md | 14 +- docs/api/make_point_rvertex.md | 14 +- docs/api/make_polyline_rwire.md | 20 +- docs/api/make_rectangle_rface.md | 14 +- docs/api/make_rectangle_rwire.md | 14 +- docs/api/make_segment_redge.md | 10 +- docs/api/make_segment_rwire.md | 10 +- docs/api/make_sphere_rsolid.md | 22 +- docs/api/make_spline_redge.md | 22 +- docs/api/make_spline_rwire.md | 14 +- docs/api/make_three_point_arc_redge.md | 14 +- docs/api/make_three_point_arc_rwire.md | 12 +- docs/api/make_wire_from_edges_rwire.md | 18 +- docs/api/mirror_shape.md | 20 +- docs/api/radial_pattern_rsolidlist.md | 20 +- docs/api/revolve_rsolid.md | 22 +- docs/api/rotate_shape.md | 20 +- docs/api/select_edges_by_tag.md | 2 +- docs/api/select_faces_by_tag.md | 2 +- docs/api/set_tag.md | 2 +- docs/api/shell_rsolid.md | 26 +- docs/api/sweep_rsolid.md | 28 +- docs/api/translate_shape.md | 20 +- docs/api/union_rsolid.md | 22 +- pyproject.toml | 6 +- scripts/README_ragflow_sync.md | 140 +++++ scripts/auto_docs_gen.py | 8 +- scripts/ragflow_cache.json | 58 ++ scripts/ragflow_env_example.sh | 17 + scripts/ragflow_sync.py | 507 +++++++++++++++ scripts/test_ragflow_connection.py | 110 ++++ src/simplecadapi/operations.py | 814 ++++++++++++------------- uv.lock | 26 +- 51 files changed, 1649 insertions(+), 789 deletions(-) create mode 100644 scripts/README_ragflow_sync.md create mode 100644 scripts/ragflow_cache.json create mode 100755 scripts/ragflow_env_example.sh create mode 100755 scripts/ragflow_sync.py create mode 100755 scripts/test_ragflow_connection.py diff --git a/docs/api/chamfer_rsolid.md b/docs/api/chamfer_rsolid.md index 961381a6..508a1b40 100644 --- a/docs/api/chamfer_rsolid.md +++ b/docs/api/chamfer_rsolid.md @@ -28,7 +28,7 @@ def chamfer_rsolid(solid: Solid, edges: List[Edge], distance: float) -> Solid - **类型**: `float` - **说明**: 倒角距离,必须为正数,定义从边缘向内的倒角深度 -## 返回值 +### 返回值 Solid: 倒角后的实体对象 @@ -39,18 +39,18 @@ Solid: 倒角后的实体对象 ## API使用例子 ```python ->>> # 对立方体的边进行倒角 ->>> box = make_box_rsolid(4, 4, 4) ->>> edges = box.get_edges() ->>> chamfered_box = chamfer_rsolid(box, edges[:4], 0.3) + # 对立方体的边进行倒角 + box = make_box_rsolid(4, 4, 4) + edges = box.get_edges() + chamfered_box = chamfer_rsolid(box, edges[:4], 0.3) ->>> # 对圆柱体的边倒角 ->>> cylinder = make_cylinder_rsolid(2.0, 5.0) ->>> cylinder_edges = cylinder.get_edges() ->>> chamfered_cylinder = chamfer_rsolid(cylinder, cylinder_edges[:2], 0.2) + # 对圆柱体的边倒角 + cylinder = make_cylinder_rsolid(2.0, 5.0) + cylinder_edges = cylinder.get_edges() + chamfered_cylinder = chamfer_rsolid(cylinder, cylinder_edges[:2], 0.2) ->>> # 选择性倒角 ->>> complex_solid = make_box_rsolid(6, 3, 2) ->>> top_edges = [e for e in complex_solid.get_edges() if e.has_tag("top")] ->>> chamfered_top = chamfer_rsolid(complex_solid, top_edges, 0.1) + # 选择性倒角 + complex_solid = make_box_rsolid(6, 3, 2) + top_edges = [e for e in complex_solid.get_edges() if e.has_tag("top")] + chamfered_top = chamfer_rsolid(complex_solid, top_edges, 0.1) ``` diff --git a/docs/api/cut_rsolid.md b/docs/api/cut_rsolid.md index 22be8852..5dd6c01d 100644 --- a/docs/api/cut_rsolid.md +++ b/docs/api/cut_rsolid.md @@ -23,7 +23,7 @@ def cut_rsolid(solid1: Solid, solid2: Solid) -> Solid - **类型**: `Solid` - **说明**: 减去的实体,将从基础实体中移除 -## 返回值 +### 返回值 Solid: 差集结果实体,从solid1中减去solid2的重叠部分 @@ -34,18 +34,18 @@ Solid: 差集结果实体,从solid1中减去solid2的重叠部分 ## API使用例子 ```python ->>> # 在立方体中创建圆形孔 ->>> box = make_box_rsolid(4, 4, 4) ->>> hole = make_cylinder_rsolid(1.0, 4.0) ->>> box_with_hole = cut_rsolid(box, hole) + # 在立方体中创建圆形孔 + box = make_box_rsolid(4, 4, 4) + hole = make_cylinder_rsolid(1.0, 4.0) + box_with_hole = cut_rsolid(box, hole) ->>> # 创建槽形结构 ->>> base = make_box_rsolid(6, 3, 2) ->>> slot = make_box_rsolid(4, 1, 2, (0, 0, 1)) ->>> slotted_base = cut_rsolid(base, slot) + # 创建槽形结构 + base = make_box_rsolid(6, 3, 2) + slot = make_box_rsolid(4, 1, 2, (0, 0, 1)) + slotted_base = cut_rsolid(base, slot) ->>> # 从球体中减去立方体 ->>> sphere = make_sphere_rsolid(2.0) ->>> cube = make_box_rsolid(2, 2, 2) ->>> carved_sphere = cut_rsolid(sphere, cube) + # 从球体中减去立方体 + sphere = make_sphere_rsolid(2.0) + cube = make_box_rsolid(2, 2, 2) + carved_sphere = cut_rsolid(sphere, cube) ``` diff --git a/docs/api/extrude_rsolid.md b/docs/api/extrude_rsolid.md index 3963f1e3..f3267e89 100644 --- a/docs/api/extrude_rsolid.md +++ b/docs/api/extrude_rsolid.md @@ -28,7 +28,7 @@ def extrude_rsolid(profile: Union[Wire, Face], direction: Tuple[float, float, fl - **类型**: `float` - **说明**: 拉伸距离,必须为正数 -## 返回值 +### 返回值 Solid: 拉伸后的实体对象 @@ -39,16 +39,16 @@ Solid: 拉伸后的实体对象 ## API使用例子 ```python ->>> # 拉伸圆形面创建圆柱体 ->>> circle = make_circle_rface((0, 0, 0), 1.0) ->>> cylinder = extrude_rsolid(circle, (0, 0, 1), 5.0) + # 拉伸圆形面创建圆柱体 + circle = make_circle_rface((0, 0, 0), 1.0) + cylinder = extrude_rsolid(circle, (0, 0, 1), 5.0) ->>> # 拉伸矩形面创建立方体 ->>> rect = make_rectangle_rface(2.0, 2.0) ->>> box = extrude_rsolid(rect, (0, 0, 1), 3.0) + # 拉伸矩形面创建立方体 + rect = make_rectangle_rface(2.0, 2.0) + box = extrude_rsolid(rect, (0, 0, 1), 3.0) ->>> # 拉伸复杂轮廓 ->>> points = [(0, 0, 0), (2, 0, 0), (2, 1, 0), (0, 1, 0)] ->>> profile_wire = make_polyline_rwire(points, closed=True) ->>> extruded_shape = extrude_rsolid(profile_wire, (0, 0, 1), 4.0) + # 拉伸复杂轮廓 + points = [(0, 0, 0), (2, 0, 0), (2, 1, 0), (0, 1, 0)] + profile_wire = make_polyline_rwire(points, closed=True) + extruded_shape = extrude_rsolid(profile_wire, (0, 0, 1), 4.0) ``` diff --git a/docs/api/fillet_rsolid.md b/docs/api/fillet_rsolid.md index 8bf525e5..13b2edad 100644 --- a/docs/api/fillet_rsolid.md +++ b/docs/api/fillet_rsolid.md @@ -28,7 +28,7 @@ def fillet_rsolid(solid: Solid, edges: List[Edge], radius: float) -> Solid - **类型**: `float` - **说明**: 圆角半径,必须为正数,不能大于相邻面的最小尺寸 -## 返回值 +### 返回值 Solid: 圆角后的实体对象 @@ -39,21 +39,21 @@ Solid: 圆角后的实体对象 ## API使用例子 ```python ->>> # 对立方体的所有边进行圆角 ->>> box = make_box_rsolid(4, 4, 4) ->>> all_edges = box.get_edges() ->>> rounded_box = fillet_rsolid(box, all_edges[:4], 0.5) # 只对前4条边圆角 + # 对立方体的所有边进行圆角 + box = make_box_rsolid(4, 4, 4) + all_edges = box.get_edges() + rounded_box = fillet_rsolid(box, all_edges[:4], 0.5) # 只对前4条边圆角 ->>> # 对圆柱体的边进行圆角 ->>> cylinder = make_cylinder_rsolid(2.0, 5.0) ->>> edges = cylinder.get_edges() + # 对圆柱体的边进行圆角 + cylinder = make_cylinder_rsolid(2.0, 5.0) + edges = cylinder.get_edges() ->>> # 选择顶部和底部的圆边 ->>> circular_edges = [e for e in edges if e.has_tag("circular")] ->>> rounded_cylinder = fillet_rsolid(cylinder, circular_edges, 0.3) + # 选择顶部和底部的圆边 + circular_edges = [e for e in edges if e.has_tag("circular")] + rounded_cylinder = fillet_rsolid(cylinder, circular_edges, 0.3) ->>> # 对复杂几何体的特定边圆角 ->>> complex_solid = union_rsolid(box, cylinder) ->>> selected_edges = complex_solid.get_edges()[:6] ->>> smoothed_solid = fillet_rsolid(complex_solid, selected_edges, 0.2) + # 对复杂几何体的特定边圆角 + complex_solid = union_rsolid(box, cylinder) + selected_edges = complex_solid.get_edges()[:6] + smoothed_solid = fillet_rsolid(complex_solid, selected_edges, 0.2) ``` diff --git a/docs/api/helical_sweep_rsolid.md b/docs/api/helical_sweep_rsolid.md index dc19f328..5a3a4159 100644 --- a/docs/api/helical_sweep_rsolid.md +++ b/docs/api/helical_sweep_rsolid.md @@ -46,7 +46,7 @@ def helical_sweep_rsolid(profile: Wire, pitch: float, height: float, radius: flo - **类型**: `Tuple[float, float, float], optional` - **说明**: 螺旋轴方向向量 (x, y, z), 默认为 (0, 0, 1) 表示沿Z轴方向 -## 返回值 +### 返回值 Solid: 螺旋扫掠后的实体对象 @@ -57,15 +57,15 @@ Solid: 螺旋扫掠后的实体对象 ## API使用例子 ```python ->>> # 创建螺旋弹簧 ->>> circle_profile = make_circle_rwire((0, 0, 0), 0.2) ->>> spring = helical_sweep_rsolid(circle_profile, 1.0, 10.0, 2.0) + # 创建螺旋弹簧 + circle_profile = make_circle_rwire((0, 0, 0), 0.2) + spring = helical_sweep_rsolid(circle_profile, 1.0, 10.0, 2.0) ->>> # 创建方形截面的螺旋管 ->>> square_profile = make_rectangle_rwire(0.5, 0.5) ->>> square_helix = helical_sweep_rsolid(square_profile, 2.0, 8.0, 1.5) + # 创建方形截面的螺旋管 + square_profile = make_rectangle_rwire(0.5, 0.5) + square_helix = helical_sweep_rsolid(square_profile, 2.0, 8.0, 1.5) ->>> # 创建紧密螺旋结构 ->>> small_circle = make_circle_rwire((0, 0, 0), 0.1) ->>> tight_helix = helical_sweep_rsolid(small_circle, 0.5, 5.0, 1.0) + # 创建紧密螺旋结构 + small_circle = make_circle_rwire((0, 0, 0), 0.1) + tight_helix = helical_sweep_rsolid(small_circle, 0.5, 5.0, 1.0) ``` diff --git a/docs/api/intersect_rsolid.md b/docs/api/intersect_rsolid.md index deb8d814..4562cce4 100644 --- a/docs/api/intersect_rsolid.md +++ b/docs/api/intersect_rsolid.md @@ -23,7 +23,7 @@ def intersect_rsolid(solid1: Solid, solid2: Solid) -> Solid - **类型**: `Solid` - **说明**: 第二个参与运算的实体对象 -## 返回值 +### 返回值 Solid: 两个实体的交集结果,只包含两个实体的重叠部分 @@ -34,20 +34,20 @@ Solid: 两个实体的交集结果,只包含两个实体的重叠部分 ## API使用例子 ```python ->>> # 计算两个重叠立方体的交集 ->>> box1 = make_box_rsolid(3, 3, 3, (0, 0, 0)) ->>> box2 = make_box_rsolid(3, 3, 3, (1, 1, 0)) ->>> intersection = intersect_rsolid(box1, box2) + # 计算两个重叠立方体的交集 + box1 = make_box_rsolid(3, 3, 3, (0, 0, 0)) + box2 = make_box_rsolid(3, 3, 3, (1, 1, 0)) + intersection = intersect_rsolid(box1, box2) ->>> # 结果是一个2×2×3的立方体 + # 结果是一个2×2×3的立方体 ->>> # 球体和立方体的交集 ->>> sphere = make_sphere_rsolid(2.0) ->>> cube = make_box_rsolid(3, 3, 3) ->>> rounded_cube = intersect_rsolid(sphere, cube) + # 球体和立方体的交集 + sphere = make_sphere_rsolid(2.0) + cube = make_box_rsolid(3, 3, 3) + rounded_cube = intersect_rsolid(sphere, cube) ->>> # 圆柱体和平面的交集 ->>> cylinder = make_cylinder_rsolid(1.5, 4.0) ->>> slab = make_box_rsolid(4, 4, 2, (0, 0, 1)) ->>> partial_cylinder = intersect_rsolid(cylinder, slab) + # 圆柱体和平面的交集 + cylinder = make_cylinder_rsolid(1.5, 4.0) + slab = make_box_rsolid(4, 4, 2, (0, 0, 1)) + partial_cylinder = intersect_rsolid(cylinder, slab) ``` diff --git a/docs/api/linear_pattern_rsolidlist.md b/docs/api/linear_pattern_rsolidlist.md index 64e660b1..099fc569 100644 --- a/docs/api/linear_pattern_rsolidlist.md +++ b/docs/api/linear_pattern_rsolidlist.md @@ -33,7 +33,7 @@ def linear_pattern_rsolidlist(shape: AnyShape, direction: Tuple[float, float, fl - **类型**: `float` - **说明**: 阵列间距,必须为正数,定义相邻对象间的距离 -## 返回值 +### 返回值 List[Solid]: 阵列后的几何体列表,包含原始对象和所有复制的对象 @@ -44,17 +44,17 @@ List[Solid]: 阵列后的几何体列表,包含原始对象和所有复制的 ## API使用例子 ```python ->>> # 创建立方体的线性阵列 ->>> box = make_box_rsolid(1, 1, 1) ->>> boxes = linear_pattern_rsolidlist(box, (2, 0, 0), 5, 2.0) + # 创建立方体的线性阵列 + box = make_box_rsolid(1, 1, 1) + boxes = linear_pattern_rsolidlist(box, (2, 0, 0), 5, 2.0) ->>> # 创建5个立方体,沿X轴方向间距2.0 + # 创建5个立方体,沿X轴方向间距2.0 ->>> # 创建圆柱体的对角线阵列 ->>> cylinder = make_cylinder_rsolid(0.5, 2.0) ->>> cylinders = linear_pattern_rsolidlist(cylinder, (1, 1, 0), 4, 1.5) + # 创建圆柱体的对角线阵列 + cylinder = make_cylinder_rsolid(0.5, 2.0) + cylinders = linear_pattern_rsolidlist(cylinder, (1, 1, 0), 4, 1.5) ->>> # 创建复杂几何体的阵列 ->>> complex_shape = union_rsolid(box, cylinder) ->>> array = linear_pattern_rsolidlist(complex_shape, (0, 3, 0), 3, 3.0) + # 创建复杂几何体的阵列 + complex_shape = union_rsolid(box, cylinder) + array = linear_pattern_rsolidlist(complex_shape, (0, 3, 0), 3, 3.0) ``` diff --git a/docs/api/loft_rsolid.md b/docs/api/loft_rsolid.md index 3e795521..beb1ea11 100644 --- a/docs/api/loft_rsolid.md +++ b/docs/api/loft_rsolid.md @@ -23,7 +23,7 @@ def loft_rsolid(profiles: List[Wire], ruled: bool = False) -> Solid - **类型**: `bool, optional` - **说明**: 是否为直纹面,默认为False。 True表示轮廓间用直线连接,False表示用平滑曲面连接 -## 返回值 +### 返回值 Solid: 放样后的实体对象 @@ -34,19 +34,19 @@ Solid: 放样后的实体对象 ## API使用例子 ```python ->>> # 创建方形到圆形的过渡体 ->>> square = make_rectangle_rwire(2, 2, (0, 0, 0)) ->>> circle = make_circle_rwire((0, 0, 3), 1.0) ->>> transition = loft_rsolid([square, circle]) + # 创建方形到圆形的过渡体 + square = make_rectangle_rwire(2, 2, (0, 0, 0)) + circle = make_circle_rwire((0, 0, 3), 1.0) + transition = loft_rsolid([square, circle]) ->>> # 创建多层过渡的复杂形状 ->>> bottom = make_rectangle_rwire(4, 4, (0, 0, 0)) ->>> middle = make_circle_rwire((0, 0, 2), 2.0) ->>> top = make_rectangle_rwire(1, 1, (0, 0, 4)) ->>> complex_shape = loft_rsolid([bottom, middle, top]) + # 创建多层过渡的复杂形状 + bottom = make_rectangle_rwire(4, 4, (0, 0, 0)) + middle = make_circle_rwire((0, 0, 2), 2.0) + top = make_rectangle_rwire(1, 1, (0, 0, 4)) + complex_shape = loft_rsolid([bottom, middle, top]) ->>> # 创建直纹面放样 ->>> profile1 = make_circle_rwire((0, 0, 0), 2.0) ->>> profile2 = make_circle_rwire((0, 0, 5), 1.0) ->>> ruled_loft = loft_rsolid([profile1, profile2], ruled=True) + # 创建直纹面放样 + profile1 = make_circle_rwire((0, 0, 0), 2.0) + profile2 = make_circle_rwire((0, 0, 5), 1.0) + ruled_loft = loft_rsolid([profile1, profile2], ruled=True) ``` diff --git a/docs/api/make_angle_arc_redge.md b/docs/api/make_angle_arc_redge.md index 1865fc74..c2d4f332 100644 --- a/docs/api/make_angle_arc_redge.md +++ b/docs/api/make_angle_arc_redge.md @@ -38,7 +38,7 @@ def make_angle_arc_redge(center: Tuple[float, float, float], radius: float, star - **类型**: `Tuple[float, float, float], optional` - **说明**: 圆弧所在平面的法向量 (x, y, z), 默认为 (0, 0, 1) 表示XY平面 -## 返回值 +### 返回值 Edge: 创建的边对象,表示指定角度范围的圆弧 @@ -49,15 +49,15 @@ Edge: 创建的边对象,表示指定角度范围的圆弧 ## API使用例子 ```python ->>> # 创建90度圆弧(从0度到90度) ->>> arc_90 = make_angle_arc_redge((0, 0, 0), 2.0, 0, 90) + # 创建90度圆弧(从0度到90度) + arc_90 = make_angle_arc_redge((0, 0, 0), 2.0, 0, 90) ->>> # 创建180度半圆弧 ->>> semicircle = make_angle_arc_redge((0, 0, 0), 1.5, 0, 180) + # 创建180度半圆弧 + semicircle = make_angle_arc_redge((0, 0, 0), 1.5, 0, 180) ->>> # 创建270度圆弧 ->>> arc_270 = make_angle_arc_redge((0, 0, 0), 1.0, 45, 315) + # 创建270度圆弧 + arc_270 = make_angle_arc_redge((0, 0, 0), 1.0, 45, 315) ->>> # 创建垂直平面上的圆弧 ->>> vertical_arc = make_angle_arc_redge((0, 0, 0), 1.0, 0, 90, (1, 0, 0)) + # 创建垂直平面上的圆弧 + vertical_arc = make_angle_arc_redge((0, 0, 0), 1.0, 0, 90, (1, 0, 0)) ``` diff --git a/docs/api/make_angle_arc_rwire.md b/docs/api/make_angle_arc_rwire.md index 4fbf1c4a..bacbd680 100644 --- a/docs/api/make_angle_arc_rwire.md +++ b/docs/api/make_angle_arc_rwire.md @@ -34,7 +34,7 @@ def make_angle_arc_rwire(center: Tuple[float, float, float], radius: float, star - **说明**: 法向量 -## 返回值 +### 返回值 Wire: 线对象,表示通过角度创建的圆弧线 @@ -45,15 +45,15 @@ Wire: 线对象,表示通过角度创建的圆弧线 ## API使用例子 ```python ->>> # 创建90度圆弧线(从0度到90度) ->>> arc_90_wire = make_angle_arc_rwire((0, 0, 0), 2.0, 0, 90) + # 创建90度圆弧线(从0度到90度) + arc_90_wire = make_angle_arc_rwire((0, 0, 0), 2.0, 0, 90) ->>> # 创建180度半圆弧线 ->>> semicircle_wire = make_angle_arc_rwire((0, 0, 0), 1.5, 0, 180) + # 创建180度半圆弧线 + semicircle_wire = make_angle_arc_rwire((0, 0, 0), 1.5, 0, 180) ->>> # 创建270度圆弧线 ->>> arc_270_wire = make_angle_arc_rwire((0, 0, 0), 1.0, 45, 315) + # 创建270度圆弧线 + arc_270_wire = make_angle_arc_rwire((0, 0, 0), 1.0, 45, 315) ->>> # 创建垂直平面(YZ,法相指向X轴正方向)上的圆弧线 ->>> vertical_arc_wire = make_angle_arc_rwire((0, 0, 0), 1.0, 0, 90, (1, 0, 0)) + # 创建垂直平面(YZ,法相指向X轴正方向)上的圆弧线 + vertical_arc_wire = make_angle_arc_rwire((0, 0, 0), 1.0, 0, 90, (1, 0, 0)) ``` diff --git a/docs/api/make_box_rsolid.md b/docs/api/make_box_rsolid.md index 2c8a5636..907acaf7 100644 --- a/docs/api/make_box_rsolid.md +++ b/docs/api/make_box_rsolid.md @@ -34,7 +34,7 @@ def make_box_rsolid(width: float, height: float, depth: float, center: Tuple[flo - **类型**: `Tuple[float, float, float], optional` - **说明**: 立方体的中心坐标 (x, y, z), 默认为 (0, 0, 0) -## 返回值 +### 返回值 Solid: 创建的实体对象,表示一个立方体 @@ -45,17 +45,17 @@ Solid: 创建的实体对象,表示一个立方体 ## API使用例子 ```python ->>> # 创建标准单位立方体 ->>> unit_cube = make_box_rsolid(1.0, 1.0, 1.0) ->>> volume = unit_cube.get_volume() # 体积为1 + # 创建标准单位立方体 + unit_cube = make_box_rsolid(1.0, 1.0, 1.0) + volume = unit_cube.get_volume() # 体积为1 ->>> # 创建矩形立方体 ->>> rect_box = make_box_rsolid(4.0, 2.0, 3.0) + # 创建矩形立方体 + rect_box = make_box_rsolid(4.0, 2.0, 3.0) ->>> # 创建偏移的立方体 ->>> offset_box = make_box_rsolid(2.0, 2.0, 2.0, (1, 1, 1)) + # 创建偏移的立方体 + offset_box = make_box_rsolid(2.0, 2.0, 2.0, (1, 1, 1)) ->>> # 获取立方体的面进行后续操作 ->>> faces = unit_cube.get_faces() ->>> top_faces = [f for f in faces if f.has_tag("top")] + # 获取立方体的面进行后续操作 + faces = unit_cube.get_faces() + top_faces = [f for f in faces if f.has_tag("top")] ``` diff --git a/docs/api/make_circle_redge.md b/docs/api/make_circle_redge.md index cd2eab29..0f91edf7 100644 --- a/docs/api/make_circle_redge.md +++ b/docs/api/make_circle_redge.md @@ -28,7 +28,7 @@ def make_circle_redge(center: Tuple[float, float, float], radius: float, normal: - **类型**: `Tuple[float, float, float], optional` - **说明**: 圆所在平面的法向量 (x, y, z), 默认为 (0, 0, 1) 表示XY平面 -## 返回值 +### 返回值 Edge: 创建的边对象,表示一个完整的圆形 @@ -39,12 +39,12 @@ Edge: 创建的边对象,表示一个完整的圆形 ## API使用例子 ```python ->>> # 创建XY平面上的圆 ->>> circle = make_circle_redge((0, 0, 0), 2.0) + # 创建XY平面上的圆 + circle = make_circle_redge((0, 0, 0), 2.0) ->>> # 创建垂直平面上的圆 ->>> vertical_circle = make_circle_redge((0, 0, 0), 1.5, (1, 0, 0)) + # 创建垂直平面上的圆 + vertical_circle = make_circle_redge((0, 0, 0), 1.5, (1, 0, 0)) ->>> # 创建指定位置的圆 ->>> offset_circle = make_circle_redge((2, 3, 1), 1.0, (0, 0, 1)) + # 创建指定位置的圆 + offset_circle = make_circle_redge((2, 3, 1), 1.0, (0, 0, 1)) ``` diff --git a/docs/api/make_circle_rface.md b/docs/api/make_circle_rface.md index 8f04d472..f6e9186a 100644 --- a/docs/api/make_circle_rface.md +++ b/docs/api/make_circle_rface.md @@ -28,7 +28,7 @@ def make_circle_rface(center: Tuple[float, float, float], radius: float, normal: - **类型**: `Tuple[float, float, float], optional` - **说明**: 圆所在平面的法向量 (x, y, z), 默认为 (0, 0, 1) 表示XY平面 -## 返回值 +### 返回值 Face: 创建的面对象,表示一个实心的圆形面 @@ -39,11 +39,11 @@ Face: 创建的面对象,表示一个实心的圆形面 ## API使用例子 ```python ->>> # 创建标准圆形面 ->>> circle_face = make_circle_rface((0, 0, 0), 2.0) ->>> area = circle_face.get_area() # 面积为π×2²≈12.57 + # 创建标准圆形面 + circle_face = make_circle_rface((0, 0, 0), 2.0) + area = circle_face.get_area() # 面积为π×2²≈12.57 ->>> # 创建用于拉伸的圆形截面 ->>> profile = make_circle_rface((0, 0, 0), 1.0) ->>> cylinder = extrude_rsolid(profile, (0, 0, 1), 5.0) + # 创建用于拉伸的圆形截面 + profile = make_circle_rface((0, 0, 0), 1.0) + cylinder = extrude_rsolid(profile, (0, 0, 1), 5.0) ``` diff --git a/docs/api/make_circle_rwire.md b/docs/api/make_circle_rwire.md index 0dc96bd5..7fb3c90e 100644 --- a/docs/api/make_circle_rwire.md +++ b/docs/api/make_circle_rwire.md @@ -28,7 +28,7 @@ def make_circle_rwire(center: Tuple[float, float, float], radius: float, normal: - **类型**: `Tuple[float, float, float], optional` - **说明**: 圆所在平面的法向量 (x, y, z), 默认为 (0, 0, 1) 表示XY平面 -## 返回值 +### 返回值 Wire: 创建的线对象,表示一个完整的圆形轮廓 @@ -39,9 +39,9 @@ Wire: 创建的线对象,表示一个完整的圆形轮廓 ## API使用例子 ```python ->>> # 创建标准圆形轮廓 ->>> circle_wire = make_circle_rwire((0, 0, 0), 3.0) + # 创建标准圆形轮廓 + circle_wire = make_circle_rwire((0, 0, 0), 3.0) ->>> # 创建小圆轮廓 ->>> small_circle = make_circle_rwire((1, 1, 0), 0.5) + # 创建小圆轮廓 + small_circle = make_circle_rwire((1, 1, 0), 0.5) ``` diff --git a/docs/api/make_cylinder_rsolid.md b/docs/api/make_cylinder_rsolid.md index 7aa0781f..8139c0d9 100644 --- a/docs/api/make_cylinder_rsolid.md +++ b/docs/api/make_cylinder_rsolid.md @@ -33,7 +33,7 @@ def make_cylinder_rsolid(radius: float, height: float, center: Tuple[float, floa - **类型**: `Tuple[float, float, float], optional` - **说明**: 圆柱体的轴向向量 (x, y, z), 定义圆柱体的方向,默认为 (0, 0, 1) 表示沿Z轴方向 -## 返回值 +### 返回值 Solid: 创建的实体对象,表示一个圆柱体 @@ -44,17 +44,17 @@ Solid: 创建的实体对象,表示一个圆柱体 ## API使用例子 ```python ->>> # 创建标准圆柱体 ->>> cylinder = make_cylinder_rsolid(2.0, 5.0) ->>> volume = cylinder.get_volume() # 体积为π×2²×5≈62.83 + # 创建标准圆柱体 + cylinder = make_cylinder_rsolid(2.0, 5.0) + volume = cylinder.get_volume() # 体积为π×2²×5≈62.83 ->>> # 创建水平圆柱体 ->>> horizontal_cyl = make_cylinder_rsolid(1.0, 4.0, (0, 0, 0), (1, 0, 0)) + # 创建水平圆柱体 + horizontal_cyl = make_cylinder_rsolid(1.0, 4.0, (0, 0, 0), (1, 0, 0)) ->>> # 创建偏移的圆柱体 ->>> offset_cyl = make_cylinder_rsolid(1.5, 3.0, (2, 2, 0)) + # 创建偏移的圆柱体 + offset_cyl = make_cylinder_rsolid(1.5, 3.0, (2, 2, 0)) ->>> # 获取圆柱体的面进行后续操作 ->>> faces = cylinder.get_faces() ->>> top_faces = [f for f in faces if f.has_tag("top")] + # 获取圆柱体的面进行后续操作 + faces = cylinder.get_faces() + top_faces = [f for f in faces if f.has_tag("top")] ``` diff --git a/docs/api/make_face_from_wire_rface.md b/docs/api/make_face_from_wire_rface.md index 60e687aa..371c2214 100644 --- a/docs/api/make_face_from_wire_rface.md +++ b/docs/api/make_face_from_wire_rface.md @@ -23,7 +23,7 @@ def make_face_from_wire_rface(wire: Wire, normal: Tuple[float, float, float] = ( - **类型**: `Tuple[float, float, float], optional` - **说明**: 期望的面法向量 (x, y, z), 用于确定面的方向,默认为 (0, 0, 1) -## 返回值 +### 返回值 Face: 创建的面对象,由输入的线轮廓围成的面 @@ -34,16 +34,16 @@ Face: 创建的面对象,由输入的线轮廓围成的面 ## API使用例子 ```python ->>> # 从矩形线创建面 ->>> rect_wire = make_rectangle_rwire(3.0, 2.0) ->>> rect_face = make_face_from_wire_rface(rect_wire) + # 从矩形线创建面 + rect_wire = make_rectangle_rwire(3.0, 2.0) + rect_face = make_face_from_wire_rface(rect_wire) ->>> # 从圆形线创建面 ->>> circle_wire = make_circle_rwire((0, 0, 0), 1.5) ->>> circle_face = make_face_from_wire_rface(circle_wire) + # 从圆形线创建面 + circle_wire = make_circle_rwire((0, 0, 0), 1.5) + circle_face = make_face_from_wire_rface(circle_wire) ->>> # 从多边形线创建面 ->>> points = [(0, 0, 0), (2, 0, 0), (2, 2, 0), (0, 2, 0)] ->>> poly_wire = make_polyline_rwire(points, closed=True) ->>> poly_face = make_face_from_wire_rface(poly_wire) + # 从多边形线创建面 + points = [(0, 0, 0), (2, 0, 0), (2, 2, 0), (0, 2, 0)] + poly_wire = make_polyline_rwire(points, closed=True) + poly_face = make_face_from_wire_rface(poly_wire) ``` diff --git a/docs/api/make_helix_redge.md b/docs/api/make_helix_redge.md index 4510cff4..f6652396 100644 --- a/docs/api/make_helix_redge.md +++ b/docs/api/make_helix_redge.md @@ -38,7 +38,7 @@ def make_helix_redge(pitch: float, height: float, radius: float, center: Tuple[f - **类型**: `Tuple[float, float, float], optional` - **说明**: 螺旋轴的方向向量 (x, y, z), 默认为 (0, 0, 1) 表示沿Z轴方向 -## 返回值 +### 返回值 Edge: 创建的边对象,表示一个螺旋线 @@ -49,12 +49,12 @@ Edge: 创建的边对象,表示一个螺旋线 ## API使用例子 ```python ->>> # 创建标准螺旋线 ->>> helix = make_helix_redge(2.0, 10.0, 1.0) # 螺距2,高度10,半径1 + # 创建标准螺旋线 + helix = make_helix_redge(2.0, 10.0, 1.0) # 螺距2,高度10,半径1 ->>> # 创建紧密螺旋线 ->>> tight_helix = make_helix_redge(0.5, 5.0, 0.5) + # 创建紧密螺旋线 + tight_helix = make_helix_redge(0.5, 5.0, 0.5) ->>> # 创建水平螺旋线 ->>> horizontal_helix = make_helix_redge(1.0, 8.0, 2.0, (0, 0, 0), (1, 0, 0)) + # 创建水平螺旋线 + horizontal_helix = make_helix_redge(1.0, 8.0, 2.0, (0, 0, 0), (1, 0, 0)) ``` diff --git a/docs/api/make_helix_rwire.md b/docs/api/make_helix_rwire.md index 817e3543..7e0b24ae 100644 --- a/docs/api/make_helix_rwire.md +++ b/docs/api/make_helix_rwire.md @@ -38,7 +38,7 @@ def make_helix_rwire(pitch: float, height: float, radius: float, center: Tuple[f - **类型**: `Tuple[float, float, float], optional` - **说明**: 螺旋轴的方向向量 (x, y, z), 默认为 (0, 0, 1) 表示沿Z轴方向 -## 返回值 +### 返回值 Wire: 创建的线对象,包含一个螺旋线 @@ -49,12 +49,12 @@ Wire: 创建的线对象,包含一个螺旋线 ## API使用例子 ```python ->>> # 创建螺旋线线对象 ->>> helix_wire = make_helix_rwire(1.5, 6.0, 1.0) + # 创建螺旋线线对象 + helix_wire = make_helix_rwire(1.5, 6.0, 1.0) ->>> # 用于扫掠操作的螺旋路径 ->>> profile = make_circle_rface((0, 0, 0), 0.1) ->>> helix_path = make_helix_rwire(2.0, 10.0, 2.0) + # 用于扫掠操作的螺旋路径 + profile = make_circle_rface((0, 0, 0), 0.1) + helix_path = make_helix_rwire(2.0, 10.0, 2.0) ->>> # 然后可以用 sweep_rsolid(profile, helix_path) 创建螺旋扫掠 + # 然后可以用 sweep_rsolid(profile, helix_path) 创建螺旋扫掠 ``` diff --git a/docs/api/make_line_redge.md b/docs/api/make_line_redge.md index 919e5769..29fef74d 100644 --- a/docs/api/make_line_redge.md +++ b/docs/api/make_line_redge.md @@ -23,7 +23,7 @@ def make_line_redge(start: Tuple[float, float, float], end: Tuple[float, float, - **类型**: `Tuple[float, float, float]` - **说明**: 结束点坐标 (x, y, z),定义线段的终点 -## 返回值 +### 返回值 Edge: 创建的边对象,表示连接两点的直线段 @@ -34,13 +34,13 @@ Edge: 创建的边对象,表示连接两点的直线段 ## API使用例子 ```python ->>> # 创建水平线段 ->>> line = make_line_redge((0, 0, 0), (5, 0, 0)) + # 创建水平线段 + line = make_line_redge((0, 0, 0), (5, 0, 0)) ->>> # 创建三维空间中的线段 ->>> line_3d = make_line_redge((1, 1, 1), (3, 2, 4)) + # 创建三维空间中的线段 + line_3d = make_line_redge((1, 1, 1), (3, 2, 4)) ->>> # 在工作平面中创建线段 ->>> with SimpleWorkplane((0, 0, 1)): + # 在工作平面中创建线段 + with SimpleWorkplane((0, 0, 1)): ... elevated_line = make_line_redge((0, 0, 0), (2, 2, 0)) ``` diff --git a/docs/api/make_point_rvertex.md b/docs/api/make_point_rvertex.md index 982c7d7c..3a2d67b0 100644 --- a/docs/api/make_point_rvertex.md +++ b/docs/api/make_point_rvertex.md @@ -28,7 +28,7 @@ def make_point_rvertex(x: float, y: float, z: float) -> Vertex - **类型**: `float` - **说明**: Z坐标值,用于定义点在Z轴方向的位置 -## 返回值 +### 返回值 Vertex: 创建的顶点对象,包含指定坐标的点 @@ -39,13 +39,13 @@ Vertex: 创建的顶点对象,包含指定坐标的点 ## API使用例子 ```python ->>> # 创建原点 ->>> origin = make_point_rvertex(0, 0, 0) + # 创建原点 + origin = make_point_rvertex(0, 0, 0) ->>> # 创建指定坐标的点 ->>> point = make_point_rvertex(1.5, 2.0, 3.0) + # 创建指定坐标的点 + point = make_point_rvertex(1.5, 2.0, 3.0) ->>> # 在工作平面中创建点 ->>> with SimpleWorkplane((1, 1, 1)): + # 在工作平面中创建点 + with SimpleWorkplane((1, 1, 1)): ... local_point = make_point_rvertex(0, 0, 0) # 实际位置为(1, 1, 1) ``` diff --git a/docs/api/make_polyline_rwire.md b/docs/api/make_polyline_rwire.md index 3615938a..01ab664b 100644 --- a/docs/api/make_polyline_rwire.md +++ b/docs/api/make_polyline_rwire.md @@ -23,7 +23,7 @@ def make_polyline_rwire(points: List[Tuple[float, float, float]], closed: bool = - **类型**: `bool, optional` - **说明**: 是否创建闭合的多段线,默认为False。 如果为True,会自动连接最后一个点和第一个点 -## 返回值 +### 返回值 Wire: 创建的线对象,由多个直线段组成的多段线 @@ -34,15 +34,15 @@ Wire: 创建的线对象,由多个直线段组成的多段线 ## API使用例子 ```python ->>> # 创建L形多段线 ->>> points = [(0, 0, 0), (3, 0, 0), (3, 2, 0)] ->>> l_shape = make_polyline_rwire(points) + # 创建L形多段线 + points = [(0, 0, 0), (3, 0, 0), (3, 2, 0)] + l_shape = make_polyline_rwire(points) ->>> # 创建三角形轮廓 ->>> triangle_points = [(0, 0, 0), (2, 0, 0), (1, 2, 0)] ->>> triangle = make_polyline_rwire(triangle_points, closed=True) + # 创建三角形轮廓 + triangle_points = [(0, 0, 0), (2, 0, 0), (1, 2, 0)] + triangle = make_polyline_rwire(triangle_points, closed=True) ->>> # 创建复杂的多边形 ->>> polygon_points = [(0, 0, 0), (2, 0, 0), (3, 1, 0), (2, 2, 0), (0, 2, 0)] ->>> polygon = make_polyline_rwire(polygon_points, closed=True) + # 创建复杂的多边形 + polygon_points = [(0, 0, 0), (2, 0, 0), (3, 1, 0), (2, 2, 0), (0, 2, 0)] + polygon = make_polyline_rwire(polygon_points, closed=True) ``` diff --git a/docs/api/make_rectangle_rface.md b/docs/api/make_rectangle_rface.md index b16e96e4..f4b472a2 100644 --- a/docs/api/make_rectangle_rface.md +++ b/docs/api/make_rectangle_rface.md @@ -33,7 +33,7 @@ def make_rectangle_rface(width: float, height: float, center: Tuple[float, float - **类型**: `Tuple[float, float, float], optional` - **说明**: 矩形所在平面的法向量 (x, y, z), 默认为 (0, 0, 1) 表示XY平面 -## 返回值 +### 返回值 Face: 创建的面对象,表示一个实心的矩形面 @@ -44,11 +44,11 @@ Face: 创建的面对象,表示一个实心的矩形面 ## API使用例子 ```python ->>> # 创建标准矩形面 ->>> rect_face = make_rectangle_rface(5.0, 3.0) ->>> area = rect_face.get_area() # 面积为5×3=15 + # 创建标准矩形面 + rect_face = make_rectangle_rface(5.0, 3.0) + area = rect_face.get_area() # 面积为5×3=15 ->>> # 创建用于拉伸的矩形截面 ->>> profile = make_rectangle_rface(2.0, 2.0) ->>> box = extrude_rsolid(profile, (0, 0, 1), 3.0) + # 创建用于拉伸的矩形截面 + profile = make_rectangle_rface(2.0, 2.0) + box = extrude_rsolid(profile, (0, 0, 1), 3.0) ``` diff --git a/docs/api/make_rectangle_rwire.md b/docs/api/make_rectangle_rwire.md index 357da702..d03c6d4a 100644 --- a/docs/api/make_rectangle_rwire.md +++ b/docs/api/make_rectangle_rwire.md @@ -33,7 +33,7 @@ def make_rectangle_rwire(width: float, height: float, center: Tuple[float, float - **类型**: `Tuple[float, float, float], optional` - **说明**: 矩形所在平面的法向量 (x, y, z), 默认为 (0, 0, 1) 表示XY平面 -## 返回值 +### 返回值 Wire: 创建的线对象,表示一个封闭的矩形轮廓 @@ -44,12 +44,12 @@ Wire: 创建的线对象,表示一个封闭的矩形轮廓 ## API使用例子 ```python ->>> # 创建标准矩形轮廓 ->>> rect = make_rectangle_rwire(4.0, 3.0) + # 创建标准矩形轮廓 + rect = make_rectangle_rwire(4.0, 3.0) ->>> # 创建偏移的矩形 ->>> offset_rect = make_rectangle_rwire(2.0, 2.0, (1, 1, 0)) + # 创建偏移的矩形 + offset_rect = make_rectangle_rwire(2.0, 2.0, (1, 1, 0)) ->>> # 创建垂直平面上的矩形 ->>> vertical_rect = make_rectangle_rwire(3.0, 2.0, (0, 0, 0), (1, 0, 0)) + # 创建垂直平面上的矩形 + vertical_rect = make_rectangle_rwire(3.0, 2.0, (0, 0, 0), (1, 0, 0)) ``` diff --git a/docs/api/make_segment_redge.md b/docs/api/make_segment_redge.md index ff68ba90..43e7e905 100644 --- a/docs/api/make_segment_redge.md +++ b/docs/api/make_segment_redge.md @@ -23,16 +23,16 @@ def make_segment_redge(start: Tuple[float, float, float], end: Tuple[float, floa - **类型**: `Tuple[float, float, float]` - **说明**: 结束点坐标 (x, y, z),定义线段的终点 -## 返回值 +### 返回值 Edge: 创建的边对象,表示连接两点的直线段 ## API使用例子 ```python ->>> # 创建垂直线段 ->>> vertical_line = make_segment_redge((0, 0, 0), (0, 0, 5)) + # 创建垂直线段 + vertical_line = make_segment_redge((0, 0, 0), (0, 0, 5)) ->>> # 创建对角线段 ->>> diagonal = make_segment_redge((0, 0, 0), (1, 1, 1)) + # 创建对角线段 + diagonal = make_segment_redge((0, 0, 0), (1, 1, 1)) ``` diff --git a/docs/api/make_segment_rwire.md b/docs/api/make_segment_rwire.md index 74c76e2e..bfab3231 100644 --- a/docs/api/make_segment_rwire.md +++ b/docs/api/make_segment_rwire.md @@ -23,7 +23,7 @@ def make_segment_rwire(start: Tuple[float, float, float], end: Tuple[float, floa - **类型**: `Tuple[float, float, float]` - **说明**: 结束点坐标 (x, y, z),定义线段的终点 -## 返回值 +### 返回值 Wire: 创建的线对象,包含一个连接两点的直线段 @@ -34,9 +34,9 @@ Wire: 创建的线对象,包含一个连接两点的直线段 ## API使用例子 ```python ->>> # 创建基本线段线 ->>> wire = make_segment_rwire((0, 0, 0), (3, 0, 0)) + # 创建基本线段线 + wire = make_segment_rwire((0, 0, 0), (3, 0, 0)) ->>> # 创建斜线段 ->>> diagonal_wire = make_segment_rwire((0, 0, 0), (2, 2, 0)) + # 创建斜线段 + diagonal_wire = make_segment_rwire((0, 0, 0), (2, 2, 0)) ``` diff --git a/docs/api/make_sphere_rsolid.md b/docs/api/make_sphere_rsolid.md index dc56695e..f870a765 100644 --- a/docs/api/make_sphere_rsolid.md +++ b/docs/api/make_sphere_rsolid.md @@ -23,7 +23,7 @@ def make_sphere_rsolid(radius: float, center: Tuple[float, float, float] = (0, 0 - **类型**: `Tuple[float, float, float], optional` - **说明**: 球体的中心坐标 (x, y, z), 默认为 (0, 0, 0) -## 返回值 +### 返回值 Solid: 创建的实体对象,表示一个球体 @@ -34,17 +34,17 @@ Solid: 创建的实体对象,表示一个球体 ## API使用例子 ```python ->>> # 创建标准单位球体 ->>> unit_sphere = make_sphere_rsolid(1.0) ->>> volume = unit_sphere.get_volume() # 体积为(4/3)π≈4.19 + # 创建标准单位球体 + unit_sphere = make_sphere_rsolid(1.0) + volume = unit_sphere.get_volume() # 体积为(4/3)π≈4.19 ->>> # 创建大球体 ->>> large_sphere = make_sphere_rsolid(3.0) + # 创建大球体 + large_sphere = make_sphere_rsolid(3.0) ->>> # 创建偏移的球体 ->>> offset_sphere = make_sphere_rsolid(2.0, (1, 1, 1)) + # 创建偏移的球体 + offset_sphere = make_sphere_rsolid(2.0, (1, 1, 1)) ->>> # 获取球体的面进行后续操作 ->>> faces = unit_sphere.get_faces() ->>> surface_faces = [f for f in faces if f.has_tag("surface")] + # 获取球体的面进行后续操作 + faces = unit_sphere.get_faces() + surface_faces = [f for f in faces if f.has_tag("surface")] ``` diff --git a/docs/api/make_spline_redge.md b/docs/api/make_spline_redge.md index bf245783..5e2aca7e 100644 --- a/docs/api/make_spline_redge.md +++ b/docs/api/make_spline_redge.md @@ -23,7 +23,7 @@ def make_spline_redge(points: List[Tuple[float, float, float]], tangents: Option - **类型**: `Optional[List[Tuple[float, float, float]]], optional` - **说明**: 可选的切线向量列表 [(x, y, z), ...],如果提供则数量必须与控制点一致 -## 返回值 +### 返回值 Edge: 创建的边对象,表示通过控制点的平滑样条曲线 @@ -34,16 +34,16 @@ Edge: 创建的边对象,表示通过控制点的平滑样条曲线 ## API使用例子 ```python ->>> # 创建简单的样条曲线 ->>> points = [(0, 0, 0), (1, 2, 0), (3, 1, 0), (4, 3, 0)] ->>> spline = make_spline_redge(points) + # 创建简单的样条曲线 + points = [(0, 0, 0), (1, 2, 0), (3, 1, 0), (4, 3, 0)] + spline = make_spline_redge(points) ->>> # 创建带切线控制的样条曲线 ->>> points = [(0, 0, 0), (2, 0, 0), (4, 0, 0)] ->>> tangents = [(1, 0, 0), (0, 1, 0), (1, 0, 0)] ->>> controlled_spline = make_spline_redge(points, tangents) + # 创建带切线控制的样条曲线 + points = [(0, 0, 0), (2, 0, 0), (4, 0, 0)] + tangents = [(1, 0, 0), (0, 1, 0), (1, 0, 0)] + controlled_spline = make_spline_redge(points, tangents) ->>> # 创建3D样条曲线 ->>> points_3d = [(0, 0, 0), (1, 1, 1), (2, 0, 2), (3, 1, 1)] ->>> spline_3d = make_spline_redge(points_3d) + # 创建3D样条曲线 + points_3d = [(0, 0, 0), (1, 1, 1), (2, 0, 2), (3, 1, 1)] + spline_3d = make_spline_redge(points_3d) ``` diff --git a/docs/api/make_spline_rwire.md b/docs/api/make_spline_rwire.md index 90b72c53..8a6ec4bf 100644 --- a/docs/api/make_spline_rwire.md +++ b/docs/api/make_spline_rwire.md @@ -28,7 +28,7 @@ def make_spline_rwire(points: List[Tuple[float, float, float]], tangents: Option - **类型**: `bool, optional` - **说明**: 是否创建闭合的样条曲线,默认为False -## 返回值 +### 返回值 Wire: 创建的线对象,包含一个样条曲线 @@ -39,11 +39,11 @@ Wire: 创建的线对象,包含一个样条曲线 ## API使用例子 ```python ->>> # 创建开放样条曲线线 ->>> points = [(0, 0, 0), (2, 3, 0), (4, 1, 0), (6, 2, 0)] ->>> spline_wire = make_spline_rwire(points) + # 创建开放样条曲线线 + points = [(0, 0, 0), (2, 3, 0), (4, 1, 0), (6, 2, 0)] + spline_wire = make_spline_rwire(points) ->>> # 创建闭合样条曲线 ->>> points = [(0, 0, 0), (2, 2, 0), (4, 0, 0), (2, -2, 0)] ->>> closed_spline = make_spline_rwire(points, closed=True) + # 创建闭合样条曲线 + points = [(0, 0, 0), (2, 2, 0), (4, 0, 0), (2, -2, 0)] + closed_spline = make_spline_rwire(points, closed=True) ``` diff --git a/docs/api/make_three_point_arc_redge.md b/docs/api/make_three_point_arc_redge.md index 380b787d..20d7aaee 100644 --- a/docs/api/make_three_point_arc_redge.md +++ b/docs/api/make_three_point_arc_redge.md @@ -28,7 +28,7 @@ def make_three_point_arc_redge(start: Tuple[float, float, float], middle: Tuple[ - **类型**: `Tuple[float, float, float]` - **说明**: 圆弧的结束点坐标 (x, y, z) -## 返回值 +### 返回值 Edge: 创建的边对象,表示通过三点的圆弧 @@ -39,12 +39,12 @@ Edge: 创建的边对象,表示通过三点的圆弧 ## API使用例子 ```python ->>> # 创建90度圆弧 ->>> arc = make_three_point_arc_redge((0, 0, 0), (1, 1, 0), (2, 0, 0)) + # 创建90度圆弧 + arc = make_three_point_arc_redge((0, 0, 0), (1, 1, 0), (2, 0, 0)) ->>> # 创建大圆弧 ->>> large_arc = make_three_point_arc_redge((0, 0, 0), (0, 3, 0), (0, 6, 0)) + # 创建大圆弧 + large_arc = make_three_point_arc_redge((0, 0, 0), (0, 3, 0), (0, 6, 0)) ->>> # 创建3D圆弧 ->>> arc_3d = make_three_point_arc_redge((0, 0, 0), (1, 1, 1), (2, 0, 2)) + # 创建3D圆弧 + arc_3d = make_three_point_arc_redge((0, 0, 0), (1, 1, 1), (2, 0, 2)) ``` diff --git a/docs/api/make_three_point_arc_rwire.md b/docs/api/make_three_point_arc_rwire.md index 316ee20a..9538f26c 100644 --- a/docs/api/make_three_point_arc_rwire.md +++ b/docs/api/make_three_point_arc_rwire.md @@ -28,7 +28,7 @@ def make_three_point_arc_rwire(start: Tuple[float, float, float], middle: Tuple[ - **类型**: `Tuple[float, float, float]` - **说明**: 圆弧的结束点坐标 (x, y, z) -## 返回值 +### 返回值 Wire: 创建的线对象,包含一个通过三点的圆弧 @@ -39,11 +39,11 @@ Wire: 创建的线对象,包含一个通过三点的圆弧 ## API使用例子 ```python ->>> # 创建圆弧线 ->>> arc_wire = make_three_point_arc_rwire((0, 0, 0), (1, 1, 0), (0, 2, 0)) + # 创建圆弧线 + arc_wire = make_three_point_arc_rwire((0, 0, 0), (1, 1, 0), (0, 2, 0)) ->>> # 与直线连接创建复杂轮廓 ->>> line = make_segment_rwire((0, 2, 0), (3, 2, 0)) + # 与直线连接创建复杂轮廓 + line = make_segment_rwire((0, 2, 0), (3, 2, 0)) ->>> # 然后可以连接arc_wire和line + # 然后可以连接arc_wire和line ``` diff --git a/docs/api/make_wire_from_edges_rwire.md b/docs/api/make_wire_from_edges_rwire.md index 880dbbe0..4c6c07a8 100644 --- a/docs/api/make_wire_from_edges_rwire.md +++ b/docs/api/make_wire_from_edges_rwire.md @@ -18,7 +18,7 @@ def make_wire_from_edges_rwire(edges: List[Edge]) -> Wire - **类型**: `List[Edge]` - **说明**: 输入的边对象列表,边应该能够连接成连续的线 -## 返回值 +### 返回值 Wire: 创建的线对象,由输入的边组成的连续线 @@ -29,13 +29,13 @@ Wire: 创建的线对象,由输入的边组成的连续线 ## API使用例子 ```python ->>> # 创建L形线 ->>> edge1 = make_line_redge((0, 0, 0), (2, 0, 0)) # 水平线 ->>> edge2 = make_line_redge((2, 0, 0), (2, 2, 0)) # 垂直线 ->>> l_wire = make_wire_from_edges_rwire([edge1, edge2]) + # 创建L形线 + edge1 = make_line_redge((0, 0, 0), (2, 0, 0)) # 水平线 + edge2 = make_line_redge((2, 0, 0), (2, 2, 0)) # 垂直线 + l_wire = make_wire_from_edges_rwire([edge1, edge2]) ->>> # 创建包含直线和圆弧的复杂线 ->>> line = make_line_redge((0, 0, 0), (2, 0, 0)) ->>> arc = make_three_point_arc_redge((2, 0, 0), (3, 1, 0), (2, 2, 0)) ->>> complex_wire = make_wire_from_edges_rwire([line, arc]) + # 创建包含直线和圆弧的复杂线 + line = make_line_redge((0, 0, 0), (2, 0, 0)) + arc = make_three_point_arc_redge((2, 0, 0), (3, 1, 0), (2, 2, 0)) + complex_wire = make_wire_from_edges_rwire([line, arc]) ``` diff --git a/docs/api/mirror_shape.md b/docs/api/mirror_shape.md index b9a682d5..fa1a3e52 100644 --- a/docs/api/mirror_shape.md +++ b/docs/api/mirror_shape.md @@ -28,7 +28,7 @@ def mirror_shape(shape: AnyShape, plane_origin: Tuple[float, float, float], plan - **类型**: `Tuple[float, float, float]` - **说明**: 镜像平面的法向量 (x, y, z), 定义镜像平面的方向,会被标准化处理 -## 返回值 +### 返回值 AnyShape: 镜像后的几何体,类型与输入相同 @@ -39,15 +39,15 @@ AnyShape: 镜像后的几何体,类型与输入相同 ## API使用例子 ```python ->>> # 沿YZ平面镜像立方体 ->>> box = make_box_rsolid(2, 2, 2, (1, 0, 0)) ->>> mirrored_box = mirror_shape(box, (0, 0, 0), (1, 0, 0)) + # 沿YZ平面镜像立方体 + box = make_box_rsolid(2, 2, 2, (1, 0, 0)) + mirrored_box = mirror_shape(box, (0, 0, 0), (1, 0, 0)) ->>> # 沿XY平面镜像圆柱体 ->>> cylinder = make_cylinder_rsolid(1.0, 3.0, (0, 0, 1)) ->>> mirrored_cyl = mirror_shape(cylinder, (0, 0, 0), (0, 0, 1)) + # 沿XY平面镜像圆柱体 + cylinder = make_cylinder_rsolid(1.0, 3.0, (0, 0, 1)) + mirrored_cyl = mirror_shape(cylinder, (0, 0, 0), (0, 0, 1)) ->>> # 沿任意平面镜像 ->>> sphere = make_sphere_rsolid(1.5, (2, 2, 0)) ->>> mirrored_sphere = mirror_shape(sphere, (1, 1, 0), (1, 1, 0)) + # 沿任意平面镜像 + sphere = make_sphere_rsolid(1.5, (2, 2, 0)) + mirrored_sphere = mirror_shape(sphere, (1, 1, 0), (1, 1, 0)) ``` diff --git a/docs/api/radial_pattern_rsolidlist.md b/docs/api/radial_pattern_rsolidlist.md index 903734f7..c5604c1c 100644 --- a/docs/api/radial_pattern_rsolidlist.md +++ b/docs/api/radial_pattern_rsolidlist.md @@ -38,7 +38,7 @@ def radial_pattern_rsolidlist(shape: AnyShape, center: Tuple[float, float, float - **类型**: `float` - **说明**: 总旋转角度,单位为度数(0-360), 定义整个阵列的角度范围 -## 返回值 +### 返回值 List[Solid]: 径向阵列后的几何体列表,包含原始对象和所有旋转的对象 @@ -49,15 +49,15 @@ List[Solid]: 径向阵列后的几何体列表,包含原始对象和所有旋 ## API使用例子 ```python ->>> # 创建立方体的径向阵列(6个,360度) ->>> box = make_box_rsolid(1, 0.5, 0.5, (2, 0, 0)) # 距离中心2单位 ->>> radial_boxes = radial_pattern_rsolidlist(box, (0, 0, 0), (0, 0, 1), 6, 360) + # 创建立方体的径向阵列(6个,360度) + box = make_box_rsolid(1, 0.5, 0.5, (2, 0, 0)) # 距离中心2单位 + radial_boxes = radial_pattern_rsolidlist(box, (0, 0, 0), (0, 0, 1), 6, 360) ->>> # 创建半圆阵列 ->>> cylinder = make_cylinder_rsolid(0.3, 1.0, (1.5, 0, 0)) ->>> half_circle = radial_pattern_rsolidlist(cylinder, (0, 0, 0), (0, 0, 1), 4, 180) + # 创建半圆阵列 + cylinder = make_cylinder_rsolid(0.3, 1.0, (1.5, 0, 0)) + half_circle = radial_pattern_rsolidlist(cylinder, (0, 0, 0), (0, 0, 1), 4, 180) ->>> # 围绕Y轴的径向阵列 ->>> element = make_sphere_rsolid(0.5, (3, 0, 0)) ->>> vertical_array = radial_pattern_rsolidlist(element, (0, 0, 0), (0, 1, 0), 8, 360) + # 围绕Y轴的径向阵列 + element = make_sphere_rsolid(0.5, (3, 0, 0)) + vertical_array = radial_pattern_rsolidlist(element, (0, 0, 0), (0, 1, 0), 8, 360) ``` diff --git a/docs/api/revolve_rsolid.md b/docs/api/revolve_rsolid.md index c1ca6e51..7dc187fb 100644 --- a/docs/api/revolve_rsolid.md +++ b/docs/api/revolve_rsolid.md @@ -33,7 +33,7 @@ def revolve_rsolid(profile: Union[Wire, Face], axis: Tuple[float, float, float] - **类型**: `Tuple[float, float, float], optional` - **说明**: 旋转轴通过的点坐标 (x, y, z), 默认为 (0, 0, 0) -## 返回值 +### 返回值 Solid: 旋转后的实体对象 @@ -44,16 +44,16 @@ Solid: 旋转后的实体对象 ## API使用例子 ```python ->>> # 旋转矩形创建圆柱体 ->>> rect = make_rectangle_rface(1.0, 3.0, (2, 0, 0)) # 远离旋转轴 ->>> cylinder = revolve_rsolid(rect, (0, 0, 1), 360) + # 旋转矩形创建圆柱体 + rect = make_rectangle_rface(1.0, 3.0, (2, 0, 0)) # 远离旋转轴 + cylinder = revolve_rsolid(rect, (0, 0, 1), 360) ->>> # 创建圆锥体 ->>> triangle_points = [(1, 0, 0), (2, 0, 0), (1.5, 2, 0)] ->>> triangle = make_polyline_rwire(triangle_points, closed=True) ->>> cone = revolve_rsolid(triangle, (0, 0, 1), 360) + # 创建圆锥体 + triangle_points = [(1, 0, 0), (2, 0, 0), (1.5, 2, 0)] + triangle = make_polyline_rwire(triangle_points, closed=True) + cone = revolve_rsolid(triangle, (0, 0, 1), 360) ->>> # 创建部分旋转体(90度扇形) ->>> rect = make_rectangle_rface(0.5, 2.0, (1.5, 0, 0)) ->>> partial_solid = revolve_rsolid(rect, (0, 0, 1), 90) + # 创建部分旋转体(90度扇形) + rect = make_rectangle_rface(0.5, 2.0, (1.5, 0, 0)) + partial_solid = revolve_rsolid(rect, (0, 0, 1), 90) ``` diff --git a/docs/api/rotate_shape.md b/docs/api/rotate_shape.md index 7fea327d..48db9bf5 100644 --- a/docs/api/rotate_shape.md +++ b/docs/api/rotate_shape.md @@ -34,7 +34,7 @@ def rotate_shape(shape: AnyShape, angle: float, axis: Tuple[float, float, float] - **类型**: `Tuple[float, float, float], optional` - **说明**: 旋转中心点坐标 (x, y, z), 默认为 (0, 0, 0) -## 返回值 +### 返回值 AnyShape: 旋转后的几何体,类型与输入相同 @@ -45,15 +45,15 @@ AnyShape: 旋转后的几何体,类型与输入相同 ## API使用例子 ```python ->>> # 绕Z轴旋转立方体45度 ->>> box = make_box_rsolid(2, 2, 2) ->>> rotated_box = rotate_shape(box, 45) + # 绕Z轴旋转立方体45度 + box = make_box_rsolid(2, 2, 2) + rotated_box = rotate_shape(box, 45) ->>> # 绕X轴旋转圆形面90度 ->>> circle = make_circle_rface((0, 0, 0), 1.0) ->>> rotated_circle = rotate_shape(circle, 90, (1, 0, 0)) + # 绕X轴旋转圆形面90度 + circle = make_circle_rface((0, 0, 0), 1.0) + rotated_circle = rotate_shape(circle, 90, (1, 0, 0)) ->>> # 围绕指定点旋转 ->>> line = make_line_redge((0, 0, 0), (2, 0, 0)) ->>> rotated_line = rotate_shape(line, 90, (0, 0, 1), (1, 0, 0)) + # 围绕指定点旋转 + line = make_line_redge((0, 0, 0), (2, 0, 0)) + rotated_line = rotate_shape(line, 90, (0, 0, 1), (1, 0, 0)) ``` diff --git a/docs/api/select_edges_by_tag.md b/docs/api/select_edges_by_tag.md index 53bc98e8..8622ec40 100644 --- a/docs/api/select_edges_by_tag.md +++ b/docs/api/select_edges_by_tag.md @@ -16,6 +16,6 @@ def select_edges_by_tag(shape: Union[Face, Solid], tag: str) -> List[Edge] - **说明**: 标签名称 -## 返回值 +### 返回值 匹配标签的边列表 diff --git a/docs/api/select_faces_by_tag.md b/docs/api/select_faces_by_tag.md index 73d8045d..bac890ec 100644 --- a/docs/api/select_faces_by_tag.md +++ b/docs/api/select_faces_by_tag.md @@ -16,6 +16,6 @@ def select_faces_by_tag(solid: Solid, tag: str) -> List[Face] - **说明**: 标签名称 -## 返回值 +### 返回值 匹配标签的面列表 diff --git a/docs/api/set_tag.md b/docs/api/set_tag.md index 6df21b73..eb96c3a1 100644 --- a/docs/api/set_tag.md +++ b/docs/api/set_tag.md @@ -16,6 +16,6 @@ def set_tag(shape: AnyShape, tag: str) -> AnyShape - **说明**: 标签名称 -## 返回值 +### 返回值 设置标签后的几何体 diff --git a/docs/api/shell_rsolid.md b/docs/api/shell_rsolid.md index 6bfdfeb0..c4c23f9c 100644 --- a/docs/api/shell_rsolid.md +++ b/docs/api/shell_rsolid.md @@ -28,7 +28,7 @@ def shell_rsolid(solid: Solid, faces_to_remove: List[Face], thickness: float) -> - **类型**: `float` - **说明**: 壁厚,必须为正数,定义抽壳后的壁厚度 -## 返回值 +### 返回值 Solid: 抽壳后的实体对象,内部为空心结构 @@ -39,19 +39,19 @@ Solid: 抽壳后的实体对象,内部为空心结构 ## API使用例子 ```python ->>> # 创建空心立方体容器 ->>> box = make_box_rsolid(4, 4, 4) ->>> top_faces = [f for f in box.get_faces() if f.has_tag("top")] ->>> container = shell_rsolid(box, top_faces, 0.2) + # 创建空心立方体容器 + box = make_box_rsolid(4, 4, 4) + top_faces = [f for f in box.get_faces() if f.has_tag("top")] + container = shell_rsolid(box, top_faces, 0.2) ->>> # 创建空心球体 ->>> sphere = make_sphere_rsolid(3.0) + # 创建空心球体 + sphere = make_sphere_rsolid(3.0) ->>> # 不移除任何面,创建闭合空心球 ->>> hollow_sphere = shell_rsolid(sphere, [], 0.3) + # 不移除任何面,创建闭合空心球 + hollow_sphere = shell_rsolid(sphere, [], 0.3) ->>> # 创建有开口的圆柱体容器 ->>> cylinder = make_cylinder_rsolid(2.0, 5.0) ->>> top_faces = [f for f in cylinder.get_faces() if f.has_tag("top")] ->>> cup = shell_rsolid(cylinder, top_faces, 0.1) + # 创建有开口的圆柱体容器 + cylinder = make_cylinder_rsolid(2.0, 5.0) + top_faces = [f for f in cylinder.get_faces() if f.has_tag("top")] + cup = shell_rsolid(cylinder, top_faces, 0.1) ``` diff --git a/docs/api/sweep_rsolid.md b/docs/api/sweep_rsolid.md index 883e04ac..5f83ef7f 100644 --- a/docs/api/sweep_rsolid.md +++ b/docs/api/sweep_rsolid.md @@ -33,7 +33,7 @@ def sweep_rsolid(profile: Face, path: Wire, make_solid: bool = True, is_frenet: - **类型**: `bool, optional` - **说明**: 是否使用Frenet框架,默认为False。 True时轮廓沿路径的法向量旋转,False时保持轮廓方向 -## 返回值 +### 返回值 Union[Solid, Shell]: 扫掠后的实体或壳体,取决于make_solid参数 @@ -44,19 +44,19 @@ Union[Solid, Shell]: 扫掠后的实体或壳体,取决于make_solid参数 ## API使用例子 ```python ->>> # 沿直线扫掠圆形创建圆管 ->>> circle = make_circle_rface((0, 0, 0), 0.5) ->>> line_path = make_segment_rwire((0, 0, 0), (10, 0, 0)) ->>> tube = sweep_rsolid(circle, line_path) + # 沿直线扫掠圆形创建圆管 + circle = make_circle_rface((0, 0, 0), 0.5) + line_path = make_segment_rwire((0, 0, 0), (10, 0, 0)) + tube = sweep_rsolid(circle, line_path) ->>> # 沿螺旋路径扫掠创建螺旋管 ->>> square = make_rectangle_rface(0.2, 0.2) ->>> helix_path = make_helix_rwire(1.0, 5.0, 2.0) ->>> spiral_tube = sweep_rsolid(square, helix_path, is_frenet=True) + # 沿螺旋路径扫掠创建螺旋管 + square = make_rectangle_rface(0.2, 0.2) + helix_path = make_helix_rwire(1.0, 5.0, 2.0) + spiral_tube = sweep_rsolid(square, helix_path, is_frenet=True) ->>> # 沿曲线扫掠创建复杂形状 ->>> profile = make_rectangle_rface(1.0, 0.5) ->>> curve_points = [(0, 0, 0), (2, 2, 1), (4, 0, 2), (6, -1, 3)] ->>> curve_path = make_spline_rwire(curve_points) ->>> swept_shape = sweep_rsolid(profile, curve_path) + # 沿曲线扫掠创建复杂形状 + profile = make_rectangle_rface(1.0, 0.5) + curve_points = [(0, 0, 0), (2, 2, 1), (4, 0, 2), (6, -1, 3)] + curve_path = make_spline_rwire(curve_points) + swept_shape = sweep_rsolid(profile, curve_path) ``` diff --git a/docs/api/translate_shape.md b/docs/api/translate_shape.md index 0f6fd62a..960eb99e 100644 --- a/docs/api/translate_shape.md +++ b/docs/api/translate_shape.md @@ -23,7 +23,7 @@ def translate_shape(shape: AnyShape, vector: Tuple[float, float, float]) -> AnyS - **类型**: `Tuple[float, float, float]` - **说明**: 平移向量 (dx, dy, dz), 定义在X、Y、Z方向上的平移距离 -## 返回值 +### 返回值 AnyShape: 平移后的几何体,类型与输入相同 @@ -34,15 +34,15 @@ AnyShape: 平移后的几何体,类型与输入相同 ## API使用例子 ```python ->>> # 平移立方体 ->>> box = make_box_rsolid(2, 2, 2) ->>> moved_box = translate_shape(box, (5, 0, 0)) # 沿X轴移动5个单位 + # 平移立方体 + box = make_box_rsolid(2, 2, 2) + moved_box = translate_shape(box, (5, 0, 0)) # 沿X轴移动5个单位 ->>> # 平移圆形面 ->>> circle = make_circle_rface((0, 0, 0), 1.0) ->>> moved_circle = translate_shape(circle, (1, 1, 2)) + # 平移圆形面 + circle = make_circle_rface((0, 0, 0), 1.0) + moved_circle = translate_shape(circle, (1, 1, 2)) ->>> # 平移线段 ->>> line = make_line_redge((0, 0, 0), (1, 0, 0)) ->>> moved_line = translate_shape(line, (0, 3, 0)) + # 平移线段 + line = make_line_redge((0, 0, 0), (1, 0, 0)) + moved_line = translate_shape(line, (0, 3, 0)) ``` diff --git a/docs/api/union_rsolid.md b/docs/api/union_rsolid.md index b7361f56..1dbd73a7 100644 --- a/docs/api/union_rsolid.md +++ b/docs/api/union_rsolid.md @@ -23,7 +23,7 @@ def union_rsolid(solid1: Solid, solid2: Solid) -> Solid - **类型**: `Solid` - **说明**: 第二个参与运算的实体对象 -## 返回值 +### 返回值 Solid: 两个实体的并集结果,包含两个实体的所有体积 @@ -34,17 +34,17 @@ Solid: 两个实体的并集结果,包含两个实体的所有体积 ## API使用例子 ```python ->>> # 创建两个重叠的立方体 ->>> box1 = make_box_rsolid(2, 2, 2, (0, 0, 0)) ->>> box2 = make_box_rsolid(2, 2, 2, (1, 0, 0)) + # 创建两个重叠的立方体 + box1 = make_box_rsolid(2, 2, 2, (0, 0, 0)) + box2 = make_box_rsolid(2, 2, 2, (1, 0, 0)) ->>> # 计算并集 ->>> union_result = union_rsolid(box1, box2) + # 计算并集 + union_result = union_rsolid(box1, box2) ->>> # 结果是一个组合的形状,体积小于两个立方体体积之和 + # 结果是一个组合的形状,体积小于两个立方体体积之和 ->>> # 圆柱和立方体的并集 ->>> cylinder = make_cylinder_rsolid(1.0, 3.0) ->>> box = make_box_rsolid(1, 1, 1, (0, 0, 1)) ->>> combined = union_rsolid(cylinder, box) + # 圆柱和立方体的并集 + cylinder = make_cylinder_rsolid(1.0, 3.0) + box = make_box_rsolid(1, 1, 1, (0, 0, 1)) + combined = union_rsolid(cylinder, box) ``` diff --git a/pyproject.toml b/pyproject.toml index daf905b7..7f3091c2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,4 +44,8 @@ requires = ["hatchling"] build-backend = "hatchling.build" [dependency-groups] -dev = ["twine>=6.1.0", "pytest"] +dev = [ + "twine>=6.1.0", + "pytest", + "ragflow-sdk>=0.19.1", +] diff --git a/scripts/README_ragflow_sync.md b/scripts/README_ragflow_sync.md new file mode 100644 index 00000000..47606643 --- /dev/null +++ b/scripts/README_ragflow_sync.md @@ -0,0 +1,140 @@ +# RAGFlow文档同步脚本使用说明 + +## 简介 + +这个脚本用于将SimpleCADAPI的文档自动同步到RAGFlow数据库。脚本会: + +1. 检查是否存在名为"SimpleCADAPI"的数据集,如果不存在则创建 +2. 扫描本地文档目录,检查文档是否有变更 +3. 对于有变更的文档,删除旧版本并创建新版本 +4. 按照二级标题(##)为单位切分文档为chunks +5. 为每个chunk提取关键词以提高搜索效果 + +## 安装依赖 + +```bash +pip install ragflow-sdk +``` + +## 环境变量设置 + +在运行脚本之前,需要设置以下环境变量: + +```bash +export RAGFLOW_API_KEY="your_ragflow_api_key" +export RAGFLOW_BASE_URL="http://your-ragflow-server:9380" # 可选,默认为localhost:9380 +``` + +## 使用方法 + +### 1. 基本使用 + +```bash +cd /Users/lildino/Project/SimpleCADAPI +python scripts/ragflow_sync.py +``` + +### 2. 检查脚本是否可执行 + +```bash +chmod +x scripts/ragflow_sync.py +./scripts/ragflow_sync.py +``` + +## 脚本功能说明 + +### 文档变更检测 + +- 脚本会计算每个文档的MD5哈希值 +- 与上次同步时的哈希值比较,只处理有变更的文档 +- 哈希值缓存在 `scripts/ragflow_cache.json` 文件中 + +### 分块策略 + +脚本按照以下策略切分文档: + +1. **按二级标题切分**:以 `## ` 开头的行作为分块边界 +2. **保留标题**:每个chunk包含其对应的标题 +3. **关键词提取**:自动提取以下关键词: + - 标题内容 + - 代码块中的函数名 + - API参数名(粗体标记) + - 其他重要术语 + +### 错误处理 + +- 如果文档上传失败,会显示错误信息但不中断整个同步过程 +- 网络错误会有重试机制(通过time.sleep实现) + +## 示例输出 + +``` +开始同步SimpleCADAPI文档到RAGFlow... +找到已存在的数据集: SimpleCADAPI +找到 45 个markdown文件 +跳过未变化的文件: api/README.md +处理文件: api/chamfer_rsolid.md + 分割为 6 个块 + 处理文档: api/chamfer_rsolid.md + 删除现有文档: api/chamfer_rsolid.md + 创建新文档: api/chamfer_rsolid.md + 添加 6 个分块 + 添加分块: API定义 + 添加分块: API作用 + 添加分块: API参数说明 + 添加分块: 返回值 + 添加分块: 异常 + 添加分块: API使用例子 + ✓ 完成处理: api/chamfer_rsolid.md + +同步完成! 共更新了 12 个文档 +数据集 'SimpleCADAPI' 现有 45 个文档,276 个分块 +``` + +## 配置选项 + +在脚本的main函数中,你可以修改以下配置: + +```python +# 数据集名称 +DATASET_NAME = "SimpleCADAPI" + +# RAGFlow服务器地址 +BASE_URL = os.getenv("RAGFLOW_BASE_URL", "http://localhost:9380") +``` + +## 故障排除 + +### 1. 连接错误 +- 检查RAGFlow服务器是否运行 +- 验证BASE_URL是否正确 +- 确认网络连接 + +### 2. 认证错误 +- 检查API_KEY是否正确 +- 确认API密钥有足够权限 + +### 3. 文档上传失败 +- 检查文档格式是否为有效的markdown +- 确认文档大小不超过限制 +- 查看详细错误信息 + +### 4. 分块问题 +- 检查markdown文档是否有正确的二级标题格式 +- 确认文档编码为UTF-8 + +## 定期同步 + +可以设置定时任务定期运行同步: + +```bash +# 添加到crontab,每小时同步一次 +0 * * * * cd /Users/lildino/Project/SimpleCADAPI && python scripts/ragflow_sync.py >> /var/log/ragflow_sync.log 2>&1 +``` + +## 注意事项 + +1. 首次运行会处理所有文档,可能需要较长时间 +2. 脚本会自动处理重复文档,删除旧版本 +3. 建议在非高峰时间运行,避免影响RAGFlow服务性能 +4. 定期备份ragflow_cache.json文件,避免重复处理未变更的文档 diff --git a/scripts/auto_docs_gen.py b/scripts/auto_docs_gen.py index 25d9646f..89341b2b 100644 --- a/scripts/auto_docs_gen.py +++ b/scripts/auto_docs_gen.py @@ -238,7 +238,7 @@ class APIDocumentGenerator: for line in content: # 检测新的例子开始(以注释开始) - if line.startswith('>>> #'): + if line.startswith(' #'): # 保存之前的例子 if current_example: examples.append('\n'.join(current_example)) @@ -246,14 +246,14 @@ class APIDocumentGenerator: # 开始新的例子 current_example.append(line) in_example_block = True - elif line.startswith('>>> ') or line.startswith('... '): + elif line.startswith(' ') or line.startswith('... '): # 继续当前例子 current_example.append(line) in_example_block = True elif line.strip() == '' and in_example_block: # 空行,但在例子块中 current_example.append(line) - elif line.strip() != '' and not line.startswith('>>> ') and not line.startswith('... '): + elif line.strip() != '' and not line.startswith(' ') and not line.startswith('... '): # 非代码行,可能是例子结束 if in_example_block and current_example: examples.append('\n'.join(current_example)) @@ -318,7 +318,7 @@ class APIDocumentGenerator: # 4. 返回值说明 if parsed_doc['returns']: - md_content.append("## 返回值") + md_content.append("### 返回值") md_content.append("") md_content.append(parsed_doc['returns']) md_content.append("") diff --git a/scripts/ragflow_cache.json b/scripts/ragflow_cache.json new file mode 100644 index 00000000..aca156c9 --- /dev/null +++ b/scripts/ragflow_cache.json @@ -0,0 +1,58 @@ +{ + "core/simple_workplane.md": "a756665d361ca4438590a851d50f75d4", + "core/wire.md": "3fb73fceb0d054993e7c31cab62485dd", + "core/compound.md": "1addc5e62a53ced9c2576674e15c6434", + "core/coordinate_system.md": "2701a83a21964df8832365784fe9e654", + "core/face.md": "9e10a50b356f2e461d050ab838f2cf0e", + "core/README.md": "f499a554aaf71127231bbe101c11f5db", + "core/edge.md": "bbdadf5d3832e8440aea4a0547e8c26c", + "core/solid.md": "d710b2d66e061f090089aa5001b3383f", + "core/tagged_mixin.md": "bb79f5e98598644d347197333cf00aa8", + "core/vertex.md": "57173f15d6caed1d2e94685dda9e7a0a", + "core/shell.md": "f6e47c51ebb3301a4fe4f05ab90b2e6a", + "api/make_helix_rwire.md": "e43399a74ddbb3853645f26b3e371743", + "api/select_edges_by_tag.md": "c39d494f101f18c86c0dd658594e373a", + "api/make_line_redge.md": "833f57f29de7f8a67e448ba287d93eb9", + "api/extrude_rsolid.md": "18c7b7126c3eb4b35a3bb024a1a04b10", + "api/make_angle_arc_redge.md": "48bb4637bc37544eb4ed77ad0dfa584b", + "api/make_three_point_arc_rwire.md": "3437db70dbbeb918e9113ecf8aaadf4d", + "api/set_tag.md": "bbafc2fc0ebc9bf50a7a955a1232c886", + "api/mirror_shape.md": "47565935d776b9ed323fcc0ea22a4eec", + "api/export_stl.md": "9fb433ca255f6dfb7e0299c892dd3e1a", + "api/radial_pattern_rsolidlist.md": "8632b17a93289a086ee0a8d3cbbcecac", + "api/make_spline_rwire.md": "c382198f5692c2c2e6e2cc9cd878afc9", + "api/cut_rsolid.md": "61b006b60ddea9629b7c38413b8161ef", + "api/sweep_rsolid.md": "2fcd04f97e1d41d98ae5c9ec89da15d0", + "api/select_faces_by_tag.md": "f50ab77854a324c78f5599921214f5c8", + "api/make_box_rsolid.md": "1468e714ab844bb05e4b4a54506d31d6", + "api/shell_rsolid.md": "672b78d80f1405b020f01768deab8cc5", + "api/rotate_shape.md": "2d1f03a132536c3fc5c03c81436842c4", + "api/make_segment_redge.md": "13e029efb24730f0246a70cc7e923b7d", + "api/make_circle_redge.md": "13962459fcbcafd16f86cd7c715d8dd5", + "api/intersect_rsolid.md": "5bf854c65f2bdf2e04fea0f6f06683aa", + "api/README.md": "3ff61b40ca25a56e47b7bc3be5e647f1", + "api/make_three_point_arc_redge.md": "e81466ce44be39d6fa793183c726e611", + "api/make_sphere_rsolid.md": "0e15f6781ee8bc25d8616799f8dde60c", + "api/make_helix_redge.md": "2b6c7046bf02ff3ee5a156eda83f6a47", + "api/make_rectangle_rface.md": "9d5efdd2a2cda55e7546c866d289e144", + "api/make_circle_rface.md": "379a65c468904375afb3c2f3c5c7286f", + "api/make_wire_from_edges_rwire.md": "98dc5dc44fd95df5f7a575d00f97a723", + "api/make_face_from_wire_rface.md": "dafe16a8b7b2c6c3e964b8ad41198b1a", + "api/helical_sweep_rsolid.md": "86bf77ef33baa111feca50494f84db69", + "api/make_angle_arc_rwire.md": "519172b7030477e2ffa6618b040ff3f6", + "api/fillet_rsolid.md": "d03132dbcf43940ed17766ce019753a0", + "api/revolve_rsolid.md": "189b6a9a17e6bfa14067cb494ff0c792", + "api/union_rsolid.md": "7e41af71b5f7437e90b41a7ce4e316db", + "api/make_polyline_rwire.md": "39c199f4e18810b25f43cef1c1d4900e", + "api/export_step.md": "996abe2126154543543eecbb0378b6f2", + "api/make_rectangle_rwire.md": "29d11c07c34aba47d372807b9ddb8fb5", + "api/translate_shape.md": "c0e8538012de103fd9e6ee4a84e3f1fe", + "api/make_segment_rwire.md": "a5223516a603684d1a238479db6e99dd", + "api/make_circle_rwire.md": "ef085c9c2e8654b05b48144a384a8be8", + "api/loft_rsolid.md": "ab16726e1fb278f28eb14975dde0b9cf", + "api/chamfer_rsolid.md": "0db670661096de54cd6cf101330f05f8", + "api/make_spline_redge.md": "62e71288e4e21345b40561b0b1a52ba9", + "api/make_point_rvertex.md": "651a93d3fff692d934f54a4dfd38bbea", + "api/linear_pattern_rsolidlist.md": "0a480aa11e3dc29d68fb045829b82f26", + "api/make_cylinder_rsolid.md": "51ec920d0eb7ea1dba36a470d966b13d" +} \ No newline at end of file diff --git a/scripts/ragflow_env_example.sh b/scripts/ragflow_env_example.sh new file mode 100755 index 00000000..e63e0317 --- /dev/null +++ b/scripts/ragflow_env_example.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# RAGFlow同步脚本环境配置示例 +# 复制此文件为 .env 并根据实际情况修改 + +# RAGFlow API密钥 (必须设置) +export RAGFLOW_API_KEY="ragflow-c3YzI1YTk0NTY0ODExZjBiNDZjYmExNm" + +# RAGFlow服务器地址 (可选,默认为localhost:9380) +export RAGFLOW_BASE_URL="http://localhost:9380" + +# 数据集名称 (在脚本中可修改) +# DATASET_NAME="SimpleCADAPI" + +echo "RAGFlow环境变量已设置" +echo "API Key: ${RAGFLOW_API_KEY:0:10}..." +echo "Base URL: $RAGFLOW_BASE_URL" diff --git a/scripts/ragflow_sync.py b/scripts/ragflow_sync.py new file mode 100755 index 00000000..3331ab9a --- /dev/null +++ b/scripts/ragflow_sync.py @@ -0,0 +1,507 @@ +#!/usr/bin/env python3 +""" +RAGFlow数据库同步脚本 +自动同步SimpleCADAPI文档到RAGFlow数据库 +""" + +import os +import hashlib +import json +import time +from pathlib import Path +from typing import Dict, List, Optional, Tuple, Any +from datetime import datetime +import re + +from ragflow_sdk import RAGFlow, Document, Chunk, DataSet + +class SimpleCADAPIRAGFlowSync: + def __init__(self, api_key: str, base_url: str, dataset_name: str = "SimpleCADAPI"): + """ + 初始化RAGFlow同步器 + + Args: + api_key: RAGFlow API密钥 + base_url: RAGFlow服务器地址 + dataset_name: 数据集名称 + """ + self.api_key = api_key + self.base_url = base_url + self.dataset_name = dataset_name + self.rag_client = RAGFlow(api_key=api_key, base_url=base_url) + self.dataset: Optional[DataSet] = None + self.docs_dir = Path(__file__).parent.parent / "docs" + self.cache_file = Path(__file__).parent / "ragflow_cache.json" + self.file_hashes = self._load_cache() + + def _load_cache(self) -> Dict[str, str]: + """加载文件哈希缓存""" + if self.cache_file.exists(): + try: + with open(self.cache_file, 'r', encoding='utf-8') as f: + return json.load(f) + except: + return {} + return {} + + def _save_cache(self): + """保存文件哈希缓存""" + with open(self.cache_file, 'w', encoding='utf-8') as f: + json.dump(self.file_hashes, f, indent=2, ensure_ascii=False) + + def _get_file_hash(self, filepath: Path) -> str: + """获取文件的MD5哈希值""" + with open(filepath, 'rb') as f: + return hashlib.md5(f.read()).hexdigest() + + def _ensure_dataset(self): + """确保数据集存在,如果不存在则创建""" + try: + # 获取所有数据集 + print("获取数据集列表...") + all_datasets = self.rag_client.list_datasets() + + # 查找匹配的数据集 + matching_datasets = [d for d in all_datasets if d.name == self.dataset_name] + + if matching_datasets: + self.dataset = matching_datasets[0] + print(f"找到已存在的数据集: {self.dataset_name}") + else: + # 创建新数据集 + print(f"创建新数据集: {self.dataset_name}") + self.dataset = self.rag_client.create_dataset( + name=self.dataset_name, + description="SimpleCADAPI文档数据集,包含所有API和核心概念文档", + chunk_method="manual" # 使用手动分块模式 + ) + print(f"成功创建数据集: {self.dataset_name}") + + except Exception as e: + print(f"处理数据集时出错: {e}") + # 尝试直接创建数据集 + print(f"尝试直接创建数据集: {self.dataset_name}") + try: + self.dataset = self.rag_client.create_dataset( + name=self.dataset_name, + description="SimpleCADAPI文档数据集,包含所有API和核心概念文档", + chunk_method="manual" # 使用手动分块模式 + ) + print(f"成功创建数据集: {self.dataset_name}") + except Exception as create_error: + print(f"创建数据集失败: {create_error}") + raise + + def _split_markdown_by_h2(self, content: str, filename: str) -> List[Dict[str, str]]: + """ + 按照二级标题(##)分割markdown文档 + + Args: + content: markdown文档内容 + filename: 文件名 + + Returns: + 包含分块信息的字典列表 + """ + chunks = [] + + # 确保输入参数不为 None + if content is None: + content = '' + if filename is None: + filename = 'unknown' + + lines = content.split('\n') + current_chunk = [] + current_title = "" + + for line in lines: + # 检查是否为二级标题 + if line.startswith('## '): + # 如果已有内容,保存上一个块 + if current_chunk: + chunk_content = '\n'.join(current_chunk).strip() + if chunk_content: + chunks.append({ + 'title': current_title or f"Section {len(chunks) + 1}", + 'content': chunk_content, + 'filename': filename + }) + + # 开始新块 + current_title = line[3:].strip() # 去掉'## ' + current_chunk = [line] + else: + current_chunk.append(line) + + # 添加最后一个块 + if current_chunk: + chunk_content = '\n'.join(current_chunk).strip() + if chunk_content: + chunks.append({ + 'title': current_title or f"Section {len(chunks) + 1}", + 'content': chunk_content, + 'filename': filename + }) + + # 如果没有找到二级标题,将整个文档作为一个块 + if not chunks: + chunks.append({ + 'title': filename, + 'content': content.strip(), + 'filename': filename + }) + + return chunks + + def _get_all_markdown_files(self) -> List[Path]: + """获取所有markdown文件""" + md_files = [] + for pattern in ["**/*.md"]: + md_files.extend(self.docs_dir.glob(pattern)) + return md_files + + def _find_document_by_name(self, doc_name: str) -> Optional[Document]: + """根据文档名称查找文档""" + assert self.dataset is not None, "数据集未初始化,请先调用 _ensure_dataset()" + docs = self.dataset.list_documents() + for doc in docs: + if doc.name == doc_name: + return doc + return None + + def _update_document_with_chunks(self, doc_name: str, chunks: List[Dict[str, str]]): + """使用分块更新文档""" + assert self.dataset is not None, "数据集未初始化,请先调用 _ensure_dataset()" + print(f" 处理文档: {doc_name}") + + # 查找现有文档 + existing_doc: Optional[Document] = self._find_document_by_name(doc_name) + + if existing_doc: + print(f" 删除现有文档: {doc_name}") + # 删除现有文档 + self.dataset.delete_documents([existing_doc.id]) + time.sleep(1) # 等待删除完成 + + # 创建新文档(使用空内容) + print(f" 创建新文档: {doc_name}") + self.dataset.upload_documents([{ + "display_name": doc_name, + "blob": b"# Document Content\n\nThis document contains API documentation." + }]) + + # 等待文档创建完成 + time.sleep(2) + + # 获取新创建的文档 + new_doc: Optional[Document] = self._find_document_by_name(doc_name) + if not new_doc: + print(f" 错误: 无法找到新创建的文档 {doc_name}") + return + + # 删除默认的chunks + existing_chunks = new_doc.list_chunks() + if existing_chunks: + chunk_ids = [chunk.id for chunk in existing_chunks] + new_doc.delete_chunks(chunk_ids) + time.sleep(1) + + # 添加新的chunks + print(f" 添加 {len(chunks)} 个分块") + for i, chunk in enumerate(chunks): + title = chunk.get('title', '') or '' + content = chunk.get('content', '') or '' + + # 确保 title 和 content 不为 None + if title is None: + title = '' + if content is None: + content = '' + + # 创建分块标题和内容 + chunk_title = f"{title}" if title else f"Section {i+1}" + full_content = f"# {chunk_title}\n\n{content}" + + # 提取重要关键词 + keywords = self._extract_keywords(content, chunk_title, doc_name) + + # 确保 keywords 不为 None 且不包含 None 值 + if keywords is None: + keywords = [] + keywords = [k for k in keywords if k is not None and k.strip()] + + try: + # 简化内容格式,避免特殊字符问题 + clean_content = content.strip() + if not clean_content: + clean_content = f"Empty content for section: {chunk_title}" + + # 创建简单的内容格式 + final_content = f"{chunk_title}\n\n{clean_content}" + + # 确保关键词都是有效的字符串 + clean_keywords = [] + for kw in keywords: + if kw and isinstance(kw, str) and len(kw.strip()) > 0: + clean_keywords.append(kw.strip()) + + # 限制关键词数量和长度 + clean_keywords = clean_keywords[:5] # 只取前5个关键词 + clean_keywords = [kw[:50] for kw in clean_keywords] # 限制每个关键词长度 + + print(f" 添加分块: {chunk_title}") + print(f" 内容长度: {len(final_content)}, 关键词: {clean_keywords}") + + # 使用简单的方法调用 + new_doc.add_chunk( + content=final_content, + important_keywords=clean_keywords + ) + + print(f" ✓ 成功添加分块: {chunk_title}") + time.sleep(0.5) # 避免请求过快 + + except Exception as e: + print(f" ✗ 添加分块失败 {chunk_title}: {e}") + print(f" 错误类型: {type(e).__name__}") + + # 尝试不带关键词的版本 + try: + simple_content = f"{chunk_title}\n\n{content.strip()}" + new_doc.add_chunk(content=simple_content) + print(f" ✓ 成功添加分块(无关键词): {chunk_title}") + except Exception as e2: + print(f" ✗ 无关键词版本也失败: {e2}") + # 继续处理下一个分块 + continue + + def _extract_keywords(self, content: str, title: str, filename: str = '') -> List[str]: + """ + 从内容中提取关键词,优先级策略: + 1. 核心类名/API名(从文件名推断) + 2. 当前二级标题 + 3. 从当前chunk中抽取的内容关键词 + """ + keywords = [] + + # 确保输入参数不为 None + if content is None: + content = '' + if title is None: + title = '' + if filename is None: + filename = '' + + # 1. 从文件名提取核心类名/API名 + core_names = self._extract_core_names_from_filename(filename) + keywords.extend(core_names) + + # 2. 添加当前二级标题作为关键词 + if title and title not in keywords: + keywords.append(title) + + # 3. 从内容中提取关键词 + content_keywords = self._extract_content_keywords(content) + keywords.extend(content_keywords) + + # 清理和去重 + cleaned_keywords = [] + for keyword in keywords: + if keyword is None: + continue + keyword = str(keyword).strip() + if keyword and len(keyword) > 1 and keyword not in cleaned_keywords: + cleaned_keywords.append(keyword) + + return cleaned_keywords[:10] # 限制关键词数量 + + def _extract_core_names_from_filename(self, filename: str) -> List[str]: + """从文件名提取核心类名和API名""" + core_names = [] + + if not filename: + return core_names + + # 从文件路径提取信息 + path_parts = filename.split('/') + + # 获取文件名(不含扩展名) + file_base = path_parts[-1].replace('.md', '') if path_parts else '' + + # API文件名模式匹配 + api_patterns = [ + r'make_(\w+)_r(\w+)', # make_box_rsolid -> box, solid + r'(\w+)_r(\w+)', # extrude_rsolid -> extrude, solid + r'(\w+)_(\w+)', # simple_workplane -> simple, workplane + ] + + for pattern in api_patterns: + matches = re.findall(pattern, file_base) + for match in matches: + core_names.extend([part for part in match if part]) + + # 直接从文件名提取关键词 + if not core_names: + # 分割文件名中的单词 + words = re.split(r'[_\-\s]+', file_base) + core_names.extend([word for word in words if len(word) > 2]) + + # 添加目录信息作为上下文 + if len(path_parts) > 1: + directory = path_parts[-2] # 获取父目录名 + if directory in ['api', 'core']: + core_names.append(directory) + + return core_names[:3] # 限制核心名称数量 + + def _extract_content_keywords(self, content: str) -> List[str]: + """从内容中提取关键词""" + keywords = [] + + # 1. 提取类名和函数名 + try: + # 提取类定义 + class_matches = re.findall(r'class\s+(\w+)', content) + keywords.extend(class_matches) + + # 提取函数定义 + func_matches = re.findall(r'def\s+(\w+)', content) + keywords.extend(func_matches) + + # 提取代码块中的函数调用 + code_blocks = re.findall(r'```python\n(.*?)\n```', content, re.DOTALL) + for block in code_blocks: + if block: + # 提取函数调用 + call_matches = re.findall(r'(\w+)\s*\(', block) + keywords.extend(call_matches) + except Exception: + pass + + # 2. 提取API相关关键词 + api_patterns = [ + r'`(\w+)`', # 代码片段 + r'- \*\*(\w+)\*\*', # 粗体参数 + r'### (.*?)(?=\n|$)', # 三级标题 + r'return\s+(\w+)', # 返回值类型 + r'(\w+)\s*:\s*(\w+)', # 参数类型声明 + r'(\w+)\s*=\s*(\w+)', # 赋值语句 + ] + + for pattern in api_patterns: + try: + matches = re.findall(pattern, content) + if isinstance(matches[0], tuple) if matches else False: + # 处理元组匹配结果 + for match_tuple in matches: + keywords.extend([item for item in match_tuple if item]) + else: + keywords.extend(matches) + except Exception: + pass + + # 3. 提取重要的术语 + important_terms = [ + 'RSolid', 'RFace', 'RWire', 'REdge', 'RVertex', + 'SimpleWorkplane', 'CoordinateSystem', 'Compound', + 'extrude', 'revolve', 'loft', 'sweep', 'fillet', 'chamfer', + 'union', 'cut', 'intersect', 'mirror', 'rotate', 'translate', + 'pattern', 'shell', 'make', 'create', 'build' + ] + + for term in important_terms: + if term.lower() in content.lower(): + keywords.append(term) + + # 4. 提取参数名 + param_matches = re.findall(r'(\w+)\s*:\s*\w+', content) + keywords.extend(param_matches) + + return keywords + + def sync_documents(self): + """同步文档到RAGFlow""" + print("开始同步SimpleCADAPI文档到RAGFlow...") + + # 确保数据集存在 + self._ensure_dataset() + + assert self.dataset is not None, "数据集未初始化,请先调用 _ensure_dataset()" + + # 获取所有markdown文件 + md_files = self._get_all_markdown_files() + print(f"找到 {len(md_files)} 个markdown文件") + + updated_count = 0 + + for md_file in md_files: + try: + # 计算文件相对路径作为文档名 + relative_path = md_file.relative_to(self.docs_dir) + doc_name = str(relative_path) + + # 检查文件是否有变化 + current_hash = self._get_file_hash(md_file) + cached_hash = self.file_hashes.get(doc_name) + + if current_hash == cached_hash: + print(f"跳过未变化的文件: {doc_name}") + continue + + print(f"处理文件: {doc_name}") + + # 读取文件内容 + with open(md_file, 'r', encoding='utf-8') as f: + content = f.read() + + # 按二级标题分割 + chunks = self._split_markdown_by_h2(content, doc_name) + print(f" 分割为 {len(chunks)} 个块") + + for i, chunk in enumerate(chunks): + print(f" 块 {i+1}: {chunk['title'][:30]}... ({len(chunk['content'])} 字符)") + + # 更新文档 + self._update_document_with_chunks(doc_name, chunks) + + # 更新缓存 + self.file_hashes[doc_name] = current_hash + updated_count += 1 + + print(f" ✓ 完成处理: {doc_name}") + + except Exception as e: + print(f" ✗ 处理文件失败 {md_file}: {e}") + + # 保存缓存 + self._save_cache() + + print(f"\n同步完成! 共更新了 {updated_count} 个文档") + + # 显示数据集信息 + docs = self.dataset.list_documents() + total_chunks = sum(len(doc.list_chunks()) for doc in docs) + print(f"数据集 '{self.dataset_name}' 现有 {len(docs)} 个文档,{total_chunks} 个分块") + +def main(): + """主函数""" + # 配置参数 + API_KEY = os.getenv("RAGFLOW_API_KEY", "") + BASE_URL = os.getenv("RAGFLOW_BASE_URL", "http://localhost:9380") + DATASET_NAME = "SimpleCADAPI" + + if not API_KEY: + print("请设置环境变量 RAGFLOW_API_KEY") + print("例如: export RAGFLOW_API_KEY='your_api_key_here'") + exit(1) + + print(f"RAGFlow服务器: {BASE_URL}") + print(f"数据集名称: {DATASET_NAME}") + + # 创建同步器并运行 + syncer = SimpleCADAPIRAGFlowSync(API_KEY, BASE_URL, DATASET_NAME) + syncer.sync_documents() + +if __name__ == "__main__": + main() diff --git a/scripts/test_ragflow_connection.py b/scripts/test_ragflow_connection.py new file mode 100755 index 00000000..9de9858b --- /dev/null +++ b/scripts/test_ragflow_connection.py @@ -0,0 +1,110 @@ +#!/usr/bin/env python3 +""" +RAGFlow连接测试脚本 +用于验证RAGFlow连接和API密钥是否正常工作 +""" + +import os +import sys +from pathlib import Path + +# 添加脚本目录到Python路径 +sys.path.insert(0, str(Path(__file__).parent)) + +try: + from ragflow_sdk import RAGFlow +except ImportError: + print("❌ 错误: 未安装ragflow-sdk") + print("请运行: pip install ragflow-sdk") + exit(1) + +def test_ragflow_connection(): + """测试RAGFlow连接""" + + # 获取环境变量 + API_KEY = os.getenv("RAGFLOW_API_KEY", "") + BASE_URL = os.getenv("RAGFLOW_BASE_URL", "http://localhost:9380") + + if not API_KEY: + print("❌ 错误: 未设置RAGFLOW_API_KEY环境变量") + print("请运行: export RAGFLOW_API_KEY='your_api_key_here'") + return False + + print(f"🔧 测试RAGFlow连接...") + print(f" 服务器地址: {BASE_URL}") + print(f" API密钥: {API_KEY[:10]}...") + + try: + # 创建RAGFlow客户端 + rag_client = RAGFlow(api_key=API_KEY, base_url=BASE_URL) + + # 测试连接 - 尝试获取数据集列表 + print("📋 获取数据集列表...") + datasets = rag_client.list_datasets() + + print(f"✅ 连接成功!") + print(f" 找到 {len(datasets)} 个数据集") + + # 显示现有数据集 + if datasets: + print("\n📚 现有数据集:") + for i, dataset in enumerate(datasets, 1): + print(f" {i}. {dataset.name}") + + # 检查是否存在SimpleCADAPI数据集 + simpleapi_datasets = [d for d in datasets if d.name == "SimpleCADAPI"] + if simpleapi_datasets: + print(f"\n🎯 找到SimpleCADAPI数据集") + dataset = simpleapi_datasets[0] + + # 获取文档数量 + try: + docs = dataset.list_documents() + print(f" 包含 {len(docs)} 个文档") + + # 统计总分块数 + total_chunks = 0 + for doc in docs[:3]: # 只检查前3个文档以节省时间 + try: + chunks = doc.list_chunks() + total_chunks += len(chunks) + except: + pass + + if total_chunks > 0: + print(f" 前3个文档包含 {total_chunks} 个分块") + + except Exception as e: + print(f" ⚠️ 获取文档信息失败: {e}") + else: + print(f"\n📝 未找到SimpleCADAPI数据集,首次运行同步脚本时会自动创建") + + return True + + except Exception as e: + print(f"❌ 连接失败: {e}") + print("\n💡 可能的解决方案:") + print(" 1. 检查RAGFlow服务器是否正在运行") + print(" 2. 验证BASE_URL是否正确") + print(" 3. 确认API_KEY是否有效") + print(" 4. 检查网络连接") + return False + +def main(): + """主函数""" + print("🚀 RAGFlow连接测试") + print("=" * 50) + + success = test_ragflow_connection() + + print("\n" + "=" * 50) + if success: + print("✅ 测试通过! 可以运行同步脚本了") + print("运行命令: python scripts/ragflow_sync.py") + else: + print("❌ 测试失败! 请检查配置后重试") + + return 0 if success else 1 + +if __name__ == "__main__": + exit(main()) diff --git a/src/simplecadapi/operations.py b/src/simplecadapi/operations.py index 6f2fc7c5..fd337b04 100644 --- a/src/simplecadapi/operations.py +++ b/src/simplecadapi/operations.py @@ -40,14 +40,14 @@ def make_point_rvertex(x: float, y: float, z: float) -> Vertex: 圆弧的控制点等。支持当前坐标系变换。 Example: - >>> # 创建原点 - >>> origin = make_point_rvertex(0, 0, 0) - >>> - >>> # 创建指定坐标的点 - >>> point = make_point_rvertex(1.5, 2.0, 3.0) - >>> - >>> # 在工作平面中创建点 - >>> with SimpleWorkplane((1, 1, 1)): + # 创建原点 + origin = make_point_rvertex(0, 0, 0) + + # 创建指定坐标的点 + point = make_point_rvertex(1.5, 2.0, 3.0) + + # 在工作平面中创建点 + with SimpleWorkplane((1, 1, 1)): ... local_point = make_point_rvertex(0, 0, 0) # 实际位置为(1, 1, 1) """ try: @@ -78,14 +78,14 @@ def make_line_redge(start: Tuple[float, float, float], 创建草图轮廓、定义路径等。支持当前坐标系变换。 Example: - >>> # 创建水平线段 - >>> line = make_line_redge((0, 0, 0), (5, 0, 0)) - >>> - >>> # 创建三维空间中的线段 - >>> line_3d = make_line_redge((1, 1, 1), (3, 2, 4)) - >>> - >>> # 在工作平面中创建线段 - >>> with SimpleWorkplane((0, 0, 1)): + # 创建水平线段 + line = make_line_redge((0, 0, 0), (5, 0, 0)) + + # 创建三维空间中的线段 + line_3d = make_line_redge((1, 1, 1), (3, 2, 4)) + + # 在工作平面中创建线段 + with SimpleWorkplane((0, 0, 1)): ... elevated_line = make_line_redge((0, 0, 0), (2, 2, 0)) """ try: @@ -118,11 +118,11 @@ def make_segment_redge(start: Tuple[float, float, float], 直线段,是构建复杂几何形状的基础元素。 Example: - >>> # 创建垂直线段 - >>> vertical_line = make_segment_redge((0, 0, 0), (0, 0, 5)) - >>> - >>> # 创建对角线段 - >>> diagonal = make_segment_redge((0, 0, 0), (1, 1, 1)) + # 创建垂直线段 + vertical_line = make_segment_redge((0, 0, 0), (0, 0, 5)) + + # 创建对角线段 + diagonal = make_segment_redge((0, 0, 0), (1, 1, 1)) """ return make_line_redge(start, end) @@ -146,11 +146,11 @@ def make_segment_rwire(start: Tuple[float, float, float], 不同,此函数返回的是线对象,可以与其他线对象连接形成复杂路径。 Example: - >>> # 创建基本线段线 - >>> wire = make_segment_rwire((0, 0, 0), (3, 0, 0)) - >>> - >>> # 创建斜线段 - >>> diagonal_wire = make_segment_rwire((0, 0, 0), (2, 2, 0)) + # 创建基本线段线 + wire = make_segment_rwire((0, 0, 0), (3, 0, 0)) + + # 创建斜线段 + diagonal_wire = make_segment_rwire((0, 0, 0), (2, 2, 0)) """ try: edge = make_line_redge(start, end) @@ -182,14 +182,14 @@ def make_circle_redge(center: Tuple[float, float, float], 支持在任意平面内创建圆形。支持当前坐标系变换。 Example: - >>> # 创建XY平面上的圆 - >>> circle = make_circle_redge((0, 0, 0), 2.0) - >>> - >>> # 创建垂直平面上的圆 - >>> vertical_circle = make_circle_redge((0, 0, 0), 1.5, (1, 0, 0)) - >>> - >>> # 创建指定位置的圆 - >>> offset_circle = make_circle_redge((2, 3, 1), 1.0, (0, 0, 1)) + # 创建XY平面上的圆 + circle = make_circle_redge((0, 0, 0), 2.0) + + # 创建垂直平面上的圆 + vertical_circle = make_circle_redge((0, 0, 0), 1.5, (1, 0, 0)) + + # 创建指定位置的圆 + offset_circle = make_circle_redge((2, 3, 1), 1.0, (0, 0, 1)) """ try: if radius <= 0: @@ -230,11 +230,11 @@ def make_circle_rwire(center: Tuple[float, float, float], 此函数返回的是线对象,可以直接用于创建面或进行其他线操作。 Example: - >>> # 创建标准圆形轮廓 - >>> circle_wire = make_circle_rwire((0, 0, 0), 3.0) - >>> - >>> # 创建小圆轮廓 - >>> small_circle = make_circle_rwire((1, 1, 0), 0.5) + # 创建标准圆形轮廓 + circle_wire = make_circle_rwire((0, 0, 0), 3.0) + + # 创建小圆轮廓 + small_circle = make_circle_rwire((1, 1, 0), 0.5) """ try: edge = make_circle_redge(center, radius, normal) @@ -266,13 +266,13 @@ def make_circle_rface(center: Tuple[float, float, float], 圆柱体、圆锥体等三维几何体。面积等于πr²。 Example: - >>> # 创建标准圆形面 - >>> circle_face = make_circle_rface((0, 0, 0), 2.0) - >>> area = circle_face.get_area() # 面积为π×2²≈12.57 - >>> - >>> # 创建用于拉伸的圆形截面 - >>> profile = make_circle_rface((0, 0, 0), 1.0) - >>> cylinder = extrude_rsolid(profile, (0, 0, 1), 5.0) + # 创建标准圆形面 + circle_face = make_circle_rface((0, 0, 0), 2.0) + area = circle_face.get_area() # 面积为π×2²≈12.57 + + # 创建用于拉伸的圆形截面 + profile = make_circle_rface((0, 0, 0), 1.0) + cylinder = extrude_rsolid(profile, (0, 0, 1), 5.0) """ try: wire = make_circle_rwire(center, radius, normal) @@ -306,14 +306,14 @@ def make_rectangle_rwire(width: float, height: float, 创建。可以用于构建复杂的多边形轮廓或作为拉伸的基础轮廓。 Example: - >>> # 创建标准矩形轮廓 - >>> rect = make_rectangle_rwire(4.0, 3.0) - >>> - >>> # 创建偏移的矩形 - >>> offset_rect = make_rectangle_rwire(2.0, 2.0, (1, 1, 0)) - >>> - >>> # 创建垂直平面上的矩形 - >>> vertical_rect = make_rectangle_rwire(3.0, 2.0, (0, 0, 0), (1, 0, 0)) + # 创建标准矩形轮廓 + rect = make_rectangle_rwire(4.0, 3.0) + + # 创建偏移的矩形 + offset_rect = make_rectangle_rwire(2.0, 2.0, (1, 1, 0)) + + # 创建垂直平面上的矩形 + vertical_rect = make_rectangle_rwire(3.0, 2.0, (0, 0, 0), (1, 0, 0)) """ try: if width <= 0 or height <= 0: @@ -392,13 +392,13 @@ def make_rectangle_rface(width: float, height: float, 立方体、棱柱等三维几何体。面积等于width×height。 Example: - >>> # 创建标准矩形面 - >>> rect_face = make_rectangle_rface(5.0, 3.0) - >>> area = rect_face.get_area() # 面积为5×3=15 - >>> - >>> # 创建用于拉伸的矩形截面 - >>> profile = make_rectangle_rface(2.0, 2.0) - >>> box = extrude_rsolid(profile, (0, 0, 1), 3.0) + # 创建标准矩形面 + rect_face = make_rectangle_rface(5.0, 3.0) + area = rect_face.get_area() # 面积为5×3=15 + + # 创建用于拉伸的矩形截面 + profile = make_rectangle_rface(2.0, 2.0) + box = extrude_rsolid(profile, (0, 0, 1), 3.0) """ try: wire = make_rectangle_rwire(width, height, center, normal) @@ -427,18 +427,18 @@ def make_face_from_wire_rface(wire: Wire, normal: Tuple[float, float, float] = ( 是封闭的,函数会检查面的法向量方向,如果与期望方向相反会发出警告。 Example: - >>> # 从矩形线创建面 - >>> rect_wire = make_rectangle_rwire(3.0, 2.0) - >>> rect_face = make_face_from_wire_rface(rect_wire) - >>> - >>> # 从圆形线创建面 - >>> circle_wire = make_circle_rwire((0, 0, 0), 1.5) - >>> circle_face = make_face_from_wire_rface(circle_wire) - >>> - >>> # 从多边形线创建面 - >>> points = [(0, 0, 0), (2, 0, 0), (2, 2, 0), (0, 2, 0)] - >>> poly_wire = make_polyline_rwire(points, closed=True) - >>> poly_face = make_face_from_wire_rface(poly_wire) + # 从矩形线创建面 + rect_wire = make_rectangle_rwire(3.0, 2.0) + rect_face = make_face_from_wire_rface(rect_wire) + + # 从圆形线创建面 + circle_wire = make_circle_rwire((0, 0, 0), 1.5) + circle_face = make_face_from_wire_rface(circle_wire) + + # 从多边形线创建面 + points = [(0, 0, 0), (2, 0, 0), (2, 2, 0), (0, 2, 0)] + poly_wire = make_polyline_rwire(points, closed=True) + poly_face = make_face_from_wire_rface(poly_wire) """ try: if not isinstance(wire, Wire): @@ -501,15 +501,15 @@ def make_wire_from_edges_rwire(edges: List[Edge]) -> Wire: 能够连接在一起。用于构建复杂的线框结构。 Example: - >>> # 创建L形线 - >>> edge1 = make_line_redge((0, 0, 0), (2, 0, 0)) # 水平线 - >>> edge2 = make_line_redge((2, 0, 0), (2, 2, 0)) # 垂直线 - >>> l_wire = make_wire_from_edges_rwire([edge1, edge2]) - >>> - >>> # 创建包含直线和圆弧的复杂线 - >>> line = make_line_redge((0, 0, 0), (2, 0, 0)) - >>> arc = make_three_point_arc_redge((2, 0, 0), (3, 1, 0), (2, 2, 0)) - >>> complex_wire = make_wire_from_edges_rwire([line, arc]) + # 创建L形线 + edge1 = make_line_redge((0, 0, 0), (2, 0, 0)) # 水平线 + edge2 = make_line_redge((2, 0, 0), (2, 2, 0)) # 垂直线 + l_wire = make_wire_from_edges_rwire([edge1, edge2]) + + # 创建包含直线和圆弧的复杂线 + line = make_line_redge((0, 0, 0), (2, 0, 0)) + arc = make_three_point_arc_redge((2, 0, 0), (3, 1, 0), (2, 2, 0)) + complex_wire = make_wire_from_edges_rwire([line, arc]) """ try: if not edges: @@ -544,19 +544,19 @@ def make_box_rsolid(width: float, height: float, depth: float, 体积等于width×height×depth。 Example: - >>> # 创建标准单位立方体 - >>> unit_cube = make_box_rsolid(1.0, 1.0, 1.0) - >>> volume = unit_cube.get_volume() # 体积为1 - >>> - >>> # 创建矩形立方体 - >>> rect_box = make_box_rsolid(4.0, 2.0, 3.0) - >>> - >>> # 创建偏移的立方体 - >>> offset_box = make_box_rsolid(2.0, 2.0, 2.0, (1, 1, 1)) - >>> - >>> # 获取立方体的面进行后续操作 - >>> faces = unit_cube.get_faces() - >>> top_faces = [f for f in faces if f.has_tag("top")] + # 创建标准单位立方体 + unit_cube = make_box_rsolid(1.0, 1.0, 1.0) + volume = unit_cube.get_volume() # 体积为1 + + # 创建矩形立方体 + rect_box = make_box_rsolid(4.0, 2.0, 3.0) + + # 创建偏移的立方体 + offset_box = make_box_rsolid(2.0, 2.0, 2.0, (1, 1, 1)) + + # 获取立方体的面进行后续操作 + faces = unit_cube.get_faces() + top_faces = [f for f in faces if f.has_tag("top")] """ try: if width <= 0 or height <= 0 or depth <= 0: @@ -601,19 +601,19 @@ def make_cylinder_rsolid(radius: float, height: float, (top、bottom、cylindrical),便于后续的面选择操作。体积等于πr²h。 Example: - >>> # 创建标准圆柱体 - >>> cylinder = make_cylinder_rsolid(2.0, 5.0) - >>> volume = cylinder.get_volume() # 体积为π×2²×5≈62.83 - >>> - >>> # 创建水平圆柱体 - >>> horizontal_cyl = make_cylinder_rsolid(1.0, 4.0, (0, 0, 0), (1, 0, 0)) - >>> - >>> # 创建偏移的圆柱体 - >>> offset_cyl = make_cylinder_rsolid(1.5, 3.0, (2, 2, 0)) - >>> - >>> # 获取圆柱体的面进行后续操作 - >>> faces = cylinder.get_faces() - >>> top_faces = [f for f in faces if f.has_tag("top")] + # 创建标准圆柱体 + cylinder = make_cylinder_rsolid(2.0, 5.0) + volume = cylinder.get_volume() # 体积为π×2²×5≈62.83 + + # 创建水平圆柱体 + horizontal_cyl = make_cylinder_rsolid(1.0, 4.0, (0, 0, 0), (1, 0, 0)) + + # 创建偏移的圆柱体 + offset_cyl = make_cylinder_rsolid(1.5, 3.0, (2, 2, 0)) + + # 获取圆柱体的面进行后续操作 + faces = cylinder.get_faces() + top_faces = [f for f in faces if f.has_tag("top")] """ try: if radius <= 0 or height <= 0: @@ -657,19 +657,19 @@ def make_sphere_rsolid(radius: float, 便于后续的面选择操作。体积等于(4/3)πr³。 Example: - >>> # 创建标准单位球体 - >>> unit_sphere = make_sphere_rsolid(1.0) - >>> volume = unit_sphere.get_volume() # 体积为(4/3)π≈4.19 - >>> - >>> # 创建大球体 - >>> large_sphere = make_sphere_rsolid(3.0) - >>> - >>> # 创建偏移的球体 - >>> offset_sphere = make_sphere_rsolid(2.0, (1, 1, 1)) - >>> - >>> # 获取球体的面进行后续操作 - >>> faces = unit_sphere.get_faces() - >>> surface_faces = [f for f in faces if f.has_tag("surface")] + # 创建标准单位球体 + unit_sphere = make_sphere_rsolid(1.0) + volume = unit_sphere.get_volume() # 体积为(4/3)π≈4.19 + + # 创建大球体 + large_sphere = make_sphere_rsolid(3.0) + + # 创建偏移的球体 + offset_sphere = make_sphere_rsolid(2.0, (1, 1, 1)) + + # 获取球体的面进行后续操作 + faces = unit_sphere.get_faces() + surface_faces = [f for f in faces if f.has_tag("surface")] """ try: if radius <= 0: @@ -716,14 +716,14 @@ def make_three_point_arc_redge(start: Tuple[float, float, float], 中间点的位置决定了圆弧的弯曲程度和方向。 Example: - >>> # 创建90度圆弧 - >>> arc = make_three_point_arc_redge((0, 0, 0), (1, 1, 0), (2, 0, 0)) - >>> - >>> # 创建大圆弧 - >>> large_arc = make_three_point_arc_redge((0, 0, 0), (0, 3, 0), (0, 6, 0)) - >>> - >>> # 创建3D圆弧 - >>> arc_3d = make_three_point_arc_redge((0, 0, 0), (1, 1, 1), (2, 0, 2)) + # 创建90度圆弧 + arc = make_three_point_arc_redge((0, 0, 0), (1, 1, 0), (2, 0, 0)) + + # 创建大圆弧 + large_arc = make_three_point_arc_redge((0, 0, 0), (0, 3, 0), (0, 6, 0)) + + # 创建3D圆弧 + arc_3d = make_three_point_arc_redge((0, 0, 0), (1, 1, 1), (2, 0, 2)) """ try: cs = get_current_cs() @@ -763,12 +763,12 @@ def make_three_point_arc_rwire(start: Tuple[float, float, float], 但返回的是线对象,可以与其他线对象连接或用于构建复杂轮廓。 Example: - >>> # 创建圆弧线 - >>> arc_wire = make_three_point_arc_rwire((0, 0, 0), (1, 1, 0), (0, 2, 0)) - >>> - >>> # 与直线连接创建复杂轮廓 - >>> line = make_segment_rwire((0, 2, 0), (3, 2, 0)) - >>> # 然后可以连接arc_wire和line + # 创建圆弧线 + arc_wire = make_three_point_arc_rwire((0, 0, 0), (1, 1, 0), (0, 2, 0)) + + # 与直线连接创建复杂轮廓 + line = make_segment_rwire((0, 2, 0), (3, 2, 0)) + # 然后可以连接arc_wire和line """ try: edge = make_three_point_arc_redge(start, middle, end) @@ -804,17 +804,17 @@ def make_angle_arc_redge(center: Tuple[float, float, float], 0度对应X轴正方向,逆时针为正角度。可以创建任意角度范围的圆弧。 Example: - >>> # 创建90度圆弧(从0度到90度) - >>> arc_90 = make_angle_arc_redge((0, 0, 0), 2.0, 0, 90) - >>> - >>> # 创建180度半圆弧 - >>> semicircle = make_angle_arc_redge((0, 0, 0), 1.5, 0, 180) - >>> - >>> # 创建270度圆弧 - >>> arc_270 = make_angle_arc_redge((0, 0, 0), 1.0, 45, 315) - >>> - >>> # 创建垂直平面上的圆弧 - >>> vertical_arc = make_angle_arc_redge((0, 0, 0), 1.0, 0, 90, (1, 0, 0)) + # 创建90度圆弧(从0度到90度) + arc_90 = make_angle_arc_redge((0, 0, 0), 2.0, 0, 90) + + # 创建180度半圆弧 + semicircle = make_angle_arc_redge((0, 0, 0), 1.5, 0, 180) + + # 创建270度圆弧 + arc_270 = make_angle_arc_redge((0, 0, 0), 1.0, 45, 315) + + # 创建垂直平面上的圆弧 + vertical_arc = make_angle_arc_redge((0, 0, 0), 1.0, 0, 90, (1, 0, 0)) """ try: if radius <= 0: @@ -891,16 +891,16 @@ def make_angle_arc_rwire(center: Tuple[float, float, float], 可以创建任意角度范围的圆弧线。 Example: - >>> # 创建90度圆弧线(从0度到90度) - >>> arc_90_wire = make_angle_arc_rwire((0, 0, 0), 2.0, 0, 90) - >>> - >>> # 创建180度半圆弧线 - >>> semicircle_wire = make_angle_arc_rwire((0, 0, 0), 1.5, 0, 180) - >>> # 创建270度圆弧线 - >>> arc_270_wire = make_angle_arc_rwire((0, 0, 0), 1.0, 45, 315) - >>> - >>> # 创建垂直平面(YZ,法相指向X轴正方向)上的圆弧线 - >>> vertical_arc_wire = make_angle_arc_rwire((0, 0, 0), 1.0, 0, 90, (1, 0, 0)) + # 创建90度圆弧线(从0度到90度) + arc_90_wire = make_angle_arc_rwire((0, 0, 0), 2.0, 0, 90) + + # 创建180度半圆弧线 + semicircle_wire = make_angle_arc_rwire((0, 0, 0), 1.5, 0, 180) + # 创建270度圆弧线 + arc_270_wire = make_angle_arc_rwire((0, 0, 0), 1.0, 45, 315) + + # 创建垂直平面(YZ,法相指向X轴正方向)上的圆弧线 + vertical_arc_wire = make_angle_arc_rwire((0, 0, 0), 1.0, 0, 90, (1, 0, 0)) """ @@ -933,18 +933,18 @@ def make_spline_redge(points: List[Tuple[float, float, float]], 所有控制点,可选择性地指定每个点的切线方向来控制曲线的形状。 Example: - >>> # 创建简单的样条曲线 - >>> points = [(0, 0, 0), (1, 2, 0), (3, 1, 0), (4, 3, 0)] - >>> spline = make_spline_redge(points) - >>> - >>> # 创建带切线控制的样条曲线 - >>> points = [(0, 0, 0), (2, 0, 0), (4, 0, 0)] - >>> tangents = [(1, 0, 0), (0, 1, 0), (1, 0, 0)] - >>> controlled_spline = make_spline_redge(points, tangents) - >>> - >>> # 创建3D样条曲线 - >>> points_3d = [(0, 0, 0), (1, 1, 1), (2, 0, 2), (3, 1, 1)] - >>> spline_3d = make_spline_redge(points_3d) + # 创建简单的样条曲线 + points = [(0, 0, 0), (1, 2, 0), (3, 1, 0), (4, 3, 0)] + spline = make_spline_redge(points) + + # 创建带切线控制的样条曲线 + points = [(0, 0, 0), (2, 0, 0), (4, 0, 0)] + tangents = [(1, 0, 0), (0, 1, 0), (1, 0, 0)] + controlled_spline = make_spline_redge(points, tangents) + + # 创建3D样条曲线 + points_3d = [(0, 0, 0), (1, 1, 1), (2, 0, 2), (3, 1, 1)] + spline_3d = make_spline_redge(points_3d) """ try: if len(points) < 2: @@ -1002,13 +1002,13 @@ def make_spline_rwire(points: List[Tuple[float, float, float]], 可以设置为闭合样条曲线,适用于构建复杂的封闭轮廓。 Example: - >>> # 创建开放样条曲线线 - >>> points = [(0, 0, 0), (2, 3, 0), (4, 1, 0), (6, 2, 0)] - >>> spline_wire = make_spline_rwire(points) - >>> - >>> # 创建闭合样条曲线 - >>> points = [(0, 0, 0), (2, 2, 0), (4, 0, 0), (2, -2, 0)] - >>> closed_spline = make_spline_rwire(points, closed=True) + # 创建开放样条曲线线 + points = [(0, 0, 0), (2, 3, 0), (4, 1, 0), (6, 2, 0)] + spline_wire = make_spline_rwire(points) + + # 创建闭合样条曲线 + points = [(0, 0, 0), (2, 2, 0), (4, 0, 0), (2, -2, 0)] + closed_spline = make_spline_rwire(points, closed=True) """ try: edge = make_spline_redge(points, tangents) @@ -1042,17 +1042,17 @@ def make_polyline_rwire(points: List[Tuple[float, float, float]], 相邻点之间用直线连接,可以创建开放或闭合的多段线。 Example: - >>> # 创建L形多段线 - >>> points = [(0, 0, 0), (3, 0, 0), (3, 2, 0)] - >>> l_shape = make_polyline_rwire(points) - >>> - >>> # 创建三角形轮廓 - >>> triangle_points = [(0, 0, 0), (2, 0, 0), (1, 2, 0)] - >>> triangle = make_polyline_rwire(triangle_points, closed=True) - >>> - >>> # 创建复杂的多边形 - >>> polygon_points = [(0, 0, 0), (2, 0, 0), (3, 1, 0), (2, 2, 0), (0, 2, 0)] - >>> polygon = make_polyline_rwire(polygon_points, closed=True) + # 创建L形多段线 + points = [(0, 0, 0), (3, 0, 0), (3, 2, 0)] + l_shape = make_polyline_rwire(points) + + # 创建三角形轮廓 + triangle_points = [(0, 0, 0), (2, 0, 0), (1, 2, 0)] + triangle = make_polyline_rwire(triangle_points, closed=True) + + # 创建复杂的多边形 + polygon_points = [(0, 0, 0), (2, 0, 0), (3, 1, 0), (2, 2, 0), (0, 2, 0)] + polygon = make_polyline_rwire(polygon_points, closed=True) """ try: if len(points) < 2: @@ -1117,14 +1117,14 @@ def make_helix_redge(pitch: float, 螺旋线绕指定轴旋转,同时沿轴向移动,形成螺旋形状。 Example: - >>> # 创建标准螺旋线 - >>> helix = make_helix_redge(2.0, 10.0, 1.0) # 螺距2,高度10,半径1 - >>> - >>> # 创建紧密螺旋线 - >>> tight_helix = make_helix_redge(0.5, 5.0, 0.5) - >>> - >>> # 创建水平螺旋线 - >>> horizontal_helix = make_helix_redge(1.0, 8.0, 2.0, (0, 0, 0), (1, 0, 0)) + # 创建标准螺旋线 + helix = make_helix_redge(2.0, 10.0, 1.0) # 螺距2,高度10,半径1 + + # 创建紧密螺旋线 + tight_helix = make_helix_redge(0.5, 5.0, 0.5) + + # 创建水平螺旋线 + horizontal_helix = make_helix_redge(1.0, 8.0, 2.0, (0, 0, 0), (1, 0, 0)) """ try: if pitch <= 0: @@ -1180,13 +1180,13 @@ def make_helix_rwire(pitch: float, 可以用于后续的扫掠操作或作为复杂路径的一部分。 Example: - >>> # 创建螺旋线线对象 - >>> helix_wire = make_helix_rwire(1.5, 6.0, 1.0) - >>> - >>> # 用于扫掠操作的螺旋路径 - >>> profile = make_circle_rface((0, 0, 0), 0.1) - >>> helix_path = make_helix_rwire(2.0, 10.0, 2.0) - >>> # 然后可以用 sweep_rsolid(profile, helix_path) 创建螺旋扫掠 + # 创建螺旋线线对象 + helix_wire = make_helix_rwire(1.5, 6.0, 1.0) + + # 用于扫掠操作的螺旋路径 + profile = make_circle_rface((0, 0, 0), 0.1) + helix_path = make_helix_rwire(2.0, 10.0, 2.0) + # 然后可以用 sweep_rsolid(profile, helix_path) 创建螺旋扫掠 """ try: cs = get_current_cs() @@ -1226,17 +1226,17 @@ def translate_shape(shape: AnyShape, vector: Tuple[float, float, float]) -> AnyS 平移操作支持当前坐标系变换,适用于所有类型的几何对象。 Example: - >>> # 平移立方体 - >>> box = make_box_rsolid(2, 2, 2) - >>> moved_box = translate_shape(box, (5, 0, 0)) # 沿X轴移动5个单位 - >>> - >>> # 平移圆形面 - >>> circle = make_circle_rface((0, 0, 0), 1.0) - >>> moved_circle = translate_shape(circle, (1, 1, 2)) - >>> - >>> # 平移线段 - >>> line = make_line_redge((0, 0, 0), (1, 0, 0)) - >>> moved_line = translate_shape(line, (0, 3, 0)) + # 平移立方体 + box = make_box_rsolid(2, 2, 2) + moved_box = translate_shape(box, (5, 0, 0)) # 沿X轴移动5个单位 + + # 平移圆形面 + circle = make_circle_rface((0, 0, 0), 1.0) + moved_circle = translate_shape(circle, (1, 1, 2)) + + # 平移线段 + line = make_line_redge((0, 0, 0), (1, 0, 0)) + moved_line = translate_shape(line, (0, 3, 0)) """ try: cs = get_current_cs() @@ -1303,17 +1303,17 @@ def rotate_shape(shape: AnyShape, 角度使用度数制,正值表示右手定则的逆时针旋转。 Example: - >>> # 绕Z轴旋转立方体45度 - >>> box = make_box_rsolid(2, 2, 2) - >>> rotated_box = rotate_shape(box, 45) - >>> - >>> # 绕X轴旋转圆形面90度 - >>> circle = make_circle_rface((0, 0, 0), 1.0) - >>> rotated_circle = rotate_shape(circle, 90, (1, 0, 0)) - >>> - >>> # 围绕指定点旋转 - >>> line = make_line_redge((0, 0, 0), (2, 0, 0)) - >>> rotated_line = rotate_shape(line, 90, (0, 0, 1), (1, 0, 0)) + # 绕Z轴旋转立方体45度 + box = make_box_rsolid(2, 2, 2) + rotated_box = rotate_shape(box, 45) + + # 绕X轴旋转圆形面90度 + circle = make_circle_rface((0, 0, 0), 1.0) + rotated_circle = rotate_shape(circle, 90, (1, 0, 0)) + + # 围绕指定点旋转 + line = make_line_redge((0, 0, 0), (2, 0, 0)) + rotated_line = rotate_shape(line, 90, (0, 0, 1), (1, 0, 0)) """ if angle == 0: return shape @@ -1384,18 +1384,18 @@ def extrude_rsolid(profile: Union[Wire, Face], 如果输入是面,直接进行拉伸。这是创建柱状、管状等规则几何体的基础操作。 Example: - >>> # 拉伸圆形面创建圆柱体 - >>> circle = make_circle_rface((0, 0, 0), 1.0) - >>> cylinder = extrude_rsolid(circle, (0, 0, 1), 5.0) - >>> - >>> # 拉伸矩形面创建立方体 - >>> rect = make_rectangle_rface(2.0, 2.0) - >>> box = extrude_rsolid(rect, (0, 0, 1), 3.0) - >>> - >>> # 拉伸复杂轮廓 - >>> points = [(0, 0, 0), (2, 0, 0), (2, 1, 0), (0, 1, 0)] - >>> profile_wire = make_polyline_rwire(points, closed=True) - >>> extruded_shape = extrude_rsolid(profile_wire, (0, 0, 1), 4.0) + # 拉伸圆形面创建圆柱体 + circle = make_circle_rface((0, 0, 0), 1.0) + cylinder = extrude_rsolid(circle, (0, 0, 1), 5.0) + + # 拉伸矩形面创建立方体 + rect = make_rectangle_rface(2.0, 2.0) + box = extrude_rsolid(rect, (0, 0, 1), 3.0) + + # 拉伸复杂轮廓 + points = [(0, 0, 0), (2, 0, 0), (2, 1, 0), (0, 1, 0)] + profile_wire = make_polyline_rwire(points, closed=True) + extruded_shape = extrude_rsolid(profile_wire, (0, 0, 1), 4.0) """ try: if distance <= 0: @@ -1456,18 +1456,18 @@ def revolve_rsolid(profile: Union[Wire, Face], 如圆柱体、圆锥体、球体等。如果输入是线,必须是封闭的线。 Example: - >>> # 旋转矩形创建圆柱体 - >>> rect = make_rectangle_rface(1.0, 3.0, (2, 0, 0)) # 远离旋转轴 - >>> cylinder = revolve_rsolid(rect, (0, 0, 1), 360) - >>> - >>> # 创建圆锥体 - >>> triangle_points = [(1, 0, 0), (2, 0, 0), (1.5, 2, 0)] - >>> triangle = make_polyline_rwire(triangle_points, closed=True) - >>> cone = revolve_rsolid(triangle, (0, 0, 1), 360) - >>> - >>> # 创建部分旋转体(90度扇形) - >>> rect = make_rectangle_rface(0.5, 2.0, (1.5, 0, 0)) - >>> partial_solid = revolve_rsolid(rect, (0, 0, 1), 90) + # 旋转矩形创建圆柱体 + rect = make_rectangle_rface(1.0, 3.0, (2, 0, 0)) # 远离旋转轴 + cylinder = revolve_rsolid(rect, (0, 0, 1), 360) + + # 创建圆锥体 + triangle_points = [(1, 0, 0), (2, 0, 0), (1.5, 2, 0)] + triangle = make_polyline_rwire(triangle_points, closed=True) + cone = revolve_rsolid(triangle, (0, 0, 1), 360) + + # 创建部分旋转体(90度扇形) + rect = make_rectangle_rface(0.5, 2.0, (1.5, 0, 0)) + partial_solid = revolve_rsolid(rect, (0, 0, 1), 90) """ try: if angle <= 0: @@ -1595,18 +1595,18 @@ def union_rsolid(solid1: Solid, solid2: Solid) -> Solid: 并集运算会合并两个实体的重叠部分,结果体积大于等于任一输入实体。 Example: - >>> # 创建两个重叠的立方体 - >>> box1 = make_box_rsolid(2, 2, 2, (0, 0, 0)) - >>> box2 = make_box_rsolid(2, 2, 2, (1, 0, 0)) - >>> - >>> # 计算并集 - >>> union_result = union_rsolid(box1, box2) - >>> # 结果是一个组合的形状,体积小于两个立方体体积之和 - >>> - >>> # 圆柱和立方体的并集 - >>> cylinder = make_cylinder_rsolid(1.0, 3.0) - >>> box = make_box_rsolid(1, 1, 1, (0, 0, 1)) - >>> combined = union_rsolid(cylinder, box) + # 创建两个重叠的立方体 + box1 = make_box_rsolid(2, 2, 2, (0, 0, 0)) + box2 = make_box_rsolid(2, 2, 2, (1, 0, 0)) + + # 计算并集 + union_result = union_rsolid(box1, box2) + # 结果是一个组合的形状,体积小于两个立方体体积之和 + + # 圆柱和立方体的并集 + cylinder = make_cylinder_rsolid(1.0, 3.0) + box = make_box_rsolid(1, 1, 1, (0, 0, 1)) + combined = union_rsolid(cylinder, box) """ try: s1 = solid1.cq_solid @@ -1652,20 +1652,20 @@ def cut_rsolid(solid1: Solid, solid2: Solid) -> Solid: 结果实体的体积等于solid1减去两个实体重叠部分的体积。 Example: - >>> # 在立方体中创建圆形孔 - >>> box = make_box_rsolid(4, 4, 4) - >>> hole = make_cylinder_rsolid(1.0, 4.0) - >>> box_with_hole = cut_rsolid(box, hole) - >>> - >>> # 创建槽形结构 - >>> base = make_box_rsolid(6, 3, 2) - >>> slot = make_box_rsolid(4, 1, 2, (0, 0, 1)) - >>> slotted_base = cut_rsolid(base, slot) - >>> - >>> # 从球体中减去立方体 - >>> sphere = make_sphere_rsolid(2.0) - >>> cube = make_box_rsolid(2, 2, 2) - >>> carved_sphere = cut_rsolid(sphere, cube) + # 在立方体中创建圆形孔 + box = make_box_rsolid(4, 4, 4) + hole = make_cylinder_rsolid(1.0, 4.0) + box_with_hole = cut_rsolid(box, hole) + + # 创建槽形结构 + base = make_box_rsolid(6, 3, 2) + slot = make_box_rsolid(4, 1, 2, (0, 0, 1)) + slotted_base = cut_rsolid(base, slot) + + # 从球体中减去立方体 + sphere = make_sphere_rsolid(2.0) + cube = make_box_rsolid(2, 2, 2) + carved_sphere = cut_rsolid(sphere, cube) """ try: cq_result = solid1.cq_solid.cut(solid2.cq_solid) @@ -1701,21 +1701,21 @@ def intersect_rsolid(solid1: Solid, solid2: Solid) -> Solid: 如果两个实体不相交,可能返回空实体。交集体积小于等于任一输入实体。 Example: - >>> # 计算两个重叠立方体的交集 - >>> box1 = make_box_rsolid(3, 3, 3, (0, 0, 0)) - >>> box2 = make_box_rsolid(3, 3, 3, (1, 1, 0)) - >>> intersection = intersect_rsolid(box1, box2) - >>> # 结果是一个2×2×3的立方体 - >>> - >>> # 球体和立方体的交集 - >>> sphere = make_sphere_rsolid(2.0) - >>> cube = make_box_rsolid(3, 3, 3) - >>> rounded_cube = intersect_rsolid(sphere, cube) - >>> - >>> # 圆柱体和平面的交集 - >>> cylinder = make_cylinder_rsolid(1.5, 4.0) - >>> slab = make_box_rsolid(4, 4, 2, (0, 0, 1)) - >>> partial_cylinder = intersect_rsolid(cylinder, slab) + # 计算两个重叠立方体的交集 + box1 = make_box_rsolid(3, 3, 3, (0, 0, 0)) + box2 = make_box_rsolid(3, 3, 3, (1, 1, 0)) + intersection = intersect_rsolid(box1, box2) + # 结果是一个2×2×3的立方体 + + # 球体和立方体的交集 + sphere = make_sphere_rsolid(2.0) + cube = make_box_rsolid(3, 3, 3) + rounded_cube = intersect_rsolid(sphere, cube) + + # 圆柱体和平面的交集 + cylinder = make_cylinder_rsolid(1.5, 4.0) + slab = make_box_rsolid(4, 4, 2, (0, 0, 1)) + partial_cylinder = intersect_rsolid(cylinder, slab) """ try: cq_result = solid1.cq_solid.intersect(solid2.cq_solid) @@ -1844,22 +1844,22 @@ def fillet_rsolid(solid: Solid, edges: List[Edge], radius: float) -> Solid: 改善外观和减少应力集中。圆角半径不能太大,否则可能导致几何冲突。 Example: - >>> # 对立方体的所有边进行圆角 - >>> box = make_box_rsolid(4, 4, 4) - >>> all_edges = box.get_edges() - >>> rounded_box = fillet_rsolid(box, all_edges[:4], 0.5) # 只对前4条边圆角 - >>> - >>> # 对圆柱体的边进行圆角 - >>> cylinder = make_cylinder_rsolid(2.0, 5.0) - >>> edges = cylinder.get_edges() - >>> # 选择顶部和底部的圆边 - >>> circular_edges = [e for e in edges if e.has_tag("circular")] - >>> rounded_cylinder = fillet_rsolid(cylinder, circular_edges, 0.3) - >>> - >>> # 对复杂几何体的特定边圆角 - >>> complex_solid = union_rsolid(box, cylinder) - >>> selected_edges = complex_solid.get_edges()[:6] - >>> smoothed_solid = fillet_rsolid(complex_solid, selected_edges, 0.2) + # 对立方体的所有边进行圆角 + box = make_box_rsolid(4, 4, 4) + all_edges = box.get_edges() + rounded_box = fillet_rsolid(box, all_edges[:4], 0.5) # 只对前4条边圆角 + + # 对圆柱体的边进行圆角 + cylinder = make_cylinder_rsolid(2.0, 5.0) + edges = cylinder.get_edges() + # 选择顶部和底部的圆边 + circular_edges = [e for e in edges if e.has_tag("circular")] + rounded_cylinder = fillet_rsolid(cylinder, circular_edges, 0.3) + + # 对复杂几何体的特定边圆角 + complex_solid = union_rsolid(box, cylinder) + selected_edges = complex_solid.get_edges()[:6] + smoothed_solid = fillet_rsolid(complex_solid, selected_edges, 0.2) """ try: if radius <= 0: @@ -1900,20 +1900,20 @@ def chamfer_rsolid(solid: Solid, edges: List[Edge], distance: float) -> Solid: 平面过渡而不是圆弧过渡。常用于机械零件的边缘处理,便于装配和安全。 Example: - >>> # 对立方体的边进行倒角 - >>> box = make_box_rsolid(4, 4, 4) - >>> edges = box.get_edges() - >>> chamfered_box = chamfer_rsolid(box, edges[:4], 0.3) - >>> - >>> # 对圆柱体的边倒角 - >>> cylinder = make_cylinder_rsolid(2.0, 5.0) - >>> cylinder_edges = cylinder.get_edges() - >>> chamfered_cylinder = chamfer_rsolid(cylinder, cylinder_edges[:2], 0.2) - >>> - >>> # 选择性倒角 - >>> complex_solid = make_box_rsolid(6, 3, 2) - >>> top_edges = [e for e in complex_solid.get_edges() if e.has_tag("top")] - >>> chamfered_top = chamfer_rsolid(complex_solid, top_edges, 0.1) + # 对立方体的边进行倒角 + box = make_box_rsolid(4, 4, 4) + edges = box.get_edges() + chamfered_box = chamfer_rsolid(box, edges[:4], 0.3) + + # 对圆柱体的边倒角 + cylinder = make_cylinder_rsolid(2.0, 5.0) + cylinder_edges = cylinder.get_edges() + chamfered_cylinder = chamfer_rsolid(cylinder, cylinder_edges[:2], 0.2) + + # 选择性倒角 + complex_solid = make_box_rsolid(6, 3, 2) + top_edges = [e for e in complex_solid.get_edges() if e.has_tag("top")] + chamfered_top = chamfer_rsolid(complex_solid, top_edges, 0.1) """ try: if distance <= 0: @@ -1955,20 +1955,20 @@ def shell_rsolid(solid: Solid, faces_to_remove: List[Face], thickness: float) -> 创建开口,壁厚决定了外壳的厚度。如果不移除任何面则创建闭合空心体。 Example: - >>> # 创建空心立方体容器 - >>> box = make_box_rsolid(4, 4, 4) - >>> top_faces = [f for f in box.get_faces() if f.has_tag("top")] - >>> container = shell_rsolid(box, top_faces, 0.2) - >>> - >>> # 创建空心球体 - >>> sphere = make_sphere_rsolid(3.0) - >>> # 不移除任何面,创建闭合空心球 - >>> hollow_sphere = shell_rsolid(sphere, [], 0.3) - >>> - >>> # 创建有开口的圆柱体容器 - >>> cylinder = make_cylinder_rsolid(2.0, 5.0) - >>> top_faces = [f for f in cylinder.get_faces() if f.has_tag("top")] - >>> cup = shell_rsolid(cylinder, top_faces, 0.1) + # 创建空心立方体容器 + box = make_box_rsolid(4, 4, 4) + top_faces = [f for f in box.get_faces() if f.has_tag("top")] + container = shell_rsolid(box, top_faces, 0.2) + + # 创建空心球体 + sphere = make_sphere_rsolid(3.0) + # 不移除任何面,创建闭合空心球 + hollow_sphere = shell_rsolid(sphere, [], 0.3) + + # 创建有开口的圆柱体容器 + cylinder = make_cylinder_rsolid(2.0, 5.0) + top_faces = [f for f in cylinder.get_faces() if f.has_tag("top")] + cup = shell_rsolid(cylinder, top_faces, 0.1) """ try: if thickness <= 0: @@ -2010,21 +2010,21 @@ def loft_rsolid(profiles: List[Wire], ruled: bool = False) -> Solid: 常用于创建复杂的过渡形状,如飞机机翼、船体等变截面结构。 Example: - >>> # 创建方形到圆形的过渡体 - >>> square = make_rectangle_rwire(2, 2, (0, 0, 0)) - >>> circle = make_circle_rwire((0, 0, 3), 1.0) - >>> transition = loft_rsolid([square, circle]) - >>> - >>> # 创建多层过渡的复杂形状 - >>> bottom = make_rectangle_rwire(4, 4, (0, 0, 0)) - >>> middle = make_circle_rwire((0, 0, 2), 2.0) - >>> top = make_rectangle_rwire(1, 1, (0, 0, 4)) - >>> complex_shape = loft_rsolid([bottom, middle, top]) - >>> - >>> # 创建直纹面放样 - >>> profile1 = make_circle_rwire((0, 0, 0), 2.0) - >>> profile2 = make_circle_rwire((0, 0, 5), 1.0) - >>> ruled_loft = loft_rsolid([profile1, profile2], ruled=True) + # 创建方形到圆形的过渡体 + square = make_rectangle_rwire(2, 2, (0, 0, 0)) + circle = make_circle_rwire((0, 0, 3), 1.0) + transition = loft_rsolid([square, circle]) + + # 创建多层过渡的复杂形状 + bottom = make_rectangle_rwire(4, 4, (0, 0, 0)) + middle = make_circle_rwire((0, 0, 2), 2.0) + top = make_rectangle_rwire(1, 1, (0, 0, 4)) + complex_shape = loft_rsolid([bottom, middle, top]) + + # 创建直纹面放样 + profile1 = make_circle_rwire((0, 0, 0), 2.0) + profile2 = make_circle_rwire((0, 0, 5), 1.0) + ruled_loft = loft_rsolid([profile1, profile2], ruled=True) """ try: if len(profiles) < 2: @@ -2076,21 +2076,21 @@ def sweep_rsolid(profile: Face, path: Wire, 复杂曲面等。Frenet框架控制轮廓在路径上的旋转行为。 Example: - >>> # 沿直线扫掠圆形创建圆管 - >>> circle = make_circle_rface((0, 0, 0), 0.5) - >>> line_path = make_segment_rwire((0, 0, 0), (10, 0, 0)) - >>> tube = sweep_rsolid(circle, line_path) - >>> - >>> # 沿螺旋路径扫掠创建螺旋管 - >>> square = make_rectangle_rface(0.2, 0.2) - >>> helix_path = make_helix_rwire(1.0, 5.0, 2.0) - >>> spiral_tube = sweep_rsolid(square, helix_path, is_frenet=True) - >>> - >>> # 沿曲线扫掠创建复杂形状 - >>> profile = make_rectangle_rface(1.0, 0.5) - >>> curve_points = [(0, 0, 0), (2, 2, 1), (4, 0, 2), (6, -1, 3)] - >>> curve_path = make_spline_rwire(curve_points) - >>> swept_shape = sweep_rsolid(profile, curve_path) + # 沿直线扫掠圆形创建圆管 + circle = make_circle_rface((0, 0, 0), 0.5) + line_path = make_segment_rwire((0, 0, 0), (10, 0, 0)) + tube = sweep_rsolid(circle, line_path) + + # 沿螺旋路径扫掠创建螺旋管 + square = make_rectangle_rface(0.2, 0.2) + helix_path = make_helix_rwire(1.0, 5.0, 2.0) + spiral_tube = sweep_rsolid(square, helix_path, is_frenet=True) + + # 沿曲线扫掠创建复杂形状 + profile = make_rectangle_rface(1.0, 0.5) + curve_points = [(0, 0, 0), (2, 2, 1), (4, 0, 2), (6, -1, 3)] + curve_path = make_spline_rwire(curve_points) + swept_shape = sweep_rsolid(profile, curve_path) """ try: # 执行扫掠操作 @@ -2136,18 +2136,18 @@ def linear_pattern_rsolidlist(shape: AnyShape, 常用于创建重复结构,如齿轮齿、栅栏、螺栓阵列等。 Example: - >>> # 创建立方体的线性阵列 - >>> box = make_box_rsolid(1, 1, 1) - >>> boxes = linear_pattern_rsolidlist(box, (2, 0, 0), 5, 2.0) - >>> # 创建5个立方体,沿X轴方向间距2.0 - >>> - >>> # 创建圆柱体的对角线阵列 - >>> cylinder = make_cylinder_rsolid(0.5, 2.0) - >>> cylinders = linear_pattern_rsolidlist(cylinder, (1, 1, 0), 4, 1.5) - >>> - >>> # 创建复杂几何体的阵列 - >>> complex_shape = union_rsolid(box, cylinder) - >>> array = linear_pattern_rsolidlist(complex_shape, (0, 3, 0), 3, 3.0) + # 创建立方体的线性阵列 + box = make_box_rsolid(1, 1, 1) + boxes = linear_pattern_rsolidlist(box, (2, 0, 0), 5, 2.0) + # 创建5个立方体,沿X轴方向间距2.0 + + # 创建圆柱体的对角线阵列 + cylinder = make_cylinder_rsolid(0.5, 2.0) + cylinders = linear_pattern_rsolidlist(cylinder, (1, 1, 0), 4, 1.5) + + # 创建复杂几何体的阵列 + complex_shape = union_rsolid(box, cylinder) + array = linear_pattern_rsolidlist(complex_shape, (0, 3, 0), 3, 3.0) """ try: if count <= 0: @@ -2225,17 +2225,17 @@ def radial_pattern_rsolidlist(shape: AnyShape, 常用于创建齿轮、花瓣、螺栓圆形分布等对称结构。 Example: - >>> # 创建立方体的径向阵列(6个,360度) - >>> box = make_box_rsolid(1, 0.5, 0.5, (2, 0, 0)) # 距离中心2单位 - >>> radial_boxes = radial_pattern_rsolidlist(box, (0, 0, 0), (0, 0, 1), 6, 360) - >>> - >>> # 创建半圆阵列 - >>> cylinder = make_cylinder_rsolid(0.3, 1.0, (1.5, 0, 0)) - >>> half_circle = radial_pattern_rsolidlist(cylinder, (0, 0, 0), (0, 0, 1), 4, 180) - >>> - >>> # 围绕Y轴的径向阵列 - >>> element = make_sphere_rsolid(0.5, (3, 0, 0)) - >>> vertical_array = radial_pattern_rsolidlist(element, (0, 0, 0), (0, 1, 0), 8, 360) + # 创建立方体的径向阵列(6个,360度) + box = make_box_rsolid(1, 0.5, 0.5, (2, 0, 0)) # 距离中心2单位 + radial_boxes = radial_pattern_rsolidlist(box, (0, 0, 0), (0, 0, 1), 6, 360) + + # 创建半圆阵列 + cylinder = make_cylinder_rsolid(0.3, 1.0, (1.5, 0, 0)) + half_circle = radial_pattern_rsolidlist(cylinder, (0, 0, 0), (0, 0, 1), 4, 180) + + # 围绕Y轴的径向阵列 + element = make_sphere_rsolid(0.5, (3, 0, 0)) + vertical_array = radial_pattern_rsolidlist(element, (0, 0, 0), (0, 1, 0), 8, 360) """ try: if count <= 0: @@ -2307,17 +2307,17 @@ def mirror_shape(shape: AnyShape, 镜像平面由一个点和法向量定义,几何体在平面另一侧生成对称副本。 Example: - >>> # 沿YZ平面镜像立方体 - >>> box = make_box_rsolid(2, 2, 2, (1, 0, 0)) - >>> mirrored_box = mirror_shape(box, (0, 0, 0), (1, 0, 0)) - >>> - >>> # 沿XY平面镜像圆柱体 - >>> cylinder = make_cylinder_rsolid(1.0, 3.0, (0, 0, 1)) - >>> mirrored_cyl = mirror_shape(cylinder, (0, 0, 0), (0, 0, 1)) - >>> - >>> # 沿任意平面镜像 - >>> sphere = make_sphere_rsolid(1.5, (2, 2, 0)) - >>> mirrored_sphere = mirror_shape(sphere, (1, 1, 0), (1, 1, 0)) + # 沿YZ平面镜像立方体 + box = make_box_rsolid(2, 2, 2, (1, 0, 0)) + mirrored_box = mirror_shape(box, (0, 0, 0), (1, 0, 0)) + + # 沿XY平面镜像圆柱体 + cylinder = make_cylinder_rsolid(1.0, 3.0, (0, 0, 1)) + mirrored_cyl = mirror_shape(cylinder, (0, 0, 0), (0, 0, 1)) + + # 沿任意平面镜像 + sphere = make_sphere_rsolid(1.5, (2, 2, 0)) + mirrored_sphere = mirror_shape(sphere, (1, 1, 0), (1, 1, 0)) """ try: cs = get_current_cs() @@ -2405,17 +2405,17 @@ def helical_sweep_rsolid(profile: Wire, - 将profile移动到距离旋转中心指定半径的位置 Example: - >>> # 创建螺旋弹簧 - >>> circle_profile = make_circle_rwire((0, 0, 0), 0.2) - >>> spring = helical_sweep_rsolid(circle_profile, 1.0, 10.0, 2.0) - >>> - >>> # 创建方形截面的螺旋管 - >>> square_profile = make_rectangle_rwire(0.5, 0.5) - >>> square_helix = helical_sweep_rsolid(square_profile, 2.0, 8.0, 1.5) - >>> - >>> # 创建紧密螺旋结构 - >>> small_circle = make_circle_rwire((0, 0, 0), 0.1) - >>> tight_helix = helical_sweep_rsolid(small_circle, 0.5, 5.0, 1.0) + # 创建螺旋弹簧 + circle_profile = make_circle_rwire((0, 0, 0), 0.2) + spring = helical_sweep_rsolid(circle_profile, 1.0, 10.0, 2.0) + + # 创建方形截面的螺旋管 + square_profile = make_rectangle_rwire(0.5, 0.5) + square_helix = helical_sweep_rsolid(square_profile, 2.0, 8.0, 1.5) + + # 创建紧密螺旋结构 + small_circle = make_circle_rwire((0, 0, 0), 0.1) + tight_helix = helical_sweep_rsolid(small_circle, 0.5, 5.0, 1.0) """ try: if pitch <= 0: diff --git a/uv.lock b/uv.lock index adf2e4a3..64126638 100644 --- a/uv.lock +++ b/uv.lock @@ -131,6 +131,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/a9/cf/45fb5261ece3e6b9817d3d82b2f343a505fd58674a92577923bc500bd1aa/bcrypt-4.3.0-cp39-abi3-win_amd64.whl", hash = "sha256:e53e074b120f2877a35cc6c736b8eb161377caae8925c17688bd46ba56daaa5b", size = 152799, upload-time = "2025-02-28T01:23:53.139Z" }, ] +[[package]] +name = "beartype" +version = "0.18.5" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/96/15/4e623478a9628ad4cee2391f19aba0b16c1dd6fedcb2a399f0928097b597/beartype-0.18.5.tar.gz", hash = "sha256:264ddc2f1da9ec94ff639141fbe33d22e12a9f75aa863b83b7046ffff1381927", size = 1193506, upload-time = "2024-04-21T07:25:58.64Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/64/43/7a1259741bd989723272ac7d381a43be932422abcff09a1d9f7ba212cb74/beartype-0.18.5-py3-none-any.whl", hash = "sha256:5301a14f2a9a5540fe47ec6d34d758e9cd8331d36c4760fc7a5499ab86310089", size = 917762, upload-time = "2024-04-21T07:25:55.758Z" }, +] + [[package]] name = "beautifulsoup4" version = "4.13.4" @@ -2405,6 +2414,19 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/69/76/37c0ccd5ab968a6a438f9c623aeecc84c202ab2fabc6a8fd927580c15b5a/QtPy-2.4.3-py3-none-any.whl", hash = "sha256:72095afe13673e017946cc258b8d5da43314197b741ed2890e563cf384b51aa1", size = 95045, upload-time = "2025-02-11T15:09:24.162Z" }, ] +[[package]] +name = "ragflow-sdk" +version = "0.19.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "beartype" }, + { name = "requests" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/9b/73/cb710c38e90d9f3253bf39f6ce65f80fd94ebb37d17501aca5bd3534feeb/ragflow_sdk-0.19.1.tar.gz", hash = "sha256:6bf6dbf453a870552e08a9217c0fede310169a33877decd64a49ed5b21fd2913", size = 7982, upload-time = "2025-06-20T10:29:18.921Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/ef/4a/3dc10a23462cbeddfd39b8eb75d974b085476682f47952659c73eed2bf11/ragflow_sdk-0.19.1-py3-none-any.whl", hash = "sha256:c71cdcfbcf4fe9dbe9e090cea521c3970cfffaa741cb5d3129f03d6749004d74", size = 14484, upload-time = "2025-06-20T10:29:17.85Z" }, +] + [[package]] name = "readme-renderer" version = "44.0" @@ -2671,7 +2693,7 @@ wheels = [ [[package]] name = "simplecadapi" -version = "0.1.2" +version = "1.0.0" source = { editable = "." } dependencies = [ { name = "cadquery" }, @@ -2695,6 +2717,7 @@ editor = [ [package.dev-dependencies] dev = [ { name = "pytest" }, + { name = "ragflow-sdk" }, { name = "twine" }, ] @@ -2715,6 +2738,7 @@ provides-extras = ["dev", "editor"] [package.metadata.requires-dev] dev = [ { name = "pytest" }, + { name = "ragflow-sdk", specifier = ">=0.19.1" }, { name = "twine", specifier = ">=6.1.0" }, ]