2008-03-26 09:18:12 +00:00
|
|
|
|
|
|
|
#ifndef __SKETCH_H
|
|
|
|
#define __SKETCH_H
|
|
|
|
|
2008-04-12 16:28:48 +00:00
|
|
|
class hGroup;
|
2008-03-28 10:00:37 +00:00
|
|
|
class hRequest;
|
2008-04-12 16:28:48 +00:00
|
|
|
class hEntity;
|
2008-03-28 10:00:37 +00:00
|
|
|
class hParam;
|
2008-04-12 16:28:48 +00:00
|
|
|
class hPoint;
|
2008-03-26 09:18:12 +00:00
|
|
|
|
2008-04-09 08:39:01 +00:00
|
|
|
class Entity;
|
2008-04-12 16:28:48 +00:00
|
|
|
class Param;
|
|
|
|
class Point;
|
2008-04-09 08:39:01 +00:00
|
|
|
|
2008-04-14 10:28:32 +00:00
|
|
|
class hEquation;
|
|
|
|
class Equation;
|
|
|
|
|
2008-04-09 08:39:01 +00:00
|
|
|
// All of the hWhatever handles are a 32-bit ID, that is used to represent
|
|
|
|
// some data structure in the sketch.
|
2008-04-08 12:54:53 +00:00
|
|
|
class hGroup {
|
|
|
|
public:
|
2008-04-09 08:39:01 +00:00
|
|
|
// bits 10: 0 -- group index
|
|
|
|
DWORD v;
|
2008-04-08 12:54:53 +00:00
|
|
|
};
|
2008-03-28 10:00:37 +00:00
|
|
|
class hRequest {
|
|
|
|
public:
|
2008-04-13 10:57:41 +00:00
|
|
|
// bits 14: 0 -- request index (the high bits may be used as an import ID)
|
2008-04-09 08:39:01 +00:00
|
|
|
DWORD v;
|
2008-04-13 10:57:41 +00:00
|
|
|
|
|
|
|
inline hEntity entity(int i);
|
2008-04-09 08:39:01 +00:00
|
|
|
};
|
|
|
|
class hEntity {
|
|
|
|
public:
|
2008-04-13 10:57:41 +00:00
|
|
|
// bits 9: 0 -- entity index
|
|
|
|
// 24:10 -- request index
|
2008-04-09 08:39:01 +00:00
|
|
|
DWORD v;
|
2008-04-13 10:57:41 +00:00
|
|
|
|
|
|
|
inline hRequest request(void);
|
|
|
|
inline hParam param(int i);
|
|
|
|
inline hPoint point(int i);
|
2008-03-28 10:00:37 +00:00
|
|
|
};
|
2008-04-08 12:54:53 +00:00
|
|
|
class hParam {
|
2008-03-28 10:00:37 +00:00
|
|
|
public:
|
2008-04-13 10:57:41 +00:00
|
|
|
// bits 6: 0 -- param index
|
|
|
|
// 16: 7 -- entity index
|
|
|
|
// 31:17 -- request index
|
2008-04-09 08:39:01 +00:00
|
|
|
DWORD v;
|
2008-04-08 12:54:53 +00:00
|
|
|
};
|
|
|
|
class hPoint {
|
2008-04-13 10:57:41 +00:00
|
|
|
// bits 6: 0 -- point index
|
|
|
|
// 16: 7 -- entity index
|
|
|
|
// 31:17 -- request index
|
2008-04-08 12:54:53 +00:00
|
|
|
public:
|
2008-04-09 08:39:01 +00:00
|
|
|
DWORD v;
|
2008-04-13 10:57:41 +00:00
|
|
|
|
|
|
|
inline bool isFromReferences(void);
|
2008-04-08 12:54:53 +00:00
|
|
|
};
|
|
|
|
|
2008-04-18 07:06:37 +00:00
|
|
|
// A set of requests. Every request must have an associated group.
|
2008-04-08 12:54:53 +00:00
|
|
|
class Group {
|
|
|
|
public:
|
|
|
|
static const hGroup HGROUP_REFERENCES;
|
2008-03-26 09:18:12 +00:00
|
|
|
|
2008-04-09 08:39:01 +00:00
|
|
|
hGroup h;
|
|
|
|
|
2008-04-08 12:54:53 +00:00
|
|
|
NameStr name;
|
2008-04-12 14:12:26 +00:00
|
|
|
|
|
|
|
char *DescriptionString(void);
|
2008-03-28 10:00:37 +00:00
|
|
|
};
|
2008-03-26 09:18:12 +00:00
|
|
|
|
2008-04-08 12:54:53 +00:00
|
|
|
// A user request for some primitive or derived operation; for example a
|
|
|
|
// line, or a
|
|
|
|
class Request {
|
2008-03-28 10:00:37 +00:00
|
|
|
public:
|
2008-04-09 08:39:01 +00:00
|
|
|
// Some predefined requests, that are present in every sketch.
|
2008-04-08 12:54:53 +00:00
|
|
|
static const hRequest HREQUEST_REFERENCE_XY;
|
|
|
|
static const hRequest HREQUEST_REFERENCE_YZ;
|
|
|
|
static const hRequest HREQUEST_REFERENCE_ZX;
|
|
|
|
|
2008-04-18 07:06:37 +00:00
|
|
|
hRequest h;
|
|
|
|
|
2008-04-09 08:39:01 +00:00
|
|
|
// Types of requests
|
2008-04-14 10:28:32 +00:00
|
|
|
static const int CSYS_2D = 10;
|
|
|
|
static const int DATUM_POINT = 11;
|
|
|
|
static const int LINE_SEGMENT = 20;
|
2008-04-08 12:54:53 +00:00
|
|
|
|
2008-03-26 09:18:12 +00:00
|
|
|
int type;
|
|
|
|
|
2008-04-18 07:06:37 +00:00
|
|
|
hEntity csys; // or Entity::NO_CSYS
|
2008-04-01 10:48:44 +00:00
|
|
|
|
2008-04-08 12:54:53 +00:00
|
|
|
hGroup group;
|
|
|
|
|
|
|
|
NameStr name;
|
|
|
|
|
2008-04-09 08:39:01 +00:00
|
|
|
inline hEntity entity(int i)
|
2008-04-13 10:57:41 +00:00
|
|
|
{ hEntity r; r.v = ((this->h.v) << 10) | i; return r; }
|
2008-04-09 08:39:01 +00:00
|
|
|
|
2008-04-12 16:28:48 +00:00
|
|
|
void AddParam(IdList<Param,hParam> *param, Entity *e, int index);
|
|
|
|
void Generate(IdList<Entity,hEntity> *entity,
|
|
|
|
IdList<Point,hPoint> *point,
|
|
|
|
IdList<Param,hParam> *param);
|
2008-04-12 14:12:26 +00:00
|
|
|
|
|
|
|
char *DescriptionString(void);
|
2008-03-28 10:00:37 +00:00
|
|
|
};
|
2008-03-26 09:18:12 +00:00
|
|
|
|
2008-04-09 08:39:01 +00:00
|
|
|
class Entity {
|
2008-03-28 10:00:37 +00:00
|
|
|
public:
|
2008-04-09 08:39:01 +00:00
|
|
|
static const hEntity NO_CSYS;
|
2008-04-08 12:54:53 +00:00
|
|
|
|
2008-04-13 10:57:41 +00:00
|
|
|
static const int CSYS_2D = 1000;
|
|
|
|
static const int DATUM_POINT = 1001;
|
|
|
|
static const int LINE_SEGMENT = 1010;
|
2008-04-09 08:39:01 +00:00
|
|
|
int type;
|
|
|
|
|
|
|
|
hEntity h;
|
|
|
|
|
|
|
|
Expr *expr[16];
|
|
|
|
|
2008-04-11 11:13:47 +00:00
|
|
|
inline hRequest request(void)
|
2008-04-13 10:57:41 +00:00
|
|
|
{ hRequest r; r.v = (this->h.v >> 10); return r; }
|
2008-04-09 08:39:01 +00:00
|
|
|
inline hParam param(int i)
|
2008-04-13 10:57:41 +00:00
|
|
|
{ hParam r; r.v = ((this->h.v) << 7) | i; return r; }
|
2008-04-09 08:39:01 +00:00
|
|
|
inline hPoint point(int i)
|
2008-04-13 10:57:41 +00:00
|
|
|
{ hPoint r; r.v = ((this->h.v) << 7) | i; return r; }
|
2008-04-09 08:39:01 +00:00
|
|
|
|
2008-04-18 07:06:37 +00:00
|
|
|
char *DescriptionString(void);
|
|
|
|
|
2008-04-13 14:28:35 +00:00
|
|
|
void Get2dCsysBasisVectors(Vector *u, Vector *v);
|
|
|
|
|
2008-04-12 14:12:26 +00:00
|
|
|
struct {
|
|
|
|
bool drawing;
|
|
|
|
Point2d mp;
|
|
|
|
double dmin;
|
|
|
|
} dogd; // state for drawing or getting distance (for hit testing)
|
|
|
|
void LineDrawOrGetDistance(Vector a, Vector b);
|
|
|
|
void DrawOrGetDistance(void);
|
2008-04-09 08:39:01 +00:00
|
|
|
void Draw(void);
|
2008-04-12 14:12:26 +00:00
|
|
|
double GetDistance(Point2d mp);
|
2008-03-28 10:00:37 +00:00
|
|
|
};
|
2008-03-26 09:18:12 +00:00
|
|
|
|
2008-04-09 08:39:01 +00:00
|
|
|
class Param {
|
2008-03-28 10:00:37 +00:00
|
|
|
public:
|
2008-04-09 08:39:01 +00:00
|
|
|
hParam h;
|
|
|
|
double val;
|
|
|
|
bool known;
|
2008-04-08 12:54:53 +00:00
|
|
|
|
2008-04-09 08:39:01 +00:00
|
|
|
void ForceTo(double v);
|
2008-03-28 10:00:37 +00:00
|
|
|
};
|
2008-03-26 09:18:12 +00:00
|
|
|
|
2008-04-09 08:39:01 +00:00
|
|
|
class Point {
|
2008-03-28 10:00:37 +00:00
|
|
|
public:
|
2008-04-09 08:39:01 +00:00
|
|
|
// The point ID is equal to the initial param ID.
|
|
|
|
hPoint h;
|
2008-03-26 09:18:12 +00:00
|
|
|
|
2008-04-09 08:39:01 +00:00
|
|
|
int type;
|
|
|
|
static const int IN_FREE_SPACE = 0; // three params, x y z
|
|
|
|
static const int IN_2D_CSYS = 1; // two params, u v, plus csys
|
|
|
|
static const int BY_EXPR = 2; // three Expr *, could be anything
|
2008-04-08 12:54:53 +00:00
|
|
|
|
|
|
|
hEntity csys;
|
|
|
|
|
2008-04-09 08:39:01 +00:00
|
|
|
inline hEntity entity(void)
|
2008-04-13 10:57:41 +00:00
|
|
|
{ hEntity r; r.v = (h.v >> 7); return r; }
|
2008-04-09 08:39:01 +00:00
|
|
|
inline hParam param(int i)
|
|
|
|
{ hParam r; r.v = h.v + i; return r; }
|
2008-03-26 09:18:12 +00:00
|
|
|
|
2008-04-09 08:39:01 +00:00
|
|
|
// The point, in base coordinates. This may be a single parameter, or
|
|
|
|
// it may be a more complex expression if our point is locked in a
|
|
|
|
// 2d csys.
|
2008-04-12 14:12:26 +00:00
|
|
|
void GetExprs(Expr **x, Expr **y, Expr **z);
|
|
|
|
Vector GetCoords(void);
|
2008-03-26 09:18:12 +00:00
|
|
|
|
2008-04-09 08:39:01 +00:00
|
|
|
void ForceTo(Vector v);
|
2008-04-12 14:12:26 +00:00
|
|
|
|
|
|
|
void Draw(void);
|
|
|
|
double GetDistance(Point2d mp);
|
2008-04-09 08:39:01 +00:00
|
|
|
};
|
2008-04-08 12:54:53 +00:00
|
|
|
|
2008-04-14 10:28:32 +00:00
|
|
|
class hConstraint {
|
|
|
|
public:
|
|
|
|
DWORD v;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Constraint {
|
|
|
|
public:
|
|
|
|
static const int USER_EQUATION = 10;
|
|
|
|
static const int POINTS_COINCIDENT = 20;
|
|
|
|
static const int PT_PT_DISTANCE = 30;
|
|
|
|
static const int PT_LINE_DISTANCE = 31;
|
|
|
|
|
|
|
|
static const int HORIZONTAL = 40;
|
|
|
|
static const int VERTICAL = 41;
|
|
|
|
|
|
|
|
hConstraint h;
|
|
|
|
int type;
|
|
|
|
hGroup group;
|
|
|
|
|
|
|
|
// These are the parameters for the constraint.
|
|
|
|
Expr *exprA;
|
|
|
|
Expr *exprB;
|
|
|
|
hPoint ptA;
|
|
|
|
hPoint ptB;
|
|
|
|
hPoint ptC;
|
|
|
|
hEntity entityA;
|
|
|
|
hEntity entityB;
|
|
|
|
|
|
|
|
// These define how the constraint is drawn on-screen.
|
|
|
|
struct {
|
|
|
|
hEntity csys;
|
|
|
|
Vector offset;
|
|
|
|
Vector u, v;
|
|
|
|
} disp;
|
|
|
|
|
|
|
|
static hConstraint AddConstraint(Constraint *c);
|
|
|
|
static void MenuConstrain(int id);
|
|
|
|
|
|
|
|
struct {
|
|
|
|
bool drawing;
|
|
|
|
Point2d mp;
|
|
|
|
double dmin;
|
|
|
|
} dogd; // state for drawing or getting distance (for hit testing)
|
|
|
|
double GetDistance(Point2d mp);
|
|
|
|
void Draw(void);
|
|
|
|
void DrawOrGetDistance(void);
|
|
|
|
|
|
|
|
bool HasLabel(void);
|
|
|
|
|
|
|
|
void Generate(IdList<Equation,hEquation> *l);
|
|
|
|
};
|
|
|
|
|
|
|
|
class hEquation {
|
|
|
|
public:
|
|
|
|
DWORD v;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Equation {
|
|
|
|
public:
|
|
|
|
hEquation h;
|
|
|
|
Expr *e;
|
|
|
|
};
|
|
|
|
|
2008-04-13 10:57:41 +00:00
|
|
|
|
|
|
|
inline hEntity hRequest::entity(int i)
|
|
|
|
{ hEntity r; r.v = (v << 10) | i; return r; }
|
|
|
|
|
|
|
|
inline hRequest hEntity::request(void)
|
|
|
|
{ hRequest r; r.v = (v >> 10); return r; }
|
|
|
|
inline hParam hEntity::param(int i)
|
|
|
|
{ hParam r; r.v = (v << 7) | i; return r; }
|
|
|
|
inline hPoint hEntity::point(int i)
|
|
|
|
{ hPoint r; r.v = (v << 7) | i; return r; }
|
|
|
|
|
|
|
|
inline bool hPoint::isFromReferences(void) {
|
|
|
|
DWORD d = v >> 17;
|
|
|
|
if(d == Request::HREQUEST_REFERENCE_XY.v) return true;
|
|
|
|
if(d == Request::HREQUEST_REFERENCE_YZ.v) return true;
|
|
|
|
if(d == Request::HREQUEST_REFERENCE_ZX.v) return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-04-08 12:54:53 +00:00
|
|
|
#endif
|