Skip to content

Commit

Permalink
Merge pull request #465 from scenerygraphics/boundingGridsForAll
Browse files Browse the repository at this point in the history
  • Loading branch information
kephale authored Jun 13, 2023
2 parents 928f33f + c0326de commit 89f7c93
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
16 changes: 15 additions & 1 deletion src/main/kotlin/sc/iview/SciView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,20 @@ class SciView : SceneryBase, CalibratedRealInterval<CalibratedAxis> {
return n
}

/**
* Make a node known to the services.
* Used for nodes that are not created/added by a SciView controlled process e.g. [BoundingGrid].
*
* @param n node to add to publish
*/
fun <N: Node> publishNode(n: N): N {
n.let {
objectService.addObject(n)
eventService.publish(NodeAddedEvent(n))
}
return n
}

/**
* Add a scenery Mesh to the scene
* @param scMesh scenery mesh to add to scene
Expand Down Expand Up @@ -1057,7 +1071,7 @@ class SciView : SceneryBase, CalibratedRealInterval<CalibratedAxis> {
* @param activePublish whether the deletion should be published
*/
@JvmOverloads
fun deleteNode(node: Node?, activePublish: Boolean = true) {
fun deleteNode(node: Node?, activePublish: Boolean = true) {
if(node is Volume) {
node.volumeManager.remove(node)
val toRemove = ArrayList<Any>()
Expand Down
23 changes: 8 additions & 15 deletions src/main/kotlin/sc/iview/commands/view/ToggleBoundingGrid.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
package sc.iview.commands.view

import graphics.scenery.BoundingGrid
import graphics.scenery.Mesh
import graphics.scenery.Node
import org.scijava.command.Command
import org.scijava.log.LogService
Expand All @@ -47,27 +46,21 @@ import sc.iview.commands.MenuWeights.VIEW_TOGGLE_BOUNDING_GRID
*/
@Plugin(type = Command::class, menuRoot = "SciView", menu = [Menu(label = "View", weight = VIEW), Menu(label = "Toggle Bounding Grid", weight = VIEW_TOGGLE_BOUNDING_GRID)])
class ToggleBoundingGrid : Command {
@Parameter
private lateinit var logService: LogService

@Parameter
private lateinit var sciView: SciView

@Parameter
private lateinit var node: Node

override fun run() {
if (node is Mesh) {
if (node.metadata.containsKey("BoundingGrid")) {
val bg = node.metadata["BoundingGrid"] as BoundingGrid?
bg!!.node = null
node.metadata.remove("BoundingGrid")
bg.getScene()!!.removeChild(bg)
} else {
val bg = BoundingGrid()
bg.node = node
node.metadata["BoundingGrid"] = bg
}
val bg = node.children.findLast { it is BoundingGrid } as? BoundingGrid
if (bg != null) {
bg.node = null
sciView.deleteNode(bg)
} else {
val newBg = BoundingGrid()
newBg.node = node
sciView.publishNode(newBg)
}
}
}

0 comments on commit 89f7c93

Please sign in to comment.