def do_snap(self,gfile):
     img = Snapshot.snapshot(width = 200, height = 200).scaled(200,200,Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
     outdata = ""
     outdata = outdata + self.overseek()
     outdata = outdata + "; bigtree thumbnail end\r\n\r\n"
     outdata = outdata + self.material_usage()
     
     fh = QFile(gfile)
     fh.open(QIODevice.ReadOnly)
     stream = QTextStream(fh)
     stream.setCodec(CODEC)
     fg = stream.readAll() + "\r\n"
     if self.extruder_M2O() == True:
         fg = fg.replace("M104 T0",";M104 T0")
         fg = fg.replace("M104 T1",";M104 T1")
         fg = fg.replace("M109 T0",";M109 T0")
         fg = fg.replace("M109 T1",";M109 T1")
     fh.close()
     bigtree3dfile = os.path.splitext(gfile)[0]+"[Bigtree].gcode"
     fh = QFile(bigtree3dfile)
     fh.open(QIODevice.WriteOnly)
     stream = QTextStream(fh)
     stream.setCodec(CODEC)
     stream << outdata
     stream << fg
     fh.close()
     os.remove(gfile)
Beispiel #2
0
 def _create_thumbnail(self, *args):
     Logger.log("d", "Creating Prusa thumbnail ...")
     try:
         self._thumbnail = Snapshot.snapshot(width=300, height=300)
     except Exception:
         Logger.logException("w", "Failed to create thumbnail")
         self._thumbnail = None
Beispiel #3
0
 def _createSnapshot(self, *args):
     Logger.log("i", "Creating chitu thumbnail image ...")
     try:
         self._snapshot = Snapshot.snapshot(width=300, height=300)
     except Exception:
         Logger.logException("w", "Failed to create snapshot image")
         self._snapshot = None
Beispiel #4
0
 def _createSnapshot(self, *args):
     # must be called from the main thread because of OpenGL
     Logger.log("d", "Creating thumbnail image...")
     try:
         self._snapshot = Snapshot.snapshot(width=300, height=300)
     except Exception:
         Logger.logException("w", "Failed to create snapshot image")
         self._snapshot = None  # Failing to create thumbnail should not fail creation of UFP
Beispiel #5
0
 def _createSnapshot(self, *args):
     Logger.log("i", "Creating thumbnail image ...")
     try:
         self._snapshot = Snapshot.snapshot(width=60, height=60)
         Logger.log("i", "self._snapshot => ", dir(self._snapshot))
     except Exception:
         Logger.logException("w", "Failed to create snapshot image")
         self._snapshot = None
Beispiel #6
0
 def _create_snapshot(self, width, height):
     # must be called from the main thread because of OpenGL
     Logger.log("d", "Creating thumbnail image...")
     try:
         snapshot = Snapshot.snapshot(width = width, height = height)
         return snapshot
     except Exception:
         Logger.logException("w", "Failed to create snapshot image")
         return None
Beispiel #7
0
 def _createSnapshot(self, *args):
     # must be called from the main thread because of OpenGL
     Logger.log("d", "Creating thumbnail image...")
     try:
         # Screen seems to be 720px wide, but not fully used to show preview so snapshot at +/- 600px
         self._snapshot = Snapshot.snapshot(width=600, height=600)
     except Exception:
         Logger.logException("w", "Failed to create snapshot image")
         self._snapshot = None  # Failing to create thumbnail should not fail creation of UFP
Beispiel #8
0
 def _createSnapshot(self) -> None:
     self._snapshot = None
     if not CuraApplication.getInstance().isVisible:
         Logger.log("w", "Can't create snapshot when renderer not initialized.")
         return
     Logger.log("i", "Creating thumbnail image (just before slice)...")
     try:
         self._snapshot = Snapshot.snapshot(width = 300, height = 300)
     except:
         Logger.logException("w", "Failed to create snapshot image")
         self._snapshot = None  # Failing to create thumbnail should not fail creation of UFP
Beispiel #9
0
    def _createSnapshot(self):
        Logger.log("d", "Creating thumbnail image...")
        if not CuraApplication.getInstance().isVisible:
            Logger.log("w", "Can't create snapshot when renderer not initialized.")
            return None
        try:
            snapshot = Snapshot.snapshot(width = 300, height = 300)
        except:
            Logger.logException("w", "Failed to create snapshot image")
            return None

        return snapshot
def render_scene():
    scene = Application.getInstance().getController().getScene()
    active_camera = scene.getActiveCamera()
    render_width, render_height = active_camera.getWindowSize()
    render_width = int(render_width)
    render_height = int(render_height)
    Logger.log("d",
               f"Found active camera with {render_width=} {render_height=}")

    QCoreApplication.processEvents()

    preview_pass = PreviewPass(render_width, render_height)
    fovy = 30
    satisfied = False
    zooms = 0
    while not satisfied and zooms < 5:
        preview_pass.render()
        pixel_output = preview_pass.getOutput().convertToFormat(
            QImage.Format_ARGB32)
        # pixel_output.save(os.path.expanduser(f"~/Downloads/foo-a-zoom-{zooms}.png"), "PNG")

        min_x, max_x, min_y, max_y = Snapshot.getImageBoundaries(pixel_output)
        size = max((max_x - min_x) / render_width,
                   (max_y - min_y) / render_height)
        if size > 0.5 or satisfied:
            satisfied = True
        else:
            # make it big and allow for some empty space around
            zooms += 1
            fovy *= 0.75
            projection_matrix = Matrix()
            projection_matrix.setPerspective(fovy,
                                             render_width / render_height, 1,
                                             500)
            active_camera.setProjectionMatrix(projection_matrix)

        Logger.log(
            "d",
            f"Rendered thumbnail: {zooms=}, {size=}, {min_x=}, {max_x=}, {min_y=}, {max_y=}, {fovy=}"
        )

    # crop to content
    pixel_output = pixel_output.copy(min_x, min_y, max_x - min_x,
                                     max_y - min_y)
    Logger.log(
        "d",
        f"Cropped thumbnail to {min_x}, {min_y}, {max_x - min_x}, {max_y - min_y}."
    )
    # pixel_output.save(os.path.expanduser("~/Downloads/foo-b-cropped.png"), "PNG")

    Logger.log("d", "Successfully rendered scene.")
    return pixel_output
 def overread(self,msize):
     moutdata = ""
     img = Snapshot.snapshot(width = msize.width(), height = msize.height()).scaled(msize.width(),msize.height(),Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
     moutdata = moutdata + ";"+(hex(msize.width())[2:]).rjust(4,'0')+(hex(msize.height())[2:]).rjust(4,'0')+"\r\n"
     pos = QSize(0,0)
     for ypos in range(0,img.height()):
         qrgb = ";"
         for xpos in range(0,img.width()):
             data = img.pixel(xpos,ypos)
             pos.setWidth(pos.width()+1)
             qrgb = qrgb + (hex(((data & 0x00F80000) >> 8 ) | ((data & 0x0000FC00) >> 5 ) | ((data & 0x000000F8) >> 3 ))[2:]).rjust(4,'0')
         pos.setWidth(0)
         pos.setHeight(pos.height()+1)
         moutdata = moutdata + qrgb + "\r\n"
     return moutdata
 def do_snap(self,gfile):
     m0 = Snapshot.snapshot(width = 900, height = 900)
     if m0 is not None:  #if not isinstance(m0,NoneType): #NoneType
         m1 = m0.scaled(150,150,Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
         m2 = m0.scaled(42,42,Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
         if m1:
             hd = []
             ds = self.trans(m2,42,42)
             db = self.trans(m1,150,150)
 
             size0 = len(ds)
             size1 = len(db)
             size2 = os.path.getsize(gfile)
 
             offset = 0
             hd.append(1)
             offset = 25
             hd.extend(i4b(offset))
             hd.extend(i4b(size0))
             offset += size0
             hd.extend(i4b(offset))
             hd.extend(i4b(size1))
             offset += size1
             hd.extend(i4b(offset))
             hd.extend(i4b(size2))
 
             fg = []
             f = open(gfile, 'rb+')
             fg = f.read()
             f.close()
 
             gjz = os.path.splitext(gfile)[0]+".gjz"
             f = open(gjz, 'wb+')
             f.write(bytes(hd))
             f.write(bytes(ds))
             f.write(bytes(db))
             f.write(fg)
             f.close()
             #os.remove(gfile)
         FlyingBearStage.FlyingBearStageIns.setUploadFileNameUSB(gjz)
     else:
         FlyingBearStage.FlyingBearStageIns.setUploadFileNameUSB(gfile)            
     #FlyingBearStage.FlyingBearStageIns.setUploadFileName(gjz)
     CuraApplication.getInstance().getController().setActiveStage("PrepareStage") #setActiveStage("PrepareStage")
     #sleep(1)
     Logger.log("d", "NAME %s",FlyingBearStage.FlyingBearStageIns.getPluginId())
     CuraApplication.getInstance().getController().setActiveStage(FlyingBearStage.FlyingBearStageIns.getPluginId())
 def _createSnapshot(self, g, *args):
     Logger.log("i", "Creating thumbnail image ...")
     try:
         # Convert the image to grayscale, and back to 24bits so it renders properly
         # in printer.
         img = Snapshot.snapshot(width=80, height=60)
         img = img.convertToFormat(QtGui.QImage.Format_Grayscale8)
         img = img.convertToFormat(QtGui.QImage.Format_RGB666)
         # Converts the image into BMP byte array.
         arr = QtCore.QByteArray()
         buff = QtCore.QBuffer(arr)
         buff.open(QtCore.QIODevice.WriteOnly)
         img.save(buff, format="BMP")
         g.bmp = arr.data()
     except Exception:
         Logger.logException("w", "Failed to create snapshot image")
         g.bmp = gx._SAMPLE_BMP
    def _generateSnapshot(self) -> Optional[str]:
        '''Grabs the snapshot from the Cura Backend if one exists and returns it as a buffer.'''
        try:
            Logger.log("i", "Generating Snapshot")
            # Attempt to get the existing snapshot, if it exists (Cura 4.9 and above):
            backend = CuraApplication.getInstance().getBackend()
            snapshot = None if getattr(
                backend, "getLatestSnapshot", None) is None else backend.getLatestSnapshot()

            if snapshot is None:
                Logger.log(
                    "i", "No snapshot from backend, generate snapshot ourselves.")
                # Try to generate a snapshot ourselves (for Cura 4.8 and before, but is not reliable (I think due to threading))
                try:
                    from cura.Snapshot import Snapshot

                    snapshot = Snapshot.snapshot(width=300, height=300)
                except:
                    Logger.log("e", "Failed to create snapshot image")
                    return None

            if snapshot:
                Logger.log("i", "Snapshot Found")

                thumbnail_buffer = QBuffer()
                thumbnail_buffer.open(QBuffer.ReadWrite)
                snapshot.save(thumbnail_buffer, "PNG")

                encodedSnapshot = thumbnail_buffer.data(
                ).toBase64().data().decode("utf-8")

                thumbnail_buffer.close()

                return encodedSnapshot
            else:
                Logger.log("i", "No Snapshot Found")
                return None

        except Exception:
            Logger.logException(
                "e", "Exception raised while saving snapshot")
            return None
 def do_snap(self,gfile):
     img = Snapshot.snapshot(width = 200, height = 200).scaled(200,200,Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
     outdata = ""
     outdata = outdata + self.overseek()
     outdata = outdata + "; bigtree thumbnail end\r\n\r\n"
     fh = QFile(gfile)
     fh.open(QIODevice.ReadOnly)
     stream = QTextStream(fh)
     stream.setCodec(CODEC)
     # lino = 0
     fg = stream.readAll() + "\r\n"
     fh.close()
     bigtree3dfile = os.path.splitext(gfile)[0]+"[Bigtree].gcode"
     fh = QFile(bigtree3dfile)
     fh.open(QIODevice.WriteOnly)
     stream = QTextStream(fh)
     stream.setCodec(CODEC)
     stream << outdata
     stream << fg
     fh.close()
     os.remove(gfile)
    def do_snap(self, gfile):
        m0 = Snapshot.snapshot(width=900, height=900)
        m1 = m0.scaled(150, 150, Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
        m2 = m0.scaled(42, 42, Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
        if m1:
            hd = []
            ds = self.trans(m2, 42, 42)
            db = self.trans(m1, 150, 150)

            size0 = len(ds)
            size1 = len(db)
            size2 = os.path.getsize(gfile)

            offset = 0
            hd.append(1)
            offset = 25
            hd.extend(i4b(offset))
            hd.extend(i4b(size0))
            offset += size0
            hd.extend(i4b(offset))
            hd.extend(i4b(size1))
            offset += size1
            hd.extend(i4b(offset))
            hd.extend(i4b(size2))

            fg = []
            f = open(gfile, 'rb+')
            fg = f.read()
            f.close()

            gjz = os.path.splitext(gfile)[0] + ".gjz"
            f = open(gjz, 'wb+')
            f.write(bytes(hd))
            f.write(bytes(ds))
            f.write(bytes(db))
            f.write(fg)
            f.close()
            #os.remove(gfile)

        FlyingBearExtension.FlyingBearExtensionIns.showPluginMainWindow(gjz)
Beispiel #17
0
    def create_snapshot(self, size):

        # Take a snapshot of given size
        snapshot = Snapshot.snapshot(width=size[0], height=size[1])

        # Used for debugging
        #snapshot.save(os.path.dirname(__file__) + "/test.png")

        # Smapshot gcode
        gcode = ''

        # Iterate all of the image  pixels
        for y in range(snapshot.height()):
            for x in range(snapshot.width()):

                # Take pixel data
                pixel = snapshot.pixelColor(x, y)

                # Convert to 16-bit (2-byte) -encoded image
                rgb16 = (pixel.red() >> 3 << 11) | (
                    pixel.green() >> 2 << 5) | (pixel.blue() >> 3)

                # Convert pixel data into hex values
                rgb16_hex = "{:04x}".format(rgb16)

                # Change rndianess to little-endian
                rgb16_hex_le = rgb16_hex[2:4] + rgb16_hex[0:2]

                # Add resulting values to a gcode
                gcode += rgb16_hex_le

            # Add a G-code code
            gcode += '\rM10086 ;'

        # Add new line break
        gcode += '\r'

        # Return resulting G-code
        return gcode
Beispiel #18
0
 def _createSnapshot(self, *args):
     # must be called from the main thread because of OpenGL
     Logger.log("d", "Creating thumbnail image...")
     self._snapshot = Snapshot.snapshot(width = 300, height = 300)
Beispiel #19
0
def take_screenshot():
    cut_image = Snapshot.snapshot(width = 900, height = 900)
    return cut_image
Beispiel #20
0
 def _createSnapshot(self, *args):
     # must be called from the main thread because of OpenGL
     Logger.log("d", "Creating thumbnail image...")
     self._snapshot = Snapshot.snapshot(width=300, height=300)
 def do_snap(self,gfile):
     img = Snapshot.snapshot(width = 200, height = 200).scaled(200,200,Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
 def _createSnapshot(self, width, height):
     Logger.log("d", "Creating thumbnail image...")
     try:
         return Snapshot.snapshot(width, height)
     except Exception:
         Logger.logException("w", "Failed to create snapshot image")