Changeset 53059e for src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject.cpp
- Timestamp:
- Apr 11, 2012, 4:52:37 PM (13 years ago)
- Branches:
- Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
- Children:
- 3e93332
- Parents:
- c0ed1e (diff), 3927ef (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - git-author:
- Frederik Heber <heber@…> (04/06/12 11:59:28)
- git-committer:
- Frederik Heber <heber@…> (04/11/12 16:52:37)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject.cpp
rc0ed1e r53059e 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.