- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject.cpp
r0aa122 r3927ef 42 42 #include "CodePatterns/MemDebug.hpp" 43 43 44 QGLMaterial *GLMoleculeObject::m_hoverMaterial = NULL; 45 QGLMaterial *GLMoleculeObject::m_selectionMaterial = NULL; 46 QGLMaterial *GLMoleculeObject::m_selectionBoxMaterial = NULL; 47 44 48 45 49 GLMoleculeObject::GLMoleculeObject(QGLSceneNode *GLMoleculeObject, QObject *parent) 46 50 : QObject(parent) 47 51 { 48 m_mesh = 0; 49 m_GLMoleculeObject = GLMoleculeObject; 52 m_mesh = GLMoleculeObject; 50 53 m_scale = 1.0f; 54 m_scaleZ = 1.0f; 51 55 m_rotationAngle = 0.0f; 52 56 m_effect = 0; 53 57 m_objectId = -1; 54 58 m_hovering = false; 59 m_selected = false; 55 60 m_material = 0; 56 m_hoverMaterial = 0;61 initStaticMaterials(); 57 62 } 58 63 … … 61 66 { 62 67 scene->setParent(this); 63 m_mesh = 0; 64 m_GLMoleculeObject = scene->mainNode(); 68 m_mesh = scene->mainNode(); 65 69 m_scale = 1.0f; 70 m_scaleZ = 1.0f; 66 71 m_rotationAngle = 0.0f; 67 72 m_effect = 0; 68 73 m_objectId = -1; 69 74 m_hovering = false; 75 m_selected = false; 70 76 m_material = 0; 71 m_hoverMaterial = 0;77 initStaticMaterials(); 72 78 } 73 79 74 80 GLMoleculeObject::~GLMoleculeObject() 75 81 { 76 delete m_mesh;77 82 } 78 83 … … 82 87 if (m_objectId != -1) 83 88 view->registerObject(m_objectId, this); 89 } 90 91 92 /** Draws a box around the mesh. 93 * 94 */ 95 void GLMoleculeObject::drawSelectionBox(QGLPainter *painter) 96 { 97 painter->setFaceMaterial(QGL::AllFaces, m_selectionBoxMaterial); 98 QVector3DArray array; 99 qreal radius = 1.0; 100 array.append(-radius, -radius, -radius); array.append( radius, -radius, -radius); 101 array.append( radius, -radius, -radius); array.append( radius, radius, -radius); 102 array.append( radius, radius, -radius); array.append(-radius, radius, -radius); 103 array.append(-radius, radius, -radius); array.append(-radius, -radius, -radius); 104 105 array.append(-radius, -radius, radius); array.append( radius, -radius, radius); 106 array.append( radius, -radius, radius); array.append( radius, radius, radius); 107 array.append( radius, radius, radius); array.append(-radius, radius, radius); 108 array.append(-radius, radius, radius); array.append(-radius, -radius, radius); 109 110 array.append(-radius, -radius, -radius); array.append(-radius, -radius, radius); 111 array.append( radius, -radius, -radius); array.append( radius, -radius, radius); 112 array.append(-radius, radius, -radius); array.append(-radius, radius, radius); 113 array.append( radius, radius, -radius); array.append( radius, radius, radius); 114 painter->clearAttributes(); 115 painter->setVertexAttribute(QGL::Position, array); 116 painter->draw(QGL::Lines, 24); 84 117 } 85 118 … … 93 126 if (m_rotationAngle != 0.0f) 94 127 painter->modelViewMatrix().rotate(m_rotationAngle, m_rotationVector); 128 if (m_scaleZ != 1.0f) 129 painter->modelViewMatrix().scale(1.0f, 1.0f, m_scaleZ); 95 130 96 131 // Apply the material and effect to the painter. … … 98 133 if (m_hovering) 99 134 material = m_hoverMaterial; 135 else if (m_selected) 136 material = m_selectionMaterial; 100 137 else 101 138 material = m_material; 139 140 ASSERT(material, "GLMoleculeObject::draw: chosen material is NULL"); 141 102 142 painter->setColor(material->diffuseColor()); 103 143 painter->setFaceMaterial(QGL::AllFaces, material); … … 113 153 114 154 // Draw the geometry mesh. 115 if (m_GLMoleculeObject) 116 m_GLMoleculeObject->draw(painter); 117 else 118 m_mesh->draw(painter); 155 m_mesh->draw(painter); 156 157 // Draw a box around the mesh, if selected. 158 if (m_selected) 159 drawSelectionBox(painter); 119 160 120 161 // Turn off the user effect, if present. … … 164 205 QGLMaterial* GLMoleculeObject::getMaterial(size_t no) 165 206 { 166 ASSERT( (no > =0) && (no < MAX_ELEMENTS),207 ASSERT( (no > 0) && (no < MAX_ELEMENTS), 167 208 "GLMoleculeView::getMaterial() - Element no "+toString(no)+" is invalid."); 168 209 if (ElementNoMaterialMap.find(no) != ElementNoMaterialMap.end()){ … … 174 215 QGLMaterial *newmaterial = new QGLMaterial(NULL); 175 216 176 if (no == 0) { // create hover material 177 newmaterial->setAmbientColor( QColor(0, 128, 128) ); 178 } else { // create material for element 179 periodentafel *periode = World::getInstance().getPeriode(); 180 const element *desiredelement = periode->FindElement(no); 181 ASSERT(desiredelement != NULL, 182 "GLMoleculeView::getMaterial() - desired element "+toString(no)+" not present in periodentafel."); 183 const unsigned char* color = desiredelement->getColor(); 184 LOG(1, "Creating new material with color " << (int)color[0] << "," << (int)color[1] << "," << (int)color[2] << "."); 185 newmaterial->setAmbientColor( QColor((int)color[0], (int)color[1], (int)color[2]) ); 186 } 217 // create material for element 218 periodentafel *periode = World::getInstance().getPeriode(); 219 const element *desiredelement = periode->FindElement(no); 220 ASSERT(desiredelement != NULL, 221 "GLMoleculeView::getMaterial() - desired element "+toString(no)+" not present in periodentafel."); 222 const unsigned char* color = desiredelement->getColor(); 223 LOG(1, "Creating new material with color " << (int)color[0] << "," << (int)color[1] << "," << (int)color[2] << "."); 224 newmaterial->setAmbientColor( QColor((int)color[0], (int)color[1], (int)color[2]) ); 187 225 newmaterial->setSpecularColor( QColor(60, 60, 60) ); 188 226 newmaterial->setShininess( 128 ); … … 190 228 191 229 return newmaterial; 230 } 231 } 232 233 /** Create the 3 materials shared by all objects. 234 * 235 */ 236 void GLMoleculeObject::initStaticMaterials() 237 { 238 if (!m_hoverMaterial){ 239 m_hoverMaterial = new QGLMaterial(NULL); 240 m_hoverMaterial->setAmbientColor( QColor(0, 128, 128) ); 241 m_hoverMaterial->setSpecularColor( QColor(60, 60, 60) ); 242 m_hoverMaterial->setShininess( 128 ); 243 } 244 if (!m_selectionMaterial){ 245 m_selectionMaterial = new QGLMaterial(NULL); 246 m_selectionMaterial->setAmbientColor( QColor(255, 50, 50) ); 247 m_selectionMaterial->setSpecularColor( QColor(60, 60, 60) ); 248 m_selectionMaterial->setShininess( 128 ); 249 } 250 if (!m_selectionBoxMaterial){ 251 m_selectionBoxMaterial = new QGLMaterial(NULL); 252 m_selectionBoxMaterial->setAmbientColor( QColor(0, 0, 0) ); 253 m_selectionBoxMaterial->setDiffuseColor( QColor(0, 0, 0) ); 254 m_selectionBoxMaterial->setEmittedLight( QColor(155, 50, 50) ); 192 255 } 193 256 } … … 205 268 } 206 269 } 270 271 272 void GLMoleculeObject::setSelected(bool value) 273 { 274 if (value != m_selected){ 275 m_selected = value; 276 emit selectionChanged(); 277 } 278 }
Note:
See TracChangeset
for help on using the changeset viewer.