📄 annotate_dialog.cpp
字号:
/* * =========================================================================== * PRODUCTION $Log: annotate_dialog.cpp,v $ * PRODUCTION Revision 1000.2 2004/06/01 18:27:40 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.15 * PRODUCTION * =========================================================================== *//* $Id: annotate_dialog.cpp,v 1000.2 2004/06/01 18:27: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: Paul Thiessen** File Description:* dialog for user annotations** ===========================================================================*/#ifdef _MSC_VER#pragma warning(disable:4018) // disable signed/unsigned mismatch warning in MSVC#endif#include <ncbi_pch.hpp>#include <corelib/ncbistd.hpp>#include "annotate_dialog.hpp"#include "messenger.hpp"#include "style_manager.hpp"#include "style_dialog.hpp"#include "structure_set.hpp"#include "show_hide_manager.hpp"#include "cn3d_tools.hpp"////////////////////////////////////////////////////////////////////////////////////////////////// The following is taken unmodified from wxDesigner's C++ header from annotate_dialog.wdr////////////////////////////////////////////////////////////////////////////////////////////////#include <wx/image.h>#include <wx/statline.h>#include <wx/spinbutt.h>#include <wx/spinctrl.h>#include <wx/splitter.h>#include <wx/listctrl.h>#include <wx/treectrl.h>#include <wx/notebook.h>// Declare window functions#define ID_TEXT 10000#define ID_L_AVAILABLE 10001#define ID_B_TURN_ON 10002#define ID_B_TURN_OFF 10003#define ID_B_MOVE_UP 10004#define ID_B_MOVE_DOWN 10005#define ID_L_DISPLAYED 10006#define ID_LINE 10007#define ID_ST_NAME 10008#define ID_B_NEW 10009#define ID_ST_DESCR 10010#define ID_B_SHOW 10011#define ID_B_EDIT 10012#define ID_B_MOVE 10013#define ID_B_DELETE 10014#define ID_B_DONE 10015wxSizer *SetupAnnotationControlDialog( wxPanel *parent, bool call_fit = TRUE, bool set_sizer = TRUE );#define ID_T_NAME 10016#define ID_B_EDIT_STYLE 10017#define ID_T_DESCR 10018#define ID_B_EDIT_DONE 10019#define ID_B_EDIT_CANCEL 10020wxSizer *SetupAnnotationEditorDialog( wxPanel *parent, bool call_fit = TRUE, bool set_sizer = TRUE );////////////////////////////////////////////////////////////////////////////////////////////////USING_NCBI_SCOPE;BEGIN_SCOPE(Cn3D)#define DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(var, id, type) \ type *var; \ var = wxDynamicCast(FindWindow(id), type); \ if (!var) { \ ERRORMSG("Can't find window with id " << id); \ return; \ }#define ANNOT_FROM_CLIENT_DATA(listbox) \ (reinterpret_cast < StyleManager::UserAnnotation * > \ ((listbox)->GetClientData((listbox)->GetSelection())))BEGIN_EVENT_TABLE(AnnotateDialog, wxDialog) EVT_CLOSE ( AnnotateDialog::OnCloseWindow) EVT_BUTTON (-1, AnnotateDialog::OnButton) EVT_LISTBOX (-1, AnnotateDialog::OnSelection)END_EVENT_TABLE()AnnotateDialog::AnnotateDialog(wxWindow *parent, StyleManager *manager, const StructureSet *set) : wxDialog(parent, -1, "User Annotations", wxPoint(400, 100), wxDefaultSize, wxCAPTION | wxSYSTEM_MENU), // not resizable styleManager(manager), structureSet(set){ // get the structure highlights present when this dialog is created GlobalMessenger()->GetHighlightedResiduesWithStructure(&highlightedResidues); // construct the panel wxPanel *panel = new wxPanel(this, -1); wxSizer *topSizer = SetupAnnotationControlDialog(panel, false); // fill in list boxes with available and displayed styles ResetListBoxes(); // set initial button states SetButtonStates(); // call sizer stuff topSizer->Fit(this); topSizer->Fit(panel); topSizer->SetSizeHints(this);}// same as hitting done buttonvoid AnnotateDialog::OnCloseWindow(wxCloseEvent& event){ EndModal(wxOK);}void AnnotateDialog::OnButton(wxCommandEvent& event){ switch (event.GetId()) { case ID_B_NEW: NewAnnotation(); break; case ID_B_EDIT: EditAnnotation(); break; case ID_B_MOVE: MoveAnnotation(); break; case ID_B_DELETE: DeleteAnnotation(); break; case ID_B_SHOW: { DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(available, ID_L_AVAILABLE, wxListBox) if (available->GetSelection() >= 0) { StyleManager::UserAnnotation *annotation = ANNOT_FROM_CLIENT_DATA(available); if (annotation) { GlobalMessenger()->SetHighlights(annotation->residues); structureSet->showHideManager->ShowDomainsWithHighlights(structureSet); highlightedResidues = annotation->residues; } else ERRORMSG("AnnotateDialog::OnButton() - error highlighting annotation #" << available->GetSelection()); } break; } case ID_B_MOVE_UP: case ID_B_MOVE_DOWN: { DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(displayed, ID_L_DISPLAYED, wxListBox) if (displayed->GetSelection() >= 0) { StyleManager::UserAnnotation *annotation = ANNOT_FROM_CLIENT_DATA(displayed); if (annotation && styleManager-> ReprioritizeDisplayOrder(annotation, (event.GetId() == ID_B_MOVE_UP))) ResetListBoxes(); else ERRORMSG("AnnotateDialog::OnButton() - error reprioritizing annotation #" << displayed->GetSelection()); } break; } case ID_B_TURN_OFF: case ID_B_TURN_ON: { int listID = (event.GetId() == ID_B_TURN_OFF) ? ID_L_DISPLAYED : ID_L_AVAILABLE; DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(listBox, listID, wxListBox) if (listBox->GetSelection() >= 0) { StyleManager::UserAnnotation *annotation = ANNOT_FROM_CLIENT_DATA(listBox); if (annotation && styleManager-> DisplayAnnotation(annotation, (event.GetId() == ID_B_TURN_ON))) ResetListBoxes(); else ERRORMSG("AnnotateDialog::OnButton() - error toggling annotation #" << listBox->GetSelection()); } break; } case ID_B_DONE: EndModal(wxOK); break; default: event.Skip(); } SetButtonStates();}void AnnotateDialog::OnSelection(wxCommandEvent& event){ DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(eventBox, event.GetId(), wxListBox) int otherID = (event.GetId() == ID_L_DISPLAYED) ? ID_L_AVAILABLE : ID_L_DISPLAYED; DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(otherBox, otherID, wxListBox) // deselect everything in the other box int e, o; for (o=0; o<otherBox->GetCount(); ++o) otherBox->SetSelection(o, false); // turn on corresponding item in other box for (e=0; e<eventBox->GetCount(); ++e) { if (eventBox->Selected(e)) { for (o=0; o<otherBox->GetCount(); ++o) { if (otherBox->GetClientData(o) == eventBox->GetClientData(e)) { otherBox->SetSelection(o, true); break; } } break; } } SetButtonStates();}void AnnotateDialog::SetButtonStates(void){ DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(available, ID_L_AVAILABLE, wxListBox) DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(displayed, ID_L_DISPLAYED, wxListBox) DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(bTurnOn, ID_B_TURN_ON, wxButton) DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(bTurnOff, ID_B_TURN_OFF, wxButton) DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(bMoveUp, ID_B_MOVE_UP, wxButton) DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(bMoveDown, ID_B_MOVE_DOWN, wxButton) DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(bNew, ID_B_NEW, wxButton) DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(bEdit, ID_B_EDIT, wxButton) DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(bMove, ID_B_MOVE, wxButton) DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(bDelete, ID_B_DELETE, wxButton) DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(bShow, ID_B_SHOW, wxButton) DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(tName, ID_ST_NAME, wxStaticText) DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(tDescr, ID_ST_DESCR, wxStaticText) bool availableSelected = (available->GetSelection() >= 0); bool displayedSelected = (displayed->GetSelection() >= 0); bTurnOn->Enable(availableSelected && !displayedSelected); bTurnOff->Enable(displayedSelected); bMoveUp->Enable(displayedSelected && displayed->GetSelection() > 0); bMoveDown->Enable(displayedSelected && displayed->GetSelection() < displayed->GetCount() - 1); bNew->Enable(HighlightsPresent()); bEdit->Enable(availableSelected); bMove->Enable(availableSelected && HighlightsPresent()); bDelete->Enable(availableSelected); bShow->Enable(availableSelected); const StyleManager::UserAnnotation *annotation = NULL; if (availableSelected) { annotation = ANNOT_FROM_CLIENT_DATA(available); if (!annotation) ERRORMSG("AnnotateDialog::SetButtonStates() - NULL annotation pointer"); } tName->SetLabel(annotation ? annotation->name.c_str() : ""); tDescr->SetLabel(annotation ? annotation->description.c_str() : "");}// recreates the list box entries, trying to keep current selectionvoid AnnotateDialog::ResetListBoxes(void){ DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(available, ID_L_AVAILABLE, wxListBox) DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(displayed, ID_L_DISPLAYED, wxListBox) StyleManager::AnnotationPtrList annotations; styleManager->GetUserAnnotations(&annotations); // determine what should be selected initially void *selection = NULL; if (available->GetSelection() >= 0) selection = available->GetClientData(available->GetSelection()); else if (styleManager->GetUserAnnotationsDisplayed().size() > 0) selection = styleManager->GetUserAnnotationsDisplayed()[0]; else if (annotations.size() > 0) selection = annotations[0]; // recreate available list available->Clear(); int i; for (i=0; i<annotations.size(); ++i) { available->Append(annotations[i]->name.c_str(), annotations[i]); if (selection == annotations[i]) available->SetSelection(i, true); } // recreate displayed list displayed->Clear(); for (i=0; i<styleManager->GetUserAnnotationsDisplayed().size(); ++i) { displayed->Append(styleManager->GetUserAnnotationsDisplayed()[i]->name.c_str(), styleManager->GetUserAnnotationsDisplayed()[i]); if (selection == styleManager->GetUserAnnotationsDisplayed()[i]) displayed->SetSelection(i, true); }}void AnnotateDialog::NewAnnotation(void){ // create new StyleSettings and UserAnnotation structures StyleManager::UserAnnotation *newAnnotation = styleManager->AddUserAnnotation(); if (!newAnnotation) return; newAnnotation->name = "(new)"; newAnnotation->residues = highlightedResidues; // copy list of stuff highlighted at dialog creation StyleSettings *style; if (!styleManager->AddUserStyle(&(newAnnotation->styleID), &style) || !style || !styleManager->DisplayAnnotation(newAnnotation, true)) { // turn on new annotation ERRORMSG("AnnotateDialog::NewAnnotation() - error setting up new annotation"); return; } *style = styleManager->GetGlobalStyle(); // set initial style to same as current global style ResetListBoxes(); // bring up the annotation editor dialog; hide highlights during this process, so the user // can see the color changes as the style is edited GlobalMessenger()->SuspendHighlighting(true); AnnotationEditorDialog dialog(this, style, structureSet, *newAnnotation); int result = dialog.ShowModal(); GlobalMessenger()->SuspendHighlighting(false); if (result == wxOK) { // copy name and description from dialog DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(tName, ID_T_NAME, wxTextCtrl) newAnnotation->name = tName->GetValue().c_str(); DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(tDescr, ID_T_DESCR, wxTextCtrl) newAnnotation->description = tDescr->GetValue().c_str(); // set selection to new annotation DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(available, ID_L_AVAILABLE, wxListBox) available->SetSelection(available->GetCount() - 1); } else { // wxCANCEL if (!styleManager->RemoveUserAnnotation(newAnnotation)) ERRORMSG("AnnotateDialog::NewAnnotation() - error removing new annotation"); } ResetListBoxes(); SetButtonStates();}void AnnotateDialog::EditAnnotation(void){ DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(available, ID_L_AVAILABLE, wxListBox) if (available->GetSelection() < 0) return; StyleManager::UserAnnotation *annotation = ANNOT_FROM_CLIENT_DATA(available); StyleSettings *style = NULL; if (!annotation || (style=styleManager->GetUserStyle(annotation->styleID)) == NULL) { ERRORMSG("AnnotateDialog::EditAnnotation() - error getting annotation and style"); return; } // bring up the annotation editor dialog StyleSettings copy = *style; AnnotationEditorDialog dialog(this, style, structureSet, *annotation); int result = dialog.ShowModal(); if (result == wxOK) { // copy name and description from dialog DECLARE_AND_FIND_WINDOW_RETURN_ON_ERR(tName, ID_T_NAME, wxTextCtrl)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -