Skip to content

Commit

Permalink
Clean up custom inspector panels
Browse files Browse the repository at this point in the history
  • Loading branch information
skalarproduktraum committed Jul 2, 2024
1 parent 3db4344 commit 2418496
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 46 deletions.
46 changes: 20 additions & 26 deletions src/main/kotlin/sc/iview/commands/edit/BasicProperties.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,21 @@ package sc.iview.commands.edit

import graphics.scenery.*
import graphics.scenery.attribute.material.HasMaterial
import net.imagej.lut.LUTService
import okio.withLock
import org.joml.Quaternionf
import org.joml.Vector3f
import org.scijava.command.Command
import org.scijava.plugin.Parameter
import org.scijava.plugin.Plugin
import org.scijava.ui.UIService
import org.scijava.util.ColorRGB
import org.scijava.widget.ChoiceWidget
import org.scijava.widget.NumberWidget
import sc.iview.event.NodeChangedEvent
import java.util.*

const val GROUP_NAME_BASIC = "group:Basic Properties"
const val GROUP_NAME_ROTATION = "group:Rotation & Scaling"

/**
* A command for interactively editing a node's properties.
*
Expand All @@ -54,52 +55,45 @@ import java.util.*
*/
@Plugin(type = Command::class, initializer = "updateCommandFields", visible = false)
class BasicProperties : InspectorInteractiveCommand() {
@Parameter
private lateinit var uiSrv: UIService

@Parameter
private lateinit var lutService: LUTService

/* Basic properties */

@Parameter(required = false, style = ChoiceWidget.LIST_BOX_STYLE, callback = "refreshSceneNodeInDialog")
private val sceneNode: String? = null

@Parameter(label = "Visible", callback = "updateNodeProperties", style = "group:Basic")
@Parameter(label = "Visible", callback = "updateNodeProperties", style = GROUP_NAME_BASIC)
private var visible = false

@Parameter(label = "Color", required = false, callback = "updateNodeProperties", style = "group:Basic")
private var colour: ColorRGB? = null
@Parameter(label = "Color", required = false, callback = "updateNodeProperties", style = GROUP_NAME_BASIC)
private var color: ColorRGB? = null

@Parameter(label = "Name", callback = "updateNodeProperties", style = "group:Basic")
@Parameter(label = "Name", callback = "updateNodeProperties", style = GROUP_NAME_BASIC)
private var name: String = ""

@Parameter(label = "Position X", style = NumberWidget.SPINNER_STYLE+ ",group:Basic" + ",format:0.000", stepSize = "0.1", callback = "updateNodeProperties")
@Parameter(label = "Position X", style = NumberWidget.SPINNER_STYLE + "," + GROUP_NAME_BASIC + ",format:0.000", stepSize = "0.1", callback = "updateNodeProperties")
private var positionX = 0f

@Parameter(label = "Position Y", style = NumberWidget.SPINNER_STYLE+ ",group:Basic" + ",format:0.000", stepSize = "0.1", callback = "updateNodeProperties")
@Parameter(label = "Position Y", style = NumberWidget.SPINNER_STYLE + "," + GROUP_NAME_BASIC + ",format:0.000", stepSize = "0.1", callback = "updateNodeProperties")
private var positionY = 0f

@Parameter(label = "Position Z", style = NumberWidget.SPINNER_STYLE+ ",group:Basic" + ",format:0.000", stepSize = "0.1", callback = "updateNodeProperties")
@Parameter(label = "Position Z", style = NumberWidget.SPINNER_STYLE + "," + GROUP_NAME_BASIC + ",format:0.000", stepSize = "0.1", callback = "updateNodeProperties")
private var positionZ = 0f


@Parameter(label = "[Rotation & Scaling]Scale X", style = NumberWidget.SPINNER_STYLE+"group:Rotation & Scaling" + ",format:0.000", stepSize = "0.1", callback = "updateNodeProperties")
@Parameter(label = "Scale X", style = NumberWidget.SPINNER_STYLE + GROUP_NAME_ROTATION + ",format:0.000", stepSize = "0.1", callback = "updateNodeProperties")
private var scaleX = 1f

@Parameter(label = "[Rotation & Scaling]Scale Y", style = NumberWidget.SPINNER_STYLE+"group:Rotation & Scaling" + ",format:0.000", stepSize = "0.1", callback = "updateNodeProperties")
@Parameter(label = "Scale Y", style = NumberWidget.SPINNER_STYLE + GROUP_NAME_ROTATION + ",format:0.000", stepSize = "0.1", callback = "updateNodeProperties")
private var scaleY = 1f

@Parameter(label = "[Rotation & Scaling]Scale Z", style = NumberWidget.SPINNER_STYLE+"group:Rotation & Scaling" + ",format:0.000", stepSize = "0.1", callback = "updateNodeProperties")
@Parameter(label = "Scale Z", style = NumberWidget.SPINNER_STYLE + GROUP_NAME_ROTATION + ",format:0.000", stepSize = "0.1", callback = "updateNodeProperties")
private var scaleZ = 1f

@Parameter(label = "[Rotation & Scaling]Rotation Phi", style = NumberWidget.SPINNER_STYLE+"group:Rotation & Scaling" + ",format:0.000", min = PI_NEG, max = PI_POS, stepSize = "0.01", callback = "updateNodeProperties")
@Parameter(label = "Rotation Phi", style = NumberWidget.SPINNER_STYLE + GROUP_NAME_ROTATION + ",format:0.000", min = PI_NEG, max = PI_POS, stepSize = "0.01", callback = "updateNodeProperties")
private var rotationPhi = 0f

@Parameter(label = "[Rotation & Scaling]Rotation Theta", style = NumberWidget.SPINNER_STYLE+"group:Rotation & Scaling" + ",format:0.000", min = PI_NEG, max = PI_POS, stepSize = "0.01", callback = "updateNodeProperties")
@Parameter(label = "Rotation Theta", style = NumberWidget.SPINNER_STYLE + GROUP_NAME_ROTATION + ",format:0.000", min = PI_NEG, max = PI_POS, stepSize = "0.01", callback = "updateNodeProperties")
private var rotationTheta = 0f

@Parameter(label = "[Rotation & Scaling]Rotation Psi", style = NumberWidget.SPINNER_STYLE+"group:Rotation & Scaling" + ",format:0.000", min = PI_NEG, max = PI_POS, stepSize = "0.01", callback = "updateNodeProperties")
@Parameter(label = "Rotation Psi", style = NumberWidget.SPINNER_STYLE + GROUP_NAME_ROTATION + ",format:0.000", min = PI_NEG, max = PI_POS, stepSize = "0.01", callback = "updateNodeProperties")
private var rotationPsi = 0f


Expand Down Expand Up @@ -168,7 +162,7 @@ class BasicProperties : InspectorInteractiveCommand() {
else -> Vector3f(0.5f)
}

colour = ColorRGB(
color = ColorRGB(
(colourVector[0] * 255).toInt(), //
(colourVector[1] * 255).toInt(), //
(colourVector[2] * 255).toInt()
Expand Down Expand Up @@ -209,9 +203,9 @@ class BasicProperties : InspectorInteractiveCommand() {

// update colour
val cVector = Vector3f(
colour!!.red / 255f,
colour!!.green / 255f,
colour!!.blue / 255f
color!!.red / 255f,
color!!.green / 255f,
color!!.blue / 255f
)
if(node is PointLight) {
node.emissionColor = cVector
Expand Down
3 changes: 0 additions & 3 deletions src/main/kotlin/sc/iview/commands/edit/ResetScene.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ import sc.iview.commands.MenuWeights.EDIT_RESET_SCENE
*/
@Plugin(type = Command::class, menuRoot = "SciView", menu = [Menu(label = "Edit", weight = EDIT), Menu(label = "Reset Scene", weight = EDIT_RESET_SCENE)])
class ResetScene : Command {
@Parameter
private lateinit var logService: LogService

@Parameter
private lateinit var sciView: SciView

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ import org.scijava.ui.UIService
*/
@Plugin(type = Command::class, initializer = "updateCommandFields", visible = false)
class SlicingPlaneProperties : InspectorInteractiveCommand() {
@Parameter
private lateinit var uiSrv: UIService

@Parameter
private lateinit var lutService: LUTService

/* Targets properties */
@Parameter(label = "Sliced volumes", callback = "updateNodeProperties", style = "group:Targets")
private var slicedVolumes: VolumeSelectorWidget.VolumeSelection = VolumeSelectorWidget.VolumeSelection()
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/sc/iview/commands/edit/TextBoardProperties.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class TextBoardProperties : InspectorInteractiveCommand() {
node.backgroundColor.z().toInt() * 255
)
transparentBackground = node.transparent > 0

maybeRemoveInput("color", ColorRGB::class.java)
}
}

Expand Down
16 changes: 5 additions & 11 deletions src/main/kotlin/sc/iview/commands/edit/VolumeProperties.kt
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
package sc.iview.commands.edit

import graphics.scenery.volumes.Volume
import net.imagej.lut.LUTService
import okio.withLock
import org.scijava.ItemVisibility
import org.scijava.command.Command
import org.scijava.plugin.Parameter
import org.scijava.plugin.Plugin
import org.scijava.ui.UIService
import org.scijava.widget.Button
import org.scijava.widget.ChoiceWidget
import org.scijava.widget.NumberWidget

const val PLAY_PAUSE_BUTTON_NAME = "playPause"
/**
* Inspector panel for [Volume] nodes.
*/
@Plugin(type = Command::class, initializer = "updateCommandFields", visible = false)
class VolumeProperties : InspectorInteractiveCommand() {
@Parameter
private lateinit var uiSrv: UIService

@Parameter
private lateinit var lutService: LUTService

/* Basic properties */

@Parameter(required = false, style = ChoiceWidget.LIST_BOX_STYLE, callback = "refreshSceneNodeInDialog")
Expand Down Expand Up @@ -62,6 +55,7 @@ class VolumeProperties : InspectorInteractiveCommand() {
}

/** Plays a volume time series, if the volume has more than one timepoint. */
@Suppress("unused")
fun playTimeSeries() {
if (currentSceneNode !is Volume) {
return
Expand All @@ -85,7 +79,7 @@ class VolumeProperties : InspectorInteractiveCommand() {
}
}
}
info.getMutableInput("playPauseButton", Button::class.java).label = "Pause"
info.getMutableInput(PLAY_PAUSE_BUTTON_NAME, Button::class.java).label = "Pause"
timeSeriesPlayer!!.start()
} else {
try {
Expand All @@ -94,7 +88,7 @@ class VolumeProperties : InspectorInteractiveCommand() {
e.printStackTrace()
}
timeSeriesPlayer = null
info.getMutableInput("playPauseButton", Button::class.java).setLabel("Play")
info.getMutableInput(PLAY_PAUSE_BUTTON_NAME, Button::class.java).setLabel("Play")
}
}

Expand Down Expand Up @@ -126,7 +120,7 @@ class VolumeProperties : InspectorInteractiveCommand() {
// reverts to the Kotlin types and you'll end up with interesting error messages
// like "float does not match type float" ;-)
maybeRemoveInput("timepoint", java.lang.Integer::class.java)
maybeRemoveInput("playPauseButton", Button::class.java)
maybeRemoveInput(PLAY_PAUSE_BUTTON_NAME, Button::class.java)
maybeRemoveInput("playSpeed", java.lang.Integer::class.java)
}
}
Expand Down

0 comments on commit 2418496

Please sign in to comment.