diff --git a/Fltk/FlGui.cpp b/Fltk/FlGui.cpp index a5a7cf804eb4f1421cd898d9fdcb08e78026a604..5f2b0d61947c0a4d3523029fff2ba9a6b921433b 100644 --- a/Fltk/FlGui.cpp +++ b/Fltk/FlGui.cpp @@ -891,7 +891,7 @@ char FlGui::selectEntity(int type) { return getCurrentOpenglWindow()->selectEntity (type, selectedVertices, selectedEdges, selectedFaces, selectedRegions, - selectedElements); + selectedElements, selectedPoints); } void FlGui::setStatus(const std::string &msg, bool opengl) diff --git a/Fltk/FlGui.h b/Fltk/FlGui.h index 265602ecc0c04d9ca01697c1e202da88d7ddd159..71a14ad480d03750792174a634f185a5be6b2b2d 100644 --- a/Fltk/FlGui.h +++ b/Fltk/FlGui.h @@ -8,6 +8,7 @@ #include <string> #include <vector> +#include "SPoint2.h" #define GMSH_WINDOW_BOX FL_FLAT_BOX #define GMSH_SIMPLE_RIGHT_BOX (Fl_Boxtype)(FL_FREE_BOXTYPE+1) @@ -51,6 +52,7 @@ class FlGui{ std::vector<GFace*> selectedFaces; std::vector<GRegion*> selectedRegions; std::vector<MElement*> selectedElements; + std::vector<SPoint2> selectedPoints; public: std::vector<graphicWindow*> graph; optionWindow *options; diff --git a/Fltk/openglWindow.cpp b/Fltk/openglWindow.cpp index 6a83afb6aad3dfabf974887f1f240fb67e2fa4b4..90ee2139e9843d4e15ea7653dbf27e487f702d09 100644 --- a/Fltk/openglWindow.cpp +++ b/Fltk/openglWindow.cpp @@ -609,9 +609,10 @@ int openglWindow::handle(int event) std::vector<GFace*> faces; std::vector<GRegion*> regions; std::vector<MElement*> elements; + std::vector<SPoint2> points; bool res = _select(_selection, false, CTX::instance()->mouseHoverMeshes, (int)_curr.win[0], (int)_curr.win[1], 5, 5, - vertices, edges, faces, regions, elements); + vertices, edges, faces, regions, elements, points); if((_selection == ENT_ALL && res) || (_selection == ENT_POINT && vertices.size()) || (_selection == ENT_LINE && edges.size()) || @@ -629,6 +630,11 @@ int openglWindow::handle(int event) std::string text; if(ge) text += ge->getInfoString(); if(me) text += me->getInfoString(); + if(points.size()){ + char tmp[256]; + sprintf(tmp, "(%g,%g)", points[0].x(), points[0].y()); + text += tmp; + } if(CTX::instance()->tooltips) drawTooltip(text); else @@ -649,7 +655,8 @@ bool openglWindow::_select(int type, bool multiple, bool mesh, std::vector<GEdge*> &edges, std::vector<GFace*> &faces, std::vector<GRegion*> ®ions, - std::vector<MElement*> &elements) + std::vector<MElement*> &elements, + std::vector<SPoint2> &points) { // same lock as in draw() to prevent firing up a GL_SELECT rendering pass // while a GL_RENDER pass is happening (due to the asynchronus nature of @@ -658,7 +665,8 @@ bool openglWindow::_select(int type, bool multiple, bool mesh, _lock = true; make_current(); bool ret = _ctx->select(type, multiple, mesh, x, y, w, h, - vertices, edges, faces, regions, elements); + vertices, edges, faces, regions, elements, + points); _lock = false; return ret; } @@ -668,7 +676,8 @@ char openglWindow::selectEntity(int type, std::vector<GEdge*> &edges, std::vector<GFace*> &faces, std::vector<GRegion*> ®ions, - std::vector<MElement*> &elements) + std::vector<MElement*> &elements, + std::vector<SPoint2> &points) { // force keyboard focus in GL window take_focus(); @@ -719,7 +728,7 @@ char openglWindow::selectEntity(int type, else if(_select(_selection, multi, true, _trySelectionXYWH[0], _trySelectionXYWH[1], _trySelectionXYWH[2], _trySelectionXYWH[3], vertices, edges, faces, - regions, elements)){ + regions, elements, points)){ _selection = ENT_NONE; selectionMode = false; if(add) diff --git a/Fltk/openglWindow.h b/Fltk/openglWindow.h index 27fe2129c15ef556d55c73843ae515e8f6c74d23..eb1e51e2a67a5d704ace5e6b6db4e3f3d53a61da 100644 --- a/Fltk/openglWindow.h +++ b/Fltk/openglWindow.h @@ -35,7 +35,7 @@ class openglWindow : public Fl_Gl_Window { bool _select(int type, bool multiple, bool mesh, int x, int y, int w, int h, std::vector<GVertex*> &vertices, std::vector<GEdge*> &edges, std::vector<GFace*> &faces, std::vector<GRegion*> ®ions, - std::vector<MElement*> &elements); + std::vector<MElement*> &elements, std::vector<SPoint2> &points); protected: void draw(); int handle(int); @@ -51,7 +51,7 @@ class openglWindow : public Fl_Gl_Window { char selectEntity(int type, std::vector<GVertex*> &vertices, std::vector<GEdge*> &edges, std::vector<GFace*> &faces, std::vector<GRegion*> ®ions, - std::vector<MElement*> &elements); + std::vector<MElement*> &elements, std::vector<SPoint2> &points); static openglWindow *getLastHandled(){ return _lastHandled; } static void setLastHandled(openglWindow *w){ _lastHandled = w; } void drawTooltip(const std::string &text); diff --git a/Graphics/drawContext.cpp b/Graphics/drawContext.cpp index 75bc9409699c1219c36a0bbee049a5c0d6ee6d1b..2990b1f548c687f220c26df057a3d1147971561a 100644 --- a/Graphics/drawContext.cpp +++ b/Graphics/drawContext.cpp @@ -32,6 +32,8 @@ drawContextGlobal *drawContext::_global = 0; +extern SPoint2 getGraph2dDataPointForTag(unsigned int); + drawContext::drawContext(drawTransform *transform) : _transform(transform) { @@ -827,7 +829,8 @@ bool drawContext::select(int type, bool multiple, bool mesh, std::vector<GEdge*> &edges, std::vector<GFace*> &faces, std::vector<GRegion*> ®ions, - std::vector<MElement*> &elements) + std::vector<MElement*> &elements, + std::vector<SPoint2> &points) { vertices.clear(); edges.clear(); @@ -1003,7 +1006,10 @@ bool drawContext::select(int type, bool multiple, bool mesh, break; case 4: { - printf("got hit with %d\n", hits[i].ient); + int tag = hits[i].ient; + SPoint2 p = getGraph2dDataPointForTag(tag); + points.push_back(p); + if(!multiple) return true; } break; } @@ -1011,7 +1017,7 @@ bool drawContext::select(int type, bool multiple, bool mesh, } if(vertices.size() || edges.size() || faces.size() || - regions.size() || elements.size()) + regions.size() || elements.size() || points.size()) return true; return false; } diff --git a/Graphics/drawContext.h b/Graphics/drawContext.h index 7d0c97402a3f5c5da49a04c4e8c8194c38bdaa18..ad403c67906923095a21d72ed36ae9711c04fa03 100644 --- a/Graphics/drawContext.h +++ b/Graphics/drawContext.h @@ -10,6 +10,7 @@ #include <vector> #include <set> #include "SBoundingBox3d.h" +#include "SPoint2.h" #include "Camera.h" #if defined(WIN32) @@ -193,7 +194,7 @@ class drawContext { bool select(int type, bool multiple, bool mesh, int x, int y, int w, int h, std::vector<GVertex*> &vertices, std::vector<GEdge*> &edges, std::vector<GFace*> &faces, std::vector<GRegion*> ®ions, - std::vector<MElement*> &elements); + std::vector<MElement*> &elements, std::vector<SPoint2> &points); int fix2dCoordinates(double *x, double *y); void draw3d(); void draw2d(); diff --git a/Graphics/drawGraph2d.cpp b/Graphics/drawGraph2d.cpp index ab90b8994c8e7ee445dbd75f369548a0ffffeb91..db2ff339a69e85b7699027477c0454233329734a 100644 --- a/Graphics/drawGraph2d.cpp +++ b/Graphics/drawGraph2d.cpp @@ -392,10 +392,28 @@ static void drawGraphAxes(drawContext *ctx, PView *p, double xleft, double ytop, } +static std::map<SPoint2, unsigned int> tags; +static std::map<unsigned int, SPoint2> tags_rev; + +static unsigned int getTagForGraph2dDataPoint(SPoint2 p) +{ + std::map<SPoint2, unsigned int>::iterator it = tags.find(p); + if(it != tags.end()) return it->second; + int t = tags.size(); + tags[p] = t; + tags_rev[t] = p; + return t; +} + +SPoint2 getGraph2dDataPointForTag(unsigned int tag) +{ + return tags_rev[tag]; +} + static void addGraphPoint(drawContext *ctx, PView *p, double xleft, double ytop, double width, double height, double x, double y, double xmin, double xmax, double ymin, double ymax, - bool numeric, bool sphere, bool inModelCoordinates) + bool numeric, bool singlePoint, bool inModelCoordinates) { PViewOptions *opt = p->getOptions(); @@ -416,29 +434,37 @@ static void addGraphPoint(drawContext *ctx, PView *p, double xleft, double ytop, if(y >= ymin && y <= ymax){ unsigned int col = opt->getColor(y, ymin, ymax, true); glColor4ubv((GLubyte *) &col); + + if(singlePoint && ctx->render_mode == drawContext::GMSH_SELECT){ + glPushName(4); + glPushName(getTagForGraph2dDataPoint(SPoint2(x, y))); + } + if(numeric){ - glRasterPos2d(px + 3, py + 3); + double offset = 3; + if(inModelCoordinates) offset *= ctx->pixel_equiv_x / ctx->s[0]; + glRasterPos2d(px + offset, py + offset); char label[256]; sprintf(label, opt->format.c_str(), y); ctx->drawString(label); } - else if(sphere){ - if(ctx->render_mode == drawContext::GMSH_SELECT){ - glPushName(4); - static int ii = 0; - glPushName(ii++); - } + else if(singlePoint && (opt->pointType == 1 || opt->pointType == 3)){ if(inModelCoordinates) ctx->drawSphere(opt->pointSize, px, py, 0, opt->light); else ctx->drawSphere(opt->pointSize, px, py, 0, 10, 10, opt->light); - if(ctx->render_mode == drawContext::GMSH_SELECT){ - glPopName(); - glPopName(); - } } - else + else{ + if(singlePoint) glBegin(GL_POINTS); glVertex2d(px, py); + if(singlePoint) glEnd(); + } + + if(singlePoint && ctx->render_mode == drawContext::GMSH_SELECT){ + glPopName(); + glPopName(); + } + } } @@ -482,22 +508,18 @@ static void drawGraphCurves(drawContext *ctx, PView *p, double xleft, double yto if(opt->intervalsType == PViewOptions::Iso || opt->intervalsType == PViewOptions::Discrete || opt->intervalsType == PViewOptions::Numeric){ - bool sphere = (opt->pointType == 1 || opt->pointType == 3); - - if(!sphere) glBegin(GL_POINTS); for(unsigned int i = 0; i < y.size(); i++) for(unsigned int j = 0; j < x.size(); j++) addGraphPoint(ctx, p, xleft, ytop, width, height, x[j], y[i][j], - xmin, xmax, opt->tmpMin, opt->tmpMax, false, sphere, + xmin, xmax, opt->tmpMin, opt->tmpMax, false, true, inModelCoordinates); - if(!sphere) glEnd(); } if(opt->intervalsType == PViewOptions::Numeric){ for(unsigned int i = 0; i < y.size(); i++) for(unsigned int j = 0; j < x.size(); j++) addGraphPoint(ctx, p, xleft, ytop, width, height, x[j], y[i][j], - xmin, xmax, opt->tmpMin, opt->tmpMax, true, false, + xmin, xmax, opt->tmpMin, opt->tmpMax, true, true, inModelCoordinates); } }