Salome HOME
Merge branch 'V9_2_2_BR'
[modules/paravis.git] / src / Plugins / View / MyView.cxx
1 // Copyright (C) 2010-2019  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "MyView.h"
21
22 #include <QLabel>
23 #include <QVBoxLayout>
24 #include <QWidget>
25 #include <vtkSMProxy.h>
26
27 #include <pqOutputPort.h>
28 #include <pqPipelineSource.h>
29 #include <pqRepresentation.h>
30 #include <pqServer.h>
31
32 MyView::MyView(const QString& viewmoduletype, 
33        const QString& group, 
34        const QString& name, 
35        vtkSMViewProxy* viewmodule, 
36        pqServer* server, 
37        QObject* p)
38  : pqView(viewmoduletype, group, name, viewmodule, server, p)
39 {
40   // our view is just a simple QWidget
41   this->MyWidget = new QWidget;
42   this->MyWidget->setAutoFillBackground(true);
43   new QVBoxLayout(this->MyWidget);
44
45   // connect to display creation so we can show them in our view
46   this->connect(this, SIGNAL(representationAdded(pqRepresentation*)),
47     SLOT(onRepresentationAdded(pqRepresentation*)));
48   this->connect(this, SIGNAL(representationRemoved(pqRepresentation*)),
49     SLOT(onRepresentationRemoved(pqRepresentation*)));
50 }
51
52 MyView::~MyView()
53 {
54   delete this->MyWidget;
55 }
56
57
58 QWidget* MyView::getWidget()
59 {
60   return this->MyWidget;
61 }
62
63 void MyView::onRepresentationAdded(pqRepresentation* d)
64 {
65   // add a label with the display id
66   QLabel* l = new QLabel(
67     QString("Display (%1)").arg(d->getProxy()->GetSelfIDAsString()), 
68     this->MyWidget);
69   this->MyWidget->layout()->addWidget(l);
70   this->Labels.insert(d, l);
71 }
72
73 void MyView::onRepresentationRemoved(pqRepresentation* d)
74 {
75   // remove the label
76   QLabel* l = this->Labels.take(d);
77   if(l)
78     {
79     this->MyWidget->layout()->removeWidget(l);
80     delete l;
81     }
82 }
83
84 void MyView::setBackground(const QColor& c)
85 {
86   QPalette p = this->MyWidget->palette();
87   p.setColor(QPalette::Window, c);
88   this->MyWidget->setPalette(p);
89 }
90
91 QColor MyView::background() const
92 {
93   return this->MyWidget->palette().color(QPalette::Window);
94 }
95
96 bool MyView::canDisplay(pqOutputPort* opPort) const
97 {
98   pqPipelineSource* source = opPort? opPort->getSource() : 0;
99   // check valid source and server connections
100   if(!source ||
101      this->getServer()->GetConnectionID() !=
102      source->getServer()->GetConnectionID())
103     {
104     return false;
105     }
106
107   // we can show MyExtractEdges as defined in the server manager xml
108   if(QString("MyExtractEdges") == source->getProxy()->GetXMLName())
109     {
110     return true;
111     }
112
113   return false;
114 }
115
116