forked from biddisco/pv-meshless
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpqSPHManagerDockWindow.cxx
318 lines (281 loc) · 9.49 KB
/
pqSPHManagerDockWindow.cxx
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
#include "pqSPHManagerDockWindow.h"
// Qt includes
#include <QSet>
#include <QStyle>
#include <QStyleFactory>
#include <QPushButton>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QScrollArea>
// version includes
#include "vtkPVConfig.h"
// ParaView Server Manager includes
#include "vtkSMProxyManager.h"
#include "vtkSMProxy.h"
// ParaView includes
#include "pqApplicationCore.h"
#include "pqProxy.h"
#include "pqServer.h"
#include "pqServerManagerModelItem.h"
#include "pqServerManagerModel.h"
#include "pqActiveObjects.h"
#include "pqUndoStack.h"
//
#include "pqSPHManagerPanel.h"
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
class pqSPHManagerDockWindow::pqUI : public QObject
{
public:
pqUI(pqSPHManagerDockWindow* p) : QObject((QDockWidget*)p)
{
this->SPHManagerPanel = NULL;
this->SPHInitialized = 0;
}
//
~pqUI() {
}
bool SPHReady() {
if (!this->ProxyReady()) return 0;
//
if (!this->SPHInitialized) {
this->SPHProxy->UpdateVTKObjects();
this->SPHInitialized = 1;
}
return this->SPHInitialized;
}
bool ProxyReady() {
if (!this->ProxyCreated()) {
this->CreateProxy();
return this->ProxyCreated();
}
return true;
}
void CreateProxy() {
vtkSMProxyManager *pm = vtkSMProxyManager::GetProxyManager();
this->SPHProxy.TakeReference(pm->NewProxy("meshless_helpers", "SPHManager"));
if (this->SPHProxy) {
this->pqSPHProxy = new pqProxy("meshless_helpers", "SPHManager", SPHProxy, 0, 0);
this->SPHProxy->UpdatePropertyInformation();
}
else {
vtkGenericWarningMacro(<<"Failed to create proxy, check plugin loaded on server");
}
}
void DeleteProxy() {
if (this->ProxyCreated()) {
vtkSMProxyManager *pm = vtkSMProxyManager::GetProxyManager();
pm->UnRegisterProxy("meshless_helpers", "SPHManager",this->SPHProxy);
this->SPHProxy = NULL;
delete this->SPHManagerPanel;
delete this->pqSPHProxy;
this->SPHManagerPanel = NULL;
this->pqSPHProxy = NULL;
}
}
void CreatePanel(QScrollArea *ScrollArea) {
if (this->SPHReady()) {
this->SPHManagerPanel = new pqSPHManagerPanel(this->pqSPHProxy,NULL);
ScrollArea->setWidget(this->SPHManagerPanel);
}
}
//
bool ProxyCreated() { return this->SPHProxy!=NULL; }
pqSPHManagerPanel *SPHManagerPanel;
int SPHInitialized;
vtkSmartPointer<vtkSMProxy> SPHProxy;
pqProxy *pqSPHProxy;
};
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
pqSPHManagerDockWindow::pqSPHManagerDockWindow(QWidget* p) : QDockWidget("SPH Manager", p)
{
this->UI = new pqSPHManagerDockWindow::pqUI(this);
QWidget *dockWidgetContents = new QWidget();
this->PanelLayout = new QVBoxLayout(dockWidgetContents);
this->PanelLayout->setMargin(0);
//
// Most of the following code is taken from pqObjectInspector
//
this->ScrollArea = new QScrollArea();
this->ScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
this->ScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
this->ScrollArea->setWidgetResizable(true);
this->ScrollArea->setFrameShape(QFrame::NoFrame);
QBoxLayout* buttonlayout = new QHBoxLayout();
this->AcceptButton = new QPushButton(this);
this->AcceptButton->setObjectName("Accept");
this->AcceptButton->setText(tr("&Apply"));
this->AcceptButton->setIcon(QIcon(QPixmap(":/pqWidgets/Icons/pqUpdate16.png")));
#ifdef Q_WS_MAC
this->AcceptButton->setShortcut(QKeySequence(Qt::AltModifier + Qt::Key_A));
#endif
this->ResetButton = new QPushButton(this);
this->ResetButton->setObjectName("Reset");
this->ResetButton->setText(tr("&Reset"));
this->ResetButton->setIcon(QIcon(QPixmap(":/pqWidgets/Icons/pqCancel16.png")));
#ifdef Q_WS_MAC
this->ResetButton->setShortcut(QKeySequence(Qt::AltModifier + Qt::Key_R));
#endif
this->InitButton = new QPushButton(this);
this->InitButton->setObjectName("Init");
this->InitButton->setText(tr("&Init"));
buttonlayout->addStretch();
buttonlayout->addWidget(InitButton);
buttonlayout->addWidget(this->AcceptButton);
buttonlayout->addWidget(this->ResetButton);
buttonlayout->addStretch();
this->PanelLayout->addLayout(buttonlayout);
this->PanelLayout->addWidget(this->ScrollArea);
this->connect(this->AcceptButton, SIGNAL(clicked()), SLOT(accept()));
this->connect(this->ResetButton, SIGNAL(clicked()), SLOT(reset()));
this->connect(this->InitButton, SIGNAL(clicked()), SLOT(init()));
this->InitButton->setEnabled(true);
this->AcceptButton->setEnabled(false);
this->ResetButton->setEnabled(false);
// if XP Style is being used
// swap it out for cleanlooks which looks almost the same
// so we can have a green accept button
// make all the buttons the same
QString styleName = this->AcceptButton->style()->metaObject()->className();
if(styleName == "QWindowsXPStyle")
{
QStyle* st = QStyleFactory::create("cleanlooks");
st->setParent(this);
this->AcceptButton->setStyle(st);
this->ResetButton->setStyle(st);
QPalette buttonPalette = this->AcceptButton->palette();
buttonPalette.setColor(QPalette::Button, QColor(244,246,244));
this->AcceptButton->setPalette(buttonPalette);
this->ResetButton->setPalette(buttonPalette);
}
// Change the accept button palette so it is green when it is active.
QPalette acceptPalette = this->AcceptButton->palette();
acceptPalette.setColor(QPalette::Active, QPalette::Button, QColor(161, 213, 135));
this->AcceptButton->setPalette(acceptPalette);
this->AcceptButton->setDefault(true);
//
this->setWidget(dockWidgetContents);
//
// Link paraview server events to callbacks
//
pqServerManagerModel* smModel =
pqApplicationCore::instance()->getServerManagerModel();
this->connect(smModel, SIGNAL(aboutToRemoveServer(pqServer *)),
this, SLOT(StartRemovingServer(pqServer *)));
this->connect(smModel, SIGNAL(serverAdded(pqServer *)),
this, SLOT(serverAdded(pqServer *)));
this->serverAdded(pqActiveObjects::instance().activeServer());
}
//----------------------------------------------------------------------------
pqSPHManagerDockWindow::~pqSPHManagerDockWindow()
{
if (this->UI->SPHManagerPanel) {
this->UI->SPHManagerPanel->SaveSettings();
}
this->UI->DeleteProxy();
}
//----------------------------------------------------------------------------
void pqSPHManagerDockWindow::init()
{
if (this->UI->SPHReady()) {
this->InitButton->setEnabled(false);
this->UI->CreatePanel(this->ScrollArea);
//
// Link gui/proxy events to callbacks
//
QObject::connect(this->UI->SPHManagerPanel, SIGNAL(modified()),
this, SLOT(updateAcceptState()));
QObject::connect(this->UI->pqSPHProxy,
SIGNAL(modifiedStateChanged(pqServerManagerModelItem*)),
this, SLOT(updateAcceptState()));
//
this->UI->SPHManagerPanel->LoadSettings();
//
this->updateAcceptState();
}
}
//----------------------------------------------------------------------------
void pqSPHManagerDockWindow::serverAdded(pqServer *server)
{
this->init();
this->accept();
}
//----------------------------------------------------------------------------
void pqSPHManagerDockWindow::StartRemovingServer(pqServer *server)
{
this->UI->DeleteProxy();
this->InitButton->setEnabled(true);
}
//-----------------------------------------------------------------------------
void pqSPHManagerDockWindow::setModified()
{
emit this->modified();
}
//----------------------------------------------------------------------------
void pqSPHManagerDockWindow::showEvent( QShowEvent * event )
{
QDockWidget::showEvent( event );
}
//-----------------------------------------------------------------------------
void pqSPHManagerDockWindow::accept()
{
BEGIN_UNDO_SET("Apply");
emit this->preaccept();
QSet<pqProxy*> proxies_to_show;
if (this->UI->SPHManagerPanel)
{
int modified_state = this->UI->pqSPHProxy->modifiedState();
if (modified_state == pqProxy::UNINITIALIZED)
{
// proxies_to_show.insert(refProxy);
}
this->UI->SPHManagerPanel->accept();
}
emit this->accepted();
emit this->postaccept();
END_UNDO_SET();
// Essential to render all views.
// pqApplicationCore::instance()->render();
}
//-----------------------------------------------------------------------------
void pqSPHManagerDockWindow::reset()
{
emit this->prereject();
if(this->UI->SPHManagerPanel)
{
this->UI->SPHManagerPanel->reset();
}
emit this->postreject();
}
//-----------------------------------------------------------------------------
void pqSPHManagerDockWindow::canAccept(bool status)
{
this->AcceptButton->setEnabled(status);
bool resetStatus = status;
if(resetStatus && this->UI->SPHManagerPanel &&
this->UI->pqSPHProxy->modifiedState() ==
pqProxy::UNINITIALIZED)
{
resetStatus = false;
}
this->ResetButton->setEnabled(resetStatus);
}
//-----------------------------------------------------------------------------
void pqSPHManagerDockWindow::updateAcceptState()
{
// watch for modified state changes
bool acceptable = false;
if(this->UI->pqSPHProxy->modifiedState() != pqProxy::UNMODIFIED)
{
acceptable = true;
}
this->canAccept(acceptable);
if (acceptable)
{
emit this->canAccept();
}
}
//-----------------------------------------------------------------------------