default_policy.hpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:15k
- /*
- * ===========================================================================
- * PRODUCTION $Log: default_policy.hpp,v $
- * PRODUCTION Revision 1000.2 2004/06/01 19:53:16 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.18
- * PRODUCTION
- * ===========================================================================
- */
- #ifndef GUI_WIDGETS_SEQ_GRAPHIC___DEFAULT_POLICY__HPP
- #define GUI_WIDGETS_SEQ_GRAPHIC___DEFAULT_POLICY__HPP
- /* $Id: default_policy.hpp,v 1000.2 2004/06/01 19:53:16 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: Vlad Lebedev
- *
- * File Description:
- *
- */
- #include <gui/gui.hpp>
- #include <gui/widgets/gl/ipolicy.hpp>
- #include <gui/objutils/feat_label.hpp>
- #include <gui/opengl/glbitmapfont.hpp>
- #include <gui/objutils/feature.hpp>
- #include <gui/objutils/alignment.hpp>
- #include <gui/objutils/pw_alignment.hpp>
- #include <gui/objutils/alignment_smear_layout.hpp>
- #include <gui/objutils/graph.hpp>
- #include <gui/objutils/comment.hpp>
- #include <gui/objutils/seq_map.hpp>
- #include <gui/objutils/histogram.hpp>
- #include <gui/objutils/feat_pack.hpp>
- #include <gui/objutils/prot_product.hpp>
- #include <gui/objutils/mate_pair.hpp>
- #include <gui/objutils/sequence.hpp>
- #include <gui/objutils/utils.hpp>
- #include <gui/objutils/label.hpp>
- #include <gui/opengl/glcolortable.hpp>
- #include <gui/widgets/seq_graphic/seqgraphic_conf.hpp>
- #include <objmgr/util/feature.hpp>
- #include <objects/seq/Seq_annot.hpp>
- BEGIN_NCBI_SCOPE
- ///////////////////////////////////////////////////////////////////////////////
- /// CDefaultPolicy is a default policy for rendering layout objects in
- // feature panel of seq_graphic widget.
- ///////////////////////////////////////////////////////////////////////////////
- class NCBI_GUIWIDGETS_SEQGRAPHIC_EXPORT CDefaultPolicy : public IPolicy
- {
- public:
- CDefaultPolicy();
- virtual ~CDefaultPolicy() { };
- // IPolicy interfaces
- virtual TModelUnit GetRowHeight(CGlPane& pane, const CLayoutObject* obj,
- bool selected) const;
- virtual bool ProcessObject(CGlPane& pane, const CLayoutObject* obj,
- TModelUnit row, EObj_IterMode mode, bool selected) const;
- virtual void SetHandle(const objects::CBioseq_Handle& handle);
- virtual void SetConfig(CSeqGraphicConfig* config);
- virtual void SetHitPoint(TModelPoint click);
- virtual void SetActiveArea(TAreaVector* p_area);
- virtual void GetTitle(const CLayoutObject* obj,
- string* title, CLabel::ELabelType) const;
- protected:
- CGlColorTable m_ColorTable;
- TVPUnit m_MinLabelWidth; // minimum label that will fit
-
- // fonts
- CGlBitmapFont m_Font_Bitmap9x15;
- CGlBitmapFont m_Font_Helv10;
- CGlBitmapFont m_Font_Helv8;
- enum EProtSeqType {
- eProteinSeq,
- eTranslatedSeq
- };
- TModelPoint m_LastClick;
- TAreaVector* m_ActiveAreas;
- // map of named annotations, with their indices
- typedef map<string, int> TNamedAnnots;
- mutable TNamedAnnots m_Annots;
- objects::CBioseq_Handle m_Handle;
- CRef<CSeqGraphicConfig> m_ConfigSettings;
-
- // returns offset from the begining of feature,
- // based on frame for protein translation
- TSeqPos x_GetProtOffset(const CLayoutFeat* feat) const;
- // is it enougth space to sequence letters?
- bool x_IsSeqLettersFit(CGlPane& pane) const;
-
- // center label in model coordinates
- GLfloat x_CenterText(CGlPane& pane, TModelRect rc, GLfloat width) const;
- // selected objects
- virtual bool x_IsObjectClicked(CGlPane& pane, const CLayoutObject* obj,
- GLfloat row_y, bool selected) const;
-
- virtual bool x_IsFeatLabelClicked(CGlPane& pane,
- const CLayoutFeatLabel* lbl, GLfloat row_y) const;
-
- TModelUnit x_CalcAlignHeight(const CLayoutAlign* align) const;
-
- // set feature color based on config
- virtual void x_SetFeatureColor(const CLayoutFeat* feat) const;
-
- // Internal incremental pool of CSeq_annots (for higlighting
- // of the named seq. annots.)
- size_t x_GetSeqAnnotIndex(const objects::CSeq_annot_Handle& annot) const;
-
- // draw functions for particular layout objects
- virtual void x_DrawAlignment(CGlPane& pane, const CLayoutAlign* align,
- GLfloat row_y, EObj_IterMode mode, bool selected) const;
-
- virtual void x_DrawAlignmentSmear(CGlPane& pane, const CLayoutAlignSmear* smear,
- GLfloat row_y, EObj_IterMode mode, bool selected) const;
-
- virtual void x_DrawFeature(CGlPane& pane, const CLayoutFeat* feat,
- GLfloat row_y, EObj_IterMode mode, bool selected) const;
- virtual void x_DrawFeatLabel(CGlPane& pane, const CLayoutFeatLabel* feat,
- GLfloat row_y, EObj_IterMode mode, bool selected) const;
-
- virtual void x_DrawProteinProduct(CGlPane& pane, const CLayoutFeat* feat,
- GLfloat row_y, EProtSeqType type, bool selected) const;
- virtual void x_DrawSeqGraph(CGlPane& pane, const CLayoutGraph* graph,
- GLfloat row_y, EObj_IterMode mode, bool selected) const;
- virtual void x_DrawComments(CGlPane& pane, const CLayoutComment* comm,
- GLfloat row_y, EObj_IterMode mode, bool selected) const;
- virtual void x_DrawSequence(CGlPane& pane, const CLayoutSequence* seqs,
- GLfloat row_y, EObj_IterMode mode, bool selected) const;
- virtual void x_DrawSeqSegment(CGlPane& pane, const CLayoutSeqMap* seg,
- GLfloat row_y, EObj_IterMode mode, bool selected) const;
- virtual void x_DrawFeatPack(CGlPane& pane, const CLayoutFeatPack* pack,
- GLfloat row_y, EObj_IterMode mode, bool selected) const;
- virtual void x_DrawHistogram(CGlPane& pane, const CLayoutHistogram* hist,
- GLfloat row_y, EObj_IterMode mode, bool selected) const;
- virtual void x_DrawMatePair(CGlPane& pane, const CLayoutMatePair* pair,
- GLfloat row_y, EObj_IterMode mode, bool selected) const;
- virtual void x_DrawPWAlign(CGlPane& pane, const CLayoutPWAlign* pw_aln,
- GLfloat row_y, EObj_IterMode mode, bool selected) const;
- virtual void x_DrawPWAlignElem(CGlPane& pane, const CLayoutPWAlign* pw_aln,
- GLfloat row_y, EObj_IterMode mode, bool selected,
- CSeqGraphicColorConfig::EDisplayElement c_fg,
- CSeqGraphicColorConfig::EDisplayElement c_seq,
- CSeqGraphicColorConfig::EDisplayElement c_mis) const;
- virtual void x_DrawGridLine(CGlPane& pane, const CLayoutObject* obj,
- GLfloat row_y) const;
- void x_Color(CSeqGraphicColorConfig::EDisplayElement e) const;
-
- void x_GetHTMLActiveAreas(CGlPane& pane, const CLayoutObject* obj,
- GLfloat row_y, bool selected) const;
- void x_AddGetHTMLActiveElement(string title, string tooltip, CGlPane& pane,
- const CLayoutObject* obj, GLfloat row_y, bool selected) const;
-
- // Row height calculations
- virtual TModelUnit x_GetRowHeight(CGlPane& pane,
- const CLayoutFeat* feat, bool selected) const;
- virtual TModelUnit x_GetRowHeight(CGlPane& pane,
- const CLayoutAlign* align, bool selected) const;
- virtual TModelUnit x_GetRowHeight(CGlPane& pane,
- const CLayoutAlignSmear* align, bool selected) const;
- virtual TModelUnit x_GetRowHeight(CGlPane& pane,
- const CLayoutFeatLabel* label, bool selected) const;
- virtual TModelUnit x_GetRowHeight(CGlPane& pane,
- const CLayoutProtProd* prot, bool selected) const;
- virtual TModelUnit x_GetRowHeight(CGlPane& pane,
- const CLayoutGraph* graph, bool selected) const;
- virtual TModelUnit x_GetRowHeight(CGlPane& pane,
- const CLayoutComment* comm, bool selected) const;
- virtual TModelUnit x_GetRowHeight(CGlPane& pane,
- const CLayoutSeqMap* seg, bool selected) const;
- virtual TModelUnit x_GetRowHeight(CGlPane& pane,
- const CLayoutFeatPack* pack, bool selected) const;
- virtual TModelUnit x_GetRowHeight(CGlPane& pane,
- const CLayoutHistogram* hist, bool selected) const;
- virtual TModelUnit x_GetRowHeight(CGlPane& pane,
- const CLayoutSequence* seqs, bool selected) const;
- virtual TModelUnit x_GetRowHeight(CGlPane& pane,
- const CLayoutMatePair* pair, bool selected) const;
- virtual TModelUnit x_GetRowHeight(CGlPane& pane,
- const CLayoutPWAlign* pw_align, bool selected) const;
- virtual void x_DrawSelection(CGlPane& pane,
- TModelUnit x1, TModelUnit y1, TModelUnit x2, TModelUnit y2) const;
- virtual void x_DrawQuad(CGlPane& pane,
- TModelUnit x1, TModelUnit y1, TModelUnit x2, TModelUnit y2) const;
- // Getting titles
- virtual void x_GetTitle(const CLayoutFeat* feat, string* title,
- CLabel::ELabelType type = CLabel::eDefault) const;
- virtual void x_GetTitle(const CLayoutAlign* align, string* title,
- CLabel::ELabelType type = CLabel::eDefault) const;
- virtual void x_GetTitle(const CLayoutGraph* graph, string* title,
- CLabel::ELabelType type = CLabel::eDefault) const;
- virtual void x_GetTitle(const CLayoutFeatPack* pack, string* title,
- CLabel::ELabelType type = CLabel::eDefault) const;
- virtual void x_GetTitle(const CLayoutHistogram* hist, string* title,
- CLabel::ELabelType type = CLabel::eDefault) const;
- virtual void x_GetTitle(const CLayoutSeqMap* seg, string* title,
- CLabel::ELabelType type = CLabel::eDefault) const;
- virtual void x_GetTitle(const CLayoutSequence* seqs, string* title,
- CLabel::ELabelType type = CLabel::eDefault) const;
- virtual void x_GetTitle(const CLayoutMatePair* pair, string* title,
- CLabel::ELabelType type = CLabel::eDefault) const;
- virtual void x_GetTitle(const CLayoutPWAlign* pw_align, string* title,
- CLabel::ELabelType type = CLabel::eDefault) const;
-
- // retrieve a set of labels for a given feature
- void x_GetLabels(const objects::CSeq_feat& feat,
- objects::CScope& scope,
- string* label_type,
- string* label_content,
- string* label_both) const;
- // x_PreparePlot and x_DrawPlot are for drawing
- // three different kind of graphs: Byte, Real and Integer
- //
- // FixMe: Code below will be changed soon to use GetOffSetX and GetOffSetY
- // methods of CGlPane
- template <class T>
- void x_DrawPlot(CGlPane& pane, const T& vec, int min_v, int max_v,
- TSeqRange range, GLfloat row_y, TModelUnit size) const
- {
- TModelUnit offsetX = pane.GetOffsetX();
- TModelUnit offsetY = pane.GetOffsetY();
- GLfloat delta = max_v - min_v;
- GLfloat step = (range.GetTo() - range.GetFrom()) / vec.size();
- GLfloat yy = row_y + 20 - offsetY;
-
- for (size_t j = 1; j <= vec.size(); ++j) {
- int curr_y = int( vec[j] );
- int prev_y = int( vec[j-1] );
- GLfloat yy1 = yy - 10 * (prev_y - min_v) / delta - 1.0f;
- GLfloat yy2 = yy - 10 * (curr_y - min_v) / delta - 1.0f;
-
- GLfloat xx1 = range.GetFrom() + (step * (j-1));
- GLfloat xx2 = range.GetFrom() + (step * j);
-
- glVertex2f(xx1 - offsetX, yy1);
- glVertex2f(xx2 - offsetX, yy2);
- }
- }
-
- template <class T>
- void x_PreparePlot(CGlPane& pane, const T& vec,
- TSeqRange range, GLfloat row_y, TModelUnit size) const
- {
- int min_v = int(vec.GetMin());
- int max_v = int(vec.GetMax());
-
- if (vec.CanGetValues()) {
- x_DrawPlot(pane, vec.GetValues(), min_v, max_v, range, row_y, size);
- }
- }
- };
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: default_policy.hpp,v $
- * Revision 1000.2 2004/06/01 19:53:16 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.18
- *
- * Revision 1.18 2004/05/14 16:00:28 lebedev
- * Respect color defines for Mate Pairs error codes. Draw pair wise alignment strand
- * indicators as arrows. Use CLabel::eTooltipDetailed mode for tooltips.
- *
- * Revision 1.17 2004/05/03 12:46:32 dicuccio
- * gui/utils ->gui/objutils where needed
- *
- * Revision 1.16 2004/04/21 16:35:40 lebedev
- * Support for pair-wise alignments added. Rendering of Mate Pairs changed.
- * Return multiple HTML Active areas for Mate Pair objects.
- *
- * Revision 1.15 2004/04/16 14:34:36 dicuccio
- * Use raw pointer for SetConfig() instead of CRef<>
- *
- * Revision 1.14 2004/04/14 11:25:50 lebedev
- * Added rendering of Mate Pairs.
- *
- * Revision 1.13 2004/04/07 12:43:02 dicuccio
- * Use CSeq_annot_Handle to get real name of annotation
- *
- * Revision 1.12 2004/04/06 13:30:47 dicuccio
- * Formatting changes. Removed dead code.
- *
- * Revision 1.11 2004/03/31 16:09:01 lebedev
- * Methods to get HTML active areas added.
- *
- * Revision 1.10 2004/03/30 13:58:39 lebedev
- * Use elements colors from configuration instead of setting colors directly.
- *
- * Revision 1.9 2004/03/26 15:46:03 lebedev
- * Rendering of SeqGraphs fixed
- *
- * Revision 1.8 2004/03/23 12:33:56 lebedev
- * Made sequence and histograms bars a layout objects in the object panel.
- * Made segment map a number of layout objects. Get rid of fixed size rows in the object panel.
- *
- * Revision 1.7 2004/03/22 16:50:19 rsmith
- * add x_DrawAlignmentSmear and x_GetRowHeight for alignment smears.
- *
- * Revision 1.6 2004/03/11 17:23:38 dicuccio
- * Use TSeqRange instead of TRange. Deprecated TIndex / TPosition / TDimension
- *
- * Revision 1.5 2004/02/24 14:47:15 lebedev
- * Support for new types of layout objects added
- *
- * Revision 1.4 2004/01/16 13:37:57 lebedev
- * Tooltips added
- *
- * Revision 1.3 2004/01/05 17:49:06 dicuccio
- * Added x_GetLabels()
- *
- * Revision 1.2 2003/12/30 14:54:59 dicuccio
- * Standardized export specifiers
- *
- * Revision 1.1 2003/12/16 18:58:59 lebedev
- * Initial revision
- *
- * ===========================================================================
- */
- #endif // GUI_WIDGETS_SEQ_GRAPHIC___DEFAULT_POLICY__HPP