From d3fba064a2cb4c614abace992f5239bcfce57c14 Mon Sep 17 00:00:00 2001 From: cp6-io Date: Fri, 20 Nov 2026 08:10:28 +0800 Subject: [PATCH] =?UTF-8?q?Wave6=20W35:=20=E7=AC=AC=E4=B8=89=E6=96=B9=20AC?= =?UTF-8?q?IS=20SAT=20=E8=87=AA=E7=94=B1=E6=9B=B2=E9=9D=A2/=E6=9B=B2?= =?UTF-8?q?=E7=BA=BF=E5=86=85=E5=B5=8C=20NURBS=20=E5=9D=97=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=20+=20degraded=20=E8=BF=91=E4=BC=BC=E9=80=9A=E9=81=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 解析记录内嵌 nubs/nurbs 块(knot 对 + 控制点/齐次权重):spline-surface/nurbs-surface 的 exactsur 控制网格 -> NurbsSurface;intcurve/spline/nurbs/exactcur/bs3-curve -> NurbsCurve,挂到 B-rep 边; - 网格/控制点缺失时显式降级:构造型自由曲面按边界拟合平面、自由曲线按端点线性近似,闭合/退化曲线诚实 跳过;has_degraded_geometry -> capability=acis-sat-text-degraded + Partial + warnings 点名记录类型; - format_capability_ex(): intcurve/spline/nurbs/*-curve/*-surface 标签细化为 acis-sat-text-nurbs(仍 partial); 格式级 14 行矩阵冻结不变; - 测试:新增 Wave6SatNurbs.* 12 例(精确网格/有理权重/缺权重/构造型回落/闭合跳过/畸形与退化拒绝/体积有界), Wave4/Wave5 旧断言随能力升级迁移;平面与短名解析路径逐位不变(140/140 PASS、CBRA 18 行逐字节一致、 B5 pass=4/4 digest=d1c875b2322e097d)。 --- docs/planning/wave6/io-notes.md | 184 +++++++ src/foundation/industrial_formats.cpp | 501 +++++++++++++++++-- tests/foundation/test_industrial_formats.cpp | 441 +++++++++++++--- 3 files changed, 1029 insertions(+), 97 deletions(-) create mode 100644 docs/planning/wave6/io-notes.md diff --git a/docs/planning/wave6/io-notes.md b/docs/planning/wave6/io-notes.md new file mode 100644 index 000000000..69f4e849c --- /dev/null +++ b/docs/planning/wave6/io-notes.md @@ -0,0 +1,184 @@ +# Wave6 / W35(P1, task-108):第三方 ACIS SAT 自由曲面/自由曲线近似 NURBS 导入 + +- 工作流:W35(VDE 内核 KCP-1.0 Wave 6,P1) +- 任务板:`task-108`(owner `cp6-io`) +- 工作区:`D:\3_Source\VDE_cp6_io`,分支 `feat/kcp6-io` +- 基线:`b185569d`(VDE 1.0.472 main,含 W30:第三方 SAT 短名解析面/曲线 + 27 行实体能力矩阵) +- 上游依据:`docs/planning/wave5/io-notes.md` §4/§6——W30 明确 deferred「spline-surface / nurbs-surface / + intcurve 曲线」并把「spline/nurbs 作为近似 NURBS 导入」列为建议下一步(1–2 人日)。 + +## 1. 问题与根因(before) + +W30 的第三方 SAT 解析器(`src/foundation/industrial_formats.cpp` 内 `acis` 命名空间)只把**短名解析面/曲线** +(`plane/cylinder/sphere/cone/torus`、`straight/ellipse`)映射进 VDE B-rep: + +1. `build_face()` 对曲面 `sat_map_surface()` 未识别的记录(`spline-surface`/`nurbs-surface`/现代 `*-surface`) + 一律跳过(`faces_skipped`/`skipped_nonplanar_surface`),整面丢失; +2. 边曲线 `sat_map_curve()` 未识别(`intcurve`/`spline`/`nurbs`/`bs3-curve` 等)时整面跳过 + (`skipped_curved_edge`),自由曲线拓扑无法进入 VDE; +3. 全自由曲面模型 → 空模型 + `Unsupported`;混合模型 → `Partial` 且丢面; +4. 能力矩阵中 `intcurve/spline/nurbs/*-curve/*-surface` 标 `partial`,但实际「未解析」,语义偏乐观; +5. 无 degraded 报告通道:近似几何无法与精确几何区分。 + +真实 SAT 文本里自由曲面/自由曲线记录通常内嵌 NURBS 控制网格(`nubs` 非有理 / `nurbs` 有理), +W30 未解析这些块。 + +## 2. 本增量(after) + +### 2.1 解析依据(clean-room) + +仅参考公开 ACIS SAT 文本结构(记录名、字段顺序、指针语法): + +- ACIS 公开文档 "Getting Started" `GET/03OV/0024.HTM`(bs3_curve/bs3_surface 的 `nubs`/`nurbs` 字段顺序); +- 公开真实 SAT 文本样本(如 coreform 官方 ACIS 7.0 `example02.sat`、ACIS 5.0 合成样本)中 + `intcurve-curve ... { exactcur nubs 3 open 2 ... }`、`spline-surface ... { exactsur nubs 1 1 ... }` 的实际布局。 + +仓库内测试夹具全部为手工合成的 SAT 文本,未使用第三方代码、无第三方 CAD 导出内容。 + +### 2.2 内嵌 NURBS 块解析(新增,anonymous namespace) + +新增辅助(`src/foundation/industrial_formats.cpp`,`sat_point_from3` 之后): + +| 函数 | 作用 | +|---|---| +| `sat_parse_knot_pairs` / `sat_expand_knots` | 解析 `` 对并按 SAT 约定展开节点:`Σmult` 展开后首末各补 1 个端点节点 → `n_cp+degree+1` 个非递减节点(SAT 保存的钳位端点重数比真实小 1) | +| `sat_parse_nurbs_curve_block` | 记录内扫描 `nubs`/`nurbs` 块 → `NurbsCurve`:`
` + knot 对 + `n_cp=Σmult-degree+1` 个 3D 极点(有理版每极点 4 个数,权重 > 0) | +| `sat_parse_nurbs_surface_block` | 优先从 `exactsur` 之后扫描(否则全记录)→ `NurbsSurface`:` ` + u/v knot 对 + `n_u×n_v` 控制网格(u 外层 v 内层;有理版每极点 4 个数) | +| `sat_approx_plane_surface` | 无控制网格的自由曲面:按面外环边界点 Newell 法向拟合平面(`NurbsSurface::plane`),退化(共线/零面积)返回 false | +| `sat_approx_linear_curve` | 无控制点的自由曲线:按边两端点线性近似(degree-1 `NurbsCurve`) | + +安全与有界性:阶次 1–64;knot entry 1–4096;控制点数 ≥ degree+1 且 ≤1e6;曲面网格 ≤4096×4096 且 +乘积 ≤1e6;控制点/节点/权重必须有限;权重必须 >0;构造后对 `evaluate(0/0.5/1)`(曲面 `(0,0)/(1,1)/(0.5,0.5)`) +做有限性校验;`NurbsCurve`/`NurbsSurface` 构造异常全部捕获并回落,不向上抛、不崩溃。 +`periodic`/`closed` 形式的 NURBS 块周期结点约定无法 clean-room 确认 → 不解析(走近似/跳过,不伪造精确性)。 + +### 2.3 精确路径(exactness=exact) + +- 曲线:`intcurve`/`intcurve-curve`/`spline`/`nurbs`/`exactcur`/`bs3-curve`/`*-curve` 记录若含 `nubs`/`nurbs` 块, + `sat_map_curve()` 返回 `exact=true` + `NurbsCurve`,`add_topology_edge()` 以 `set_edge_curve` 挂到 B-rep 边; + 权重保留(`nurbs` 块齐次权),`nubs` 块均匀权重 1。 +- 曲面:`spline-surface`/`nurbs-surface`/`*-surface` 记录若含 `exactsur`(可选 `full`)+ `nubs`/`nurbs` 网格, + `NurbsSurface` 精确导入(`degree_u/v`、`num_control_points()`、`weights()` 与文件一致)。 +- 统计:`imported_surface_types` / `imported_curve_types` 记记录名;`has_analytic_geometry=true`; + 报告 capability = `acis-sat-text-analytic`。 + +### 2.4 近似路径(degraded,显式标注、不伪造) + +- 构造型自由曲面(`rotsur`/`rulesur` 等,无 2D 控制网格)→ 按外环边界平面近似,统计 + `faces_with_approximate_surface`/`approximate_surface_types`,`has_degraded_geometry=true`; +- 自由曲线无内嵌块(如 `intcurve-curve ... { ref 1 }` 子类型引用)→ 边端点线性近似,统计 + `edges_with_approximate_curve`/`approximate_curve_types`; +- 闭合/退化自由曲线(边两端点重合、无法线性近似)→ 该面诚实跳过:`skipped_closed_freeform_curve` / + `skipped_closed_curve_types`,warning 明示「闭合」; +- 报告通道:`has_degraded_geometry` 时报告 `capability="acis-sat-text-degraded"`、`status=Partial`、 + `error_code="import.partial.third_party_sat"`,message 追加「近似面 X,近似曲线 Y(无内嵌 NURBS 控制网格, + 按边界/端点近似)」,warnings 逐类点名记录名与降级原因。 + +### 2.5 既有路径逐位不变 + +- `plane-surface`(W24 路径)仍逐面新建单位 1×1 平面、直边不挂曲线;`plane/cylinder/sphere/cone/torus` + 短名解析面、`straight/straight-curve`、`ellipse/ellipse-curve` 映射逻辑未改动; +- `native_import_capabilities()` 14 行 format/payload 矩阵冻结不变; +- `PlaneImportBitIdenticalRegression` 等既有回归测试不改断言仍全绿。 + +### 2.6 能力矩阵更新(`format_capability_ex()`) + +实体级矩阵 32 行结构不变,仅自由曲面/曲线行的 capability 标签细化: + +| record | change | +|---|---| +| `intcurve` / `spline` / `nurbs` / `*-curve` | `acis-sat-text-analytic` + partial → `acis-sat-text-nurbs` + partial | +| `*-surface` | `acis-sat-text-analytic` + partial → `acis-sat-text-nurbs` + partial | +| 其余 27 行 | 不变 | + +`acis-sat-text-nurbs` 的 exactness 语义:内嵌 `nubs`/`nurbs` 块 → 精确 NURBS;块缺失 → 运行期降级为 +`acis-sat-text-degraded`(近似平面/线性曲线),矩阵状态仍为 partial(不宣称全面支持)。 + +## 3. 测试 + +- 新增 `Wave6SatNurbs.*` 测试 12 个(`tests/foundation/test_industrial_formats.cpp` 末尾): + 1. `SplineSurfaceExactNurbsGrid`:exactsur+nubs 2×2 网格 → 精确双线性曲面、四角命中、权重均匀 1; + 2. `NurbsSurfaceRationalWeights`:nurbs 有理网格 → 权重 1/0.5/2/1 保留、端点精确; + 3. `NurbsSurfaceMissingWeightsUniform`:缺权重 → 均匀权重 1; + 4. `SplineSurfaceConstructedFallback`:rotsur 构造型 → 边界平面近似 + degraded + warning 含记录名; + 5. `IntcurveNurbsCurveExact`:exactcur+nubs 三次 Bezier → 边曲线 degree 3、端点精确; + 6. `IntcurveRefApproxFallback`:`{ ref N }` 无控制点 → 端点线性近似 + degraded; + 7. `ClosedIntcurveSkippedHonestly`:闭合 intcurve 边端点重合 → 面诚实跳过、skipped_entity_types 含记录名; + 8. `MalformedNurbsBlockFallsBack`:网格截断 → 回落近似、不崩溃; + 9. `DegenerateNurbsCountsRejected`:非法 entry 计数 → 拒绝解析、回落近似; + 10. `ApproxGeometryVolumeBounded`:多面自由曲面 → 面数受控、采样点有限有界(±1e3); + 11. `SplineSurfaceApproxFallback`:平面+自由曲面混合 → 平面精确、曲面 degraded、2 面均导入; + 12. `NurbsCurveApproxFallback`:nurbs 曲线无块 → 不再整面 Unsupported,近似 + degraded。 +- 原 Wave5 用例 `SplineSurfacePartialDiagnostic` / `NurbsCurveExplicitUnsupported` 的旧「明确跳过/Unsupported」 + 断言随能力升级迁移为上述 W35 行为用例(注释保留迁移说明);`FormatCapabilityExConsistency` 的三条 + capability 断言更新为 `acis-sat-text-nurbs`。 +- Wave4 互操作用例随「自由曲面不再整面跳过」升级了 3 条(断言从 skip/Unsupported 改为 degraded 近似导入): + `SatPartialWithDegradedSurface`(原 `SatPartialWithUnsupportedSurface`)、 + `SatCurvedOnlyDegradedApproximation`(原 `SatCurvedOnlyExplicitUnsupported`)、 + `ImportCadCurvedOnlySatDegradedWarning`(原 `ImportCadCurvedOnlySatFailsExplicitly`)。 +- 既有平面/解析面/椭圆/SAB 用例断言不变;`PlaneImportBitIdenticalRegression`、Wave5 短名解析面 + (sphere/cylinder/cone/torus/ellipse)5+1 用例全绿 → 平面与解析路径逐位不变。 + +## 4. 未支持与边界(诚实清单) + +- 周期/闭合(`periodic`/`closed`)NURBS 曲线块的周期结点语义未 clean-room 确认 → 不解析(近似/跳过); +- 构造型曲面(`rotsur`/`rulesur`/`sumsur` 等)不重建真实旋转/直纹面,仅 degraded 边界平面近似; +- 曲面 trim:导入面拓扑使用 SAT loop 顶点,不做 pcurve/trim 精确边界; +- 多重曲面(同一 face 多曲面记录)仍只取首曲面记录; +- 无内嵌控制点的自由曲线(`ref` 子类型引用、闭式曲线)不伪造控制点; +- 第三方 SAB 二进制仍显式拒绝(W30 语义不变)。 + +## 5. 风险与后续 + +- 近似几何(degraded)仅保证拓扑可导入与几何有界,不保证形状精度;消费方应读取 + `capability=acis-sat-text-degraded` / warnings 区分精确与近似; +- `acis-sat-text-nurbs` 为新 capability 标签:既有消费者若做白名单匹配需同步(格式级 14 行矩阵未变); +- 后续可提升:周期 NURBS 块(需确认周期结点约定)、构造型曲面的真旋转/直纹重建、pcurve trim 边界。 + +## 6. 验证证据 + +采集日期:2026-11-20;工作区 `D:\3_Source\VDE_cp6_io`(分支 `feat/kcp6-io`);证据目录 +`D:\3_Source\VDE_drawint\build\kcp6_evidence\io\`。 + +### 6.1 定向回归(`ctest -R "Industrial|Format|Import|Export|Sat|Interop"`) + +```text +100% tests passed, 0 tests failed out of 140 +Total Test time (real) = 4.59 sec +``` + +- 二进制全量:`build\tests\foundation\test_industrial_formats.exe` → 140/140 PASSED(17 suite, + 含既有 Wave4Interop 12 条、Wave5SatSurface 13 条、Wave6SatNurbs 12 条)。 +- 新增测试 12 个(`Wave6SatNurbs.*`);改写 3 条 Wave4 断言(见 §3)与 Wave5 能力断言; + `native_import_capabilities()` 14 行冻结未动(`CapabilityMatrixSnapshot` 绿)。 +- 证据:`ctest_targeted.log`。 + +### 6.2 CBRA 18 行 gated 逐字节一致(默认路径不变) + +```text +test_curved_boolean_baseline.exe --gtest_filter=CurvedBooleanBaseline.CurvedSurfaceFixturesBaseline +(VDE_CB4_SLOW_INTEGRATION=1)→ 提取 18 行 [CBRA] +ours=2344B ref=2344B DIFFBYTES=0 identical=True +ours_sha256=b3acddc6924eab8310ec18c6b24e1cc40e58d6e9e1df25544138327f56b42e2c +ref_sha256 =b3acddc6924eab8310ec18c6b24e1cc40e58d6e9e1df25544138327f56b42e2c +``` + +参考文件:`D:\3_Source\ViewDesignEngine\build\ab_1050_final_cbra_gated.txt`(SHA256 与 W30 记录的 +`B3ACDDC6…` 一致)。证据:`cbra_raw.log`、`cbra_gated_18lines.txt`、`cbra_verify.txt`。 + +### 6.3 B5 确定性 digest 不变 + +```text +bench_kcp.exe --suite b5 --rounds 3 --threads 1(OMP_NUM_THREADS=1) +BENCH B5 pass=4/4 digest=d1c875b2322e097d bit_identical=true +topology = 284 vertices / 436 edges / 146 loops / 146 faces / 1 shell +``` + +与 W30/W15 基线一致(pass=4/4、digest/topo 逐位不变)。证据:`b5_t1.log`、`b5_t1.json`。 + +### 6.4 交付物 + +- commit:``(基于 `b185569d`,1 个 commit:`industrial_formats.cpp` + `test_industrial_formats.cpp` + + 本 notes)。 +- patch:`D:\3_Source\VDE_drawint\build\catchup6\io.patch`。 + diff --git a/src/foundation/industrial_formats.cpp b/src/foundation/industrial_formats.cpp index 40738ba4a..54426fa82 100644 --- a/src/foundation/industrial_formats.cpp +++ b/src/foundation/industrial_formats.cpp @@ -2424,6 +2424,14 @@ struct SatThirdPartyStats { int faces_with_analytic_surface = 0; ///< 含解析曲面(短名记录映射)的面数 int edges_with_analytic_curve = 0; ///< 含解析曲线(非直线)的边数 bool has_analytic_geometry = false; ///< 是否导入了短名解析面/曲线 + // Wave6 W35:自由曲面/自由曲线近似导入统计(内嵌 NURBS 块缺失时的降级路径) + int faces_with_approximate_surface = 0; ///< 按边界平面近似的自由曲面数 + int edges_with_approximate_curve = 0; ///< 按端点线性近似的自由曲线数 + int skipped_closed_freeform_curve = 0; ///< 闭合/退化自由曲线跳过数 + bool has_degraded_geometry = false; ///< 是否发生 degraded 近似 + std::set approximate_surface_types; ///< 近似导入的曲面记录类型 + std::set approximate_curve_types; ///< 近似导入的曲线记录类型 + std::set skipped_closed_curve_types; ///< 闭合自由曲线记录类型 std::vector warnings; }; @@ -2616,6 +2624,300 @@ Point3D sat_point_from3(const std::vector& v, size_t at) { return Point3D(v[at], v[at + 1], v[at + 2]); } +bool sat_parse_int_token(const std::string& t, int& out) { + if (t.empty()) return false; + char* endp = nullptr; + const long v = std::strtol(t.c_str(), &endp, 10); + if (endp == nullptr || *endp != '\0') return false; + if (v < -2147483647L || v > 2147483647L) return false; + out = static_cast(v); + return true; +} + +bool sat_point_finite(const Point3D& p) { + return std::isfinite(p.x()) && std::isfinite(p.y()) && std::isfinite(p.z()); +} + +// ── Wave6 W35:自由曲面/自由曲线记录内嵌 NURBS 缓存解析 ── +// +// 公开 SAT 文本把 bs3 曲线/曲面存为 `nubs`(非有理)或 `nurbs`(有理,每极点 +// 后多一个齐次权)关键字引导的控制点/节点块;字段顺序见 ACIS 公开文档 +// "GET/03OV/0024.HTM"(clean-room:仅公开文本结构,不依赖 ACIS 头文件/源码): +// 曲线块: nubs +// + n_knot_entries 组 +// + n_cp 个极点(有理版 x y z w) +// + fit tolerance 及子类型尾部(忽略)。 +// 曲面块: nubs +// +// + u 向 对 + v 向 对 +// + n_cp_u × n_cp_v 控制网格(u 外层 v 内层)+ fit tolerance(忽略)。 +// n_cp = Σmult - degree + 1;节点多重度展开后首末各补 1(SAT 保存的钳位端点 +// 重数比真实小 1)得到 VDE 需要的 n_cp + degree + 1 个非递减节点。周期/闭合 +// 形式(periodic/closed)的周期结点约定无法 clean-room 确认,保守交给近似 +// 路径处理,不伪造精确几何。 +bool sat_parse_knot_pairs(const std::vector& tok, size_t& pos, int count, + std::vector>& pairs) { + pairs.clear(); + if (count < 1 || count > 4096) return false; + for (int i = 0; i < count; ++i) { + if (pos + 1 >= tok.size()) return false; + double knot = 0; + int mult = 0; + if (!sat_parse_double(tok[pos], knot) || !std::isfinite(knot)) return false; + if (!sat_parse_int_token(tok[pos + 1], mult) || mult <= 0 || mult > 4096) return false; + pairs.emplace_back(knot, mult); + pos += 2; + } + return true; +} + +bool sat_expand_knots(const std::vector>& pairs, int n_cp, int degree, + std::vector& knots) { + knots.clear(); + for (const auto& p : pairs) + for (int i = 0; i < p.second; ++i) knots.push_back(p.first); + const size_t needed = static_cast(n_cp + degree + 1); + if (knots.size() + 2 == needed) { + knots.insert(knots.begin(), pairs.front().first); + knots.push_back(pairs.back().first); + } else if (knots.size() != needed) { + return false; + } + bool first = true; + double prev = 0.0; + for (const double k : knots) { + if (!std::isfinite(k)) return false; + if (!first && k < prev) return false; + prev = k; + first = false; + } + return true; +} + +struct SatNurbsCurveCache { + bool ok = false; + bool rational = false; + std::string form; + NurbsCurve curve; +}; + +bool sat_parse_nurbs_curve_block(const SatRawRecord& rec, SatNurbsCurveCache& out) { + out = SatNurbsCurveCache{}; + const std::vector& tok = rec.tokens; + for (size_t i = 1; i + 3 < tok.size(); ++i) { + const bool rational = (tok[i] == "nurbs"); + if (!rational && tok[i] != "nubs") continue; + int degree = 0; + int n_entries = 0; + if (!sat_parse_int_token(tok[i + 1], degree)) continue; + if (degree < 1 || degree > 64) continue; + const std::string form = tok[i + 2]; + if (form != "open") continue; // periodic/closed:保守降级 + if (!sat_parse_int_token(tok[i + 3], n_entries)) continue; + size_t pos = i + 4; + std::vector> pairs; + if (!sat_parse_knot_pairs(tok, pos, n_entries, pairs)) continue; + long long sum = 0; + for (const auto& p : pairs) { + sum += p.second; + if (sum > 1000000) break; + } + if (sum > 1000000) continue; + const long long n_cp_ll = sum - degree + 1; + if (n_cp_ll < degree + 1 || n_cp_ll > 1000000) continue; + const int n_cp = static_cast(n_cp_ll); + std::vector knots; + if (!sat_expand_knots(pairs, n_cp, degree, knots)) continue; + const size_t stride = rational ? 4u : 3u; + if (pos + static_cast(n_cp) * stride > tok.size()) continue; + std::vector cps; + std::vector weights; + cps.reserve(static_cast(n_cp)); + if (rational) weights.reserve(static_cast(n_cp)); + bool numeric_ok = true; + for (int k = 0; k < n_cp && numeric_ok; ++k) { + double v[4] = {0.0, 0.0, 0.0, 1.0}; + for (size_t c = 0; c < stride; ++c) { + if (!sat_parse_double(tok[pos + static_cast(k) * stride + c], v[c]) || + !std::isfinite(v[c])) { + numeric_ok = false; + break; + } + } + if (!numeric_ok) break; + if (rational && !(v[3] > 0.0)) { + numeric_ok = false; + break; + } + cps.emplace_back(v[0], v[1], v[2]); + if (rational) weights.push_back(v[3]); + } + if (!numeric_ok) continue; + try { + NurbsCurve curve(cps, knots, rational ? weights : std::vector{}, degree); + if (!sat_point_finite(curve.evaluate(0.0)) || + !sat_point_finite(curve.evaluate(0.5)) || + !sat_point_finite(curve.evaluate(1.0))) + continue; + out.ok = true; + out.rational = rational; + out.form = form; + out.curve = std::move(curve); + return true; + } catch (const std::exception&) { + continue; + } + } + return false; +} + +struct SatNurbsSurfaceCache { + bool ok = false; + bool rational = false; + NurbsSurface surface; +}; + +bool sat_parse_nurbs_surface_block(const SatRawRecord& rec, SatNurbsSurfaceCache& out) { + out = SatNurbsSurfaceCache{}; + const std::vector& tok = rec.tokens; + // 优先精确子类型 `exactsur`(可带 `full` 前缀)之后的块;否则全记录扫描 + // (兼容直接内嵌曲面网格的记录,如 nurbs-surface)。 + size_t start = 1; + for (size_t i = 1; i < tok.size(); ++i) { + if (tok[i] == "exactsur") { + start = i + 1; + break; + } + } + for (size_t i = start; i + 8 < tok.size(); ++i) { + const bool rational = (tok[i] == "nurbs"); + if (!rational && tok[i] != "nubs") continue; + int udeg = 0, vdeg = 0, n_u_entries = 0, n_v_entries = 0; + if (!sat_parse_int_token(tok[i + 1], udeg)) continue; + if (!sat_parse_int_token(tok[i + 2], vdeg)) continue; + if (udeg < 1 || udeg > 64 || vdeg < 1 || vdeg > 64) continue; + if (tok[i + 3] != "open" || tok[i + 4] != "open") continue; + // tok[i + 5] / tok[i + 6] 为 u/v singularity 标识(none/singular 等)。 + if (!sat_parse_int_token(tok[i + 7], n_u_entries)) continue; + if (!sat_parse_int_token(tok[i + 8], n_v_entries)) continue; + size_t pos = i + 9; + std::vector> u_pairs, v_pairs; + if (!sat_parse_knot_pairs(tok, pos, n_u_entries, u_pairs)) continue; + if (!sat_parse_knot_pairs(tok, pos, n_v_entries, v_pairs)) continue; + long long sum_u = 0, sum_v = 0; + for (const auto& p : u_pairs) sum_u += p.second; + for (const auto& p : v_pairs) sum_v += p.second; + if (sum_u > 1000000 || sum_v > 1000000) continue; + const long long n_u_ll = sum_u - udeg + 1; + const long long n_v_ll = sum_v - vdeg + 1; + if (n_u_ll < udeg + 1 || n_v_ll < vdeg + 1) continue; + if (n_u_ll > 4096 || n_v_ll > 4096) continue; + if (n_u_ll * n_v_ll > 1000000) continue; + const int n_u = static_cast(n_u_ll); + const int n_v = static_cast(n_v_ll); + std::vector knots_u, knots_v; + if (!sat_expand_knots(u_pairs, n_u, udeg, knots_u)) continue; + if (!sat_expand_knots(v_pairs, n_v, vdeg, knots_v)) continue; + const size_t stride = rational ? 4u : 3u; + const size_t n_grid = static_cast(n_u) * static_cast(n_v); + if (pos + n_grid * stride > tok.size()) continue; + std::vector> grid( + static_cast(n_u), std::vector(static_cast(n_v))); + std::vector> weights; + if (rational) + weights.assign(static_cast(n_u), std::vector(static_cast(n_v), 1.0)); + bool numeric_ok = true; + size_t at = pos; + for (int iu = 0; iu < n_u && numeric_ok; ++iu) { + for (int iv = 0; iv < n_v && numeric_ok; ++iv) { + double v[4] = {0.0, 0.0, 0.0, 1.0}; + for (size_t c = 0; c < stride; ++c) { + if (!sat_parse_double(tok[at + c], v[c]) || !std::isfinite(v[c])) { + numeric_ok = false; + break; + } + } + if (!numeric_ok) break; + if (rational && !(v[3] > 0.0)) { + numeric_ok = false; + break; + } + grid[static_cast(iu)][static_cast(iv)] = Point3D(v[0], v[1], v[2]); + if (rational) weights[static_cast(iu)][static_cast(iv)] = v[3]; + at += stride; + } + } + if (!numeric_ok) continue; + try { + NurbsSurface surface(rational ? grid : std::move(grid), knots_u, knots_v, + rational ? weights : std::vector>{}, udeg, + vdeg); + if (!sat_point_finite(surface.evaluate(0.0, 0.0)) || + !sat_point_finite(surface.evaluate(1.0, 1.0)) || + !sat_point_finite(surface.evaluate(0.5, 0.5))) + continue; + out.ok = true; + out.rational = rational; + out.surface = std::move(surface); + return true; + } catch (const std::exception&) { + continue; + } + } + return false; +} + +// 无内嵌控制网格的自由曲面:以面边界点拟合平面近似(degraded),保证拓扑可 +// 导入且几何有界。返回 false 表示边界退化(共线/零面积)无法近似。 +bool sat_approx_plane_surface(const std::vector& pts, NurbsSurface& out) { + if (pts.size() < 3) return false; + Vector3D n = Vector3D::Zero(); + for (size_t i = 0; i < pts.size(); ++i) { + const Point3D& a = pts[i]; + const Point3D& b = pts[(i + 1) % pts.size()]; + n += a.cross(b); + } + if (n.norm() <= 1e-14) return false; + n = Vector3D(n / n.norm()); + const Point3D origin = pts.front(); + Vector3D u; + for (size_t i = 1; i < pts.size(); ++i) { + Vector3D d = pts[i] - origin; + d = d - n * d.dot(n); + if (d.norm() > 1e-12) { + u = Vector3D(d / d.norm()); + break; + } + } + if (u.norm() <= 1e-12) return false; + const Vector3D v = Vector3D(n.cross(u)); + double umax = 0.0, vmax = 0.0; + for (const Point3D& p : pts) { + const Vector3D d = p - origin; + umax = std::max(umax, std::abs(d.dot(u))); + vmax = std::max(vmax, std::abs(d.dot(v))); + } + if (!(umax > 1e-12) || !(vmax > 1e-12)) return false; + try { + out = NurbsSurface::plane(origin, u, v, umax, vmax); + } catch (const std::exception&) { + return false; + } + return !out.is_empty() && (out.degree_u() > 0 || out.degree_v() > 0); +} + +// 无内嵌控制点的自由曲线:以边两端点线性近似(degraded)。 +bool sat_approx_linear_curve(const Point3D& p0, const Point3D& p1, NurbsCurve& out) { + if (!sat_point_finite(p0) || !sat_point_finite(p1)) return false; + if ((p1 - p0).norm() <= 1e-14) return false; + try { + out = NurbsCurve({p0, p1}, {0.0, 0.0, 1.0, 1.0}, {}, 1); + } catch (const std::exception&) { + return false; + } + return sat_point_finite(out.evaluate(0.0)) && sat_point_finite(out.evaluate(1.0)); +} + // 曲面实体映射结果:recognized=记录属精确子集;exact=已成功映射到 VDE 解析曲面。 struct SatSurfaceMapping { bool recognized = false; @@ -2624,11 +2926,13 @@ struct SatSurfaceMapping { NurbsSurface surface; }; -// 曲线实体映射结果:is_line=直线(无需显式曲线对象,按既有边处理)。 +// 曲线实体映射结果:is_line=直线(无需显式曲线对象,按既有边处理); +// approximate=记录属自由曲线子集但无内嵌 nubs/nurbs 块(按端点线性近似)。 struct SatCurveMapping { bool recognized = false; bool exact = false; bool is_line = false; + bool approximate = false; std::string record_type; NurbsCurve curve; }; @@ -2725,8 +3029,17 @@ SatSurfaceMapping sat_map_surface(const SatRawRecord& rec) { return m; } +// 自由(非直线/非椭圆)曲线记录名:intcurve/spline/nurbs/bs3-curve/exactcur 等。 +bool sat_freeform_curve_name(const std::string& t) { + return t == "intcurve" || t == "intcurve-curve" || t == "spline" || t == "spline-curve" || + t == "nurbs" || t == "nurbs-curve" || t == "exactcur" || t == "exactcur-curve" || + t == "bs3-curve" || sat_ends_with(t, "-curve"); +} + // SAT 曲线记录 → VDE 解析曲线。straight/straight-curve 视为直线(按既有直边 -// 拓扑处理,不建显式曲线对象);ellipse/ellipse-curve 映射为 NurbsCurve::ellipse。 +// 拓扑处理,不建显式曲线对象);ellipse/ellipse-curve 映射为 NurbsCurve::ellipse; +// Wave6 W35:intcurve/spline/nurbs 等自由曲线若有内嵌 nubs/nurbs 块则精确构造, +// 无块(如 { ref N } 子类型引用)时标记 approximate 由调用方按端点近似并告警。 SatCurveMapping sat_map_curve(const SatRawRecord& rec) { SatCurveMapping m; m.record_type = rec.type; @@ -2736,7 +3049,18 @@ SatCurveMapping sat_map_curve(const SatRawRecord& rec) { m.is_line = true; return m; } - if (rec.type != "ellipse" && rec.type != "ellipse-curve") return m; + if (rec.type != "ellipse" && rec.type != "ellipse-curve") { + if (!sat_freeform_curve_name(rec.type)) return m; + m.recognized = true; + SatNurbsCurveCache cache; + if (sat_parse_nurbs_curve_block(rec, cache)) { + m.exact = true; + m.curve = std::move(cache.curve); + } else { + m.approximate = true; + } + return m; + } m.recognized = true; const std::vector nums = sat_numeric_fields(rec, sat_geometry_first_token(rec), 11); @@ -2828,8 +3152,9 @@ public: result_.stats.warnings.push_back( "跳过 " + std::to_string(result_.stats.skipped_nonplanar_surface) + " 个含未支持曲面记录的 SAT 面(" + types + - ");当前精确子集支持 plane/plane-surface 与短名解析面 " - "plane/cylinder/sphere/cone/torus"); + ");当前支持平面/多面体、短名解析面 " + "plane/cylinder/sphere/cone/torus 与内嵌 exactsur nubs/nurbs 网格的自由曲面" + "(控制网格缺失时按边界近似 + degraded)"); } if (!result_.stats.unsupported_curve_types.empty()) { std::string types; @@ -2840,8 +3165,43 @@ public: result_.stats.warnings.push_back( "跳过 " + std::to_string(result_.stats.skipped_curved_edge) + " 个含未支持曲线记录的 SAT 面(" + types + - ");当前精确子集支持直边 straight/straight-curve 与椭圆曲线 " - "ellipse/ellipse-curve"); + ");当前支持直边 straight/straight-curve、椭圆曲线 " + "ellipse/ellipse-curve 与内嵌 nubs/nurbs 网格的自由曲线" + "(控制点缺失时按端点近似 + degraded)"); + } + if (!result_.stats.approximate_surface_types.empty()) { + std::string types; + for (const auto& t : result_.stats.approximate_surface_types) { + if (!types.empty()) types += "/"; + types += t; + } + result_.stats.warnings.push_back( + "近似导入 " + std::to_string(result_.stats.faces_with_approximate_surface) + + " 个含自由曲面记录的 SAT 面(" + types + + "):记录内无 clean-room 可解析的 exactsur nubs/nurbs 控制网格," + "已按面边界拟合平面近似(degraded,非精确 B-Rep)"); + } + if (!result_.stats.approximate_curve_types.empty()) { + std::string types; + for (const auto& t : result_.stats.approximate_curve_types) { + if (!types.empty()) types += "/"; + types += t; + } + result_.stats.warnings.push_back( + "近似导入 " + std::to_string(result_.stats.edges_with_approximate_curve) + + " 条自由曲线(" + types + + "):记录内无可解析 nubs/nurbs 控制点/节点,已按边端点线性近似(degraded)"); + } + if (result_.stats.skipped_closed_freeform_curve > 0) { + std::string types; + for (const auto& t : result_.stats.skipped_closed_curve_types) { + if (!types.empty()) types += "/"; + types += t; + } + result_.stats.warnings.push_back( + "跳过 " + std::to_string(result_.stats.skipped_closed_freeform_curve) + + " 个含闭合/退化自由曲线记录的 SAT 面(" + types + + "):闭合 intcurve 无内嵌 nubs/nurbs 控制点,无法按端点线性近似(degraded)"); } result_.stats.faces_imported = static_cast(result_.model.num_faces()); } @@ -2963,6 +3323,7 @@ private: const int eid = model_.add_edge(v0, v1); edge_cache_[erec] = eid; // Wave5 W30:显式解析曲线(当前仅椭圆)挂到边上;直线沿用既有直边拓扑。 + // Wave6 W35:自由曲线有内嵌 nubs/nurbs 块→精确 NURBS;无块→端点线性近似。 if (curve_rec != static_cast(-1)) { const SatCurveMapping cm = sat_map_curve(recs_[curve_rec]); if (cm.exact && !cm.is_line) { @@ -2970,6 +3331,17 @@ private: ++result_.stats.edges_with_analytic_curve; result_.stats.imported_curve_types.insert(cm.record_type); result_.stats.has_analytic_geometry = true; + } else if (cm.approximate) { + Point3D p0, p1; + NurbsCurve line; + if (sat_vertex_point(recs_[vrec0], recs_, p0) && + sat_vertex_point(recs_[vrec1], recs_, p1) && + sat_approx_linear_curve(p0, p1, line)) { + model_.set_edge_curve(eid, line); + ++result_.stats.edges_with_approximate_curve; + result_.stats.approximate_curve_types.insert(cm.record_type); + result_.stats.has_degraded_geometry = true; + } } } return eid; @@ -2992,13 +3364,26 @@ private: // (plane/cylinder/sphere/cone/torus)映射到 VDE 解析曲面,其余明确跳过。 const bool legacy_plane = (surf_type == "plane-surface"); SatSurfaceMapping smap; + // Wave6 W35:自由曲面(spline-surface/nurbs-surface 等)优先解析记录内嵌的 + // exactsur/nubs/nurbs 控制网格(精确);无网格(rotsur 等构造型)则标记 + // approximate,稍后按面边界拟合平面近似并显式告警(degraded,不伪造精确性)。 + bool approximate_surface = false; if (!legacy_plane) { smap = sat_map_surface(recs_[surfaces.front()]); if (!smap.exact) { - ++result_.stats.faces_skipped; - ++result_.stats.skipped_nonplanar_surface; - result_.stats.unsupported_surface_types.insert(surf_type); - return -1; + SatNurbsSurfaceCache cache; + if (sat_parse_nurbs_surface_block(recs_[surfaces.front()], cache)) { + smap.recognized = true; + smap.exact = true; + smap.surface = std::move(cache.surface); + } else if (sat_ends_with(surf_type, "-surface")) { + approximate_surface = true; + } else { + ++result_.stats.faces_skipped; + ++result_.stats.skipped_nonplanar_surface; + result_.stats.unsupported_surface_types.insert(surf_type); + return -1; + } } } @@ -3012,6 +3397,7 @@ private: }; std::vector pending; bool curved = false; + bool closed_freeform = false; std::string curve_type; for (const size_t lrec : loops) { bool broken_chain = false; @@ -3034,15 +3420,19 @@ private: const auto curves = sat_ptrs_of(recs_[erec], recs_, SatEntClass::Curve, bad_e); add_structural(bad_e); size_t curve_rec = static_cast(-1); + bool curve_approximate = false; if (!curves.empty()) { const SatCurveMapping cm = sat_map_curve(recs_[curves.front()]); - if (!cm.exact) { + if (!cm.exact && !cm.approximate) { curved = true; curve_type = recs_[curves.front()].type; ok = false; break; } - if (!cm.is_line) curve_rec = curves.front(); + if (!cm.is_line) { + curve_rec = curves.front(); + curve_approximate = cm.approximate; + } } int bad_v = 0; const auto verts = sat_ptrs_of(recs_[erec], recs_, SatEntClass::Vertex, bad_v); @@ -3055,6 +3445,14 @@ private: ok = false; break; } + // 闭合/退化自由曲线(两端点重合)无法按端点线性近似,整面诚实跳过。 + if (curve_approximate && (p1 - p0).norm() <= 1e-9) { + curved = true; + closed_freeform = true; + curve_type = recs_[curves.front()].type; + ok = false; + break; + } const bool fwd = sat_coedge_forward(recs_[c]); pl.edge_recs.push_back(erec); pl.vertex_rec0.push_back(verts[0]); @@ -3079,7 +3477,12 @@ private: if (curved) { ++result_.stats.faces_skipped; ++result_.stats.skipped_curved_edge; - result_.stats.unsupported_curve_types.insert(curve_type); + if (closed_freeform) { + ++result_.stats.skipped_closed_freeform_curve; + result_.stats.skipped_closed_curve_types.insert(curve_type); + } else { + result_.stats.unsupported_curve_types.insert(curve_type); + } return -1; } if (pending.empty()) { @@ -3090,6 +3493,17 @@ private: // 多个 loop(含孔)时面积最大者为外环,其余为内环。 std::sort(pending.begin(), pending.end(), [](const PendingLoop& a, const PendingLoop& b) { return a.area > b.area; }); + // 无内嵌控制网格的自由曲面:以最大 loop(外环)边界点拟合平面近似。 + if (approximate_surface) { + if (!sat_approx_plane_surface(pending.front().points, smap.surface)) { + ++result_.stats.faces_skipped; + ++result_.stats.skipped_nonplanar_surface; + result_.stats.unsupported_surface_types.insert(surf_type); + return -1; + } + smap.recognized = true; + smap.exact = true; + } std::vector loop_ids; for (size_t k = 0; k < pending.size(); ++k) { const PendingLoop& pl = pending[k]; @@ -3110,6 +3524,12 @@ private: int sid = -1; if (legacy_plane) { sid = model_.add_surface(make_plane_surface()); + } else if (approximate_surface) { + // degraded:边界平面近似,不计入解析面统计,显式标注近似来源。 + sid = model_.add_surface(smap.surface); + ++result_.stats.faces_with_approximate_surface; + result_.stats.has_degraded_geometry = true; + result_.stats.approximate_surface_types.insert(surf_type); } else { sid = model_.add_surface(smap.surface); ++result_.stats.faces_with_analytic_surface; @@ -3286,23 +3706,27 @@ std::vector format_capability_ex() { {"SAT", "edge", "topology", "acis-sat-text-planar", "supported"}, {"SAT", "vertex", "topology", "acis-sat-text-planar", "supported"}, {"SAT", "point", "topology", "acis-sat-text-planar", "supported"}, - // SAT 曲线记录:直线按既有直边拓扑;椭圆映射为解析曲线;其余明确跳过 + // SAT 曲线记录:直线按既有直边拓扑;椭圆映射为解析曲线; + // Wave6 W35:intcurve/spline/nurbs 等自由曲线记录内嵌 nubs/nurbs 块→精确 + // NURBS 曲线;无块时按端点线性近似并在导入报告标 degraded(不伪造精确性)。 {"SAT", "straight", "curve", "acis-sat-text-planar", "supported"}, {"SAT", "straight-curve","curve", "acis-sat-text-planar", "supported"}, {"SAT", "ellipse", "curve", "acis-sat-text-analytic", "supported"}, {"SAT", "ellipse-curve", "curve", "acis-sat-text-analytic", "supported"}, - {"SAT", "intcurve", "curve", "acis-sat-text-analytic", "partial"}, - {"SAT", "spline", "curve", "acis-sat-text-analytic", "partial"}, - {"SAT", "nurbs", "curve", "acis-sat-text-analytic", "partial"}, - {"SAT", "*-curve", "curve", "acis-sat-text-analytic", "partial"}, - // SAT 曲面记录:plane/plane-surface 精确平面;短名解析面映射 VDE 解析曲面 + {"SAT", "intcurve", "curve", "acis-sat-text-nurbs", "partial"}, + {"SAT", "spline", "curve", "acis-sat-text-nurbs", "partial"}, + {"SAT", "nurbs", "curve", "acis-sat-text-nurbs", "partial"}, + {"SAT", "*-curve", "curve", "acis-sat-text-nurbs", "partial"}, + // SAT 曲面记录:plane/plane-surface 精确平面;短名解析面映射 VDE 解析曲面; + // Wave6 W35:spline-surface/nurbs-surface 内嵌 exactsur nubs/nurbs 网格→精确 + // NURBS 曲面;无网格(rotsur 等构造型)按边界平面近似 + degraded。 {"SAT", "plane", "surface", "acis-sat-text-planar", "supported"}, {"SAT", "plane-surface", "surface", "acis-sat-text-planar", "supported"}, {"SAT", "cylinder", "surface", "acis-sat-text-analytic", "supported"}, {"SAT", "sphere", "surface", "acis-sat-text-analytic", "supported"}, {"SAT", "cone", "surface", "acis-sat-text-analytic", "supported"}, {"SAT", "torus", "surface", "acis-sat-text-analytic", "supported"}, - {"SAT", "*-surface", "surface", "acis-sat-text-analytic", "partial"}, + {"SAT", "*-surface", "surface", "acis-sat-text-nurbs", "partial"}, // SAT 二进制:第三方 SAB 明确拒绝(不静默空模型) {"SAT", "SAB ", "binary", "acis-sab-third-party-unsupported", "unsupported"}, {"SAT", "ACIS BinaryFile","binary", "acis-sab-third-party-unsupported", "unsupported"}, @@ -3420,10 +3844,16 @@ BrepModel import_acis_sat_ex(const std::string& path, NativeImportReport* report report->imported_entity_types.push_back(t); for (const auto& t : tp.stats.imported_curve_types) report->imported_entity_types.push_back(t); + for (const auto& t : tp.stats.approximate_surface_types) + report->imported_entity_types.push_back(t); + for (const auto& t : tp.stats.approximate_curve_types) + report->imported_entity_types.push_back(t); for (const auto& t : tp.stats.unsupported_surface_types) report->skipped_entity_types.push_back(t); for (const auto& t : tp.stats.unsupported_curve_types) report->skipped_entity_types.push_back(t); + for (const auto& t : tp.stats.skipped_closed_curve_types) + report->skipped_entity_types.push_back(t); }; if (report) { report->faces_imported = tp.stats.faces_imported; @@ -3432,18 +3862,27 @@ BrepModel import_acis_sat_ex(const std::string& path, NativeImportReport* report } if (!tp.model.all_bodies().empty()) { fill_entity_types(); - const bool partial = tp.stats.faces_skipped > 0 || !tp.stats.warnings.empty(); + const bool degraded = tp.stats.has_degraded_geometry; const bool analytic = tp.stats.has_analytic_geometry; - const char* capability = - analytic ? "acis-sat-text-analytic" : "acis-sat-text-planar"; + const bool partial = + degraded || tp.stats.faces_skipped > 0 || !tp.stats.warnings.empty(); + const char* capability = degraded ? "acis-sat-text-degraded" + : analytic ? "acis-sat-text-analytic" + : "acis-sat-text-planar"; std::string msg = - analytic ? "第三方 ACIS SAT 解析面/曲线子集导入:faces=" - : "第三方 ACIS SAT 平面/多面体子集导入:faces="; + degraded ? "第三方 ACIS SAT 自由曲面/曲线近似导入(含 degraded 近似):faces=" + : (analytic ? "第三方 ACIS SAT 解析面/曲线子集导入:faces=" + : "第三方 ACIS SAT 平面/多面体子集导入:faces="); msg += std::to_string(tp.stats.faces_imported) + ",bodies=" + std::to_string(tp.stats.bodies_imported); if (tp.stats.faces_skipped > 0) { msg += ",明确跳过 " + std::to_string(tp.stats.faces_skipped) + " 面(超出精确子集)"; } + if (degraded) { + msg += ",近似面 " + std::to_string(tp.stats.faces_with_approximate_surface) + + ",近似曲线 " + std::to_string(tp.stats.edges_with_approximate_curve) + + "(无内嵌 NURBS 控制网格,按边界/端点近似)"; + } if (!tp.stats.imported_surface_types.empty()) msg += ",曲面记录:" + join_set(tp.stats.imported_surface_types); if (!tp.stats.imported_curve_types.empty()) @@ -3482,9 +3921,13 @@ BrepModel import_acis_sat_ex(const std::string& path, NativeImportReport* report msg += ";跳过曲面记录:" + join_set(tp.stats.unsupported_surface_types); if (!tp.stats.unsupported_curve_types.empty()) msg += ";跳过曲线记录:" + join_set(tp.stats.unsupported_curve_types) + - "(spline/nurbs/intcurve 未解析)"; - msg += ";当前精确子集支持平面/多面体(直边多边形)与短名解析面/曲线" - "(plane/cylinder/sphere/cone/torus、straight/ellipse)"; + "(无内嵌 nubs/nurbs 块且无法按端点近似)"; + if (!tp.stats.skipped_closed_curve_types.empty()) + msg += ";跳过闭合自由曲线记录:" + join_set(tp.stats.skipped_closed_curve_types) + + "(闭合/退化边界无法按端点近似)"; + msg += ";当前支持平面/多面体(直边多边形)、短名解析面/曲线" + "(plane/cylinder/sphere/cone/torus、straight/ellipse)以及内嵌 nubs/nurbs 网格的" + "自由曲面/曲线(网格缺失时按边界/端点近似 + degraded,不伪造精确性)"; set_report(NativeImportStatus::Unsupported, "acis-sat-text-planar", std::move(msg), "import.unsupported.third_party_sat"); } diff --git a/tests/foundation/test_industrial_formats.cpp b/tests/foundation/test_industrial_formats.cpp index 511c9e8f4..5ccc49b14 100644 --- a/tests/foundation/test_industrial_formats.cpp +++ b/tests/foundation/test_industrial_formats.cpp @@ -2648,7 +2648,8 @@ std::string wave4_write_file(const char* name, const std::string& content) { // 记录索引(0 基):0 body / 1 lump / 2 shell / 3 plane-surface / 4..7 face / // 8..11 loop / 12..23 coedge / 24..29 edge / 30..33 vertex / 34..37 point / // 38 straight-curve / 39 sphere-surface(仅 sphere_faces>0 时写出)。 -// sphere_faces: 0=全平面(精确子集内);1=1 个面为非平面(Partial);4=全部非平面(Unsupported)。 +// sphere_faces: 0=全平面(精确子集内);1=1 个面为自由曲面(degraded 边界近似→Partial); +// 4=全部自由曲面(degraded 边界近似→Partial)。 // broken_body: body 的 lump 指针越界(结构损坏 → Malformed)。 std::string sat_tetra_text(int sphere_faces, bool broken_body) { std::ostringstream s; @@ -2768,19 +2769,21 @@ TEST(Wave4Interop, SatEmbeddedStringContractStaysVdeOnly) { EXPECT_EQ(from_string.num_faces(), 0u); } -// 3) 混合曲面:可精确导入的面保留,超子集面明确跳过并降级为 Partial。 -TEST(Wave4Interop, SatPartialWithUnsupportedSurface) { +// 3) 混合曲面(W35 起):可精确导入的平面面保留,自由曲面(*-surface)面按边界 +// 平面近似导入并显式标 degraded → Partial,不再整面跳过(不伪造精确性)。 +TEST(Wave4Interop, SatPartialWithDegradedSurface) { const std::string path = wave4_write_file("w4_tetra_partial.sat", sat_tetra_text(1, false)); NativeImportReport report; const BrepModel model = import_acis_sat_ex(path, &report); std::remove(path.c_str()); - EXPECT_EQ(model.num_faces(), 3u); + EXPECT_EQ(model.num_faces(), 4u); EXPECT_EQ(report.status, NativeImportStatus::Partial); - EXPECT_EQ(report.capability, "acis-sat-text-planar"); - EXPECT_EQ(report.faces_imported, 3); - EXPECT_EQ(report.faces_skipped_unsupported, 1); + EXPECT_EQ(report.capability, "acis-sat-text-degraded"); + EXPECT_EQ(report.faces_imported, 4); + EXPECT_EQ(report.faces_skipped_unsupported, 0); EXPECT_EQ(report.error_code, "import.partial.third_party_sat"); EXPECT_FALSE(report.warnings.empty()); + EXPECT_NE(report.message.find("近似"), std::string::npos) << report.message; } // 4) 结构损坏(拓扑指针越界):显式 Malformed,不再静默空模型。 @@ -2796,17 +2799,21 @@ TEST(Wave4Interop, SatMalformedPointerDiagnosed) { EXPECT_FALSE(report.message.empty()); } -// 5) 全部非平面:明确 Unsupported(原因含"平面/多面体子集"),空模型但绝不静默。 -TEST(Wave4Interop, SatCurvedOnlyExplicitUnsupported) { +// 5) 全部自由曲面(W35 起):按面边界平面近似导入并标 degraded,绝不静默/伪造精确。 +TEST(Wave4Interop, SatCurvedOnlyDegradedApproximation) { const std::string path = wave4_write_file("w4_tetra_curved.sat", sat_tetra_text(4, false)); NativeImportReport report; const BrepModel model = import_acis_sat_ex(path, &report); std::remove(path.c_str()); - EXPECT_TRUE(model.all_bodies().empty()); - EXPECT_EQ(report.status, NativeImportStatus::Unsupported); - EXPECT_EQ(report.error_code, "import.unsupported.third_party_sat"); - EXPECT_NE(report.message.find("平面/多面体"), std::string::npos) << report.message; - EXPECT_EQ(report.faces_skipped_unsupported, 4); + EXPECT_FALSE(model.all_bodies().empty()); + EXPECT_EQ(model.num_faces(), 4u); + EXPECT_EQ(report.status, NativeImportStatus::Partial); + EXPECT_EQ(report.error_code, "import.partial.third_party_sat"); + EXPECT_EQ(report.capability, "acis-sat-text-degraded"); + EXPECT_EQ(report.faces_imported, 4); + EXPECT_EQ(report.faces_skipped_unsupported, 0); + EXPECT_NE(report.message.find("近似"), std::string::npos) << report.message; + EXPECT_FALSE(report.warnings.empty()); } // 6) 缺失文件:EmptyInput + 稳定错误码(旧 API 仍返回空模型不抛异常)。 @@ -2933,16 +2940,23 @@ TEST(Wave4Interop, ImportCadThirdPartySatSucceeds) { EXPECT_FALSE(result.diagnostic.parsed == false); } -// 14) 统一入口:曲面只含 SAT 明确失败(ok=false),原因/稳定码进诊断 JSON。 -TEST(Wave4Interop, ImportCadCurvedOnlySatFailsExplicitly) { +// 14) 统一入口(W35 起):曲面只含 SAT 不再整体失败;自由曲面按近似导入并在诊断 +// JSON 中给 Warning issue(degraded 语义显式,不冒充精确 B-Rep)。 +TEST(Wave4Interop, ImportCadCurvedOnlySatDegradedWarning) { const std::string path = wave4_write_file("w4_cad_curved.sat", sat_tetra_text(4, false)); const CadImportResult result = import_cad(path); std::remove(path.c_str()); - EXPECT_FALSE(result.ok); - EXPECT_TRUE(result.diagnostic.has_errors()); - EXPECT_FALSE(result.diagnostic.parsed); - EXPECT_TRUE(has_issue_code(result.diagnostic, "import.unsupported.third_party_sat")); - EXPECT_NE(result.diagnostic.to_json().find("import.unsupported.third_party_sat"), + EXPECT_TRUE(result.ok); + ASSERT_EQ(result.bodies.size(), 1u); + EXPECT_EQ(result.bodies[0].num_faces(), 4u); + EXPECT_FALSE(result.diagnostic.has_errors()); + EXPECT_TRUE(result.diagnostic.has_warnings()); + EXPECT_TRUE(result.diagnostic.parsed); + EXPECT_TRUE(has_issue_code(result.diagnostic, "import.partial.third_party_sat")); + EXPECT_TRUE(has_issue_with_severity(result.diagnostic, ImportIssueSeverity::Warning)); + EXPECT_NE(result.diagnostic.to_json().find("import.partial.third_party_sat"), + std::string::npos); + EXPECT_NE(result.diagnostic.to_json().find("acis-sat-text-degraded"), std::string::npos); } @@ -3314,50 +3328,8 @@ TEST(Wave5SatSurface, PlanePlusSphereCombo) { EXPECT_EQ(planar_faces, 1); } -// 25) spline-surface 记录:明确跳过并给 Partial 诊断(实体名/记录名可见)。 -TEST(Wave5SatSurface, SplineSurfacePartialDiagnostic) { - W5FaceSpec plane; - plane.points = w5_quad(0.0); - plane.surface_record = "plane-surface $-1 0 0 0 1 0 0 0 1 forward_v I I I I"; - W5FaceSpec spline; - spline.points = w5_quad(0.0); - spline.surface_record = "spline-surface $-1 0 0 0 1 0 0 0 1 forward_v I I I I"; - const std::string path = w5_write_file("w5_spline.sat", w5_sat_text({plane, spline})); - NativeImportReport report; - const BrepModel model = import_acis_sat_ex(path, &report); - std::remove(path.c_str()); - EXPECT_EQ(model.num_faces(), 1u); - EXPECT_EQ(report.status, NativeImportStatus::Partial); - EXPECT_EQ(report.capability, "acis-sat-text-planar"); - EXPECT_EQ(report.error_code, "import.partial.third_party_sat"); - EXPECT_EQ(report.faces_skipped_unsupported, 1); - EXPECT_TRUE(w5_has(report.imported_entity_types, "plane-surface")); - EXPECT_TRUE(w5_has(report.skipped_entity_types, "spline-surface")) - << "skipped entity 诊断必须含记录名"; - // 诊断文本必须点名记录类型 - std::string all; - for (const auto& w : report.warnings) all += w + "\n"; - all += report.message; - EXPECT_NE(all.find("spline-surface"), std::string::npos) << all; -} - -// 26) nurbs 曲线记录:明确 Unsupported(含实体/记录名),不静默空模型。 -TEST(Wave5SatSurface, NurbsCurveExplicitUnsupported) { - W5FaceSpec f; - f.points = w5_quad(0.0); - f.surface_record = "plane-surface $-1 0 0 0 1 0 0 0 1 forward_v I I I I"; - f.curve_records = {"nurbs $-1 0 0 0 1 0 0 1 1"}; - const std::string path = w5_write_file("w5_nurbs.sat", w5_sat_text({f})); - NativeImportReport report; - const BrepModel model = import_acis_sat_ex(path, &report); - std::remove(path.c_str()); - EXPECT_TRUE(model.all_bodies().empty()); - EXPECT_EQ(report.status, NativeImportStatus::Unsupported); - EXPECT_EQ(report.error_code, "import.unsupported.third_party_sat"); - EXPECT_NE(report.message.find("平面/多面体"), std::string::npos) << report.message; - EXPECT_NE(report.message.find("nurbs"), std::string::npos) << report.message; - EXPECT_TRUE(w5_has(report.skipped_entity_types, "nurbs")); -} +// 25/26) 原 Wave5 的「spline-surface/nurbs 明确跳过」用例已随 W35 自由曲面/曲线 +// 近似导入能力升级迁移至 Wave6SatNurbs.*(见本文件末尾 Wave6 用例)。 // 27) SAB 二进制("SAB " 头,无 VDE 载荷):明确 Unsupported,绝不静默空模型。 TEST(Wave5SatSurface, SabBinaryMagicRejected) { @@ -3413,9 +3385,11 @@ TEST(Wave5SatSurface, FormatCapabilityExConsistency) { check("SAT", "torus", "supported", "acis-sat-text-analytic"); check("SAT", "ellipse", "supported", "acis-sat-text-analytic"); check("SAT", "straight", "supported", "acis-sat-text-planar"); - check("SAT", "spline", "partial", "acis-sat-text-analytic"); - check("SAT", "nurbs", "partial", "acis-sat-text-analytic"); - check("SAT", "*-surface", "partial", "acis-sat-text-analytic"); + check("SAT", "spline", "partial", "acis-sat-text-nurbs"); + check("SAT", "nurbs", "partial", "acis-sat-text-nurbs"); + check("SAT", "intcurve", "partial", "acis-sat-text-nurbs"); + check("SAT", "*-curve", "partial", "acis-sat-text-nurbs"); + check("SAT", "*-surface", "partial", "acis-sat-text-nurbs"); check("SAT", "ACIS BinaryFile", "unsupported", "acis-sab-third-party-unsupported"); check("XT", "brep", "unsupported", "third-party-xt-unsupported"); check("JT", "brep", "supported", "jt-brep-payload"); @@ -3499,3 +3473,334 @@ TEST(Wave5SatSurface, ImportCadSabFailsExplicitly) { std::string::npos); } +// ═══════════════════════════════════════════════════════════════ +// Wave6 W35:SAT 自由曲面/自由曲线近似 NURBS 导入 +// - spline-surface/nurbs-surface 内嵌 exactsur nubs/nurbs 网格 → 精确 NURBS 曲面 +// - intcurve/spline/nurbs 曲线内嵌 nubs/nurbs 块 → 精确 NURBS 曲线 +// - 控制网格/控制点缺失(rotsur 等构造型、{ ref N } 子类型引用)→ degraded 近似 +// 平面/线性曲线 + 显式 warning + 导入报告 capability=acis-sat-text-degraded +// - 闭合/退化自由曲线无法按端点近似时诚实跳过(不伪造支持) +// ═══════════════════════════════════════════════════════════════ +namespace { + +// 合成 spline-surface 记录:内嵌 exactsur + nubs 网格(控制网格 2×2,双线性)。 +// keyword="nubs" 时无权重;keyword="nurbs" 时每极点后带齐次权重。 +std::string w6_surface_grid_record(bool rational) { + std::string r = "spline-surface $-1 forward { exactsur "; + r += rational ? "nurbs " : "nubs "; + r += "1 1 open open none none 2 2 0 1 1 1 0 1 1 1 "; + if (!rational) { + r += "0 0 0 0 4 0 4 0 0 4 4 0 "; + } else { + // (x y z w):四角权重 1 / 0.5 / 2 / 1 + r += "0 0 0 1 0 4 0 0.5 4 0 0 2 4 4 0 1 "; + } + r += "0 0 0 0 0 0 0 F 0 F 1 F 0 F 2 } I I I I"; + return r; +} + +// 合成 spline-surface 记录:构造型(rotsur + 内嵌 intcurve),无 2D 控制网格。 +std::string w6_surface_constructed_record() { + return "spline-surface $-1 -1 -1 forward { rotsur intcurve forward { surfintcur full " + "nubs 3 open 3 0 3 1 3 2 2 0 0 0 1 2 0 2 2 0 } nullbs I I 0 0 0 } I I I I"; +} + +// 合成 intcurve-curve 记录:内嵌 exactcur + nubs 块(三次 Bezier,4 极点)。 +std::string w6_intcurve_exact_record() { + return "intcurve-curve $-1 -1 $-1 forward { exactcur nubs 3 open 2 0 3 1 3 " + "0 0 0 1 2 0 2 2 0 3 0 0 0 } I I"; +} + +// 合成 intcurve-curve 记录:仅 subtype 引用(无内嵌控制点)→ approximated。 +std::string w6_intcurve_ref_record() { + return "intcurve-curve $-1 -1 $-1 forward { ref 1 } I I"; +} + +// 有限/有界断言:曲面任意采样点坐标有限且落在 ±1e3 内(防爆体积/NaN)。 +void w6_expect_surface_bounded(const NurbsSurface& s) { + for (int i = 0; i <= 4; ++i) { + for (int j = 0; j <= 4; ++j) { + const Point3D p = s.evaluate(i / 4.0, j / 4.0); + EXPECT_TRUE(std::isfinite(p.x()) && std::isfinite(p.y()) && std::isfinite(p.z())); + EXPECT_LE(std::abs(p.x()), 1e3); + EXPECT_LE(std::abs(p.y()), 1e3); + EXPECT_LE(std::abs(p.z()), 1e3); + } + } +} + +std::string w6_join_warnings(const NativeImportReport& report) { + std::string all; + for (const auto& w : report.warnings) all += w + "\n"; + all += report.message; + return all; +} + +} // namespace + +// W35-01) spline-surface 内嵌 exactsur+nubs 网格 → 精确双线性 NURBS 曲面。 +TEST(Wave6SatNurbs, SplineSurfaceExactNurbsGrid) { + W5FaceSpec f; + f.points = w5_quad(0.0); + f.surface_record = w6_surface_grid_record(false); + const std::string path = w5_write_file("w6_surf_grid.sat", w5_sat_text({f})); + NativeImportReport report; + const BrepModel model = import_acis_sat_ex(path, &report); + std::remove(path.c_str()); + ASSERT_EQ(model.num_faces(), 1u); + EXPECT_EQ(report.status, NativeImportStatus::Ok); + EXPECT_EQ(report.capability, "acis-sat-text-analytic"); + EXPECT_EQ(report.faces_skipped_unsupported, 0); + EXPECT_TRUE(w5_has(report.imported_entity_types, "spline-surface")) + << w6_join_warnings(report); + const NurbsSurface& s = model.face_surface(0); + EXPECT_EQ(s.degree_u(), 1); + EXPECT_EQ(s.degree_v(), 1); + const auto ncp = s.num_control_points(); + EXPECT_EQ(ncp[0], 2); + EXPECT_EQ(ncp[1], 2); + // 双线性插值:四角精确命中控制点;缺权重时权重均匀为 1。 + EXPECT_NEAR((s.evaluate(0.0, 0.0) - Point3D(0, 0, 0)).norm(), 0.0, 1e-12); + EXPECT_NEAR((s.evaluate(0.0, 1.0) - Point3D(0, 4, 0)).norm(), 0.0, 1e-12); + EXPECT_NEAR((s.evaluate(1.0, 0.0) - Point3D(4, 0, 0)).norm(), 0.0, 1e-12); + EXPECT_NEAR((s.evaluate(1.0, 1.0) - Point3D(4, 4, 0)).norm(), 0.0, 1e-12); + for (const auto& row : s.weights()) + for (const double w : row) EXPECT_EQ(w, 1.0); + w6_expect_surface_bounded(s); +} + +// W35-02) nurbs 关键字(有理)网格:齐次权重保留,面精确导入。 +TEST(Wave6SatNurbs, NurbsSurfaceRationalWeights) { + W5FaceSpec f; + f.points = w5_quad(0.0); + f.surface_record = w6_surface_grid_record(true); + const std::string path = w5_write_file("w6_surf_rational.sat", w5_sat_text({f})); + NativeImportReport report; + const BrepModel model = import_acis_sat_ex(path, &report); + std::remove(path.c_str()); + ASSERT_EQ(model.num_faces(), 1u); + EXPECT_EQ(report.status, NativeImportStatus::Ok); + EXPECT_EQ(report.capability, "acis-sat-text-analytic"); + const NurbsSurface& s = model.face_surface(0); + const auto weights = s.weights(); + ASSERT_EQ(weights.size(), 2u); + ASSERT_EQ(weights[0].size(), 2u); + EXPECT_DOUBLE_EQ(weights[0][0], 1.0); + EXPECT_DOUBLE_EQ(weights[0][1], 0.5); + EXPECT_DOUBLE_EQ(weights[1][0], 2.0); + EXPECT_DOUBLE_EQ(weights[1][1], 1.0); + // 有理端点仍精确落在首末控制点。 + EXPECT_NEAR((s.evaluate(0.0, 0.0) - Point3D(0, 0, 0)).norm(), 0.0, 1e-12); + EXPECT_NEAR((s.evaluate(1.0, 1.0) - Point3D(4, 4, 0)).norm(), 0.0, 1e-12); + w6_expect_surface_bounded(s); +} + +// W35-03) 缺权重(nubs)→ 均匀权重 1(不伪造非均匀有理权)。 +TEST(Wave6SatNurbs, NurbsSurfaceMissingWeightsUniform) { + W5FaceSpec f; + f.points = w5_quad(0.0); + f.surface_record = w6_surface_grid_record(false); + const std::string path = w5_write_file("w6_surf_noweights.sat", w5_sat_text({f})); + NativeImportReport report; + const BrepModel model = import_acis_sat_ex(path, &report); + std::remove(path.c_str()); + ASSERT_EQ(model.num_faces(), 1u); + ASSERT_EQ(report.status, NativeImportStatus::Ok); + const NurbsSurface& s = model.face_surface(0); + const auto weights = s.weights(); + ASSERT_EQ(weights.size(), 2u); + for (const auto& row : weights) + for (const double w : row) EXPECT_EQ(w, 1.0); +} + +// W35-04) 构造型 spline-surface(rotsur,无 2D 控制网格)→ 边界平面近似 + degraded。 +TEST(Wave6SatNurbs, SplineSurfaceConstructedFallback) { + W5FaceSpec f; + f.points = w5_quad(0.0); + f.surface_record = w6_surface_constructed_record(); + const std::string path = w5_write_file("w6_surf_rotsur.sat", w5_sat_text({f})); + NativeImportReport report; + const BrepModel model = import_acis_sat_ex(path, &report); + std::remove(path.c_str()); + ASSERT_EQ(model.num_faces(), 1u); + EXPECT_EQ(report.status, NativeImportStatus::Partial); + EXPECT_EQ(report.capability, "acis-sat-text-degraded"); + EXPECT_EQ(report.error_code, "import.partial.third_party_sat"); + EXPECT_TRUE(w5_has(report.imported_entity_types, "spline-surface")); + EXPECT_TRUE(report.skipped_entity_types.empty()); + const std::string all = w6_join_warnings(report); + EXPECT_NE(all.find("近似"), std::string::npos) << all; + EXPECT_NE(all.find("spline-surface"), std::string::npos) << all; + EXPECT_NE(all.find("degraded"), std::string::npos) << all; + w6_expect_surface_bounded(model.face_surface(0)); +} + +// W35-05) intcurve-curve 内嵌 exactcur+nubs 块 → 精确三次 NURBS 边曲线。 +TEST(Wave6SatNurbs, IntcurveNurbsCurveExact) { + W5FaceSpec f; + f.points = w5_quad(0.0); + f.surface_record = "plane-surface $-1 0 0 0 1 0 0 0 1 forward_v I I I I"; + for (int i = 0; i < 4; ++i) f.curve_records.push_back(w6_intcurve_exact_record()); + const std::string path = w5_write_file("w6_intcurve_exact.sat", w5_sat_text({f})); + NativeImportReport report; + const BrepModel model = import_acis_sat_ex(path, &report); + std::remove(path.c_str()); + ASSERT_EQ(model.num_faces(), 1u); + EXPECT_EQ(report.status, NativeImportStatus::Ok); + EXPECT_EQ(report.capability, "acis-sat-text-analytic"); + EXPECT_TRUE(w5_has(report.imported_entity_types, "intcurve-curve")); + ASSERT_EQ(model.num_edges(), 4u); + for (size_t e = 0; e < model.num_edges(); ++e) { + const auto ec = model.edge_curve(static_cast(e)); + ASSERT_TRUE(ec != nullptr) << "edge " << e; + EXPECT_EQ(ec->degree(), 3); + EXPECT_NEAR((ec->evaluate(0.0) - Point3D(0, 0, 0)).norm(), 0.0, 1e-12); + EXPECT_NEAR((ec->evaluate(1.0) - Point3D(3, 0, 0)).norm(), 0.0, 1e-12); + } +} + +// W35-06) intcurve-curve 仅 { ref N } 子类型引用(无控制点)→ 端点线性近似 + degraded。 +TEST(Wave6SatNurbs, IntcurveRefApproxFallback) { + W5FaceSpec f; + f.points = w5_quad(0.0); + f.surface_record = "plane-surface $-1 0 0 0 1 0 0 0 1 forward_v I I I I"; + f.curve_records = {w6_intcurve_ref_record()}; + const std::string path = w5_write_file("w6_intcurve_ref.sat", w5_sat_text({f})); + NativeImportReport report; + const BrepModel model = import_acis_sat_ex(path, &report); + std::remove(path.c_str()); + ASSERT_EQ(model.num_faces(), 1u); + EXPECT_EQ(report.status, NativeImportStatus::Partial); + EXPECT_EQ(report.capability, "acis-sat-text-degraded"); + EXPECT_TRUE(w5_has(report.imported_entity_types, "intcurve-curve")); + const std::string all = w6_join_warnings(report); + EXPECT_NE(all.find("近似曲线 1"), std::string::npos) << all; + EXPECT_NE(all.find("intcurve-curve"), std::string::npos) << all; + ASSERT_GE(model.num_edges(), 4u); + const auto ec = model.edge_curve(0); + ASSERT_TRUE(ec != nullptr); + EXPECT_EQ(ec->degree(), 1); // 线性近似 +} + +// W35-07) 闭合 intcurve(边两端点重合、无内嵌控制点)→ 无法线性近似,诚实跳过面。 +TEST(Wave6SatNurbs, ClosedIntcurveSkippedHonestly) { + W5FaceSpec f; + f.points = {{0, 0, 0}, {0, 0, 0}, {4, 0, 0}, {0, 3, 0}}; // 边 0 两端点重合 + f.surface_record = "plane-surface $-1 0 0 0 1 0 0 0 1 forward_v I I I I"; + f.curve_records = {w6_intcurve_ref_record()}; + const std::string path = w5_write_file("w6_closed_intcurve.sat", w5_sat_text({f})); + NativeImportReport report; + const BrepModel model = import_acis_sat_ex(path, &report); + std::remove(path.c_str()); + EXPECT_TRUE(model.all_bodies().empty()); + EXPECT_EQ(report.status, NativeImportStatus::Unsupported); + EXPECT_EQ(report.error_code, "import.unsupported.third_party_sat"); + EXPECT_TRUE(w5_has(report.skipped_entity_types, "intcurve-curve")); + const std::string all = w6_join_warnings(report); + EXPECT_NE(all.find("闭合"), std::string::npos) << all; + EXPECT_NE(all.find("intcurve-curve"), std::string::npos) << all; +} + +// W35-08) exactsur 网格截断(节点齐全但控制网格缺失)→ 解析失败回落近似,不崩溃。 +TEST(Wave6SatNurbs, MalformedNurbsBlockFallsBack) { + W5FaceSpec f; + f.points = w5_quad(0.0); + f.surface_record = + "spline-surface $-1 forward { exactsur nubs 1 1 open open none none 2 2 0 1 1 1 } " + "I I I I"; + const std::string path = w5_write_file("w6_surf_truncated.sat", w5_sat_text({f})); + NativeImportReport report; + const BrepModel model = import_acis_sat_ex(path, &report); + std::remove(path.c_str()); + ASSERT_EQ(model.num_faces(), 1u); + EXPECT_EQ(report.status, NativeImportStatus::Partial); + EXPECT_EQ(report.capability, "acis-sat-text-degraded"); + const std::string all = w6_join_warnings(report); + EXPECT_NE(all.find("近似"), std::string::npos) << all; + w6_expect_surface_bounded(model.face_surface(0)); +} + +// W35-09) 非法 nubs 计数字段(entry=0)→ 拒绝网格解析、回落近似;体积有界。 +TEST(Wave6SatNurbs, DegenerateNurbsCountsRejected) { + W5FaceSpec f; + f.points = w5_quad(0.0); + f.surface_record = + "spline-surface $-1 forward { exactsur nubs 3 3 open open none none 0 0 } I I I I"; + const std::string path = w5_write_file("w6_surf_badcount.sat", w5_sat_text({f})); + NativeImportReport report; + const BrepModel model = import_acis_sat_ex(path, &report); + std::remove(path.c_str()); + ASSERT_EQ(model.num_faces(), 1u); + EXPECT_EQ(report.status, NativeImportStatus::Partial); + EXPECT_EQ(report.capability, "acis-sat-text-degraded"); + const Point3D p = model.face_surface(0).evaluate(0.5, 0.5); + EXPECT_TRUE(std::isfinite(p.x()) && std::isfinite(p.y()) && std::isfinite(p.z())); +} + +// W35-10) 多面自由曲面近似导入:体积有限(不爆、不 NaN),面数受控。 +TEST(Wave6SatNurbs, ApproxGeometryVolumeBounded) { + std::vector faces; + for (int i = 0; i < 3; ++i) { + W5FaceSpec f; + f.points = w5_quad(static_cast(i)); + f.surface_record = w6_surface_constructed_record(); + faces.push_back(f); + } + const std::string path = w5_write_file("w6_surf_multi.sat", w5_sat_text(faces)); + NativeImportReport report; + const BrepModel model = import_acis_sat_ex(path, &report); + std::remove(path.c_str()); + EXPECT_EQ(model.num_faces(), 3u); + EXPECT_EQ(report.status, NativeImportStatus::Partial); + EXPECT_EQ(report.capability, "acis-sat-text-degraded"); + for (size_t fi = 0; fi < model.num_faces(); ++fi) + w6_expect_surface_bounded(model.face_surface(static_cast(fi))); + EXPECT_LE(report.faces_imported, 3); +} + +// W35-11) 平面 + 构造型 spline-surface 混合:平面路径保持精确,自由曲面降级近似。 +TEST(Wave6SatNurbs, SplineSurfaceApproxFallback) { + W5FaceSpec plane; + plane.points = w5_quad(0.0); + plane.surface_record = "plane-surface $-1 0 0 0 1 0 0 0 1 forward_v I I I I"; + W5FaceSpec spline; + spline.points = w5_quad(0.0); + spline.surface_record = w6_surface_constructed_record(); + const std::string path = w5_write_file("w6_surf_mixed.sat", w5_sat_text({plane, spline})); + NativeImportReport report; + const BrepModel model = import_acis_sat_ex(path, &report); + std::remove(path.c_str()); + ASSERT_EQ(model.num_faces(), 2u); + EXPECT_EQ(report.status, NativeImportStatus::Partial); + EXPECT_EQ(report.capability, "acis-sat-text-degraded"); + EXPECT_EQ(report.faces_skipped_unsupported, 0); + EXPECT_TRUE(w5_has(report.imported_entity_types, "plane-surface")); + EXPECT_TRUE(w5_has(report.imported_entity_types, "spline-surface")); + const std::string all = w6_join_warnings(report); + EXPECT_NE(all.find("近似"), std::string::npos) << all; + EXPECT_NE(all.find("spline-surface"), std::string::npos) << all; + w6_expect_surface_bounded(model.face_surface(1)); +} + +// W35-12) nurbs 曲线记录无内嵌块 → 端点线性近似 + degraded(不再整面 Unsupported)。 +TEST(Wave6SatNurbs, NurbsCurveApproxFallback) { + W5FaceSpec f; + f.points = w5_quad(0.0); + f.surface_record = "plane-surface $-1 0 0 0 1 0 0 0 1 forward_v I I I I"; + f.curve_records = {"nurbs $-1 0 0 0 1 0 0 1 1"}; + const std::string path = w5_write_file("w6_nurbs_curve.sat", w5_sat_text({f})); + NativeImportReport report; + const BrepModel model = import_acis_sat_ex(path, &report); + std::remove(path.c_str()); + ASSERT_EQ(model.num_faces(), 1u); + EXPECT_EQ(report.status, NativeImportStatus::Partial); + EXPECT_EQ(report.capability, "acis-sat-text-degraded"); + EXPECT_TRUE(w5_has(report.imported_entity_types, "nurbs")); + const std::string all = w6_join_warnings(report); + EXPECT_NE(all.find("近似"), std::string::npos) << all; + EXPECT_NE(all.find("nurbs"), std::string::npos) << all; + const auto ec = model.edge_curve(0); + ASSERT_TRUE(ec != nullptr); + EXPECT_EQ(ec->degree(), 1); +} +