scenerygraphics / sciview

sciview is a tool for visualization and interaction with ND image and mesh data
BSD 2-Clause "Simplified" License
67 stars 17 forks source link

SciView.requestPropEditorRefresh() ain't working #358

Closed xulman closed 1 year ago

xulman commented 3 years ago
        //grab a sciview from somewhere...
        SciView sv = sciView;

        //show node inspector (why it does not have a param to tell the desired state?)
        sv.mainWindow.toggleSidebar();

        Node n1 = new Node("level 1");
        sv.addNode(n1); //NB: sciview API, not avail for Node, shows up in the inspector

        Node n2 = new Node("level 2");
        n1.addChild(n2); //NB: scenery API, avail for every Node, also shows up in the inspector

        n2.addChild(new Node("level 3")); //shows up...
        // Nodes have no problem to appear

        //add leaves, esp. anything but pure Node instances...
        sv.addNode(new Box(new Vector3f(1),false));  //shows up, sciview API
        final Box box = new Box(new Vector3f(1),false);
        n1.addChild(box);                                              //nope... (scenery API)
        n2.addChild(new Box(new Vector3f(1),false));  //nope...

        //NB: requestPropEditorRefresh(...); triggers NodeChangedEvent(...) event
        //sv.requestPropEditorRefresh(n1); //does NOT show the leaves in the inspector
        sv.requestPropEditorRefresh(box);  //does NOT show the leaves in the inspector
        //events.publish(new NodeAddedEvent(box));  //does show all
        //events.publish(new NodeAddedEvent(n1));   //does NOT show all
        //events.publish(new NodeChangedEvent(n1)); //does NOT show all, same as sv.requestPropEditorRefresh(n1);
        //sv.mainWindow.rebuildSceneTree(); //does show all

        //Events seems to be effective only they match their contract:, that is, as follows:
        //  NodeChangedEvent works on node that has changed where adding children does not count as "changed"
        //  NodeChangedEvent does not enforce adding new node into the Inspector
        //  NodeAddedEvent works on a node that was indeed added recently, shows it in the Inspector
        //  NodeAddedEvent does nothing on previously shown node

I propose to modify requestPropEditorRefresh() to just call the rebuildSceneTree() unless we have something less brutal (like locally updating the tree rather than rebuilding it (from scratch?); or it could trigger two events (Add & Changed)...

Events work but need to be used exactly (must match the purpose and the correct object). Intention why a user calls requestPropEditorRefresh() is not clear because of its name, this excludes Events to be under the hood.

kephale commented 1 year ago

One concern about using rebuildSceneTree() is that it would cause something like https://github.com/scenerygraphics/sciview/issues/480 (which already happens, heh).

kephale commented 1 year ago

In https://github.com/scenerygraphics/sciview/pull/499 I used this strategy:

https://github.com/scenerygraphics/sciview/blob/b2175f07b71d42d1c9c08d0ef842b6e8c6a7f40a/src/main/kotlin/sc/iview/SciView.kt#L903

which is part of publishNode, would that be OK in this case?

kephale commented 1 year ago

I think this is complete. @moreApi added publishNode to the API (go figure). @xulman said he likes publishNode over Zulip at the 2023 hackathon.