pqDefaultViewBehavior.cxx 7.88 KB
Newer Older
1
2
3
4
5
6
7
8
9
/*=========================================================================

   Program: ParaView
   Module:    pqDefaultViewBehavior.cxx

   Copyright (c) 2005,2006 Sandia Corporation, Kitware Inc.
   All rights reserved.

   ParaView is a free software; you can redistribute it and/or modify it
Kitware Robot's avatar
Kitware Robot committed
10
   under the terms of the ParaView license version 1.2.
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

   See License_v1.2.txt for the full ParaView license.
   A copy of this license can be obtained by contacting
   Kitware Inc.
   28 Corporate Drive
   Clifton Park, NY 12065
   USA

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

========================================================================*/
#include "pqDefaultViewBehavior.h"

#include "pqApplicationCore.h"
#include "pqCoreUtilities.h"
#include "pqObjectBuilder.h"
37
#include "pqPluginManager.h"
38
39
40
#include "pqRenderView.h"
#include "pqServer.h"
#include "pqServerManagerModel.h"
41
#include "vtkNew.h"
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
42
#include "vtkPVGeneralSettings.h"
43
#include "vtkPVOpenGLInformation.h"
44
#include "vtkPVRenderingCapabilitiesInformation.h"
45
46
#include "vtkSMSession.h"
#include "vtkSMSessionProxyManager.h"
47
48

#include <QCoreApplication>
49
50
#include <QMessageBox>

51
52
#include <cassert>

53
54
namespace
{
Kitware Robot's avatar
Kitware Robot committed
55
56
57
58
QString openGLVersionInfo(vtkSMSession* session, vtkPVSession::ServerFlags server_flag)
{
  vtkNew<vtkPVOpenGLInformation> glinfo;
  session->GatherInformation(server_flag, glinfo.GetPointer(), 0);
59
60
  return QString(QCoreApplication::translate("pqDefaultViewBehavior",
                   ("OpenGL Vendor: %1\nOpenGL Version: %2\nOpenGL Renderer: %3")))
Kitware Robot's avatar
Kitware Robot committed
61
62
    .arg(glinfo->GetVendor().c_str(), glinfo->GetVersion().c_str(), glinfo->GetRenderer().c_str());
}
63
64
}

65
66
//-----------------------------------------------------------------------------
pqDefaultViewBehavior::pqDefaultViewBehavior(QObject* parentObject)
Kitware Robot's avatar
Kitware Robot committed
67
  : Superclass(parentObject)
68
{
Kitware Robot's avatar
Kitware Robot committed
69
70
  QObject::connect(pqApplicationCore::instance()->getServerManagerModel(),
    SIGNAL(serverAdded(pqServer*)), this, SLOT(onServerCreation(pqServer*)));
71

72
73
74
75
76
  this->ViewCreationTimer.setSingleShot(true);
  this->ViewCreationTimer.setInterval(0);
  this->connect(
    &this->ViewCreationTimer, &pqTimer::timeout, [=] { this->createView(this->CurrentServer); });

77
78
  this->WarningsTimer.setSingleShot(true);
  this->connect(&this->WarningsTimer, SIGNAL(timeout()), SLOT(showWarnings()));
79
80
81
82
83
84

  // Listen for when the environment is fully set up. Among other things, this marks the end
  // of autoload plugins being loaded, so it safe to create a view that may potentially be
  // modified by a plugin.
  this->connect(pqApplicationCore::instance(), &pqApplicationCore::clientEnvironmentDone,
    [=]() { this->EnvironmentComplete = true; });
85
86
87
}

//-----------------------------------------------------------------------------
88
void pqDefaultViewBehavior::showWarnings()
89
{
90
91
92
  using RCInfo = vtkPVRenderingCapabilitiesInformation;
  if (RCInfo::Supports(this->ClientCapabilities, RCInfo::OPENGL) &&
    RCInfo::Supports(this->ServerCapabilities, RCInfo::OPENGL))
Kitware Robot's avatar
Kitware Robot committed
93
  {
94
95
96
    // all's well!
    return;
  }
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
  if (this->Server == nullptr)
  {
    return;
  }

  if (!RCInfo::Supports(this->ClientCapabilities, RCInfo::OPENGL))
  {
    QString msg = tr("Your OpenGL drivers don't support\n"
                     "required OpenGL features for basic rendering.\n"
                     "Application cannot continue. Please exit and use an older version.\n\n"
                     "CONTINUE AT YOUR OWN RISK!\n\n");
    msg += openGLVersionInfo(this->Server->session(), vtkSMSession::CLIENT);
    QMessageBox::warning(
      pqCoreUtilities::mainWidget(), tr("OpenGL support inadequate!"), msg, QMessageBox::Ok);
    return;
  }

  if (!this->Server->isRemote())
  {
    // for non remote server, that's the only message.
    return;
  }

  if (!RCInfo::Supports(this->ServerCapabilities, RCInfo::RENDERING))
  {
    QMessageBox::warning(pqCoreUtilities::mainWidget(), tr("Server DISPLAY not accessible!"),
      tr("Display is not accessible on the server side.\n"
         "Remote rendering will be disabled."),
      QMessageBox::Ok);
  }
  else if (!RCInfo::Supports(this->ServerCapabilities, RCInfo::OPENGL))
  {
    QString msg = tr("OpenGL drivers on the server side don't support\n"
                     "required OpenGL features for basic rendering.\n"
                     "Remote rendering will be disabled.");
    msg += openGLVersionInfo(this->Server->session(), vtkSMSession::RENDER_SERVER);
    QMessageBox::warning(
      pqCoreUtilities::mainWidget(), tr("Server OpenGL support inadequate!"), msg, QMessageBox::Ok);
Kitware Robot's avatar
Kitware Robot committed
136
  }
137
138
139
140
141
}

//-----------------------------------------------------------------------------
void pqDefaultViewBehavior::onServerCreation(pqServer* server)
{
142
  using RCInfo = vtkPVRenderingCapabilitiesInformation;
143
  this->CurrentServer = server;
144

145
146
147
148
149
150
151
152
  // Get information about rendering capabilities.
  vtkNew<RCInfo> info;
  server->session()->GatherInformation(vtkSMSession::RENDER_SERVER, info.GetPointer(), 0);

  this->Server = server;
  this->ServerCapabilities = this->ClientCapabilities = info->GetCapabilities();

  // if server is remote, we separately get client capabilities.
153
  if (server->isRemote())
Kitware Robot's avatar
Kitware Robot committed
154
  {
155
    this->ClientCapabilities = RCInfo::GetLocalCapabilities();
Kitware Robot's avatar
Kitware Robot committed
156
  }
157

158
  // Setup a timer to show warning messages, if needed.
159
  this->WarningsTimer.start(500);
160

161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
  this->createView(this->CurrentServer);

  // Show warning dialogs before server times out.
  QObject::connect(
    server, SIGNAL(fiveMinuteTimeoutWarning()), this, SLOT(fiveMinuteTimeoutWarning()));
  QObject::connect(server, SIGNAL(finalTimeoutWarning()), this, SLOT(finalTimeoutWarning()));
}

//-----------------------------------------------------------------------------
void pqDefaultViewBehavior::createView(pqServer* server)
{
  if (!this->EnvironmentComplete)
  {
    this->ViewCreationTimer.start();
    return;
  }

  using RCInfo = vtkPVRenderingCapabilitiesInformation;

180
181
  // See if some view are already present and if we're in a collaborative
  // session, we are the master.
182
  pqApplicationCore* core = pqApplicationCore::instance();
183
  if (core->getServerManagerModel()->getNumberOfItems<pqView*>() == 0 && server->isMaster())
Kitware Robot's avatar
Kitware Robot committed
184
185
  {
    pqObjectBuilder* builder = pqApplicationCore::instance()->getObjectBuilder();
186
187
    const QString viewType = vtkPVGeneralSettings::GetInstance()->GetDefaultViewType();
    if (viewType != "None" && !viewType.isEmpty() &&
188
      RCInfo::Supports(this->ClientCapabilities, RCInfo::OPENGL))
Kitware Robot's avatar
Kitware Robot committed
189
    {
190
      // When a server is created, we create a new render view for it.
191
192
193
194
195
      if (auto pqview = builder->createView(viewType, server))
      {
        // let's put this view under a layout.
        builder->addToLayout(pqview);
      }
196
    }
Kitware Robot's avatar
Kitware Robot committed
197
  }
198
199
200
201
202
}

//-----------------------------------------------------------------------------
void pqDefaultViewBehavior::fiveMinuteTimeoutWarning()
{
Kitware Robot's avatar
Kitware Robot committed
203
  QMessageBox::warning(pqCoreUtilities::mainWidget(), tr("Server Timeout Warning"),
204
    tr("The server connection will timeout under 5 minutes.\n"
Kitware Robot's avatar
Kitware Robot committed
205
       "Please save your work."),
206
207
208
209
210
211
    QMessageBox::Ok);
}

//-----------------------------------------------------------------------------
void pqDefaultViewBehavior::finalTimeoutWarning()
{
Kitware Robot's avatar
Kitware Robot committed
212
  QMessageBox::critical(pqCoreUtilities::mainWidget(), tr("Server Timeout Warning"),
213
    tr("The server connection will timeout shortly.\n"
Kitware Robot's avatar
Kitware Robot committed
214
       "Please save your work."),
215
216
    QMessageBox::Ok);
}