Ejemplo n.º 1
0
 def getZ(self):
     # We want to display based on the bottom instead of the actual coordinate.
     if Selection.hasSelection():
         # Note; The switching of z & y is intentional. We display z as up for the user,
         # But store the data in openGL space.
         return float(Selection.getBoundingBox().bottom)
     return 0.0
Ejemplo n.º 2
0
 def getZ(self) -> float:
     # We want to display based on the bottom instead of the actual coordinate.
     if Selection.hasSelection():
         # Note; The switching of z & y is intentional. We display z as up for the user,
         # But store the data in openGL space.
         return float(Selection.getBoundingBox().bottom)
     return 0.0
Ejemplo n.º 3
0
    def setX(self, x: str) -> None:
        parsed_x = self._parseFloat(x)
        bounding_box = Selection.getBoundingBox()

        if not Float.fuzzyCompare(parsed_x, float(bounding_box.center.x),
                                  DIMENSION_TOLERANCE):
            selected_nodes = self._getSelectedObjectsWithoutSelectedAncestors()
            if len(selected_nodes) > 1:
                op = GroupedOperation()
                for selected_node in self._getSelectedObjectsWithoutSelectedAncestors(
                ):
                    world_position = selected_node.getWorldPosition()
                    new_position = world_position.set(
                        x=parsed_x +
                        (world_position.x - bounding_box.center.x))
                    node_op = TranslateOperation(selected_node,
                                                 new_position,
                                                 set_position=True)
                    op.addOperation(node_op)
                op.push()
            else:
                for selected_node in self._getSelectedObjectsWithoutSelectedAncestors(
                ):
                    world_position = selected_node.getWorldPosition()
                    new_position = world_position.set(
                        x=parsed_x +
                        (world_position.x - bounding_box.center.x))
                    TranslateOperation(selected_node,
                                       new_position,
                                       set_position=True).push()

        self._controller.toolOperationStopped.emit(self)
Ejemplo n.º 4
0
    def setY(self, y: str) -> None:
        """Set the y-location of the selected object(s) by translating relative to

        the selection bounding box center.
        :param y: Location in mm.
        """
        parsed_y = self._parseFloat(y)
        bounding_box = Selection.getBoundingBox()

        if not Float.fuzzyCompare(parsed_y, float(bounding_box.center.z), DIMENSION_TOLERANCE):
            selected_nodes = self._getSelectedObjectsWithoutSelectedAncestors()
            if len(selected_nodes) > 1:
                op = GroupedOperation()
                for selected_node in selected_nodes:
                    # Note; The switching of z & y is intentional. We display z as up for the user,
                    # But store the data in openGL space.
                    world_position = selected_node.getWorldPosition()
                    new_position = world_position.set(z = parsed_y + (world_position.z - bounding_box.center.z))
                    node_op = TranslateOperation(selected_node, new_position, set_position = True)
                    op.addOperation(node_op)
                op.push()
            else:
                for selected_node in selected_nodes:
                    world_position = selected_node.getWorldPosition()
                    new_position = world_position.set(z = parsed_y + (world_position.z - bounding_box.center.z))
                    TranslateOperation(selected_node, new_position, set_position = True).push()

        self._controller.toolOperationStopped.emit(self)
Ejemplo n.º 5
0
    def setZ(self, z: str) -> None:
        parsed_z = self._parseFloat(z)
        bounding_box = Selection.getBoundingBox()

        if not Float.fuzzyCompare(parsed_z, float(bounding_box.bottom),
                                  DIMENSION_TOLERANCE):
            selected_nodes = self._getSelectedObjectsWithoutSelectedAncestors()
            if len(selected_nodes) > 1:
                op = GroupedOperation()
                for selected_node in selected_nodes:
                    # Note: The switching of z & y is intentional. We display z as up for the user,
                    # But store the data in openGL space.
                    world_position = selected_node.getWorldPosition()
                    new_position = world_position.set(
                        y=parsed_z + (world_position.y - bounding_box.bottom))
                    node_op = TranslateOperation(selected_node,
                                                 new_position,
                                                 set_position=True)
                    op.addOperation(node_op)
                op.push()
            else:
                for selected_node in selected_nodes:
                    world_position = selected_node.getWorldPosition()
                    new_position = world_position.set(
                        y=parsed_z + (world_position.y - bounding_box.bottom))
                    TranslateOperation(selected_node,
                                       new_position,
                                       set_position=True).push()
        self._controller.toolOperationStopped.emit(self)
Ejemplo n.º 6
0
    def getX(self) -> float:
        """Get the x-location of the selection bounding box center.

        :return: X location in mm.
        """
        if Selection.hasSelection():
            return float(Selection.getBoundingBox().center.x)
        return 0.0
Ejemplo n.º 7
0
    def getY(self) -> float:
        """Get the y-location of the selection bounding box center.

        :return: Y location in mm.
        """
        if Selection.hasSelection():
            # Note; The switching of z & y is intentional. We display z as up for the user,
            # But store the data in openGL space.
            return float(Selection.getBoundingBox().center.z)
        return 0.0
Ejemplo n.º 8
0
    def setX(self, x):
        bounding_box = Selection.getBoundingBox()

        op = GroupedOperation()
        for selected_node in Selection.getAllSelectedObjects():
            world_position = selected_node.getWorldPosition()
            new_position = world_position.set(x=float(x) + (world_position.x - bounding_box.center.x))
            node_op = TranslateOperation(selected_node, new_position, set_position = True)
            op.addOperation(node_op)
        op.push()
        self.operationStopped.emit(self)
Ejemplo n.º 9
0
    def setZ(self, z):
        bounding_box = Selection.getBoundingBox()

        op = GroupedOperation()
        for selected_node in Selection.getAllSelectedObjects():
            # Note: The switching of z & y is intentional. We display z as up for the user,
            # But store the data in openGL space.
            world_position = selected_node.getWorldPosition()
            new_position = world_position.set(y=float(z) + (world_position.y - bounding_box.bottom))
            node_op = TranslateOperation(selected_node, new_position, set_position = True)
            op.addOperation(node_op)
        op.push()
        self.operationStopped.emit(self)
Ejemplo n.º 10
0
    def getZ(self) -> float:
        """Get the z-location of the selection bounding box bottom

        The bottom is used as opposed to the center, because the biggest use
        case is to push the selection into the build plate.
        :return: Z location in mm.
        """
        # We want to display based on the bottom instead of the actual coordinate.
        if Selection.hasSelection():
            # Note; The switching of z & y is intentional. We display z as up for the user,
            # But store the data in openGL space.
            return float(Selection.getBoundingBox().bottom)
        return 0.0
Ejemplo n.º 11
0
    def setX(self, x):
        parsed_x = self._parseInt(x)
        bounding_box = Selection.getBoundingBox()

        op = GroupedOperation()
        if not Float.fuzzyCompare(parsed_x, float(bounding_box.center.x), DIMENSION_TOLERANCE):
            for selected_node in Selection.getAllSelectedObjects():
                world_position = selected_node.getWorldPosition()
                new_position = world_position.set(x=parsed_x + (world_position.x - bounding_box.center.x))
                node_op = TranslateOperation(selected_node, new_position, set_position = True)
                op.addOperation(node_op)
            op.push()
        self._controller.toolOperationStopped.emit(self)
Ejemplo n.º 12
0
    def setX(self, x):
        parsed_x = self._parseInt(x)
        bounding_box = Selection.getBoundingBox()

        op = GroupedOperation()
        if not Float.fuzzyCompare(parsed_x, float(bounding_box.center.x), DIMENSION_TOLERANCE):
            for selected_node in Selection.getAllSelectedObjects():
                world_position = selected_node.getWorldPosition()
                new_position = world_position.set(x=parsed_x + (world_position.x - bounding_box.center.x))
                node_op = TranslateOperation(selected_node, new_position, set_position = True)
                op.addOperation(node_op)
            op.push()
        self._controller.toolOperationStopped.emit(self)
Ejemplo n.º 13
0
    def setX(self, x):
        Benchmark.start("Moving object in X from {start} to {end}".format(start = self.getX(), end = x))
        parsed_x = self._parseInt(x)
        bounding_box = Selection.getBoundingBox()

        op = GroupedOperation()
        if not Float.fuzzyCompare(parsed_x, float(bounding_box.center.x), DIMENSION_TOLERANCE):
            for selected_node in self._getSelectedObjectsWithoutSelectedAncestors():
                world_position = selected_node.getWorldPosition()
                new_position = world_position.set(x=parsed_x + (world_position.x - bounding_box.center.x))
                node_op = TranslateOperation(selected_node, new_position, set_position = True)
                op.addOperation(node_op)
            op.push()
        self._controller.toolOperationStopped.emit(self)
Ejemplo n.º 14
0
    def setZ(self, z):
        parsed_z = self._parseInt(z)
        bounding_box = Selection.getBoundingBox()

        op = GroupedOperation()
        if not Float.fuzzyCompare(parsed_z, float(bounding_box.center.y), DIMENSION_TOLERANCE):
            for selected_node in Selection.getAllSelectedObjects():
                # Note: The switching of z & y is intentional. We display z as up for the user,
                # But store the data in openGL space.
                world_position = selected_node.getWorldPosition()
                new_position = world_position.set(y=parsed_z + (world_position.y - bounding_box.bottom))
                node_op = TranslateOperation(selected_node, new_position, set_position = True)
                op.addOperation(node_op)
            op.push()
        self._controller.toolOperationStopped.emit(self)
Ejemplo n.º 15
0
    def setZ(self, z):
        parsed_z = self._parseInt(z)
        bounding_box = Selection.getBoundingBox()

        op = GroupedOperation()
        if not Float.fuzzyCompare(parsed_z, float(bounding_box.center.y), DIMENSION_TOLERANCE):
            for selected_node in Selection.getAllSelectedObjects():
                # Note: The switching of z & y is intentional. We display z as up for the user,
                # But store the data in openGL space.
                world_position = selected_node.getWorldPosition()
                new_position = world_position.set(y=parsed_z + (world_position.y - bounding_box.bottom))
                node_op = TranslateOperation(selected_node, new_position, set_position = True)
                op.addOperation(node_op)
            op.push()
        self._controller.toolOperationStopped.emit(self)
Ejemplo n.º 16
0
    def setX(self, x):
        bounding_box = Selection.getBoundingBox()

        op = GroupedOperation()
        for selected_node in Selection.getAllSelectedObjects():
            new_position = selected_node.getWorldPosition()
            new_position.setY(
                float(y) + (new_position.x - bounding_box.center.x))

            node_op = TranslateOperation(selected_node,
                                         new_position,
                                         set_position=True)
            op.addOperation(node_op)
        op.push()
        self.operationStopped.emit(self)
Ejemplo n.º 17
0
    def setZ(self, z):
        Benchmark.start("Moving object in Z from {start} to {end}".format(start = self.getZ(), end = z))
        parsed_z = self._parseInt(z)
        bounding_box = Selection.getBoundingBox()

        op = GroupedOperation()
        if not Float.fuzzyCompare(parsed_z, float(bounding_box.bottom), DIMENSION_TOLERANCE):
            for selected_node in self._getSelectedObjectsWithoutSelectedAncestors():
                # Note: The switching of z & y is intentional. We display z as up for the user,
                # But store the data in openGL space.
                world_position = selected_node.getWorldPosition()
                new_position = world_position.set(y=parsed_z + (world_position.y - bounding_box.bottom))
                node_op = TranslateOperation(selected_node, new_position, set_position = True)
                op.addOperation(node_op)
            op.push()
        self._controller.toolOperationStopped.emit(self)
Ejemplo n.º 18
0
    def setY(self, y):
        bounding_box = Selection.getBoundingBox()

        op = GroupedOperation()
        for selected_node in Selection.getAllSelectedObjects():
            # Note; The switching of z & y is intentional. We display z as up for the user,
            # But store the data in openGL space.
            new_position = selected_node.getWorldPosition()
            new_position.setY(
                float(y) + (new_position.z - bounding_box.center.z))

            node_op = TranslateOperation(selected_node,
                                         new_position,
                                         set_position=True)
            op.addOperation(node_op)
        op.push()
        self.operationStopped.emit(self)
Ejemplo n.º 19
0
    def setX(self, x: str) -> None:
        parsed_x = self._parseInt(x)
        bounding_box = Selection.getBoundingBox()

        if not Float.fuzzyCompare(parsed_x, float(bounding_box.center.x), DIMENSION_TOLERANCE):
            selected_nodes = self._getSelectedObjectsWithoutSelectedAncestors()
            if len(selected_nodes) > 1:
                op = GroupedOperation()
                for selected_node in self._getSelectedObjectsWithoutSelectedAncestors():
                    world_position = selected_node.getWorldPosition()
                    new_position = world_position.set(x = parsed_x + (world_position.x - bounding_box.center.x))
                    node_op = TranslateOperation(selected_node, new_position, set_position = True)
                    op.addOperation(node_op)
                op.push()
            else:
                for selected_node in self._getSelectedObjectsWithoutSelectedAncestors():
                    world_position = selected_node.getWorldPosition()
                    new_position = world_position.set(x = parsed_x + (world_position.x - bounding_box.center.x))
                    TranslateOperation(selected_node, new_position, set_position = True).push()

        self._controller.toolOperationStopped.emit(self)
Ejemplo n.º 20
0
    def setY(self, y: str) -> None:
        parsed_y = self._parseInt(y)
        bounding_box = Selection.getBoundingBox()

        op = GroupedOperation()
        if not Float.fuzzyCompare(parsed_y, float(bounding_box.center.z),
                                  DIMENSION_TOLERANCE):
            for selected_node in self._getSelectedObjectsWithoutSelectedAncestors(
            ):
                # Note; The switching of z & y is intentional. We display z as up for the user,
                # But store the data in openGL space.
                world_position = selected_node.getWorldPosition()
                new_position = world_position.set(
                    z=parsed_y + (world_position.z - bounding_box.center.z))

                node_op = TranslateOperation(selected_node,
                                             new_position,
                                             set_position=True)
                op.addOperation(node_op)
            op.push()
        self._controller.toolOperationStopped.emit(self)
Ejemplo n.º 21
0
    def setY(self, y: str) -> None:
        parsed_y = self._parseInt(y)
        bounding_box = Selection.getBoundingBox()

        if not Float.fuzzyCompare(parsed_y, float(bounding_box.center.z), DIMENSION_TOLERANCE):
            selected_nodes = self._getSelectedObjectsWithoutSelectedAncestors()
            if len(selected_nodes) > 1:
                op = GroupedOperation()
                for selected_node in selected_nodes:
                    # Note; The switching of z & y is intentional. We display z as up for the user,
                    # But store the data in openGL space.
                    world_position = selected_node.getWorldPosition()
                    new_position = world_position.set(z = parsed_y + (world_position.z - bounding_box.center.z))
                    node_op = TranslateOperation(selected_node, new_position, set_position = True)
                    op.addOperation(node_op)
                op.push()
            else:
                for selected_node in selected_nodes:
                    world_position = selected_node.getWorldPosition()
                    new_position = world_position.set(z = parsed_y + (world_position.z - bounding_box.center.z))
                    TranslateOperation(selected_node, new_position, set_position = True).push()

        self._controller.toolOperationStopped.emit(self)
Ejemplo n.º 22
0
 def getY(self) -> float:
     if Selection.hasSelection():
         # Note; The switching of z & y is intentional. We display z as up for the user,
         # But store the data in openGL space.
         return float(Selection.getBoundingBox().center.z)
     return 0.0
Ejemplo n.º 23
0
 def getX(self) -> float:
     if Selection.hasSelection():
         return float(Selection.getBoundingBox().center.x)
     return 0.0
    def _fitSelection() -> None:
        camera = SpaceMouseTool._scene.getActiveCamera()
        if not camera or not camera.isEnabled():
            Logger.log("d", "No camera available")
            return

        if not Selection.hasSelection():
            Logger.log("d", "Nothing selected to fit")
            return

        aabb = Selection.getBoundingBox()
        minAabb = aabb.minimum  # type: Vector
        maxAabb = aabb.maximum  # type: Vector
        centerAabb = aabb.center  # type: Vector

        # get center in viewspace:
        viewMatrix = camera.getInverseWorldTransformation()
        centerInViewSpace = homogenize(
            np.dot(viewMatrix.getData(), np.append(centerAabb.getData(), 1)))
        # translate camera in xy-plane such that it is looking on the center
        centerInViewSpace[2] = 0
        centerInViewSpace = Vector(data=centerInViewSpace)
        camera.translate(centerInViewSpace)

        if camera.isPerspective():
            # compute the smaller of the two field of views
            aspect = camera.getViewportWidth() / camera.getViewportHeight()
            halfFovY = math.radians(
                30) / 2.  # from Camera.py _updatePerspectiveMarix
            halfFovX = math.atan(aspect * math.tan(halfFovY))
            halfFov = min(halfFovX, halfFovY)

            # radius of the bounding sphere containing the bounding box
            boundingSphereRadius = (centerAabb - minAabb).length()

            # compute distance of camera to center
            # (sin, as we use a point tangential to the bounding sphere)
            distCamCenter = boundingSphereRadius / math.sin(halfFov)

            # unit vector pointing from center to camera
            centerToCam = (camera.getWorldPosition() - centerAabb).normalized()

            # compute new position for camera
            newCamPos = centerAabb + centerToCam * distCamCenter

            camera.setPosition(newCamPos)
        else:
            minX = None
            maxX = None
            minY = None
            maxY = None
            for x in [minAabb.x, maxAabb.x]:
                for y in [minAabb.y, maxAabb.y]:
                    for z in [minAabb.z, maxAabb.z]:
                        # get corner of aabb in view space
                        cornerInViewSpace = homogenize(
                            np.dot(viewMatrix.getData(), np.array([x, y, z,
                                                                   1])))
                        cornerInViewSpace = Vector(data=cornerInViewSpace)
                        minX = cornerInViewSpace.x if minX is None\
                            else min(minX, cornerInViewSpace.x)
                        maxX = cornerInViewSpace.x if maxX is None\
                            else max(maxX, cornerInViewSpace.x)
                        minY = cornerInViewSpace.y if minY is None\
                            else min(minY, cornerInViewSpace.y)
                        maxY = cornerInViewSpace.y if maxY is None\
                            else max(maxY, cornerInViewSpace.y)
            widthWithBorder = (1 + 2 * SpaceMouseTool._fitBorderPercentage) * (
                maxX - minX)
            heightWithBorder = (
                1 + 2 * SpaceMouseTool._fitBorderPercentage) * (maxY - minY)

            # set zoom factor in such a way, that the width or height with border fills the width
            # or height of the viewport, respectively
            zoomFactorHor = widthWithBorder / 2. / camera.getViewportWidth(
            ) - 0.5
            zoomFactorVer = heightWithBorder / 2. / camera.getViewportHeight(
            ) - 0.5

            # use max as zoom factor get more negative if we zoom into the scene
            zoomFactor = max(zoomFactorHor, zoomFactorVer)
            camera.setZoomFactor(zoomFactor)
Ejemplo n.º 25
0
 def getY(self):
     if Selection.hasSelection():
         # Note; The switching of z & y is intentional. We display z as up for the user,
         # But store the data in openGL space.
         return float(Selection.getBoundingBox().center.z)
     return 0.0
Ejemplo n.º 26
0
 def getX(self):
     if Selection.hasSelection():
         return float(Selection.getBoundingBox().center.x)
     return 0.0