Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYElementGraphic.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 
29 
30 #include "TYElementGraphic.h"
34 #include "models/common/3d.h"
35 #include <QtOpenGL>
36 #include <qvector3d.h>
37 
38 #define IMG(id) OLocalizator::getPicture("TYElementGraphic", (id))
39 
42 
44 {
45  _pElement = pElt;
46 
47  _modified = true;
48  _visible = true;
49  _highlight = false;
50  _texture = false;
51 
52  // Highlight
53  _viewOnlyHighlight = false;
54  _boundingBoxDirty = true;
55 }
56 
58 
60 {
61  _pElement = pElt;
62 }
63 
65 {
67  TYElement* pParent = _pElement->getParent();
68 
69  if (getModified() && pParent && pParent->getGraphicObject())
70  {
71  // On force la mise a jour du parent
72  pParent->setIsGeometryModified(true);
73  // On remonte l'arbre
74  pParent->getGraphicObject()->updateTree();
75  }
76  else
77  {
78  // On appelle la methode update surchargee par les objets graphiques
79  update();
80  }
81 }
82 
83 void TYElementGraphic::update(bool force /*=false*/)
84 {
86  if (_pElement)
87  {
89  {
91  }
92  else
93  {
94  _visible = false;
95  }
96  }
97 
98  // Update highlight seulement si actif
100 
101  // On repositionne le flag modified
102  setModified(false);
103 
104 #if TY_USE_IHM
105  // Emission du signal de notification de mise a jour
106  activateSignal();
107 #endif // TY_USE_IHM
108 }
109 
111 {
112  return _modified;
113 }
114 
115 void TYElementGraphic::setBoundingBoxVisible(bool state /*=true*/)
116 {
117  // Update
118  _highlight = state;
119 }
120 
122 {
123  OVector3D n = normal; // getElement()->_normale;
124  OPoint3D p2;
125  p2._x = p1._x + n._x;
126  p2._y = p1._y + n._y;
127  p2._z = p1._z + n._z;
128  glColor3f(1.0f, 0.5f, 0.0f);
129  glLineWidth(2);
130  glPointSize(4);
131 
132  glBegin(GL_LINE_STRIP);
133  glVertex3f(p1._x, p1._y, p1._z);
134  glVertex3f(p2._x, p2._y, p2._z);
135  glEnd();
136 }
137 
139 {
141  const TYGeometryNode* pGeoNode = TYGeometryNode::GetGeoNode(renderContext.modelerElement);
142  // pour déterminer la position du texte, il faut le centre de la boundingbox dans le repère du modeleur.
143  QVector3D origin;
144  float org[3];
145  OBox bBox = boundingBox();
146  org[0] = (bBox._min._x + bBox._max._x) / 2;
147  org[1] = (bBox._min._y + bBox._max._y) / 2;
148  org[2] = (bBox._min._z + bBox._max._z) / 2;
149  if (pThisGeoNode)
150  {
151  OMatrix mat;
152  if (pGeoNode != nullptr)
153  {
154  mat = pThisGeoNode->localToGeoNode(pGeoNode);
155  }
156  else
157  {
158  mat = pThisGeoNode->localToGlobal();
159  }
160 
161  origin = QVector3D(
162  org[0] * mat._m[0][0] + org[1] * mat._m[0][1] + org[2] * mat._m[0][2] + mat._m[0][3],
163  org[0] * mat._m[2][0] + org[1] * mat._m[2][1] + org[2] * mat._m[2][2] + mat._m[2][3],
164  -(org[0] * mat._m[1][0] + org[1] * mat._m[1][1] + org[2] * mat._m[1][2] + mat._m[1][3]));
165  }
166  else
167  {
168  origin = QVector3D(org[0], org[2], -org[1]);
169  }
170  QVector3D ret = renderContext.viewport.worldToDisplay(origin);
171 
172  // ajouter une etiquette avec le nom
173  OGLTextElement oOGLTextElement;
174  oOGLTextElement.setFont(IMG("id_font"));
175  oOGLTextElement.setVisibility(true);
176  if (_pElement)
177  {
178  oOGLTextElement.setTextToDisplay(_pElement->getName());
179  }
180  oOGLTextElement.setColor(OColor::BLACK);
181  oOGLTextElement.setDisplayPosition(ret.x() + 22, ret.y() + 40);
182  oOGLTextElement.render();
183 
184  OGLLineElement oglLineElement;
185  oglLineElement.setColor(OColor::BLACK);
186  oglLineElement.setLineWidth(2.0f);
187  oglLineElement.setPoint1(QVector3D(ret.x(), ret.y(), 0));
188  oglLineElement.setPoint2(QVector3D(ret.x() + 20, ret.y() + 40, 0));
189  oglLineElement.setVisibility(true);
190  oglLineElement.render();
191 }
192 
194 {
195  return _highlight;
196 }
197 
198 void TYElementGraphic::setOnlyBoundingBox(bool state /*=true*/)
199 {
200  _viewOnlyHighlight = state;
201 
202  // Active le highlight
204 }
205 
207 {
208 #if TY_USE_IHM
209  // Emission du signal de notification de mise a jour
210  activateSignal();
211 
212 #endif // TY_USE_IHM
213 }
214 
215 void TYElementGraphic::setRecursiveVisible(bool visible /*=true*/)
216 {
217  LPTYElementArray childs;
218 
219  _pElement->getChilds(childs);
220 
221  for (int i = 0; i < childs.size(); i++)
222  {
223  childs[i]->getGraphicObject()->setVisible(visible);
224  }
225 }
226 
228 {
229  if (_boundingBoxDirty)
230  {
232  _boundingBoxDirty = false;
233  }
234  return _boundingBox;
235 }
236 
238 {
239  OBox Box;
240 
242  getChilds(childs, false);
243  if (childs.size() > 0)
244  {
245  const TYElementGraphic* pChild = nullptr;
246  TYListPtrConstTYElementGraphic::iterator ite = childs.begin();
247  pChild = (*ite);
248  Box = OBox{pChild->boundingBox()};
249  ite++;
250  for (; ite != childs.end(); ite++)
251  {
252  pChild = (*ite);
253  if (pChild != nullptr)
254  {
255  Box.Enlarge(pChild->boundingBox());
256  }
257  }
258  }
259  return Box;
260 }
261 
263 {
264  TYElement* parent = getTYElement()->getParent();
265  if (parent != nullptr)
266  {
267  LPTYElementGraphic parentGraphicElement = parent->getGraphicObject();
268  if (parentGraphicElement != nullptr)
269  {
270  parentGraphicElement->invalidateBoundingBox();
271  }
272  }
273  LPTYElementArray children;
274  getTYElement()->getChilds(children, false);
275  LPTYElementGraphic childGraphicElement;
276  for (int i = 0; i < children.size(); i++)
277  {
278  childGraphicElement = children[i]->getGraphicObject();
279  if (childGraphicElement != nullptr)
280  {
281  childGraphicElement->_boundingBoxDirty = true;
282  }
283  }
284  this->_boundingBoxDirty = true;
285 }
All base classes related to 3D manipulation.
#define IMG(id)
Representation graphique d'un element de base (fichier header)
list< const TYElementGraphic * > TYListPtrConstTYElementGraphic
List de pointeur de TYElement.
std::vector< LPTYElement > LPTYElementArray
Definition: TYElement.h:344
Realise le rendu VTK et le rendu OpenGL (fichier header)
Contexte de rendu utilisé par les fonctions d'affichage.
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
OPoint3D _min
Minimal coordinates of the OBox.
Definition: 3d.h:1423
OPoint3D _max
Maximal coordinates of the OBox.
Definition: 3d.h:1424
static const OColor BLACK
Definition: color.h:86
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
void setVisibility(bool bVisible)
Definition: OGLElement.h:51
void setDisplayPosition(double displayPositionX, double displayPositionY)
Definition: OGLElement.h:46
void setPoint2(const QVector3D &point2)
void setColor(const OColor &oColor)
void setLineWidth(float lineWidth)
virtual int render()
void setPoint1(const QVector3D &point1)
virtual int render()
void setColor(const OColor &oColor)
void setTextToDisplay(const QString &qsText)
void setFont(const QString &qsFontPath)
The 4x4 matrix class.
Definition: 3d.h:625
double _m[4][4]
The 4x4 matrix array.
Definition: 3d.h:974
The 3D point class.
Definition: 3d.h:487
The 3D vector class.
Definition: 3d.h:298
classe graphique pour un element de base
bool _modified
Indique si l'element associe a ete modifie.
void setOnlyBoundingBox(bool state=true)
void drawName(TYRenderContext &renderContext)
bool _visible
Inique si l'element est visible.
void setModified(bool modified=true)
TYElement * getTYElement()
void setRecursiveVisible(bool visible=true)
static bool _gDrawNormals
Indique si les normals doivent etre visible.
bool _texture
Indique si le texturing est active pour cet element.
OBox boundingBox() const
void setBoundingBoxVisible(bool state=true)
TYElementGraphic(TYElement *pElt)
bool _highlight
Indique si le highlight est active pour cet element.
void displayNormal(OVector3D normal, OPoint3D p1)
virtual void update(bool force=false)
bool isBoundingBoxVisible() const
static bool _gDrawPlafond
Indique si les plafonds doivent etre visible.
virtual void getChilds(TYListPtrTYElementGraphic &childs, bool recursif=true)
virtual void display(TYRenderContext &renderContext)
void setElement(TYElement *pElt)
TYElement * _pElement
L'element metier auquel cet element graphique metier est associe.
virtual OBox computeBoundingBox() const
bool getModified() const
virtual ~TYElementGraphic()
bool _viewOnlyHighlight
Inique si on affiche la bounding box seule.
TYElement * getParent() const
Definition: TYElement.h:706
virtual bool isInCurrentCalcul()
Definition: TYElement.h:539
virtual QString getName() const
Definition: TYElement.h:691
virtual void getChilds(LPTYElementArray &childs, bool recursif=true)
Definition: TYElement.h:530
virtual void setIsGeometryModified(bool isModified)
Definition: TYElement.cpp:253
OMatrix localToGlobal() const
OMatrix localToGeoNode(const TYGeometryNode *pGeoNode) const
static TYGeometryNode * GetGeoNode(TYElement *pElement)
const TYRenderViewport viewport
TYElement *const modelerElement
QVector3D worldToDisplay(const QVector3D &world) const