Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bounding grids for all #465

Merged
merged 2 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
}