
from . import Operation

from UM.Scene.SceneNode import SceneNode

class AddSceneNodeOperation(Operation.Operation):
    def __init__(self, node, parent):
        super().__init__()
        self._node = node
        self._parent = parent

    def undo(self):
        self._node.setParent(None)

    def redo(self):
        self._node.setParent(self._parent)


from . import Operation

from UM.Scene.Selection import Selection
from UM.Scene.SceneNode import SceneNode

class AddSceneNodeOperation(Operation.Operation):
    def __init__(self, node, parent):
        super().__init__()
        self._node = node
        self._parent = parent
        self._selected = False

    def undo(self):
        self._node.setParent(None)
        self._selected = Selection.isSelected(self._node)
        if self._selected:
            Selection.remove(self._node)

    def redo(self):
        self._node.setParent(self._parent)
        if self._selected:
            Selection.add(self._node)

Undo & redo of add SceneNode now correctly set the previous selection state.
Undo & redo of add SceneNode now correctly set the previous selection state.

CURA-640

  
  from . import Operation
  
+ from UM.Scene.Selection import Selection
  from UM.Scene.SceneNode import SceneNode
  
  class AddSceneNodeOperation(Operation.Operation):
      def __init__(self, node, parent):
          super().__init__()
          self._node = node
          self._parent = parent
+         self._selected = False
  
      def undo(self):
          self._node.setParent(None)
+         self._selected = Selection.isSelected(self._node)
+         if self._selected:
+             Selection.remove(self._node)
  
      def redo(self):
          self._node.setParent(self._parent)
+         if self._selected:
+             Selection.add(self._node)
  
Undo & redo of add SceneNode now correctly set the previous selection state.
## Code Before:

from . import Operation

from UM.Scene.SceneNode import SceneNode

class AddSceneNodeOperation(Operation.Operation):
    def __init__(self, node, parent):
        super().__init__()
        self._node = node
        self._parent = parent

    def undo(self):
        self._node.setParent(None)

    def redo(self):
        self._node.setParent(self._parent)

## Instruction:
Undo & redo of add SceneNode now correctly set the previous selection state.
## Code After:

from . import Operation

from UM.Scene.Selection import Selection
from UM.Scene.SceneNode import SceneNode

class AddSceneNodeOperation(Operation.Operation):
    def __init__(self, node, parent):
        super().__init__()
        self._node = node
        self._parent = parent
        self._selected = False

    def undo(self):
        self._node.setParent(None)
        self._selected = Selection.isSelected(self._node)
        if self._selected:
            Selection.remove(self._node)

    def redo(self):
        self._node.setParent(self._parent)
        if self._selected:
            Selection.add(self._node)
