Skip to content

Commit 94a81b3

Browse files
Evgeni Raikhelclaude
andcommitted
refactor(grid-overlay): move config from XML to realsense-config.json
Replace config-settings.xml + RapidXML parsing with config_file::get_nested / set_nested_default so grid parameters live in the standard viewer JSON config (%APPDATA%\realsense-config.json) under a viewer_model.grid sub-object. set_nested_default writes the keys with defaults on first launch so the user can discover and edit them without hunting for a separate XML file. Validation rules (out-of-range → default) are preserved. Remove the POST_BUILD copy of config-settings.xml from CMakeLists. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent f218c14 commit 94a81b3

5 files changed

Lines changed: 33 additions & 83 deletions

File tree

common/device-model.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,17 @@ namespace rs2
151151
static const char* lpc_point_size{ "viewer_model.lpc_point_size" };
152152
static const char* show_safety_zones_3d{ "viewer_model.show_safety_zones_3d" };
153153
static const char* show_safety_zones_2d{ "viewer_model.show_safety_zones_2d" };
154+
#ifdef BUILD_VIEWPORT_GRID_OVERLAY
155+
namespace viewport_grid
156+
{
157+
static const char* horizontal_lines{ "viewer_model.grid.horizontal_lines" };
158+
static const char* vertical_lines { "viewer_model.grid.vertical_lines" };
159+
static const char* line_width { "viewer_model.grid.line_width" };
160+
static const char* line_color_r { "viewer_model.grid.line_color_r" };
161+
static const char* line_color_g { "viewer_model.grid.line_color_g" };
162+
static const char* line_color_b { "viewer_model.grid.line_color_b" };
163+
}
164+
#endif
154165
}
155166
namespace window
156167
{

common/stream-model.cpp

Lines changed: 22 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include <imgui_internal.h>
99
#include <realsense_imgui.h>
1010
#ifdef BUILD_VIEWPORT_GRID_OVERLAY
11-
#include "../third-party/rapidxml/rapidxml.hpp"
12-
#include <fstream>
1311
#include <iomanip>
1412
#include <sstream>
1513
#endif
@@ -35,7 +33,28 @@ namespace rs2
3533
show_safety_zones_2d = config_file::instance().get_or_default(
3634
configurations::viewer::show_safety_zones_2d, true);
3735
#ifdef BUILD_VIEWPORT_GRID_OVERLAY
38-
load_grid_config();
36+
{
37+
namespace cfg = configurations::viewer::viewport_grid;
38+
auto& cf = config_file::instance();
39+
40+
cf.set_nested_default( cfg::horizontal_lines, 1 );
41+
cf.set_nested_default( cfg::vertical_lines, 1 );
42+
cf.set_nested_default( cfg::line_width, 1 );
43+
cf.set_nested_default( cfg::line_color_r, 255 );
44+
cf.set_nested_default( cfg::line_color_g, 255 );
45+
cf.set_nested_default( cfg::line_color_b, 255 );
46+
47+
auto valid_lines = []( int v ) { return ( v >= 1 && v <= 5 ) ? v : 1; };
48+
grid_h_lines = valid_lines( cf.get_nested<int>( cfg::horizontal_lines, 1 ) );
49+
grid_v_lines = valid_lines( cf.get_nested<int>( cfg::vertical_lines, 1 ) );
50+
int w = cf.get_nested<int>( cfg::line_width, 1 );
51+
if ( w >= 1 ) grid_line_width = w;
52+
int r = cf.get_nested<int>( cfg::line_color_r, 255 );
53+
int g = cf.get_nested<int>( cfg::line_color_g, 255 );
54+
int b = cf.get_nested<int>( cfg::line_color_b, 255 );
55+
if ( r >= 0 && r <= 255 && g >= 0 && g <= 255 && b >= 0 && b <= 255 )
56+
{ grid_color_r = r; grid_color_g = g; grid_color_b = b; }
57+
}
3958
#endif
4059
}
4160

@@ -166,56 +185,6 @@ namespace rs2
166185
glPopAttrib();
167186
}
168187

169-
void stream_model::load_grid_config()
170-
{
171-
std::ifstream fin("config-settings.xml");
172-
if (!fin.is_open())
173-
return;
174-
175-
std::stringstream ss;
176-
ss << fin.rdbuf();
177-
auto xml = ss.str();
178-
179-
try
180-
{
181-
rapidxml::xml_document<> doc;
182-
doc.parse<0>(doc.allocate_string(xml.c_str()));
183-
184-
auto viewer_root = doc.first_node("realsense-viewer");
185-
if (!viewer_root) return;
186-
auto root = viewer_root->first_node("viewport-grid");
187-
if (!root) return;
188-
189-
auto valid_lines = [](int v) { return (v >= 1 && v <= 5) ? v : 1; };
190-
191-
if (auto n = root->first_node("horizontal_lines"))
192-
if (auto a = n->first_attribute("count"))
193-
grid_h_lines = valid_lines(std::atoi(a->value()));
194-
195-
if (auto n = root->first_node("vertical_lines"))
196-
if (auto a = n->first_attribute("count"))
197-
grid_v_lines = valid_lines(std::atoi(a->value()));
198-
199-
if (auto n = root->first_node("line_width"))
200-
if (auto a = n->first_attribute("pixels"))
201-
{
202-
int w = std::atoi(a->value());
203-
if (w >= 1) grid_line_width = w;
204-
}
205-
206-
if (auto n = root->first_node("line_color"))
207-
{
208-
auto valid_byte = [](int v) { return v >= 0 && v <= 255; };
209-
int r = grid_color_r, g = grid_color_g, b = grid_color_b;
210-
if (auto a = n->first_attribute("r")) r = std::atoi(a->value());
211-
if (auto a = n->first_attribute("g")) g = std::atoi(a->value());
212-
if (auto a = n->first_attribute("b")) b = std::atoi(a->value());
213-
if (valid_byte(r) && valid_byte(g) && valid_byte(b))
214-
{ grid_color_r = r; grid_color_g = g; grid_color_b = b; }
215-
}
216-
}
217-
catch (...) {}
218-
}
219188
#endif
220189

221190
bool stream_model::is_stream_visible() const

common/stream-model.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,6 @@ namespace rs2
139139
void add_dds_metadata_descriptions(std::map<rs2_frame_metadata_value, std::string>& descriptions) const;
140140
void deal_d585S_metadata_md_values_special_cases(const frame& f);
141141
std::string get_meaning(const rs2_frame_metadata_value& md_val, const std::vector<std::string>& reasons, const std::string& reason_for_zero = "") const;
142-
#ifdef BUILD_VIEWPORT_GRID_OVERLAY
143-
void load_grid_config();
144-
#endif
145142
};
146143

147144

tools/realsense-viewer/CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,6 @@ endif()
259259
if(BUILD_VIEWPORT_GRID_OVERLAY)
260260
message(STATUS "Viewport grid overlay enabled for realsense-viewer")
261261
target_compile_definitions(realsense-viewer PRIVATE BUILD_VIEWPORT_GRID_OVERLAY)
262-
add_custom_command(TARGET realsense-viewer POST_BUILD
263-
COMMAND ${CMAKE_COMMAND} -E copy_if_different
264-
${CMAKE_CURRENT_SOURCE_DIR}/config-settings.xml
265-
$<TARGET_FILE_DIR:realsense-viewer>/config-settings.xml
266-
COMMENT "Copying grid config-settings.xml to output directory"
267-
)
268262
endif()
269263

270264
source_group("SW-Update" FILES ${SW_UPDATE_FILES})

tools/realsense-viewer/config-settings.xml

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)