Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ project(Robocut
LANGUAGES C CXX)

# Set the CMAKE_PREFIX_PATH environment variable to (e.g) ~/Qt/5.8/clang_64 so it can find Qt.
find_package(Qt5 COMPONENTS Core Widgets Svg REQUIRED)
find_package(Qt5 COMPONENTS Core Widgets Svg Xml REQUIRED)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
Expand Down Expand Up @@ -70,6 +70,7 @@ add_executable(Robocut MACOSX_BUNDLE WIN32
target_link_libraries(Robocut
Qt5::Widgets
Qt5::Svg
Qt5::Xml
libusb
)

Expand Down
37 changes: 28 additions & 9 deletions MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
#include <iostream>
#include <QWheelEvent>

#include <QDomDocument>

using namespace std;

const double InitialZoom = 2.0;
Expand Down Expand Up @@ -123,6 +125,29 @@ void MainWindow::on_actionIdentify_triggered()
cout << " " << id->msg << endl;
}

constexpr double defaultPpm = 96.0/25.4; // Pixels per mm.

inline float stringSizeToMm(const QString& repr, double ppm=defaultPpm)
{
if (repr.endsWith("mm")) {
return repr.left(repr.size() - 2).toFloat();
}
return repr.toFloat() / defaultPpm;
}

void MainWindow::readPageSize()
{
QDomDocument xmlDocument;
QFile file(filename);

xmlDocument.setContent(&file);

QDomElement svgNode = xmlDocument.elementsByTagName("svg").item(0).toElement();
const QString widthXmlValue = svgNode.attribute("width");
const QString heightXmlValue = svgNode.attribute("height");

mediaSize = {stringSizeToMm(widthXmlValue), stringSizeToMm(heightXmlValue)};
}

void MainWindow::loadFile()
{
Expand All @@ -139,19 +164,13 @@ void MainWindow::loadFile()
return;
}

readPageSize();

qDebug() << "SVG default size: " << rend.defaultSize() << endl;
qDebug() << "SVG view box: " << rend.viewBoxF() << endl;

// Geqt size from SVG. TODO: Sanity check.
// Also TODO: This won't handle offset viewboxes... need to get the offset and subtract it from
// all the objects.
mediaSize = rend.viewBoxF().size() * 25.4 / 96.0;

double ppm = 96.0/25.4; // Pixels per mm.

qDebug() << "Page size (mm): " << mediaSize << endl;

PathPaintDevice pg(mediaSize.width(), mediaSize.height(), ppm);
PathPaintDevice pg(mediaSize.width(), mediaSize.height(), defaultPpm);
QPainter p(&pg);

rend.render(&p);
Expand Down
2 changes: 2 additions & 0 deletions MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class MainWindow : public QMainWindow

QString filename;

void readPageSize();

public:
int sortFlag;
int tspFlag;
Expand Down