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

Del key and add commands #492

Merged
merged 5 commits into from
Jun 15, 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
2 changes: 1 addition & 1 deletion src/main/java/sc/iview/commands/edit/DeleteObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class DeleteObject implements Command {
@Override
public void run() {
if( sciView.getActiveNode() != null ) {
sciView.deleteActiveNode();
sciView.deleteActiveNode(false);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/sc/iview/Controls.kt
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ open class Controls(val sciview: SciView) {
h.addKeyBinding("node: move selected one closer or further away", "ctrl scroll")
h.addBehaviour("node: rotate selected one", NodeRotateControl(sciview))
h.addKeyBinding("node: rotate selected one", "ctrl shift button1")
h.addBehaviour("node: delete selected one", ClickBehaviour { _, _ -> sciview.deleteActiveNode(true) })
h.addKeyBinding("node: delete selected one", "DELETE")


// within-scene navigation: ArcBall and FPS
enableArcBallControl()
Expand Down
32 changes: 25 additions & 7 deletions src/main/kotlin/sc/iview/SciView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ import java.util.function.Consumer
import java.util.function.Function
import java.util.function.Predicate
import java.util.stream.Collectors
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
import javax.swing.JOptionPane
import kotlin.math.cos
import kotlin.math.sin

Expand Down Expand Up @@ -644,10 +643,14 @@ class SciView : SceneryBase, CalibratedRealInterval<CalibratedAxis> {
* @param num_segments number of segments to represent the cylinder
* @return the Node corresponding to the cylinder
*/
@JvmOverloads
fun addCylinder(position: Vector3f, radius: Float, height: Float, num_segments: Int, block: Cylinder.() -> Unit = {}): Cylinder {
fun addCylinder(position: Vector3f, radius: Float, height: Float, color: ColorRGB = DEFAULT_COLOR, num_segments: Int, block: Cylinder.() -> Unit = {}): Cylinder {
val cyl = Cylinder(radius, height, num_segments)
cyl.spatial().position = position
cyl.material {
ambient = Vector3f(1.0f, 0.0f, 0.0f)
diffuse = Utils.convertToVector3f(color)
specular = Vector3f(1.0f, 1.0f, 1.0f)
}
cyl.name = generateUniqueName("Cylinder")
return addNode(cyl, block = block)
}
Expand All @@ -660,10 +663,14 @@ class SciView : SceneryBase, CalibratedRealInterval<CalibratedAxis> {
* @param num_segments number of segments used to represent cone
* @return the Node corresponding to the cone
*/
@JvmOverloads
fun addCone(position: Vector3f, radius: Float, height: Float, num_segments: Int, block: Cone.() -> Unit = {}): Cone {
fun addCone(position: Vector3f, radius: Float, height: Float, color: ColorRGB = DEFAULT_COLOR, num_segments: Int, block: Cone.() -> Unit = {}): Cone {
val cone = Cone(radius, height, num_segments, Vector3f(0.0f, 0.0f, 1.0f))
cone.spatial().position = position
cone.material {
ambient = Vector3f(1.0f, 0.0f, 0.0f)
diffuse = Utils.convertToVector3f(color)
specular = Vector3f(1.0f, 1.0f, 1.0f)
}
cone.name = generateUniqueName("Cone")
return addNode(cone, block = block)
}
Expand Down Expand Up @@ -1122,7 +1129,18 @@ class SciView : SceneryBase, CalibratedRealInterval<CalibratedAxis> {
/**
* Delete the current active node
*/
fun deleteActiveNode() {
fun deleteActiveNode(askUser: Boolean = false) {
if(askUser && activeNode != null){
val options = arrayOf("Cancel", "Delete ${activeNode!!.name}")
val x = JOptionPane.showOptionDialog(
null, "Please confirm delete of ${activeNode!!.name}? ",
"Delete confirm",
JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[1]
)
if (x == 0){
return
}
}
deleteNode(activeNode)
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/sc/iview/commands/MenuWeights.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ object MenuWeights {
// Edit/Add
const val EDIT_ADD_BOX = 0.0
const val EDIT_ADD_SPHERE = 1.0
const val EDIT_ADD_CYLINDER = 1.3
const val EDIT_ADD_CONE = 1.6
const val EDIT_ADD_LINE = 2.0
const val EDIT_ADD_POINTLIGHT = 3.0
const val EDIT_ADD_LABELIMAGE = 4.0
Expand Down
80 changes: 80 additions & 0 deletions src/main/kotlin/sc/iview/commands/edit/add/AddCone.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*-
* #%L
* Scenery-backed 3D visualization package for ImageJ.
* %%
* Copyright (C) 2016 - 2021 SciView developers.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* #L%
*/
package sc.iview.commands.edit.add

import org.joml.Vector3f
import org.scijava.command.Command
import org.scijava.plugin.Menu
import org.scijava.plugin.Parameter
import org.scijava.plugin.Plugin
import org.scijava.util.ColorRGB
import sc.iview.SciView
import sc.iview.commands.MenuWeights.EDIT
import sc.iview.commands.MenuWeights.EDIT_ADD
import sc.iview.commands.MenuWeights.EDIT_ADD_CONE
import sc.iview.commands.MenuWeights.EDIT_ADD_CYLINDER

/**
* Command to add a box to the scene
*
* @author Jan Tiemann
*/
@Plugin(
type = Command::class,
menuRoot = "SciView",
menu = [Menu(label = "Edit", weight = EDIT), Menu(label = "Add", weight = EDIT_ADD), Menu(
label = "Cone...",
weight = EDIT_ADD_CONE
)]
)
class AddCone : Command {

@Parameter
private lateinit var sciView: SciView

// FIXME
// @Parameter
// private String position = "0; 0; 0";

@Parameter
private var height = 1.0f

@Parameter
private var radius = 1.0f

@Parameter
private var color: ColorRGB = SciView.DEFAULT_COLOR;

override fun run() {
//final Vector3 pos = ClearGLVector3.parse( position );
val pos = Vector3f(0f, 0f, 0f)

sciView.addCone(pos,radius,height,color,20)
}
}
80 changes: 80 additions & 0 deletions src/main/kotlin/sc/iview/commands/edit/add/AddCylinder.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*-
* #%L
* Scenery-backed 3D visualization package for ImageJ.
* %%
* Copyright (C) 2016 - 2021 SciView developers.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* #L%
*/
package sc.iview.commands.edit.add

import org.joml.Vector3f
import org.scijava.command.Command
import org.scijava.plugin.Menu
import org.scijava.plugin.Parameter
import org.scijava.plugin.Plugin
import org.scijava.util.ColorRGB
import sc.iview.SciView
import sc.iview.Utils
import sc.iview.commands.MenuWeights.EDIT
import sc.iview.commands.MenuWeights.EDIT_ADD
import sc.iview.commands.MenuWeights.EDIT_ADD_CYLINDER

/**
* Command to add a box to the scene
*
* @author Jan Tiemann
*/
@Plugin(
type = Command::class,
menuRoot = "SciView",
menu = [Menu(label = "Edit", weight = EDIT), Menu(label = "Add", weight = EDIT_ADD), Menu(
label = "Cylinder...",
weight = EDIT_ADD_CYLINDER
)]
)
class AddCylinder : Command {

@Parameter
private lateinit var sciView: SciView

// FIXME
// @Parameter
// private String position = "0; 0; 0";

@Parameter
private var height = 1.0f

@Parameter
private var radius = 1.0f

@Parameter
private var color: ColorRGB = SciView.DEFAULT_COLOR;

override fun run() {
//final Vector3 pos = ClearGLVector3.parse( position );
val pos = Vector3f(0f, 0f, 0f)

sciView.addCylinder(pos,radius,height,color,20)
}
}
Loading