From 96da71770977fac9d089a7bc4b91569cac34b5ab Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Tue, 29 Sep 2009 06:17:46 +0000
Subject: [PATCH] remote stuff now mostly functional

---
 Common/GmshDaemon.cpp  |  6 ++++--
 Common/VertexArray.cpp | 24 +++++++++++++++---------
 Post/PViewDataRemote.h |  3 +--
 3 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/Common/GmshDaemon.cpp b/Common/GmshDaemon.cpp
index f951ec00dc..cc820418e2 100644
--- a/Common/GmshDaemon.cpp
+++ b/Common/GmshDaemon.cpp
@@ -12,9 +12,11 @@
 #include "PViewOptions.h"
 #include "PViewData.h"
 #include "VertexArray.h"
+#include "Context.h"
 
 static void computeAndSendVertexArrays(GmshClient &client)
 {
+  CTX::instance()->terminal = 1; // debug
   client.Info("Sending vertex arrays");
   for(unsigned int i = 0; i < PView::list.size(); i++){
     PView *p = PView::list[i];
@@ -23,7 +25,7 @@ static void computeAndSendVertexArrays(GmshClient &client)
     VertexArray *va[4] = 
       {p->va_points, p->va_lines, p->va_triangles, p->va_vectors};
     for(int type = 0; type < 4; type++){
-      if(va[type] && va[type]->getNumVertices()){
+      if(va[type]){
         int len;
         char *str = va[type]->toChar
           (p->getNum(), type + 1, data->getMin(), data->getMax(),
@@ -79,6 +81,7 @@ int GmshDaemon(std::string socket)
       break;
     }
     else if(type == GmshSocket::GMSH_VERTEX_ARRAY){
+      ParseString(msg);
       computeAndSendVertexArrays(client);
     }
     else if(type == GmshSocket::GMSH_MERGE_FILE){
@@ -87,7 +90,6 @@ int GmshDaemon(std::string socket)
     }
     else if(type == GmshSocket::GMSH_PARSE_STRING){
       ParseString(msg);
-      computeAndSendVertexArrays(client);
     }
     else if(type == GmshSocket::GMSH_SPEED_TEST){
       client.Info("Sending huge array");
diff --git a/Common/VertexArray.cpp b/Common/VertexArray.cpp
index 8a747147d2..d8ed66c622 100644
--- a/Common/VertexArray.cpp
+++ b/Common/VertexArray.cpp
@@ -241,11 +241,11 @@ char *VertexArray::toChar(int num, int type, double min, double max, double time
   memcpy(&bytes[index], &ymax, ds); index += ds;
   memcpy(&bytes[index], &zmax, ds); index += ds;
   memcpy(&bytes[index], &vn, is); index += is;
-  memcpy(&bytes[index], &_vertices[0], vs); index += vs;
+  if(vs){ memcpy(&bytes[index], &_vertices[0], vs); index += vs; }
   memcpy(&bytes[index], &nn, is); index += is;
-  memcpy(&bytes[index], &_normals[0], ns); index += ns;
+  if(ns){ memcpy(&bytes[index], &_normals[0], ns); index += ns; }
   memcpy(&bytes[index], &cn, is); index += is;
-  memcpy(&bytes[index], &_colors[0], cs); index += cs;
+  if(cs){ memcpy(&bytes[index], &_colors[0], cs); index += cs; }
   return bytes;
 }
 
@@ -270,14 +270,20 @@ void VertexArray::fromChar(const char *bytes)
   double zmax; memcpy(&zmax, &bytes[index], ds); index += ds;
 
   int vn; memcpy(&vn, &bytes[index], is); index += is;
-  _vertices.resize(vn); int vs = vn * sizeof(float);
-  memcpy(&_vertices[0], &bytes[index], vs); index += vs;
+  if(vn){
+    _vertices.resize(vn); int vs = vn * sizeof(float);
+    memcpy(&_vertices[0], &bytes[index], vs); index += vs;
+  }
 
   int nn; memcpy(&nn, &bytes[index], is); index += is;
-  _normals.resize(nn); int ns = nn * sizeof(char); 
-  memcpy(&_normals[0], &bytes[index], ns); index += ns;
+  if(nn){
+    _normals.resize(nn); int ns = nn * sizeof(char); 
+    memcpy(&_normals[0], &bytes[index], ns); index += ns;
+  }
 
   int cn; memcpy(&cn, &bytes[index], is); index += is;
-  _colors.resize(cn); int cs = cn * sizeof(unsigned char); 
-  memcpy(&_colors[0], &bytes[index], cs); index += cs;
+  if(cn){
+    _colors.resize(cn); int cs = cn * sizeof(unsigned char); 
+    memcpy(&_colors[0], &bytes[index], cs); index += cs;
+  }
 }
diff --git a/Post/PViewDataRemote.h b/Post/PViewDataRemote.h
index 0c81c9e18b..1a8c769e80 100644
--- a/Post/PViewDataRemote.h
+++ b/Post/PViewDataRemote.h
@@ -71,8 +71,7 @@ class PViewDataRemote : public PViewData {
     // FIXME: until we rewrite the option code and allow nice serialization ;-)
     PrintOptions(0, GMSH_FULLRC, 0, 0, fileName.c_str());
     std::string options = ConvertFileToString(fileName);
-    server->SendString(GmshSocket::GMSH_PARSE_STRING, options.c_str());
-    server->SendString(GmshSocket::GMSH_VERTEX_ARRAY, "Send the vertex arrays!");
+    server->SendString(GmshSocket::GMSH_VERTEX_ARRAY, options.c_str());
     return 1;
   }
 };
-- 
GitLab