Beispiel #1
0
 def _changeRenderMode(self, faces=True):
     if Selection.hasSelection() and Selection.getFaceSelectMode() != faces:
         self._select = False
         Selection.setFaceSelectMode(faces)
         if self._selection_pass:
             self._selection_pass.render()
         self._select = True
Beispiel #2
0
    def setActiveTool(self, tool: Optional[Union["Tool", str]]):
        from UM.Tool import Tool
        if self._active_tool:
            self._active_tool.event(ToolEvent(ToolEvent.ToolDeactivateEvent))

        if isinstance(tool, Tool) or tool is None:
            new_tool = cast(Optional[Tool], tool)
        else:
            new_tool = self.getTool(tool)

        tool_changed = False
        if self._active_tool is not new_tool:
            self._active_tool = new_tool
            tool_changed = True

        if self._active_tool:
            self._active_tool.event(ToolEvent(ToolEvent.ToolActivateEvent))

        from UM.Scene.Selection import Selection  # Imported here to prevent a circular dependency.
        if not self._active_tool and Selection.getCount() > 0:  # If something is selected, a tool must always be active.
            if "TranslateTool" in self._tools:
                self._active_tool = self._tools["TranslateTool"]  # Then default to the translation tool.
                self._active_tool.event(ToolEvent(ToolEvent.ToolActivateEvent))
                tool_changed = True
            else:
                Logger.log("w", "Controller does not have an active tool and could not default to Translate tool.")

        if tool_changed:
            Selection.setFaceSelectMode(False)
            Selection.clearFace()
            self.activeToolChanged.emit()
Beispiel #3
0
 def setSelectFaceToLayFlatMode(self, select: bool) -> None:
     if select != self._select_face_mode or select != Selection.getFaceSelectMode(
     ):
         self._select_face_mode = select
         if not select:
             Selection.clearFace()
         Selection.setFaceSelectMode(self._select_face_mode)
         self.propertyChanged.emit()
Beispiel #4
0
    def setSelectFaceToLayFlatMode(self, select: bool) -> None:
        """Set the rotate tool to/from 'Lay flat by face'-Mode."""

        if select != self._select_face_mode or select != Selection.getFaceSelectMode():
            self._select_face_mode = select
            if not select:
                Selection.clearFace()
            Selection.setFaceSelectMode(self._select_face_mode)
            self.propertyChanged.emit()
    def _onActiveStateChanged(self):
        controller = Application.getInstance().getController()
        active_tool = controller.getActiveTool()
        Logger.log("d", "Application.getInstance().getController().getActiveTool(): {}".format(active_tool))

        if active_tool == self:
            stage = controller.getActiveStage()
            controller.setFallbackTool(stage._our_toolset[0])
            if Selection.hasSelection():
                Selection.setFaceSelectMode(True)
                Logger.log("d", "Enabled faceSelectMode!")
            else:
                Selection.setFaceSelectMode(False)
                Logger.log("d", "Disabled faceSelectMode!")

            self._calculateMesh()
Beispiel #6
0
    def _onActiveStateChanged(self):

        stage = self._controller.getActiveStage()

        if stage.getPluginId() == self.getPluginId():
            self._controller.setFallbackTool(stage._our_toolset[0])
        else:
            return

        if Selection.hasSelection():
            # self._changeRenderMode(True)
            Selection.setFaceSelectMode(True)
        else:
            # self._changeRenderMode(False)
            Selection.setFaceSelectMode(False)

        self.extension.cloud._onApplicationActivityChanged()
    def _setup(self):
        # scene = CuraApplication.getInstance().getController().getScene().getRoot()
        selected_node = Selection.getSelectedObject(0)
        Selection.setFaceSelectMode(True)

        if not selected_node:
            Logger.warning("No node selected for creating boundary conditions")
            return

        self._smart_slice_scene_node = findChildSceneNode(selected_node, SmartSliceScene.Root)

        if not self._smart_slice_scene_node:
            Logger.warning("No SmartSlice node found for creating boundary conditions")
            return

        self._smart_slice_scene_node.childrenChanged.connect(self._smartSliceSceneChanged)

        self._populateList()
Beispiel #8
0
    def setActiveTool(self, tool: Optional[Union["Tool", str]]):
        """Set the current active tool.

        The tool can be set by name of the tool or directly passing the tool object.
        :param tool: A tool object or the name of a tool.
        """

        from UM.Tool import Tool
        if self._active_tool:
            self._active_tool.event(ToolEvent(ToolEvent.ToolDeactivateEvent))

        if isinstance(tool, Tool) or tool is None:
            new_tool = cast(Optional[Tool], tool)
        else:
            new_tool = self.getTool(tool)

        tool_changed = False
        if self._active_tool is not new_tool:
            self._active_tool = new_tool
            tool_changed = True

        if self._active_tool:
            self._active_tool.event(ToolEvent(ToolEvent.ToolActivateEvent))

        from UM.Scene.Selection import Selection  # Imported here to prevent a circular dependency.
        if not self._active_tool and Selection.getCount(
        ) > 0:  # If something is selected, a tool must always be active.
            if self._fallback_tool in self._tools:
                self._active_tool = self._tools[
                    self.
                    _fallback_tool]  # Then default to the translation tool.
                self._active_tool.event(ToolEvent(ToolEvent.ToolActivateEvent))
                tool_changed = True
            else:
                Logger.log(
                    "w",
                    "Controller does not have an active tool and could not default to the tool, called \"{}\"."
                    .format(self._fallback_tool))

        if tool_changed:
            Selection.setFaceSelectMode(False)
            Selection.clearFace()
            self.activeToolChanged.emit()
    def add(self):
        Selection.clearFace()
        if not Selection.getFaceSelectMode():
            Selection.setFaceSelectMode(True)

        if len(self._bcs) == 0:
            N = 1
        else:
            N = int(self._bcs[-1].getName().split(" ")[1]) + 1

        if self._bc_type == BoundaryConditionListModel.Anchor:
            bc = SmartSliceScene.AnchorFace('Anchor ' + str(N))
            bc.surface_type = SmartSliceScene.HighlightFace.SurfaceType.Flat
        else:
            bc = SmartSliceScene.LoadFace('Load ' + str(N))
            bc.force.magnitude = 10.0
            bc.force.direction_type = SmartSliceScene.Force.DirectionType.Normal
            bc.surface_type = SmartSliceScene.HighlightFace.SurfaceType.Flat

        self._smart_slice_scene_node.addFace(bc)
Beispiel #10
0
    def test_faceSelectMode(self):
        Selection.selectedFaceChanged = MagicMock()

        Selection.setFaceSelectMode(True)
        assert Selection.getFaceSelectMode()

        Selection.setFaceSelectMode(True)
        Selection.setFaceSelectMode(False)
        assert not Selection.getFaceSelectMode()
        assert Selection.selectedFaceChanged.emit.call_count == 2
Beispiel #11
0
 def setFaceSelectMode(self, select: bool) -> None:
     Selection.setFaceSelectMode(select)
     if not select:
         Selection.clearFace()
Beispiel #12
0
 def setFaceSelectMode(self, select: bool) -> None:
     Selection.setFaceSelectMode(select)