From f0cbeec58f07380eb37f769f9a2d81c63073d9fe Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Mon, 27 Dec 2004 03:57:23 +0000
Subject: [PATCH] - new alternative Draw_String function taking a "style"
 argument (used   only for font size at the moment) - new Plugin(Annotate) to
 add simple text strings to a view

---
 Fltk/Opengl.cpp       |  13 +++-
 Graphics/Draw.h       |   1 +
 Graphics/Graph2D.cpp  |   6 +-
 Plugin/Annotate.cpp   | 150 ++++++++++++++++++++++++++++++++++++++++++
 Plugin/Annotate.h     |  44 +++++++++++++
 Plugin/Makefile       |  20 ++++--
 Plugin/Plugin.cpp     |   5 +-
 doc/VERSIONS          |   4 +-
 doc/texinfo/gmsh.texi |  12 ++--
 9 files changed, 236 insertions(+), 19 deletions(-)
 create mode 100644 Plugin/Annotate.cpp
 create mode 100644 Plugin/Annotate.h

diff --git a/Fltk/Opengl.cpp b/Fltk/Opengl.cpp
index e1a9d2f27f..987382da87 100644
--- a/Fltk/Opengl.cpp
+++ b/Fltk/Opengl.cpp
@@ -1,4 +1,4 @@
-// $Id: Opengl.cpp,v 1.43 2004-10-28 06:11:22 geuzaine Exp $
+// $Id: Opengl.cpp,v 1.44 2004-12-27 03:57:23 geuzaine Exp $
 //
 // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
 //
@@ -80,6 +80,17 @@ void Draw_String(char *s)
   }
 }
 
+void Draw_String(char *s, double style)
+{
+  int size = (int)style, oldsize = CTX.gl_fontsize;
+  // extract the 8 lower bits of style to get the font size (and
+  // ignore if size==0):
+  size &= 0xff;
+  if(size) CTX.gl_fontsize = size;
+  Draw_String(s);
+  if(size) CTX.gl_fontsize = oldsize;
+}
+
 void Draw_OnScreenMessages()
 {
 
diff --git a/Graphics/Draw.h b/Graphics/Draw.h
index e008a4ea87..89d24722e2 100644
--- a/Graphics/Draw.h
+++ b/Graphics/Draw.h
@@ -59,6 +59,7 @@ void Draw2d(void);
 void Draw(void);
 
 void Draw_String(char *s);
+void Draw_String(char *s, double style);
 void Draw_Geom(Mesh *m);
 void Draw_Post(void);
 void Draw_Graph2D(void);
diff --git a/Graphics/Graph2D.cpp b/Graphics/Graph2D.cpp
index 76ac3d8716..667eae6dcf 100644
--- a/Graphics/Graph2D.cpp
+++ b/Graphics/Graph2D.cpp
@@ -1,4 +1,4 @@
-// $Id: Graph2D.cpp,v 1.38 2004-11-25 02:10:32 geuzaine Exp $
+// $Id: Graph2D.cpp,v 1.39 2004-12-27 03:57:23 geuzaine Exp $
 //
 // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
 //
@@ -490,9 +490,9 @@ void Draw_Text2D3D(int dim, int timestep, int nb, List_T * td, List_T * tc)
         l++;
     }
     if(k < nbchar && l == timestep)
-      Draw_String(&c[k]);
+      Draw_String(&c[k], style);
     else
-      Draw_String(c);
+      Draw_String(c, style);
   }
 }
 
diff --git a/Plugin/Annotate.cpp b/Plugin/Annotate.cpp
new file mode 100644
index 0000000000..53482192d2
--- /dev/null
+++ b/Plugin/Annotate.cpp
@@ -0,0 +1,150 @@
+// $Id: Annotate.cpp,v 1.1 2004-12-27 03:57:23 geuzaine Exp $
+//
+// Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+// USA.
+// 
+// Please report all bugs and problems to <gmsh@geuz.org>.
+
+#include "Plugin.h"
+#include "Annotate.h"
+#include "List.h"
+#include "Views.h"
+#include "Context.h"
+#include "Numeric.h"
+
+extern Context_T CTX;
+
+StringXNumber AnnotateOptions_Number[] = {
+  {GMSH_FULLRC, "X", NULL, 20.},
+  {GMSH_FULLRC, "Y", NULL, 20.},
+  {GMSH_FULLRC, "Z", NULL, 0.},
+  {GMSH_FULLRC, "3D", NULL, 0.},
+  {GMSH_FULLRC, "FontSize", NULL, 14.},
+  {GMSH_FULLRC, "iView", NULL, -1.}
+};
+
+StringXString AnnotateOptions_String[] = {
+  {GMSH_FULLRC, "Text", NULL, "My Text"}
+};
+
+extern "C"
+{
+  GMSH_Plugin *GMSH_RegisterAnnotatePlugin()
+  {
+    return new GMSH_AnnotatePlugin();
+  }
+}
+
+GMSH_AnnotatePlugin::GMSH_AnnotatePlugin()
+{
+  ;
+}
+
+void GMSH_AnnotatePlugin::getName(char *name) const
+{
+  strcpy(name, "Annotate");
+}
+
+void GMSH_AnnotatePlugin::getInfos(char *author, char *copyright,
+				   char *help_text) const
+{
+  strcpy(author, "C. Geuzaine (geuz@geuz.org)");
+  strcpy(copyright, "DGR (www.multiphysics.com)");
+  strcpy(help_text,
+         "Plugin(Annotate) adds a text string of size\n"
+	 "`FontSize' in the view `iView'. If `3D' is\n"
+	 "equal to 1, the plugin inserts the string\n"
+	 "in model coordinates at the position (`X',`Y',`Z').\n"
+	 "If `3D' is equal to 0, the plugin inserts the\n"
+	 "string in screen coordinates at the position\n"
+	 "(`X',`Y'). If `iView' < 0, the plugin is run on\n"
+	 "the current view.\n"
+	 "\n"
+	 "Plugin(Annotate) is executed in-place.\n");
+}
+
+int GMSH_AnnotatePlugin::getNbOptions() const
+{
+  return sizeof(AnnotateOptions_Number) / sizeof(StringXNumber);
+}
+
+StringXNumber *GMSH_AnnotatePlugin::getOption(int iopt)
+{
+  return &AnnotateOptions_Number[iopt];
+}
+
+int GMSH_AnnotatePlugin::getNbOptionsStr() const
+{
+  return sizeof(AnnotateOptions_String) / sizeof(StringXString);
+}
+
+StringXString *GMSH_AnnotatePlugin::getOptionStr(int iopt)
+{
+  return &AnnotateOptions_String[iopt];
+}
+
+void GMSH_AnnotatePlugin::catchErrorMessage(char *errorMessage) const
+{
+  strcpy(errorMessage, "Annotate failed...");
+}
+
+Post_View *GMSH_AnnotatePlugin::execute(Post_View * v)
+{
+  double X = AnnotateOptions_Number[0].def;
+  double Y = AnnotateOptions_Number[1].def;
+  double Z = AnnotateOptions_Number[2].def;
+  int dim3 = (int)AnnotateOptions_Number[3].def;
+  int fontsize = (int)AnnotateOptions_Number[4].def;
+  int iView = (int)AnnotateOptions_Number[5].def;
+  char *text = AnnotateOptions_String[0].def;
+
+  if(iView < 0)
+    iView = v ? v->Index : 0;
+
+  if(!List_Pointer_Test(CTX.post.list, iView)) {
+    Msg(GERROR, "View[%d] does not exist", iView);
+    return v;
+  }
+
+  Post_View *v1 = *(Post_View **)List_Pointer(CTX.post.list, iView);
+  
+  double style = (double)fontsize; // for now...
+
+  if(dim3){
+    List_Add(v1->T3D, &X);
+    List_Add(v1->T3D, &Y);
+    List_Add(v1->T3D, &Z);
+    List_Add(v1->T3D, &style); 
+    double d = List_Nbr(v1->T3C);
+    List_Add(v1->T3D, &d); 
+    for(int i = 0; i < (int)strlen(text)+1; i++) 
+      List_Add(v1->T3C, &text[i]); 
+    v1->NbT3++;
+  }
+  else{
+    List_Add(v1->T2D, &X);
+    List_Add(v1->T2D, &Y);
+    List_Add(v1->T2D, &style); 
+    double d = List_Nbr(v1->T2C);
+    List_Add(v1->T2D, &d); 
+    for(int i = 0; i < (int)strlen(text)+1; i++) 
+      List_Add(v1->T2C, &text[i]); 
+    v1->NbT2++;
+  }
+
+  return v1;
+}
diff --git a/Plugin/Annotate.h b/Plugin/Annotate.h
new file mode 100644
index 0000000000..e3102264a8
--- /dev/null
+++ b/Plugin/Annotate.h
@@ -0,0 +1,44 @@
+#ifndef _ANNOTATE_H_
+#define _ANNOTATE_H_
+
+// Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+// USA.
+// 
+// Please report all bugs and problems to <gmsh@geuz.org>.
+
+#include "Plugin.h"
+
+extern "C"
+{
+  GMSH_Plugin *GMSH_RegisterAnnotatePlugin();
+}
+
+class GMSH_AnnotatePlugin : public GMSH_Post_Plugin
+{
+public:
+  GMSH_AnnotatePlugin();
+  void getName(char *name) const;
+  void getInfos(char *author, char *copyright, char *helpText) const;
+  void catchErrorMessage(char *errorMessage) const;
+  int getNbOptions() const;
+  StringXNumber* getOption(int iopt);  
+  int getNbOptionsStr() const;
+  StringXString* getOptionStr(int iopt);  
+  Post_View *execute(Post_View *);
+};
+
+#endif
diff --git a/Plugin/Makefile b/Plugin/Makefile
index b8c9c2afc1..55d0fddc0d 100644
--- a/Plugin/Makefile
+++ b/Plugin/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.65 2004-12-14 20:05:44 geuzaine Exp $
+# $Id: Makefile,v 1.66 2004-12-27 03:57:23 geuzaine Exp $
 #
 # Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
 #
@@ -44,6 +44,7 @@ SRC = Plugin.cpp\
         DecomposeInSimplex.cpp\
         Evaluate.cpp\
         Integrate.cpp\
+        Annotate.cpp\
         HarmonicToTime.cpp
 
 OBJ = ${SRC:.cpp=.o}
@@ -75,12 +76,12 @@ Plugin.o: Plugin.cpp Plugin.h ../Common/Options.h ../Common/Message.h \
   ../Common/GmshMatrix.h ../Common/AdaptiveViews.h PluginManager.h \
   CutMap.h Levelset.h CutGrid.h StreamLines.h CutPlane.h CutParametric.h \
   CutSphere.h Skin.h ../DataStr/Tree.h ../DataStr/avl.h Extract.h \
-  HarmonicToTime.h Integrate.h DecomposeInSimplex.h Smooth.h Transform.h \
-  Triangulate.h SphericalRaise.h DisplacementRaise.h StructuralSolver.h \
-  ../Geo/Geo.h ../Mesh/Mesh.h ../Mesh/Vertex.h ../Mesh/Element.h \
-  ../Mesh/Simplex.h ../Mesh/Face.h ../Mesh/Edge.h ../Geo/ExtrudeParams.h \
-  ../Mesh/STL.h ../Mesh/Metric.h ../Mesh/Matrix.h ../Common/GmshUI.h \
-  Eigenvectors.h Evaluate.h ../Common/Context.h
+  HarmonicToTime.h Integrate.h Annotate.h DecomposeInSimplex.h Smooth.h \
+  Transform.h Triangulate.h SphericalRaise.h DisplacementRaise.h \
+  StructuralSolver.h ../Geo/Geo.h ../Mesh/Mesh.h ../Mesh/Vertex.h \
+  ../Mesh/Element.h ../Mesh/Simplex.h ../Mesh/Face.h ../Mesh/Edge.h \
+  ../Geo/ExtrudeParams.h ../Mesh/STL.h ../Mesh/Metric.h ../Mesh/Matrix.h \
+  ../Common/GmshUI.h Eigenvectors.h Evaluate.h ../Common/Context.h
 Levelset.o: Levelset.cpp Levelset.h Plugin.h ../Common/Options.h \
   ../Common/Message.h ../Common/Views.h ../Common/ColorTable.h \
   ../DataStr/List.h ../Common/VertexArray.h ../Common/SmoothNormals.h \
@@ -215,6 +216,11 @@ Integrate.o: Integrate.cpp Plugin.h ../Common/Options.h \
   ../DataStr/List.h ../Common/VertexArray.h ../Common/SmoothNormals.h \
   ../Common/GmshMatrix.h ../Common/AdaptiveViews.h Integrate.h \
   ../Common/Context.h ../Numeric/Numeric.h ShapeFunctions.h
+Annotate.o: Annotate.cpp Plugin.h ../Common/Options.h ../Common/Message.h \
+  ../Common/Views.h ../Common/ColorTable.h ../DataStr/List.h \
+  ../Common/VertexArray.h ../Common/SmoothNormals.h \
+  ../Common/GmshMatrix.h ../Common/AdaptiveViews.h Annotate.h \
+  ../Common/Context.h ../Numeric/Numeric.h
 HarmonicToTime.o: HarmonicToTime.cpp Plugin.h ../Common/Options.h \
   ../Common/Message.h ../Common/Views.h ../Common/ColorTable.h \
   ../DataStr/List.h ../Common/VertexArray.h ../Common/SmoothNormals.h \
diff --git a/Plugin/Plugin.cpp b/Plugin/Plugin.cpp
index de86bfed81..cbe295cde0 100644
--- a/Plugin/Plugin.cpp
+++ b/Plugin/Plugin.cpp
@@ -1,4 +1,4 @@
-// $Id: Plugin.cpp,v 1.66 2004-12-10 03:35:29 geuzaine Exp $
+// $Id: Plugin.cpp,v 1.67 2004-12-27 03:57:23 geuzaine Exp $
 //
 // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
 //
@@ -42,6 +42,7 @@
 #include "Extract.h"
 #include "HarmonicToTime.h"
 #include "Integrate.h"
+#include "Annotate.h"
 #include "DecomposeInSimplex.h"
 #include "Smooth.h"
 #include "Transform.h"
@@ -195,6 +196,8 @@ void GMSH_PluginManager::registerDefaultPlugins()
 		      ("HarmonicToTime", GMSH_RegisterHarmonicToTimePlugin()));
     allPlugins.insert(std::pair < char *, GMSH_Plugin * >
 		      ("Integrate", GMSH_RegisterIntegratePlugin()));
+    allPlugins.insert(std::pair < char *, GMSH_Plugin * >
+		      ("Annotate", GMSH_RegisterAnnotatePlugin()));
     allPlugins.insert(std::pair < char *, GMSH_Plugin * >
 		      ("Eigenvectors", GMSH_RegisterEigenvectorsPlugin()));
 #if defined(HAVE_TRIANGLE)
diff --git a/doc/VERSIONS b/doc/VERSIONS
index 81a8ccba32..72a6d46d88 100644
--- a/doc/VERSIONS
+++ b/doc/VERSIONS
@@ -1,9 +1,9 @@
-$Id: VERSIONS,v 1.282 2004-12-27 00:47:04 geuzaine Exp $
+$Id: VERSIONS,v 1.283 2004-12-27 03:57:23 geuzaine Exp $
 
 New since 1.57: new File->Rename menu; new colormaps+improved colormap
 handling; new color+min/max options in views; new GetValue() function
 to ask for values interactively in scripts; generalized For/EndFor
-loops in parser;
+loops in parser; new Plugin(Annotate);
 
 New in 1.57: generalized displacement maps to display arbitrary view
 types; the arrows representing a vector field can now also be colored
diff --git a/doc/texinfo/gmsh.texi b/doc/texinfo/gmsh.texi
index 97146bffd8..a3fab52960 100644
--- a/doc/texinfo/gmsh.texi
+++ b/doc/texinfo/gmsh.texi
@@ -1,5 +1,5 @@
 \input texinfo.tex @c -*-texinfo-*-
-@c $Id: gmsh.texi,v 1.151 2004-12-27 00:47:04 geuzaine Exp $
+@c $Id: gmsh.texi,v 1.152 2004-12-27 03:57:23 geuzaine Exp $
 @c
 @c Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
 @c
@@ -3232,8 +3232,9 @@ is a list of 4 double precision numbers:
 @end example
 where @var{coord1} and @var{coord2} give the coordinates of the leftmost
 element of the 2D string in screen coordinates, @var{index} gives the
-starting index of the string in @var{text2d-chars} and @var{style} is
-currently unused.
+starting index of the string in @var{text2d-chars} and, if nonzero, the
+eight lower bits in @var{style} give the font size (the rest of @var{style}
+is reserved for future use).
 
 @item @var{text2d-chars}
 is a list of @var{nb-text2d-chars} characters. Substrings are separated with
@@ -3246,8 +3247,9 @@ is a list of 5 double precision numbers
 @end example
 where @var{coord1}, @var{coord2} and @var{coord3} give the coordinates of
 the leftmost element of the 3D string in model (real world) coordinates,
-@var{index} gives the starting index of the string in @var{text3d-chars} and
-@var{style} is currently unused.
+@var{index} gives the starting index of the string in @var{text3d-chars}
+and, if nonzero, the eight lower bits in @var{style} give the font size (the
+rest of @var{style} is reserved for future use).
 
 @item @var{text3d-chars}
 is a list of @var{nb-text3d-chars} chars. Substrings are separated with the
-- 
GitLab