def __init__(self, device_id: str, connection_type: "ConnectionType" = ConnectionType.NotConnected, parent: QObject = None) -> None:
        super().__init__(device_id = device_id, parent = parent) # type: ignore  # MyPy complains with the multiple inheritance

        self._printers = []  # type: List[PrinterOutputModel]
        self._unique_configurations = []   # type: List[PrinterConfigurationModel]

        self._monitor_view_qml_path = ""  # type: str
        self._monitor_component = None  # type: Optional[QObject]
        self._monitor_item = None  # type: Optional[QObject]

        self._control_view_qml_path = ""  # type: str
        self._control_component = None  # type: Optional[QObject]
        self._control_item = None  # type: Optional[QObject]

        self._accepts_commands = False  # type: bool

        self._update_timer = QTimer()  # type: QTimer
        self._update_timer.setInterval(2000)  # TODO; Add preference for update interval
        self._update_timer.setSingleShot(False)
        self._update_timer.timeout.connect(self._update)

        self._connection_state = ConnectionState.Closed  # type: ConnectionState
        self._connection_type = connection_type  # type: ConnectionType

        self._firmware_updater = None  # type: Optional[FirmwareUpdater]
        self._firmware_name = None  # type: Optional[str]
        self._address = ""  # type: str
        self._connection_text = ""  # type: str
        self.printersChanged.connect(self._onPrintersChanged)
        QtApplication.getInstance().getOutputDeviceManager().outputDevicesChanged.connect(self._updateUniqueConfigurations)
Exemple #2
0
    def __init__(self, width: int, height: int) -> None:
        super().__init__("picking", width, height)

        self._renderer = QtApplication.getInstance().getRenderer()

        self._shader = None #type: Optional[ShaderProgram]
        self._scene = QtApplication.getInstance().getController().getScene()
Exemple #3
0
    def __init__(self, parent = None) -> None:
        super().__init__(parent)

        self._max_layers = 0
        self._current_layer_num = 0
        self._minimum_layer_num = 0
        self._current_layer_mesh = None
        self._current_layer_jumps = None
        self._top_layers_job = None  # type: Optional["_CreateTopLayersJob"]
        self._activity = False
        self._old_max_layers = 0

        self._max_paths = 0
        self._current_path_num = 0
        self._minimum_path_num = 0
        self.currentLayerNumChanged.connect(self._onCurrentLayerNumChanged)

        self._busy = False
        self._simulation_running = False

        self._ghost_shader = None  # type: Optional["ShaderProgram"]
        self._layer_pass = None  # type: Optional[SimulationPass]
        self._composite_pass = None  # type: Optional[CompositePass]
        self._old_layer_bindings = None  # type: Optional[List[str]]
        self._simulationview_composite_shader = None  # type: Optional["ShaderProgram"]
        self._old_composite_shader = None  # type: Optional["ShaderProgram"]

        self._global_container_stack = None  # type: Optional[ContainerStack]
        self._proxy = SimulationViewProxy()
        self._controller.getScene().getRoot().childrenChanged.connect(self._onSceneChanged)

        self._resetSettings()
        self._legend_items = None
        self._show_travel_moves = False
        self._nozzle_node = None  # type: Optional[NozzleNode]

        Application.getInstance().getPreferences().addPreference("view/top_layer_count", 5)
        Application.getInstance().getPreferences().addPreference("view/only_show_top_layers", False)
        Application.getInstance().getPreferences().addPreference("view/force_layer_view_compatibility_mode", False)

        Application.getInstance().getPreferences().addPreference("layerview/layer_view_type", 0)
        Application.getInstance().getPreferences().addPreference("layerview/extruder_opacities", "")

        Application.getInstance().getPreferences().addPreference("layerview/show_travel_moves", False)
        Application.getInstance().getPreferences().addPreference("layerview/show_helpers", True)
        Application.getInstance().getPreferences().addPreference("layerview/show_skin", True)
        Application.getInstance().getPreferences().addPreference("layerview/show_infill", True)

        Application.getInstance().getPreferences().preferenceChanged.connect(self._onPreferencesChanged)
        self._updateWithPreferences()

        self._solid_layers = int(Application.getInstance().getPreferences().getValue("view/top_layer_count"))
        self._only_show_top_layers = bool(Application.getInstance().getPreferences().getValue("view/only_show_top_layers"))
        self._compatibility_mode = self._evaluateCompatibilityMode()

        self._wireprint_warning_message = Message(catalog.i18nc("@info:status", "Cura does not accurately display layers when Wire Printing is enabled"),
                                                  title = catalog.i18nc("@info:title", "Simulation View"))

        QtApplication.getInstance().engineCreatedSignal.connect(self._onEngineCreated)
Exemple #4
0
    def _zoomCamera(self, zoom_range: float, event: Optional[Event] = None) -> None:
        camera = self._scene.getActiveCamera()
        if not camera or not camera.isEnabled():
            return

        self.clipToZoom()

        self._scene.getSceneLock().acquire()

        r = (camera.getWorldPosition() - self._origin).length()
        delta = r * (zoom_range / 128 / 10.0)
        r -= delta

        if self._invert_zoom:
            delta *= -1

        move_vector = Vector(0.0, 0.0, 1.0)

        if event is not None and self._zoom_to_mouse:
            viewport_center_x = QtApplication.getInstance().getRenderer().getViewportWidth() / 2
            viewport_center_y = QtApplication.getInstance().getRenderer().getViewportHeight() / 2
            main_window = cast(MainWindow, QtApplication.getInstance().getMainWindow())
            mouse_diff_center_x = viewport_center_x - main_window.mouseX
            mouse_diff_center_y = viewport_center_y - main_window.mouseY

            x_component = mouse_diff_center_x / QtApplication.getInstance().getRenderer().getViewportWidth()
            y_component = mouse_diff_center_y / QtApplication.getInstance().getRenderer().getViewportHeight()

            move_vector = Vector(x_component, -y_component, 1)
            move_vector = move_vector.normalized()

        move_vector = -delta * move_vector
        if delta != 0:
            if self._min_zoom < r < self._max_zoom:
                camera.translate(move_vector)
                if self._zoom_to_mouse:
                    # Set the origin of the camera to the new distance, right in front of the new camera position.
                    self._origin = (r * Vector(0.0, 0.0, -1.0)).preMultiply(camera.getWorldTransformation())
        self._scene.getSceneLock().release()
Exemple #5
0
    def __init__(self, node: SceneNode, hull: Optional[Polygon], thickness: float, parent: Optional[SceneNode] = None) -> None:
        super().__init__(parent)

        self.setCalculateBoundingBox(False)

        self._original_parent = parent

        # Color of the drawn convex hull
        if not Application.getInstance().getIsHeadLess():
            theme = QtApplication.getInstance().getTheme()
            if theme:
                self._color = Color(*theme.getColor("convex_hull").getRgb())
            else:
                self._color = Color(0, 0, 0)
        else:
            self._color = Color(0, 0, 0)

        # The y-coordinate of the convex hull mesh. Must not be 0, to prevent z-fighting.
        self._mesh_height = 0.1

        self._thickness = thickness

        # The node this mesh is "watching"
        self._node = node
        self._convex_hull_head_mesh = None

        self._node.decoratorsChanged.connect(self._onNodeDecoratorsChanged)
        self._onNodeDecoratorsChanged(self._node)

        self._hull = hull
        if self._hull:
            hull_mesh_builder = MeshBuilder()

            if hull_mesh_builder.addConvexPolygonExtrusion(
                self._hull.getPoints()[::-1],  # bottom layer is reversed
                self._mesh_height - thickness, self._mesh_height, color = self._color):

                hull_mesh = hull_mesh_builder.build()
                self.setMeshData(hull_mesh)
Exemple #6
0
    def _createMonitorViewFromQML(self) -> None:
        if not self._monitor_view_qml_path:
            return

        if self._monitor_item is None:
            self._monitor_item = QtApplication.getInstance().createQmlComponent(self._monitor_view_qml_path, {"OutputDevice": self})
Exemple #7
0
    def __init__(self, parent=None) -> None:
        super().__init__(parent)

        self._max_layers = 0
        self._current_layer_num = 0
        self._minimum_layer_num = 0
        self._current_layer_mesh = None
        self._current_layer_jumps = None
        self._top_layers_job = None  # type: Optional["_CreateTopLayersJob"]
        self._activity = False
        self._old_max_layers = 0

        self._max_paths = 0
        self._current_path_num = 0
        self._minimum_path_num = 0
        self.currentLayerNumChanged.connect(self._onCurrentLayerNumChanged)

        self._busy = False
        self._simulation_running = False

        self._ghost_shader = None  # type: Optional["ShaderProgram"]
        self._layer_pass = None  # type: Optional[SimulationPass]
        self._composite_pass = None  # type: Optional[CompositePass]
        self._old_layer_bindings = None  # type: Optional[List[str]]
        self._simulationview_composite_shader = None  # type: Optional["ShaderProgram"]
        self._old_composite_shader = None  # type: Optional["ShaderProgram"]

        self._max_feedrate = sys.float_info.min
        self._min_feedrate = sys.float_info.max
        self._max_thickness = sys.float_info.min
        self._min_thickness = sys.float_info.max
        self._max_line_width = sys.float_info.min
        self._min_line_width = sys.float_info.max

        self._global_container_stack = None  # type: Optional[ContainerStack]
        self._proxy = None

        self._resetSettings()
        self._legend_items = None
        self._show_travel_moves = False
        self._nozzle_node = None  # type: Optional[NozzleNode]

        Application.getInstance().getPreferences().addPreference(
            "view/top_layer_count", 5)
        Application.getInstance().getPreferences().addPreference(
            "view/only_show_top_layers", False)
        Application.getInstance().getPreferences().addPreference(
            "view/force_layer_view_compatibility_mode", False)

        Application.getInstance().getPreferences().addPreference(
            "layerview/layer_view_type", 1)  # Default to "Line Type".
        Application.getInstance().getPreferences().addPreference(
            "layerview/extruder_opacities", "")

        Application.getInstance().getPreferences().addPreference(
            "layerview/show_travel_moves", False)
        Application.getInstance().getPreferences().addPreference(
            "layerview/show_helpers", True)
        Application.getInstance().getPreferences().addPreference(
            "layerview/show_skin", True)
        Application.getInstance().getPreferences().addPreference(
            "layerview/show_infill", True)
        Application.getInstance().getPreferences().addPreference(
            "layerview/show_starts", True)

        self.visibleStructuresChanged.connect(self.calculateColorSchemeLimits)
        self._updateWithPreferences()

        self._solid_layers = int(
            Application.getInstance().getPreferences().getValue(
                "view/top_layer_count"))
        self._only_show_top_layers = bool(
            Application.getInstance().getPreferences().getValue(
                "view/only_show_top_layers"))
        self._compatibility_mode = self._evaluateCompatibilityMode()

        self._wireprint_warning_message = Message(catalog.i18nc(
            "@info:status",
            "Cura does not accurately display layers when Wire Printing is enabled."
        ),
                                                  title=catalog.i18nc(
                                                      "@info:title",
                                                      "Simulation View"))
        self._slice_first_warning_message = Message(
            catalog.i18nc("@info:status",
                          "Nothing is shown because you need to slice first."),
            title=catalog.i18nc("@info:title", "No layers to show"),
            option_text=catalog.i18nc("@info:option_text",
                                      "Do not show this message again"),
            option_state=False)
        self._slice_first_warning_message.optionToggled.connect(
            self._onDontAskMeAgain)
        CuraApplication.getInstance().getPreferences().addPreference(
            self._no_layers_warning_preference, True)

        QtApplication.getInstance().engineCreatedSignal.connect(
            self._onEngineCreated)
Exemple #8
0
    def __init__(self, parent=None) -> None:
        super().__init__(parent)

        self._max_layers = 0
        self._current_layer_num = 0
        self._minimum_layer_num = 0
        self._current_layer_mesh = None
        self._current_layer_jumps = None
        self._top_layers_job = None  # type: Optional["_CreateTopLayersJob"]
        self._activity = False
        self._old_max_layers = 0

        self._max_paths = 0
        self._current_path_num = 0
        self._minimum_path_num = 0
        self.currentLayerNumChanged.connect(self._onCurrentLayerNumChanged)

        self._busy = False
        self._simulation_running = False

        self._ghost_shader = None  # type: Optional["ShaderProgram"]
        self._layer_pass = None  # type: Optional[SimulationPass]
        self._composite_pass = None  # type: Optional[CompositePass]
        self._old_layer_bindings = None  # type: Optional[List[str]]
        self._simulationview_composite_shader = None  # type: Optional["ShaderProgram"]
        self._old_composite_shader = None  # type: Optional["ShaderProgram"]

        self._global_container_stack = None  # type: Optional[ContainerStack]
        self._proxy = SimulationViewProxy()
        self._controller.getScene().getRoot().childrenChanged.connect(
            self._onSceneChanged)

        self._resetSettings()
        self._legend_items = None
        self._show_travel_moves = False
        self._nozzle_node = None  # type: Optional[NozzleNode]

        Application.getInstance().getPreferences().addPreference(
            "view/top_layer_count", 5)
        Application.getInstance().getPreferences().addPreference(
            "view/only_show_top_layers", False)
        Application.getInstance().getPreferences().addPreference(
            "view/force_layer_view_compatibility_mode", False)

        Application.getInstance().getPreferences().addPreference(
            "layerview/layer_view_type", 0)
        Application.getInstance().getPreferences().addPreference(
            "layerview/extruder_opacities", "")

        Application.getInstance().getPreferences().addPreference(
            "layerview/show_travel_moves", False)
        Application.getInstance().getPreferences().addPreference(
            "layerview/show_helpers", True)
        Application.getInstance().getPreferences().addPreference(
            "layerview/show_skin", True)
        Application.getInstance().getPreferences().addPreference(
            "layerview/show_infill", True)

        Application.getInstance().getPreferences().preferenceChanged.connect(
            self._onPreferencesChanged)
        self._updateWithPreferences()

        self._solid_layers = int(
            Application.getInstance().getPreferences().getValue(
                "view/top_layer_count"))
        self._only_show_top_layers = bool(
            Application.getInstance().getPreferences().getValue(
                "view/only_show_top_layers"))
        self._compatibility_mode = self._evaluateCompatibilityMode()

        self._wireprint_warning_message = Message(catalog.i18nc(
            "@info:status",
            "Cura does not accurately display layers when Wire Printing is enabled"
        ),
                                                  title=catalog.i18nc(
                                                      "@info:title",
                                                      "Simulation View"))

        QtApplication.getInstance().engineCreatedSignal.connect(
            self._onEngineCreated)
Exemple #9
0
 def __init__(self, *args, **kwargs) -> None:
     super().__init__(*args, **kwargs)
     from UM.Qt.QtApplication import QtApplication
     self._application = QtApplication.getInstance()
     self._handler = QtApplication.getInstance().getMeshFileHandler()
Exemple #10
0
    def event(self, event: Event):
        if event.type == Event.ToolActivateEvent:
            active_view = QtApplication.getInstance().getController(
            ).getActiveView()

            if active_view is not None:
                self._previous_view = active_view.getPluginId()
            QtApplication.getInstance().getController().setActiveView(
                "SolidView")
            #QtApplication.getInstance().getController().disableSelection()
            QtApplication.getInstance().setOverrideCursor(self._cursor)

        elif event.type == Event.ToolDeactivateEvent:
            if self._previous_view is not None:
                QtApplication.getInstance().getController().setActiveView(
                    self._previous_view)
                self._previous_view = None
            QtApplication.getInstance().getController().enableSelection()
            QtApplication.getInstance().restoreOverrideCursor()

        elif event.type == Event.MousePressEvent and MouseEvent.LeftButton in event.buttons:
            #Reset the draw buffer and start painting.
            self._draw_buffer = QImage(
                QtApplication.getInstance().getMainWindow().width(),
                QtApplication.getInstance().getMainWindow().height(),
                QImage.Format_Grayscale8)
            self._draw_buffer.fill(Qt.black)
            self._painter = QPainter(self._draw_buffer)
            self._painter.setBrush(QBrush(Qt.white))
            self._painter.setPen(self._endcap_pen)
            self._last_x, self._last_y = self._cursorCoordinates()
            self._painter.drawEllipse(
                self._last_x - self.brush_size / 2,
                self._last_y - self.brush_size / 2, self.brush_size,
                self.brush_size
            )  #Paint an initial ellipse at the spot you're clicking.
            QtApplication.getInstance().getController().getView(
                "SolidView").setExtraOverhang(self._draw_buffer)

        elif event.type == Event.MouseReleaseEvent and MouseEvent.LeftButton in event.buttons:
            #Complete drawing.
            self._last_x, self._last_y = self._cursorCoordinates()
            if self._painter:
                self._painter.setPen(self._endcap_pen)
                self._painter.drawEllipse(
                    self._last_x - self.brush_size / 2,
                    self._last_y - self.brush_size / 2, self.brush_size,
                    self.brush_size
                )  #Paint another ellipse when you're releasing as endcap.
                self._painter = None
            QtApplication.getInstance().getController().getView(
                "SolidView").setExtraOverhang(self._draw_buffer)
            self._constructSupport(
                self._draw_buffer)  #Actually place the support.
            self._resetDrawBuffer()
        elif event.type == Event.MouseMoveEvent and self._painter is not None:  #While dragging.
            self._painter.setPen(self._line_pen)
            new_x, new_y = self._cursorCoordinates()
            self._painter.drawLine(self._last_x, self._last_y, new_x, new_y)
            self._last_x = new_x
            self._last_y = new_y
            QtApplication.getInstance().getController().getView(
                "SolidView").setExtraOverhang(self._draw_buffer)
Exemple #11
0
 def _cursorCoordinates(self) -> Tuple[int, int]:
     return QtApplication.getInstance().getMainWindow(
     ).mouseX, QtApplication.getInstance().getMainWindow().mouseY
Exemple #12
0
 def __init__(self, filename: str) -> None:
     super().__init__(filename)
     from UM.Qt.QtApplication import QtApplication
     self._application = QtApplication.getInstance()
     self._handler = QtApplication.getInstance().getMeshFileHandler()
Exemple #13
0
    def __init__(self,
                 node: SceneNode,
                 hull: Optional[Polygon],
                 thickness: float,
                 parent: Optional[SceneNode] = None) -> None:
        """Convex hull node is a special type of scene node that is used to display an area, to indicate the

        location an object uses on the buildplate. This area (or area's in case of one at a time printing) is
        then displayed as a transparent shadow. If the adhesion type is set to raft, the area is extruded
        to represent the raft as well.
        """
        super().__init__(parent)

        self.setCalculateBoundingBox(False)

        self._original_parent = parent

        # Color of the drawn convex hull
        if not Application.getInstance().getIsHeadLess():
            theme = QtApplication.getInstance().getTheme()
            if theme:
                self._color = Color(*theme.getColor("convex_hull").getRgb())
            else:
                self._color = Color(0, 0, 0)
        else:
            self._color = Color(0, 0, 0)

        # The y-coordinate of the convex hull mesh. Must not be 0, to prevent z-fighting.
        self._mesh_height = 0.1

        self._thickness = thickness

        # The node this mesh is "watching"
        self._node = node
        # Area of the head + fans for display as a shadow on the buildplate
        self._convex_hull_head_mesh = None  # type: Optional[MeshData]

        self._node.decoratorsChanged.connect(self._onNodeDecoratorsChanged)
        self._onNodeDecoratorsChanged(self._node)

        self._hull = hull
        if self._hull:
            hull_mesh_builder = MeshBuilder()
            if self._thickness == 0:
                if hull_mesh_builder.addConvexPolygon(
                        self._hull.getPoints()[::],  # bottom layer is reversed
                        self._mesh_height,
                        color=self._color):
                    hull_mesh_builder.resetNormals()

                    hull_mesh = hull_mesh_builder.build()
                    self.setMeshData(hull_mesh)
            else:
                if hull_mesh_builder.addConvexPolygonExtrusion(
                        self._hull.getPoints()
                    [::-1],  # bottom layer is reversed
                        self._mesh_height - thickness,
                        self._mesh_height,
                        color=self._color):
                    hull_mesh_builder.resetNormals()
                    hull_mesh = hull_mesh_builder.build()
                    self.setMeshData(hull_mesh)
Exemple #14
0
    def _createMonitorViewFromQML(self) -> None:
        if not self._monitor_view_qml_path:
            return

        if self._monitor_item is None:
            self._monitor_item = QtApplication.getInstance().createQmlComponent(self._monitor_view_qml_path, {"OutputDevice": self})
Exemple #15
0
    def _zoomCamera(self,
                    zoom_range: float,
                    event: Optional[Event] = None) -> None:
        """"Zoom" the camera in response to a mouse event.

        Note that the camera field of view is left unaffected, but instead the camera moves closer to the origin
        :param zoom_range: factor by which the distance to the origin is multiplied, multiplied by 1280
        """

        camera = self._scene.getActiveCamera()
        if not camera or not camera.isEnabled():
            return

        self.clipToZoom()

        if camera.isPerspective():
            r = (camera.getWorldPosition() - self._origin).length()
            delta = r * (zoom_range / 128 / 10.0)
            r -= delta

            if self._invert_zoom:
                delta *= -1

            move_vector = Vector(0.0, 0.0, 1.0)

            if event is not None and self._zoom_to_mouse:
                viewport_center_x = QtApplication.getInstance().getRenderer(
                ).getViewportWidth() / 2
                viewport_center_y = QtApplication.getInstance().getRenderer(
                ).getViewportHeight() / 2
                main_window = cast(MainWindow,
                                   QtApplication.getInstance().getMainWindow())
                mouse_diff_center_x = viewport_center_x - main_window.mouseX
                mouse_diff_center_y = viewport_center_y - main_window.mouseY

                x_component = mouse_diff_center_x / QtApplication.getInstance(
                ).getRenderer().getViewportWidth()
                y_component = mouse_diff_center_y / QtApplication.getInstance(
                ).getRenderer().getViewportHeight()

                move_vector = Vector(x_component, -y_component, 1)
                move_vector = move_vector.normalized()

            move_vector = -delta * move_vector
            if delta != 0:
                if self._min_zoom < r < self._max_zoom:
                    camera.translate(move_vector)
                    if self._zoom_to_mouse:
                        # Set the origin of the camera to the new distance, right in front of the new camera position.
                        self._origin = (r *
                                        Vector(0.0, 0.0, -1.0)).preMultiply(
                                            camera.getWorldTransformation())
        else:
            amount_of_zoom = zoom_range / 1280 / 10.0
            if self._invert_zoom:
                amount_of_zoom *= -1
            new_zoom_factor = camera.getZoomFactor() - amount_of_zoom

            if new_zoom_factor > 1:
                camera.setZoomFactor(1)
            elif new_zoom_factor < -0.495:
                camera.setZoomFactor(-0.495)
            else:
                camera.setZoomFactor(new_zoom_factor)