Add menu item to center view at a point; and move non-ID list data
structure from polygon.h into dsc.h, since it is used outside the polygon/mesh code. [git-p4: depot-paths = "//depot/solvespace/": change = 1892]
This commit is contained in:
parent
995e9397a8
commit
ef11978d2c
50
dsc.h
50
dsc.h
@ -89,6 +89,56 @@ public:
|
|||||||
Point2d WithMagnitude(double v);
|
Point2d WithMagnitude(double v);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// A simple list
|
||||||
|
template <class T>
|
||||||
|
class List {
|
||||||
|
public:
|
||||||
|
T *elem;
|
||||||
|
int n;
|
||||||
|
int elemsAllocated;
|
||||||
|
|
||||||
|
void Add(T *t) {
|
||||||
|
if(n >= elemsAllocated) {
|
||||||
|
elemsAllocated = (elemsAllocated + 32)*2;
|
||||||
|
elem = (T *)MemRealloc(elem, elemsAllocated*sizeof(elem[0]));
|
||||||
|
}
|
||||||
|
elem[n++] = *t;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClearTags(void) {
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < n; i++) {
|
||||||
|
elem[i].tag = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Clear(void) {
|
||||||
|
if(elem) MemFree(elem);
|
||||||
|
elem = NULL;
|
||||||
|
n = elemsAllocated = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveTagged(void) {
|
||||||
|
int src, dest;
|
||||||
|
dest = 0;
|
||||||
|
for(src = 0; src < n; src++) {
|
||||||
|
if(elem[src].tag) {
|
||||||
|
// this item should be deleted
|
||||||
|
} else {
|
||||||
|
if(src != dest) {
|
||||||
|
elem[dest] = elem[src];
|
||||||
|
}
|
||||||
|
dest++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
n = dest;
|
||||||
|
// and elemsAllocated is untouched, because we didn't resize
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// A list, where each element has an integer identifier. The list is kept
|
||||||
|
// sorted by that identifier, and items can be looked up in log n time by
|
||||||
|
// id.
|
||||||
template <class T, class H>
|
template <class T, class H>
|
||||||
class IdList {
|
class IdList {
|
||||||
public:
|
public:
|
||||||
|
@ -39,8 +39,9 @@ const GraphicsWindow::MenuEntry GraphicsWindow::menu[] = {
|
|||||||
{ 1, "Zoom &Out\t-", MNU_ZOOM_OUT, '-', mView },
|
{ 1, "Zoom &Out\t-", MNU_ZOOM_OUT, '-', mView },
|
||||||
{ 1, "Zoom To &Fit\tF", MNU_ZOOM_TO_FIT, 'F', mView },
|
{ 1, "Zoom To &Fit\tF", MNU_ZOOM_TO_FIT, 'F', mView },
|
||||||
{ 1, NULL, 0, NULL },
|
{ 1, NULL, 0, NULL },
|
||||||
{ 1, "Nearest &Ortho View\tF1", MNU_NEAREST_ORTHO, F(1), mView },
|
{ 1, "Nearest &Ortho View\tF2", MNU_NEAREST_ORTHO, F(2), mView },
|
||||||
{ 1, "Nearest &Isometric View\tF2", MNU_NEAREST_ISO, F(2), mView },
|
{ 1, "Nearest &Isometric View\tF3", MNU_NEAREST_ISO, F(3), mView },
|
||||||
|
{ 1, "&Center View At Point\tF4", MNU_CENTER_VIEW, F(4), mView },
|
||||||
{ 1, NULL, 0, NULL },
|
{ 1, NULL, 0, NULL },
|
||||||
{ 1, "Show Text &Window\tTab", MNU_SHOW_TEXT_WND, '\t', mView },
|
{ 1, "Show Text &Window\tTab", MNU_SHOW_TEXT_WND, '\t', mView },
|
||||||
{ 1, "Show &Toolbar", MNU_SHOW_TOOLBAR, 0, mView },
|
{ 1, "Show &Toolbar", MNU_SHOW_TOOLBAR, 0, mView },
|
||||||
@ -394,6 +395,21 @@ void GraphicsWindow::MenuView(int id) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case MNU_CENTER_VIEW:
|
||||||
|
SS.GW.GroupSelection();
|
||||||
|
if(SS.GW.gs.n == 1 && SS.GW.gs.points == 1) {
|
||||||
|
Quaternion quat0;
|
||||||
|
// Offset is the selected point, quaternion is same as before
|
||||||
|
Vector pt = SS.GetEntity(SS.GW.gs.point[0])->PointGetNum();
|
||||||
|
quat0 = Quaternion::From(SS.GW.projRight, SS.GW.projUp);
|
||||||
|
SS.GW.AnimateOnto(quat0, pt.ScaledBy(-1));
|
||||||
|
SS.GW.ClearSelection();
|
||||||
|
} else {
|
||||||
|
Error("Select a point; this point will become the center "
|
||||||
|
"of the view on screen.");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case MNU_SHOW_TEXT_WND:
|
case MNU_SHOW_TEXT_WND:
|
||||||
SS.GW.showTextWindow = !SS.GW.showTextWindow;
|
SS.GW.showTextWindow = !SS.GW.showTextWindow;
|
||||||
SS.GW.EnsureValidActives();
|
SS.GW.EnsureValidActives();
|
||||||
|
54
polygon.h
54
polygon.h
@ -7,52 +7,6 @@ class SContour;
|
|||||||
class SMesh;
|
class SMesh;
|
||||||
class SBsp3;
|
class SBsp3;
|
||||||
|
|
||||||
template <class T>
|
|
||||||
class SList {
|
|
||||||
public:
|
|
||||||
T *elem;
|
|
||||||
int n;
|
|
||||||
int elemsAllocated;
|
|
||||||
|
|
||||||
void Add(T *t) {
|
|
||||||
if(n >= elemsAllocated) {
|
|
||||||
elemsAllocated = (elemsAllocated + 32)*2;
|
|
||||||
elem = (T *)MemRealloc(elem, elemsAllocated*sizeof(elem[0]));
|
|
||||||
}
|
|
||||||
elem[n++] = *t;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ClearTags(void) {
|
|
||||||
int i;
|
|
||||||
for(i = 0; i < n; i++) {
|
|
||||||
elem[i].tag = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Clear(void) {
|
|
||||||
if(elem) MemFree(elem);
|
|
||||||
elem = NULL;
|
|
||||||
n = elemsAllocated = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RemoveTagged(void) {
|
|
||||||
int src, dest;
|
|
||||||
dest = 0;
|
|
||||||
for(src = 0; src < n; src++) {
|
|
||||||
if(elem[src].tag) {
|
|
||||||
// this item should be deleted
|
|
||||||
} else {
|
|
||||||
if(src != dest) {
|
|
||||||
elem[dest] = elem[src];
|
|
||||||
}
|
|
||||||
dest++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
n = dest;
|
|
||||||
// and elemsAllocated is untouched, because we didn't resize
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class SEdge {
|
class SEdge {
|
||||||
public:
|
public:
|
||||||
int tag;
|
int tag;
|
||||||
@ -63,7 +17,7 @@ public:
|
|||||||
|
|
||||||
class SEdgeList {
|
class SEdgeList {
|
||||||
public:
|
public:
|
||||||
SList<SEdge> l;
|
List<SEdge> l;
|
||||||
|
|
||||||
void Clear(void);
|
void Clear(void);
|
||||||
void AddEdge(Vector a, Vector b);
|
void AddEdge(Vector a, Vector b);
|
||||||
@ -80,7 +34,7 @@ public:
|
|||||||
|
|
||||||
class SContour {
|
class SContour {
|
||||||
public:
|
public:
|
||||||
SList<SPoint> l;
|
List<SPoint> l;
|
||||||
|
|
||||||
void AddPoint(Vector p);
|
void AddPoint(Vector p);
|
||||||
void MakeEdgesInto(SEdgeList *el);
|
void MakeEdgesInto(SEdgeList *el);
|
||||||
@ -99,7 +53,7 @@ typedef struct {
|
|||||||
|
|
||||||
class SPolygon {
|
class SPolygon {
|
||||||
public:
|
public:
|
||||||
SList<SContour> l;
|
List<SContour> l;
|
||||||
Vector normal;
|
Vector normal;
|
||||||
|
|
||||||
Vector ComputeNormal(void);
|
Vector ComputeNormal(void);
|
||||||
@ -188,7 +142,7 @@ public:
|
|||||||
|
|
||||||
class SMesh {
|
class SMesh {
|
||||||
public:
|
public:
|
||||||
SList<STriangle> l;
|
List<STriangle> l;
|
||||||
|
|
||||||
bool flipNormal;
|
bool flipNormal;
|
||||||
bool keepCoplanar;
|
bool keepCoplanar;
|
||||||
|
2
sketch.h
2
sketch.h
@ -110,7 +110,7 @@ public:
|
|||||||
struct {
|
struct {
|
||||||
int how;
|
int how;
|
||||||
int dof;
|
int dof;
|
||||||
SList<hConstraint> remove;
|
List<hConstraint> remove;
|
||||||
} solved;
|
} solved;
|
||||||
|
|
||||||
// For drawings in 2d
|
// For drawings in 2d
|
||||||
|
@ -319,7 +319,7 @@ public:
|
|||||||
class TtfFontList {
|
class TtfFontList {
|
||||||
public:
|
public:
|
||||||
bool loaded;
|
bool loaded;
|
||||||
SList<TtfFont> l;
|
List<TtfFont> l;
|
||||||
|
|
||||||
void LoadAll(void);
|
void LoadAll(void);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user