This little tools helps you with getting your PCBs populated.

mainwindow.cpp 4.2KB

    #include "mainwindow.h" #include "ui_mainwindow.h" #include <QFile> #include <QFileDialog> #include <QGraphicsScene> #include <QGraphicsPixmapItem> #include <QString> #include <QTextStream> #include <QPrinter> #include <QPainter> #include "partdata.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); ui->graphicsView->setScene(new QGraphicsScene()); Background=0; Foreground=0; } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_SelectMnt_clicked() { QString File=QFileDialog::getOpenFileName(0, QString("mnt-File"), QString(), QString("*.mnt")); if (File.isEmpty()) return; ui->mntFile->setText(File); } void MainWindow::on_SelectOutput_clicked() { QString Dir=QFileDialog::getExistingDirectory(); ui->outputDir->setText(Dir); } void MainWindow::on_SelectBackground_clicked() { QString File=QFileDialog::getOpenFileName(0, QString("mnt-File"), QString(), QString("*.mnt")); if (File.isEmpty()) return; ui->backgroundImage->setText(File); ui->graphicsView->scene()->clear(); Background=ui->graphicsView->scene()->addPixmap(QPixmap(ui->backgroundImage->text())); Foreground=ui->graphicsView->scene()->addPixmap(QPixmap()); ui->graphicsView->scene()->addItem(Foreground); ui->graphicsView->fitInView(Background); } void MainWindow::on_Make_clicked() { QFile InputFile(ui->mntFile->text()); if(!InputFile.open(QIODevice::Text | QIODevice::ReadOnly)) return; QList<PartData> Parts; QTextStream Input(&InputFile); while(!Input.atEnd()) { QString Line=Input.readLine(); QStringList LineParts=Line.split(QRegExp("[;\t]")); PartData Part; Part.Value=LineParts[0]; Part.Rotation=LineParts[3].toDouble(); Part.Designator=LineParts[4]; double x=LineParts[1].toDouble()*0.0254; double y=LineParts[2].toDouble()*0.0254; Part.Position=QPointF(x,y); Parts.append(Part); } while(Parts.size()) { QList<PartData> SubParts; SubParts.append(Parts[0]); QString ValueToFind=Parts[0].Value.trimmed(); QString DesignatorToFind=Parts[0].Designator.trimmed(); while(DesignatorToFind.size()) { if (DesignatorToFind.right(1).at(0).isDigit()) DesignatorToFind=DesignatorToFind.left(DesignatorToFind.size()-1); else break; } Parts.removeAt(0); for (int i=0;i<Parts.size();i++) { QString ValueToCompare=Parts[i].Value.trimmed(); if (ValueToCompare==ValueToFind) { QString DesignatorToCompare=Parts[i].Designator.trimmed(); while(DesignatorToCompare.right(1).at(0).isDigit()) DesignatorToCompare=DesignatorToCompare.left(DesignatorToCompare.size()-1); if (DesignatorToCompare==DesignatorToFind) { SubParts.append(Parts[i]); Parts.removeAt(i); i--; } } } QDir Dir; Dir.setPath(ui->outputDir->text()); QString FilePath=Dir.absoluteFilePath(SubParts[0].Designator+QString("_")+SubParts[0].Value+QString(".pdf")); QPrinter Printer(QPrinter::HighResolution); Printer.setPageSize(QPrinter::A4); Printer.setOrientation(QPrinter::Landscape); Printer.setOutputFormat(QPrinter::PdfFormat); Printer.setOutputFileName(FilePath); QSize ImageSize=Background->pixmap().size(); QPixmap Pixmap(ImageSize); Pixmap.fill(Qt::transparent); QPainter Painter(&Pixmap); Painter.setBrush(QBrush(Qt::white)); Painter.setPen(QPen(QBrush(Qt::white), 10)); for (int i=0;i<SubParts.size();i++) { QPointF Pt; Pt.setX(SubParts[i].Position.x()*(double)ImageSize.width()/ui->width->value()); Pt.setY(ImageSize.height()-SubParts[i].Position.y()*(double)ImageSize.height()/ui->height->value()); Painter.drawLine(QPointF(0,0), Pt); } Painter.end(); Foreground->setPixmap(Pixmap); Painter.begin(&Printer); ui->graphicsView->render(&Painter); Painter.end(); } }