00001 /* $Id $ 00002 * =========================================================================== 00003 * 00004 * PUBLIC DOMAIN NOTICE 00005 * National Center for Biotechnology Information 00006 * 00007 * This software/database is a "United States Government Work" under the 00008 * terms of the United States Copyright Act. It was written as part of 00009 * the author's official duties as a United States Government employee and 00010 * thus cannot be copyrighted. This software/database is freely available 00011 * to the public for use. The National Library of Medicine and the U.S. 00012 * Government have not placed any restriction on its use or reproduction. 00013 * 00014 * Although all reasonable efforts have been taken to ensure the accuracy 00015 * and reliability of the software and data, the NLM and the U.S. 00016 * Government do not and cannot warrant the performance or results that 00017 * may be obtained by using this software or data. The NLM and the U.S. 00018 * Government disclaim all warranties, express or implied, including 00019 * warranties of performance, merchantability or fitness for any particular 00020 * purpose. 00021 * 00022 * Please cite the author in any work or product based on this material. 00023 * 00024 * =========================================================================== 00025 * 00026 * Authors: Robert G. Smith 00027 * 00028 * File Description: 00029 * 00030 */ 00031 00032 #include <ncbi_pch.hpp> 00033 #include <gui/widgets/seq_graphic/seqgraphic_conf_panel.hpp> 00034 00035 #include <gui/widgets/seq_graphic/seqgraphic_preview.hpp> 00036 #include <gui/widgets/seq_graphic/seqgraphic_conf.hpp> 00037 #include <gui/widgets/seq_graphic/seqgraphic_ds.hpp> 00038 00039 #include <gui/utils/string_utils.hpp> 00040 00041 #include <objmgr/object_manager.hpp> 00042 #include <objects/seqset/Seq_entry.hpp> 00043 #include <objmgr/scope.hpp> 00044 #include <serial/serial.hpp> 00045 #include <serial/objistr.hpp> 00046 00047 00048 BEGIN_NCBI_SCOPE 00049 00050 CSeqGraphicConfigPanel::CSeqGraphicConfigPanel() 00051 { 00052 // Set our direction. 00053 // can't change after making the widgets. 00054 SetLayoutDirection(CThemeConfigPanel2::eLayoutDirection_Vertical); 00055 } 00056 00057 00058 CSeqGraphicConfigPanel::~CSeqGraphicConfigPanel() 00059 { 00060 } 00061 00062 00063 void CSeqGraphicConfigPanel::MakeWidgets() 00064 { 00065 CThemeConfigPanel2::MakeWidgets(); 00066 00067 00068 _ASSERT(m_PreviewConfig.IsNull()); // Should only be called once in the life time of this class. 00069 00070 // Do all the plumbing to support the preview: 00071 00072 // create our own CSeqGraphicConfig. 00073 m_PreviewConfig.Reset(new CSeqGraphicConfig()); 00074 00075 // create a CThemePreviewMediator which contains this panel and our private config. 00076 // when any widget here changes we tell this to save the changes 00077 // and notify the preview widget. 00078 m_PreviewMediator.Reset(new CThemePreviewMediator(*m_PreviewConfig, *this)); 00079 00080 // Size and put the preview widget in the parent's preview group. 00081 // It got created by the parent above. 00082 Fl_Group* preview_group = GetPreviewLocation(); 00083 00084 // create a preview widget. 00085 const int inset = 2; 00086 m_PreviewWidget = new CSeqGraphicPreview( 00087 preview_group->x() + inset, 00088 preview_group->y() + inset, 00089 preview_group->w() - 2 * inset, 00090 preview_group->h() - 2 * inset); 00091 00092 // Set its config to our private config. 00093 m_PreviewWidget->SetConfig(m_PreviewConfig); 00094 00095 // give it the special Data source. 00096 00097 m_PreviewWidget->SetDataSource(& x_GetFakeDataSource()); 00098 00099 preview_group->add(m_PreviewWidget); 00100 preview_group->resizable(m_PreviewWidget); 00101 } 00102 00103 00104 00105 void CSeqGraphicConfigPanel::UpdatePreview() 00106 { 00107 // Save the dialog's values so we can display them. 00108 m_PreviewMediator->Save(kEmptyStr); 00109 00110 // Tell the preview that its configuration has changed. 00111 m_PreviewWidget->UpdateConfig(); 00112 00113 } 00114 00115 // file defines s_PreviewData 00116 #include "preview_data.hpp" 00117 const string kPreviewId("lcl|fake_nuc"); 00118 00119 CSeqGraphicDataSource& CSeqGraphicConfigPanel::x_GetFakeDataSource() 00120 { 00121 USING_SCOPE(objects); 00122 00123 if (! m_PreviewDS) { 00124 // read in data from a static memory into a seq entry. 00125 string preview_data_str = CStringUtil::BuildString(s_PreviewData); 00126 CRef<CSeq_entry> preview_TSE(new CSeq_entry); 00127 00128 CNcbiIstrstream is(preview_data_str.c_str(), strlen(preview_data_str.c_str())); 00129 auto_ptr<CObjectIStream> 00130 pd_in(CObjectIStream::Open(eSerial_AsnText, is)); 00131 *pd_in >> *preview_TSE; 00132 _TRACE("CSettings::x_GetFakeDataSource(): " 00133 "text preview data source read from string: \"" 00134 << preview_data_str.substr(0,20) << " ... \"" ); 00135 00136 CRef<CScope> preview_scope(new CScope(*CObjectManager::GetInstance()) ); 00137 preview_scope->AddTopLevelSeqEntry(*preview_TSE); 00138 00139 CSeq_id preview_id(kPreviewId); 00140 00141 // create data source from the above. 00142 m_PreviewDS.Reset(new CSeqGraphicDataSource(*preview_scope, preview_id)); 00143 } 00144 00145 return *m_PreviewDS; 00146 } 00147 00148 00149 END_NCBI_SCOPE 00150 00151
1.4.6
Modified on Mon Dec 07 16:21:05 2009 by modify_doxy.py rev. 173732