scenerygraphics / sciview

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

SciView: set active node only when centerOnNewNodes is true #551

Closed smlpt closed 4 months ago

smlpt commented 4 months ago

This fixes an issue where adding new objects to the scene would be slowed down by the fact that each new node would always be set as the active node. This would also cause excessive log outputs about each active node like:

[INFO] Custom module found: null
[INFO] Adding input scaleX/Scale X
[INFO] Custom module found: null
[INFO] Adding input scaleY/Scale Y
[INFO] Custom module found: null
[INFO] Adding input scaleZ/Scale Z
[INFO] Custom module found: null
[INFO] Adding input rotationPhi/Rotation Phi
[INFO] Custom module found: null
[INFO] Adding input rotationTheta/Rotation Theta
[INFO] Custom module found: null
[INFO] Adding input rotationPsi/Rotation Psi

With this fix, new nodes are only considered active when centerOnNewNodes is set to true.

xulman commented 4 months ago

the setActiveNode() (even in the new proposed position) will not follow the activePublish flag.. no? it would always trigger the publishing event (yes, a different one, but still some)

for me, the purpose of the activePublish flag was that I could temporarily suspend publishing when adding a burst of nodes, and trigger the publishing only with the last node added

just thinking now aloud

smlpt commented 4 months ago

I changed it so that setActiveNode is only called if activePublish is true:

fun <N: Node?> addNode(n: N, activePublish: Boolean = true, block: N.() -> Unit = {}, parent: Node = scene): N {
        n?.let {
            it.block()
            // Ensure name is unique
            n.name = generateUniqueName(n.name)
            parent.addChild(it)
            objectService.addObject(n)
            if (blockOnNewNodes) {
                Utils.blockWhile({ this.find(n.name) == null }, 20)
                //System.out.println("find(name) " + find(n.getName()) );
            }

            if (activePublish) {
                eventService.publish(NodeAddedEvent(n))
                setActiveNode(n)
                // Set new node as centered
                if (centerOnNewNodes) {
                    centerOnNode(n)
                }
            }
        }
        return n
    }
kephale commented 4 months ago

LGTM, than you @smlpt