~ubuntu-branches/ubuntu/karmic/gmsh/karmic

« back to all changes in this revision

Viewing changes to Graphics/SelectBuffer.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme, Christophe Prud'homme, Daniel Leidert
  • Date: 2008-05-18 12:46:05 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20080518124605-716xqbqeo07o497k
Tags: 2.2.0-2
[Christophe Prud'homme]
* Bug fix: "gmsh ships no .desktop", thanks to Vassilis Pandis (Closes:
  #375770). Applied the Ubuntu patch.

[Daniel Leidert]
* debian/control (Vcs-Svn): Fixed.
  (Build-Depends): Use texlive instead of tetex-bin.
* debian/gmsh.doc-base (Section): Fixed accordingly to doc-base (>= 0.8.10).
* debian/rules: Removed some variable declarations, that lead to double
  configuration and seem to be useless.
  (build/gmsh): Try to avoid multiple runs by using a stamp.
  (orig-tarball): Renamed to get-orig-source and changed to use uscan.
* debian/watch: Added.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// $Id: SelectBuffer.cpp,v 1.12 2007-02-04 15:59:18 geuzaine Exp $
 
1
// $Id: SelectBuffer.cpp,v 1.21 2008-03-20 11:44:08 geuzaine Exp $
2
2
//
3
 
// Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 
3
// Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle
4
4
//
5
5
// This program is free software; you can redistribute it and/or modify
6
6
// it under the terms of the GNU General Public License as published by
19
19
// 
20
20
// Please report all bugs and problems to <gmsh@geuz.org>.
21
21
 
22
 
#include "Gmsh.h"
 
22
#include "Message.h"
23
23
#include "GmshUI.h"
24
24
#include "GmshDefines.h"
 
25
#include "GModel.h"
 
26
#include "MElement.h"
25
27
#include "Draw.h"
26
28
#include "Context.h"
27
29
#include "SelectBuffer.h"
28
 
#include "GModel.h"
29
 
#include "MRep.h"
 
30
#include "VertexArray.h"
30
31
 
31
32
extern Context_T CTX;
32
 
extern GModel *GMODEL;
33
33
 
34
34
class hit{
35
35
public:
46
46
  }
47
47
};
48
48
 
 
49
// returns the element at a given position in a vertex array (element
 
50
// pointers are not always stored: returning 0 is not an error)
 
51
MElement *getElement(GEntity *e, int va_type, int index)
 
52
{
 
53
  switch(va_type){
 
54
  case 2: 
 
55
    if(e->va_lines && index < e->va_lines->getNumElementPointers())
 
56
      return *e->va_lines->getElementPointerArray(index);
 
57
    break;
 
58
  case 3:
 
59
    if(e->va_triangles && index < e->va_triangles->getNumElementPointers())
 
60
      return *e->va_triangles->getElementPointerArray(index);
 
61
    break;
 
62
  }
 
63
  return 0;
 
64
}
 
65
 
49
66
bool ProcessSelectionBuffer(int entityType,
50
 
                            bool multipleSelection, bool meshSelection,
51
 
                            int x, int y, int w, int h,
52
 
                            std::vector<GVertex*> &vertices,
53
 
                            std::vector<GEdge*> &edges,
54
 
                            std::vector<GFace*> &faces,
55
 
                            std::vector<GRegion*> &regions,
56
 
                            std::vector<MElement*> &elements)
 
67
                            bool multipleSelection, bool meshSelection,
 
68
                            int x, int y, int w, int h,
 
69
                            std::vector<GVertex*> &vertices,
 
70
                            std::vector<GEdge*> &edges,
 
71
                            std::vector<GFace*> &faces,
 
72
                            std::vector<GRegion*> &regions,
 
73
                            std::vector<MElement*> &elements)
57
74
{
58
75
  vertices.clear();
59
76
  edges.clear();
63
80
 
64
81
  // In our case the selection buffer size is equal to between 5 and 7
65
82
  // times the maximum number of possible hits
66
 
  int eles = (meshSelection && CTX.pick_elements) ? 4 * GMODEL->numElements() : 0;
67
 
  int size = 7 * (GMODEL->numVertex() + GMODEL->numEdge() + GMODEL->numFace() + 
68
 
                  GMODEL->numRegion() + eles) + 1000 ;
 
83
  GModel *m = GModel::current();
 
84
  int eles = (meshSelection && CTX.pick_elements) ? 4 * m->getNumMeshElements() : 0;
 
85
  int size = 7 * (m->getNumVertices() + m->getNumEdges() + m->getNumFaces() + 
 
86
                  m->getNumRegions() + eles) + 1000 ;
69
87
 
70
88
  GLuint *selectionBuffer = new GLuint[size];
71
89
  glSelectBuffer(size, selectionBuffer);
152
170
       (entityType == ENT_VOLUME && hits[i].type == 3)){
153
171
      switch (hits[i].type) {
154
172
      case 0:
155
 
        {
156
 
          GVertex *v = GMODEL->vertexByTag(hits[i].ient);
157
 
          if(!v){
158
 
            Msg(GERROR, "Problem in point selection processing");
159
 
            return false;
160
 
          }
161
 
          vertices.push_back(v);
162
 
          if(!multipleSelection) return true;
163
 
        }
164
 
        break;
 
173
        {
 
174
          GVertex *v = m->getVertexByTag(hits[i].ient);
 
175
          if(!v){
 
176
            Msg(GERROR, "Problem in point selection processing");
 
177
            return false;
 
178
          }
 
179
          vertices.push_back(v);
 
180
          if(!multipleSelection) return true;
 
181
        }
 
182
        break;
165
183
      case 1:
166
 
        {
167
 
          GEdge *e = GMODEL->edgeByTag(hits[i].ient);
168
 
          if(!e){
169
 
            Msg(GERROR, "Problem in line selection processing");
170
 
            return false;
171
 
          }
172
 
          if(hits[i].type2 && e->meshRep){
173
 
            MElement *ele = e->meshRep->getElement(hits[i].type2, hits[i].ient2);
174
 
            if(ele) elements.push_back(ele);
175
 
          }
176
 
          edges.push_back(e);
177
 
          if(!multipleSelection) return true;
178
 
        }
179
 
        break;
 
184
        {
 
185
          GEdge *e = m->getEdgeByTag(hits[i].ient);
 
186
          if(!e){
 
187
            Msg(GERROR, "Problem in line selection processing");
 
188
            return false;
 
189
          }
 
190
          if(hits[i].type2){
 
191
            MElement *ele = getElement(e, hits[i].type2, hits[i].ient2);
 
192
            if(ele) elements.push_back(ele);
 
193
          }
 
194
          edges.push_back(e);
 
195
          if(!multipleSelection) return true;
 
196
        }
 
197
        break;
180
198
      case 2:
181
 
        {
182
 
          GFace *f = GMODEL->faceByTag(hits[i].ient);
183
 
          if(!f){
184
 
            Msg(GERROR, "Problem in surface selection processing");
185
 
            return false;
186
 
          }
187
 
          if(hits[i].type2 && f->meshRep){
188
 
            MElement *ele = f->meshRep->getElement(hits[i].type2, hits[i].ient2);
189
 
            if(ele) elements.push_back(ele);
190
 
          }
191
 
          faces.push_back(f);
192
 
          if(!multipleSelection) return true;
193
 
        }
194
 
        break;
 
199
        {
 
200
          GFace *f = m->getFaceByTag(hits[i].ient);
 
201
          if(!f){
 
202
            Msg(GERROR, "Problem in surface selection processing");
 
203
            return false;
 
204
          }
 
205
          if(hits[i].type2){
 
206
            MElement *ele = getElement(f, hits[i].type2, hits[i].ient2);
 
207
            if(ele) elements.push_back(ele);
 
208
          }
 
209
          faces.push_back(f);
 
210
          if(!multipleSelection) return true;
 
211
        }
 
212
        break;
195
213
      case 3:
196
 
        {
197
 
          GRegion *r = GMODEL->regionByTag(hits[i].ient);
198
 
          if(!r){
199
 
            Msg(GERROR, "Problem in volume selection processing");
200
 
            return false;
201
 
          }
202
 
          if(hits[i].type2 && r->meshRep){
203
 
            MElement *ele = r->meshRep->getElement(hits[i].type2, hits[i].ient2);
204
 
            if(ele) elements.push_back(ele);
205
 
          }
206
 
          regions.push_back(r);
207
 
          if(!multipleSelection) return true;
208
 
        }
209
 
        break;
 
214
        {
 
215
          GRegion *r = m->getRegionByTag(hits[i].ient);
 
216
          if(!r){
 
217
            Msg(GERROR, "Problem in volume selection processing");
 
218
            return false;
 
219
          }
 
220
          if(hits[i].type2){
 
221
            MElement *ele = getElement(r, hits[i].type2, hits[i].ient2);
 
222
            if(ele) elements.push_back(ele);
 
223
          }
 
224
          regions.push_back(r);
 
225
          if(!multipleSelection) return true;
 
226
        }
 
227
        break;
210
228
      }
211
229
    }
212
230
  }
224
242
 
225
243
void HighlightEntityNum(int v, int c, int s, int r)
226
244
{
 
245
  GModel *m = GModel::current();
227
246
  if(v) {
228
 
    GVertex *pv = GMODEL->vertexByTag(v);
 
247
    GVertex *pv = m->getVertexByTag(v);
229
248
    if(pv) HighlightEntity(pv);
230
249
  }
231
250
  if(c) {
232
 
    GEdge *pc = GMODEL->edgeByTag(c);
 
251
    GEdge *pc = m->getEdgeByTag(c);
233
252
    if(pc) HighlightEntity(pc);
234
253
  }
235
254
  if(s) {
236
 
    GFace *ps = GMODEL->faceByTag(s);
 
255
    GFace *ps = m->getFaceByTag(s);
237
256
    if(ps) HighlightEntity(ps);
238
257
  }
239
258
  if(r) {
240
 
    GRegion *pr = GMODEL->regionByTag(r);
 
259
    GRegion *pr = m->getRegionByTag(r);
241
260
    if(pr) HighlightEntity(pr);
242
261
  }
243
262
}
257
276
 
258
277
void ZeroHighlightEntityNum(int v, int c, int s, int r)
259
278
{
 
279
  GModel *m = GModel::current();
260
280
  if(v) {
261
 
    GVertex *pv = GMODEL->vertexByTag(v);
 
281
    GVertex *pv = m->getVertexByTag(v);
262
282
    if(pv) ZeroHighlightEntity(pv);
263
283
  }
264
284
  if(c) {
265
 
    GEdge *pc = GMODEL->edgeByTag(c);
 
285
    GEdge *pc = m->getEdgeByTag(c);
266
286
    if(pc) ZeroHighlightEntity(pc);
267
287
  }
268
288
  if(s) {
269
 
    GFace *ps = GMODEL->faceByTag(s);
 
289
    GFace *ps = m->getFaceByTag(s);
270
290
    if(ps) ZeroHighlightEntity(ps);
271
291
  }
272
292
  if(r) {
273
 
    GRegion *pr = GMODEL->regionByTag(r);
 
293
    GRegion *pr = m->getRegionByTag(r);
274
294
    if(pr) ZeroHighlightEntity(pr);
275
295
  }
276
296
}
277
297
 
278
298
void ZeroHighlight()
279
299
{
280
 
  for(GModel::viter it = GMODEL->firstVertex(); it != GMODEL->lastVertex(); it++)
281
 
    ZeroHighlightEntity(*it);
282
 
  for(GModel::eiter it = GMODEL->firstEdge(); it != GMODEL->lastEdge(); it++)
283
 
    ZeroHighlightEntity(*it);
284
 
  for(GModel::fiter it = GMODEL->firstFace(); it != GMODEL->lastFace(); it++)
285
 
    ZeroHighlightEntity(*it);
286
 
  for(GModel::riter it = GMODEL->firstRegion(); it != GMODEL->lastRegion(); it++)
287
 
    ZeroHighlightEntity(*it);
288
 
 
289
 
  for(GModel::eiter it = GMODEL->firstEdge(); it != GMODEL->lastEdge(); it++){
 
300
  GModel *m = GModel::current();
 
301
 
 
302
  for(GModel::viter it = m->firstVertex(); it != m->lastVertex(); it++)
 
303
    ZeroHighlightEntity(*it);
 
304
  for(GModel::eiter it = m->firstEdge(); it != m->lastEdge(); it++)
 
305
    ZeroHighlightEntity(*it);
 
306
  for(GModel::fiter it = m->firstFace(); it != m->lastFace(); it++)
 
307
    ZeroHighlightEntity(*it);
 
308
  for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); it++)
 
309
    ZeroHighlightEntity(*it);
 
310
 
 
311
  for(GModel::eiter it = m->firstEdge(); it != m->lastEdge(); it++){
290
312
    for(unsigned int i = 0; i < (*it)->lines.size(); i++)
291
313
      if((*it)->lines[i]->getVisibility() == 2)
292
 
        (*it)->lines[i]->setVisibility(1);
 
314
        (*it)->lines[i]->setVisibility(1);
293
315
  }
294
 
  for(GModel::fiter it = GMODEL->firstFace(); it != GMODEL->lastFace(); it++){
 
316
  for(GModel::fiter it = m->firstFace(); it != m->lastFace(); it++){
295
317
    for(unsigned int i = 0; i < (*it)->triangles.size(); i++)
296
318
      if((*it)->triangles[i]->getVisibility() == 2)
297
 
        (*it)->triangles[i]->setVisibility(1);
 
319
        (*it)->triangles[i]->setVisibility(1);
298
320
    for(unsigned int i = 0; i < (*it)->quadrangles.size(); i++)
299
321
      if((*it)->quadrangles[i]->getVisibility() == 2) 
300
 
        (*it)->quadrangles[i]->setVisibility(1);
 
322
        (*it)->quadrangles[i]->setVisibility(1);
301
323
  }
302
 
  for(GModel::riter it = GMODEL->firstRegion(); it != GMODEL->lastRegion(); it++){
 
324
  for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); it++){
303
325
    for(unsigned int i = 0; i < (*it)->tetrahedra.size(); i++)
304
326
      if((*it)->tetrahedra[i]->getVisibility() == 2)
305
 
        (*it)->tetrahedra[i]->setVisibility(1);
 
327
        (*it)->tetrahedra[i]->setVisibility(1);
306
328
    for(unsigned int i = 0; i < (*it)->hexahedra.size(); i++)
307
329
      if((*it)->hexahedra[i]->getVisibility() == 2)
308
 
        (*it)->hexahedra[i]->setVisibility(1);
 
330
        (*it)->hexahedra[i]->setVisibility(1);
309
331
    for(unsigned int i = 0; i < (*it)->prisms.size(); i++)
310
332
      if((*it)->prisms[i]->getVisibility() == 2)
311
 
        (*it)->prisms[i]->setVisibility(1);
 
333
        (*it)->prisms[i]->setVisibility(1);
312
334
    for(unsigned int i = 0; i < (*it)->pyramids.size(); i++)
313
335
      if((*it)->pyramids[i]->getVisibility() == 2)
314
 
        (*it)->pyramids[i]->setVisibility(1);
 
336
        (*it)->pyramids[i]->setVisibility(1);
315
337
  }
316
338
  
317
339
}