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

Go to the SVN repository for this file.

1 /* $Id: open_view_manager_impl.cpp 45154 2020-06-09 18:35:34Z ivanov $
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: Liangshou Wu
27  *
28  * File Description:
29  */
30 
31 
32 #include <ncbi_pch.hpp>
33 
35 
36 #include <gui/objutils/utils.hpp>
37 #include <gui/objutils/label.hpp>
40 
41 #include <objmgr/util/sequence.hpp>
42 
47 
50 #include <objmgr/util/sequence.hpp>
51 #include <serial/typeinfo.hpp>
52 
53 #include <wx/statline.h>
54 #include <wx/valgen.h>
55 #include <wx/sizer.h>
56 #include <wx/stattext.h>
57 #include <wx/checkbox.h>
58 #include <wx/msgdlg.h>
59 #include <wx/bitmap.h>
60 #include <wx/icon.h>
61 
64 
65 /*
66 The main flow of opening view will be as follows.
67 
68 User selects some data and opens OpenViewDialog. This dialog
69 is filled with project view factories. Factory is able to test
70 input objects against its view, and also it can provide
71 OpenViewManager (separately), that is responsible for further
72 steps and pages for choosing particular objects to view.
73 
74 Currently all OpenViewManagers are the same.
75 
76 In the end of dialog there are "objects to show" and info about
77 how to combine them together (i.e., one more array with ints,
78 specifying what view to use; same numbers go to the same view).
79 
80 After that there is(are) a call(s) of AddProjectView() - it is
81 not clear where should be this call. Now it is ProjectService
82 method, it seems that it is better be ViewService method.
83 
84 It happens in COpenViewlDlgTask::x_Run().
85 
86 As for merging vs combining, Combining should be preferred.
87 So should the interface of OpenViewManager be changed.
88 
89 For now, combining step should be done automatically.
90 */
91 
92 
93 IMPLEMENT_DYNAMIC_CLASS( CParamsPanel, wxPanel )
94 
95 BEGIN_EVENT_TABLE( CParamsPanel, wxPanel )
96 
97 ////@begin CParamsPanel event table entries
99 
100 ////@end CParamsPanel event table entries
101 
103 
104 
106  : m_OneViewPerObject( false )
107 {
108 }
109 
110 bool CParamsPanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
111 {
112  return wxPanel::Create( parent, id, pos, size, style );
113 }
114 
116 {
117  return true;
118 }
119 
120 
121 wxBitmap CParamsPanel::GetBitmapResource( const wxString& name )
122 {
123  // Bitmap retrieval
124 ////@begin CParamsPanel bitmap retrieval
125  wxUnusedVar(name);
126  return wxNullBitmap;
127 ////@end CParamsPanel bitmap retrieval
128 }
129 
130 
131 wxIcon CParamsPanel::GetIconResource( const wxString& name )
132 {
133  // Icon retrieval
134 ////@begin CParamsPanel icon retrieval
135  wxUnusedVar(name);
136  return wxNullIcon;
137 ////@end CParamsPanel icon retrieval
138 }
139 
140 
141 void CParamsPanel::OnOneViewPerObjectClick( wxCommandEvent& event )
142 {
143  TransferDataFromWindow();
144 }
145 
147 {
148  m_ObjectMaps = objs;
149 }
150 
152 {
153  return !m_OneViewPerObject;
154 }
155 
156 
158 {
159  m_OneViewPerObject = true;
160  TransferDataToWindow();
161 }
162 
163 
164 void CParamsPanel::SetRegistryPath(const string& path)
165 {
166  m_RegPath = path;
167  //m_ListPanel->SetRegistryPath(m_RegPath + ".ObjectList");
168 }
169 
170 
171 static const char* kOneViewPerObject = "OneViewPerObject";
172 
174 {
175  if ( !m_RegPath.empty() ) {
177  CRegistryWriteView view = gui_reg.GetWriteView(m_RegPath);
179  //m_ListPanel->SaveSettings();
180  }
181 }
182 
183 
185 {
186  if ( !m_RegPath.empty() ) {
188  CRegistryReadView view = gui_reg.GetReadView(m_RegPath);
189 
191  //m_ListPanel->LoadSettings();
192  //TransferDataToWindow();
193  }
194 }
195 
196 
197 
198 
199 IMPLEMENT_DYNAMIC_CLASS( CConversionResultPanel, CParamsPanel )
200 
201 
202 BEGIN_EVENT_TABLE( CConversionResultPanel, CParamsPanel )
203 
204 ////@begin CParamsPanel event table entries
206 
207 ////@end CParamsPanel event table entries
208 
210 
212 {
213  /****** PUBLIC DEFINITION SECTION ******/
214 public:
216  : m_Factory( factory )
217  {}
218 
219  virtual void operator()( const TConstScopedObjects& objects,
220  TObjectsMap& objects_map ) const;
221 
222 private:
224 };
225 
227  TObjectsMap& objects_map
228 ) const {
229  if( m_Factory ){
230  m_Factory->CombineObjects( objects, objects_map );
231  }
232 }
233 
235 {
236  Init();
237 }
238 
239 
240 CConversionResultPanel::CConversionResultPanel( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
241 {
242  Init();
243  Create(parent, id, pos, size, style);
244 }
245 
246 
247 bool CConversionResultPanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
248 {
249  ////@begin CConversionResultPanel creation
250  CParamsPanel::Create( parent, id, pos, size, style );
251 
252  CreateControls();
253  if (GetSizer())
254  {
255  GetSizer()->SetSizeHints(this);
256  }
257  Centre();
258  ////@end CConversionResultPanel creation
259 
261  m_ListPanel->SetCombinator( comber );
262 
263  return true;
264 }
265 
267 {
268  ////@begin CConversionResultPanel member initialization
269  m_ListPanel = NULL;
270  m_GroupCtrl = NULL;
272  ////@end CConversionResultPanel member initialization
273 }
274 
275 
277 {
278  ////@begin CConversionResultPanel content construction
279  CConversionResultPanel* itemPanel1 = this;
280 
281  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
282  itemPanel1->SetSizer(itemBoxSizer2);
283 
284  m_ListPanel = new CObjectListWidgetSel( itemPanel1, wxID_ANY, wxDefaultPosition, wxSize(100, 100), 0 );
285  itemBoxSizer2->Add(m_ListPanel, 1, wxGROW|wxALL, 5);
286 
287  m_GroupCtrl = new CwxTableListCtrl( itemPanel1, wxID_ANY, wxDefaultPosition, wxSize(100, 100), 0 );
288  itemBoxSizer2->Add(m_GroupCtrl, 1, wxGROW|wxALL, 5);
289 
290  m_GroupCheckBox = new wxCheckBox( itemPanel1, ID_GROUPVIEW, _("Group objects by identifying sequences"), wxDefaultPosition, wxDefaultSize, 0 );
291  m_GroupCheckBox->SetValue(false);
292  itemBoxSizer2->Add(m_GroupCheckBox, 0, wxALIGN_LEFT|wxLEFT|wxBOTTOM, 5);
293 
294  m_OneViewPerObjectCheckBox = new wxCheckBox( itemPanel1, ID_ONEVIEWPEROBJECT, _("Open each object in a separate view"), wxDefaultPosition, wxDefaultSize, 0 );
295  m_OneViewPerObjectCheckBox->SetValue(true);
296  itemBoxSizer2->Add(m_OneViewPerObjectCheckBox, 0, wxALIGN_LEFT|wxLEFT|wxBOTTOM, 5);
297 
298  // Set validators
299  m_OneViewPerObjectCheckBox->SetValidator( wxGenericValidator(& m_OneViewPerObject) );
300  ////@end CConversionResultPanel content construction
301 
303  m_ListPanel->SetTitle(wxT("Converted objects"));
304 
305  m_GroupCheckBox->Hide();
306  m_GroupCtrl->Hide();
307 }
308 
309 void CConversionResultPanel::OnGroupViewClick( wxCommandEvent& event )
310 {
311  if( event.IsChecked() ){
312  m_ListPanel->Hide();
313  m_GroupCtrl->Show();
314  } else {
315  m_GroupCtrl->Hide();
316  m_ListPanel->Show();
317  }
318 
319  Layout();
320  Refresh();
321 }
322 
323 
325 {
327 }
328 
329 const char* kSelection = "Selection";
330 
332 {
333  CParamsPanel::SetObjects( objs );
334 
335  m_ListPanel->SetObjects( objs );
337 
338  // No need to do grouping for object type in seq-loc or seq-id.
339  // It is too slow for a large number of objects.
340  if (objs.begin()->second->GetNumRows() > 0) {
341  const CSerialObject* obj =
342  dynamic_cast<const CSerialObject*>(objs.begin()->second->GetObject(0));
343  if (obj && (obj->GetThisTypeInfo() == CSeq_id::GetTypeInfo() ||
344  obj->GetThisTypeInfo() == CSeq_loc::GetTypeInfo())) {
345  return;
346  }
347  }
348 
349  vector<wxString> columns;
350  columns.push_back( wxT("Objects/groups") );
351  columns.push_back( wxT("Type") );
352  columns.push_back( wxT("Description") );
353 
354  CTextTableModel* model = new CTextTableModel();
355 
356  m_Groups.clear();
357  m_GroupSize.clear();
358  m_LocHandles.clear();
359  m_AlnHandles.clear();
360 
362  if( m_ObjectMaps.size() == 1 ){
363  objects = m_ObjectMaps.begin()->second;
364  } else {
366  }
367 
368  size_t num_objects = objects->GetNumRows();
369 
370  m_Groups.resize( num_objects, -1 );
371  m_GroupSize.resize( 2*num_objects, 0 );
372 
373  vector<CScope*> loc_scopes, aln_scopes;
374 
375  map<CSeq_id_Handle, int> find_map;
376 
377  int num_simple = 0;
378  for( size_t ix = 0; ix < num_objects; ix++ ){
379 
380  const CObject* object = objects->GetObject((int)ix);
381  CScope* scope = objects->GetScope((int)ix);
382 
383  const CSeq_loc* loc = dynamic_cast<const CSeq_loc*>( object );
384  if( loc ){
385  CSeq_id_Handle idh = sequence::GetIdHandle( *loc, scope );
386  idh = sequence::GetId( idh, *scope, sequence::eGetId_Canonical );
387 
388 
390 // vector<CSeq_id_Handle>::iterator found =
391 // find( m_LocHandles.begin(), m_LocHandles.end(), idh )
392 // ;
393 // if( found != m_LocHandles.end() ){
394 // m_Groups[ix] = found - m_LocHandles.begin();
395  if( it != find_map.end() ){
396  m_Groups[ix] = it->second;
397  } else {
398  find_map[idh] = (int)m_LocHandles.size();
399  m_Groups[ix] = (int)m_LocHandles.size();
400  m_LocHandles.push_back( idh );
401  loc_scopes.push_back( scope );
402  }
403  m_GroupSize[ m_Groups[ix] ]++;
404 
405  continue;
406  }
407 
408  const CSeq_align* aln = dynamic_cast<const CSeq_align*>( object );
409  if( aln ){
410  int num_seqs = aln->CheckNumRows();
411  if( num_seqs <= 0 ){
412  continue;
413  }
414 
415  set<CSeq_id_Handle> idh_set;
416  for( int q = 0; q < num_seqs; q++ ){
417  const CSeq_id& seq_id = aln->GetSeq_id( q );
419  idh = sequence::GetId( idh, *scope, sequence::eGetId_Canonical );
420  idh_set.insert( idh );
421  }
422 
423  vector< set<CSeq_id_Handle> >::iterator found =
424  find( m_AlnHandles.begin(), m_AlnHandles.end(), idh_set )
425  ;
426  if( found != m_AlnHandles.end() ){
427  m_Groups[ix] = (int)(found - m_AlnHandles.begin() + num_objects);
428  } else {
429  m_Groups[ix] = (int)(m_AlnHandles.size() + num_objects);
430  m_AlnHandles.push_back( idh_set );
431  aln_scopes.push_back( scope );
432  }
433  m_GroupSize[ m_Groups[ix] ]++;
434 
435  continue;
436  }
437 
438  num_simple++;
439  }
440 
441  model->Init( columns, (int)(m_LocHandles.size() + m_AlnHandles.size() + num_simple) );
442 
443  int row = 0;
444  for( size_t ix = 0; ix < m_LocHandles.size(); ix++ ){
445  CSeq_id_Handle idh = sequence::GetId( m_LocHandles[ix], *loc_scopes[ix], sequence::eGetId_Best );
446  if ( !idh ) {
447  idh = m_LocHandles[ix];
448  }
449 
450  string label = idh.GetSeqId()->GetSeqIdString();
451  label += " ["
453  + " objects]"
454  ;
455 
456  model->SetStringValueAt( row++, 0, wxString::FromUTF8( label.c_str() ) );
457  }
458 
459  for( size_t ix = 0; ix < m_AlnHandles.size(); ix++ ){
460  const set<CSeq_id_Handle>& aln_set = m_AlnHandles[ix];
461 
462  string label;
463 
464  bool first = true;
465  ITERATE( set<CSeq_id_Handle>, aln_ir, aln_set ){
466  if( first ){
467  first = false;
468  } else {
469  label += " x ";
470  }
471 
472  CSeq_id_Handle idh = sequence::GetId( *aln_ir, *aln_scopes[ix], sequence::eGetId_Best );
473  if (!idh)
474  idh = *aln_ir;
475  label += idh.GetSeqId()->GetSeqIdString();
476  }
477  label += " ["
478  + NStr::IntToString( m_GroupSize[ix+num_objects], NStr::fWithCommas )
479  + " objects]"
480  ;
481 
482  model->SetStringValueAt( row++, 0, wxString::FromUTF8( label.c_str() ) );
483  }
484 
485  for( size_t ix = 0; ix < num_objects; ix++ ){
486  if( m_Groups[ix] < 0 ){
487  string label;
488 
489  CLabel::GetLabel( *objects->GetObject((int)ix), &label,
490  CLabel::eDefault, objects->GetScope((int)ix));
491 
492  model->SetStringValueAt( row++, 0, wxString::FromUTF8( label.c_str() ) );
493  //! Important: m_Groups contains -(row+1) index for objects alone.
494  m_Groups[ix] = -row;
495  }
496  }
497 
498  m_GroupCtrl->SetModel( model, true );
499  m_GroupCtrl->SetColumnWidth( 0, 250 );
500  m_GroupCtrl->TransferDataToWindow();
501 }
502 
504 {
506  return false;
507  }
508 
509  buf.clear();
510 
511  if( m_GroupCheckBox->IsChecked() ){
512 
514  if( m_ObjectMaps.size() == 1 ){
515  objects = m_ObjectMaps.begin()->second;
516  } else {
518  }
519 
520  size_t num_objects = objects->GetNumRows();
521 
522  vector<int> rows_selected;
523  m_GroupCtrl->GetDataRowsSelected( rows_selected );
524 
525  for( size_t row = 0; row < rows_selected.size(); row++ ){
526  int ix = rows_selected[row];
527 
528  if( ix < (int)m_LocHandles.size() ){
529  for( size_t i = 0; i < num_objects; i++ ){
530  if( m_Groups[i] == ix ){
532  s_obj(objects->GetObject((int)i), objects->GetScope((int)i));
533  buf.push_back(s_obj);
534  }
535  }
536 
537  continue;
538  }
539 
540  ix -= (int)m_LocHandles.size();
541 
542  if (ix < (int)m_AlnHandles.size()) {
543  for (size_t i = 0; i < num_objects; i++) {
544  if (int(m_Groups[i] - num_objects) == ix) {
546  s_obj(objects->GetObject((int)i), objects->GetScope((int)i));
547  buf.push_back(s_obj);
548  }
549  }
550 
551  continue;
552  }
553 
554  ix += (int)m_LocHandles.size();
555 
556  for( size_t i = 0; i < num_objects; i++ ){
557  if( m_Groups[i] == -(ix+1) ){
559  s_obj(objects->GetObject((int)i), objects->GetScope((int)i));
560  buf.push_back(s_obj);
561  }
562  }
563 
564  }
565 
566  } else {
567  if( m_ListPanel ){
569  }
570  }
571 
572  return ( ! buf.empty());
573 }
574 
576 {
577  buf.clear();
578 
579  if( m_GroupCheckBox->IsChecked() ){
580 
582  if( m_ObjectMaps.size() == 1 ){
583  objects = m_ObjectMaps.begin()->second;
584  } else {
586  }
587 
588  size_t num_objects = objects->GetNumRows();
589 
590  vector<int> rows_selected;
591  m_GroupCtrl->GetDataRowsSelected( rows_selected );
592 
593  for( size_t row = 0; row < rows_selected.size(); row++ ){
594  int ix = rows_selected[row];
595 
596  if( ix < (int)m_LocHandles.size() ){
597  for( size_t i = 0; i < num_objects; i++ ){
598  if( m_Groups[i] == ix ){
599  buf.push_back( m_Groups[i] );
600  }
601  }
602 
603  continue;
604  }
605 
606  ix -= (unsigned)m_LocHandles.size();
607 
608  if( ix < (int)m_AlnHandles.size() ){
609  for( size_t i = 0; i < num_objects; i++ ){
610  if( int(m_Groups[i] - num_objects) == ix ){
611  buf.push_back( m_Groups[i] );
612  }
613  }
614 
615  continue;
616  }
617 
618  // No need to process single objects
619  }
620  }
621 
622  return !buf.empty();
623 }
624 
625 
627 {
629 
630  m_OneViewPerObjectCheckBox->Disable();
631 }
632 
633 
635 {
637 
638  m_ListPanel->SetRegistryPath(m_RegPath + ".ObjectList");
639 }
640 
641 
643 {
645 
646  if (!m_RegPath.empty()) {
648  }
649 }
650 
651 
653 {
655 
656  if (!m_RegPath.empty()) {
658  }
659 }
660 
661 
663  : m_Factory( NULL )
664  , m_Descriptor( NULL )
665 {
666 }
667 
668 
670  : m_Factory( &factory )
671  , m_Descriptor( &factory.GetProjectViewTypeDescriptor() )
672 {
673 }
674 
676 {
677  m_Factory = factory;
678  m_Descriptor = factory ? &factory->GetProjectViewTypeDescriptor() : NULL;
679 }
680 
681 void COpenViewManager::SetParentWindow(wxWindow* parent)
682 {
683  m_ParentWindow = parent;
684 }
685 
687 {
688  m_State = eInvalid;
689  m_ParamPanel = NULL;
690 }
691 
693 {
694  // clear the panels
695  m_State = eInvalid;
696  m_ParamPanel = NULL;
697 
698  // clear the essential objects
699  m_InputObjects.clear();
700  m_OutputObjects.clear();
701  m_OutputIndices.clear();
702 }
703 
705 {
707 
708  m_OutputObjects.clear();
709  m_OutputIndices.clear();
710 }
711 
712 
714 {
715  return m_OutputObjects;
716 }
717 
718 const vector<int> COpenViewManager::GetOutputIndices() const
719 {
721  if( !m_Factory ) return vector<int>();
722 
723  if( !m_OutputIndices.empty() ){
724  return m_OutputIndices;
725  }
726 
727  if( mf_IsCombineRequested ){
729  }
730 
731  return m_OutputIndices;
732 }
733 
734 
736 {
737  if (m_State == eParams) {
738  return m_ParamPanel;
739  }
740  return NULL;
741 }
742 
743 
745 {
746  return (m_State == eParams);
747 }
748 
749 
751 {
752  return (m_State == eCompleted);
753 }
754 
755 
757 {
758  switch (m_State) {
759  case eInvalid:
760  return action == eNext;
761  case eParams:
762  return action == eNext || action == eBack;
763  case eCompleted:
764  return false; // nothing left to do
765  default:
766  _ASSERT(false);
767  return false;
768  }
769 }
770 
772 {
774  if (it != objects.end() && it->second->GetNumRows() == 1) return false;
775 
776  if( objects.size() > 1 ||
777  (objects.size() == 1 && objects.begin()->second->GetNumRows() > 1)) {
778  return true;
779 
780  } else if( objects.begin()->second->GetNumRows() == 1 ){
781  return false;
782 
783  } else {
784  NCBI_THROW( COVMException, eGroupErr, "Input objects are not suitable to be seen" );
785  }
786 }
787 
789 {
792 
793  return panel;
794 }
795 
797 {
799 }
800 
801 
803 {
804  if (m_ParamPanel) {
806  m_Descriptor->GetLabel() + ".ParamPanel");
808  }
809 }
810 
811 #define MAX_NUM_VIEWS_SAFE 10
812 
814 {
816  if(!m_Factory) return false;
817 
818  wxBusyCursor wait;
819 
820  if( m_State == eInvalid && action == eNext ){
821  // do conversion
822  TObjectListMap object_map;
823  x_DoConversion( object_map );
824 
825  if( object_map.empty() || object_map.begin()->second->GetNumRows() == 0 ){
826  wxMessageBox(
827  wxT("The selections can't be opened in the selected view!"),
828  wxT("Open View"), wxOK | wxICON_EXCLAMATION
829  );
830 
831  return false;
832  }
833 
834  try {
835  if( NeedParamsPanel( object_map ) ){
837  m_ParamPanel->Hide(); // to reduce flicker
840 
845  }
846 
847  m_ParamPanel->SetObjects( object_map );
848 
849  m_State = eParams;
850 
851  } else {
853  if (it == object_map.end()) it = object_map.begin();
854 
855  TObjectList objects = it->second;
856  int num_objects = objects->GetNumRows();
857  for( int idx = 0; idx < num_objects; ++idx ){
858  SConstScopedObject s_obj(objects->GetObject(idx), objects->GetScope(idx));
859  m_OutputObjects.push_back( s_obj );
860  }
861  mf_IsCombineRequested = true;
862 
863  FinalizeParams();
864  }
865 
866  } catch( COVMException& ){
867  wxMessageBox(
868  wxT("The input object is not compatible with the selected view."),
869  wxT("Open View"), wxOK | wxICON_EXCLAMATION
870  );
871  return false;
872 
873  } catch( CException& ex ){
874  wxMessageBox(
875  wxT("Particular kind of this input object is not supported:\n")
876  + ToWxString( ex.GetMsg() ),
877  wxT("Open View"), wxOK | wxICON_EXCLAMATION
878  );
879  return false;
880  }
881 
882  return true;
883 
884  } else if (m_State == eParams) {
885  if( action == eNext ){
887  wxMessageBox(
888  wxT("Please select at least one object."),
889  wxT("Open View"), wxOK | wxICON_EXCLAMATION
890  );
891  return false;
892  }
893 
895 
896  int num_groups = 0;
897  if( mf_IsCombineRequested ){
898  //vector<int> indices = GetOutputIndices();
900  NON_CONST_ITERATE( vector<int>, ix_trv, m_OutputIndices ){
901  vector<int>::iterator found = find( m_OutputIndices.begin(), ix_trv, *ix_trv );
902 
903  if( found == ix_trv ){
904  num_groups++;
905  }
906  }
907  } else {
908  num_groups = (unsigned)GetOutputObjects().size();
909  }
910 
911  if( num_groups > MAX_NUM_VIEWS_SAFE ){
912  string message = "You are about to open more than ";
914  message += " views at a time.\nAre you sure?";
915  if(
916  NcbiMessageBox( message, eDialog_OkCancel, eIcon_Exclamation, "Attention!" )
917  != eOK
918  ){
919  return false;
920  }
921  }
922 
924  FinalizeParams();
925 
926  return true;
927 
928  } else if( action == eBack ){
930  m_State = eInvalid;
931 
932  return true;
933  }
934  }
935 
936  _ASSERT(false);
937  return false;
938 }
939 
941 {
942  try {
943  GUI_AsyncExec([this, &objects](ICanceled& cancel) { this->DoAsyncConversion(objects, cancel); },
944  wxT("Doing object conversion..."));
945  }
946  NCBI_CATCH("COpenViewManager::x_DoConversion");
947 }
948 
949 
951  bool operator()(const CSeq_loc* loc1, const CSeq_loc* loc2) const
952  {
953  return loc1->Compare(*loc2) < 0;
954  }
955 };
956 
957 
959 {
960  const string target_type = m_Descriptor->GetPrimaryInputType();
961  set<const CObject*> obj_ptrs;
962  // special case for seq-loc
963  // make sure no two identical location are added
964  typedef set<const CSeq_loc*, SCompareSeqLoc> TLocPtrs;
965  typedef map<CSeq_id_Handle, TLocPtrs> TLocMap;
966  TLocMap loc_map;
967 
968  bool need_extra_col = m_InputObjects.size() == 1;
969  if (need_extra_col) {
970  const CSerialObject* obj =
971  dynamic_cast<const CSerialObject*>(m_InputObjects.front().object.GetPointer());
972  if (!obj || obj->GetThisTypeInfo() != CGC_Assembly::GetTypeInfo()){
973  need_extra_col = false;
974  }
975  }
976 
977  for (auto& i : m_InputObjects) {
978  if (cancel.IsCanceled()) return;
979 
980  const CObject* obj = i.object;
981  CScope* scope = const_cast<CScope*>(i.scope.GetPointer());
982  if (!scope || !obj) continue;
983 
984  if (m_Factory->IsCompatibleWith(*obj, *scope)) {
985  TObjectList& obj_list = objects[kSelection];
986  if (!obj_list) obj_list.Reset(new CObjectList);
987  obj_list->AddRow(const_cast<CObject*>(obj), scope);
988  obj_ptrs.insert(obj);
989 
990  const CSeq_loc* loc = dynamic_cast<const CSeq_loc*>(obj);
991  if (loc) {
992  CSeq_id_Handle idh = sequence::GetIdHandle(*loc, scope);
993  loc_map[idh].insert(loc);
994  }
995  }
996  }
997 
998 
999  for (auto& i : m_InputObjects) {
1000  if (cancel.IsCanceled()) return;
1001 
1002  const CObject* obj = i.object;
1003  CScope* scope = const_cast<CScope*>(i.scope.GetPointer());
1004  if (!scope || !obj) continue;
1005 
1007  CObjectConverter::FindRelations(*scope, *obj, target_type, relations);
1008 
1010  if (cancel.IsCanceled()) return;
1011 
1012  /// If there are more than one relation, the first one contains
1013  /// all the conversions, and the rest contain categorized
1014  /// conversions.
1015  if (relations.size() > 1 && itr == relations.begin()) continue;
1016 
1017  CRelation::TObjects converts;
1018  CRelation& rel = **itr;
1019  string relName = rel.GetProperty(target_type);
1020 
1021  CRelation::TObjects related;
1022  rel.GetRelated(*scope, *obj, related, CRelation::fConvert_NoExpensive, &cancel);
1023 
1024  converts.reserve(related.size());
1025  ITERATE( CRelation::TObjects, obj_iter, related ){
1026  if (cancel.IsCanceled()) return;
1027 
1028  const CObject* converted_obj = &obj_iter->GetObject();
1029 
1030  if( obj_ptrs.insert( converted_obj ).second ){
1031  bool valid = true;
1032  const CSeq_loc* loc = dynamic_cast<const CSeq_loc*>(converted_obj);
1033  if (loc) {
1034  CSeq_id_Handle idh = sequence::GetIdHandle(*loc, scope);
1035  if ( !loc_map[idh].insert(loc).second ) {
1036  valid = false;
1037  }
1038  }
1039 
1040  if(valid && m_Factory->IsCompatibleWith(*converted_obj, *scope)){
1041  converts.push_back(*obj_iter);
1042  }
1043  }
1044  }
1045 
1046  if( !converts.empty() ){
1047  TObjectList& obj_list = objects[relName];
1048  if ( !obj_list ) {
1049  obj_list.Reset(new CObjectList);
1050  if (need_extra_col) {
1051  obj_list->AddColumn( CObjectList::eString, "Chromosome" );
1052  }
1053  }
1054  ITERATE (CRelation::TObjects, obj_iter, converts) {
1055  int row_num = obj_list->AddRow(const_cast<CObject*>(obj_iter->GetObjectPtr()), scope);
1056  if (need_extra_col) {
1057  obj_list->SetString( 0, row_num, obj_iter->GetComment() );
1058  }
1059  }
1060  }
1061  }
1062  }
1063 }
1064 
1065 
1066 void COpenViewManager::SetRegistryPath(const string& path)
1067 {
1068  m_RegPath = path; // store for later use
1069 }
1070 
1071 
1073 {
1074  if( ! m_RegPath.empty()) {
1075  /// save conversion parameters
1076  if(m_ParamPanel) {
1078  }
1079  }
1080 }
1081 
1082 
1084 {
1085  if( ! m_RegPath.empty()) {
1086  /// save conversion parameters
1087  if(m_ParamPanel) {
1089  }
1090  }
1091 }
1092 
1094 
EVT_CHECKBOX(ID_CADJUSTFEATURES_CHECKBOX, CAdjustFeaturesForGaps::OnKnownUnknownSelected) EVT_CHECKBOX(ID_CADJUSTFEATURES_CHECKBOX1
std::invoke_result< _Fty, ICanceled & >::type GUI_AsyncExec(_Fty &&_Fnarg, const wxString &msg=wxT("Accessing network..."))
Definition: async_call.hpp:130
virtual void SaveSettings() const
virtual void SetObjects(const TObjectListMap &objs)
add your methods here
void OnGroupViewClick(wxCommandEvent &event)
vector< CSeq_id_Handle > m_LocHandles
IProjectViewFactory * m_PVFactory
void SetProjectViewFactory(IProjectViewFactory *factory)
vector< set< CSeq_id_Handle > > m_AlnHandles
virtual bool GetSelectedIndices(vector< int > &buf)
CObjectListWidgetSel * m_ListPanel
virtual void EnforceOneViewPerObject()
Force OneViewPerObject true, and lock it.
virtual void SetRegistryPath(const string &path)
virtual bool Create(wxWindow *parent, wxWindowID id=ID_CCONVERSIONRESULTPANEL, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxNO_BORDER|wxTAB_TRAVERSAL)
virtual bool GetSelection(TConstScopedObjects &buf)
Return the selected item.
CRegistryWriteView GetWriteView(const string &section)
get a read-write view at a particular level.
Definition: registry.cpp:462
static CGuiRegistry & GetInstance()
access the application-wide singleton
Definition: registry.cpp:400
CRegistryReadView GetReadView(const string &section) const
get a read-only view at a particular level.
Definition: registry.cpp:428
vector< TRelation > TRelationVector
static void FindRelations(objects::CScope &scope, const CObject &obj, const string &to_type_in, TRelationVector &relations)
virtual void SetRegistryPath(const string &path)
IRegSettings.
TConstScopedObjects GetSelection() const
void SetAccessionValidator(IObjectListAccValidator *validator)
void SetObjects(const TObjectListMap &value)
void SetCombinator(CIRef< IObjectCombinator > value)
virtual bool TransferDataFromWindow()
Transfer data from the window.
void SetTitle(const wxString &value)
virtual bool TransferDataToWindow()
Transfer data to the window.
virtual void SaveSettings() const
CObjectList Data structure representing a list of CObjects with associated Scopes and other optional ...
Definition: object_list.hpp:63
int AddRow(CObject *obj, objects::CScope *scope)
void SetString(int col, int row, const string &val)
int AddColumn(EColumnType type, const string &name, int col=-1)
CObject –.
Definition: ncbiobj.hpp:180
virtual bool CanDo(EAction action)
indicates whether a transition (action) is possible
const CProjectViewTypeDescriptor * m_Descriptor
virtual void SetInputObjects(const TConstScopedObjects &input)
Set input objects that serve as original user input data.
virtual bool AtFinalStep()
true if state is Final (i.e. "Finish" button shall be shown instead of "Next")
virtual void CleanUI()
clean UI objects associated with the Manager
virtual const TConstScopedObjects & GetOutputObjects() const
Return the final input objects for views after possible object conversions and object aggregation.
virtual void SetParentWindow(wxWindow *parent)
virtual bool IsCompletedState()
true if data gathering has finished and Open dialog shall be closed
IProjectViewFactory * m_Factory
CParamsPanel * m_ParamPanel
The GUI panel listing the parameters guiding the object conversion and the conversion results.
void SetProjectViewFactory(IProjectViewFactory *factory)
void x_DoConversion(TObjectListMap &objects)
virtual bool NeedParamsPanel(const TObjectListMap &objects)
void DoAsyncConversion(TObjectListMap &objects, ICanceled &cancel)
virtual const vector< int > GetOutputIndices() const
virtual CParamsPanel * CreateParamsPanel()
virtual void SaveSettings() const
virtual wxPanel * GetCurrentPanel()
return the panel corresponding to the current state the function may create a new panel or return a p...
virtual bool DoTransition(EAction action)
perform transition if possible and returns true, otherwise the function shall warn the user about the...
virtual void InitUI()
initialize the Manager before using in UI (set it to Initial state)
TConstScopedObjects m_InputObjects
objects that serve as input arguments for the object converter
TConstScopedObjects m_OutputObjects
The output objects after view-specific object conversion and possible object aggregation.
virtual void SetRegistryPath(const string &path)
CPVFactoryCombinator(IProjectViewFactory *factory)
virtual void operator()(const TConstScopedObjects &objects, TObjectsMap &objects_map) const
IProjectViewFactory * m_Factory
virtual bool IsCombineRequested() const
virtual bool GetSelectedObjects(TConstScopedObjects &buf)
TObjectListMap m_ObjectMaps
virtual void SelectAll()
void OnOneViewPerObjectClick(wxCommandEvent &event)
virtual bool GetSelectedIndices(vector< int > &buf)
wxBitmap GetBitmapResource(const wxString &name)
virtual void SetObjects(const TObjectListMap &objs)
add your methods here
virtual void LoadSettings()
virtual void SaveSettings() const
static bool ShowToolTips()
wxIcon GetIconResource(const wxString &name)
virtual void SetRegistryPath(const string &path)
virtual void EnforceOneViewPerObject()
Force OneViewPerObject true, and lock it.
virtual bool Create(wxWindow *parent, wxWindowID id=ID_CPARAMSPANEL, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxNO_BORDER|wxTAB_TRAVERSAL)
const string GetPrimaryInputType() const
EPVObjectsAccepted GetObjectsAccepted() const
class CRegistryReadView provides a nested hierarchical view at a particular key.
Definition: reg_view.hpp:58
bool GetBool(const string &key, bool default_val=false) const
Definition: reg_view.cpp:241
void Set(const string &key, int val)
access a named key at this level, with no recursion
Definition: reg_view.cpp:533
vector< SObject > TObjects
Definition: relation.hpp:130
virtual string GetProperty(const string &) const
Definition: relation.hpp:145
virtual void GetRelated(objects::CScope &scope, const CObject &obj, TObjects &related, TFlags flags=eDefault, ICanceled *cancel=NULL) const =0
@ fConvert_NoExpensive
do not perform any expensive tests (such as fetching from the network)
Definition: relation.hpp:60
CScope –.
Definition: scope.hpp:92
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
Base class for all serializable objects.
Definition: serialbase.hpp:150
CwxTextTableModel - very simple model for storing SMALL numbers fo strings.
virtual void Init(int n_cols, int n_rows)
virtual void SetStringValueAt(int row, int col, const wxString &value)
CwxTableListCtrl - generic wxListCtrl-based Table Control.
wxArrayInt GetDataRowsSelected() const
void SetModel(IwxTableModel *data_model, bool own=false)
Interface for testing cancellation request in a long lasting operation.
Definition: icanceled.hpp:51
IProjectViewFactory.
virtual bool IsCompatibleWith(const CObject &object, objects::CScope &scope)
virtual vector< int > CombineInputObjects(const TConstScopedObjects &objects)
virtual const CProjectViewTypeDescriptor & GetProjectViewTypeDescriptor() const =0
returns a Descriptor for the View Type supported by the Factory
virtual void CombineObjects(const TConstScopedObjects &objects, TObjectsMap &objects_map)
size_type size() const
Definition: map.hpp:148
const_iterator begin() const
Definition: map.hpp:151
const_iterator end() const
Definition: map.hpp:152
bool empty() const
Definition: map.hpp:149
const_iterator find(const key_type &key) const
Definition: map.hpp:153
Definition: set.hpp:45
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
#define _(proto)
Definition: ct_nlmzip_i.h:78
#define false
Definition: bool.h:36
static DLIST_TYPE *DLIST_NAME() first(DLIST_LIST_TYPE *list)
Definition: dlist.tmpl.h:46
static const column_t columns[]
Definition: utf8_2.c:22
#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
#define NULL
Definition: ncbistd.hpp:225
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:704
#define NCBI_CATCH(message)
Catch CExceptions as well This macro is deprecated - use *_X or *_XX variant instead of it.
Definition: ncbiexpt.hpp:580
const string & GetMsg(void) const
Get message string.
Definition: ncbiexpt.cpp:461
static void GetLabel(const CObject &obj, string *label, ELabelType type=eDefault)
Definition: label.cpp:140
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
virtual const string & GetLabel() const
Definition: ui_object.cpp:124
vector< SConstScopedObject > TConstScopedObjects
Definition: objects.hpp:65
@ eDefault
Definition: label.hpp:73
virtual const CTypeInfo * GetThisTypeInfo(void) const =0
string GetSeqIdString(bool with_version=false) const
Return seqid string with optional version for text seqid type.
Definition: Seq_id.cpp:2145
CConstRef< CSeq_id > GetSeqId(void) const
static CSeq_id_Handle GetHandle(const CSeq_id &id)
Normal way of getting a handle, works for any seq-id.
int Compare(const CSeq_loc &loc) const
Definition: Seq_loc.cpp:590
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,...
CSeq_id_Handle GetIdHandle(const CSeq_loc &loc, CScope *scope)
@ 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
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
virtual bool IsCanceled(void) const =0
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5084
@ fWithCommas
Use commas as thousands separator.
Definition: ncbistr.hpp:254
static const char label[]
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
@ eIcon_Exclamation
Definition: types.hpp:65
@ eOK
Definition: types.hpp:74
@ eDialog_OkCancel
Definition: types.hpp:48
END_EVENT_TABLE()
char * buf
static int input()
int i
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
USING_SCOPE(objects)
#define MAX_NUM_VIEWS_SAFE
static const char * kOneViewPerObject
const char * kSelection
@ eAnyObjectsAccepted
@ eOneObjectAccepted
static static static wxID_ANY
#define row(bind, expected)
Definition: string_bind.c:73
bool operator()(const CSeq_loc *loc1, const CSeq_loc *loc2) const
#define _ASSERT
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
Modified on Tue Apr 23 07:37:37 2024 by modify_doxy.py rev. 669887