📄 structure_window.cpp
字号:
} wxFontData initialFontData; initialFontData.SetInitialFont(*initialFont); // bring up font chooser dialog#if wxCHECK_VERSION(2,3,3) wxFontDialog dialog(this, initialFontData);#else wxFontDialog dialog(this, &initialFontData);#endif int result = dialog.ShowModal(); // if user selected a font if (result == wxID_OK) { // set registry values appropriately wxFontData& fontData = dialog.GetFontData(); wxFont font = fontData.GetChosenFont(); if (!RegistrySetString(section, REG_FONT_NATIVE_FONT_INFO, font.GetNativeFontInfoDesc().c_str())) { ERRORMSG("StructureWindow::OnSetFont() - error setting registry data"); return; } // call font setup INFOMSG("setting new font"); if (event.GetId() == MID_OPENGL_FONT) { glCanvas->SetCurrent(); glCanvas->SetGLFontFromRegistry(); GlobalMessenger()->PostRedrawAllStructures(); } else if (event.GetId() == MID_SEQUENCE_FONT) { GlobalMessenger()->NewSequenceViewerFont(); } }}static string GetFavoritesFile(bool forRead){ // try to get value from registry string file; RegistryGetString(REG_CONFIG_SECTION, REG_FAVORITES_NAME, &file); // if not set, ask user for a folder, then set in registry if (file == NO_FAVORITES_FILE) { file = wxFileSelector("Select a file for favorites:", GetPrefsDir().c_str(), "Favorites", "", "*.*", forRead ? wxOPEN : wxSAVE | wxOVERWRITE_PROMPT).c_str(); if (file.size() > 0) if (!RegistrySetString(REG_CONFIG_SECTION, REG_FAVORITES_NAME, file)) ERRORMSG("Error setting favorites file in registry"); } return file;}static bool LoadFavorites(void){ string favoritesFile; RegistryGetString(REG_CONFIG_SECTION, REG_FAVORITES_NAME, &favoritesFile); if (favoritesFile != NO_FAVORITES_FILE) { favoriteStyles.Reset(); if (wxFile::Exists(favoritesFile.c_str())) { INFOMSG("loading favorites from " << favoritesFile); string err; if (ReadASNFromFile(favoritesFile.c_str(), &favoriteStyles, false, &err)) { favoriteStylesChanged = false; return true; } } else { WARNINGMSG("Favorites file does not exist: " << favoritesFile); RegistrySetString(REG_CONFIG_SECTION, REG_FAVORITES_NAME, NO_FAVORITES_FILE); } } return false;}static void SaveFavorites(void){ if (favoriteStylesChanged) { int choice = wxMessageBox("Do you want to save changes to your current Favorites file?", "Save favorites?", wxYES_NO); if (choice == wxYES) { string favoritesFile = GetFavoritesFile(false); if (favoritesFile != NO_FAVORITES_FILE) { string err; if (!WriteASNToFile(favoritesFile.c_str(), favoriteStyles, false, &err)) ERRORMSG("Error saving Favorites to " << favoritesFile << '\n' << err); favoriteStylesChanged = false; } } }}void StructureWindow::OnEditFavorite(wxCommandEvent& event){ if (!glCanvas->structureSet) return; if (event.GetId() == MID_ADD_FAVORITE) { // get name from user wxString name = wxGetTextFromUser("Enter a name for this style:", "Input name", "", this); if (name.size() == 0) return; // replace style of same name CCn3d_style_settings *settings; CCn3d_style_settings_set::Tdata::iterator f, fe = favoriteStyles.Set().end(); for (f=favoriteStyles.Set().begin(); f!=fe; ++f) { if (Stricmp((*f)->GetName().c_str(), name.c_str()) == 0) { settings = f->GetPointer(); break; } } // else add style to list if (f == favoriteStyles.Set().end()) { if (favoriteStyles.Set().size() >= MID_FAVORITES_END - MID_FAVORITES_BEGIN + 1) { ERRORMSG("Already have max # Favorites"); return; } else { CRef < CCn3d_style_settings > ref(settings = new CCn3d_style_settings()); favoriteStyles.Set().push_back(ref); } } // put in data from global style if (!glCanvas->structureSet->styleManager->GetGlobalStyle().SaveSettingsToASN(settings)) ERRORMSG("Error converting global style to asn"); settings->SetName(name.c_str()); favoriteStylesChanged = true; } else if (event.GetId() == MID_REMOVE_FAVORITE) { wxString *choices = new wxString[favoriteStyles.Get().size()]; int i = 0; CCn3d_style_settings_set::Tdata::iterator f, fe = favoriteStyles.Set().end(); for (f=favoriteStyles.Set().begin(); f!=fe; ++f) choices[i++] = (*f)->GetName().c_str(); int picked = wxGetSingleChoiceIndex("Choose a style to remove from the Favorites list:", "Select for removal", favoriteStyles.Set().size(), choices, this); if (picked < 0 || picked >= favoriteStyles.Set().size()) return; for (f=favoriteStyles.Set().begin(), i=0; f!=fe; ++f, ++i) { if (i == picked) { favoriteStyles.Set().erase(f); favoriteStylesChanged = true; break; } } } else if (event.GetId() == MID_FAVORITES_FILE) { SaveFavorites(); favoriteStyles.Reset(); RegistrySetString(REG_CONFIG_SECTION, REG_FAVORITES_NAME, NO_FAVORITES_FILE); string newFavorites = GetFavoritesFile(true); if (newFavorites != NO_FAVORITES_FILE && wxFile::Exists(newFavorites.c_str())) { if (!LoadFavorites()) ERRORMSG("Error loading Favorites from " << newFavorites.c_str()); } } // update menu SetupFavoritesMenu();}void StructureWindow::SetupFavoritesMenu(void){ int i; for (i=MID_FAVORITES_BEGIN; i<=MID_FAVORITES_END; ++i) { wxMenuItem *item = favoritesMenu->FindItem(i); if (item) favoritesMenu->Delete(item); } CCn3d_style_settings_set::Tdata::const_iterator f, fe = favoriteStyles.Get().end(); for (f=favoriteStyles.Get().begin(), i=0; f!=fe; ++f, ++i) favoritesMenu->Append(MID_FAVORITES_BEGIN + i, (*f)->GetName().c_str());}void StructureWindow::OnSelectFavorite(wxCommandEvent& event){ if (!glCanvas->structureSet) return; if (event.GetId() >= MID_FAVORITES_BEGIN && event.GetId() <= MID_FAVORITES_END) { int index = event.GetId() - MID_FAVORITES_BEGIN; CCn3d_style_settings_set::Tdata::const_iterator f, fe = favoriteStyles.Get().end(); int i = 0; for (f=favoriteStyles.Get().begin(); f!=fe; ++f, ++i) { if (i == index) { INFOMSG("using favorite: " << (*f)->GetName()); glCanvas->structureSet->styleManager->SetGlobalStyle(**f); SetRenderingMenuFlag(0); SetColoringMenuFlag(0); break; } } }}void StructureWindow::OnShowWindow(wxCommandEvent& event){ switch (event.GetId()) { case MID_SHOW_LOG: RaiseLogWindow(); break; case MID_SHOW_SEQ_V: if (glCanvas->structureSet) glCanvas->structureSet->alignmentManager->ShowSequenceViewer(); break; case MID_SHOW_LOG_START: RegistrySetBoolean(REG_CONFIG_SECTION, REG_SHOW_LOG_ON_START, menuBar->IsChecked(MID_SHOW_LOG_START)); break; }}void StructureWindow::DialogTextChanged(const MultiTextDialog *changed){ if (!changed || !glCanvas->structureSet) return; if (changed == cddNotesDialog) { StructureSet::TextLines lines; cddNotesDialog->GetLines(&lines); if (!glCanvas->structureSet->SetCDDNotes(lines)) ERRORMSG("Error saving CDD notes"); } if (changed == cddDescriptionDialog) { string line; cddDescriptionDialog->GetLine(&line); if (!glCanvas->structureSet->SetCDDDescription(line)) ERRORMSG("Error saving CDD description"); }}void StructureWindow::DialogDestroyed(const MultiTextDialog *destroyed){ TRACEMSG("MultiTextDialog destroyed"); if (destroyed == cddNotesDialog) cddNotesDialog = NULL; if (destroyed == cddDescriptionDialog) cddDescriptionDialog = NULL;}void StructureWindow::DestroyNonModalDialogs(void){ if (cddAnnotateDialog) cddAnnotateDialog->Destroy(); if (cddNotesDialog) cddNotesDialog->DestroyDialog(); if (cddDescriptionDialog) cddDescriptionDialog->DestroyDialog(); if (cddRefDialog) cddRefDialog->Destroy(); if (cddBookRefDialog) cddBookRefDialog->Destroy(); if (cddOverview) cddOverview->Destroy();}void StructureWindow::OnPreferences(wxCommandEvent& event){ PreferencesDialog dialog(this); int result = dialog.ShowModal(); glCanvas->Refresh(true); // in case stereo options changed}bool StructureWindow::SaveDialog(bool prompt, bool canCancel){ // check for whether save is necessary if (!glCanvas->structureSet || !glCanvas->structureSet->HasDataChanged()) 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 save your work to a file?", "", option); option = dialog.ShowModal(); if (option == wxID_CANCEL) return false; // user cancelled this operation } if (option == wxID_YES) { wxCommandEvent event; event.SetId(prompt ? MID_SAVE_AS : MID_SAVE_SAME); OnSave(event); // save data } return true;}// for sorting sequence list in reject dialogtypedef pair < const Sequence * , wxString > SeqAndDescr;typedef vector < SeqAndDescr > SeqAndDescrList;static bool CompareSequencesByIdentifier(const SeqAndDescr& a, const SeqAndDescr& b){ return MoleculeIdentifier::CompareIdentifiers( a.first->identifier, b.first->identifier);}void StructureWindow::ShowCDDOverview(void){ if (!cddOverview) cddOverview = new CDDSplashDialog( this, glCanvas->structureSet, &cddOverview, this, -1, "CDD Descriptive Items", wxPoint(200,50)); cddOverview->Raise(); cddOverview->Show(true);}void StructureWindow::ShowCDDAnnotations(void){ if (!cddAnnotateDialog) cddAnnotateDialog = new CDDAnnotateDialog(this, &cddAnnotateDialog, glCanvas->structureSet); cddAnnotateDialog->Raise(); cddAnnotateDialog->Show(true);}void StructureWindow::ShowCDDReferences(void){ if (!cddRefDialog) cddRefDialog = new CDDRefDialog( glCanvas->structureSet, &cddRefDialog, this, -1, "CDD PubMed References"); cddRefDialog->Raise(); cddRefDialog->Show(true);}void StructureWindow::ShowCDDBookReferences(void){ if (!cddBookRefDialog) cddBookRefDialog = new CDDBookRefDialog( glCanvas->structureSet, &cddBookRefDialog, this, -1, "CDD Book References"); cddBookRefDialog->Raise(); cddBookRefDialog->Show(true);}void StructureWindow::OnCDD(wxCommandEvent& event){ if (!glCanvas->structureSet || !glCanvas->structureSet->IsCDD()) return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -