align_mark_handler.hpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:9k
- /*
- * ===========================================================================
- * PRODUCTION $Log: align_mark_handler.hpp,v $
- * PRODUCTION Revision 1000.3 2004/04/12 18:15:40 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [CATCHUP_003] Dev-tree R1.13
- * PRODUCTION
- * ===========================================================================
- */
- #ifndef GUI_WIDGETS_ALNMULTI___ALIGN_MARK_HANDLER__HPP
- #define GUI_WIDGETS_ALNMULTI___ALIGN_MARK_HANDLER__HPP
- /* $Id: align_mark_handler.hpp,v 1000.3 2004/04/12 18:15:40 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: Andrey Yazhuk
- *
- * File Description:
- * CAlignMarkHandler - class implementing support for Marks in alignments.
- * IAlignMarkHandlerHost - context in which CAlignMarkHandler operates.
- */
- #include <corelib/ncbistl.hpp>
- #include <corelib/ncbistd.hpp>
- #include <util/range_coll.hpp>
- #include <gui/opengl/glpane.hpp>
- #include <gui/utils/gui_event.hpp>
- #include <gui/widgets/gl/ievent_handler.hpp>
- #include <objects/seqloc/Seq_loc.hpp>
- #include <gui/widgets/aln_multiple/alnmulti_ds.hpp>
- #include <gui/widgets/aln_multiple/list_mvc.hpp>
- BEGIN_NCBI_SCOPE
- // Mark is collection of ranges representing selection on a sequence
- // CRangeCollection<TSeqPos> is used to repreesent marks
- ////////////////////////////////////////////////////////////////////////////////
- /// interface IAlignMarkHandlerHost
- // This interface represent context in which CAlignMarkHandler operates.
- // This context provides the following things:
- // - A way to obtain ISelListModel interface in order to check which sequences are
- // currently selected.
- // - Functions for conversions Pixels <-> Line numbers <-> Alignment Row Indexes
- // - Function converting horz. screen coordinate in the position in alignment.
- // - Function forsing redrawing of the context.
- class IAlignMarkHandlerHost
- {
- public:
- typedef IAlnMultiDataSource::TNumrow TNumrow;
- typedef CRangeCollection<TSeqPos> TRangeColl;
- typedef map<TNumrow, TRangeColl> TRowToMarkMap;
- typedef ISelListModel<TNumrow> TSelListModel;
- public:
- virtual ~IAlignMarkHandlerHost() {};
-
- virtual const IAlnMultiDataSource* MHH_GetAlnDS() const = 0;
- virtual const TSelListModel* MHH_GetSelListModel() const = 0;
- virtual TNumrow MHH_GetRowByLine(int Index) const = 0;
- virtual int MHH_GetLineByRowNum(TNumrow Row) const = 0;
- virtual int MHH_GetLineByWindowY(int Y) const = 0;
- virtual int MHH_GetLinePosY(int Index) const = 0;
- virtual int MHH_GetLineHeight(int Index) const = 0;
- virtual TModelUnit MHH_GetSeqPosByX(int X) const = 0;
- virtual void MHH_Redraw() = 0;
- };
- ////////////////////////////////////////////////////////////////////////////////
- /// CAlignMarkHandler manages handling and editing of marks on alignments.
- ///
- /// It holds a collection of marks corresponding to sequences of the alignment
- /// and processes FLTK events in order to provide interactive editing of marks.
- /// CAlignMarkHandler renders marks in the provided CGlPane instance (which needs
- /// to be properly setup). Each mark is represented as collection of intervals
- /// stored in CRangeCollection container.
- class CAlignMarkHandler : public IEventHandler
- {
- public:
- typedef IAlnMultiDataSource::TNumrow TNumrow;
- typedef IAlignMarkHandlerHost::TRangeColl TRangeColl;
- typedef IAlignMarkHandlerHost::TSelListModel TSelListModel;
- typedef map<TNumrow, TRangeColl> TRowToMarkMap;
- CAlignMarkHandler();
- void SetHost(IAlignMarkHandlerHost* pHost);
- /// IEventHandler implementation.
- virtual int handle(CGUIEvent& event, CGlPane& Pane);
- void Render(CGlPane& Pane); // renders marks
- // opeartions with Mark (don't automaticaly update display)
- void MarkSelectedRows(const TRangeColl& C, bool bMark);
- void UnMarkAll();
- void UnMarkSelected();
- const TRowToMarkMap& GetMarks() const;
- protected:
- // FLTK event handlers - translate event to signals
- int x_OnMousePush(CGUIEvent& event);
- int x_OnMouseDrag(CGUIEvent& event);
- int x_OnMouseRelease(CGUIEvent& event);
- int x_OnMouseMove(CGUIEvent& event);
- int x_OnKeyDown(CGUIEvent& event);
- int x_OnKeyUp(CGUIEvent& event);
- enum EState {
- eIdle,
- eReady,
- eResize
- };
-
-
- // signal handlers - functions doing the real job
- void x_OnStartSel();
- void x_OnChangeSelRange();
- void x_OnEndSelRange(EState new_state);
- void x_OnResetAll();
-
-
- protected:
- // helper class representing range being edited
- struct SMarkDelta {
- enum EExtState {
- eNoExt,
- eExtRangeStart,
- eExtRangeEnd,
- };
- TSeqRange m_HitRange; // preexisted range that was hit by the mouse
- TSeqRange m_Range; // current range
- EExtState m_StartState; //initial extension state
- EExtState m_State; //current extension state
- SMarkDelta() : m_StartState(eNoExt), m_State(eNoExt) {}
- SMarkDelta(const TSeqRange& HitR, const TSeqRange& R, EExtState StartS, EExtState S)
- : m_HitRange(HitR), m_Range(R), m_StartState(StartS), m_State(S) {}
- };
-
- // helper functions
- bool x_ModifiersOk() const;
- TModelUnit x_MouseToSeqPos();
- TSeqPos x_ClipPosByRange(TSeqPos Pos);
- bool x_HitRangeBorder() const;
-
- void x_InitDeltaMap();
- void x_HitTest(TNumrow Row, const TRangeColl& C, int X, TSeqRange& Range, bool& bHitStart) const;
- bool x_HitSelectedLine();
- void x_UpdateDelta(TSeqRange& R, SMarkDelta::EExtState& State, TSeqPos Pos);
- void x_UpdateSelection(TSeqPos NewPos);
- void x_UpdateMarks();
- void x_UpdateState(bool b_key);
- bool x_OpKeyPressed() const;
- void x_OnSelectCursor();
- const IAlignMarkHandlerHost* x_GetHost() const { return m_pHost; }
- IAlignMarkHandlerHost* x_GetHost() { return m_pHost; }
- protected:
- typedef map<TNumrow, SMarkDelta> TRowToDeltaMap;
- TRowToMarkMap m_mpRowToMark; // Marks
- TRowToDeltaMap m_mpRowToDelta; // Ranges being edited
- IAlignMarkHandlerHost* m_pHost;
- CGlPane* m_pPane;
- bool m_bHitResizable;
- EState m_State; // operation type
- Fl_Cursor m_Cursor;
- TSeqPos m_PrevPos;
-
- CGlColor m_FillColor;
- CGlColor m_FrameColor;
- };
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: align_mark_handler.hpp,v $
- * Revision 1000.3 2004/04/12 18:15:40 gouriano
- * PRODUCTION: UPGRADED [CATCHUP_003] Dev-tree R1.13
- *
- * Revision 1.13 2004/03/17 20:16:56 yazhuk
- * Replaced #include <..fltk_utils.hpp> with <...gui_event.hpp>
- *
- * Revision 1.12 2004/03/11 17:24:13 dicuccio
- * Use TSeqRange instead of TRange
- *
- * Revision 1.11 2003/12/18 21:12:36 yazhuk
- * Updated code to supported template ISelListModel
- *
- * Revision 1.10 2003/12/10 17:12:09 yazhuk
- * Added colors as data members.
- *
- * Revision 1.9 2003/12/01 16:42:59 yazhuk
- * Refactored event handling - introduced CGUIEvent
- *
- * Revision 1.8 2003/11/17 21:12:00 yazhuk
- * Updated include path for ievent_handler.hpp
- *
- * Revision 1.7 2003/11/06 20:01:09 dicuccio
- * Removed USING_SCOPE(objects)
- *
- * Revision 1.6 2003/10/29 23:23:06 yazhuk
- * Replaced CAlnMultiDataSource with IAlignMultiDataSource
- *
- * Revision 1.5 2003/10/20 15:45:54 yazhuk
- * Inherited from IEventHandler
- *
- * Revision 1.4 2003/10/15 21:22:47 yazhuk
- * Migrated from using CAlnVec to accessing data via "generic" interface in CAlignDataSource.
- *
- * Revision 1.3 2003/10/08 14:12:58 dicuccio
- * Moved CGlPane into opengl
- *
- * Revision 1.2 2003/09/29 13:45:39 yazhuk
- * Added GetMarks()
- *
- * Revision 1.1 2003/09/23 21:18:37 yazhuk
- * Initial revision
- *
- * ===========================================================================
- */
- #endif // GUI_WIDGETS_ALNMULTI___ALIGN_MARK_HANDLER__HPP