summaryrefslogtreecommitdiff
path: root/src/mainwin.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/mainwin.cc')
-rw-r--r--src/mainwin.cc211
1 files changed, 108 insertions, 103 deletions
diff --git a/src/mainwin.cc b/src/mainwin.cc
index 17b9ef7..dd855fb 100644
--- a/src/mainwin.cc
+++ b/src/mainwin.cc
@@ -48,6 +48,11 @@
#include "ProgressWidget.h"
#include "ThrownTogetherRenderer.h"
#include "csgtermnormalizer.h"
+#include "QGLView.h"
+#include "AutoUpdater.h"
+#ifdef Q_OS_MAC
+#include "CocoaUtils.h"
+#endif
#include <QMenu>
#include <QTime>
@@ -190,8 +195,8 @@ MainWindow::MainWindow(const QString &filename)
editor->setTabStopWidth(30);
editor->setLineWrapping(true); // Not designable
- this->glview->statusLabel = new QLabel(this);
- statusBar()->addWidget(this->glview->statusLabel);
+ this->qglview->statusLabel = new QLabel(this);
+ statusBar()->addWidget(this->qglview->statusLabel);
animate_timer = new QTimer(this);
connect(animate_timer, SIGNAL(timeout()), this, SLOT(updateTVal()));
@@ -205,6 +210,16 @@ MainWindow::MainWindow(const QString &filename)
animate_panel->hide();
+ // Application menu
+#ifdef DEBUG
+ this->appActionUpdateCheck->setEnabled(false);
+#else
+#ifdef Q_OS_MAC
+ this->appActionUpdateCheck->setMenuRole(QAction::ApplicationSpecificRole);
+ this->appActionUpdateCheck->setEnabled(true);
+ connect(this->appActionUpdateCheck, SIGNAL(triggered()), this, SLOT(actionUpdateCheck()));
+#endif
+#endif
// File menu
connect(this->fileActionNew, SIGNAL(triggered()), this, SLOT(actionNew()));
connect(this->fileActionOpen, SIGNAL(triggered()), this, SLOT(actionOpen()));
@@ -291,7 +306,7 @@ MainWindow::MainWindow(const QString &filename)
this->viewActionOpenCSG->setVisible(false);
#else
connect(this->viewActionOpenCSG, SIGNAL(triggered()), this, SLOT(viewModeOpenCSG()));
- if (!this->glview->hasOpenCSGSupport()) {
+ if (!this->qglview->hasOpenCSGSupport()) {
this->viewActionOpenCSG->setEnabled(false);
}
#endif
@@ -343,9 +358,9 @@ MainWindow::MainWindow(const QString &filename)
connect(editor->document(), SIGNAL(contentsChanged()), this, SLOT(animateUpdateDocChanged()));
connect(editor->document(), SIGNAL(modificationChanged(bool)), this, SLOT(setWindowModified(bool)));
connect(editor->document(), SIGNAL(modificationChanged(bool)), fileActionSave, SLOT(setEnabled(bool)));
- connect(this->glview, SIGNAL(doAnimateUpdate()), this, SLOT(animateUpdate()));
+ connect(this->qglview, SIGNAL(doAnimateUpdate()), this, SLOT(animateUpdate()));
- connect(Preferences::inst(), SIGNAL(requestRedraw()), this->glview, SLOT(updateGL()));
+ connect(Preferences::inst(), SIGNAL(requestRedraw()), this->qglview, SLOT(updateGL()));
connect(Preferences::inst(), SIGNAL(fontChanged(const QString&,uint)),
this, SLOT(setFont(const QString&,uint)));
connect(Preferences::inst(), SIGNAL(openCSGSettingsChanged()),
@@ -507,7 +522,7 @@ MainWindow::setFileName(const QString &filename)
this->fileName = fileinfo.fileName();
}
- this->root_ctx.setDocumentPath(fileinfo.dir().absolutePath().toStdString());
+ this->root_ctx.setDocumentPath(fileinfo.dir().absolutePath().toLocal8Bit().constData());
QDir::setCurrent(fileinfo.dir().absolutePath());
}
@@ -571,28 +586,19 @@ void MainWindow::refreshDocument()
QFile file(this->fileName);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
PRINTB("Failed to open file %s: %s",
- this->fileName.toStdString() % file.errorString().toStdString());
+ this->fileName.toLocal8Bit().constData() % file.errorString().toLocal8Bit().constData());
}
else {
QTextStream reader(&file);
reader.setCodec("UTF-8");
QString text = reader.readAll();
- PRINTB("Loaded design '%s'.", this->fileName.toStdString());
+ PRINTB("Loaded design '%s'.", this->fileName.toLocal8Bit().constData());
editor->setPlainText(text);
}
}
setCurrentOutput();
}
-AbstractNode *MainWindow::find_root_tag(AbstractNode *n)
-{
- BOOST_FOREACH (AbstractNode *v, n->children) {
- if (v->modinst->isRoot()) return v;
- if (AbstractNode *vroot = find_root_tag(v)) return vroot;
- }
- return NULL;
-}
-
/*!
Parse and evaluate the design => this->root_node
@@ -604,7 +610,7 @@ bool MainWindow::compile(bool reload, bool procevents)
if (!compileTopLevelDocument(reload)) return false;
// Invalidate renderers before we kill the CSG tree
- this->glview->setRenderer(NULL);
+ this->qglview->setRenderer(NULL);
delete this->opencsgRenderer;
this->opencsgRenderer = NULL;
delete this->thrownTogetherRenderer;
@@ -768,7 +774,7 @@ void MainWindow::compileCSG(bool procevents)
this->opencsgRenderer = new OpenCSGRenderer(this->root_chain,
this->highlights_chain,
this->background_chain,
- this->glview->shaderinfo);
+ this->qglview->shaderinfo);
}
this->thrownTogetherRenderer = new ThrownTogetherRenderer(this->root_chain,
this->highlights_chain,
@@ -781,6 +787,13 @@ void MainWindow::compileCSG(bool procevents)
}
}
+void MainWindow::actionUpdateCheck()
+{
+ if (AutoUpdater *updater =AutoUpdater::updater()) {
+ updater->checkForUpdates();
+ }
+}
+
void MainWindow::actionNew()
{
#ifdef ENABLE_MDI
@@ -891,13 +904,13 @@ void MainWindow::actionSave()
setCurrentOutput();
QFile file(this->fileName);
if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) {
- PRINTB("Failed to open file for writing: %s (%s)", this->fileName.toStdString() % file.errorString().toStdString());
+ PRINTB("Failed to open file for writing: %s (%s)", this->fileName.toLocal8Bit().constData() % file.errorString().toLocal8Bit().constData());
}
else {
QTextStream writer(&file);
writer.setCodec("UTF-8");
writer << this->editor->toPlainText();
- PRINTB("Saved design '%s'.", this->fileName.toStdString());
+ PRINTB("Saved design '%s'.", this->fileName.toLocal8Bit().constData());
this->editor->setContentModified(false);
}
clearCurrentOutput();
@@ -951,7 +964,7 @@ void MainWindow::pasteViewportTranslation()
{
QTextCursor cursor = editor->textCursor();
QString txt;
- txt.sprintf("[ %.2f, %.2f, %.2f ]", -this->glview->object_trans_x, -this->glview->object_trans_y, -this->glview->object_trans_z);
+ txt.sprintf("[ %.2f, %.2f, %.2f ]", -qglview->cam.object_trans.x(), -qglview->cam.object_trans.y(), -qglview->cam.object_trans.z());
cursor.insertText(txt);
}
@@ -960,7 +973,7 @@ void MainWindow::pasteViewportRotation()
QTextCursor cursor = editor->textCursor();
QString txt;
txt.sprintf("[ %.2f, %.2f, %.2f ]",
- fmodf(360 - this->glview->object_rot_x + 90, 360), fmodf(360 - this->glview->object_rot_y, 360), fmodf(360 - this->glview->object_rot_z, 360));
+ fmodf(360 - qglview->cam.object_rot.x() + 90, 360), fmodf(360 - qglview->cam.object_rot.y(), 360), fmodf(360 - qglview->cam.object_rot.z(), 360));
cursor.insertText(txt);
}
@@ -969,15 +982,15 @@ void MainWindow::updateTemporalVariables()
this->root_ctx.set_variable("$t", Value(this->e_tval->text().toDouble()));
Value::VectorType vpt;
- vpt.push_back(Value(-this->glview->object_trans_x));
- vpt.push_back(Value(-this->glview->object_trans_y));
- vpt.push_back(Value(-this->glview->object_trans_z));
+ vpt.push_back(Value(-qglview->cam.object_trans.x()));
+ vpt.push_back(Value(-qglview->cam.object_trans.y()));
+ vpt.push_back(Value(-qglview->cam.object_trans.z()));
this->root_ctx.set_variable("$vpt", Value(vpt));
Value::VectorType vpr;
- vpr.push_back(Value(fmodf(360 - this->glview->object_rot_x + 90, 360)));
- vpr.push_back(Value(fmodf(360 - this->glview->object_rot_y, 360)));
- vpr.push_back(Value(fmodf(360 - this->glview->object_rot_z, 360)));
+ vpr.push_back(Value(fmodf(360 - qglview->cam.object_rot.x() + 90, 360)));
+ vpr.push_back(Value(fmodf(360 - qglview->cam.object_rot.y(), 360)));
+ vpr.push_back(Value(fmodf(360 - qglview->cam.object_rot.z(), 360)));
root_ctx.set_variable("$vpr", Value(vpr));
}
@@ -1027,8 +1040,9 @@ bool MainWindow::compileTopLevelDocument(bool reload)
{
bool shouldcompiletoplevel = !reload;
- if ((reload && fileChangedOnDisk() && checkEditorModified()) ||
- includesChanged()) {
+ if (includesChanged()) shouldcompiletoplevel = true;
+
+ if (reload && fileChangedOnDisk() && checkEditorModified()) {
shouldcompiletoplevel = true;
refreshDocument();
}
@@ -1040,7 +1054,8 @@ bool MainWindow::compileTopLevelDocument(bool reload)
this->last_compiled_doc = editor->toPlainText();
std::string fulltext =
- this->last_compiled_doc.toStdString() + "\n" + commandline_commands;
+ std::string(this->last_compiled_doc.toLocal8Bit().constData()) +
+ "\n" + commandline_commands;
delete this->root_module;
this->root_module = NULL;
@@ -1156,7 +1171,7 @@ void MainWindow::actionCompile()
}
if (viewActionAnimate->isChecked() && e_dump->isChecked()) {
- QImage img = this->glview->grabFrameBuffer();
+ QImage img = this->qglview->grabFrameBuffer();
QString filename;
double s = this->e_fsteps->text().toDouble();
double t = this->e_tval->text().toDouble();
@@ -1185,7 +1200,7 @@ void MainWindow::actionRenderCGAL()
return;
}
- this->glview->setRenderer(NULL);
+ this->qglview->setRenderer(NULL);
delete this->cgalRenderer;
this->cgalRenderer = NULL;
if (this->root_N) {
@@ -1279,7 +1294,7 @@ void MainWindow::actionDisplayAST()
e->setWindowTitle("AST Dump");
e->setReadOnly(true);
if (root_module) {
- e->setPlainText(QString::fromStdString(root_module->dump("", "")));
+ e->setPlainText(QString::fromLocal8Bit(root_module->dump("", "").c_str()));
} else {
e->setPlainText("No AST to dump. Please try compiling first...");
}
@@ -1297,7 +1312,7 @@ void MainWindow::actionDisplayCSGTree()
e->setWindowTitle("CSG Tree Dump");
e->setReadOnly(true);
if (this->root_node) {
- e->setPlainText(QString::fromStdString(this->tree.getString(*this->root_node)));
+ e->setPlainText(QString::fromLocal8Bit(this->tree.getString(*this->root_node).c_str()));
} else {
e->setPlainText("No CSG to dump. Please try compiling first...");
}
@@ -1314,7 +1329,12 @@ void MainWindow::actionDisplayCSGProducts()
e->setTabStopWidth(30);
e->setWindowTitle("CSG Products Dump");
e->setReadOnly(true);
- e->setPlainText(QString("\nCSG before normalization:\n%1\n\n\nCSG after normalization:\n%2\n\n\nCSG rendering chain:\n%3\n\n\nHighlights CSG rendering chain:\n%4\n\n\nBackground CSG rendering chain:\n%5\n").arg(root_raw_term ? QString::fromStdString(root_raw_term->dump()) : "N/A", root_norm_term ? QString::fromStdString(root_norm_term->dump()) : "N/A", this->root_chain ? QString::fromStdString(this->root_chain->dump()) : "N/A", highlights_chain ? QString::fromStdString(highlights_chain->dump()) : "N/A", background_chain ? QString::fromStdString(background_chain->dump()) : "N/A"));
+ e->setPlainText(QString("\nCSG before normalization:\n%1\n\n\nCSG after normalization:\n%2\n\n\nCSG rendering chain:\n%3\n\n\nHighlights CSG rendering chain:\n%4\n\n\nBackground CSG rendering chain:\n%5\n")
+ .arg(root_raw_term ? QString::fromLocal8Bit(root_raw_term->dump().c_str()) : "N/A",
+ root_norm_term ? QString::fromLocal8Bit(root_norm_term->dump().c_str()) : "N/A",
+ this->root_chain ? QString::fromLocal8Bit(this->root_chain->dump().c_str()) : "N/A",
+ highlights_chain ? QString::fromLocal8Bit(highlights_chain->dump().c_str()) : "N/A",
+ background_chain ? QString::fromLocal8Bit(background_chain->dump().c_str()) : "N/A"));
e->show();
e->resize(600, 400);
clearCurrentOutput();
@@ -1362,7 +1382,7 @@ void MainWindow::actionExportSTLorOFF(bool)
std::ofstream fstream(stl_filename.toUtf8());
if (!fstream.is_open()) {
- PRINTB("Can't open file \"%s\" for export", stl_filename.toStdString());
+ PRINTB("Can't open file \"%s\" for export", stl_filename.toLocal8Bit().constData());
}
else {
if (stl_mode) export_stl(this->root_N, fstream);
@@ -1415,7 +1435,7 @@ void MainWindow::actionExportDXF()
std::ofstream fstream(dxf_filename.toUtf8());
if (!fstream.is_open()) {
- PRINTB("Can't open file \"%s\" for export", dxf_filename.toStdString());
+ PRINTB("Can't open file \"%s\" for export", dxf_filename.toLocal8Bit().constData());
}
else {
export_dxf(this->root_N, fstream);
@@ -1448,7 +1468,7 @@ void MainWindow::actionExportCSG()
std::ofstream fstream(csg_filename.toUtf8());
if (!fstream.is_open()) {
- PRINTB("Can't open file \"%s\" for export", csg_filename.toStdString());
+ PRINTB("Can't open file \"%s\" for export", csg_filename.toLocal8Bit().constData());
}
else {
fstream << this->tree.getString(*this->root_node) << "\n";
@@ -1461,20 +1481,17 @@ void MainWindow::actionExportCSG()
void MainWindow::actionExportImage()
{
- QImage img = this->glview->grabFrameBuffer();
setCurrentOutput();
QString img_filename = QFileDialog::getSaveFileName(this,
"Export Image", "", "PNG Files (*.png)");
if (img_filename.isEmpty()) {
PRINT("No filename specified. Image export aborted.");
- clearCurrentOutput();
- return;
+ } else {
+ qglview->save(img_filename.toLocal8Bit().constData());
}
-
- img.save(img_filename, "PNG");
-
clearCurrentOutput();
+ return;
}
void MainWindow::actionFlushCaches()
@@ -1506,10 +1523,11 @@ void MainWindow::viewModeActionsUncheck()
*/
void MainWindow::viewModeOpenCSG()
{
- if (this->glview->hasOpenCSGSupport()) {
+ if (this->qglview->hasOpenCSGSupport()) {
viewModeActionsUncheck();
viewActionOpenCSG->setChecked(true);
- this->glview->setRenderer(this->opencsgRenderer ? (Renderer *)this->opencsgRenderer : (Renderer *)this->thrownTogetherRenderer);
+ this->qglview->setRenderer(this->opencsgRenderer ? (Renderer *)this->opencsgRenderer : (Renderer *)this->thrownTogetherRenderer);
+ this->qglview->updateGL();
} else {
viewModeThrownTogether();
}
@@ -1523,17 +1541,18 @@ void MainWindow::viewModeCGALSurface()
{
viewModeActionsUncheck();
viewActionCGALSurfaces->setChecked(true);
- this->glview->setShowFaces(true);
- this->glview->setRenderer(this->cgalRenderer);
- this->glview->updateGL();
+ this->qglview->setShowFaces(true);
+ this->qglview->setRenderer(this->cgalRenderer);
+ this->qglview->updateGL();
}
void MainWindow::viewModeCGALGrid()
{
viewModeActionsUncheck();
viewActionCGALGrid->setChecked(true);
- this->glview->setShowFaces(false);
- this->glview->setRenderer(this->cgalRenderer);
+ this->qglview->setShowFaces(false);
+ this->qglview->setRenderer(this->cgalRenderer);
+ this->qglview->updateGL();
}
#endif /* ENABLE_CGAL */
@@ -1542,31 +1561,32 @@ void MainWindow::viewModeThrownTogether()
{
viewModeActionsUncheck();
viewActionThrownTogether->setChecked(true);
- this->glview->setRenderer(this->thrownTogetherRenderer);
+ this->qglview->setRenderer(this->thrownTogetherRenderer);
+ this->qglview->updateGL();
}
void MainWindow::viewModeShowEdges()
{
QSettings settings;
settings.setValue("view/showEdges",viewActionShowEdges->isChecked());
- this->glview->setShowEdges(viewActionShowEdges->isChecked());
- this->glview->updateGL();
+ this->qglview->setShowEdges(viewActionShowEdges->isChecked());
+ this->qglview->updateGL();
}
void MainWindow::viewModeShowAxes()
{
QSettings settings;
settings.setValue("view/showAxes",viewActionShowAxes->isChecked());
- this->glview->setShowAxes(viewActionShowAxes->isChecked());
- this->glview->updateGL();
+ this->qglview->setShowAxes(viewActionShowAxes->isChecked());
+ this->qglview->updateGL();
}
void MainWindow::viewModeShowCrosshairs()
{
QSettings settings;
settings.setValue("view/showCrosshairs",viewActionShowCrosshairs->isChecked());
- this->glview->setShowCrosshairs(viewActionShowCrosshairs->isChecked());
- this->glview->updateGL();
+ this->qglview->setShowCrosshairs(viewActionShowCrosshairs->isChecked());
+ this->qglview->updateGL();
}
void MainWindow::viewModeAnimate()
@@ -1604,66 +1624,50 @@ void MainWindow::animateUpdate()
void MainWindow::viewAngleTop()
{
- this->glview->object_rot_x = 90;
- this->glview->object_rot_y = 0;
- this->glview->object_rot_z = 0;
- this->glview->updateGL();
+ qglview->cam.object_rot << 90,0,0;
+ this->qglview->updateGL();
}
void MainWindow::viewAngleBottom()
{
- this->glview->object_rot_x = 270;
- this->glview->object_rot_y = 0;
- this->glview->object_rot_z = 0;
- this->glview->updateGL();
+ qglview->cam.object_rot << 270,0,0;
+ this->qglview->updateGL();
}
void MainWindow::viewAngleLeft()
{
- this->glview->object_rot_x = 0;
- this->glview->object_rot_y = 0;
- this->glview->object_rot_z = 90;
- this->glview->updateGL();
+ qglview->cam.object_rot << 0,0,90;
+ this->qglview->updateGL();
}
void MainWindow::viewAngleRight()
{
- this->glview->object_rot_x = 0;
- this->glview->object_rot_y = 0;
- this->glview->object_rot_z = 270;
- this->glview->updateGL();
+ qglview->cam.object_rot << 0,0,270;
+ this->qglview->updateGL();
}
void MainWindow::viewAngleFront()
{
- this->glview->object_rot_x = 0;
- this->glview->object_rot_y = 0;
- this->glview->object_rot_z = 0;
- this->glview->updateGL();
+ qglview->cam.object_rot << 0,0,0;
+ this->qglview->updateGL();
}
void MainWindow::viewAngleBack()
{
- this->glview->object_rot_x = 0;
- this->glview->object_rot_y = 0;
- this->glview->object_rot_z = 180;
- this->glview->updateGL();
+ qglview->cam.object_rot << 0,0,180;
+ this->qglview->updateGL();
}
void MainWindow::viewAngleDiagonal()
{
- this->glview->object_rot_x = 35;
- this->glview->object_rot_y = 0;
- this->glview->object_rot_z = -25;
- this->glview->updateGL();
+ qglview->cam.object_rot << 35,0,-25;
+ this->qglview->updateGL();
}
void MainWindow::viewCenter()
{
- this->glview->object_trans_x = 0;
- this->glview->object_trans_y = 0;
- this->glview->object_trans_z = 0;
- this->glview->updateGL();
+ qglview->cam.object_trans << 0,0,0;
+ this->qglview->updateGL();
}
void MainWindow::viewPerspective()
@@ -1672,8 +1676,8 @@ void MainWindow::viewPerspective()
settings.setValue("view/orthogonalProjection",false);
viewActionPerspective->setChecked(true);
viewActionOrthogonal->setChecked(false);
- this->glview->setOrthoMode(false);
- this->glview->updateGL();
+ this->qglview->setOrthoMode(false);
+ this->qglview->updateGL();
}
void MainWindow::viewOrthogonal()
@@ -1682,8 +1686,8 @@ void MainWindow::viewOrthogonal()
settings.setValue("view/orthogonalProjection",true);
viewActionPerspective->setChecked(false);
viewActionOrthogonal->setChecked(true);
- this->glview->setOrthoMode(true);
- this->glview->updateGL();
+ this->qglview->setOrthoMode(true);
+ this->qglview->updateGL();
}
void MainWindow::hideConsole()
@@ -1754,13 +1758,11 @@ void MainWindow::helpLibrary()
qVersion());
if (!this->openglbox) {
- this->openglbox = new QMessageBox(QMessageBox::Information,
- "OpenGL Info", "Detailed Library Info",
- QMessageBox::Ok, this);
-
+ this->openglbox = new QMessageBox(QMessageBox::Information,
+ "OpenGL Info", "OpenSCAD Detailed Library Info ",
+ QMessageBox::Ok, this);
}
-
- this->openglbox->setDetailedText(libinfo + this->glview->getRendererInfo());
+ this->openglbox->setDetailedText(libinfo + QString(qglview->getRendererInfo().c_str()));
this->openglbox->show();
}
@@ -1825,6 +1827,9 @@ void MainWindow::quit()
QApplication::sendEvent(QApplication::instance(), &ev);
if (ev.isAccepted()) QApplication::instance()->quit();
// FIXME: Cancel any CGAL calculations
+#ifdef Q_OS_MAC
+ CocoaUtils::endApplication();
+#endif
}
void MainWindow::consoleOutput(const std::string &msg, void *userdata)
@@ -1833,7 +1838,7 @@ void MainWindow::consoleOutput(const std::string &msg, void *userdata)
// originates in a worker thread.
MainWindow *thisp = static_cast<MainWindow*>(userdata);
QMetaObject::invokeMethod(thisp->console, "append", Qt::QueuedConnection,
- Q_ARG(QString, QString::fromStdString(msg)));
+ Q_ARG(QString, QString::fromLocal8Bit(msg.c_str())));
}
void MainWindow::setCurrentOutput()
contact: Jan Huwald // Impressum