📄 style_manager.cpp
字号:
/* * =========================================================================== * PRODUCTION $Log: style_manager.cpp,v $ * PRODUCTION Revision 1000.2 2004/06/01 18:29:44 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.84 * PRODUCTION * =========================================================================== *//* $Id: style_manager.cpp,v 1000.2 2004/06/01 18:29:44 gouriano Exp $* ===========================================================================** PUBLIC DOMAIN NOTICE* National Center for Biotechnology Information** This software/database is a "United States Government Work" under the* terms of the United States Copyright Act. It was written as part of* the author's official duties as a United States Government employee and* thus cannot be copyrighted. This software/database is freely available* to the public for use. The National Library of Medicine and the U.S.* Government have not placed any restriction on its use or reproduction.** Although all reasonable efforts have been taken to ensure the accuracy* and reliability of the software and data, the NLM and the U.S.* Government do not and cannot warrant the performance or results that* may be obtained by using this software or data. The NLM and the U.S.* Government disclaim all warranties, express or implied, including* warranties of performance, merchantability or fitness for any particular* purpose.** Please cite the author in any work or product based on this material.** ===========================================================================** Authors: Paul Thiessen** File Description:* manager object to track drawing style of objects at various levels** ===========================================================================*/#ifdef _MSC_VER#pragma warning(disable:4018) // disable signed/unsigned mismatch warning in MSVC#endif#include <ncbi_pch.hpp>#include <corelib/ncbistd.hpp>#include <corelib/ncbiobj.hpp>#include <objects/cn3d/Cn3d_backbone_style.hpp>#include <objects/cn3d/Cn3d_general_style.hpp>#include <objects/cn3d/Cn3d_backbone_label_style.hpp>#include <objects/cn3d/Cn3d_color.hpp>#include <objects/cn3d/Cn3d_style_table_item.hpp>#include <objects/cn3d/Cn3d_style_table_id.hpp>#include <objects/cn3d/Cn3d_user_annotation.hpp>#include <objects/cn3d/Cn3d_object_location.hpp>#include <objects/mmdb1/Biostruc_id.hpp>#include <objects/mmdb1/Mmdb_id.hpp>#include <objects/cn3d/Cn3d_molecule_location.hpp>#include <objects/cn3d/Cn3d_residue_range.hpp>#include <objects/mmdb1/Residue_id.hpp>#include <objects/mmdb1/Molecule_id.hpp>#include <memory>#include <string.h> // for memcpy()#include "style_manager.hpp"#include "structure_set.hpp"#include "chemical_graph.hpp"#include "residue.hpp"#include "periodic_table.hpp"#include "bond.hpp"#include "show_hide_manager.hpp"#include "object_3d.hpp"#include "alignment_manager.hpp"#include "messenger.hpp"#include "cn3d_colors.hpp"#include "style_dialog.hpp"#include "annotate_dialog.hpp"#include "molecule_identifier.hpp"#include "atom_set.hpp"#include "cn3d_tools.hpp"USING_NCBI_SCOPE;USING_SCOPE(objects);BEGIN_SCOPE(Cn3D)///// StyleSettings stuff /////static void Vector2ASNColor(const Vector &vec, CCn3d_color *asnColor){ static const int SCALE = 10000; asnColor->SetScale_factor(SCALE); asnColor->SetRed((int) (vec[0] * SCALE)); asnColor->SetGreen((int) (vec[1] * SCALE)); asnColor->SetBlue((int) (vec[2] * SCALE)); asnColor->SetAlpha(SCALE); // no alpha in Cn3D's colors}static bool SaveBackboneStyleToASN( const StyleSettings::BackboneStyle bbSettings, CCn3d_backbone_style *bbASN){ // these casts rely on correspondence of enumerated values! bbASN->SetType((ECn3d_backbone_type) bbSettings.type); bbASN->SetStyle((ECn3d_drawing_style) bbSettings.style); bbASN->SetColor_scheme((ECn3d_color_scheme) bbSettings.colorScheme); Vector2ASNColor(bbSettings.userColor, &(bbASN->SetUser_color())); return true;}static bool SaveGeneralStyleToASN( const StyleSettings::GeneralStyle gSettings, CCn3d_general_style *gASN){ // these casts rely on correspondence of enumerated values! gASN->SetIs_on(gSettings.isOn); gASN->SetStyle((ECn3d_drawing_style) gSettings.style); gASN->SetColor_scheme((ECn3d_color_scheme) gSettings.colorScheme); Vector2ASNColor(gSettings.userColor, &(gASN->SetUser_color())); return true;}static bool SaveLabelStyleToASN( const StyleSettings::LabelStyle lSettings, CCn3d_backbone_label_style *lASN){ lASN->SetSpacing(lSettings.spacing); // these casts rely on correspondence of enumerated values! lASN->SetType((CCn3d_backbone_label_style::EType) lSettings.type); lASN->SetNumber((CCn3d_backbone_label_style::ENumber) lSettings.numbering); lASN->SetTermini(lSettings.terminiOn); lASN->SetWhite(lSettings.white); return true;}bool StyleSettings::SaveSettingsToASN(CCn3d_style_settings *styleASN) const{ styleASN->SetVirtual_disulfides_on(virtualDisulfidesOn); Vector2ASNColor(virtualDisulfideColor, &(styleASN->SetVirtual_disulfide_color())); styleASN->SetHydrogens_on(hydrogensOn); Vector2ASNColor(backgroundColor, &(styleASN->SetBackground_color())); styleASN->SetIon_labels(ionLabelsOn); static const int SCALE = 10000; styleASN->SetScale_factor(SCALE); styleASN->SetSpace_fill_proportion((int) (spaceFillProportion * SCALE)); styleASN->SetBall_radius((int) (ballRadius * SCALE)); styleASN->SetStick_radius((int) (stickRadius * SCALE)); styleASN->SetTube_radius((int) (tubeRadius * SCALE)); styleASN->SetTube_worm_radius((int) (tubeWormRadius * SCALE)); styleASN->SetHelix_radius((int) (helixRadius * SCALE)); styleASN->SetStrand_width((int) (strandWidth * SCALE)); styleASN->SetStrand_thickness((int) (strandThickness * SCALE)); return ( SaveBackboneStyleToASN(proteinBackbone, &(styleASN->SetProtein_backbone())) && SaveBackboneStyleToASN(nucleotideBackbone, &(styleASN->SetNucleotide_backbone())) && SaveGeneralStyleToASN(proteinSidechains, &(styleASN->SetProtein_sidechains())) && SaveGeneralStyleToASN(nucleotideSidechains, &(styleASN->SetNucleotide_sidechains())) && SaveGeneralStyleToASN(heterogens, &(styleASN->SetHeterogens())) && SaveGeneralStyleToASN(solvents, &(styleASN->SetSolvents())) && SaveGeneralStyleToASN(connections, &(styleASN->SetConnections())) && SaveGeneralStyleToASN(helixObjects, &(styleASN->SetHelix_objects())) && SaveGeneralStyleToASN(strandObjects, &(styleASN->SetStrand_objects())) && SaveLabelStyleToASN(proteinLabels, &(styleASN->SetProtein_labels())) && SaveLabelStyleToASN(nucleotideLabels, &(styleASN->SetNucleotide_labels())) );}static void ASNColor2Vector(const CCn3d_color& asnColor, Vector *vec){ int SCALE = asnColor.GetScale_factor(); vec->Set( 1.0 * asnColor.GetRed() / SCALE, 1.0 * asnColor.GetGreen() / SCALE, 1.0 * asnColor.GetBlue() / SCALE ); // no alpha in Cn3D's colors}static bool LoadBackboneStyleFromASN( const CCn3d_backbone_style& bbASN, StyleSettings::BackboneStyle *bbSettings){ // these casts rely on correspondence of enumerated values! bbSettings->type = (StyleSettings::eBackboneType) bbASN.GetType(); bbSettings->style = (StyleSettings::eDrawingStyle) bbASN.GetStyle(); bbSettings->colorScheme = (StyleSettings::eColorScheme) bbASN.GetColor_scheme(); ASNColor2Vector(bbASN.GetUser_color(), &(bbSettings->userColor)); return true;}static bool LoadGeneralStyleFromASN( const CCn3d_general_style& gASN, StyleSettings::GeneralStyle *gSettings){ // these casts rely on correspondence of enumerated values! gSettings->isOn = gASN.GetIs_on(); gSettings->style = (StyleSettings::eDrawingStyle) gASN.GetStyle(); gSettings->colorScheme = (StyleSettings::eColorScheme) gASN.GetColor_scheme(); ASNColor2Vector(gASN.GetUser_color(), &(gSettings->userColor)); return true;}static bool LoadLabelStyleFromASN( const CCn3d_backbone_label_style& lASN, StyleSettings::LabelStyle *lSettings){ lSettings->spacing = lASN.GetSpacing(); // these casts rely on correspondence of enumerated values! lSettings->type = (StyleSettings::eLabelType) lASN.GetType(); lSettings->numbering = (StyleSettings::eNumberType) lASN.GetNumber(); lSettings->terminiOn = lASN.GetTermini(); lSettings->white = lASN.GetWhite(); return true;}static void SetDefaultLabelStyle(StyleSettings::LabelStyle *lStyle){ lStyle->spacing = 0; lStyle->type = StyleSettings::eThreeLetter; lStyle->numbering = StyleSettings::eSequentialNumbering; lStyle->terminiOn = false; lStyle->white = true;}bool StyleSettings::LoadSettingsFromASN(const CCn3d_style_settings& styleASN){ virtualDisulfidesOn = styleASN.GetVirtual_disulfides_on(); ASNColor2Vector(styleASN.GetVirtual_disulfide_color(), &virtualDisulfideColor); hydrogensOn = styleASN.GetHydrogens_on(); ASNColor2Vector(styleASN.GetBackground_color(), &backgroundColor); int SCALE = styleASN.GetScale_factor(); spaceFillProportion = 1.0 * styleASN.GetSpace_fill_proportion() / SCALE; stickRadius = 1.0 * styleASN.GetStick_radius() / SCALE; tubeRadius = 1.0 * styleASN.GetTube_radius() / SCALE; tubeWormRadius = 1.0 * styleASN.GetTube_worm_radius() / SCALE; helixRadius = 1.0 * styleASN.GetHelix_radius() / SCALE; strandWidth = 1.0 * styleASN.GetStrand_width() / SCALE; strandThickness = 1.0 * styleASN.GetStrand_thickness() / SCALE; // label defaults (since they're optional in ASN spec) if (styleASN.IsSetProtein_labels()) { if (!LoadLabelStyleFromASN(styleASN.GetProtein_labels(), &proteinLabels)) return false; } else SetDefaultLabelStyle(&proteinLabels); if (styleASN.IsSetNucleotide_labels()) { if (!LoadLabelStyleFromASN(styleASN.GetNucleotide_labels(), &nucleotideLabels)) return false; } else SetDefaultLabelStyle(&nucleotideLabels); // ion labels on by default ionLabelsOn = (styleASN.IsSetIon_labels()) ? styleASN.GetIon_labels() : true; return ( LoadBackboneStyleFromASN(styleASN.GetProtein_backbone(), &proteinBackbone) && LoadBackboneStyleFromASN(styleASN.GetNucleotide_backbone(), &nucleotideBackbone) && LoadGeneralStyleFromASN(styleASN.GetProtein_sidechains(), &proteinSidechains) && LoadGeneralStyleFromASN(styleASN.GetNucleotide_sidechains(), &nucleotideSidechains) && LoadGeneralStyleFromASN(styleASN.GetHeterogens(), &heterogens) && LoadGeneralStyleFromASN(styleASN.GetSolvents(), &solvents) && LoadGeneralStyleFromASN(styleASN.GetConnections(), &connections) && LoadGeneralStyleFromASN(styleASN.GetHelix_objects(), &helixObjects) && LoadGeneralStyleFromASN(styleASN.GetStrand_objects(), &strandObjects) );}StyleSettings& StyleSettings::operator = (const StyleSettings& orig){ memcpy(this, &orig, sizeof(StyleSettings)); return *this;}void StyleSettings::SetRenderingStyle(ePredefinedRenderingStyle style){ // variable settings switch (style) { // set sidechains isOn only case eToggleSidechainsShortcut: proteinSidechains.isOn = !proteinSidechains.isOn; nucleotideSidechains.isOn = !nucleotideSidechains.isOn; return; case eWormShortcut: proteinBackbone.type = nucleotideBackbone.type = eTrace; proteinBackbone.style = nucleotideBackbone.style = eTubeWorm; proteinSidechains.isOn = nucleotideSidechains.isOn = false; proteinSidechains.style = nucleotideSidechains.style = eWire; heterogens.style = eBallAndStick; solvents.isOn = false; solvents.style = eBallAndStick; connections.style = eTubes; helixObjects.isOn = strandObjects.isOn = true; helixObjects.style = strandObjects.style = eWithArrows; break; case eTubeShortcut: proteinBackbone.type = nucleotideBackbone.type = eTrace; proteinBackbone.style = nucleotideBackbone.style = eTubes; proteinSidechains.isOn = nucleotideSidechains.isOn = false; proteinSidechains.style = nucleotideSidechains.style = eWire; heterogens.style = eBallAndStick; solvents.isOn = false; solvents.style = eBallAndStick; connections.style = eTubes; helixObjects.isOn = strandObjects.isOn = false; helixObjects.style = strandObjects.style = eWithArrows; break; case eWireframeShortcut: proteinBackbone.type = nucleotideBackbone.type = eComplete; proteinBackbone.style = nucleotideBackbone.style = eWire; proteinSidechains.isOn = nucleotideSidechains.isOn = true; proteinSidechains.style = nucleotideSidechains.style = eWire;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -