From ef11978d2c22a9849e065943be01b1f5a72e0333 Mon Sep 17 00:00:00 2001 From: Jonathan Westhues Date: Mon, 12 Jan 2009 22:56:05 -0800 Subject: [PATCH] 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] --- dsc.h | 50 +++++++++++++++++++++++++++++++++++++++++++++ graphicswin.cpp | 20 ++++++++++++++++-- polygon.h | 54 ++++--------------------------------------------- sketch.h | 2 +- solvespace.h | 2 +- ui.h | 1 + 6 files changed, 75 insertions(+), 54 deletions(-) diff --git a/dsc.h b/dsc.h index 92a2179..0c80980 100644 --- a/dsc.h +++ b/dsc.h @@ -89,6 +89,56 @@ public: Point2d WithMagnitude(double v); }; +// A simple list +template +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 IdList { public: diff --git a/graphicswin.cpp b/graphicswin.cpp index e694997..30bcd85 100644 --- a/graphicswin.cpp +++ b/graphicswin.cpp @@ -39,8 +39,9 @@ const GraphicsWindow::MenuEntry GraphicsWindow::menu[] = { { 1, "Zoom &Out\t-", MNU_ZOOM_OUT, '-', mView }, { 1, "Zoom To &Fit\tF", MNU_ZOOM_TO_FIT, 'F', mView }, { 1, NULL, 0, NULL }, -{ 1, "Nearest &Ortho View\tF1", MNU_NEAREST_ORTHO, F(1), mView }, -{ 1, "Nearest &Isometric View\tF2", MNU_NEAREST_ISO, F(2), mView }, +{ 1, "Nearest &Ortho View\tF2", MNU_NEAREST_ORTHO, 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, "Show Text &Window\tTab", MNU_SHOW_TEXT_WND, '\t', mView }, { 1, "Show &Toolbar", MNU_SHOW_TOOLBAR, 0, mView }, @@ -394,6 +395,21 @@ void GraphicsWindow::MenuView(int id) { 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: SS.GW.showTextWindow = !SS.GW.showTextWindow; SS.GW.EnsureValidActives(); diff --git a/polygon.h b/polygon.h index dfba724..cfbd5ac 100644 --- a/polygon.h +++ b/polygon.h @@ -7,52 +7,6 @@ class SContour; class SMesh; class SBsp3; -template -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 { public: int tag; @@ -63,7 +17,7 @@ public: class SEdgeList { public: - SList l; + List l; void Clear(void); void AddEdge(Vector a, Vector b); @@ -80,7 +34,7 @@ public: class SContour { public: - SList l; + List l; void AddPoint(Vector p); void MakeEdgesInto(SEdgeList *el); @@ -99,7 +53,7 @@ typedef struct { class SPolygon { public: - SList l; + List l; Vector normal; Vector ComputeNormal(void); @@ -188,7 +142,7 @@ public: class SMesh { public: - SList l; + List l; bool flipNormal; bool keepCoplanar; diff --git a/sketch.h b/sketch.h index 622f2d8..1597e85 100644 --- a/sketch.h +++ b/sketch.h @@ -110,7 +110,7 @@ public: struct { int how; int dof; - SList remove; + List remove; } solved; // For drawings in 2d diff --git a/solvespace.h b/solvespace.h index a38864b..a808d4c 100644 --- a/solvespace.h +++ b/solvespace.h @@ -319,7 +319,7 @@ public: class TtfFontList { public: bool loaded; - SList l; + List l; void LoadAll(void); diff --git a/ui.h b/ui.h index 9bda2e1..f49562f 100644 --- a/ui.h +++ b/ui.h @@ -186,6 +186,7 @@ public: MNU_ZOOM_TO_FIT, MNU_NEAREST_ORTHO, MNU_NEAREST_ISO, + MNU_CENTER_VIEW, MNU_SHOW_TEXT_WND, MNU_SHOW_TOOLBAR, MNU_UNITS_INCHES,