From 786f5a45caf28067cd6be93ca1096fee2e6f7f28 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Thu, 2 Nov 2006 17:24:54 +0000
Subject: [PATCH] mesh edit

---
 Common/Options.cpp        |  5 +++--
 Fltk/Callbacks.cpp        |  5 +++--
 Graphics/Mesh.cpp         | 18 +++++++++++++-----
 Graphics/SelectBuffer.cpp |  8 ++++----
 4 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/Common/Options.cpp b/Common/Options.cpp
index e23d4f30a0..5b3e749d16 100644
--- a/Common/Options.cpp
+++ b/Common/Options.cpp
@@ -1,4 +1,4 @@
-// $Id: Options.cpp,v 1.313 2006-11-01 22:19:26 geuzaine Exp $
+// $Id: Options.cpp,v 1.314 2006-11-02 17:24:53 geuzaine Exp $
 //
 // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle
 //
@@ -4992,7 +4992,8 @@ double opt_mesh_color_carousel(OPT_ARGS_NUM)
   if(action & GMSH_SET) {
     // vertex arrays need to be regenerated only when we color by
     // element type or by partition
-    if(CTX.mesh.color_carousel != (int)val && (val == 0. || val == 3.))
+    if(CTX.mesh.color_carousel != (int)val && 
+       ((val == 0. || val == 3.) || CTX.pick_elements))
       CTX.mesh.changed = ENT_LINE | ENT_SURFACE | ENT_VOLUME;
     CTX.mesh.color_carousel = (int)val;
     if(CTX.mesh.color_carousel < 0 || CTX.mesh.color_carousel > 3)
diff --git a/Fltk/Callbacks.cpp b/Fltk/Callbacks.cpp
index af36f2fd17..42215a9832 100644
--- a/Fltk/Callbacks.cpp
+++ b/Fltk/Callbacks.cpp
@@ -1,4 +1,4 @@
-// $Id: Callbacks.cpp,v 1.466 2006-11-02 00:56:31 geuzaine Exp $
+// $Id: Callbacks.cpp,v 1.467 2006-11-02 17:24:53 geuzaine Exp $
 //
 // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle
 //
@@ -3540,7 +3540,8 @@ void mesh_delete_parts_cb(CALLBACK_ARGS)
       Msg(ONSCREEN, "Select %s\n"
 	  "[Press 'e' to end selection or 'q' to abort]", str);
 
-    char ib = SelectEntity(ENT_ALL, vertices, edges, faces, regions, elements);
+    char ib = SelectEntity(CTX.pick_elements ? ENT_ALL : ENT_SURFACE, 
+			   vertices, edges, faces, regions, elements);
     if(ib == 'l') {
       if(CTX.pick_elements){
 	for(unsigned int i = 0; i < elements.size(); i++){
diff --git a/Graphics/Mesh.cpp b/Graphics/Mesh.cpp
index 654bb21cfa..aac7daebdd 100644
--- a/Graphics/Mesh.cpp
+++ b/Graphics/Mesh.cpp
@@ -1,4 +1,4 @@
-// $Id: Mesh.cpp,v 1.186 2006-11-01 22:19:26 geuzaine Exp $
+// $Id: Mesh.cpp,v 1.187 2006-11-02 17:24:54 geuzaine Exp $
 //
 // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle
 //
@@ -70,10 +70,7 @@ static unsigned int getColorByElement(MElement *ele)
     default: return CTX.color.geom.volume_sel;
     }
   }
-  else if(CTX.mesh.color_carousel == 3){ // by partition
-    return CTX.color.mesh.carousel[abs(ele->getPartition() % 20)];
-  }
-  else{ // by element type
+  else if(CTX.mesh.color_carousel == 0){ // by element type
     switch(ele->getNumEdges()){
     case 1: return CTX.color.mesh.line;
     case 3: return CTX.color.mesh.triangle;
@@ -85,6 +82,17 @@ static unsigned int getColorByElement(MElement *ele)
     default: return CTX.color.mesh.vertex;
     }
   }
+  else if(CTX.mesh.color_carousel == 3){ // by partition
+    return CTX.color.mesh.carousel[abs(ele->getPartition() % 20)];
+  }
+  else{ // by entity
+    for(int i = 0; i < ele->getNumVertices(); i++){
+      GEntity *e = ele->getVertex(i)->onWhat();
+      if(e->dim() == ele->getDim()) 
+	return getColorByEntity(e);
+    }
+  }
+  return CTX.color.fg;
 }
 
 static double intersectCutPlane(MElement *ele)
diff --git a/Graphics/SelectBuffer.cpp b/Graphics/SelectBuffer.cpp
index 85b793e3fa..c39f74c267 100644
--- a/Graphics/SelectBuffer.cpp
+++ b/Graphics/SelectBuffer.cpp
@@ -1,4 +1,4 @@
-// $Id: SelectBuffer.cpp,v 1.6 2006-11-01 22:19:27 geuzaine Exp $
+// $Id: SelectBuffer.cpp,v 1.7 2006-11-02 17:24:54 geuzaine Exp $
 //
 // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle
 //
@@ -63,9 +63,9 @@ bool ProcessSelectionBuffer(int entityType,
 
   // In our case the selection buffer size is equal to between 5 and 7
   // times the maximum number of possible hits
-  int eles = (meshSelection && CTX.pick_elements) ? 3 * GMODEL->numElement() : 0;
+  int eles = (meshSelection && CTX.pick_elements) ? 4 * GMODEL->numElement() : 0;
   int size = 7 * (GMODEL->numVertex() + GMODEL->numEdge() + GMODEL->numFace() + 
-		  GMODEL->numRegion() + eles) ;
+		  GMODEL->numRegion() + eles) + 1000 ;
 
   GLuint *selectionBuffer = new GLuint[size];
   glSelectBuffer(size, selectionBuffer);
@@ -90,7 +90,7 @@ bool ProcessSelectionBuffer(int entityType,
   }
   else if(numhits < 0){ // overflow
     delete [] selectionBuffer;
-    Msg(WARNING, "Selection buffer size exceeded");
+    Msg(WARNING, "Too many entities selected");
     return false;
   }
 
-- 
GitLab