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

Go to the SVN repository for this file.

1 /* $Id: edit_table_views.cpp 47479 2023-05-02 13:24:02Z ucko $
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>
33 
34 #include "edit_table_views.hpp"
35 
37 #include <gui/core/document.hpp>
38 
42 
43 #include <wx/grid.h>
44 #include <wx/msgdlg.h>
45 
53 
57 
58 #include <gui/objutils/utils.hpp>
63 
65 
66 // for SaveData
68 
70 
71 #include <objmgr/util/sequence.hpp>
72 #include <gui/objutils/label.hpp>
73 
76 
81 
82 void CTableViewWithTextViewNav::DestroyViewWindow()
83 {
84  if( m_Window ){
85  m_Window->Destroy();
86  m_Window = 0;
87  }
88 }
89 
91 {
92  if (params) {
94  m_Params->Assign(*params);
95  } else {
97  }
98 }
99 
100 bool CTableViewWithTextViewNav::InitView(TConstScopedObjects& objects, const objects::CUser_object* params)
101 {
102  SetParams(params);
104 
106  _ASSERT(srv);
107 
108  CRef<CGBWorkspace> ws = srv->GetGBWorkspace();
109  if (!ws) return false;
110 
111  CScope* scope = m_OrigObjects.front().scope;
112 
113  CGBDocument* doc = dynamic_cast<CGBDocument*>(ws->GetProjectFromScope(*scope));
114  _ASSERT(doc);
115  if (doc) {
116  x_LoadData();
117  x_AttachToProject(*doc);
119 
120  IProjectView* projectTextView = srv->FindView(*m_OrigObjects.front().object, "Text View");
121  if(projectTextView) {
122  CTextPanel* panel = dynamic_cast<CTextPanel*>(projectTextView->GetWindow());
123  panel->GetWidget()->SetTrackSelection(true);
124  }
125  return true;
126  }
127 
129  return false;
130 }
131 
133 {
134  if (evt.GetSubtype() == CProjectViewEvent::eData ||
136  m_Window->Refresh();
137  }
138 }
139 
141 {
142  if (m_Window && x_HasProject()) {
144 
145  TConstScopedObjects sobjs;
146  grid->GetSelectedObjects (sobjs);
147 
148  TConstObjects objs;
149  ITERATE(TConstScopedObjects, it, sobjs) {
150  objs.push_back(it->object);
151  }
152 
153  evt.AddObjectSelection(objs);
154  }
155 }
156 
157 
159 {
160  if (m_Window && x_HasProject()) {
162  grid->GetSelectedObjects (objs);
163  }
164 }
165 
166 
168 {
169  if (m_Window && x_HasProject()) {
170  /*CGridWidget* grid = (CGridWidget*)m_Window;*/
171 
172  if(m_OrigObjects.size() > 0) {
173  const SConstScopedObject& ScopedObject(m_OrigObjects[0]);
174  const CObject* object = ScopedObject.object.GetPointer();
175  if (object) {
176  CScope* scope(const_cast<CScope*>(ScopedObject.scope.GetPointer()));
177  objs.push_back(SConstScopedObject(object, scope));
178  }
179  }
180  }
181 }
182 
183 // override function to suppress Navigation toolbar
185 {
187 }
188 
190 {
191  if(m_OrigObjects.size() > 0) {
192  return m_OrigObjects[0].object.GetPointer();
193  }
194 
195  return NULL;
196 }
197 
198 void CTableViewWithTextViewNav::SetRegistryPath(const string& reg_path)
199 {
200  IRegSettings* reg_set = dynamic_cast<IRegSettings*>(m_Window);
201  if (reg_set)
202  reg_set->SetRegistryPath(reg_path);
203 }
204 
206 {
207  IRegSettings* reg_set = dynamic_cast<IRegSettings*>(m_Window);
208  if (reg_set)
209  reg_set->LoadSettings();
210 }
211 
212 
214 {
215  IRegSettings* reg_set = dynamic_cast<IRegSettings*>(m_Window);
216  if (reg_set)
217  reg_set->SaveSettings();
218 }
219 
221 {
222  CGridWidgetEvent* tableEvt(dynamic_cast<CGridWidgetEvent*>(evt));
223  if (!tableEvt) return;
225  x_LoadData();
226 }
227 
229 {
231 
233 
234  if (!objects.empty()) {
236  }
237 }
238 
240 {
241  CQueryPanelEvent* queryEvt = dynamic_cast<CQueryPanelEvent*>(evt);
242  if (!queryEvt) return;
243 
245  sb_srv->SetStatusMessage(queryEvt->GetStatus());
246 }
247 
248 static const string sTextViewType("Text View");
249 
251 {
252  CRef<CUser_object> params(new CUser_object());
254  type->SetStr("TextViewParams");
255  params->SetType(*type);
256 
257  CUser_object::TData& data = params->SetData();
258 
259  {{
260  CRef<CUser_field> param(new CUser_field());
262  label->SetStr("TextViewType");
263  param->SetLabel(*label);
264  param->SetData().SetStr("Flat File");
265  data.push_back(param);
266  }}
267 
268  {{
269  CRef<CUser_field> param(new CUser_field());
271  label->SetStr("ExpandAll");
272  param->SetLabel(*label);
273  param->SetData().SetBool(true);
274  data.push_back(param);
275  }}
276 
277  {{
278  CRef<CUser_field> param(new CUser_field());
280  label->SetStr("TrackSelection");
281  param->SetLabel(*label);
282  param->SetData().SetBool(true);
283  data.push_back(param);
284  }}
285 
286  CIRef<IProjectView> prj_view = prjSrv->AddProjectView(sTextViewType, objects, params);
287  return prj_view;
288 }
289 
290 
292 {
293  CIRef<IFlatFileCtrl> FlatFileCtrl;
294 
296  CIRef<IProjectView> pTextView(prjSrv->FindView(*(objects.front().object), sTextViewType));
297  if (!pTextView) {
298  pTextView = x_CreateDefaultTextView(prjSrv, objects);
299  }
300 
301  FlatFileCtrl.Reset(dynamic_cast<IFlatFileCtrl*>(pTextView.GetPointerOrNull()));
302 
303  return FlatFileCtrl;
304 }
305 
306 
308 {
309  if (objects.size() == 0) return NULL;
311  if (!srv) return NULL;
312 
313  CRef<CGBWorkspace> ws = srv->GetGBWorkspace();
314  if (!ws) return NULL;
315 
316  CGBDocument* doc = dynamic_cast<CGBDocument*>(ws->GetProjectFromScope(*(objects.front().scope)));
317  if (doc) {
318  return &doc->GetUndoManager();
319  } else {
320  return NULL;
321  }
322 }
323 
324 
326 {
328  if (!seh) {
329  return false;
330  }
331 
332  const CSeq_feat *feat = dynamic_cast<const CSeq_feat *>(obj.object.GetPointer());
333  const CSeqdesc *desc = dynamic_cast<const CSeqdesc *>(obj.object.GetPointer());
334  if (feat || desc) {
335  return true;
336  } else {
337  return false;
338  }
339 }
340 
341 
343 {
345  objects.push_back(obj);
346  ICommandProccessor* cmd_processor = x_GetCmdProcessor(objects);
347 
348  const CSeq_align *align = dynamic_cast<const CSeq_align *>(obj.object.GetPointer());
349  if (align)
350  {
351  CRef<objects::CScope> scope = obj.scope;
352  CSeq_entry_Handle seh;
353  int num_rows = align->CheckNumRows();
354  for (size_t row = 0; row < num_rows; row++)
355  {
356  const CSeq_id& id = align->GetSeq_id(static_cast<CSeq_table::TNum_rows>(row));
357  CBioseq_Handle bsh = scope->GetBioseqHandle(id);
358  if (bsh)
359  {
360  seh = bsh.GetTopLevelEntry();
361  if (seh)
362  break;
363  }
364  }
365  CAlignmentAssistant *dlg = NULL;
366  try
367  {
368  dlg = new CAlignmentAssistant( m_Window, seh, cmd_processor, ConstRef(align));
369  dlg->Show(true);
370  } catch (CException&)
371  {
372  if (dlg)
373  dlg->Destroy();
374  wxMessageBox(wxT("Unable to load the alignment"), wxT("Error"), wxOK | wxICON_ERROR);
375  }
376  return;
377  }
378 
379  if (!IsEditable(obj)) {
380  return;
381  }
383 
384  CIRef<IEditObject> editor = CreateEditorForObject(obj.object, seh, false);
385  CEditObjViewDlg* edit_dlg = new CEditObjViewDlg(NULL, false);
386  edit_dlg->SetUndoManager(cmd_processor);
387  wxWindow* editorWindow = editor->CreateWindow(edit_dlg);
388  editorWindow->TransferDataToWindow();
389  edit_dlg->SetEditorWindow(editorWindow);
390  edit_dlg->SetEditor(editor);
391  editorWindow->GetParent()->CenterOnParent();
392  edit_dlg->Show(true);
393 }
394 
395 
397  const TConstScopedObjects& objects, TObjectsMap& objects_map
398 ){
399  typedef map<vector<CSeq_id_Handle>, TConstScopedObjects> TIdsToObjectsMap;
400  TIdsToObjectsMap handle_groups;
401 
403 
404  CConstRef<CObject> object = obtr->object;
405  CRef<CScope> scope = obtr->scope;
406 
407  if( object.IsNull() || scope.IsNull() ){
408  continue;
409  }
410 
411  vector<CSeq_id_Handle> idh_vec;
412 
413  const CSeq_id* id = dynamic_cast<const CSeq_id*>( &*object );
414  if( id ){
416  idh_vec.push_back( idh ? idh : CSeq_id_Handle::GetHandle( *id ) );
417  }
418 
419  const CSeq_loc* loc = dynamic_cast<const CSeq_loc*>( &*object );
420  if( loc ){
421  //! If loc is mix, we need to iterate ids
422  const CSeq_id& seq_id = *loc->GetId();
424  idh_vec.push_back( idh ? idh : CSeq_id_Handle::GetHandle( seq_id ) );
425  }
426 
427  const CSeq_align* aln = dynamic_cast<const CSeq_align*>( &*object );
428  if( aln ){
429  int num_seqs = aln->CheckNumRows();
430  if( num_seqs <= 0 ){
431  continue;
432  }
433 
434  set<CSeq_id_Handle> idh_set;
435  for( int seqix = 0; seqix < num_seqs; seqix++ ){
436  const CSeq_id& seq_id = aln->GetSeq_id( seqix );
438  idh_set.insert( idh ? idh : CSeq_id_Handle::GetHandle( seq_id ) );
439  }
440 
441  ITERATE( set<CSeq_id_Handle>, idh_itr, idh_set ){
442  idh_vec.push_back( *idh_itr );
443  }
444 
445  if( idh_vec.size() == 1 ){
446  idh_vec.push_back( idh_vec.front() );
447  }
448  }
449 
450 
451  handle_groups[idh_vec].push_back( *obtr );
452  }
453 
454  objects_map.clear();
455  NON_CONST_ITERATE( TIdsToObjectsMap, sidhtr, handle_groups ){
456  const vector<CSeq_id_Handle>& idh_vec = sidhtr->first;
457  TConstScopedObjects& group = sidhtr->second;
458 
459  string label;
460 
461  bool comma = false;
462  ITERATE( vector<CSeq_id_Handle>, idhtr, idh_vec ){
463  if( comma ){
464  label += " x ";
465  } else {
466  comma = true;
467  }
468 
469  CSeq_id_Handle idh = sequence::GetId( *idhtr, *group[0].scope, sequence::eGetId_Best );
470  label += (idh ? idh : *idhtr).GetSeqId()->GetSeqIdString( true );
471  }
472 
473  if( !label.empty() ){
474  objects_map[label] = group;
475 
476  } else {
477  NON_CONST_ITERATE( TConstScopedObjects, scobtr, group ){
478  TConstScopedObjects single;
479  single.push_back( *scobtr );
480 
481  CLabel::GetLabel( *scobtr->object, &label, CLabel::eContent, scobtr->scope );
482 
483  objects_map[label].push_back( *scobtr );
484  label.clear();
485  }
486  }
487  }
488 }
489 
CIRef< IEditObject > CreateEditorForObject(CConstRef< CObject > obj, objects::CSeq_entry_Handle seh, bool create)
CBioseq_Handle –.
void SetEditorWindow(wxWindow *editorWindow)
void SetEditor(CIRef< IEditObject > editor)
virtual void SetUndoManager(ICommandProccessor *cmdProccessor)
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.
virtual void x_ReportInvalidInputData(TConstScopedObjects &objects)
use this function to report incompatible data in InitView()
virtual void OnProjectChanged()
virtual void x_UpdateContentLabel()
virtual void x_AttachToProject(CGBDocument &doc)
virtual bool x_HasProject() const
CProjectViewEvent.
Definition: document.hpp:62
EEventSubtype GetSubtype() const
Definition: document.hpp:96
CProjectView.
const string & GetStatus() const
CRef –.
Definition: ncbiobj.hpp:618
CScope –.
Definition: scope.hpp:92
CSelectionEvent CSelectionEvent is used for broadcasting selection between views.
Definition: obj_event.hpp:68
bool AddObjectSelection(const CObject &obj)
Definition: obj_event.cpp:177
TDim CheckNumRows(void) const
Validatiors.
Definition: Seq_align.cpp:73
const CSeq_id & GetSeq_id(TDim row) const
Get seq-id (the first one if segments have different ids).
Definition: Seq_align.cpp:317
CSeq_entry_Handle –.
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
CRef< objects::CUser_object > m_Params
static void CombineObjects(const TConstScopedObjects &objects, TObjectsMap &objects_map)
void x_EditObject(SConstScopedObject &obj)
CIRef< IProjectView > x_CreateDefaultTextView(CIRef< CProjectService > prjSrv, TConstScopedObjects &objects)
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 GetMainObject(TConstScopedObjects &objs) const
Adds the main data objects represented by the client to "objects".
CIRef< IFlatFileCtrl > x_GetFlatFileCtrl(TConstScopedObjects &objects)
virtual void GetSelection(CSelectionEvent &evt) const
get selection for broadcasting
void SetParams(const objects::CUser_object *params)
virtual void x_LoadData()=0
ICommandProccessor * x_GetCmdProcessor(TConstScopedObjects &objects)
TConstScopedObjects m_OrigObjects
void x_OnRefreshData(CEvent *evt)
virtual void SetRegistryPath(const string &reg_path)
virtual void SaveSettings() const
void x_QueryStatusChange(CEvent *evt)
void SetTrackSelection(bool trackSelection)
CTextItemPanel * GetWidget() const
Definition: text_panel.hpp:229
Undo/Redo interface for editing operations.
class IProjectView defines the abstract interface for views observing projects.
IRegSettings An interface for objects that save / restore settings using CGuiRegistry.
virtual void SaveSettings() const =0
virtual void LoadSettings()=0
virtual void SetRegistryPath(const string &path)=0
virtual wxWindow * GetWindow()=0
returns a pointer to the wxWindow representing the client
void clear()
Definition: map.hpp:169
Definition: set.hpp:45
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
static const struct name_t names[]
USING_SCOPE(objects)
bool IsEditable(SConstScopedObject &obj)
static const string sTextViewType("Text View")
static int type
Definition: getdata.c:31
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
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::CSeq_entry_Handle GetTopSeqEntryFromScopedObject(SConstScopedObject &obj)
Definition: utils.cpp:2542
static void GetLabel(const CObject &obj, string *label, ELabelType type=eDefault)
Definition: label.cpp:140
CRef< objects::CScope > scope
Definition: objects.hpp:53
vector< CConstRef< CObject > > TConstObjects
Definition: objects.hpp:64
#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.
vector< SConstScopedObject > TConstScopedObjects
Definition: objects.hpp:65
@ eContent
Definition: label.hpp:62
static CSeq_id_Handle GetHandle(const CSeq_id &id)
Normal way of getting a handle, works for any seq-id.
const CSeq_id * GetId(void) const
Get the id of the location return NULL if has multiple ids or no id at all.
Definition: Seq_loc.hpp:941
const CSeq_id & GetId(const CSeq_loc &loc, CScope *scope)
If all CSeq_ids embedded in CSeq_loc refer to the same CBioseq, returns the first CSeq_id found,...
@ eGetId_Best
return the "best" gi (uses FindBestScore(), with CSeq_id::CalculateScore() as the score function
Definition: sequence.hpp:101
@ eGetId_Canonical
Definition: sequence.hpp:114
CSeq_entry_Handle GetTopLevelEntry(void) const
Get top level Seq-entry handle.
TObjectType * GetPointer(void) const THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:1684
CConstRef< C > ConstRef(const C *object)
Template function for conversion of const object pointer to CConstRef.
Definition: ncbiobj.hpp:2024
TObjectType * GetPointer(void) THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:998
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
bool IsNull(void) const THROWS_NONE
Check if pointer is null – same effect as Empty().
Definition: ncbiobj.hpp:735
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static const char label[]
TData & SetData(void)
Assign a value to Data data member.
void SetLabel(TLabel &value)
Assign a value to Label data member.
void SetType(TType &value)
Assign a value to Type data member.
void SetData(TData &value)
Assign a value to Data data member.
vector< CRef< CUser_field > > TData
void GetViewObjects(IWorkbench *workbench, TConstScopedObjects &objects)
#define wxT(x)
Definition: muParser.cpp:41
static bool GetSeqId(const T &d, set< string > &labels, const string name="", bool detect=false, bool found=false)
Definition: type.c:6
#define _ASSERT
Modified on Mon Mar 04 05:12:32 2024 by modify_doxy.py rev. 669887