ParaView
pqServerManagerModel.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ParaView
4  Module: pqServerManagerModel.h
5 
6  Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
7  All rights reserved.
8 
9  ParaView is a free software; you can redistribute it and/or modify it
10  under the terms of the ParaView license version 1.2.
11 
12  See License_v1.2.txt for the full ParaView license.
13  A copy of this license can be obtained by contacting
14  Kitware Inc.
15  28 Corporate Drive
16  Clifton Park, NY 12065
17  USA
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
23 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 ========================================================================*/
32 #ifndef pqServerManagerModel_h
33 #define pqServerManagerModel_h
34 
35 #include "pqCoreModule.h"
36 #include "vtkType.h" // for vtkIdType.
37 #include <QList>
38 #include <QObject>
39 
40 class pqPipelineSource;
41 class pqProxy;
42 class pqRepresentation;
43 class pqServer;
46 class pqServerResource;
47 class pqView;
48 class vtkPVXMLElement;
49 class vtkSession;
50 class vtkSMProxy;
51 class vtkSMProxyLocator;
52 class vtkSMSession;
53 
55 
56 template <class T> inline QList<T> pqFindItems(
57  const pqServerManagerModel* const model);
58 template <class T> inline QList<T> pqFindItems(
59  const pqServerManagerModel* const model, pqServer* server);
60 template <class T> inline T pqFindItem(
61  const pqServerManagerModel* const model, const QString& name);
62 template <class T> inline T pqFindItem(
63  const pqServerManagerModel* const model, vtkSMProxy* proxy);
64 template <class T> inline T pqFindItem(
65  const pqServerManagerModel* const model, vtkTypeUInt32 id);
66 template <class T> inline int pqGetNumberOfItems(
67  const pqServerManagerModel* const model);
68 template <class T> inline T pqGetItemAtIndex(
69  const pqServerManagerModel* const model, int index);
70 
77 class PQCORE_EXPORT pqServerManagerModel : public QObject
78 {
79  Q_OBJECT
80  typedef QObject Superclass;
81 public:
86  QObject* parent=0);
88 
91  pqServer* findServer(vtkIdType cid) const;
92 
95  pqServer* findServer(vtkSession*) const;
96  pqServer* findServer(vtkSMSession*) const;
97 
99  pqServer* findServer(const pqServerResource& resource) const;
100 
102  void beginRemoveServer(pqServer *server);
103  void endRemoveServer();
104 
110  void setActiveResource(const pqServerResource& resource);
111 
114  template<class T>
115  T findItem(vtkSMProxy* proxy) const
116  {
117  return ::pqFindItem<T>(this, proxy);
118  }
119 
122  template<class T>
123  T findItem(vtkTypeUInt32 id) const
124  {
125  return ::pqFindItem<T>(this, id);
126  }
127 
129  template <class T>
130  QList<T> findItems() const
131  {
132  return ::pqFindItems<T>(this);
133  }
134 
136  template <class T>
137  int getNumberOfItems() const
138  {
139  return ::pqGetNumberOfItems<T>(this);
140  }
141 
145  template <class T>
146  T getItemAtIndex(int index) const
147  {
148  return ::pqGetItemAtIndex<T>(this, index);
149  }
150 
153  template <class T>
154  QList<T> findItems(pqServer* server) const
155  {
156  return ::pqFindItems<T>(this, server);
157  }
158 
163  template <class T>
164  T findItem(const QString& name) const
165  {
166  return ::pqFindItem<T>(this, name);
167  }
168 
170  static void findItemsHelper(const pqServerManagerModel * const model,
171  const QMetaObject &mo, QList<void *> *list, pqServer* server=0);
172 
174  static pqServerManagerModelItem* findItemHelper(const pqServerManagerModel* const model,
175  const QMetaObject& mo, vtkSMProxy* proxy);
176 
178  static pqServerManagerModelItem* findItemHelper(const pqServerManagerModel* const model,
179  const QMetaObject& mo, vtkTypeUInt32 id);
180 
182  static pqServerManagerModelItem* findItemHelper(const pqServerManagerModel* const model,
183  const QMetaObject& mo, const QString& name);
184 
185 signals:
187  void preServerAdded(pqServer*);
188  void serverAdded(pqServer*);
189 
194  void serverReady(pqServer*);
195 
197  void preServerRemoved(pqServer*);
198  void serverRemoved(pqServer*);
199 
201  void aboutToRemoveServer(pqServer* server);
202 
204  void finishedRemovingServer();
205 
207  void preItemAdded(pqServerManagerModelItem*);
208  void itemAdded(pqServerManagerModelItem*);
209 
212  void preItemRemoved(pqServerManagerModelItem*);
213  void itemRemoved(pqServerManagerModelItem*);
214 
215  void preProxyAdded(pqProxy*);
216  void proxyAdded(pqProxy*);
217 
218  void preProxyRemoved(pqProxy*);
219  void proxyRemoved(pqProxy*);
220 
222  void preSourceAdded(pqPipelineSource* source);
223  void sourceAdded(pqPipelineSource* source);
224 
226  void preSourceRemoved(pqPipelineSource*);
227  void sourceRemoved(pqPipelineSource*);
228 
230  void preViewAdded(pqView* view);
231  void viewAdded(pqView* view);
232 
234  void preViewRemoved(pqView*);
235  void viewRemoved(pqView*);
236 
238  void preRepresentationAdded(pqRepresentation* rep);
239  void representationAdded(pqRepresentation* rep);
240 
242  void preRepresentationRemoved(pqRepresentation*);
243  void representationRemoved(pqRepresentation*);
244 
246  void nameChanged(pqServerManagerModelItem *item);
247 
248 
250  void modifiedStateChanged(pqServerManagerModelItem *item);
251 
253  void connectionAdded(pqPipelineSource* source,
254  pqPipelineSource* consumer, int srcOutputPort);
255  void preConnectionAdded(pqPipelineSource* source,
256  pqPipelineSource* consumer, int srcOutputPort);
257 
259  void connectionRemoved(pqPipelineSource* source,
260  pqPipelineSource* consumer, int srcOutputPort);
261  void preConnectionRemoved(pqPipelineSource* source,
262  pqPipelineSource* consumer, int srcOutputPort);
263 
266  void dataUpdated(pqPipelineSource*);
267 
268 protected slots:
270  virtual void onProxyRegistered(const QString& group, const QString& name,
271  vtkSMProxy* proxy);
272 
274  virtual void onProxyUnRegistered(const QString& group, const QString& name,
275  vtkSMProxy* proxy);
276 
278  virtual void onConnectionCreated(vtkIdType id);
279 
281  virtual void onConnectionClosed(vtkIdType id);
282 
285  virtual void onStateLoaded(vtkPVXMLElement*, vtkSMProxyLocator*);
286 
287 private:
288  Q_DISABLE_COPY(pqServerManagerModel)
289 
290 
291  void updateSettingsFromQSettings(pqServer* server);
293 
294  class pqInternal;
295  pqInternal* Internal;
296 };
297 
298 
299 //-----------------------------------------------------------------------------
300 template <class T>
301 inline QList<T> pqFindItems(const pqServerManagerModel* const model)
302 {
303  QList<T> list;
304  pqServerManagerModel::findItemsHelper(model, ((T)0)->staticMetaObject,
305  reinterpret_cast<QList<void *>*>(&list), 0);
306  return list;
307 }
308 
309 //-----------------------------------------------------------------------------
310 template <class T>
311 inline QList<T> pqFindItems(const pqServerManagerModel* const model,
312  pqServer* server)
313 {
314  QList<T> list;
315  pqServerManagerModel::findItemsHelper(model, ((T)0)->staticMetaObject,
316  reinterpret_cast<QList<void *>*>(&list), server);
317  return list;
318 }
319 
320 //-----------------------------------------------------------------------------
321 template <class T>
322 inline T pqFindItem(const pqServerManagerModel* const model, vtkSMProxy* proxy)
323 {
324  return qobject_cast<T>(
325  pqServerManagerModel::findItemHelper(model, ((T)0)->staticMetaObject, proxy));
326 }
327 
328 //-----------------------------------------------------------------------------
329 template <class T>
330 inline T pqFindItem(const pqServerManagerModel* const model,
331  vtkTypeUInt32 id)
332 {
333  return qobject_cast<T>(
334  pqServerManagerModel::findItemHelper(model, ((T)0)->staticMetaObject, id));
335 }
336 
337 //-----------------------------------------------------------------------------
338 template <class T>
339 inline T pqFindItem(const pqServerManagerModel* const model,
340  const QString& name)
341 {
342  return qobject_cast<T>(
343  pqServerManagerModel::findItemHelper(model, ((T)0)->staticMetaObject, name));
344 }
345 
346 //-----------------------------------------------------------------------------
347 template <class T>
348 inline int pqGetNumberOfItems(const pqServerManagerModel* const model)
349 {
350  return pqFindItems<T>(model).size();
351 }
352 
353 //-----------------------------------------------------------------------------
354 template <class T>
355 inline T pqGetItemAtIndex(const pqServerManagerModel* const model, int index)
356 {
357  QList<T> items = pqFindItems<T>(model);
358  if (index < items.size())
359  {
360  return items[index];
361  }
362 
363  return 0;
364 }
365 
366 #endif
367 
368 
int pqGetNumberOfItems(const pqServerManagerModel *const model)
QList< T > pqFindItems(const pqServerManagerModel *const model)
This is PQ representation for a single representation.
pqServerManagerModelItem is a element maintained by pqServerManagerModel.
T pqGetItemAtIndex(const pqServerManagerModel *const model, int index)
This is a PQ abstraction of a generic view module.
Definition: pqView.h:55
T findItem(const QString &name) const
Returns an item with the given name.
static pqServerManagerModelItem * findItemHelper(const pqServerManagerModel *const model, const QMetaObject &mo, vtkSMProxy *proxy)
Internal method.
T findItem(vtkTypeUInt32 id) const
Given the gloabal id for a proxy, locates a pqServerManagerModelItem subclass for the proxy...
This is a vtkSMProxyManager observer.
QList< T > findItems() const
Returns a list of pqServerManagerModelItem of the given type.
T pqFindItem(const pqServerManagerModel *const model, const QString &name)
T findItem(vtkSMProxy *proxy) const
Given a proxy, locates a pqServerManagerModelItem subclass for the given proxy.
This class represents any registered Server Manager proxy.
Definition: pqProxy.h:52
pqServerManagerModel is the model for the Server Manager.
int getNumberOfItems() const
Returns the number of items of the given type.
PQ representation for a vtkSMProxy that can be involved in a pipeline.
T getItemAtIndex(int index) const
Returns the item of the given type and the given index.
QList< T > findItems(pqServer *server) const
Same as findItems<T>() except that this returns only those items that are on the indicated server...
pqServerResource encapsulates a resource in ParaView.
static void findItemsHelper(const pqServerManagerModel *const model, const QMetaObject &mo, QList< void *> *list, pqServer *server=0)
Internal method.
pqServer (should be renamed to pqSession) is a pqServerManagerModelItem subclass that represents a vt...
Definition: pqServer.h:62