Skip to content

Commit febdafd

Browse files
committed
fixed graph view
1 parent 51790f9 commit febdafd

3 files changed

Lines changed: 35 additions & 20 deletions

File tree

CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ install(FILES
8989
)
9090

9191
# Build demo executable from docs/examples/demo.cpp
92-
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/docs/examples/demo.cpp")
93-
add_executable(demo docs/examples/demo.cpp)
94-
target_link_libraries(demo PRIVATE pythonic)
95-
message(STATUS "Demo executable configured: run with './demo' after building")
96-
endif()
92+
# if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/docs/examples/demo.cpp")
93+
# add_executable(demo docs/examples/demo.cpp)
94+
# target_link_libraries(demo PRIVATE pythonic)
95+
# message(STATUS "Demo executable configured: run with './demo' after building")
96+
# endif()
9797

9898
# ============================================================================
9999
# Optional: Interactive Graph Viewer

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,31 +31,36 @@ Welcome! Pythonic is a modern C++20 library that brings the expressive power and
3131
The library includes an **optional** interactive graph visualization feature. To enable it, you need to install the following dependencies:
3232

3333
### Ubuntu/Debian:
34+
3435
```bash
3536
sudo apt-get update
3637
sudo apt-get install libglfw3-dev libgl1-mesa-dev
3738
git clone https://github.com/ocornut/imgui.git external/imgui
3839
```
3940

4041
### macOS:
42+
4143
```bash
4244
brew install glfw
4345
git clone https://github.com/ocornut/imgui.git external/imgui
4446
```
4547

4648
### Windows (vcpkg):
49+
4750
```bash
4851
vcpkg install glfw3:x64-windows
4952
git clone https://github.com/ocornut/imgui.git external/imgui
5053
```
5154

5255
Then build with:
56+
5357
```bash
5458
cmake -B build -DPYTHONIC_ENABLE_GRAPH_VIEWER=ON
5559
cmake --build build
5660
```
5761

5862
Use in code:
63+
5964
```cpp
6065
#include <pythonic/pythonic.hpp>
6166
using namespace pythonic::vars;
@@ -72,7 +77,6 @@ We’re looking for users to test the library and provide feedback!
7277
Please open Issues or Discussions with any bug reports, questions, or feature ideas.
7378
**Note:** Direct code contributions are not accepted at this time.
7479
75-
7680
## Acknowledgments
7781
7882
Parts of this project, including some code generation and much of documentation, were assisted by GitHub Copilot (AI programming assistant). Copilot provided suggestions and support throughout the development process.

src/graph_viewer.cpp

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,13 +1426,15 @@ namespace pythonic
14261426
// Retrieve original edge IDs from the snapshot index under lock
14271427
size_t orig_u = (size_t)-1;
14281428
size_t orig_v = (size_t)-1;
1429-
1429+
14301430
{
14311431
std::lock_guard<std::mutex> lock(snapshot_mutex_);
14321432
// This ensures we remove the ACTUAL existing edge, not the potentially-swapped UI values
1433-
if (last_selected_edge_idx_ >= 0 && last_selected_edge_idx_ < back_snapshot_.edges.size()) {
1434-
const auto& es = back_snapshot_.edges[last_selected_edge_idx_];
1435-
if (es.from < back_snapshot_.nodes.size() && es.to < back_snapshot_.nodes.size()) {
1433+
if (last_selected_edge_idx_ >= 0 && last_selected_edge_idx_ < back_snapshot_.edges.size())
1434+
{
1435+
const auto &es = back_snapshot_.edges[last_selected_edge_idx_];
1436+
if (es.from < back_snapshot_.nodes.size() && es.to < back_snapshot_.nodes.size())
1437+
{
14361438
orig_u = back_snapshot_.nodes[es.from].node_id;
14371439
orig_v = back_snapshot_.nodes[es.to].node_id;
14381440
}
@@ -1447,7 +1449,7 @@ namespace pythonic
14471449
// Remove original edge(s) completely to avoid duplicates/residue
14481450
graph_var_.remove_edge(orig_u, orig_v, true);
14491451
graph_var_.remove_edge(orig_v, orig_u, true);
1450-
1452+
14511453
if (directed)
14521454
graph_var_.add_edge(selected_edge_node_from_id_, selected_edge_node_to_id_, w1, std::numeric_limits<double>::quiet_NaN(), true);
14531455
else
@@ -1467,12 +1469,14 @@ namespace pythonic
14671469
// Use original IDs for removal to ensure it works even if UI was flipped
14681470
size_t orig_u = (size_t)-1;
14691471
size_t orig_v = (size_t)-1;
1470-
1472+
14711473
{
14721474
std::lock_guard<std::mutex> lock(snapshot_mutex_);
1473-
if (last_selected_edge_idx_ >= 0 && last_selected_edge_idx_ < back_snapshot_.edges.size()) {
1474-
const auto& es = back_snapshot_.edges[last_selected_edge_idx_];
1475-
if (es.from < back_snapshot_.nodes.size() && es.to < back_snapshot_.nodes.size()) {
1475+
if (last_selected_edge_idx_ >= 0 && last_selected_edge_idx_ < back_snapshot_.edges.size())
1476+
{
1477+
const auto &es = back_snapshot_.edges[last_selected_edge_idx_];
1478+
if (es.from < back_snapshot_.nodes.size() && es.to < back_snapshot_.nodes.size())
1479+
{
14761480
orig_u = back_snapshot_.nodes[es.from].node_id;
14771481
orig_v = back_snapshot_.nodes[es.to].node_id;
14781482
}
@@ -2158,8 +2162,10 @@ namespace pythonic
21582162
{
21592163
size_t node_id = static_cast<size_t>(path_var[i].toInt());
21602164
// Map node_id to snapshot index
2161-
for (size_t idx = 0; idx < back_snapshot_.nodes.size(); ++idx) {
2162-
if (back_snapshot_.nodes[idx].node_id == node_id) {
2165+
for (size_t idx = 0; idx < back_snapshot_.nodes.size(); ++idx)
2166+
{
2167+
if (back_snapshot_.nodes[idx].node_id == node_id)
2168+
{
21632169
sp_path_indices_.push_back(idx);
21642170
break;
21652171
}
@@ -2282,9 +2288,14 @@ namespace pythonic
22822288
running_ = true;
22832289

22842290
// RAII guard to ensure physics thread stops even on exception
2285-
struct PhysicsGuard {
2286-
GraphViewer::Impl* impl;
2287-
~PhysicsGuard() { impl->stop_physics(); impl->running_ = false; }
2291+
struct PhysicsGuard
2292+
{
2293+
GraphViewer::Impl *impl;
2294+
~PhysicsGuard()
2295+
{
2296+
impl->stop_physics();
2297+
impl->running_ = false;
2298+
}
22882299
} guard{this};
22892300

22902301
while (!glfwWindowShouldClose(window_) && !close_requested_)

0 commit comments

Comments
 (0)