1 /* $Id: style_manager.hpp 411368 2013-08-28 11:25:58Z thiessen $ 2 * =========================================================================== 3 * 4 * PUBLIC DOMAIN NOTICE 5 * National Center for Biotechnology Information 6 * 7 * This software/database is a "United States Government Work" under the 8 * terms of the United States Copyright Act. It was written as part of 9 * the author's official duties as a United States Government employee and 10 * thus cannot be copyrighted. This software/database is freely available 11 * to the public for use. The National Library of Medicine and the U.S. 12 * Government have not placed any restriction on its use or reproduction. 13 * 14 * Although all reasonable efforts have been taken to ensure the accuracy 15 * and reliability of the software and data, the NLM and the U.S. 16 * Government do not and cannot warrant the performance or results that 17 * may be obtained by using this software or data. The NLM and the U.S. 18 * Government disclaim all warranties, express or implied, including 19 * warranties of performance, merchantability or fitness for any particular 20 * purpose. 21 * 22 * Please cite the author in any work or product based on this material. 23 * 24 * =========================================================================== 25 * 26 * Authors: Paul Thiessen 27 * 28 * File Description: 29 * manager object to track drawing style of objects at various levels 30 * 31 * =========================================================================== 32 */ 33 34 #ifndef CN3D_STYLE_MANAGER__HPP 35 #define CN3D_STYLE_MANAGER__HPP 36 37 #include <corelib/ncbistl.hpp> 38 #include <corelib/ncbiobj.hpp> 39 40 #include <objects/cn3d/Cn3d_style_dictionary.hpp> 41 #include <objects/cn3d/Cn3d_style_settings.hpp> 42 #include <objects/cn3d/Cn3d_user_annotations.hpp> 43 44 #include <string> 45 #include <list> 46 #include <map> 47 #include <vector> 48 49 #include "vector_math.hpp" 50 51 class wxWindow; 52 53 54 BEGIN_SCOPE(Cn3D) 55 56 // for hydrophobicity and charge coloring 57 extern const double UNKNOWN_HYDROPHOBICITY; 58 extern double GetHydrophobicity(char code); 59 extern int GetCharge(char code); 60 61 62 // StyleSettings is a complete set of instructions on how to draw a set of 63 // molecules. It is used for "global" settings as well as for individual 64 // annotations. It is meant to contain all settings that can be saved on 65 // a per-output file basis. 66 67 // values of enumerations must match those in cn3d.asn! 68 69 class StyleSettings 70 { 71 public: 72 // for different types of backbone displays 73 enum eBackboneType { 74 eOff = 1, 75 eTrace = 2, 76 ePartial = 3, 77 eComplete = 4 78 }; 79 80 // available drawing styles (not all necessarily applicable to all objects) 81 enum eDrawingStyle { 82 // for atoms and bonds 83 eWire = 1, 84 eTubes = 2, 85 eBallAndStick = 3, 86 eSpaceFill = 4, 87 eWireWorm = 5, 88 eTubeWorm = 6, 89 90 // for 3d-objects 91 eWithArrows = 7, 92 eWithoutArrows = 8 93 }; 94 95 // available color schemes (not all necessarily applicable to all objects) 96 enum eColorScheme { 97 eElement = 1, 98 eObject = 2, 99 eMolecule = 3, 100 eDomain = 4, 101 eResidue = 20, 102 eSecondaryStructure = 5, 103 eTemperature = 13, 104 eHydrophobicity = 14, 105 eCharge = 15, 106 eRainbow = 16, 107 eUserSelect = 6, 108 109 // different alignment conservation coloring (currently only used for proteins) 110 eAligned = 7, 111 eIdentity = 8, 112 eVariety = 9, 113 eWeightedVariety = 10, 114 eInformationContent = 11, 115 eFit = 12, 116 eBlockFit = 17, 117 eBlockZFit = 18, 118 eBlockRowFit = 19 119 }; 120 121 typedef struct { 122 eBackboneType type; 123 eDrawingStyle style; 124 eColorScheme colorScheme; 125 Vector userColor; 126 } BackboneStyle; 127 128 typedef struct { 129 bool isOn; 130 eDrawingStyle style; 131 eColorScheme colorScheme; 132 Vector userColor; 133 } GeneralStyle; 134 135 enum eLabelType { 136 eOneLetter = 1, 137 eThreeLetter = 2 138 }; 139 140 enum eNumberType { 141 eNoNumbers = 0, 142 eSequentialNumbering = 1, // from 1 by residues present, to match sequence loc 143 ePDBNumbering = 2 // use number assigned by PDB 144 }; 145 146 typedef struct { 147 int spacing; 148 eLabelType type; 149 eNumberType numbering; 150 bool 151 terminiOn, // label chain termini 152 white; // use white labels (or if bg is light, use black for contrast) 153 } LabelStyle; 154 155 BackboneStyle proteinBackbone, nucleotideBackbone; 156 157 GeneralStyle 158 proteinSidechains, nucleotideSidechains, 159 heterogens, 160 solvents, 161 connections, 162 helixObjects, strandObjects; 163 164 LabelStyle proteinLabels, nucleotideLabels; 165 166 bool virtualDisulfidesOn, hydrogensOn, ionLabelsOn; 167 168 Vector virtualDisulfideColor, backgroundColor; 169 170 double spaceFillProportion, ballRadius, stickRadius, tubeRadius, tubeWormRadius, 171 helixRadius, strandWidth, strandThickness; 172 173 // to set to predetermined renderings 174 enum ePredefinedRenderingStyle { 175 eWormShortcut, 176 eTubeShortcut, 177 eWireframeShortcut, 178 eBallAndStickShortcut, 179 eSpacefillShortcut, 180 eToggleSidechainsShortcut 181 }; 182 void SetRenderingStyle(ePredefinedRenderingStyle style); 183 184 // to set to predetermined colors 185 enum ePredefinedColorScheme { 186 eSecondaryStructureShortcut, 187 eAlignedShortcut, 188 eIdentityShortcut, 189 eVarietyShortcut, 190 eWeightedVarietyShortcut, 191 eInformationContentShortcut, 192 eFitShortcut, 193 eBlockFitShortcut, 194 eBlockZFitShortcut, 195 eBlockRowFitShortcut, 196 eObjectShortcut, 197 eDomainShortcut, 198 eMoleculeShortcut, 199 eResidueShortcut, 200 eRainbowShortcut, 201 eHydrophobicityShortcut, 202 eChargeShortcut, 203 eTemperatureShortcut, 204 eElementShortcut 205 }; 206 void SetColorScheme(ePredefinedColorScheme scheme); 207 208 // default labeling style 209 void SetDefaultLabeling(void); 210 211 // default and copy constructors StyleSettings(void)212 StyleSettings(void) 213 { 214 SetRenderingStyle(eWormShortcut); 215 SetColorScheme(eSecondaryStructureShortcut); 216 SetDefaultLabeling(); 217 } StyleSettings(const StyleSettings & orig)218 StyleSettings(const StyleSettings& orig) { *this = orig; } 219 220 // copy settings 221 StyleSettings& operator = (const StyleSettings& v); 222 223 // to convert to/from asn 224 bool SaveSettingsToASN(ncbi::objects::CCn3d_style_settings *styleASN) const; 225 bool LoadSettingsFromASN(const ncbi::objects::CCn3d_style_settings& styleASN); 226 }; 227 228 229 class StructureSet; 230 class StructureObject; 231 class Residue; 232 class AtomPntr; 233 class AtomCoord; 234 class Bond; 235 class BondStyle; 236 class AtomStyle; 237 class Object3D; 238 class ObjectStyle; 239 class Helix3D; 240 class HelixStyle; 241 class Strand3D; 242 class StrandStyle; 243 class Molecule; 244 class MoleculeIdentifier; 245 class AnnotateDialog; 246 247 class StyleManager 248 { 249 public: 250 StyleManager(const StructureSet *set); 251 252 // display styles for various types of objects 253 enum eDisplayStyle { 254 eSolidAtom, 255 eTransparentAtom, 256 eLineBond, 257 eCylinderBond, 258 eLineWormBond, 259 eThickWormBond, 260 eObjectWithArrow, 261 eObjectWithoutArrow, 262 eNotDisplayed 263 }; 264 GetBackgroundColor(void) const265 const Vector& GetBackgroundColor(void) const { return globalStyle.backgroundColor; } 266 267 // style accessors for individual objects 268 bool GetAtomStyle(const Residue *residue, const AtomPntr& atom, 269 const AtomCoord *coord, AtomStyle *atomStyle, 270 const StyleSettings::BackboneStyle* *saveBackboneStyle = NULL, 271 const StyleSettings::GeneralStyle* *saveGeneralStyle = NULL) const; 272 bool GetBondStyle(const Bond *bond, 273 const AtomPntr& atom1, const AtomCoord *coord1, 274 const AtomPntr& atom2, const AtomCoord *coord2, 275 double bondLength, BondStyle *bondStyle) const; 276 bool GetHelixStyle(const StructureObject *object, 277 const Helix3D& helix, HelixStyle *helixStyle) const; 278 bool GetStrandStyle(const StructureObject *object, 279 const Strand3D& strand, StrandStyle *strandStyle) const; 280 281 // bring up dialog to edit global style; returns true if style changed 282 bool EditGlobalStyle(wxWindow *parent); 283 284 // edit user annotations; returns true if any style changed 285 bool EditUserAnnotations(wxWindow *parent); 286 287 // check style option consistency 288 bool CheckStyleSettings(StyleSettings *settings); 289 bool CheckGlobalStyleSettings(void); 290 291 // load/save asn style dictionary to/from current styles 292 ncbi::objects::CCn3d_style_dictionary * CreateASNStyleDictionary(void) const; 293 bool LoadFromASNStyleDictionary(const ncbi::objects::CCn3d_style_dictionary& styleDictionary); 294 295 // add a new user style with default settings; returns true if successful, 296 // and sets style ID assigned to the new style and pointer to the new style structure 297 bool AddUserStyle(int *id, StyleSettings **newStyle); 298 299 // remove a style; returns false if a user style of the given ID is not found 300 bool RemoveUserStyle(int id); 301 302 // StyleSettings accessors GetGlobalStyle(void) const303 const StyleSettings& GetGlobalStyle(void) const { return globalStyle; } 304 const StyleSettings& GetStyleForResidue(const StructureObject *object, 305 int moleculeID, int residueID) const; 306 const Vector& GetObjectColor(const Molecule *molecule) const; GetUserStyle(int id) const307 const StyleSettings * GetUserStyle(int id) const 308 { 309 StyleMap::const_iterator style = userStyles.find(id); 310 return ((style != userStyles.end()) ? &(style->second) : NULL); 311 } GetUserStyle(int id)312 StyleSettings * GetUserStyle(int id) 313 { 314 StyleMap::iterator style = userStyles.find(id); 315 return ((style != userStyles.end()) ? &(style->second) : NULL); 316 } 317 318 // checks for presence of active user styles 319 bool MoleculeHasUserStyle(const StructureObject *object, int moleculeID) const; 320 bool ResidueHasUserStyle(const StructureObject *object, int moleculeID, int residueID) const; 321 322 // predefined styles 323 void SetGlobalColorScheme(StyleSettings::ePredefinedColorScheme scheme); 324 void SetGlobalRenderingStyle(StyleSettings::ePredefinedRenderingStyle style); 325 326 // set global style 327 bool SetGlobalStyle(const ncbi::objects::CCn3d_style_settings& styleASN); 328 329 // load/save asn user annotations 330 bool SaveToASNUserAnnotations(ncbi::objects::CCn3d_user_annotations *annotations) const; 331 bool LoadFromASNUserAnnotations(const ncbi::objects::CCn3d_user_annotations& annotations); 332 333 // typedefs for UserAnnotation 334 typedef std::map < const MoleculeIdentifier * , std::vector < bool > > ResidueMap; 335 class UserAnnotation : public ncbi::CObject { 336 public: 337 std::string name, description; 338 int styleID; 339 ResidueMap residues; 340 bool isDisplayed; 341 }; 342 typedef std::list < ncbi::CRef < UserAnnotation > > UserAnnotationList; 343 344 // add a new (empty) annotation; returns a pointer to the new UserAnnotation structure 345 UserAnnotation * AddUserAnnotation(void); 346 347 // remove an annotation; returns false if the given annotation isn't found 348 bool RemoveUserAnnotation(UserAnnotation *annotation); 349 350 // sets the displayed status of the given annotation; returns false if annotation not found. 351 // Should use this rather than setting UserAnnotation.isDisplayed directly. 352 bool DisplayUserAnnotation(UserAnnotation *annotation, bool display); 353 354 // moves the priority of annotation up (moveUp==true) or down (moveUp==false); 355 // returns false if annotation not found 356 bool MoveUserAnnotation(UserAnnotation *annotation, bool moveUp); 357 358 // annotation list accessors GetUserAnnotations(void)359 UserAnnotationList& GetUserAnnotations(void) { return userAnnotations; } GetUserAnnotations(void) const360 const UserAnnotationList& GetUserAnnotations(void) const { return userAnnotations; } 361 362 private: 363 const StructureSet *structureSet; 364 StyleSettings globalStyle; 365 366 // a set of user styles, each with its own unique integer id 367 typedef std::map < int , StyleSettings > StyleMap; 368 StyleMap userStyles; 369 370 // the priority-ordered list of annotations, including which are currently displayed; 371 // lowest-indexed annotation has highest priority (to reflect GUI list where the 372 // annotation on top of the stack has priority) 373 UserAnnotationList userAnnotations; 374 375 bool GetObjectStyle(const StructureObject *object, const Object3D& object3D, 376 const StyleSettings::GeneralStyle& generalStyle, ObjectStyle *objectStyle) const; 377 }; 378 379 // the following are convenience containers to tell the Draw functions how 380 // to render various individual objects 381 382 class AtomStyle 383 { 384 public: 385 StyleManager::eDisplayStyle style; 386 Vector color; 387 double radius, alpha; 388 unsigned int name; 389 std::string centerLabel; 390 bool isHighlighted; 391 }; 392 393 class BondStyle 394 { 395 public: 396 typedef struct { 397 StyleManager::eDisplayStyle style; 398 Vector color; 399 double radius; 400 bool atomCap; 401 unsigned int name; 402 } EndStyle; 403 EndStyle end1, end2; 404 bool midCap; 405 double tension; 406 }; 407 408 class ObjectStyle 409 { 410 public: 411 StyleManager::eDisplayStyle style; 412 Vector color; 413 double arrowLength, arrowBaseWidthProportion; 414 }; 415 416 class HelixStyle : public ObjectStyle 417 { 418 public: 419 double radius, arrowTipWidthProportion; 420 }; 421 422 class StrandStyle : public ObjectStyle 423 { 424 public: 425 double width, thickness; 426 }; 427 428 END_SCOPE(Cn3D) 429 430 #endif // CN3D_STYLE_MANAGER__HPP 431