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

Go to the SVN repository for this file.

1 /* $Id: graphic_panel.cpp 47034 2022-05-23 19:56:10Z 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
27 *
28 * File Description:
29 *
30 */
31 
32 #include <ncbi_pch.hpp>
33 
34 #include <wx/choice.h>
35 #include <wx/time.h>
36 #include <wx/menuitem.h>
37 
46 
49 
50 BEGIN_EVENT_TABLE(CGraphicPanel, wxPanel)
51  EVT_CHOICE(ID_TB_AssemblyList, CGraphicPanel::OnAssemblySelected)
54  EVT_TIMER(-1, CGraphicPanel::OnTimer)
55  EVT_TEXT_ENTER( ID_TB_SearchTerm, CGraphicPanel::OnSearchTermCtrlEnter )
56  EVT_MENU( ID_TB_SearchButton, CGraphicPanel::OnFindNextClick )
58 
59 static const wxChar* pszMainToolbar = wxT("Main Toolbar");
60 
61 CGraphicPanel::CGraphicPanel(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style)
62  : m_Timer(this), m_AssemblyLoaded(false)
63 {
64  Init();
65  Create(parent, id, pos, size, style);
66  CreateControls();
67 }
68 
70 {
71  m_AuiManager.UnInit();
72 }
73 
75 {
76  m_SeqWidget = 0;
77  m_FindTextCtrl = nullptr;
78  m_FindModeCtrl = nullptr;
79 }
80 
82 {
83  Hide();
84 
85  m_AuiManager.SetManagedWindow(this);
86 
89  m_AuiManager.AddPane(m_SeqWidget, wxAuiPaneInfo().CenterPane());
90 }
91 
93 {
94  if (!x_CheckLoaded())
95  m_Timer.Start(500);
96 
98 }
99 
100 bool CGraphicPanel::ProcessEvent(wxEvent &event)
101 {
102  if (event.IsCommandEvent()) {
103  wxEventType type = event.GetEventType();
104  if (type == wxEVT_UPDATE_UI || type == wxEVT_COMMAND_MENU_SELECTED) {
105  wxEvtHandler* evtHandler = 0;
106  if (m_SeqWidget) evtHandler = m_SeqWidget->GetEventHandler();
107  if (evtHandler && evtHandler->ProcessEventLocally(event))
108  return true;
109  }
110  }
111  return wxPanel::ProcessEvent(event);
112 }
113 
114 void CGraphicPanel::OnAssemblySelected(wxCommandEvent& event)
115 {
116  int selection = event.GetSelection();
117  if (selection < 0 || selection >= (int)m_Assemblies.size())
118  return;
119 
121  if (fp)
122  fp->SetAssembly(m_Assemblies[selection]->GetAccession());
123 }
124 
125 void CGraphicPanel::OnTimer(wxTimerEvent& event)
126 {
127  if (x_CheckLoaded()) {
128  m_Timer.Stop();
129  x_CreateToolbar();
130  }
131 }
132 
134 {
136  if (!fp) return false;
137 
138  m_AssemblyLoaded = fp->AssemblyLoaded();
139  if (m_AssemblyLoaded) {
140  m_Assemblies = fp->GetAssemblies();
141  m_CurrentAssembly = fp->GetCurrentAssembly();
142  }
143  return m_AssemblyLoaded;
144 }
145 
147 {
148  static bool sImagesRegistered = false;
149  if (!sImagesRegistered) {
151  provider->RegisterFileAlias(wxT("graphic_panel::search"), wxT("search.png"));
152  sImagesRegistered = true;
153  }
154 
155  wxAuiPaneInfo& pane = m_AuiManager.GetPane(pszMainToolbar);
156  wxAuiToolBar* toolbar = nullptr;
157  wxString searchTerm;
158  if (pane.IsOk()) {
159  toolbar = (wxAuiToolBar*)pane.window;
160 
161  wxControl* ctrl = toolbar->FindControl(ID_TB_AssemblyLabel);
162  if (ctrl) ctrl->Destroy();
163 
164  ctrl = toolbar->FindControl(ID_TB_AssemblyList);
165  if (ctrl) ctrl->Destroy();
166 
167  ctrl = toolbar->FindControl(ID_TB_SearchModeCtrl);
168  if (ctrl) ctrl->Destroy();
169  m_FindModeCtrl = 0;
170 
171  ctrl = toolbar->FindControl(ID_TB_SearchTerm);
172  if (ctrl) {
173  searchTerm = ((CRichTextCtrl*)ctrl)->GetValue();
174  ctrl->Destroy();
175  }
176  m_FindTextCtrl = 0;
177 
178  toolbar->ClearTools();
179  }
180  else {
181  toolbar = new wxAuiToolBar(this, wxID_ANY, wxDefaultPosition,
182  wxDefaultSize, wxAUI_TB_HORIZONTAL | wxBORDER_NONE);
183  }
184 
186 
187  cmd_reg.AppendTool(*toolbar, eCmdBack);
188  cmd_reg.AppendTool(*toolbar, eCmdForward);
189  toolbar->AddSeparator();
190  cmd_reg.AppendTool(*toolbar, eCmdZoomOut);
191  cmd_reg.AppendTool(*toolbar, eCmdZoomIn);
192  cmd_reg.AppendTool(*toolbar, eCmdZoomAll);
193  cmd_reg.AppendTool(*toolbar, eCmdZoomSeq);
194  cmd_reg.AppendTool(*toolbar, eCmdZoomSel);
195  toolbar->AddSeparator();
196  cmd_reg.AppendTool(*toolbar, eCmdConfigureTracks);
197  toolbar->AddSeparator();
198 
199 // if (RunningInsideNCBI())
200  {
201  toolbar->AddLabel(ID_TB_SearchModeLabel, wxT("Find mode:"));
202  wxArrayString strings;
203  strings.Add(_("Match case"));
204  strings.Add(_("Do not match case"));
205  m_FindModeCtrl = new wxChoice(toolbar, ID_TB_SearchModeCtrl, wxDefaultPosition, wxDefaultSize, strings);
206  m_FindModeCtrl->SetSelection(0);
207  toolbar->AddControl(m_FindModeCtrl);
208 
209  m_FindTextCtrl = new CRichTextCtrl(toolbar, ID_TB_SearchTerm, searchTerm, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
210  m_FindTextCtrl->SetMaxLength(60);
211 
212  wxMenu* menu = new wxMenu();
213  menu->Append(wxID_COPY, _("&Copy"));
214  menu->Append(wxID_PASTE, _("&Paste"));
216 
217  toolbar->AddControl(m_FindTextCtrl, wxT("Enter search term"));
218 
219  toolbar->AddTool(ID_TB_SearchButton, wxT("Search"), wxArtProvider::GetBitmap(wxT("graphic_panel::search")), wxT("Search"));
220  toolbar->AddSeparator();
221  }
222 
223  if (m_AssemblyLoaded) {
224  toolbar->AddLabel(ID_TB_AssemblyLabel, wxT("Assembly:"));
225  if (m_Assemblies.empty())
226  toolbar->AddLabel(ID_TB_AssemblyList, wxT("N/A"));
227  else {
228  int selection = -1;
229  wxChoice* assListCtrl = new wxChoice(toolbar, ID_TB_AssemblyList);
230  for (auto i : m_Assemblies) {
231  string accession = i->GetAccession();
232  string name = i->GetName();
233  int index = assListCtrl->Append(ToWxString(name + " (") + accession + ")");
234  if (!m_CurrentAssembly.empty() &&
235  m_CurrentAssembly == accession)
236  selection = index;
237  //objects::CGC_Assembly::TFullAssemblies ass = i->GetFullAssemblies();
238  //for (auto a : ass)
239  //assListCtrl->Append(ToWxString(a->GetName()));
240  }
241  if (selection >= 0)
242  assListCtrl->SetSelection(selection);
243  toolbar->AddControl(assListCtrl);
244  }
245  }
246  else {
247  toolbar->AddLabel(ID_TB_AssemblyLabel, wxT("Querying Assembly..."));
248  toolbar->AddControl(new CIndProgressBar(toolbar, ID_TB_AssemblyList, wxDefaultPosition, 80),
249  wxT("Querying..."));
250  }
251 
252  toolbar->AddStretchSpacer();
253  toolbar->AddTool(ID_TB_Help, wxEmptyString,
254  wxArtProvider::GetBitmap(wxART_HELP, wxART_OTHER, wxSize(16, 16)),
255  wxT("Graphical View Help"));
256 
257  // As part of auto resize tollbar is resized in vertical position for a moment
258  // this is visible on MS windows screen - so hide it
259  toolbar->Hide();
260  toolbar->Realize();
261  toolbar->Show();
262 
263  if (!pane.IsOk())
264  m_AuiManager.AddPane(toolbar, wxAuiPaneInfo()
265  .Name(pszMainToolbar)
266  .Caption(pszMainToolbar)
267  .ToolbarPane()
268  .Top()
269  .TopDockable(true)
270  .LeftDockable(false)
271  .RightDockable(false)
272  .BottomDockable(false)
273  .Floatable(false)
274  .Resizable(true)
275  .DockFixed()
276  .Gripper(false)
277  .DestroyOnClose(true)
278  .Position(0));
279  else
280  pane.BestSize(toolbar->GetClientSize());
281 
282  m_AuiManager.Update();
283  Update();
284 }
285 
286 
287 void CGraphicPanel::OnConfigureTracks(wxCommandEvent&)
288 {
290 }
291 
292 void CGraphicPanel::OnHelpClick(wxCommandEvent& evt)
293 {
294  wxAuiPaneInfo& pane = m_AuiManager.GetPane(pszMainToolbar);
295  if (!pane.IsOk()) return;
296 
297  wxAuiToolBar* tb = static_cast<wxAuiToolBar*>(pane.window);
299 
300  wxMenu menuPopup;
301  cmd_reg.AppendMenuItem(menuPopup, eCmdWebHelpGSVNavigation);
303  cmd_reg.AppendMenuItem(menuPopup, eCmdWebHelpGSVLegends);
304  cmd_reg.AppendMenuItem(menuPopup, eCmdWebHelpApp);
305 
306  // line up our menu with the button
307  wxRect rect = tb->GetToolRect(evt.GetId());
308  wxPoint pt = tb->ClientToScreen(rect.GetBottomLeft());
309  pt = ScreenToClient(pt);
310 
311  PopupMenu(&menuPopup, pt);
312 }
313 
315 {
316  if (!m_SeqWidget)
317  return;
318 
319  const wxString caption = wxT("Find Text");
320 
321  wxString text = m_FindTextCtrl->GetValue();
322  if (text.empty()) {
324  wxMessageBox(wxT("Search string is empty."), caption, wxOK | wxICON_EXCLAMATION);
325  return;
326  }
327 
328  bool found = false;
329  {
330  wxBusyCursor wait;
331  string tmp = text.ToStdString();
333  found = m_SeqWidget->FindText(tmp, (m_FindModeCtrl->GetSelection() == 0));
334  }
335 
336  if (!found)
337  wxMessageBox(wxT("Search string not found."), caption, wxOK | wxICON_EXCLAMATION);
338 }
339 
340 
341 void CGraphicPanel::OnFindNextClick( wxCommandEvent& event )
342 {
343  x_FindText();
344 }
345 
346 void CGraphicPanel::OnSearchTermCtrlEnter( wxCommandEvent& event )
347 {
348  x_FindText();
349 }
350 
#define static
#define false
Definition: bool.h:36
virtual void Create()
creates controls and performs basic initialization
wxChoice * m_FindModeCtrl
void OnAssemblySelected(wxCommandEvent &event)
void OnSearchTermCtrlEnter(wxCommandEvent &event)
virtual bool ProcessEvent(wxEvent &event)
void OnFindNextClick(wxCommandEvent &event)
void x_CreateToolbar()
CSeqGraphicWidget * m_SeqWidget
void CreateControls()
vector< CRef< objects::CGC_Assembly > > m_Assemblies
void OnTimer(wxTimerEvent &event)
wxAuiManager m_AuiManager
void CreateToolbar()
CRichTextCtrl * m_FindTextCtrl
void OnHelpClick(wxCommandEvent &event)
void OnConfigureTracks(wxCommandEvent &event)
string m_CurrentAssembly
CRichTextCtrl - a wrapper for wxRichTextCtrl that handles additional keyboard events (such as Clipboa...
void SetContextMenu(wxMenu *contextMenu)
bool FindText(const string &text, bool match_case)
CFeaturePanel * GetFeaturePanel()
CUICommandRegistry is a centralized registry where all application commands should be registered.
Definition: ui_command.hpp:146
static CUICommandRegistry & GetInstance()
the main instance associated with the application
Definition: ui_command.cpp:176
void AppendTool(wxToolBar &tool_bar, TCmdID cmd_id)
Definition: ui_command.cpp:448
wxMenuItem * AppendMenuItem(wxMenu &menu, TCmdID cmd_id) const
Definition: ui_command.cpp:300
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
static const char fp[]
Definition: des.c:87
int Main(int argc, const char *argv[])
USING_SCOPE(objects)
static const wxChar * pszMainToolbar
@ eCmdConfigureTracks
Definition: command.hpp:86
@ eCmdForward
Definition: command.hpp:101
@ eCmdWebHelpGSVLegends
Definition: command.hpp:94
@ eCmdZoomIn
empty command
Definition: command.hpp:68
@ eCmdWebHelpApp
Definition: command.hpp:90
@ eCmdZoomOut
Definition: command.hpp:69
@ eCmdZoomSeq
Zoom to Selection.
Definition: command.hpp:74
@ eCmdWebHelpGSVInteractionGuide
Definition: command.hpp:93
@ eCmdZoomAll
Definition: command.hpp:70
@ eCmdBack
Navigation commands.
Definition: command.hpp:100
@ eCmdWebHelpGSVNavigation
Definition: command.hpp:92
@ eCmdZoomSel
Definition: command.hpp:73
#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 void TruncateSpacesInPlace(string &str, ETrunc where=eTrunc_Both)
Truncate spaces in a string (in-place)
Definition: ncbistr.cpp:3197
END_EVENT_TABLE()
int i
static void text(MDB_val *v)
Definition: mdb_dump.c:62
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
const CConstRef< CSeq_id > GetAccession(const CSeq_id_Handle &id_handle)
static const char *const strings[]
Definition: utf8.c:21
static char tmp[2048]
Definition: utf8.c:42
wxEVT_COMMAND_MENU_SELECTED
static static static wxID_ANY
ViewerWindowBase::OnEditMenu ViewerWindowBase::OnJustification EVT_MENU(MID_SHOW_GEOM_VLTNS, ViewerWindowBase::OnShowGeomVltns) EVT_MENU(MID_FIND_PATTERN
Definition: type.c:6
wxFileArtProvider * GetDefaultFileArtProvider()
Definition: wx_utils.cpp:334
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
#define const
Definition: zconf.h:230
Modified on Wed Feb 21 09:55:28 2024 by modify_doxy.py rev. 669887