Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYPointControlGraphic.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012-2024> <EDF-DTG> <FRANCE>
3  * This file is part of Code_TYMPAN (R).
4  * Code_TYMPAN (R) is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * Code_TYMPAN (R) is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  * You should have received a copy of the GNU General Public License along
13  * with Code_TYMPAN (R). If not, see <https://www.gnu.org/licenses/>.
14  */
15 
21 #include "gui/gl/TYRenderContext.h"
22 #include <QtOpenGL>
23 
28 #include "TYPointControlGraphic.h"
29 
31 static const float PointControlGraphicDefaultSize = 2.0;
32 
34 {
35  setSize();
36 }
37 
39 
41 {
42  _size = PointControlGraphicDefaultSize;
43 
44 #if TY_USE_IHM
45  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "PointControlGraphicSize"))
46  {
47  _size = TYPreferenceManager::getFloat(TYDIRPREFERENCEMANAGER, "PointControlGraphicSize");
48  }
49  else
50  {
51  TYPreferenceManager::setFloat(TYDIRPREFERENCEMANAGER, "PointControlGraphicSize", _size);
52  }
53 #endif
54 }
55 
56 void TYPointControlGraphic::update(bool force /*=false*/)
57 {
59 }
60 
62 {
64  LPTYPointControl pPt = getElement();
65  if (pPt == NULL)
66  {
67  return boundingBox;
68  }
69 
70  boundingBox.Enlarge((float)(pPt->_x - _size / 2), (float)(pPt->_y - _size / 2),
71  (float)(pPt->_z - _size / 2));
72  boundingBox.Enlarge((float)(pPt->_x + _size / 2), (float)(pPt->_y + _size / 2),
73  (float)(pPt->_z + _size / 2));
74  return boundingBox;
75 }
76 
78 {
79  // Pas affiche si inactif
80  if (getElement()->etat() == false)
81  {
82  return;
83  }
84 
85  setSize();
86 
87  LPTYPointControl pPt = getElement();
88 
89  if (pPt == NULL)
90  {
91  return;
92  }
93 
94  OColor color = getElement()->getColor();
95 
96  int object = getElement()->getObject();
97 
98  if (_highlight && _visible)
99  {
100  OColor tmpColor;
101  glGetFloatv(GL_CURRENT_COLOR, tmpColor);
102  if (renderContext.pass == TYRenderPass::Overlay)
103  {
104  drawName(renderContext);
105  }
106  // Modification de la couleur en GL_CURRENT_COLOR si _highlight.
107  glColor3fv(tmpColor);
108  }
109 
110  if (_visible)
111  {
112  if (renderContext.type == TYRenderType::Picking)
113  {
114  TYPickingTable::addElement(getElement());
115  glPushName((GLuint)(TYPickingTable::getIndex()));
116  }
117 
118  glColor4fv(color);
119 
120  switch (object)
121  {
123  drawCube(pPt);
124  break;
126  drawPyramid(pPt);
127  break;
129  drawSphere(pPt);
130  break;
132  drawStar(pPt);
133  break;
134  default:
135  break;
136  }
137 
138  if (renderContext.type == TYRenderType::Picking)
139  {
140  glPopName();
141  }
142  }
143 }
144 
146 {
147  glBegin(GL_QUADS);
148 
149  glNormal3f(0.0f, 1.0f, 0.0f);
150  glVertex3f(pPt->_x + _size / 2, pPt->_y + _size / 2, pPt->_z - _size / 2);
151  glVertex3f(pPt->_x - _size / 2, pPt->_y + _size / 2, pPt->_z - _size / 2);
152  glVertex3f(pPt->_x - _size / 2, pPt->_y + _size / 2, pPt->_z + _size / 2);
153  glVertex3f(pPt->_x + _size / 2, pPt->_y + _size / 2, pPt->_z + _size / 2);
154 
155  glNormal3f(0.0f, -1.0f, 0.0f);
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  glVertex3f(pPt->_x + _size / 2, pPt->_y - _size / 2, pPt->_z - _size / 2);
160 
161  glNormal3f(0.0f, 0.0f, 1.0f);
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  glVertex3f(pPt->_x + _size / 2, pPt->_y - _size / 2, pPt->_z + _size / 2);
166 
167  glNormal3f(0.0f, 0.0f, -1.0f);
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  glVertex3f(pPt->_x + _size / 2, pPt->_y + _size / 2, pPt->_z - _size / 2);
172 
173  glNormal3f(-1.0f, 0.0f, 0.0f);
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  glVertex3f(pPt->_x - _size / 2, pPt->_y - _size / 2, pPt->_z + _size / 2);
178 
179  glNormal3f(1.0f, 0.0f, 0.0f);
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  glVertex3f(pPt->_x + _size / 2, pPt->_y - _size / 2, pPt->_z - _size / 2);
184 
185  glEnd();
186 }
187 
189 {
190  glBegin(GL_TRIANGLES);
191 
192  glNormal3f(0.0f, -1.0f, 0.5f);
193  glVertex3f(pPt->_x, pPt->_y, pPt->_z + _size / 2);
194  glVertex3f(pPt->_x - _size / 2, pPt->_y - _size / 2, pPt->_z - _size / 2);
195  glVertex3f(pPt->_x + _size / 2, pPt->_y - _size / 2, pPt->_z - _size / 2);
196 
197  glNormal3f(1.0f, 0.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(0.0f, 1.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(-1.0f, 0.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  glEnd();
213 
214  glBegin(GL_QUADS);
215 
216  glNormal3f(0.0f, 0.0f, -1.0f);
217  glVertex3f(pPt->_x + _size / 2, pPt->_y - _size / 2, pPt->_z - _size / 2);
218  glVertex3f(pPt->_x - _size / 2, pPt->_y - _size / 2, pPt->_z - _size / 2);
219  glVertex3f(pPt->_x - _size / 2, pPt->_y + _size / 2, pPt->_z - _size / 2);
220  glVertex3f(pPt->_x + _size / 2, pPt->_y + _size / 2, pPt->_z - _size / 2);
221 
222  glEnd();
223 }
224 
226 {
227  GLUquadricObj* qobj = gluNewQuadric();
228  glTranslatef(pPt->_x, pPt->_y, pPt->_z);
229  gluSphere(qobj, _size / 2.0f, 20, 20);
230  glTranslatef(-pPt->_x, -pPt->_y, -pPt->_z);
231  gluDeleteQuadric(qobj);
232 }
233 
235 {
236  glBegin(GL_TRIANGLES);
237 
238  // Up pyramid
239  glNormal3f(0.0f, -1.0f, 0.5f);
240  glVertex3f(pPt->_x, pPt->_y, pPt->_z + _size / 2);
241  glVertex3f(pPt->_x - _size / 6, pPt->_y - _size / 6, pPt->_z + _size / 6);
242  glVertex3f(pPt->_x + _size / 6, pPt->_y - _size / 6, pPt->_z + _size / 6);
243 
244  glNormal3f(1.0f, 0.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(0.0f, 1.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(-1.0f, 0.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  // Right pyramid
260  glNormal3f(0.5f, -1.0f, 0.0f);
261  glVertex3f(pPt->_x + _size / 2, pPt->_y, pPt->_z);
262  glVertex3f(pPt->_x + _size / 6, pPt->_y - _size / 6, pPt->_z + _size / 6);
263  glVertex3f(pPt->_x + _size / 6, pPt->_y - _size / 6, pPt->_z - _size / 6);
264 
265  glNormal3f(0.5f, 0.0f, -1.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, 1.0f, 0.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, 0.0f, 1.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  // Down pyramid
281  glNormal3f(0.0f, 1.0f, 0.5f);
282  glVertex3f(pPt->_x, pPt->_y, pPt->_z - _size / 2);
283  glVertex3f(pPt->_x - _size / 6, pPt->_y - _size / 6, pPt->_z - _size / 6);
284  glVertex3f(pPt->_x + _size / 6, pPt->_y - _size / 6, pPt->_z - _size / 6);
285 
286  glNormal3f(-1.0f, 0.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(0.0f, -1.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(1.0f, 0.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  // Left pyramid
302  glNormal3f(0.5f, 1.0f, 0.0f);
303  glVertex3f(pPt->_x - _size / 2, pPt->_y, pPt->_z);
304  glVertex3f(pPt->_x - _size / 6, pPt->_y - _size / 6, pPt->_z + _size / 6);
305  glVertex3f(pPt->_x - _size / 6, pPt->_y - _size / 6, pPt->_z - _size / 6);
306 
307  glNormal3f(0.5f, 0.0f, 1.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, -1.0f, 0.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, 0.0f, -1.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  // Back pyramid
323  glNormal3f(0.0f, 0.5f, 1.0f);
324  glVertex3f(pPt->_x, pPt->_y + _size / 2, pPt->_z);
325  glVertex3f(pPt->_x - _size / 6, pPt->_y + _size / 6, pPt->_z + _size / 6);
326  glVertex3f(pPt->_x + _size / 6, pPt->_y + _size / 6, pPt->_z + _size / 6);
327 
328  glNormal3f(1.0f, 0.5f, 0.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(0.0f, 0.5f, -1.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(-1.0f, 0.5f, 0.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  // Front pyramid
344  glNormal3f(0.0f, 0.5f, -1.0f);
345  glVertex3f(pPt->_x, pPt->_y - _size / 2, pPt->_z);
346  glVertex3f(pPt->_x - _size / 6, pPt->_y - _size / 6, pPt->_z + _size / 6);
347  glVertex3f(pPt->_x + _size / 6, pPt->_y - _size / 6, pPt->_z + _size / 6);
348 
349  glNormal3f(-1.0f, 0.5f, 0.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(0.0f, 0.5f, 1.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(1.0f, 0.5f, 0.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  glEnd();
365 }
#define TYDIRPREFERENCEMANAGER
Definition: TYElement.h:51
Gestion de la table de correspondance indice/element pour le picking (fichier header)
Representation graphique d'un point de controle (fichier header)
Contexte de rendu utilisé par les fonctions d'affichage.
@ Picking
The current render is only done for picking purpose.
@ Overlay
The current render pass is for overlay elements.
The box class.
Definition: 3d.h:1346
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(TYRenderContext &renderContext)
bool _visible
Inique si l'element est visible.
OBox boundingBox() const
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 OBox computeBoundingBox() const
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(TYRenderContext &renderContext)
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...
const TYRenderType type
const TYRenderPass pass