From 91886e6a8eac9807e4565dbb63e6d59995ba883c Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Sun, 14 Nov 2004 04:38:11 +0000
Subject: [PATCH] Better interactive point creation (modified patch from
 schumact@colorado.edu)

---
 Fltk/Callbacks.cpp     | 37 ++++++++++++++-----------------------
 Fltk/Opengl_Window.cpp | 23 +++++++++++++++++++++--
 Fltk/Opengl_Window.h   |  5 +++--
 3 files changed, 38 insertions(+), 27 deletions(-)

diff --git a/Fltk/Callbacks.cpp b/Fltk/Callbacks.cpp
index f03bf643b5..d252b8ded0 100644
--- a/Fltk/Callbacks.cpp
+++ b/Fltk/Callbacks.cpp
@@ -1,4 +1,4 @@
-// $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
 //
@@ -1670,35 +1670,26 @@ void geometry_elementary_add_new_point_cb(CALLBACK_ARGS)
 
   while(1) {
     Msg(STATUS3N, "Creating point");
-    Msg(ONSCREEN, "Click and/or enter coordinates\n"
-	"[Press 'e' or 'Add' to add point or 'q' to abort]");
+    WID->g_opengl_window->AddPointMode = true;
+    Msg(ONSCREEN, "Move mouse and/or enter coordinates\n"
+	"[Press 'Shift' to hold position, 'e' to add point or 'q' to abort]");
     Vertex *v;
     Curve *c;
     Surface *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'){
+      WID->g_opengl_window->AddPointMode = false;
+      WID->g_opengl_window->cursor(FL_CURSOR_DEFAULT, FL_BLACK, FL_WHITE);
       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(ONSCREEN, "");
diff --git a/Fltk/Opengl_Window.cpp b/Fltk/Opengl_Window.cpp
index 4cd80402cf..b8ee85a41c 100644
--- a/Fltk/Opengl_Window.cpp
+++ b/Fltk/Opengl_Window.cpp
@@ -1,4 +1,4 @@
-// $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
 //
@@ -160,7 +160,7 @@ int Opengl_Window::handle(int event)
     ibut = Fl::event_button();
     xpos = Fl::event_x();
     ypos = Fl::event_y();
-
+    
     if(ibut == 1 && !Fl::event_state(FL_SHIFT) && !Fl::event_state(FL_ALT)) {
       if(!ZoomClick && Fl::event_state(FL_CTRL)) {
         ZOOM_X0 = ZOOM_X1 =
@@ -302,6 +302,25 @@ int Opengl_Window::handle(int event)
   case FL_MOVE:
     xmov = Fl::event_x() - xpos;
     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) {
       ZOOM = 1;
diff --git a/Fltk/Opengl_Window.h b/Fltk/Opengl_Window.h
index d580e85bb5..ce07490da8 100644
--- a/Fltk/Opengl_Window.h
+++ b/Fltk/Opengl_Window.h
@@ -26,9 +26,9 @@
 
 class Opengl_Window : public Fl_Gl_Window {
  public:
-  int xpos, ypos;
+  bool AddPointMode;
  private:
-  int xmov, ymov, ibut, hits;
+  int xpos, ypos, xmov, ymov, ibut, hits;
   int ZoomClick, FirstClick;
   GLdouble xc, yc, xc1, yc1, xc2, yc2, xt1, yt1, xscale1, yscale1;
   Vertex *v, *ov;
@@ -43,6 +43,7 @@ class Opengl_Window : public Fl_Gl_Window {
  public:
   Opengl_Window(int x,int y,int w,int h,const char *l=0)
     : Fl_Gl_Window(x, y, w, h, l) {
+    AddPointMode = false;
     xpos = ypos = xmov = ymov = ibut = hits = 0;
     ZoomClick = FirstClick = 0;
     v = ov = NULL;
-- 
GitLab