Changeset 3b229e for src


Ignore:
Timestamp:
Apr 6, 2012, 11:57:23 AM (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:
225cf5
Parents:
c67518
git-author:
Michael Ankele <ankele@…> (04/02/12 10:48:10)
git-committer:
Frederik Heber <heber@…> (04/06/12 11:57:23)
Message:

GL: made hover/selection materials static

  • no more getMaterial(_evil_number_) workaround
Location:
src/UIElements/Views/Qt4/Qt3D
Files:
4 edited

Legend:

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

    rc67518 r3b229e  
    4141
    4242#include "CodePatterns/MemDebug.hpp"
     43
     44QGLMaterial *GLMoleculeObject::m_hoverMaterial = NULL;
     45QGLMaterial *GLMoleculeObject::m_selectionMaterial = NULL;
     46QGLMaterial *GLMoleculeObject::m_selectionBoxMaterial = NULL;
    4347
    4448
     
    5559   m_selected = false;
    5660   m_material = 0;
    57    m_hoverMaterial = 0;
    58    m_selectionMaterial = 0;
     61   initStaticMaterials();
    5962}
    6063
     
    7275   m_selected = false;
    7376   m_material = 0;
    74    m_hoverMaterial = 0;
    75    m_selectionMaterial = 0;
     77   initStaticMaterials();
    7678}
    7779
     
    107109   else
    108110       material = m_material;
     111
     112   ASSERT(material, "GLMoleculeObject::draw: chosen material is NULL");
     113
    109114   painter->setColor(material->diffuseColor());
    110115   painter->setFaceMaterial(QGL::AllFaces, material);
     
    123128
    124129   if (m_selected){
     130     painter->setFaceMaterial(QGL::AllFaces, m_selectionBoxMaterial);
    125131     QVector3DArray array;
    126132     qreal radius = 0.3f;
     
    190196QGLMaterial* GLMoleculeObject::getMaterial(size_t no)
    191197{
    192   ASSERT( (no >= 0) && (no < MAX_ELEMENTS) || (no == 65536),
     198  ASSERT( (no > 0) && (no < MAX_ELEMENTS),
    193199      "GLMoleculeView::getMaterial() - Element no "+toString(no)+" is invalid.");
    194200  if (ElementNoMaterialMap.find(no) != ElementNoMaterialMap.end()){
     
    200206    QGLMaterial *newmaterial = new QGLMaterial(NULL);
    201207
    202     if (no == 0) { // create hover material
    203       newmaterial->setAmbientColor( QColor(0, 128, 128) );
    204     } else if (no == 65536) { // create selection material
    205       newmaterial->setAmbientColor( QColor(255, 50, 50) );
    206     } else { // create material for element
    207       periodentafel *periode = World::getInstance().getPeriode();
    208       const element *desiredelement = periode->FindElement(no);
    209       ASSERT(desiredelement != NULL,
    210           "GLMoleculeView::getMaterial() - desired element "+toString(no)+" not present in periodentafel.");
    211       const unsigned char* color = desiredelement->getColor();
    212       LOG(1, "Creating new material with color " << (int)color[0] << "," << (int)color[1] << "," << (int)color[2] << ".");
    213       newmaterial->setAmbientColor( QColor((int)color[0], (int)color[1], (int)color[2]) );
    214     }
     208    // create material for element
     209    periodentafel *periode = World::getInstance().getPeriode();
     210    const element *desiredelement = periode->FindElement(no);
     211    ASSERT(desiredelement != NULL,
     212        "GLMoleculeView::getMaterial() - desired element "+toString(no)+" not present in periodentafel.");
     213    const unsigned char* color = desiredelement->getColor();
     214    LOG(1, "Creating new material with color " << (int)color[0] << "," << (int)color[1] << "," << (int)color[2] << ".");
     215    newmaterial->setAmbientColor( QColor((int)color[0], (int)color[1], (int)color[2]) );
    215216    newmaterial->setSpecularColor( QColor(60, 60, 60) );
    216217    newmaterial->setShininess( 128 );
     
    218219
    219220    return newmaterial;
     221  }
     222}
     223
     224/** Create the 3 materials shared by all objects.
     225 *
     226 */
     227void GLMoleculeObject::initStaticMaterials()
     228{
     229  if (!m_hoverMaterial){
     230    m_hoverMaterial = new QGLMaterial(NULL);
     231    m_hoverMaterial->setAmbientColor( QColor(0, 128, 128) );
     232    m_hoverMaterial->setSpecularColor( QColor(60, 60, 60) );
     233    m_hoverMaterial->setShininess( 128 );
     234  }
     235  if (!m_selectionMaterial){
     236    m_selectionMaterial = new QGLMaterial(NULL);
     237    m_selectionMaterial->setAmbientColor( QColor(255, 50, 50) );
     238    m_selectionMaterial->setSpecularColor( QColor(60, 60, 60) );
     239    m_selectionMaterial->setShininess( 128 );
     240  }
     241  if (!m_selectionBoxMaterial){
     242    m_selectionBoxMaterial = new QGLMaterial(NULL);
     243    m_selectionBoxMaterial->setAmbientColor( QColor(0, 0, 0) );
     244    m_selectionBoxMaterial->setDiffuseColor( QColor(0, 0, 0) );
     245    m_selectionBoxMaterial->setEmittedLight( QColor(155, 50, 50) );
    220246  }
    221247}
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject.hpp

    rc67518 r3b229e  
    5757
    5858   QGLMaterial *material() const { return m_material; }
    59    void setMaterial(QGLMaterial *value)
    60        { m_material = value; m_hoverMaterial = value; }
    61 
    62    QGLMaterial *hoverMaterial() const { return m_hoverMaterial; }
    63    void setHoverMaterial(QGLMaterial *value) { m_hoverMaterial = value; }
    64 
    65    QGLMaterial *selectionMaterial() const { return m_selectionMaterial; }
    66    void setSelectionMaterial(QGLMaterial *value) { m_selectionMaterial = value; }
     59   void setMaterial(QGLMaterial *value) { m_material = value; }
    6760
    6861   QGLAbstractEffect *effect() const { return m_effect; }
     
    7568   void setSelected(bool value);
    7669
     70   void initStaticMaterials();
    7771   void initialize(QGLView *view, QGLPainter *painter);
    7872   void draw(QGLPainter *painter);
     
    106100   QVector3D m_rotationVector;
    107101   QGLMaterial *m_material;
    108    QGLMaterial *m_hoverMaterial;
    109    QGLMaterial *m_selectionMaterial;
     102   static QGLMaterial *m_hoverMaterial;
     103   static QGLMaterial *m_selectionMaterial;
     104   static QGLMaterial *m_selectionBoxMaterial;
    110105   QGLAbstractEffect *m_effect;
    111106   int m_objectId;
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.cpp

    rc67518 r3b229e  
    106106      "GLMoleculeObject_atom::GLMoleculeObject_atom() - QGLMaterial ref from getter function is NULL.");
    107107  setMaterial(elementmaterial);
    108   QGLMaterial *hovermaterial = getMaterial(0); // 0 is the hover material
    109   ASSERT(hovermaterial != NULL,
    110       "GLMoleculeObject_atom::GLMoleculeObject_atom() - QGLMaterial ref from getter function for hover is NULL.");
    111   setHoverMaterial(hovermaterial);
    112   QGLMaterial *selectionmaterial = getMaterial(65536); // 65536 is the selection material
    113   ASSERT(selectionmaterial != NULL,
    114       "GLMoleculeObject_atom::GLMoleculeObject_atom() - QGLMaterial ref from getter function for selection is NULL.");
    115   setSelectionMaterial(selectionmaterial);
    116108
    117109  // set scale
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.cpp

    rc67518 r3b229e  
    6363  setPosition(QVector3D(0,0,0));
    6464  setScale(5.0f);
    65   QGLMaterial *selectionmaterial = getMaterial(65536); // 65536 is the selection material
    66   setMaterial(selectionmaterial);
    67   setSelectionMaterial(selectionmaterial);
     65  setMaterial(getMaterial(1));
    6866}
    6967
Note: See TracChangeset for help on using the changeset viewer.