Ignore:
Timestamp:
Apr 11, 2012, 4:52:37 PM (13 years ago)
Author:
Frederik Heber <heber@…>
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)
Message:

Merge branch 'michi-track-molecules' into stable

Conflicts:

src/World.hpp

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject.cpp

    rc0ed1e r53059e  
    4242#include "CodePatterns/MemDebug.hpp"
    4343
     44QGLMaterial *GLMoleculeObject::m_hoverMaterial = NULL;
     45QGLMaterial *GLMoleculeObject::m_selectionMaterial = NULL;
     46QGLMaterial *GLMoleculeObject::m_selectionBoxMaterial = NULL;
     47
    4448
    4549GLMoleculeObject::GLMoleculeObject(QGLSceneNode *GLMoleculeObject, QObject *parent)
    4650   : QObject(parent)
    4751{
    48    m_mesh = 0;
    49    m_GLMoleculeObject = GLMoleculeObject;
     52   m_mesh = GLMoleculeObject;
    5053   m_scale = 1.0f;
     54   m_scaleZ = 1.0f;
    5155   m_rotationAngle = 0.0f;
    5256   m_effect = 0;
    5357   m_objectId = -1;
    5458   m_hovering = false;
     59   m_selected = false;
    5560   m_material = 0;
    56    m_hoverMaterial = 0;
     61   initStaticMaterials();
    5762}
    5863
     
    6166{
    6267   scene->setParent(this);
    63    m_mesh = 0;
    64    m_GLMoleculeObject = scene->mainNode();
     68   m_mesh = scene->mainNode();
    6569   m_scale = 1.0f;
     70   m_scaleZ = 1.0f;
    6671   m_rotationAngle = 0.0f;
    6772   m_effect = 0;
    6873   m_objectId = -1;
    6974   m_hovering = false;
     75   m_selected = false;
    7076   m_material = 0;
    71    m_hoverMaterial = 0;
     77   initStaticMaterials();
    7278}
    7379
    7480GLMoleculeObject::~GLMoleculeObject()
    7581{
    76    delete m_mesh;
    7782}
    7883
     
    8287   if (m_objectId != -1)
    8388       view->registerObject(m_objectId, this);
     89}
     90
     91
     92/** Draws a box around the mesh.
     93 *
     94 */
     95void 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);
    84117}
    85118
     
    93126   if (m_rotationAngle != 0.0f)
    94127       painter->modelViewMatrix().rotate(m_rotationAngle, m_rotationVector);
     128   if (m_scaleZ != 1.0f)
     129       painter->modelViewMatrix().scale(1.0f, 1.0f, m_scaleZ);
    95130
    96131   // Apply the material and effect to the painter.
     
    98133   if (m_hovering)
    99134       material = m_hoverMaterial;
     135   else if (m_selected)
     136       material = m_selectionMaterial;
    100137   else
    101138       material = m_material;
     139
     140   ASSERT(material, "GLMoleculeObject::draw: chosen material is NULL");
     141
    102142   painter->setColor(material->diffuseColor());
    103143   painter->setFaceMaterial(QGL::AllFaces, material);
     
    113153
    114154   // 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);
    119160
    120161   // Turn off the user effect, if present.
     
    164205QGLMaterial* GLMoleculeObject::getMaterial(size_t no)
    165206{
    166   ASSERT( (no >= 0) && (no < MAX_ELEMENTS),
     207  ASSERT( (no > 0) && (no < MAX_ELEMENTS),
    167208      "GLMoleculeView::getMaterial() - Element no "+toString(no)+" is invalid.");
    168209  if (ElementNoMaterialMap.find(no) != ElementNoMaterialMap.end()){
     
    174215    QGLMaterial *newmaterial = new QGLMaterial(NULL);
    175216
    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]) );
    187225    newmaterial->setSpecularColor( QColor(60, 60, 60) );
    188226    newmaterial->setShininess( 128 );
     
    190228
    191229    return newmaterial;
     230  }
     231}
     232
     233/** Create the 3 materials shared by all objects.
     234 *
     235 */
     236void 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) );
    192255  }
    193256}
     
    205268  }
    206269}
     270
     271
     272void 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.