Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYPolyLineGraphic.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 
23 #include "gui/gl/TYRenderContext.h"
24 #include <QtOpenGL>
25 
26 #include "TYPolyLineGraphic.h"
28 
29 TYPolyLineGraphic::TYPolyLineGraphic(bool closed /*=false*/) : TYElementGraphic(NULL), width(default_width_px)
30 {
31  _closed = closed;
32 }
33 
35 
36 void TYPolyLineGraphic::update(bool force /*=false*/)
37 {
39 }
40 
42 {
44  size_t nbPts = _tabPts.size();
45  if (nbPts > 0)
46  {
47  TYPoint pt{_tabPts[0 % nbPts]};
48  boundingBox = OBox{pt, pt};
49  for (size_t i = 1; i < nbPts; i++)
50  {
51  pt = TYPoint{_tabPts[i % nbPts]};
52  boundingBox.Enlarge((float)(pt._x), (float)(pt._y), (float)(pt._z));
53  }
54  }
55  return boundingBox;
56 }
58 {
59  size_t nbPts = _tabPts.size();
60  float colorTYPolyLineGraphic[4];
61  glGetFloatv(GL_CURRENT_COLOR, colorTYPolyLineGraphic);
62 
63  if (_highlight)
64  {
65  if (renderContext.pass == TYRenderPass::Overlay)
66  {
67  drawName(renderContext);
68  }
69  glColor3f(colorTYPolyLineGraphic[0], colorTYPolyLineGraphic[1], colorTYPolyLineGraphic[2]);
70  }
71 
72  if (_visible)
73  {
74  GLenum line_mode = 0;
75 
76  if (_closed)
77  {
78  line_mode = GL_LINE_LOOP;
79  }
80  else
81  {
82  line_mode = GL_LINE_STRIP;
83  }
84 
85  glLineWidth(width);
86 
87  glBegin(line_mode);
88 
89  for (size_t i = 0; i < nbPts; i++)
90  {
91  TYPoint pt(_tabPts[i % (_tabPts.size())]);
92  glVertex3f(pt._x, pt._y, pt._z);
93  }
94 
95  glEnd();
96  glColor3f(colorTYPolyLineGraphic[0], colorTYPolyLineGraphic[1], colorTYPolyLineGraphic[2]);
97  }
98 }
Representation graphique d'une polyligne (fichier header)
Contexte de rendu utilisé par les fonctions d'affichage.
@ 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
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)
TYPolyLineGraphic(bool closed=false)
virtual void update(bool force=false)
virtual OBox computeBoundingBox() const
virtual void display(TYRenderContext &renderContext)
float width
Line width - cf OpenGL doc for exact meaning.
TYRenderPass pass