mirror of https://github.com/vitalif/openscad
header file reorg
git-svn-id: http://svn.clifford.at/openscad/trunk@365 b57f626f-c46c-0410-a088-ec61d464b74cstl_dim
parent
6940d17181
commit
191dc4857c
|
@ -237,7 +237,7 @@ namespace OpenSCAD {
|
|||
glVertex3dv(pc);
|
||||
}
|
||||
|
||||
inline void CGAL_GLU_TESS_CALLBACK combineCallback(GLdouble coords[3], GLvoid *d[4], GLfloat w[4], GLvoid **dataOut)
|
||||
inline void CGAL_GLU_TESS_CALLBACK combineCallback(GLdouble coords[3], GLvoid *[4], GLfloat [4], GLvoid **dataOut)
|
||||
{
|
||||
static std::list<GLdouble*> pcache;
|
||||
if (dataOut) {
|
||||
|
|
|
@ -4,6 +4,10 @@
|
|||
#include <QMainWindow>
|
||||
#include "ui_MainWindow.h"
|
||||
#include "openscad.h"
|
||||
#include "context.h"
|
||||
#include "module.h"
|
||||
#include "polyset.h"
|
||||
#include <QPointer>
|
||||
|
||||
class MainWindow : public QMainWindow, public Ui::MainWindow
|
||||
{
|
||||
|
@ -27,11 +31,11 @@ public:
|
|||
AbstractNode *absolute_root_node; // Result of tree evaluation
|
||||
AbstractNode *root_node; // Root if the root modifier (!) is used
|
||||
|
||||
CSGTerm *root_raw_term; // Result of CSG term rendering
|
||||
class CSGTerm *root_raw_term; // Result of CSG term rendering
|
||||
CSGTerm *root_norm_term; // Normalized CSG products
|
||||
CSGChain *root_chain;
|
||||
class CSGChain *root_chain;
|
||||
#ifdef ENABLE_CGAL
|
||||
CGAL_Nef_polyhedron *root_N;
|
||||
class CGAL_Nef_polyhedron *root_N;
|
||||
bool recreate_cgal_ogl_p;
|
||||
void *cgal_ogl_p;
|
||||
PolySet *cgal_ogl_ps;
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
#ifndef BUILTIN_H_
|
||||
#define BUILTIN_H_
|
||||
|
||||
#include <QHash>
|
||||
|
||||
extern QHash<QString, class AbstractFunction*> builtin_functions;
|
||||
extern void initialize_builtin_functions();
|
||||
extern void destroy_builtin_functions();
|
||||
|
||||
extern QHash<QString, class AbstractModule*> builtin_modules;
|
||||
extern void initialize_builtin_modules();
|
||||
extern void destroy_builtin_modules();
|
||||
|
||||
extern void register_builtin_csgops();
|
||||
extern void register_builtin_transform();
|
||||
extern void register_builtin_primitives();
|
||||
extern void register_builtin_surface();
|
||||
extern void register_builtin_control();
|
||||
extern void register_builtin_render();
|
||||
extern void register_builtin_import();
|
||||
extern void register_builtin_dxf_linear_extrude();
|
||||
extern void register_builtin_dxf_rotate_extrude();
|
||||
extern void initialize_builtin_dxf_dim();
|
||||
|
||||
#endif
|
|
@ -0,0 +1,59 @@
|
|||
#ifndef CGAL_H_
|
||||
#define CGAL_H_
|
||||
|
||||
#ifdef ENABLE_CGAL
|
||||
|
||||
#include <CGAL/Gmpq.h>
|
||||
#include <CGAL/Extended_cartesian.h>
|
||||
#include <CGAL/Nef_polyhedron_2.h>
|
||||
#include <CGAL/Cartesian.h>
|
||||
#include <CGAL/Polyhedron_3.h>
|
||||
#include <CGAL/Nef_polyhedron_3.h>
|
||||
#include <CGAL/IO/Polyhedron_iostream.h>
|
||||
|
||||
typedef CGAL::Extended_cartesian<CGAL::Gmpq> CGAL_Kernel2;
|
||||
typedef CGAL::Nef_polyhedron_2<CGAL_Kernel2> CGAL_Nef_polyhedron2;
|
||||
typedef CGAL_Kernel2::Aff_transformation_2 CGAL_Aff_transformation2;
|
||||
|
||||
typedef CGAL::Cartesian<CGAL::Gmpq> CGAL_Kernel3;
|
||||
typedef CGAL::Polyhedron_3<CGAL_Kernel3> CGAL_Polyhedron;
|
||||
typedef CGAL_Polyhedron::HalfedgeDS CGAL_HDS;
|
||||
typedef CGAL::Polyhedron_incremental_builder_3<CGAL_HDS> CGAL_Polybuilder;
|
||||
typedef CGAL::Nef_polyhedron_3<CGAL_Kernel3> CGAL_Nef_polyhedron3;
|
||||
typedef CGAL_Nef_polyhedron3::Aff_transformation_3 CGAL_Aff_transformation;
|
||||
typedef CGAL_Nef_polyhedron3::Vector_3 CGAL_Vector;
|
||||
typedef CGAL_Nef_polyhedron3::Plane_3 CGAL_Plane;
|
||||
typedef CGAL_Nef_polyhedron3::Point_3 CGAL_Point;
|
||||
|
||||
struct CGAL_Nef_polyhedron
|
||||
{
|
||||
int dim;
|
||||
CGAL_Nef_polyhedron2 p2;
|
||||
CGAL_Nef_polyhedron3 p3;
|
||||
|
||||
CGAL_Nef_polyhedron() {
|
||||
dim = 0;
|
||||
}
|
||||
|
||||
CGAL_Nef_polyhedron(const CGAL_Nef_polyhedron2 &p) {
|
||||
dim = 2;
|
||||
p2 = p;
|
||||
}
|
||||
|
||||
CGAL_Nef_polyhedron(const CGAL_Nef_polyhedron3 &p) {
|
||||
dim = 3;
|
||||
p3 = p;
|
||||
}
|
||||
|
||||
int weight() {
|
||||
if (dim == 2)
|
||||
return p2.explorer().number_of_vertices();
|
||||
if (dim == 3)
|
||||
return p3.number_of_vertices();
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* ENABLE_CGAL */
|
||||
|
||||
#endif
|
|
@ -18,7 +18,10 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "openscad.h"
|
||||
#include "context.h"
|
||||
#include "expression.h"
|
||||
#include "function.h"
|
||||
#include "module.h"
|
||||
#include "printutils.h"
|
||||
|
||||
Context::Context(const Context *parent)
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
#ifndef CONTEXT_H_
|
||||
#define CONTEXT_H_
|
||||
|
||||
#include <QHash>
|
||||
#include <QString>
|
||||
#include "value.h"
|
||||
|
||||
class Context
|
||||
{
|
||||
public:
|
||||
const Context *parent;
|
||||
QHash<QString, Value> variables;
|
||||
QHash<QString, Value> config_variables;
|
||||
const QHash<QString, class AbstractFunction*> *functions_p;
|
||||
const QHash<QString, class AbstractModule*> *modules_p;
|
||||
const class ModuleInstantiation *inst_p;
|
||||
|
||||
static QVector<const Context*> ctx_stack;
|
||||
|
||||
Context(const Context *parent = NULL);
|
||||
~Context();
|
||||
|
||||
void args(const QVector<QString> &argnames, const QVector<class Expression*> &argexpr, const QVector<QString> &call_argnames, const QVector<Value> &call_argvalues);
|
||||
|
||||
void set_variable(QString name, Value value);
|
||||
Value lookup_variable(QString name, bool silent = false) const;
|
||||
|
||||
Value evaluate_function(QString name, const QVector<QString> &argnames, const QVector<Value> &argvalues) const;
|
||||
class AbstractNode *evaluate_module(const ModuleInstantiation *inst) const;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -18,9 +18,10 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#define INCLUDE_ABSTRACT_NODE_DETAILS
|
||||
|
||||
#include "openscad.h"
|
||||
#include "module.h"
|
||||
#include "node.h"
|
||||
#include "context.h"
|
||||
#include "builtin.h"
|
||||
#include "printutils.h"
|
||||
|
||||
enum control_type_e {
|
||||
|
|
|
@ -18,10 +18,14 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#define INCLUDE_ABSTRACT_NODE_DETAILS
|
||||
|
||||
#include "openscad.h"
|
||||
#include "module.h"
|
||||
#include "node.h"
|
||||
#include "csgterm.h"
|
||||
#include "builtin.h"
|
||||
#include "printutils.h"
|
||||
#ifdef ENABLE_CGAL
|
||||
# include "cgal.h"
|
||||
#endif
|
||||
|
||||
enum csg_type_e {
|
||||
CSG_TYPE_UNION,
|
||||
|
|
|
@ -18,9 +18,8 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#define INCLUDE_ABSTRACT_NODE_DETAILS
|
||||
|
||||
#include "openscad.h"
|
||||
#include "csgterm.h"
|
||||
#include "polyset.h"
|
||||
|
||||
CSGTerm::CSGTerm(PolySet *polyset, double m[20], QString label)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
#ifndef CSGTERM_H_
|
||||
#define CSGTERM_H_
|
||||
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
|
||||
class CSGTerm
|
||||
{
|
||||
public:
|
||||
enum type_e {
|
||||
TYPE_PRIMITIVE,
|
||||
TYPE_UNION,
|
||||
TYPE_INTERSECTION,
|
||||
TYPE_DIFFERENCE
|
||||
};
|
||||
|
||||
type_e type;
|
||||
class PolySet *polyset;
|
||||
QString label;
|
||||
CSGTerm *left;
|
||||
CSGTerm *right;
|
||||
double m[20];
|
||||
int refcounter;
|
||||
|
||||
CSGTerm(PolySet *polyset, double m[20], QString label);
|
||||
CSGTerm(type_e type, CSGTerm *left, CSGTerm *right);
|
||||
|
||||
CSGTerm *normalize();
|
||||
CSGTerm *normalize_tail();
|
||||
|
||||
CSGTerm *link();
|
||||
void unlink();
|
||||
QString dump();
|
||||
};
|
||||
|
||||
class CSGChain
|
||||
{
|
||||
public:
|
||||
QVector<PolySet*> polysets;
|
||||
QVector<double*> matrices;
|
||||
QVector<CSGTerm::type_e> types;
|
||||
QVector<QString> labels;
|
||||
|
||||
CSGChain();
|
||||
|
||||
void add(PolySet *polyset, double *m, CSGTerm::type_e type, QString label);
|
||||
void import(CSGTerm *term, CSGTerm::type_e type = CSGTerm::TYPE_UNION);
|
||||
QString dump();
|
||||
};
|
||||
|
||||
#endif
|
|
@ -18,11 +18,16 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "openscad.h"
|
||||
#include "dxfdata.h"
|
||||
#include "grid.h"
|
||||
#include "printutils.h"
|
||||
#include "openscad.h" // handle_dep()
|
||||
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
#include <QHash>
|
||||
#include <QVector>
|
||||
#include <math.h>
|
||||
|
||||
struct Line {
|
||||
typedef DxfData::Point Point;
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
#ifndef DXFDATA_H_
|
||||
#define DXFDATA_H_
|
||||
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
|
||||
class DxfData
|
||||
{
|
||||
public:
|
||||
struct Point {
|
||||
double x, y;
|
||||
Point() : x(0), y(0) { }
|
||||
Point(double x, double y) : x(x), y(y) { }
|
||||
};
|
||||
struct Path {
|
||||
QList<Point*> points;
|
||||
bool is_closed, is_inner;
|
||||
Path() : is_closed(false), is_inner(false) { }
|
||||
};
|
||||
struct Dim {
|
||||
unsigned int type;
|
||||
double coords[7][2];
|
||||
double angle;
|
||||
double length;
|
||||
QString name;
|
||||
Dim() {
|
||||
for (int i = 0; i < 7; i++)
|
||||
for (int j = 0; j < 2; j++)
|
||||
coords[i][j] = 0;
|
||||
type = 0;
|
||||
angle = 0;
|
||||
length = 0;
|
||||
}
|
||||
};
|
||||
|
||||
QList<Point> points;
|
||||
QList<Path> paths;
|
||||
QList<Dim> dims;
|
||||
|
||||
DxfData();
|
||||
DxfData(double fn, double fs, double fa, QString filename, QString layername = QString(), double xorigin = 0.0, double yorigin = 0.0, double scale = 1.0);
|
||||
DxfData(const struct CGAL_Nef_polyhedron &N);
|
||||
|
||||
Point *addPoint(double x, double y);
|
||||
|
||||
private:
|
||||
void fixup_path_direction();
|
||||
};
|
||||
|
||||
#endif
|
|
@ -18,12 +18,18 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "openscad.h"
|
||||
#include "dxfdim.h"
|
||||
#include "value.h"
|
||||
#include "function.h"
|
||||
#include "dxfdata.h"
|
||||
#include "builtin.h"
|
||||
#include "printutils.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <QHash>
|
||||
|
||||
QHash<QString,Value> dxf_dim_cache;
|
||||
QHash<QString,Value> dxf_cross_cache;
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
#ifndef DXFDIM_H_
|
||||
#define DXFDIM_H_
|
||||
|
||||
#include <QHash>
|
||||
#include "value.h"
|
||||
|
||||
extern QHash<QString,Value> dxf_cross_cache;
|
||||
extern QHash<QString,Value> dxf_dim_cache;
|
||||
|
||||
#endif
|
|
@ -18,10 +18,15 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#define INCLUDE_ABSTRACT_NODE_DETAILS
|
||||
|
||||
#include "openscad.h"
|
||||
#include "module.h"
|
||||
#include "node.h"
|
||||
#include "context.h"
|
||||
#include "printutils.h"
|
||||
#include "builtin.h"
|
||||
#include "dxfdata.h"
|
||||
#include "dxftess.h"
|
||||
#include "polyset.h"
|
||||
#include "openscad.h" // get_fragments_from_r()
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
@ -29,6 +34,7 @@
|
|||
|
||||
#include <QApplication>
|
||||
#include <QTime>
|
||||
#include <QProgressDialog>
|
||||
|
||||
class DxfLinearExtrudeModule : public AbstractModule
|
||||
{
|
||||
|
|
|
@ -18,10 +18,14 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#define INCLUDE_ABSTRACT_NODE_DETAILS
|
||||
|
||||
#include "openscad.h"
|
||||
#include "module.h"
|
||||
#include "node.h"
|
||||
#include "context.h"
|
||||
#include "printutils.h"
|
||||
#include "builtin.h"
|
||||
#include "polyset.h"
|
||||
#include "dxfdata.h"
|
||||
#include "openscad.h" // get_fragments_from_r()
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
@ -29,6 +33,7 @@
|
|||
|
||||
#include <QTime>
|
||||
#include <QApplication>
|
||||
#include <QProgressDialog>
|
||||
|
||||
class DxfRotateExtrudeModule : public AbstractModule
|
||||
{
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#include "openscad.h"
|
||||
#include "printutils.h"
|
||||
|
||||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
#include "dxftess.h"
|
||||
#include "dxfdata.h"
|
||||
#include "polyset.h"
|
||||
#include "grid.h"
|
||||
|
||||
#ifdef ENABLE_OPENCSG
|
||||
// this must be included before the GL headers
|
||||
# include <GL/glew.h>
|
||||
#endif
|
||||
#include <qgl.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifdef WIN32
|
||||
# define STDCALL __stdcall
|
||||
#else
|
||||
|
|
|
@ -18,9 +18,6 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#define INCLUDE_ABSTRACT_NODE_DETAILS
|
||||
|
||||
#include "openscad.h"
|
||||
#include "printutils.h"
|
||||
|
||||
#ifdef CGAL_TESSELATE
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef DXFTESS_H_
|
||||
#define DXFTESS_H_
|
||||
|
||||
class DxfData;
|
||||
class PolySet;
|
||||
void dxf_tesselate(PolySet *ps, DxfData *dxf, double rot, bool up, bool do_triangle_splitting, double h);
|
||||
void dxf_border_to_ps(PolySet *ps, DxfData *dxf);
|
||||
|
||||
#endif
|
|
@ -18,15 +18,15 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#define INCLUDE_ABSTRACT_NODE_DETAILS
|
||||
|
||||
#include "openscad.h"
|
||||
#include "printutils.h"
|
||||
#include "MainWindow.h"
|
||||
#include "dxfdata.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QProgressDialog>
|
||||
|
||||
#ifdef ENABLE_CGAL
|
||||
#include "cgal.h"
|
||||
|
||||
void export_stl(CGAL_Nef_polyhedron *root_N, QString filename, QProgressDialog *pd)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
#ifndef EXPORT_H_
|
||||
#define EXPORT_H_
|
||||
|
||||
#ifdef ENABLE_CGAL
|
||||
void export_stl(class CGAL_Nef_polyhedron *root_N, QString filename, class QProgressDialog *pd);
|
||||
void export_off(CGAL_Nef_polyhedron *root_N, QString filename, QProgressDialog *pd);
|
||||
void export_dxf(CGAL_Nef_polyhedron *root_N, QString filename, QProgressDialog *pd);
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -18,7 +18,9 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "openscad.h"
|
||||
#include "expression.h"
|
||||
#include "value.h"
|
||||
#include "context.h"
|
||||
|
||||
Expression::Expression()
|
||||
{
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
#ifndef EXPRESSION_H_
|
||||
#define EXPRESSION_H_
|
||||
|
||||
#include <QVector>
|
||||
#include <QString>
|
||||
|
||||
class Expression
|
||||
{
|
||||
public:
|
||||
QVector<Expression*> children;
|
||||
|
||||
class Value *const_value;
|
||||
QString var_name;
|
||||
|
||||
QString call_funcname;
|
||||
QVector<QString> call_argnames;
|
||||
|
||||
// Boolean: ! && ||
|
||||
// Operators: * / % + -
|
||||
// Relations: < <= == != >= >
|
||||
// Vector element: []
|
||||
// Condition operator: ?:
|
||||
// Invert (prefix '-'): I
|
||||
// Constant value: C
|
||||
// Create Range: R
|
||||
// Create Vector: V
|
||||
// Create Matrix: M
|
||||
// Lookup Variable: L
|
||||
// Lookup member per name: N
|
||||
// Function call: F
|
||||
QString type;
|
||||
|
||||
Expression();
|
||||
~Expression();
|
||||
|
||||
Value evaluate(const class Context *context) const;
|
||||
QString dump() const;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -18,7 +18,12 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "openscad.h"
|
||||
#include "function.h"
|
||||
#include "expression.h"
|
||||
#include "context.h"
|
||||
#include "dxfdim.h"
|
||||
#include "builtin.h"
|
||||
#include <math.h>
|
||||
|
||||
AbstractFunction::~AbstractFunction()
|
||||
{
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
#ifndef FUNCTION_H_
|
||||
#define FUNCTION_H_
|
||||
|
||||
#include "value.h"
|
||||
#include <QString>
|
||||
|
||||
class AbstractFunction
|
||||
{
|
||||
public:
|
||||
virtual ~AbstractFunction();
|
||||
virtual Value evaluate(const class Context *ctx, const QVector<QString> &call_argnames, const QVector<Value> &call_argvalues) const;
|
||||
virtual QString dump(QString indent, QString name) const;
|
||||
};
|
||||
|
||||
class BuiltinFunction : public AbstractFunction
|
||||
{
|
||||
public:
|
||||
typedef Value (*eval_func_t)(const QVector<QString> &argnames, const QVector<Value> &args);
|
||||
eval_func_t eval_func;
|
||||
|
||||
BuiltinFunction(eval_func_t f) : eval_func(f) { }
|
||||
virtual ~BuiltinFunction();
|
||||
|
||||
virtual Value evaluate(const Context *ctx, const QVector<QString> &call_argnames, const QVector<Value> &call_argvalues) const;
|
||||
virtual QString dump(QString indent, QString name) const;
|
||||
};
|
||||
|
||||
class Function : public AbstractFunction
|
||||
{
|
||||
public:
|
||||
QVector<QString> argnames;
|
||||
QVector<class Expression*> argexpr;
|
||||
|
||||
Expression *expr;
|
||||
|
||||
Function() { }
|
||||
virtual ~Function();
|
||||
|
||||
virtual Value evaluate(const Context *ctx, const QVector<QString> &call_argnames, const QVector<Value> &call_argvalues) const;
|
||||
virtual QString dump(QString indent, QString name) const;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -18,7 +18,6 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "openscad.h"
|
||||
#include "GLView.h"
|
||||
#include "Preferences.h"
|
||||
|
||||
|
@ -27,6 +26,7 @@
|
|||
#include <QMouseEvent>
|
||||
#include <QMessageBox>
|
||||
#include <QTimer>
|
||||
#include <math.h>
|
||||
|
||||
#define FAR_FAR_AWAY 100000.0
|
||||
|
||||
|
|
|
@ -0,0 +1,136 @@
|
|||
#ifndef GRID_H_
|
||||
#define GRID_H_
|
||||
|
||||
#include <math.h>
|
||||
#include <QHash>
|
||||
|
||||
const double GRID_COARSE = 0.001;
|
||||
const double GRID_FINE = 0.000001;
|
||||
|
||||
template <typename T>
|
||||
class Grid2d
|
||||
{
|
||||
public:
|
||||
double res;
|
||||
QHash<QPair<int64_t,int64_t>, T> db;
|
||||
|
||||
Grid2d(double resolution) {
|
||||
res = resolution;
|
||||
}
|
||||
/*!
|
||||
Aligns x,y to the grid or to existing point if one close enough exists.
|
||||
Returns the value stored if a point already existing or an uninitialized new value
|
||||
if not.
|
||||
*/
|
||||
T &align(double &x, double &y) {
|
||||
int64_t ix = (int64_t)round(x / res);
|
||||
int64_t iy = (int64_t)round(y / res);
|
||||
if (!db.contains(QPair<int64_t,int64_t>(ix, iy))) {
|
||||
int dist = 10;
|
||||
for (int64_t jx = ix - 1; jx <= ix + 1; jx++) {
|
||||
for (int64_t jy = iy - 1; jy <= iy + 1; jy++) {
|
||||
if (!db.contains(QPair<int64_t,int64_t>(jx, jy)))
|
||||
continue;
|
||||
if (abs(ix-jx) + abs(iy-jy) < dist) {
|
||||
dist = abs(ix-jx) + abs(iy-jy);
|
||||
ix = jx;
|
||||
iy = jy;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
x = ix * res, y = iy * res;
|
||||
return db[QPair<int64_t,int64_t>(ix, iy)];
|
||||
}
|
||||
bool has(double x, double y) const {
|
||||
int64_t ix = (int64_t)round(x / res);
|
||||
int64_t iy = (int64_t)round(y / res);
|
||||
if (db.contains(QPair<int64_t,int64_t>(ix, iy)))
|
||||
return true;
|
||||
for (int64_t jx = ix - 1; jx <= ix + 1; jx++)
|
||||
for (int64_t jy = iy - 1; jy <= iy + 1; jy++) {
|
||||
if (db.contains(QPair<int64_t,int64_t>(jx, jy)))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool eq(double x1, double y1, double x2, double y2) {
|
||||
align(x1, y1);
|
||||
align(x2, y2);
|
||||
if (fabs(x1 - x2) < res && fabs(y1 - y2) < res)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
T &data(double x, double y) {
|
||||
return align(x, y);
|
||||
}
|
||||
T &operator()(double x, double y) {
|
||||
return align(x, y);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class Grid3d
|
||||
{
|
||||
public:
|
||||
double res;
|
||||
QHash<QPair<QPair<int64_t,int64_t>,int64_t>, T> db;
|
||||
|
||||
Grid3d(double resolution) {
|
||||
res = resolution;
|
||||
}
|
||||
T &align(double &x, double &y, double &z) {
|
||||
int64_t ix = (int64_t)round(x / res);
|
||||
int64_t iy = (int64_t)round(y / res);
|
||||
int64_t iz = (int64_t)round(z / res);
|
||||
if (!db.contains(QPair<QPair<int64_t,int64_t>,int64_t>(QPair<int64_t,int64_t>(ix, iy), iz))) {
|
||||
int dist = 10;
|
||||
for (int64_t jx = ix - 1; jx <= ix + 1; jx++) {
|
||||
for (int64_t jy = iy - 1; jy <= iy + 1; jy++) {
|
||||
for (int64_t jz = iz - 1; jz <= iz + 1; jz++) {
|
||||
if (!db.contains(QPair<QPair<int64_t,int64_t>,int64_t>(QPair<int64_t,int64_t>(jx, jy), jz)))
|
||||
continue;
|
||||
if (abs(ix-jx) + abs(iy-jy) + abs(iz-jz) < dist) {
|
||||
dist = abs(ix-jx) + abs(iy-jy) + abs(iz-jz);
|
||||
ix = jx;
|
||||
iy = jy;
|
||||
iz = jz;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
x = ix * res, y = iy * res, z = iz * res;
|
||||
return db[QPair<QPair<int64_t,int64_t>,int64_t>(QPair<int64_t,int64_t>(ix, iy), iz)];
|
||||
}
|
||||
bool has(double x, double y, double z) {
|
||||
int64_t ix = (int64_t)round(x / res);
|
||||
int64_t iy = (int64_t)round(y / res);
|
||||
int64_t iz = (int64_t)round(z / res);
|
||||
if (db.contains(QPair<QPair<int64_t,int64_t>,int64_t>(QPair<int64_t,int64_t>(ix, iy), iz)))
|
||||
return true;
|
||||
for (int64_t jx = ix - 1; jx <= ix + 1; jx++)
|
||||
for (int64_t jy = iy - 1; jy <= iy + 1; jy++)
|
||||
for (int64_t jz = iz - 1; jz <= iz + 1; jz++) {
|
||||
if (db.contains(QPair<QPair<int64_t,int64_t>,int64_t>(QPair<int64_t,int64_t>(jx, jy), jz)))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
bool eq(double x1, double y1, double z1, double x2, double y2, double z2) {
|
||||
align(x1, y1, z1);
|
||||
align(x2, y2, z2);
|
||||
if (fabs(x1 - x2) < res && fabs(y1 - y2) < res && fabs(z1 - z2) < res)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
T &data(double x, double y, double z) {
|
||||
return align(x, y, z);
|
||||
}
|
||||
T &operator()(double x, double y, double z) {
|
||||
return align(x, y, z);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
|
@ -18,7 +18,8 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "openscad.h"
|
||||
#include "highlighter.h"
|
||||
#include "openscad.h" // extern int parser_error_pos;
|
||||
|
||||
Highlighter::Highlighter(QTextDocument *parent)
|
||||
: QSyntaxHighlighter(parent)
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
#ifndef HIGHLIGHTER_H_
|
||||
#define HIGHLIGHTER_H_
|
||||
|
||||
#include <QSyntaxHighlighter>
|
||||
|
||||
class Highlighter : public QSyntaxHighlighter
|
||||
{
|
||||
public:
|
||||
Highlighter(QTextDocument *parent);
|
||||
void highlightBlock(const QString &text);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -18,10 +18,15 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#define INCLUDE_ABSTRACT_NODE_DETAILS
|
||||
|
||||
#include "openscad.h"
|
||||
#include "module.h"
|
||||
#include "node.h"
|
||||
#include "polyset.h"
|
||||
#include "context.h"
|
||||
#include "builtin.h"
|
||||
#include "dxfdata.h"
|
||||
#include "dxftess.h"
|
||||
#include "printutils.h"
|
||||
#include "openscad.h" // handle_dep()
|
||||
|
||||
#include <QFile>
|
||||
#include <sys/types.h>
|
||||
|
|
|
@ -18,12 +18,19 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#define INCLUDE_ABSTRACT_NODE_DETAILS
|
||||
|
||||
#include "openscad.h"
|
||||
#include "MainWindow.h"
|
||||
#include "Preferences.h"
|
||||
#include "printutils.h"
|
||||
#include "node.h"
|
||||
#include "polyset.h"
|
||||
#include "csgterm.h"
|
||||
#include "highlighter.h"
|
||||
#include "grid.h"
|
||||
#include "dxfdata.h"
|
||||
#include "dxfdim.h"
|
||||
#include "export.h"
|
||||
#include "builtin.h"
|
||||
#include "dxftess.h"
|
||||
|
||||
#include <QMenu>
|
||||
#include <QTime>
|
||||
|
|
180
src/module.cc
180
src/module.cc
|
@ -18,9 +18,12 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#define INCLUDE_ABSTRACT_NODE_DETAILS
|
||||
|
||||
#include "openscad.h"
|
||||
#include "module.h"
|
||||
#include "node.h"
|
||||
#include "context.h"
|
||||
#include "expression.h"
|
||||
#include "function.h"
|
||||
#include "builtin.h"
|
||||
#include "printutils.h"
|
||||
|
||||
AbstractModule::~AbstractModule()
|
||||
|
@ -201,174 +204,3 @@ void destroy_builtin_modules()
|
|||
delete v;
|
||||
builtin_modules.clear();
|
||||
}
|
||||
|
||||
int AbstractNode::idx_counter;
|
||||
|
||||
AbstractNode::AbstractNode(const ModuleInstantiation *mi)
|
||||
{
|
||||
modinst = mi;
|
||||
idx = idx_counter++;
|
||||
}
|
||||
|
||||
AbstractNode::~AbstractNode()
|
||||
{
|
||||
foreach (AbstractNode *v, children)
|
||||
delete v;
|
||||
}
|
||||
|
||||
QString AbstractNode::mk_cache_id() const
|
||||
{
|
||||
QString cache_id = dump("");
|
||||
cache_id.remove(QRegExp("[a-zA-Z_][a-zA-Z_0-9]*:"));
|
||||
cache_id.remove(' ');
|
||||
cache_id.remove('\t');
|
||||
cache_id.remove('\n');
|
||||
return cache_id;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_CGAL
|
||||
|
||||
AbstractNode::cgal_nef_cache_entry::cgal_nef_cache_entry(CGAL_Nef_polyhedron N) :
|
||||
N(N), msg(print_messages_stack.last()) { };
|
||||
|
||||
QCache<QString, AbstractNode::cgal_nef_cache_entry> AbstractNode::cgal_nef_cache(100000);
|
||||
|
||||
static CGAL_Nef_polyhedron render_cgal_nef_polyhedron_backend(const AbstractNode *that, bool intersect)
|
||||
{
|
||||
QString cache_id = that->mk_cache_id();
|
||||
if (that->cgal_nef_cache.contains(cache_id)) {
|
||||
that->progress_report();
|
||||
PRINT(that->cgal_nef_cache[cache_id]->msg);
|
||||
return that->cgal_nef_cache[cache_id]->N;
|
||||
}
|
||||
|
||||
print_messages_push();
|
||||
|
||||
bool first = true;
|
||||
CGAL_Nef_polyhedron N;
|
||||
foreach (AbstractNode *v, that->children) {
|
||||
if (v->modinst->tag_background)
|
||||
continue;
|
||||
if (first) {
|
||||
N = v->render_cgal_nef_polyhedron();
|
||||
if (N.dim != 0)
|
||||
first = false;
|
||||
} else if (N.dim == 2) {
|
||||
if (intersect)
|
||||
N.p2 *= v->render_cgal_nef_polyhedron().p2;
|
||||
else
|
||||
N.p2 += v->render_cgal_nef_polyhedron().p2;
|
||||
} else {
|
||||
if (intersect)
|
||||
N.p3 *= v->render_cgal_nef_polyhedron().p3;
|
||||
else
|
||||
N.p3 += v->render_cgal_nef_polyhedron().p3;
|
||||
}
|
||||
}
|
||||
|
||||
that->cgal_nef_cache.insert(cache_id, new AbstractNode::cgal_nef_cache_entry(N), N.weight());
|
||||
that->progress_report();
|
||||
print_messages_pop();
|
||||
|
||||
return N;
|
||||
}
|
||||
|
||||
CGAL_Nef_polyhedron AbstractNode::render_cgal_nef_polyhedron() const
|
||||
{
|
||||
return render_cgal_nef_polyhedron_backend(this, false);
|
||||
}
|
||||
|
||||
CGAL_Nef_polyhedron AbstractIntersectionNode::render_cgal_nef_polyhedron() const
|
||||
{
|
||||
return render_cgal_nef_polyhedron_backend(this, true);
|
||||
}
|
||||
|
||||
#endif /* ENABLE_CGAL */
|
||||
|
||||
static CSGTerm *render_csg_term_backend(const AbstractNode *that, bool intersect, double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background)
|
||||
{
|
||||
CSGTerm *t1 = NULL;
|
||||
foreach(AbstractNode *v, that->children) {
|
||||
CSGTerm *t2 = v->render_csg_term(m, highlights, background);
|
||||
if (t2 && !t1) {
|
||||
t1 = t2;
|
||||
} else if (t2 && t1) {
|
||||
if (intersect)
|
||||
t1 = new CSGTerm(CSGTerm::TYPE_INTERSECTION, t1, t2);
|
||||
else
|
||||
t1 = new CSGTerm(CSGTerm::TYPE_UNION, t1, t2);
|
||||
}
|
||||
}
|
||||
if (t1 && that->modinst->tag_highlight && highlights)
|
||||
highlights->append(t1->link());
|
||||
if (t1 && that->modinst->tag_background && background) {
|
||||
background->append(t1);
|
||||
return NULL;
|
||||
}
|
||||
return t1;
|
||||
}
|
||||
|
||||
CSGTerm *AbstractNode::render_csg_term(double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const
|
||||
{
|
||||
return render_csg_term_backend(this, false, m, highlights, background);
|
||||
}
|
||||
|
||||
CSGTerm *AbstractIntersectionNode::render_csg_term(double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const
|
||||
{
|
||||
return render_csg_term_backend(this, true, m, highlights, background);
|
||||
}
|
||||
|
||||
QString AbstractNode::dump(QString indent) const
|
||||
{
|
||||
if (dump_cache.isEmpty()) {
|
||||
QString text = indent + QString("n%1: group() {\n").arg(idx);
|
||||
foreach (AbstractNode *v, children)
|
||||
text += v->dump(indent + QString("\t"));
|
||||
((AbstractNode*)this)->dump_cache = text + indent + "}\n";
|
||||
}
|
||||
return dump_cache;
|
||||
}
|
||||
|
||||
QString AbstractIntersectionNode::dump(QString indent) const
|
||||
{
|
||||
if (dump_cache.isEmpty()) {
|
||||
QString text = indent + QString("n%1: intersection() {\n").arg(idx);
|
||||
foreach (AbstractNode *v, children)
|
||||
text += v->dump(indent + QString("\t"));
|
||||
((AbstractNode*)this)->dump_cache = text + indent + "}\n";
|
||||
}
|
||||
return dump_cache;
|
||||
}
|
||||
|
||||
int progress_report_count;
|
||||
void (*progress_report_f)(const class AbstractNode*, void*, int);
|
||||
void *progress_report_vp;
|
||||
|
||||
void AbstractNode::progress_prepare()
|
||||
{
|
||||
foreach (AbstractNode *v, children)
|
||||
v->progress_prepare();
|
||||
progress_mark = ++progress_report_count;
|
||||
}
|
||||
|
||||
void AbstractNode::progress_report() const
|
||||
{
|
||||
if (progress_report_f)
|
||||
progress_report_f(this, progress_report_vp, progress_mark);
|
||||
}
|
||||
|
||||
void progress_report_prep(AbstractNode *root, void (*f)(const class AbstractNode *node, void *vp, int mark), void *vp)
|
||||
{
|
||||
progress_report_count = 0;
|
||||
progress_report_f = f;
|
||||
progress_report_vp = vp;
|
||||
root->progress_prepare();
|
||||
}
|
||||
|
||||
void progress_report_fin()
|
||||
{
|
||||
progress_report_count = 0;
|
||||
progress_report_f = NULL;
|
||||
progress_report_vp = NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
#ifndef MODULE_H_
|
||||
#define MODULE_H_
|
||||
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
#include <QHash>
|
||||
#include "value.h"
|
||||
|
||||
class ModuleInstantiation
|
||||
{
|
||||
public:
|
||||
QString label;
|
||||
QString modname;
|
||||
QVector<QString> argnames;
|
||||
QVector<class Expression*> argexpr;
|
||||
QVector<Value> argvalues;
|
||||
QVector<ModuleInstantiation*> children;
|
||||
|
||||
bool tag_root;
|
||||
bool tag_highlight;
|
||||
bool tag_background;
|
||||
const class Context *ctx;
|
||||
|
||||
ModuleInstantiation() : tag_root(false), tag_highlight(false), tag_background(false), ctx(NULL) { }
|
||||
~ModuleInstantiation();
|
||||
|
||||
QString dump(QString indent) const;
|
||||
class AbstractNode *evaluate(const Context *ctx) const;
|
||||
};
|
||||
|
||||
class AbstractModule
|
||||
{
|
||||
public:
|
||||
virtual ~AbstractModule();
|
||||
virtual class AbstractNode *evaluate(const Context *ctx, const ModuleInstantiation *inst) const;
|
||||
virtual QString dump(QString indent, QString name) const;
|
||||
};
|
||||
|
||||
class Module : public AbstractModule
|
||||
{
|
||||
public:
|
||||
QVector<QString> argnames;
|
||||
QVector<Expression*> argexpr;
|
||||
|
||||
QVector<QString> assignments_var;
|
||||
QVector<Expression*> assignments_expr;
|
||||
|
||||
QHash<QString, class AbstractFunction*> functions;
|
||||
QHash<QString, AbstractModule*> modules;
|
||||
|
||||
QVector<ModuleInstantiation*> children;
|
||||
|
||||
Module() { }
|
||||
virtual ~Module();
|
||||
|
||||
virtual AbstractNode *evaluate(const Context *ctx, const ModuleInstantiation *inst) const;
|
||||
virtual QString dump(QString indent, QString name) const;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -18,9 +18,9 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#define INCLUDE_ABSTRACT_NODE_DETAILS
|
||||
|
||||
#include "openscad.h"
|
||||
#include "dxfdata.h"
|
||||
#include "grid.h"
|
||||
#include "cgal.h"
|
||||
|
||||
DxfData::DxfData(const struct CGAL_Nef_polyhedron &N)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,196 @@
|
|||
/*
|
||||
* OpenSCAD (www.openscad.at)
|
||||
* Copyright (C) 2009 Clifford Wolf <clifford@clifford.at>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "printutils.h"
|
||||
#include "node.h"
|
||||
#include "module.h"
|
||||
#include "csgterm.h"
|
||||
#include <QRegExp>
|
||||
|
||||
int AbstractNode::idx_counter;
|
||||
|
||||
AbstractNode::AbstractNode(const ModuleInstantiation *mi)
|
||||
{
|
||||
modinst = mi;
|
||||
idx = idx_counter++;
|
||||
}
|
||||
|
||||
AbstractNode::~AbstractNode()
|
||||
{
|
||||
foreach (AbstractNode *v, children)
|
||||
delete v;
|
||||
}
|
||||
|
||||
QString AbstractNode::mk_cache_id() const
|
||||
{
|
||||
QString cache_id = dump("");
|
||||
cache_id.remove(QRegExp("[a-zA-Z_][a-zA-Z_0-9]*:"));
|
||||
cache_id.remove(' ');
|
||||
cache_id.remove('\t');
|
||||
cache_id.remove('\n');
|
||||
return cache_id;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_CGAL
|
||||
|
||||
AbstractNode::cgal_nef_cache_entry::cgal_nef_cache_entry(CGAL_Nef_polyhedron N) :
|
||||
N(N), msg(print_messages_stack.last()) { };
|
||||
|
||||
QCache<QString, AbstractNode::cgal_nef_cache_entry> AbstractNode::cgal_nef_cache(100000);
|
||||
|
||||
static CGAL_Nef_polyhedron render_cgal_nef_polyhedron_backend(const AbstractNode *that, bool intersect)
|
||||
{
|
||||
QString cache_id = that->mk_cache_id();
|
||||
if (that->cgal_nef_cache.contains(cache_id)) {
|
||||
that->progress_report();
|
||||
PRINT(that->cgal_nef_cache[cache_id]->msg);
|
||||
return that->cgal_nef_cache[cache_id]->N;
|
||||
}
|
||||
|
||||
print_messages_push();
|
||||
|
||||
bool first = true;
|
||||
CGAL_Nef_polyhedron N;
|
||||
foreach (AbstractNode *v, that->children) {
|
||||
if (v->modinst->tag_background)
|
||||
continue;
|
||||
if (first) {
|
||||
N = v->render_cgal_nef_polyhedron();
|
||||
if (N.dim != 0)
|
||||
first = false;
|
||||
} else if (N.dim == 2) {
|
||||
if (intersect)
|
||||
N.p2 *= v->render_cgal_nef_polyhedron().p2;
|
||||
else
|
||||
N.p2 += v->render_cgal_nef_polyhedron().p2;
|
||||
} else {
|
||||
if (intersect)
|
||||
N.p3 *= v->render_cgal_nef_polyhedron().p3;
|
||||
else
|
||||
N.p3 += v->render_cgal_nef_polyhedron().p3;
|
||||
}
|
||||
}
|
||||
|
||||
that->cgal_nef_cache.insert(cache_id, new AbstractNode::cgal_nef_cache_entry(N), N.weight());
|
||||
that->progress_report();
|
||||
print_messages_pop();
|
||||
|
||||
return N;
|
||||
}
|
||||
|
||||
CGAL_Nef_polyhedron AbstractNode::render_cgal_nef_polyhedron() const
|
||||
{
|
||||
return render_cgal_nef_polyhedron_backend(this, false);
|
||||
}
|
||||
|
||||
CGAL_Nef_polyhedron AbstractIntersectionNode::render_cgal_nef_polyhedron() const
|
||||
{
|
||||
return render_cgal_nef_polyhedron_backend(this, true);
|
||||
}
|
||||
|
||||
#endif /* ENABLE_CGAL */
|
||||
|
||||
static CSGTerm *render_csg_term_backend(const AbstractNode *that, bool intersect, double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background)
|
||||
{
|
||||
CSGTerm *t1 = NULL;
|
||||
foreach(AbstractNode *v, that->children) {
|
||||
CSGTerm *t2 = v->render_csg_term(m, highlights, background);
|
||||
if (t2 && !t1) {
|
||||
t1 = t2;
|
||||
} else if (t2 && t1) {
|
||||
if (intersect)
|
||||
t1 = new CSGTerm(CSGTerm::TYPE_INTERSECTION, t1, t2);
|
||||
else
|
||||
t1 = new CSGTerm(CSGTerm::TYPE_UNION, t1, t2);
|
||||
}
|
||||
}
|
||||
if (t1 && that->modinst->tag_highlight && highlights)
|
||||
highlights->append(t1->link());
|
||||
if (t1 && that->modinst->tag_background && background) {
|
||||
background->append(t1);
|
||||
return NULL;
|
||||
}
|
||||
return t1;
|
||||
}
|
||||
|
||||
CSGTerm *AbstractNode::render_csg_term(double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const
|
||||
{
|
||||
return render_csg_term_backend(this, false, m, highlights, background);
|
||||
}
|
||||
|
||||
CSGTerm *AbstractIntersectionNode::render_csg_term(double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const
|
||||
{
|
||||
return render_csg_term_backend(this, true, m, highlights, background);
|
||||
}
|
||||
|
||||
QString AbstractNode::dump(QString indent) const
|
||||
{
|
||||
if (dump_cache.isEmpty()) {
|
||||
QString text = indent + QString("n%1: group() {\n").arg(idx);
|
||||
foreach (AbstractNode *v, children)
|
||||
text += v->dump(indent + QString("\t"));
|
||||
((AbstractNode*)this)->dump_cache = text + indent + "}\n";
|
||||
}
|
||||
return dump_cache;
|
||||
}
|
||||
|
||||
QString AbstractIntersectionNode::dump(QString indent) const
|
||||
{
|
||||
if (dump_cache.isEmpty()) {
|
||||
QString text = indent + QString("n%1: intersection() {\n").arg(idx);
|
||||
foreach (AbstractNode *v, children)
|
||||
text += v->dump(indent + QString("\t"));
|
||||
((AbstractNode*)this)->dump_cache = text + indent + "}\n";
|
||||
}
|
||||
return dump_cache;
|
||||
}
|
||||
|
||||
int progress_report_count;
|
||||
void (*progress_report_f)(const class AbstractNode*, void*, int);
|
||||
void *progress_report_vp;
|
||||
|
||||
void AbstractNode::progress_prepare()
|
||||
{
|
||||
foreach (AbstractNode *v, children)
|
||||
v->progress_prepare();
|
||||
progress_mark = ++progress_report_count;
|
||||
}
|
||||
|
||||
void AbstractNode::progress_report() const
|
||||
{
|
||||
if (progress_report_f)
|
||||
progress_report_f(this, progress_report_vp, progress_mark);
|
||||
}
|
||||
|
||||
void progress_report_prep(AbstractNode *root, void (*f)(const class AbstractNode *node, void *vp, int mark), void *vp)
|
||||
{
|
||||
progress_report_count = 0;
|
||||
progress_report_f = f;
|
||||
progress_report_vp = vp;
|
||||
root->progress_prepare();
|
||||
}
|
||||
|
||||
void progress_report_fin()
|
||||
{
|
||||
progress_report_count = 0;
|
||||
progress_report_f = NULL;
|
||||
progress_report_vp = NULL;
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
#ifndef NODE_H_
|
||||
#define NODE_H_
|
||||
|
||||
#include <QCache>
|
||||
#include <QVector>
|
||||
|
||||
#ifdef ENABLE_CGAL
|
||||
#include "cgal.h"
|
||||
#endif
|
||||
|
||||
extern int progress_report_count;
|
||||
extern void (*progress_report_f)(const class AbstractNode*, void*, int);
|
||||
extern void *progress_report_vp;
|
||||
|
||||
void progress_report_prep(AbstractNode *root, void (*f)(const class AbstractNode *node, void *vp, int mark), void *vp);
|
||||
void progress_report_fin();
|
||||
|
||||
class AbstractNode
|
||||
{
|
||||
public:
|
||||
QVector<AbstractNode*> children;
|
||||
const class ModuleInstantiation *modinst;
|
||||
|
||||
int progress_mark;
|
||||
void progress_prepare();
|
||||
void progress_report() const;
|
||||
|
||||
int idx;
|
||||
static int idx_counter;
|
||||
QString dump_cache;
|
||||
|
||||
AbstractNode(const ModuleInstantiation *mi);
|
||||
virtual ~AbstractNode();
|
||||
virtual QString mk_cache_id() const;
|
||||
#ifdef ENABLE_CGAL
|
||||
struct cgal_nef_cache_entry {
|
||||
CGAL_Nef_polyhedron N;
|
||||
QString msg;
|
||||
cgal_nef_cache_entry(CGAL_Nef_polyhedron N);
|
||||
};
|
||||
static QCache<QString, cgal_nef_cache_entry> cgal_nef_cache;
|
||||
virtual CGAL_Nef_polyhedron render_cgal_nef_polyhedron() const;
|
||||
#endif
|
||||
virtual class CSGTerm *render_csg_term(double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const;
|
||||
virtual QString dump(QString indent) const;
|
||||
};
|
||||
|
||||
class AbstractIntersectionNode : public AbstractNode
|
||||
{
|
||||
public:
|
||||
AbstractIntersectionNode(const ModuleInstantiation *mi) : AbstractNode(mi) { };
|
||||
#ifdef ENABLE_CGAL
|
||||
virtual CGAL_Nef_polyhedron render_cgal_nef_polyhedron() const;
|
||||
#endif
|
||||
virtual CSGTerm *render_csg_term(double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const;
|
||||
virtual QString dump(QString indent) const;
|
||||
};
|
||||
|
||||
class AbstractPolyNode : public AbstractNode
|
||||
{
|
||||
public:
|
||||
enum render_mode_e {
|
||||
RENDER_CGAL,
|
||||
RENDER_OPENCSG
|
||||
};
|
||||
AbstractPolyNode(const ModuleInstantiation *mi) : AbstractNode(mi) { };
|
||||
virtual class PolySet *render_polyset(render_mode_e mode) const;
|
||||
#ifdef ENABLE_CGAL
|
||||
virtual CGAL_Nef_polyhedron render_cgal_nef_polyhedron() const;
|
||||
#endif
|
||||
virtual CSGTerm *render_csg_term(double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const;
|
||||
static CSGTerm *render_csg_term_from_ps(double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background, PolySet *ps, const ModuleInstantiation *modinst, int idx);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -22,6 +22,16 @@
|
|||
|
||||
#include "openscad.h"
|
||||
#include "MainWindow.h"
|
||||
#include "node.h"
|
||||
#include "module.h"
|
||||
#include "context.h"
|
||||
#include "value.h"
|
||||
#include "export.h"
|
||||
#include "builtin.h"
|
||||
|
||||
#ifdef ENABLE_CGAL
|
||||
#include "cgal.h"
|
||||
#endif
|
||||
|
||||
#include <QApplication>
|
||||
#include <QFile>
|
||||
|
@ -162,6 +172,7 @@ int main(int argc, char **argv)
|
|||
root_ctx.set_variable("$vpt", zero3);
|
||||
root_ctx.set_variable("$vpr", zero3);
|
||||
|
||||
|
||||
AbstractModule *root_module;
|
||||
ModuleInstantiation root_inst;
|
||||
AbstractNode *root_node;
|
||||
|
|
697
src/openscad.h
697
src/openscad.h
|
@ -26,712 +26,19 @@
|
|||
# include <GL/glew.h>
|
||||
#endif
|
||||
|
||||
#include <qgl.h>
|
||||
|
||||
#include <QHash>
|
||||
#include <QCache>
|
||||
#include <QVector>
|
||||
#include <QProgressDialog>
|
||||
#include <QSyntaxHighlighter>
|
||||
#include <QPointer>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
// for win32 and maybe others..
|
||||
#ifndef M_PI
|
||||
# define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
class Value;
|
||||
class Expression;
|
||||
|
||||
class AbstractFunction;
|
||||
class BuiltinFunction;
|
||||
class Function;
|
||||
|
||||
class AbstractModule;
|
||||
class ModuleInstantiation;
|
||||
class Module;
|
||||
|
||||
class Context;
|
||||
class PolySet;
|
||||
class CSGTerm;
|
||||
class CSGChain;
|
||||
class AbstractNode;
|
||||
class AbstractIntersectionNode;
|
||||
class AbstractPolyNode;
|
||||
struct CGAL_Nef_polyhedron;
|
||||
|
||||
const double GRID_COARSE = 0.001;
|
||||
const double GRID_FINE = 0.000001;
|
||||
|
||||
template <typename T>
|
||||
class Grid2d
|
||||
{
|
||||
public:
|
||||
double res;
|
||||
QHash<QPair<int64_t,int64_t>, T> db;
|
||||
|
||||
Grid2d(double resolution) {
|
||||
res = resolution;
|
||||
}
|
||||
/*!
|
||||
Aligns x,y to the grid or to existing point if one close enough exists.
|
||||
Returns the value stored if a point already existing or an uninitialized new value
|
||||
if not.
|
||||
*/
|
||||
T &align(double &x, double &y) {
|
||||
int64_t ix = (int64_t)round(x / res);
|
||||
int64_t iy = (int64_t)round(y / res);
|
||||
if (!db.contains(QPair<int64_t,int64_t>(ix, iy))) {
|
||||
int dist = 10;
|
||||
for (int64_t jx = ix - 1; jx <= ix + 1; jx++) {
|
||||
for (int64_t jy = iy - 1; jy <= iy + 1; jy++) {
|
||||
if (!db.contains(QPair<int64_t,int64_t>(jx, jy)))
|
||||
continue;
|
||||
if (abs(ix-jx) + abs(iy-jy) < dist) {
|
||||
dist = abs(ix-jx) + abs(iy-jy);
|
||||
ix = jx;
|
||||
iy = jy;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
x = ix * res, y = iy * res;
|
||||
return db[QPair<int64_t,int64_t>(ix, iy)];
|
||||
}
|
||||
bool has(double x, double y) const {
|
||||
int64_t ix = (int64_t)round(x / res);
|
||||
int64_t iy = (int64_t)round(y / res);
|
||||
if (db.contains(QPair<int64_t,int64_t>(ix, iy)))
|
||||
return true;
|
||||
for (int64_t jx = ix - 1; jx <= ix + 1; jx++)
|
||||
for (int64_t jy = iy - 1; jy <= iy + 1; jy++) {
|
||||
if (db.contains(QPair<int64_t,int64_t>(jx, jy)))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool eq(double x1, double y1, double x2, double y2) {
|
||||
align(x1, y1);
|
||||
align(x2, y2);
|
||||
if (fabs(x1 - x2) < res && fabs(y1 - y2) < res)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
T &data(double x, double y) {
|
||||
return align(x, y);
|
||||
}
|
||||
T &operator()(double x, double y) {
|
||||
return align(x, y);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class Grid3d
|
||||
{
|
||||
public:
|
||||
double res;
|
||||
QHash<QPair<QPair<int64_t,int64_t>,int64_t>, T> db;
|
||||
|
||||
Grid3d(double resolution) {
|
||||
res = resolution;
|
||||
}
|
||||
T &align(double &x, double &y, double &z) {
|
||||
int64_t ix = (int64_t)round(x / res);
|
||||
int64_t iy = (int64_t)round(y / res);
|
||||
int64_t iz = (int64_t)round(z / res);
|
||||
if (!db.contains(QPair<QPair<int64_t,int64_t>,int64_t>(QPair<int64_t,int64_t>(ix, iy), iz))) {
|
||||
int dist = 10;
|
||||
for (int64_t jx = ix - 1; jx <= ix + 1; jx++) {
|
||||
for (int64_t jy = iy - 1; jy <= iy + 1; jy++) {
|
||||
for (int64_t jz = iz - 1; jz <= iz + 1; jz++) {
|
||||
if (!db.contains(QPair<QPair<int64_t,int64_t>,int64_t>(QPair<int64_t,int64_t>(jx, jy), jz)))
|
||||
continue;
|
||||
if (abs(ix-jx) + abs(iy-jy) + abs(iz-jz) < dist) {
|
||||
dist = abs(ix-jx) + abs(iy-jy) + abs(iz-jz);
|
||||
ix = jx;
|
||||
iy = jy;
|
||||
iz = jz;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
x = ix * res, y = iy * res, z = iz * res;
|
||||
return db[QPair<QPair<int64_t,int64_t>,int64_t>(QPair<int64_t,int64_t>(ix, iy), iz)];
|
||||
}
|
||||
bool has(double x, double y, double z) {
|
||||
int64_t ix = (int64_t)round(x / res);
|
||||
int64_t iy = (int64_t)round(y / res);
|
||||
int64_t iz = (int64_t)round(z / res);
|
||||
if (db.contains(QPair<QPair<int64_t,int64_t>,int64_t>(QPair<int64_t,int64_t>(ix, iy), iz)))
|
||||
return true;
|
||||
for (int64_t jx = ix - 1; jx <= ix + 1; jx++)
|
||||
for (int64_t jy = iy - 1; jy <= iy + 1; jy++)
|
||||
for (int64_t jz = iz - 1; jz <= iz + 1; jz++) {
|
||||
if (db.contains(QPair<QPair<int64_t,int64_t>,int64_t>(QPair<int64_t,int64_t>(jx, jy), jz)))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
bool eq(double x1, double y1, double z1, double x2, double y2, double z2) {
|
||||
align(x1, y1, z1);
|
||||
align(x2, y2, z2);
|
||||
if (fabs(x1 - x2) < res && fabs(y1 - y2) < res && fabs(z1 - z2) < res)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
T &data(double x, double y, double z) {
|
||||
return align(x, y, z);
|
||||
}
|
||||
T &operator()(double x, double y, double z) {
|
||||
return align(x, y, z);
|
||||
}
|
||||
};
|
||||
|
||||
class Value
|
||||
{
|
||||
public:
|
||||
enum type_e {
|
||||
UNDEFINED,
|
||||
BOOL,
|
||||
NUMBER,
|
||||
RANGE,
|
||||
VECTOR,
|
||||
STRING
|
||||
};
|
||||
|
||||
enum type_e type;
|
||||
|
||||
bool b;
|
||||
double num;
|
||||
QVector<Value*> vec;
|
||||
double range_begin;
|
||||
double range_step;
|
||||
double range_end;
|
||||
QString text;
|
||||
|
||||
Value();
|
||||
~Value();
|
||||
|
||||
Value(bool v);
|
||||
Value(double v);
|
||||
Value(const QString &t);
|
||||
|
||||
Value(const Value &v);
|
||||
Value& operator = (const Value &v);
|
||||
|
||||
Value operator ! () const;
|
||||
Value operator && (const Value &v) const;
|
||||
Value operator || (const Value &v) const;
|
||||
|
||||
Value operator + (const Value &v) const;
|
||||
Value operator - (const Value &v) const;
|
||||
Value operator * (const Value &v) const;
|
||||
Value operator / (const Value &v) const;
|
||||
Value operator % (const Value &v) const;
|
||||
|
||||
Value operator < (const Value &v) const;
|
||||
Value operator <= (const Value &v) const;
|
||||
Value operator == (const Value &v) const;
|
||||
Value operator != (const Value &v) const;
|
||||
Value operator >= (const Value &v) const;
|
||||
Value operator > (const Value &v) const;
|
||||
|
||||
Value inv() const;
|
||||
|
||||
bool getnum(double &v) const;
|
||||
bool getv2(double &x, double &y) const;
|
||||
bool getv3(double &x, double &y, double &z) const;
|
||||
|
||||
QString dump() const;
|
||||
|
||||
private:
|
||||
void reset_undef();
|
||||
};
|
||||
|
||||
class Expression
|
||||
{
|
||||
public:
|
||||
QVector<Expression*> children;
|
||||
|
||||
Value *const_value;
|
||||
QString var_name;
|
||||
|
||||
QString call_funcname;
|
||||
QVector<QString> call_argnames;
|
||||
|
||||
// Boolean: ! && ||
|
||||
// Operators: * / % + -
|
||||
// Relations: < <= == != >= >
|
||||
// Vector element: []
|
||||
// Condition operator: ?:
|
||||
// Invert (prefix '-'): I
|
||||
// Constant value: C
|
||||
// Create Range: R
|
||||
// Create Vector: V
|
||||
// Create Matrix: M
|
||||
// Lookup Variable: L
|
||||
// Lookup member per name: N
|
||||
// Function call: F
|
||||
QString type;
|
||||
|
||||
Expression();
|
||||
~Expression();
|
||||
|
||||
Value evaluate(const Context *context) const;
|
||||
QString dump() const;
|
||||
};
|
||||
|
||||
class AbstractFunction
|
||||
{
|
||||
public:
|
||||
virtual ~AbstractFunction();
|
||||
virtual Value evaluate(const Context *ctx, const QVector<QString> &call_argnames, const QVector<Value> &call_argvalues) const;
|
||||
virtual QString dump(QString indent, QString name) const;
|
||||
};
|
||||
|
||||
class BuiltinFunction : public AbstractFunction
|
||||
{
|
||||
public:
|
||||
typedef Value (*eval_func_t)(const QVector<QString> &argnames, const QVector<Value> &args);
|
||||
eval_func_t eval_func;
|
||||
|
||||
BuiltinFunction(eval_func_t f) : eval_func(f) { }
|
||||
virtual ~BuiltinFunction();
|
||||
|
||||
virtual Value evaluate(const Context *ctx, const QVector<QString> &call_argnames, const QVector<Value> &call_argvalues) const;
|
||||
virtual QString dump(QString indent, QString name) const;
|
||||
};
|
||||
|
||||
class Function : public AbstractFunction
|
||||
{
|
||||
public:
|
||||
QVector<QString> argnames;
|
||||
QVector<Expression*> argexpr;
|
||||
|
||||
Expression *expr;
|
||||
|
||||
Function() { }
|
||||
virtual ~Function();
|
||||
|
||||
virtual Value evaluate(const Context *ctx, const QVector<QString> &call_argnames, const QVector<Value> &call_argvalues) const;
|
||||
virtual QString dump(QString indent, QString name) const;
|
||||
};
|
||||
|
||||
extern QHash<QString, AbstractFunction*> builtin_functions;
|
||||
extern void initialize_builtin_functions();
|
||||
extern void initialize_builtin_dxf_dim();
|
||||
extern void destroy_builtin_functions();
|
||||
|
||||
class AbstractModule
|
||||
{
|
||||
public:
|
||||
virtual ~AbstractModule();
|
||||
virtual AbstractNode *evaluate(const Context *ctx, const ModuleInstantiation *inst) const;
|
||||
virtual QString dump(QString indent, QString name) const;
|
||||
};
|
||||
|
||||
class ModuleInstantiation
|
||||
{
|
||||
public:
|
||||
QString label;
|
||||
QString modname;
|
||||
QVector<QString> argnames;
|
||||
QVector<Expression*> argexpr;
|
||||
QVector<Value> argvalues;
|
||||
QVector<ModuleInstantiation*> children;
|
||||
|
||||
bool tag_root;
|
||||
bool tag_highlight;
|
||||
bool tag_background;
|
||||
const Context *ctx;
|
||||
|
||||
ModuleInstantiation() : tag_root(false), tag_highlight(false), tag_background(false), ctx(NULL) { }
|
||||
~ModuleInstantiation();
|
||||
|
||||
QString dump(QString indent) const;
|
||||
AbstractNode *evaluate(const Context *ctx) const;
|
||||
};
|
||||
|
||||
class Module : public AbstractModule
|
||||
{
|
||||
public:
|
||||
QVector<QString> argnames;
|
||||
QVector<Expression*> argexpr;
|
||||
|
||||
QVector<QString> assignments_var;
|
||||
QVector<Expression*> assignments_expr;
|
||||
|
||||
QHash<QString, AbstractFunction*> functions;
|
||||
QHash<QString, AbstractModule*> modules;
|
||||
|
||||
QVector<ModuleInstantiation*> children;
|
||||
|
||||
Module() { }
|
||||
virtual ~Module();
|
||||
|
||||
virtual AbstractNode *evaluate(const Context *ctx, const ModuleInstantiation *inst) const;
|
||||
virtual QString dump(QString indent, QString name) const;
|
||||
};
|
||||
|
||||
extern QHash<QString, AbstractModule*> builtin_modules;
|
||||
extern void initialize_builtin_modules();
|
||||
extern void destroy_builtin_modules();
|
||||
|
||||
extern void register_builtin_csgops();
|
||||
extern void register_builtin_transform();
|
||||
extern void register_builtin_primitives();
|
||||
extern void register_builtin_surface();
|
||||
extern void register_builtin_control();
|
||||
extern void register_builtin_render();
|
||||
extern void register_builtin_import();
|
||||
extern void register_builtin_dxf_linear_extrude();
|
||||
extern void register_builtin_dxf_rotate_extrude();
|
||||
|
||||
class Context
|
||||
{
|
||||
public:
|
||||
const Context *parent;
|
||||
QHash<QString, Value> variables;
|
||||
QHash<QString, Value> config_variables;
|
||||
const QHash<QString, AbstractFunction*> *functions_p;
|
||||
const QHash<QString, AbstractModule*> *modules_p;
|
||||
const ModuleInstantiation *inst_p;
|
||||
|
||||
static QVector<const Context*> ctx_stack;
|
||||
|
||||
Context(const Context *parent = NULL);
|
||||
~Context();
|
||||
|
||||
void args(const QVector<QString> &argnames, const QVector<Expression*> &argexpr, const QVector<QString> &call_argnames, const QVector<Value> &call_argvalues);
|
||||
|
||||
void set_variable(QString name, Value value);
|
||||
Value lookup_variable(QString name, bool silent = false) const;
|
||||
|
||||
Value evaluate_function(QString name, const QVector<QString> &argnames, const QVector<Value> &argvalues) const;
|
||||
AbstractNode *evaluate_module(const ModuleInstantiation *inst) const;
|
||||
};
|
||||
|
||||
class DxfData
|
||||
{
|
||||
public:
|
||||
struct Point {
|
||||
double x, y;
|
||||
Point() : x(0), y(0) { }
|
||||
Point(double x, double y) : x(x), y(y) { }
|
||||
};
|
||||
struct Path {
|
||||
QList<Point*> points;
|
||||
bool is_closed, is_inner;
|
||||
Path() : is_closed(false), is_inner(false) { }
|
||||
};
|
||||
struct Dim {
|
||||
unsigned int type;
|
||||
double coords[7][2];
|
||||
double angle;
|
||||
double length;
|
||||
QString name;
|
||||
Dim() {
|
||||
for (int i = 0; i < 7; i++)
|
||||
for (int j = 0; j < 2; j++)
|
||||
coords[i][j] = 0;
|
||||
type = 0;
|
||||
angle = 0;
|
||||
length = 0;
|
||||
}
|
||||
};
|
||||
|
||||
QList<Point> points;
|
||||
QList<Path> paths;
|
||||
QList<Dim> dims;
|
||||
|
||||
DxfData();
|
||||
DxfData(double fn, double fs, double fa, QString filename, QString layername = QString(), double xorigin = 0.0, double yorigin = 0.0, double scale = 1.0);
|
||||
DxfData(const struct CGAL_Nef_polyhedron &N);
|
||||
|
||||
Point *addPoint(double x, double y);
|
||||
|
||||
private:
|
||||
void fixup_path_direction();
|
||||
};
|
||||
|
||||
// The CGAL template magic slows down the compilation process by a factor of 5.
|
||||
// So we only include the declaration of AbstractNode where it is needed...
|
||||
#ifdef INCLUDE_ABSTRACT_NODE_DETAILS
|
||||
|
||||
#ifdef ENABLE_CGAL
|
||||
|
||||
#include <CGAL/Gmpq.h>
|
||||
#include <CGAL/Extended_cartesian.h>
|
||||
#include <CGAL/Nef_polyhedron_2.h>
|
||||
#include <CGAL/Cartesian.h>
|
||||
#include <CGAL/Polyhedron_3.h>
|
||||
#include <CGAL/Nef_polyhedron_3.h>
|
||||
#include <CGAL/IO/Polyhedron_iostream.h>
|
||||
|
||||
typedef CGAL::Extended_cartesian<CGAL::Gmpq> CGAL_Kernel2;
|
||||
typedef CGAL::Nef_polyhedron_2<CGAL_Kernel2> CGAL_Nef_polyhedron2;
|
||||
typedef CGAL_Kernel2::Aff_transformation_2 CGAL_Aff_transformation2;
|
||||
|
||||
typedef CGAL::Cartesian<CGAL::Gmpq> CGAL_Kernel3;
|
||||
typedef CGAL::Polyhedron_3<CGAL_Kernel3> CGAL_Polyhedron;
|
||||
typedef CGAL_Polyhedron::HalfedgeDS CGAL_HDS;
|
||||
typedef CGAL::Polyhedron_incremental_builder_3<CGAL_HDS> CGAL_Polybuilder;
|
||||
typedef CGAL::Nef_polyhedron_3<CGAL_Kernel3> CGAL_Nef_polyhedron3;
|
||||
typedef CGAL_Nef_polyhedron3::Aff_transformation_3 CGAL_Aff_transformation;
|
||||
typedef CGAL_Nef_polyhedron3::Vector_3 CGAL_Vector;
|
||||
typedef CGAL_Nef_polyhedron3::Plane_3 CGAL_Plane;
|
||||
typedef CGAL_Nef_polyhedron3::Point_3 CGAL_Point;
|
||||
|
||||
struct CGAL_Nef_polyhedron
|
||||
{
|
||||
int dim;
|
||||
CGAL_Nef_polyhedron2 p2;
|
||||
CGAL_Nef_polyhedron3 p3;
|
||||
|
||||
CGAL_Nef_polyhedron() {
|
||||
dim = 0;
|
||||
}
|
||||
|
||||
CGAL_Nef_polyhedron(const CGAL_Nef_polyhedron2 &p) {
|
||||
dim = 2;
|
||||
p2 = p;
|
||||
}
|
||||
|
||||
CGAL_Nef_polyhedron(const CGAL_Nef_polyhedron3 &p) {
|
||||
dim = 3;
|
||||
p3 = p;
|
||||
}
|
||||
|
||||
int weight() {
|
||||
if (dim == 2)
|
||||
return p2.explorer().number_of_vertices();
|
||||
if (dim == 3)
|
||||
return p3.number_of_vertices();
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* ENABLE_CGAL */
|
||||
|
||||
#ifdef ENABLE_OPENCSG
|
||||
# include <opencsg.h>
|
||||
#endif
|
||||
|
||||
class PolySet
|
||||
{
|
||||
public:
|
||||
struct Point {
|
||||
double x, y, z;
|
||||
Point() : x(0), y(0), z(0) { }
|
||||
Point(double x, double y, double z) : x(x), y(y), z(z) { }
|
||||
};
|
||||
typedef QList<Point> Polygon;
|
||||
QVector<Polygon> polygons;
|
||||
QVector<Polygon> borders;
|
||||
Grid3d<void*> grid;
|
||||
|
||||
bool is2d;
|
||||
int convexity;
|
||||
|
||||
PolySet();
|
||||
~PolySet();
|
||||
|
||||
void append_poly();
|
||||
void append_vertex(double x, double y, double z);
|
||||
void insert_vertex(double x, double y, double z);
|
||||
|
||||
void append_vertex(double x, double y) {
|
||||
append_vertex(x, y, 0.0);
|
||||
}
|
||||
void insert_vertex(double x, double y) {
|
||||
insert_vertex(x, y, 0.0);
|
||||
}
|
||||
|
||||
enum colormode_e {
|
||||
COLORMODE_NONE,
|
||||
COLORMODE_MATERIAL,
|
||||
COLORMODE_CUTOUT,
|
||||
COLORMODE_HIGHLIGHT,
|
||||
COLORMODE_BACKGROUND
|
||||
};
|
||||
|
||||
enum csgmode_e {
|
||||
CSGMODE_NONE,
|
||||
CSGMODE_NORMAL = 1,
|
||||
CSGMODE_DIFFERENCE = 2,
|
||||
CSGMODE_BACKGROUND = 11,
|
||||
CSGMODE_BACKGROUND_DIFFERENCE = 12,
|
||||
CSGMODE_HIGHLIGHT = 21,
|
||||
CSGMODE_HIGHLIGHT_DIFFERENCE = 22
|
||||
};
|
||||
|
||||
struct ps_cache_entry {
|
||||
PolySet *ps;
|
||||
QString msg;
|
||||
ps_cache_entry(PolySet *ps);
|
||||
~ps_cache_entry();
|
||||
};
|
||||
|
||||
static QCache<QString,ps_cache_entry> ps_cache;
|
||||
|
||||
void render_surface(colormode_e colormode, csgmode_e csgmode, double *m, GLint *shaderinfo = NULL) const;
|
||||
void render_edges(colormode_e colormode, csgmode_e csgmode) const;
|
||||
|
||||
#ifdef ENABLE_CGAL
|
||||
CGAL_Nef_polyhedron render_cgal_nef_polyhedron() const;
|
||||
#endif
|
||||
|
||||
int refcount;
|
||||
PolySet *link();
|
||||
void unlink();
|
||||
};
|
||||
|
||||
class CSGTerm
|
||||
{
|
||||
public:
|
||||
enum type_e {
|
||||
TYPE_PRIMITIVE,
|
||||
TYPE_UNION,
|
||||
TYPE_INTERSECTION,
|
||||
TYPE_DIFFERENCE
|
||||
};
|
||||
|
||||
type_e type;
|
||||
PolySet *polyset;
|
||||
QString label;
|
||||
CSGTerm *left;
|
||||
CSGTerm *right;
|
||||
double m[20];
|
||||
int refcounter;
|
||||
|
||||
CSGTerm(PolySet *polyset, double m[20], QString label);
|
||||
CSGTerm(type_e type, CSGTerm *left, CSGTerm *right);
|
||||
|
||||
CSGTerm *normalize();
|
||||
CSGTerm *normalize_tail();
|
||||
|
||||
CSGTerm *link();
|
||||
void unlink();
|
||||
QString dump();
|
||||
};
|
||||
|
||||
class CSGChain
|
||||
{
|
||||
public:
|
||||
QVector<PolySet*> polysets;
|
||||
QVector<double*> matrices;
|
||||
QVector<CSGTerm::type_e> types;
|
||||
QVector<QString> labels;
|
||||
|
||||
CSGChain();
|
||||
|
||||
void add(PolySet *polyset, double *m, CSGTerm::type_e type, QString label);
|
||||
void import(CSGTerm *term, CSGTerm::type_e type = CSGTerm::TYPE_UNION);
|
||||
QString dump();
|
||||
};
|
||||
|
||||
class AbstractNode
|
||||
{
|
||||
public:
|
||||
QVector<AbstractNode*> children;
|
||||
const ModuleInstantiation *modinst;
|
||||
|
||||
int progress_mark;
|
||||
void progress_prepare();
|
||||
void progress_report() const;
|
||||
|
||||
int idx;
|
||||
static int idx_counter;
|
||||
QString dump_cache;
|
||||
|
||||
AbstractNode(const ModuleInstantiation *mi);
|
||||
virtual ~AbstractNode();
|
||||
virtual QString mk_cache_id() const;
|
||||
#ifdef ENABLE_CGAL
|
||||
struct cgal_nef_cache_entry {
|
||||
CGAL_Nef_polyhedron N;
|
||||
QString msg;
|
||||
cgal_nef_cache_entry(CGAL_Nef_polyhedron N);
|
||||
};
|
||||
static QCache<QString, cgal_nef_cache_entry> cgal_nef_cache;
|
||||
virtual CGAL_Nef_polyhedron render_cgal_nef_polyhedron() const;
|
||||
#endif
|
||||
virtual CSGTerm *render_csg_term(double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const;
|
||||
virtual QString dump(QString indent) const;
|
||||
};
|
||||
|
||||
class AbstractIntersectionNode : public AbstractNode
|
||||
{
|
||||
public:
|
||||
AbstractIntersectionNode(const ModuleInstantiation *mi) : AbstractNode(mi) { };
|
||||
#ifdef ENABLE_CGAL
|
||||
virtual CGAL_Nef_polyhedron render_cgal_nef_polyhedron() const;
|
||||
#endif
|
||||
virtual CSGTerm *render_csg_term(double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const;
|
||||
virtual QString dump(QString indent) const;
|
||||
};
|
||||
|
||||
class AbstractPolyNode : public AbstractNode
|
||||
{
|
||||
public:
|
||||
enum render_mode_e {
|
||||
RENDER_CGAL,
|
||||
RENDER_OPENCSG
|
||||
};
|
||||
AbstractPolyNode(const ModuleInstantiation *mi) : AbstractNode(mi) { };
|
||||
virtual PolySet *render_polyset(render_mode_e mode) const;
|
||||
#ifdef ENABLE_CGAL
|
||||
virtual CGAL_Nef_polyhedron render_cgal_nef_polyhedron() const;
|
||||
#endif
|
||||
virtual CSGTerm *render_csg_term(double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const;
|
||||
static CSGTerm *render_csg_term_from_ps(double m[20], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background, PolySet *ps, const ModuleInstantiation *modinst, int idx);
|
||||
};
|
||||
|
||||
extern QHash<QString,Value> dxf_dim_cache;
|
||||
extern QHash<QString,Value> dxf_cross_cache;
|
||||
|
||||
extern int progress_report_count;
|
||||
extern void (*progress_report_f)(const class AbstractNode*, void*, int);
|
||||
extern void *progress_report_vp;
|
||||
|
||||
void progress_report_prep(AbstractNode *root, void (*f)(const class AbstractNode *node, void *vp, int mark), void *vp);
|
||||
void progress_report_fin();
|
||||
|
||||
void dxf_tesselate(PolySet *ps, DxfData *dxf, double rot, bool up, bool do_triangle_splitting, double h);
|
||||
void dxf_border_to_ps(PolySet *ps, DxfData *dxf);
|
||||
|
||||
#endif /* INCLUDE_ABSTRACT_NODE_DETAILS */
|
||||
|
||||
class Highlighter : public QSyntaxHighlighter
|
||||
{
|
||||
public:
|
||||
Highlighter(QTextDocument *parent);
|
||||
void highlightBlock(const QString &text);
|
||||
};
|
||||
|
||||
extern AbstractModule *parse(const char *text, int debug);
|
||||
extern class AbstractModule *parse(const char *text, int debug);
|
||||
extern int get_fragments_from_r(double r, double fn, double fs, double fa);
|
||||
|
||||
#include <QString>
|
||||
extern QString commandline_commands;
|
||||
extern int parser_error_pos;
|
||||
|
||||
#ifdef ENABLE_CGAL
|
||||
void export_stl(CGAL_Nef_polyhedron *root_N, QString filename, QProgressDialog *pd);
|
||||
void export_off(CGAL_Nef_polyhedron *root_N, QString filename, QProgressDialog *pd);
|
||||
void export_dxf(CGAL_Nef_polyhedron *root_N, QString filename, QProgressDialog *pd);
|
||||
#endif
|
||||
extern void handle_dep(QString filename);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -18,9 +18,10 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#define INCLUDE_ABSTRACT_NODE_DETAILS
|
||||
|
||||
#include "openscad.h"
|
||||
#include "polyset.h"
|
||||
#include "node.h"
|
||||
#include "module.h"
|
||||
#include "csgterm.h"
|
||||
#include "printutils.h"
|
||||
#include "Preferences.h"
|
||||
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
#ifndef POLYSET_H_
|
||||
#define POLYSET_H_
|
||||
|
||||
#ifdef ENABLE_OPENCSG
|
||||
// this must be included before the GL headers
|
||||
# include <GL/glew.h>
|
||||
#endif
|
||||
#include <qgl.h>
|
||||
|
||||
#include "grid.h"
|
||||
#ifdef ENABLE_OPENCSG
|
||||
# include <opencsg.h>
|
||||
#endif
|
||||
#ifdef ENABLE_CGAL
|
||||
# include "cgal.h"
|
||||
#endif
|
||||
|
||||
#include <QCache.h>
|
||||
|
||||
class PolySet
|
||||
{
|
||||
public:
|
||||
struct Point {
|
||||
double x, y, z;
|
||||
Point() : x(0), y(0), z(0) { }
|
||||
Point(double x, double y, double z) : x(x), y(y), z(z) { }
|
||||
};
|
||||
typedef QList<Point> Polygon;
|
||||
QVector<Polygon> polygons;
|
||||
QVector<Polygon> borders;
|
||||
Grid3d<void*> grid;
|
||||
|
||||
bool is2d;
|
||||
int convexity;
|
||||
|
||||
PolySet();
|
||||
~PolySet();
|
||||
|
||||
void append_poly();
|
||||
void append_vertex(double x, double y, double z);
|
||||
void insert_vertex(double x, double y, double z);
|
||||
|
||||
void append_vertex(double x, double y) {
|
||||
append_vertex(x, y, 0.0);
|
||||
}
|
||||
void insert_vertex(double x, double y) {
|
||||
insert_vertex(x, y, 0.0);
|
||||
}
|
||||
|
||||
enum colormode_e {
|
||||
COLORMODE_NONE,
|
||||
COLORMODE_MATERIAL,
|
||||
COLORMODE_CUTOUT,
|
||||
COLORMODE_HIGHLIGHT,
|
||||
COLORMODE_BACKGROUND
|
||||
};
|
||||
|
||||
enum csgmode_e {
|
||||
CSGMODE_NONE,
|
||||
CSGMODE_NORMAL = 1,
|
||||
CSGMODE_DIFFERENCE = 2,
|
||||
CSGMODE_BACKGROUND = 11,
|
||||
CSGMODE_BACKGROUND_DIFFERENCE = 12,
|
||||
CSGMODE_HIGHLIGHT = 21,
|
||||
CSGMODE_HIGHLIGHT_DIFFERENCE = 22
|
||||
};
|
||||
|
||||
struct ps_cache_entry {
|
||||
PolySet *ps;
|
||||
QString msg;
|
||||
ps_cache_entry(PolySet *ps);
|
||||
~ps_cache_entry();
|
||||
};
|
||||
|
||||
static QCache<QString,ps_cache_entry> ps_cache;
|
||||
|
||||
void render_surface(colormode_e colormode, csgmode_e csgmode, double *m, GLint *shaderinfo = NULL) const;
|
||||
void render_edges(colormode_e colormode, csgmode_e csgmode) const;
|
||||
|
||||
#ifdef ENABLE_CGAL
|
||||
CGAL_Nef_polyhedron render_cgal_nef_polyhedron() const;
|
||||
#endif
|
||||
|
||||
int refcount;
|
||||
PolySet *link();
|
||||
void unlink();
|
||||
};
|
||||
|
||||
#endif
|
|
@ -18,9 +18,13 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#define INCLUDE_ABSTRACT_NODE_DETAILS
|
||||
|
||||
#include "openscad.h"
|
||||
#include "module.h"
|
||||
#include "node.h"
|
||||
#include "polyset.h"
|
||||
#include "context.h"
|
||||
#include "dxfdata.h"
|
||||
#include "dxftess.h"
|
||||
#include "builtin.h"
|
||||
|
||||
enum primitive_type_e {
|
||||
CUBE,
|
||||
|
|
|
@ -18,10 +18,18 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#define INCLUDE_ABSTRACT_NODE_DETAILS
|
||||
|
||||
#include "openscad.h"
|
||||
#include "module.h"
|
||||
#include "node.h"
|
||||
#include "polyset.h"
|
||||
#include "context.h"
|
||||
#include "dxfdata.h"
|
||||
#include "dxftess.h"
|
||||
#include "csgterm.h"
|
||||
#include "builtin.h"
|
||||
#include "printutils.h"
|
||||
#ifdef ENABLE_CGAL
|
||||
# include "cgal.h"
|
||||
#endif
|
||||
|
||||
#include <QProgressDialog>
|
||||
#include <QApplication>
|
||||
|
|
|
@ -18,10 +18,14 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#define INCLUDE_ABSTRACT_NODE_DETAILS
|
||||
|
||||
#include "openscad.h"
|
||||
#include "module.h"
|
||||
#include "node.h"
|
||||
#include "polyset.h"
|
||||
#include "context.h"
|
||||
#include "builtin.h"
|
||||
#include "dxftess.h"
|
||||
#include "printutils.h"
|
||||
#include "openscad.h" // handle_dep()
|
||||
|
||||
#include <QFile>
|
||||
|
||||
|
|
|
@ -18,9 +18,14 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#define INCLUDE_ABSTRACT_NODE_DETAILS
|
||||
|
||||
#include "openscad.h"
|
||||
#include "module.h"
|
||||
#include "node.h"
|
||||
#include "context.h"
|
||||
#include "dxfdata.h"
|
||||
#include "csgterm.h"
|
||||
#include "polyset.h"
|
||||
#include "dxftess.h"
|
||||
#include "builtin.h"
|
||||
#include "printutils.h"
|
||||
|
||||
enum transform_type_e {
|
||||
|
|
|
@ -18,7 +18,8 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "openscad.h"
|
||||
#include "value.h"
|
||||
#include <math.h>
|
||||
|
||||
Value::Value()
|
||||
{
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
#ifndef VALUE_H_
|
||||
#define VALUE_H_
|
||||
|
||||
#include <QVector>
|
||||
#include <QString>
|
||||
|
||||
class Value
|
||||
{
|
||||
public:
|
||||
enum type_e {
|
||||
UNDEFINED,
|
||||
BOOL,
|
||||
NUMBER,
|
||||
RANGE,
|
||||
VECTOR,
|
||||
STRING
|
||||
};
|
||||
|
||||
enum type_e type;
|
||||
|
||||
bool b;
|
||||
double num;
|
||||
QVector<Value*> vec;
|
||||
double range_begin;
|
||||
double range_step;
|
||||
double range_end;
|
||||
QString text;
|
||||
|
||||
Value();
|
||||
~Value();
|
||||
|
||||
Value(bool v);
|
||||
Value(double v);
|
||||
Value(const QString &t);
|
||||
|
||||
Value(const Value &v);
|
||||
Value& operator = (const Value &v);
|
||||
|
||||
Value operator ! () const;
|
||||
Value operator && (const Value &v) const;
|
||||
Value operator || (const Value &v) const;
|
||||
|
||||
Value operator + (const Value &v) const;
|
||||
Value operator - (const Value &v) const;
|
||||
Value operator * (const Value &v) const;
|
||||
Value operator / (const Value &v) const;
|
||||
Value operator % (const Value &v) const;
|
||||
|
||||
Value operator < (const Value &v) const;
|
||||
Value operator <= (const Value &v) const;
|
||||
Value operator == (const Value &v) const;
|
||||
Value operator != (const Value &v) const;
|
||||
Value operator >= (const Value &v) const;
|
||||
Value operator > (const Value &v) const;
|
||||
|
||||
Value inv() const;
|
||||
|
||||
bool getnum(double &v) const;
|
||||
bool getv2(double &x, double &y) const;
|
||||
bool getv3(double &x, double &y, double &z) const;
|
||||
|
||||
QString dump() const;
|
||||
|
||||
private:
|
||||
void reset_undef();
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue