valerror_display.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:7k
- /*
- * ===========================================================================
- * PRODUCTION $Log: valerror_display.cpp,v $
- * PRODUCTION Revision 1000.1 2004/06/01 21:03:20 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.4
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: valerror_display.cpp,v 1000.1 2004/06/01 21:03:20 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: Mati Shomrat
- *
- * File Description:
- *
- *
- */
- #include <ncbi_pch.hpp>
- #include <corelib/ncbistd.hpp>
- #include <objtools/validator/validator.hpp>
- #include <FL/Fl.H>
- #include <FL/Fl_Group.H>
- #include <FL/Fl_Scroll.H>
- #include <FL/Fl_Pack.H>
- #include <FL/Fl_Box.H>
- #include "valerror_display.hpp"
- #include "erritem_view.hpp"
- #include "filter.hpp"
- #include "statistics.hpp"
- USING_SCOPE(ncbi::objects::validator);
- BEGIN_NCBI_SCOPE
- // static variables initializers
- const string CValidErrorDisplay::sm_ShownLabel = "Error shown: ";
- // public:
- CValidErrorDisplay::CValidErrorDisplay(int x, int y, int w, int h) :
- Fl_Group(x, y, w, h, 0),
- m_Scroll(0),
- m_Pack(0),
- m_Shown(0),
- m_Stats(0)
- {
- m_Shown = CreateShown(x, y, w, 25);
- SetShown(0);
- m_Scroll = CreateScroll(x, y + 25, w, h - 55);
- m_Pack = CreatePack(x, y + 25, w, h - 55);
- m_Scroll->add(m_Pack);
- m_Stats = new CValidErrorStats(x + 10, y + h - 25 , w, 25);
- end();
- }
- CValidErrorDisplay::~CValidErrorDisplay(void)
- {
- }
- void CValidErrorDisplay::Update(const CValidatorFilter* filter)
- {
- EDiagSev min = eDiag_Info;
- EDiagSev max = eDiag_Critical;
- string err_code = kEmptyStr;
- string search_str = kEmptyStr;
- CValidErrItemView::EMessage message = CValidErrItemView::eMessage_Verbose;
- if ( filter ) {
- min = filter->GetMinSev();
- max = filter->GetMaxSev();
- err_code = filter->GetErrCode();
- if ( err_code == "All" ) {
- err_code = kEmptyStr;
- }
- search_str = filter->GetSearchString();
- message = filter->GetMessage();
- }
- m_Pack->clear();
- for ( CValidError_CI iter(*m_Errors, err_code, min, max);
- iter;
- ++iter ) {
- if ( search_str.empty() ||
- NStr::FindNoCase(iter->GetMsg(), search_str) != NPOS) {
- m_Pack->add(new CValidErrItemView(*iter, w(), message));
- }
- }
- SetShown(m_Pack->children());
-
- m_Scroll->redraw();
- }
- void CValidErrorDisplay::SetValidError(const CValidError& errors)
- {
- m_Errors.Reset(&errors);
- m_Stats->SetValidError(errors);
- Update();
- }
- void CValidErrorDisplay::DisplayVerbose(bool verbose)
- {
- Fl_Widget*const* items = m_Pack->array();
- SIZE_TYPE num_items = m_Pack->children();
- CValidErrItemView::EMessage message = verbose ?
- CValidErrItemView::eMessage_Verbose : CValidErrItemView::eMessage_Terse;
- for ( SIZE_TYPE i = 0; i < num_items; ++i ) {
- CValidErrItemView* item = dynamic_cast<CValidErrItemView*>(items[i]);
- item->SetMessage(message);
- }
- m_Scroll->position(0,0);
- m_Scroll->redraw();
- }
- // private:
- class CMyScroll : public Fl_Scroll
- {
- public:
- CMyScroll(int x, int y, int w, int h, const char* label = 0) :
- Fl_Scroll(x, y, w, h, label)
- {}
-
- // Insure the scrollbars are the last children:
- void fix_scrollbar_order()
- {
- Fl_Widget** a = (Fl_Widget**)array();
- if (a[children()-1] != &scrollbar) {
- int i,j; for (i = j = 0; j < children(); j++)
- if (a[j] != &hscrollbar && a[j] != &scrollbar) a[i++] = a[j];
- a[i++] = &hscrollbar;
- a[i++] = &scrollbar;
- }
- }
- virtual void resize(int X, int Y, int W, int H)
- {
- fix_scrollbar_order();
- // size all the children:
- int _W = W - scrollbar.w();
- int _H = H - hscrollbar.h();
- Fl_Widget*const* a = array();
- for (int i=children()-2; i--;) {
- Fl_Widget* o = *a++;
- o->resize(o->x()+X-x(), o->y()+Y-y(), _W, _H);
- }
- Fl_Widget::resize(X,Y,W,H);
- }
- };
- Fl_Scroll* CValidErrorDisplay::CreateScroll(int X, int Y, int W, int H)
- {
- Fl_Boxtype box_type = FL_DOWN_FRAME;
- int dx = Fl::box_dx(box_type);
- int dy = Fl::box_dy(box_type);
- int dw = Fl::box_dw(box_type);
- int dh = Fl::box_dh(box_type);
-
- Fl_Group* group = new Fl_Group(X, Y, W, H);
- group->box(box_type);
- resizable(group);
- Fl_Scroll* scroll = new CMyScroll(X + dx, Y + dy, W - dw, H - dh);
- scroll->type(Fl_Scroll::VERTICAL);
- scroll->color(FL_WHITE);
- scroll->end();
- group->end();
- return scroll;
- }
- Fl_Pack* CValidErrorDisplay::CreatePack(int x, int y, int w, int h)
- {
- Fl_Pack* pack = new Fl_Pack(x, y, w, h, 0);
- pack->end();
- return pack;
- }
- Fl_Box* CValidErrorDisplay::CreateShown(int x, int y, int w, int h)
- {
- Fl_Box* shown = new Fl_Box(x, y, w, h, 0);
- shown->labelfont(FL_COURIER);
- shown->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE);
-
- return shown;
- }
- void CValidErrorDisplay::SetShown(int num)
- {
- m_ShownLabel = "Errors Shown: " + NStr::IntToString(num);
- m_Shown->label(m_ShownLabel.c_str());
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- *
- * $Log: valerror_display.cpp,v $
- * Revision 1000.1 2004/06/01 21:03:20 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.4
- *
- * Revision 1.4 2004/05/21 22:27:50 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.3 2003/06/02 16:06:25 dicuccio
- * Rearranged src/objects/ subtree. This includes the following shifts:
- * - src/objects/asn2asn --> arc/app/asn2asn
- * - src/objects/testmedline --> src/objects/ncbimime/test
- * - src/objects/objmgr --> src/objmgr
- * - src/objects/util --> src/objmgr/util
- * - src/objects/alnmgr --> src/objtools/alnmgr
- * - src/objects/flat --> src/objtools/flat
- * - src/objects/validator --> src/objtools/validator
- * - src/objects/cddalignview --> src/objtools/cddalignview
- * In addition, libseq now includes six of the objects/seq... libs, and libmmdb
- * replaces the three libmmdb? libs.
- *
- * Revision 1.2 2003/04/22 16:24:52 shomrat
- * Fl -> FL
- *
- * Revision 1.1 2003/04/18 19:57:16 shomrat
- * Initial revision
- *
- *
- * ===========================================================================
- */