NCBI C++ ToolKit
seq_desktop_panel.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: seq_desktop_panel.cpp 44457 2019-12-19 19:25:12Z asztalos $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Roman Katargin, Andrea Asztalos
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
35 #include <objmgr/feat_ci.hpp>
41 
42 #include <gui/utils/menu_item.hpp>
48 
49 #include <wx/srchctrl.h>
50 
53 
54 IMPLEMENT_DYNAMIC_CLASS(CSeqDesktopPanel, wxPanel)
55 
56 BEGIN_EVENT_TABLE(CSeqDesktopPanel, wxPanel)
61 
64  EVT_LEFT_DOWN(CSeqDesktopPanel::OnMouseClick)
65 
66  EVT_SEARCHCTRL_SEARCH_BTN(ID_SEARCHCTRL, CSeqDesktopPanel::OnSearchCtrlClick)
68 
69 /*!
70 * CSeqDesktopPanel constructors
71 */
72 
74 {
75  Init();
76 }
77 
78 
79 CSeqDesktopPanel::CSeqDesktopPanel(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style)
80 {
81  Init();
82  Create(parent, id, pos, size, style);
84 }
85 
86 /*!
87 * CSeqDesktopPanel destructor
88 */
89 
91 {
92  m_AuiManager.UnInit();
93 }
94 
95 
97 {
100  m_MaxExpansion = 2;
102  m_CmdProccessor = nullptr;
105 }
106 
107 /*!
108 * Control creation for CSeqDesktopPanel
109 */
110 
111 static const wxChar* pszMainToolbar = wxT("Main Toolbar");
112 
114 {
115  SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY);
116 
117  Hide();
118 
119  m_AuiManager.SetManagedWindow(this);
120 
121  m_TextWindow = new CDesktopCanvas(this, ID_WIDGET, wxDefaultPosition, wxDefaultSize, wxNO_BORDER | wxHSCROLL | wxVSCROLL | wxFULL_REPAINT_ON_RESIZE);
122  m_AuiManager.AddPane(m_TextWindow, wxAuiPaneInfo().CenterPane());
123 
124  m_TextWindow->SetBackgroundColour(wxColor(wxT("white")));
125  m_TextWindow->SetFocus();
126 
127  m_AuiManager.Update();
128 
129  // m_TextWindow->SetFont();
130 }
131 
133 {
134  static bool sImagesRegistered = false;
135  if (!sImagesRegistered) {
137  provider->RegisterFileAlias(wxT("seq_desktop_panel::zoom_in"), wxT("zoom_in.png"));
138  provider->RegisterFileAlias(wxT("seq_desktop_panel::zoom_out"), wxT("zoom_out.png"));
139  sImagesRegistered = true;
140  }
141 
142  // create the toolbar
143  m_Toolbar = new wxAuiToolBar(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxAUI_TB_HORZ_LAYOUT | wxBORDER_NONE);
144  m_Toolbar->AddTool(ID_TB_ZOOMIN, wxT("Zoom In"), wxArtProvider::GetBitmap(wxT("seq_desktop_panel::zoom_in")), wxT("Zoom In"));
145  m_Toolbar->AddTool(ID_TB_ZOOMOUT, wxT("Zoom Out"), wxArtProvider::GetBitmap(wxT("seq_desktop_panel::zoom_out")), wxT("Zoom Out"));
146  m_Toolbar->EnableTool(ID_TB_ZOOMOUT, false);
147 
148  m_Toolbar->AddSeparator();
149  m_SearchCtrl = new wxSearchCtrl(m_Toolbar, ID_SEARCHCTRL, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
150  m_SearchCtrl->SetDescriptiveText(_("Search the view"));
151  //m_SearchCtrl->Bind(wxEVT_TEXT_ENTER, &CSeqDesktopPanel::OnSearchCtrlEnter, this);
152  m_SearchCtrl->Bind(wxEVT_CHAR_HOOK, &CSeqDesktopPanel::OnSearchCtrlEnter, this); // a hack, the wxEVT_TEXT_ENTER event should be bound to the control
153  m_Toolbar->AddControl(m_SearchCtrl);
154 
155  m_Toolbar->Realize();
156 
157  m_AuiManager.AddPane(m_Toolbar, wxAuiPaneInfo()
158  .Name(pszMainToolbar)
159  .Caption(pszMainToolbar)
160  .ToolbarPane()
161  .Top()
162  .TopDockable(true)
163  .LeftDockable(false)
164  .RightDockable(false)
165  .BottomDockable(false)
166  .Floatable(false)
167  .Resizable(false)
168  .DestroyOnClose(true)
169  .Position(0));
170 
171  m_AuiManager.Update();
172 }
173 
175 {
176  m_WidgetHost = host;
177 }
178 
180 {
181  if (objects.size() != 1) return false;
182 
183  m_Scope.Reset(objects.front().scope.GetPointer());
184  m_SO.Reset(dynamic_cast<const CSerialObject*>(objects.front().object.GetPointer()));
185 
187  Load();
188  return true;
189 }
190 
192 {
193  if (!m_SO) return;
194 
195  if (!m_AuiManager.GetPane(pszMainToolbar).IsOk())
196  x_CreateToolbar();
197 
199  CIRef<IDesktopItem> root = builder.GetRootDesktopItem();
203 }
204 
205 
207 {
208  if (!m_SO) return;
209  m_MaxExpansion = 2;
210 
211  const CSeq_entry* entry = dynamic_cast<const CSeq_entry*>(m_SO.GetPointer());
212  const CSeq_submit* submit = dynamic_cast<const CSeq_submit*>(m_SO.GetPointer());
213  const CSeq_id* seq_id = dynamic_cast<const CSeq_id*>(m_SO.GetPointer());
214  const CSeq_annot* seq_annot = dynamic_cast<const CSeq_annot*>(m_SO.GetPointer());
215 
216  CSeq_entry_Handle seh;
217  if (submit && submit->IsSetData()) {
218  const CSeq_submit::TData& data = submit->GetData();
219  if (data.IsEntrys()) {
220  const CSeq_submit::TData::TEntrys& entries = data.GetEntrys();
221  if (!entries.empty()) {
222  entry = *entries.begin();
223  }
224  }
225  }
226 
227  if (seq_id) {
228  CBioseq_Handle bsh = m_Scope->GetBioseqHandle(*seq_id);
229  if (bsh) {
230  seh = bsh.GetTopLevelEntry();
231  }
232  }
233  else if (entry) {
234  seh = m_Scope->GetSeq_entryHandle(*entry);
235  }
236 
237  if (seh) {
238  CFeat_CI feat_it(seh);
239  if (feat_it) {
240  m_MaxExpansion = 4;
241  }
242  }
243  else if (seq_annot) {
244  CSeq_annot_Handle ah = m_Scope->GetSeq_annotHandle(*seq_annot);
245  if (ah) {
246  CFeat_CI feat_it(ah);
247  if (feat_it) {
248  m_MaxExpansion = 4;
249  }
250  }
251  }
252 }
253 
255 {
256  if (m_SO) {
257  SConstScopedObject scoped_object;
258  scoped_object.object = m_SO;
259  scoped_object.scope = m_Scope;
260  objs.push_back(scoped_object);
261  }
262 }
263 
265 {
266  return m_SO.GetPointerOrNull();
267 }
268 
270 {
272 }
273 
275 {
277 }
278 
280 {
281  m_CmdProccessor = cmdProccessor;
282 }
283 
285 {
286  m_TextWindow->GetViewStart(&m_SavedStartX, &m_SavedStartY);
288 }
289 
291 {
294 
295  if (m_WidgetHost) {
299  // the view should notify the selection service about selection change
301  }
302 
303  if (m_SavedStartY > 0) {
304  int x, y;
305  m_TextWindow->GetVirtualSize(&x, &y);
306 
307  int xUnit, yUnit;
308  m_TextWindow->GetScrollPixelsPerUnit(&xUnit, &yUnit);
309  if (y / yUnit > m_SavedStartY)
311  }
313 }
314 
315 void CSeqDesktopPanel::OnZoomInClick(wxCommandEvent& event)
316 {
317  m_TextWindow->ZoomIn();
318 }
319 
320 void CSeqDesktopPanel::OnZoomOutClick(wxCommandEvent& event)
321 {
323 }
324 
325 void CSeqDesktopPanel::UpdateZoomIn(wxUpdateUIEvent& event)
326 {
327  m_Toolbar->EnableTool(event.GetId(), (m_TextWindow->GetExpansionLevel() < m_MaxExpansion));
328 }
329 
330 void CSeqDesktopPanel::UpdateZoomOut(wxUpdateUIEvent& event)
331 {
332  m_Toolbar->EnableTool(event.GetId(), (m_TextWindow->GetExpansionLevel() > 0));
333 }
334 
336 {
337  CIRef<IBioseqEditor> editor;
338  if (m_CmdProccessor) {
339  editor = x_CreateEditor();
340  }
341 
344  return context;
345 }
346 
348 {
349  CIRef<IBioseqEditor> editor;
350 
351  vector<IEditorFactory*> factories;
353 
354  ITERATE(vector<IEditorFactory*>, it, factories) {
355  editor.Reset(dynamic_cast<IBioseqEditor*>(
356  (*it)->CreateEditor(typeid(IBioseqEditor).name(), *m_CmdProccessor, m_WidgetHost)));
357 
358  if (editor)
359  break;
360  }
361 
362  return editor;
363 }
364 
365 void CSeqDesktopPanel::OnCutSelection(wxCommandEvent& event)
366 {
367  x_SaveSelection();
368 }
369 
370 void CSeqDesktopPanel::OnCopySelection(wxCommandEvent& event)
371 {
372  x_SaveSelection();
373 }
374 
376 {
379 }
380 
381 void CSeqDesktopPanel::OnMouseClick(wxMouseEvent& event)
382 {
383  switch (event.GetId()) {
384  case ID_WIDGET:
385  {
386  // redirect event handling to the view
388  Send(&click_event, ePool_Parent);
389  break;
390  }
391  default:
392  break;
393  }
394 
395  event.Skip();
396 }
397 
398 void CSeqDesktopPanel::OnSearchCtrlClick(wxCommandEvent& event)
399 {
400  x_FindText(ToStdString(event.GetString()));
401 }
402 
403 /*
404 void CSeqDesktopPanel::OnSearchCtrlEnter(wxCommandEvent& event)
405 {
406  x_FindText(ToStdString(event.GetString()));
407 }
408 */
409 
410 void CSeqDesktopPanel::OnSearchCtrlEnter(wxKeyEvent& event)
411 {
412  switch (event.GetKeyCode()) {
413  case WXK_RETURN:
414  case WXK_NUMPAD_ENTER:
415  x_FindText(ToStdString(m_SearchCtrl->GetValue()));
416  break;
417  default:
418  break;
419  }
420  event.Skip();
421 }
422 
423 void CSeqDesktopPanel::x_FindText(const string& search)
424 {
425  if (search.empty()) {
426  NcbiMessageBox("Search string is empty");
427  return;
428  }
429 
430  // for now, every search is case insensitive
431  bool found = m_TextWindow->FindText(search);
432  if (!found) {
433  NcbiInfoBox("Search string was not found.");
434  }
435 }
436 
User-defined methods of the data storage class.
EVT_UPDATE_UI(eCmdAlnShowMethodsDlg, CAlnMultiWidget::OnUpdateShowMethodDlg) EVT_UPDATE_UI(eCmdMethodProperties
CBioseq_Handle –.
Defines a scrollable canvas for drawing purposes.
void SetMainItem(IDesktopItem *main_item, int state=0)
void SetContext(CDesktopViewContext *context)
CDesktopViewContext * GetContext() const
int GetExpansionLevel() const
void SetSelectedObjects(const TConstObjects &objs)
bool FindText(const string &search)
void GetSelectedObjects(TConstObjects &objects) const
void ZoomOut(void)
CIRef< IDesktopItem > GetRootDesktopItem() const
Definition: desktop_ds.hpp:55
ESavedObjectType GetSavedObjectType() const
const CSerialObject * GetSavedObject() const
CFeat_CI –.
Definition: feat_ci.hpp:64
CObject –.
Definition: ncbiobj.hpp:180
wxSearchCtrl * m_SearchCtrl
wxAuiManager m_AuiManager
CDesktopViewContext * x_CreateDesktopViewContext()
virtual bool InitWidget(TConstScopedObjects &objects)
void Init()
Initialises member variables.
virtual void DataChanged()
virtual void GetSelectedObjects(TConstObjects &objects) const
virtual void SetUndoManager(ICommandProccessor *cmdProccessor)
void OnZoomInClick(wxCommandEvent &event)
virtual void DataChanging()
CDesktopCanvas * m_TextWindow
The canvas where all drawing takes place.
void OnMouseClick(wxMouseEvent &event)
void OnSearchCtrlClick(wxCommandEvent &event)
int m_MaxExpansion
Maximum level of expansion to be shown for the main object.
CDesktopViewContext::ESavedObjectType m_SavedType
void Load(int state=0)
Calls the builder (CDesktopDataBuilder) that creates all desktop items.
ICommandProccessor * m_CmdProccessor
CSeqDesktopPanel()
Constructors.
void UpdateZoomOut(wxUpdateUIEvent &event)
wxAuiToolBar * m_Toolbar
CIRef< IBioseqEditor > x_CreateEditor()
Creates the IBioseqEditor event handler. This is responsible for the Edit & Delete context menu items...
virtual void SetHost(IGuiWidgetHost *host)
virtual const CObject * GetOrigObject() const
void UpdateZoomIn(wxUpdateUIEvent &event)
void GetMainObjects(TConstScopedObjects &objs) const
void OnCopySelection(wxCommandEvent &event)
virtual void SetSelectedObjects(const TConstObjects &objects)
void OnCutSelection(wxCommandEvent &event)
void x_FindText(const string &search)
void OnSearchCtrlEnter(wxKeyEvent &event)
void x_SaveSelection()
Obtains the saved object and its type from the context for a possible, future Paste operation.
CConstRef< CSerialObject > m_SO
Main object to be displayed.
IGuiWidgetHost * m_WidgetHost
void CreateControls()
Creates the controls and sizers.
virtual ~CSeqDesktopPanel()
Destructor.
CRef< objects::CScope > m_Scope
Scope of the main object.
CConstRef< CSerialObject > m_SavedObject
void x_SetMaxExpansionLevel(void)
Sets m_MaxExpansion for the main object.
void OnZoomOutClick(wxCommandEvent &event)
CSeq_annot_Handle –.
CSeq_entry_Handle –.
Definition: Seq_entry.hpp:56
Base class for all serializable objects.
Definition: serialbase.hpp:150
IBioseqEditor.
Undo/Redo interface for editing operations.
virtual void GetAppSelection(TConstObjects &)
Definition: gui_widget.hpp:55
virtual void WidgetSelectionChanged()=0
virtual void RegisterFileAlias(const wxArtID &anId, const wxArtClient &aClient, const wxSize &aSize, const wxString &aName, long aType=wxBITMAP_TYPE_ANY, int anIndex=-1)
#define _(proto)
Definition: ct_nlmzip_i.h:78
static void Init(void)
Definition: cursor6.c:76
char data[12]
Definition: iconv.c:80
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NULL
Definition: ncbistd.hpp:225
EDialogReturnValue NcbiInfoBox(const string &message, const string &title="Info")
specialized Message Box function for reporting general information messages
CRef< objects::CScope > scope
Definition: objects.hpp:53
void GetExtensionAsInterface(const string &ext_point_id, vector< CIRef< I > > &interfaces)
GetExtensionAsInterface() is a helper function that extracts all extensions implementing the specifie...
vector< CConstRef< CObject > > TConstObjects
Definition: objects.hpp:64
EDialogReturnValue NcbiMessageBox(const string &message, TDialogType type=eDialog_Ok, EDialogIcon icon=eIcon_Exclamation, const string &title="Error", EDialogTextMode text_mode=eRaw)
Definition: message_box.cpp:48
CConstRef< CObject > object
Definition: objects.hpp:52
vector< SConstScopedObject > TConstScopedObjects
Definition: objects.hpp:65
virtual bool Send(CEvent *evt, EDispatch disp_how=eDispatch_Default, int pool_name=ePool_Default)
Sends an event synchronously.
@ eEvent_Message
message from one class to another
Definition: event.hpp:99
CSeq_entry_Handle GetTopLevelEntry(void) const
Get top level Seq-entry handle.
TObjectType * GetPointer(void) const THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:1684
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:1439
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
TObjectType * GetPointerOrNull(void) const THROWS_NONE
Get pointer value.
Definition: ncbiobj.hpp:1672
TObjectType & GetObject(void) const
Get object.
Definition: ncbiobj.hpp:1697
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
bool IsSetData(void) const
Check if a value has been assigned to Data data member.
list< CRef< CSeq_entry > > TEntrys
const TData & GetData(void) const
Get the Data member data.
#define EXT_POINT__EDITOR_FACTORY
END_EVENT_TABLE()
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
#define ID_SEARCHCTRL
USING_SCOPE(objects)
static const wxChar * pszMainToolbar
static static static wxID_ANY
ViewerWindowBase::OnEditMenu ViewerWindowBase::OnJustification EVT_MENU(MID_SHOW_GEOM_VLTNS, ViewerWindowBase::OnShowGeomVltns) EVT_MENU(MID_FIND_PATTERN
#define _ASSERT
static CS_CONTEXT * context
Definition: will_convert.c:21
static wxAcceleratorEntry entries[3]
wxFileArtProvider * GetDefaultFileArtProvider()
Definition: wx_utils.cpp:334
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Mon Jun 17 05:08:55 2024 by modify_doxy.py rev. 669887