Ejemplo n.º 1
0
class SelectionTool(EditorTool):
    name = "Select"
    iconName = "select_blocks"

    def __init__(self, editorSession, *args, **kwargs):
        """
        :type editorSession: EditorSession
        """
        super(SelectionTool, self).__init__(editorSession, *args, **kwargs)
        toolWidget = QtGui.QWidget()

        editorSession.selectionChanged.connect(self.selectionDidChange)

        self.toolWidget = toolWidget

        self.optionsButton = QtGui.QPushButton(self.tr("Options"))

        self.optionsMenu = QtGui.QMenu()
        self.optionsButton.setMenu(self.optionsMenu)

        classicSelectionAction = self.optionsMenu.addAction(
            self.tr("Classic Selection"))
        stickySelectionAction = self.optionsMenu.addAction(
            self.tr("Sticky Selection"))

        self.coordInput = SelectionCoordinateWidget()
        self.coordInput.boxChanged.connect(self.coordInputChanged)
        self.shapeInput = ShapeWidget(addShapes=[ChunkShape()])
        self.shapeInput.shapeChanged.connect(self.shapeDidChange)
        self.shapeInput.shapeOptionsChanged.connect(self.shapeDidChange)

        self.toolWidget.setLayout(
            Column(self.optionsButton, self.coordInput, self.shapeInput, None))

        self.cursorNode = SelectionCursor()
        self.overlayNode = scenenode.Node("selectOverlay")
        self.faceHoverNode = SelectionFaceNode()
        self.selectionNode = SelectionScene()
        self.overlayNode.addChild(self.selectionNode)
        self.overlayNode.addChild(self.faceHoverNode)

        self.boxHandleNode = BoxHandle()
        self.boxHandleNode.boundsChanged.connect(self.boxHandleResized)
        self.boxHandleNode.boundsChangedDone.connect(self.boxHandleResizedDone)
        self.overlayNode.addChild(self.boxHandleNode)

        self.newSelectionNode = None

        classicSelectionAction.setCheckable(True)
        classicSelectionAction.toggled.connect(ClassicSelectionOption.setValue)
        classicSelectionAction.setChecked(ClassicSelectionOption.value())
        ClassicSelectionOption.connectAndCall(self.setClassicSelection)

        stickySelectionAction.setCheckable(True)
        stickySelectionAction.toggled.connect(StickySelectionOption.setValue)
        stickySelectionAction.setChecked(StickySelectionOption.value())
        StickySelectionOption.connectAndCall(self.setStickySelection)

        editorSession.dimensionChanged.connect(self.dimensionDidChange)
        editorSession.revisionChanged.connect(self.revisionDidChange)

    def revisionDidChange(self, changes):
        chunks = changes.chunks[self.editorSession.currentDimension.dimName]
        for cx, cz in chunks:
            self.selectionNode.discardChunk(cx, cz)

    def dimensionDidChange(self):
        self.selectionNode.dimension = self.editorSession.currentDimension

    def shapeDidChange(self):
        if self.currentSelection is not None:
            self.currentSelection = self.createShapedSelection(
                self.currentSelection)

    def toolActive(self):
        self.boxHandleNode.boxNode.wireColor = 1, 1, 1, .5

    def toolInactive(self):
        self.faceHoverNode.visible = False
        self.boxHandleNode.boxNode.wireColor = 1, 1, 1, .33

    @property
    def hideSelectionWalls(self):
        return not self.selectionNode.filled

    @hideSelectionWalls.setter
    def hideSelectionWalls(self, value):
        self.selectionNode.filled = not value

    @property
    def currentSelection(self):
        return self.editorSession.currentSelection

    @currentSelection.setter
    def currentSelection(self, value):
        self.editorSession.currentSelection = value

    def coordInputChanged(self, box):
        self.currentSelection = self.createShapedSelection(box)

    def selectionDidChange(self, value):
        self.coordInput.boundingBox = value
        self.updateNodes()

    def updateNodes(self):
        box = self.currentSelection
        if box:
            self.boxHandleNode.bounds = BoundingBox(box.origin, box.size)
            self.selectionNode.visible = True
            self.selectionNode.selection = box
        else:
            self.boxHandleNode.bounds = None
            self.selectionNode.visible = False
            self.faceHoverNode.visible = False
            self.selectionNode.selection = None

    lastResizeTime = time.time()

    def boxHandleResized(self, box):
        if box is not None:
            self.selectionNode.selection = self.createShapedSelection(box)
            if time.time() - self.lastResizeTime > 0.025:
                self.selectionNode.loadImmediateChunks(0.025)
            self.lastResizeTime = time.time()
        else:
            self.selectionNode.selection = None

    def boxHandleResizedDone(self, box, oldBox):
        if box is not None:
            selection = self.createShapedSelection(box)
            command = SelectCommand(self.editorSession, selection)
            if oldBox is not None:
                command.setText(self.tr("Resize Selection"))
            self.editorSession.pushCommand(command)
            self.updateNodes()
            self.selectionNode.loadImmediateChunks()
        else:
            self.selectionNode.selection = None

    def mousePress(self, event):
        self.boxHandleNode.mousePress(event)

    def mouseMove(self, event):
        self.mouseDrag(event)

    def mouseDrag(self, event):
        # Update cursor
        self.cursorNode.point = event.blockPosition
        self.cursorNode.face = event.blockFace

        self.boxHandleNode.mouseMove(event)

    def mouseRelease(self, event):
        self.boxHandleNode.mouseRelease(event)

    selectionColor = (0.8, 0.8, 1.0)
    alpha = 0.33

    showPreviousSelection = True

    def createShapedSelection(self, box):
        return self.shapeInput.currentShape.createShapedSelection(
            box, self.editorSession.currentDimension)

    def setClassicSelection(self, enabled):
        self.boxHandleNode.classicSelection = enabled

    def setStickySelection(self, enabled):
        self.boxHandleNode.stickySelection = enabled
Ejemplo n.º 2
0
class SelectionTool(EditorTool):
    name = "Select"
    iconName = "select_blocks"

    def __init__(self, editorSession, *args, **kwargs):
        """
        :type editorSession: EditorSession
        """
        super(SelectionTool, self).__init__(editorSession, *args, **kwargs)
        toolWidget = QtGui.QWidget()

        editorSession.selectionChanged.connect(self.selectionDidChange)

        self.toolWidget = toolWidget

        self.coordInput = SelectionCoordinateWidget()
        self.coordInput.boxChanged.connect(self.coordInputChanged)
        self.shapeInput = ShapeWidget(addShapes=[ChunkShape()])
        self.shapeInput.shapeChanged.connect(self.shapeDidChange)
        self.shapeInput.shapeOptionsChanged.connect(self.shapeDidChange)

        self.toolWidget.setLayout(Column(self.coordInput,
                                         self.shapeInput,
                                         None))

        self.cursorNode = SelectionCursor()
        self.overlayNode = scenenode.Node()
        self.faceHoverNode = SelectionFaceNode()
        self.selectionNode = SelectionScene()
        self.overlayNode.addChild(self.selectionNode)
        self.overlayNode.addChild(self.faceHoverNode)

        self.boxHandleNode = BoxHandle()
        self.boxHandleNode.boundsChanged.connect(self.boxHandleResized)
        self.boxHandleNode.boundsChangedDone.connect(self.boxHandleResizedDone)
        self.overlayNode.addChild(self.boxHandleNode)

        self.newSelectionNode = None

        editorSession.dimensionChanged.connect(self.dimensionDidChange)
        editorSession.revisionChanged.connect(self.revisionDidChange)

    def revisionDidChange(self, changes):
        chunks = changes.chunks[self.editorSession.currentDimension.dimName]
        for cx, cz in chunks:
            self.selectionNode.discardChunk(cx, cz)

    def dimensionDidChange(self):
        self.selectionNode.dimension = self.editorSession.currentDimension

    def shapeDidChange(self):
        if self.currentSelection is not None:
            self.currentSelection = self.createShapedSelection(self.currentSelection)

    def toolActive(self):
        self.boxHandleNode.boxNode.wireColor = 1, 1, 1, .5

    def toolInactive(self):
        self.faceHoverNode.visible = False
        self.boxHandleNode.boxNode.wireColor = 1, 1, 1, .33

    @property
    def hideSelectionWalls(self):
        return not self.selectionNode.filled

    @hideSelectionWalls.setter
    def hideSelectionWalls(self, value):
        self.selectionNode.filled = not value

    @property
    def currentSelection(self):
        return self.editorSession.currentSelection

    @currentSelection.setter
    def currentSelection(self, value):
        self.editorSession.currentSelection = value

    def coordInputChanged(self, box):
        self.currentSelection = self.createShapedSelection(box)

    def selectionDidChange(self, value):
        self.coordInput.boundingBox = value
        self.updateNodes()

    def updateNodes(self):
        box = self.currentSelection
        if box:
            self.boxHandleNode.bounds = BoundingBox(box.origin, box.size)
            self.selectionNode.visible = True
            self.selectionNode.selection = box
        else:
            self.boxHandleNode.bounds = None
            self.selectionNode.visible = False
            self.faceHoverNode.visible = False

    lastResizeTime = time.time()

    def boxHandleResized(self, box):
        if box is not None:
            self.selectionNode.selection = self.createShapedSelection(box)
            if time.time() - self.lastResizeTime > 0.025:
                self.selectionNode.loadImmediateChunks(0.025)
            self.lastResizeTime = time.time()

    def boxHandleResizedDone(self, box, oldBox):
        if box is not None:
            selection = self.createShapedSelection(box)
            command = SelectCommand(self.editorSession, selection)
            if oldBox is not None:
                command.setText(self.tr("Resize Selection"))
            self.editorSession.undoStack.push(command)
            self.updateNodes()
            self.selectionNode.loadImmediateChunks()

    def mousePress(self, event):
        self.boxHandleNode.mousePress(event)

    def mouseMove(self, event):
        self.mouseDrag(event)

    def mouseDrag(self, event):
        # Update cursor
        self.cursorNode.point = event.blockPosition
        self.cursorNode.face = event.blockFace

        self.boxHandleNode.mouseMove(event)

    def mouseRelease(self, event):
        self.boxHandleNode.mouseRelease(event)

    selectionColor = (0.8, 0.8, 1.0)
    alpha = 0.33

    showPreviousSelection = True

    def createShapedSelection(self, box):
        return self.shapeInput.currentShape.createShapedSelection(box, self.editorSession.currentDimension)
Ejemplo n.º 3
0
class SelectionTool(EditorTool):
    name = "Select"
    iconName = "select_blocks"

    def __init__(self, editorSession, *args, **kwargs):
        """
        :type editorSession: EditorSession
        """
        super(SelectionTool, self).__init__(editorSession, *args, **kwargs)
        toolWidget = QtGui.QWidget()

        editorSession.selectionChanged.connect(self.selectionDidChange)

        self.toolWidget = toolWidget

        self.coordInput = SelectionCoordinateWidget()
        self.coordInput.boxChanged.connect(self.coordInputChanged)
        self.shapeInput = ShapeWidget(addShapes=[ChunkShape()])
        self.shapeInput.shapeChanged.connect(self.shapeDidChange)
        self.shapeInput.shapeOptionsChanged.connect(self.shapeDidChange)

        self.toolWidget.setLayout(
            Column(self.coordInput, self.shapeInput, None))

        self.cursorNode = SelectionCursor()
        self.overlayNode = scenegraph.Node()
        self.faceHoverNode = SelectionFaceNode()
        self.selectionNode = SelectionScene()
        self.overlayNode.addChild(self.selectionNode)
        self.overlayNode.addChild(self.faceHoverNode)

        self.boxHandleNode = BoxHandle()
        self.boxHandleNode.boundsChanged.connect(self.boxHandleResized)
        self.boxHandleNode.boundsChangedDone.connect(self.boxHandleResizedDone)
        self.overlayNode.addChild(self.boxHandleNode)

        self.newSelectionNode = None

        editorSession.dimensionChanged.connect(self.dimensionDidChange)
        editorSession.revisionChanged.connect(self.revisionDidChange)

    def revisionDidChange(self, changes):
        chunks = changes.chunks[self.editorSession.currentDimension.dimName]
        for cx, cz in chunks:
            self.selectionNode.discardChunk(cx, cz)

    def dimensionDidChange(self):
        self.selectionNode.dimension = self.editorSession.currentDimension

    def shapeDidChange(self):
        if self.currentSelection is not None:
            self.currentSelection = self.createShapedSelection(
                self.currentSelection)

    def toolActive(self):
        self.boxHandleNode.boxNode.wireColor = 1, 1, 1, .5

    def toolInactive(self):
        self.faceHoverNode.visible = False
        self.boxHandleNode.boxNode.wireColor = 1, 1, 1, .33

    @property
    def hideSelectionWalls(self):
        return not self.selectionNode.filled

    @hideSelectionWalls.setter
    def hideSelectionWalls(self, value):
        self.selectionNode.filled = not value

    @property
    def currentSelection(self):
        return self.editorSession.currentSelection

    @currentSelection.setter
    def currentSelection(self, value):
        self.editorSession.currentSelection = value

    def coordInputChanged(self, box):
        self.currentSelection = self.createShapedSelection(box)

    def selectionDidChange(self, value):
        self.coordInput.boundingBox = value
        self.updateNodes()

    def updateNodes(self):
        box = self.currentSelection
        if box:
            self.boxHandleNode.bounds = BoundingBox(box.origin, box.size)
            self.selectionNode.visible = True
            self.selectionNode.selection = box
        else:
            self.boxHandleNode.bounds = None
            self.selectionNode.visible = False
            self.faceHoverNode.visible = False

    def boxHandleResized(self, box):
        if box is not None:
            self.selectionNode.selection = self.createShapedSelection(box)

    def boxHandleResizedDone(self, box, newSelection):
        if box is not None:
            selection = self.createShapedSelection(box)
            command = SelectCommand(self.editorSession, selection)
            if not newSelection:
                command.setText(self.tr("Resize Selection"))
            self.editorSession.undoStack.push(command)
            self.updateNodes()

    def mousePress(self, event):
        self.boxHandleNode.mousePress(event)

    def mouseMove(self, event):
        self.mouseDrag(event)

    def mouseDrag(self, event):
        # Update cursor
        self.cursorNode.point = event.blockPosition
        self.cursorNode.face = event.blockFace

        self.boxHandleNode.mouseMove(event)

    def mouseRelease(self, event):
        self.boxHandleNode.mouseRelease(event)

    selectionColor = (0.8, 0.8, 1.0)
    alpha = 0.33

    showPreviousSelection = True

    def createShapedSelection(self, box):
        return self.shapeInput.currentShape.createShapedSelection(
            box, self.editorSession.currentDimension)