예제 #1
0
파일: pdf.py 프로젝트: jonntd/eddy
 def run(self, path):
     """
     Perform PDF document generation.
     :type path: str
     """
     shape = self.diagram.visibleRect(margin=20)
     if shape:
         LOGGER.info('Exporting diagram %s to %s', self.diagram.name, path)
         printer = QtPrintSupport.QPrinter(
             QtPrintSupport.QPrinter.HighResolution)
         printer.setOutputFormat(QtPrintSupport.QPrinter.PdfFormat)
         printer.setOutputFileName(path)
         printer.setPaperSize(QtPrintSupport.QPrinter.Custom)
         printer.setPageSize(
             QtGui.QPageSize(QtCore.QSizeF(shape.width(), shape.height()),
                             QtGui.QPageSize.Point))
         painter = QtGui.QPainter()
         if painter.begin(printer):
             # TURN CACHING OFF
             for item in self.diagram.items():
                 if item.isNode() or item.isEdge():
                     item.setCacheMode(AbstractItem.NoCache)
             # RENDER THE DIAGRAM IN THE PAINTER
             self.diagram.render(painter, source=shape)
             # TURN CACHING ON
             for item in self.diagram.items():
                 if item.isNode() or item.isEdge():
                     item.setCacheMode(AbstractItem.DeviceCoordinateCache)
             # COMPLETE THE EXPORT
             painter.end()
             # OPEN THE DOCUMENT
             openPath(path)
예제 #2
0
 def run(self, path):
     """
     Perform PDF document generation.
     :type path: str
     """
     shape = self.diagram.visibleRect(margin=20)
     if shape:
         LOGGER.info("Exporting diagram %s to %s", self.diagram.name, path)
         printer = QtPrintSupport.QPrinter(QtPrintSupport.QPrinter.HighResolution)
         printer.setOutputFormat(QtPrintSupport.QPrinter.PdfFormat)
         printer.setOutputFileName(path)
         printer.setPaperSize(QtPrintSupport.QPrinter.Custom)
         printer.setPageSize(QtGui.QPageSize(QtCore.QSizeF(shape.width(), shape.height()), QtGui.QPageSize.Point))
         painter = QtGui.QPainter()
         if painter.begin(printer):
             # TURN CACHING OFF
             for item in self.diagram.items():
                 if item.isNode() or item.isEdge():
                     item.setCacheMode(AbstractItem.NoCache)
             # RENDER THE DIAGRAM IN THE PAINTER
             self.diagram.render(painter, source=shape)
             # TURN CACHING ON
             for item in self.diagram.items():
                 if item.isNode() or item.isEdge():
                     item.setCacheMode(AbstractItem.DeviceCoordinateCache)
             # COMPLETE THE EXPORT
             painter.end()
             # OPEN THE DOCUMENT
             openPath(path)
예제 #3
0
    def run(self, path):
        """
        Perform CSV file generation.
        :type path: str
        """
        if self.diagrams is None:
            dialog = DiagramSelectionDialog(self.session)
            if not dialog.exec_():
                return
            self.diagrams = dialog.selectedDiagrams()

        LOGGER.info(
            'Exporting selected diagrams in project %s in CSV format: %s',
            self.project.name, path)
        collection = {x: {} for x in self.Types}

        for diagram in self.diagrams:
            nodes = self.project.predicates(diagram=diagram)
            for node in nodes:
                if node.type() in collection:
                    if not node.text() in collection[node.type()]:
                        meta = self.project.meta(node.type(), node.text())
                        collection[node.type()][node.text()] = {
                            CsvExporter.KeyName:
                            node.text().replace('\n', ''),
                            CsvExporter.KeyType:
                            node.shortName,
                            CsvExporter.KeyDescription:
                            self.plainText(meta.get(K_DESCRIPTION, '')),
                            CsvExporter.KeyDiagrams:
                            DistinctList()
                        }
                    collection[node.type()][node.text()][self.KeyDiagrams] += [
                        node.diagram.name
                    ]

        buffer = io.StringIO()
        writer = csv.writer(buffer,
                            delimiter=',',
                            quotechar='"',
                            quoting=csv.QUOTE_ALL)
        writer.writerow((self.KeyName, self.KeyType, self.KeyDescription,
                         self.KeyDiagrams))
        for i, j in sorted(((v, k) for k in collection for v in collection[k]),
                           key=itemgetter(0)):
            writer.writerow((
                collection[j][i][self.KeyName],
                collection[j][i][self.KeyType],
                collection[j][i][self.KeyDescription],
                sorted(collection[j][i][self.KeyDiagrams]),
            ))

        fwrite(buffer.getvalue(), path)

        if self.open:
            openPath(path)
예제 #4
0
 def doExport(self):
     """
     Export the generated OWL and schema.
     """
     dialog = QtWidgets.QFileDialog(self)
     dialog.setFileMode(QtWidgets.QFileDialog.Directory)
     if dialog.exec_():
         directory = first(dialog.selectedFiles())
         owl = self.findChild(QtWidgets.QTextEdit, 'owl_text').toPlainText()
         fwrite(owl, os.path.join(directory, 'ontology.owl'))
         openPath(directory)
예제 #5
0
파일: csv_exporter.py 프로젝트: Njrob/eddy
    def run(self, path):
        """
        Perform CSV file generation.
        :type path: str
        """
        diagrams_selection_dialog = DiagramsSelectionDialog(
            self.project, self.session)
        diagrams_selection_dialog.exec_()
        self.selected_diagrams = diagrams_selection_dialog.diagrams_selected

        LOGGER.info(
            'Exporting selected diagrams in project %s in CSV format: %s',
            self.project.name, path)
        collection = {x: {} for x in self.Types}

        for diag in self.selected_diagrams:
            nodes = self.project.predicates(diagram=diag)
            for node in nodes:
                if node.type() in collection:
                    if not node.text() in collection[node.type()]:
                        meta = self.project.meta(node.type(), node.text())
                        collection[node.type()][node.text()] = {
                            #CsvExporter.KeyName: lstrip(OWLShortIRI('', node.text()), ':'),
                            CsvExporter.KeyName:
                            node.text().replace('\n', ''),
                            CsvExporter.KeyType:
                            node.shortName,
                            #CsvExporter.KeyDescription: meta.get(K_DESCRIPTION, ''),
                            CsvExporter.KeyDescription:
                            QtWidgets.QTextEdit(meta.get(K_DESCRIPTION,
                                                         '')).toPlainText(),
                            CsvExporter.KeyDiagrams:
                            DistinctList()
                        }
                    collection[node.type()][node.text()][self.KeyDiagrams] += [
                        node.diagram.name
                    ]

        buffer = io.StringIO()
        writer = csv.writer(buffer)
        writer.writerow((self.KeyName, self.KeyType, self.KeyDescription,
                         self.KeyDiagrams))
        for i, j in sorted(((v, k) for k in collection for v in collection[k]),
                           key=itemgetter(0)):
            writer.writerow((
                collection[j][i][self.KeyName],
                collection[j][i][self.KeyType],
                collection[j][i][self.KeyDescription],
                sorted(collection[j][i][self.KeyDiagrams]),
            ))

        fwrite(buffer.getvalue(), path)

        openPath(path)
예제 #6
0
    def run(self, path):
        """
        Perform CSV file generation.
        :type path: str
        """
        LOGGER.info('Exporting project %s in CSV format: %s',
                    self.project.name, path)
        collection = {x: {} for x in self.Types}

        for node in self.project.predicates():
            if node.type() in collection:
                if not node.text() in collection[node.type()]:
                    meta = self.project.meta(node.type(), node.text())
                    collection[node.type()][node.text()] = {
                        CsvExporter.KeyName:
                        lstrip(OWLShortIRI('', node.text()), ':'),
                        CsvExporter.KeyType:
                        node.shortName,
                        CsvExporter.KeyDescription:
                        meta.get(K_DESCRIPTION, ''),
                        CsvExporter.KeyDiagrams:
                        DistinctList()
                    }
                collection[node.type()][node.text()][self.KeyDiagrams] += [
                    node.diagram.name
                ]

        buffer = io.StringIO()
        writer = csv.writer(buffer)
        writer.writerow((self.KeyName, self.KeyType, self.KeyDescription,
                         self.KeyDiagrams))
        for i, j in sorted(((v, k) for k in collection for v in collection[k]),
                           key=itemgetter(0)):
            writer.writerow((
                collection[j][i][self.KeyName],
                collection[j][i][self.KeyType],
                collection[j][i][self.KeyDescription],
                sorted(collection[j][i][self.KeyDiagrams]),
            ))

        fwrite(buffer.getvalue(), path)

        openPath(path)
예제 #7
0
    def export(self, path):
        """
        Perform CSV file generation.
        :type path: str
        """
        LOGGER.info('Exporting project %s in CSV format: %s', self.project.name, path)
        collection = {x: {} for x in self.Types}

        for node in self.project.predicates():
            if node.type() in collection:
                # If there is no data for this predicate node, create a new entry.
                if not node.text() in collection[node.type()]:
                    meta = self.project.meta(node.type(), node.text())
                    collection[node.type()][node.text()] = {
                        CsvExporter.KeyName: lstrip(OWLShortIRI('', node.text()), ':'),
                        CsvExporter.KeyType: node.shortName,
                        CsvExporter.KeyDescription: meta.get('description', ''),
                        CsvExporter.KeyDiagrams: DistinctList()}
                # Append the name of the diagram to the diagram list.
                collection[node.type()][node.text()][self.KeyDiagrams] += [node.diagram.name]

        # Collect data in a buffer.
        buffer = io.StringIO()
        writer = csv.writer(buffer)
        writer.writerow((self.KeyName, self.KeyType, self.KeyDescription, self.KeyDiagrams))
        for i, j in sorted(((v, k) for k in collection for v in collection[k]), key=itemgetter(0)):
            writer.writerow((
                collection[j][i][self.KeyName],
                collection[j][i][self.KeyType],
                collection[j][i][self.KeyDescription],
                sorted(collection[j][i][self.KeyDiagrams]),
            ))

        # Write to disk.
        fwrite(buffer.getvalue(), path)

        # Open the document.
        openPath(path)
예제 #8
0
    def run(self, path):
        """
        Perform PDF document generation.
        :type path: str
        """
        printer = QtPrintSupport.QPrinter(QtPrintSupport.QPrinter.HighResolution)
        printer.setOutputFormat(QtPrintSupport.QPrinter.PdfFormat)
        printer.setOutputFileName(path)
        printer.setOrientation(QtPrintSupport.QPrinter.Landscape)
        printer.setPrinterName(self.project.name)
        painter = QtGui.QPainter()

        # DIAGRAM SELECTION
        if self.diagrams is None:
            dialog = DiagramSelectionDialog(self.session)
            if not dialog.exec_():
                return
            self.diagrams = dialog.selectedDiagrams()
        # DIAGRAM PAGE SIZE SELECTION
        if self.pageSize is None:
            dialog = PageSetupDialog(printer, self.session)
            if not dialog.exec_():
                return
        else:
            printer.setPageSize(self.pageSize)

        ##############################################################
        # DIAGRAMS
        ##############################################################

        for n, diagram in enumerate(natsorted(self.diagrams, key=lambda diagram: diagram.name)):
            shape = diagram.visibleRect(margin=400)
            if shape:
                if n > 0:
                    printer.newPage()
                if painter.isActive() or painter.begin(printer):
                    # TURN CACHING OFF
                    for item in diagram.items():
                        if item.isNode() or item.isEdge():
                            item.setCacheMode(AbstractItem.NoCache)
                    # RENDER THE DIAGRAM
                    diagram.render(painter, source=shape)
                    # RENDER DIAGRAM NAME
                    title = QtGui.QTextDocument()
                    title.setDefaultFont(Font(pixelSize=140))
                    title.setHtml('{0}<hr width=100%/>'.format(diagram.name))
                    title.setTextWidth(printer.pageRect().width())
                    title.drawContents(painter)
                    # TURN CACHING ON
                    for item in diagram.items():
                        if item.isNode() or item.isEdge():
                            item.setCacheMode(AbstractItem.DeviceCoordinateCache)

        ##############################################################
        # IRI TABLE
        ##############################################################

        # RESET PAGE SIZE AND ORIENTATION FOR PREDICATE TABLES
        printer.setPageSize(QtPrintSupport.QPrinter.A4)
        printer.setOrientation(QtPrintSupport.QPrinter.Landscape)
        printer.setPageMargins(12.5, 12.5, 12.5, 12.5, QtPrintSupport.QPrinter.Millimeter)

        prefixRows = []
        for prefix in sorted(self.project.getManagedPrefixes()):
            ns = self.project.getPrefixResolution(prefix)
            prefixRows.append(dedent('''
                    <tr>
                        <td width=25%>{0}</td>
                        <td width=75%>{1}</td>
                    </tr>
                '''.format(prefix, ns)))
        sections = [prefixRows[i:i+self.rowsPerPage] for i in range(0, len(prefixRows), self.rowsPerPage)]

        for section in sections:
            if len(section) > 0:
                if len(self.diagrams) > 0:
                    printer.newPage()
                doc = QtGui.QTextDocument()
                htmlTable = '''
                <table width=100% border=5 cellspacing=0 cellpadding=60>
                    <thead>
                        <tr>
                            <th bgcolor=#c8c8c8>PREFIX</th>
                            <th bgcolor=#c8c8c8>IRI</th>
                        </tr>
                    </thead>
                 <tbody>'''
                htmlTable += '\n'.join(section)
                htmlTable += '</tbody>'
                htmlTable += '</table>'
                doc.setDefaultFont(Font(pixelSize=180))
                doc.setHtml(htmlTable)
                doc.setPageSize(QtCore.QSizeF(printer.pageRect().size()))
                doc.drawContents(painter)

        ##############################################################
        # ROLES AND ATTRIBUTES TABLE
        ##############################################################

        predicateRows = []
        predicateIRIs = set()
        for item in {Item.RoleIRINode, Item.AttributeIRINode}:
            for node in self.project.iriOccurrences(item=item):
                if not node.iri.isTopBottomEntity():
                    predicateIRIs.add(node.iri)

        for predicateIRI in sorted(predicateIRIs,key=str):
            meta = predicateIRI.getMetaProperties()
            attributes = [
                meta.get(K_FUNCTIONAL, False),
                meta.get(K_INVERSE_FUNCTIONAL, False),
                meta.get(K_REFLEXIVE, False),
                meta.get(K_IRREFLEXIVE, False),
                meta.get(K_SYMMETRIC, False),
                meta.get(K_ASYMMETRIC, False),
                meta.get(K_TRANSITIVE, False),
            ]
            predicateRows.append('''
                <tr>
                    <td width=30%>{0}</td>
                    <td width=10%><center>{1}</center></td>
                    <td width=10%><center>{2}</center></td>
                    <td width=10%><center>{3}</center></td>
                    <td width=10%><center>{4}</center></td>
                    <td width=10%><center>{5}</center></td>
                    <td width=10%><center>{6}</center></td>
                    <td width=10%><center>{7}</center></td>
                </tr>
            '''.format(str(predicateIRI).replace('\n', ''), *map(lambda x: u'\u2713' if x else '', attributes)))
        sections = [predicateRows[i:i+self.rowsPerPage] for i in range(0, len(predicateRows), self.rowsPerPage)]

        for section in sections:
            if len(section) > 0:
                if len(self.diagrams) > 0:
                    printer.newPage()
                doc = QtGui.QTextDocument()
                htmlTable = '''
                <table width=100% border=5 cellspacing=0 cellpadding=60>
                    <thead>
                        <tr>
                            <th bgcolor=#c8c8c8>ENTITY</th>
                            <th bgcolor=#c8c8c8>FUNCT</th>
                            <th bgcolor=#c8c8c8>INVERSE FUNCT</th>
                            <th bgcolor=#c8c8c8>TRANS</th>
                            <th bgcolor=#c8c8c8>REFL</th>
                            <th bgcolor=#c8c8c8>IRREFL</th>
                            <th bgcolor=#c8c8c8>SYMM</th>
                            <th bgcolor=#c8c8c8>ASYMM</th>
                        </tr>
                    </thead>
                 <tbody>'''
                htmlTable += '\n'.join(section)
                htmlTable += '</tbody>'
                htmlTable += '</table>'
                doc.setDefaultFont(Font(pixelSize=180))
                doc.setHtml(htmlTable)
                doc.setPageSize(QtCore.QSizeF(printer.pageRect().size()))
                doc.drawContents(painter)

        # COMPLETE THE EXPORT
        if painter.isActive():
            painter.end()

        # OPEN THE DOCUMENT
        if self.open:
            openPath(printer.outputFileName())