📄 messenger.cpp
字号:
/* * =========================================================================== * PRODUCTION $Log: messenger.cpp,v $ * PRODUCTION Revision 1000.3 2004/06/01 18:28:39 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.42 * PRODUCTION * =========================================================================== *//* $Id: messenger.cpp,v 1000.3 2004/06/01 18:28:39 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:* Classes to handle messaging and communication between sequence* and structure windows** ===========================================================================*/#ifdef _MSC_VER#pragma warning(disable:4018) // disable signed/unsigned mismatch warning in MSVC#endif#include <ncbi_pch.hpp>#include <corelib/ncbistd.hpp>#include <memory>#include <objects/mmdb1/Biostruc_id.hpp>#include <objects/mmdb1/Mmdb_id.hpp>#include <objects/mmdb3/Biostruc_feature_set.hpp>#include <objects/mmdb3/Biostruc_feature_set_id.hpp>#include <objects/mmdb3/Biostruc_feature.hpp>#include <objects/mmdb3/Chem_graph_pntrs.hpp>#include <objects/mmdb3/Residue_pntrs.hpp>#include <objects/mmdb3/Residue_interval_pntr.hpp>#include <objects/mmdb1/Molecule_id.hpp>#include <objects/mmdb1/Residue_id.hpp>#include "messenger.hpp"#include "structure_window.hpp"#include "cn3d_glcanvas.hpp"#include "sequence_viewer.hpp"#include "opengl_renderer.hpp"#include "structure_set.hpp"#include "chemical_graph.hpp"#include "sequence_set.hpp"#include "molecule_identifier.hpp"#include "cn3d_tools.hpp"USING_NCBI_SCOPE;USING_SCOPE(objects);BEGIN_SCOPE(Cn3D)// the global Messenger objectstatic Messenger messenger;Messenger * GlobalMessenger(void){ return &messenger;}void Messenger::PostRedrawAllStructures(void){ redrawAllStructures = true; redrawMolecules.clear();}void Messenger::PostRedrawMolecule(const Molecule *molecule){ if (!redrawAllStructures) redrawMolecules[molecule] = true;}void Messenger::PostRedrawAllSequenceViewers(void){ redrawAllSequenceViewers = true; redrawSequenceViewers.clear();}void Messenger::PostRedrawSequenceViewer(ViewerBase *viewer){ if (!redrawAllSequenceViewers) redrawSequenceViewers[viewer] = true;}void Messenger::UnPostRedrawAllSequenceViewers(void){ redrawAllSequenceViewers = false; redrawSequenceViewers.clear();}void Messenger::UnPostRedrawSequenceViewer(ViewerBase *viewer){ if (redrawAllSequenceViewers) { SequenceViewerList::const_iterator q, qe = sequenceViewers.end(); for (q=sequenceViewers.begin(); q!=qe; ++q) redrawSequenceViewers[*q] = true; redrawAllSequenceViewers = false; } RedrawSequenceViewerList::iterator f = redrawSequenceViewers.find(viewer); if (f != redrawSequenceViewers.end()) redrawSequenceViewers.erase(f);}void Messenger::UnPostStructureRedraws(void){ redrawAllStructures = false; redrawMolecules.clear();}void Messenger::ProcessRedraws(void){ if (redrawAllSequenceViewers) { SequenceViewerList::const_iterator q, qe = sequenceViewers.end(); for (q=sequenceViewers.begin(); q!=qe; ++q) (*q)->Refresh(); redrawAllSequenceViewers = false; } else if (redrawSequenceViewers.size() > 0) { RedrawSequenceViewerList::const_iterator q, qe = redrawSequenceViewers.end(); for (q=redrawSequenceViewers.begin(); q!=qe; ++q) q->first->Refresh(); redrawSequenceViewers.clear(); } if (redrawAllStructures) { if (structureWindow) { structureWindow->glCanvas->SetCurrent(); structureWindow->glCanvas->renderer->Construct(); structureWindow->glCanvas->renderer->NewView(); structureWindow->glCanvas->Refresh(false); } redrawAllStructures = false; } else if (redrawMolecules.size() > 0) { map < const StructureObject * , bool > hetsRedrawn; RedrawMoleculeList::const_iterator m, me = redrawMolecules.end(); for (m=redrawMolecules.begin(); m!=me; ++m) { const StructureObject *object; if (!m->first->GetParentOfType(&object)) continue; // hets/solvents are always redrawn with each molecule, so don't need to repeat if ((m->first->IsSolvent() || m->first->IsHeterogen()) && hetsRedrawn.find(object) != hetsRedrawn.end()) continue; object->graph->RedrawMolecule(m->first->id); hetsRedrawn[object] = true; } if (structureWindow) { structureWindow->glCanvas->renderer->NewView(); structureWindow->glCanvas->Refresh(false); } redrawMolecules.clear(); }}void Messenger::RemoveStructureWindow(const StructureWindow *window){ if (window != structureWindow) ERRORMSG("Messenger::RemoveStructureWindow() - window mismatch"); structureWindow = NULL;}void Messenger::RemoveSequenceViewer(const ViewerBase *sequenceViewer){ SequenceViewerList::iterator t, te = sequenceViewers.end(); for (t=sequenceViewers.begin(); t!=te; ++t) { if (*t == sequenceViewer) sequenceViewers.erase(t); break; }}void Messenger::SequenceWindowsSave(bool prompt){ SequenceViewerList::const_iterator q, qe = sequenceViewers.end(); for (q=sequenceViewers.begin(); q!=qe; ++q) (*q)->SaveDialog(prompt);}void Messenger::NewSequenceViewerFont(void){ SequenceViewerList::const_iterator q, qe = sequenceViewers.end(); for (q=sequenceViewers.begin(); q!=qe; ++q) (*q)->NewFont();}///// highlighting functions /////bool Messenger::IsHighlighted(const MoleculeIdentifier *identifier, int index) const{ if (highlightingSuspended) return false; MoleculeHighlightMap::const_iterator h = highlights.find(identifier); if (h == highlights.end()) return false; if (index == -1) return true; // special check for highlight anywhere if (index < 0 || index >= h->second.size()) { ERRORMSG("Messenger::IsHighlighted() - index out of range"); return false; } else return h->second[index];}bool Messenger::IsHighlighted(const Molecule *molecule, int residueID) const{ return IsHighlighted(molecule->identifier, residueID - 1); // assume index = id - 1}bool Messenger::IsHighlighted(const Sequence *sequence, int seqIndex) const{ return IsHighlighted(sequence->identifier, seqIndex);}bool Messenger::IsHighlightedAnywhere(const MoleculeIdentifier *identifier) const{ return IsHighlighted(identifier, -1);}void Messenger::RedrawMoleculesWithIdentifier(const MoleculeIdentifier *identifier, const StructureSet *set){ StructureSet::ObjectList::const_iterator o, oe = set->objects.end(); ChemicalGraph::MoleculeMap::const_iterator m, me; for (o=set->objects.begin(); o!=oe; ++o) { for (m=(*o)->graph->molecules.begin(), me=(*o)->graph->molecules.end(); m!=me; ++m) { if (m->second->identifier == identifier) PostRedrawMolecule(m->second); } }}void Messenger::AddHighlights(const Sequence *sequence, int seqIndexFrom, int seqIndexTo){ if (seqIndexFrom < 0 || seqIndexTo < 0 || seqIndexFrom > seqIndexTo || seqIndexFrom >= sequence->Length() || seqIndexTo >= sequence->Length()) { ERRORMSG("Messenger::AddHighlights() - seqIndex out of range"); return; } MoleculeHighlightMap::iterator h = highlights.find(sequence->identifier); if (h == highlights.end()) { highlights[sequence->identifier].resize(sequence->Length(), false); h = highlights.find(sequence->identifier); } for (int i=seqIndexFrom; i<=seqIndexTo; ++i) h->second[i] = true; PostRedrawAllSequenceViewers(); RedrawMoleculesWithIdentifier(sequence->identifier, sequence->parentSet);}void Messenger::HighlightAndShowSequence(const Sequence *sequence){ RemoveAllHighlights(true); AddHighlights(sequence, 0, sequence->Length() - 1); SequenceViewerList::const_iterator q, qe = sequenceViewers.end(); for (q=sequenceViewers.begin(); q!=qe; ++q) (*q)->MakeSequenceVisible(sequence->identifier);}void Messenger::RemoveHighlights(const Sequence *sequence, int seqIndexFrom, int seqIndexTo){ if (seqIndexFrom < 0 || seqIndexTo < 0 || seqIndexFrom > seqIndexTo || seqIndexFrom >= sequence->Length() || seqIndexTo >= sequence->Length()) { ERRORMSG("Messenger::RemoveHighlights() - seqIndex out of range"); return; } MoleculeHighlightMap::iterator h = highlights.find(sequence->identifier); if (h != highlights.end()) { int i; for (i=seqIndexFrom; i<=seqIndexTo; ++i) h->second[i] = false; // remove sequence from store if no highlights left for (i=0; i<sequence->Length(); ++i) if (h->second[i] == true) break; if (i == sequence->Length()) highlights.erase(h); PostRedrawAllSequenceViewers(); RedrawMoleculesWithIdentifier(sequence->identifier, sequence->parentSet); }}void Messenger::ToggleHighlights(const MoleculeIdentifier *identifier, int indexFrom, int indexTo, const StructureSet *set){ if (indexFrom < 0 || indexTo < 0 || indexFrom > indexTo || indexFrom >= identifier->nResidues || indexTo >= identifier->nResidues) { ERRORMSG("Messenger::ToggleHighlights() - index out of range"); return; } MoleculeHighlightMap::iterator h = highlights.find(identifier); if (h == highlights.end()) { highlights[identifier].resize(identifier->nResidues, false); h = highlights.find(identifier); } int i; for (i=indexFrom; i<=indexTo; ++i) h->second[i] = !h->second[i]; // remove sequence from store if no highlights left for (i=0; i<h->second.size(); ++i) if (h->second[i] == true) break; if (i == h->second.size()) highlights.erase(h); PostRedrawAllSequenceViewers(); RedrawMoleculesWithIdentifier(identifier, set);}void Messenger::ToggleHighlights(const Sequence *sequence, int seqIndexFrom, int seqIndexTo){ ToggleHighlights(sequence->identifier, seqIndexFrom, seqIndexTo, sequence->parentSet);}void Messenger::ToggleHighlight(const Molecule *molecule, int residueID, bool scrollViewersTo){ // assume index = id - 1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -