From 72b5f6f25f39d11d718d807a86edc65855a963a1 Mon Sep 17 00:00:00 2001 From: gaozheng Date: Tue, 30 Jun 2026 21:14:12 +0800 Subject: [PATCH] =?UTF-8?q?feat(vtk):=20=E6=B8=B2=E6=9F=93=E7=AD=96?= =?UTF-8?q?=E7=95=A5=E6=8E=A5=E5=8F=A3+=E5=AD=97=E7=AC=A6=E4=B8=B2?= =?UTF-8?q?=E9=94=AE=E6=B3=A8=E5=86=8C=E8=A1=A8+3=E9=AA=A8=E6=9E=B6?= =?UTF-8?q?=E7=AD=96=E7=95=A5(volume/curtain/plane2d)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/CMakeLists.txt | 1 + src/controller/DatasetRenderStrategy.cpp | 15 ++++++ src/controller/DatasetRenderStrategy.hpp | 52 +++++++++++++++++++ tests/CMakeLists.txt | 2 + .../test_render_strategy_registry.cpp | 22 ++++++++ 5 files changed, 92 insertions(+) create mode 100644 src/controller/DatasetRenderStrategy.cpp create mode 100644 src/controller/DatasetRenderStrategy.hpp create mode 100644 tests/controller/test_render_strategy_registry.cpp diff --git a/src/controller/CMakeLists.txt b/src/controller/CMakeLists.txt index 2f57347..b8ce020 100644 --- a/src/controller/CMakeLists.txt +++ b/src/controller/CMakeLists.txt @@ -3,6 +3,7 @@ add_library(geopro_controller STATIC WorkbenchNavController.cpp DatasetDetailController.cpp DatasetViewState.cpp + DatasetRenderStrategy.cpp VtkSceneController.cpp) target_include_directories(geopro_controller PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_link_libraries(geopro_controller PUBLIC geopro_data Qt6::Core) diff --git a/src/controller/DatasetRenderStrategy.cpp b/src/controller/DatasetRenderStrategy.cpp new file mode 100644 index 0000000..628c994 --- /dev/null +++ b/src/controller/DatasetRenderStrategy.cpp @@ -0,0 +1,15 @@ +#include "controller/DatasetRenderStrategy.hpp" + +namespace geopro::controller { + +// 骨架实现:渲染体由后续阶段填充(Phase B / E / F)。当前为空实现,仅保证链接。 +void VolumeRenderStrategy::add(const std::string& /*typeId*/, const std::string& /*dsId*/) {} +void VolumeRenderStrategy::remove(const std::string& /*dsId*/) {} + +void CurtainRenderStrategy::add(const std::string& /*typeId*/, const std::string& /*dsId*/) {} +void CurtainRenderStrategy::remove(const std::string& /*dsId*/) {} + +void Plane2DRenderStrategy::add(const std::string& /*typeId*/, const std::string& /*dsId*/) {} +void Plane2DRenderStrategy::remove(const std::string& /*dsId*/) {} + +} // namespace geopro::controller diff --git a/src/controller/DatasetRenderStrategy.hpp b/src/controller/DatasetRenderStrategy.hpp new file mode 100644 index 0000000..e6cda9d --- /dev/null +++ b/src/controller/DatasetRenderStrategy.hpp @@ -0,0 +1,52 @@ +#pragma once +#include +#include +#include + +namespace geopro::controller { + +class IDatasetRenderStrategy { +public: + virtual ~IDatasetRenderStrategy() = default; + virtual void add(const std::string& typeId, const std::string& dsId) = 0; + virtual void remove(const std::string& dsId) = 0; + virtual void onTypeActivated(const std::string& /*typeId*/) {} + virtual void onTypeDeactivated(const std::string& /*typeId*/) {} +}; + +class RenderStrategyRegistry { +public: + void registerStrategy(std::string id, std::unique_ptr s) { + strategies_[std::move(id)] = std::move(s); + } + IDatasetRenderStrategy* get(const std::string& id) const { + auto it = strategies_.find(id); + return it == strategies_.end() ? nullptr : it->second.get(); + } +private: + std::map> strategies_; +}; + +// 3 骨架策略:本任务仅建类与注册。add/remove 的真实渲染实现由后续阶段填充—— +// Phase B(VolumeRenderStrategy/CurtainRenderStrategy 包现有 3D 分支)与 +// Phase E/F(Plane2DRenderStrategy 平面 z + 底图)。届时各自接所需的 +// VtkSceneController& / View / Repo 引用。当前 .cpp 给空实现使链接通过。 +class VolumeRenderStrategy : public IDatasetRenderStrategy { +public: + void add(const std::string& typeId, const std::string& dsId) override; + void remove(const std::string& dsId) override; +}; + +class CurtainRenderStrategy : public IDatasetRenderStrategy { +public: + void add(const std::string& typeId, const std::string& dsId) override; + void remove(const std::string& dsId) override; +}; + +class Plane2DRenderStrategy : public IDatasetRenderStrategy { +public: + void add(const std::string& typeId, const std::string& dsId) override; + void remove(const std::string& dsId) override; +}; + +} // namespace geopro::controller diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index cb66ab2..c4316c2 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -218,6 +218,8 @@ target_sources(geopro_tests PRIVATE controller/test_dataset_detail_controller.cp target_sources(geopro_tests PRIVATE controller/test_workbench_nav_controller.cpp) # VtkSceneController 编排:注入 fake repo + fake view,断言 视图模式×图层 组合下 add 的图元类型/数量;取消勾选清空。 target_sources(geopro_tests PRIVATE controller/test_vtk_scene_controller.cpp) +# RenderStrategyRegistry:字符串键策略注册表解析(register/get,纯逻辑,FakeStrategy)。 +target_sources(geopro_tests PRIVATE controller/test_render_strategy_registry.cpp) target_link_libraries(geopro_tests PRIVATE geopro_controller Qt6::Test) # io/gpr 层:.iprh 头解析 + .iprb B-scan 读取(纯 C++17,零 Qt/VTK)。 diff --git a/tests/controller/test_render_strategy_registry.cpp b/tests/controller/test_render_strategy_registry.cpp new file mode 100644 index 0000000..9bb4043 --- /dev/null +++ b/tests/controller/test_render_strategy_registry.cpp @@ -0,0 +1,22 @@ +#include +#include "controller/DatasetRenderStrategy.hpp" + +using namespace geopro::controller; + +namespace { +struct FakeStrategy : IDatasetRenderStrategy { + int added = 0; + void add(const std::string&, const std::string&) override { ++added; } + void remove(const std::string&) override {} +}; +} + +TEST(RenderStrategyRegistry, ResolvesById) { + RenderStrategyRegistry reg; + reg.registerStrategy("fake", std::make_unique()); + auto* s = reg.get("fake"); + ASSERT_NE(s, nullptr); + s->add("trajectory", "d1"); + EXPECT_EQ(static_cast(s)->added, 1); + EXPECT_EQ(reg.get("missing"), nullptr); +}