⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 update_viewer_window.cpp

📁 ncbi源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* * =========================================================================== * PRODUCTION $Log: update_viewer_window.cpp,v $ * PRODUCTION Revision 1000.2  2004/06/01 18:29:52  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.61 * PRODUCTION * =========================================================================== *//*  $Id: update_viewer_window.cpp,v 1000.2 2004/06/01 18:29:52 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:*      implementation of GUI part of update viewer** ===========================================================================*/#ifdef _MSC_VER#pragma warning(disable:4018)   // disable signed/unsigned mismatch warning in MSVC#endif#include <ncbi_pch.hpp>#include <corelib/ncbistd.hpp>#ifdef __WXMSW__#include <windows.h>#include <wx/msw/winundef.h>#endif#include <wx/wx.h>#include <wx/stattext.h>#include "update_viewer_window.hpp"#include "update_viewer.hpp"#include "messenger.hpp"#include "sequence_display.hpp"#include "alignment_manager.hpp"#include "cn3d_threader.hpp"#include "wx_tools.hpp"#include "cn3d_tools.hpp"#include "molecule_identifier.hpp"#include "cn3d_ba_interface.hpp"USING_NCBI_SCOPE;BEGIN_SCOPE(Cn3D)BEGIN_EVENT_TABLE(UpdateViewerWindow, wxFrame)    INCLUDE_VIEWER_WINDOW_BASE_EVENTS    EVT_CLOSE     (                                     UpdateViewerWindow::OnCloseWindow)    EVT_MENU      (MID_DELETE_ALL_BLOCKS,               UpdateViewerWindow::OnDelete)    EVT_MENU      (MID_SORT_UPDATES_IDENTIFIER,         UpdateViewerWindow::OnSortUpdates)    EVT_MENU_RANGE(MID_THREAD_ONE, MID_THREAD_ALL,      UpdateViewerWindow::OnRunThreader)    EVT_MENU_RANGE(MID_MERGE_ONE, MID_MERGE_ALL,        UpdateViewerWindow::OnMerge)    EVT_MENU_RANGE(MID_DELETE_ONE, MID_DELETE_ALL,      UpdateViewerWindow::OnDelete)    EVT_MENU_RANGE(MID_IMPORT_SEQUENCES, MID_IMPORT_STRUCTURE,  UpdateViewerWindow::OnImport)    EVT_MENU_RANGE(MID_BLAST_ONE, MID_BLAST_NEIGHBOR,   UpdateViewerWindow::OnRunBlast)    EVT_MENU_RANGE(MID_SET_REGION, MID_RESET_REGIONS,   UpdateViewerWindow::OnSetRegion)    EVT_MENU_RANGE(MID_BLOCKALIGN_ONE, MID_BLOCKALIGN_ALL,  UpdateViewerWindow::OnBlockAlign)END_EVENT_TABLE()UpdateViewerWindow::UpdateViewerWindow(UpdateViewer *thisUpdateViewer) :    ViewerWindowBase(thisUpdateViewer, wxPoint(0,50), wxSize(1000,300)),    updateViewer(thisUpdateViewer){    SetWindowTitle();    // Edit menu    editMenu->AppendSeparator();    wxMenu *subMenu = new wxMenu;    subMenu->Append(MID_SORT_UPDATES_IDENTIFIER, "By &Identifier");    editMenu->Append(MID_SORT_UPDATES, "So&rt Imports...", subMenu);    editMenu->AppendSeparator();    editMenu->Append(MID_IMPORT_SEQUENCES, "&Import Sequences");    editMenu->Append(MID_IMPORT_STRUCTURE, "Import S&tructure");    // insert at hard-coded location, since FindItem doesn't seem to work...    editMenu->Insert(8, MID_DELETE_ALL_BLOCKS, "Delete A&ll Blocks", "", true);    // Mouse mode menu    menuBar->Enable(MID_SELECT_COLS, false);    // Algorithms menu    wxMenu *menu = new wxMenu;    menu->Append(MID_BLOCKALIGN_ONE, "B&lock Align Single", "", true);    menu->Append(MID_BLOCKALIGN_ALL, "Bloc&k Align All");    menu->AppendSeparator();    menu->Append(MID_BLAST_ONE, "&BLAST Single", "", true);    menu->Append(MID_BLAST_PSSM_ONE, "BLAST/&PSSM Single", "", true);    menu->Append(MID_BLAST_NEIGHBOR, "BLAST &Neighbor", "", true);    menu->AppendSeparator();    menu->Append(MID_THREAD_ONE, "Thread &Single", "", true);    menu->Append(MID_THREAD_ALL, "Thread &All");    menu->AppendSeparator();    menu->Append(MID_SET_REGION, "Set &Region", "", true);    menu->Append(MID_RESET_REGIONS, "Reset All Re&gions");    menuBar->Append(menu, "Al&gorithms");    // Alignments menu    menu = new wxMenu;    menu->Append(MID_MERGE_ONE, "&Merge Single", "", true);    menu->Append(MID_MERGE_NEIGHBOR, "Merge to &Neighbor", "", true);    menu->Append(MID_MERGE_ALL, "Merge &All");    menu->AppendSeparator();    menu->Append(MID_DELETE_ONE, "&Delete Single", "", true);    menu->Append(MID_DELETE_ALL, "Delete A&ll");    menuBar->Append(menu, "&Alignments");    // editor always on    EnableBaseEditorMenuItems(true);    menuBar->Check(MID_ENABLE_EDIT, true);    menuBar->Enable(MID_ENABLE_EDIT, false);    // set default mouse mode    viewerWidget->SetMouseMode(SequenceViewerWidget::eDragHorizontal);    menuBar->Check(MID_DRAG_HORIZ, true);    menuBar->Check(MID_SELECT_RECT, false);    SetMenuBar(menuBar);}UpdateViewerWindow::~UpdateViewerWindow(void){}void UpdateViewerWindow::OnCloseWindow(wxCloseEvent& event){    if (viewer) {        if (event.CanVeto()) {            Show(false);    // just hide the window if we can            event.Veto();            return;        }        SaveDialog(true, false);        viewer->GUIDestroyed(); // make sure UpdateViewer knows the GUI is gone        GlobalMessenger()->UnPostRedrawSequenceViewer(viewer);  // don't try to redraw after destroyed!    }    Destroy();}void UpdateViewerWindow::SetWindowTitle(void){    SetTitle(wxString(GetWorkingTitle().c_str()) + " - Import Viewer");}void UpdateViewerWindow::EnableDerivedEditorMenuItems(bool enabled){}void UpdateViewerWindow::OnRunThreader(wxCommandEvent& event){    switch (event.GetId()) {        case MID_THREAD_ONE:            CancelAllSpecialModesExcept(MID_THREAD_ONE);            if (DoThreadSingle())                SetCursor(*wxCROSS_CURSOR);            else                ThreadSingleOff();            break;        case MID_THREAD_ALL: {            if (!updateViewer->alignmentManager->GetCurrentMultipleAlignment()) {                ERRORMSG("Can't run threader without existing core alignment");                return;            }            if (updateViewer->GetCurrentAlignments().size() == 0) return;            // base nRS estimate on first update...            globalThreaderOptions.nRandomStarts = Threader::EstimateNRandomStarts(                updateViewer->alignmentManager->GetCurrentMultipleAlignment(),                updateViewer->GetCurrentAlignments().front());            ThreaderOptionsDialog optDialog(this, globalThreaderOptions);            if (optDialog.ShowModal() == wxCANCEL) return;  // user cancelled            if (!optDialog.GetValues(&globalThreaderOptions)) {                ERRORMSG("Error retrieving options values from dialog");                return;            }            RaiseLogWindow();            SetCursor(*wxHOURGLASS_CURSOR);            updateViewer->alignmentManager->ThreadAllUpdates(globalThreaderOptions);            SetCursor(wxNullCursor);            break;        }    }}void UpdateViewerWindow::OnMerge(wxCommandEvent& event){    switch (event.GetId()) {        case MID_MERGE_ONE:            CancelAllSpecialModesExcept(MID_MERGE_ONE);            if (DoMergeSingle())                SetCursor(*wxCROSS_CURSOR);            else                MergeSingleOff();            break;        case MID_MERGE_NEIGHBOR:            CancelAllSpecialModesExcept(MID_MERGE_NEIGHBOR);            if (DoMergeNeighbor())                SetCursor(*wxCROSS_CURSOR);            else                MergeNeighborOff();            break;        case MID_MERGE_ALL:        {            AlignmentManager::UpdateMap all;    // construct map/list of all updates            const ViewerBase::AlignmentList& currentUpdates = updateViewer->GetCurrentAlignments();            if (currentUpdates.size() > 0) {                ViewerBase::AlignmentList::const_iterator u, ue = currentUpdates.end();                for (u=currentUpdates.begin(); u!=ue; ++u) all[*u] = true;                updateViewer->alignmentManager->MergeUpdates(all, false);            }            break;        }    }}void UpdateViewerWindow::OnDelete(wxCommandEvent& event){    switch (event.GetId()) {        case MID_DELETE_ALL_BLOCKS:            CancelAllSpecialModesExcept(MID_DELETE_ALL_BLOCKS);            if (DoDeleteAllBlocks())                SetCursor(*wxCROSS_CURSOR);            else                DeleteAllBlocksOff();            break;        case MID_DELETE_ONE:            CancelAllSpecialModesExcept(MID_DELETE_ONE);            if (DoDeleteSingle())                SetCursor(*wxCROSS_CURSOR);            else                DeleteSingleOff();            break;        case MID_DELETE_ALL: {            ViewerBase::AlignmentList empty;            updateViewer->ReplaceAlignments(empty);            break;        }    }}bool UpdateViewerWindow::SaveDialog(bool prompt, bool canCancel){    // quick & dirty check for whether save is necessary, by whether Undo is enabled    if (!menuBar->IsEnabled(MID_UNDO)) return true;    int option = wxID_YES;    if (prompt) {        option = wxYES_NO | wxYES_DEFAULT | wxICON_EXCLAMATION | wxCENTRE;        if (canCancel) option |= wxCANCEL;        wxMessageDialog dialog(NULL, "Do you want to keep the changes to these updates?", "", option);        option = dialog.ShowModal();        if (option == wxID_CANCEL) return false; // user cancelled this operation    }    if (option == wxID_YES)        updateViewer->SaveAlignments();     // save data    else {        updateViewer->Revert();				// revert to original        updateViewer->EnableStacks();       // but keep undo stack active    }    return true;}void UpdateViewerWindow::OnImport(wxCommandEvent& event){    if (event.GetId() == MID_IMPORT_SEQUENCES) updateViewer->ImportSequences();    else if (event.GetId() == MID_IMPORT_STRUCTURE) updateViewer->ImportStructure();}void UpdateViewerWindow::OnRunBlast(wxCommandEvent& event){    switch (event.GetId()) {        case MID_BLAST_ONE:            CancelAllSpecialModesExcept(MID_BLAST_ONE);            if (DoBlastSingle())                SetCursor(*wxCROSS_CURSOR);            else                BlastSingleOff();            break;        case MID_BLAST_PSSM_ONE:            CancelAllSpecialModesExcept(MID_BLAST_PSSM_ONE);            if (DoBlastPSSMSingle())                SetCursor(*wxCROSS_CURSOR);            else                BlastPSSMSingleOff();            break;        case MID_BLAST_NEIGHBOR:            CancelAllSpecialModesExcept(MID_BLAST_NEIGHBOR);            if (DoBlastNeighborSingle())                SetCursor(*wxCROSS_CURSOR);            else                BlastNeighborSingleOff();            break;    }}void UpdateViewerWindow::OnSortUpdates(wxCommandEvent& event){    if (event.GetId() == MID_SORT_UPDATES_IDENTIFIER)        updateViewer->SortByIdentifier();}void UpdateViewerWindow::OnSetRegion(wxCommandEvent& event){    if (event.GetId() == MID_SET_REGION) {        CancelAllSpecialModesExcept(MID_SET_REGION);        if (DoSetRegion())            SetCursor(*wxCROSS_CURSOR);        else            SetRegionOff();    }    else if (event.GetId() == MID_RESET_REGIONS) {		UpdateViewer::AlignmentList::const_iterator a, ae = updateViewer->GetCurrentAlignments().end();        for (a=updateViewer->GetCurrentAlignments().begin(); a!=ae; ++a) {            (*a)->alignSlaveFrom = -1;            (*a)->alignSlaveTo = -1;        }    }}void UpdateViewerWindow::OnBlockAlign(wxCommandEvent& event){    if (event.GetId() == MID_BLOCKALIGN_ONE) {        CancelAllSpecialModesExcept(MID_BLOCKALIGN_ONE);        if (DoBlockAlignSingle())            SetCursor(*wxCROSS_CURSOR);        else            BlockAlignSingleOff();    }    else if (event.GetId() == MID_BLOCKALIGN_ALL) {        updateViewer->alignmentManager->BlockAlignAllUpdates();    }}/////////////////////////////////////////////////////////////////////////////////// ThreaderOptionsDialog implementation/////////////////////////////////////////////////////////////////////////////////BEGIN_EVENT_TABLE(ThreaderOptionsDialog, wxDialog)    EVT_BUTTON(-1,  ThreaderOptionsDialog::OnButton)    EVT_CLOSE (     ThreaderOptionsDialog::OnCloseWindow)END_EVENT_TABLE()ThreaderOptionsDialog::ThreaderOptionsDialog(wxWindow* parent, const ThreaderOptions& initialOptions) :    wxDialog(parent, -1, "Set Threader Options", wxDefaultPosition, wxDefaultSize,        wxCAPTION | wxSYSTEM_MENU) // not resizable{    // the following code is modified (heavily) from wxDesigner C++ output from threader_dialog.wdr    wxPanel *panel = new wxPanel(this, -1);    wxBoxSizer *item0 = new wxBoxSizer(wxVERTICAL);    wxBoxSizer *item1 = new wxBoxSizer(wxVERTICAL);    wxStaticBox *item3 = new wxStaticBox(panel, -1, "Threader Options");    wxStaticBoxSizer *item2 = new wxStaticBoxSizer(item3, wxHORIZONTAL);    wxFlexGridSizer *grid = new wxFlexGridSizer(3, 5, 0);    // PSSM weight    wxStaticText *item5 = new wxStaticText(panel, -1, "Weighting of PSSM/Contact score? [0 .. 1], 1 = PSSM only", wxDefaultPosition, wxDefaultSize, 0);    grid->Add(item5, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);    fpWeight = new FloatingPointSpinCtrl(panel,        0.0, 1.0, 0.05, initialOptions.weightPSSM,        wxDefaultPosition, wxSize(80, SPIN_CTRL_HEIGHT), 0,        wxDefaultPosition, wxSize(-1, SPIN_CTRL_HEIGHT));    grid->Add(fpWeight->GetTextCtrl(), 0, wxALIGN_CENTRE|wxLEFT|wxTOP|wxBOTTOM, 5);    grid->Add(fpWeight->GetSpinButton(), 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxTOP|wxBOTTOM, 5);    // loop lengths    wxStaticText *item8 = new wxStaticText(panel, -1, "Loop length multiplier? [0.1 .. 10]", wxDefaultPosition, wxDefaultSize, 0);    grid->Add(item8, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);    fpLoops = new FloatingPointSpinCtrl(panel,        0.1, 10.0, 0.25, initialOptions.loopLengthMultiplier,        wxDefaultPosition, wxSize(80, SPIN_CTRL_HEIGHT), 0,        wxDefaultPosition, wxSize(-1, SPIN_CTRL_HEIGHT));    grid->Add(fpLoops->GetTextCtrl(), 0, wxALIGN_CENTRE|wxLEFT|wxTOP|wxBOTTOM, 5);    grid->Add(fpLoops->GetSpinButton(), 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxTOP|wxBOTTOM, 5);    // random starts    wxStaticText *item11 = new wxStaticText(panel, -1, "Number of random starts? [1 .. 1000]", wxDefaultPosition, wxDefaultSize, 0);    grid->Add(item11, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -