2008-03-25 10:02:13 +00:00
|
|
|
|
|
|
|
#ifndef __SOLVESPACE_H
|
|
|
|
#define __SOLVESPACE_H
|
|
|
|
|
2008-03-28 10:00:37 +00:00
|
|
|
// Debugging functions
|
|
|
|
#define oops() do { dbp("oops at line %d, file %s", __LINE__, __FILE__); \
|
2008-05-17 23:21:02 +00:00
|
|
|
if(1) *(char *)0 = 1; exit(-1); } while(0)
|
2008-03-28 10:00:37 +00:00
|
|
|
#ifndef min
|
|
|
|
#define min(x, y) ((x) < (y) ? (x) : (y))
|
|
|
|
#endif
|
|
|
|
#ifndef max
|
|
|
|
#define max(x, y) ((x) > (y) ? (x) : (y))
|
|
|
|
#endif
|
|
|
|
|
2008-06-03 18:28:41 +00:00
|
|
|
#define isnan(x) (((x) != (x)) || (x > 1e11) || (x < -1e11))
|
|
|
|
|
2008-05-26 03:39:45 +00:00
|
|
|
inline int WRAP(int v, int n) {
|
2009-01-03 12:27:33 +00:00
|
|
|
// Clamp it to the range [0, n)
|
2008-05-26 03:39:45 +00:00
|
|
|
while(v >= n) v -= n;
|
|
|
|
while(v < 0) v += n;
|
|
|
|
return v;
|
|
|
|
}
|
2009-01-03 12:27:33 +00:00
|
|
|
inline double WRAP_NOT_0(double v, double n) {
|
|
|
|
// Clamp it to the range (0, n]
|
|
|
|
while(v > n) v -= n;
|
|
|
|
while(v <= 0) v += n;
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2008-05-11 10:40:37 +00:00
|
|
|
#define SWAP(T, a, b) do { T temp = (a); (a) = (b); (b) = temp; } while(0)
|
2008-05-19 09:23:49 +00:00
|
|
|
#define ZERO(v) memset((v), 0, sizeof(*(v)))
|
2008-05-22 10:28:28 +00:00
|
|
|
#define CO(v) (v).x, (v).y, (v).z
|
|
|
|
|
2009-03-08 10:59:57 +00:00
|
|
|
#define LENGTH_EPS (1e-6)
|
2009-01-27 05:48:40 +00:00
|
|
|
#define VERY_POSITIVE (1e10)
|
|
|
|
#define VERY_NEGATIVE (-1e10)
|
2008-05-11 10:40:37 +00:00
|
|
|
|
2008-04-17 06:42:32 +00:00
|
|
|
#define isforname(c) (isalnum(c) || (c) == '_' || (c) == '-' || (c) == '#')
|
|
|
|
|
2008-04-18 11:11:48 +00:00
|
|
|
typedef signed long SDWORD;
|
2008-06-30 09:09:17 +00:00
|
|
|
typedef signed short SWORD;
|
2008-04-18 11:11:48 +00:00
|
|
|
|
2008-03-25 10:02:13 +00:00
|
|
|
#include <stdlib.h>
|
2008-04-17 06:42:32 +00:00
|
|
|
#include <ctype.h>
|
2008-03-25 10:02:13 +00:00
|
|
|
#include <string.h>
|
2008-03-26 09:18:12 +00:00
|
|
|
#include <stdio.h>
|
2008-03-27 09:53:51 +00:00
|
|
|
#include <math.h>
|
2008-04-01 10:48:44 +00:00
|
|
|
#include <windows.h> // required for GL stuff
|
|
|
|
#include <gl/gl.h>
|
|
|
|
#include <gl/glu.h>
|
|
|
|
|
2009-02-09 12:40:48 +00:00
|
|
|
inline double Random(double vmax) {
|
|
|
|
return (vmax*rand()) / RAND_MAX;
|
|
|
|
}
|
|
|
|
|
2008-04-14 10:28:32 +00:00
|
|
|
class Expr;
|
2008-04-22 13:14:15 +00:00
|
|
|
class ExprVector;
|
2008-05-05 06:18:01 +00:00
|
|
|
class ExprQuaternion;
|
2008-04-14 10:28:32 +00:00
|
|
|
|
2008-05-29 10:10:12 +00:00
|
|
|
|
2008-06-30 09:09:17 +00:00
|
|
|
//================
|
2008-04-14 10:28:32 +00:00
|
|
|
// From the platform-specific code.
|
2008-05-28 10:10:31 +00:00
|
|
|
#define MAX_RECENT 8
|
|
|
|
#define RECENT_OPEN (0xf000)
|
|
|
|
#define RECENT_IMPORT (0xf100)
|
|
|
|
extern char RecentFile[MAX_RECENT][MAX_PATH];
|
|
|
|
void RefreshRecentMenus(void);
|
|
|
|
|
2008-04-18 11:11:48 +00:00
|
|
|
int SaveFileYesNoCancel(void);
|
2008-05-29 10:10:12 +00:00
|
|
|
#define SLVS_PATTERN "SolveSpace Models (*.slvs)\0*.slvs\0All Files (*)\0*\0\0"
|
|
|
|
#define SLVS_EXT "slvs"
|
2008-06-18 08:35:14 +00:00
|
|
|
#define PNG_PATTERN "PNG (*.png)\0*.png\0All Files (*)\0*\0\0"
|
|
|
|
#define PNG_EXT "png"
|
2008-07-06 09:24:31 +00:00
|
|
|
#define STL_PATTERN "STL Mesh (*.stl)\0*.stl\0All Files (*)\0*\0\0"
|
|
|
|
#define STL_EXT "stl"
|
2009-01-27 05:48:40 +00:00
|
|
|
#define VEC_PATTERN "DXF File (*.dxf)\0*.dxf\0" \
|
|
|
|
"Encapsulated PostScript (*.eps;*.ps)\0*.eps;*.ps\0" \
|
|
|
|
"Scalable Vector Graphics (*.svg)\0*.svg\0" \
|
|
|
|
"HPGL File (*.plt;*.hpgl)\0*.plt;*.hpgl\0" \
|
|
|
|
"All Files (*)\0*\0\0"
|
|
|
|
#define VEC_EXT "dxf"
|
2008-07-20 11:27:22 +00:00
|
|
|
#define CSV_PATTERN "CSV File (*.csv)\0*.csv\0All Files (*)\0*\0\0"
|
|
|
|
#define CSV_EXT "csv"
|
2008-02-09 13:52:01 +00:00
|
|
|
#define LICENSE_PATTERN \
|
|
|
|
"License File (*.license)\0*.license\0All Files (*)\0*\0\0"
|
|
|
|
#define LICENSE_EXT "license"
|
2008-04-18 11:11:48 +00:00
|
|
|
BOOL GetSaveFile(char *file, char *defExtension, char *selPattern);
|
|
|
|
BOOL GetOpenFile(char *file, char *defExtension, char *selPattern);
|
2008-06-25 05:14:49 +00:00
|
|
|
void GetAbsoluteFilename(char *file);
|
2008-06-30 09:09:17 +00:00
|
|
|
void LoadAllFontFiles(void);
|
2008-04-18 11:11:48 +00:00
|
|
|
|
2008-02-09 13:52:01 +00:00
|
|
|
void OpenWebsite(char *url);
|
|
|
|
|
2008-04-14 10:28:32 +00:00
|
|
|
void CheckMenuById(int id, BOOL checked);
|
2008-04-18 07:06:37 +00:00
|
|
|
void EnableMenuById(int id, BOOL checked);
|
2008-04-18 11:11:48 +00:00
|
|
|
|
2008-04-21 10:12:04 +00:00
|
|
|
void ShowGraphicsEditControl(int x, int y, char *s);
|
|
|
|
void HideGraphicsEditControl(void);
|
|
|
|
BOOL GraphicsEditControlIsVisible(void);
|
2008-05-27 06:36:59 +00:00
|
|
|
void ShowTextEditControl(int hr, int c, char *s);
|
|
|
|
void HideTextEditControl(void);
|
|
|
|
BOOL TextEditControlIsVisible(void);
|
2008-04-21 10:12:04 +00:00
|
|
|
|
2008-04-27 05:00:12 +00:00
|
|
|
void ShowTextWindow(BOOL visible);
|
2008-04-14 10:28:32 +00:00
|
|
|
void InvalidateText(void);
|
2008-04-27 05:00:12 +00:00
|
|
|
void InvalidateGraphics(void);
|
2008-04-18 11:11:48 +00:00
|
|
|
void PaintGraphics(void);
|
2008-06-12 07:31:41 +00:00
|
|
|
void GetGraphicsWindowSize(int *w, int *h);
|
2008-04-27 05:00:12 +00:00
|
|
|
SDWORD GetMilliseconds(void);
|
2008-04-18 11:11:48 +00:00
|
|
|
|
2008-04-14 10:28:32 +00:00
|
|
|
void dbp(char *str, ...);
|
2008-05-30 07:32:30 +00:00
|
|
|
#define DBPTRI(tri) \
|
|
|
|
dbp("tri: (%.3f %.3f %.3f) (%.3f %.3f %.3f) (%.3f %.3f %.3f)", \
|
|
|
|
CO((tri).a), CO((tri).b), CO((tri).c))
|
|
|
|
|
2008-07-08 08:02:22 +00:00
|
|
|
void SetWindowTitle(char *str);
|
2008-02-09 13:52:01 +00:00
|
|
|
void Message(char *str, ...);
|
2008-04-14 10:28:32 +00:00
|
|
|
void Error(char *str, ...);
|
2009-01-02 10:38:36 +00:00
|
|
|
void SetTimerFor(int milliseconds);
|
2008-06-03 18:48:47 +00:00
|
|
|
void ExitNow(void);
|
2008-07-08 08:02:22 +00:00
|
|
|
|
2009-01-02 10:38:36 +00:00
|
|
|
void DrawWithBitmapFont(char *str);
|
|
|
|
void GetBitmapFontExtent(char *str, int *w, int *h);
|
|
|
|
|
2008-06-11 04:22:52 +00:00
|
|
|
void CnfFreezeString(char *str, char *name);
|
|
|
|
void CnfFreezeDWORD(DWORD v, char *name);
|
2008-07-08 07:41:29 +00:00
|
|
|
void CnfFreezeFloat(float v, char *name);
|
2008-06-11 04:22:52 +00:00
|
|
|
void CnfThawString(char *str, int maxLen, char *name);
|
|
|
|
DWORD CnfThawDWORD(DWORD v, char *name);
|
2008-07-08 07:41:29 +00:00
|
|
|
float CnfThawFloat(float v, char *name);
|
2008-04-18 11:11:48 +00:00
|
|
|
|
2008-04-25 10:11:29 +00:00
|
|
|
void *AllocTemporary(int n);
|
2008-07-13 12:58:52 +00:00
|
|
|
void FreeTemporary(void *p);
|
2008-04-25 10:11:29 +00:00
|
|
|
void FreeAllTemporary(void);
|
2008-04-18 07:06:37 +00:00
|
|
|
void *MemRealloc(void *p, int n);
|
|
|
|
void *MemAlloc(int n);
|
|
|
|
void MemFree(void *p);
|
2008-06-30 09:09:17 +00:00
|
|
|
void vl(void); // debug function to validate heaps
|
|
|
|
|
|
|
|
// End of platform-specific functions
|
|
|
|
//================
|
2008-04-14 10:28:32 +00:00
|
|
|
|
|
|
|
|
2009-02-27 14:05:08 +00:00
|
|
|
class SSurface;
|
2008-03-25 10:02:13 +00:00
|
|
|
#include "dsc.h"
|
2008-04-23 07:29:19 +00:00
|
|
|
#include "polygon.h"
|
2009-01-15 03:55:42 +00:00
|
|
|
#include "srf/surface.h"
|
2008-05-29 10:10:12 +00:00
|
|
|
|
|
|
|
class Entity;
|
|
|
|
class hEntity;
|
2008-06-23 08:25:17 +00:00
|
|
|
class Param;
|
|
|
|
class hParam;
|
2008-05-29 10:10:12 +00:00
|
|
|
typedef IdList<Entity,hEntity> EntityList;
|
2008-06-23 08:25:17 +00:00
|
|
|
typedef IdList<Param,hParam> ParamList;
|
2008-05-29 10:10:12 +00:00
|
|
|
|
2008-03-26 09:18:12 +00:00
|
|
|
#include "sketch.h"
|
2008-04-12 14:12:26 +00:00
|
|
|
#include "ui.h"
|
2008-04-08 12:54:53 +00:00
|
|
|
#include "expr.h"
|
2008-03-25 10:02:13 +00:00
|
|
|
|
2008-03-27 09:53:51 +00:00
|
|
|
|
2008-04-11 11:13:47 +00:00
|
|
|
// Utility functions that are provided in the platform-independent code.
|
|
|
|
void glxVertex3v(Vector u);
|
2008-05-22 10:28:28 +00:00
|
|
|
#define GLX_CALLBACK __stdcall
|
|
|
|
typedef void GLX_CALLBACK glxCallbackFptr(void);
|
|
|
|
void glxTesselatePolygon(GLUtesselator *gt, SPolygon *p);
|
2008-04-25 07:04:09 +00:00
|
|
|
void glxFillPolygon(SPolygon *p);
|
2008-06-02 03:31:37 +00:00
|
|
|
void glxFillMesh(int color, SMesh *m, DWORD h, DWORD s1, DWORD s2);
|
2008-05-19 09:23:49 +00:00
|
|
|
void glxDebugPolygon(SPolygon *p);
|
2008-07-06 07:56:24 +00:00
|
|
|
void glxDrawEdges(SEdgeList *l);
|
2008-05-22 10:28:28 +00:00
|
|
|
void glxDebugMesh(SMesh *m);
|
2008-05-05 09:47:23 +00:00
|
|
|
void glxMarkPolygonNormal(SPolygon *p);
|
2008-04-11 11:13:47 +00:00
|
|
|
void glxWriteText(char *str);
|
2008-04-30 08:14:32 +00:00
|
|
|
void glxWriteTextRefCenter(char *str);
|
2008-05-07 08:19:37 +00:00
|
|
|
double glxStrWidth(char *str);
|
|
|
|
double glxStrHeight(void);
|
2008-04-11 11:13:47 +00:00
|
|
|
void glxTranslatev(Vector u);
|
2008-04-27 03:26:27 +00:00
|
|
|
void glxOntoWorkplane(Vector u, Vector v);
|
2008-04-19 11:09:47 +00:00
|
|
|
void glxLockColorTo(double r, double g, double b);
|
|
|
|
void glxUnlockColor(void);
|
2008-04-25 07:04:09 +00:00
|
|
|
void glxColor3d(double r, double g, double b);
|
|
|
|
void glxColor4d(double r, double g, double b, double a);
|
2008-06-17 19:12:25 +00:00
|
|
|
void glxDepthRangeOffset(int units);
|
|
|
|
void glxDepthRangeLockToFront(bool yes);
|
2008-03-27 09:53:51 +00:00
|
|
|
|
2008-03-25 10:02:13 +00:00
|
|
|
|
2008-03-26 09:18:12 +00:00
|
|
|
#define arraylen(x) (sizeof((x))/sizeof((x)[0]))
|
2008-03-27 09:53:51 +00:00
|
|
|
#define PI (3.1415926535897931)
|
|
|
|
void MakeMatrix(double *mat, double a11, double a12, double a13, double a14,
|
|
|
|
double a21, double a22, double a23, double a24,
|
|
|
|
double a31, double a32, double a33, double a34,
|
|
|
|
double a41, double a42, double a43, double a44);
|
2008-06-25 05:14:49 +00:00
|
|
|
void MakePathRelative(char *base, char *path);
|
|
|
|
void MakePathAbsolute(char *base, char *path);
|
2008-03-27 09:53:51 +00:00
|
|
|
|
2008-04-20 11:35:10 +00:00
|
|
|
class System {
|
|
|
|
public:
|
|
|
|
#define MAX_UNKNOWNS 200
|
|
|
|
|
2008-06-23 08:25:17 +00:00
|
|
|
EntityList entity;
|
|
|
|
ParamList param;
|
2008-04-20 11:35:10 +00:00
|
|
|
IdList<Equation,hEquation> eq;
|
|
|
|
|
|
|
|
// In general, the tag indicates the subsys that a variable/equation
|
2008-05-07 07:10:20 +00:00
|
|
|
// has been assigned to; these are exceptions for variables:
|
2008-06-04 10:22:30 +00:00
|
|
|
static const int VAR_SUBSTITUTED = 10000;
|
2009-01-04 12:01:46 +00:00
|
|
|
static const int VAR_DOF_TEST = 10001;
|
2008-05-07 07:10:20 +00:00
|
|
|
// and for equations:
|
|
|
|
static const int EQ_SUBSTITUTED = 20000;
|
2008-04-20 11:35:10 +00:00
|
|
|
|
2008-04-21 01:26:36 +00:00
|
|
|
// The system Jacobian matrix
|
2008-04-20 11:35:10 +00:00
|
|
|
struct {
|
2008-04-21 01:26:36 +00:00
|
|
|
// The corresponding equation for each row
|
|
|
|
hEquation eq[MAX_UNKNOWNS];
|
2008-04-20 11:35:10 +00:00
|
|
|
|
2008-04-21 01:26:36 +00:00
|
|
|
// The corresponding parameter for each column
|
|
|
|
hParam param[MAX_UNKNOWNS];
|
2008-05-01 06:25:38 +00:00
|
|
|
|
2008-04-21 01:26:36 +00:00
|
|
|
// We're solving AX = B
|
2008-04-20 11:35:10 +00:00
|
|
|
int m, n;
|
2008-04-21 01:26:36 +00:00
|
|
|
struct {
|
|
|
|
Expr *sym[MAX_UNKNOWNS][MAX_UNKNOWNS];
|
|
|
|
double num[MAX_UNKNOWNS][MAX_UNKNOWNS];
|
|
|
|
} A;
|
2008-05-01 06:25:38 +00:00
|
|
|
|
2008-05-13 02:35:31 +00:00
|
|
|
double scale[MAX_UNKNOWNS];
|
|
|
|
|
2008-05-12 07:29:50 +00:00
|
|
|
// Some helpers for the least squares solve
|
|
|
|
double AAt[MAX_UNKNOWNS][MAX_UNKNOWNS];
|
|
|
|
double Z[MAX_UNKNOWNS];
|
|
|
|
|
2008-04-21 01:26:36 +00:00
|
|
|
double X[MAX_UNKNOWNS];
|
2008-05-01 06:25:38 +00:00
|
|
|
|
2008-04-21 01:26:36 +00:00
|
|
|
struct {
|
|
|
|
Expr *sym[MAX_UNKNOWNS];
|
|
|
|
double num[MAX_UNKNOWNS];
|
|
|
|
} B;
|
|
|
|
} mat;
|
2008-04-20 11:35:10 +00:00
|
|
|
|
2008-09-05 11:25:53 +00:00
|
|
|
static const double RANK_MAG_TOLERANCE, CONVERGE_TOLERANCE;
|
2008-07-02 08:18:25 +00:00
|
|
|
int CalculateRank(void);
|
2008-05-12 07:29:50 +00:00
|
|
|
static bool SolveLinearSystem(double X[], double A[][MAX_UNKNOWNS],
|
|
|
|
double B[], int N);
|
|
|
|
bool SolveLeastSquares(void);
|
2008-04-20 11:35:10 +00:00
|
|
|
|
2008-06-26 09:34:26 +00:00
|
|
|
void WriteJacobian(int tag);
|
2008-04-20 11:35:10 +00:00
|
|
|
void EvalJacobian(void);
|
|
|
|
|
2008-05-26 09:56:50 +00:00
|
|
|
void WriteEquationsExceptFor(hConstraint hc, hGroup hg);
|
|
|
|
void FindWhichToRemoveToFixJacobian(Group *g);
|
2008-05-07 07:10:20 +00:00
|
|
|
void SolveBySubstitution(void);
|
|
|
|
|
|
|
|
static bool IsDragged(hParam p);
|
2008-05-01 06:25:38 +00:00
|
|
|
|
2008-04-20 11:35:10 +00:00
|
|
|
bool NewtonSolve(int tag);
|
2009-01-04 12:01:46 +00:00
|
|
|
void Solve(Group *g, bool andFindFree);
|
2008-04-20 11:35:10 +00:00
|
|
|
};
|
|
|
|
|
2008-06-30 09:09:17 +00:00
|
|
|
class TtfFont {
|
|
|
|
public:
|
|
|
|
typedef struct {
|
|
|
|
bool onCurve;
|
|
|
|
bool lastInContour;
|
|
|
|
SWORD x;
|
|
|
|
SWORD y;
|
|
|
|
} FontPoint;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
FontPoint *pt;
|
|
|
|
int pts;
|
|
|
|
|
|
|
|
int xMax;
|
|
|
|
int xMin;
|
|
|
|
int leftSideBearing;
|
|
|
|
int advanceWidth;
|
|
|
|
} Glyph;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int x, y;
|
|
|
|
} IntPoint;
|
|
|
|
|
|
|
|
char fontFile[MAX_PATH];
|
|
|
|
NameStr name;
|
|
|
|
bool loaded;
|
|
|
|
|
|
|
|
// The font itself, plus the mapping from ASCII codes to glyphs
|
|
|
|
int useGlyph[256];
|
|
|
|
Glyph *glyph;
|
|
|
|
int glyphs;
|
|
|
|
|
|
|
|
int maxPoints;
|
|
|
|
int scale;
|
|
|
|
|
|
|
|
// The filehandle, while loading
|
|
|
|
FILE *fh;
|
|
|
|
// Some state while rendering a character to curves
|
|
|
|
static const int NOTHING = 0;
|
|
|
|
static const int ON_CURVE = 1;
|
|
|
|
static const int OFF_CURVE = 2;
|
|
|
|
int lastWas;
|
|
|
|
IntPoint lastOnCurve;
|
|
|
|
IntPoint lastOffCurve;
|
|
|
|
|
|
|
|
// And the state that the caller must specify, determines where we
|
|
|
|
// render to and how
|
2009-01-19 03:51:00 +00:00
|
|
|
SBezierList *beziers;
|
|
|
|
Vector origin, u, v;
|
2008-06-30 09:09:17 +00:00
|
|
|
|
|
|
|
int Getc(void);
|
|
|
|
int GetBYTE(void);
|
|
|
|
int GetWORD(void);
|
|
|
|
int GetDWORD(void);
|
|
|
|
|
|
|
|
void LoadGlyph(int index);
|
|
|
|
bool LoadFontFromFile(bool nameOnly);
|
|
|
|
char *FontFileBaseName(void);
|
|
|
|
|
|
|
|
void Flush(void);
|
|
|
|
void Handle(int *dx, int x, int y, bool onCurve);
|
|
|
|
void PlotCharacter(int *dx, int c, double spacing);
|
|
|
|
void PlotString(char *str, double spacing,
|
2009-01-19 03:51:00 +00:00
|
|
|
SBezierList *sbl, Vector origin, Vector u, Vector v);
|
2008-06-30 09:09:17 +00:00
|
|
|
|
|
|
|
Vector TransformIntPoint(int x, int y);
|
|
|
|
void LineSegment(int x0, int y0, int x1, int y1);
|
|
|
|
void Bezier(int x0, int y0, int x1, int y1, int x2, int y2);
|
2008-07-10 05:26:08 +00:00
|
|
|
void BezierPwl(double ta, double tb, Vector p0, Vector p1, Vector p2);
|
|
|
|
Vector BezierEval(double t, Vector p0, Vector p1, Vector p2);
|
2008-06-30 09:09:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class TtfFontList {
|
|
|
|
public:
|
|
|
|
bool loaded;
|
2009-01-13 06:56:05 +00:00
|
|
|
List<TtfFont> l;
|
2008-06-30 09:09:17 +00:00
|
|
|
|
|
|
|
void LoadAll(void);
|
|
|
|
|
|
|
|
void PlotString(char *font, char *str, double spacing,
|
2009-01-19 03:51:00 +00:00
|
|
|
SBezierList *sbl, Vector origin, Vector u, Vector v);
|
2008-06-30 09:09:17 +00:00
|
|
|
};
|
2008-03-26 09:18:12 +00:00
|
|
|
|
2009-01-14 05:10:42 +00:00
|
|
|
class VectorFileWriter {
|
|
|
|
public:
|
|
|
|
FILE *f;
|
2009-01-27 05:48:40 +00:00
|
|
|
Vector ptMin, ptMax;
|
2009-01-14 05:10:42 +00:00
|
|
|
|
|
|
|
static bool StringEndsIn(char *str, char *ending);
|
|
|
|
static VectorFileWriter *ForFile(char *file);
|
|
|
|
|
2009-03-17 16:33:46 +00:00
|
|
|
void Output(SEdgeList *sel, SMesh *sm);
|
2009-01-27 05:48:40 +00:00
|
|
|
|
2009-01-14 05:10:42 +00:00
|
|
|
virtual void LineSegment(double x0, double y0, double x1, double y1) = 0;
|
2009-03-17 16:33:46 +00:00
|
|
|
virtual void Triangle(STriangle *tr) = 0;
|
2009-01-14 05:10:42 +00:00
|
|
|
virtual void StartFile(void) = 0;
|
|
|
|
virtual void FinishAndCloseFile(void) = 0;
|
|
|
|
};
|
|
|
|
class DxfFileWriter : public VectorFileWriter {
|
|
|
|
public:
|
2009-01-27 05:48:40 +00:00
|
|
|
void LineSegment(double x0, double y0, double x1, double y1);
|
2009-03-17 16:33:46 +00:00
|
|
|
void Triangle(STriangle *tr);
|
2009-01-27 05:48:40 +00:00
|
|
|
void StartFile(void);
|
|
|
|
void FinishAndCloseFile(void);
|
|
|
|
};
|
|
|
|
class EpsFileWriter : public VectorFileWriter {
|
|
|
|
public:
|
|
|
|
static double MmToPoints(double mm);
|
|
|
|
void LineSegment(double x0, double y0, double x1, double y1);
|
2009-03-17 16:33:46 +00:00
|
|
|
void Triangle(STriangle *tr);
|
2009-01-27 05:48:40 +00:00
|
|
|
void StartFile(void);
|
|
|
|
void FinishAndCloseFile(void);
|
|
|
|
};
|
|
|
|
class SvgFileWriter : public VectorFileWriter {
|
|
|
|
public:
|
|
|
|
void LineSegment(double x0, double y0, double x1, double y1);
|
2009-03-17 16:33:46 +00:00
|
|
|
void Triangle(STriangle *tr);
|
2009-01-27 05:48:40 +00:00
|
|
|
void StartFile(void);
|
|
|
|
void FinishAndCloseFile(void);
|
|
|
|
};
|
|
|
|
class HpglFileWriter : public VectorFileWriter {
|
|
|
|
public:
|
|
|
|
static double MmToHpglUnits(double mm);
|
2009-01-14 05:10:42 +00:00
|
|
|
void LineSegment(double x0, double y0, double x1, double y1);
|
2009-03-17 16:33:46 +00:00
|
|
|
void Triangle(STriangle *tr);
|
2009-01-14 05:10:42 +00:00
|
|
|
void StartFile(void);
|
|
|
|
void FinishAndCloseFile(void);
|
|
|
|
};
|
|
|
|
|
2008-03-28 10:00:37 +00:00
|
|
|
class SolveSpace {
|
|
|
|
public:
|
2008-03-26 09:18:12 +00:00
|
|
|
TextWindow TW;
|
|
|
|
GraphicsWindow GW;
|
|
|
|
|
2008-04-14 10:28:32 +00:00
|
|
|
// These lists define the sketch, and are edited by the user.
|
|
|
|
IdList<Group,hGroup> group;
|
|
|
|
IdList<Request,hRequest> request;
|
|
|
|
IdList<Constraint,hConstraint> constraint;
|
|
|
|
|
|
|
|
// These lists are generated automatically when we solve the sketch.
|
|
|
|
IdList<Entity,hEntity> entity;
|
|
|
|
IdList<Param,hParam> param;
|
|
|
|
|
|
|
|
inline Constraint *GetConstraint(hConstraint h)
|
|
|
|
{ return constraint.FindById(h); }
|
|
|
|
inline Request *GetRequest(hRequest h) { return request.FindById(h); }
|
|
|
|
inline Entity *GetEntity (hEntity h) { return entity. FindById(h); }
|
|
|
|
inline Param *GetParam (hParam h) { return param. FindById(h); }
|
2008-04-20 11:35:10 +00:00
|
|
|
inline Group *GetGroup (hGroup h) { return group. FindById(h); }
|
2008-04-13 14:28:35 +00:00
|
|
|
|
2008-06-04 10:22:30 +00:00
|
|
|
// The state for undo/redo
|
|
|
|
typedef struct {
|
|
|
|
IdList<Group,hGroup> group;
|
|
|
|
IdList<Request,hRequest> request;
|
|
|
|
IdList<Constraint,hConstraint> constraint;
|
|
|
|
IdList<Param,hParam> param;
|
|
|
|
hGroup activeGroup;
|
|
|
|
} UndoState;
|
|
|
|
static const int MAX_UNDO = 16;
|
|
|
|
typedef struct {
|
|
|
|
UndoState d[MAX_UNDO];
|
|
|
|
int cnt;
|
|
|
|
int write;
|
|
|
|
} UndoStack;
|
|
|
|
UndoStack undo;
|
|
|
|
UndoStack redo;
|
|
|
|
void UndoEnableMenus(void);
|
|
|
|
void UndoRemember(void);
|
|
|
|
void UndoUndo(void);
|
|
|
|
void UndoRedo(void);
|
|
|
|
void PushFromCurrentOnto(UndoStack *uk);
|
|
|
|
void PopOntoCurrentFrom(UndoStack *uk);
|
|
|
|
void UndoClearState(UndoState *ut);
|
|
|
|
void UndoClearStack(UndoStack *uk);
|
|
|
|
|
2008-06-11 04:22:52 +00:00
|
|
|
// Little bits of extra configuration state
|
|
|
|
static const int MODEL_COLORS = 8;
|
|
|
|
int modelColor[MODEL_COLORS];
|
2008-06-11 04:30:18 +00:00
|
|
|
Vector lightDir[2];
|
2008-06-11 04:22:52 +00:00
|
|
|
double lightIntensity[2];
|
2009-03-17 16:33:46 +00:00
|
|
|
double ambientIntensity;
|
2008-07-10 05:26:08 +00:00
|
|
|
double chordTol;
|
2008-02-12 13:00:26 +00:00
|
|
|
int maxSegments;
|
2008-06-17 19:12:25 +00:00
|
|
|
double cameraTangent;
|
2008-07-06 07:56:24 +00:00
|
|
|
DWORD edgeColor;
|
2008-07-08 07:41:29 +00:00
|
|
|
float exportScale;
|
2008-08-14 08:28:25 +00:00
|
|
|
float exportOffset;
|
2008-08-11 10:56:08 +00:00
|
|
|
int drawBackFaces;
|
2009-01-02 10:38:36 +00:00
|
|
|
int showToolbar;
|
2009-03-18 04:26:04 +00:00
|
|
|
int exportShadedTriangles;
|
|
|
|
int exportExactCurves;
|
2008-07-06 07:56:24 +00:00
|
|
|
|
2008-06-14 09:51:25 +00:00
|
|
|
int CircleSides(double r);
|
|
|
|
typedef enum {
|
|
|
|
UNIT_MM = 0,
|
|
|
|
UNIT_INCHES,
|
|
|
|
} Unit;
|
|
|
|
Unit viewUnits;
|
|
|
|
char *MmToString(double v);
|
|
|
|
double ExprToMm(Expr *e);
|
2008-07-20 11:27:22 +00:00
|
|
|
double StringToMm(char *s);
|
2009-03-08 10:59:57 +00:00
|
|
|
double ChordTolMm(void);
|
2008-06-14 09:51:25 +00:00
|
|
|
|
|
|
|
// The platform-dependent code calls this before entering the msg loop
|
2008-06-11 04:22:52 +00:00
|
|
|
void Init(char *cmdLine);
|
2008-02-09 13:52:01 +00:00
|
|
|
void CheckLicenseFromRegistry(void);
|
2008-06-11 04:22:52 +00:00
|
|
|
void Exit(void);
|
|
|
|
|
2008-06-04 10:22:30 +00:00
|
|
|
// File load/save routines, including the additional files that get
|
|
|
|
// loaded when we have import groups.
|
2008-04-18 11:11:48 +00:00
|
|
|
FILE *fh;
|
2008-05-28 10:10:31 +00:00
|
|
|
void AfterNewFile(void);
|
|
|
|
static void RemoveFromRecentList(char *file);
|
|
|
|
static void AddToRecentList(char *file);
|
2008-04-24 06:22:16 +00:00
|
|
|
char saveFile[MAX_PATH];
|
|
|
|
bool unsaved;
|
|
|
|
typedef struct {
|
|
|
|
char type;
|
|
|
|
char *desc;
|
|
|
|
char fmt;
|
|
|
|
void *ptr;
|
|
|
|
} SaveTable;
|
|
|
|
static const SaveTable SAVED[];
|
|
|
|
void SaveUsingTable(int type);
|
2008-04-27 10:01:23 +00:00
|
|
|
void LoadUsingTable(char *key, char *val);
|
2008-04-24 06:22:16 +00:00
|
|
|
struct {
|
|
|
|
Group g;
|
|
|
|
Request r;
|
|
|
|
Entity e;
|
|
|
|
Param p;
|
|
|
|
Constraint c;
|
|
|
|
} sv;
|
2008-04-18 11:11:48 +00:00
|
|
|
static void MenuFile(int id);
|
2008-06-03 18:28:41 +00:00
|
|
|
bool GetFilenameAndSave(bool saveAs);
|
|
|
|
bool OkayToStartNewFile(void);
|
2008-06-02 11:43:27 +00:00
|
|
|
hGroup CreateDefaultDrawingGroup(void);
|
2008-07-08 08:02:22 +00:00
|
|
|
void UpdateWindowTitle(void);
|
2008-04-24 06:22:16 +00:00
|
|
|
void NewFile(void);
|
2008-04-18 11:11:48 +00:00
|
|
|
bool SaveToFile(char *filename);
|
|
|
|
bool LoadFromFile(char *filename);
|
2008-05-29 10:10:12 +00:00
|
|
|
bool LoadEntitiesFromFile(char *filename, EntityList *le, SMesh *m);
|
|
|
|
void ReloadAllImported(void);
|
2008-07-06 09:24:31 +00:00
|
|
|
// And the various export options
|
2008-06-18 08:35:14 +00:00
|
|
|
void ExportAsPngTo(char *file);
|
2008-07-06 09:24:31 +00:00
|
|
|
void ExportMeshTo(char *file);
|
2009-01-14 05:10:42 +00:00
|
|
|
void ExportViewTo(char *file);
|
|
|
|
void ExportSectionTo(char *file);
|
2009-03-17 16:33:46 +00:00
|
|
|
void ExportLinesAndMesh(SEdgeList *sel, SMesh *sm,
|
|
|
|
Vector u, Vector v, Vector n, Vector origin,
|
|
|
|
double cameraTan,
|
|
|
|
VectorFileWriter *out);
|
2008-04-20 11:35:10 +00:00
|
|
|
|
2008-07-20 11:27:22 +00:00
|
|
|
static void MenuAnalyze(int id);
|
|
|
|
struct {
|
|
|
|
SContour path;
|
|
|
|
hEntity point;
|
|
|
|
} traced;
|
2009-01-25 09:19:59 +00:00
|
|
|
SEdgeList nakedEdges;
|
2008-07-20 11:27:22 +00:00
|
|
|
|
2008-06-02 09:31:26 +00:00
|
|
|
void MarkGroupDirty(hGroup hg);
|
2008-06-02 11:43:27 +00:00
|
|
|
void MarkGroupDirtyByEntity(hEntity he);
|
2008-06-02 09:31:26 +00:00
|
|
|
|
2008-06-04 10:22:30 +00:00
|
|
|
// Consistency checking on the sketch: stuff with missing dependencies
|
|
|
|
// will get deleted automatically.
|
2008-05-17 06:04:55 +00:00
|
|
|
struct {
|
|
|
|
int requests;
|
|
|
|
int groups;
|
|
|
|
int constraints;
|
2009-01-03 12:27:33 +00:00
|
|
|
int nonTrivialConstraints;
|
2008-05-17 06:04:55 +00:00
|
|
|
} deleted;
|
|
|
|
bool GroupExists(hGroup hg);
|
|
|
|
bool PruneOrphans(void);
|
|
|
|
bool EntityExists(hEntity he);
|
|
|
|
bool GroupsInOrder(hGroup before, hGroup after);
|
|
|
|
bool PruneGroups(hGroup hg);
|
|
|
|
bool PruneRequests(hGroup hg);
|
|
|
|
bool PruneConstraints(hGroup hg);
|
2008-04-27 09:03:01 +00:00
|
|
|
|
2008-06-02 09:31:26 +00:00
|
|
|
void GenerateAll(void);
|
2009-01-04 12:01:46 +00:00
|
|
|
void GenerateAll(int first, int last, bool andFindFree=false);
|
|
|
|
void SolveGroup(hGroup hg, bool andFindFree);
|
2008-04-27 09:03:01 +00:00
|
|
|
void ForceReferences(void);
|
|
|
|
|
2008-07-20 11:27:22 +00:00
|
|
|
bool AllGroupsOkay(void);
|
|
|
|
|
2008-04-20 11:35:10 +00:00
|
|
|
// The system to be solved.
|
|
|
|
System sys;
|
2008-06-03 18:28:41 +00:00
|
|
|
|
2008-06-30 09:09:17 +00:00
|
|
|
// All the TrueType fonts in memory
|
|
|
|
TtfFontList fonts;
|
|
|
|
|
2008-06-25 05:14:49 +00:00
|
|
|
// Everything has been pruned, so we know there's no dangling references
|
|
|
|
// to entities that don't exist. Before that, we mustn't try to display
|
|
|
|
// the sketch!
|
|
|
|
bool allConsistent;
|
|
|
|
|
2008-06-03 18:28:41 +00:00
|
|
|
struct {
|
|
|
|
bool showTW;
|
|
|
|
bool generateAll;
|
|
|
|
} later;
|
|
|
|
void DoLater(void);
|
2008-02-09 13:52:01 +00:00
|
|
|
|
|
|
|
// For the licensing
|
|
|
|
class Crc {
|
|
|
|
public:
|
|
|
|
static const DWORD POLY = 0xedb88320;
|
|
|
|
DWORD shiftReg;
|
|
|
|
|
|
|
|
void ProcessBit(int bit);
|
|
|
|
void ProcessByte(BYTE b);
|
|
|
|
void ProcessString(char *s);
|
|
|
|
};
|
|
|
|
Crc crc;
|
|
|
|
struct {
|
|
|
|
bool licensed;
|
|
|
|
char line1[512];
|
|
|
|
char line2[512];
|
|
|
|
char users[512];
|
|
|
|
DWORD key;
|
|
|
|
} license;
|
|
|
|
static void MenuHelp(int id);
|
|
|
|
void CleanEol(char *s);
|
|
|
|
void LoadLicenseFile(char *filename);
|
|
|
|
bool LicenseValid(char *line1, char *line2, char *users, DWORD key);
|
2008-03-28 10:00:37 +00:00
|
|
|
};
|
2008-03-25 10:02:13 +00:00
|
|
|
|
|
|
|
extern SolveSpace SS;
|
|
|
|
|
|
|
|
#endif
|