1 /** 2 * UGENE - Integrated Bioinformatics Tools. 3 * Copyright (C) 2008-2021 UniPro <ugene@unipro.ru> 4 * http://ugene.net 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * as published by the Free Software Foundation; either version 2 9 * of the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 * MA 02110-1301, USA. 20 */ 21 22 #ifndef _U2_BIOSTRUCT3D_COLORSCHEME_H 23 #define _U2_BIOSTRUCT3D_COLORSCHEME_H 24 25 #include <QColor> 26 #include <QHash> 27 #include <QLinkedList> 28 #include <QMap> 29 #include <QPair> 30 31 #include <U2Core/BioStruct3D.h> 32 33 #include "GraphicUtils.h" 34 35 namespace U2 { 36 37 class BioStruct3DObject; 38 class BioStruct3DColorScheme; 39 class BioStruct3DColorSchemeFactory; 40 class LRegionsSelection; 41 class U2Region; 42 43 //! Singleton regisrtry for color scheme fabrics. 44 class BioStruct3DColorSchemeRegistry { 45 public: 46 //! @return Default colo scheme factory name. 47 static const QString defaultFactoryName(); 48 49 //! @return List of all factories names. 50 static const QList<QString> factoriesNames(); 51 52 //! @return Concreete factory by name. 53 static const BioStruct3DColorSchemeFactory *getFactory(const QString &name); 54 55 //! @return Constructed color scheme by factory name. 56 static BioStruct3DColorScheme *createColorScheme(const QString &name, const BioStruct3DObject *biostruct); 57 58 private: 59 //! Hidden constructor. Called by getInstance() 60 BioStruct3DColorSchemeRegistry(); 61 62 //! Returns singleton instance of registry. 63 static BioStruct3DColorSchemeRegistry *getInstance(); 64 65 //! Registers all render factories. 66 void registerFactories(); 67 68 private: 69 QMap<QString, BioStruct3DColorSchemeFactory *> factories; 70 }; // class BioStruct3DColorSchemeRegistry 71 72 //! Abstract factory for BioStruct3DColorScheme 73 class BioStruct3DColorSchemeFactory { 74 public: 75 virtual BioStruct3DColorScheme *createInstance(const BioStruct3DObject *biostruct) const = 0; 76 //! Method creates factories 77 }; 78 79 #define COLOR_SCHEME_FACTORY(c) \ 80 public: \ 81 static const QString schemeName; \ 82 class Factory : public BioStruct3DColorSchemeFactory { \ 83 public: \ 84 BioStruct3DColorScheme *createInstance(const BioStruct3DObject *biostructObj) const { \ 85 return new c(biostructObj); \ 86 } \ 87 }; 88 89 //! Abstract BioStruct3DColorScheme 90 /*! 91 * Color scheme determines 3d structure coloring style. For example, we could use colors to mark chemical 92 * elements or secondary structure. 93 */ 94 class BioStruct3DColorScheme { 95 protected: 96 BioStruct3DColorScheme(const BioStruct3DObject *biostruct); 97 98 public: ~BioStruct3DColorScheme()99 virtual ~BioStruct3DColorScheme() {}; 100 101 Color4f getAtomColor(const SharedAtom &atom) const; 102 103 void updateSelectionRegion(int chainID, const QVector<U2Region> &added, const QVector<U2Region> &removed); 104 bool isInSelection(const SharedAtom &atom) const; 105 106 void setSelectionColor(QColor color); 107 void setUnselectedShadingLevel(float shading); 108 109 protected: 110 virtual Color4f getSchemeAtomColor(const SharedAtom &atom) const; 111 112 protected: 113 Color4f defaultAtomColor; 114 Color4f selectionColor; 115 116 BioStruct3DChainSelection selection; 117 118 private: 119 float unselectedShading; 120 }; // class BioStruct3DColorScheme 121 122 class ChemicalElemColorScheme : public BioStruct3DColorScheme { 123 QHash<int, Color4f> elementColorMap; 124 ChemicalElemColorScheme(const BioStruct3DObject *biostruct); 125 virtual Color4f getSchemeAtomColor(const SharedAtom &atom) const; 126 127 public: 128 COLOR_SCHEME_FACTORY(ChemicalElemColorScheme) 129 }; // class ChemicalElemColorScheme 130 131 class ChainsColorScheme : public BioStruct3DColorScheme { 132 QMap<int, Color4f> chainColorMap; 133 ChainsColorScheme(const BioStruct3DObject *biostruct); 134 virtual Color4f getSchemeAtomColor(const SharedAtom &atom) const; 135 136 private: 137 //! @return Molecular chain colors for biostruct object. 138 static const QMap<int, QColor> getChainColors(const BioStruct3DObject *biostruct); 139 140 public: 141 COLOR_SCHEME_FACTORY(ChainsColorScheme) 142 }; // class ChainsColorScheme 143 144 class SecStructColorScheme : public BioStruct3DColorScheme { 145 struct MolStructs { 146 QHash<int, QByteArray> strucResidueTable; 147 }; 148 QMap<QByteArray, Color4f> secStrucColorMap; 149 QMap<int, MolStructs> molMap; 150 SecStructColorScheme(const BioStruct3DObject *biostruct); 151 virtual Color4f getSchemeAtomColor(const SharedAtom &atom) const; 152 153 private: 154 //! @return Secondary structure annotation colors for biostruct object. 155 static const QMap<QString, QColor> getSecStructAnnotationColors(const BioStruct3DObject *biostruct); 156 157 public: 158 COLOR_SCHEME_FACTORY(SecStructColorScheme) 159 }; // class SecStructColorScheme 160 161 /** One color scheme for debug purposes */ 162 class SimpleColorScheme : public BioStruct3DColorScheme { 163 SimpleColorScheme(const BioStruct3DObject *biostruct); 164 165 private: 166 static QVector<Color4f> colors; 167 static void createColors(); 168 169 public: 170 COLOR_SCHEME_FACTORY(SimpleColorScheme) 171 }; // class SimpleColorScheme 172 173 } // namespace U2 174 175 #endif //_U2_BIOSTRUCT3D_COLORSCHEME_H_ 176