Skip to content

laneway

巷道/隧道相关 CLI 命令(本地操作 + Dimine 导入)。

cmd_section(fmt, section_type, width, height, width_up=0.0, wide_arch_ratio=2, point_count=20)

计算巷道断面轮廓点坐标(本地操作)。

Source code in dimine_python_sdk\cli\commands\laneway.py
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
def cmd_section(fmt: str, section_type: int, width: float, height: float | None,
                width_up: float = 0.0, wide_arch_ratio: int = 2, point_count: int = 20) -> None:
    """计算巷道断面轮廓点坐标(本地操作)。"""
    section_type = safe_int(section_type)
    width = safe_float(width)
    if height is not None:
        height = safe_float(height)
    width_up = safe_float(width_up)
    wide_arch_ratio = safe_int(wide_arch_ratio)
    point_count = safe_int(point_count)

    err = require_local_sdk()
    if err:
        output_error(err, fmt)

    from dimine_python_sdk.lib.exploitation import Laneway, SectionParam

    try:
        h = height if height is not None else width * 0.8
        param = SectionParam(
            type=section_type,
            width=width,
            wall_height=h,
            width_up=width_up,
            wide_arch_ratio=wide_arch_ratio,
            point_count=point_count,
        )
        result = Laneway.get_section(param)
        contour_points = _points_to_list(result)
        output_result({
            "success": True,
            "section_type": section_type,
            "width": width,
            "wall_height": h,
            "width_up": width_up,
            "wide_arch_ratio": wide_arch_ratio,
            "point_count": len(contour_points),
            "points": contour_points,
        }, fmt)
    except Exception as e:
        output_error(f"计算断面轮廓失败: {e}", fmt)

cmd_tunnel(fmt, section_type, width, height, center_lines, width_up=0.0, wide_arch_ratio=2, point_count=20, close=False, connectivity=True, method=0, no_import=False)

根据中心线和断面生成巷道三维模型,默认自动导入 Dimine。

Source code in dimine_python_sdk\cli\commands\laneway.py
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
def cmd_tunnel(fmt: str, section_type: int, width: float, height: float | None,
               center_lines: str | None, width_up: float = 0.0, wide_arch_ratio: int = 2,
               point_count: int = 20, close: bool = False, connectivity: bool = True,
               method: int = 0, no_import: bool = False) -> None:
    """根据中心线和断面生成巷道三维模型,默认自动导入 Dimine。"""
    import_to_dimine = not no_import
    section_type = safe_int(section_type)
    width = safe_float(width)
    if height is not None:
        height = safe_float(height)
    width_up = safe_float(width_up)
    wide_arch_ratio = safe_int(wide_arch_ratio)
    point_count = safe_int(point_count)
    method = safe_int(method)

    err = require_local_sdk()
    if err:
        output_error(err, fmt)

    if center_lines is None:
        err = require_remote_sdk()
        if err:
            output_error(f"未提供 --center-lines,需要从 Dimine 获取选中线段: {err}", fmt)
        try:
            lines = asyncio.run(_fetch_center_lines_from_selection())
        except Exception as e:
            output_error(f"获取选中线段失败: {e}", fmt)
    else:
        try:
            lines = _parse_center_lines(center_lines)
        except ValueError as e:
            output_error(str(e), fmt)

    if not isinstance(lines, list) or not lines:
        output_error("中心线必须是包含至少 1 条线段的数组", fmt)

    # 兼容用户直接传入单条线的情况:[[x,y,z], [x,y,z], ...] → 包装成列表
    if isinstance(lines[0], list) and len(lines[0]) > 0 and not isinstance(lines[0][0], list):
        lines = [lines]

    if lines and not all(isinstance(line, list) for line in lines):
        output_error("中心线必须是包含至少 1 条线段的数组", fmt)

    if all(len(line) < 2 for line in lines):
        output_error("中心线每条线段必须包含至少 2 个点", fmt)

    from dimine_python_sdk.lib.exploitation import Laneway, LanewayParam, SectionParam

    try:
        h = height if height is not None else width * 0.8
        section = SectionParam(
            type=section_type,
            width=width,
            wall_height=h,
            width_up=width_up,
            wide_arch_ratio=wide_arch_ratio,
            point_count=point_count,
        )
        param = LanewayParam(
            section=section,
            polylines_set=lines,
            close=close,
            connectivity=connectivity,
            method=method,
        )
        geometries = Laneway.get_lane_way_model(param)
        if not geometries and lines:
            output_error("有线段但是无法生成巷道模型,请检查输入参数")
        if not geometries:
            output_error("无法生成巷道模型,请检查输入参数")

        result: dict = {
            "success": True,
            "section_type": section_type,
            "width": width,
            "wall_height": h,
            "center_line_points": sum(len(line) for line in lines),
            "total_faces": sum(len(g.faces) for g in geometries),
            "total_vertices": sum(len(g.points) for g in geometries),
        }

        if import_to_dimine:
            import_result = asyncio.run(_import_to_dimine(geometries))
            result["imported"] = import_result
        else:
            # 仅在明确不导入时返回简化模型摘要,不含原始坐标
            result["imported"] = False

        output_result(result, fmt)
    except Exception as e:
        output_error(f"生成巷道模型失败: {e}", fmt)

register_commands(subparsers, format_parent)

向 subparsers 注册巷道相关子命令。

Source code in dimine_python_sdk\cli\commands\laneway.py
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
def register_commands(subparsers, format_parent) -> None:
    """向 subparsers 注册巷道相关子命令。"""
    p = subparsers.add_parser("laneway-section", parents=[format_parent], help="计算巷道断面轮廓点")
    p.add_argument("--type", type=int, required=True, dest="section_type",
                   help="断面类型编号: 0=矩形拱 1=梯形拱 2=圆形拱 3=圆弧拱 4=三心拱 5=六边形拱 6=自定义")
    p.add_argument("--width", type=float, required=True, help="巷道宽度(米)")
    p.add_argument("--height", type=float, default=None, help="墙高(米),不提供则默认 width * 0.8")
    p.add_argument("--width-up", type=float, default=0.0, help="上宽度(米),默认 0.0")
    p.add_argument("--wide-arch-ratio", type=int, default=2, help="宽度/拱高比,默认 2")
    p.add_argument("--point-count", type=int, default=20, help="轮廓采集点数,默认 20")

    p = subparsers.add_parser("laneway-tunnel", parents=[format_parent], help="生成巷道三维模型并导入 Dimine")
    p.add_argument("--type", type=int, required=True, dest="section_type",
                   help="断面类型编号: 0=矩形拱 1=梯形拱 2=圆形拱 3=圆弧拱 4=三心拱 5=六边形拱 6=自定义")
    p.add_argument("--width", type=float, required=True, help="巷道宽度(米)")
    p.add_argument("--height", type=float, default=None, help="墙高(米),不提供则默认 width * 0.8")
    p.add_argument("--width-up", type=float, default=0.0, help="上宽度(米),默认 0.0")
    p.add_argument("--wide-arch-ratio", type=int, default=2, help="宽度/拱高比,默认 2")
    p.add_argument("--point-count", type=int, default=20, help="轮廓采集点数,默认 20")
    p.add_argument("--center-lines", default=None, help="中心线 JSON 数组 [[[x1,y1,z1],[x2,y2,z2],...],...],每条多段线为内层数组;不指定则自动获取当前选中的线段")
    p.add_argument("--close", action="store_true", default=False, help="巷道尽头是否封口")
    p.add_argument("--no-connectivity", action="store_false", dest="connectivity", default=True, help="禁用交叉口自动联通(默认自动联通)")
    p.add_argument("--method", type=int, default=0, choices=[0, 1, 2],
                   help="建模方法: 0=整体连接 1=拐点分离 2=顶墙分离")
    p.add_argument("--no-import", action="store_true", default=False,
                   help="仅生成本地模型,不导入到 Dimine")