Extracted MainWindow.h from openscad.h, moved GUI definition to MainWindow.ui. NB! This is not thoroughly tested yet

git-svn-id: http://svn.clifford.at/openscad/trunk@155 b57f626f-c46c-0410-a088-ec61d464b74c
stl_dim
kintel 2009-12-09 14:25:09 +00:00
parent c8baf2b227
commit 1a3769d595
7 changed files with 799 additions and 359 deletions

114
MainWindow.h Normal file
View File

@ -0,0 +1,114 @@
#ifndef MAINWINDOW_H_
#define MAINWINDOW_H_
#include <QMainWindow>
#include "ui_MainWindow.h"
#include "openscad.h"
class MainWindow : public QMainWindow, public Ui::MainWindow
{
Q_OBJECT
public:
static QPointer<MainWindow> current_win;
QString filename;
class Highlighter *highlighter;
QTimer *animate_timer;
double tval, fps, fsteps;
Context root_ctx;
AbstractModule *root_module;
AbstractNode *absolute_root_node;
CSGTerm *root_raw_term;
CSGTerm *root_norm_term;
CSGChain *root_chain;
#ifdef ENABLE_CGAL
CGAL_Nef_polyhedron *root_N;
bool recreate_cgal_ogl_p;
void *cgal_ogl_p;
#endif
QVector<CSGTerm*> highlight_terms;
CSGChain *highlights_chain;
QVector<CSGTerm*> background_terms;
CSGChain *background_chain;
AbstractNode *root_node;
QString last_compiled_doc;
bool enableOpenCSG;
MainWindow(const char *filename = 0);
~MainWindow();
private slots:
void updatedFps();
void updateTVal();
private:
void load();
void maybe_change_dir();
void find_root_tag(AbstractNode *n);
void compile(bool procevents);
private slots:
void actionNew();
void actionOpen();
void actionSave();
void actionSaveAs();
void actionReload();
private slots:
void editIndent();
void editUnindent();
void editComment();
void editUncomment();
void pasteViewportTranslation();
void pasteViewportRotation();
private slots:
void actionReloadCompile();
void actionCompile();
#ifdef ENABLE_CGAL
void actionRenderCGAL();
#endif
void actionDisplayAST();
void actionDisplayCSGTree();
void actionDisplayCSGProducts();
void actionExportSTLorOFF(bool stl_mode);
void actionExportSTL();
void actionExportOFF();
public:
void viewModeActionsUncheck();
public slots:
#ifdef ENABLE_OPENCSG
void viewModeOpenCSG();
#endif
#ifdef ENABLE_CGAL
void viewModeCGALSurface();
void viewModeCGALGrid();
#endif
void viewModeThrownTogether();
void viewModeShowEdges();
void viewModeShowAxes();
void viewModeShowCrosshairs();
void viewModeAnimate();
void viewAngleTop();
void viewAngleBottom();
void viewAngleLeft();
void viewAngleRight();
void viewAngleFront();
void viewAngleBack();
void viewAngleDiagonal();
void viewCenter();
void viewPerspective();
void viewOrthogonal();
void animateUpdateDocChanged();
void animateUpdate();
void dragEnterEvent(QDragEnterEvent *event);
void dropEvent(QDropEvent *event);
};
#endif

559
MainWindow.ui Normal file
View File

@ -0,0 +1,559 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>681</width>
<height>647</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QSplitter" name="splitter1">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QTextEdit" name="editor"/>
<widget class="QWidget" name="layoutWidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QSplitter" name="splitter2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<widget class="GLView" name="screen" native="true"/>
<widget class="QTextEdit" name="console"/>
</widget>
</item>
<item>
<widget class="QFrame" name="animate_panel">
<property name="enabled">
<bool>true</bool>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Time:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="e_tval"/>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>FPS:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="e_fps"/>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Steps:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="e_fsteps"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>681</width>
<height>22</height>
</rect>
</property>
<widget class="QMenu" name="menu_File">
<property name="title">
<string>&amp;File</string>
</property>
<addaction name="fileActionNew"/>
<addaction name="fileActionOpen"/>
<addaction name="fileActionSave"/>
<addaction name="fileActionSaveAs"/>
<addaction name="fileActionReload"/>
<addaction name="fileActionQuit"/>
</widget>
<widget class="QMenu" name="menu_Edit">
<property name="title">
<string>&amp;Edit</string>
</property>
<addaction name="editActionUndo"/>
<addaction name="editActionRedo"/>
<addaction name="separator"/>
<addaction name="editActionCut"/>
<addaction name="editActionCopy"/>
<addaction name="editActionPaste"/>
<addaction name="separator"/>
<addaction name="editActionIndent"/>
<addaction name="editActionUnindent"/>
<addaction name="separator"/>
<addaction name="editActionComment"/>
<addaction name="editActionUncomment"/>
<addaction name="separator"/>
<addaction name="editActionPasteVPT"/>
<addaction name="editActionPasteVPR"/>
<addaction name="separator"/>
<addaction name="editActionZoomIn"/>
<addaction name="editActionZoomOut"/>
</widget>
<widget class="QMenu" name="menu_Design">
<property name="title">
<string>&amp;Design</string>
</property>
<addaction name="designActionReloadAndCompile"/>
<addaction name="designActionCompile"/>
<addaction name="designActionCompileAndRender"/>
<addaction name="designActionDisplayAST"/>
<addaction name="designActionDisplayCSGTree"/>
<addaction name="designActionDisplayCSGProducts"/>
<addaction name="designActionExportSTL"/>
<addaction name="designActionExportOFF"/>
</widget>
<widget class="QMenu" name="menu_View">
<property name="title">
<string>&amp;View</string>
</property>
<addaction name="viewActionOpenCSG"/>
<addaction name="viewActionCGALSurfaces"/>
<addaction name="viewActionCGALGrid"/>
<addaction name="viewActionThrownTogether"/>
<addaction name="separator"/>
<addaction name="viewActionShowEdges"/>
<addaction name="viewActionShowAxes"/>
<addaction name="viewActionShowCrosshairs"/>
<addaction name="viewActionAnimate"/>
<addaction name="separator"/>
<addaction name="viewActionTop"/>
<addaction name="viewActionBottom"/>
<addaction name="viewActionLeft"/>
<addaction name="viewActionRight"/>
<addaction name="viewActionFront"/>
<addaction name="viewActionBack"/>
<addaction name="viewActionDiagonal"/>
<addaction name="viewActionCenter"/>
<addaction name="separator"/>
<addaction name="viewActionPerspective"/>
<addaction name="viewActionOrthogonal"/>
</widget>
<addaction name="menu_File"/>
<addaction name="menu_Edit"/>
<addaction name="menu_Design"/>
<addaction name="menu_View"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<action name="fileActionNew">
<property name="text">
<string>&amp;New</string>
</property>
<property name="shortcut">
<string>Ctrl+N</string>
</property>
</action>
<action name="fileActionOpen">
<property name="text">
<string>&amp;Open...</string>
</property>
<property name="shortcut">
<string>Ctrl+O</string>
</property>
</action>
<action name="fileActionSave">
<property name="text">
<string>&amp;Save</string>
</property>
<property name="shortcut">
<string>Ctrl+S</string>
</property>
</action>
<action name="fileActionSaveAs">
<property name="text">
<string>Save &amp;As...</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+S</string>
</property>
</action>
<action name="fileActionReload">
<property name="text">
<string>&amp;Reload</string>
</property>
<property name="shortcut">
<string>Ctrl+R</string>
</property>
</action>
<action name="fileActionQuit">
<property name="text">
<string>&amp;Quit</string>
</property>
</action>
<action name="editActionUndo">
<property name="text">
<string>&amp;Undo</string>
</property>
<property name="shortcut">
<string>Ctrl+Z</string>
</property>
</action>
<action name="editActionRedo">
<property name="text">
<string>&amp;Redo</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+Z</string>
</property>
</action>
<action name="editActionCut">
<property name="text">
<string>Cu&amp;t</string>
</property>
<property name="shortcut">
<string>Ctrl+X</string>
</property>
</action>
<action name="editActionCopy">
<property name="text">
<string>&amp;Copy</string>
</property>
<property name="shortcut">
<string>Ctrl+C</string>
</property>
</action>
<action name="editActionPaste">
<property name="text">
<string>&amp;Paste</string>
</property>
<property name="shortcut">
<string>Ctrl+V</string>
</property>
</action>
<action name="editActionIndent">
<property name="text">
<string>&amp;Indent</string>
</property>
<property name="shortcut">
<string>Ctrl+I</string>
</property>
</action>
<action name="editActionUnindent">
<property name="text">
<string>U&amp;nindent</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+I</string>
</property>
</action>
<action name="editActionComment">
<property name="text">
<string>C&amp;omment</string>
</property>
<property name="shortcut">
<string>Ctrl+D</string>
</property>
</action>
<action name="editActionUncomment">
<property name="text">
<string>Unco&amp;mment</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+D</string>
</property>
</action>
<action name="editActionPasteVPT">
<property name="text">
<string>Paste viewport translation</string>
</property>
<property name="shortcut">
<string>Ctrl+T</string>
</property>
</action>
<action name="editActionPasteVPR">
<property name="text">
<string>Paste viewport rotation</string>
</property>
</action>
<action name="editActionZoomIn">
<property name="text">
<string>Zoom In</string>
</property>
<property name="shortcut">
<string>Ctrl++</string>
</property>
</action>
<action name="editActionZoomOut">
<property name="text">
<string>Zoom Out</string>
</property>
<property name="shortcut">
<string>Ctrl+-</string>
</property>
</action>
<action name="designActionReloadAndCompile">
<property name="text">
<string>&amp;Reload and Compile</string>
</property>
<property name="shortcut">
<string>F4</string>
</property>
</action>
<action name="designActionCompile">
<property name="text">
<string>&amp;Compile</string>
</property>
<property name="shortcut">
<string>F5</string>
</property>
</action>
<action name="designActionCompileAndRender">
<property name="text">
<string>Compile and &amp;Render (CGAL)</string>
</property>
<property name="shortcut">
<string>F6</string>
</property>
</action>
<action name="designActionDisplayAST">
<property name="text">
<string>Display &amp;AST...</string>
</property>
</action>
<action name="designActionDisplayCSGTree">
<property name="text">
<string>Display CSG &amp;Tree...</string>
</property>
</action>
<action name="designActionDisplayCSGProducts">
<property name="text">
<string>Display CSG &amp;Products...</string>
</property>
</action>
<action name="designActionExportSTL">
<property name="text">
<string>Export as &amp;STL...</string>
</property>
</action>
<action name="designActionExportOFF">
<property name="text">
<string>Export as &amp;OFF...</string>
</property>
</action>
<action name="viewActionOpenCSG">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>OpenCSG</string>
</property>
<property name="shortcut">
<string>F9</string>
</property>
</action>
<action name="viewActionCGALSurfaces">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>CGAL Surfaces</string>
</property>
<property name="shortcut">
<string>F10</string>
</property>
</action>
<action name="viewActionCGALGrid">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>CGAL Grid Only</string>
</property>
<property name="shortcut">
<string>F11</string>
</property>
</action>
<action name="viewActionThrownTogether">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Thrown Together</string>
</property>
<property name="shortcut">
<string>F12</string>
</property>
</action>
<action name="viewActionShowEdges">
<property name="text">
<string>Show Edges</string>
</property>
<property name="shortcut">
<string>Ctrl+1</string>
</property>
</action>
<action name="viewActionShowAxes">
<property name="text">
<string>Show Axes</string>
</property>
<property name="shortcut">
<string>Ctrl+2</string>
</property>
</action>
<action name="viewActionShowCrosshairs">
<property name="text">
<string>Show Crosshairs</string>
</property>
<property name="shortcut">
<string>Ctrl+3</string>
</property>
</action>
<action name="viewActionAnimate">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Animate</string>
</property>
</action>
<action name="viewActionTop">
<property name="text">
<string>Top</string>
</property>
<property name="shortcut">
<string>Ctrl+4</string>
</property>
</action>
<action name="viewActionBottom">
<property name="text">
<string>Bottom</string>
</property>
<property name="shortcut">
<string>Ctrl+5</string>
</property>
</action>
<action name="viewActionLeft">
<property name="text">
<string>Left</string>
</property>
<property name="shortcut">
<string>Ctrl+6</string>
</property>
</action>
<action name="viewActionRight">
<property name="text">
<string>Right</string>
</property>
<property name="shortcut">
<string>Ctrl+7</string>
</property>
</action>
<action name="viewActionFront">
<property name="text">
<string>Front</string>
</property>
<property name="shortcut">
<string>Ctrl+8</string>
</property>
</action>
<action name="viewActionBack">
<property name="text">
<string>Back</string>
</property>
<property name="shortcut">
<string>Ctrl+9</string>
</property>
</action>
<action name="viewActionDiagonal">
<property name="text">
<string>Diagonal</string>
</property>
<property name="shortcut">
<string>Ctrl+0</string>
</property>
</action>
<action name="viewActionCenter">
<property name="text">
<string>Center</string>
</property>
<property name="shortcut">
<string>Ctrl+P</string>
</property>
</action>
<action name="viewActionPerspective">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Perspective</string>
</property>
</action>
<action name="viewActionOrthogonal">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Orthogonal</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
<class>GLView</class>
<extends>QWidget</extends>
<header>GLView.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>fileActionQuit</sender>
<signal>triggered()</signal>
<receiver>MainWindow</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>340</x>
<y>323</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -21,6 +21,8 @@
#define INCLUDE_ABSTRACT_NODE_DETAILS
#include "openscad.h"
#include "printutils.h"
#include "MainWindow.h"
#include <QApplication>
@ -39,7 +41,7 @@ void export_stl(CGAL_Nef_polyhedron *root_N, QString filename, QProgressDialog *
FILE *f = fopen(filename.toAscii().data(), "w");
if (!f) {
PRINT("Can't open STL file for STL export.");
current_win = NULL;
MainWindow::current_win = NULL;
return;
}
fprintf(f, "solid\n");

View File

@ -21,6 +21,8 @@
#define INCLUDE_ABSTRACT_NODE_DETAILS
#include "openscad.h"
#include "MainWindow.h"
#include "printutils.h"
#include <QMenu>
#include <QTime>
@ -37,6 +39,7 @@
#include <QDropEvent>
#include <QMimeData>
#include <QUrl>
#include <QTimer>
//for chdir
#include <unistd.h>
@ -60,12 +63,15 @@
#endif
QPointer<MainWindow> current_win;
QPointer<MainWindow> MainWindow::current_win = NULL;
MainWindow::MainWindow(const char *filename)
{
setupUi(this);
root_ctx.functions_p = &builtin_functions;
root_ctx.modules_p = &builtin_modules;
root_ctx.modules_p = &builtin_modules;
root_ctx.set_variable("$fn", Value(0.0));
root_ctx.set_variable("$fs", Value(1.0));
root_ctx.set_variable("$fa", Value(12.0));
@ -99,139 +105,91 @@ MainWindow::MainWindow(const char *filename)
fps = 0;
fsteps = 1;
s1 = new QSplitter(Qt::Horizontal, this);
editor = new QTextEdit(s1);
highlighter = new Highlighter(editor->document());
QFont font;
font.setStyleHint(QFont::TypeWriter);
editor->setFont(font);
QWidget *w1 = new QWidget(s1);
QVBoxLayout *l1 = new QVBoxLayout(w1);
l1->setSpacing(0);
l1->setMargin(0);
s2 = new QSplitter(Qt::Vertical, w1);
l1->addWidget(s2);
screen = new GLView(s2);
console = new QTextEdit(s2);
screen->statusLabel = new QLabel(this);
statusBar()->addWidget(screen->statusLabel);
QWidget *w2 = new QWidget(w1);
QHBoxLayout *l2 = new QHBoxLayout(w2);
l1->addWidget(w2);
animate_timer = new QTimer(this);
connect(animate_timer, SIGNAL(timeout()), this, SLOT(updateTVal()));
l2->addWidget(new QLabel("Time:", w2));
l2->addWidget(e_tval = new QLineEdit("0", w2));
connect(e_tval, SIGNAL(textChanged(QString)), this, SLOT(actionCompile()));
l2->addWidget(new QLabel("FPS:", w2));
l2->addWidget(e_fps = new QLineEdit("0", w2));
connect(e_fps, SIGNAL(textChanged(QString)), this, SLOT(updatedFps()));
l2->addWidget(new QLabel("Steps:", w2));
l2->addWidget(e_fsteps = new QLineEdit("100", w2));
animate_panel = w2;
animate_panel->hide();
{
QMenu *menu = menuBar()->addMenu("&File");
menu->addAction("&New", this, SLOT(actionNew()));
menu->addAction("&Open...", this, SLOT(actionOpen()));
menu->addAction("&Save", this, SLOT(actionSave()), QKeySequence(Qt::Key_F2));
menu->addAction("Save &As...", this, SLOT(actionSaveAs()));
menu->addAction("&Reload", this, SLOT(actionReload()), QKeySequence(Qt::Key_F3));
menu->addAction("&Quit", this, SLOT(close()));
}
{
QMenu *menu = menuBar()->addMenu("&Edit");
menu->addAction("&Undo", editor, SLOT(undo()), QKeySequence(Qt::CTRL + Qt::Key_Z));
menu->addAction("&Redo", editor, SLOT(redo()), QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Z));
menu->addSeparator();
menu->addAction("Cu&t", editor, SLOT(cut()), QKeySequence(Qt::CTRL + Qt::Key_X));
menu->addAction("&Copy", editor, SLOT(copy()), QKeySequence(Qt::CTRL + Qt::Key_C));
menu->addAction("&Paste", editor, SLOT(paste()), QKeySequence(Qt::CTRL + Qt::Key_V));
menu->addSeparator();
menu->addAction("&Indent", this, SLOT(editIndent()), QKeySequence(Qt::CTRL + Qt::Key_I));
menu->addAction("&Unindent", this, SLOT(editUnindent()), QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_I));
menu->addSeparator();
menu->addAction("C&omment", this, SLOT(editComment()), QKeySequence(Qt::CTRL + Qt::Key_D));
menu->addAction("&Uncomment", this, SLOT(editUncomment()), QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_D));
menu->addSeparator();
menu->addAction("Paste viewport translation", this, SLOT(pasteViewportTranslation()), QKeySequence(Qt::CTRL + Qt::Key_T));
menu->addAction("Paste viewport rotation", this, SLOT(pasteViewportRotation()), QKeySequence(Qt::CTRL + Qt::Key_R));
menu->addSeparator();
menu->addAction("Zoom In", editor, SLOT(zoomIn()), QKeySequence(Qt::CTRL + Qt::Key_Plus));
menu->addAction("Zoom Out", editor, SLOT(zoomOut()), QKeySequence(Qt::CTRL + Qt::Key_Minus));
}
{
QMenu *menu = menuBar()->addMenu("&Design");
menu->addAction("&Reload and Compile", this, SLOT(actionReloadCompile()), QKeySequence(Qt::Key_F4));
menu->addAction("&Compile", this, SLOT(actionCompile()), QKeySequence(Qt::Key_F5));
#ifdef ENABLE_CGAL
menu->addAction("Compile and &Render (CGAL)", this, SLOT(actionRenderCGAL()), QKeySequence(Qt::Key_F6));
// File menu
connect(this->fileActionNew, SIGNAL(triggered()), this, SLOT(actionNew()));
connect(this->fileActionOpen, SIGNAL(triggered()), this, SLOT(actionOpen()));
connect(this->fileActionSave, SIGNAL(triggered()), this, SLOT(actionSave()));
connect(this->fileActionSaveAs, SIGNAL(triggered()), this, SLOT(actionSaveAs()));
connect(this->fileActionReload, SIGNAL(triggered()), this, SLOT(actionReload()));
#ifndef __APPLE__
this->fileActionSave->setShortcut(QKeySequence(Qt::Key_F2));
this->fileActionReload->setShortcut(QKeySequence(Qt::Key_F4));
#endif
menu->addAction("Display &AST...", this, SLOT(actionDisplayAST()));
menu->addAction("Display CSG &Tree...", this, SLOT(actionDisplayCSGTree()));
menu->addAction("Display CSG &Products...", this, SLOT(actionDisplayCSGProducts()));
menu->addAction("Export as &STL...", this, SLOT(actionExportSTL()));
menu->addAction("Export as &OFF...", this, SLOT(actionExportOFF()));
// Edit menu
connect(this->editActionUndo, SIGNAL(triggered()), editor, SLOT(undo()));
connect(this->editActionRedo, SIGNAL(triggered()), editor, SLOT(redo()));
connect(this->editActionCut, SIGNAL(triggered()), editor, SLOT(cut()));
connect(this->editActionCopy, SIGNAL(triggered()), editor, SLOT(copy()));
connect(this->editActionPaste, SIGNAL(triggered()), editor, SLOT(paste()));
connect(this->editActionIndent, SIGNAL(triggered()), this, SLOT(editIndent()));
connect(this->editActionUnindent, SIGNAL(triggered()), this, SLOT(editUnindent()));
connect(this->editActionComment, SIGNAL(triggered()), this, SLOT(editComment()));
connect(this->editActionUncomment, SIGNAL(triggered()), this, SLOT(editUncomment()));
connect(this->editActionPasteVPT, SIGNAL(triggered()), this, SLOT(pasteViewportTranslation()));
connect(this->editActionPasteVPR, SIGNAL(triggered()), this, SLOT(pasteViewportRotation()));
connect(this->editActionZoomIn, SIGNAL(triggered()), editor, SLOT(zoomIn()));
connect(this->editActionZoomOut, SIGNAL(triggered()), editor, SLOT(zoomOut()));
// Design menu
connect(this->designActionReloadAndCompile, SIGNAL(triggered()), this, SLOT(actionReloadCompile()));
connect(this->designActionCompile, SIGNAL(triggered()), this, SLOT(actionCompile()));
connect(this->designActionCompileAndRender, SIGNAL(triggered()), this, SLOT(actionRenderCGAL()));
connect(this->designActionDisplayAST, SIGNAL(triggered()), this, SLOT(actionDisplayAST()));
connect(this->designActionDisplayCSGTree, SIGNAL(triggered()), this, SLOT(actionDisplayCSGTree()));
connect(this->designActionDisplayCSGProducts, SIGNAL(triggered()), this, SLOT(actionDisplayCSGProducts()));
connect(this->designActionExportSTL, SIGNAL(triggered()), this, SLOT(actionExportSTL()));
connect(this->designActionExportOFF, SIGNAL(triggered()), this, SLOT(actionExportOFF()));
// View menu
connect(this->viewActionOpenCSG, SIGNAL(triggered()), this, SLOT(viewModeOpenCSG()));
#ifndef ENABLE_OPENCSG
this->viewActionOpenCSG->setVisible(false);
#else
if (!screen->opencsg_support) {
this->viewActionOpenCSG->setEnabled(false);
}
{
QMenu *menu = menuBar()->addMenu("&View");
#ifdef ENABLE_OPENCSG
if (screen->opencsg_support) {
actViewModeOpenCSG = menu->addAction("OpenCSG", this, SLOT(viewModeOpenCSG()), QKeySequence(Qt::Key_F9));
actViewModeOpenCSG->setCheckable(true);
} else {
actViewModeOpenCSG = NULL;
}
#endif
#ifdef ENABLE_CGAL
actViewModeCGALSurface = menu->addAction("CGAL Surfaces", this, SLOT(viewModeCGALSurface()), QKeySequence(Qt::Key_F10));
actViewModeCGALGrid = menu->addAction("CGAL Grid Only", this, SLOT(viewModeCGALGrid()), QKeySequence(Qt::Key_F11));
actViewModeCGALSurface->setCheckable(true);
actViewModeCGALGrid->setCheckable(true);
#endif
actViewModeThrownTogether = menu->addAction("Thrown Together", this, SLOT(viewModeThrownTogether()), QKeySequence(Qt::Key_F12));
actViewModeThrownTogether->setCheckable(true);
menu->addSeparator();
actViewModeShowEdges = menu->addAction("Show Edges", this, SLOT(viewModeShowEdges()), QKeySequence(Qt::CTRL + Qt::Key_1));
actViewModeShowEdges->setCheckable(true);
actViewModeShowAxes = menu->addAction("Show Axes", this, SLOT(viewModeShowAxes()), QKeySequence(Qt::CTRL + Qt::Key_2));
actViewModeShowAxes->setCheckable(true);
actViewModeShowCrosshairs = menu->addAction("Show Crosshairs", this, SLOT(viewModeShowCrosshairs()), QKeySequence(Qt::CTRL + Qt::Key_3));
actViewModeShowCrosshairs->setCheckable(true);
actViewModeAnimate = menu->addAction("Animate", this, SLOT(viewModeAnimate()));
actViewModeAnimate->setCheckable(true);
connect(this->viewActionCGALSurfaces, SIGNAL(triggered()), this, SLOT(viewModeCGALSurface()));
connect(this->viewActionCGALGrid, SIGNAL(triggered()), this, SLOT(viewModeCGALGrid()));
connect(this->viewActionThrownTogether, SIGNAL(triggered()), this, SLOT(viewModeThrownTogether()));
connect(this->viewActionShowEdges, SIGNAL(triggered()), this, SLOT(viewModeShowEdges()));
connect(this->viewActionShowAxes, SIGNAL(triggered()), this, SLOT(viewModeShowAxes()));
connect(this->viewActionShowCrosshairs, SIGNAL(triggered()), this, SLOT(viewModeShowCrosshairs()));
connect(this->viewActionAnimate, SIGNAL(triggered()), this, SLOT(viewModeAnimate()));
connect(this->viewActionTop, SIGNAL(triggered()), this, SLOT(viewAngleTop()));
connect(this->viewActionBottom, SIGNAL(triggered()), this, SLOT(viewAngleBottom()));
connect(this->viewActionLeft, SIGNAL(triggered()), this, SLOT(viewAngleLeft()));
connect(this->viewActionRight, SIGNAL(triggered()), this, SLOT(viewAngleRight()));
connect(this->viewActionFront, SIGNAL(triggered()), this, SLOT(viewAngleFront()));
connect(this->viewActionBack, SIGNAL(triggered()), this, SLOT(viewAngleBack()));
connect(this->viewActionDiagonal, SIGNAL(triggered()), this, SLOT(viewAngleDiagonal()));
connect(this->viewActionCenter, SIGNAL(triggered()), this, SLOT(viewCenter()));
connect(this->viewActionPerspective, SIGNAL(triggered()), this, SLOT(viewPerspective()));
connect(this->viewActionOrthogonal, SIGNAL(triggered()), this, SLOT(viewOrthogonal()));
menu->addSeparator();
menu->addAction("Top", this, SLOT(viewAngleTop()), QKeySequence(Qt::CTRL + Qt::Key_4));
menu->addAction("Bottom", this, SLOT(viewAngleBottom()), QKeySequence(Qt::CTRL + Qt::Key_5));
menu->addAction("Left", this, SLOT(viewAngleLeft()), QKeySequence(Qt::CTRL + Qt::Key_6));
menu->addAction("Right", this, SLOT(viewAngleRight()), QKeySequence(Qt::CTRL + Qt::Key_7));
menu->addAction("Front", this, SLOT(viewAngleFront()), QKeySequence(Qt::CTRL + Qt::Key_8));
menu->addAction("Back", this, SLOT(viewAngleBack()), QKeySequence(Qt::CTRL + Qt::Key_9));
menu->addAction("Diagonal", this, SLOT(viewAngleDiagonal()), QKeySequence(Qt::CTRL + Qt::Key_0));
menu->addAction("Center", this, SLOT(viewCenter()), QKeySequence(Qt::CTRL + Qt::Key_P));
menu->addSeparator();
actViewPerspective = menu->addAction("Perspective", this, SLOT(viewPerspective()));
actViewPerspective->setCheckable(true);
actViewOrthogonal = menu->addAction("Orthogonal", this, SLOT(viewOrthogonal()));
actViewOrthogonal->setCheckable(true);
}
// #ifdef ENABLE_CGAL
// viewActionCGALSurface = menu->addAction("CGAL Surfaces", this, SLOT(viewModeCGALSurface()), QKeySequence(Qt::Key_F10));
// viewActionCGALGrid = menu->addAction("CGAL Grid Only", this, SLOT(viewModeCGALGrid()), QKeySequence(Qt::Key_F11));
// #endif
console->setReadOnly(true);
current_win = this;
@ -256,8 +214,6 @@ MainWindow::MainWindow(const char *filename)
setWindowTitle("New Document");
}
setCentralWidget(s1);
connect(editor->document(), SIGNAL(contentsChanged()), this, SLOT(animateUpdateDocChanged()));
connect(screen, SIGNAL(doAnimateUpdate()), this, SLOT(animateUpdate()));
@ -267,8 +223,8 @@ MainWindow::MainWindow(const char *filename)
// make sure it looks nice..
resize(800, 600);
s1->setSizes(QList<int>() << 400 << 400);
s2->setSizes(QList<int>() << 400 << 200);
splitter1->setSizes(QList<int>() << 400 << 400);
splitter2->setSizes(QList<int>() << 400 << 200);
#ifdef ENABLE_OPENCSG
viewModeOpenCSG();
@ -734,8 +690,8 @@ void MainWindow::actionReloadCompile()
compile(true);
#ifdef ENABLE_OPENCSG
if (!(actViewModeOpenCSG && actViewModeOpenCSG->isChecked()) &&
!actViewModeThrownTogether->isChecked()) {
if (!(viewActionOpenCSG->isVisible() && viewActionOpenCSG->isChecked()) &&
!viewActionThrownTogether->isChecked()) {
viewModeOpenCSG();
}
else
@ -751,11 +707,11 @@ void MainWindow::actionCompile()
current_win = this;
console->clear();
compile(!actViewModeAnimate->isChecked());
compile(!viewActionAnimate->isChecked());
#ifdef ENABLE_OPENCSG
if (!(actViewModeOpenCSG && actViewModeOpenCSG->isChecked()) &&
!actViewModeThrownTogether->isChecked()) {
if (!(viewActionOpenCSG->isVisible() && viewActionOpenCSG->isChecked()) &&
!viewActionThrownTogether->isChecked()) {
viewModeOpenCSG();
}
else
@ -835,7 +791,7 @@ void MainWindow::actionRenderCGAL()
int s = t.elapsed() / 1000;
PRINTF("Total rendering time: %d hours, %d minutes, %d seconds", s / (60*60), (s / 60) % 60, s % 60);
if (!actViewModeCGALSurface->isChecked() && !actViewModeCGALGrid->isChecked()) {
if (!viewActionCGALSurfaces->isChecked() && !viewActionCGALGrid->isChecked()) {
viewModeCGALSurface();
} else {
screen->updateGL();
@ -956,15 +912,12 @@ void MainWindow::actionExportOFF()
void MainWindow::viewModeActionsUncheck()
{
#ifdef ENABLE_OPENCSG
if (actViewModeOpenCSG)
actViewModeOpenCSG->setChecked(false);
#endif
viewActionOpenCSG->setChecked(false);
#ifdef ENABLE_CGAL
actViewModeCGALSurface->setChecked(false);
actViewModeCGALGrid->setChecked(false);
viewActionCGALSurfaces->setChecked(false);
viewActionCGALGrid->setChecked(false);
#endif
actViewModeThrownTogether->setChecked(false);
viewActionThrownTogether->setChecked(false);
}
#ifdef ENABLE_OPENCSG
@ -1053,12 +1006,12 @@ static void renderGLviaOpenCSG(void *vp)
GLint *shaderinfo = m->screen->shaderinfo;
if (!shaderinfo[0])
shaderinfo = NULL;
renderCSGChainviaOpenCSG(m->root_chain, m->actViewModeShowEdges->isChecked() ? shaderinfo : NULL, false, false);
renderCSGChainviaOpenCSG(m->root_chain, m->viewActionShowEdges->isChecked() ? shaderinfo : NULL, false, false);
if (m->background_chain) {
renderCSGChainviaOpenCSG(m->background_chain, m->actViewModeShowEdges->isChecked() ? shaderinfo : NULL, false, true);
renderCSGChainviaOpenCSG(m->background_chain, m->viewActionShowEdges->isChecked() ? shaderinfo : NULL, false, true);
}
if (m->highlights_chain) {
renderCSGChainviaOpenCSG(m->highlights_chain, m->actViewModeShowEdges->isChecked() ? shaderinfo : NULL, true, false);
renderCSGChainviaOpenCSG(m->highlights_chain, m->viewActionShowEdges->isChecked() ? shaderinfo : NULL, true, false);
}
}
}
@ -1067,15 +1020,11 @@ void MainWindow::viewModeOpenCSG()
{
if (screen->opencsg_support) {
viewModeActionsUncheck();
actViewModeOpenCSG->setChecked(true);
viewActionOpenCSG->setChecked(true);
screen->renderfunc = renderGLviaOpenCSG;
screen->renderfunc_vp = this;
screen->updateGL();
} else {
if (actViewModeOpenCSG) {
delete actViewModeOpenCSG;
actViewModeOpenCSG = NULL;
}
viewModeThrownTogether();
}
}
@ -1100,16 +1049,16 @@ static void renderGLviaCGAL(void *vp)
CGAL::OGL::Nef3_Converter<CGAL_Nef_polyhedron>::convert_to_OGLPolyhedron(*m->root_N, p);
p->init();
}
if (m->actViewModeCGALSurface->isChecked())
if (m->viewActionCGALSurfaces->isChecked())
p->set_style(CGAL::OGL::SNC_BOUNDARY);
if (m->actViewModeCGALGrid->isChecked())
if (m->viewActionCGALGrid->isChecked())
p->set_style(CGAL::OGL::SNC_SKELETON);
#if 0
p->draw();
#else
if (p->style == CGAL::OGL::SNC_BOUNDARY) {
glCallList(p->object_list_+2);
if (m->actViewModeShowEdges->isChecked()) {
if (m->viewActionShowEdges->isChecked()) {
glDisable(GL_LIGHTING);
glCallList(p->object_list_+1);
glCallList(p->object_list_);
@ -1126,7 +1075,7 @@ static void renderGLviaCGAL(void *vp)
void MainWindow::viewModeCGALSurface()
{
viewModeActionsUncheck();
actViewModeCGALSurface->setChecked(true);
viewActionCGALSurfaces->setChecked(true);
screen->renderfunc = renderGLviaCGAL;
screen->renderfunc_vp = this;
screen->updateGL();
@ -1135,7 +1084,7 @@ void MainWindow::viewModeCGALSurface()
void MainWindow::viewModeCGALGrid()
{
viewModeActionsUncheck();
actViewModeCGALGrid->setChecked(true);
viewActionCGALGrid->setChecked(true);
screen->renderfunc = renderGLviaCGAL;
screen->renderfunc_vp = this;
screen->updateGL();
@ -1147,7 +1096,7 @@ static void renderGLThrownTogetherChain(MainWindow *m, CSGChain *chain, bool hig
{
glDepthFunc(GL_LEQUAL);
QHash<QPair<PolySet*,double*>,int> polySetVisitMark;
bool showEdges = m->actViewModeShowEdges->isChecked();
bool showEdges = m->viewActionShowEdges->isChecked();
for (int i = 0; i < chain->polysets.size(); i++) {
if (polySetVisitMark[QPair<PolySet*,double*>(chain->polysets[i], chain->matrices[i])]++ > 0)
continue;
@ -1209,7 +1158,7 @@ static void renderGLThrownTogether(void *vp)
void MainWindow::viewModeThrownTogether()
{
viewModeActionsUncheck();
actViewModeThrownTogether->setChecked(true);
viewActionThrownTogether->setChecked(true);
screen->renderfunc = renderGLThrownTogether;
screen->renderfunc_vp = this;
screen->updateGL();
@ -1222,19 +1171,19 @@ void MainWindow::viewModeShowEdges()
void MainWindow::viewModeShowAxes()
{
screen->showaxes = actViewModeShowAxes->isChecked();
screen->showaxes = viewActionShowAxes->isChecked();
screen->updateGL();
}
void MainWindow::viewModeShowCrosshairs()
{
screen->showcrosshairs = actViewModeShowCrosshairs->isChecked();
screen->showcrosshairs = viewActionShowCrosshairs->isChecked();
screen->updateGL();
}
void MainWindow::viewModeAnimate()
{
if (actViewModeAnimate->isChecked()) {
if (viewActionAnimate->isChecked()) {
animate_panel->show();
actionCompile();
updatedFps();
@ -1331,16 +1280,16 @@ void MainWindow::viewCenter()
void MainWindow::viewPerspective()
{
actViewPerspective->setChecked(true);
actViewOrthogonal->setChecked(false);
viewActionPerspective->setChecked(true);
viewActionOrthogonal->setChecked(false);
screen->orthomode = false;
screen->updateGL();
}
void MainWindow::viewOrthogonal()
{
actViewPerspective->setChecked(false);
actViewOrthogonal->setChecked(true);
viewActionPerspective->setChecked(false);
viewActionOrthogonal->setChecked(true);
screen->orthomode = true;
screen->updateGL();
}

View File

@ -21,6 +21,7 @@
#define INCLUDE_ABSTRACT_NODE_DETAILS
#include "openscad.h"
#include "MainWindow.h"
#include <QApplication>
#include <QFile>

View File

@ -29,16 +29,9 @@
#include <QHash>
#include <QCache>
#include <QVector>
#include <QMainWindow>
#include <QProgressDialog>
#include <QSyntaxHighlighter>
#include <QSplitter>
#include <QTextEdit>
#include <QLineEdit>
#include <QGLWidget>
#include <QPointer>
#include <QLabel>
#include <QTimer>
#include <stdio.h>
#include <errno.h>
@ -530,13 +523,13 @@ public:
class PolySetPtr
{
public:
PolySet *ps;
PolySetPtr(PolySet *ps) {
this->ps = ps;
}
~PolySetPtr() {
ps->unlink();
}
PolySet *ps;
PolySetPtr(PolySet *ps) {
this->ps = ps;
}
~PolySetPtr() {
ps->unlink();
}
};
class CSGTerm
@ -652,62 +645,6 @@ struct CGAL_Nef_polyhedron;
#endif /* HIDE_ABSTRACT_NODE_DETAILS */
class GLView : public QGLWidget
{
Q_OBJECT
public:
void (*renderfunc)(void*);
void *renderfunc_vp;
bool orthomode;
bool showaxes;
bool showcrosshairs;
double viewer_distance;
double object_rot_x;
double object_rot_y;
double object_rot_z;
double object_trans_x;
double object_trans_y;
double object_trans_z;
double w_h_ratio;
GLint shaderinfo[11];
QLabel *statusLabel;
#ifdef ENABLE_OPENCSG
bool opencsg_support;
#endif
GLView(QWidget *parent = NULL);
protected:
bool mouse_drag_active;
int last_mouse_x;
int last_mouse_y;
void keyPressEvent(QKeyEvent *event);
void wheelEvent(QWheelEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void initializeGL();
void resizeGL(int w, int h);
void paintGL();
#ifdef ENABLE_OPENCSG
private slots:
void display_opengl20_warning();
#endif
signals:
void doAnimateUpdate();
};
class MainWindow;
class Highlighter : public QSyntaxHighlighter
{
public:
@ -715,136 +652,11 @@ public:
void highlightBlock(const QString &text);
};
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
QString filename;
QSplitter *s1, *s2;
QTextEdit *editor;
Highlighter *highlighter;
GLView *screen;
QTextEdit *console;
QWidget *animate_panel;
QTimer *animate_timer;
double tval, fps, fsteps;
QLineEdit *e_tval, *e_fps, *e_fsteps;
Context root_ctx;
AbstractModule *root_module;
AbstractNode *absolute_root_node;
CSGTerm *root_raw_term;
CSGTerm *root_norm_term;
CSGChain *root_chain;
#ifdef ENABLE_CGAL
CGAL_Nef_polyhedron *root_N;
bool recreate_cgal_ogl_p;
void *cgal_ogl_p;
#endif
QVector<CSGTerm*> highlight_terms;
CSGChain *highlights_chain;
QVector<CSGTerm*> background_terms;
CSGChain *background_chain;
AbstractNode *root_node;
QString last_compiled_doc;
bool enableOpenCSG;
MainWindow(const char *filename = 0);
~MainWindow();
private slots:
void updatedFps();
void updateTVal();
private:
void load();
void maybe_change_dir();
void find_root_tag(AbstractNode *n);
void compile(bool procevents);
private slots:
void actionNew();
void actionOpen();
void actionSave();
void actionSaveAs();
void actionReload();
private slots:
void editIndent();
void editUnindent();
void editComment();
void editUncomment();
void pasteViewportTranslation();
void pasteViewportRotation();
private slots:
void actionReloadCompile();
void actionCompile();
#ifdef ENABLE_CGAL
void actionRenderCGAL();
#endif
void actionDisplayAST();
void actionDisplayCSGTree();
void actionDisplayCSGProducts();
void actionExportSTLorOFF(bool stl_mode);
void actionExportSTL();
void actionExportOFF();
public:
#ifdef ENABLE_OPENCSG
QAction *actViewModeOpenCSG;
#endif
#ifdef ENABLE_CGAL
QAction *actViewModeCGALSurface;
QAction *actViewModeCGALGrid;
#endif
QAction *actViewModeThrownTogether;
QAction *actViewModeShowEdges;
QAction *actViewModeShowAxes;
QAction *actViewModeShowCrosshairs;
QAction *actViewModeAnimate;
QAction *actViewPerspective;
QAction *actViewOrthogonal;
void viewModeActionsUncheck();
public slots:
#ifdef ENABLE_OPENCSG
void viewModeOpenCSG();
#endif
#ifdef ENABLE_CGAL
void viewModeCGALSurface();
void viewModeCGALGrid();
#endif
void viewModeThrownTogether();
void viewModeShowEdges();
void viewModeShowAxes();
void viewModeShowCrosshairs();
void viewModeAnimate();
void viewAngleTop();
void viewAngleBottom();
void viewAngleLeft();
void viewAngleRight();
void viewAngleFront();
void viewAngleBack();
void viewAngleDiagonal();
void viewCenter();
void viewPerspective();
void viewOrthogonal();
void animateUpdateDocChanged();
void animateUpdate();
void dragEnterEvent(QDragEnterEvent *event);
void dropEvent(QDropEvent *event);
};
extern AbstractModule *parse(const char *text, int debug);
extern int get_fragments_from_r(double r, double fn, double fs, double fa);
extern QString commandline_commands;
extern int parser_error_pos;
extern QPointer<MainWindow> current_win;
#ifdef ENABLE_CGAL
void export_stl(CGAL_Nef_polyhedron *root_N, QString filename, QProgressDialog *pd);
@ -852,9 +664,5 @@ void export_off(CGAL_Nef_polyhedron *root_N, QString filename, QProgressDialog *
#endif
extern void handle_dep(QString filename);
#define PRINT(_msg) do { if (current_win.isNull()) fprintf(stderr, "%s\n", QString(_msg).toAscii().data()); else current_win->console->append(_msg); } while (0)
#define PRINTF(_fmt, ...) do { QString _m; _m.sprintf(_fmt, ##__VA_ARGS__); PRINT(_m); } while (0)
#define PRINTA(_fmt, ...) do { QString _m = QString(_fmt).arg(__VA_ARGS__); PRINT(_m); } while (0)
#endif

View File

@ -35,13 +35,20 @@ win32:LIBS += -lglew32 -lboost_thread -lgmp
LEXSOURCES += lexer.l
YACCSOURCES += parser.y
HEADERS += openscad.h
SOURCES += openscad.cc mainwin.cc glview.cc export.cc
SOURCES += value.cc expr.cc func.cc module.cc context.cc
SOURCES += csgterm.cc polyset.cc csgops.cc transform.cc
SOURCES += primitives.cc surface.cc control.cc render.cc
SOURCES += import.cc dxfdata.cc dxftess.cc dxfdim.cc
SOURCES += dxflinextrude.cc dxfrotextrude.cc highlighter.cc
FORMS += MainWindow.ui
HEADERS += openscad.h \
MainWindow.h \
GLView.h \
printutils.h
SOURCES += openscad.cc mainwin.cc glview.cc export.cc \
value.cc expr.cc func.cc module.cc context.cc \
csgterm.cc polyset.cc csgops.cc transform.cc \
primitives.cc surface.cc control.cc render.cc \
import.cc dxfdata.cc dxftess.cc dxfdim.cc \
dxflinextrude.cc dxfrotextrude.cc highlighter.cc \
printutils.cc
QMAKE_CXXFLAGS += -O0
# QMAKE_CXXFLAGS += -O3 -march=pentium