Skip to content

laneway

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

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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
def register_commands(subparsers, format_parent) -> None:
    """向 subparsers 注册巷道相关子命令。"""
    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")