Salome HOME
V2008a - invoking cmake from configure and remaining plugins
[modules/paravis.git] / src / Plugins / View / MyView.cxx
1
2 #include "MyView.h"
3
4 #include <QLabel>
5 #include <QVBoxLayout>
6 #include <QWidget>
7 #include <vtkSMProxy.h>
8
9 #include <pqOutputPort.h>
10 #include <pqPipelineSource.h>
11 #include <pqRepresentation.h>
12 #include <pqServer.h>
13
14 MyView::MyView(const QString& viewmoduletype, 
15        const QString& group, 
16        const QString& name, 
17        vtkSMViewProxy* viewmodule, 
18        pqServer* server, 
19        QObject* p)
20  : pqView(viewmoduletype, group, name, viewmodule, server, p)
21 {
22   // our view is just a simple QWidget
23   this->MyWidget = new QWidget;
24   this->MyWidget->setAutoFillBackground(true);
25   new QVBoxLayout(this->MyWidget);
26
27   // connect to display creation so we can show them in our view
28   this->connect(this, SIGNAL(representationAdded(pqRepresentation*)),
29     SLOT(onRepresentationAdded(pqRepresentation*)));
30   this->connect(this, SIGNAL(representationRemoved(pqRepresentation*)),
31     SLOT(onRepresentationRemoved(pqRepresentation*)));
32 }
33
34 MyView::~MyView()
35 {
36   delete this->MyWidget;
37 }
38
39
40 QWidget* MyView::getWidget()
41 {
42   return this->MyWidget;
43 }
44
45 void MyView::onRepresentationAdded(pqRepresentation* d)
46 {
47   // add a label with the display id
48   QLabel* l = new QLabel(
49     QString("Display (%1)").arg(d->getProxy()->GetSelfIDAsString()), 
50     this->MyWidget);
51   this->MyWidget->layout()->addWidget(l);
52   this->Labels.insert(d, l);
53 }
54
55 void MyView::onRepresentationRemoved(pqRepresentation* d)
56 {
57   // remove the label
58   QLabel* l = this->Labels.take(d);
59   if(l)
60     {
61     this->MyWidget->layout()->removeWidget(l);
62     delete l;
63     }
64 }
65
66 void MyView::setBackground(const QColor& c)
67 {
68   QPalette p = this->MyWidget->palette();
69   p.setColor(QPalette::Window, c);
70   this->MyWidget->setPalette(p);
71 }
72
73 QColor MyView::background() const
74 {
75   return this->MyWidget->palette().color(QPalette::Window);
76 }
77
78 bool MyView::canDisplay(pqOutputPort* opPort) const
79 {
80   pqPipelineSource* source = opPort? opPort->getSource() : 0;
81   // check valid source and server connections
82   if(!source ||
83      this->getServer()->GetConnectionID() !=
84      source->getServer()->GetConnectionID())
85     {
86     return false;
87     }
88
89   // we can show MyExtractEdges as defined in the server manager xml
90   if(QString("MyExtractEdges") == source->getProxy()->GetXMLName())
91     {
92     return true;
93     }
94
95   return false;
96 }
97
98