def mousePressEvent(self, event): ''' Inform the scene viewer of a mouse press event. ''' self._handle_mouse_events = False # Track when the zinc should be handling mouse events if not self._ignore_mouse_events and (event.modifiers() & self._editModifier) and \ (self._nodeEditMode or self._nodeEditVectorMode or self._nodeCreateMode) and \ button_map[event.button()] == Sceneviewerinput.BUTTON_TYPE_LEFT: return_code, selectedNode, selectedCoordinateField, selectedGraphics = \ self.nodeIsSelectedAtCoordinates(event.x(), event.y()) if return_code: self._nodeEditInfo._node = selectedNode self._nodeEditInfo._coordinateField = selectedCoordinateField self._nodeEditInfo._graphics = selectedGraphics self._selection_position_start = (event.x(), event.y()) if self._nodeEditMode: self._selection_mode = SelectionMode.EDIT_POSITION else: attributes = self._nodeEditInfo._graphics.getGraphicspointattributes() if attributes.isValid(): self._nodeEditInfo._orientationField = attributes.getOrientationScaleField() if self._nodeEditInfo._orientationField and self._nodeEditInfo._orientationField.isValid(): self._selection_mode = SelectionMode.EDIT_VECTOR return_code, self._nodeEditInfo._glyphCentre = attributes.getGlyphOffset(3) return_code, self._nodeEditInfo._glyphSize = attributes.getBaseSize(3) return_code, self._nodeEditInfo._glyphScaleFactors = attributes.getScaleFactors(3) self._nodeEditInfo._variableScaleField = attributes.getSignedScaleField() elif self._nodeCreateMode: self._selection_mode = SelectionMode.CREATE else: SelectionSceneviewerWidget.mousePressEvent(self, event)
def mouseReleaseEvent(self, event): ''' Inform the scene viewer of a mouse release event. ''' if not self._ignore_mouse_events and (self._selection_mode == SelectionMode.EDIT_POSITION or \ self._selection_mode == SelectionMode.EDIT_VECTOR): self._nodeEditInfo.reset() elif not self._ignore_mouse_events and self._selection_mode == SelectionMode.CREATE: x = event.x() y = event.y() self._selection_box.setVisibilityFlag(False) if self._createCoordinatesField and self._createCoordinatesField.isValid( ): self._nodeEditInfo._createCoordinatesField = self._createCoordinatesField if self._nodeConstrainMode == True: returnCode, self._nodeEditInfo._nearestElement, self._nodeEditInfo._elementCoordinateField = \ self.getNearestSurfacesElementAndCoordinates(x, y) if self._nodeEditInfo._nearestElement and self._nodeEditInfo._elementCoordinateField: self.createNodeAtCoordinates(self._nodeEditInfo, x, y) else: self.createNodeAtCoordinates(self._nodeEditInfo, x, y) self._nodeEditInfo.reset() else: SelectionSceneviewerWidget.mouseReleaseEvent(self, event) self._selection_mode = SelectionMode.NONE
def __init__(self, parent=None, shared=None): # Selection attributes SelectionSceneviewerWidget.__init__(self, parent, shared) self._nodeEditMode = False self._nodeEditVectorMode = False self._nodeCreateMode = False self._nodeConstrainMode = False self._ignore_mouse_events = False self._editModifier = QtCore.Qt.CTRL self._nodeEditInfo = NodeEditInfo() self._createCoordinatesField = None
def mouseMoveEvent(self, event): ''' Inform the scene viewer of a mouse move event and update the OpenGL scene to reflect this change to the viewport. ''' if not self._ignore_mouse_events and self._selection_mode != SelectionMode.NONE: x = event.x() y = event.y() xdiff = float(x - self._selection_position_start[0]) ydiff = float(y - self._selection_position_start[1]) if abs(xdiff) < 0.0001: xdiff = 1 if abs(ydiff) < 0.0001: ydiff = 1 if self._selection_mode == SelectionMode.EDIT_POSITION: if self._nodeConstrainMode == True: returnCode, self._nodeEditInfo._nearestElement, self._nodeEditInfo._elementCoordinateField = \ self.getNearestSurfacesElementAndCoordinates(x, y) if self._nodeEditInfo._nearestElement and self._nodeEditInfo._elementCoordinateField: delta = self.getCoordinatesDelta( self._nodeEditInfo, x, y) self.updateSelectedNodesCoordinatesWithDelta(self._nodeEditInfo, \ self._selectionGroup, delta[0], delta[1], delta[2]) else: delta = self.getCoordinatesDelta(self._nodeEditInfo, x, y) self.updateSelectedNodesCoordinatesWithDelta(self._nodeEditInfo, \ self._selectionGroup, delta[0], delta[1], delta[2]) elif self._selection_mode == SelectionMode.EDIT_VECTOR: if self._nodeEditInfo._orientationField and self._nodeEditInfo._orientationField.isValid( ): delta = self.getVectorDelta(self._nodeEditInfo, x, y) self.updateSelectedNodesVectorWithDelta(self._nodeEditInfo, \ self._selectionGroup, delta[0], delta[1], delta[2]) else: SelectionSceneviewerWidget.mouseMoveEvent(self, event) elif not self._ignore_mouse_events and self._handle_mouse_events: SelectionSceneviewerWidget.mouseMoveEvent(self, event)
def mousePressEvent(self, event): ''' Inform the scene viewer of a mouse press event. ''' self._handle_mouse_events = False # Track when the zinc should be handling mouse events if not self._ignore_mouse_events and (event.modifiers() & self._editModifier) and \ (self._nodeEditMode or self._nodeEditVectorMode or self._nodeCreateMode) and \ button_map[event.button()] == Sceneviewerinput.BUTTON_TYPE_LEFT: return_code, selectedNode, selectedCoordinateField, selectedGraphics = \ self.nodeIsSelectedAtCoordinates(event.x(), event.y()) if return_code: self._nodeEditInfo._node = selectedNode self._nodeEditInfo._coordinateField = selectedCoordinateField self._nodeEditInfo._graphics = selectedGraphics self._selection_position_start = (event.x(), event.y()) if self._nodeEditMode: self._selection_mode = SelectionMode.EDIT_POSITION else: attributes = self._nodeEditInfo._graphics.getGraphicspointattributes( ) if attributes.isValid(): self._nodeEditInfo._orientationField = attributes.getOrientationScaleField( ) if self._nodeEditInfo._orientationField and self._nodeEditInfo._orientationField.isValid( ): self._selection_mode = SelectionMode.EDIT_VECTOR return_code, self._nodeEditInfo._glyphCentre = attributes.getGlyphOffset( 3) return_code, self._nodeEditInfo._glyphSize = attributes.getBaseSize( 3) return_code, self._nodeEditInfo._glyphScaleFactors = attributes.getScaleFactors( 3) self._nodeEditInfo._variableScaleField = attributes.getSignedScaleField( ) elif self._nodeCreateMode: self._selection_mode = SelectionMode.CREATE else: SelectionSceneviewerWidget.mousePressEvent(self, event)
def mouseMoveEvent(self, event): ''' Inform the scene viewer of a mouse move event and update the OpenGL scene to reflect this change to the viewport. ''' if not self._ignore_mouse_events and self._selection_mode != SelectionMode.NONE: x = event.x() y = event.y() xdiff = float(x - self._selection_position_start[0]) ydiff = float(y - self._selection_position_start[1]) if abs(xdiff) < 0.0001: xdiff = 1 if abs(ydiff) < 0.0001: ydiff = 1 if self._selection_mode == SelectionMode.EDIT_POSITION: if self._nodeConstrainMode == True: returnCode, self._nodeEditInfo._nearestElement, self._nodeEditInfo._elementCoordinateField = \ self.getNearestSurfacesElementAndCoordinates(x, y) if self._nodeEditInfo._nearestElement and self._nodeEditInfo._elementCoordinateField: delta = self.getCoordinatesDelta(self._nodeEditInfo, x, y) self.updateSelectedNodesCoordinatesWithDelta(self._nodeEditInfo, \ self._selectionGroup, delta[0], delta[1], delta[2]) else: delta = self.getCoordinatesDelta(self._nodeEditInfo, x, y) self.updateSelectedNodesCoordinatesWithDelta(self._nodeEditInfo, \ self._selectionGroup, delta[0], delta[1], delta[2]) elif self._selection_mode == SelectionMode.EDIT_VECTOR: if self._nodeEditInfo._orientationField and self._nodeEditInfo._orientationField.isValid(): delta = self.getVectorDelta(self._nodeEditInfo, x, y) self.updateSelectedNodesVectorWithDelta(self._nodeEditInfo, \ self._selectionGroup, delta[0], delta[1], delta[2]) else: SelectionSceneviewerWidget.mouseMoveEvent(self, event) elif not self._ignore_mouse_events and self._handle_mouse_events: SelectionSceneviewerWidget.mouseMoveEvent(self, event)
def mouseReleaseEvent(self, event): ''' Inform the scene viewer of a mouse release event. ''' if not self._ignore_mouse_events and (self._selection_mode == SelectionMode.EDIT_POSITION or \ self._selection_mode == SelectionMode.EDIT_VECTOR): self._nodeEditInfo.reset() elif not self._ignore_mouse_events and self._selection_mode == SelectionMode.CREATE: x = event.x() y = event.y() self._selection_box.setVisibilityFlag(False) if self._createCoordinatesField and self._createCoordinatesField.isValid(): self._nodeEditInfo._createCoordinatesField = self._createCoordinatesField if self._nodeConstrainMode == True: returnCode, self._nodeEditInfo._nearestElement, self._nodeEditInfo._elementCoordinateField = \ self.getNearestSurfacesElementAndCoordinates(x, y) if self._nodeEditInfo._nearestElement and self._nodeEditInfo._elementCoordinateField: self.createNodeAtCoordinates(self._nodeEditInfo, x, y) else: self.createNodeAtCoordinates(self._nodeEditInfo, x, y) self._nodeEditInfo.reset() else: SelectionSceneviewerWidget.mouseReleaseEvent(self, event) self._selection_mode = SelectionMode.NONE