summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README42
-rw-r--r--example.scad12
-rw-r--r--mainwin.cc51
3 files changed, 98 insertions, 7 deletions
diff --git a/README b/README
new file mode 100644
index 0000000..2ae9eb4
--- /dev/null
+++ b/README
@@ -0,0 +1,42 @@
+
+WHAT IS IT?
+===========
+
+OpenSCAD (Open Solid CAD) is a tool for designing solid 3D objects using CSG
+techniques. Basically OpenSCAD is a compiler that transforms descriptions of
+3D objects written in a special computer language to 3D models.
+
+FIXME: Add some more introduction..
+
+
+PREREQUISITES
+=============
+
+To build OpenSCAD, you need some libraries and tools. The version numbers in
+brakets specify the versions I have used for my tests. Other versions may or
+may not work as well..
+
+* Qt4 (4.5.1):
+ http://www.qtsoftware.com/
+
+* CGAL (3.4):
+ http://www.cgal.org/
+
+* OpenCSG (1.1.0):
+ http://www.opencsg.org/
+
+* GCC C++ Compiler (4.3.1):
+ http://gcc.gnu.org/
+
+* Bison (2.4):
+ http://www.gnu.org/software/bison/
+
+* Flex (2.5.35):
+ http://flex.sourceforge.net/
+
+
+LANGUAGE DESCRIPTION
+====================
+
+FIXME: This still needs to be written..
+
diff --git a/example.scad b/example.scad
index b74c29c..8583963 100644
--- a/example.scad
+++ b/example.scad
@@ -31,8 +31,16 @@ module test002()
module test003()
{
- cylinder(h = 5, r1 = 3, r2 = 1, center = true);
- // cylinder(h = 7, r1 = 1, r2 = 5, center = true);
+ intersection() {
+ difference() {
+ cube([3 3 3], center = true);
+ cube([5 1 1], center = true);
+ cube([1 5 1], center = true);
+ cube([1 1 5], center = true);
+ }
+ trans([0 0 0.5])
+ cylinder(h = 5, r1 = 2, r2 = 0.5, center = true);
+ }
}
test003();
diff --git a/mainwin.cc b/mainwin.cc
index 943bf65..c6e3402 100644
--- a/mainwin.cc
+++ b/mainwin.cc
@@ -25,6 +25,8 @@
#include <QMenu>
#include <QMenuBar>
#include <QSplitter>
+#include <QFileDialog>
+#include <QApplication>
MainWindow::MainWindow(const char *filename)
{
@@ -103,7 +105,7 @@ MainWindow::MainWindow(const char *filename)
QString text;
FILE *fp = fopen(filename, "rt");
if (!fp) {
- console->append(QString("Failed to open text file: %1 (%2)").arg(QString(filename), QString(strerror(errno))));
+ console->append(QString("Failed to open file: %1 (%2)").arg(QString(filename), QString(strerror(errno))));
} else {
char buffer[513];
int rc;
@@ -112,6 +114,7 @@ MainWindow::MainWindow(const char *filename)
text += buffer;
}
fclose(fp);
+ console->append(QString("Loaded design `%1'.").arg(QString(filename)));
}
editor->setPlainText(text);
}
@@ -138,22 +141,57 @@ MainWindow::~MainWindow()
void MainWindow::actionNew()
{
- console->append(QString("Function %1 is not implemented yet!").arg(QString(__PRETTY_FUNCTION__)));
+ filename = QString();
+ setWindowTitle("New Document");
+ editor->setPlainText("");
}
void MainWindow::actionOpen()
{
- console->append(QString("Function %1 is not implemented yet!").arg(QString(__PRETTY_FUNCTION__)));
+ QString new_filename = QFileDialog::getOpenFileName(this, "Open File", "", "OpenSCAD Designs (*.scad)");
+ if (!new_filename.isEmpty())
+ {
+ filename = new_filename;
+ setWindowTitle(filename);
+
+ QString text;
+ FILE *fp = fopen(filename.toAscii().data(), "rt");
+ if (!fp) {
+ console->append(QString("Failed to open file: %1 (%2)").arg(QString(filename), QString(strerror(errno))));
+ } else {
+ char buffer[513];
+ int rc;
+ while ((rc = fread(buffer, 1, 512, fp)) > 0) {
+ buffer[rc] = 0;
+ text += buffer;
+ }
+ fclose(fp);
+ console->append(QString("Loaded design `%1'.").arg(QString(filename)));
+ }
+ editor->setPlainText(text);
+ }
}
void MainWindow::actionSave()
{
- console->append(QString("Function %1 is not implemented yet!").arg(QString(__PRETTY_FUNCTION__)));
+ FILE *fp = fopen(filename.toAscii().data(), "wt");
+ if (!fp) {
+ console->append(QString("Failed to open file for writing: %1 (%2)").arg(QString(filename), QString(strerror(errno))));
+ } else {
+ fprintf(fp, "%s", editor->toPlainText().toAscii().data());
+ fclose(fp);
+ console->append(QString("Saved design `%1'.").arg(QString(filename)));
+ }
}
void MainWindow::actionSaveAs()
{
- console->append(QString("Function %1 is not implemented yet!").arg(QString(__PRETTY_FUNCTION__)));
+ QString new_filename = QFileDialog::getSaveFileName(this, "Save File", filename, "OpenSCAD Designs (*.scad)");
+ if (!new_filename.isEmpty()) {
+ filename = new_filename;
+ setWindowTitle(filename);
+ actionSave();
+ }
}
void MainWindow::actionCompile()
@@ -164,6 +202,7 @@ void MainWindow::actionCompile()
}
console->append("Parsing design (AST generation)...");
+ QApplication::processEvents();
root_module = parse(editor->toPlainText().toAscii().data(), false);
if (!root_module) {
@@ -177,6 +216,7 @@ void MainWindow::actionCompile()
}
console->append("Compiling design (CSG generation)...");
+ QApplication::processEvents();
root_node = root_module->evaluate(&root_ctx, QVector<QString>(), QVector<Value>(), QVector<AbstractNode*>());
if (!root_node) {
@@ -194,6 +234,7 @@ static void report_func(const class AbstractNode*, void *vp, int mark)
MainWindow *m = (MainWindow*)vp;
QString msg;
msg.sprintf("CSG rendering progress: %.2f%%", (mark*100.0) / progress_report_count);
+ QApplication::processEvents();
m->console->append(msg);
}
contact: Jan Huwald // Impressum