-
Notifications
You must be signed in to change notification settings - Fork 122
/
ViewBase.cpp
917 lines (828 loc) · 27.7 KB
/
ViewBase.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
#include "MantidVatesSimpleGuiViewWidgets/ViewBase.h"
#include "MantidVatesSimpleGuiViewWidgets/BackgroundRgbProvider.h"
#include "MantidVatesSimpleGuiViewWidgets/RebinnedSourcesManager.h"
#include "MantidVatesAPI/ADSWorkspaceProvider.h"
#include "MantidAPI/IMDEventWorkspace.h"
#include "MantidVatesAPI/BoxInfo.h"
#if defined(__INTEL_COMPILER)
#pragma warning disable 1170
#endif
#include <pqActiveObjects.h>
#include <pqAnimationManager.h>
#include <pqAnimationScene.h>
#include <pqApplicationCore.h>
#include <pqDataRepresentation.h>
#include <pqDeleteReaction.h>
#include <pqObjectBuilder.h>
#include <pqPipelineFilter.h>
#include <pqPipelineRepresentation.h>
#include <pqPipelineSource.h>
#include <pqPVApplicationCore.h>
#include <pqRenderView.h>
#include <pqScalarsToColors.h>
#include <pqServer.h>
#include <pqServerManagerModel.h>
#include <pqView.h>
#include <vtkSMDoubleVectorProperty.h>
#include <vtkSMPropertyHelper.h>
#include <vtkSMPropertyIterator.h>
#include <vtkSMProxy.h>
#include <vtkSMSourceProxy.h>
#if defined(__INTEL_COMPILER)
#pragma warning enable 1170
#endif
#include <QDebug>
#include <QHBoxLayout>
#include <QPointer>
#include <QSet>
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
#include <boost/optional.hpp>
#include <stdexcept>
namespace Mantid
{
namespace Vates
{
namespace SimpleGui
{
/**
* Default constructor.
* @param parent the parent widget for the view
* @param rebinnedSourcesManager Pointer to a RebinnedSourcesManager
*/
ViewBase::ViewBase(QWidget *parent, RebinnedSourcesManager* rebinnedSourcesManager) : QWidget(parent),
m_rebinnedSourcesManager(rebinnedSourcesManager), m_currentColorMapModel(NULL), m_internallyRebinnedWorkspaceIdentifier("rebinned_vsi")
{
}
/**
* This function creates a single standard ParaView view instance.
* @param widget the UI widget to associate the view with
* @param viewName the requested view type, if empty will default to RenderView
* @return the created view
*/
pqRenderView* ViewBase::createRenderView(QWidget* widget, QString viewName)
{
QHBoxLayout *hbox = new QHBoxLayout(widget);
hbox->setMargin(0);
if (viewName == QString(""))
{
viewName = pqRenderView::renderViewType();
}
// Create a new render view.
pqObjectBuilder* builder = pqApplicationCore::instance()->getObjectBuilder();
pqRenderView *view = qobject_cast<pqRenderView*>(\
builder->createView(viewName,
pqActiveObjects::instance().activeServer()));
pqActiveObjects::instance().setActiveView(view);
// Place the widget for the render view in the frame provided.
hbox->addWidget(view->getWidget());
/// Make a connection to the view's endRender signal for later checking.
QObject::connect(view, SIGNAL(endRender()),
this, SIGNAL(renderingDone()));
return view;
}
/**
* This function removes all filters of a given name: i.e. Slice.
* @param name the class name of the filters to remove
*/
void ViewBase::destroyFilter(const QString &name)
{
pqServer *server = pqActiveObjects::instance().activeServer();
pqServerManagerModel *smModel = pqApplicationCore::instance()->getServerManagerModel();
QList<pqPipelineSource *> sources;
QList<pqPipelineSource *>::Iterator source;
sources = smModel->findItems<pqPipelineSource *>(server);
QSet<pqPipelineSource*> toDelete;
for (source = sources.begin(); source != sources.end(); ++source)
{
const QString sourceName = (*source)->getSMName();
if (sourceName.startsWith(name))
{
toDelete.insert(*source);
}
}
pqDeleteReaction::deleteSources(toDelete);
}
/**
* This function is responsible for setting the color scale range from the
* full extent of the data.
* @param colorSelectionWidget Pointer to the color selection widget.
*/
void ViewBase::onAutoScale(ColorSelectionWidget* colorSelectionWidget)
{
// Update the colorUpdater
this->colorUpdater.updateState(colorSelectionWidget);
if (this->colorUpdater.isAutoScale())
{
this->setAutoColorScale();
}
}
/**
* Set the color scale for auto color scaling.
*
*/
void ViewBase::setAutoColorScale()
{
VsiColorScale colorScale;
try
{
colorScale = this->colorUpdater.autoScale();
}
catch (std::invalid_argument &)
{
// Got a bad proxy or color scale range, so do nothing
return;
}
// Set the color scale widget
emit this->dataRange(colorScale.minValue, colorScale.maxValue);
emit this->setLogScale(colorScale.useLogScale);
}
/**
* This function sets the requested color map on the data.
* @param model the color map to use
*/
void ViewBase::onColorMapChange(const pqColorMapModel *model)
{
pqPipelineRepresentation *rep = this->getRep();
if (NULL == rep)
{
return;
}
// Work around a "bug" in pqScalarToColors::checkRange() where the lower
// limit gets lost when log scaling is used. This only happens when
// changing the color map.
bool logStateChanged = false;
if (this->colorUpdater.isLogScale())
{
this->colorUpdater.logScale(false);
logStateChanged = true;
}
this->colorUpdater.colorMapChange(rep, model);
if (logStateChanged)
{
this->colorUpdater.logScale(true);
}
rep->renderViewEventually();
if (this->colorUpdater.isAutoScale())
{
setAutoColorScale();
}
// Workaround for colormap but when changing the visbility of a source
this->m_currentColorMapModel = model;
}
/**
* This function sets the data color scale range to the requested bounds.
* @param min the minimum bound for the color scale
* @param max the maximum bound for the color scale
*/
void ViewBase::onColorScaleChange(double min, double max)
{
this->colorUpdater.colorScaleChange(min, max);
}
/**
* This function sets logarithmic color scaling on the data.
* @param state Flag to determine whether or not to use log color scaling
*/
void ViewBase::onLogScale(int state)
{
this->colorUpdater.logScale(state);
}
/**
* This function passes the color selection widget to the color updater
* object.
* @param cs : Reference to the color selection widget
*/
void ViewBase::setColorScaleState(ColorSelectionWidget *cs)
{
this->colorUpdater.updateState(cs);
}
/**
* This function checks the current state from the color updater and
* processes the necessary color changes.
* @param colorScale A pointer to the colorscale widget.
*/
void ViewBase::setColorsForView(ColorSelectionWidget *colorScale)
{
// Update the colorupdater with the settings of the colorSelectionWidget
setColorScaleState(colorScale);
if (this->colorUpdater.isAutoScale())
{
this->onAutoScale(colorScale);
}
else
{
this->onColorScaleChange(this->colorUpdater.getMinimumRange(),
this->colorUpdater.getMaximumRange());
}
if (this->colorUpdater.isLogScale())
{
this->onLogScale(true);
}
}
/**
* This function checks a pqPipelineSource (either from a file or workspace)
* to see if it is derived from a PeaksWorkspace.
* @param src the pipeline source to check
* @return true if the pipeline source is derived from PeaksWorkspace
*/
bool ViewBase::isPeaksWorkspace(pqPipelineSource *src)
{
if (NULL == src)
{
return false;
}
QString wsType(vtkSMPropertyHelper(src->getProxy(),
"WorkspaceTypeName", true).GetAsString());
if (wsType.isEmpty())
{
wsType = src->getSMName();
}
return wsType.contains("PeaksWorkspace");
}
/**
* This function retrieves the active pqPipelineRepresentation object according
* to ParaView's ActiveObjects mechanism.
* @return the currently active representation
*/
pqPipelineRepresentation *ViewBase::getPvActiveRep()
{
pqDataRepresentation *drep = pqActiveObjects::instance().activeRepresentation();
return qobject_cast<pqPipelineRepresentation *>(drep);
}
/**
* This function creates a ParaView source from a given plugin name and
* workspace name. This is used in the plugin mode of the simple interface.
* @param pluginName name of the ParaView plugin
* @param wsName name of the Mantid workspace to pass to the plugin
*/
pqPipelineSource* ViewBase::setPluginSource(QString pluginName, QString wsName)
{
// Create the source from the plugin
pqObjectBuilder* builder = pqApplicationCore::instance()->getObjectBuilder();
pqServer *server = pqActiveObjects::instance().activeServer();
pqPipelineSource *src = builder->createSource("sources", pluginName,
server);
src->getProxy()->SetAnnotation("MdViewerWidget0", "1");
vtkSMPropertyHelper(src->getProxy(),
"Mantid Workspace Name").Set(wsName.toStdString().c_str());
// WORKAROUND BEGIN
// We are setting the recursion depth to 1 when we are dealing with MDEvent workspaces
// with top level splitting, but this is not updated in the plugin line edit field.
// We do this here.
if (auto split = Mantid::VATES::findRecursionDepthForTopLevelSplitting(wsName.toStdString())) {
vtkSMPropertyHelper(src->getProxy(),
"Recursion Depth").Set(split.get());
}
// WORKAROUND END
// Update the source so that it retrieves the data from the Mantid workspace
src->getProxy()->UpdateVTKObjects(); // Updates all the proxies
src->updatePipeline(); // Updates the pipeline
src->setModifiedState(pqProxy::UNMODIFIED); // Just to that the UI state looks consistent with the apply
// Update the properties, from PV3.98.1 to PV4.3.1, it wasn't updating any longer, so need to force it
src->getProxy()->UpdatePropertyInformation();
return src;
}
/**
* This function retrieves the active pqPipelineSource object according to ParaView's
* ActiveObjects mechanism.
* @return the currently active source
*/
pqPipelineSource *ViewBase::getPvActiveSrc()
{
return pqActiveObjects::instance().activeSource();
}
/**
* This function sets the status for the view mode control buttons. This
* implementation looks at the original source for a view. Views may override
* this function to provide alternate checks.
* @param initialView The initial view.
*/
void ViewBase::checkView(ModeControlWidget::Views initialView)
{
if (this->isMDHistoWorkspace(this->origSrc))
{
emit this->setViewsStatus(initialView, true);
emit this->setViewStatus(ModeControlWidget::SPLATTERPLOT, false);
}
else if (this->isPeaksWorkspace(this->origSrc))
{
emit this->setViewsStatus(initialView, false);
}
else
{
emit this->setViewsStatus(initialView, true);
}
}
/**
* This metod sets the status of the splatterplot button explictly to a desired value
* @param visibility The state of the the splatterplot view button.
*/
void ViewBase::setSplatterplot(bool visibility)
{
emit this->setViewStatus(ModeControlWidget::SPLATTERPLOT, visibility);
}
/**
* This metod sets the status of the standard view button explictly to a desired value
* @param visibility The state of the the standard view button.
*/
void ViewBase::setStandard(bool visibility)
{
emit this->setViewStatus(ModeControlWidget::STANDARD, visibility);
}
/**
* This function sets the status for the view mode control buttons when the
* view switches.
*/
void ViewBase::checkViewOnSwitch()
{
if (this->hasWorkspaceType("MDHistoWorkspace"))
{
emit this->setViewStatus(ModeControlWidget::SPLATTERPLOT, false);
}
}
/**
* This function is responsible for checking if a pipeline source has time
* step information. If not, it will disable the animation controls. If the
* pipeline source has time step information, the animation controls will be
* enabled.
*/
void ViewBase::updateAnimationControls()
{
pqPipelineSource *src = this->getPvActiveSrc();
unsigned int numSrcs = this->getNumSources();
if (this->isPeaksWorkspace(src))
{
if (1 == numSrcs)
{
emit this->setAnimationControlState(false);
return;
}
if (2 <= numSrcs)
{
return;
}
}
vtkSMSourceProxy *srcProxy1 = vtkSMSourceProxy::SafeDownCast(src->getProxy());
srcProxy1->Modified();
srcProxy1->UpdatePipelineInformation();
vtkSMDoubleVectorProperty *tsv = vtkSMDoubleVectorProperty::SafeDownCast(\
srcProxy1->GetProperty("TimestepValues"));
this->handleTimeInfo(tsv);
}
/**
* This function looks through the ParaView server manager model and finds
* those pipeline sources whose server manager group name is "sources". It
* returns the total count of those present;
* @return the number of true pipeline sources
*/
unsigned int ViewBase::getNumSources()
{
unsigned int count = 0;
pqServer *server = pqActiveObjects::instance().activeServer();
pqServerManagerModel *smModel = pqApplicationCore::instance()->getServerManagerModel();
QList<pqPipelineSource *> sources;
QList<pqPipelineSource *>::Iterator source;
sources = smModel->findItems<pqPipelineSource *>(server);
for (source = sources.begin(); source != sources.end(); ++source)
{
const QString srcProxyName = (*source)->getProxy()->GetXMLGroup();
if (srcProxyName == QString("sources"))
{
count++;
}
}
return count;
}
/**
* This function takes the incoming property and determines the number of
* "time" steps. It enables/disables the animation controls widget based on
* the number of "time" steps.
* @param dvp the vector property containing the "time" information
*/
void ViewBase::handleTimeInfo(vtkSMDoubleVectorProperty *dvp)
{
if (NULL == dvp)
{
// This is a normal filter and therefore has no timesteps.
//qDebug() << "No timestep vector, returning.";
return;
}
const int numTimesteps = static_cast<int>(dvp->GetNumberOfElements());
//qDebug() << "# timesteps: " << numTimesteps;
if (1 < numTimesteps)
{
double tStart = dvp->GetElement(0);
double tEnd = dvp->GetElement(dvp->GetNumberOfElements() - 1);
emit this->setAnimationControlInfo(tStart, tEnd, numTimesteps);
emit this->setAnimationControlState(true);
}
else
{
emit this->setAnimationControlState(false);
}
}
/**
* This function takes a given set of coordinates and resets the center of
* rotation of the view to that given point.
* @param x the x coordinate of the center point
* @param y the y coordinate of the center point
* @param z the z coordinate of the center point
*/
void ViewBase::onResetCenterToPoint(double x, double y, double z)
{
pqRenderView *renderView = this->getPvActiveView();
pqDataRepresentation* repr = pqActiveObjects::instance().activeRepresentation();
if (!repr || !renderView)
{
//qDebug() << "Active source not shown in active view. Cannot set center.";
return;
}
double center[3];
center[0] = x;
center[1] = y;
center[2] = z;
renderView->setCenterOfRotation(center);
renderView->render();
}
/**
* This function is used to set the current state of the view between a
* parallel projection and the normal projection.
* @param state whether or not to use parallel projection
*/
void ViewBase::onParallelProjection(bool state)
{
pqRenderView *cview = this->getPvActiveView();
vtkSMProxy *proxy = cview->getProxy();
vtkSMPropertyHelper(proxy, "CameraParallelProjection").Set(state);
proxy->UpdateVTKObjects();
cview->render();
}
/**
* This function is used to set the LOD threshold for the view.
* @param state : whether or not to use the LOD threshold
* @param defVal : default value of LOD threshold
*/
void ViewBase::onLodThresholdChange(bool state, double defVal)
{
pqRenderView *cview = this->getPvActiveView();
vtkSMProxy *proxy = cview->getProxy();
if (state)
{
vtkSMPropertyHelper(proxy, "LODThreshold").Set(defVal);
}
else
{
vtkSMPropertyHelper(proxy, "LODThreshold").Set(VTK_DOUBLE_MAX);
}
proxy->UpdateVTKObjects();
cview->render();
}
/**
* This function retrieves the active pqRenderView object according to
* ParaView's ActiveObjects mechanism.
* @return the currently active view
*/
pqRenderView *ViewBase::getPvActiveView()
{
return qobject_cast<pqRenderView*>(pqActiveObjects::instance().activeView());
}
/**
* This function checks the original pipeline object for the WorkspaceName
* property. This will get an empty string if the simple interface is
* launched in standalone mode.
* @return the workspace name for the original pipeline object
*/
QString ViewBase::getWorkspaceName()
{
pqServerManagerModel *smModel = pqApplicationCore::instance()->getServerManagerModel();
pqPipelineSource *src = smModel->getItemAtIndex<pqPipelineSource *>(0);
QString wsName(vtkSMPropertyHelper(src->getProxy(),
"WorkspaceName",
true).GetAsString());
return wsName;
}
/**
* This function gets a property iterator from the source proxy and iterates
* over the properties, printing out the keys.
* @param src pqPipelineSource to print properties from
*/
void ViewBase::printProxyProps(pqPipelineSource *src)
{
std::cout << src->getSMName().toStdString() << " Properties:" << std::endl;
vtkSMPropertyIterator *piter = src->getProxy()->NewPropertyIterator();
while ( !piter->IsAtEnd() )
{
std::cout << piter->GetKey() << std::endl;
piter->Next();
}
}
/**
* This function iterrogates the pqPipelineSource for the TimestepValues
* property. It then checks to see if the number of timesteps is non-zero.
* @param src pqPipelineSource to check for timesteps
* @return true if pqPipelineSource has a non-zero number of timesteps
*/
bool ViewBase::srcHasTimeSteps(pqPipelineSource *src)
{
vtkSMSourceProxy *srcProxy1 = vtkSMSourceProxy::SafeDownCast(src->getProxy());
srcProxy1->Modified();
srcProxy1->UpdatePipelineInformation();
vtkSMDoubleVectorProperty *tsv = vtkSMDoubleVectorProperty::SafeDownCast(\
srcProxy1->GetProperty("TimestepValues"));
const unsigned int numTimesteps = tsv->GetNumberOfElements();
return 0 < numTimesteps;
}
/**
* This function retrieves the current timestep as determined by ParaView's
* AnimationManager.
* @return the current timestep from the animation scene
*/
double ViewBase::getCurrentTimeStep()
{
pqAnimationManager* mgr = pqPVApplicationCore::instance()->animationManager();
pqAnimationScene *scene = mgr->getActiveScene();
return scene->getAnimationTime();
}
/**
* This function will close view generated sub-windows. Most views will not
* reimplement this function, so the default is to do nothing.
*/
void ViewBase::closeSubWindows()
{
}
/**
* This function returns the representation appropriate for the request. It
* checks the ParaView active representation first. If that can't be found, the
* fallback is to check the original representation associated with the view.
* @return the discovered representation
*/
pqPipelineRepresentation *ViewBase::getRep()
{
pqPipelineRepresentation *rep = this->getPvActiveRep();
if (NULL == rep)
{
rep = this->origRep;
}
return rep;
}
/**
* This function checks if a pqPipelineSource is a MDHistoWorkspace.
* @return true if the source is a MDHistoWorkspace
*/
bool ViewBase::isMDHistoWorkspace(pqPipelineSource *src)
{
if (NULL == src)
{
return false;
}
QString wsType(vtkSMPropertyHelper(src->getProxy(),
"WorkspaceTypeName", true).GetAsString());
if (wsType.isEmpty())
{
wsType = src->getSMName();
}
return wsType.contains("MDHistoWorkspace");
}
/**
* This function checks if a pqPipelineSource is an internally rebinned workspace.
* @return true if the source is an internally rebinned workspace;
*/
bool ViewBase::isInternallyRebinnedWorkspace(pqPipelineSource *src)
{
if (NULL == src)
{
return false;
}
QString wsType(vtkSMPropertyHelper(src->getProxy(),
"WorkspaceTypeName", true).GetAsString());
if (wsType.isEmpty())
{
wsType = src->getSMName();
}
QString wsName(vtkSMPropertyHelper(src->getProxy(),
"WorkspaceName", true).GetAsString());
if (wsName.contains(m_internallyRebinnedWorkspaceIdentifier) && m_rebinnedSourcesManager->isRebinnedSourceBeingTracked(src))
{
return true;
}
else
{
return false;
}
}
/**
* This function is where one specifies updates to the UI components for a
* view.
*/
void ViewBase::updateUI()
{
}
/**
* This function is where one specifies updates to the held view.
*/
void ViewBase::updateView()
{
}
/// This function is used to update settings, such as background color etc.
void ViewBase::updateSettings()
{
this->backgroundRgbProvider.update();
}
/**
* This function checks the current pipeline for a filter with the specified
* name. The function works for generic filter names only.
* @param name the name of the filter to search for
* @return true if the filter is found
*/
bool ViewBase::hasFilter(const QString &name)
{
pqServer *server = pqActiveObjects::instance().activeServer();
pqServerManagerModel *smModel = pqApplicationCore::instance()->getServerManagerModel();
QList<pqPipelineSource *> sources;
QList<pqPipelineSource *>::Iterator source;
sources = smModel->findItems<pqPipelineSource *>(server);
for (source = sources.begin(); source != sources.end(); ++source)
{
const QString sourceName = (*source)->getSMName();
if (sourceName.startsWith(name))
{
return true;
}
}
return false;
}
/**
* This function looks through all pipeline sources for one containing the given
* workspace name. It hands back a null pointer if that name can't be found.
* @param name : The workspace name to search for
* @return : Pointer to the pipeline source if found
*/
pqPipelineSource *ViewBase::hasWorkspace(const QString &name)
{
pqServer *server = pqActiveObjects::instance().activeServer();
pqServerManagerModel *smModel = pqApplicationCore::instance()->getServerManagerModel();
QList<pqPipelineSource *> sources;
QList<pqPipelineSource *>::Iterator source;
sources = smModel->findItems<pqPipelineSource *>(server);
for (source = sources.begin(); source != sources.end(); ++source)
{
QString wsName(vtkSMPropertyHelper((*source)->getProxy(),
"WorkspaceName", true).GetAsString());
if (!wsName.isEmpty())
{
if (wsName == name)
{
return (*source);
}
}
}
return NULL;
}
/**
* This function looks through all pipeline sources for one containing the given
* workspace typename.
* @param wsTypeName : The workspace typename (Id) to look for.
* @return : True if a source is found with the workspace type.
*/
bool ViewBase::hasWorkspaceType(const QString &wsTypeName)
{
pqServer *server = pqActiveObjects::instance().activeServer();
pqServerManagerModel *smModel = pqApplicationCore::instance()->getServerManagerModel();
QList<pqPipelineSource *> sources;
QList<pqPipelineSource *>::Iterator source;
sources = smModel->findItems<pqPipelineSource *>(server);
bool hasWsType = false;
for (source = sources.begin(); source != sources.end(); ++source)
{
QString wsType(vtkSMPropertyHelper((*source)->getProxy(),
"WorkspaceTypeName", true).GetAsString());
if (wsType.isEmpty())
{
wsType = (*source)->getSMName();
}
hasWsType = wsType.contains(wsTypeName);
if (hasWsType)
{
break;
}
}
return hasWsType;
}
/**
* This function sets the default colors for the background and connects a tracker for changes of the background color by the user.
* @param useCurrentColorSettings If the view was switched or created.
*/
void ViewBase::setColorForBackground(bool useCurrentColorSettings)
{
backgroundRgbProvider.setBackgroundColor(this->getView(), useCurrentColorSettings);
backgroundRgbProvider.observe(this->getView());
}
/**
* React to a change of the visibility of a representation of a source.
* This can be a change of the status if the "eye" symbol in the PipelineBrowserWidget
* as well as the addition or removal of a representation.
* @param source The pipeleine source assoicated with the call.
* @param representation The representation associatied with the call
*/
void ViewBase::onVisibilityChanged(pqPipelineSource*, pqDataRepresentation*)
{
// Reset the colorscale if it is set to autoscale
if (colorUpdater.isAutoScale())
{
// Workaround: A ParaView bug requires us to reload the ColorMap when the visibility changes.
if (m_currentColorMapModel) {
onColorMapChange(m_currentColorMapModel);
}
this->setAutoColorScale();
}
}
/**
* Initializes the settings of the color scale
*/
void ViewBase::initializeColorScale()
{
colorUpdater.initializeColorScale();
}
/**
* This function reacts to a destroyed source.
*/
void ViewBase::onSourceDestroyed()
{
}
/**
* Destroy all sources in the view.
*/
void ViewBase::destroyAllSourcesInView() {
pqServer *server = pqActiveObjects::instance().activeServer();
pqServerManagerModel *smModel = pqApplicationCore::instance()->getServerManagerModel();
QList<pqPipelineSource *> sources = smModel->findItems<pqPipelineSource *>(server);
// Out of all pqPipelineSources, find the "true" sources, which were
// created by a Source Plugin, i.e. MDEW Source, MDHW Source, PeakSource
QList<pqPipelineSource*> trueSources;
for (QList<pqPipelineSource *>::iterator source = sources.begin(); source != sources.end(); ++source) {
if (!qobject_cast<pqPipelineFilter*>(*source)) {
trueSources.push_back(*source);
}
}
// For each true source, go to the end of the pipeline and destroy it on the way back
// to the start. This assumes linear pipelines.
for (QList<pqPipelineSource *>::iterator trueSource = trueSources.begin(); trueSource != trueSources.end(); ++trueSource) {
destroySinglePipeline(*trueSource);
}
}
/**
* Destroy a single, linear pipeline
* @param source A true pqPiplineSource, i.e. not a filter.
*/
void ViewBase::destroySinglePipeline(pqPipelineSource * source) {
pqObjectBuilder* builder = pqApplicationCore::instance()->getObjectBuilder();
// Move to the end of the pipeline
pqPipelineSource *sourceBuffer = source;
while(sourceBuffer->getNumberOfConsumers() > 0) {
sourceBuffer = sourceBuffer->getConsumer(0);
}
// Now destroy the pipeline coming back again
pqPipelineFilter* filter = qobject_cast<pqPipelineFilter*>(sourceBuffer);
while(filter) {
sourceBuffer = filter->getInput(0);
builder->destroy(filter);
filter = qobject_cast<pqPipelineFilter*>(sourceBuffer);
}
builder->destroy(sourceBuffer);
}
/**
* Set the listener for the visibility of the representations
*/
void ViewBase::setVisibilityListener()
{
// Set the connection to listen to a visibility change of the representation.
pqServer *server = pqActiveObjects::instance().activeServer();
pqServerManagerModel *smModel = pqApplicationCore::instance()->getServerManagerModel();
QList<pqPipelineSource *> sources;
sources = smModel->findItems<pqPipelineSource *>(server);
// Attach the visibilityChanged signal for all sources.
for (QList<pqPipelineSource *>::iterator source = sources.begin(); source != sources.end(); ++source)
{
QObject::connect((*source), SIGNAL(visibilityChanged(pqPipelineSource*, pqDataRepresentation*)),
this, SLOT(onVisibilityChanged(pqPipelineSource*, pqDataRepresentation*)),
Qt::UniqueConnection);
}
}
/**
* Disconnects the visibility listener connection for all sources
*/
void ViewBase::removeVisibilityListener() {
// Set the connection to listen to a visibility change of the representation.
pqServer *server = pqActiveObjects::instance().activeServer();
pqServerManagerModel *smModel = pqApplicationCore::instance()->getServerManagerModel();
QList<pqPipelineSource *> sources;
sources = smModel->findItems<pqPipelineSource *>(server);
// Attach the visibilityChanged signal for all sources.
for (QList<pqPipelineSource *>::iterator source = sources.begin(); source != sources.end(); ++source)
{
QObject::disconnect((*source), SIGNAL(visibilityChanged(pqPipelineSource*, pqDataRepresentation*)),
this, SLOT(onVisibilityChanged(pqPipelineSource*, pqDataRepresentation*)));
}
}
} // namespace SimpleGui
} // namespace Vates
} // namespace Mantid