filter.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:8k
- /*
- * ===========================================================================
- * PRODUCTION $Log: filter.cpp,v $
- * PRODUCTION Revision 1000.1 2004/06/01 21:03:16 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.3
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: filter.cpp,v 1000.1 2004/06/01 21:03: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: Mati Shomrat
- *
- * File Description:
- *
- *
- */
- #include <ncbi_pch.hpp>
- #include <corelib/ncbistd.hpp>
- #include <FL/Fl.H>
- #include <FL/Fl_Choice.H>
- #include <FL/Fl_Box.H>
- #include <FL/Fl_Button.H>
- #include <FL/Fl_Check_Button.H>
- #include <FL/Fl_Input.H>
- #include <algorithm>
- #include "filter.hpp"
- #include "valerror_display.hpp"
- #include "erritem_view.hpp"
- BEGIN_NCBI_SCOPE
- // Public:
- CValidatorFilter::CValidatorFilter
- (int x,
- int y,
- EDiagSev min,
- EDiagSev max,
- bool verbose) :
- Fl_Group(x, y, 580, 134, 0)
- {
- box(FL_ENGRAVED_BOX);
- resizable(0);
- AddSeverityFilter(min, max);
- AddErrCodeFilter();
- AddSearchFilter();
- AddVerboseFilter(verbose);
- end();
- }
- CValidatorFilter::~CValidatorFilter(void)
- {
- }
- string CValidatorFilter::GetErrCode(void) const
- {
- return (m_ErrCodesChoice->value() == 0) ?
- kEmptyStr : m_ErrCodesChoice->text();
- }
- string CValidatorFilter::GetSearchString(void) const
- {
- return m_SearchInput->value();
- }
- EDiagSev CValidatorFilter::GetMinSev(void) const
- {
- return static_cast<EDiagSev>(m_MinSevChoice->value());
- }
- EDiagSev CValidatorFilter::GetMaxSev(void) const
- {
- return static_cast<EDiagSev>(m_MaxSevChoice->value());
- }
- CValidErrItemView::EMessage CValidatorFilter::GetMessage(void) const
- {
- return m_VerboseButton->value() ?
- CValidErrItemView::eMessage_Verbose : CValidErrItemView::eMessage_Terse;
- }
- void CValidatorFilter::SetErrCodes(const set<string>& errcodes)
- {
- m_ErrCodesChoice->clear();
- ITERATE( set<string>, errcode, errcodes ) {
- m_ErrCodesChoice->add(errcode->c_str(), 0, 0);
- }
- m_ErrCodesChoice->value(0);
- }
- // Private:
- void CValidatorFilter::AddSeverityFilter(EDiagSev min, EDiagSev max)
- {
- static const char* sevstr = "Info|Warning|Error|Critical";
-
- Fl_Box* b = new Fl_Box(x() + 2, y() + 5, 130, 25, "Severity - Min:");
- b->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE);
- b->labelfont(FL_COURIER);
- m_MinSevChoice = new Fl_Choice(x() + 130, y() + 5, 85, 25);
- m_MinSevChoice->labelfont(FL_COURIER);
- m_MinSevChoice->add(sevstr);
- m_MinSevChoice->value(min);
- m_MinSevChoice->callback((Fl_Callback*)CValidatorFilter::cb_OnSevChange, this);
- b = new Fl_Box(x() + 230, y() + 5, 50, 25, "Max:");
- b->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE);
- b->labelfont(FL_COURIER);
- m_MaxSevChoice = new Fl_Choice(x() + 270, y() + 5, 85, 25);
- m_MaxSevChoice->labelfont(FL_COURIER);
- m_MaxSevChoice->add(sevstr);
- m_MaxSevChoice->value(max);
- m_MaxSevChoice->callback((Fl_Callback*)CValidatorFilter::cb_OnSevChange, this);
- InactivateSev();
- }
- void CValidatorFilter::AddErrCodeFilter(void)
- {
- Fl_Box* b = new Fl_Box(x() + 2, y() + 42, 130, 25, "Error Codes:");
- b->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE);
- b->labelfont(FL_COURIER);
- m_ErrCodesChoice = new Fl_Choice(x() + 130, y() + 42, 250, 25);
- m_ErrCodesChoice->labelfont(FL_COURIER);
- m_ErrCodesChoice->callback((Fl_Callback*)CValidatorFilter::cb_OnErrCodeChange, this);
- }
- void CValidatorFilter::AddSearchFilter(void)
- {
- m_SearchButton = new Fl_Button(x() + 5, y() + 78, 90, 25, "Search:");
- m_SearchButton->labelfont(FL_COURIER);
- m_SearchButton->deactivate();
- m_SearchButton->callback((Fl_Callback*)CValidatorFilter::cb_OnSearchPressed, this);
-
- m_SearchInput = new Fl_Input(x() + 130, y() + 78, 200, 25, 0);
- m_SearchInput->callback((Fl_Callback*)CValidatorFilter::cb_OnSearchInput, this);
- m_SearchInput->when(FL_WHEN_CHANGED | FL_WHEN_ENTER_KEY_ALWAYS);
- }
- void CValidatorFilter::AddVerboseFilter(bool verbose)
- {
- m_VerboseButton = new Fl_Check_Button(x() + 2, y() + 110, 25 , 25, " Verbose");
- m_VerboseButton->labelfont(FL_COURIER);
- m_VerboseButton->when(FL_WHEN_RELEASE);
- m_VerboseButton->value(verbose);
- m_VerboseButton->callback((Fl_Callback*)CValidatorFilter::cb_OnVerboseChange, this);
- }
- void CValidatorFilter::InactivateSev(void)
- {
- int size = m_MinSevChoice->size() - 1;
- unsigned int flag;
- for ( int i = 0; i < size; ++i) {
- flag = (i > m_MaxSevChoice->value()) ? FL_MENU_INACTIVE : 0;
- m_MinSevChoice->mode(i, flag);
- }
-
- for ( int i = 0; i < size; ++i) {
- flag = (i < m_MinSevChoice->value()) ? FL_MENU_INACTIVE : 0;
- m_MaxSevChoice->mode(i, flag);
- }
- }
- // Callbacks:
- void CValidatorFilter::cb_OnSevChange(Fl_Choice*, CValidatorFilter* _this)
- {
- _this->x_OnSevChange();
- }
- void CValidatorFilter::x_OnSevChange(void)
- {
- InactivateSev();
- m_Display->Update(this);
- }
- void CValidatorFilter::cb_OnErrCodeChange(Fl_Choice*, CValidatorFilter* _this)
- {
- _this->x_OnOnErrCodeChange();
- }
- void CValidatorFilter::x_OnOnErrCodeChange(void)
- {
- m_Display->Update(this);
- }
- void CValidatorFilter::cb_OnSearchPressed(Fl_Button*, CValidatorFilter* _this)
- {
- _this->x_OnSearchPressed();
- }
- void CValidatorFilter::x_OnSearchPressed(void)
- {
- m_Display->Update(this);
- }
- void CValidatorFilter::cb_OnSearchInput(Fl_Input*, CValidatorFilter* _this)
- {
- _this->x_OnSearchInput();
- }
- void CValidatorFilter::x_OnSearchInput(void)
- {
- string value = m_SearchInput->value();
- if ( value.empty() ) {
- m_SearchButton->deactivate();
- } else {
- m_SearchButton->activate();
- }
- if ( value.empty() || Fl::event_key() == FL_Enter ) {
- m_Display->Update(this);
- }
- }
- void CValidatorFilter::cb_OnVerboseChange(Fl_Check_Button* b, CValidatorFilter* _this)
- {
- _this->x_OnVerboseChange(b);
- }
- void CValidatorFilter::x_OnVerboseChange(Fl_Check_Button* b)
- {
- m_Display->DisplayVerbose(b->value() != 0);
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- *
- * $Log: filter.cpp,v $
- * Revision 1000.1 2004/06/01 21:03:16 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.3
- *
- * Revision 1.3 2004/05/21 22:27:50 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.2 2003/04/22 16:25:32 shomrat
- * Fl -> FL
- *
- * Revision 1.1 2003/04/18 19:56:49 shomrat
- * Initial revision
- *
- *
- * ===========================================================================
- */