Esempio n. 1
0
    def centerObject(self, object_id):
        node = self.getController().getScene().findObject(object_id)

        if not node and object_id != 0: #Workaround for tool handles overlapping the selected object
            node = Selection.getSelectedObject(0)

        if node:
            op = SetTransformOperation(node, Vector())
            op.push()
Esempio n. 2
0
    def centerObject(self, object_id):
        node = self.getController().getScene().findObject(object_id)

        if not node and object_id != 0:  #Workaround for tool handles overlapping the selected object
            node = Selection.getSelectedObject(0)

        if node:
            op = SetTransformOperation(node, Vector())
            op.push()
Esempio n. 3
0
 def setScaleZ(self, scale):
     obj = Selection.getSelectedObject(0)
     if obj:
         obj_scale = obj.getScale()
         if obj_scale.z != scale:
             obj_scale.setZ(scale)
             if not self._non_uniform_scale:
                 obj_scale.setY(scale)
                 obj_scale.setX(scale)
             operation = SetTransformOperation(obj, None, None, obj_scale)
             operation.push()
Esempio n. 4
0
 def setScaleZ(self, scale):
     obj = Selection.getSelectedObject(0)
     if obj:
         obj_scale = obj.getScale()
         if obj_scale.z != scale:
             obj_scale.setZ(scale)
             if not self._non_uniform_scale:
                 obj_scale.setY(scale)
                 obj_scale.setX(scale)
             operation = SetTransformOperation(obj, None, None, obj_scale)
             operation.push()
Esempio n. 5
0
 def setObjectDepth(self, depth):
     obj = Selection.getSelectedObject(0)
     if obj:
         obj_scale = obj.getScale()
         obj_depth = obj.getBoundingBox().depth / obj_scale.z
         target_scale = float(depth) / obj_depth
         if obj_scale.z != target_scale:
             obj_scale.setZ(target_scale)
             if not self._non_uniform_scale:
                 obj_scale.setY(target_scale)
                 obj_scale.setX(target_scale)
             operation = SetTransformOperation(obj, None, None, obj_scale)
             operation.push()
Esempio n. 6
0
 def setObjectHeight(self, height):
     obj = Selection.getSelectedObject(0)
     if obj:
         obj_scale = obj.getScale()
         obj_height = obj.getBoundingBox().height / obj_scale.y
         target_scale = float(height) / obj_height
         if obj_scale.y != target_scale:
             obj_scale.setY(target_scale)
             if not self._non_uniform_scale:
                 obj_scale.setX(target_scale)
                 obj_scale.setZ(target_scale)
             operation = SetTransformOperation(obj, None, None, obj_scale)
             operation.push()
Esempio n. 7
0
 def setObjectDepth(self, depth):
     obj = Selection.getSelectedObject(0)
     if obj:
         obj_scale = obj.getScale()
         obj_depth = obj.getBoundingBox().depth / obj_scale.z
         target_scale = float(depth) / obj_depth
         if obj_scale.z != target_scale:
             obj_scale.setZ(target_scale)
             if not self._non_uniform_scale:
                 obj_scale.setY(target_scale)
                 obj_scale.setX(target_scale)
             operation = SetTransformOperation(obj, None, None, obj_scale)
             operation.push()
Esempio n. 8
0
 def setObjectHeight(self, height):
     obj = Selection.getSelectedObject(0)
     if obj:
         obj_scale = obj.getScale()
         obj_height = obj.getBoundingBox().height / obj_scale.y
         target_scale = float(height) / obj_height
         if obj_scale.y != target_scale:
             obj_scale.setY(target_scale)
             if not self._non_uniform_scale:
                 obj_scale.setX(target_scale)
                 obj_scale.setZ(target_scale)
             operation = SetTransformOperation(obj, None, None, obj_scale)
             operation.push()
Esempio n. 9
0
    def resetAll(self):
        Logger.log("i", "Resetting all scene transformations")
        nodes = []
        for node in DepthFirstIterator(
                self.getController().getScene().getRoot()):
            if type(node) is not SceneNode:
                continue
            if not node.getMeshData() and not node.callDecoration("isGroup"):
                continue  # Node that doesnt have a mesh and is not a group.
            if node.getParent() and node.getParent().callDecoration("isGroup"):
                continue  # Grouped nodes don't need resetting as their parent (the group) is resetted)
            nodes.append(node)

        if nodes:
            op = GroupedOperation()
            for node in nodes:
                # Ensure that the object is above the build platform
                node.removeDecorator(ZOffsetDecorator.ZOffsetDecorator)
                center_y = 0
                if node.callDecoration("isGroup"):
                    center_y = node.getWorldPosition().y - node.getBoundingBox(
                    ).bottom
                else:
                    center_y = node.getMeshData().getCenterPosition().y
                op.addOperation(
                    SetTransformOperation(node, Vector(0, center_y, 0),
                                          Quaternion(), Vector(1, 1, 1)))
            op.push()
Esempio n. 10
0
 def centerSelection(self) -> None:
     operation = GroupedOperation()
     for node in Selection.getAllSelectedObjects():
         current_node = node
         while current_node.getParent() and current_node.getParent(
         ).callDecoration("isGroup"):
             current_node = current_node.getParent()
         vector = Vector()
         print_mode_enabled = Application.getInstance(
         ).getGlobalContainerStack().getProperty("print_mode", "enabled")
         if print_mode_enabled:
             print_mode = Application.getInstance().getGlobalContainerStack(
             ).getProperty("print_mode", "value")
             if print_mode != "regular":
                 machine_width = Application.getInstance(
                 ).getGlobalContainerStack().getProperty(
                     "machine_width", "value")
                 center = -machine_width / 4
                 if print_mode == "mirror":
                     machine_head_with_fans_polygon = Application.getInstance(
                     ).getGlobalContainerStack().getProperty(
                         "machine_head_with_fans_polygon", "value")
                     machine_head_size = math.fabs(
                         machine_head_with_fans_polygon[0][0] -
                         machine_head_with_fans_polygon[2][0])
                     center -= machine_head_size / 4
                 vector = Vector(center, 0, 0)
         center_operation = SetTransformOperation(current_node, vector)
         operation.addOperation(center_operation)
     operation.push()
Esempio n. 11
0
    def resetAll(self):
        nodes = []
        for node in DepthFirstIterator(
                self.getController().getScene().getRoot()):
            if type(node) is not SceneNode:
                continue
            if not node.getMeshData() and not node.callDecoration("isGroup"):
                continue  #Node that doesnt have a mesh and is not a group.
            if node.getParent() and node.getParent().callDecoration("isGroup"):
                continue  #Grouped nodes don't need resetting as their parent (the group) is resetted)
            nodes.append(node)

        if nodes:
            op = GroupedOperation()

            for node in nodes:
                # Ensure that the object is above the build platform
                move_distance = node.getBoundingBox().center.y
                if move_distance <= 0:
                    move_distance = -node.getBoundingBox().bottom
                op.addOperation(
                    SetTransformOperation(node, Vector(0, move_distance, 0),
                                          Quaternion(), Vector(1, 1, 1)))

            op.push()
Esempio n. 12
0
    def centerSelection(self) -> None:
        operation = GroupedOperation()
        for node in Selection.getAllSelectedObjects():
            current_node = node
            while current_node.getParent() and current_node.getParent(
            ).callDecoration("isGroup"):
                current_node = current_node.getParent()

            center_operation = SetTransformOperation(current_node, Vector())
            operation.addOperation(center_operation)
        operation.push()
Esempio n. 13
0
    def resetAll(self):
        nodes = []
        for node in DepthFirstIterator(self.getController().getScene().getRoot()):
            if type(node) is not SceneNode or not node.getMeshData():
                continue
            nodes.append(node)

        if nodes:
            op = GroupedOperation()

            for node in nodes:
                op.addOperation(SetTransformOperation(node, Vector(), Quaternion(), Vector(1, 1, 1)))

            op.push()
Esempio n. 14
0
    def resetAllTranslation(self):
        nodes = []
        for node in DepthFirstIterator(
                self.getController().getScene().getRoot()):
            if type(node) is not SceneNode:
                continue
            if not node.getMeshData() and not node.callDecoration("isGroup"):
                continue  #Node that doesnt have a mesh and is not a group.
            if node.getParent() and node.getParent().callDecoration("isGroup"):
                continue  #Grouped nodes don't need resetting as their parent (the group) is resetted)

            nodes.append(node)
        if nodes:
            op = GroupedOperation()
            for node in nodes:
                op.addOperation(SetTransformOperation(node, Vector()))

            op.push()
Esempio n. 15
0
    def randomiseMeshLocation(self) -> None:
        nodes_list = self._getAllSelectedNodes()
        if not nodes_list:
            return

        global_container_stack = self._application.getGlobalContainerStack()
        if not global_container_stack:
            return

        disallowed_edge = self._application.getBuildVolume().getEdgeDisallowedSize() + 2  # Allow for some rounding errors
        max_x_coordinate = (global_container_stack.getProperty("machine_width", "value") / 2) - disallowed_edge
        max_y_coordinate = (global_container_stack.getProperty("machine_depth", "value") / 2) - disallowed_edge

        op = GroupedOperation()
        for node in nodes_list:
            node_bounds = node.getBoundingBox()
            position = self._randomLocation(node_bounds, max_x_coordinate, max_y_coordinate)
            op.addOperation(SetTransformOperation(node, translation=position))
        op.push()
Esempio n. 16
0
    def centerObject(self, object_id):
        node = self.getController().getScene().findObject(object_id)

        if node:
            op = SetTransformOperation(node, Vector())
            op.push()