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

Go to the SVN repository for this file.

1 /* $Id: sequin_desktop_view.cpp 41968 2018-11-23 17:42:33Z filippov $
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
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
35 #include <objmgr/bioseq_ci.hpp>
36 #include <objmgr/util/sequence.hpp>
37 
40 #include <gui/core/document.hpp>
45 #include <gui/objutils/utils.hpp>
56 
57 #include <wx/panel.h>
58 #include <wx/aui/aui.h>
59 
62 
63 namespace {
64 CProjectViewTypeDescriptor s_ViewTypeDescr(
65  "Sequin Desktop View", // type name
66  "sequin_desktop_view", // icon alias
67  "Create an interactive text representation of data.",
68  "The Sequin Desktop View shows Seq-entry hierarchy.",
69  "SEQUIN_DESKTOP_VIEW", // help ID
70  "Sequence", // category
71  false, // not a singleton
72  "Seq-entry",
74 );
75 }
76 
77 
82 
84  : CProjectView(), m_Window(0)
85 {
86 }
87 
89 {
90 }
91 
93 {
95  return m_Window;
96 }
97 
99 {
100  _ASSERT(m_Window);
101  return m_Window->GetWidget()->GetEventHandler();
102 }
103 
104 // override function to suppress Navigation toolbar
106 {
108 }
109 
111 {
112  return 0;
113 }
114 
116 {
117  CScope* scope = NULL;
118  const CObject* object = NULL;
119 
120 
121  if(objects.size() == 1) {
122  object = objects[0].object.GetPointer();
123  scope = objects[0].scope.GetPointer();
124  }
125 
126  if (object) {
128  _ASSERT(srv);
129 
130  CRef<CGBWorkspace> ws = srv->GetGBWorkspace();
131  if (!ws) return false;
132  CWorkspaceFolder& root_folder = ws->SetWorkspace();
133 
134  CGBDocument* doc = dynamic_cast<CGBDocument*>(ws->GetProjectFromScope(*scope));
135  _ASSERT(doc);
136 
137  if (doc) {
139 
140  if (!m_Window->InitWidget(objects)) return false;
141 
142  x_AttachToProject(*doc);
144 
145  // When the Flat File view is focused on Nucleotides/All, the visible area
146  // is automatically updated to show the selected object.
147  // In other circumstances, this automatic update of the visible area does not take place
148  IProjectView* projectTextView = srv->FindView(*object, "Text View");
149  if (projectTextView) {
150  CTextPanel* panel = dynamic_cast<CTextPanel*>(projectTextView->GetWindow());
151  panel->GetWidget()->SetTrackSelection(true);
152  }
153 
154  return true;
155  }
156  return false;
157  } else {
158  // cannot represent the data
160  return false;
161  }
162 }
163 
165 {
168  }
169  else if (evt.GetSubtype() == CProjectViewEvent::eData ||
171  if (m_Window) m_Window->DataChanged();
172  }
173 }
174 
175 
177 {
178  _ASSERT(!m_Window);
179 
180  m_Window = new CSeqDesktopPanel(parent, wxID_ANY, wxDefaultPosition, wxSize(0, 0), wxTAB_TRAVERSAL | wxNO_BORDER);
181  m_Window->SetHost(this);
182  m_Window->GetWidget()->SetHost(this);
183 
185 }
186 
187 
189 {
190  if (m_Window) {
191  m_Window->GetWidget()->SetHost(nullptr);
192  m_Window->SetHost(nullptr);
193  m_Window->Destroy();
194  m_Window = nullptr;
195  }
196 }
197 
198 
200 {
201  return s_ViewTypeDescr;
202 }
203 
204 
206 {
207  if (!m_Window && !x_HasProject()) return;
208 
212 }
213 
214 
216 {
217  if (!m_Window && !x_HasProject()) return;
218 
219  CScope* scope = x_GetScope();
222  ITERATE(vector< CConstRef<CObject> >, it, objects)
223  objs.push_back(SConstScopedObject(*it, scope));
224 }
225 
226 
228 {
229  if (!m_Window && !x_HasProject()) return;
230 
231  m_Window->GetMainObjects(objs);
232 }
233 
235 {
236  if (!m_Window && !x_HasProject()) return;
237 
238  TConstObjects objs;
239  evt.GetAllObjects(objs);
240  evt.GetOther(objs);
242 }
243 
244 
246 {
247  return m_Window ? m_Window->GetOrigObject() : 0;
248 }
249 
250 /// IGuiWidgetHost implementation
251 
253 {
255  prjSrv->RemoveProjectView(*this);
256 }
257 
259 {
261  Send(&evt, ePool_Parent);
262 }
263 
265 {
266 }
267 
269 {
271  TConstScopedObjects scopedObjects;
272  sel_srv->GetCurrentSelection(scopedObjects);
273  ITERATE(TConstScopedObjects, it, scopedObjects)
274  objects.push_back(it->object);
275 }
276 
278 {
279 }
280 
281 void CSequinDesktopView::ShowView(const string& viewName, FWindowFactory widgetFactory, TConstScopedObjects& objects, bool bFloat)
282 {
283  if (objects.empty()) return;
285  prjSrv->ShowView(viewName, widgetFactory, objects, bFloat);
286 }
287 
289 {
290  CDesktopWidgetEvent* desktop_event(dynamic_cast<CDesktopWidgetEvent*>(evt));
291  if (!desktop_event) return;
292 
296 
297 }
298 
300 {
301  const CBioseq* bseq = dynamic_cast<const CBioseq*>(scoped_object.object.GetPointer());
302  const CSeqdesc* desc = dynamic_cast<const CSeqdesc*>(scoped_object.object.GetPointer());
303  const CSeq_feat* feat = dynamic_cast<const CSeq_feat*>(scoped_object.object.GetPointer());
304 
305  CBioseq_Handle bsh;
306  if (bseq) {
307  bsh = scoped_object.scope->GetBioseqHandle(*bseq);
308  }
309  else if (desc) {
310  CSeq_entry_Handle seh = edit::GetSeqEntryForSeqdesc(scoped_object.scope, *desc);
311  if (seh) {
312  if (seh.IsSeq()) {
313  bsh = seh.GetSeq();
314  }
315  else {
316  CBioseq_CI b_iter(seh, CSeq_inst::eMol_na);
317  if (b_iter) {
318  bsh = *b_iter;
319  }
320  }
321  }
322  }
323  else if (feat) {
324  bsh = GetBioseqForSeqFeat(*feat, *scoped_object.scope);
325  }
326 
327  return bsh;
328 }
329 
331 {
332  CDesktopWidgetEvent* desktop_event(dynamic_cast<CDesktopWidgetEvent*>(event));
333  if (!desktop_event) return;
334 
335  // get the flat file view
336 
338  _ASSERT(srv);
339 
340  TConstScopedObjects main_object;
341  GetMainObject(main_object);
342  if (main_object.empty()) {
343  return;
344  }
345  CIRef<IProjectView> text_view(srv->FindView(*(main_object.front().object), "Text View"));
346  if (!text_view) {
347  // don't open a new text view if there is not one already
348  return;
349  }
350 
351  CIRef<IFlatFileCtrl> FlatFileCtrl(dynamic_cast<IFlatFileCtrl*>(text_view.GetPointerOrNull()));
352  if (FlatFileCtrl) {
353  TConstScopedObjects objs;
354  GetSelection(objs);
355  if (!objs.empty()) {
356  try {
357  CBioseq_Handle bsh = s_GetAccession(objs.front());
358  FlatFileCtrl->SetPosition(bsh, objs.front().object.GetPointer());
359  }
360  catch (const CException&) {}
361  }
362  }
363 }
364 
365 ///////////////////////////////////////////////////////////////////////////////
366 /// CSequinDesktopViewFactory
368 {
369  static string sid("sequin_desktop_view_factory");
370  return sid;
371 }
372 
373 
375 {
376  static string slabel("Sequin Desktop View Factory");
377  return slabel;
378 }
379 
380 
382 {
383  string alias = GetViewTypeDescriptor().GetIconAlias();
384  provider.RegisterFileAlias(ToWxString(alias), wxT("text_view.png"));
385 }
386 
388 {
389 }
390 
392 {
393  return s_ViewTypeDescr;
394 }
395 
396 
398 {
399  return new CSequinDesktopView();
400 }
401 
402 
404 {
405  return NULL;
406 }
407 
408 
410 {
411  bool found_good = false;
412  bool found_bad = false;
413 
414  for( size_t i = 0; i < objects.size(); i++) {
415  const CSerialObject* so =
416  dynamic_cast<const CSerialObject*>(objects[i].object.GetPointer());
417  if (so
418  && (dynamic_cast<const CSeq_submit*>(so)
419  || dynamic_cast<const CSeq_entry*>(so)
420  || dynamic_cast<const CBioseq*>(so)
421  || dynamic_cast<const CBioseq_set*>(so)
422  || dynamic_cast<const CSeq_annot*>(so)
423  || dynamic_cast<const CSeq_id*>(so))) {
424  found_good = true;
425  }
426  else {
427  found_bad = true;
428  }
429  }
430 
431  if (found_good)
432  return fCanShowSeparated | (found_bad ? fCanShowSome : fCanShowAll);
433 
434  return 0; // can show nothing
435 }
436 
CSeq_entry_Handle GetSeqEntryForSeqdesc(CRef< CScope > scope, const CSeqdesc &seq_desc)
CBioseq_CI –.
Definition: bioseq_ci.hpp:69
CBioseq_Handle –.
void SetHost(IGuiWidgetHost *host)
CEvent - generic event implementation TODO TODO - Attachments.
Definition: event.hpp:86
CGBDocument.
Definition: document.hpp:113
CUndoManager & GetUndoManager()
Definition: document.hpp:158
CObject –.
Definition: ncbiobj.hpp:180
CProjectService - a service providing API for operations with Workspaces and Projects.
void RemoveProjectView(IProjectView &view)
removes the view from View manager Service and disconnects it from the project
virtual void x_ReportInvalidInputData(TConstScopedObjects &objects)
use this function to report incompatible data in InitView()
virtual void OnProjectChanged()
virtual void x_UpdateContentLabel()
virtual objects::CScope * x_GetScope() const
virtual void x_AttachToProject(CGBDocument &doc)
virtual bool x_HasProject() const
CProjectViewEvent.
Definition: document.hpp:62
EEventSubtype GetSubtype() const
Definition: document.hpp:96
CProjectViewTypeDescriptor - holds description of a project view type.
CProjectView.
CRef –.
Definition: ncbiobj.hpp:618
CScope –.
Definition: scope.hpp:92
CSelectionEvent CSelectionEvent is used for broadcasting selection between views.
Definition: obj_event.hpp:68
void GetAllObjects(TConstObjects &objs) const
Definition: obj_event.cpp:314
void GetOther(TConstObjects &objs) const
Definition: obj_event.cpp:338
bool AddObjectSelection(const CObject &obj)
Definition: obj_event.cpp:177
virtual bool InitWidget(TConstScopedObjects &objects)
virtual void DataChanged()
virtual void GetSelectedObjects(TConstObjects &objects) const
virtual void SetUndoManager(ICommandProccessor *cmdProccessor)
virtual void DataChanging()
CDesktopCanvas * GetWidget() const
virtual void SetHost(IGuiWidgetHost *host)
virtual const CObject * GetOrigObject() const
void GetMainObjects(TConstScopedObjects &objs) const
virtual void SetSelectedObjects(const TConstObjects &objects)
CSeq_entry_Handle –.
Definition: Seq_entry.hpp:56
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
CSequinDesktopView.
Base class for all serializable objects.
Definition: serialbase.hpp:150
void SetTrackSelection(bool trackSelection)
CTextItemPanel * GetWidget() const
Definition: text_panel.hpp:229
CUICommandRegistry is a centralized registry where all application commands should be registered.
Definition: ui_command.hpp:146
@ eWidgetSelectionChanged
a view has been destroyed
Definition: view_event.hpp:55
CViewTypeDescriptor - holds description of a view type.
Definition: view.hpp:98
virtual const CViewTypeDescriptor & GetViewTypeDescriptor() const
returns a Descriptor for the View Type supported by the Factory
class IProjectView defines the abstract interface for views observing projects.
IView - represents a standard visual part of Workbench UI.
Definition: view.hpp:73
CFingerprint identifies an instance of IWMClient and is used for labeling layout positions.
Definition: wm_client.hpp:58
virtual wxWindow * GetWindow()=0
returns a pointer to the wxWindow representing the client
virtual void RegisterFileAlias(const wxArtID &anId, const wxArtClient &aClient, const wxSize &aSize, const wxString &aName, long aType=wxBITMAP_TYPE_ANY, int anIndex=-1)
static const struct name_t names[]
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
virtual void GetCompatibleToolBars(vector< string > &names)
returns the names of toolbars compatible with this class (toolbars that are relevant and useful in th...
virtual const CObject * x_GetOrigObject() const
#define NULL
Definition: ncbistd.hpp:225
CIRef< T > GetServiceByType()
retrieves a typed reference to a service, the name of C++ type is used as the name of the service.
Definition: service.hpp:91
objects::CBioseq_Handle GetBioseqForSeqFeat(const objects::CSeq_feat &f, objects::CScope &scope)
virtual void DestroyViewWindow()
destroy Window corresponding to the view
virtual void RegisterIconAliases(wxFileArtProvider &provider)
called by the framework to give Factory a chance to register images used by view
virtual wxEvtHandler * GetCommandHandler()
IWMClient implementation.
void x_OnSingleMouseClick(CEvent *event)
Scrolls to the corresponding item in the Flat File View and selects it.
virtual int TestInputObjects(TConstScopedObjects &objects)
tests input objects (not using object conversion) and returns a combination of ETestResult flags bett...
virtual void WidgetActivated()
virtual string GetExtensionIdentifier() const
CSequinDesktopViewFactory.
virtual void ShowView(const string &viewName, FWindowFactory widgetFactory, TConstScopedObjects &objects, bool bFloat)
virtual bool InitView(TConstScopedObjects &objects, const objects::CUser_object *params)
initialize view with data, inside this function the view must call CProjectService::AttachView to con...
virtual void RegisterCommands(CUICommandRegistry &cmd_reg, wxFileArtProvider &provider)
called by the framework to give Factory a chance to register commands used by view
virtual void GetSelection(CSelectionEvent &evt) const
get selection for broadcasting
virtual const wxMenu * GetMenu()
returns a menu (must be deleted by the caller) menu injections should follow a separator named "Contr...
virtual void CreateViewWindow(wxWindow *parent)
create Window corresponding to the view
virtual void WidgetSelectionChanged()
virtual IView * CreateInstanceByFingerprint(const TFingerprint &fingerprint) const
if fingerprint is recognized - creates and returns a new instance
virtual void GetAppSelection(TConstObjects &objects)
virtual string GetExtensionLabel() const
returns a displayable label for this extension ( please capitalize the key words - "My Extension" )
virtual void CloseWidget()
IGuiWidgetHost implementation.
CSeqDesktopPanel * m_Window
virtual const CProjectViewTypeDescriptor & GetProjectViewTypeDescriptor() const
returns a Descriptor for the View Type supported by the Factory
virtual void GetMainObject(TConstScopedObjects &objs) const
Adds the main data objects represented by the client to "objects".
virtual wxWindow * GetWindow()
returns a pointer to the wxWindow representing the client
virtual const CViewTypeDescriptor & GetTypeDescriptor() const
return an object providing meta information about thei view type
void x_OnRefreshData(CEvent *event)
virtual void x_OnSetSelection(CSelectionEvent &evt)
override in derived classes in order to handle selection broadcast
virtual void OnWidgetCommand(const string &command)
virtual IView * CreateInstance() const
creates a view instance
CRef< objects::CScope > scope
Definition: objects.hpp:53
vector< CConstRef< CObject > > TConstObjects
Definition: objects.hpp:64
virtual const string & GetIconAlias() const
Definition: ui_object.cpp:130
#define ON_EVENT(type, id, handler)
#define END_EVENT_MAP()
Ends definition of Command Map.
CConstRef< CObject > object
Definition: objects.hpp:52
#define BEGIN_EVENT_MAP(thisClass, baseClass)
Begins definition of Command Map for CEventHandler-derived class.
virtual void AddListener(CEventHandler *listener, int pool_name=ePool_Default)
Add a listener.
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
TSeq GetSeq(void) const
bool IsSeq(void) const
TObjectType * GetPointer(void) const THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:1684
TObjectType * GetPointerOrNull(void) THROWS_NONE
Get pointer value.
Definition: ncbiobj.hpp:986
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
@ eMol_na
just a nucleic acid
Definition: Seq_inst_.hpp:113
wxWindow *(* FWindowFactory)(wxWindow *)
Definition: gui_widget.hpp:45
int i
void GetViewObjects(IWorkbench *workbench, TConstScopedObjects &objects)
#define wxT(x)
Definition: muParser.cpp:41
const char * command
@ eOneObjectAccepted
static static static wxID_ANY
USING_SCOPE(objects)
static CBioseq_Handle s_GetAccession(SConstScopedObject &scoped_object)
#define _ASSERT
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
Modified on Fri Sep 20 14:57:51 2024 by modify_doxy.py rev. 669887