A52 (IGES face orientation closure, importer/exporter symmetric): - importer: apply_shell_orientation derives face.reversed = (514 ORIENTATION==0) XOR (186 SHELLFLAG==0); token_is_pure_int guards legacy "0HNAME"; convert_face reads 510 OUTERLOOPFLAG, convert_loop reads 508 ORIENTATION (diagnostics only); empty/void shells use their own SHELLFLAG - exporter: 514 writes per-face ORIENTATION (0 when reversed), 510 OUTERLOOPFLAG=1, 508 ORIENTATION from edge.reversed; 144 counts reversed trimmed faces only (no orientation field); 186 keeps "1,0" - test_iges_export 34 -> 43 tests (T1-T8, real corpus round-trips): occ__bug25415 vol_rel 0.9697 -> 8.30e-12, occ__bug22821_test 2.0 -> 0, PWB/31000/28366 stay ~0 A53 (IGES import zero-copy caches): - curve_cache_/surface_cache_ become unordered_map<int, shared_ptr<const NurbsCurve/NurbsSurface>>; hits share pointers, misses make_shared<const T>(std::move(...)); composite curves return pointers - split_params/params_of return std::string_view (zero-copy token slicing; tokens are substrings) - import_iges reads the file in one sized binary read (chunked fallback for >16GB or tellg failure) - V8 Motor_1.igs 3.40 -> 1.346 s, moteur_v8_asm.igs 9.27 -> 3.284 s; topology/model hashes unchanged A54/A55 (UTF-8 path leftovers): - A54: 13 foundation files, 17 open sites -> open_ifstream_utf8/open_ofstream_utf8; 9 UTF-8 cases - A55: 13 infra/plugin/capi/core files, 24+ sites (11 user-path sites in plugin_manager); 12 UTF-8 cases - Linux-only fixed paths (/sys,/proc,/etc/machine-id) and platform.cpp fopen wrapper intentionally kept Verification: 23 suites 918 passed / 0 failed; PR gate 1067/1067 (81.44 s); four KPI windows bit-identical (fixed 196/36, auto 196/36, band 8/0 and 8/0); 35 extra suites green; redline identical.
284 lines
10 KiB
C++
284 lines
10 KiB
C++
#include "vde/foundation/io_vda.h"
|
||
#include "vde/foundation/utf8_path.h"
|
||
#include "vde/foundation/format_detect.h"
|
||
#include "vde/brep/format_io.h"
|
||
|
||
#include <gtest/gtest.h>
|
||
#include <cstdio>
|
||
#include <filesystem>
|
||
#include <fstream>
|
||
#include <string>
|
||
#include <vector>
|
||
|
||
using namespace vde::foundation;
|
||
using namespace vde::brep;
|
||
|
||
namespace {
|
||
|
||
/// 合成 VDA-FS 文本写盘(不依赖真实语料;WP-108-05 减少 provided-skip)。
|
||
std::string write_vda_fixture(const char* name, const std::string& text) {
|
||
const std::string path = std::string(VDE_TEST_TEMP_DIR) + name;
|
||
std::ofstream out(path, std::ios::binary | std::ios::trunc);
|
||
out << text;
|
||
out.close();
|
||
return path;
|
||
}
|
||
|
||
/// 合成文本头部后的填充行:避免 detect_iges() 把任意文本第 73 列误判为 IGES
|
||
/// 卡片的节区字母(VDA 的 magic 探测在 IGES 之后,需保持 80 列探测点非 S/G/D/P/T)。
|
||
std::string vda_filler_line() { return std::string(1200, 'x') + "\n"; }
|
||
|
||
/// 基础合成文件:HDR + CURVE(4 段闭合方形)+ CONS + FACE(边界回退面)+ SURF(双线性面)+ FACE。
|
||
const std::string kSyntheticVda =
|
||
"VDAFS 2.0 TEST\n" + vda_filler_line() +
|
||
"HDR1 = HEADER / VDAFS 2.0 SYNTHETIC\n"
|
||
"CUR1 = CURVE / 4\n"
|
||
"0 0.25 0.5 0.75 1\n"
|
||
"2 0 0 0 10 0 0\n"
|
||
"2 10 0 0 10 10 0\n"
|
||
"2 10 10 0 0 10 0\n"
|
||
"2 0 10 0 0 0 0\n"
|
||
"CNS1 = CONS / CUR1\n"
|
||
"FACE1 = FACE /\n"
|
||
"CNS1\n"
|
||
"SURF1 = SURF / 1 1\n"
|
||
"0 1 0 1\n"
|
||
"2 2\n"
|
||
"0 0 1 1\n"
|
||
"0 1 0 1\n"
|
||
"0 0 0 0\n"
|
||
"FACE2 = FACE / SURF1\n";
|
||
|
||
/// 仅 CURVE/CONS/FACE(无 SURF):覆盖 DEGRADED 边界扇三角化路径。
|
||
const std::string kSyntheticCurveOnly =
|
||
"VDAFS 2.0 TEST\n" + vda_filler_line() +
|
||
"HDR1 = HEADER / VDAFS 2.0 SYNTHETIC CURVE ONLY\n"
|
||
"CUR1 = CURVE / 3\n"
|
||
"0 0.333 0.666 1\n"
|
||
"2 0 0 0 4 0 0\n"
|
||
"2 4 0 0 0 3 0\n"
|
||
"2 0 3 0 0 0 0\n"
|
||
"CNS1 = CONS / CUR1\n"
|
||
"FACE1 = FACE /\n"
|
||
"CNS1\n";
|
||
|
||
bool warning_contains(const std::vector<std::string>& warnings, const std::string& needle) {
|
||
for (const auto& w : warnings)
|
||
if (w.find(needle) != std::string::npos) return true;
|
||
return false;
|
||
}
|
||
|
||
} // namespace
|
||
|
||
TEST(Vda, SyntheticHeaderCurveConsSurfaceFaceImport) {
|
||
const std::string path = write_vda_fixture("wp108_vda_full.vda", kSyntheticVda);
|
||
VdaImportResult r = import_vda(path);
|
||
std::remove(path.c_str());
|
||
ASSERT_TRUE(r.success) << r.error;
|
||
EXPECT_EQ(r.bodies.size(), 2u); // FACE1 边界面 + FACE2 SURF 参数面
|
||
size_t faces = 0;
|
||
for (const auto& b : r.bodies) faces += b.num_faces();
|
||
EXPECT_GT(faces, 0u);
|
||
EXPECT_TRUE(warning_contains(r.warnings, "SURF 参数面已精确采样")) << r.warnings.front();
|
||
EXPECT_TRUE(warning_contains(r.warnings, "未做 FACE trim"));
|
||
}
|
||
|
||
TEST(Vda, SyntheticCurveOnlyFallsBackToBoundaryPatch) {
|
||
const std::string path = write_vda_fixture("wp108_vda_curve.vda", kSyntheticCurveOnly);
|
||
VdaImportResult r = import_vda(path);
|
||
std::remove(path.c_str());
|
||
ASSERT_TRUE(r.success) << r.error;
|
||
EXPECT_EQ(r.bodies.size(), 1u);
|
||
EXPECT_GT(r.bodies[0].num_faces(), 0u);
|
||
EXPECT_TRUE(warning_contains(r.warnings, "DEGRADED")) << r.warnings.front();
|
||
}
|
||
|
||
TEST(Vda, ImportCadDetectsSyntheticVda) {
|
||
const std::string path = write_vda_fixture("wp108_vda_cad.vda", kSyntheticVda);
|
||
CadImportResult r = import_cad(path);
|
||
std::remove(path.c_str());
|
||
EXPECT_TRUE(r.ok) << (r.messages.empty() ? "" : r.messages.front());
|
||
EXPECT_EQ(r.detected.format, vde::io::FileFormat::Vda);
|
||
EXPECT_FALSE(r.bodies.empty());
|
||
}
|
||
|
||
TEST(Vda, BadInputWithoutRecordsFails) {
|
||
const std::string path = write_vda_fixture("wp108_vda_bad.vda", "not a VDA file\n");
|
||
VdaImportResult r = import_vda(path);
|
||
std::remove(path.c_str());
|
||
EXPECT_FALSE(r.success);
|
||
EXPECT_NE(r.error.find("未找到 VDAFS 记录"), std::string::npos) << r.error;
|
||
}
|
||
|
||
TEST(Vda, FaceWithoutConsReportsWarningAndFails) {
|
||
const std::string path = write_vda_fixture(
|
||
"wp108_vda_nocons.vda",
|
||
"VDAFS 2.0 TEST\nHDR1 = HEADER / VDAFS 2.0\nFACE1 = FACE /\n");
|
||
VdaImportResult r = import_vda(path);
|
||
std::remove(path.c_str());
|
||
EXPECT_FALSE(r.success);
|
||
EXPECT_NE(r.error.find("无可用的边界曲线"), std::string::npos) << r.error;
|
||
EXPECT_TRUE(warning_contains(r.warnings, "FACE 无 CONS 引用"));
|
||
}
|
||
|
||
TEST(Vda, MalformedCurveWarnsAndDoesNotCrash) {
|
||
const std::string path = write_vda_fixture(
|
||
"wp108_vda_curvebad.vda",
|
||
"VDAFS 2.0 TEST\nCUR1 = CURVE / 0\n2 0 0 0 1 0 0\nFACE1 = FACE /\nCNS1\n"
|
||
"CNS1 = CONS / CUR1\n");
|
||
VdaImportResult r = import_vda(path);
|
||
std::remove(path.c_str());
|
||
EXPECT_TRUE(warning_contains(r.warnings, "CURVE 段数非法"));
|
||
EXPECT_FALSE(r.success);
|
||
}
|
||
|
||
TEST(Vda, MalformedSurfaceFallsBackToBoundaryFace) {
|
||
const std::string path = write_vda_fixture(
|
||
"wp108_vda_surf_bad.vda",
|
||
"VDAFS 2.0 TEST\nHDR1 = HEADER / VDAFS 2.0\n"
|
||
"CUR1 = CURVE / 3\n0 0.25 0.5 1\n2 0 0 0 4 0 0\n2 4 0 0 0 3 0\n2 0 3 0 0 0 0\n"
|
||
"CNS1 = CONS / CUR1\n"
|
||
"SURF1 = SURF /\n"
|
||
"FACE1 = FACE /\nCNS1\n");
|
||
VdaImportResult r = import_vda(path);
|
||
std::remove(path.c_str());
|
||
ASSERT_TRUE(r.success) << r.error;
|
||
EXPECT_TRUE(warning_contains(r.warnings, "SURF 解析失败")) << r.warnings.front();
|
||
EXPECT_EQ(r.bodies.size(), 1u);
|
||
}
|
||
|
||
TEST(Vda, MissingFileFailsClearly) {
|
||
VdaImportResult r = import_vda(std::string(VDE_TEST_TEMP_DIR) + "no_such_file_108.vda");
|
||
EXPECT_FALSE(r.success);
|
||
EXPECT_NE(r.error.find("无法打开"), std::string::npos) << r.error;
|
||
}
|
||
|
||
|
||
TEST(Vda, PlanarSurfWithConsUsesBoundaryPatch) {
|
||
const std::string fixture =
|
||
"VDAFS 2.0 TEST\n" + vda_filler_line() +
|
||
"HDR1 = HEADER / VDAFS 2.0 PLANAR TRIM\n"
|
||
"CUR1 = CURVE / 4\n"
|
||
"0 0.25 0.5 0.75 1\n"
|
||
"2 0 0 0 4 0 0\n"
|
||
"2 4 0 0 4 4 0\n"
|
||
"2 4 4 0 0 4 0\n"
|
||
"2 0 4 0 0 0 0\n"
|
||
"CNS1 = CONS / CUR1\n"
|
||
"SURF1 = SURF / 1 1\n"
|
||
"0 1 0 1\n"
|
||
"2 2\n"
|
||
"0 0 1 1\n"
|
||
"0 10 0 10\n"
|
||
"0 0 0 0\n"
|
||
"FACE1 = FACE /\n"
|
||
"CNS1\n"
|
||
"SURF1\n";
|
||
const std::string path = write_vda_fixture("wp108_vda_planar_trim.vda", fixture);
|
||
VdaImportResult r = import_vda(path);
|
||
std::remove(path.c_str());
|
||
ASSERT_TRUE(r.success) << r.error;
|
||
ASSERT_EQ(r.bodies.size(), 1u);
|
||
double max_x = 0.0;
|
||
for (const auto& v : r.bodies[0].all_vertices()) max_x = std::max(max_x, v.point.x());
|
||
EXPECT_LE(max_x, 4.1);
|
||
EXPECT_TRUE(warning_contains(r.warnings, "平面 FACE 使用 CONS 边界 patch"));
|
||
}
|
||
|
||
|
||
TEST(Vda, CurvedSurfWithPlanarConsIsClipped) {
|
||
const std::string fixture =
|
||
"VDAFS 2.0 TEST\n" + vda_filler_line() +
|
||
"HDR1 = HEADER / VDAFS 2.0 CURVED TRIM\n"
|
||
"CUR1 = CURVE / 4\n"
|
||
"0 0.25 0.5 0.75 1\n"
|
||
"2 2 2 0 4 2 0\n"
|
||
"2 4 2 0 4 4 0\n"
|
||
"2 4 4 0 2 4 0\n"
|
||
"2 2 4 0 2 2 0\n"
|
||
"CNS1 = CONS / CUR1\n"
|
||
"SURF1 = SURF / 1 1\n"
|
||
"0 1 0 1\n"
|
||
"3 3\n"
|
||
"0 5 10 0 5 10 0 5 10\n"
|
||
"0 0 0 5 5 5 10 10 10\n"
|
||
"0 2.5 10 0 2.5 10 0 2.5 10\n"
|
||
"FACE1 = FACE /\n"
|
||
"CNS1\n"
|
||
"SURF1\n";
|
||
const std::string path = write_vda_fixture("wp108_vda_curved_trim.vda", fixture);
|
||
VdaImportResult r = import_vda(path);
|
||
std::remove(path.c_str());
|
||
ASSERT_TRUE(r.success) << r.error;
|
||
ASSERT_EQ(r.bodies.size(), 1u);
|
||
double min_x = 1e9, max_x = -1e9, max_y = -1e9;
|
||
for (const auto& v : r.bodies[0].all_vertices()) {
|
||
min_x = std::min(min_x, v.point.x());
|
||
max_x = std::max(max_x, v.point.x());
|
||
max_y = std::max(max_y, v.point.y());
|
||
}
|
||
std::printf("curved trim bbox x=[%.3f,%.3f] max_y=%.3f\n", min_x, max_x, max_y);
|
||
EXPECT_GE(min_x, 1.9);
|
||
EXPECT_LE(max_x, 4.1);
|
||
EXPECT_LE(max_y, 4.1);
|
||
EXPECT_TRUE(warning_contains(r.warnings, "曲面 FACE 使用边界裁剪近似"));
|
||
}
|
||
|
||
|
||
TEST(Vda, CurvedSurfWithNonPlanarConsUsesBoundaryPatch) {
|
||
const std::string fixture =
|
||
"VDAFS 2.0 TEST\n" + vda_filler_line() +
|
||
"HDR1 = HEADER / VDAFS 2.0 CURVED NONPLANAR\n"
|
||
"CUR1 = CURVE / 4\n"
|
||
"0 0.25 0.5 0.75 1\n"
|
||
"2 2 2 0 4 2 0\n"
|
||
"2 4 2 0 4 4 2\n"
|
||
"2 4 4 2 2 4 0\n"
|
||
"2 2 4 0 2 2 0\n"
|
||
"CNS1 = CONS / CUR1\n"
|
||
"SURF1 = SURF / 1 1\n"
|
||
"0 1 0 1\n"
|
||
"3 3\n"
|
||
"0 5 10 0 5 10 0 5 10\n"
|
||
"0 0 0 5 5 5 10 10 10\n"
|
||
"0 2.5 10 0 2.5 10 0 2.5 10\n"
|
||
"FACE1 = FACE /\n"
|
||
"CNS1\n"
|
||
"SURF1\n";
|
||
const std::string path = write_vda_fixture("wp108_vda_nonplanar_int.vda", fixture);
|
||
VdaImportResult r = import_vda(path);
|
||
std::remove(path.c_str());
|
||
ASSERT_TRUE(r.success) << r.error;
|
||
ASSERT_EQ(r.bodies.size(), 1u);
|
||
double min_x = 1e9, max_x = -1e9;
|
||
for (const auto& v : r.bodies[0].all_vertices()) {
|
||
min_x = std::min(min_x, v.point.x());
|
||
max_x = std::max(max_x, v.point.x());
|
||
}
|
||
EXPECT_GE(min_x, 1.9);
|
||
EXPECT_LE(max_x, 4.1);
|
||
EXPECT_TRUE(warning_contains(r.warnings, "非平面边界 patch 近似"));
|
||
}
|
||
|
||
// ═══════════════════════════════════════════════════════════
|
||
// Wave21 A54:UTF-8(中文/非 ASCII)路径导入
|
||
// ═══════════════════════════════════════════════════════════
|
||
TEST(Vda, Utf8PathImportSynthetic) {
|
||
const std::string path = std::string(VDE_TEST_TEMP_DIR) + "wp108_vda_模型_①.vda";
|
||
std::error_code ec;
|
||
std::filesystem::remove(path_from_utf8(path), ec);
|
||
{
|
||
std::ofstream out = open_ofstream_utf8(path, std::ios::binary | std::ios::trunc);
|
||
ASSERT_TRUE(static_cast<bool>(out));
|
||
out << kSyntheticVda;
|
||
}
|
||
EXPECT_TRUE(std::filesystem::exists(path_from_utf8(path)));
|
||
|
||
const VdaImportResult r = import_vda(path);
|
||
ASSERT_TRUE(r.success) << r.error;
|
||
EXPECT_EQ(r.bodies.size(), 2u);
|
||
|
||
std::filesystem::remove(path_from_utf8(path), ec);
|
||
EXPECT_FALSE(std::filesystem::exists(path_from_utf8(path)));
|
||
}
|