From 379f421cbe7a26e9e2ab917d03da8016eb80d64f Mon Sep 17 00:00:00 2001 From: NiJingzhe <1448976235@qq.com> Date: Fri, 13 Mar 2026 16:40:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EQL=E6=9F=A5=E8=AF=A2=E4=B8=8E?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=E4=BC=A0=E6=92=AD=E5=9F=BA=E7=A1=80=EF=BC=8C?= =?UTF-8?q?=E7=BB=9F=E4=B8=80API=E6=96=87=E6=A1=A3=E4=B8=8E=E6=8A=80?= =?UTF-8?q?=E8=83=BD=E8=A7=84=E8=8C=83=E3=80=82=E4=B8=BA=E5=A3=B0=E6=98=8E?= =?UTF-8?q?=E5=BC=8F=E9=80=89=E6=8B=A9=E4=B8=8E=E9=94=9A=E7=82=B9=E6=89=A9?= =?UTF-8?q?=E5=B1=95=E6=89=93=E5=9F=BA=E7=A1=80=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/api/README.md | 32 +- docs/api/add_part_rassembly.md | 6 +- docs/api/and_.md | 25 ++ docs/api/chamfer_rsolid.md | 32 +- docs/api/clear_constraints_rassembly.md | 6 +- docs/api/clone_assembly_rassembly.md | 6 +- docs/api/constrain_coincident_rassembly.md | 6 +- docs/api/constrain_concentric_rassembly.md | 6 +- docs/api/constrain_distance_rassembly.md | 6 +- docs/api/constrain_offset_rassembly.md | 6 +- docs/api/cut_rsolidlist.md | 22 +- docs/api/export_step.md | 14 +- docs/api/export_stl.md | 14 +- docs/api/extrude_rsolid.md | 32 +- docs/api/fillet_rsolid.md | 32 +- docs/api/geo.md | 29 ++ docs/api/helical_sweep_rsolid.md | 44 +-- docs/api/intersect_rsolidlist.md | 22 +- docs/api/linear_pattern_rsolidlist.md | 36 +- docs/api/loft_rsolid.md | 28 +- docs/api/make_angle_arc_redge.md | 42 +-- docs/api/make_angle_arc_rwire.md | 30 +- docs/api/make_assembly_rassembly.md | 6 +- docs/api/make_box_rsolid.md | 38 +- docs/api/make_circle_redge.md | 32 +- docs/api/make_circle_rface.md | 30 +- docs/api/make_circle_rwire.md | 30 +- docs/api/make_cone_rsolid.md | 38 +- docs/api/make_cylinder_rsolid.md | 38 +- docs/api/make_face_from_wire_rface.md | 28 +- docs/api/make_helix_redge.md | 40 +- docs/api/make_helix_rwire.md | 38 +- docs/api/make_line_redge.md | 28 +- docs/api/make_n_hole_flange_rsolid.md | 50 +-- docs/api/make_naca_propeller_blade_rsolid.md | 38 +- docs/api/make_point_rvertex.md | 32 +- docs/api/make_polyline_rwire.md | 28 +- docs/api/make_rectangle_rface.md | 34 +- docs/api/make_rectangle_rwire.md | 36 +- docs/api/make_segment_redge.md | 24 +- docs/api/make_segment_rwire.md | 26 +- docs/api/make_sphere_rsolid.md | 30 +- docs/api/make_spline_redge.md | 28 +- docs/api/make_spline_rwire.md | 30 +- docs/api/make_threaded_rod_rsolid.md | 38 +- docs/api/make_three_point_arc_redge.md | 32 +- docs/api/make_three_point_arc_rwire.md | 30 +- docs/api/make_wire_from_edges_rwire.md | 22 +- docs/api/meta.md | 45 +++ docs/api/mirror_shape.md | 32 +- docs/api/not_.md | 25 ++ docs/api/or_.md | 25 ++ docs/api/radial_pattern_rsolidlist.md | 40 +- docs/api/revolve_rsolid.md | 36 +- docs/api/rotate_part_rassembly.md | 6 +- docs/api/rotate_shape.md | 36 +- docs/api/select.md | 25 ++ docs/api/select_edges_by_tag.md | 14 +- docs/api/select_faces_by_tag.md | 14 +- docs/api/set_tag.md | 14 +- docs/api/shell_rsolid.md | 32 +- docs/api/solve_assembly_rresult.md | 6 +- docs/api/stack.md | 6 +- docs/api/stack_rassembly.md | 6 +- docs/api/sweep_rsolid.md | 32 +- docs/api/tag.md | 37 ++ docs/api/translate_part_rassembly.md | 6 +- docs/api/translate_shape.md | 28 +- docs/api/union_rsolidlist.md | 20 +- docs/api/value.md | 36 ++ refactor-plan/tagging.md | 149 ++++++++ skills/simplecad-self-evolve/SKILL.md | 7 + src/simplecadapi/__init__.py | 3 + src/simplecadapi/auto_tools/auto_docs_gen.py | 65 ++-- src/simplecadapi/auto_tools/skill_pack.py | 7 + src/simplecadapi/constraints.py | 15 +- src/simplecadapi/core.py | 64 +++- src/simplecadapi/operations.py | 43 ++- src/simplecadapi/ql.py | 363 +++++++++++++++++++ src/simplecadapi/tagging.py | 137 +++++++ test/test_ql.py | 74 ++++ test/test_tagging_refactor.py | 74 ++++ 82 files changed, 1989 insertions(+), 833 deletions(-) create mode 100644 docs/api/and_.md create mode 100644 docs/api/geo.md create mode 100644 docs/api/meta.md create mode 100644 docs/api/not_.md create mode 100644 docs/api/or_.md create mode 100644 docs/api/select.md create mode 100644 docs/api/tag.md create mode 100644 docs/api/value.md create mode 100644 refactor-plan/tagging.md create mode 100644 src/simplecadapi/ql.py create mode 100644 src/simplecadapi/tagging.py create mode 100644 test/test_ql.py create mode 100644 test/test_tagging_refactor.py diff --git a/docs/api/README.md b/docs/api/README.md index 6ad7586f..bc6f769c 100644 --- a/docs/api/README.md +++ b/docs/api/README.md @@ -1,8 +1,8 @@ -# SimpleCAD API 文档索引 +# SimpleCAD API Index -本文档包含了 SimpleCAD API (来自 `operations.py`、`evolve.py`、`constraints.py`) 的所有函数说明。 +This index includes API docs generated from `operations.py`, `evolve.py`, `constraints.py`, and `ql.py`. -## 基础图形创建 +## Basic Creation - [make_angle_arc_redge](make_angle_arc_redge.md) *(来自 operations.py)* - [make_angle_arc_rwire](make_angle_arc_rwire.md) *(来自 operations.py)* @@ -29,50 +29,50 @@ - [make_three_point_arc_rwire](make_three_point_arc_rwire.md) *(来自 operations.py)* - [make_wire_from_edges_rwire](make_wire_from_edges_rwire.md) *(来自 operations.py)* -## 变换操作 +## Transforms - [mirror_shape](mirror_shape.md) *(来自 operations.py)* - [rotate_shape](rotate_shape.md) *(来自 operations.py)* - [translate_shape](translate_shape.md) *(来自 operations.py)* -## 3D操作 +## 3D Operations - [extrude_rsolid](extrude_rsolid.md) *(来自 operations.py)* - [loft_rsolid](loft_rsolid.md) *(来自 operations.py)* - [revolve_rsolid](revolve_rsolid.md) *(来自 operations.py)* - [sweep_rsolid](sweep_rsolid.md) *(来自 operations.py)* -## 标签和选择 +## Tagging and Selection - [select_edges_by_tag](select_edges_by_tag.md) *(来自 operations.py)* - [select_faces_by_tag](select_faces_by_tag.md) *(来自 operations.py)* - [set_tag](set_tag.md) *(来自 operations.py)* -## 布尔运算 +## Boolean Operations - [cut_rsolidlist](cut_rsolidlist.md) *(来自 operations.py)* - [intersect_rsolidlist](intersect_rsolidlist.md) *(来自 operations.py)* - [union_rsolidlist](union_rsolidlist.md) *(来自 operations.py)* -## 导出功能 +## Export - [export_step](export_step.md) *(来自 operations.py)* - [export_stl](export_stl.md) *(来自 operations.py)* -## 高级特征 +## Advanced Features - [chamfer_rsolid](chamfer_rsolid.md) *(来自 operations.py)* - [fillet_rsolid](fillet_rsolid.md) *(来自 operations.py)* - [helical_sweep_rsolid](helical_sweep_rsolid.md) *(来自 operations.py)* - [shell_rsolid](shell_rsolid.md) *(来自 operations.py)* -## 自进化 +## Evolve - [make_n_hole_flange_rsolid](make_n_hole_flange_rsolid.md) *(来自 evolve.py)* - [make_naca_propeller_blade_rsolid](make_naca_propeller_blade_rsolid.md) *(来自 evolve.py)* - [make_threaded_rod_rsolid](make_threaded_rod_rsolid.md) *(来自 evolve.py)* -## 声明式装配约束 +## Assembly Constraints - [add_part_rassembly](add_part_rassembly.md) *(来自 constraints.py)* - [clear_constraints_rassembly](clear_constraints_rassembly.md) *(来自 constraints.py)* @@ -88,7 +88,15 @@ - [stack_rassembly](stack_rassembly.md) *(来自 constraints.py)* - [translate_part_rassembly](translate_part_rassembly.md) *(来自 constraints.py)* -## 其他 +## Other +- [and_](and_.md) *(来自 ql.py)* +- [geo](geo.md) *(来自 ql.py)* - [linear_pattern_rsolidlist](linear_pattern_rsolidlist.md) *(来自 operations.py)* +- [meta](meta.md) *(来自 ql.py)* +- [not_](not_.md) *(来自 ql.py)* +- [or_](or_.md) *(来自 ql.py)* - [radial_pattern_rsolidlist](radial_pattern_rsolidlist.md) *(来自 operations.py)* +- [select](select.md) *(来自 ql.py)* +- [tag](tag.md) *(来自 ql.py)* +- [value](value.md) *(来自 ql.py)* diff --git a/docs/api/add_part_rassembly.md b/docs/api/add_part_rassembly.md index 72e8e57e..e970f265 100644 --- a/docs/api/add_part_rassembly.md +++ b/docs/api/add_part_rassembly.md @@ -1,13 +1,13 @@ # add_part_rassembly -## API定义 +## API Definition ```python def add_part_rassembly(assembly: Assembly, name: str, solid: Solid, parent: Optional[Union[str, PartHandle]] = None, local_transform: Optional[Union[np.ndarray, Sequence[Sequence[float]]]] = None) -> Assembly ``` -*来源文件: constraints.py* +*Source: constraints.py* -## API作用 +## Description Type-2映射:在装配空间中新增零件并返回新装配对象。 diff --git a/docs/api/and_.md b/docs/api/and_.md new file mode 100644 index 00000000..5c335fb4 --- /dev/null +++ b/docs/api/and_.md @@ -0,0 +1,25 @@ +# and_ + +## API Definition + +```python +def and_(*predicates: Predicate) -> Predicate +``` + +*Source: ql.py* + +## Description + +构造 AND 组合谓词。 + +Q.and_(Q.tag("face.top"), Q.tag("role.mounting_surface")) + +## Parameters + +### *predicates + +- **Description**: 任意数量谓词。 + +## Returns + +Callable[[Any], bool]: 组合谓词。 diff --git a/docs/api/chamfer_rsolid.md b/docs/api/chamfer_rsolid.md index d5cf92f6..9eec94f8 100644 --- a/docs/api/chamfer_rsolid.md +++ b/docs/api/chamfer_rsolid.md @@ -1,48 +1,48 @@ # chamfer_rsolid -## API定义 +## API Definition ```python def chamfer_rsolid(solid: Solid, edges: List[Edge], distance: float) -> Solid ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 对实体的边进行倒角操作 对实体的指定边进行倒角处理,创建斜面过渡。与圆角不同,倒角创建的是 平面过渡而不是圆弧过渡。常用于机械零件的边缘处理,便于装配和安全。 -## API参数说明 +## Parameters ### solid -- **类型**: `Solid` -- **说明**: 要进行倒角操作的实体对象 +- **Type**: `Solid` +- **Description**: 要进行倒角操作的实体对象 ### edges -- **类型**: `List[Edge]` -- **说明**: 要进行倒角的边列表,通常从实体获取 +- **Type**: `List[Edge]` +- **Description**: 要进行倒角的边列表,通常从实体获取 ### distance -- **类型**: `float` -- **说明**: 倒角距离,必须为正数,定义从边缘向内的倒角深度 +- **Type**: `float` +- **Description**: 倒角距离,必须为正数,定义从边缘向内的倒角深度 -## 返回值说明 +## Returns Solid: 倒角后的实体对象 -## 异常 +## Raises - **ValueError**: 当倒角距离小于等于0或倒角操作失败时抛出异常 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 对立方体的边进行倒角 box = make_box_rsolid(4, 4, 4) @@ -50,7 +50,7 @@ edges = box.get_edges() chamfered_box = chamfer_rsolid(box, edges[:4], 0.3) ``` -### 例子 2 +### Example 2 ```python # 对圆柱体的边倒角 cylinder = make_cylinder_rsolid(2.0, 5.0) @@ -58,7 +58,7 @@ cylinder_edges = cylinder.get_edges() chamfered_cylinder = chamfer_rsolid(cylinder, cylinder_edges[:2], 0.2) ``` -### 例子 3 +### Example 3 ```python # 选择性倒角 complex_solid = make_box_rsolid(6, 3, 2) diff --git a/docs/api/clear_constraints_rassembly.md b/docs/api/clear_constraints_rassembly.md index 6fdfb5ac..dd9c6f78 100644 --- a/docs/api/clear_constraints_rassembly.md +++ b/docs/api/clear_constraints_rassembly.md @@ -1,13 +1,13 @@ # clear_constraints_rassembly -## API定义 +## API Definition ```python def clear_constraints_rassembly(assembly: Assembly) -> Assembly ``` -*来源文件: constraints.py* +*Source: constraints.py* -## API作用 +## Description Type-2映射:清空约束并返回新装配对象。 diff --git a/docs/api/clone_assembly_rassembly.md b/docs/api/clone_assembly_rassembly.md index 5049ee1a..e773c35e 100644 --- a/docs/api/clone_assembly_rassembly.md +++ b/docs/api/clone_assembly_rassembly.md @@ -1,13 +1,13 @@ # clone_assembly_rassembly -## API定义 +## API Definition ```python def clone_assembly_rassembly(assembly: Assembly) -> Assembly ``` -*来源文件: constraints.py* +*Source: constraints.py* -## API作用 +## Description Type-2映射:装配对象到装配对象(克隆)。 diff --git a/docs/api/constrain_coincident_rassembly.md b/docs/api/constrain_coincident_rassembly.md index b1803e4f..15515362 100644 --- a/docs/api/constrain_coincident_rassembly.md +++ b/docs/api/constrain_coincident_rassembly.md @@ -1,13 +1,13 @@ # constrain_coincident_rassembly -## API定义 +## API Definition ```python def constrain_coincident_rassembly(assembly: Assembly, reference: PointAnchor, moving: PointAnchor) -> Assembly ``` -*来源文件: constraints.py* +*Source: constraints.py* -## API作用 +## Description Type-2映射:添加点重合约束并返回新装配对象。 diff --git a/docs/api/constrain_concentric_rassembly.md b/docs/api/constrain_concentric_rassembly.md index e865a95f..77132ab8 100644 --- a/docs/api/constrain_concentric_rassembly.md +++ b/docs/api/constrain_concentric_rassembly.md @@ -1,13 +1,13 @@ # constrain_concentric_rassembly -## API定义 +## API Definition ```python def constrain_concentric_rassembly(assembly: Assembly, reference: AxisAnchor, moving: AxisAnchor, same_direction: bool = False) -> Assembly ``` -*来源文件: constraints.py* +*Source: constraints.py* -## API作用 +## Description Type-2映射:添加同轴约束并返回新装配对象。 diff --git a/docs/api/constrain_distance_rassembly.md b/docs/api/constrain_distance_rassembly.md index a18a60cf..aa4757cf 100644 --- a/docs/api/constrain_distance_rassembly.md +++ b/docs/api/constrain_distance_rassembly.md @@ -1,13 +1,13 @@ # constrain_distance_rassembly -## API定义 +## API Definition ```python def constrain_distance_rassembly(assembly: Assembly, reference: PointAnchor, moving: PointAnchor, distance: float, fallback_axis: AxisLike = 'x') -> Assembly ``` -*来源文件: constraints.py* +*Source: constraints.py* -## API作用 +## Description Type-2映射:添加点距约束并返回新装配对象。 diff --git a/docs/api/constrain_offset_rassembly.md b/docs/api/constrain_offset_rassembly.md index c6d68860..4e25b9cf 100644 --- a/docs/api/constrain_offset_rassembly.md +++ b/docs/api/constrain_offset_rassembly.md @@ -1,13 +1,13 @@ # constrain_offset_rassembly -## API定义 +## API Definition ```python def constrain_offset_rassembly(assembly: Assembly, reference: PointAnchor, moving: PointAnchor, distance: float, axis: AxisLike = 'z') -> Assembly ``` -*来源文件: constraints.py* +*Source: constraints.py* -## API作用 +## Description Type-2映射:添加轴向偏移约束并返回新装配对象。 diff --git a/docs/api/cut_rsolidlist.md b/docs/api/cut_rsolidlist.md index f257817c..3b33b530 100644 --- a/docs/api/cut_rsolidlist.md +++ b/docs/api/cut_rsolidlist.md @@ -1,38 +1,38 @@ # cut_rsolidlist -## API定义 +## API Definition ```python def cut_rsolidlist(*solids: Union[Solid, Sequence[Solid]]) -> List[Solid] ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 实体差集运算(布尔减法) 从第一个实体中依次减去其他实体的重叠部分,常用于创建孔洞、凹槽等。 结果实体的体积 = solid1体积 - (solid1∩solid2) - (结果∩solid3) - ... -## API参数说明 +## Parameters ### *solids -- **说明**: 需要进行差集运算的实体对象,可以传入: - 单个序列:cut_rsolidlist([solid1, solid2, ...]) - 多个参数:cut_rsolidlist(solid1, solid2, ...) - 混合输入:cut_rsolidlist(solid1, [solid2, solid3], ...),会自动展开所有序列 第一个实体作为基础实体,后续实体依次从基础实体中减去。 +- **Description**: 需要进行差集运算的实体对象,可以传入: - 单个序列:cut_rsolidlist([solid1, solid2, ...]) - 多个参数:cut_rsolidlist(solid1, solid2, ...) - 混合输入:cut_rsolidlist(solid1, [solid2, solid3], ...),会自动展开所有序列 第一个实体作为基础实体,后续实体依次从基础实体中减去。 -## 返回值说明 +## Returns List[Solid]: 差集运算结果的实体列表。从第一个实体中依次减去其他所有实体。 返回包含结果的列表:[result_solid] -## 异常 +## Raises - **ValueError**: 当输入实体无效或运算失败时抛出异常 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 在立方体中创建圆形孔(两种方式等价) box = make_box_rsolid(4, 4, 4) @@ -41,7 +41,7 @@ result1 = cut_rsolidlist(box, hole) result2 = cut_rsolidlist([box, hole]) ``` -### 例子 2 +### Example 2 ```python # 创建多个孔的结构 base = make_box_rsolid(6, 3, 2) @@ -50,7 +50,7 @@ hole2 = make_cylinder_rsolid(0.5, 2, (5, 0, 0)) slotted_base = cut_rsolidlist(base, hole1, hole2) ``` -### 例子 3 +### Example 3 ```python # 从球体中减去立方体 sphere = make_sphere_rsolid(2.0) diff --git a/docs/api/export_step.md b/docs/api/export_step.md index 92d8129e..8e60d51a 100644 --- a/docs/api/export_step.md +++ b/docs/api/export_step.md @@ -1,27 +1,27 @@ # export_step -## API定义 +## API Definition ```python def export_step(shapes: Union[AnyShape, Sequence[AnyShape]], filename: str) -> None ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 导出为STEP格式 -## API参数说明 +## Parameters ### shapes -- **说明**: 要导出的几何体或几何体列表 +- **Description**: 要导出的几何体或几何体列表 ### filename -- **说明**: 输出文件名 +- **Description**: 输出文件名 -## 异常 +## Raises - **ValueError**: 当导出失败时 diff --git a/docs/api/export_stl.md b/docs/api/export_stl.md index e2e4f7ec..c352029d 100644 --- a/docs/api/export_stl.md +++ b/docs/api/export_stl.md @@ -1,27 +1,27 @@ # export_stl -## API定义 +## API Definition ```python def export_stl(shapes: Union[AnyShape, Sequence[AnyShape]], filename: str) -> None ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 导出为STL格式 -## API参数说明 +## Parameters ### shapes -- **说明**: 要导出的几何体或几何体列表 +- **Description**: 要导出的几何体或几何体列表 ### filename -- **说明**: 输出文件名 +- **Description**: 输出文件名 -## 异常 +## Raises - **ValueError**: 当导出失败时 diff --git a/docs/api/extrude_rsolid.md b/docs/api/extrude_rsolid.md index d3245f59..d57f32aa 100644 --- a/docs/api/extrude_rsolid.md +++ b/docs/api/extrude_rsolid.md @@ -1,62 +1,62 @@ # extrude_rsolid -## API定义 +## API Definition ```python def extrude_rsolid(profile: Union[Wire, Face], direction: Tuple[float, float, float], distance: float) -> Solid ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 拉伸轮廓创建实体 沿指定方向拉伸二维轮廓创建三维实体。如果输入是线,必须是封闭的线; 如果输入是面,直接进行拉伸。这是创建柱状、管状等规则几何体的基础操作。 -## API参数说明 +## Parameters ### profile -- **类型**: `Union[Wire, Face]` -- **说明**: 要拉伸的轮廓,可以是封闭的线或面 +- **Type**: `Union[Wire, Face]` +- **Description**: 要拉伸的轮廓,可以是封闭的线或面 ### direction -- **类型**: `Tuple[float, float, float]` -- **说明**: 拉伸方向向量 (x, y, z), 定义拉伸的方向,会被标准化处理 +- **Type**: `Tuple[float, float, float]` +- **Description**: 拉伸方向向量 (x, y, z), 定义拉伸的方向,会被标准化处理 ### distance -- **类型**: `float` -- **说明**: 拉伸距离,必须为正数 +- **Type**: `float` +- **Description**: 拉伸距离,必须为正数 -## 返回值说明 +## Returns Solid: 拉伸后的实体对象 -## 异常 +## Raises - **ValueError**: 当轮廓不是封闭的线、距离小于等于0或其他参数无效时抛出异常 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 拉伸圆形面创建圆柱体 circle = make_circle_rface((0, 0, 0), 1.0) cylinder = extrude_rsolid(circle, (0, 0, 1), 5.0) ``` -### 例子 2 +### Example 2 ```python # 拉伸矩形面创建立方体 rect = make_rectangle_rface(2.0, 2.0) box = extrude_rsolid(rect, (0, 0, 1), 3.0) ``` -### 例子 3 +### Example 3 ```python # 拉伸复杂轮廓 points = [(0, 0, 0), (2, 0, 0), (2, 1, 0), (0, 1, 0)] diff --git a/docs/api/fillet_rsolid.md b/docs/api/fillet_rsolid.md index 786c7d11..d731186b 100644 --- a/docs/api/fillet_rsolid.md +++ b/docs/api/fillet_rsolid.md @@ -1,48 +1,48 @@ # fillet_rsolid -## API定义 +## API Definition ```python def fillet_rsolid(solid: Solid, edges: List[Edge], radius: float) -> Solid ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 对实体的边进行圆角操作 对实体的指定边进行圆角处理,创建平滑的过渡面。常用于消除尖锐边缘, 改善外观和减少应力集中。圆角半径不能太大,否则可能导致几何冲突。 -## API参数说明 +## Parameters ### solid -- **类型**: `Solid` -- **说明**: 要进行圆角操作的实体对象 +- **Type**: `Solid` +- **Description**: 要进行圆角操作的实体对象 ### edges -- **类型**: `List[Edge]` -- **说明**: 要进行圆角的边列表,通常从实体获取 +- **Type**: `List[Edge]` +- **Description**: 要进行圆角的边列表,通常从实体获取 ### radius -- **类型**: `float` -- **说明**: 圆角半径,必须为正数,不能大于相邻面的最小尺寸 +- **Type**: `float` +- **Description**: 圆角半径,必须为正数,不能大于相邻面的最小尺寸 -## 返回值说明 +## Returns Solid: 圆角后的实体对象 -## 异常 +## Raises - **ValueError**: 当圆角半径小于等于0或圆角操作失败时抛出异常 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 对立方体的所有边进行圆角 box = make_box_rsolid(4, 4, 4) @@ -50,7 +50,7 @@ all_edges = box.get_edges() rounded_box = fillet_rsolid(box, all_edges[:4], 0.5) # 只对前4条边圆角 ``` -### 例子 2 +### Example 2 ```python # 对圆柱体的边进行圆角 cylinder = make_cylinder_rsolid(2.0, 5.0) @@ -60,7 +60,7 @@ circular_edges = [e for e in edges if e.has_tag("circular")] rounded_cylinder = fillet_rsolid(cylinder, circular_edges, 0.3) ``` -### 例子 3 +### Example 3 ```python # 对复杂几何体的特定边圆角 complex_solid = union_rsolidlist([box, cylinder])[0] diff --git a/docs/api/geo.md b/docs/api/geo.md new file mode 100644 index 00000000..5aa3377c --- /dev/null +++ b/docs/api/geo.md @@ -0,0 +1,29 @@ +# geo + +## API Definition + +```python +def geo(field: str, default: Any = None) -> KeyFn +``` + +*Source: ql.py* + +## Description + +快捷构造 geo 元数据取值函数。 + +Q.select(items).order_by(Q.geo("height")) + +## Parameters + +### field + +- **Description**: geo 字段名,如 "type"、"height"。 + +### default + +- **Description**: 取值失败时的默认值。 + +## Returns + +Callable[[Any], Any]: 取值函数。 diff --git a/docs/api/helical_sweep_rsolid.md b/docs/api/helical_sweep_rsolid.md index 8f0292ae..d2f31b62 100644 --- a/docs/api/helical_sweep_rsolid.md +++ b/docs/api/helical_sweep_rsolid.md @@ -1,14 +1,14 @@ # helical_sweep_rsolid -## API定义 +## API Definition ```python def helical_sweep_rsolid(profile: Wire, pitch: float, height: float, radius: float, center: Tuple[float, float, float] = (0, 0, 0), dir: Tuple[float, float, float] = (0, 0, 1)) -> Solid ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 沿螺旋路径扫掠轮廓创建实体 @@ -19,63 +19,63 @@ def helical_sweep_rsolid(profile: Wire, pitch: float, height: float, radius: flo - 确保profile的法向量朝向X轴正方向或负方向 - 将profile移动到距离旋转中心指定半径的位置 -## API参数说明 +## Parameters ### profile -- **类型**: `Wire` -- **说明**: 要扫掠的轮廓线,必须是封闭的线轮廓 +- **Type**: `Wire` +- **Description**: 要扫掠的轮廓线,必须是封闭的线轮廓 ### pitch -- **类型**: `float` -- **说明**: 螺距,每转一圈在轴向上的距离,必须为正数 +- **Type**: `float` +- **Description**: 螺距,每转一圈在轴向上的距离,必须为正数 ### height -- **类型**: `float` -- **说明**: 螺旋的总高度,必须为正数 +- **Type**: `float` +- **Description**: 螺旋的总高度,必须为正数 ### radius -- **类型**: `float` -- **说明**: 螺旋的半径,必须为正数 +- **Type**: `float` +- **Description**: 螺旋的半径,必须为正数 ### center -- **类型**: `Tuple[float, float, float], optional` -- **说明**: 螺旋中心点坐标 (x, y, z), 默认为 (0, 0, 0) +- **Type**: `Tuple[float, float, float], optional` +- **Description**: 螺旋中心点坐标 (x, y, z), 默认为 (0, 0, 0) ### dir -- **类型**: `Tuple[float, float, float], optional` -- **说明**: 螺旋轴方向向量 (x, y, z), 默认为 (0, 0, 1) 表示沿Z轴方向 +- **Type**: `Tuple[float, float, float], optional` +- **Description**: 螺旋轴方向向量 (x, y, z), 默认为 (0, 0, 1) 表示沿Z轴方向 -## 返回值说明 +## Returns Solid: 螺旋扫掠后的实体对象 -## 异常 +## Raises - **ValueError**: 当轮廓不封闭、螺距/高度/半径无效或扫掠失败时抛出异常 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 创建螺旋弹簧 circle_profile = make_circle_rwire((0, 0, 0), 0.2) spring = helical_sweep_rsolid(circle_profile, 1.0, 10.0, 2.0) ``` -### 例子 2 +### Example 2 ```python # 创建方形截面的螺旋管 square_profile = make_rectangle_rwire(0.5, 0.5) square_helix = helical_sweep_rsolid(square_profile, 2.0, 8.0, 1.5) ``` -### 例子 3 +### Example 3 ```python # 创建紧密螺旋结构 small_circle = make_circle_rwire((0, 0, 0), 0.1) diff --git a/docs/api/intersect_rsolidlist.md b/docs/api/intersect_rsolidlist.md index 7ee45506..6dabbd8b 100644 --- a/docs/api/intersect_rsolidlist.md +++ b/docs/api/intersect_rsolidlist.md @@ -1,38 +1,38 @@ # intersect_rsolidlist -## API定义 +## API Definition ```python def intersect_rsolidlist(*solids: Union[Solid, Sequence[Solid]]) -> List[Solid] ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 实体交集运算(布尔交集) 计算多个实体的交集,返回只包含所有实体重叠部分的新实体列表。 如果多个实体不相交,可能返回空列表。交集体积小于等于任一输入实体。 -## API参数说明 +## Parameters ### *solids -- **说明**: 需要进行交集运算的实体对象,可以传入: - 单个序列:intersect_rsolidlist([solid1, solid2, ...]) - 多个参数:intersect_rsolidlist(solid1, solid2, ...) - 混合输入:intersect_rsolidlist(solid1, [solid2, solid3], ...),会自动展开所有序列 +- **Description**: 需要进行交集运算的实体对象,可以传入: - 单个序列:intersect_rsolidlist([solid1, solid2, ...]) - 多个参数:intersect_rsolidlist(solid1, solid2, ...) - 混合输入:intersect_rsolidlist(solid1, [solid2, solid3], ...),会自动展开所有序列 -## 返回值说明 +## Returns List[Solid]: 交集运算结果的实体列表。所有输入实体的共同交集部分。 如果没有有效的交集,返回空列表。 -## 异常 +## Raises - **ValueError**: 当输入实体无效或运算失败时抛出异常 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 计算多个实体的交集(两个方式等价) box1 = make_box_rsolid(3, 3, 3, (0, 0, 0)) @@ -43,7 +43,7 @@ intersection2 = intersect_rsolidlist(box1, box2, sphere) # 两种调用方式等价 ``` -### 例子 2 +### Example 2 ```python # 球体和立方体的交集 sphere = make_sphere_rsolid(2.0) @@ -51,7 +51,7 @@ cube = make_box_rsolid(3, 3, 3) rounded_cube = intersect_rsolidlist(sphere, cube) ``` -### 例子 3 +### Example 3 ```python # 三个实体的交集 cylinder = make_cylinder_rsolid(1.5, 4.0) diff --git a/docs/api/linear_pattern_rsolidlist.md b/docs/api/linear_pattern_rsolidlist.md index 12e41727..a053f29e 100644 --- a/docs/api/linear_pattern_rsolidlist.md +++ b/docs/api/linear_pattern_rsolidlist.md @@ -1,53 +1,53 @@ # linear_pattern_rsolidlist -## API定义 +## API Definition ```python def linear_pattern_rsolidlist(shape: AnyShape, direction: Tuple[float, float, float], count: int, spacing: float) -> List[Solid] ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 创建线性阵列 沿指定方向创建几何体的线性阵列,生成指定数量的等间距排列对象。 常用于创建重复结构,如齿轮齿、栅栏、螺栓阵列等。 -## API参数说明 +## Parameters ### shape -- **类型**: `AnyShape` -- **说明**: 要阵列的几何体,可以是任意类型的几何对象 +- **Type**: `AnyShape` +- **Description**: 要阵列的几何体,可以是任意类型的几何对象 ### direction -- **类型**: `Tuple[float, float, float]` -- **说明**: 阵列方向向量 (x, y, z), 定义阵列的方向,会被标准化处理 +- **Type**: `Tuple[float, float, float]` +- **Description**: 阵列方向向量 (x, y, z), 定义阵列的方向,会被标准化处理 ### count -- **类型**: `int` -- **说明**: 阵列数量,必须为正整数,包括原始对象 +- **Type**: `int` +- **Description**: 阵列数量,必须为正整数,包括原始对象 ### spacing -- **类型**: `float` -- **说明**: 阵列间距,必须为正数,定义相邻对象间的距离 +- **Type**: `float` +- **Description**: 阵列间距,必须为正数,定义相邻对象间的距离 -## 返回值说明 +## Returns List[Solid]: 阵列后的几何体列表,包含原始对象和所有复制的对象 -## 异常 +## Raises - **ValueError**: 当阵列数量小于等于0或间距小于等于0时抛出异常 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 创建立方体的线性阵列 box = make_box_rsolid(1, 1, 1) @@ -55,14 +55,14 @@ boxes = linear_pattern_rsolidlist(box, (2, 0, 0), 5, 2.0) # 创建5个立方体,沿X轴方向间距2.0 ``` -### 例子 2 +### Example 2 ```python # 创建圆柱体的对角线阵列 cylinder = make_cylinder_rsolid(0.5, 2.0) cylinders = linear_pattern_rsolidlist(cylinder, (1, 1, 0), 4, 1.5) ``` -### 例子 3 +### Example 3 ```python # 创建复杂几何体的阵列 complex_shape = union_rsolidlist([box, cylinder])[0] diff --git a/docs/api/loft_rsolid.md b/docs/api/loft_rsolid.md index a693abd9..36bcd592 100644 --- a/docs/api/loft_rsolid.md +++ b/docs/api/loft_rsolid.md @@ -1,43 +1,43 @@ # loft_rsolid -## API定义 +## API Definition ```python def loft_rsolid(profiles: List[Wire], ruled: bool = False) -> Solid ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 通过多个轮廓放样创建实体 通过多个二维轮廓创建三维实体,轮廓间通过放样面连接。 常用于创建复杂的过渡形状,如飞机机翼、船体等变截面结构。 -## API参数说明 +## Parameters ### profiles -- **类型**: `List[Wire]` -- **说明**: 轮廓线列表,至少需要2个轮廓, 轮廓按顺序连接,第一个为起始轮廓,最后一个为结束轮廓 +- **Type**: `List[Wire]` +- **Description**: 轮廓线列表,至少需要2个轮廓, 轮廓按顺序连接,第一个为起始轮廓,最后一个为结束轮廓 ### ruled -- **类型**: `bool, optional` -- **说明**: 是否为直纹面,默认为False。 True表示轮廓间用直线连接,False表示用平滑曲面连接 +- **Type**: `bool, optional` +- **Description**: 是否为直纹面,默认为False。 True表示轮廓间用直线连接,False表示用平滑曲面连接 -## 返回值说明 +## Returns Solid: 放样后的实体对象 -## 异常 +## Raises - **ValueError**: 当轮廓少于2个或放样操作失败时抛出异常 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 创建方形到圆形的过渡体 square = make_rectangle_rwire(2, 2, (0, 0, 0)) @@ -45,7 +45,7 @@ circle = make_circle_rwire((0, 0, 3), 1.0) transition = loft_rsolid([square, circle]) ``` -### 例子 2 +### Example 2 ```python # 创建多层过渡的复杂形状 bottom = make_rectangle_rwire(4, 4, (0, 0, 0)) @@ -54,7 +54,7 @@ top = make_rectangle_rwire(1, 1, (0, 0, 4)) complex_shape = loft_rsolid([bottom, middle, top]) ``` -### 例子 3 +### Example 3 ```python # 创建直纹面放样 profile1 = make_circle_rwire((0, 0, 0), 2.0) diff --git a/docs/api/make_angle_arc_redge.md b/docs/api/make_angle_arc_redge.md index e8f2f029..49b49a07 100644 --- a/docs/api/make_angle_arc_redge.md +++ b/docs/api/make_angle_arc_redge.md @@ -1,76 +1,76 @@ # make_angle_arc_redge -## API定义 +## API Definition ```python def make_angle_arc_redge(center: Tuple[float, float, float], radius: float, start_angle: float, end_angle: float, normal: Tuple[float, float, float] = (0, 0, 1)) -> Edge ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 通过角度创建圆弧并返回边对象 通过指定中心点、半径和角度范围创建圆弧边。角度采用度数制, 0度对应X轴正方向,逆时针为正角度。可以创建任意角度范围的圆弧。 -## API参数说明 +## Parameters ### center -- **类型**: `Tuple[float, float, float]` -- **说明**: 圆弧的中心点坐标 (x, y, z) +- **Type**: `Tuple[float, float, float]` +- **Description**: 圆弧的中心点坐标 (x, y, z) ### radius -- **类型**: `float` -- **说明**: 圆弧的半径,必须为正数 +- **Type**: `float` +- **Description**: 圆弧的半径,必须为正数 ### start_angle -- **类型**: `float` -- **说明**: 起始角度,单位为度数(0-360) +- **Type**: `float` +- **Description**: 起始角度,单位为度数(0-360) ### end_angle -- **类型**: `float` -- **说明**: 结束角度,单位为度数(0-360) +- **Type**: `float` +- **Description**: 结束角度,单位为度数(0-360) ### normal -- **类型**: `Tuple[float, float, float], optional` -- **说明**: 圆弧所在平面的法向量 (x, y, z), 默认为 (0, 0, 1) 表示XY平面 +- **Type**: `Tuple[float, float, float], optional` +- **Description**: 圆弧所在平面的法向量 (x, y, z), 默认为 (0, 0, 1) 表示XY平面 -## 返回值说明 +## Returns Edge: 创建的边对象,表示指定角度范围的圆弧 -## 异常 +## Raises - **ValueError**: 当半径小于等于0或其他参数无效时抛出异常 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 创建90度圆弧(从0度到90度) arc_90 = make_angle_arc_redge((0, 0, 0), 2.0, 0, 90) ``` -### 例子 2 +### Example 2 ```python # 创建180度半圆弧 semicircle = make_angle_arc_redge((0, 0, 0), 1.5, 0, 180) ``` -### 例子 3 +### Example 3 ```python # 创建270度圆弧 arc_270 = make_angle_arc_redge((0, 0, 0), 1.0, 45, 315) ``` -### 例子 4 +### Example 4 ```python # 创建垂直平面上的圆弧 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 4574e29b..94676d05 100644 --- a/docs/api/make_angle_arc_rwire.md +++ b/docs/api/make_angle_arc_rwire.md @@ -1,14 +1,14 @@ # make_angle_arc_rwire -## API定义 +## API Definition ```python def make_angle_arc_rwire(center: Tuple[float, float, float], radius: float, start_angle: float, end_angle: float, normal: Tuple[float, float, float] = (0, 0, 1)) -> Wire ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 通过角度创建圆弧并返回线对象 @@ -16,45 +16,45 @@ def make_angle_arc_rwire(center: Tuple[float, float, float], radius: float, star 角度采用度数制,0度对应X轴正方向,逆时针为正角度。 可以创建任意角度范围的圆弧线。 -## API参数说明 +## Parameters ### center -- **说明**: 圆心坐标 +- **Description**: 圆心坐标 ### radius -- **说明**: 半径 +- **Description**: 半径 ### start_angle -- **说明**: 起始角度(弧度) +- **Description**: 起始角度(弧度) ### end_angle -- **说明**: 结束角度(弧度) +- **Description**: 结束角度(弧度) ### normal -- **说明**: 法向量 +- **Description**: 法向量 -## 返回值说明 +## Returns Wire: 线对象,表示通过角度创建的圆弧线 -## 异常 +## Raises - **ValueError**: 当半径小于等于0或其他参数无效时 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 创建90度圆弧线(从0度到90度) arc_90_wire = make_angle_arc_rwire((0, 0, 0), 2.0, 0, 90) ``` -### 例子 2 +### Example 2 ```python # 创建180度半圆弧线 semicircle_wire = make_angle_arc_rwire((0, 0, 0), 1.5, 0, 180) @@ -62,7 +62,7 @@ semicircle_wire = make_angle_arc_rwire((0, 0, 0), 1.5, 0, 180) arc_270_wire = make_angle_arc_rwire((0, 0, 0), 1.0, 45, 315) ``` -### 例子 3 +### Example 3 ```python # 创建垂直平面(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_assembly_rassembly.md b/docs/api/make_assembly_rassembly.md index eba6dd92..0f995ca0 100644 --- a/docs/api/make_assembly_rassembly.md +++ b/docs/api/make_assembly_rassembly.md @@ -1,13 +1,13 @@ # make_assembly_rassembly -## API定义 +## API Definition ```python def make_assembly_rassembly(parts: Sequence[Tuple[str, Solid]], name: str = 'assembly', parents: Optional[Dict[str, str]] = None, local_transforms: Optional[Dict[str, Union[np.ndarray, Sequence[Sequence[float]]]]] = None) -> Assembly ``` -*来源文件: constraints.py* +*Source: constraints.py* -## API作用 +## Description Type-1映射:从参数描述提升到装配对象。 diff --git a/docs/api/make_box_rsolid.md b/docs/api/make_box_rsolid.md index 9d840752..4e4aac28 100644 --- a/docs/api/make_box_rsolid.md +++ b/docs/api/make_box_rsolid.md @@ -1,14 +1,14 @@ # make_box_rsolid -## API定义 +## API Definition ```python def make_box_rsolid(width: float, height: float, depth: float, bottom_face_center: Tuple[float, float, float] = (0, 0, 0)) -> Solid ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 创建立方体并返回实体对象 @@ -16,58 +16,58 @@ def make_box_rsolid(width: float, height: float, depth: float, bottom_face_cente 标签(top、bottom、front、back、left、right),便于后续的面选择操作。 体积等于width×height×depth。 -## API参数说明 +## Parameters ### width -- **类型**: `float` -- **说明**: 立方体的宽度(X方向尺寸),必须为正数 +- **Type**: `float` +- **Description**: 立方体的宽度(X方向尺寸),必须为正数 ### height -- **类型**: `float` -- **说明**: 立方体的高度(Y方向尺寸),必须为正数 +- **Type**: `float` +- **Description**: 立方体的高度(Y方向尺寸),必须为正数 ### depth -- **类型**: `float` -- **说明**: 立方体的深度(Z方向尺寸),必须为正数 +- **Type**: `float` +- **Description**: 立方体的深度(Z方向尺寸),必须为正数 ### bottom_face_center -- **类型**: `Tuple[float, float, float], optional` -- **说明**: 立方体的底面中心坐标 (x, y, z), 默认为 (0, 0, 0),注意这里的中心是立方体底面的中心点 +- **Type**: `Tuple[float, float, float], optional` +- **Description**: 立方体的底面中心坐标 (x, y, z), 默认为 (0, 0, 0),注意这里的中心是立方体底面的中心点 -## 返回值说明 +## Returns Solid: 创建的实体对象,表示一个立方体 -## 异常 +## Raises - **ValueError**: 当宽度、高度或深度小于等于0时抛出异常 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 创建标准单位立方体 unit_cube = make_box_rsolid(1.0, 1.0, 1.0) volume = unit_cube.get_volume() # 体积为1 ``` -### 例子 2 +### Example 2 ```python # 创建矩形立方体 rect_box = make_box_rsolid(4.0, 2.0, 3.0) ``` -### 例子 3 +### Example 3 ```python # 创建偏移的立方体 offset_box = make_box_rsolid(2.0, 2.0, 2.0, (1, 1, 1)) ``` -### 例子 4 +### Example 4 ```python # 获取立方体的面进行后续操作 faces = unit_cube.get_faces() diff --git a/docs/api/make_circle_redge.md b/docs/api/make_circle_redge.md index bff393e5..1752e6be 100644 --- a/docs/api/make_circle_redge.md +++ b/docs/api/make_circle_redge.md @@ -1,60 +1,60 @@ # make_circle_redge -## API定义 +## API Definition ```python def make_circle_redge(center: Tuple[float, float, float], radius: float, normal: Tuple[float, float, float] = (0, 0, 1)) -> Edge ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 创建圆形并返回边对象 创建圆形边对象,用于构建圆形轮廓、圆弧路径等。圆的方向由法向量确定, 支持在任意平面内创建圆形。支持当前坐标系变换。 -## API参数说明 +## Parameters ### center -- **类型**: `Tuple[float, float, float]` -- **说明**: 圆心坐标 (x, y, z),定义圆的中心位置 +- **Type**: `Tuple[float, float, float]` +- **Description**: 圆心坐标 (x, y, z),定义圆的中心位置 ### radius -- **类型**: `float` -- **说明**: 圆的半径,必须为正数 +- **Type**: `float` +- **Description**: 圆的半径,必须为正数 ### normal -- **类型**: `Tuple[float, float, float], optional` -- **说明**: 圆所在平面的法向量 (x, y, z), 默认为 (0, 0, 1) 表示XY平面 +- **Type**: `Tuple[float, float, float], optional` +- **Description**: 圆所在平面的法向量 (x, y, z), 默认为 (0, 0, 1) 表示XY平面 -## 返回值说明 +## Returns Edge: 创建的边对象,表示一个完整的圆形 -## 异常 +## Raises - **ValueError**: 当半径小于等于0或其他参数无效时抛出异常 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 创建XY平面上的圆 circle = make_circle_redge((0, 0, 0), 2.0) ``` -### 例子 2 +### Example 2 ```python # 创建垂直平面上的圆 vertical_circle = make_circle_redge((0, 0, 0), 1.5, (1, 0, 0)) ``` -### 例子 3 +### Example 3 ```python # 创建指定位置的圆 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 5350cdc2..68a94d58 100644 --- a/docs/api/make_circle_rface.md +++ b/docs/api/make_circle_rface.md @@ -1,55 +1,55 @@ # make_circle_rface -## API定义 +## API Definition ```python def make_circle_rface(center: Tuple[float, float, float], radius: float, normal: Tuple[float, float, float] = (0, 0, 1)) -> Face ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 创建圆形并返回面对象 创建圆形面对象,用于构建实心圆形截面。可以用于拉伸、旋转等操作来创建 圆柱体、圆锥体等三维几何体。面积等于πr²。 -## API参数说明 +## Parameters ### center -- **类型**: `Tuple[float, float, float]` -- **说明**: 圆心坐标 (x, y, z),定义圆的中心位置 +- **Type**: `Tuple[float, float, float]` +- **Description**: 圆心坐标 (x, y, z),定义圆的中心位置 ### radius -- **类型**: `float` -- **说明**: 圆的半径,必须为正数 +- **Type**: `float` +- **Description**: 圆的半径,必须为正数 ### normal -- **类型**: `Tuple[float, float, float], optional` -- **说明**: 圆所在平面的法向量 (x, y, z), 默认为 (0, 0, 1) 表示XY平面 +- **Type**: `Tuple[float, float, float], optional` +- **Description**: 圆所在平面的法向量 (x, y, z), 默认为 (0, 0, 1) 表示XY平面 -## 返回值说明 +## Returns Face: 创建的面对象,表示一个实心的圆形面 -## 异常 +## Raises - **ValueError**: 当半径小于等于0或其他参数无效时抛出异常 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 创建标准圆形面 circle_face = make_circle_rface((0, 0, 0), 2.0) area = circle_face.get_area() # 面积为π×2²≈12.57 ``` -### 例子 2 +### Example 2 ```python # 创建用于拉伸的圆形截面 profile = make_circle_rface((0, 0, 0), 1.0) diff --git a/docs/api/make_circle_rwire.md b/docs/api/make_circle_rwire.md index 101469d4..e6955105 100644 --- a/docs/api/make_circle_rwire.md +++ b/docs/api/make_circle_rwire.md @@ -1,54 +1,54 @@ # make_circle_rwire -## API定义 +## API Definition ```python def make_circle_rwire(center: Tuple[float, float, float], radius: float, normal: Tuple[float, float, float] = (0, 0, 1)) -> Wire ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 创建圆形并返回线对象 创建圆形线对象,用于构建封闭的圆形轮廓。与make_circle_redge不同, 此函数返回的是线对象,可以直接用于创建面或进行其他线操作。 -## API参数说明 +## Parameters ### center -- **类型**: `Tuple[float, float, float]` -- **说明**: 圆心坐标 (x, y, z),定义圆的中心位置 +- **Type**: `Tuple[float, float, float]` +- **Description**: 圆心坐标 (x, y, z),定义圆的中心位置 ### radius -- **类型**: `float` -- **说明**: 圆的半径,必须为正数 +- **Type**: `float` +- **Description**: 圆的半径,必须为正数 ### normal -- **类型**: `Tuple[float, float, float], optional` -- **说明**: 圆所在平面的法向量 (x, y, z), 默认为 (0, 0, 1) 表示XY平面 +- **Type**: `Tuple[float, float, float], optional` +- **Description**: 圆所在平面的法向量 (x, y, z), 默认为 (0, 0, 1) 表示XY平面 -## 返回值说明 +## Returns Wire: 创建的线对象,表示一个完整的圆形轮廓 -## 异常 +## Raises - **ValueError**: 当半径小于等于0或其他参数无效时抛出异常 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 创建标准圆形轮廓 circle_wire = make_circle_rwire((0, 0, 0), 3.0) ``` -### 例子 2 +### Example 2 ```python # 创建小圆轮廓 small_circle = make_circle_rwire((1, 1, 0), 0.5) diff --git a/docs/api/make_cone_rsolid.md b/docs/api/make_cone_rsolid.md index 922e8ea5..a661edaa 100644 --- a/docs/api/make_cone_rsolid.md +++ b/docs/api/make_cone_rsolid.md @@ -1,65 +1,65 @@ # make_cone_rsolid -## API定义 +## API Definition ```python def make_cone_rsolid(bottom_radius: float, height: float, top_radius: float = 0.0, bottom_face_center: Tuple[float, float, float] = (0, 0, 0), axis: Tuple[float, float, float] = (0, 0, 1)) -> Solid ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 创建圆锥体并返回实体对象 创建圆锥体实体,是基础的三维几何体之一。自动为圆锥体的面添加标签 (top、bottom、conical),便于后续的面选择操作。 -## API参数说明 +## Parameters ### bottom_radius -- **类型**: `float` -- **说明**: 圆锥体的底面半径,必须为正数 +- **Type**: `float` +- **Description**: 圆锥体的底面半径,必须为正数 ### height -- **类型**: `float` -- **说明**: 圆锥体的高度,必须为正数 +- **Type**: `float` +- **Description**: 圆锥体的高度,必须为正数 ### top_radius -- **类型**: `float, optional` -- **说明**: 圆锥体的顶面半径,默认为0.0(尖锥) +- **Type**: `float, optional` +- **Description**: 圆锥体的顶面半径,默认为0.0(尖锥) ### bottom_face_center -- **类型**: `Tuple[float, float, float], optional` -- **说明**: 圆锥体底面中心坐标 (x, y, z), 默认为 (0, 0, 0) +- **Type**: `Tuple[float, float, float], optional` +- **Description**: 圆锥体底面中心坐标 (x, y, z), 默认为 (0, 0, 0) ### axis -- **类型**: `Tuple[float, float, float], optional` -- **说明**: 圆锥体的轴向向量 (x, y, z), 定义圆锥体的方向,默认为 (0, 0, 1) 表示沿Z轴方向 +- **Type**: `Tuple[float, float, float], optional` +- **Description**: 圆锥体的轴向向量 (x, y, z), 定义圆锥体的方向,默认为 (0, 0, 1) 表示沿Z轴方向 -## 返回值说明 +## Returns Solid: 创建的实体对象,表示一个圆锥体 -## 异常 +## Raises - **ValueError**: 当半径或高度小于等于0时抛出异常 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 创建标准圆锥体(尖锥) cone = make_cone_rsolid(2.0, 5.0) volume = cone.get_volume() # 体积为(1/3)π×2²×5≈20.94 ``` -### 例子 2 +### Example 2 ```python # 创建截锥体 truncated_cone = make_cone_rsolid(3.0, 4.0, 1.0) diff --git a/docs/api/make_cylinder_rsolid.md b/docs/api/make_cylinder_rsolid.md index 5ac73d8b..56521d95 100644 --- a/docs/api/make_cylinder_rsolid.md +++ b/docs/api/make_cylinder_rsolid.md @@ -1,72 +1,72 @@ # make_cylinder_rsolid -## API定义 +## API Definition ```python def make_cylinder_rsolid(radius: float, height: float, bottom_face_center: Tuple[float, float, float] = (0, 0, 0), axis: Tuple[float, float, float] = (0, 0, 1)) -> Solid ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 创建圆柱体并返回实体对象 创建圆柱体实体,是基础的三维几何体之一。自动为圆柱体的面添加标签 (top、bottom、cylindrical),便于后续的面选择操作。体积等于πr²h。 -## API参数说明 +## Parameters ### radius -- **类型**: `float` -- **说明**: 圆柱体的半径,必须为正数 +- **Type**: `float` +- **Description**: 圆柱体的半径,必须为正数 ### height -- **类型**: `float` -- **说明**: 圆柱体的高度,必须为正数 +- **Type**: `float` +- **Description**: 圆柱体的高度,必须为正数 ### bottom_face_center -- **类型**: `Tuple[float, float, float], optional` -- **说明**: 圆柱体底面中心坐标 (x, y, z), 默认为 (0, 0, 0) +- **Type**: `Tuple[float, float, float], optional` +- **Description**: 圆柱体底面中心坐标 (x, y, z), 默认为 (0, 0, 0) ### axis -- **类型**: `Tuple[float, float, float], optional` -- **说明**: 圆柱体的轴向向量 (x, y, z), 定义圆柱体的方向,默认为 (0, 0, 1) 表示沿Z轴方向 +- **Type**: `Tuple[float, float, float], optional` +- **Description**: 圆柱体的轴向向量 (x, y, z), 定义圆柱体的方向,默认为 (0, 0, 1) 表示沿Z轴方向 -## 返回值说明 +## Returns Solid: 创建的实体对象,表示一个圆柱体 -## 异常 +## Raises - **ValueError**: 当半径或高度小于等于0时抛出异常 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 创建标准圆柱体 cylinder = make_cylinder_rsolid(2.0, 5.0) volume = cylinder.get_volume() # 体积为π×2²×5≈62.83 ``` -### 例子 2 +### Example 2 ```python # 创建水平圆柱体 horizontal_cyl = make_cylinder_rsolid(radius=1.0, height=4.0, bottom_face_center=(0, 0, 0), axis=(1, 0, 0)) ``` -### 例子 3 +### Example 3 ```python # 创建偏移的圆柱体,底面中心在(2, 2, 0) offset_cyl = make_cylinder_rsolid(1.5, 3.0, (2, 2, 0)) ``` -### 例子 4 +### Example 4 ```python # 获取圆柱体的面进行后续操作 faces = cylinder.get_faces() diff --git a/docs/api/make_face_from_wire_rface.md b/docs/api/make_face_from_wire_rface.md index b6b05c5d..60165666 100644 --- a/docs/api/make_face_from_wire_rface.md +++ b/docs/api/make_face_from_wire_rface.md @@ -1,57 +1,57 @@ # make_face_from_wire_rface -## API定义 +## API Definition ```python def make_face_from_wire_rface(wire: Wire, normal: Tuple[float, float, float] = (0, 0, 1)) -> Face ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 从封闭的线对象创建面对象 将封闭的线轮廓转换为面对象,用于从复杂的线框轮廓创建面。输入的线必须 是封闭的,函数会检查面的法向量方向,如果与期望方向相反会发出警告。 -## API参数说明 +## Parameters ### wire -- **类型**: `Wire` -- **说明**: 输入的线对象,必须是封闭的线轮廓 +- **Type**: `Wire` +- **Description**: 输入的线对象,必须是封闭的线轮廓 ### normal -- **类型**: `Tuple[float, float, float], optional` -- **说明**: 期望的面法向量 (x, y, z), 用于确定面的方向,默认为 (0, 0, 1) +- **Type**: `Tuple[float, float, float], optional` +- **Description**: 期望的面法向量 (x, y, z), 用于确定面的方向,默认为 (0, 0, 1) -## 返回值说明 +## Returns Face: 创建的面对象,由输入的线轮廓围成的面 -## 异常 +## Raises - **ValueError**: 当输入的线对象无效、不封闭或创建面失败时抛出异常 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 从矩形线创建面 rect_wire = make_rectangle_rwire(3.0, 2.0) rect_face = make_face_from_wire_rface(rect_wire) ``` -### 例子 2 +### Example 2 ```python # 从圆形线创建面 circle_wire = make_circle_rwire((0, 0, 0), 1.5) circle_face = make_face_from_wire_rface(circle_wire) ``` -### 例子 3 +### Example 3 ```python # 从多边形线创建面 points = [(0, 0, 0), (2, 0, 0), (2, 2, 0), (0, 2, 0)] diff --git a/docs/api/make_helix_redge.md b/docs/api/make_helix_redge.md index f40cd0ea..578879c1 100644 --- a/docs/api/make_helix_redge.md +++ b/docs/api/make_helix_redge.md @@ -1,70 +1,70 @@ # make_helix_redge -## API定义 +## API Definition ```python def make_helix_redge(pitch: float, height: float, radius: float, center: Tuple[float, float, float] = (0, 0, 0), dir: Tuple[float, float, float] = (0, 0, 1)) -> Edge ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 创建螺旋线并返回边对象 创建螺旋线边对象,用于构建螺旋形状的路径或进行螺旋扫掠。 螺旋线绕指定轴旋转,同时沿轴向移动,形成螺旋形状。 -## API参数说明 +## Parameters ### pitch -- **类型**: `float` -- **说明**: 螺距,每转一圈在轴向上的距离,必须为正数 +- **Type**: `float` +- **Description**: 螺距,每转一圈在轴向上的距离,必须为正数 ### height -- **类型**: `float` -- **说明**: 螺旋线的总高度,必须为正数 +- **Type**: `float` +- **Description**: 螺旋线的总高度,必须为正数 ### radius -- **类型**: `float` -- **说明**: 螺旋线的半径,必须为正数 +- **Type**: `float` +- **Description**: 螺旋线的半径,必须为正数 ### center -- **类型**: `Tuple[float, float, float], optional` -- **说明**: 螺旋线的中心点坐标 (x, y, z), 默认为 (0, 0, 0) +- **Type**: `Tuple[float, float, float], optional` +- **Description**: 螺旋线的中心点坐标 (x, y, z), 默认为 (0, 0, 0) ### dir -- **类型**: `Tuple[float, float, float], optional` -- **说明**: 螺旋轴的方向向量 (x, y, z), 默认为 (0, 0, 1) 表示沿Z轴方向 +- **Type**: `Tuple[float, float, float], optional` +- **Description**: 螺旋轴的方向向量 (x, y, z), 默认为 (0, 0, 1) 表示沿Z轴方向 -## 返回值说明 +## Returns Edge: 创建的边对象,表示一个螺旋线 -## 异常 +## Raises - **ValueError**: 当螺距、高度或半径小于等于0时抛出异常 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 创建标准螺旋线 helix = make_helix_redge(2.0, 10.0, 1.0) # 螺距2,高度10,半径1 ``` -### 例子 2 +### Example 2 ```python # 创建紧密螺旋线 tight_helix = make_helix_redge(0.5, 5.0, 0.5) ``` -### 例子 3 +### Example 3 ```python # 创建水平螺旋线 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 ad3032d5..1da8dbd6 100644 --- a/docs/api/make_helix_rwire.md +++ b/docs/api/make_helix_rwire.md @@ -1,64 +1,64 @@ # make_helix_rwire -## API定义 +## API Definition ```python def make_helix_rwire(pitch: float, height: float, radius: float, center: Tuple[float, float, float] = (0, 0, 0), dir: Tuple[float, float, float] = (0, 0, 1)) -> Wire ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 创建螺旋线并返回线对象 创建螺旋线线对象,与make_helix_redge功能相同但返回线对象。 可以用于后续的扫掠操作或作为复杂路径的一部分。 -## API参数说明 +## Parameters ### pitch -- **类型**: `float` -- **说明**: 螺距,每转一圈在轴向上的距离,必须为正数 +- **Type**: `float` +- **Description**: 螺距,每转一圈在轴向上的距离,必须为正数 ### height -- **类型**: `float` -- **说明**: 螺旋线的总高度,必须为正数 +- **Type**: `float` +- **Description**: 螺旋线的总高度,必须为正数 ### radius -- **类型**: `float` -- **说明**: 螺旋线的半径,必须为正数 +- **Type**: `float` +- **Description**: 螺旋线的半径,必须为正数 ### center -- **类型**: `Tuple[float, float, float], optional` -- **说明**: 螺旋线的中心点坐标 (x, y, z), 默认为 (0, 0, 0) +- **Type**: `Tuple[float, float, float], optional` +- **Description**: 螺旋线的中心点坐标 (x, y, z), 默认为 (0, 0, 0) ### dir -- **类型**: `Tuple[float, float, float], optional` -- **说明**: 螺旋轴的方向向量 (x, y, z), 默认为 (0, 0, 1) 表示沿Z轴方向 +- **Type**: `Tuple[float, float, float], optional` +- **Description**: 螺旋轴的方向向量 (x, y, z), 默认为 (0, 0, 1) 表示沿Z轴方向 -## 返回值说明 +## Returns Wire: 创建的线对象,包含一个螺旋线 -## 异常 +## Raises - **ValueError**: 当螺距、高度或半径小于等于0时抛出异常 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 创建螺旋线线对象 helix_wire = make_helix_rwire(1.5, 6.0, 1.0) ``` -### 例子 2 +### Example 2 ```python # 用于扫掠操作的螺旋路径 profile = make_circle_rface((0, 0, 0), 0.1) diff --git a/docs/api/make_line_redge.md b/docs/api/make_line_redge.md index 4158886f..41b3d0e3 100644 --- a/docs/api/make_line_redge.md +++ b/docs/api/make_line_redge.md @@ -1,55 +1,55 @@ # make_line_redge -## API定义 +## API Definition ```python def make_line_redge(start: Tuple[float, float, float], end: Tuple[float, float, float]) -> Edge ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 创建两点之间的直线段并返回边对象 创建两点之间的直线段,是构建复杂几何形状的基础元素。可用于构造线框、 创建草图轮廓、定义路径等。支持当前坐标系变换。 -## API参数说明 +## Parameters ### start -- **类型**: `Tuple[float, float, float]` -- **说明**: 起始点坐标 (x, y, z),定义线段的起点 +- **Type**: `Tuple[float, float, float]` +- **Description**: 起始点坐标 (x, y, z),定义线段的起点 ### end -- **类型**: `Tuple[float, float, float]` -- **说明**: 结束点坐标 (x, y, z),定义线段的终点 +- **Type**: `Tuple[float, float, float]` +- **Description**: 结束点坐标 (x, y, z),定义线段的终点 -## 返回值说明 +## Returns Edge: 创建的边对象,表示连接两点的直线段 -## 异常 +## Raises - **ValueError**: 当坐标无效或起始点与结束点重合时抛出异常 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 创建水平线段 line = make_line_redge((0, 0, 0), (5, 0, 0)) ``` -### 例子 2 +### Example 2 ```python # 创建三维空间中的线段 line_3d = make_line_redge((1, 1, 1), (3, 2, 4)) ``` -### 例子 3 +### Example 3 ```python # 在工作平面中创建线段 with SimpleWorkplane((0, 0, 1)): diff --git a/docs/api/make_n_hole_flange_rsolid.md b/docs/api/make_n_hole_flange_rsolid.md index 8e1bdb7e..15b9e1ad 100644 --- a/docs/api/make_n_hole_flange_rsolid.md +++ b/docs/api/make_n_hole_flange_rsolid.md @@ -1,14 +1,14 @@ # make_n_hole_flange_rsolid -## API定义 +## API Definition ```python def make_n_hole_flange_rsolid(flange_outer_diameter = 120.0, flange_inner_diameter = 60.0, flange_thickness = 15.0, boss_outer_diameter = 80.0, boss_height = 5.0, hole_diameter = 8.0, hole_circle_diameter = 100.0, hole_count = 8, chamfer_size = 1.0) -> Solid ``` -*来源文件: evolve.py* +*Source: evolve.py* -## API作用 +## Description 创建n孔法兰,包含中心凸起圆环和倒角,最终法兰的底面中心在原点(0,0,0) @@ -19,64 +19,64 @@ def make_n_hole_flange_rsolid(flange_outer_diameter = 120.0, flange_inner_diamet 连接孔体积:连接孔体积 倒角体积:倒角体积 -## API参数说明 +## Parameters ### flange_outer_diameter -- **类型**: `float` -- **说明**: 法兰外径 +- **Type**: `float` +- **Description**: 法兰外径 ### flange_inner_diameter -- **类型**: `float` -- **说明**: 法兰内径 +- **Type**: `float` +- **Description**: 法兰内径 ### flange_thickness -- **类型**: `float` -- **说明**: 法兰厚度 +- **Type**: `float` +- **Description**: 法兰厚度 ### boss_outer_diameter -- **类型**: `float` -- **说明**: 凸起圆环外径 +- **Type**: `float` +- **Description**: 凸起圆环外径 ### boss_height -- **类型**: `float` -- **说明**: 凸起圆环高度 +- **Type**: `float` +- **Description**: 凸起圆环高度 ### hole_diameter -- **类型**: `float` -- **说明**: 连接孔直径 +- **Type**: `float` +- **Description**: 连接孔直径 ### hole_circle_diameter -- **类型**: `float` -- **说明**: 连接孔分布圆直径 +- **Type**: `float` +- **Description**: 连接孔分布圆直径 ### hole_count -- **类型**: `int` -- **说明**: 连接孔数量 +- **Type**: `int` +- **Description**: 连接孔数量 ### chamfer_size -- **类型**: `float` -- **说明**: 倒角尺寸 +- **Type**: `float` +- **Description**: 倒角尺寸 -## 返回值说明 +## Returns Solid: 创建的n孔法兰 -## 异常 +## Raises - **ValueError**: 如果在创建法兰主体、切割内孔、或后续几何操作过程中发生错误(如几何体重叠、尺寸不合理等),会抛出该异常。 - **TypeError**: 如果传入的参数类型不正确(如应为float却传入了str等),会抛出该异常。 - **ValueError**: 如果参数值不在合理范围(如直径为负数、孔数量小于1、内径大于外径等),会抛出该异常。 -## API使用例子 +## Examples ```python flange = make_n_hole_flange_rsolid( diff --git a/docs/api/make_naca_propeller_blade_rsolid.md b/docs/api/make_naca_propeller_blade_rsolid.md index 3a93d7e5..151fc8c6 100644 --- a/docs/api/make_naca_propeller_blade_rsolid.md +++ b/docs/api/make_naca_propeller_blade_rsolid.md @@ -1,14 +1,14 @@ # make_naca_propeller_blade_rsolid -## API定义 +## API Definition ```python def make_naca_propeller_blade_rsolid(blade_length = 5.0, root_chord = 1.5, tip_chord = 0.3, total_twist_angle = 45.0, num_sections = 7, t_c = 0.16) -> Solid ``` -*来源文件: evolve.py* +*Source: evolve.py* -## API作用 +## Description 创建单个螺旋桨叶片模型, 默认使用NACA0016翼型,扭转45度,7个截面,厚度比16% 最终桨叶的根部在原点,桨叶沿着Z轴方向延伸 @@ -16,50 +16,50 @@ def make_naca_propeller_blade_rsolid(blade_length = 5.0, root_chord = 1.5, tip_c 创建单个螺旋桨叶片模型, 默认使用NACA0016翼型,扭转45度,7个截面,厚度比16% 厚度比:翼型厚度比(0.0到1.0), NACA0016为0.16 -## API参数说明 +## Parameters ### blade_length -- **类型**: `float` -- **说明**: 桨叶径向长度 +- **Type**: `float` +- **Description**: 桨叶径向长度 ### root_chord -- **类型**: `float` -- **说明**: 桨叶根部弦长 +- **Type**: `float` +- **Description**: 桨叶根部弦长 ### tip_chord -- **类型**: `float` -- **说明**: 桨叶叶尖弦长 +- **Type**: `float` +- **Description**: 桨叶叶尖弦长 ### total_twist_angle -- **类型**: `float` -- **说明**: 桨叶从根部到叶尖的总扭转角度(度) +- **Type**: `float` +- **Description**: 桨叶从根部到叶尖的总扭转角度(度) ### num_sections -- **类型**: `int` -- **说明**: 沿径向生成的截面数量 +- **Type**: `int` +- **Description**: 沿径向生成的截面数量 ### t_c -- **类型**: `float` -- **说明**: 翼型厚度比(0.0到1.0), NACA0016为0.16 +- **Type**: `float` +- **Description**: 翼型厚度比(0.0到1.0), NACA0016为0.16 -## 返回值说明 +## Returns Solid: 螺旋桨叶片实体 -## 异常 +## Raises - **ValueError**: 如果翼型截面生成失败,可能是NACA翼型计算或几何变换失败 - **ValueError**: 如果截面数量不足,需要至少2个截面 - **ValueError**: 如果放样结果不是有效的Solid对象 - **ValueError**: 如果翼型厚度比超出有效范围(0.0到1.0) -## API使用例子 +## Examples ```python # 创建一个扭转45度,7个截面,厚度比16%的螺旋桨叶片 diff --git a/docs/api/make_point_rvertex.md b/docs/api/make_point_rvertex.md index c0ae1a4d..285b7635 100644 --- a/docs/api/make_point_rvertex.md +++ b/docs/api/make_point_rvertex.md @@ -1,60 +1,60 @@ # make_point_rvertex -## API定义 +## API Definition ```python def make_point_rvertex(x: float, y: float, z: float) -> Vertex ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 创建三维空间中的点并返回顶点对象 创建三维空间中的几何点,通常用作其他几何对象的构造参数,如作为线段的端点、 圆弧的控制点等。支持当前坐标系变换。 -## API参数说明 +## Parameters ### x -- **类型**: `float` -- **说明**: X坐标值,用于定义点在X轴方向的位置 +- **Type**: `float` +- **Description**: X坐标值,用于定义点在X轴方向的位置 ### y -- **类型**: `float` -- **说明**: Y坐标值,用于定义点在Y轴方向的位置 +- **Type**: `float` +- **Description**: Y坐标值,用于定义点在Y轴方向的位置 ### z -- **类型**: `float` -- **说明**: Z坐标值,用于定义点在Z轴方向的位置 +- **Type**: `float` +- **Description**: Z坐标值,用于定义点在Z轴方向的位置 -## 返回值说明 +## Returns Vertex: 创建的顶点对象,包含指定坐标的点 -## 异常 +## Raises - **ValueError**: 当坐标无效时抛出异常 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 创建原点 origin = make_point_rvertex(0, 0, 0) ``` -### 例子 2 +### Example 2 ```python # 创建指定坐标的点 point = make_point_rvertex(1.5, 2.0, 3.0) ``` -### 例子 3 +### Example 3 ```python # 在工作平面中创建点 with SimpleWorkplane((1, 1, 1)): diff --git a/docs/api/make_polyline_rwire.md b/docs/api/make_polyline_rwire.md index ca5aa410..9f5bcb86 100644 --- a/docs/api/make_polyline_rwire.md +++ b/docs/api/make_polyline_rwire.md @@ -1,57 +1,57 @@ # make_polyline_rwire -## API定义 +## API Definition ```python def make_polyline_rwire(points: List[Tuple[float, float, float]], closed: bool = False) -> Wire ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 创建多段线并返回线对象 创建由多个直线段连接的多段线,用于构建折线、多边形轮廓等。 相邻点之间用直线连接,可以创建开放或闭合的多段线。 -## API参数说明 +## Parameters ### points -- **类型**: `List[Tuple[float, float, float]]` -- **说明**: 顶点坐标列表 [(x, y, z), ...], 至少需要2个点,相邻点之间用直线连接 +- **Type**: `List[Tuple[float, float, float]]` +- **Description**: 顶点坐标列表 [(x, y, z), ...], 至少需要2个点,相邻点之间用直线连接 ### closed -- **类型**: `bool, optional` -- **说明**: 是否创建闭合的多段线,默认为False。 如果为True,会自动连接最后一个点和第一个点 +- **Type**: `bool, optional` +- **Description**: 是否创建闭合的多段线,默认为False。 如果为True,会自动连接最后一个点和第一个点 -## 返回值说明 +## Returns Wire: 创建的线对象,由多个直线段组成的多段线 -## 异常 +## Raises - **ValueError**: 当顶点少于2个时抛出异常 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 创建L形多段线 points = [(0, 0, 0), (3, 0, 0), (3, 2, 0)] l_shape = make_polyline_rwire(points) ``` -### 例子 2 +### Example 2 ```python # 创建三角形轮廓 triangle_points = [(0, 0, 0), (2, 0, 0), (1, 2, 0)] triangle = make_polyline_rwire(triangle_points, closed=True) ``` -### 例子 3 +### Example 3 ```python # 创建复杂的多边形 polygon_points = [(0, 0, 0), (2, 0, 0), (3, 1, 0), (2, 2, 0), (0, 2, 0)] diff --git a/docs/api/make_rectangle_rface.md b/docs/api/make_rectangle_rface.md index 4fbfcb91..07f7f20d 100644 --- a/docs/api/make_rectangle_rface.md +++ b/docs/api/make_rectangle_rface.md @@ -1,60 +1,60 @@ # make_rectangle_rface -## API定义 +## API Definition ```python def make_rectangle_rface(width: float, height: float, center: Tuple[float, float, float] = (0, 0, 0), normal: Tuple[float, float, float] = (0, 0, 1)) -> Face ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 创建矩形并返回面对象 创建矩形面对象,用于构建实心矩形截面。可以用于拉伸、旋转等操作来创建 立方体、棱柱等三维几何体。面积等于width×height。 -## API参数说明 +## Parameters ### width -- **类型**: `float` -- **说明**: 矩形的宽度,必须为正数 +- **Type**: `float` +- **Description**: 矩形的宽度,必须为正数 ### height -- **类型**: `float` -- **说明**: 矩形的高度,必须为正数 +- **Type**: `float` +- **Description**: 矩形的高度,必须为正数 ### center -- **类型**: `Tuple[float, float, float], optional` -- **说明**: 矩形中心坐标 (x, y, z), 默认为 (0, 0, 0) +- **Type**: `Tuple[float, float, float], optional` +- **Description**: 矩形中心坐标 (x, y, z), 默认为 (0, 0, 0) ### normal -- **类型**: `Tuple[float, float, float], optional` -- **说明**: 矩形所在平面的法向量 (x, y, z), 默认为 (0, 0, 1) 表示XY平面 +- **Type**: `Tuple[float, float, float], optional` +- **Description**: 矩形所在平面的法向量 (x, y, z), 默认为 (0, 0, 1) 表示XY平面 -## 返回值说明 +## Returns Face: 创建的面对象,表示一个实心的矩形面 -## 异常 +## Raises - **ValueError**: 当宽度或高度小于等于0或其他参数无效时抛出异常 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 创建标准矩形面 rect_face = make_rectangle_rface(5.0, 3.0) area = rect_face.get_area() # 面积为5×3=15 ``` -### 例子 2 +### Example 2 ```python # 创建用于拉伸的矩形截面 profile = make_rectangle_rface(2.0, 2.0) diff --git a/docs/api/make_rectangle_rwire.md b/docs/api/make_rectangle_rwire.md index 46ed39ae..5fcfab8a 100644 --- a/docs/api/make_rectangle_rwire.md +++ b/docs/api/make_rectangle_rwire.md @@ -1,65 +1,65 @@ # make_rectangle_rwire -## API定义 +## API Definition ```python def make_rectangle_rwire(width: float, height: float, center: Tuple[float, float, float] = (0, 0, 0), normal: Tuple[float, float, float] = (0, 0, 1)) -> Wire ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 创建矩形并返回线对象 创建矩形线对象,用于构建矩形轮廓。矩形以指定中心点为中心,在指定平面内 创建。可以用于构建复杂的多边形轮廓或作为拉伸的基础轮廓。 -## API参数说明 +## Parameters ### width -- **类型**: `float` -- **说明**: 矩形的宽度,必须为正数 +- **Type**: `float` +- **Description**: 矩形的宽度,必须为正数 ### height -- **类型**: `float` -- **说明**: 矩形的高度,必须为正数 +- **Type**: `float` +- **Description**: 矩形的高度,必须为正数 ### center -- **类型**: `Tuple[float, float, float], optional` -- **说明**: 矩形中心坐标 (x, y, z), 默认为 (0, 0, 0) +- **Type**: `Tuple[float, float, float], optional` +- **Description**: 矩形中心坐标 (x, y, z), 默认为 (0, 0, 0) ### normal -- **类型**: `Tuple[float, float, float], optional` -- **说明**: 矩形所在平面的法向量 (x, y, z), 默认为 (0, 0, 1) 表示XY平面 +- **Type**: `Tuple[float, float, float], optional` +- **Description**: 矩形所在平面的法向量 (x, y, z), 默认为 (0, 0, 1) 表示XY平面 -## 返回值说明 +## Returns Wire: 创建的线对象,表示一个封闭的矩形轮廓 -## 异常 +## Raises - **ValueError**: 当宽度或高度小于等于0或其他参数无效时抛出异常 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 创建标准矩形轮廓 rect = make_rectangle_rwire(4.0, 3.0) ``` -### 例子 2 +### Example 2 ```python # 创建偏移的矩形 offset_rect = make_rectangle_rwire(2.0, 2.0, (1, 1, 0)) ``` -### 例子 3 +### Example 3 ```python # 创建垂直平面上的矩形 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 fcdd9883..245224b2 100644 --- a/docs/api/make_segment_redge.md +++ b/docs/api/make_segment_redge.md @@ -1,45 +1,45 @@ # make_segment_redge -## API定义 +## API Definition ```python def make_segment_redge(start: Tuple[float, float, float], end: Tuple[float, float, float]) -> Edge ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 创建线段并返回边对象(make_line_redge的别名函数) 与make_line_redge功能完全相同,提供更直观的函数名称。用于创建两点之间的 直线段,是构建复杂几何形状的基础元素。 -## API参数说明 +## Parameters ### start -- **类型**: `Tuple[float, float, float]` -- **说明**: 起始点坐标 (x, y, z),定义线段的起点 +- **Type**: `Tuple[float, float, float]` +- **Description**: 起始点坐标 (x, y, z),定义线段的起点 ### end -- **类型**: `Tuple[float, float, float]` -- **说明**: 结束点坐标 (x, y, z),定义线段的终点 +- **Type**: `Tuple[float, float, float]` +- **Description**: 结束点坐标 (x, y, z),定义线段的终点 -## 返回值说明 +## Returns Edge: 创建的边对象,表示连接两点的直线段 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 创建垂直线段 vertical_line = make_segment_redge((0, 0, 0), (0, 0, 5)) ``` -### 例子 2 +### Example 2 ```python # 创建对角线段 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 942b7373..34151f6b 100644 --- a/docs/api/make_segment_rwire.md +++ b/docs/api/make_segment_rwire.md @@ -1,49 +1,49 @@ # make_segment_rwire -## API定义 +## API Definition ```python def make_segment_rwire(start: Tuple[float, float, float], end: Tuple[float, float, float]) -> Wire ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 创建线段并返回线对象 创建包含单个线段的线对象,用于构建更复杂的线框结构。与make_segment_redge 不同,此函数返回的是线对象,可以与其他线对象连接形成复杂路径。 -## API参数说明 +## Parameters ### start -- **类型**: `Tuple[float, float, float]` -- **说明**: 起始点坐标 (x, y, z),定义线段的起点 +- **Type**: `Tuple[float, float, float]` +- **Description**: 起始点坐标 (x, y, z),定义线段的起点 ### end -- **类型**: `Tuple[float, float, float]` -- **说明**: 结束点坐标 (x, y, z),定义线段的终点 +- **Type**: `Tuple[float, float, float]` +- **Description**: 结束点坐标 (x, y, z),定义线段的终点 -## 返回值说明 +## Returns Wire: 创建的线对象,包含一个连接两点的直线段 -## 异常 +## Raises - **ValueError**: 当坐标无效或创建线对象失败时抛出异常 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 创建基本线段线 wire = make_segment_rwire((0, 0, 0), (3, 0, 0)) ``` -### 例子 2 +### Example 2 ```python # 创建斜线段 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 186d5cec..83844d63 100644 --- a/docs/api/make_sphere_rsolid.md +++ b/docs/api/make_sphere_rsolid.md @@ -1,62 +1,62 @@ # make_sphere_rsolid -## API定义 +## API Definition ```python def make_sphere_rsolid(radius: float, center: Tuple[float, float, float] = (0, 0, 0)) -> Solid ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 创建球体并返回实体对象 创建球体实体,是基础的三维几何体之一。自动为球体的面添加标签(surface), 便于后续的面选择操作。体积等于(4/3)πr³。 -## API参数说明 +## Parameters ### radius -- **类型**: `float` -- **说明**: 球体的半径,必须为正数 +- **Type**: `float` +- **Description**: 球体的半径,必须为正数 ### center -- **类型**: `Tuple[float, float, float], optional` -- **说明**: 球体的中心坐标 (x, y, z), 默认为 (0, 0, 0) +- **Type**: `Tuple[float, float, float], optional` +- **Description**: 球体的中心坐标 (x, y, z), 默认为 (0, 0, 0) -## 返回值说明 +## Returns Solid: 创建的实体对象,表示一个球体 -## 异常 +## Raises - **ValueError**: 当半径小于等于0时抛出异常 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 创建标准单位球体 unit_sphere = make_sphere_rsolid(1.0) volume = unit_sphere.get_volume() # 体积为(4/3)π≈4.19 ``` -### 例子 2 +### Example 2 ```python # 创建大球体 large_sphere = make_sphere_rsolid(3.0) ``` -### 例子 3 +### Example 3 ```python # 创建偏移的球体 offset_sphere = make_sphere_rsolid(2.0, (1, 1, 1)) ``` -### 例子 4 +### Example 4 ```python # 获取球体的面进行后续操作 faces = unit_sphere.get_faces() diff --git a/docs/api/make_spline_redge.md b/docs/api/make_spline_redge.md index 344a0a33..385fcef9 100644 --- a/docs/api/make_spline_redge.md +++ b/docs/api/make_spline_redge.md @@ -1,50 +1,50 @@ # make_spline_redge -## API定义 +## API Definition ```python def make_spline_redge(points: List[Tuple[float, float, float]], tangents: Optional[List[Tuple[float, float, float]]] = None) -> Edge ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 创建样条曲线并返回边对象 创建平滑的样条曲线边,用于构建复杂的曲线路径。样条曲线会平滑地通过 所有控制点,可选择性地指定每个点的切线方向来控制曲线的形状。 -## API参数说明 +## Parameters ### points -- **类型**: `List[Tuple[float, float, float]]` -- **说明**: 控制点坐标列表 [(x, y, z), ...], 至少需要2个点,点的顺序决定样条曲线的走向 +- **Type**: `List[Tuple[float, float, float]]` +- **Description**: 控制点坐标列表 [(x, y, z), ...], 至少需要2个点,点的顺序决定样条曲线的走向 ### tangents -- **类型**: `Optional[List[Tuple[float, float, float]]], optional` -- **说明**: 可选的切线向量列表 [(x, y, z), ...],如果提供则数量必须与控制点一致 +- **Type**: `Optional[List[Tuple[float, float, float]]], optional` +- **Description**: 可选的切线向量列表 [(x, y, z), ...],如果提供则数量必须与控制点一致 -## 返回值说明 +## Returns Edge: 创建的边对象,表示通过控制点的平滑样条曲线 -## 异常 +## Raises - **ValueError**: 当控制点少于2个或切线向量数量不匹配时抛出异常 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 创建简单的样条曲线 points = [(0, 0, 0), (1, 2, 0), (3, 1, 0), (4, 3, 0)] spline = make_spline_redge(points) ``` -### 例子 2 +### Example 2 ```python # 创建带切线控制的样条曲线 points = [(0, 0, 0), (2, 0, 0), (4, 0, 0)] @@ -52,7 +52,7 @@ tangents = [(1, 0, 0), (0, 1, 0), (1, 0, 0)] controlled_spline = make_spline_redge(points, tangents) ``` -### 例子 3 +### Example 3 ```python # 创建3D样条曲线 points_3d = [(0, 0, 0), (1, 1, 1), (2, 0, 2), (3, 1, 1)] diff --git a/docs/api/make_spline_rwire.md b/docs/api/make_spline_rwire.md index b9546f72..aa2ed2dd 100644 --- a/docs/api/make_spline_rwire.md +++ b/docs/api/make_spline_rwire.md @@ -1,55 +1,55 @@ # make_spline_rwire -## API定义 +## API Definition ```python def make_spline_rwire(points: List[Tuple[float, float, float]], tangents: Optional[List[Tuple[float, float, float]]] = None, closed: bool = False) -> Wire ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 创建样条曲线并返回线对象 创建样条曲线线对象,与make_spline_redge功能相同但返回线对象。 可以设置为闭合样条曲线,适用于构建复杂的封闭轮廓。 -## API参数说明 +## Parameters ### points -- **类型**: `List[Tuple[float, float, float]]` -- **说明**: 控制点坐标列表 [(x, y, z), ...], 至少需要2个点,点的顺序决定样条曲线的走向 +- **Type**: `List[Tuple[float, float, float]]` +- **Description**: 控制点坐标列表 [(x, y, z), ...], 至少需要2个点,点的顺序决定样条曲线的走向 ### tangents -- **类型**: `Optional[List[Tuple[float, float, float]]], optional` -- **说明**: 可选的切线向量列表 [(x, y, z), ...],如果提供则数量必须与控制点一致 +- **Type**: `Optional[List[Tuple[float, float, float]]], optional` +- **Description**: 可选的切线向量列表 [(x, y, z), ...],如果提供则数量必须与控制点一致 ### closed -- **类型**: `bool, optional` -- **说明**: 是否创建闭合的样条曲线,默认为False +- **Type**: `bool, optional` +- **Description**: 是否创建闭合的样条曲线,默认为False -## 返回值说明 +## Returns Wire: 创建的线对象,包含一个样条曲线 -## 异常 +## Raises - **ValueError**: 当控制点少于2个或切线向量数量不匹配时抛出异常 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 创建开放样条曲线线 points = [(0, 0, 0), (2, 3, 0), (4, 1, 0), (6, 2, 0)] spline_wire = make_spline_rwire(points) ``` -### 例子 2 +### Example 2 ```python # 创建闭合样条曲线 points = [(0, 0, 0), (2, 2, 0), (4, 0, 0), (2, -2, 0)] diff --git a/docs/api/make_threaded_rod_rsolid.md b/docs/api/make_threaded_rod_rsolid.md index f53e32ed..4d886f75 100644 --- a/docs/api/make_threaded_rod_rsolid.md +++ b/docs/api/make_threaded_rod_rsolid.md @@ -1,14 +1,14 @@ # make_threaded_rod_rsolid -## API定义 +## API Definition ```python def make_threaded_rod_rsolid(thread_diameter = 8.0, thread_length = 20.0, total_length = 30.0, thread_pitch = 1.25, thread_start_position = 0.0, chamfer_size = 0.5) -> Solid ``` -*来源文件: evolve.py* +*Source: evolve.py* -## API作用 +## Description 创建带螺纹的螺杆,支持可调节的杆子长度、螺纹范围和螺距。 注意,创建的螺杆顶部中心在原点,向Z轴负方向延伸。 @@ -21,49 +21,49 @@ def make_threaded_rod_rsolid(thread_diameter = 8.0, thread_length = 20.0, total_ 螺纹起始位置:螺纹起始位置(从螺杆底部算起) 螺杆末端倒角:螺杆末端倒角尺寸 -## API参数说明 +## Parameters ### thread_diameter -- **类型**: `float` -- **说明**: 螺纹杆直径(螺纹大径) +- **Type**: `float` +- **Description**: 螺纹杆直径(螺纹大径) ### thread_length -- **类型**: `float` -- **说明**: 螺纹部分长度 +- **Type**: `float` +- **Description**: 螺纹部分长度 ### total_length -- **类型**: `float` -- **说明**: 螺杆总长度 +- **Type**: `float` +- **Description**: 螺杆总长度 ### thread_pitch -- **类型**: `float` -- **说明**: 螺纹螺距 +- **Type**: `float` +- **Description**: 螺纹螺距 ### thread_start_position -- **类型**: `float` -- **说明**: 螺纹起始位置(从螺杆底部算起) +- **Type**: `float` +- **Description**: 螺纹起始位置(从螺杆底部算起) ### chamfer_size -- **类型**: `float` -- **说明**: 螺杆末端倒角尺寸 +- **Type**: `float` +- **Description**: 螺杆末端倒角尺寸 -## 返回值说明 +## Returns Solid: 创建的带螺纹螺杆 -## 异常 +## Raises - **ValueError**: 如果螺杆参数无效(如直径小于等于0、长度不合理等) - **ValueError**: 如果螺纹参数无效(如螺距小于等于0、螺纹长度大于总长度等) - **ValueError**: 如果螺纹起始位置超出螺杆范围 -## API使用例子 +## Examples ```python # 创建标准M8螺杆 diff --git a/docs/api/make_three_point_arc_redge.md b/docs/api/make_three_point_arc_redge.md index d7388efa..9a423086 100644 --- a/docs/api/make_three_point_arc_redge.md +++ b/docs/api/make_three_point_arc_redge.md @@ -1,60 +1,60 @@ # make_three_point_arc_redge -## API定义 +## API Definition ```python def make_three_point_arc_redge(start: Tuple[float, float, float], middle: Tuple[float, float, float], end: Tuple[float, float, float]) -> Edge ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 通过三点创建圆弧并返回边对象 通过三个点创建圆弧边,三个点不能共线。圆弧从起始点经过中间点到结束点。 中间点的位置决定了圆弧的弯曲程度和方向。 -## API参数说明 +## Parameters ### start -- **类型**: `Tuple[float, float, float]` -- **说明**: 圆弧的起始点坐标 (x, y, z) +- **Type**: `Tuple[float, float, float]` +- **Description**: 圆弧的起始点坐标 (x, y, z) ### middle -- **类型**: `Tuple[float, float, float]` -- **说明**: 圆弧上的中间点坐标 (x, y, z), 用于确定圆弧的曲率和方向 +- **Type**: `Tuple[float, float, float]` +- **Description**: 圆弧上的中间点坐标 (x, y, z), 用于确定圆弧的曲率和方向 ### end -- **类型**: `Tuple[float, float, float]` -- **说明**: 圆弧的结束点坐标 (x, y, z) +- **Type**: `Tuple[float, float, float]` +- **Description**: 圆弧的结束点坐标 (x, y, z) -## 返回值说明 +## Returns Edge: 创建的边对象,表示通过三点的圆弧 -## 异常 +## Raises - **ValueError**: 当三个点共线或坐标无效时抛出异常 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 创建90度圆弧 arc = make_three_point_arc_redge((0, 0, 0), (1, 1, 0), (2, 0, 0)) ``` -### 例子 2 +### Example 2 ```python # 创建大圆弧 large_arc = make_three_point_arc_redge((0, 0, 0), (0, 3, 0), (0, 6, 0)) ``` -### 例子 3 +### Example 3 ```python # 创建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 7a42ac44..081116d9 100644 --- a/docs/api/make_three_point_arc_rwire.md +++ b/docs/api/make_three_point_arc_rwire.md @@ -1,54 +1,54 @@ # make_three_point_arc_rwire -## API定义 +## API Definition ```python def make_three_point_arc_rwire(start: Tuple[float, float, float], middle: Tuple[float, float, float], end: Tuple[float, float, float]) -> Wire ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 通过三点创建圆弧并返回线对象 通过三个点创建圆弧线对象,与make_three_point_arc_redge功能相同, 但返回的是线对象,可以与其他线对象连接或用于构建复杂轮廓。 -## API参数说明 +## Parameters ### start -- **类型**: `Tuple[float, float, float]` -- **说明**: 圆弧的起始点坐标 (x, y, z) +- **Type**: `Tuple[float, float, float]` +- **Description**: 圆弧的起始点坐标 (x, y, z) ### middle -- **类型**: `Tuple[float, float, float]` -- **说明**: 圆弧上的中间点坐标 (x, y, z), 用于确定圆弧的曲率和方向 +- **Type**: `Tuple[float, float, float]` +- **Description**: 圆弧上的中间点坐标 (x, y, z), 用于确定圆弧的曲率和方向 ### end -- **类型**: `Tuple[float, float, float]` -- **说明**: 圆弧的结束点坐标 (x, y, z) +- **Type**: `Tuple[float, float, float]` +- **Description**: 圆弧的结束点坐标 (x, y, z) -## 返回值说明 +## Returns Wire: 创建的线对象,包含一个通过三点的圆弧 -## 异常 +## Raises - **ValueError**: 当三个点共线或坐标无效时抛出异常 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 创建圆弧线 arc_wire = make_three_point_arc_rwire((0, 0, 0), (1, 1, 0), (0, 2, 0)) ``` -### 例子 2 +### Example 2 ```python # 与直线连接创建复杂轮廓 line = make_segment_rwire((0, 2, 0), (3, 2, 0)) diff --git a/docs/api/make_wire_from_edges_rwire.md b/docs/api/make_wire_from_edges_rwire.md index 90209c9c..c2945665 100644 --- a/docs/api/make_wire_from_edges_rwire.md +++ b/docs/api/make_wire_from_edges_rwire.md @@ -1,38 +1,38 @@ # make_wire_from_edges_rwire -## API定义 +## API Definition ```python def make_wire_from_edges_rwire(edges: List[Edge]) -> Wire ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 从边对象列表创建线对象 将多个边对象连接成一个连续的线对象。边的顺序很重要,相邻的边应该 能够连接在一起。用于构建复杂的线框结构。 -## API参数说明 +## Parameters ### edges -- **类型**: `List[Edge]` -- **说明**: 输入的边对象列表,边应该能够连接成连续的线 +- **Type**: `List[Edge]` +- **Description**: 输入的边对象列表,边应该能够连接成连续的线 -## 返回值说明 +## Returns Wire: 创建的线对象,由输入的边组成的连续线 -## 异常 +## Raises - **ValueError**: 当边列表为空或边无法连接时抛出异常 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 创建L形线 edge1 = make_line_redge((0, 0, 0), (2, 0, 0)) # 水平线 @@ -40,7 +40,7 @@ edge2 = make_line_redge((2, 0, 0), (2, 2, 0)) # 垂直线 l_wire = make_wire_from_edges_rwire([edge1, edge2]) ``` -### 例子 2 +### Example 2 ```python # 创建包含直线和圆弧的复杂线 line = make_line_redge((0, 0, 0), (2, 0, 0)) diff --git a/docs/api/meta.md b/docs/api/meta.md new file mode 100644 index 00000000..58afe120 --- /dev/null +++ b/docs/api/meta.md @@ -0,0 +1,45 @@ +# meta + +## API Definition + +```python +def meta(path: str, op: str, value: Any) -> Predicate +``` + +*Source: ql.py* + +## Description + +构造基于元数据的谓词。 + +Q.meta("geo.type", "==", "box") + +## Parameters + +### path + +- **Description**: 元数据路径,例如 "geo.type"。 + +### op + +- **Description**: 比较操作符,支持 == != > >= < <= 。 + +### value + +- **Description**: 比较目标值。 + +## Returns + +Callable[[Any], bool]: 谓词函数。 + +## Raises + +- **TypeError**: op 不是字符串。 +- **ValueError**: 操作符不支持。 + +## Examples + +```python +pred = Q.meta("geo.size.x", ">", 1.0) +matched = pred(obj) +``` diff --git a/docs/api/mirror_shape.md b/docs/api/mirror_shape.md index 3310a246..9ca80a16 100644 --- a/docs/api/mirror_shape.md +++ b/docs/api/mirror_shape.md @@ -1,62 +1,62 @@ # mirror_shape -## API定义 +## API Definition ```python def mirror_shape(shape: AnyShape, plane_origin: Tuple[float, float, float], plane_normal: Tuple[float, float, float]) -> AnyShape ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 镜像几何体 将几何体沿指定平面进行镜像复制,创建对称的几何结构。 镜像平面由一个点和法向量定义,几何体在平面另一侧生成对称副本。 -## API参数说明 +## Parameters ### shape -- **类型**: `AnyShape` -- **说明**: 要镜像的几何体,可以是任意类型的几何对象 +- **Type**: `AnyShape` +- **Description**: 要镜像的几何体,可以是任意类型的几何对象 ### plane_origin -- **类型**: `Tuple[float, float, float]` -- **说明**: 镜像平面上的一个点坐标 (x, y, z), 定义镜像平面的位置 +- **Type**: `Tuple[float, float, float]` +- **Description**: 镜像平面上的一个点坐标 (x, y, z), 定义镜像平面的位置 ### plane_normal -- **类型**: `Tuple[float, float, float]` -- **说明**: 镜像平面的法向量 (x, y, z), 定义镜像平面的方向,会被标准化处理 +- **Type**: `Tuple[float, float, float]` +- **Description**: 镜像平面的法向量 (x, y, z), 定义镜像平面的方向,会被标准化处理 -## 返回值说明 +## Returns AnyShape: 镜像后的几何体,类型与输入相同 -## 异常 +## Raises - **ValueError**: 当几何体或镜像平面参数无效时抛出异常 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 沿YZ平面镜像立方体 box = make_box_rsolid(2, 2, 2, (1, 0, 0)) mirrored_box = mirror_shape(box, (0, 0, 0), (1, 0, 0)) ``` -### 例子 2 +### Example 2 ```python # 沿XY平面镜像圆柱体 cylinder = make_cylinder_rsolid(1.0, 3.0, (0, 0, 1)) mirrored_cyl = mirror_shape(cylinder, (0, 0, 0), (0, 0, 1)) ``` -### 例子 3 +### Example 3 ```python # 沿任意平面镜像 sphere = make_sphere_rsolid(1.5, (2, 2, 0)) diff --git a/docs/api/not_.md b/docs/api/not_.md new file mode 100644 index 00000000..855aa8b0 --- /dev/null +++ b/docs/api/not_.md @@ -0,0 +1,25 @@ +# not_ + +## API Definition + +```python +def not_(predicate: Predicate) -> Predicate +``` + +*Source: ql.py* + +## Description + +构造 NOT 谓词。 + +Q.not_(Q.tag("state.*")) + +## Parameters + +### predicate + +- **Description**: 单个谓词。 + +## Returns + +Callable[[Any], bool]: 取反谓词。 diff --git a/docs/api/or_.md b/docs/api/or_.md new file mode 100644 index 00000000..62cf68b3 --- /dev/null +++ b/docs/api/or_.md @@ -0,0 +1,25 @@ +# or_ + +## API Definition + +```python +def or_(*predicates: Predicate) -> Predicate +``` + +*Source: ql.py* + +## Description + +构造 OR 组合谓词。 + +Q.or_(Q.tag("face.top"), Q.tag("face.bottom")) + +## Parameters + +### *predicates + +- **Description**: 任意数量谓词。 + +## Returns + +Callable[[Any], bool]: 组合谓词。 diff --git a/docs/api/radial_pattern_rsolidlist.md b/docs/api/radial_pattern_rsolidlist.md index 45bb8198..2b3ba44f 100644 --- a/docs/api/radial_pattern_rsolidlist.md +++ b/docs/api/radial_pattern_rsolidlist.md @@ -1,72 +1,72 @@ # radial_pattern_rsolidlist -## API定义 +## API Definition ```python def radial_pattern_rsolidlist(shape: AnyShape, center: Tuple[float, float, float], axis: Tuple[float, float, float], count: int, total_rotation_angle: float) -> List[Solid] ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 创建径向阵列(圆形阵列) 围绕指定轴创建几何体的径向阵列,生成等角度间隔的旋转排列。 常用于创建齿轮、花瓣、螺栓圆形分布等对称结构。 -## API参数说明 +## Parameters ### shape -- **类型**: `AnyShape` -- **说明**: 要阵列的几何体,可以是任意类型的几何对象 +- **Type**: `AnyShape` +- **Description**: 要阵列的几何体,可以是任意类型的几何对象 ### center -- **类型**: `Tuple[float, float, float]` -- **说明**: 旋转中心点坐标 (x, y, z) +- **Type**: `Tuple[float, float, float]` +- **Description**: 旋转中心点坐标 (x, y, z) ### axis -- **类型**: `Tuple[float, float, float]` -- **说明**: 旋转轴向量 (x, y, z),定义旋转轴方向 +- **Type**: `Tuple[float, float, float]` +- **Description**: 旋转轴向量 (x, y, z),定义旋转轴方向 ### count -- **类型**: `int` -- **说明**: 阵列数量,必须为正整数,包括原始对象 +- **Type**: `int` +- **Description**: 阵列数量,必须为正整数,包括原始对象 ### total_rotation_angle -- **类型**: `float` -- **说明**: 总旋转角度,单位为度数(0-360), 定义整个阵列的角度范围 +- **Type**: `float` +- **Description**: 总旋转角度,单位为度数(0-360), 定义整个阵列的角度范围 -## 返回值说明 +## Returns List[Solid]: 径向阵列后的几何体列表,包含原始对象和所有旋转的对象 -## 异常 +## Raises - **ValueError**: 当阵列数量小于等于0或角度无效时抛出异常 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```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) ``` -### 例子 2 +### Example 2 ```python # 创建半圆阵列 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) ``` -### 例子 3 +### Example 3 ```python # 围绕Y轴的径向阵列 element = make_sphere_rsolid(0.5, (3, 0, 0)) diff --git a/docs/api/revolve_rsolid.md b/docs/api/revolve_rsolid.md index 53fd078b..4cdcaee6 100644 --- a/docs/api/revolve_rsolid.md +++ b/docs/api/revolve_rsolid.md @@ -1,60 +1,60 @@ # revolve_rsolid -## API定义 +## API Definition ```python def revolve_rsolid(profile: Union[Wire, Face], axis: Tuple[float, float, float] = (0, 0, 1), angle: float = 360, origin: Tuple[float, float, float] = (0, 0, 0)) -> Solid ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 围绕轴旋转轮廓创建实体 围绕指定轴旋转二维轮廓创建三维实体。常用于创建轴对称的几何体, 如圆柱体、圆锥体、球体等。如果输入是线,必须是封闭的线。 -## API参数说明 +## Parameters ### profile -- **类型**: `Union[Wire, Face]` -- **说明**: 要旋转的轮廓,可以是封闭的线或面 +- **Type**: `Union[Wire, Face]` +- **Description**: 要旋转的轮廓,可以是封闭的线或面 ### axis -- **类型**: `Tuple[float, float, float], optional` -- **说明**: 旋转轴向量 (x, y, z), 定义旋转轴的方向,默认为 (0, 0, 1) +- **Type**: `Tuple[float, float, float], optional` +- **Description**: 旋转轴向量 (x, y, z), 定义旋转轴的方向,默认为 (0, 0, 1) ### angle -- **类型**: `float, optional` -- **说明**: 旋转角度,单位为度数(0-360), 默认为360度(完整旋转),正值表示逆时针旋转 +- **Type**: `float, optional` +- **Description**: 旋转角度,单位为度数(0-360), 默认为360度(完整旋转),正值表示逆时针旋转 ### origin -- **类型**: `Tuple[float, float, float], optional` -- **说明**: 旋转轴通过的点坐标 (x, y, z), 默认为 (0, 0, 0), 由此我们知道,origin和axis可以求出转轴两点,一点是origin本身,另一点是origin+axis向量的终点 +- **Type**: `Tuple[float, float, float], optional` +- **Description**: 旋转轴通过的点坐标 (x, y, z), 默认为 (0, 0, 0), 由此我们知道,origin和axis可以求出转轴两点,一点是origin本身,另一点是origin+axis向量的终点 -## 返回值说明 +## Returns Solid: 旋转后的实体对象 -## 异常 +## Raises - **ValueError**: 当轮廓不是封闭的线、角度小于等于0或其他参数无效时抛出异常 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 旋转矩形创建圆柱体 rect = make_rectangle_rface(1.0, 3.0, (2, 0, 0)) # 远离旋转轴 cylinder = revolve_rsolid(rect, (0, 0, 1), 360) ``` -### 例子 2 +### Example 2 ```python # 创建圆锥体 triangle_points = [(1, 0, 0), (2, 0, 0), (1.5, 2, 0)] @@ -62,7 +62,7 @@ triangle = make_polyline_rwire(triangle_points, closed=True) cone = revolve_rsolid(triangle, (0, 0, 1), 360) ``` -### 例子 3 +### Example 3 ```python # 创建部分旋转体(90度扇形) rect = make_rectangle_rface(0.5, 2.0, (1.5, 0, 0)) diff --git a/docs/api/rotate_part_rassembly.md b/docs/api/rotate_part_rassembly.md index 27a34dfa..946ee12a 100644 --- a/docs/api/rotate_part_rassembly.md +++ b/docs/api/rotate_part_rassembly.md @@ -1,13 +1,13 @@ # rotate_part_rassembly -## API定义 +## API Definition ```python def rotate_part_rassembly(assembly: Assembly, part: Union[str, PartHandle], angle_deg: float, axis: AxisLike = 'z', origin: Vec3Like = (0.0, 0.0, 0.0), frame: Literal['world', 'local'] = 'world') -> Assembly ``` -*来源文件: constraints.py* +*Source: constraints.py* -## API作用 +## Description Type-2映射:旋转零件并返回新装配对象。 diff --git a/docs/api/rotate_shape.md b/docs/api/rotate_shape.md index e3011403..0f4d5f13 100644 --- a/docs/api/rotate_shape.md +++ b/docs/api/rotate_shape.md @@ -1,14 +1,14 @@ # rotate_shape -## API定义 +## API Definition ```python def rotate_shape(shape: AnyShape, angle: float, axis: Tuple[float, float, float] = (0, 0, 1), origin: Tuple[float, float, float] = (0, 0, 0)) -> AnyShape ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 旋转几何体到新方向 @@ -16,53 +16,53 @@ def rotate_shape(shape: AnyShape, angle: float, axis: Tuple[float, float, float] 旋转操作支持当前坐标系变换,适用于所有类型的几何对象。 角度使用度数制,正值表示右手定则的逆时针旋转。 -## API参数说明 +## Parameters ### shape -- **类型**: `AnyShape` -- **说明**: 要旋转的几何体,可以是点、边、线、面、实体等任意几何对象 +- **Type**: `AnyShape` +- **Description**: 要旋转的几何体,可以是点、边、线、面、实体等任意几何对象 ### angle -- **类型**: `float` -- **说明**: 旋转角度,单位为度数(0-360),正值表示逆时针旋转 +- **Type**: `float` +- **Description**: 旋转角度,单位为度数(0-360),正值表示逆时针旋转 ### axis -- **类型**: `Tuple[float, float, float], optional` -- **说明**: 旋转轴向量 (x, y, z), 默认为 (0, 0, 1) 表示绕Z轴旋转 +- **Type**: `Tuple[float, float, float], optional` +- **Description**: 旋转轴向量 (x, y, z), 默认为 (0, 0, 1) 表示绕Z轴旋转 ### origin -- **类型**: `Tuple[float, float, float], optional` -- **说明**: 旋转中心点坐标 (x, y, z), 默认为 (0, 0, 0) +- **Type**: `Tuple[float, float, float], optional` +- **Description**: 旋转中心点坐标 (x, y, z), 默认为 (0, 0, 0) -## 返回值说明 +## Returns AnyShape: 旋转后的几何体,类型与输入相同 -## 异常 +## Raises - **ValueError**: 当几何体或旋转参数无效时抛出异常 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 绕Z轴旋转立方体45度 box = make_box_rsolid(2, 2, 2) rotated_box = rotate_shape(box, 45) ``` -### 例子 2 +### Example 2 ```python # 绕X轴旋转圆形面90度 circle = make_circle_rface((0, 0, 0), 1.0) rotated_circle = rotate_shape(circle, 90, (1, 0, 0)) ``` -### 例子 3 +### Example 3 ```python # 围绕指定点旋转 line = make_line_redge((0, 0, 0), (2, 0, 0)) diff --git a/docs/api/select.md b/docs/api/select.md new file mode 100644 index 00000000..9d5f88a6 --- /dev/null +++ b/docs/api/select.md @@ -0,0 +1,25 @@ +# select + +## API Definition + +```python +def select(items: Iterable[Any]) -> Query +``` + +*Source: ql.py* + +## Description + +创建查询对象。 + +Q.select(items).where(Q.tag("face.top")).first() + +## Parameters + +### items + +- **Description**: 任意可迭代对象。 + +## Returns + +Query: 查询对象。 diff --git a/docs/api/select_edges_by_tag.md b/docs/api/select_edges_by_tag.md index e8311204..cfdf4b62 100644 --- a/docs/api/select_edges_by_tag.md +++ b/docs/api/select_edges_by_tag.md @@ -1,27 +1,27 @@ # select_edges_by_tag -## API定义 +## API Definition ```python def select_edges_by_tag(shape: Union[Face, Solid], tag: str) -> List[Edge] ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 根据标签选择边 -## API参数说明 +## Parameters ### shape -- **说明**: 面或实体 +- **Description**: 面或实体 ### tag -- **说明**: 标签名称 +- **Description**: 标签名称 -## 返回值说明 +## Returns 匹配标签的边列表 diff --git a/docs/api/select_faces_by_tag.md b/docs/api/select_faces_by_tag.md index c0c64e53..76493ba0 100644 --- a/docs/api/select_faces_by_tag.md +++ b/docs/api/select_faces_by_tag.md @@ -1,27 +1,27 @@ # select_faces_by_tag -## API定义 +## API Definition ```python def select_faces_by_tag(solid: Solid, tag: str) -> List[Face] ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 根据标签选择面 -## API参数说明 +## Parameters ### solid -- **说明**: 实体 +- **Description**: 实体 ### tag -- **说明**: 标签名称 +- **Description**: 标签名称 -## 返回值说明 +## Returns 匹配标签的面列表 diff --git a/docs/api/set_tag.md b/docs/api/set_tag.md index 5b5fb3fa..5be2f35c 100644 --- a/docs/api/set_tag.md +++ b/docs/api/set_tag.md @@ -1,27 +1,27 @@ # set_tag -## API定义 +## API Definition ```python def set_tag(shape: AnyShape, tag: str) -> AnyShape ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 为几何体设置标签 -## API参数说明 +## Parameters ### shape -- **说明**: 几何体 +- **Description**: 几何体 ### tag -- **说明**: 标签名称 +- **Description**: 标签名称 -## 返回值说明 +## Returns 设置标签后的几何体 diff --git a/docs/api/shell_rsolid.md b/docs/api/shell_rsolid.md index 3034c4b1..d5bb6566 100644 --- a/docs/api/shell_rsolid.md +++ b/docs/api/shell_rsolid.md @@ -1,48 +1,48 @@ # shell_rsolid -## API定义 +## API Definition ```python def shell_rsolid(solid: Solid, faces_to_remove: List[Face], thickness: float) -> Solid ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 对实体进行抽壳操作,创建空心结构 将实体转换为空心结构,常用于创建容器、外壳等。通过移除指定面 创建开口,壁厚决定了外壳的厚度。如果不移除任何面则创建闭合空心体。 -## API参数说明 +## Parameters ### solid -- **类型**: `Solid` -- **说明**: 要抽壳的实体对象 +- **Type**: `Solid` +- **Description**: 要抽壳的实体对象 ### faces_to_remove -- **类型**: `List[Face]` -- **说明**: 要移除的面列表,这些面将被开口, 如果为空列表则不移除任何面(闭合抽壳) +- **Type**: `List[Face]` +- **Description**: 要移除的面列表,这些面将被开口, 如果为空列表则不移除任何面(闭合抽壳) ### thickness -- **类型**: `float` -- **说明**: 壁厚,必须为正数,定义抽壳后的壁厚度 +- **Type**: `float` +- **Description**: 壁厚,必须为正数,定义抽壳后的壁厚度 -## 返回值说明 +## Returns Solid: 抽壳后的实体对象,内部为空心结构 -## 异常 +## Raises - **ValueError**: 当壁厚小于等于0或抽壳操作失败时抛出异常 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 创建空心立方体容器 box = make_box_rsolid(4, 4, 4) @@ -50,7 +50,7 @@ top_faces = [f for f in box.get_faces() if f.has_tag("top")] container = shell_rsolid(box, top_faces, 0.2) ``` -### 例子 2 +### Example 2 ```python # 创建空心球体 sphere = make_sphere_rsolid(3.0) @@ -58,7 +58,7 @@ sphere = make_sphere_rsolid(3.0) hollow_sphere = shell_rsolid(sphere, [], 0.3) ``` -### 例子 3 +### Example 3 ```python # 创建有开口的圆柱体容器 cylinder = make_cylinder_rsolid(2.0, 5.0) diff --git a/docs/api/solve_assembly_rresult.md b/docs/api/solve_assembly_rresult.md index c4ce5d38..926e1892 100644 --- a/docs/api/solve_assembly_rresult.md +++ b/docs/api/solve_assembly_rresult.md @@ -1,13 +1,13 @@ # solve_assembly_rresult -## API定义 +## API Definition ```python def solve_assembly_rresult(assembly: Assembly, max_iterations: int = 30, tolerance: float = 1e-06) -> AssemblyResult ``` -*来源文件: constraints.py* +*Source: constraints.py* -## API作用 +## Description Type-2映射:从装配对象映射到求解结果,不修改原对象。 diff --git a/docs/api/stack.md b/docs/api/stack.md index 17a7e362..4083bb0e 100644 --- a/docs/api/stack.md +++ b/docs/api/stack.md @@ -1,14 +1,14 @@ # stack -## API定义 +## API Definition ```python def stack(assembly: Assembly, parts: Sequence[Union[str, PartHandle]], axis: str = 'z', gap: float = 0.0, align: Literal['center', 'start', 'end'] = 'center', justify: Literal['start', 'center', 'end', 'space-between'] = 'start', bounds: Optional[Tuple[PointAnchor, PointAnchor]] = None) -> Assembly ``` -*来源文件: constraints.py* +*Source: constraints.py* -## API作用 +## Description 沿指定轴将多个零件做声明式堆叠。 diff --git a/docs/api/stack_rassembly.md b/docs/api/stack_rassembly.md index ee3997eb..cb0de15e 100644 --- a/docs/api/stack_rassembly.md +++ b/docs/api/stack_rassembly.md @@ -1,13 +1,13 @@ # stack_rassembly -## API定义 +## API Definition ```python def stack_rassembly(assembly: Assembly, parts: Sequence[Union[str, PartHandle]], axis: str = 'z', gap: float = 0.0, align: Literal['center', 'start', 'end'] = 'center', justify: Literal['start', 'center', 'end', 'space-between'] = 'start', bounds: Optional[Tuple[PointAnchor, PointAnchor]] = None) -> Assembly ``` -*来源文件: constraints.py* +*Source: constraints.py* -## API作用 +## Description Type-2映射:应用 stack 布局并返回新装配对象。 diff --git a/docs/api/sweep_rsolid.md b/docs/api/sweep_rsolid.md index dff64b1b..827ee2a7 100644 --- a/docs/api/sweep_rsolid.md +++ b/docs/api/sweep_rsolid.md @@ -1,48 +1,48 @@ # sweep_rsolid -## API定义 +## API Definition ```python def sweep_rsolid(profile: Face, path: Wire, is_frenet: bool = False) -> Solid ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 沿路径扫掠轮廓创建实体 沿指定路径扫掠二维轮廓创建三维实体或壳体。常用于创建管道、导线、 复杂曲面等。Frenet框架控制轮廓在路径上的旋转行为。 -## API参数说明 +## Parameters ### profile -- **类型**: `Face` -- **说明**: 要扫掠的轮廓面,定义扫掠的横截面形状 +- **Type**: `Face` +- **Description**: 要扫掠的轮廓面,定义扫掠的横截面形状 ### path -- **类型**: `Wire` -- **说明**: 扫掠路径线,定义轮廓沿其移动的路径 +- **Type**: `Wire` +- **Description**: 扫掠路径线,定义轮廓沿其移动的路径 ### is_frenet -- **类型**: `bool, optional` -- **说明**: 是否使用Frenet框架,默认为False。 True时轮廓沿路径的法向量旋转,False时保持轮廓方向 +- **Type**: `bool, optional` +- **Description**: 是否使用Frenet框架,默认为False。 True时轮廓沿路径的法向量旋转,False时保持轮廓方向 -## 返回值说明 +## Returns Union[Solid, Shell]: 扫掠后的实体或壳体,取决于make_solid参数 -## 异常 +## Raises - **ValueError**: 当轮廓、路径无效或扫掠操作失败时抛出异常 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 沿直线扫掠圆形创建圆管 circle = make_circle_rface((0, 0, 0), 0.5) @@ -50,7 +50,7 @@ line_path = make_segment_rwire((0, 0, 0), (10, 0, 0)) tube = sweep_rsolid(circle, line_path) ``` -### 例子 2 +### Example 2 ```python # 沿螺旋路径扫掠创建螺旋管 square = make_rectangle_rface(0.2, 0.2) @@ -58,7 +58,7 @@ helix_path = make_helix_rwire(1.0, 5.0, 2.0) spiral_tube = sweep_rsolid(square, helix_path, is_frenet=True) ``` -### 例子 3 +### Example 3 ```python # 沿曲线扫掠创建复杂形状 profile = make_rectangle_rface(1.0, 0.5) diff --git a/docs/api/tag.md b/docs/api/tag.md new file mode 100644 index 00000000..dbc17b4d --- /dev/null +++ b/docs/api/tag.md @@ -0,0 +1,37 @@ +# tag + +## API Definition + +```python +def tag(pattern: str) -> Predicate +``` + +*Source: ql.py* + +## Description + +构造基于标签的谓词。 + +Q.tag("face.top") 或 Q.tag("role.*")。 + +## Parameters + +### pattern + +- **Description**: 标签匹配模式,支持后缀通配符 "*"。 + +## Returns + +Callable[[Any], bool]: 谓词函数。 + +## Raises + +- **TypeError**: pattern 不是字符串。 +- **ValueError**: 通配符位置不合法。 + +## Examples + +```python +pred = Q.tag("role.*") +matched = pred(obj) +``` diff --git a/docs/api/translate_part_rassembly.md b/docs/api/translate_part_rassembly.md index afa2ac22..f12d0f85 100644 --- a/docs/api/translate_part_rassembly.md +++ b/docs/api/translate_part_rassembly.md @@ -1,13 +1,13 @@ # translate_part_rassembly -## API定义 +## API Definition ```python def translate_part_rassembly(assembly: Assembly, part: Union[str, PartHandle], vector: Vec3Like, frame: Literal['world', 'local'] = 'world') -> Assembly ``` -*来源文件: constraints.py* +*Source: constraints.py* -## API作用 +## Description Type-2映射:平移零件并返回新装配对象。 diff --git a/docs/api/translate_shape.md b/docs/api/translate_shape.md index 25905659..c9a12e17 100644 --- a/docs/api/translate_shape.md +++ b/docs/api/translate_shape.md @@ -1,57 +1,57 @@ # translate_shape -## API定义 +## API Definition ```python def translate_shape(shape: AnyShape, vector: Tuple[float, float, float]) -> AnyShape ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 平移几何体到新位置 将几何体从当前位置平移到新位置,不改变几何体的形状和大小。 平移操作支持当前坐标系变换,适用于所有类型的几何对象。 -## API参数说明 +## Parameters ### shape -- **类型**: `AnyShape` -- **说明**: 要平移的几何体,可以是点、边、线、面、实体等任意几何对象 +- **Type**: `AnyShape` +- **Description**: 要平移的几何体,可以是点、边、线、面、实体等任意几何对象 ### vector -- **类型**: `Tuple[float, float, float]` -- **说明**: 平移向量 (dx, dy, dz), 定义在X、Y、Z方向上的平移距离 +- **Type**: `Tuple[float, float, float]` +- **Description**: 平移向量 (dx, dy, dz), 定义在X、Y、Z方向上的平移距离 -## 返回值说明 +## Returns AnyShape: 平移后的几何体,类型与输入相同 -## 异常 +## Raises - **ValueError**: 当几何体或平移向量无效时抛出异常 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 平移立方体 box = make_box_rsolid(2, 2, 2) moved_box = translate_shape(box, (5, 0, 0)) # 沿X轴移动5个单位 ``` -### 例子 2 +### Example 2 ```python # 平移圆形面 circle = make_circle_rface((0, 0, 0), 1.0) moved_circle = translate_shape(circle, (1, 1, 2)) ``` -### 例子 3 +### Example 3 ```python # 平移线段 line = make_line_redge((0, 0, 0), (1, 0, 0)) diff --git a/docs/api/union_rsolidlist.md b/docs/api/union_rsolidlist.md index c3a2e131..42010063 100644 --- a/docs/api/union_rsolidlist.md +++ b/docs/api/union_rsolidlist.md @@ -1,14 +1,14 @@ # union_rsolidlist -## API定义 +## API Definition ```python def union_rsolidlist(*solids: Union[Solid, Sequence[Solid]]) -> List[Solid] ``` -*来源文件: operations.py* +*Source: operations.py* -## API作用 +## Description 实体列表并集运算 @@ -16,24 +16,24 @@ def union_rsolidlist(*solids: Union[Solid, Sequence[Solid]]) -> List[Solid] 都会被融合成一个新的实体;无法连接的实体保持独立。该过程会一直 进行,直到没有新的实体可以被成功融合为止。 -## API参数说明 +## Parameters ### *solids -- **说明**: 需要尝试并集的实体对象,可以传入: - 单个序列:union_rsolidlist([solid1, solid2, ...]) - 多个参数:union_rsolidlist(solid1, solid2, ...) - 混合输入:union_rsolidlist(solid1, [solid2, solid3], ...),会自动展开所有序列 +- **Description**: 需要尝试并集的实体对象,可以传入: - 单个序列:union_rsolidlist([solid1, solid2, ...]) - 多个参数:union_rsolidlist(solid1, solid2, ...) - 混合输入:union_rsolidlist(solid1, [solid2, solid3], ...),会自动展开所有序列 -## 返回值说明 +## Returns List[Solid]: 并集运算后的实体列表。可以合并为整体的实体会被融合, 无法融合的实体会原样保留。 -## 异常 +## Raises - **ValueError**: 当输入列表无效或内部包含非Solid对象时抛出异常 -## API使用例子 +## Examples -### 例子 1 +### Example 1 ```python # 创建三个实体,其中前两个接触可以融合,第三个独立 box1 = make_box_rsolid(2, 2, 2, (0, 0, 0)) @@ -41,7 +41,7 @@ box2 = make_box_rsolid(2, 2, 2, (1, 0, 0)) sphere = make_sphere_rsolid(1.0, (10, 0, 0)) ``` -### 例子 2 +### Example 2 ```python # 多种调用方式都支持且等价 union_results1 = union_rsolidlist([box1, box2, sphere]) diff --git a/docs/api/value.md b/docs/api/value.md new file mode 100644 index 00000000..259e49f9 --- /dev/null +++ b/docs/api/value.md @@ -0,0 +1,36 @@ +# value + +## API Definition + +```python +def value(path: str, default: Any = None) -> KeyFn +``` + +*Source: ql.py* + +## Description + +构造取值函数,用于排序或投影。 + +Q.select(items).order_by(Q.value("geo.height")) + +## Parameters + +### path + +- **Description**: 元数据路径,例如 "geo.height"。 + +### default + +- **Description**: 取值失败时的默认值。 + +## Returns + +Callable[[Any], Any]: 取值函数。 + +## Examples + +```python +key = Q.value("geo.height", 0.0) +height = key(obj) +``` diff --git a/refactor-plan/tagging.md b/refactor-plan/tagging.md new file mode 100644 index 00000000..5c5055fe --- /dev/null +++ b/refactor-plan/tagging.md @@ -0,0 +1,149 @@ +Tagging Refactor Plan (Naming + Propagation + Anchor Semantics) + +Goals +- Define a strict, query-friendly tag naming scheme for QL. +- Make tag propagation explicit, predictable, and consistent across topology levels. +- Align tag semantics with constraint/assembly anchors. +- Move all numeric geometry data into metadata/geo data (no numbers in tags). + +Non-Goals (Phase 1) +- Persistent topological IDs across boolean ops and remeshing. +- Automatic recovery of face/edge tags after arbitrary topology changes. +- Full QL implementation (this plan only prepares the data model). + +1) Tag Naming Scheme + +Format +- Lowercase ASCII only. +- Dot-separated segments: segment(.segment)* +- Segment grammar: [a-z][a-z0-9_-]* +- Forbidden: whitespace, colon (:), slash (/), uppercase. + +Rationale +- Dot segments allow prefix queries (QL) and structured namespaces. +- No colon because anchor syntax uses face:. + +Examples +- geom.primitive.box +- face.top +- edge.circular +- feature.extrude.start_face +- role.mounting_surface +- anchor.datum.primary +- group.fasteners +- state.debug + +2) Tag Namespaces (Reserved Prefixes) + +Core namespaces (stable semantics) +- geom.*: geometry category/type (primitive or derived) +- face.* / edge.* / wire.* / vertex.* / solid.*: topology-level semantics +- role.*: stable semantic role (preferred for anchors and QL) +- anchor.*: explicit anchor naming (aliasable from role.*) +- group.*: grouping and selection convenience + +Process/ephemeral namespaces +- feature.*: derived from operations (extrude, loft, sweep, boolean) +- state.*: debug/test/temporary flags (not for anchors) +- legacy.*: compatibility aliases during migration + +Multiple namespaces on one object +- Yes, a single object can carry multiple tags from different namespaces. +- Tags are orthogonal: e.g., a face can be both geom.primitive.box and role.mounting_surface. +- Avoid redundant tags that encode the same meaning across namespaces. +- Anchor resolution uses a defined priority (role > anchor > face/edge/wire > legacy). + +3) Propagation Rules + +Principles +- Propagation is opt-in and prefix-based. +- Only stable semantic tags should propagate by default. +- Propagation should be directional (parent -> children) and explicit. + +Default propagation policy by prefix +- role.*: propagate down (Solid -> Face -> Wire -> Edge -> Vertex) +- anchor.*: propagate down (same as role.*) +- group.*: propagate down (same as role.*) +- geom.*: propagate down to Face/Wire/Edge (optional; toggleable) +- face.* / edge.* / wire.* / vertex.*: do NOT propagate (object-specific) +- feature.*: do NOT propagate by default +- state.*: never propagate + +Implementation sketch +- Introduce a TagPolicy registry keyed by prefix. +- Add propagate parameter to set_tag (none | down | custom). +- Provide helper: apply_tag(shape, tag, propagate=None). +- Propagation should be implemented in core (TaggedMixin) and reused in ops. + +4) Anchor Semantics (Constraint Integration) + +Anchor naming goals +- Anchor selection should be stable and semantic. +- Anchor names should be directly queryable by QL. +- Existing anchor syntax (face:) should remain valid. + +Proposed rules +- Use role.* as the primary semantic source for anchors. +- For standard primitives, define canonical face tags: + - face.top / face.bottom / face.left / face.right / face.front / face.back + - face.side (cylinder/cone), face.surface (sphere) +- For assembly anchors, resolve tag by priority: + 1) role. + 2) anchor. + 3) face. (or edge., wire.) + 4) legacy. and historical tags (top, bottom, side, surface) + +Example +- Face tag: role.mounting_surface +- Anchor usage: face:mounting_surface +- Resolver maps to role.mounting_surface (or anchor.mounting_surface) + +5) Geometry Data in Metadata/Geo Data + +Policy +- No numeric or dimensional data in tags. +- All geometry facts go into metadata under a reserved key. + +Proposed schema +- metadata["geo"]: dict with normalized keys + - type: "box" | "cylinder" | "sphere" | ... + - size: {x, y, z} or {radius, height} + - center: (x, y, z) + - axis: (x, y, z) + - bbox: {min, max, center, size} + +Example (box) +- tags: geom.primitive.box, role.container +- metadata["geo"]: + {"type":"box","size":{"x":4,"y":3,"z":2},"center":(0,0,0)} + +6) Migration Plan (Incremental) + +Phase A: Naming and aliasing +- Add TagPolicy registry and prefix normalization utilities. +- Update anchor resolver to try role/anchor/face prefixes + legacy tags. +- Start emitting role/face tags in auto_tag_faces with legacy aliases. + +Phase B: Propagation +- Implement propagation helpers in TaggedMixin (downward only). +- Update auto_tag_faces to call propagation hooks. +- Add explicit propagation to key ops (extrude/loft/sweep/mirror). + +Phase C: Geo data +- Replace numeric tag strings with metadata["geo"] in primitives. +- Deprecate tags like "size: 2x3x4" and "bottom center: ...". + +Phase D: Query readiness +- Update docs and tests to use role/anchor semantics. +- Provide QL examples for tag prefix queries and geo metadata queries. + +7) Compatibility Notes +- Keep legacy tags during migration (add legacy.* aliases). +- Provide a single normalization helper for tag lookup and anchor selection. +- Document any tag renames in release notes and update tests. + +Open Questions +- Should geom.* propagate by default or remain opt-in? +- Do we need a separate geo_data attribute instead of metadata["geo"]? +- Should anchors prefer role.* over face.* even when both exist? +- How far should propagation go for Wire/Edge derived from new topology? diff --git a/skills/simplecad-self-evolve/SKILL.md b/skills/simplecad-self-evolve/SKILL.md index 89708ce8..72c696da 100644 --- a/skills/simplecad-self-evolve/SKILL.md +++ b/skills/simplecad-self-evolve/SKILL.md @@ -19,6 +19,13 @@ metadata: - Runtime code is installed from PyPI into active virtual environment site-packages. - Skill-local evolved cases are stored under `cases/simplecad_self_evolve_cases/`. +## MUST Requirements +1. You MUST run `ls` on `references/docs` before coding. The document filenames enumerate all available APIs. +2. Geometry construction APIs MUST be used only to build integrated parts. Final assembly MUST use declarative constraints, and parameters MUST reflect design intent. +3. You MUST use the tagging mechanism fully and consistently. +4. You MUST NOT write the entire solution at once. Each step MUST include a grounding `print`, and grounding MUST use QL where possible. +5. After model construction, you MUST ask the user if they are satisfied and whether modifications are needed. Only when the user explicitly confirms satisfaction MAY you add the script to evolve cases. + ## Install behavior - Preferred: run `scripts/install.sh` once when skill is installed/activated. - Runtime wrappers auto-install on demand if `simplecadapi` is missing. diff --git a/src/simplecadapi/__init__.py b/src/simplecadapi/__init__.py index 1b475342..1e33efb0 100644 --- a/src/simplecadapi/__init__.py +++ b/src/simplecadapi/__init__.py @@ -105,6 +105,8 @@ from .constraints import ( stack, ) +from . import ql + __author__ = "SimpleCAD API Team" __description__ = "Simplified CAD modeling Python API based on CADQuery" @@ -245,6 +247,7 @@ __all__ = [ "PointAnchor", "AxisAnchor", "stack", + "ql", # 别名 "create_angle_arc", "create_angle_arc_wire", diff --git a/src/simplecadapi/auto_tools/auto_docs_gen.py b/src/simplecadapi/auto_tools/auto_docs_gen.py index 5f912289..cce32072 100644 --- a/src/simplecadapi/auto_tools/auto_docs_gen.py +++ b/src/simplecadapi/auto_tools/auto_docs_gen.py @@ -20,6 +20,7 @@ DEFAULT_SOURCES: tuple[Path, ...] = ( PROJECT_ROOT / "src/simplecadapi/operations.py", PROJECT_ROOT / "src/simplecadapi/evolve.py", PROJECT_ROOT / "src/simplecadapi/constraints.py", + PROJECT_ROOT / "src/simplecadapi/ql.py", ) DEFAULT_OUTPUT_DIRS: tuple[Path, ...] = (PROJECT_ROOT / "docs/api",) @@ -143,13 +144,13 @@ class APIDocumentGenerator: md_lines.append(f"# {api.name}") md_lines.append("") - md_lines.append("## API定义") + md_lines.append("## API Definition") md_lines.append("") md_lines.append("```python") md_lines.append(api.signature) md_lines.append("```") md_lines.append("") - md_lines.append(f"*来源文件: {api.source_file}*") + md_lines.append(f"*Source: {api.source_file}*") md_lines.append("") description = str(parsed.get("description", "")).strip() @@ -157,14 +158,14 @@ class APIDocumentGenerator: usage_parts = [part for part in [description, usage] if part] if usage_parts: merged_usage = "\n\n".join(dict.fromkeys(usage_parts)) - md_lines.append("## API作用") + md_lines.append("## Description") md_lines.append("") md_lines.extend(merged_usage.splitlines()) md_lines.append("") args = parsed.get("args", []) if isinstance(args, list) and args: - md_lines.append("## API参数说明") + md_lines.append("## Parameters") md_lines.append("") for arg in args: arg_name = str(arg.get("name", "")).strip() @@ -174,20 +175,20 @@ class APIDocumentGenerator: md_lines.append(f"### {arg_name}") md_lines.append("") if arg_type: - md_lines.append(f"- **类型**: `{arg_type}`") - md_lines.append(f"- **说明**: {arg_desc}") + md_lines.append(f"- **Type**: `{arg_type}`") + md_lines.append(f"- **Description**: {arg_desc}") md_lines.append("") returns_text = str(parsed.get("returns", "")).strip() if returns_text: - md_lines.append("## 返回值说明") + md_lines.append("## Returns") md_lines.append("") md_lines.extend(returns_text.splitlines()) md_lines.append("") raises = parsed.get("raises", []) if isinstance(raises, list) and raises: - md_lines.append("## 异常") + md_lines.append("## Raises") md_lines.append("") for exc in raises: exc_type = str(exc.get("type", "")).strip() @@ -197,11 +198,11 @@ class APIDocumentGenerator: examples = parsed.get("examples", []) if isinstance(examples, list) and examples: - md_lines.append("## API使用例子") + md_lines.append("## Examples") md_lines.append("") for index, block in enumerate(examples, start=1): if len(examples) > 1: - md_lines.append(f"### 例子 {index}") + md_lines.append(f"### Example {index}") md_lines.append("```python") md_lines.extend(block.splitlines()) md_lines.append("```") @@ -211,52 +212,52 @@ class APIDocumentGenerator: def _build_api_index_markdown(self) -> str: categories: Dict[str, List[ApiInfo]] = { - "基础图形创建": [], - "变换操作": [], - "3D操作": [], - "标签和选择": [], - "布尔运算": [], - "导出功能": [], - "高级特征": [], - "自进化": [], - "声明式装配约束": [], - "其他": [], + "Basic Creation": [], + "Transforms": [], + "3D Operations": [], + "Tagging and Selection": [], + "Boolean Operations": [], + "Export": [], + "Advanced Features": [], + "Evolve": [], + "Assembly Constraints": [], + "Other": [], } for api in self.apis: name = api.name if api.source_file == "evolve.py": - categories["自进化"].append(api) + categories["Evolve"].append(api) continue if api.source_file == "constraints.py": - categories["声明式装配约束"].append(api) + categories["Assembly Constraints"].append(api) continue if name.startswith("make_"): - categories["基础图形创建"].append(api) + categories["Basic Creation"].append(api) elif name.startswith(("translate_", "rotate_", "mirror_")): - categories["变换操作"].append(api) + categories["Transforms"].append(api) elif name.startswith(("extrude_", "revolve_", "loft_", "sweep_")): - categories["3D操作"].append(api) + categories["3D Operations"].append(api) elif name.startswith(("set_tag", "select_")): - categories["标签和选择"].append(api) + categories["Tagging and Selection"].append(api) elif name.startswith(("union_", "cut_", "intersect_")): - categories["布尔运算"].append(api) + categories["Boolean Operations"].append(api) elif name.startswith("export_"): - categories["导出功能"].append(api) + categories["Export"].append(api) elif name.startswith( ("fillet_", "chamfer_", "shell_", "pattern_", "helical_") ): - categories["高级特征"].append(api) + categories["Advanced Features"].append(api) else: - categories["其他"].append(api) + categories["Other"].append(api) md_lines: List[str] = [ - "# SimpleCAD API 文档索引", + "# SimpleCAD API Index", "", - "本文档包含了 SimpleCAD API (来自 `operations.py`、`evolve.py`、`constraints.py`) 的所有函数说明。", + "This index includes API docs generated from `operations.py`, `evolve.py`, `constraints.py`, and `ql.py`.", "", ] diff --git a/src/simplecadapi/auto_tools/skill_pack.py b/src/simplecadapi/auto_tools/skill_pack.py index 947a4138..0426eb26 100644 --- a/src/simplecadapi/auto_tools/skill_pack.py +++ b/src/simplecadapi/auto_tools/skill_pack.py @@ -374,6 +374,13 @@ class SkillPackager: - Runtime code is installed from PyPI into active virtual environment site-packages. - Skill-local evolved cases are stored under `cases/{cases_module}/`. + ## MUST Requirements + 1. You MUST run `ls` on `references/docs` before coding. The document filenames enumerate all available APIs. + 2. Geometry construction APIs MUST be used only to build integrated parts. Final assembly MUST use declarative constraints, and parameters MUST reflect design intent. + 3. You MUST use the tagging mechanism fully and consistently. + 4. You MUST NOT write the entire solution at once. Each step MUST include a grounding `print`, and grounding MUST use QL where possible. + 5. After model construction, you MUST ask the user if they are satisfied and whether modifications are needed. Only when the user explicitly confirms satisfaction MAY you add the script to evolve cases. + ## Install behavior - Preferred: run `scripts/install.sh` once when skill is installed/activated. - Runtime wrappers auto-install on demand if `simplecadapi` is missing. diff --git a/src/simplecadapi/constraints.py b/src/simplecadapi/constraints.py index dcab17b0..f4668220 100644 --- a/src/simplecadapi/constraints.py +++ b/src/simplecadapi/constraints.py @@ -21,6 +21,7 @@ import numpy as np from OCP.gp import gp_Trsf from .core import Solid, Face +from .tagging import resolve_anchor_tag_candidates Vec3Like = Union[Tuple[float, float, float], List[float], np.ndarray] @@ -778,12 +779,14 @@ class Assembly: def _find_tagged_face(self, part_name: str, tag: str) -> Face: node = self._parts[part_name] - faces = [face for face in node.solid.get_faces() if face.has_tag(tag)] - if not faces: - raise ValueError( - f"零件 '{part_name}' 未找到标签为 '{tag}' 的面,请先执行 auto_tag_faces() 或手动打标签" - ) - return faces[0] + candidates = resolve_anchor_tag_candidates(tag) + for candidate in candidates: + faces = [face for face in node.solid.get_faces() if face.has_tag(candidate)] + if faces: + return faces[0] + raise ValueError( + f"零件 '{part_name}' 未找到标签为 '{tag}' 的面,请先执行 auto_tag_faces() 或手动打标签" + ) # ------------------------------------------------------------------ # output helpers diff --git a/src/simplecadapi/core.py b/src/simplecadapi/core.py index c0c1a93c..00e7c810 100644 --- a/src/simplecadapi/core.py +++ b/src/simplecadapi/core.py @@ -18,6 +18,8 @@ from cadquery.occ_impl.shapes import ( Compound as CQCompound, ) +from .tagging import DEFAULT_TAG_POLICY, normalize_tag + class CoordinateSystem: """三维坐标系 @@ -265,6 +267,35 @@ class TaggedMixin: raise TypeError("标签必须是字符串类型") self._tags.add(tag) + def apply_tag( + self, + tag: str, + *, + normalize: bool = True, + propagate: Optional[bool] = None, + ) -> None: + if normalize: + tag = normalize_tag(tag, strict=True) + self._tags.add(tag) + + if propagate is None: + propagate = DEFAULT_TAG_POLICY.should_propagate(tag) + + if propagate: + self._propagate_tag_down(tag) + + def _propagate_tag_down(self, tag: str) -> None: + if not isinstance(self, TopoMixein): + return + try: + children = self.get_children() + except Exception: + return + for child in children: + if isinstance(child, TaggedMixin): + child._tags.add(tag) + child._propagate_tag_down(tag) + def remove_tag(self, tag: str) -> None: """移除标签 @@ -519,7 +550,6 @@ class Edge(TaggedMixin, TopoMixein): end_coord = self.get_end_vertex().get_coordinates() part1 = f"from: {start_coord}, to: {end_coord}" except Exception: - part1 = "from: [unable to retrieve], to: [unable to retrieve], ususally this is a circle" return f"Edge({part1}, length={length:.3f}, tags={self.get_tags()})" @@ -604,10 +634,11 @@ class Wire(TaggedMixin, TopoMixein): def _tag_edges(self) -> None: """给构成wire的edges打tag""" - + policy = DEFAULT_TAG_POLICY for i, edge in enumerate(self.get_edges()): - for tags in self.get_tags(): - edge.add_tag(tags) + for tag in self.get_tags(): + if policy.should_propagate(tag): + edge.add_tag(tag) edge.add_tag("edge") edge.add_tag(f"{i}") @@ -675,11 +706,13 @@ class Face(TaggedMixin, TopoMixein): outer_wire = Wire(self.cq_face.outerWire()) outer_wire.add_tag("outer_wire") + outer_wire.apply_tag("wire.outer", propagate=False) self.add_child(outer_wire) for w in self.cq_face.innerWires(): iw = Wire(w) iw.add_tag("inner_wire") + iw.apply_tag("wire.inner", propagate=False) self.add_child(iw) except Exception as e: @@ -714,15 +747,21 @@ class Face(TaggedMixin, TopoMixein): def _tag_wires(self) -> None: """为面上的边线添加标签""" - for tags in self.get_tags(): - self.get_outer_wire().add_tag(tags) - self.get_outer_wire().add_tag("outer_wire") - self.get_outer_wire()._tag_edges() + policy = DEFAULT_TAG_POLICY + outer_wire = self.get_outer_wire() + for tag in self.get_tags(): + if policy.should_propagate(tag): + outer_wire.add_tag(tag) + outer_wire.add_tag("outer_wire") + outer_wire.apply_tag("wire.outer", propagate=False) + outer_wire._tag_edges() for i, iw in enumerate(self.get_inner_wires()): for tag in self.get_tags(): - iw.add_tag(tag) + if policy.should_propagate(tag): + iw.add_tag(tag) iw.add_tag("inner_wire") + iw.apply_tag("wire.inner", propagate=False) iw.add_tag(f"{i}") iw._tag_edges() @@ -736,7 +775,8 @@ class Face(TaggedMixin, TopoMixein): return [ w for w in cast(List[Wire], self.get_children()) - if w.is_closed() and w.has_tag("outer_wire") + if w.is_closed() + and (w.has_tag("outer_wire") or w.has_tag("wire.outer")) ][0] except Exception as e: raise ValueError(f"获取外边界线失败: {e}") @@ -751,7 +791,8 @@ class Face(TaggedMixin, TopoMixein): return [ w for w in cast(List[Wire], self.get_children()) - if w.is_closed() and w.has_tag("inner_wire") + if w.is_closed() + and (w.has_tag("inner_wire") or w.has_tag("wire.inner")) ] except Exception as e: raise ValueError(f"获取内边界线失败: {e}") @@ -980,6 +1021,7 @@ class Solid(TaggedMixin, TopoMixein): """ # 同时也添加到面对象本身 face.add_tag(tag) + face.apply_tag(f"face.{tag}", propagate=False) face._tag_wires() def __str__(self) -> str: diff --git a/src/simplecadapi/operations.py b/src/simplecadapi/operations.py index 4f96e39c..be9fc0d9 100644 --- a/src/simplecadapi/operations.py +++ b/src/simplecadapi/operations.py @@ -602,9 +602,18 @@ def make_box_rsolid( # 自动标记面 solid.auto_tag_faces("box") + solid.apply_tag("geom.primitive.box", propagate=False) solid.add_tag("box") solid.add_tag(f"bottom center: {bottom_face_center}") - solid.add_tag("size: {width}x{height}x{depth}") + solid.add_tag(f"size: {width}x{height}x{depth}") + solid.set_metadata( + "geo", + { + "type": "box", + "size": {"x": width, "y": height, "z": depth}, + "bottom_face_center": bottom_face_center, + }, + ) return solid except Exception as e: @@ -668,9 +677,20 @@ def make_cylinder_rsolid( # 自动标记面 solid.auto_tag_faces("cylinder") + solid.apply_tag("geom.primitive.cylinder", propagate=False) solid.add_tag("cylinder") solid.add_tag(f"bottom center: {bottom_face_center}") solid.add_tag(f"size: {radius}x{height}") + solid.set_metadata( + "geo", + { + "type": "cylinder", + "radius": radius, + "height": height, + "bottom_face_center": bottom_face_center, + "axis": axis, + }, + ) return solid except Exception as e: @@ -733,11 +753,23 @@ def make_cone_rsolid( solid = Solid(cq_solid) # 自动标记面 + solid.apply_tag("geom.primitive.cone", propagate=False) solid.add_tag("cone") solid.add_tag(f"bottom center: {bottom_face_center}") solid.add_tag( f"size: bottom_radius: {bottom_radius}, top_radius: {top_radius}, height: {height}" ) + solid.set_metadata( + "geo", + { + "type": "cone", + "bottom_radius": bottom_radius, + "top_radius": top_radius, + "height": height, + "bottom_face_center": bottom_face_center, + "axis": axis, + }, + ) return solid except Exception as e: @@ -804,9 +836,18 @@ def make_sphere_rsolid( # 自动标记面 solid.auto_tag_faces("sphere") + solid.apply_tag("geom.primitive.sphere", propagate=False) solid.add_tag("sphere") solid.add_tag(f"center: {center}") solid.add_tag(f"radius: {radius}") + solid.set_metadata( + "geo", + { + "type": "sphere", + "radius": radius, + "center": center, + }, + ) return solid except Exception as e: diff --git a/src/simplecadapi/ql.py b/src/simplecadapi/ql.py new file mode 100644 index 00000000..d06287e8 --- /dev/null +++ b/src/simplecadapi/ql.py @@ -0,0 +1,363 @@ +from __future__ import annotations + +from typing import Any, Callable, Iterable, List, Optional + + +Predicate = Callable[[Any], bool] +KeyFn = Callable[[Any], Any] + + +def _get_tags(obj: Any) -> List[str]: + """读取对象上的标签列表。 + + Args: + obj: 任意对象,优先读取 get_tags(),其次读取 _tags。 + + Returns: + List[str]: 标签列表,未找到则返回空列表。 + """ + if hasattr(obj, "get_tags"): + try: + return list(obj.get_tags()) + except Exception: + return [] + tags = getattr(obj, "_tags", None) + if tags is None: + return [] + return list(tags) + + +def _get_metadata_root(obj: Any) -> dict: + """读取对象的元数据字典。 + + Args: + obj: 任意对象,优先读取 _metadata。 + + Returns: + dict: 元数据根字典,未找到则返回空字典。 + """ + root = getattr(obj, "_metadata", None) + if isinstance(root, dict): + return root + return {} + + +def _lookup_metadata(obj: Any, path: str) -> Any: + """按点路径读取对象元数据。 + + Args: + obj: 任意对象。 + path: 点分隔路径,例如 "geo.type"。 + + Returns: + Any: 命中值,未命中返回 None。 + """ + if not isinstance(path, str) or not path: + return None + segments = path.split(".") + current: Any = _get_metadata_root(obj) + for seg in segments: + if isinstance(current, dict) and seg in current: + current = current[seg] + else: + return None + return current + + +def tag(pattern: str) -> Predicate: + """构造基于标签的谓词。 + + Args: + pattern: 标签匹配模式,支持后缀通配符 "*"。 + + Returns: + Callable[[Any], bool]: 谓词函数。 + + Raises: + TypeError: pattern 不是字符串。 + ValueError: 通配符位置不合法。 + + Usage: + Q.tag("face.top") 或 Q.tag("role.*")。 + + Examples: + pred = Q.tag("role.*") + matched = pred(obj) + """ + if not isinstance(pattern, str): + raise TypeError("pattern must be a string") + + pattern = pattern.strip() + if "*" in pattern and not pattern.endswith("*"): + raise ValueError("only trailing '*' wildcard is supported") + + if pattern.endswith("*"): + prefix = pattern[:-1] + + def _predicate(obj: Any) -> bool: + return any(tag.startswith(prefix) for tag in _get_tags(obj)) + + return _predicate + + def _predicate(obj: Any) -> bool: + return pattern in _get_tags(obj) + + return _predicate + + +def meta(path: str, op: str, value: Any) -> Predicate: + """构造基于元数据的谓词。 + + Args: + path: 元数据路径,例如 "geo.type"。 + op: 比较操作符,支持 == != > >= < <= 。 + value: 比较目标值。 + + Returns: + Callable[[Any], bool]: 谓词函数。 + + Raises: + TypeError: op 不是字符串。 + ValueError: 操作符不支持。 + + Usage: + Q.meta("geo.type", "==", "box") + + Examples: + pred = Q.meta("geo.size.x", ">", 1.0) + matched = pred(obj) + """ + if not isinstance(op, str): + raise TypeError("op must be a string") + + op = op.strip() + + def _predicate(obj: Any) -> bool: + actual = _lookup_metadata(obj, path) + if op == "==": + return actual == value + if op == "!=": + return actual != value + if actual is None: + return False + try: + if op == ">": + return actual > value + if op == ">=": + return actual >= value + if op == "<": + return actual < value + if op == "<=": + return actual <= value + except Exception: + return False + raise ValueError(f"unsupported op: {op}") + + return _predicate + + +def value(path: str, default: Any = None) -> KeyFn: + """构造取值函数,用于排序或投影。 + + Args: + path: 元数据路径,例如 "geo.height"。 + default: 取值失败时的默认值。 + + Returns: + Callable[[Any], Any]: 取值函数。 + + Usage: + Q.select(items).order_by(Q.value("geo.height")) + + Examples: + key = Q.value("geo.height", 0.0) + height = key(obj) + """ + + def _getter(obj: Any) -> Any: + actual = _lookup_metadata(obj, path) + if actual is not None: + return actual + + if path.startswith("geo."): + remainder = path.split(".", 1)[1] + if "." not in remainder: + if remainder == "area" and hasattr(obj, "get_area"): + try: + return obj.get_area() + except Exception: + return default + if remainder == "length" and hasattr(obj, "get_length"): + try: + return obj.get_length() + except Exception: + return default + if remainder == "volume" and hasattr(obj, "get_volume"): + try: + return obj.get_volume() + except Exception: + return default + return default + + return _getter + + +def geo(field: str, default: Any = None) -> KeyFn: + """快捷构造 geo 元数据取值函数。 + + Args: + field: geo 字段名,如 "type"、"height"。 + default: 取值失败时的默认值。 + + Returns: + Callable[[Any], Any]: 取值函数。 + + Usage: + Q.select(items).order_by(Q.geo("height")) + """ + return value(f"geo.{field}", default) + + +def and_(*predicates: Predicate) -> Predicate: + """构造 AND 组合谓词。 + + Args: + *predicates: 任意数量谓词。 + + Returns: + Callable[[Any], bool]: 组合谓词。 + + Usage: + Q.and_(Q.tag("face.top"), Q.tag("role.mounting_surface")) + """ + + def _predicate(obj: Any) -> bool: + for pred in predicates: + if not pred(obj): + return False + return True + + return _predicate + + +def or_(*predicates: Predicate) -> Predicate: + """构造 OR 组合谓词。 + + Args: + *predicates: 任意数量谓词。 + + Returns: + Callable[[Any], bool]: 组合谓词。 + + Usage: + Q.or_(Q.tag("face.top"), Q.tag("face.bottom")) + """ + + def _predicate(obj: Any) -> bool: + for pred in predicates: + if pred(obj): + return True + return False + + return _predicate + + +def not_(predicate: Predicate) -> Predicate: + """构造 NOT 谓词。 + + Args: + predicate: 单个谓词。 + + Returns: + Callable[[Any], bool]: 取反谓词。 + + Usage: + Q.not_(Q.tag("state.*")) + """ + + def _predicate(obj: Any) -> bool: + return not predicate(obj) + + return _predicate + + +class Query: + def __init__(self, items: Iterable[Any]): + """创建查询对象。 + + Args: + items: 任意可迭代对象。 + """ + self._items = list(items) + + def where(self, predicate: Predicate) -> "Query": + """根据谓词过滤对象。 + + Args: + predicate: 过滤谓词。 + + Returns: + Query: 新查询对象。 + """ + return Query([item for item in self._items if predicate(item)]) + + def order_by(self, key: KeyFn, desc: bool = False) -> "Query": + """按 key 排序。 + + Args: + key: 取值函数。 + desc: 是否降序。 + + Returns: + Query: 新查询对象。 + """ + + def _safe_key(obj: Any): + value = key(obj) + return (value is None, value) + + return Query(sorted(self._items, key=_safe_key, reverse=desc)) + + def limit(self, count: int) -> "Query": + """限制返回数量。 + + Args: + count: 最大数量。 + + Returns: + Query: 新查询对象。 + """ + if count <= 0: + return Query([]) + return Query(self._items[:count]) + + def first(self) -> Optional[Any]: + """返回首个元素。 + + Returns: + Optional[Any]: 首元素或 None。 + """ + return self._items[0] if self._items else None + + def all(self) -> List[Any]: + """返回全部结果。 + + Returns: + List[Any]: 结果列表。 + """ + return list(self._items) + + +def select(items: Iterable[Any]) -> Query: + """创建查询对象。 + + Args: + items: 任意可迭代对象。 + + Returns: + Query: 查询对象。 + + Usage: + Q.select(items).where(Q.tag("face.top")).first() + """ + return Query(items) diff --git a/src/simplecadapi/tagging.py b/src/simplecadapi/tagging.py new file mode 100644 index 00000000..83e8e966 --- /dev/null +++ b/src/simplecadapi/tagging.py @@ -0,0 +1,137 @@ +from __future__ import annotations + +from dataclasses import dataclass +import re +from typing import List + + +_TAG_SEGMENT = r"[a-z][a-z0-9_-]*" +_TAG_RE = re.compile(rf"^{_TAG_SEGMENT}(?:\.{_TAG_SEGMENT})*$") + + +def is_normalized_tag(tag: str) -> bool: + """检查标签是否符合规范格式。 + + Args: + tag: 标签字符串。 + + Returns: + bool: 是否符合规范。 + """ + if not isinstance(tag, str): + return False + return bool(_TAG_RE.fullmatch(tag)) + + +def normalize_tag(tag: str, *, strict: bool = True) -> str: + """规范化标签。 + + Args: + tag: 原始标签。 + strict: 是否严格校验,True 时只接受已规范化格式。 + + Returns: + str: 规范化后的标签。 + + Raises: + TypeError: tag 不是字符串。 + ValueError: 规范化失败。 + """ + if not isinstance(tag, str): + raise TypeError("tag must be a string") + cleaned = tag.strip() + if strict: + if not is_normalized_tag(cleaned): + raise ValueError(f"tag '{tag}' is not normalized") + return cleaned + + lowered = cleaned.lower() + lowered = re.sub(r"\s+", "_", lowered) + lowered = lowered.replace(":", "_") + lowered = lowered.replace("/", ".") + if not is_normalized_tag(lowered): + raise ValueError(f"tag '{tag}' cannot be normalized") + return lowered + + +@dataclass(frozen=True) +class TagPolicy: + """标签传播策略。""" + + propagate_prefixes: tuple[str, ...] = ( + "role.", + "anchor.", + "group.", + ) + propagate_exact: tuple[str, ...] = ( + "top", + "bottom", + "left", + "right", + "front", + "back", + "side", + "surface", + ) + block_prefixes: tuple[str, ...] = ( + "feature.", + "state.", + "face.", + "edge.", + "wire.", + "vertex.", + "solid.", + "legacy.", + ) + block_exact: tuple[str, ...] = () + + def should_propagate(self, tag: str) -> bool: + """判断标签是否应该向下传播。 + + Args: + tag: 标签字符串。 + + Returns: + bool: 是否传播。 + """ + if tag in self.block_exact: + return False + if any(tag.startswith(prefix) for prefix in self.block_prefixes): + return False + if tag in self.propagate_exact: + return True + if any(tag.startswith(prefix) for prefix in self.propagate_prefixes): + return True + return False + + +DEFAULT_TAG_POLICY = TagPolicy() + + +def resolve_anchor_tag_candidates(tag: str) -> List[str]: + """生成锚点标签的候选列表。 + + Args: + tag: 用户输入标签。 + + Returns: + List[str]: 候选标签列表,按优先级排序。 + """ + token = tag.strip().lower() + if not token: + return [] + + if is_normalized_tag(token) and "." in token: + candidates = [token] + for prefix in ("role.", "anchor.", "face.", "legacy."): + if token.startswith(prefix): + candidates.append(token[len(prefix) :]) + return candidates + + return [ + f"role.{token}", + f"anchor.{token}", + f"face.{token}", + f"legacy.{token}", + token, + ] diff --git a/test/test_ql.py b/test/test_ql.py new file mode 100644 index 00000000..c8b9ac5f --- /dev/null +++ b/test/test_ql.py @@ -0,0 +1,74 @@ +import unittest + +import simplecadapi as scad +from simplecadapi import ql as Q + + +class TestQLTagPredicates(unittest.TestCase): + def test_tag_exact_and_wildcard(self): + box = scad.make_box_rsolid(1.0, 1.0, 1.0) + box.apply_tag("role.mounting_surface") + + self.assertTrue(Q.tag("role.mounting_surface")(box)) + self.assertTrue(Q.tag("role.*")(box)) + self.assertFalse(Q.tag("role.other")(box)) + + def test_tag_face_prefix(self): + box = scad.make_box_rsolid(1.0, 1.0, 1.0) + box.auto_tag_faces("box") + top_faces = [face for face in box.get_faces() if face.has_tag("face.top")] + self.assertTrue(top_faces) + + top_face = top_faces[0] + self.assertTrue(Q.tag("face.top")(top_face)) + self.assertTrue(Q.tag("face.*")(top_face)) + + +class TestQLMetadataPredicates(unittest.TestCase): + def test_meta_eq_and_compare(self): + box = scad.make_box_rsolid(2.0, 3.0, 4.0) + + self.assertTrue(Q.meta("geo.type", "==", "box")(box)) + self.assertTrue(Q.meta("geo.size.x", ">", 1.0)(box)) + + def test_select_where_order_first(self): + c1 = scad.make_cylinder_rsolid(1.0, 1.0) + c2 = scad.make_cylinder_rsolid(1.0, 3.0) + c3 = scad.make_cylinder_rsolid(1.0, 2.0) + + result = ( + Q.select([c1, c2, c3]).order_by(Q.value("geo.height"), desc=True).first() + ) + + self.assertIsNotNone(result) + self.assertEqual(result.get_metadata("geo")["height"], 3.0) + + def test_where_and_not(self): + box = scad.make_box_rsolid(1.0, 1.0, 1.0) + cyl = scad.make_cylinder_rsolid(1.0, 1.0) + box.apply_tag("role.mounting_surface") + box.apply_tag("state.debug", propagate=False) + + predicate = Q.and_( + Q.meta("geo.type", "==", "box"), + Q.tag("role.mounting_surface"), + Q.not_(Q.tag("state.*")), + ) + + result = Q.select([box, cyl]).where(predicate).all() + self.assertEqual(result, []) + + predicate = Q.and_( + Q.meta("geo.type", "==", "box"), + Q.tag("role.mounting_surface"), + ) + + result = Q.select([box, cyl]).where(predicate).all() + self.assertEqual(result, [box]) + + def test_first_empty(self): + self.assertIsNone(Q.select([]).first()) + + +if __name__ == "__main__": + unittest.main() diff --git a/test/test_tagging_refactor.py b/test/test_tagging_refactor.py new file mode 100644 index 00000000..7f3cbada --- /dev/null +++ b/test/test_tagging_refactor.py @@ -0,0 +1,74 @@ +import unittest + +import simplecadapi as scad +from simplecadapi import tagging + + +class TestTaggingRefactor(unittest.TestCase): + def test_tag_validation(self): + self.assertTrue(tagging.is_normalized_tag("geom.primitive.box")) + self.assertTrue(tagging.is_normalized_tag("face.top")) + self.assertFalse(tagging.is_normalized_tag("Face.Top")) + self.assertFalse(tagging.is_normalized_tag("size: 2x3x4")) + + def test_tag_policy_propagation(self): + policy = tagging.DEFAULT_TAG_POLICY + self.assertTrue(policy.should_propagate("role.mounting_surface")) + self.assertTrue(policy.should_propagate("anchor.datum.primary")) + self.assertTrue(policy.should_propagate("group.fasteners")) + self.assertFalse(policy.should_propagate("feature.extrude.start_face")) + self.assertFalse(policy.should_propagate("state.debug")) + self.assertFalse(policy.should_propagate("face.top")) + self.assertFalse(policy.should_propagate("legacy.top")) + + def test_apply_tag_propagates_role(self): + box = scad.make_box_rsolid(1.0, 1.0, 1.0) + box.apply_tag("role.mounting_surface") + + faces = box.get_faces() + self.assertTrue(any(face.has_tag("role.mounting_surface") for face in faces)) + + edges = box.get_edges() + self.assertTrue(any(edge.has_tag("role.mounting_surface") for edge in edges)) + + def test_anchor_resolution_role_tag(self): + box = scad.make_box_rsolid(1.0, 1.0, 1.0) + box.auto_tag_faces("box") + top_faces = [face for face in box.get_faces() if face.has_tag("top")] + self.assertTrue(top_faces) + top_face = top_faces[0] + top_face.apply_tag("role.mounting_surface") + + asm = scad.make_assembly_rassembly([("box", box)]) + anchor = asm.part("box").face_center("mounting_surface") + + self.assertEqual(anchor.part, "box") + self.assertEqual(anchor.label, "face:mounting_surface") + + +class TestAutoTagFacesNamespaces(unittest.TestCase): + def test_box_faces_have_new_tags(self): + box = scad.make_box_rsolid(1.0, 1.0, 1.0) + box.auto_tag_faces("box") + faces = box.get_faces() + self.assertTrue(any(face.has_tag("face.top") for face in faces)) + self.assertTrue(any(face.has_tag("face.bottom") for face in faces)) + + def test_cylinder_faces_have_new_tags(self): + cylinder = scad.make_cylinder_rsolid(1.0, 2.0) + cylinder.auto_tag_faces("cylinder") + faces = cylinder.get_faces() + self.assertTrue(any(face.has_tag("face.top") for face in faces)) + self.assertTrue(any(face.has_tag("face.bottom") for face in faces)) + self.assertTrue(any(face.has_tag("face.side") for face in faces)) + + def test_sphere_faces_have_new_tags(self): + sphere = scad.make_sphere_rsolid(1.0) + sphere.auto_tag_faces("sphere") + faces = sphere.get_faces() + self.assertEqual(len(faces), 1) + self.assertTrue(faces[0].has_tag("face.surface")) + + +if __name__ == "__main__": + unittest.main()