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

Go to the SVN repository for this file.

1 /* $Id: viewer_base.cpp 64773 2014-10-08 13:59:20Z thiessen $
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: Paul Thiessen
27 *
28 * File Description:
29 * base functionality for non-GUI part of viewers
30 *
31 * ===========================================================================
32 */
33 
34 #include <ncbi_pch.hpp>
35 #include <corelib/ncbistd.hpp>
36 
37 #include <map>
38 
40 
41 #include "viewer_base.hpp"
42 #include "viewer_window_base.hpp"
43 #include "sequence_display.hpp"
44 #include "messenger.hpp"
45 #include "cn3d_tools.hpp"
46 #include "alignment_manager.hpp"
47 #include "cn3d_blast.hpp"
48 
50 
51 
52 BEGIN_SCOPE(Cn3D)
53 
54 // limits the size of the stack (set to -1 for unlimited)
55 const unsigned int ViewerBase::MAX_UNDO_STACK_SIZE = 50;
56 
58  alignmentManager(alnMgr), viewerWindow(window), currentDisplay(NULL)
59 {
60  if (!window) ERRORMSG("ViewerBase::ViewerBase() - got NULL handle");
61 }
62 
64 {
65  DestroyGUI();
66  ClearAllData();
67 }
68 
70 {
71  if ((*viewerWindow)) {
72  (*viewerWindow)->KillWindow();
73  GUIDestroyed();
74  }
75 }
76 
78 {
79  if (*viewerWindow)
80  (*viewerWindow)->SetWindowTitle();
81 }
82 
83 void ViewerBase::InitData(const AlignmentList *alignments, SequenceDisplay *display)
84 {
85  ClearAllData();
86  if (alignments) currentAlignments = *alignments; // copy list
87  currentDisplay = display;
88  stacksEnabled = false;
90 }
91 
93 {
94  if (stacksEnabled) {
95  ERRORMSG("ViewerBase::EnableStacks() - already enabled!");
96  return;
97  }
98 
99  stacksEnabled = true;
100  nRedosStored = 0;
101  Save();
102 }
103 
105 {
106  if (!currentDisplay || !stacksEnabled) {
107  ERRORMSG("ViewerBase::Save() - stacks not enabled, or no alignment/display data");
108  return;
109  }
110 
111  // clear out any data in the stack above the current position (deletes "redo" list)
112  if (nRedosStored > 0) {
113  TRACEMSG("deleting " << nRedosStored << " redo elements from the stack");
114  for (; nRedosStored>0; --nRedosStored) {
116  alignmentStack.pop_back();
117  delete displayStack.back();
118  displayStack.pop_back();
119  }
120  }
121 
122  // remove the one-up-from-bottom of the stack if it's too big (so original isn't lost)
123  if (alignmentStack.size() == MAX_UNDO_STACK_SIZE) {
124  WARNINGMSG("max undo stack size exceeded - deleting next-from-bottom item");
126  alignmentStack.erase(++(alignmentStack.begin()));
127  delete *(++(displayStack.begin()));
128  displayStack.erase(++(displayStack.begin()));
129  }
130 
131  // clone current alignments onto top of stack
132  alignmentStack.resize(alignmentStack.size() + 1);
133  Old2NewAlignmentMap newAlignmentMap;
134  AlignmentList::const_iterator a, ae = currentAlignments.end();
135  for (a=currentAlignments.begin(); a!=ae; ++a) {
136  BlockMultipleAlignment *newAlignment = (*a)->Clone();
137  alignmentStack.back().push_back(newAlignment);
138  newAlignmentMap[*a] = newAlignment;
139  }
140 
141  // clone display
142  displayStack.push_back(currentDisplay->Clone(newAlignmentMap));
143 
145 }
146 
148 {
149  if ((alignmentStack.size() - nRedosStored) <= 1 || !stacksEnabled) {
150  ERRORMSG("ViewerBase::Undo() - stacks disabled, or no more undo data");
151  return;
152  }
153 
154  ++nRedosStored;
157 }
158 
160 {
161  if (nRedosStored == 0 || !stacksEnabled) {
162  ERRORMSG("ViewerBase::Redo() - stacks disabled, or no more redo data");
163  return;
164  }
165 
166  --nRedosStored;
169 }
170 
172 {
173  if (*viewerWindow) {
174  (*viewerWindow)->EnableUndo((alignmentStack.size() - nRedosStored) > 1 && stacksEnabled);
175  (*viewerWindow)->EnableRedo(nRedosStored > 0 && stacksEnabled);
176  }
177 }
178 
180 {
181  // delete current objects
183  delete currentDisplay;
184 
185  // move to appropriate stack object
186  AlignmentStack::reverse_iterator as = alignmentStack.rbegin();
187  DisplayStack::reverse_iterator ds = displayStack.rbegin();
188  for (int i=0; i<nRedosStored; ++i) {
189  ++as;
190  ++ds;
191  }
192 
193  // clone alignments into current
194  Old2NewAlignmentMap newAlignmentMap;
195  AlignmentList::const_iterator a, ae = as->end();
196  for (a=as->begin(); a!=ae; ++a) {
197  BlockMultipleAlignment *newAlignment = (*a)->Clone();
198  currentAlignments.push_back(newAlignment);
199  newAlignmentMap[*a] = newAlignment;
200  }
201 
202  // clone display
203  currentDisplay = (*ds)->Clone(newAlignmentMap);
204 }
205 
207 {
209  while (alignmentStack.size() > 0) {
211  alignmentStack.pop_back();
212  }
213 
214  delete currentDisplay;
216  while (displayStack.size() > 0) {
217  delete displayStack.back();
218  displayStack.pop_back();
219  }
220 }
221 
223 {
224  if (!stacksEnabled) {
225  ERRORMSG("ViewerBase::Revert() - stacks disabled!");
226  return;
227  }
228 
229  nRedosStored = 0;
230 
231  // revert to the bottom of the stack; delete the rest
232  while (alignmentStack.size() > 0) {
233 
234  if (alignmentStack.size() == 1)
236 
238  alignmentStack.pop_back();
239  delete displayStack.back();
240  displayStack.pop_back();
241  }
242  stacksEnabled = false;
244 }
245 
247 {
248  if (!stacksEnabled) return;
249 
250  // delete all stack data (leaving current stuff unchanged)
251  while (alignmentStack.size() > 0) {
253  alignmentStack.pop_back();
254  }
255  while (displayStack.size() > 0) {
256  delete displayStack.back();
257  displayStack.pop_back();
258  }
259  nRedosStored = 0;
260  stacksEnabled = false;
262 }
263 
264 bool ViewerBase::EditorIsOn(void) const
265 {
266  return (*viewerWindow && (*viewerWindow)->EditorIsOn());
267 }
268 
270 {
271  if (*viewerWindow) (*viewerWindow)->SetupFontFromRegistry();
272 }
273 
274 void ViewerBase::MakeResidueVisible(const Molecule *molecule, int seqIndex)
275 {
276  if (!(*viewerWindow) || !currentDisplay) return;
277 
278  unsigned int column, row;
279  if (currentDisplay->GetDisplayCoordinates(molecule, seqIndex,
280  (*viewerWindow)->GetCurrentJustification(), &column, &row))
281  (*viewerWindow)->MakeCellVisible(column, row);
282 }
283 
285 {
286  if (*viewerWindow) (*viewerWindow)->MakeSequenceVisible(identifier);
287 }
288 
289 void ViewerBase::SaveDialog(bool prompt)
290 {
291  if (*viewerWindow) (*viewerWindow)->SaveDialog(prompt, false);
292 }
293 
295 {
296  if (*viewerWindow) (*viewerWindow)->RefreshWidget();
297 }
298 
300 {
302 }
303 
305 {
307 }
308 
309 END_SCOPE(Cn3D)
void CalculateSelfHitScores(const BlockMultipleAlignment *multiple)
Definition: cn3d_blast.cpp:504
BlockMultipleAlignment * Clone(void) const
SequenceDisplay * Clone(const Old2NewAlignmentMap &newAlignments) const
bool GetDisplayCoordinates(const Molecule *molecule, unsigned int seqIndex, BlockMultipleAlignment::eUnalignedJustification justification, unsigned int *column, unsigned int *row)
void RemoveBlockBoundaryRows(void)
AlignmentStack alignmentStack
void SetWindowTitle(void) const
Definition: viewer_base.cpp:77
virtual ~ViewerBase(void)
Definition: viewer_base.cpp:63
AlignmentList currentAlignments
std::list< BlockMultipleAlignment * > AlignmentList
Definition: viewer_base.hpp:89
void MakeSequenceVisible(const MoleculeIdentifier *identifier)
void SetUndoRedoMenuStates(void)
void ClearAllData(void)
AlignmentManager * alignmentManager
Definition: viewer_base.hpp:96
void RemoveBlockBoundaryRows(void)
void Save(void)
void KeepCurrent(void)
DisplayStack displayStack
bool EditorIsOn(void) const
SequenceDisplay * currentDisplay
void InitData(const AlignmentList *alignments, SequenceDisplay *display)
Definition: viewer_base.cpp:83
void Refresh(void)
void EnableStacks(void)
Definition: viewer_base.cpp:92
void Revert(void)
bool stacksEnabled
virtual void SaveDialog(bool prompt)
void GUIDestroyed(void)
Definition: viewer_base.hpp:67
void CalculateSelfHitScores(const BlockMultipleAlignment *multiple)
ViewerBase(ViewerWindowBase **window, AlignmentManager *alnMgr)
Definition: viewer_base.cpp:57
static const unsigned int MAX_UNDO_STACK_SIZE
ViewerWindowBase **const viewerWindow
Definition: viewer_base.hpp:99
void Undo(void)
void MakeResidueVisible(const Molecule *molecule, int seqIndex)
void DestroyGUI(void)
Definition: viewer_base.cpp:69
void NewFont(void)
void CopyDataFromStack(void)
void Redo(void)
bool EditorIsOn(void) const
#define TRACEMSG(stream)
Definition: cn3d_tools.hpp:83
#define WARNINGMSG(stream)
Definition: cn3d_tools.hpp:85
#define ERRORMSG(stream)
Definition: cn3d_tools.hpp:86
Include a standard set of the NCBI C++ Toolkit most basic headers.
static const char * column
Definition: stats.c:23
#define NULL
Definition: ncbistd.hpp:225
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
int i
unsigned int a
Definition: ncbi_localip.c:102
std::map< BlockMultipleAlignment *, BlockMultipleAlignment * > Old2NewAlignmentMap
#define row(bind, expected)
Definition: string_bind.c:73
#define DELETE_ALL_AND_CLEAR(container, ContainerType)
Definition: su_private.hpp:82
USING_NCBI_SCOPE
Definition: viewer_base.cpp:49
Modified on Sat May 18 11:38:33 2024 by modify_doxy.py rev. 669887