def project(self, position: Vector) -> Tuple[float, float]: projection = self._projection_matrix view = self.getWorldTransformation().getInverse() position = position.preMultiply(view) position = position.preMultiply(projection) return position.x / position.z / 2.0, position.y / position.z / 2.0
def project(self, position: Vector) -> Tuple[float, float]: projection = self._projection_matrix view = self.getWorldTransformation() view.invert() position = position.preMultiply(view) position = position.preMultiply(projection) return position.x / position.z / 2.0, position.y / position.z / 2.0
def project(self, position: Vector) -> Tuple[float, float]: """Project a 3D position onto the 2D view plane.""" projection = self._projection_matrix view = self.getWorldTransformation() view.invert() position = position.preMultiply(view) position = position.preMultiply(projection) return position.x / position.z / 2.0, position.y / position.z / 2.0
def event(self, event: Event) -> bool: result = super().event(event) if not self._tool_enabled: return result # overridden from ToolHandle.event(), because we also want to show the handle when there is no selection # disabling the tool oon Event.ToolDeactivateEvent is properly handled in ToolHandle.evemt() if event.type == Event.ToolActivateEvent: if self._handle: self._handle.setParent( self.getController().getScene().getRoot()) self._handle.setEnabled(True) self._selection_tool = self._controller._selection_tool self._controller.setSelectionTool(None) self._application.callLater( lambda: self._forceToolEnabled(passive=True)) if event.type == Event.ToolDeactivateEvent: self._controller.setSelectionTool(self._selection_tool or "SelectionTool") self._selection_tool = None self._application.callLater( lambda: self._forceToolEnabled(passive=True)) if (event.type == Event.MouseReleaseEvent and MouseEvent.LeftButton in cast(MouseEvent, event).buttons): self._dragging = False if (event.type == Event.MousePressEvent and MouseEvent.LeftButton in cast(MouseEvent, event).buttons): mouse_event = cast(MouseEvent, event) if QApplication.keyboardModifiers() & KeyboardShiftModifier: if self._active_point == 0: self._active_point = 1 else: self._active_point = 0 else: distances = [] # type: List[float] camera = self._controller.getScene().getActiveCamera() for point in self._points: if camera.isPerspective(): projected_point = camera.project( Vector(point.x(), point.y(), point.z())) else: # Camera.project() does not work for orthographic views in Cura 4.9 and before, so we calculate our own projection projection = camera.getProjectionMatrix() view = camera.getWorldTransformation() view.invert() position = Vector(point.x(), point.y(), point.z()) position = position.preMultiply(view) position = position.preMultiply(projection) projected_point = (position.x, position.y) dx = projected_point[0] - ( (camera.getWindowSize()[0] * (mouse_event.x + 1) / camera.getViewportWidth()) - 1) dy = projected_point[1] + mouse_event.y distances.append(dx * dx + dy * dy) self._active_point = 0 if distances[1] < distances[0]: self._active_point = 1 self._dragging = True result = self._handle_mouse_event(event, result) if event.type == Event.MouseMoveEvent: if self._dragging: result = self._handle_mouse_event(event, result) if self._selection_tool: self._selection_tool.event(event) return result