From 49befd884b62da13bebd672986bf4a1cb8147ff6 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Tue, 28 Aug 2007 22:54:06 +0000
Subject: [PATCH] interface strings in new post

---
 Graphics/Graph2D.cpp  | 24 +++++++++++++--
 Graphics/Post.cpp     | 11 +++++--
 Post/PViewData.cpp    | 68 ++++++++++++++++++++++++++++++++++++++++++-
 Post/PViewData.h      | 14 +++++++++
 Post/PViewOptions.cpp | 16 +++++-----
 Post/PViewOptions.h   |  7 +++--
 6 files changed, 124 insertions(+), 16 deletions(-)

diff --git a/Graphics/Graph2D.cpp b/Graphics/Graph2D.cpp
index ea4b5a7b39..f24b187314 100644
--- a/Graphics/Graph2D.cpp
+++ b/Graphics/Graph2D.cpp
@@ -1,4 +1,4 @@
-// $Id: Graph2D.cpp,v 1.58 2006-11-27 22:22:14 geuzaine Exp $
+// $Id: Graph2D.cpp,v 1.59 2007-08-28 22:54:06 geuzaine Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
@@ -526,12 +526,30 @@ void Draw_Text2D3D(int dim, int timestep, int nb, List_T * td, List_T * tc)
   }
 }
 
+#include "PView.h"
 
-void Draw_Text2D(void)
+void Draw_Text2D()
 {
+  for(unsigned int i = 0; i < PView::list.size(); i++){
+    PViewData *data = PView::list[i]->getData();
+    PViewOptions *opt = PView::list[i]->getOptions();
+    if(opt->Visible && opt->DrawStrings){
+      glColor4ubv((GLubyte *) & opt->color.text2d);
+      for(int j = 0; j < data->getNumStrings2D(); j++){
+	double x, y, style;
+	std::string str;
+	data->getString2D(j, opt->TimeStep, str, x, y, style);
+	Fix2DCoordinates(&x, &y);
+	glRasterPos2d(x, y);
+	Draw_String((char*)str.c_str(), style);
+      }
+    }
+  }
+
+  ///////// remove this ////////
+
   if(!CTX.post.list)
     return;
-
   for(int i = 0; i < List_Nbr(CTX.post.list); i++) {
     Post_View *v = *(Post_View **) List_Pointer(CTX.post.list, i);
     if(v->Visible && !v->Dirty && v->DrawStrings){
diff --git a/Graphics/Post.cpp b/Graphics/Post.cpp
index 41a6810870..2be9183fb1 100644
--- a/Graphics/Post.cpp
+++ b/Graphics/Post.cpp
@@ -1,4 +1,4 @@
-// $Id: Post.cpp,v 1.123 2007-08-28 08:38:47 geuzaine Exp $
+// $Id: Post.cpp,v 1.124 2007-08-28 22:54:06 geuzaine Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
@@ -1301,9 +1301,16 @@ class drawPView {
     // glyphs in "pseudo" vertex arrays
     drawGlyphs(p);
 
+    // draw the 3D strings
     if(opt->DrawStrings){
       glColor4ubv((GLubyte *) & opt->color.text3d);
-      //Draw_Text2D3D(3, opt->TimeStep, data->NbT3, data->T3D, data->T3C);
+      for(int i = 0; i < data->getNumStrings3D(); i++){
+	double x, y, z, style;
+	std::string str;
+	data->getString3D(i, opt->TimeStep, str, x, y, z, style);
+	glRasterPos3d(x, y, z);
+	Draw_String((char*)str.c_str(), style);
+      }
     }
     
     if(CTX.alpha){
diff --git a/Post/PViewData.cpp b/Post/PViewData.cpp
index 2b096f5b9e..d8918b4921 100644
--- a/Post/PViewData.cpp
+++ b/Post/PViewData.cpp
@@ -1,4 +1,4 @@
-// $Id: PViewData.cpp,v 1.5 2007-08-27 13:46:22 geuzaine Exp $
+// $Id: PViewData.cpp,v 1.6 2007-08-28 22:54:06 geuzaine Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
@@ -321,3 +321,69 @@ int PViewDataList::getNumEdges(int ele)
   if(ele != _lastElement) _setLast(ele);
   return _lastNumEdges;
 }
+
+void PViewDataList::_getString(int dim, int i, int timestep, std::string &str, 
+			       double &x, double &y, double &z, double &style)
+{
+  // 3D: T3D is a list of double: x,y,z,style,index,x,y,z,style,index,...
+  //     T3C is a list of chars: string\0,string\0,string\0,string\0,...
+  //     Parser format is: T3(x,y,z,style){"str","str",...};
+  // 2D: T2D is a list of double: x,y,style,index,x,y,style,index,...
+  //     T2C is a list of chars: string\0,string\0,string\0,string\0,...
+  //     Parser format is: T2(x,y,style){"str","str",...};
+
+  int nb = (dim == 2) ? NbT2 : NbT3;
+  List_T *td = (dim == 2) ? T2D : T3D;
+  List_T *tc = (dim == 2) ? T2C : T3C;
+  int nbd = (dim == 2) ? 4 : 5;
+
+  int index, nbchar;
+  double *d1 = (double *)List_Pointer(td, i * nbd);
+  double *d2 = (double *)List_Pointer_Test(td, (i + 1) * nbd);
+  if(dim == 2) {
+    x = d1[0];
+    y = d1[1];
+    z = 0.;
+    style = d1[2];
+    index = (int)d1[3];
+    if(d2)
+      nbchar = (int)d2[3] - index;
+    else
+      nbchar = List_Nbr(tc) - index;
+  }
+  else {
+    x = d1[0];
+    y = d1[1];
+    z = d1[2];
+    style = d1[3];
+    index = (int)d1[4];
+    if(d2)
+      nbchar = (int)d2[4] - index;
+    else
+      nbchar = List_Nbr(tc) - index;
+  }
+  
+  char *c = (char *)List_Pointer(tc, index);
+  int k = 0, l = 0;
+  while(k < nbchar && l != timestep) {
+    if(c[k++] == '\0')
+      l++;
+  }
+  if(k < nbchar && l == timestep)
+    str = std::string(&c[k]);
+  else
+    str = std::string(c);
+}
+
+void PViewDataList::getString2D(int i, int step, std::string &str, 
+				double &x, double &y, double &style)
+{
+  double z;
+  _getString(2, i, step, str, x, y, z, style);
+}
+
+void PViewDataList::getString3D(int i, int step, std::string &str, 
+				double &x, double &y, double &z, double &style)
+{
+  _getString(3, i, step, str, x, y, z, style);
+}
diff --git a/Post/PViewData.h b/Post/PViewData.h
index 869f5c0b67..0d592b2bc8 100644
--- a/Post/PViewData.h
+++ b/Post/PViewData.h
@@ -63,6 +63,12 @@ class PViewData {
   virtual int getNumComponents(int ele) = 0;
   virtual void getValue(int ele, int node, int comp, int step, double &val) = 0;
   virtual int getNumEdges(int ele) = 0;
+  virtual int getNumStrings2D(){ return 0; }
+  virtual int getNumStrings3D(){ return 0; }
+  virtual void getString2D(int i, int step, std::string &str, 
+			   double &x, double &y, double &style){}
+  virtual void getString3D(int i, int step, std::string &str, 
+			   double &x, double &y, double &z, double &style){}
   virtual bool read(std::string filename){}
 };
 
@@ -107,6 +113,8 @@ class PViewDataList : public PViewData {
   void _setLast(int ele);
   void _setLast(int ele, int dim, int nbnod, int nbcomp, int nbedg,
 		List_T *list, int nblist);
+  void _getString(int dim, int i, int timestep, std::string &str, 
+		  double &x, double &y, double &z, double &style);
  public:
   PViewDataList(bool allocate=true);
   ~PViewDataList();
@@ -138,6 +146,12 @@ class PViewDataList : public PViewData {
   int getNumComponents(int ele);
   void getValue(int ele, int node, int comp, int step, double &val);
   int getNumEdges(int ele);
+  int getNumStrings2D(){ return NbT2; }
+  int getNumStrings3D(){ return NbT3; }
+  void getString2D(int i, int step, std::string &str, 
+		   double &x, double &y, double &style);
+  void getString3D(int i, int step, std::string &str, 
+		   double &x, double &y, double &z, double &style);
   bool read(std::string filename);
 };
 
diff --git a/Post/PViewOptions.cpp b/Post/PViewOptions.cpp
index d2d04a06ce..a2df5ccf5f 100644
--- a/Post/PViewOptions.cpp
+++ b/Post/PViewOptions.cpp
@@ -1,4 +1,4 @@
-// $Id: PViewOptions.cpp,v 1.9 2007-08-28 08:38:47 geuzaine Exp $
+// $Id: PViewOptions.cpp,v 1.10 2007-08-28 22:54:06 geuzaine Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
@@ -79,8 +79,8 @@ PViewOptions::PViewOptions()
   DrawStrings = DrawPoints = DrawLines = DrawTriangles = DrawQuadrangles =
     DrawTetrahedra = DrawHexahedra = DrawPrisms = DrawPyramids =
     DrawScalars = DrawVectors = DrawTensors = 1;
-  Boundary = 1;
-  PointType = LineType = 2;
+  Boundary = 0;
+  PointType = LineType = 0;
   PointSize = 3;
   LineWidth = 2;
   UseStipple = 0;
@@ -135,11 +135,12 @@ double PViewOptions::getScaleValue(int iso, int numIso, double min, double max)
   return 0.;
 }
 
-int PViewOptions::getScaleIndex(double val, int numIso, double min, double max)
+int PViewOptions::getScaleIndex(double val, int numIso, double min, double max,
+				bool forceLinear)
 {
   if(min == max) return numIso / 2;
 
-  if(ScaleType == Linear){
+  if(forceLinear || ScaleType == Linear){
     return (int)((val - min) * (numIso - 1) / (max - min));
   }
   else if(ScaleType == Logarithmic){
@@ -155,10 +156,11 @@ int PViewOptions::getScaleIndex(double val, int numIso, double min, double max)
 }
 
 // val in [min, max]
-unsigned int PViewOptions::getColor(double val, double min, double max)
+unsigned int PViewOptions::getColor(double val, double min, double max, 
+				    bool forceLinear)
 {
   if(CT.size == 1) return CT.table[0];
-  int index = getScaleIndex(val, CT.size, min, max);
+  int index = getScaleIndex(val, CT.size, min, max, forceLinear);
   return CT.table[index];
 }
 
diff --git a/Post/PViewOptions.h b/Post/PViewOptions.h
index 4fb150b715..f0b5f9b536 100644
--- a/Post/PViewOptions.h
+++ b/Post/PViewOptions.h
@@ -118,10 +118,11 @@ class PViewOptions {
   ~PViewOptions();
   void createGeneralRaise();
   void destroyGeneralRaise();
-  unsigned int getColor(int i, int nb);
-  unsigned int getColor(double val, double min, double max);
   double getScaleValue(int iso, int numIso, double min, double max);
-  int getScaleIndex(double val, int numIso, double min, double max);
+  int getScaleIndex(double val, int numIso, double min, double max, 
+		    bool forceLinear=false);
+  unsigned int getColor(int i, int nb);
+  unsigned int getColor(double val, double min, double max, bool forceLinear=false);
 };
 
 #endif
-- 
GitLab