File: Q3VTKWidgetPlugin.cxx

package info (click to toggle)
vtk 5.0.2-4
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 51,080 kB
  • ctags: 67,442
  • sloc: cpp: 522,627; ansic: 221,292; tcl: 43,377; python: 14,072; perl: 3,102; java: 1,436; yacc: 1,033; sh: 469; lex: 248; makefile: 181; asm: 154
file content (167 lines) | stat: -rw-r--r-- 5,118 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
 * Copyright 2004 Sandia Corporation.
 * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
 * license for use of this work by or on behalf of the
 * U.S. Government. Redistribution and use in source and binary forms, with
 * or without modification, are permitted provided that this Notice and any
 * statement of authorship are reproduced on all copies.
 */

/*========================================================================
 For general information about using VTK and Qt, see:
 http://www.trolltech.com/products/3rdparty/vtksupport.html
=========================================================================*/

/*========================================================================
 !!! WARNING for those who want to contribute code to this file.
 !!! If you use a commercial edition of Qt, you can modify this code.
 !!! If you use an open source version of Qt, you are free to modify
 !!! and use this code within the guidelines of the GPL license.
 !!! Unfortunately, you cannot contribute the changes back into this
 !!! file.  Doing so creates a conflict between the GPL and BSD-like VTK
 !!! license.
=========================================================================*/

#include "qwidgetplugin.h"

// derive from QWidgetPlugin and implement the plugin interface
class QVTKWidgetPlugin : public QWidgetPlugin
{
  public:
    QVTKWidgetPlugin();
    ~QVTKWidgetPlugin();
    
    QStringList keys() const;
    QWidget* create( const QString& key, QWidget* parent = 0, const char* name = 0);
    QString group( const QString& ) const;
    QIconSet iconSet( const QString& ) const;
    QString includeFile( const QString& ) const;
    QString toolTip( const QString& ) const;
    QString whatsThis( const QString& ) const;
    bool isContainer( const QString& ) const;
};

#include "QVTKWidget.h"
#include "QVTKWidget.xpm"

#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkSphereSource.h"
#include "vtkDataSetMapper.h"
#include "vtkPolyData.h"
#include "vtkElevationFilter.h"
#include "vtkActor.h"

// macro for debug printing
#define qDebug(a)
//#define qDebug(a) printf(a)

QVTKWidgetPlugin::QVTKWidgetPlugin()
{
  qDebug("QVTKWidgetPlugin instantiated\n");
}

QVTKWidgetPlugin::~QVTKWidgetPlugin()
{
  qDebug("QVTKWidgetPlugin destructed\n");
}

//! return a list of keys for what widgets this plugin makes
QStringList QVTKWidgetPlugin::keys() const
{
  qDebug("QVTKWidgetPlugin::keys\n");
  QStringList list;
  list << "QVTKWidget";
  return list;
}

//! create a widget by key
QWidget* QVTKWidgetPlugin::create( const QString& key, QWidget* parent, const char* name)
{
  qDebug("QVTKWidgetPlugin::create\n");
  if(key == "QVTKWidget")
  {
    QVTKWidget* widget = new QVTKWidget(parent, name);
    // gotta make a renderer so we get a nice black background in the designer
    vtkRenderer* ren = vtkRenderer::New();
    widget->GetRenderWindow()->AddRenderer(ren);

    // also for fun, let's make a cylinder and put it in the window
    // this REALLY lets the user know that a QVTKWidget works in the designer
    vtkSphereSource* cyl = vtkSphereSource::New();
    vtkElevationFilter* ele = vtkElevationFilter::New();
    ele->SetLowPoint(0.0, -0.5, 0.0);
    ele->SetHighPoint(0.0, 0.5, 0.0);
    ele->SetInput(cyl->GetOutput());
    vtkDataSetMapper* mapper = vtkDataSetMapper::New();
    mapper->SetInput(ele->GetOutput());
    ele->Delete();
    cyl->Delete();
    vtkActor* actor = vtkActor::New();
    actor->SetMapper(mapper);
    mapper->Delete();
#if (VTK_MAJOR_VERSION > 4) || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION >=5)
    ren->AddViewProp(actor);
#else
    ren->AddProp(actor);
#endif
    actor->Delete();
    ren->Delete();

    // return the widget
    return widget;
  }
  return 0;
}

//! what group this plugin shows up in the designer
QString QVTKWidgetPlugin::group( const QString& feature) const
{
  qDebug("QVTKWidgetPlugin::group\n");
  if(feature == "QVTKWidget")
    return "QVTK";
  return QString::null;
}
//! the icons for the widgets
QIconSet QVTKWidgetPlugin::iconSet( const QString& ) const
{
  qDebug("QVTKWidgetPlugin::iconSet\n");
  return QIconSet( QPixmap( QVTKWidget_image ) );
}

//! the name of the include file for building an app with a widget
QString QVTKWidgetPlugin::includeFile( const QString& feature) const
{
  qDebug("QVTKWidgetPlugin::includeFile\n");
  if ( feature == "QVTKWidget" )
    return "QVTKWidget.h";
  return QString::null;
}

//! tool tip text
QString QVTKWidgetPlugin::toolTip( const QString& feature) const
{
  qDebug("QVTKWidgetPlugin::toolTip\n");
  if(feature == "QVTKWidget")
    return "Qt VTK Widget";
  return QString::null;
}

//! what's this text
QString QVTKWidgetPlugin::whatsThis( const QString& feature) const
{
  qDebug("QVTKWidgetPlugin::whatsThis\n");
  if ( feature == "QVTKWidget" )
    return "A Qt/VTK Graphics Window";
  return QString::null;
}

//! returns whether widget is a container
bool QVTKWidgetPlugin::isContainer( const QString& ) const
{
  qDebug("QVTKWidgetPlugin::isContainer\n");
  return false;
}

Q_EXPORT_PLUGIN(QVTKWidgetPlugin)