2014-04-28 21:09:25 +04:00
|
|
|
#pragma once
|
2009-12-09 17:25:09 +03:00
|
|
|
|
2014-10-18 21:13:57 +04:00
|
|
|
#include "qtgettext.h"
|
2009-12-09 17:25:09 +03:00
|
|
|
#include <QMainWindow>
|
2014-06-28 18:37:12 +04:00
|
|
|
#include <QIcon>
|
2009-12-09 17:25:09 +03:00
|
|
|
#include "ui_MainWindow.h"
|
2014-09-14 04:08:57 +04:00
|
|
|
#include "UIUtils.h"
|
2009-12-09 17:25:09 +03:00
|
|
|
#include "openscad.h"
|
2013-04-09 08:28:16 +04:00
|
|
|
#include "modcontext.h"
|
2010-01-30 07:26:05 +03:00
|
|
|
#include "module.h"
|
2010-07-12 01:29:01 +04:00
|
|
|
#include "Tree.h"
|
2011-12-06 04:16:54 +04:00
|
|
|
#include "memory.h"
|
2014-06-07 19:42:41 +04:00
|
|
|
#include "editor.h"
|
2010-09-07 04:02:22 +04:00
|
|
|
#include <vector>
|
2011-12-26 02:00:30 +04:00
|
|
|
#include <QMutex>
|
2014-02-21 11:09:30 +04:00
|
|
|
#include <QSet>
|
2014-12-17 02:01:25 +03:00
|
|
|
#include <QTime>
|
2009-12-09 17:25:09 +03:00
|
|
|
|
2014-02-11 02:43:57 +04:00
|
|
|
enum export_type_e {
|
|
|
|
EXPORT_TYPE_UNKNOWN,
|
|
|
|
EXPORT_TYPE_STL,
|
|
|
|
EXPORT_TYPE_AMF,
|
|
|
|
EXPORT_TYPE_OFF
|
|
|
|
};
|
2009-12-09 17:25:09 +03:00
|
|
|
|
|
|
|
class MainWindow : public QMainWindow, public Ui::MainWindow
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2009-12-13 00:27:54 +03:00
|
|
|
static void requestOpenFile(const QString &filename);
|
2009-12-09 17:25:09 +03:00
|
|
|
|
2009-12-13 23:24:15 +03:00
|
|
|
QString fileName;
|
2009-12-09 17:25:09 +03:00
|
|
|
|
2010-01-15 04:02:28 +03:00
|
|
|
class Preferences *prefs;
|
|
|
|
|
2009-12-09 17:25:09 +03:00
|
|
|
QTimer *animate_timer;
|
|
|
|
double tval, fps, fsteps;
|
|
|
|
|
2010-05-09 17:27:05 +04:00
|
|
|
QTimer *autoReloadTimer;
|
2012-02-14 04:30:39 +04:00
|
|
|
std::string autoReloadId;
|
2013-05-28 09:25:03 +04:00
|
|
|
QTimer *waitAfterReloadTimer;
|
2010-05-09 17:27:05 +04:00
|
|
|
|
2014-12-17 02:01:25 +03:00
|
|
|
QTime renderingTime;
|
|
|
|
|
2013-04-24 17:17:25 +04:00
|
|
|
ModuleContext top_ctx;
|
2013-04-20 01:52:01 +04:00
|
|
|
FileModule *root_module; // Result of parsing
|
2010-01-10 01:43:33 +03:00
|
|
|
ModuleInstantiation root_inst; // Top level instance
|
2010-01-07 00:35:01 +03:00
|
|
|
AbstractNode *absolute_root_node; // Result of tree evaluation
|
|
|
|
AbstractNode *root_node; // Root if the root modifier (!) is used
|
2010-07-12 01:29:01 +04:00
|
|
|
Tree tree;
|
2010-01-07 00:35:01 +03:00
|
|
|
|
2011-12-06 04:16:54 +04:00
|
|
|
shared_ptr<class CSGTerm> root_raw_term; // Result of CSG term rendering
|
|
|
|
shared_ptr<CSGTerm> root_norm_term; // Normalized CSG products
|
2010-01-30 07:26:05 +03:00
|
|
|
class CSGChain *root_chain;
|
2009-12-09 17:25:09 +03:00
|
|
|
#ifdef ENABLE_CGAL
|
2013-12-22 10:43:08 +04:00
|
|
|
shared_ptr<const class Geometry> root_geom;
|
2011-07-30 23:29:40 +04:00
|
|
|
class CGALRenderer *cgalRenderer;
|
2009-12-09 17:25:09 +03:00
|
|
|
#endif
|
2011-07-30 23:29:40 +04:00
|
|
|
#ifdef ENABLE_OPENCSG
|
|
|
|
class OpenCSGRenderer *opencsgRenderer;
|
|
|
|
#endif
|
|
|
|
class ThrownTogetherRenderer *thrownTogetherRenderer;
|
2009-12-09 17:25:09 +03:00
|
|
|
|
2011-12-06 04:16:54 +04:00
|
|
|
std::vector<shared_ptr<CSGTerm> > highlight_terms;
|
2009-12-09 17:25:09 +03:00
|
|
|
CSGChain *highlights_chain;
|
2011-12-06 04:16:54 +04:00
|
|
|
std::vector<shared_ptr<CSGTerm> > background_terms;
|
2009-12-09 17:25:09 +03:00
|
|
|
CSGChain *background_chain;
|
|
|
|
QString last_compiled_doc;
|
|
|
|
|
2014-09-14 04:08:57 +04:00
|
|
|
QAction *actionRecentFile[UIUtils::maxRecentFiles];
|
2014-05-13 00:47:42 +04:00
|
|
|
QMap<QString, QString> knownFileExtensions;
|
2014-09-13 23:19:44 +04:00
|
|
|
|
2014-12-23 08:24:57 +03:00
|
|
|
QLabel *versionLabel;
|
2014-11-01 20:55:48 +03:00
|
|
|
QWidget *editorDockTitleWidget;
|
|
|
|
QWidget *consoleDockTitleWidget;
|
|
|
|
|
2014-08-07 06:04:37 +04:00
|
|
|
QString editortype;
|
|
|
|
bool useScintilla;
|
2009-12-13 23:24:15 +03:00
|
|
|
|
2015-01-07 05:14:46 +03:00
|
|
|
int compileErrors;
|
|
|
|
int compileWarnings;
|
|
|
|
|
2013-10-04 07:21:26 +04:00
|
|
|
MainWindow(const QString &filename);
|
2009-12-09 17:25:09 +03:00
|
|
|
~MainWindow();
|
|
|
|
|
2009-12-14 07:24:51 +03:00
|
|
|
protected:
|
|
|
|
void closeEvent(QCloseEvent *event);
|
|
|
|
|
2009-12-09 17:25:09 +03:00
|
|
|
private slots:
|
|
|
|
void updatedFps();
|
|
|
|
void updateTVal();
|
2014-05-13 00:47:42 +04:00
|
|
|
void updateMdiMode(bool mdi);
|
|
|
|
void updateUndockMode(bool undockMode);
|
2014-11-01 20:55:48 +03:00
|
|
|
void updateReorderMode(bool reorderMode);
|
2009-12-13 23:24:15 +03:00
|
|
|
void setFileName(const QString &filename);
|
2010-01-22 15:28:30 +03:00
|
|
|
void setFont(const QString &family, uint size);
|
2014-08-15 01:16:24 +04:00
|
|
|
void setColorScheme(const QString &cs);
|
2010-02-12 18:43:56 +03:00
|
|
|
void showProgress();
|
2012-01-14 04:22:46 +04:00
|
|
|
void openCSGSettingsChanged();
|
2015-02-05 20:08:38 +03:00
|
|
|
void consoleOutput(const QString &msg);
|
2015-02-04 09:20:53 +03:00
|
|
|
|
2009-12-09 17:25:09 +03:00
|
|
|
private:
|
2015-01-09 21:04:43 +03:00
|
|
|
void initActionIcon(QAction *action, const char *darkResource, const char *lightResource);
|
2009-12-13 00:27:54 +03:00
|
|
|
void openFile(const QString &filename);
|
2014-05-13 00:47:42 +04:00
|
|
|
void handleFileDrop(const QString &filename);
|
2012-02-14 04:30:39 +04:00
|
|
|
void refreshDocument();
|
2014-06-21 03:28:34 +04:00
|
|
|
void updateCamera();
|
2012-02-14 04:30:39 +04:00
|
|
|
void updateTemporalVariables();
|
|
|
|
bool fileChangedOnDisk();
|
2013-05-28 09:25:03 +04:00
|
|
|
void compileTopLevelDocument();
|
2015-01-07 05:14:46 +03:00
|
|
|
void updateCompileResult();
|
2013-05-28 09:25:03 +04:00
|
|
|
void compile(bool reload, bool forcedone = false);
|
2010-02-09 16:48:09 +03:00
|
|
|
void compileCSG(bool procevents);
|
2009-12-14 07:24:51 +03:00
|
|
|
bool maybeSave();
|
2012-02-22 16:50:38 +04:00
|
|
|
bool checkEditorModified();
|
2010-04-12 04:16:36 +04:00
|
|
|
QString dumpCSGTree(AbstractNode *root);
|
2011-12-26 02:00:30 +04:00
|
|
|
static void consoleOutput(const std::string &msg, void *userdata);
|
2011-07-04 00:57:07 +04:00
|
|
|
void loadViewSettings();
|
2011-07-06 03:07:26 +04:00
|
|
|
void loadDesignSettings();
|
2014-02-13 09:15:35 +04:00
|
|
|
void saveBackup();
|
|
|
|
void writeBackup(class QFile *file);
|
2014-05-13 08:50:25 +04:00
|
|
|
QString get2dExportFilename(QString format, QString extension);
|
2014-05-03 23:13:06 +04:00
|
|
|
void show_examples();
|
2014-05-13 08:50:25 +04:00
|
|
|
void setDockWidgetTitle(QDockWidget *dockWidget, QString prefix, bool topLevel);
|
2014-09-19 00:55:06 +04:00
|
|
|
void addKeyboardShortCut(const QList<QAction *> &actions);
|
2014-12-23 08:24:57 +03:00
|
|
|
void updateStatusBar(class ProgressWidget *progressWidget);
|
2009-12-09 17:25:09 +03:00
|
|
|
|
2014-06-07 19:22:14 +04:00
|
|
|
EditorInterface *editor;
|
2014-06-07 19:42:41 +04:00
|
|
|
|
2014-09-15 06:08:18 +04:00
|
|
|
class LibraryInfoDialog* library_info_dialog;
|
2013-11-21 04:01:42 +04:00
|
|
|
class FontListDialog *font_list_dialog;
|
2011-12-09 06:43:06 +04:00
|
|
|
|
2009-12-09 17:25:09 +03:00
|
|
|
private slots:
|
|
|
|
void actionNew();
|
|
|
|
void actionOpen();
|
2009-12-13 23:24:15 +03:00
|
|
|
void actionOpenRecent();
|
2010-01-22 18:20:52 +03:00
|
|
|
void actionOpenExample();
|
2011-09-08 11:52:02 +04:00
|
|
|
void updateRecentFiles();
|
2009-12-13 23:24:15 +03:00
|
|
|
void clearRecentFiles();
|
|
|
|
void updateRecentFileActions();
|
2009-12-09 17:25:09 +03:00
|
|
|
void actionSave();
|
|
|
|
void actionSaveAs();
|
|
|
|
void actionReload();
|
2013-05-22 02:02:16 +04:00
|
|
|
void actionShowLibraryFolder();
|
2014-09-20 01:25:49 +04:00
|
|
|
void convertTabsToSpaces();
|
2009-12-09 17:25:09 +03:00
|
|
|
|
2013-05-28 09:25:03 +04:00
|
|
|
void instantiateRoot();
|
|
|
|
void compileDone(bool didchange);
|
|
|
|
void compileEnded();
|
|
|
|
|
2009-12-09 17:25:09 +03:00
|
|
|
private slots:
|
|
|
|
void pasteViewportTranslation();
|
|
|
|
void pasteViewportRotation();
|
2010-01-15 04:02:28 +03:00
|
|
|
void preferences();
|
2014-10-01 01:18:40 +04:00
|
|
|
void hideToolbars();
|
|
|
|
void hideEditor();
|
|
|
|
void hideConsole();
|
2015-01-07 05:14:46 +03:00
|
|
|
void showConsole();
|
2009-12-09 17:25:09 +03:00
|
|
|
|
2014-02-01 14:46:05 +04:00
|
|
|
private slots:
|
2014-02-01 18:53:18 +04:00
|
|
|
void selectFindType(int);
|
2014-02-01 14:46:05 +04:00
|
|
|
void find();
|
2014-08-14 02:52:01 +04:00
|
|
|
void findString(QString);
|
2014-02-01 18:53:18 +04:00
|
|
|
void findAndReplace();
|
2014-02-01 14:46:05 +04:00
|
|
|
void findNext();
|
|
|
|
void findPrev();
|
2014-09-19 21:52:01 +04:00
|
|
|
void useSelectionForFind();
|
2014-02-01 18:53:18 +04:00
|
|
|
void replace();
|
|
|
|
void replaceAll();
|
2014-09-20 00:35:20 +04:00
|
|
|
|
|
|
|
// Mac OSX FindBuffer support
|
|
|
|
void findBufferChanged();
|
|
|
|
void updateFindBuffer(QString);
|
2014-02-01 14:46:05 +04:00
|
|
|
protected:
|
|
|
|
virtual bool eventFilter(QObject* obj, QEvent *event);
|
|
|
|
|
2009-12-09 17:25:09 +03:00
|
|
|
private slots:
|
2013-12-22 10:43:08 +04:00
|
|
|
void actionRenderPreview();
|
2013-05-28 09:25:03 +04:00
|
|
|
void csgRender();
|
|
|
|
void csgReloadRender();
|
2009-12-09 17:25:09 +03:00
|
|
|
#ifdef ENABLE_CGAL
|
2013-12-22 10:43:08 +04:00
|
|
|
void actionRender();
|
|
|
|
void actionRenderDone(shared_ptr<const class Geometry>);
|
2013-05-28 09:25:03 +04:00
|
|
|
void cgalRender();
|
2009-12-09 17:25:09 +03:00
|
|
|
#endif
|
2014-02-03 18:10:46 +04:00
|
|
|
void actionCheckValidity();
|
2009-12-09 17:25:09 +03:00
|
|
|
void actionDisplayAST();
|
|
|
|
void actionDisplayCSGTree();
|
|
|
|
void actionDisplayCSGProducts();
|
2014-02-11 02:43:57 +04:00
|
|
|
void actionExport(export_type_e, const char *, const char *);
|
2009-12-09 17:25:09 +03:00
|
|
|
void actionExportSTL();
|
|
|
|
void actionExportOFF();
|
2014-02-11 02:43:57 +04:00
|
|
|
void actionExportAMF();
|
2010-01-06 05:04:49 +03:00
|
|
|
void actionExportDXF();
|
2014-03-02 22:26:17 +04:00
|
|
|
void actionExportSVG();
|
2011-10-19 19:35:14 +04:00
|
|
|
void actionExportCSG();
|
2011-06-05 22:05:55 +04:00
|
|
|
void actionExportImage();
|
2015-05-16 18:41:52 +03:00
|
|
|
void actionCopyViewport();
|
2010-01-08 00:08:47 +03:00
|
|
|
void actionFlushCaches();
|
2009-12-09 17:25:09 +03:00
|
|
|
|
|
|
|
public:
|
2014-10-10 06:13:18 +04:00
|
|
|
static QSet<MainWindow*> *getWindows();
|
2009-12-09 17:25:09 +03:00
|
|
|
void viewModeActionsUncheck();
|
2010-02-28 23:54:55 +03:00
|
|
|
void setCurrentOutput();
|
|
|
|
void clearCurrentOutput();
|
2009-12-09 17:25:09 +03:00
|
|
|
|
|
|
|
public slots:
|
2013-12-22 10:43:08 +04:00
|
|
|
void actionReloadRenderPreview();
|
2014-05-13 00:47:42 +04:00
|
|
|
void on_editorDock_visibilityChanged(bool);
|
|
|
|
void on_consoleDock_visibilityChanged(bool);
|
2015-01-09 20:20:07 +03:00
|
|
|
void on_toolButtonCompileResultClose_clicked();
|
2014-05-13 00:47:42 +04:00
|
|
|
void editorTopLevelChanged(bool);
|
|
|
|
void consoleTopLevelChanged(bool);
|
2009-12-09 17:25:09 +03:00
|
|
|
#ifdef ENABLE_OPENCSG
|
2013-12-22 10:43:08 +04:00
|
|
|
void viewModePreview();
|
2009-12-09 17:25:09 +03:00
|
|
|
#endif
|
|
|
|
#ifdef ENABLE_CGAL
|
2013-12-22 10:43:08 +04:00
|
|
|
void viewModeSurface();
|
|
|
|
void viewModeWireframe();
|
2009-12-09 17:25:09 +03:00
|
|
|
#endif
|
|
|
|
void viewModeThrownTogether();
|
|
|
|
void viewModeShowEdges();
|
|
|
|
void viewModeShowAxes();
|
|
|
|
void viewModeShowCrosshairs();
|
2015-01-02 10:32:37 +03:00
|
|
|
void viewModeShowScaleProportional();
|
2009-12-09 17:25:09 +03:00
|
|
|
void viewModeAnimate();
|
|
|
|
void viewAngleTop();
|
|
|
|
void viewAngleBottom();
|
|
|
|
void viewAngleLeft();
|
|
|
|
void viewAngleRight();
|
|
|
|
void viewAngleFront();
|
|
|
|
void viewAngleBack();
|
|
|
|
void viewAngleDiagonal();
|
|
|
|
void viewCenter();
|
|
|
|
void viewPerspective();
|
|
|
|
void viewOrthogonal();
|
2014-04-11 03:18:08 +04:00
|
|
|
void viewResetView();
|
2014-06-22 00:12:55 +04:00
|
|
|
void viewAll();
|
2009-12-09 17:25:09 +03:00
|
|
|
void animateUpdateDocChanged();
|
|
|
|
void animateUpdate();
|
|
|
|
void dragEnterEvent(QDragEnterEvent *event);
|
|
|
|
void dropEvent(QDropEvent *event);
|
2009-12-13 01:04:32 +03:00
|
|
|
void helpAbout();
|
2010-02-20 13:20:18 +03:00
|
|
|
void helpHomepage();
|
2009-12-13 01:19:53 +03:00
|
|
|
void helpManual();
|
2015-01-14 22:01:53 +03:00
|
|
|
void helpCheatSheet();
|
2012-02-15 04:26:38 +04:00
|
|
|
void helpLibrary();
|
2013-11-21 04:01:42 +04:00
|
|
|
void helpFontInfo();
|
2010-01-26 00:39:34 +03:00
|
|
|
void quit();
|
2010-05-09 17:27:05 +04:00
|
|
|
void checkAutoReload();
|
2013-05-28 09:25:03 +04:00
|
|
|
void waitAfterReload();
|
2010-05-09 17:27:05 +04:00
|
|
|
void autoReloadSet(bool);
|
2014-11-06 10:14:04 +03:00
|
|
|
void setContentsChanged();
|
2015-02-03 22:35:54 +03:00
|
|
|
void showFontCacheDialog();
|
|
|
|
void hideFontCacheDialog();
|
2011-12-26 02:00:30 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
static void report_func(const class AbstractNode*, void *vp, int mark);
|
2014-10-10 06:13:18 +04:00
|
|
|
static bool mdiMode;
|
|
|
|
static bool undockMode;
|
2014-11-01 20:55:48 +03:00
|
|
|
static bool reorderMode;
|
2014-10-10 06:13:18 +04:00
|
|
|
static QSet<MainWindow*> *windows;
|
2015-02-03 22:35:54 +03:00
|
|
|
static class QProgressDialog *fontCacheDialog;
|
2011-12-26 02:00:30 +04:00
|
|
|
|
2013-05-28 09:25:03 +04:00
|
|
|
char const * afterCompileSlot;
|
|
|
|
bool procevents;
|
2014-02-13 09:15:35 +04:00
|
|
|
class QTemporaryFile *tempFile;
|
2011-12-26 02:00:30 +04:00
|
|
|
class ProgressWidget *progresswidget;
|
|
|
|
class CGALWorker *cgalworker;
|
|
|
|
QMutex consolemutex;
|
2014-11-06 10:14:04 +03:00
|
|
|
bool contentschanged; // Set if the source code has changes since the last render (F6)
|
2014-04-11 03:18:08 +04:00
|
|
|
|
2014-02-17 23:19:42 +04:00
|
|
|
signals:
|
|
|
|
void highlightError(int);
|
|
|
|
void unhighlightLastError();
|
2009-12-09 17:25:09 +03:00
|
|
|
};
|
|
|
|
|
2010-11-06 18:03:01 +03:00
|
|
|
class GuiLocker
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GuiLocker() {
|
|
|
|
gui_locked++;
|
|
|
|
}
|
|
|
|
~GuiLocker() {
|
|
|
|
gui_locked--;
|
|
|
|
}
|
|
|
|
static bool isLocked() { return gui_locked > 0; }
|
2011-12-26 02:00:30 +04:00
|
|
|
static void lock() { gui_locked++; }
|
|
|
|
static void unlock() { gui_locked--; }
|
2010-11-06 18:03:01 +03:00
|
|
|
|
|
|
|
private:
|
2013-10-04 07:21:26 +04:00
|
|
|
static unsigned int gui_locked;
|
2010-11-06 18:03:01 +03:00
|
|
|
};
|