Beispiel #1
0
def __readTemplate(stream, instructions):

    filename = str(stream.readQString())
    if stream.licFileVersion >= 15:
        TemplatePage.separatorsVisible = stream.readBool()

    # Read in the entire abstractPart dictionary
    global partDict, colorDict
    colorDict = instructions.colorDict
    partDict = {}
    for unused in __readPartDictionary(stream, instructions):
        pass

    submodelPart = __readSubmodel(stream, None)
    template = __readPage(stream, instructions.mainModel, instructions, submodelPart)
    template.submodelPart = submodelPart

    if stream.licFileVersion >= 12:

        class T(object):
            pass

        t = template.staticInfo = T()
        t.page, t.csi, t.pli, t.smp = T(), T(), T(), T()
        __readStaticInfo(stream, t.page, t.csi, t.pli, t.smp)

    if stream.licFileVersion >= 5:
        values = []
        for unused in range(stream.readInt32()):
            values.append(stream.readFloat())
        LicGLHelpers.setLightParameters(*values)

    for part in template.submodelPart.parts:
        if partDict.has_key(part.filename):
            part.abstractPart = partDict[part.filename]
        else:
            part.abstractPart = AbstractPart(part.filename)

        template.steps[0].csi.addPart(part)

    for abstractPart in partDict.values():
        if abstractPart.glDispID == LicGLHelpers.UNINIT_GL_DISPID:
            abstractPart.createGLDisplayList()

    for glItem in template.glItemIterator():
        if hasattr(glItem, "createGLDisplayList"):
            glItem.createGLDisplayList()

    template.submodelPart.createGLDisplayList()
    template.submodelItem.setAbstractPart(template.submodelPart)
    template.postLoadInit(filename)
    return template
Beispiel #2
0
def __readTemplate(stream, instructions):

    filename = str(stream.readQString())
    if stream.licFileVersion >= 15:
        TemplatePage.separatorsVisible = stream.readBool()

    # Read in the entire abstractPart dictionary
    global partDict, colorDict
    colorDict = instructions.colorDict
    partDict = {}
    for unused in __readPartDictionary(stream, instructions):
        pass

    submodelPart = __readSubmodel(stream, None)
    template = __readPage(stream, instructions.mainModel, instructions, submodelPart)
    template.submodelPart = submodelPart

    if stream.licFileVersion >= 12:
        class T(object):
            pass
        t = template.staticInfo = T()
        t.page, t.csi, t.pli, t.smp = T(), T(), T(), T()
        __readStaticInfo(stream, t.page, t.csi, t.pli, t.smp)

    if stream.licFileVersion >= 5:
        values = []
        for unused in range(stream.readInt32()):
            values.append(stream.readFloat())
        LicGLHelpers.setLightParameters(*values)

    for part in template.submodelPart.parts:
        if partDict.has_key(part.filename):
            part.abstractPart = partDict[part.filename]
        else:
            part.abstractPart = AbstractPart(part.filename)

        template.steps[0].csi.addPart(part)

    for abstractPart in partDict.values():
        if abstractPart.glDispID == LicGLHelpers.UNINIT_GL_DISPID:
            abstractPart.createGLDisplayList()

    for glItem in template.glItemIterator():
        if hasattr(glItem, 'createGLDisplayList'):
            glItem.createGLDisplayList()

    template.submodelPart.createGLDisplayList()
    template.submodelItem.setAbstractPart(template.submodelPart)
    template.postLoadInit(filename)
    return template
Beispiel #3
0
 def changeLighting(self):
     parentWidget = self.scene().views()[0]
     dialog = LicDialogs.LightingDialog(parentWidget,
                                        *LicGLHelpers.getLightParameters())
     parentWidget.connect(dialog, SIGNAL("changeValues"),
                          self.changeLightValues)
     parentWidget.connect(dialog, SIGNAL("acceptValues"),
                          self.acceptLightValues)
     dialog.exec_()
Beispiel #4
0
    def initGLDimension(self, part, glContext):

        glContext.makeCurrent()
        for size in [512, 1024, 2048]:
            # Create a new buffer tied to the existing GLWidget, to get access to its display lists
            pBuffer = QGLPixelBuffer(size, size, LicGLHelpers.getGLFormat(), glContext)
            pBuffer.makeCurrent()

            # Render CSI and calculate its size
            if part.initSize(size, pBuffer):
                break
        glContext.makeCurrent()
Beispiel #5
0
    def initGLDimension(self, part, glContext):

        glContext.makeCurrent()
        for size in [512, 1024, 2048]:
            # Create a new buffer tied to the existing GLWidget, to get access to its display lists
            pBuffer = QGLPixelBuffer(size, size, LicGLHelpers.getGLFormat(),
                                     glContext)
            pBuffer.makeCurrent()

            # Render CSI and calculate its size
            if part.initSize(size, pBuffer):
                break
        glContext.makeCurrent()
Beispiel #6
0
def __writeTemplate(stream, template):

    # Build part dictionary, since it's not implicitly stored anywhere
    partDictionary = {}
    for part in template.steps[0].csi.getPartList():
        if part.abstractPart.filename not in partDictionary:
            part.abstractPart.buildSubAbstractPartDict(partDictionary)

    stream << QString(os.path.basename(template.filename))
    stream.writeBool(template.separatorsVisible)
    __writePartDictionary(stream, partDictionary)
    __writeSubmodel(stream, template.submodelPart)
    __writePage(stream, template)

    __writeStaticInfo(stream)  # Need to save PageSize, PLI|CSI size, etc, so we can apply these on template load

    values = LicGLHelpers.getLightParameters()
    stream.writeInt32(len(values))
    for v in values:
        stream.writeFloat(v)
Beispiel #7
0
def __writeTemplate(stream, template):

    # Build part dictionary, since it's not implicitly stored anywhere
    partDictionary = {}
    for part in template.steps[0].csi.getPartList():
        if part.abstractPart.filename not in partDictionary:
            part.abstractPart.buildSubAbstractPartDict(partDictionary)

    stream << QString(os.path.basename(template.filename))
    stream.writeBool(template.separatorsVisible)
    __writePartDictionary(stream, partDictionary)
    __writeSubmodel(stream, template.submodelPart)
    __writePage(stream, template)

    __writeStaticInfo(stream)  # Need to save PageSize, PLI|CSI size, etc, so we can apply these on template load

    values = LicGLHelpers.getLightParameters()
    stream.writeInt32(len(values))
    for v in values:
        stream.writeFloat(v)
Beispiel #8
0
    def drawItems(self, painter, items, options, widget):

        LicGLHelpers.clear([0.62, 0.62, 0.65, 1.0])

        # First draw all items that are not annotations
        if self.renderMode == 'full' or self.renderMode == 'background':
            for i, item in enumerate(items):
                if item.isVisible() and (not hasattr(item, 'isAnnotation') or not item.isAnnotation):
                    self.drawOneItem(painter, item, options[i], widget)

        if widget and self.renderMode == 'full':

            # Build list of pages to be drawn (if any)
            rect = QRectF(self.views()[0].mapToScene(QPoint()), QSizeF(widget.size()) / self.scaleFactor)
            pagesToDraw = []
            for page in self.pages:
                if page.isVisible() and rect.intersects(page.rect().translated(page.pos())):
                    pagesToDraw.append(page)

            if pagesToDraw:
                # Setup the GL items to be drawn & the necessary context
                painter.beginNativePainting()
                LicGLHelpers.initFreshContext(False)
    
                # Draw all GL items
                for page in pagesToDraw:
                    page.drawGLItems(rect)
    
                LicGLHelpers.setupForQtPainter()  # Reset all GL lighting, so that subsequent drawing is not affected
                painter.endNativePainting()
            
        # Draw all annotation
        if self.renderMode == 'full' or self.renderMode == 'foreground':
            for i, item in enumerate(items):
                if item.isVisible() and (hasattr(item, 'isAnnotation') and item.isAnnotation):
                    self.drawOneItem(painter, item, options[i], widget)
    def setItemtoMove(self, part=None):
        self.destItem = None
        self._item = part
        step = part
        while step and not isinstance(step, Step):
            step = step.parent()
        self._step.setText(step.data(Qt.DisplayRole))
        self._page.setText(step.parentItem().data(Qt.DisplayRole))
        self._warning.clear()
        if part:
            pItem = None
            if step and step.hasPLI():
                for pliItem in step.pli.pliItems:
                    if pliItem.abstractPart.filename == part.abstractPart.filename:
                        pItem = pliItem
                        break

            sRect = self._thumbnail.scene().sceneRect()
            if isinstance(pItem, (Part, PLIItem)):
                a = pItem.abstractPart
                filename = os.path.join(config.grayscalePath(), os.path.splitext(a.filename)[0] + ".png").lower()
                if not os.path.exists(filename):
                    pRect = pItem.sceneBoundingRect().toRect()
                    wt = Page.PageSize.width()
                    ht = Page.PageSize.height()
                    mx = int(PLI.margin.x() / 2)
                    bufferManager = LicGLHelpers.FrameBufferManager(wt, ht)
                    try:
                        bufferManager.bindMSFB()
                        LicGLHelpers.initFreshContext(True)

                        step.parentItem().drawGLItemsOffscreen(QRectF(0, 0, wt, ht), 1.0)
                        bufferManager.blitMSFB()
                        temp_data = bufferManager.readFB()
                        temp_cord = (
                            pRect.left() - mx,
                            pRect.top() - mx,
                            a.width + pRect.left() + mx,
                            a.height + pRect.top() + mx,
                        )
                        temp_name = tempfile.TemporaryFile().name + ".png".lower()
                        temp = Image.fromstring("RGBA", (wt, ht), temp_data)
                        temp = temp.transpose(Image.FLIP_TOP_BOTTOM)
                        temp = temp.crop(temp_cord)
                        temp.save(temp_name)
                    finally:
                        image = QImage(temp_name, "LA")
                        # convertToGrayscale
                        for i in range(0, image.width()):
                            for j in range(0, image.height()):
                                pix = image.pixel(i, j)
                                if pix > 0:
                                    color = qGray(pix)
                                    image.setPixel(i, j, qRgb(color, color, color))
                        # saveResult
                        image.save(filename, "PNG")
                        # cleanUp
                        bufferManager.cleanup()
                        os.remove(temp_name)
                else:
                    image = QImage(filename, "LA")
                image = image.scaledToHeight(sRect.height(), Qt.SmoothTransformation)
            else:
                image = QImage(sRect.width(), sRect.height(), QImage.Format_Mono)
                painter = QPainter(image)
                painter.fillRect(sRect, Qt.white)
                painter.setFont(QFont("Helvetica [Cronyx]", 10, QFont.Bold))
                painter.drawLine(1, 1, sRect.width() - 1, sRect.height() - 1)
                painter.drawLine(sRect.width() - 1, 1, 1, sRect.height() - 1)
                painter.drawText(sRect, Qt.TextSingleLine | Qt.AlignVCenter, self._noPLIText)
                painter.end()

            self._thumbnail.setPixmap(QPixmap.fromImage(image))

        if not self.isVisible():
            self.show()
    def setItemtoMove(self, part=None):
        self.destItem = None
        self._item = part
        step = part
        while step and not isinstance(step, Step):
            step = step.parent()
        self._step.setText(step.data(Qt.DisplayRole))
        self._page.setText(step.parentItem().data(Qt.DisplayRole))
        self._warning.clear()
        if part:
            pItem = None
            if step and step.hasPLI():
                for pliItem in step.pli.pliItems:
                    if pliItem.abstractPart.filename == part.abstractPart.filename:
                        pItem = pliItem
                        break

            sRect = self._thumbnail.scene().sceneRect()
            if isinstance(pItem, (Part, PLIItem)):
                a = pItem.abstractPart
                filename = os.path.join(
                    config.grayscalePath(),
                    os.path.splitext(a.filename)[0] + ".png").lower()
                if not os.path.exists(filename):
                    pRect = pItem.sceneBoundingRect().toRect()
                    wt = Page.PageSize.width()
                    ht = Page.PageSize.height()
                    mx = int(PLI.margin.x() / 2)
                    bufferManager = LicGLHelpers.FrameBufferManager(wt, ht)
                    try:
                        bufferManager.bindMSFB()
                        LicGLHelpers.initFreshContext(True)

                        step.parentItem().drawGLItemsOffscreen(
                            QRectF(0, 0, wt, ht), 1.0)
                        bufferManager.blitMSFB()
                        temp_data = bufferManager.readFB()
                        temp_cord = (pRect.left() - mx, pRect.top() - mx,
                                     a.width + pRect.left() + mx,
                                     a.height + pRect.top() + mx)
                        temp_name = tempfile.TemporaryFile(
                        ).name + ".png".lower()
                        temp = Image.fromstring("RGBA", (wt, ht), temp_data)
                        temp = temp.transpose(Image.FLIP_TOP_BOTTOM)
                        temp = temp.crop(temp_cord)
                        temp.save(temp_name)
                    finally:
                        image = QImage(temp_name, "LA")
                        #convertToGrayscale
                        for i in range(0, image.width()):
                            for j in range(0, image.height()):
                                pix = image.pixel(i, j)
                                if pix > 0:
                                    color = qGray(pix)
                                    image.setPixel(i, j,
                                                   qRgb(color, color, color))
                        #saveResult
                        image.save(filename, "PNG")
                        #cleanUp
                        bufferManager.cleanup()
                        os.remove(temp_name)
                else:
                    image = QImage(filename, "LA")
                image = image.scaledToHeight(sRect.height(),
                                             Qt.SmoothTransformation)
            else:
                image = QImage(sRect.width(), sRect.height(),
                               QImage.Format_Mono)
                painter = QPainter(image)
                painter.fillRect(sRect, Qt.white)
                painter.setFont(QFont("Helvetica [Cronyx]", 10, QFont.Bold))
                painter.drawLine(1, 1, sRect.width() - 1, sRect.height() - 1)
                painter.drawLine(sRect.width() - 1, 1, 1, sRect.height() - 1)
                painter.drawText(sRect, Qt.TextSingleLine | Qt.AlignVCenter,
                                 self._noPLIText)
                painter.end()

            self._thumbnail.setPixmap(QPixmap.fromImage(image))

        if not self.isVisible():
            self.show()
Beispiel #11
0
 def changeLightValues(self, newValues):
     LicGLHelpers.setLightParameters(*newValues)
     self.update()
Beispiel #12
0
 def changeLighting(self):
     parentWidget = self.scene().views()[0]
     dialog = LicDialogs.LightingDialog(parentWidget, *LicGLHelpers.getLightParameters())
     parentWidget.connect(dialog, SIGNAL("changeValues"), self.changeLightValues)
     parentWidget.connect(dialog, SIGNAL("acceptValues"), self.acceptLightValues)
     dialog.exec_()
Beispiel #13
0
 def changeLightValues(self, newValues):
     LicGLHelpers.setLightParameters(*newValues)
     self.update()