2008-04-01 10:48:44 +00:00
|
|
|
#include "solvespace.h"
|
|
|
|
|
2008-04-18 07:06:37 +00:00
|
|
|
char *Entity::DescriptionString(void) {
|
|
|
|
Request *r = SS.GetRequest(request());
|
|
|
|
return r->DescriptionString();
|
|
|
|
}
|
|
|
|
|
2008-04-13 14:28:35 +00:00
|
|
|
void Entity::Get2dCsysBasisVectors(Vector *u, Vector *v) {
|
|
|
|
double q[4];
|
|
|
|
for(int i = 0; i < 4; i++) {
|
|
|
|
q[i] = SS.param.FindById(param(i))->val;
|
|
|
|
}
|
2008-04-18 11:11:48 +00:00
|
|
|
Quaternion quat = Quaternion::MakeFrom(q[0], q[1], q[2], q[3]);
|
2008-04-13 14:28:35 +00:00
|
|
|
|
2008-04-18 11:11:48 +00:00
|
|
|
*u = quat.RotationU();
|
|
|
|
*v = quat.RotationV();
|
2008-04-13 14:28:35 +00:00
|
|
|
}
|
|
|
|
|
2008-04-12 14:12:26 +00:00
|
|
|
void Entity::LineDrawOrGetDistance(Vector a, Vector b) {
|
|
|
|
if(dogd.drawing) {
|
|
|
|
glBegin(GL_LINE_STRIP);
|
|
|
|
glxVertex3v(a);
|
|
|
|
glxVertex3v(b);
|
|
|
|
glEnd();
|
|
|
|
} else {
|
|
|
|
Point2d ap = SS.GW.ProjectPoint(a);
|
|
|
|
Point2d bp = SS.GW.ProjectPoint(b);
|
|
|
|
|
|
|
|
double d = dogd.mp.DistanceToLine(ap, bp.Minus(ap), true);
|
|
|
|
dogd.dmin = min(dogd.dmin, d);
|
|
|
|
}
|
2008-04-11 11:13:47 +00:00
|
|
|
}
|
|
|
|
|
2008-04-01 10:48:44 +00:00
|
|
|
void Entity::Draw(void) {
|
2008-04-12 14:12:26 +00:00
|
|
|
dogd.drawing = true;
|
|
|
|
DrawOrGetDistance();
|
|
|
|
}
|
|
|
|
|
|
|
|
double Entity::GetDistance(Point2d mp) {
|
|
|
|
dogd.drawing = false;
|
|
|
|
dogd.mp = mp;
|
|
|
|
dogd.dmin = 1e12;
|
|
|
|
|
|
|
|
DrawOrGetDistance();
|
|
|
|
|
|
|
|
return dogd.dmin;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Entity::DrawOrGetDistance(void) {
|
2008-04-09 08:39:01 +00:00
|
|
|
switch(type) {
|
|
|
|
case CSYS_2D: {
|
|
|
|
Vector p;
|
2008-04-12 14:12:26 +00:00
|
|
|
p = SS.point.FindById(point(16))->GetCoords();
|
2008-04-01 10:48:44 +00:00
|
|
|
|
2008-04-13 14:28:35 +00:00
|
|
|
Vector u, v;
|
|
|
|
Get2dCsysBasisVectors(&u, &v);
|
2008-04-01 10:48:44 +00:00
|
|
|
|
2008-04-13 10:57:41 +00:00
|
|
|
double s = (min(SS.GW.width, SS.GW.height))*0.4/SS.GW.scale;
|
2008-04-01 10:48:44 +00:00
|
|
|
|
2008-04-13 10:57:41 +00:00
|
|
|
Vector us = u.ScaledBy(s);
|
|
|
|
Vector vs = v.ScaledBy(s);
|
|
|
|
|
|
|
|
Vector pp = p.Plus (us).Plus (vs);
|
|
|
|
Vector pm = p.Plus (us).Minus(vs);
|
|
|
|
Vector mm = p.Minus(us).Minus(vs);
|
|
|
|
Vector mp = p.Minus(us).Plus (vs);
|
2008-04-11 11:13:47 +00:00
|
|
|
|
2008-04-12 14:12:26 +00:00
|
|
|
LineDrawOrGetDistance(pp, pm);
|
|
|
|
LineDrawOrGetDistance(pm, mm);
|
|
|
|
LineDrawOrGetDistance(mm, mp);
|
|
|
|
LineDrawOrGetDistance(mp, pp);
|
2008-04-01 10:48:44 +00:00
|
|
|
|
2008-04-12 14:12:26 +00:00
|
|
|
if(dogd.drawing) {
|
|
|
|
Request *r = SS.request.FindById(this->request());
|
|
|
|
glPushMatrix();
|
|
|
|
glxTranslatev(mm);
|
|
|
|
glxOntoCsys(u, v);
|
|
|
|
glxWriteText(r->DescriptionString());
|
|
|
|
glPopMatrix();
|
|
|
|
}
|
2008-04-09 08:39:01 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-04-13 10:57:41 +00:00
|
|
|
case DATUM_POINT:
|
|
|
|
// All display is handled by the generated point.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LINE_SEGMENT: {
|
|
|
|
Vector a = SS.point.FindById(point(16))->GetCoords();
|
|
|
|
Vector b = SS.point.FindById(point(16+3))->GetCoords();
|
|
|
|
LineDrawOrGetDistance(a, b);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-04-09 08:39:01 +00:00
|
|
|
default:
|
|
|
|
oops();
|
2008-04-01 10:48:44 +00:00
|
|
|
}
|
|
|
|
}
|
2008-04-12 15:17:58 +00:00
|
|
|
|