CompositePeaksPresenter.cpp 20.2 KB
Newer Older
1
#include "MantidQtSliceViewer/CompositePeaksPresenter.h"
2
#include "MantidAPI/IPeaksWorkspace.h"
3
#include <stdexcept>
4

Owen Arnold's avatar
Owen Arnold committed
5
using Mantid::Geometry::PeakTransform_sptr;
6

Owen Arnold's avatar
Owen Arnold committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
namespace MantidQt {
namespace SliceViewer {
/**
Constructor
*/
CompositePeaksPresenter::CompositePeaksPresenter(
    ZoomablePeaksView *const zoomablePlottingWidget,
    PeaksPresenter_sptr defaultPresenter)
    : m_zoomablePlottingWidget(zoomablePlottingWidget),
      m_default(defaultPresenter), m_owner(NULL), m_zoomedPeakIndex(-1) {
  if (m_zoomablePlottingWidget == NULL) {
    throw std::runtime_error("Zoomable Plotting Widget is NULL");
  }
}
21

Owen Arnold's avatar
Owen Arnold committed
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
Destructor
*/
CompositePeaksPresenter::~CompositePeaksPresenter() {}

/**
Overrriden update method
*/
void CompositePeaksPresenter::update() {
  if (useDefault()) {
    m_default->update();
    return;
  }
  for (auto it = m_subjects.begin(); it != m_subjects.end(); ++it) {
    (*it)->update();
  }
}
39

Owen Arnold's avatar
Owen Arnold committed
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
Overriden updateWithSlicePoint
@param point : Slice point to update with
*/
void
CompositePeaksPresenter::updateWithSlicePoint(const PeakBoundingBox &point) {
  if (useDefault()) {
    m_default->updateWithSlicePoint(point);
    return;
  }
  for (auto it = m_subjects.begin(); it != m_subjects.end(); ++it) {
    (*it)->updateWithSlicePoint(point);
  }
}
54

Owen Arnold's avatar
Owen Arnold committed
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
Handle dimension display changing.
*/
bool CompositePeaksPresenter::changeShownDim() {
  if (useDefault()) {
    return m_default->changeShownDim();
  }
  bool result = true;
  for (auto it = m_subjects.begin(); it != m_subjects.end(); ++it) {
    result &= (*it)->changeShownDim();
  }
  return result;
}
68

Owen Arnold's avatar
Owen Arnold committed
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
Determine wheter a given axis label correponds to the free peak axis.
@return True only if the label is that of the free peak axis.
*/
bool
CompositePeaksPresenter::isLabelOfFreeAxis(const std::string &label) const {
  if (useDefault()) {
    return m_default->isLabelOfFreeAxis(label);
  }
  bool result = true;
  for (auto it = m_subjects.begin(); it != m_subjects.end(); ++it) {
    result &= (*it)->isLabelOfFreeAxis(label);
  }
  return result;
}
84

Owen Arnold's avatar
Owen Arnold committed
85
86
87
88
/**
Clear all peaks
*/
void CompositePeaksPresenter::clear() {
Owen Arnold's avatar
Owen Arnold committed
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
  if (!m_subjects.empty()) {
    m_subjects.clear();
    this->m_zoomablePlottingWidget->detach();
    PeakPalette temp;
    m_palette = temp;
  }
}

/**
 * @brief Determine wheter the workspace contents is different with another
 * presenter.
 * @param other
 * @return
 */
bool CompositePeaksPresenter::contentsDifferent(
    PeaksPresenter const *const other) const {
  /*
   What we are doing here is looking through all workspaces associated with the
   incoming presenter
   and seeing if ANY of the exising subjects of this composite is already
   presenting one of these workspaces.
   ONLY if there is no intesection between the two sets will we allow addition.
   */
  const SetPeaksWorkspaces otherWorkspaces = other->presentedWorkspaces();
  const SetPeaksWorkspaces existingWorkspaces = this->presentedWorkspaces();

  SetPeaksWorkspaces difference;
  std::set_difference(existingWorkspaces.begin(), existingWorkspaces.end(),
                      otherWorkspaces.begin(), otherWorkspaces.end(),
                      std::inserter(difference, difference.end()));

  // Is the candidate set the same as the difference set (i.e. no intesection)
  // and also non-zero in size
  const bool different = (difference.size() == existingWorkspaces.size());
  return different;
Owen Arnold's avatar
Owen Arnold committed
124
}
125

Owen Arnold's avatar
Owen Arnold committed
126
127
128
129
130
131
132
133
134
/**
Add peaks presenter
@param presenter : Subject peaks presenter
*/
void CompositePeaksPresenter::addPeaksPresenter(PeaksPresenter_sptr presenter) {
  if (this->size() == 10) {
    throw std::invalid_argument("Maximum number of PeaksWorkspaces that can be "
                                "simultaneously displayed is 10.");
  }
135

Owen Arnold's avatar
Owen Arnold committed
136
  // Look for the same presenter added twice.
Owen Arnold's avatar
Owen Arnold committed
137
  auto result_it = std::find(m_subjects.begin(), m_subjects.end(), presenter);
Owen Arnold's avatar
Owen Arnold committed
138
139
140
141

  // Only add a peaks presenter if the contents are different. The presenter may
  // be different, but manage the same workspace set.
  if (result_it == m_subjects.end() && presenter->contentsDifferent(this)) {
Owen Arnold's avatar
Owen Arnold committed
142
143
144
145
    m_subjects.push_back(presenter);
    presenter->registerOwningPresenter(this);
  }
}
146

Owen Arnold's avatar
Owen Arnold committed
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/**
@return the number of subjects in the composite
*/
size_t CompositePeaksPresenter::size() const { return m_subjects.size(); }

/**
Return a collection of all referenced workspaces on demand.
*/
SetPeaksWorkspaces CompositePeaksPresenter::presentedWorkspaces() const {
  SetPeaksWorkspaces allWorkspaces;
  for (auto it = m_subjects.begin(); it != m_subjects.end(); ++it) {
    auto workspacesToAppend = (*it)->presentedWorkspaces();
    allWorkspaces.insert(workspacesToAppend.begin(), workspacesToAppend.end());
  }
  return allWorkspaces;
}
163

Owen Arnold's avatar
Owen Arnold committed
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/**
@param ws : Peaks Workspace to look for on sub-presenters.
@return the identified sub-presenter for the workspace, or a NullPeaksPresenter.
*/
CompositePeaksPresenter::SubjectContainer::iterator
CompositePeaksPresenter::getPresenterIteratorFromWorkspace(
    boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws) {
  SubjectContainer::iterator presenterFound = m_subjects.end();
  for (auto presenterIterator = m_subjects.begin();
       presenterIterator != m_subjects.end(); ++presenterIterator) {
    auto workspacesOfSubject = (*presenterIterator)->presentedWorkspaces();
    SetPeaksWorkspaces::iterator iteratorFound = workspacesOfSubject.find(ws);
    if (iteratorFound != workspacesOfSubject.end()) {
      presenterFound = presenterIterator;
      break;
179
    }
Owen Arnold's avatar
Owen Arnold committed
180
181
182
  }
  return presenterFound;
}
183

Owen Arnold's avatar
Owen Arnold committed
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/**
@param ws : Peaks Workspace to look for on sub-presenters.
@return the identified sub-presenter for the workspace, or a NullPeaksPresenter.
*/
CompositePeaksPresenter::SubjectContainer::const_iterator
CompositePeaksPresenter::getPresenterIteratorFromWorkspace(
    boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws) const {
  SubjectContainer::const_iterator presenterFound = m_subjects.end();
  for (auto presenterIterator = m_subjects.begin();
       presenterIterator != m_subjects.end(); ++presenterIterator) {
    auto workspacesOfSubject = (*presenterIterator)->presentedWorkspaces();
    SetPeaksWorkspaces::iterator iteratorFound = workspacesOfSubject.find(ws);
    if (iteratorFound != workspacesOfSubject.end()) {
      presenterFound = presenterIterator;
      break;
199
    }
Owen Arnold's avatar
Owen Arnold committed
200
201
202
  }
  return presenterFound;
}
203

Owen Arnold's avatar
Owen Arnold committed
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/**
Set the foreground colour of the peaks.
@ workspace containing the peaks to re-colour
@ colour to use for re-colouring
*/
void CompositePeaksPresenter::setForegroundColour(
    boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws,
    const QColor colour) {
  SubjectContainer::iterator iterator = getPresenterIteratorFromWorkspace(ws);

  // Update the palette the foreground colour
  const int pos = static_cast<int>(std::distance(m_subjects.begin(), iterator));
  m_palette.setForegroundColour(pos, colour);

  // Apply the foreground colour
  (*iterator)->setForegroundColor(colour);
}
221

Owen Arnold's avatar
Owen Arnold committed
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/**
Set the background colour of the peaks.
@ workspace containing the peaks to re-colour
@ colour to use for re-colouring
*/
void CompositePeaksPresenter::setBackgroundColour(
    boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws,
    const QColor colour) {
  SubjectContainer::iterator iterator = getPresenterIteratorFromWorkspace(ws);

  // Update the palette background colour.
  const int pos = static_cast<int>(std::distance(m_subjects.begin(), iterator));
  m_palette.setBackgroundColour(pos, colour);

  // Apply the background colour
  (*iterator)->setBackgroundColor(colour);
}
239

Owen Arnold's avatar
Owen Arnold committed
240
241
242
243
244
245
246
247
248
249
/**
Getter for the name of the transform.
@return transform name.
*/
std::string CompositePeaksPresenter::getTransformName() const {
  if (useDefault()) {
    return m_default->getTransformName();
  }
  return (*m_subjects.begin())->getTransformName();
}
250

Owen Arnold's avatar
Owen Arnold committed
251
252
253
254
255
256
/**
@return a copy of the peaks palette.
*/
PeakPalette CompositePeaksPresenter::getPalette() const {
  return this->m_palette;
}
257

Owen Arnold's avatar
Owen Arnold committed
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
/**
@param ws: PeakWorkspace to get the colour for.
@return the foreground colour corresponding to the peaks workspace.
*/
QColor CompositePeaksPresenter::getForegroundColour(
    boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws) const {
  if (useDefault()) {
    throw std::runtime_error("Foreground colours from palette cannot be "
                             "fetched until nested presenters are added.");
  }
  SubjectContainer::const_iterator iterator =
      getPresenterIteratorFromWorkspace(ws);
  const int pos = static_cast<int>(std::distance(m_subjects.begin(), iterator));
  return m_palette.foregroundIndexToColour(pos);
}
273

Owen Arnold's avatar
Owen Arnold committed
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/**
@param ws: PeakWorkspace to get the colour for.
@return the background colour corresponding to the peaks workspace.
*/
QColor CompositePeaksPresenter::getBackgroundColour(
    boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws) const {
  if (useDefault()) {
    throw std::runtime_error("Background colours from palette cannot be "
                             "fetched until nested presenters are added.");
  }
  SubjectContainer::const_iterator iterator =
      getPresenterIteratorFromWorkspace(ws);
  const int pos = static_cast<int>(std::distance(m_subjects.begin(), iterator));
  return m_palette.backgroundIndexToColour(pos);
}
289

Owen Arnold's avatar
Owen Arnold committed
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
/**
 * Set to show the background radius.
 * @param ws : Workspace upon which the backgoround radius should be
 * shown/hidden.
 * @param shown : True to show.
 */
void CompositePeaksPresenter::setBackgroundRadiusShown(
    boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws,
    const bool shown) {
  if (useDefault()) {
    return m_default->showBackgroundRadius(shown);
  }
  auto iterator = getPresenterIteratorFromWorkspace(ws);
  (*iterator)->showBackgroundRadius(shown);
}
305

Owen Arnold's avatar
Owen Arnold committed
306
307
308
309
310
311
312
313
314
315
316
317
318
/**
 * Remove a peaks list altogether from the reporting and peaks overlays.
 * @param peaksWS : Peaks list to remove.
 */
void CompositePeaksPresenter::remove(
    boost::shared_ptr<const Mantid::API::IPeaksWorkspace> peaksWS) {
  if (useDefault()) {
    return;
  }
  auto iterator = getPresenterIteratorFromWorkspace(peaksWS);
  if (iterator != m_subjects.end()) {
    m_subjects.erase(iterator);
  }
Owen Arnold's avatar
Owen Arnold committed
319
320
321
  if (m_subjects.empty()) {
    this->m_zoomablePlottingWidget->detach();
  }
Owen Arnold's avatar
Owen Arnold committed
322
}
323

Owen Arnold's avatar
Owen Arnold committed
324
325
326
327
328
329
330
331
332
333
334
335
336
337
/**
 * Allow the peaks list to be hidden or visible.
 * @param peaksWS : Peaks list to show/hide.
 * @param shown : True to show.
 */
void CompositePeaksPresenter::setShown(
    boost::shared_ptr<const Mantid::API::IPeaksWorkspace> peaksWS,
    const bool shown) {
  if (useDefault()) {
    return m_default->setShown(shown);
  }
  auto iterator = getPresenterIteratorFromWorkspace(peaksWS);
  (*iterator)->setShown(shown);
}
338

Owen Arnold's avatar
Owen Arnold committed
339
340
341
342
343
344
345
346
347
348
349
350
351
352
/**
 * Zoom in on a given peak in a given peaks list according to the current
 * viewing dimensions.
 * @param peaksWS : Peaks list from which a choosen peak will be zoomed into.
 * @param peakIndex : Index of the peak in the peaks list to zoom into.
 */
void CompositePeaksPresenter::zoomToPeak(
    boost::shared_ptr<const Mantid::API::IPeaksWorkspace> peaksWS,
    const int peakIndex) {
  auto iterator = getPresenterIteratorFromWorkspace(peaksWS);
  auto subjectPresenter = *iterator;
  auto boundingBox = subjectPresenter->getBoundingBox(peakIndex);
  m_zoomablePlottingWidget->zoomToRectangle(boundingBox);
}
353

Owen Arnold's avatar
Owen Arnold committed
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
/**
 * Sort the peaks workspace.
 * @param peaksWS : Peaks list to sort.
 * @param columnToSortBy : Column to sort by.
 * @param sortedAscending : Direction of the sort. True for Ascending.
 */
void CompositePeaksPresenter::sortPeaksWorkspace(
    boost::shared_ptr<const Mantid::API::IPeaksWorkspace> peaksWS,
    const std::string &columnToSortBy, const bool sortedAscending) {
  auto iterator = getPresenterIteratorFromWorkspace(peaksWS);
  auto subjectPresenter = *iterator;
  subjectPresenter->sortPeaksWorkspace(columnToSortBy, sortedAscending);
  // We want to zoom out now, because any currently selected peak will be wrong.
  m_zoomablePlottingWidget->resetView();
  m_zoomedPeakIndex = -1;
  m_zoomedPresenter.reset();
}
Owen Arnold's avatar
Owen Arnold committed
371

Owen Arnold's avatar
Owen Arnold committed
372
373
374
375
376
377
378
379
380
381
382
383
384
/**
 * Set the peaks size on the current projection using the supplied fraction.
 * @param fraction of the view width to use as the peak radius.
 */
void CompositePeaksPresenter::setPeakSizeOnProjection(const double fraction) {
  if (useDefault()) {
    return m_default->setPeakSizeOnProjection(fraction);
  }
  for (auto presenterIterator = m_subjects.begin();
       presenterIterator != m_subjects.end(); ++presenterIterator) {
    (*presenterIterator)->setPeakSizeOnProjection(fraction);
  }
}
385

Owen Arnold's avatar
Owen Arnold committed
386
387
388
389
390
391
392
393
394
395
396
397
398
/**
 * Fraction of the z-range to use as the peak radius.
 * @param fraction to use as the peak radius
 */
void CompositePeaksPresenter::setPeakSizeIntoProjection(const double fraction) {
  if (useDefault()) {
    return m_default->setPeakSizeIntoProjection(fraction);
  }
  for (auto presenterIterator = m_subjects.begin();
       presenterIterator != m_subjects.end(); ++presenterIterator) {
    (*presenterIterator)->setPeakSizeIntoProjection(fraction);
  }
}
399

Owen Arnold's avatar
Owen Arnold committed
400
401
402
403
404
405
406
407
408
409
410
411
412
413
/**
 * Get the peak size on the projection plane
 * @return size
 */
double CompositePeaksPresenter::getPeakSizeOnProjection() const {
  if (useDefault()) {
    return m_default->getPeakSizeOnProjection();
  }
  double result = 0;
  for (auto it = m_subjects.begin(); it != m_subjects.end(); ++it) {
    double temp = (*it)->getPeakSizeOnProjection();
    if (temp > 0) {
      result = temp;
      break;
414
    }
Owen Arnold's avatar
Owen Arnold committed
415
416
417
  }
  return result;
}
418

Owen Arnold's avatar
Owen Arnold committed
419
420
421
422
423
424
425
426
427
428
429
430
431
432
/**
 * Get peak size into the projection
 * @return size
 */
double CompositePeaksPresenter::getPeakSizeIntoProjection() const {
  if (useDefault()) {
    return m_default->getPeakSizeIntoProjection();
  }
  double result = 0;
  for (auto it = m_subjects.begin(); it != m_subjects.end(); ++it) {
    double temp = (*it)->getPeakSizeIntoProjection();
    if (temp > 0) {
      result = temp;
      break;
433
    }
Owen Arnold's avatar
Owen Arnold committed
434
435
436
  }
  return result;
}
437

Owen Arnold's avatar
Owen Arnold committed
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
/**
 * Determine if the background is to be shown for a particular workspace.
 * @param ws
 * @return
 */
bool CompositePeaksPresenter::getShowBackground(
    boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws) const {
  if (useDefault()) {
    throw std::runtime_error("Get show background cannot be fetched until "
                             "nested presenters are added.");
  }
  SubjectContainer::const_iterator iterator =
      getPresenterIteratorFromWorkspace(ws);
  return (*iterator)->getShowBackground();
}
453

Owen Arnold's avatar
Owen Arnold committed
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
namespace {
// Helper comparitor type.
class MatchWorkspaceName
    : public std::unary_function<SetPeaksWorkspaces::value_type, bool> {
private:
  const QString m_wsName;

public:
  MatchWorkspaceName(const QString &name) : m_wsName(name) {}
  bool operator()(SetPeaksWorkspaces::value_type ws) {
    const std::string wsName = ws->name();
    const std::string toMatch = m_wsName.toStdString();
    const bool result = (wsName == toMatch);
    return result;
  }
};
}
471

Owen Arnold's avatar
Owen Arnold committed
472
473
474
475
476
477
478
479
480
481
482
483
CompositePeaksPresenter::SubjectContainer::iterator
CompositePeaksPresenter::getPresenterIteratorFromName(const QString &name) {
  MatchWorkspaceName comparitor(name);
  SubjectContainer::iterator presenterFound = m_subjects.end();
  for (auto presenterIterator = m_subjects.begin();
       presenterIterator != m_subjects.end(); ++presenterIterator) {
    auto wsOfSubject = (*presenterIterator)->presentedWorkspaces();
    SetPeaksWorkspaces::iterator iteratorFound =
        std::find_if(wsOfSubject.begin(), wsOfSubject.end(), comparitor);
    if (iteratorFound != wsOfSubject.end()) {
      presenterFound = presenterIterator;
      break;
484
    }
Owen Arnold's avatar
Owen Arnold committed
485
486
487
  }
  return presenterFound;
}
488

Owen Arnold's avatar
Owen Arnold committed
489
/**
Owen Arnold's avatar
Owen Arnold committed
490
 * Get the peaks presenter corresponding to a peaks workspace name.
Owen Arnold's avatar
Owen Arnold committed
491
492
493
494
495
496
497
498
499
500
501
502
503
 * @param name
 * @return Peaks presenter.
 */
PeaksPresenter *
CompositePeaksPresenter::getPeaksPresenter(const QString &name) {
  SubjectContainer::iterator presenterFound =
      this->getPresenterIteratorFromName(name);
  if (presenterFound == m_subjects.end()) {
    throw std::invalid_argument("Cannot find peaks workspace called :" +
                                name.toStdString());
  }
  return (*presenterFound).get();
}
504

Owen Arnold's avatar
Owen Arnold committed
505
506
507
508
509
510
511
512
/**
 * Register an owning presenter for this object.
 * @param owner
 */
void
CompositePeaksPresenter::registerOwningPresenter(UpdateableOnDemand *owner) {
  m_owner = owner;
}
513

Owen Arnold's avatar
Owen Arnold committed
514
515
516
517
518
519
520
521
522
523
524
525
526
527
/**
 * Perform steps associated with an update. Driven by nested presenters.
 */
void CompositePeaksPresenter::performUpdate() {
  for (auto presenterIterator = m_subjects.begin();
       presenterIterator != m_subjects.end(); ++presenterIterator) {
    auto presenter = (*presenterIterator);
    const int pos =
        static_cast<int>(std::distance(m_subjects.begin(), presenterIterator));
    m_palette.setBackgroundColour(pos, presenter->getBackgroundColor());
    m_palette.setForegroundColour(pos, presenter->getForegroundColor());

    if (m_owner) {
      m_owner->performUpdate();
528
    }
Owen Arnold's avatar
Owen Arnold committed
529
530
  }
}
531

Owen Arnold's avatar
Owen Arnold committed
532
533
534
535
536
namespace {
// Private helper class
class MatchPointer : public std::unary_function<bool, PeaksPresenter_sptr> {
private:
  PeaksPresenter *m_toFind;
537

Owen Arnold's avatar
Owen Arnold committed
538
539
540
541
542
543
544
public:
  MatchPointer(PeaksPresenter *toFind) : m_toFind(toFind) {}
  bool operator()(PeaksPresenter_sptr candidate) {
    return candidate.get() == m_toFind;
  }
};
}
545

Owen Arnold's avatar
Owen Arnold committed
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
/**
 * Zoom to a peak
 * @param presenter: Holds the peaks workspace.
 * @param peakIndex: The peak index.
 */
void CompositePeaksPresenter::zoomToPeak(PeaksPresenter *const presenter,
                                         const int peakIndex) {

  MatchPointer comparitor(presenter);
  m_zoomedPeakIndex = peakIndex;
  SubjectContainer::iterator it =
      std::find_if(m_subjects.begin(), m_subjects.end(), comparitor);
  if (it == m_subjects.end()) {
    throw std::invalid_argument(
        "Cannot file subject presenter at CompositePeaksPresenter::zoomToPeak");
  }
  const PeakBoundingBox &box = presenter->getBoundingBox(peakIndex);
  m_zoomablePlottingWidget->zoomToRectangle(box);
  m_zoomedPresenter = *it;
  m_zoomedPeakIndex = peakIndex;
  if (m_owner) {
    m_owner->performUpdate();
  }
}
570

Owen Arnold's avatar
Owen Arnold committed
571
572
573
574
575
576
577
578
579
580
581
/**
 * Determine if the presenter is hidden.
 * @param peaksWS to use to find the right presenter.
 * @return True if hidden.
 */
bool CompositePeaksPresenter::getIsHidden(
    boost::shared_ptr<const Mantid::API::IPeaksWorkspace> peaksWS) const {
  auto iterator = getPresenterIteratorFromWorkspace(peaksWS);
  auto subjectPresenter = *iterator;
  return subjectPresenter->isHidden();
}
582

Owen Arnold's avatar
Owen Arnold committed
583
584
585
586
587
588
589
590
591
592
593
594
/**
 * Reset the zoom.
 * Forget any optional zoom extents.
 */
void CompositePeaksPresenter::resetZoom() {
  m_zoomedPeakIndex = -1;
  m_zoomedPresenter.reset();
  if (m_owner) {
    m_owner->performUpdate(); // This tells any 'listening GUIs' to sort
                              // themselves out.
  }
}
595

Owen Arnold's avatar
Owen Arnold committed
596
597
598
599
600
601
602
/**
 * @return an optional zoomed peak presenter.
 */
boost::optional<PeaksPresenter_sptr>
CompositePeaksPresenter::getZoomedPeakPresenter() const {
  return m_zoomedPresenter;
}
603

Owen Arnold's avatar
Owen Arnold committed
604
605
606
607
608
609
/**
 * @return a zoomed peak index.
 */
int CompositePeaksPresenter::getZoomedPeakIndex() const {
  return m_zoomedPeakIndex;
}
610

Owen Arnold's avatar
Owen Arnold committed
611
612
613
614
615
616
617
void CompositePeaksPresenter::updatePeaksWorkspace(
    const std::string &toName,
    boost::shared_ptr<const Mantid::API::IPeaksWorkspace> toWorkspace) {
  if (m_owner) {
    m_owner->updatePeaksWorkspace(toName, toWorkspace);
  }
}
618

Owen Arnold's avatar
Owen Arnold committed
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
void CompositePeaksPresenter::notifyWorkspaceChanged(
    const std::string &wsName,
    Mantid::API::IPeaksWorkspace_sptr &changedPeaksWS) {
  // Try to find the peaks workspace via location, in the case of changes
  // involving in-place operations.
  auto iterator = this->getPresenterIteratorFromWorkspace(changedPeaksWS);

  // If the above strategy fails. Look for a presenter via a name.
  if (iterator == m_subjects.end()) {
    // Try to find the peaks workspace via name in the case of changes involving
    // changes to ADS values, but no changes to keys (copy-swap type
    // operations).

    // The peaks workspace location may have changed, but the workspace name has
    // not.
    iterator = this->getPresenterIteratorFromName(
        wsName.c_str()); // TODO. don't ask the peaks workspace for it's name
                         // directly as it gets it from the workspace object,
                         // and that object would have been changed!
    if (iterator == m_subjects.end()) {
      return;
640
    }
Owen Arnold's avatar
Owen Arnold committed
641
642
643
  }
  const int pos = static_cast<int>(std::distance(m_subjects.begin(), iterator));
  m_subjects[pos]->reInitialize(changedPeaksWS);
644

Owen Arnold's avatar
Owen Arnold committed
645
646
647
648
649
650
651
  auto presentedWorkspaces = m_subjects[pos]->presentedWorkspaces();
  // We usually only have a single workspace, but just incase there are more.
  if (m_owner) {
    for (SetPeaksWorkspaces::iterator it = presentedWorkspaces.begin();
         it != presentedWorkspaces.end(); ++it) {
      m_owner->updatePeaksWorkspace(wsName, *it);
    }
652
  }
653
}
Owen Arnold's avatar
Owen Arnold committed
654
655
}
}