Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYPointControlGraphic.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012> <EDF-R&D> <FRANCE>
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  * See the GNU General Public License for more details.
11  * You should have received a copy of the GNU General Public License along
12  * with this program; if not, write to the Free Software Foundation, Inc.,
13  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
14  */
15 
25 #include "TYPointControlGraphic.h"
26 
28 static const float PointControlGraphicDefaultSize = 2.0;
29 
31 {
32  setSize();
33 }
34 
36 
38 {
39  _size = PointControlGraphicDefaultSize;
40 
41 #if TY_USE_IHM
42  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "PointControlGraphicSize"))
43  {
44  _size = TYPreferenceManager::getFloat(TYDIRPREFERENCEMANAGER, "PointControlGraphicSize");
45  }
46  else
47  {
48  TYPreferenceManager::setFloat(TYDIRPREFERENCEMANAGER, "PointControlGraphicSize", _size);
49  }
50 #endif
51 }
52 
53 void TYPointControlGraphic::update(bool force /*=false*/)
54 {
56 }
57 
59 {
60  OBox reset;
61  _boundingBox = reset;
62  LPTYPointControl pPt = getElement();
63  if (pPt == NULL)
64  {
65  return;
66  }
67 
68  _boundingBox.Enlarge((float)(pPt->_x - _size / 2), (float)(pPt->_y - _size / 2),
69  (float)(pPt->_z - _size / 2));
70  _boundingBox.Enlarge((float)(pPt->_x + _size / 2), (float)(pPt->_y + _size / 2),
71  (float)(pPt->_z + _size / 2));
72 }
73 
74 void TYPointControlGraphic::display(TYElement* pModelerElement /*= nullptr*/, GLenum mode /*= GL_RENDER*/)
75 {
76  // Pas affiche si inactif
77  if (getElement()->etat() == false)
78  {
79  return;
80  }
81 
82  setSize();
83 
84  LPTYPointControl pPt = getElement();
85 
86  if (pPt == NULL)
87  {
88  return;
89  }
90 
91  OColor color = getElement()->getColor();
92 
93  int object = getElement()->getObject();
94 
95  if (_highlight)
96  {
97  OColor tmpColor;
98  glGetFloatv(GL_CURRENT_COLOR, tmpColor);
99  if (_bFirstDisp)
100  {
102  _bFirstDisp = false;
103  }
105  if (mode == GL_COMPILE)
106  {
107  drawName(pModelerElement);
108  }
109  // Modification de la couleur en GL_CURRENT_COLOR si _highlight.
110  glColor3fv(tmpColor);
111  }
112 
113  if (_visible)
114  {
115  if (mode == GL_SELECT)
116  {
117  TYPickingTable::addElement(getElement());
118  glPushName((GLuint)(TYPickingTable::getIndex()));
119  }
120 
121  glColor4fv(color);
122 
123  switch (object)
124  {
126  drawCube(pPt);
127  break;
129  drawPyramid(pPt);
130  break;
132  drawSphere(pPt);
133  break;
135  drawStar(pPt);
136  break;
137  default:
138  break;
139  }
140 
141  if (mode == GL_SELECT)
142  {
143  glPopName();
144  }
145  // Calcul du volume englobant pour le fit:
147  }
148 }
149 
151 {
152  glBegin(GL_QUADS);
153 
154  glNormal3f(0.0f, 1.0f, 0.0f);
155  glVertex3f(pPt->_x + _size / 2, pPt->_y + _size / 2, pPt->_z - _size / 2);
156  glVertex3f(pPt->_x - _size / 2, pPt->_y + _size / 2, pPt->_z - _size / 2);
157  glVertex3f(pPt->_x - _size / 2, pPt->_y + _size / 2, pPt->_z + _size / 2);
158  glVertex3f(pPt->_x + _size / 2, pPt->_y + _size / 2, pPt->_z + _size / 2);
159 
160  glNormal3f(0.0f, -1.0f, 0.0f);
161  glVertex3f(pPt->_x + _size / 2, pPt->_y - _size / 2, pPt->_z + _size / 2);
162  glVertex3f(pPt->_x - _size / 2, pPt->_y - _size / 2, pPt->_z + _size / 2);
163  glVertex3f(pPt->_x - _size / 2, pPt->_y - _size / 2, pPt->_z - _size / 2);
164  glVertex3f(pPt->_x + _size / 2, pPt->_y - _size / 2, pPt->_z - _size / 2);
165 
166  glNormal3f(0.0f, 0.0f, 1.0f);
167  glVertex3f(pPt->_x + _size / 2, pPt->_y + _size / 2, pPt->_z + _size / 2);
168  glVertex3f(pPt->_x - _size / 2, pPt->_y + _size / 2, pPt->_z + _size / 2);
169  glVertex3f(pPt->_x - _size / 2, pPt->_y - _size / 2, pPt->_z + _size / 2);
170  glVertex3f(pPt->_x + _size / 2, pPt->_y - _size / 2, pPt->_z + _size / 2);
171 
172  glNormal3f(0.0f, 0.0f, -1.0f);
173  glVertex3f(pPt->_x + _size / 2, pPt->_y - _size / 2, pPt->_z - _size / 2);
174  glVertex3f(pPt->_x - _size / 2, pPt->_y - _size / 2, pPt->_z - _size / 2);
175  glVertex3f(pPt->_x - _size / 2, pPt->_y + _size / 2, pPt->_z - _size / 2);
176  glVertex3f(pPt->_x + _size / 2, pPt->_y + _size / 2, pPt->_z - _size / 2);
177 
178  glNormal3f(-1.0f, 0.0f, 0.0f);
179  glVertex3f(pPt->_x - _size / 2, pPt->_y + _size / 2, pPt->_z + _size / 2);
180  glVertex3f(pPt->_x - _size / 2, pPt->_y + _size / 2, pPt->_z - _size / 2);
181  glVertex3f(pPt->_x - _size / 2, pPt->_y - _size / 2, pPt->_z - _size / 2);
182  glVertex3f(pPt->_x - _size / 2, pPt->_y - _size / 2, pPt->_z + _size / 2);
183 
184  glNormal3f(1.0f, 0.0f, 0.0f);
185  glVertex3f(pPt->_x + _size / 2, pPt->_y + _size / 2, pPt->_z - _size / 2);
186  glVertex3f(pPt->_x + _size / 2, pPt->_y + _size / 2, pPt->_z + _size / 2);
187  glVertex3f(pPt->_x + _size / 2, pPt->_y - _size / 2, pPt->_z + _size / 2);
188  glVertex3f(pPt->_x + _size / 2, pPt->_y - _size / 2, pPt->_z - _size / 2);
189 
190  glEnd();
191 }
192 
194 {
195  glBegin(GL_TRIANGLES);
196 
197  glNormal3f(0.0f, -1.0f, 0.5f);
198  glVertex3f(pPt->_x, pPt->_y, pPt->_z + _size / 2);
199  glVertex3f(pPt->_x - _size / 2, pPt->_y - _size / 2, pPt->_z - _size / 2);
200  glVertex3f(pPt->_x + _size / 2, pPt->_y - _size / 2, pPt->_z - _size / 2);
201 
202  glNormal3f(1.0f, 0.0f, 0.5f);
203  glVertex3f(pPt->_x, pPt->_y, pPt->_z + _size / 2);
204  glVertex3f(pPt->_x + _size / 2, pPt->_y - _size / 2, pPt->_z - _size / 2);
205  glVertex3f(pPt->_x + _size / 2, pPt->_y + _size / 2, pPt->_z - _size / 2);
206 
207  glNormal3f(0.0f, 1.0f, 0.5f);
208  glVertex3f(pPt->_x, pPt->_y, pPt->_z + _size / 2);
209  glVertex3f(pPt->_x + _size / 2, pPt->_y + _size / 2, pPt->_z - _size / 2);
210  glVertex3f(pPt->_x - _size / 2, pPt->_y + _size / 2, pPt->_z - _size / 2);
211 
212  glNormal3f(-1.0f, 0.0f, 0.5f);
213  glVertex3f(pPt->_x, pPt->_y, pPt->_z + _size / 2);
214  glVertex3f(pPt->_x - _size / 2, pPt->_y + _size / 2, pPt->_z - _size / 2);
215  glVertex3f(pPt->_x - _size / 2, pPt->_y - _size / 2, pPt->_z - _size / 2);
216 
217  glEnd();
218 
219  glBegin(GL_QUADS);
220 
221  glNormal3f(0.0f, 0.0f, -1.0f);
222  glVertex3f(pPt->_x + _size / 2, pPt->_y - _size / 2, pPt->_z - _size / 2);
223  glVertex3f(pPt->_x - _size / 2, pPt->_y - _size / 2, pPt->_z - _size / 2);
224  glVertex3f(pPt->_x - _size / 2, pPt->_y + _size / 2, pPt->_z - _size / 2);
225  glVertex3f(pPt->_x + _size / 2, pPt->_y + _size / 2, pPt->_z - _size / 2);
226 
227  glEnd();
228 }
229 
231 {
232  GLUquadricObj* qobj = gluNewQuadric();
233  glTranslatef(pPt->_x, pPt->_y, pPt->_z);
234  gluSphere(qobj, _size / 2.0f, 20, 20);
235  glTranslatef(-pPt->_x, -pPt->_y, -pPt->_z);
236  gluDeleteQuadric(qobj);
237 }
238 
240 {
241  glBegin(GL_TRIANGLES);
242 
243  // Up pyramid
244  glNormal3f(0.0f, -1.0f, 0.5f);
245  glVertex3f(pPt->_x, pPt->_y, pPt->_z + _size / 2);
246  glVertex3f(pPt->_x - _size / 6, pPt->_y - _size / 6, pPt->_z + _size / 6);
247  glVertex3f(pPt->_x + _size / 6, pPt->_y - _size / 6, pPt->_z + _size / 6);
248 
249  glNormal3f(1.0f, 0.0f, 0.5f);
250  glVertex3f(pPt->_x, pPt->_y, pPt->_z + _size / 2);
251  glVertex3f(pPt->_x + _size / 6, pPt->_y - _size / 6, pPt->_z + _size / 6);
252  glVertex3f(pPt->_x + _size / 6, pPt->_y + _size / 6, pPt->_z + _size / 6);
253 
254  glNormal3f(0.0f, 1.0f, 0.5f);
255  glVertex3f(pPt->_x, pPt->_y, pPt->_z + _size / 2);
256  glVertex3f(pPt->_x + _size / 6, pPt->_y + _size / 6, pPt->_z + _size / 6);
257  glVertex3f(pPt->_x - _size / 6, pPt->_y + _size / 6, pPt->_z + _size / 6);
258 
259  glNormal3f(-1.0f, 0.0f, 0.5f);
260  glVertex3f(pPt->_x, pPt->_y, pPt->_z + _size / 2);
261  glVertex3f(pPt->_x - _size / 6, pPt->_y + _size / 6, pPt->_z + _size / 6);
262  glVertex3f(pPt->_x - _size / 6, pPt->_y - _size / 6, pPt->_z + _size / 6);
263 
264  // Right pyramid
265  glNormal3f(0.5f, -1.0f, 0.0f);
266  glVertex3f(pPt->_x + _size / 2, pPt->_y, pPt->_z);
267  glVertex3f(pPt->_x + _size / 6, pPt->_y - _size / 6, pPt->_z + _size / 6);
268  glVertex3f(pPt->_x + _size / 6, pPt->_y - _size / 6, pPt->_z - _size / 6);
269 
270  glNormal3f(0.5f, 0.0f, -1.0f);
271  glVertex3f(pPt->_x + _size / 2, pPt->_y, pPt->_z);
272  glVertex3f(pPt->_x + _size / 6, pPt->_y - _size / 6, pPt->_z - _size / 6);
273  glVertex3f(pPt->_x + _size / 6, pPt->_y + _size / 6, pPt->_z - _size / 6);
274 
275  glNormal3f(0.5f, 1.0f, 0.0f);
276  glVertex3f(pPt->_x + _size / 2, pPt->_y, pPt->_z);
277  glVertex3f(pPt->_x + _size / 6, pPt->_y + _size / 6, pPt->_z - _size / 6);
278  glVertex3f(pPt->_x + _size / 6, pPt->_y + _size / 6, pPt->_z + _size / 6);
279 
280  glNormal3f(0.5f, 0.0f, 1.0f);
281  glVertex3f(pPt->_x + _size / 2, pPt->_y, pPt->_z);
282  glVertex3f(pPt->_x + _size / 6, pPt->_y + _size / 6, pPt->_z + _size / 6);
283  glVertex3f(pPt->_x + _size / 6, pPt->_y - _size / 6, pPt->_z + _size / 6);
284 
285  // Down pyramid
286  glNormal3f(0.0f, 1.0f, 0.5f);
287  glVertex3f(pPt->_x, pPt->_y, pPt->_z - _size / 2);
288  glVertex3f(pPt->_x - _size / 6, pPt->_y - _size / 6, pPt->_z - _size / 6);
289  glVertex3f(pPt->_x + _size / 6, pPt->_y - _size / 6, pPt->_z - _size / 6);
290 
291  glNormal3f(-1.0f, 0.0f, 0.5f);
292  glVertex3f(pPt->_x, pPt->_y, pPt->_z - _size / 2);
293  glVertex3f(pPt->_x + _size / 6, pPt->_y - _size / 6, pPt->_z - _size / 6);
294  glVertex3f(pPt->_x + _size / 6, pPt->_y + _size / 6, pPt->_z - _size / 6);
295 
296  glNormal3f(0.0f, -1.0f, 0.5f);
297  glVertex3f(pPt->_x, pPt->_y, pPt->_z - _size / 2);
298  glVertex3f(pPt->_x + _size / 6, pPt->_y + _size / 6, pPt->_z - _size / 6);
299  glVertex3f(pPt->_x - _size / 6, pPt->_y + _size / 6, pPt->_z - _size / 6);
300 
301  glNormal3f(1.0f, 0.0f, 0.5f);
302  glVertex3f(pPt->_x, pPt->_y, pPt->_z - _size / 2);
303  glVertex3f(pPt->_x - _size / 6, pPt->_y + _size / 6, pPt->_z - _size / 6);
304  glVertex3f(pPt->_x - _size / 6, pPt->_y - _size / 6, pPt->_z - _size / 6);
305 
306  // Left pyramid
307  glNormal3f(0.5f, 1.0f, 0.0f);
308  glVertex3f(pPt->_x - _size / 2, pPt->_y, pPt->_z);
309  glVertex3f(pPt->_x - _size / 6, pPt->_y - _size / 6, pPt->_z + _size / 6);
310  glVertex3f(pPt->_x - _size / 6, pPt->_y - _size / 6, pPt->_z - _size / 6);
311 
312  glNormal3f(0.5f, 0.0f, 1.0f);
313  glVertex3f(pPt->_x - _size / 2, pPt->_y, pPt->_z);
314  glVertex3f(pPt->_x - _size / 6, pPt->_y - _size / 6, pPt->_z - _size / 6);
315  glVertex3f(pPt->_x - _size / 6, pPt->_y + _size / 6, pPt->_z - _size / 6);
316 
317  glNormal3f(0.5f, -1.0f, 0.0f);
318  glVertex3f(pPt->_x - _size / 2, pPt->_y, pPt->_z);
319  glVertex3f(pPt->_x - _size / 6, pPt->_y + _size / 6, pPt->_z - _size / 6);
320  glVertex3f(pPt->_x - _size / 6, pPt->_y + _size / 6, pPt->_z + _size / 6);
321 
322  glNormal3f(0.5f, 0.0f, -1.0f);
323  glVertex3f(pPt->_x - _size / 2, pPt->_y, pPt->_z);
324  glVertex3f(pPt->_x - _size / 6, pPt->_y + _size / 6, pPt->_z + _size / 6);
325  glVertex3f(pPt->_x - _size / 6, pPt->_y - _size / 6, pPt->_z + _size / 6);
326 
327  // Back pyramid
328  glNormal3f(0.0f, 0.5f, 1.0f);
329  glVertex3f(pPt->_x, pPt->_y + _size / 2, pPt->_z);
330  glVertex3f(pPt->_x - _size / 6, pPt->_y + _size / 6, pPt->_z + _size / 6);
331  glVertex3f(pPt->_x + _size / 6, pPt->_y + _size / 6, pPt->_z + _size / 6);
332 
333  glNormal3f(1.0f, 0.5f, 0.0f);
334  glVertex3f(pPt->_x, pPt->_y + _size / 2, pPt->_z);
335  glVertex3f(pPt->_x + _size / 6, pPt->_y + _size / 6, pPt->_z + _size / 6);
336  glVertex3f(pPt->_x + _size / 6, pPt->_y + _size / 6, pPt->_z - _size / 6);
337 
338  glNormal3f(0.0f, 0.5f, -1.0f);
339  glVertex3f(pPt->_x, pPt->_y + _size / 2, pPt->_z);
340  glVertex3f(pPt->_x + _size / 6, pPt->_y + _size / 6, pPt->_z - _size / 6);
341  glVertex3f(pPt->_x - _size / 6, pPt->_y + _size / 6, pPt->_z - _size / 6);
342 
343  glNormal3f(-1.0f, 0.5f, 0.0f);
344  glVertex3f(pPt->_x, pPt->_y + _size / 2, pPt->_z);
345  glVertex3f(pPt->_x - _size / 6, pPt->_y + _size / 6, pPt->_z - _size / 6);
346  glVertex3f(pPt->_x - _size / 6, pPt->_y + _size / 6, pPt->_z + _size / 6);
347 
348  // Front pyramid
349  glNormal3f(0.0f, 0.5f, -1.0f);
350  glVertex3f(pPt->_x, pPt->_y - _size / 2, pPt->_z);
351  glVertex3f(pPt->_x - _size / 6, pPt->_y - _size / 6, pPt->_z + _size / 6);
352  glVertex3f(pPt->_x + _size / 6, pPt->_y - _size / 6, pPt->_z + _size / 6);
353 
354  glNormal3f(-1.0f, 0.5f, 0.0f);
355  glVertex3f(pPt->_x, pPt->_y - _size / 2, pPt->_z);
356  glVertex3f(pPt->_x + _size / 6, pPt->_y - _size / 6, pPt->_z + _size / 6);
357  glVertex3f(pPt->_x + _size / 6, pPt->_y - _size / 6, pPt->_z - _size / 6);
358 
359  glNormal3f(0.0f, 0.5f, 1.0f);
360  glVertex3f(pPt->_x, pPt->_y - _size / 2, pPt->_z);
361  glVertex3f(pPt->_x + _size / 6, pPt->_y - _size / 6, pPt->_z - _size / 6);
362  glVertex3f(pPt->_x - _size / 6, pPt->_y - _size / 6, pPt->_z - _size / 6);
363 
364  glNormal3f(1.0f, 0.5f, 0.0f);
365  glVertex3f(pPt->_x, pPt->_y - _size / 2, pPt->_z);
366  glVertex3f(pPt->_x - _size / 6, pPt->_y - _size / 6, pPt->_z - _size / 6);
367  glVertex3f(pPt->_x - _size / 6, pPt->_y - _size / 6, pPt->_z + _size / 6);
368 
369  glEnd();
370 }
#define TYDIRPREFERENCEMANAGER
Definition: TYElement.h:52
Gestion de la table de correspondance indice/element pour le picking (fichier header)
Representation graphique d'un point de controle (fichier header)
The box class.
Definition: 3d.h:1294
virtual void Enlarge(const OPoint3D &pt)
Enlarge the box with the point if the point is outside the box.
Definition: 3d.cpp:1614
Definition: color.h:31
double _y
y coordinate of OCoord3D
Definition: 3d.h:283
double _z
z coordinate of OCoord3D
Definition: 3d.h:284
double _x
x coordinate of OCoord3D
Definition: 3d.h:282
classe graphique pour un element de base
void drawName(TYElement *pModelerElement=nullptr)
static OBox _globalBoundingBox
bool _visible
Inique si l'element est visible.
bool _highlight
Indique si le highlight est active pour cet element.
virtual void update(bool force=false)
static int getIndex()
static void addElement(TYElement *pElt)
virtual void update(bool force=false)
TYPointControlGraphic(TYPointControl *pElement)
void drawPyramid(TYPointControl *pPt) const
void drawSphere(TYPointControl *pPt) const
void drawStar(TYPointControl *pPt) const
virtual void display(TYElement *pModelerElement=nullptr, GLenum mode=GL_RENDER)
void drawCube(TYPointControl *pPt) const
Classe de definition d'un point de controle.Le point de controle est un point de calcul avec une haut...