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

Adding copy and paste functions for the nodes in the scenegraph #12

Closed
wants to merge 2 commits into from
Closed
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
4 changes: 4 additions & 0 deletions src/main/java/com/ss/editor/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ public class Messages {

public static final String MODEL_NODE_TREE_ACTION_REMOVE;
public static final String MODEL_NODE_TREE_ACTION_RENAME;
public static final String MODEL_NODE_TREE_ACTION_COPY;
public static final String MODEL_NODE_TREE_ACTION_PASTE;
public static final String MODEL_NODE_TREE_ACTION_OPTIMIZE_GEOMETRY;
public static final String MODEL_NODE_TREE_ACTION_TOOLS;
public static final String MODEL_NODE_TREE_ACTION_CREATE;
Expand Down Expand Up @@ -893,6 +895,8 @@ public class Messages {

MODEL_NODE_TREE_ACTION_REMOVE = bundle.getString("ModelNodeTreeActionRemove");
MODEL_NODE_TREE_ACTION_RENAME = bundle.getString("ModelNodeTreeActionRename");
MODEL_NODE_TREE_ACTION_COPY = bundle.getString("ModelNodeTreeActionCopy");
MODEL_NODE_TREE_ACTION_PASTE = bundle.getString("ModelNodeTreeActionPaste");
MODEL_NODE_TREE_ACTION_OPTIMIZE_GEOMETRY = bundle.getString("ModelNodeTreeActionOptimizeGeometry");
MODEL_NODE_TREE_ACTION_TOOLS = bundle.getString("ModelNodeTreeActionTools");
MODEL_NODE_TREE_ACTION_CREATE = bundle.getString("ModelNodeTreeActionCreate");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
import com.ss.editor.ui.control.model.node.control.ControlTreeNode;
import com.ss.editor.ui.control.model.node.light.LightTreeNode;
import com.ss.editor.ui.control.model.tree.ModelNodeTree;
import com.ss.editor.ui.control.model.tree.action.AddUserDataAction;
import com.ss.editor.ui.control.model.tree.action.RemoveNodeAction;
import com.ss.editor.ui.control.model.tree.action.*;
import com.ss.editor.ui.control.model.tree.action.control.CreateCustomControlAction;
import com.ss.editor.ui.control.model.tree.action.control.CreateLightControlAction;
import com.ss.editor.ui.control.model.tree.action.control.CreateMotionControlAction;
Expand Down Expand Up @@ -84,6 +83,15 @@ public void fillContextMenu(@NotNull final NodeTree<?> nodeTree,
items.add(new RemoveNodeAction(nodeTree, this));
}

if(canCopy()){
items.add(new CopyNodeAction(nodeTree,this));
}

if(DataCopy.getCopySpatial() != null || DataCopy.getCopyGeom() != null){
items.add(new PasteNodeAction(nodeTree,this));
}


super.fillContextMenu(nodeTree, items);
}

Expand Down Expand Up @@ -183,6 +191,7 @@ public boolean canRemove() {
return menu;
}


/**
* Create tool menu menu.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.ss.editor.ui.control.model.tree.action;

import com.jme3.scene.Spatial;
import com.ss.editor.Messages;
import com.ss.editor.model.undo.editor.ModelChangeConsumer;
import com.ss.editor.ui.control.model.node.spatial.GeometryTreeNode;
import com.ss.editor.ui.control.model.node.spatial.NodeTreeNode;
import com.ss.editor.ui.control.tree.NodeTree;
import com.ss.editor.ui.control.tree.action.AbstractNodeAction;
import com.ss.editor.ui.control.tree.node.TreeNode;
import org.jetbrains.annotations.NotNull;

public class CopyNodeAction extends AbstractNodeAction<ModelChangeConsumer> {

public CopyNodeAction(@NotNull NodeTree<?> nodeTree, @NotNull TreeNode<?> node) {
super(nodeTree, node);
}

@NotNull
@Override
protected String getName() {
return Messages.MODEL_NODE_TREE_ACTION_COPY;
}

@Override
protected void process() {
super.process();
if(this.getNode() instanceof GeometryTreeNode)
DataCopy.setCopyGeom((GeometryTreeNode)this.getNode());
else
DataCopy.setCopySpatial((NodeTreeNode) this.getNode());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.ss.editor.ui.control.model.tree.action;


import com.ss.editor.ui.control.model.node.spatial.GeometryTreeNode;
import com.ss.editor.ui.control.model.node.spatial.NodeTreeNode;

public class DataCopy
{
private static NodeTreeNode copySpatial = null;

private static GeometryTreeNode copyGeom = null;


public static NodeTreeNode getCopySpatial() {
return copySpatial;
}

public static void setCopySpatial(NodeTreeNode copySpatial) {
DataCopy.copySpatial = copySpatial;
DataCopy.copyGeom = null;
}

public static GeometryTreeNode getCopyGeom() {
return copyGeom;
}

public static void setCopyGeom(GeometryTreeNode copyGeom) {
DataCopy.copyGeom = copyGeom;
DataCopy.copySpatial = null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.ss.editor.ui.control.model.tree.action;

import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.ss.editor.Messages;
import com.ss.editor.extension.scene.SceneLayer;
import com.ss.editor.model.undo.editor.ChangeConsumer;
import com.ss.editor.model.undo.editor.ModelChangeConsumer;
import com.ss.editor.ui.control.model.node.spatial.NodeTreeNode;
import com.ss.editor.ui.control.model.node.spatial.SpatialTreeNode;
import com.ss.editor.ui.control.model.tree.action.operation.AddChildOperation;
import com.ss.editor.ui.control.tree.NodeTree;
import com.ss.editor.ui.control.tree.action.AbstractNodeAction;
import com.ss.editor.ui.control.tree.node.TreeNode;
import org.jetbrains.annotations.NotNull;

import static com.ss.editor.util.EditorUtil.getDefaultLayer;
import static com.ss.rlib.util.ObjectUtils.notNull;

public class PasteNodeAction extends AbstractNodeAction<ModelChangeConsumer> {

public PasteNodeAction(@NotNull NodeTree<?> nodeTree, @NotNull TreeNode<?> node) {
super(nodeTree, node);
}

@NotNull
@Override
protected String getName() {
return Messages.MODEL_NODE_TREE_ACTION_PASTE;
}

@Override
protected void process() {
super.process();

if(DataCopy.getCopySpatial() != null){
final ChangeConsumer consumer = notNull(this.getNodeTree().getChangeConsumer());
consumer.execute(new AddChildOperation(((Spatial)DataCopy.getCopySpatial().getElement()).clone(),(Node)this.getNode().getElement()));
}
else{
final ChangeConsumer consumer = notNull(this.getNodeTree().getChangeConsumer());
consumer.execute(new AddChildOperation(((Geometry)DataCopy.getCopyGeom().getElement()).clone(),(Node)this.getNode().getElement()));
}



}
}
2 changes: 2 additions & 0 deletions src/main/resources/messages/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ SceneFileEditorToolLayers=Layers

ModelNodeTreeActionRemove=Remove
ModelNodeTreeActionRename=Rename
ModelNodeTreeActionCopy=Copy Node
ModelNodeTreeActionPaste=Paste Node
ModelNodeTreeActionOptimizeGeometry=Optimize geometry
ModelNodeTreeActionTools=Tools
ModelNodeTreeActionCreate=Create
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.ss.editor.ui.control.model.tree.action

class DataCopyTest extends GroovyTestCase {
}