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)
|