Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYAcousticRectangleGraphic.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 
26 #include "gui/gl/TYRenderContext.h"
29 
30 #include <QtOpenGL>
31 #include <memory>
32 #include <qcolor.h>
33 #include <qnamespace.h>
34 #include <qsize.h>
35 
37  : TYElementGraphic(pElement)
38 {
39  // Construction d'un tableau 4x3 de doubles
40  std::array<std::array<double, 3>, 4> coords;
41  for (size_t i = 0; i < 4; ++i)
42  {
43  coords[i][0] = pElement->getShape()->_pts[i]._x;
44  coords[i][1] = pElement->getShape()->_pts[i]._y;
45  coords[i][2] = pElement->getShape()->_pts[i]._z;
46  }
47 
48  // Création du rectangle mesh avec ce tableau
49  _rectangleMesh = std::make_shared<OGLRectangleMesh>(coords);
51 }
52 
53 void TYAcousticRectangleGraphic::update(bool force /*=false*/)
54 {
56 
57  TYAcousticRectangle* pRectangle = TYAcousticRectangle::safeDownCast(getElement());
58  // Construction d'un tableau 4x3 de doubles
59  std::array<std::array<double, 3>, 4> coords;
60  for (size_t i = 0; i < 4; ++i)
61  {
62  coords[i][0] = pRectangle->getShape()->_pts[i]._x;
63  coords[i][1] = pRectangle->getShape()->_pts[i]._y;
64  coords[i][2] = pRectangle->getShape()->_pts[i]._z;
65  }
66  _rectangleMesh->setVertices(coords);
67 }
68 
70 {
71  TYElementGraphic* pTYElementGraphic = nullptr;
72  pTYElementGraphic = getElement()->getSrcSurf()->getGraphicObject();
73  childs.push_back(pTYElementGraphic);
74  if (recursif)
75  {
76  pTYElementGraphic->getChilds(childs, recursif);
77  }
78 
79  pTYElementGraphic = getElement()->getShape()->getGraphicObject();
80  childs.push_back(pTYElementGraphic);
81  if (recursif)
82  {
83  pTYElementGraphic->getChilds(childs, recursif);
84  }
85 }
86 
88 {
90 
91  boundingBox.Enlarge(getElement()->getSrcSurf()->getGraphicObject()->boundingBox());
92  boundingBox.Enlarge(getElement()->getShape()->getGraphicObject()->boundingBox());
93  return boundingBox;
94 }
95 
97 {
98  // CLM-NT35: En overlay, affiche seulement le nom de l'élément localisé
99  if (renderContext.pass == TYRenderPass::Overlay)
100  {
101  drawName(renderContext);
102  }
103  else
104  {
105  OColor color = getElement()->getColor();
106  color.a = 1.0;
107 
108 #if TY_USE_IHM
109  if (getElement()->getIsSub() && strcmp(getElement()->getClassName(), "TYMurElement") == 0)
110  {
111  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "WinOpacity"))
112  {
113  color.a = TYPreferenceManager::getDouble(TYDIRPREFERENCEMANAGER, "WinOpacity");
114  }
115  else
116  {
117  TYPreferenceManager::setDouble(TYDIRPREFERENCEMANAGER, "WinOpacity", color.a);
118  }
119  }
120 #endif // TY_USE_IHM
121 
122  if (_visible)
123  {
124  glColor4fv(color);
125 
126  getElement()->getSrcSurf()->getGraphicObject()->display(renderContext);
127  // getElement()->getShape()->setInCurrentCalcul(getElement()->isInCurrentCalcul());
128  // Update shape
129  if (renderContext.type == TYRenderType::Picking)
130  {
131  if ((getElement()->getIsSub()))
132  {
133  TYPickingTable::addElement(getElement());
134  glPushName((GLuint)(TYPickingTable::getIndex()));
135  }
136 
137  getElement()->getShape()->getGraphicObject()->display(renderContext);
138 
139  if ((getElement()->getIsSub()))
140  {
141  glPopName();
142  }
143  }
144  }
145  }
146 }
147 void TYAcousticRectangleGraphic::collectMeshInstances(std::vector<OGLMeshInstance>& meshInstances,
148  TYRenderContext* renderContext) const
149 {
150  if (renderContext && renderContext->showDistributedSources && getElement()->getIsRayonnant())
151  {
152  float r = 255.0f, g = 0.0f, b = 0.0f;
153 
154  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "SrcPonctGraphicColorR"))
155  {
156  TYPreferenceManager::getColor(TYDIRPREFERENCEMANAGER, "SrcPonctGraphicColor", r, g, b);
157  }
158  else
159  {
160  TYPreferenceManager::setColor(TYDIRPREFERENCEMANAGER, "SrcPonctGraphicColor", r, g, b);
161  }
162  _rectangleMesh->material().color = QColor(r, g, b);
163  }
164  else
165  {
166  _rectangleMesh->material().color = getElement()->getColor();
167  }
168  meshInstances.emplace_back(_rectangleMesh, globalMatrix());
169 }
Representation graphique d'un rectangle acoustique (fichier header)
list< TYElementGraphic * > TYListPtrTYElementGraphic
List de pointeur de TYElement.
#define TYDIRPREFERENCEMANAGER
Definition: TYElement.h:51
Gestion de la table de correspondance indice/element pour le picking (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.
Representation graphique d'une surface de source (fichier header)
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:36
float a
Definition: color.h:38
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
static OPrototype * safeDownCast(OPrototype *pObject)
Definition: TYElement.cpp:71
virtual void display(TYRenderContext &renderContext)
virtual void getChilds(TYListPtrTYElementGraphic &childs, bool recursif=true)
void collectMeshInstances(std::vector< OGLMeshInstance > &meshInstances, TYRenderContext *renderContext) const override
virtual void update(bool force=false)
std::shared_ptr< OGLRectangleMesh > _rectangleMesh
TYAcousticRectangleGraphic(TYAcousticRectangle *pElement)
TYRectangle * getShape()
classe graphique pour un element de base
void drawName(TYRenderContext &renderContext)
bool _visible
Inique si l'element est visible.
OBox boundingBox() const
virtual void update(bool force=false)
virtual void getChilds(TYListPtrTYElementGraphic &childs, bool recursif=true)
QMatrix4x4 globalMatrix() const
static int getIndex()
static void addElement(TYElement *pElt)
TYPoint _pts[4]
Sommets.
Definition: TYRectangle.h:274
TYRenderType type
TYRenderPass pass