Skip to content
Snippets Groups Projects
Commit 91886e6a authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

Better interactive point creation (modified patch from schumact@colorado.edu)
parent 25514ecb
No related branches found
No related tags found
No related merge requests found
// $Id: Callbacks.cpp,v 1.297 2004-11-13 22:52:45 geuzaine Exp $ // $Id: Callbacks.cpp,v 1.298 2004-11-14 04:38:11 geuzaine Exp $
// //
// Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
// //
...@@ -1670,35 +1670,26 @@ void geometry_elementary_add_new_point_cb(CALLBACK_ARGS) ...@@ -1670,35 +1670,26 @@ void geometry_elementary_add_new_point_cb(CALLBACK_ARGS)
while(1) { while(1) {
Msg(STATUS3N, "Creating point"); Msg(STATUS3N, "Creating point");
Msg(ONSCREEN, "Click and/or enter coordinates\n" WID->g_opengl_window->AddPointMode = true;
"[Press 'e' or 'Add' to add point or 'q' to abort]"); Msg(ONSCREEN, "Move mouse and/or enter coordinates\n"
"[Press 'Shift' to hold position, 'e' to add point or 'q' to abort]");
Vertex *v; Vertex *v;
Curve *c; Curve *c;
Surface *s; Surface *s;
char ib = SelectEntity(ENT_NONE, &v, &c, &s); char ib = SelectEntity(ENT_NONE, &v, &c, &s);
if(ib == 'e'){
add_point(CTX.filename,
(char*)WID->context_geometry_input[2]->value(),
(char*)WID->context_geometry_input[3]->value(),
(char*)WID->context_geometry_input[4]->value(),
(char*)WID->context_geometry_input[5]->value());
Draw();
}
if(ib == 'q'){ if(ib == 'q'){
WID->g_opengl_window->AddPointMode = false;
WID->g_opengl_window->cursor(FL_CURSOR_DEFAULT, FL_BLACK, FL_WHITE);
break; break;
} }
else if(ib == 'e') {
con_geometry_define_point_cb(NULL, NULL);
}
else if(ib == 'c') { // mouse click
// find line in real space corresponding to current cursor position
double p[3], d[3];
unproject(WID->g_opengl_window->xpos, WID->g_opengl_window->ypos, p, d);
// fin closest point to the center of gravity
double r[3] = {CTX.cg[0]-p[0], CTX.cg[1]-p[1], CTX.cg[2]-p[2]};
double t;
prosca(r, d, &t);
double sol[3] = {p[0]+t*d[0], p[1]+t*d[1], p[2]+t*d[2]};
char str[32];
sprintf(str, "%g", sol[0]);
WID->context_geometry_input[2]->value(str);
sprintf(str, "%g", sol[1]);
WID->context_geometry_input[3]->value(str);
sprintf(str, "%g", sol[2]);
WID->context_geometry_input[4]->value(str);
}
} }
Msg(STATUS3N, "Ready"); Msg(STATUS3N, "Ready");
Msg(ONSCREEN, ""); Msg(ONSCREEN, "");
......
// $Id: Opengl_Window.cpp,v 1.40 2004-10-28 03:44:37 geuzaine Exp $ // $Id: Opengl_Window.cpp,v 1.41 2004-11-14 04:38:11 geuzaine Exp $
// //
// Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
// //
...@@ -160,7 +160,7 @@ int Opengl_Window::handle(int event) ...@@ -160,7 +160,7 @@ int Opengl_Window::handle(int event)
ibut = Fl::event_button(); ibut = Fl::event_button();
xpos = Fl::event_x(); xpos = Fl::event_x();
ypos = Fl::event_y(); ypos = Fl::event_y();
if(ibut == 1 && !Fl::event_state(FL_SHIFT) && !Fl::event_state(FL_ALT)) { if(ibut == 1 && !Fl::event_state(FL_SHIFT) && !Fl::event_state(FL_ALT)) {
if(!ZoomClick && Fl::event_state(FL_CTRL)) { if(!ZoomClick && Fl::event_state(FL_CTRL)) {
ZOOM_X0 = ZOOM_X1 = ZOOM_X0 = ZOOM_X1 =
...@@ -302,6 +302,25 @@ int Opengl_Window::handle(int event) ...@@ -302,6 +302,25 @@ int Opengl_Window::handle(int event)
case FL_MOVE: case FL_MOVE:
xmov = Fl::event_x() - xpos; xmov = Fl::event_x() - xpos;
ymov = Fl::event_y() - ypos; ymov = Fl::event_y() - ypos;
if(AddPointMode && !Fl::event_state(FL_SHIFT)){
WID->g_opengl_window->cursor(FL_CURSOR_CROSS, FL_BLACK, FL_WHITE);
// find line in real space corresponding to current cursor position
double p[3],d[3];
unproject(Fl::event_x(), Fl::event_y(), p, d);
// fin closest point to the center of gravity
double r[3] = {CTX.cg[0]-p[0], CTX.cg[1]-p[1], CTX.cg[2]-p[2]};
double t;
prosca(r,d,&t);
double sol[3] = {p[0]+t*d[0], p[1]+t*d[1], p[2]+t*d[2]};
char str[32];
sprintf(str, "%g", sol[0]);
WID->context_geometry_input[2]->value(str);
sprintf(str, "%g", sol[1]);
WID->context_geometry_input[3]->value(str);
sprintf(str, "%g", sol[2]);
WID->context_geometry_input[4]->value(str);
}
if(ZoomClick) { if(ZoomClick) {
ZOOM = 1; ZOOM = 1;
......
...@@ -26,9 +26,9 @@ ...@@ -26,9 +26,9 @@
class Opengl_Window : public Fl_Gl_Window { class Opengl_Window : public Fl_Gl_Window {
public: public:
int xpos, ypos; bool AddPointMode;
private: private:
int xmov, ymov, ibut, hits; int xpos, ypos, xmov, ymov, ibut, hits;
int ZoomClick, FirstClick; int ZoomClick, FirstClick;
GLdouble xc, yc, xc1, yc1, xc2, yc2, xt1, yt1, xscale1, yscale1; GLdouble xc, yc, xc1, yc1, xc2, yc2, xt1, yt1, xscale1, yscale1;
Vertex *v, *ov; Vertex *v, *ov;
...@@ -43,6 +43,7 @@ class Opengl_Window : public Fl_Gl_Window { ...@@ -43,6 +43,7 @@ class Opengl_Window : public Fl_Gl_Window {
public: public:
Opengl_Window(int x,int y,int w,int h,const char *l=0) Opengl_Window(int x,int y,int w,int h,const char *l=0)
: Fl_Gl_Window(x, y, w, h, l) { : Fl_Gl_Window(x, y, w, h, l) {
AddPointMode = false;
xpos = ypos = xmov = ymov = ibut = hits = 0; xpos = ypos = xmov = ymov = ibut = hits = 0;
ZoomClick = FirstClick = 0; ZoomClick = FirstClick = 0;
v = ov = NULL; v = ov = NULL;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment