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:
parent
555b316c2f
commit
66747461b5
@ -60,17 +60,19 @@ currentViewSetting = sessionSettings.getOption("currentview", unicode, "cam")
|
|||||||
# chunks into its viewports.
|
# chunks into its viewports.
|
||||||
|
|
||||||
class PendingImport(object):
|
class PendingImport(object):
|
||||||
def __init__(self, schematic, pos, text):
|
def __init__(self, sourceDim, pos, selection, text):
|
||||||
|
self.selection = selection
|
||||||
self.text = text
|
self.text = text
|
||||||
self.pos = pos
|
self.pos = pos
|
||||||
self.schematic = schematic
|
self.sourceDim = sourceDim
|
||||||
|
|
||||||
def __repr__(self):
|
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
|
@property
|
||||||
def bounds(self):
|
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):
|
class PasteImportCommand(QtGui.QUndoCommand):
|
||||||
@ -615,7 +617,8 @@ class EditorSession(QtCore.QObject):
|
|||||||
if self.copiedSchematic is None:
|
if self.copiedSchematic is None:
|
||||||
return
|
return
|
||||||
view = self.editorTab.currentView()
|
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")
|
command = PasteImportCommand(self, imp, "Paste")
|
||||||
self.undoStack.push(command)
|
self.undoStack.push(command)
|
||||||
|
|
||||||
@ -808,7 +811,8 @@ class EditorSession(QtCore.QObject):
|
|||||||
pos = ray.point
|
pos = ray.point
|
||||||
|
|
||||||
name = os.path.basename(filename)
|
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)
|
command = PasteImportCommand(self, imp, "Import %s" % name)
|
||||||
self.undoStack.push(command)
|
self.undoStack.push(command)
|
||||||
|
|
||||||
|
@ -126,22 +126,28 @@ class PendingImportNode(TranslateNode):
|
|||||||
self.pendingImport = pendingImport
|
self.pendingImport = pendingImport
|
||||||
self.pos = pendingImport.pos
|
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.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 = SelectionBoxNode()
|
||||||
self.outlineNode.filled = False
|
self.outlineNode.filled = False
|
||||||
self.outlineNode.selectionBox = dim.bounds
|
self.outlineNode.selectionBox = box
|
||||||
self.addChild(self.outlineNode)
|
self.addChild(self.outlineNode)
|
||||||
|
|
||||||
self.faceHoverNode = SelectionFaceNode()
|
self.faceHoverNode = SelectionFaceNode()
|
||||||
self.faceHoverNode.selectionBox = dim.bounds
|
self.faceHoverNode.selectionBox = box
|
||||||
self.addChild(self.faceHoverNode)
|
self.addChild(self.faceHoverNode)
|
||||||
|
|
||||||
self.loader = WorldLoader(self.worldScene)
|
self.loader = WorldLoader(self.worldScene,
|
||||||
|
list(pendingImport.selection.chunkPositions()))
|
||||||
self.loader.timer.start()
|
self.loader.timer.start()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -216,6 +222,7 @@ class MoveTool(EditorTool):
|
|||||||
# --- Pending imports ---
|
# --- Pending imports ---
|
||||||
|
|
||||||
def addPendingImport(self, pendingImport):
|
def addPendingImport(self, pendingImport):
|
||||||
|
log.info("Added import: %s", pendingImport)
|
||||||
self.pendingImports.append(pendingImport)
|
self.pendingImports.append(pendingImport)
|
||||||
item = QtGui.QStandardItem()
|
item = QtGui.QStandardItem()
|
||||||
item.setEditable(False)
|
item.setEditable(False)
|
||||||
@ -270,7 +277,7 @@ class MoveTool(EditorTool):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def schematicBox(self):
|
def schematicBox(self):
|
||||||
box = self.currentImport.schematic.getDimension().bounds
|
box = self.currentImport.selection
|
||||||
return BoundingBox(self.movePosition, box.size)
|
return BoundingBox(self.movePosition, box.size)
|
||||||
|
|
||||||
# --- Mouse events ---
|
# --- Mouse events ---
|
||||||
@ -310,13 +317,6 @@ class MoveTool(EditorTool):
|
|||||||
self.movePosition = self.dragStartMovePosition + map(int, delta)
|
self.movePosition = self.dragStartMovePosition + map(int, delta)
|
||||||
|
|
||||||
def mousePress(self, event):
|
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:
|
if self.currentImport is not None:
|
||||||
point, face = boxFaceUnderCursor(self.schematicBox, event.ray)
|
point, face = boxFaceUnderCursor(self.schematicBox, event.ray)
|
||||||
self.dragStartFace = face
|
self.dragStartFace = face
|
||||||
@ -333,19 +333,16 @@ class MoveTool(EditorTool):
|
|||||||
def toolActive(self):
|
def toolActive(self):
|
||||||
self.editorSession.selectionTool.hideSelectionWalls = True
|
self.editorSession.selectionTool.hideSelectionWalls = True
|
||||||
if self.currentImport is None:
|
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:
|
if self.editorSession.currentSelection is None:
|
||||||
return
|
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():
|
# This makes a reference to the latest revision in the editor.
|
||||||
fill = self.editorSession.currentDimension.fillBlocksIter(self.editorSession.currentSelection, "air")
|
# If the moved area is changed between "Move" and "Confirm", the changed
|
||||||
showProgress("Clearing...", fill)
|
# 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)
|
self.editorSession.pushCommand(moveCommand)
|
||||||
|
|
||||||
@ -362,7 +359,14 @@ class MoveTool(EditorTool):
|
|||||||
command = MoveFinishCommand(self, self.currentImport)
|
command = MoveFinishCommand(self, self.currentImport)
|
||||||
|
|
||||||
with command.begin():
|
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)
|
showProgress(self.tr("Pasting..."), task)
|
||||||
|
|
||||||
self.editorSession.pushCommand(command)
|
self.editorSession.pushCommand(command)
|
||||||
|
Reference in New Issue
Block a user