Back to index

salome-paravis  6.5.0
MyView.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2010-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "MyView.h"
00021 
00022 #include <QLabel>
00023 #include <QVBoxLayout>
00024 #include <QWidget>
00025 #include <vtkSMProxy.h>
00026 
00027 #include <pqOutputPort.h>
00028 #include <pqPipelineSource.h>
00029 #include <pqRepresentation.h>
00030 #include <pqServer.h>
00031 
00032 MyView::MyView(const QString& viewmoduletype, 
00033        const QString& group, 
00034        const QString& name, 
00035        vtkSMViewProxy* viewmodule, 
00036        pqServer* server, 
00037        QObject* p)
00038  : pqView(viewmoduletype, group, name, viewmodule, server, p)
00039 {
00040   // our view is just a simple QWidget
00041   this->MyWidget = new QWidget;
00042   this->MyWidget->setAutoFillBackground(true);
00043   new QVBoxLayout(this->MyWidget);
00044 
00045   // connect to display creation so we can show them in our view
00046   this->connect(this, SIGNAL(representationAdded(pqRepresentation*)),
00047     SLOT(onRepresentationAdded(pqRepresentation*)));
00048   this->connect(this, SIGNAL(representationRemoved(pqRepresentation*)),
00049     SLOT(onRepresentationRemoved(pqRepresentation*)));
00050 }
00051 
00052 MyView::~MyView()
00053 {
00054   delete this->MyWidget;
00055 }
00056 
00057 
00058 QWidget* MyView::getWidget()
00059 {
00060   return this->MyWidget;
00061 }
00062 
00063 void MyView::onRepresentationAdded(pqRepresentation* d)
00064 {
00065   // add a label with the display id
00066   QLabel* l = new QLabel(
00067     QString("Display (%1)").arg(d->getProxy()->GetSelfIDAsString()), 
00068     this->MyWidget);
00069   this->MyWidget->layout()->addWidget(l);
00070   this->Labels.insert(d, l);
00071 }
00072 
00073 void MyView::onRepresentationRemoved(pqRepresentation* d)
00074 {
00075   // remove the label
00076   QLabel* l = this->Labels.take(d);
00077   if(l)
00078     {
00079     this->MyWidget->layout()->removeWidget(l);
00080     delete l;
00081     }
00082 }
00083 
00084 void MyView::setBackground(const QColor& c)
00085 {
00086   QPalette p = this->MyWidget->palette();
00087   p.setColor(QPalette::Window, c);
00088   this->MyWidget->setPalette(p);
00089 }
00090 
00091 QColor MyView::background() const
00092 {
00093   return this->MyWidget->palette().color(QPalette::Window);
00094 }
00095 
00096 bool MyView::canDisplay(pqOutputPort* opPort) const
00097 {
00098   pqPipelineSource* source = opPort? opPort->getSource() : 0;
00099   // check valid source and server connections
00100   if(!source ||
00101      this->getServer()->GetConnectionID() !=
00102      source->getServer()->GetConnectionID())
00103     {
00104     return false;
00105     }
00106 
00107   // we can show MyExtractEdges as defined in the server manager xml
00108   if(QString("MyExtractEdges") == source->getProxy()->GetXMLName())
00109     {
00110     return true;
00111     }
00112 
00113   return false;
00114 }
00115 
00116