Skip to content

Commit

Permalink
Xic: Update to grip handling. Now handles all location codes. The
Browse files Browse the repository at this point in the history
locations that are not centered on a Manhattan edge are displayed as
glyph grips (others remain as lines).  45 degree rotations work now.
  • Loading branch information
wrcad committed Sep 7, 2019
1 parent 4261e99 commit 8cef6d7
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 32 deletions.
4 changes: 4 additions & 0 deletions xic/include/dsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@
// is less than this value in pixels, don't show fence (grip) marks.
#define DSP_MIN_FENCE_INST_PIXELS 100

// The grip marks that are not shown as fence lines are diamond shapes
// extending this many pixels from the center.
#define DSP_GRIP_MARK_PIXELS 4

// Default dashed line style for unfilled boxes.
#define DEF_BoxLineStyle 0xe38

Expand Down
10 changes: 7 additions & 3 deletions xic/include/grip.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,21 @@ struct sGrip : public sCniGripDesc
int end1y() const { return (g_y1); }
int end2x() const { return (g_x2); }
int end2y() const { return (g_y2); }
int ux() const { return (g_ux); }
int uy() const { return (g_uy); }
bool active() const { return (g_active); }

private:
double g_value; // Parameter value.
CDc *g_cdesc; // PCell instance pointer.
const PConstraint *g_constr;// Pointer to parameter constraint.
int g_id; // Unique id for this grip.
int g_x1; // These define the grip line segment,
int g_y1; // motion is constrained to be perpendicular
int g_x2; // to the segment.
int g_x1; // These define the grip: either a
int g_y1; // line segment or point.
int g_x2;
int g_y2;
signed char g_ux; // Unit vector of allowed motion.
signed char g_uy;
bool g_active; // Inactive when instance not expanded.
};

Expand Down
15 changes: 8 additions & 7 deletions xic/src/display/dsp_mark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4577,10 +4577,11 @@ sMark_Fence::show(WindowDesc *wdesc, bool display)
wdesc->LToP(mX, mY, x1, y1);
wdesc->LToP(mEndX, mEndY, x2, y2);
if (x1 == x2 && y1 == y2) {
show_line(wdesc, x1-3, y1, x1, y1+3);
show_line(wdesc, x1, y1+3, x1+3, y1);
show_line(wdesc, x1+3, y1, x1, y1-3);
show_line(wdesc, x1, y1-3, x1-3, y1);
const int p = DSP_GRIP_MARK_PIXELS;
show_line(wdesc, x1-p, y1, x1, y1+p);
show_line(wdesc, x1, y1+p, x1+p, y1);
show_line(wdesc, x1+p, y1, x1, y1-p);
show_line(wdesc, x1, y1-p, x1-p, y1);
}
else if (x1 == x2) {
show_line(wdesc, x1-1, y1, x1-1, y2);
Expand All @@ -4591,12 +4592,12 @@ sMark_Fence::show(WindowDesc *wdesc, bool display)
show_line(wdesc, x1, y1+1, x2, y1+1);
}
else {
// shouldn't get here
show_line(wdesc, x1, y1, x2, y2);
show_line(wdesc, x1, y1-1, x2, y2-1);
show_line(wdesc, x1, y1+1, x2, y2+1);
}
}
else {
int delta = (int)(2.0/wdesc->Ratio());
int delta = (int)(DSP_GRIP_MARK_PIXELS/wdesc->Ratio());
BBox BB(mX, mY, mEndX, mEndY);
BB.fix();
BB.bloat(delta);
Expand Down
205 changes: 183 additions & 22 deletions xic/src/edit/grip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -491,9 +491,9 @@ sCniGripDesc::parse(const char **pstr)
t += strlen("location:");
if (!strcasecmp(t, "lower_left"))
gd_loc = CN_LL;
if (!strcasecmp(t, "center_left"))
else if (!strcasecmp(t, "center_left"))
gd_loc = CN_CL; // L
if (!strcasecmp(t, "upper_left"))
else if (!strcasecmp(t, "upper_left"))
gd_loc = CN_UL;
else if (!strcasecmp(t, "lower_center"))
gd_loc = CN_LC; // B
Expand Down Expand Up @@ -610,6 +610,8 @@ sGrip::sGrip(CDc *cd)
g_y1 = 0;
g_x2 = 0;
g_y2 = 0;
g_ux = 0;
g_uy = 0;
g_active = false;
}

Expand Down Expand Up @@ -775,11 +777,63 @@ sGrip::setup(const sCniGripDesc &gd, const BBox &BB)
break;
}

if (gd_vert) {
g_ux = 0;
g_uy = 1;
}
else {
g_ux = 1;
g_uy = 0;
}

if (g_cdesc) {
// Convert to parent cell coordinates.
cTfmStack stk;
stk.TPush();
stk.TApplyTransform(g_cdesc);

int xm = (x1 + x2)/2;
int ym = (y1 + y2)/2;
int xmp = xm;
int ymp = ym;
if (gd_vert)
ymp += 10;
else
xmp += 10;
stk.TPoint(&xm, &ym);
stk.TPoint(&xmp, &ymp);
xmp -= xm;
ymp -= ym;

if (abs(ymp) <= 1) {
g_uy = 0;
if (xmp > 0)
g_ux = 1;
else
g_ux = -1;
}
else if (abs(xmp) <= 1) {
g_ux = 0;
if (ymp > 0)
g_uy = 1;
else
g_uy = -1;
}
else if (xmp > 0) {
g_ux = 1;
if (ymp > 0)
g_uy = 1;
else
g_uy = -1;
}
else {
g_ux = -1;
if (ymp > 0)
g_uy = 1;
else
g_uy = -1;
}

stk.TPoint(&x1, &y1);
stk.TPoint(&x2, &y2);
stk.TPop();
Expand Down Expand Up @@ -836,25 +890,22 @@ sGrip::param_value(int x1, int y1, int x2, int y2, double *pval) const
if (d <= 2.0)
return (false);

#if 1
Point_c p1(end1x(), end1y());
Point_c p2(end2x(), end2y());
Point_c pmid((p1.x + p2.x)/2, (p1.y + p2.y)/2);
Point_c p2m(p2.x - pmid.x, p2.y - pmid.y);
d = distance(p2m.x, p2m.y);
double ux = p2m.y/d;
double uy = -p2m.x/d;

// We don't care about x1,y1. The "up" location x2,y2 defines the
// new parameter value.
(void)x1;
(void)y1;

// We don't care about x1,y1. The "up" location x2,y2 defines
// the new parameter value.
int dx = x2 - pmid.x;
int dy = y2 - pmid.y;
double a = (ux*dx + uy*dy)/CDphysResolution;
double a = (g_ux*dx + g_uy*dy)/CDphysResolution;
if (g_ux && g_uy)
a /= M_SQRT2;

double scale = gd_scale;
double snap = gd_snap;
// Note gd_absolute is not handled, wtf does it do?
// Note gd_absolute is not handled.

double dnew = a*scale;
if (snap != 0.0)
Expand Down Expand Up @@ -883,6 +934,104 @@ sGrip::param_value(int x1, int y1, int x2, int y2, double *pval) const
if (g_constr && !g_constr->checkConstraint(dnew))
return (false);

#else
Point_c p1(end1x(), end1y());
Point_c p2(end2x(), end2y());
double dnew;
if (p1 != p2) {
Point_c pmid((p1.x + p2.x)/2, (p1.y + p2.y)/2);
Point_c p2m(p2.x - pmid.x, p2.y - pmid.y);
d = distance(p2m.x, p2m.y);
double ux = p2m.y/d;
double uy = -p2m.x/d;
// We don't care about x1,y1. The "up" location x2,y2 defines
// the new parameter value.
int dx = x2 - pmid.x;
int dy = y2 - pmid.y;
double a = (ux*dx + uy*dy)/CDphysResolution;
double scale = gd_scale;
double snap = gd_snap;
// Note gd_absolute is not handled, wtf does it do?
dnew = a*scale;
if (snap != 0.0)
dnew = snap*(int)(dnew/snap);
dnew += g_value;
double amax = (gd_maxval - g_value)/scale;
double amin = (gd_minval - g_value)/scale;
bool rv = false;
if (amax < amin) {
double t = amin;
amin = amax;
amax = t;
rv = true;
}
if (a > amax) {
a = amax;
dnew = rv ? gd_minval : gd_maxval;
}
else if (a < amin) {
a = amin;
dnew = rv ? gd_maxval : gd_minval;
}
// Check against the constraint, if any.
if (g_constr && !g_constr->checkConstraint(dnew))
return (false);
}
else {
// We don't care about x1,y1. The "up" location x2,y2 defines the
// new parameter value.
int dx = x2 - p1.x;
int dy = y2 - p1.y;
int ux = gd_vert ? 0 : 1;
int uy = gd_vert ? 1 : 0;
//XXX
/*
cTfmStack stk;
stk.TPush();
stk.TApplyTransform(g_cdesc);
stk.TPoint(&ux, &uy);
stk.TPop();
*/
double a = (ux*dx + uy*dy)/CDphysResolution;
double scale = gd_scale;
double snap = gd_snap;
dnew = a*scale;
if (snap != 0.0)
dnew = snap*(int)(dnew/snap);
dnew += g_value;
double amax = (gd_maxval - g_value)/scale;
double amin = (gd_minval - g_value)/scale;
bool rv = false;
if (amax < amin) {
double t = amin;
amin = amax;
amax = t;
rv = true;
}
if (a > amax) {
a = amax;
dnew = rv ? gd_minval : gd_maxval;
}
else if (a < amin) {
a = amin;
dnew = rv ? gd_maxval : gd_minval;
}
// Check against the constraint, if any.
if (g_constr && !g_constr->checkConstraint(dnew))
return (false);
}
#endif

if (pval)
*pval = dnew;
return (dnew != g_value);
Expand All @@ -895,18 +1044,16 @@ sGrip::show_ghost(int map_x, int map_y, bool erase)
Point_c p1(end1x(), end1y());
Point_c p2(end2x(), end2y());
Point_c pmid((p1.x + p2.x)/2, (p1.y + p2.y)/2);
Point_c p2m(p2.x - pmid.x, p2.y - pmid.y);
double d = distance(p2m.x, p2m.y);
double ux = p2m.y/d;
double uy = -p2m.x/d;

int dx = map_x - pmid.x;
int dy = map_y - pmid.y;
double a = (ux*dx + uy*dy)/CDphysResolution;
double a = (g_ux*dx + g_uy*dy)/CDphysResolution;
if (g_ux && g_uy)
a /= M_SQRT2;

double scale = gd_scale;
double snap = gd_snap;
// Note gd_absolute is not handled, wtf does it do?
// Note gd_absolute is not handled.

double dnew = a*scale;
if (snap != 0.0)
Expand Down Expand Up @@ -935,8 +1082,14 @@ sGrip::show_ghost(int map_x, int map_y, bool erase)
if (g_constr && !g_constr->checkConstraint(dnew))
return;

dx = mmRnd(a*ux*CDphysResolution);
dy = mmRnd(a*uy*CDphysResolution);
if (g_ux && g_uy) {
dx = mmRnd(a*g_ux*CDphysResolution/M_SQRT2);
dy = mmRnd(a*g_uy*CDphysResolution/M_SQRT2);
}
else {
dx = mmRnd(a*g_ux*CDphysResolution);
dy = mmRnd(a*g_uy*CDphysResolution);
}
p1.x += dx;
p1.y += dy;
p2.x += dx;
Expand All @@ -951,7 +1104,15 @@ sGrip::show_ghost(int map_x, int map_y, bool erase)
if (xlev == 0 && !g_cdesc->has_flag(wdesc->DisplFlags()))
continue;
}
wdesc->ShowLineW(p1.x, p1.y, p2.x, p2.y);
if (p1 == p2) {
int delta = (int)((DSP_GRIP_MARK_PIXELS+1)/wdesc->Ratio());
wdesc->ShowLineW(p1.x-delta, p1.y, p1.x, p1.y+delta);
wdesc->ShowLineW(p1.x, p1.y+delta, p1.x+delta, p1.y);
wdesc->ShowLineW(p1.x+delta, p1.y, p1.x, p1.y-delta);
wdesc->ShowLineW(p1.x, p1.y-delta, p1.x-delta, p1.y);
}
else
wdesc->ShowLineW(p1.x, p1.y, p2.x, p2.y);

char buf[128];
sprintf(buf, "%s %.5f", gd_param, dnew);
Expand Down

0 comments on commit 8cef6d7

Please sign in to comment.