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-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;
|
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-19 11:09:47 +00:00
|
|
|
// bits 15: 0 -- group index
|
2008-04-09 08:39:01 +00:00
|
|
|
DWORD v;
|
2008-04-08 12:54:53 +00:00
|
|
|
};
|
2008-03-28 10:00:37 +00:00
|
|
|
class hRequest {
|
|
|
|
public:
|
2008-04-19 11:09:47 +00:00
|
|
|
// bits 15: 0 -- request index
|
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-19 11:09:47 +00:00
|
|
|
inline hParam param(int i);
|
2008-04-21 08:16:38 +00:00
|
|
|
|
|
|
|
inline bool IsFromReferences(void);
|
2008-04-09 08:39:01 +00:00
|
|
|
};
|
|
|
|
class hEntity {
|
|
|
|
public:
|
2008-04-19 11:09:47 +00:00
|
|
|
// bits 15: 0 -- entity index
|
|
|
|
// 31:16 -- request index
|
2008-04-09 08:39:01 +00:00
|
|
|
DWORD v;
|
2008-04-13 10:57:41 +00:00
|
|
|
|
|
|
|
inline hRequest request(void);
|
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-19 11:09:47 +00:00
|
|
|
// bits 15: 0 -- param index
|
|
|
|
// 31:16 -- request index
|
2008-04-09 08:39:01 +00:00
|
|
|
DWORD v;
|
2008-04-13 10:57:41 +00:00
|
|
|
|
2008-04-19 11:09:47 +00:00
|
|
|
inline hRequest request(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-18 07:21:17 +00:00
|
|
|
int tag;
|
2008-04-09 08:39:01 +00:00
|
|
|
hGroup h;
|
|
|
|
|
2008-04-20 11:35:10 +00:00
|
|
|
int solveOrder;
|
|
|
|
bool solved;
|
|
|
|
|
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-20 11:35:10 +00:00
|
|
|
|
|
|
|
class EntityId {
|
|
|
|
DWORD v; // entity ID, starting from 0
|
|
|
|
};
|
|
|
|
class EntityMap {
|
|
|
|
int tag;
|
|
|
|
|
|
|
|
EntityId h;
|
|
|
|
hEntity input;
|
|
|
|
int copyNumber;
|
|
|
|
// (input, copyNumber) gets mapped to ((Request)xxx).entity(h.v)
|
|
|
|
};
|
|
|
|
|
2008-04-08 12:54:53 +00:00
|
|
|
// A user request for some primitive or derived operation; for example a
|
2008-04-20 11:35:10 +00:00
|
|
|
// line, or a step and repeat.
|
2008-04-08 12:54:53 +00:00
|
|
|
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:21:17 +00:00
|
|
|
int tag;
|
2008-04-18 07:06:37 +00:00
|
|
|
hRequest h;
|
|
|
|
|
2008-04-09 08:39:01 +00:00
|
|
|
// Types of requests
|
2008-04-18 11:11:48 +00:00
|
|
|
static const int CSYS_2D = 100;
|
|
|
|
static const int DATUM_POINT = 101;
|
|
|
|
static const int LINE_SEGMENT = 200;
|
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-08 12:54:53 +00:00
|
|
|
hGroup group;
|
|
|
|
NameStr name;
|
2008-04-22 13:14:15 +00:00
|
|
|
bool construction;
|
2008-04-08 12:54:53 +00:00
|
|
|
|
2008-04-20 11:35:10 +00:00
|
|
|
// When a request generates entities from entities, and the source
|
|
|
|
// entities may have come from multiple requests, it's necessary to
|
|
|
|
// remap the entity ID so that it's still unique. We do this with a
|
|
|
|
// mapping list.
|
|
|
|
IdList<EntityId,EntityMap> remap;
|
|
|
|
hEntity Remap(hEntity in, int copyNumber);
|
|
|
|
|
2008-04-19 11:09:47 +00:00
|
|
|
hParam AddParam(IdList<Param,hParam> *param, hParam hp);
|
|
|
|
void Generate(IdList<Entity,hEntity> *entity, 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-18 11:11:48 +00:00
|
|
|
int tag;
|
|
|
|
hEntity h;
|
|
|
|
|
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;
|
2008-04-19 11:09:47 +00:00
|
|
|
static const int POINT_IN_3D = 2000;
|
|
|
|
static const int POINT_IN_2D = 2001;
|
|
|
|
static const int LINE_SEGMENT = 3000;
|
2008-04-09 08:39:01 +00:00
|
|
|
int type;
|
|
|
|
|
2008-04-19 11:09:47 +00:00
|
|
|
bool symbolic;
|
|
|
|
// The params are usually handles to the symbolic variables, but may
|
|
|
|
// also be constants
|
|
|
|
union {
|
|
|
|
hParam h[16];
|
|
|
|
double v[16];
|
|
|
|
} param;
|
|
|
|
// Associated entities, e.g. the endpoints for a line segment
|
|
|
|
hEntity assoc[16];
|
2008-04-09 08:39:01 +00:00
|
|
|
|
2008-04-19 11:09:47 +00:00
|
|
|
hEntity csys; // or Entity::NO_CSYS
|
2008-04-18 07:06:37 +00:00
|
|
|
|
2008-04-19 11:09:47 +00:00
|
|
|
// Applies only for a CSYS_2D type
|
2008-04-19 11:44:44 +00:00
|
|
|
void Csys2dGetBasisVectors(Vector *u, Vector *v);
|
2008-04-22 13:14:15 +00:00
|
|
|
void Csys2dGetBasisExprs(ExprVector *u, ExprVector *v);
|
2008-04-13 14:28:35 +00:00
|
|
|
|
2008-04-19 11:09:47 +00:00
|
|
|
bool IsPoint(void);
|
2008-04-22 13:14:15 +00:00
|
|
|
bool IsPointIn3d(void);
|
2008-04-19 11:09:47 +00:00
|
|
|
// Applies for any of the point types
|
2008-04-19 11:44:44 +00:00
|
|
|
Vector PointGetCoords(void);
|
2008-04-22 13:14:15 +00:00
|
|
|
ExprVector PointGetExprs(void);
|
2008-04-19 11:44:44 +00:00
|
|
|
void PointForceTo(Vector v);
|
|
|
|
bool PointIsFromReferences(void);
|
2008-04-21 08:16:38 +00:00
|
|
|
bool PointIsKnown(void);
|
|
|
|
|
|
|
|
// Applies for anything that comes with a plane
|
|
|
|
bool HasPlane(void);
|
|
|
|
// The plane is points P such that P dot (xn, yn, zn) - d = 0
|
2008-04-22 13:14:15 +00:00
|
|
|
void PlaneGetExprs(ExprVector *n, Expr **d);
|
2008-04-19 11:09:47 +00:00
|
|
|
|
|
|
|
// Routines to draw and hit-test the representation of the entity
|
|
|
|
// on-screen.
|
2008-04-12 14:12:26 +00:00
|
|
|
struct {
|
|
|
|
bool drawing;
|
|
|
|
Point2d mp;
|
|
|
|
double dmin;
|
2008-04-19 11:09:47 +00:00
|
|
|
} dogd;
|
2008-04-12 14:12:26 +00:00
|
|
|
void LineDrawOrGetDistance(Vector a, Vector b);
|
2008-04-22 10:53:42 +00:00
|
|
|
void DrawOrGetDistance(int order);
|
|
|
|
void Draw(int order);
|
2008-04-12 14:12:26 +00:00
|
|
|
double GetDistance(Point2d mp);
|
2008-04-19 11:09:47 +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 Param {
|
2008-03-28 10:00:37 +00:00
|
|
|
public:
|
2008-04-18 07:21:17 +00:00
|
|
|
int tag;
|
2008-04-09 08:39:01 +00:00
|
|
|
hParam h;
|
2008-04-18 07:21:17 +00:00
|
|
|
|
2008-04-09 08:39:01 +00:00
|
|
|
double val;
|
|
|
|
bool known;
|
2008-03-28 10:00:37 +00:00
|
|
|
};
|
2008-03-26 09:18:12 +00:00
|
|
|
|
2008-04-08 12:54:53 +00:00
|
|
|
|
2008-04-21 08:16:38 +00:00
|
|
|
inline bool hRequest::IsFromReferences(void) {
|
|
|
|
if(v == Request::HREQUEST_REFERENCE_XY.v) return true;
|
|
|
|
if(v == Request::HREQUEST_REFERENCE_YZ.v) return true;
|
|
|
|
if(v == Request::HREQUEST_REFERENCE_ZX.v) return true;
|
|
|
|
return false;
|
|
|
|
}
|
2008-04-18 07:21:17 +00:00
|
|
|
inline hEntity hRequest::entity(int i)
|
2008-04-19 11:09:47 +00:00
|
|
|
{ hEntity r; r.v = (v << 16) | i; return r; }
|
|
|
|
inline hParam hRequest::param(int i)
|
|
|
|
{ hParam r; r.v = (v << 16) | i; return r; }
|
2008-04-18 07:21:17 +00:00
|
|
|
|
|
|
|
inline hRequest hEntity::request(void)
|
2008-04-19 11:09:47 +00:00
|
|
|
{ hRequest r; r.v = (v >> 16); return r; }
|
2008-04-18 07:21:17 +00:00
|
|
|
|
2008-04-19 11:09:47 +00:00
|
|
|
inline hRequest hParam::request(void)
|
|
|
|
{ hRequest r; r.v = (v >> 16); return r; }
|
2008-04-18 07:21:17 +00:00
|
|
|
|
|
|
|
|
2008-04-14 10:28:32 +00:00
|
|
|
class hConstraint {
|
|
|
|
public:
|
|
|
|
DWORD v;
|
2008-04-20 11:35:10 +00:00
|
|
|
|
|
|
|
hEquation equation(int i);
|
2008-04-14 10:28:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
2008-04-21 08:16:38 +00:00
|
|
|
static const int PT_IN_PLANE = 40;
|
2008-04-22 05:00:49 +00:00
|
|
|
static const int EQUAL_LENGTH_LINES = 50;
|
2008-04-14 10:28:32 +00:00
|
|
|
|
2008-04-22 05:00:49 +00:00
|
|
|
static const int HORIZONTAL = 80;
|
|
|
|
static const int VERTICAL = 81;
|
2008-04-14 10:28:32 +00:00
|
|
|
|
2008-04-18 07:21:17 +00:00
|
|
|
int tag;
|
2008-04-14 10:28:32 +00:00
|
|
|
hConstraint h;
|
2008-04-18 07:21:17 +00:00
|
|
|
|
2008-04-14 10:28:32 +00:00
|
|
|
int type;
|
|
|
|
hGroup group;
|
|
|
|
|
|
|
|
// These are the parameters for the constraint.
|
|
|
|
Expr *exprA;
|
|
|
|
Expr *exprB;
|
2008-04-19 11:09:47 +00:00
|
|
|
hEntity ptA;
|
|
|
|
hEntity ptB;
|
|
|
|
hEntity ptC;
|
2008-04-14 10:28:32 +00:00
|
|
|
hEntity entityA;
|
|
|
|
hEntity entityB;
|
|
|
|
|
|
|
|
// These define how the constraint is drawn on-screen.
|
|
|
|
struct {
|
|
|
|
Vector offset;
|
|
|
|
} 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)
|
2008-04-21 08:16:38 +00:00
|
|
|
void LineDrawOrGetDistance(Vector a, Vector b);
|
2008-04-21 10:12:04 +00:00
|
|
|
void DrawOrGetDistance(Vector *labelPos);
|
|
|
|
|
2008-04-14 10:28:32 +00:00
|
|
|
double GetDistance(Point2d mp);
|
2008-04-21 10:12:04 +00:00
|
|
|
Vector GetLabelPos(void);
|
2008-04-14 10:28:32 +00:00
|
|
|
void Draw(void);
|
|
|
|
|
|
|
|
bool HasLabel(void);
|
|
|
|
|
|
|
|
void Generate(IdList<Equation,hEquation> *l);
|
2008-04-20 11:35:10 +00:00
|
|
|
// Some helpers when generating symbolic constraint equations
|
2008-04-22 10:53:42 +00:00
|
|
|
void ModifyToSatisfy(void);
|
2008-04-20 11:35:10 +00:00
|
|
|
void AddEq(IdList<Equation,hEquation> *l, Expr *expr, int index);
|
|
|
|
static Expr *Distance(hEntity pa, hEntity pb);
|
2008-04-14 10:28:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class hEquation {
|
|
|
|
public:
|
|
|
|
DWORD v;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Equation {
|
|
|
|
public:
|
2008-04-18 07:21:17 +00:00
|
|
|
int tag;
|
2008-04-14 10:28:32 +00:00
|
|
|
hEquation h;
|
2008-04-18 07:21:17 +00:00
|
|
|
|
2008-04-14 10:28:32 +00:00
|
|
|
Expr *e;
|
|
|
|
};
|
|
|
|
|
2008-04-20 11:35:10 +00:00
|
|
|
inline hEquation hConstraint::equation(int i)
|
|
|
|
{ hEquation r; r.v = (v << 16) | i; return r; }
|
|
|
|
|
2008-04-13 10:57:41 +00:00
|
|
|
|
2008-04-08 12:54:53 +00:00
|
|
|
#endif
|