📄 cn3d_app.cpp
字号:
/* * =========================================================================== * PRODUCTION $Log: cn3d_app.cpp,v $ * PRODUCTION Revision 1000.3 2004/06/01 18:28:05 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.21 * PRODUCTION * =========================================================================== *//* $Id: cn3d_app.cpp,v 1000.3 2004/06/01 18:28:05 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:* log and application object for Cn3D** ===========================================================================*/#ifdef _MSC_VER#pragma warning(disable:4018) // disable signed/unsigned mismatch warning in MSVC#endif#include <ncbi_pch.hpp>#include <corelib/ncbistd.hpp>#include <corelib/ncbitime.hpp> // avoids some 'CurrentTime' conflict later on...#include <ctools/ctools.h>#include <serial/objostr.hpp>#include <objects/mmdb1/Biostruc.hpp>#include <objects/ncbimime/Ncbi_mime_asn1.hpp>#include <objects/ncbimime/Biostruc_seq.hpp>#include <objects/seq/Bioseq.hpp>#include <objects/seqset/Seq_entry.hpp>#include <objects/seqset/Bioseq_set.hpp>#include <objects/mmdb2/Biostruc_model.hpp>#include <objects/mmdb2/Model_type.hpp>#include <objects/mmdb1/Biostruc_graph.hpp>#include <objects/mmdb1/Molecule_graph.hpp>#include <objects/seqloc/Seq_id.hpp>#include <algorithm>#include <vector>#ifdef __WXMSW__#include <windows.h>#include <wx/msw/winundef.h>#endif#include <wx/wx.h>#include <wx/filesys.h>#include <wx/fs_zip.h>#include "asn_reader.hpp"#include "cn3d_app.hpp"#include "structure_window.hpp"#include "cn3d_tools.hpp"#include "structure_set.hpp"#include "chemical_graph.hpp"#include "cn3d_glcanvas.hpp"#include "opengl_renderer.hpp"#include "messenger.hpp"#include "alignment_manager.hpp"#include "cn3d_cache.hpp"// the application icon (under Windows it is in resources)#if defined(__WXGTK__) || defined(__WXMAC__) #include "cn3d.xpm"#endif#include <ncbi.h>#include <ncbienv.h>USING_NCBI_SCOPE;USING_SCOPE(objects);// `Main program' equivalentIMPLEMENT_APP(Cn3D::Cn3DApp)BEGIN_SCOPE(Cn3D)// global strings for various directories - will include trailing path separator characterstatic string workingDir, // current working directory programDir, // directory where Cn3D executable lives dataDir, // 'data' directory with external data files prefsDir; // application preferences directoryconst string& GetWorkingDir(void) { return workingDir; }const string& GetProgramDir(void) { return programDir; }const string& GetDataDir(void) { return dataDir; }const string& GetPrefsDir(void) { return prefsDir; }// top-level window (the main structure window)static wxFrame *topWindow = NULL;wxFrame * GlobalTopWindow(void) { return topWindow; }// Set the NCBI diagnostic streams to go to this method, which then pastes them// into a wxWindow. This log window can be closed anytime, but will be hidden,// not destroyed. More serious errors will bring up a dialog, so that the user// will get a chance to see the error before the program halts upon a fatal error.class MsgFrame;static MsgFrame *logFrame = NULL;static list < string > backLog;class MsgFrame : public wxFrame{public: wxTextCtrl *logText; int totalChars; MsgFrame(const wxString& title, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize) : wxFrame(GlobalTopWindow(), wxID_HIGHEST + 5, title, pos, size, wxDEFAULT_FRAME_STYLE#if defined(__WXMSW__) | wxFRAME_TOOL_WINDOW | wxFRAME_NO_TASKBAR | wxFRAME_FLOAT_ON_PARENT#endif ) { totalChars = 0; SetIcon(wxICON(cn3d)); } ~MsgFrame(void) { logFrame = NULL; logText = NULL; }private: // need to define a custom close window handler, so that window isn't actually destroyed, // just hidden when user closes it with system close button void OnCloseWindow(wxCloseEvent& event); DECLARE_EVENT_TABLE()};BEGIN_EVENT_TABLE(MsgFrame, wxFrame) EVT_CLOSE(MsgFrame::OnCloseWindow)END_EVENT_TABLE()void MsgFrame::OnCloseWindow(wxCloseEvent& event){ if (event.CanVeto()) { Show(false); event.Veto(); } else { Destroy(); logFrame = NULL; }}static bool dialogSevereErrors = true;void SetDialogSevereErrors(bool status){ dialogSevereErrors = status;}void DisplayDiagnostic(const SDiagMessage& diagMsg){ string errMsg; diagMsg.Write(errMsg); // severe errors get a special error dialog if (diagMsg.m_Severity >= eDiag_Error && diagMsg.m_Severity != eDiag_Trace && dialogSevereErrors) { wxMessageDialog dlg(NULL, errMsg.c_str(), "Severe Error!", wxOK | wxCENTRE | wxICON_EXCLAMATION); dlg.ShowModal(); } // info messages and less severe errors get added to the log else { if (logFrame) { // delete top of log if too big if (logFrame->totalChars + errMsg.size() > 100000) { logFrame->logText->Clear(); logFrame->totalChars = 0; } logFrame->logText->SetInsertionPoint(logFrame->logText->GetLastPosition()); *(logFrame->logText) << errMsg.c_str(); logFrame->totalChars += errMsg.size(); } else { // if message window doesn't exist yet, store messages until later backLog.push_back(errMsg.c_str()); } }}void RaiseLogWindow(void){ if (!logFrame) { logFrame = new MsgFrame("Cn3D Message Log", wxPoint(500, 0), wxSize(500, 500));#ifdef __WXMAC__ // make empty menu for this window wxMenuBar *menuBar = new wxMenuBar; logFrame->SetMenuBar(menuBar);#endif logFrame->SetSizeHints(150, 100); logFrame->logText = new wxTextCtrl(logFrame, -1, "", wxPoint(0,0), logFrame->GetClientSize(), wxTE_RICH | wxTE_MULTILINE | wxTE_READONLY | wxHSCROLL); // display any messages received before window created while (backLog.size() > 0) { *(logFrame->logText) << backLog.front().c_str(); logFrame->totalChars += backLog.front().size(); backLog.erase(backLog.begin()); } } logFrame->logText->ShowPosition(logFrame->logText->GetLastPosition()); logFrame->Show(true);#if defined(__WXMSW__) if (logFrame->IsIconized()) logFrame->Maximize(false);#endif logFrame->Raise();}BEGIN_EVENT_TABLE(Cn3DApp, wxGLApp) EVT_IDLE(Cn3DApp::OnIdle)END_EVENT_TABLE()Cn3DApp::Cn3DApp() : wxGLApp(){ // setup the diagnostic stream SetDiagHandler(DisplayDiagnostic, NULL, NULL); SetDiagPostLevel(eDiag_Info); // report all messages SetDiagTrace(eDT_Default); // trace messages only when DIAG_TRACE env. var. is set#ifdef _DEBUG SetDiagPostFlag(eDPF_File); SetDiagPostFlag(eDPF_Line);#else UnsetDiagTraceFlag(eDPF_File); UnsetDiagTraceFlag(eDPF_Line);#endif SetupCToolkitErrPost(); // reroute C-toolkit err messages to C++ err streams // C++ object verification CSerialObject::SetVerifyDataGlobal(eSerialVerifyData_Always); CObjectIStream::SetVerifyDataGlobal(eSerialVerifyData_Always); CObjectOStream::SetVerifyDataGlobal(eSerialVerifyData_Always); if (!InitGLVisual(NULL)) FATALMSG("InitGLVisual failed");}void Cn3DApp::InitRegistry(void){ // first set up defaults, then override any/all with stuff from registry file // default log window startup RegistrySetBoolean(REG_CONFIG_SECTION, REG_SHOW_LOG_ON_START, false); RegistrySetString(REG_CONFIG_SECTION, REG_FAVORITES_NAME, NO_FAVORITES_FILE); // default animation controls RegistrySetInteger(REG_ANIMATION_SECTION, REG_SPIN_DELAY, 50); RegistrySetDouble(REG_ANIMATION_SECTION, REG_SPIN_INCREMENT, 2.0), RegistrySetInteger(REG_ANIMATION_SECTION, REG_FRAME_DELAY, 500); // default quality settings RegistrySetInteger(REG_QUALITY_SECTION, REG_QUALITY_ATOM_SLICES, 10); RegistrySetInteger(REG_QUALITY_SECTION, REG_QUALITY_ATOM_STACKS, 8); RegistrySetInteger(REG_QUALITY_SECTION, REG_QUALITY_BOND_SIDES, 6); RegistrySetInteger(REG_QUALITY_SECTION, REG_QUALITY_WORM_SIDES, 6); RegistrySetInteger(REG_QUALITY_SECTION, REG_QUALITY_WORM_SEGMENTS, 6); RegistrySetInteger(REG_QUALITY_SECTION, REG_QUALITY_HELIX_SIDES, 12); RegistrySetBoolean(REG_QUALITY_SECTION, REG_HIGHLIGHTS_ON, true); RegistrySetString(REG_QUALITY_SECTION, REG_PROJECTION_TYPE, "Perspective"); // default font for OpenGL (structure window) wxFont *font = wxFont::New(#if defined(__WXMSW__) 12,#elif defined(__WXGTK__) 14,#elif defined(__WXMAC__) 14,#endif wxSWISS, wxNORMAL, wxBOLD, false); if (font && font->Ok()) RegistrySetString(REG_OPENGL_FONT_SECTION, REG_FONT_NATIVE_FONT_INFO, font->GetNativeFontInfoDesc().c_str()); else ERRORMSG("Can't create default structure window font"); if (font) delete font; // default font for sequence viewers font = wxFont::New(#if defined(__WXMSW__) 10,#elif defined(__WXGTK__) 14,#elif defined(__WXMAC__) 12,#endif wxROMAN, wxNORMAL, wxNORMAL, false); if (font && font->Ok()) RegistrySetString(REG_SEQUENCE_FONT_SECTION, REG_FONT_NATIVE_FONT_INFO, font->GetNativeFontInfoDesc().c_str()); else ERRORMSG("Can't create default sequence window font"); if (font) delete font; // default cache settings RegistrySetBoolean(REG_CACHE_SECTION, REG_CACHE_ENABLED, true); if (GetPrefsDir().size() > 0) RegistrySetString(REG_CACHE_SECTION, REG_CACHE_FOLDER, GetPrefsDir() + "cache"); else RegistrySetString(REG_CACHE_SECTION, REG_CACHE_FOLDER, GetProgramDir() + "cache"); RegistrySetInteger(REG_CACHE_SECTION, REG_CACHE_MAX_SIZE, 25); // default advanced options RegistrySetBoolean(REG_ADVANCED_SECTION, REG_CDD_ANNOT_READONLY, true);#ifdef __WXGTK__ RegistrySetString(REG_ADVANCED_SECTION, REG_BROWSER_LAUNCH, // for launching netscape in a separate window "( netscape -noraise -remote 'openURL(<URL>,new-window)' || netscape '<URL>' ) >/dev/null 2>&1 &" // for launching netscape in an existing window// "( netscape -raise -remote 'openURL(<URL>)' || netscape '<URL>' ) >/dev/null 2>&1 &" );#endif RegistrySetInteger(REG_ADVANCED_SECTION, REG_MAX_N_STRUCTS, 10); RegistrySetInteger(REG_ADVANCED_SECTION, REG_FOOTPRINT_RES, 15); // default stereo options RegistrySetDouble(REG_ADVANCED_SECTION, REG_STEREO_SEPARATION, 5.0); RegistrySetBoolean(REG_ADVANCED_SECTION, REG_PROXIMAL_STEREO, true); // load program registry - overriding defaults if present LoadRegistry();}static CNcbi_mime_asn1 * CreateMimeFromBiostruc(const wxString& filename, EModel_type model){ // read Biostruc CRef < CBiostruc > biostruc(new CBiostruc()); string err; SetDiagPostLevel(eDiag_Fatal); // ignore all but Fatal errors while reading data bool okay = (ReadASNFromFile(filename.c_str(), biostruc.GetPointer(), true, &err) || ReadASNFromFile(filename.c_str(), biostruc.GetPointer(), false, &err));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -