Move tool no longer makes a copy immediately.

Now it creates a reference to the area to be moved and renders that instead.
This commit is contained in:
David Vierra 2015-09-08 10:34:13 -10:00
parent 555b316c2f
commit 66747461b5
2 changed files with 39 additions and 31 deletions

View File

@ -60,17 +60,19 @@ currentViewSetting = sessionSettings.getOption("currentview", unicode, "cam")
# chunks into its viewports.
class PendingImport(object):
def __init__(self, schematic, pos, text):
def __init__(self, sourceDim, pos, selection, text):
self.selection = selection
self.text = text
self.pos = pos
self.schematic = schematic
self.sourceDim = sourceDim
def __repr__(self):
return "%s(%r, %r)" % (self.__class__.__name__, self.schematic, self.pos)
return "%s(%r, %r, %r)" % (self.__class__.__name__, self.sourceDim, self.selection, self.pos)
@property
def bounds(self):
return BoundingBox(self.pos, self.schematic.getDimension().bounds.size)
return BoundingBox(self.pos, self.selection.size)
#return BoundingBox(self.pos, self.sourceDim.bounds.size)
class PasteImportCommand(QtGui.QUndoCommand):
@ -615,7 +617,8 @@ class EditorSession(QtCore.QObject):
if self.copiedSchematic is None:
return
view = self.editorTab.currentView()
imp = PendingImport(self.copiedSchematic, view.mouseBlockPos, self.tr("<Pasted Object>"))
dim = self.copiedSchematic.getDimension()
imp = PendingImport(dim, view.mouseBlockPos, dim.bounds, self.tr("<Pasted Object>"))
command = PasteImportCommand(self, imp, "Paste")
self.undoStack.push(command)
@ -808,7 +811,8 @@ class EditorSession(QtCore.QObject):
pos = ray.point
name = os.path.basename(filename)
imp = PendingImport(schematic, pos, name)
dim = schematic.getDimension()
imp = PendingImport(schematic.getDimension(), pos, dim.bounds, name)
command = PasteImportCommand(self, imp, "Import %s" % name)
self.undoStack.push(command)

View File

@ -126,22 +126,28 @@ class PendingImportNode(TranslateNode):
self.pendingImport = pendingImport
self.pos = pendingImport.pos
dim = pendingImport.schematic.getDimension()
dim = pendingImport.sourceDim
self.worldScene = WorldScene(dim, textureAtlas)
self.worldSceneTranslateNode = TranslateNode()
self.worldScene = WorldScene(dim, textureAtlas, bounds=pendingImport.selection)
self.worldScene.depthOffsetNode.depthOffset = DepthOffset.PreviewRenderer
self.addChild(self.worldScene)
self.worldSceneTranslateNode.translateOffset = -self.pendingImport.selection.origin
self.worldSceneTranslateNode.addChild(self.worldScene)
self.addChild(self.worldSceneTranslateNode)
box = BoundingBox((0, 0, 0), pendingImport.bounds.size)
self.outlineNode = SelectionBoxNode()
self.outlineNode.filled = False
self.outlineNode.selectionBox = dim.bounds
self.outlineNode.selectionBox = box
self.addChild(self.outlineNode)
self.faceHoverNode = SelectionFaceNode()
self.faceHoverNode.selectionBox = dim.bounds
self.faceHoverNode.selectionBox = box
self.addChild(self.faceHoverNode)
self.loader = WorldLoader(self.worldScene)
self.loader = WorldLoader(self.worldScene,
list(pendingImport.selection.chunkPositions()))
self.loader.timer.start()
@property
@ -216,6 +222,7 @@ class MoveTool(EditorTool):
# --- Pending imports ---
def addPendingImport(self, pendingImport):
log.info("Added import: %s", pendingImport)
self.pendingImports.append(pendingImport)
item = QtGui.QStandardItem()
item.setEditable(False)
@ -270,7 +277,7 @@ class MoveTool(EditorTool):
@property
def schematicBox(self):
box = self.currentImport.schematic.getDimension().bounds
box = self.currentImport.selection
return BoundingBox(self.movePosition, box.size)
# --- Mouse events ---
@ -310,13 +317,6 @@ class MoveTool(EditorTool):
self.movePosition = self.dragStartMovePosition + map(int, delta)
def mousePress(self, event):
# Record which face/axis was clicked for mouseDrag. Store current revision # in MoveCommand, begin undo
# revision, cut selection from world, end undo revision, create overlay node for pasted selection
# Inform EditorSession that a multi-step undo is being recorded and give it a callback to use when something
# else tries to call beginUndo before we're done - call it an "undo block"
# begin drag
if self.currentImport is not None:
point, face = boxFaceUnderCursor(self.schematicBox, event.ray)
self.dragStartFace = face
@ -333,19 +333,16 @@ class MoveTool(EditorTool):
def toolActive(self):
self.editorSession.selectionTool.hideSelectionWalls = True
if self.currentImport is None:
# Need to cut out selection
# xxxx for huge selections, don't cut, just do everything at the end?
if self.editorSession.currentSelection is None:
return
export = self.editorSession.currentDimension.exportSchematicIter(self.editorSession.currentSelection)
schematic = showProgress("Copying...", export)
pos = self.editorSession.currentSelection.origin
pendingImport = PendingImport(schematic, pos, self.tr("<Moved Object>"))
moveCommand = MoveSelectionCommand(self, pendingImport)
with moveCommand.begin():
fill = self.editorSession.currentDimension.fillBlocksIter(self.editorSession.currentSelection, "air")
showProgress("Clearing...", fill)
# This makes a reference to the latest revision in the editor.
# If the moved area is changed between "Move" and "Confirm", the changed
# blocks will be moved.
pos = self.editorSession.currentSelection.origin
pendingImport = PendingImport(self.editorSession.currentDimension, pos,
self.editorSession.currentSelection, self.tr("<Moved Object>"))
moveCommand = MoveSelectionCommand(self, pendingImport)
self.editorSession.pushCommand(moveCommand)
@ -362,7 +359,14 @@ class MoveTool(EditorTool):
command = MoveFinishCommand(self, self.currentImport)
with command.begin():
task = self.editorSession.currentDimension.importSchematicIter(self.currentImport.schematic, self.currentImport.pos)
# TODO don't use intermediate schematic...
export = self.currentImport.sourceDim.exportSchematicIter(self.currentImport.selection)
schematic = showProgress("Copying...", export)
fill = self.editorSession.currentDimension.fillBlocksIter(self.editorSession.currentSelection, "air")
showProgress("Clearing...", fill)
task = self.editorSession.currentDimension.importSchematicIter(schematic, self.currentImport.pos)
showProgress(self.tr("Pasting..."), task)
self.editorSession.pushCommand(command)