Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/Application/src/objectbrowser.cpp
3203 views
1
/*****************************************************************************
2
* *
3
* Elmer, A Finite Element Software for Multiphysical Problems *
4
* *
5
* Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland *
6
* *
7
* This program is free software; you can redistribute it and/or *
8
* modify it under the terms of the GNU General Public License *
9
* as published by the Free Software Foundation; either version 2 *
10
* of the License, or (at your option) any later version. *
11
* *
12
* This program is distributed in the hope that it will be useful, *
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15
* GNU General Public License for more details. *
16
* *
17
* You should have received a copy of the GNU General Public License *
18
* along with this program (in file fem/GPL-2); if not, write to the *
19
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
20
* Boston, MA 02110-1301, USA. *
21
* *
22
*****************************************************************************/
23
24
/*****************************************************************************
25
* *
26
* ElmerGUI objectbrowser.cpp *
27
* *
28
*****************************************************************************
29
* *
30
* Author: Saeki Takayuki *
31
* Original Date: 11 Jan 2020 *
32
* *
33
*****************************************************************************/
34
35
#include "objectbrowser.h"
36
#include "mainwindow.h"
37
#include <QSettings>
38
#include <QtGui>
39
#include <iostream>
40
41
using namespace std;
42
43
ObjectBrowser::ObjectBrowser(QMainWindow *parent, Qt::WindowFlags flags)
44
: QDockWidget("Object Browser", parent, flags) {
45
setTitleBarWidget(new QWidget());
46
setFeatures(QDockWidget::NoDockWidgetFeatures /*QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable*/);
47
setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
48
if (parent)
49
parent->addDockWidget(Qt::LeftDockWidgetArea, this);
50
51
tree = new QTreeWidget(this);
52
tree->setColumnCount(2);
53
QStringList headerLabels;
54
headerLabels << "Object"
55
<< "Value";
56
tree->setHeaderLabels(headerLabels);
57
58
geometryTopLevelTreeItem = new QTreeWidgetItem();
59
modelTopLevelTreeItem = new QTreeWidgetItem();
60
geometryTopLevelTreeItem->setText(0, "Geometry");
61
modelTopLevelTreeItem->setText(0, "Model");
62
63
bodyPropertyParentTreeItem = new QTreeWidgetItem();
64
boundaryPropertyParentTreeItem = new QTreeWidgetItem();
65
geometryParentTreeItem = new QTreeWidgetItem();
66
setupParentTreeItem = new QTreeWidgetItem();
67
equationParentTreeItem = new QTreeWidgetItem();
68
materialParentTreeItem = new QTreeWidgetItem();
69
bodyForceParentTreeItem = new QTreeWidgetItem();
70
initialConditionParentTreeItem = new QTreeWidgetItem();
71
boundaryConditionParentTreeItem = new QTreeWidgetItem();
72
73
bodyPropertyParentTreeItem->setText(0, "Body");
74
boundaryPropertyParentTreeItem->setText(0, "Boundary");
75
geometryParentTreeItem->setText(0, "Input file");
76
setupParentTreeItem->setText(0, "Setup");
77
equationParentTreeItem->setText(0, "Equation");
78
equationParentTreeItem->setText(1, "[Add...]");
79
materialParentTreeItem->setText(0, "Material");
80
materialParentTreeItem->setText(1, "[Add...]");
81
bodyForceParentTreeItem->setText(0, "Body force");
82
bodyForceParentTreeItem->setText(1, "[Add...]");
83
initialConditionParentTreeItem->setText(0, "Initial condition");
84
initialConditionParentTreeItem->setText(1, "[Add...]");
85
boundaryConditionParentTreeItem->setText(0, "Boundary condition");
86
boundaryConditionParentTreeItem->setText(1, "[Add...]");
87
88
tree->addTopLevelItem(geometryTopLevelTreeItem);
89
tree->addTopLevelItem(modelTopLevelTreeItem);
90
91
geometryTopLevelTreeItem->addChild(geometryParentTreeItem);
92
geometryTopLevelTreeItem->addChild(bodyPropertyParentTreeItem);
93
geometryTopLevelTreeItem->addChild(boundaryPropertyParentTreeItem);
94
// modelTopLevelTreeItem->addChild(setupParentTreeItem); Setup will not be
95
// used so frequently...
96
modelTopLevelTreeItem->addChild(equationParentTreeItem);
97
modelTopLevelTreeItem->addChild(materialParentTreeItem);
98
modelTopLevelTreeItem->addChild(bodyForceParentTreeItem);
99
modelTopLevelTreeItem->addChild(initialConditionParentTreeItem);
100
modelTopLevelTreeItem->addChild(boundaryConditionParentTreeItem);
101
102
geometryTopLevelTreeItem->setExpanded(true);
103
modelTopLevelTreeItem->setExpanded(true);
104
tree->resizeColumnToContents(0);
105
tree->resizeColumnToContents(1);
106
107
setWidget(tree);
108
109
mainWindow = parent;
110
MainWindow *mainwindow = (MainWindow *)mainWindow;
111
112
connect(mainwindow->modelSetupAct, SIGNAL(triggered()), this,
113
SLOT(modelSetupSlot()));
114
connect(mainwindow->addEquationAct, SIGNAL(triggered()), this,
115
SLOT(addEquationSlot()));
116
connect(mainwindow->addMaterialAct, SIGNAL(triggered()), this,
117
SLOT(addMaterialSlot()));
118
connect(mainwindow->addBodyForceAct, SIGNAL(triggered()), this,
119
SLOT(addBodyForceSlot()));
120
connect(mainwindow->addInitialConditionAct, SIGNAL(triggered()), this,
121
SLOT(addInitialConditionSlot()));
122
connect(mainwindow->addBoundaryConditionAct, SIGNAL(triggered()), this,
123
SLOT(addBoundaryConditionSlot()));
124
connect(mainwindow->equationMenu, SIGNAL(triggered(QAction *)), this,
125
SLOT(equationSelectedSlot(QAction *)));
126
connect(mainwindow->materialMenu, SIGNAL(triggered(QAction *)), this,
127
SLOT(materialSelectedSlot(QAction *)));
128
connect(mainwindow->bodyForceMenu, SIGNAL(triggered(QAction *)), this,
129
SLOT(bodyForceSelectedSlot(QAction *)));
130
connect(mainwindow->initialConditionMenu, SIGNAL(triggered(QAction *)), this,
131
SLOT(initialConditionSelectedSlot(QAction *)));
132
connect(mainwindow->boundaryConditionMenu, SIGNAL(triggered(QAction *)), this,
133
SLOT(boundaryConditionSelectedSlot(QAction *)));
134
connect(tree, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this,
135
SLOT(treeItemClickedSlot(QTreeWidgetItem *, int)));
136
connect(tree, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this,
137
SLOT(treeItemDoubleClickedSlot(QTreeWidgetItem *, int)));
138
connect(tree, SIGNAL(itemExpanded(QTreeWidgetItem *)), this,
139
SLOT(treeItemExpandedSlot(
140
QTreeWidgetItem *))); // used to update body and boundary parent
141
connect(tree, SIGNAL(itemSelectionChanged()), this,
142
SLOT(treeItemSelectionChangedSlot()));
143
connect(mainwindow->openAct, SIGNAL(triggered()), this, SLOT(openSlot()));
144
connect(mainwindow->loadAct, SIGNAL(triggered()), this, SLOT(loadSlot()));
145
connect(mainwindow->loadProjectAct, SIGNAL(triggered()), this,
146
SLOT(loadProjectSlot()));
147
connect(mainwindow->recentProject0Act, SIGNAL(triggered()), this,
148
SLOT(loadProjectSlot()));
149
connect(mainwindow->recentProject1Act, SIGNAL(triggered()), this,
150
SLOT(loadProjectSlot()));
151
connect(mainwindow->recentProject2Act, SIGNAL(triggered()), this,
152
SLOT(loadProjectSlot()));
153
connect(mainwindow->recentProject3Act, SIGNAL(triggered()), this,
154
SLOT(loadProjectSlot()));
155
connect(mainwindow->recentProject4Act, SIGNAL(triggered()), this,
156
SLOT(loadProjectSlot()));
157
connect(mainwindow->saveProjectAct, SIGNAL(triggered()), this,
158
SLOT(saveProjectSlot()));
159
connect(mainwindow->newProjectAct, SIGNAL(triggered()), this,
160
SLOT(newProjectSlot()));
161
connect(mainwindow->modelClearAct, SIGNAL(triggered()), this,
162
SLOT(modelClearSlot()));
163
164
connect(mainwindow->viewFullScreenAct, SIGNAL(triggered()), this,
165
SLOT(viewFullScreenSlot()));
166
connect(mainwindow->glWidget, SIGNAL(escPressed()), this,
167
SLOT(viewNormalModeSlot()));
168
169
connect(mainwindow->boundaryDivide, SIGNAL(signalDoDivideSurface(double)),
170
this, SLOT(boundaryDividedSlot(double)));
171
connect(mainwindow->boundaryDivide, SIGNAL(signalDoDivideEdge(double)), this,
172
SLOT(boundaryDividedSlot(double)));
173
connect(mainwindow->surfaceUnifyAct, SIGNAL(triggered()), this,
174
SLOT(boundaryUnifiedSlot()));
175
connect(mainwindow->edgeUnifyAct, SIGNAL(triggered()), this,
176
SLOT(boundaryUnifiedSlot()));
177
178
connect(mainwindow->glWidget, SIGNAL(signalBoundarySelected(list_t *, Qt::KeyboardModifiers)), this,
179
SLOT(boundarySelectedSlot(list_t *, Qt::KeyboardModifiers)));
180
181
connect(mainwindow->meshingThread, SIGNAL(started()), this,
182
SLOT(meshingStartedSlot()));
183
connect(mainwindow->meshingThread, SIGNAL(finished()), this,
184
SLOT(meshingFinishedSlot()));
185
connect(mainwindow->meshingThread, SIGNAL(terminated()), this,
186
SLOT(meshingTerminatedSlot()));
187
188
QApplication *q = (QApplication *)QCoreApplication::instance();
189
connect(q, SIGNAL(focusChanged(QWidget *, QWidget *)), this,
190
SLOT(focusChangedSlot(QWidget *, QWidget *)));
191
192
connect(mainwindow->newProjectAct, SIGNAL(triggered()), this,
193
SLOT(loadProjectSlot()));
194
195
loadProjectSlot();
196
}
197
198
ObjectBrowser::~ObjectBrowser() {}
199
200
void ObjectBrowser::focusChangedSlot(QWidget *old, QWidget *now) {
201
202
if (now == NULL)
203
return;
204
205
QWidget *p = now->parentWidget();
206
while (p != NULL) {
207
now = p;
208
p = now->parentWidget();
209
}
210
211
MainWindow *mainwindow = (MainWindow *)mainWindow;
212
213
if (now->windowTitle() == "Equation") {
214
selectTreeItemByID(equationParentTreeItem, ((DynamicEditor *)now)->ID);
215
return;
216
}
217
if (now->windowTitle() == "Material") {
218
selectTreeItemByID(materialParentTreeItem, ((DynamicEditor *)now)->ID);
219
return;
220
}
221
if (now->windowTitle() == "BodyForce") {
222
selectTreeItemByID(bodyForceParentTreeItem, ((DynamicEditor *)now)->ID);
223
return;
224
}
225
if (now->windowTitle() == "InitialCondition") {
226
selectTreeItemByID(initialConditionParentTreeItem,
227
((DynamicEditor *)now)->ID);
228
return;
229
}
230
if (now->windowTitle() == "BoundaryCondition") {
231
selectTreeItemByID(boundaryConditionParentTreeItem,
232
((DynamicEditor *)now)->ID);
233
return;
234
}
235
if (now->windowTitle().indexOf(QString("Properties for body")) == 0) {
236
int n = bodyPropertyParentTreeItem->childCount();
237
for (int i = 0; i < n; i++) {
238
QTreeWidgetItem *item = bodyPropertyParentTreeItem->child(i);
239
if (item->data(0, Qt::UserRole).value<qulonglong>() == (qulonglong)now) {
240
tree->setCurrentItem(item);
241
return;
242
}
243
}
244
return;
245
}
246
if (now->windowTitle().indexOf(QString("Properties for boundary")) == 0) {
247
int n = boundaryPropertyParentTreeItem->childCount();
248
for (int i = 0; i < n; i++) {
249
QTreeWidgetItem *item = boundaryPropertyParentTreeItem->child(i);
250
if (item->data(0, Qt::UserRole).value<qulonglong>() == (qulonglong)now) {
251
tree->setCurrentItem(item);
252
return;
253
}
254
}
255
return;
256
}
257
}
258
259
void ObjectBrowser::treeItemClickedSlot(QTreeWidgetItem *item, int column) {
260
MainWindow* mainwindow = (MainWindow*) mainWindow;
261
262
// clicking [Add...] button
263
if (item == equationParentTreeItem) {
264
if (column == 1) {
265
mainwindow->addEquationSlot();
266
addEquationSlot();
267
}
268
return;
269
}
270
if (item == materialParentTreeItem) {
271
if (column == 1) {
272
mainwindow->addMaterialSlot();
273
addMaterialSlot();
274
}
275
return;
276
}
277
if (item == bodyForceParentTreeItem) {
278
if (column == 1) {
279
mainwindow->addBodyForceSlot();
280
addBodyForceSlot();
281
}
282
return;
283
}
284
if (item == initialConditionParentTreeItem) {
285
if (column == 1) {
286
mainwindow->addInitialConditionSlot();
287
addInitialConditionSlot();
288
}
289
return;
290
}
291
if (item == boundaryConditionParentTreeItem) {
292
if (column == 1) {
293
mainwindow->addBoundaryConditionSlot();
294
addBoundaryConditionSlot();
295
}
296
return;
297
}
298
}
299
300
void ObjectBrowser::treeItemDoubleClickedSlot(QTreeWidgetItem *item,
301
int column) {
302
303
MainWindow *mainwindow = (MainWindow *)mainWindow;
304
305
// Show selected dynamic editor
306
if (item->parent() == equationParentTreeItem) {
307
DynamicEditor *pe =
308
(DynamicEditor *)item->data(0, Qt::UserRole).value<qulonglong>();
309
// snap(pe);
310
mainwindow->equationSelectedSlot(pe->menuAction);
311
312
QGroupBox *box = (QGroupBox *)pe->spareScroll->widget();
313
if (!mainwindow->glWidget->hasMesh() || box == NULL)
314
return;
315
for (int i = 2; i < box->children().size(); i++) {
316
QCheckBox *cb = (QCheckBox *)box->children()[i];
317
connect1(cb, SIGNAL(stateChanged(int)), this,
318
SLOT(bodyCheckBoxChangedSlot(int)));
319
}
320
321
return;
322
}
323
if (item->parent() == materialParentTreeItem) {
324
DynamicEditor *pe =
325
(DynamicEditor *)item->data(0, Qt::UserRole).value<qulonglong>();
326
// snap(pe);
327
mainwindow->materialSelectedSlot(pe->menuAction);
328
329
QGroupBox *box = (QGroupBox *)pe->spareScroll->widget();
330
if (!mainwindow->glWidget->hasMesh() || box == NULL)
331
return;
332
for (int i = 2; i < box->children().size(); i++) {
333
QCheckBox *cb = (QCheckBox *)box->children()[i];
334
connect1(cb, SIGNAL(stateChanged(int)), this,
335
SLOT(bodyCheckBoxChangedSlot(int)));
336
}
337
338
return;
339
}
340
if (item->parent() == bodyForceParentTreeItem) {
341
DynamicEditor *pe =
342
(DynamicEditor *)item->data(0, Qt::UserRole).value<qulonglong>();
343
// snap(pe);
344
mainwindow->bodyForceSelectedSlot(pe->menuAction);
345
346
QGroupBox *box = (QGroupBox *)pe->spareScroll->widget();
347
if (!mainwindow->glWidget->hasMesh() || box == NULL)
348
return;
349
for (int i = 2; i < box->children().size(); i++) {
350
QCheckBox *cb = (QCheckBox *)box->children()[i];
351
connect1(cb, SIGNAL(stateChanged(int)), this,
352
SLOT(bodyCheckBoxChangedSlot(int)));
353
}
354
355
return;
356
}
357
if (item->parent() == initialConditionParentTreeItem) {
358
DynamicEditor *pe =
359
(DynamicEditor *)item->data(0, Qt::UserRole).value<qulonglong>();
360
// snap(pe);
361
mainwindow->initialConditionSelectedSlot(pe->menuAction);
362
363
QGroupBox *box = (QGroupBox *)pe->spareScroll->widget();
364
if (!mainwindow->glWidget->hasMesh() || box == NULL)
365
return;
366
for (int i = 2; i < box->children().size(); i++) {
367
QCheckBox *cb = (QCheckBox *)box->children()[i];
368
connect1(cb, SIGNAL(stateChanged(int)), this,
369
SLOT(bodyCheckBoxChangedSlot(int)));
370
}
371
372
return;
373
}
374
if (item->parent() == boundaryConditionParentTreeItem) {
375
DynamicEditor *pe =
376
(DynamicEditor *)item->data(0, Qt::UserRole).value<qulonglong>();
377
// snap(pe);
378
mainwindow->boundaryConditionSelectedSlot(pe->menuAction);
379
380
// connect checkbox
381
QGroupBox *box = (QGroupBox *)pe->spareScroll->widget();
382
if (!mainwindow->glWidget->hasMesh() || box == NULL)
383
return;
384
for (int i = 2; i < box->children().size(); i++) {
385
QCheckBox *cb = (QCheckBox *)box->children()[i];
386
connect1(cb, SIGNAL(stateChanged(int)), this,
387
SLOT(boundaryCheckBoxChangedSlot(int)));
388
}
389
390
return;
391
}
392
393
// show property editor
394
// bool bodyEditActive = mainwindow->bodyEditActive;
395
// bool bcEditActive = mainwindow->bcEditActive;
396
if (item->parent() == boundaryPropertyParentTreeItem) {
397
BoundaryPropertyEditor *pe =
398
(BoundaryPropertyEditor *)item->data(0, Qt::UserRole)
399
.value<qulonglong>();
400
if (pe == NULL) {
401
cout << " BoundaryPropertyEditor NULL" << endl;
402
return;
403
}
404
list_t *l = selectBoundary(pe);
405
mainwindow->bcEditActive = true;
406
mainwindow->bodyEditActive = false;
407
mainwindow->glWidget->bodyEditActive = false;
408
mainwindow->bcEditAct->setChecked(true);
409
mainwindow->bodyEditAct->setChecked(false);
410
mainwindow->boundarySelectedSlot(l, Qt::NoModifier);
411
// mainwindow->bcEditActive = bcEditActive;
412
// mainwindow->bodyEditActive = bodyEditActive;
413
connect1(
414
pe, SIGNAL(BoundaryComboChanged(BoundaryPropertyEditor *, QString)),
415
this, SLOT(boundaryComboChanged(BoundaryPropertyEditor *, QString)));
416
connect1(pe->ui.applyButton, SIGNAL(clicked(bool)), this,
417
SLOT(boundaryPropertyEditorAccepted(bool)));
418
connect1(pe->ui.discardButton, SIGNAL(clicked(bool)), this,
419
SLOT(boundaryPropertyEditorDiscarded(bool)));
420
snap(pe);
421
pe->show();
422
pe->raise();
423
return;
424
}
425
if (item->parent() != NULL &&
426
item->parent()->parent() == boundaryPropertyParentTreeItem) {
427
BoundaryPropertyEditor *pe = (BoundaryPropertyEditor *)item->parent()
428
->data(0, Qt::UserRole)
429
.value<qulonglong>();
430
if (pe == NULL) {
431
cout << " BoundaryPropertyEditor NULL" << endl;
432
return;
433
}
434
list_t *l = selectBoundary(pe);
435
mainwindow->bcEditActive = true;
436
mainwindow->bodyEditActive = false;
437
mainwindow->glWidget->bodyEditActive = false;
438
mainwindow->bcEditAct->setChecked(true);
439
mainwindow->bodyEditAct->setChecked(false);
440
mainwindow->boundarySelectedSlot(l, Qt::NoModifier);
441
// mainwindow->bcEditActive = bcEditActive;
442
// mainwindow->bodyEditActive = bodyEditActive;
443
connect1(
444
pe, SIGNAL(BoundaryComboChanged(BoundaryPropertyEditor *, QString)),
445
this, SLOT(boundaryComboChanged(BoundaryPropertyEditor *, QString)));
446
connect1(pe->ui.applyButton, SIGNAL(clicked(bool)), this,
447
SLOT(boundaryPropertyEditorAccepted(bool)));
448
connect1(pe->ui.discardButton, SIGNAL(clicked(bool)), this,
449
SLOT(boundaryPropertyEditorDiscarded(bool)));
450
snap(pe);
451
pe->show();
452
pe->raise();
453
return;
454
}
455
if (item->parent() == bodyPropertyParentTreeItem) {
456
BodyPropertyEditor *pe =
457
(BodyPropertyEditor *)item->data(0, Qt::UserRole).value<qulonglong>();
458
if (pe == NULL) {
459
cout << " BodyPropertyEditor NULL" << endl;
460
return;
461
}
462
list_t *l = selectBody(pe);
463
mainwindow->bcEditActive = false;
464
mainwindow->bodyEditActive = true;
465
mainwindow->glWidget->bodyEditActive = true;
466
mainwindow->bcEditAct->setChecked(false);
467
mainwindow->bodyEditAct->setChecked(true);
468
mainwindow->boundarySelectedSlot(l, Qt::NoModifier);
469
// mainwindow->bcEditActive = bcEditActive;
470
// mainwindow->bodyEditActive = bodyEditActive;
471
connect1(pe,
472
SIGNAL(BodyMaterialComboChanged(BodyPropertyEditor *, QString)),
473
this, SLOT(bodyComboChanged(BodyPropertyEditor *, QString)));
474
connect1(pe, SIGNAL(BodyInitialComboChanged(BodyPropertyEditor *, QString)),
475
this, SLOT(bodyComboChanged(BodyPropertyEditor *, QString)));
476
connect1(pe, SIGNAL(BodyForceComboChanged(BodyPropertyEditor *, QString)),
477
this, SLOT(bodyComboChanged(BodyPropertyEditor *, QString)));
478
connect1(pe,
479
SIGNAL(BodyEquationComboChanged(BodyPropertyEditor *, QString)),
480
this, SLOT(bodyComboChanged(BodyPropertyEditor *, QString)));
481
connect1(pe->ui.applyButton, SIGNAL(clicked(bool)), this,
482
SLOT(bodyPropertyEditorAccepted(bool)));
483
connect1(pe->ui.discardButton, SIGNAL(clicked(bool)), this,
484
SLOT(bodyPropertyEditorDiscarded(bool)));
485
snap(pe);
486
pe->show();
487
pe->raise();
488
tree->collapseItem(item);
489
return;
490
}
491
if (item->parent() != NULL &&
492
item->parent()->parent() == bodyPropertyParentTreeItem) {
493
BodyPropertyEditor *pe = (BodyPropertyEditor *)item->parent()
494
->data(0, Qt::UserRole)
495
.value<qulonglong>();
496
if (pe == NULL) {
497
cout << " BodyPropertyEditor NULL" << endl;
498
return;
499
}
500
list_t *l = selectBody(pe);
501
mainwindow->bcEditActive = false;
502
mainwindow->bodyEditActive = true;
503
mainwindow->glWidget->bodyEditActive = true;
504
mainwindow->bcEditAct->setChecked(false);
505
mainwindow->bodyEditAct->setChecked(true);
506
mainwindow->boundarySelectedSlot(l, Qt::NoModifier);
507
// mainwindow->bcEditActive = bcEditActive;
508
// mainwindow->bodyEditActive = bodyEditActive;
509
connect1(pe,
510
SIGNAL(BodyMaterialComboChanged(BodyPropertyEditor *, QString)),
511
this, SLOT(bodyComboChanged(BodyPropertyEditor *, QString)));
512
connect1(pe, SIGNAL(BodyInitialComboChanged(BodyPropertyEditor *, QString)),
513
this, SLOT(bodyComboChanged(BodyPropertyEditor *, QString)));
514
connect1(pe, SIGNAL(BodyForceComboChanged(BodyPropertyEditor *, QString)),
515
this, SLOT(bodyComboChanged(BodyPropertyEditor *, QString)));
516
connect1(pe,
517
SIGNAL(BodyEquationComboChanged(BodyPropertyEditor *, QString)),
518
this, SLOT(bodyComboChanged(BodyPropertyEditor *, QString)));
519
connect1(pe->ui.applyButton, SIGNAL(clicked(bool)), this,
520
SLOT(bodyPropertyEditorAccepted(bool)));
521
connect1(pe->ui.discardButton, SIGNAL(clicked(bool)), this,
522
SLOT(bodyPropertyEditorDiscarded(bool)));
523
snap(pe);
524
pe->show();
525
pe->raise();
526
return;
527
}
528
}
529
530
void ObjectBrowser::addToTree(DynamicEditor *de, bool select /*= false*/) {
531
if (de == NULL)
532
return;
533
if (de->ID < 0)
534
return; // removed item
535
QTreeWidgetItem *treeItem = new QTreeWidgetItem();
536
treeItem->setText(0,
537
de->nameEdit->text()
538
.trimmed()); // +" [" + QString::number(de->ID) + "]");
539
QString title = de->windowTitle();
540
if (title == "Equation") {
541
equationParentTreeItem->addChild(treeItem);
542
connect1(de, SIGNAL(dynamicEditorReady(int, int)), this,
543
SLOT(equationEditorFinishedSlot(int, int)));
544
545
QGroupBox *box = (QGroupBox *)de->spareScroll->widget();
546
bool used = false;
547
if (box != NULL) {
548
for (int i = 2; i < box->children().size(); i++) {
549
QCheckBox *cb = (QCheckBox *)box->children()[i];
550
connect1(cb, SIGNAL(stateChanged(int)), this,
551
SLOT(bodyCheckBoxChangedSlot(int)));
552
used |= cb->isChecked();
553
}
554
}
555
// if(!used) treeItem->setText(0, "*" + de->nameEdit->text().trimmed());
556
} else if (title == "Material") {
557
materialParentTreeItem->addChild(treeItem);
558
connect1(de, SIGNAL(dynamicEditorReady(int, int)), this,
559
SLOT(materialEditorFinishedSlot(int, int)));
560
561
QGroupBox *box = (QGroupBox *)de->spareScroll->widget();
562
bool used = false;
563
if (box != NULL) {
564
for (int i = 2; i < box->children().size(); i++) {
565
QCheckBox *cb = (QCheckBox *)box->children()[i];
566
connect1(cb, SIGNAL(stateChanged(int)), this,
567
SLOT(bodyCheckBoxChangedSlot(int)));
568
used |= cb->isChecked();
569
}
570
}
571
// if(!used) treeItem->setText(0, "*" + de->nameEdit->text().trimmed());
572
} else if (title == "BodyForce") {
573
bodyForceParentTreeItem->addChild(treeItem);
574
connect1(de, SIGNAL(dynamicEditorReady(int, int)), this,
575
SLOT(bodyForceEditorFinishedSlot(int, int)));
576
577
QGroupBox *box = (QGroupBox *)de->spareScroll->widget();
578
bool used = false;
579
if (box != NULL) {
580
for (int i = 2; i < box->children().size(); i++) {
581
QCheckBox *cb = (QCheckBox *)box->children()[i];
582
connect1(cb, SIGNAL(stateChanged(int)), this,
583
SLOT(bodyCheckBoxChangedSlot(int)));
584
used |= cb->isChecked();
585
}
586
}
587
// if(!used) treeItem->setText(0, "*" + de->nameEdit->text().trimmed());
588
} else if (title == "InitialCondition") {
589
initialConditionParentTreeItem->addChild(treeItem);
590
connect1(de, SIGNAL(dynamicEditorReady(int, int)), this,
591
SLOT(initialConditionEditorFinishedSlot(int, int)));
592
593
QGroupBox *box = (QGroupBox *)de->spareScroll->widget();
594
bool used = false;
595
if (box != NULL) {
596
for (int i = 2; i < box->children().size(); i++) {
597
QCheckBox *cb = (QCheckBox *)box->children()[i];
598
connect1(cb, SIGNAL(stateChanged(int)), this,
599
SLOT(bodyCheckBoxChangedSlot(int)));
600
used |= cb->isChecked();
601
}
602
}
603
// if(!used) treeItem->setText(0, "*" + de->nameEdit->text().trimmed());
604
} else if (title == "BoundaryCondition") {
605
boundaryConditionParentTreeItem->addChild(treeItem);
606
connect1(de, SIGNAL(dynamicEditorReady(int, int)), this,
607
SLOT(boundaryConditionEditorFinishedSlot(int, int)));
608
609
QGroupBox *box = (QGroupBox *)de->spareScroll->widget();
610
bool used = false;
611
if (box != NULL) {
612
for (int i = 2; i < box->children().size(); i++) {
613
QCheckBox *cb = (QCheckBox *)box->children()[i];
614
connect1(cb, SIGNAL(stateChanged(int)), this,
615
SLOT(boundaryCheckBoxChangedSlot(int)));
616
used |= cb->isChecked();
617
}
618
}
619
// if(!used) treeItem->setText(0, "*" + de->nameEdit->text().trimmed());
620
} else {
621
cout << " ***Warning*** In ObjectBrowser::addTotree(), the DynamicEditor "
622
"did not match to any of categories.";
623
}
624
625
treeItem->setData(0, Qt::UserRole, QVariant::fromValue((qulonglong)de));
626
if (select)
627
tree->setCurrentItem(treeItem);
628
else
629
treeItem->parent()->setExpanded(true);
630
631
// tree->resizeColumnToContents(0);
632
// tree->resizeColumnToContents(1);
633
}
634
635
void ObjectBrowser::modelSetupSlot() {}
636
void ObjectBrowser::addEquationSlot() {
637
MainWindow *mainwindow = (MainWindow *)mainWindow;
638
DynamicEditor *de = (DynamicEditor *)mainwindow->equationEditor.last();
639
addToTree(de, true);
640
snap(de);
641
}
642
void ObjectBrowser::addMaterialSlot() {
643
MainWindow *mainwindow = (MainWindow *)mainWindow;
644
DynamicEditor *de = (DynamicEditor *)mainwindow->materialEditor.last();
645
addToTree(de, true);
646
snap(de);
647
}
648
void ObjectBrowser::addBodyForceSlot() {
649
MainWindow *mainwindow = (MainWindow *)mainWindow;
650
DynamicEditor *de = (DynamicEditor *)mainwindow->bodyForceEditor.last();
651
addToTree(de, true);
652
snap(de);
653
}
654
void ObjectBrowser::addInitialConditionSlot() {
655
MainWindow *mainwindow = (MainWindow *)mainWindow;
656
DynamicEditor *de =
657
(DynamicEditor *)mainwindow->initialConditionEditor.last();
658
addToTree(de, true);
659
snap(de);
660
}
661
void ObjectBrowser::addBoundaryConditionSlot() {
662
MainWindow *mainwindow = (MainWindow *)mainWindow;
663
DynamicEditor *de =
664
(DynamicEditor *)mainwindow->boundaryConditionEditor.last();
665
addToTree(de, true);
666
snap(de);
667
}
668
void ObjectBrowser::equationSelectedSlot(QAction *action) {
669
int n = equationParentTreeItem->childCount();
670
for (int i = 0; i < n; i++) {
671
QTreeWidgetItem *child = equationParentTreeItem->child(i);
672
DynamicEditor *de =
673
(DynamicEditor *)child->data(0, Qt::UserRole).value<qulonglong>();
674
if (de->menuAction == action) {
675
tree->setCurrentItem(child);
676
return;
677
}
678
}
679
}
680
void ObjectBrowser::materialSelectedSlot(QAction *action) {
681
int n = materialParentTreeItem->childCount();
682
for (int i = 0; i < n; i++) {
683
QTreeWidgetItem *child = materialParentTreeItem->child(i);
684
DynamicEditor *de =
685
(DynamicEditor *)child->data(0, Qt::UserRole).value<qulonglong>();
686
if (de->menuAction == action) {
687
tree->setCurrentItem(child);
688
return;
689
}
690
}
691
}
692
void ObjectBrowser::bodyForceSelectedSlot(QAction *action) {
693
int n = bodyForceParentTreeItem->childCount();
694
for (int i = 0; i < n; i++) {
695
QTreeWidgetItem *child = bodyForceParentTreeItem->child(i);
696
DynamicEditor *de =
697
(DynamicEditor *)child->data(0, Qt::UserRole).value<qulonglong>();
698
if (de->menuAction == action) {
699
tree->setCurrentItem(child);
700
return;
701
}
702
}
703
}
704
void ObjectBrowser::initialConditionSelectedSlot(QAction *action) {
705
int n = initialConditionParentTreeItem->childCount();
706
for (int i = 0; i < n; i++) {
707
QTreeWidgetItem *child = initialConditionParentTreeItem->child(i);
708
DynamicEditor *de =
709
(DynamicEditor *)child->data(0, Qt::UserRole).value<qulonglong>();
710
if (de->menuAction == action) {
711
tree->setCurrentItem(child);
712
return;
713
}
714
}
715
}
716
void ObjectBrowser::boundaryConditionSelectedSlot(QAction *action) {
717
int n = boundaryConditionParentTreeItem->childCount();
718
for (int i = 0; i < n; i++) {
719
QTreeWidgetItem *child = boundaryConditionParentTreeItem->child(i);
720
DynamicEditor *de =
721
(DynamicEditor *)child->data(0, Qt::UserRole).value<qulonglong>();
722
if (de->menuAction == action) {
723
tree->setCurrentItem(child);
724
return;
725
}
726
}
727
}
728
729
void ObjectBrowser::equationEditorFinishedSlot(int signal, int id) {
730
updateEquation();
731
updateBodyProperties();
732
updateBoundaryProperties();
733
if (signal != MAT_NEW)
734
selectTreeItemByID(equationParentTreeItem, id);
735
else {
736
MainWindow *mainwindow = (MainWindow *)mainWindow;
737
DynamicEditor *de = mainwindow->equationEditor.last();
738
if (de != NULL)
739
selectTreeItemByID(equationParentTreeItem, de->ID);
740
else
741
selectTreeItemByID(equationParentTreeItem, -1);
742
}
743
}
744
745
void ObjectBrowser::materialEditorFinishedSlot(int signal, int id) {
746
updateMaterial();
747
updateBodyProperties();
748
updateBoundaryProperties();
749
if (signal != MAT_NEW)
750
selectTreeItemByID(materialParentTreeItem, id);
751
else {
752
MainWindow *mainwindow = (MainWindow *)mainWindow;
753
DynamicEditor *de = mainwindow->materialEditor.last();
754
if (de != NULL)
755
selectTreeItemByID(materialParentTreeItem, de->ID);
756
else
757
selectTreeItemByID(materialParentTreeItem, -1);
758
}
759
}
760
761
void ObjectBrowser::bodyForceEditorFinishedSlot(int signal, int id) {
762
updateBodyForce();
763
updateBodyProperties();
764
updateBoundaryProperties();
765
if (signal != MAT_NEW)
766
selectTreeItemByID(bodyForceParentTreeItem, id);
767
else {
768
MainWindow *mainwindow = (MainWindow *)mainWindow;
769
DynamicEditor *de = mainwindow->bodyForceEditor.last();
770
if (de != NULL)
771
selectTreeItemByID(bodyForceParentTreeItem, de->ID);
772
else
773
selectTreeItemByID(bodyForceParentTreeItem, -1);
774
}
775
}
776
777
void ObjectBrowser::initialConditionEditorFinishedSlot(int signal, int id) {
778
updateInitialCondition();
779
updateBodyProperties();
780
updateBoundaryProperties();
781
if (signal != MAT_NEW)
782
selectTreeItemByID(initialConditionParentTreeItem, id);
783
else {
784
MainWindow *mainwindow = (MainWindow *)mainWindow;
785
DynamicEditor *de = mainwindow->initialConditionEditor.last();
786
if (de != NULL)
787
selectTreeItemByID(initialConditionParentTreeItem, de->ID);
788
else
789
selectTreeItemByID(initialConditionParentTreeItem, -1);
790
}
791
}
792
793
void ObjectBrowser::boundaryConditionEditorFinishedSlot(int signal, int id) {
794
updateBoundaryCondition();
795
updateBodyProperties();
796
updateBoundaryProperties();
797
if (signal != MAT_NEW)
798
selectTreeItemByID(boundaryConditionParentTreeItem, id);
799
else {
800
MainWindow *mainwindow = (MainWindow *)mainWindow;
801
DynamicEditor *de = mainwindow->boundaryConditionEditor.last();
802
if (de != NULL)
803
selectTreeItemByID(boundaryConditionParentTreeItem, de->ID);
804
else
805
selectTreeItemByID(boundaryConditionParentTreeItem, -1);
806
}
807
}
808
809
void ObjectBrowser::openSlot() {
810
MainWindow *mainwindow = (MainWindow *)mainWindow;
811
QFileInfo fi(mainwindow->geometryInputFileName);
812
geometryParentTreeItem->setText(0, "Input file");
813
geometryParentTreeItem->setText(1, fi.fileName());
814
815
bodyPropertyParentTreeItem->setExpanded(false);
816
bodyPropertyParentTreeItem->addChild(new QTreeWidgetItem()); // dummy
817
boundaryPropertyParentTreeItem->setExpanded(false);
818
boundaryPropertyParentTreeItem->addChild(new QTreeWidgetItem()); // dummy
819
}
820
821
void ObjectBrowser::loadSlot() {
822
MainWindow *mainwindow = (MainWindow *)mainWindow;
823
QFileInfo fi(mainwindow->saveDirName);
824
geometryParentTreeItem->setText(0, "Elmer mesh dir");
825
geometryParentTreeItem->setText(1, fi.fileName());
826
827
bodyPropertyParentTreeItem->setExpanded(false);
828
bodyPropertyParentTreeItem->addChild(new QTreeWidgetItem()); // dummy
829
boundaryPropertyParentTreeItem->setExpanded(false);
830
boundaryPropertyParentTreeItem->addChild(new QTreeWidgetItem()); // dummy
831
}
832
833
void ObjectBrowser::loadProjectSlot() {
834
MainWindow *mainwindow = (MainWindow *)mainWindow;
835
if (mainwindow->currentProjectDirName.isEmpty())
836
return;
837
838
modelClearSlot();
839
840
int n = mainwindow->equationEditor.size();
841
for (int i = 0; i < n; i++) {
842
addToTree(mainwindow->equationEditor.at(i));
843
}
844
n = mainwindow->materialEditor.size();
845
for (int i = 0; i < n; i++) {
846
addToTree(mainwindow->materialEditor.at(i));
847
}
848
n = mainwindow->bodyForceEditor.size();
849
for (int i = 0; i < n; i++) {
850
addToTree(mainwindow->bodyForceEditor.at(i));
851
}
852
n = mainwindow->initialConditionEditor.size();
853
for (int i = 0; i < n; i++) {
854
addToTree(mainwindow->initialConditionEditor.at(i));
855
}
856
n = mainwindow->boundaryConditionEditor.size();
857
for (int i = 0; i < n; i++) {
858
addToTree(mainwindow->boundaryConditionEditor.at(i));
859
}
860
861
if (!mainwindow->geometryInputFileName.isEmpty()) {
862
QFileInfo fi(mainwindow->geometryInputFileName);
863
geometryParentTreeItem->setText(0, "Input file");
864
geometryParentTreeItem->setText(1, fi.fileName());
865
} else if (!mainwindow->saveDirName.isEmpty()) {
866
QFileInfo fi(mainwindow->saveDirName);
867
geometryParentTreeItem->setText(0, "Elmer mesh dir");
868
geometryParentTreeItem->setText(1, fi.fileName());
869
} else {
870
geometryParentTreeItem->setText(0, "Input file");
871
geometryParentTreeItem->setText(1, "");
872
}
873
874
bodyPropertyParentTreeItem->setExpanded(false);
875
bodyPropertyParentTreeItem->addChild(new QTreeWidgetItem()); // dummy
876
boundaryPropertyParentTreeItem->setExpanded(false);
877
boundaryPropertyParentTreeItem->addChild(new QTreeWidgetItem()); // dummy
878
879
tree->resizeColumnToContents(0);
880
tree->resizeColumnToContents(1);
881
882
/* Call rebuildGLLists() to avoid a problem of 3D surface mesh not shown
883
correctly when project loading (typically, TemperatureGeneric sample) */
884
mainwindow->rebuildGLLists();
885
}
886
887
void ObjectBrowser::saveProjectSlot() {
888
MainWindow *mainwindow = (MainWindow *)mainWindow;
889
if (mainwindow->currentProjectDirName.isEmpty())
890
return;
891
892
if (!mainwindow->geometryInputFileName.isEmpty()) {
893
QFileInfo fi(mainwindow->geometryInputFileName);
894
geometryParentTreeItem->setText(0, "Input file");
895
geometryParentTreeItem->setText(1, fi.fileName());
896
} else if (!mainwindow->saveDirName.isEmpty()) {
897
QFileInfo fi(mainwindow->saveDirName);
898
geometryParentTreeItem->setText(0, "Elmer mesh dir");
899
geometryParentTreeItem->setText(1, fi.fileName());
900
} else {
901
geometryParentTreeItem->setText(0, "Input file");
902
geometryParentTreeItem->setText(1, "");
903
}
904
}
905
906
void ObjectBrowser::newProjectSlot() { modelClearSlot(); }
907
908
void ObjectBrowser::modelClearSlot() {
909
geometryParentTreeItem->setText(1, "");
910
QTreeWidgetItem *treeItem = 0;
911
tree->setCurrentItem(geometryTopLevelTreeItem);
912
while (treeItem = bodyPropertyParentTreeItem->takeChild(0))
913
delete treeItem;
914
while (treeItem = boundaryPropertyParentTreeItem->takeChild(0))
915
delete treeItem;
916
while (treeItem = equationParentTreeItem->takeChild(0))
917
delete treeItem;
918
while (treeItem = materialParentTreeItem->takeChild(0))
919
delete treeItem;
920
while (treeItem = bodyForceParentTreeItem->takeChild(0))
921
delete treeItem;
922
while (treeItem = initialConditionParentTreeItem->takeChild(0))
923
delete treeItem;
924
while (treeItem = boundaryConditionParentTreeItem->takeChild(0))
925
delete treeItem;
926
927
openSlot();
928
}
929
930
void ObjectBrowser::treeItemExpandedSlot(
931
QTreeWidgetItem *item) { // used to update body and boundary parent
932
933
if (item == bodyPropertyParentTreeItem) {
934
updateBodyProperties();
935
for (int i = 0; i < bodyPropertyParentTreeItem->childCount(); i++)
936
bodyPropertyParentTreeItem->child(i)->setExpanded(true);
937
updateBoundaryProperties(); // This was added to avoid crushing when choosing
938
// body property just after loading 3D mesh
939
// without expanding boundary condition parent
940
// item.
941
}
942
943
if (item == boundaryPropertyParentTreeItem)
944
updateBoundaryProperties();
945
}
946
947
void ObjectBrowser::updateBoundaryProperties(
948
BoundaryPropertyEditor *selectThis /*=NULL*/) {
949
950
MainWindow *mainwindow = (MainWindow *)mainWindow;
951
if (tree->currentItem() != NULL &&
952
tree->currentItem()->parent() == boundaryPropertyParentTreeItem) {
953
tree->setCurrentItem(boundaryPropertyParentTreeItem); // to improve speed
954
}
955
QTreeWidgetItem *treeItem = 0;
956
while (treeItem = boundaryPropertyParentTreeItem->takeChild(0))
957
delete treeItem;
958
959
QMapIterator<int, int> itr(mainwindow->glWidget->boundaryMap);
960
while (itr.hasNext()) {
961
itr.next();
962
int n = itr.key();
963
if (n >= 0) {
964
int m = itr.value();
965
966
if (m >= mainwindow->boundaryPropertyEditor.size())
967
mainwindow->boundaryPropertyEditor.resize(m + 1);
968
969
if (!mainwindow->boundaryPropertyEditor[m])
970
mainwindow->boundaryPropertyEditor[m] = new BoundaryPropertyEditor;
971
972
BoundaryPropertyEditor *pe = mainwindow->boundaryPropertyEditor[m];
973
974
treeItem = new QTreeWidgetItem();
975
boundaryPropertyParentTreeItem->addChild(treeItem);
976
977
treeItem->setText(0, "Boundary " + QString::number(n));
978
// if(pe->touched && pe->condition != 0) treeItem->setText(0, "Boundary "
979
// + QString::number(n)); else treeItem->setText(0, "*Boundary " +
980
// QString::number(n));
981
982
treeItem->setData(0, Qt::UserRole, QVariant::fromValue((qulonglong)pe));
983
if (pe->condition != 0) {
984
if (pe->touched)
985
treeItem->setText(1, pe->condition->nameEdit->text().trimmed());
986
else
987
treeItem->setText(1, "<Canceled>" +
988
pe->condition->nameEdit->text().trimmed());
989
treeItem->setData(1, Qt::UserRole,
990
QVariant::fromValue((qulonglong)pe->condition));
991
}
992
}
993
}
994
995
if (selectThis != NULL) {
996
QTreeWidgetItem *item;
997
for (int i = 0; i < boundaryPropertyParentTreeItem->childCount(); i++) {
998
item = boundaryPropertyParentTreeItem->child(i);
999
if (item->data(0, Qt::UserRole).value<qulonglong>() ==
1000
(qulonglong)selectThis) {
1001
tree->setCurrentItem(item);
1002
return;
1003
}
1004
}
1005
}
1006
}
1007
1008
void ObjectBrowser::boundaryUnifiedSlot() {
1009
updateBodyProperties();
1010
updateBoundaryProperties();
1011
}
1012
void ObjectBrowser::boundaryDividedSlot(double d) {
1013
bodyPropertyParentTreeItem->setExpanded(false);
1014
bodyPropertyParentTreeItem->addChild(new QTreeWidgetItem()); // dummy
1015
boundaryPropertyParentTreeItem->setExpanded(false);
1016
boundaryPropertyParentTreeItem->addChild(new QTreeWidgetItem()); // dummy
1017
}
1018
1019
void ObjectBrowser::boundarySelectedSlot(list_t *l, Qt::KeyboardModifiers modifiers) {
1020
1021
bodyPropertyParentTreeItem->setExpanded(true);
1022
boundaryPropertyParentTreeItem->setExpanded(true);
1023
1024
MainWindow *mainwindow = (MainWindow *)mainWindow;
1025
QDialog *dialog = NULL;
1026
1027
if (mainwindow->bodyEditActive &&
1028
mainwindow->glWidget->currentlySelectedBody != -1) {
1029
int m = mainwindow->glWidget->bodyMap.value(
1030
mainwindow->glWidget->currentlySelectedBody);
1031
dialog = (QDialog *)mainwindow->bodyPropertyEditor[m];
1032
} else {
1033
1034
for (int i = 0; i < mainwindow->glWidget->boundaryMap.count(); i++) {
1035
int n = mainwindow->glWidget->boundaryMap.key(i);
1036
if (n >= 0) {
1037
int m = mainwindow->glWidget->boundaryMap.value(n);
1038
if (m >= 0 && m < mainwindow->boundaryPropertyEditor.size() &&
1039
mainwindow->boundaryPropertyEditor[m] != NULL &&
1040
boundaryList(n) == l) {
1041
dialog = mainwindow->boundaryPropertyEditor[m];
1042
}
1043
}
1044
}
1045
1046
if (dialog == NULL) {
1047
for (int i = 0; i < mainwindow->glWidget->bodyMap.count(); i++) {
1048
int n = mainwindow->glWidget->bodyMap.key(i);
1049
if (n >= 0) {
1050
int m = mainwindow->glWidget->bodyMap.value(n);
1051
if (m >= 0 && m < mainwindow->bodyPropertyEditor.size() &&
1052
mainwindow->bodyPropertyEditor[m] != NULL && bodyList(n) == l) {
1053
dialog = mainwindow->bodyPropertyEditor[m];
1054
}
1055
}
1056
}
1057
}
1058
}
1059
1060
if (dialog == NULL) {
1061
cout << " could not find selected body/boundary in "
1062
"ObjectBrowser::boundarySelectedSlot(list_t*, Qt::KeyboardModifiers). list_t:"
1063
<< (qulonglong)l << endl;
1064
return;
1065
}
1066
1067
for (int i = 0; i < boundaryPropertyParentTreeItem->childCount(); i++) {
1068
QTreeWidgetItem *child = boundaryPropertyParentTreeItem->child(i);
1069
if (child->data(0, Qt::UserRole) == (qulonglong)dialog) {
1070
if( !(modifiers & Qt::ControlModifier) )tree->setCurrentItem(child);
1071
BoundaryPropertyEditor *pe = (BoundaryPropertyEditor *)dialog;
1072
connect1(
1073
pe, SIGNAL(BoundaryComboChanged(BoundaryPropertyEditor *, QString)),
1074
this, SLOT(boundaryComboChanged(BoundaryPropertyEditor *, QString)));
1075
connect1(pe->ui.applyButton, SIGNAL(clicked(bool)), this,
1076
SLOT(boundaryPropertyEditorAccepted(bool)));
1077
connect1(pe->ui.discardButton, SIGNAL(clicked(bool)), this,
1078
SLOT(boundaryPropertyEditorDiscarded(bool)));
1079
return;
1080
}
1081
}
1082
1083
for (int i = 0; i < bodyPropertyParentTreeItem->childCount(); i++) {
1084
QTreeWidgetItem *child = bodyPropertyParentTreeItem->child(i);
1085
if (child->data(0, Qt::UserRole) == (qulonglong)dialog) {
1086
if( !(modifiers & Qt::ControlModifier)) tree->setCurrentItem(child);
1087
BodyPropertyEditor *pe = (BodyPropertyEditor *)dialog;
1088
connect1(pe,
1089
SIGNAL(BodyMaterialComboChanged(BodyPropertyEditor *, QString)),
1090
this, SLOT(bodyComboChanged(BodyPropertyEditor *, QString)));
1091
connect1(pe,
1092
SIGNAL(BodyInitialComboChanged(BodyPropertyEditor *, QString)),
1093
this, SLOT(bodyComboChanged(BodyPropertyEditor *, QString)));
1094
connect1(pe, SIGNAL(BodyForceComboChanged(BodyPropertyEditor *, QString)),
1095
this, SLOT(bodyComboChanged(BodyPropertyEditor *, QString)));
1096
connect1(pe,
1097
SIGNAL(BodyEquationComboChanged(BodyPropertyEditor *, QString)),
1098
this, SLOT(bodyComboChanged(BodyPropertyEditor *, QString)));
1099
connect1(pe->ui.applyButton, SIGNAL(clicked(bool)), this,
1100
SLOT(bodyPropertyEditorAccepted(bool)));
1101
connect1(pe->ui.discardButton, SIGNAL(clicked(bool)), this,
1102
SLOT(bodyPropertyEditorDiscarded(bool)));
1103
return;
1104
}
1105
}
1106
}
1107
1108
list_t *ObjectBrowser::boundaryList(int index) {
1109
1110
MainWindow *mainwindow = (MainWindow *)mainWindow;
1111
1112
int n = mainwindow->glWidget->getLists();
1113
int boundaryCount = 0;
1114
for (int i = 0; i < n; i++) {
1115
list_t *l = mainwindow->glWidget->getList(i);
1116
if (l->getNature() == PDE_BOUNDARY && l->getIndex() == index)
1117
return l;
1118
}
1119
return NULL;
1120
}
1121
1122
list_t *ObjectBrowser::selectBoundary(BoundaryPropertyEditor *pe_in_tree,
1123
bool append /*=false*/,
1124
bool select /*=true*/) {
1125
1126
MainWindow *mainwindow = (MainWindow *)mainWindow;
1127
if (mainwindow->glWidget->getMesh() == NULL)
1128
return NULL;
1129
1130
// unselect all the bodies
1131
for (int i = 0; i < mainwindow->glWidget->bodyMap.count(); i++) {
1132
int n = mainwindow->glWidget->bodyMap.key(i);
1133
if (n >= 0 && bodyList(n) != NULL)
1134
bodyList(n)->setSelected(false);
1135
if (bodyList(n) == NULL) {
1136
// cout << " *** bodyList(" << n << ") is NULL" <<
1137
// endl; cout << " *** body index is " <<
1138
// mainwindow->glWidget->bodyMap.value(i) << endl;
1139
}
1140
}
1141
1142
list_t *l = NULL;
1143
list_t *l_selected = NULL;
1144
// select boundary
1145
for (int i = 0; i < mainwindow->glWidget->boundaryMap.count(); i++) {
1146
int n = mainwindow->glWidget->boundaryMap.key(i);
1147
if (n >= 0) {
1148
int m = mainwindow->glWidget->boundaryMap.value(n);
1149
if (m >= 0 && m < mainwindow->boundaryPropertyEditor.size() &&
1150
mainwindow->boundaryPropertyEditor[m] != NULL) {
1151
BoundaryPropertyEditor *pe = mainwindow->boundaryPropertyEditor[m];
1152
l = boundaryList(n);
1153
if (l != NULL /*&& pe_in_tree != NULL*/) {
1154
if (pe == pe_in_tree) {
1155
l->setSelected(select);
1156
l_selected = l;
1157
}
1158
if (pe != pe_in_tree && append == false) {
1159
l->setSelected(!select);
1160
}
1161
}
1162
}
1163
}
1164
}
1165
1166
if (!append) {
1167
mainwindow->glWidget->rebuildEdgeLists();
1168
mainwindow->glWidget->rebuildSurfaceLists();
1169
mainwindow->glWidget->updateGL();
1170
}
1171
return l_selected;
1172
}
1173
1174
list_t *ObjectBrowser::selectBody(BodyPropertyEditor *pe_in_tree,
1175
bool append /*=false*/,
1176
bool select /*=true*/) {
1177
1178
MainWindow *mainwindow = (MainWindow *)mainWindow;
1179
if (mainwindow->glWidget->getMesh() == NULL)
1180
return NULL;
1181
1182
// unselect all the boundaries
1183
if (!append) {
1184
for (int i = 0; i < mainwindow->glWidget->boundaryMap.count(); i++) {
1185
int n = mainwindow->glWidget->boundaryMap.key(i);
1186
if (n >= 0 && boundaryList(n) != NULL)
1187
boundaryList(n)->setSelected(false);
1188
if (boundaryList(n) == NULL)
1189
cout << " *** boundaryList(" << n << ") is NULL" << endl;
1190
}
1191
}
1192
mainwindow->glWidget->currentlySelectedBody = -1;
1193
1194
list_t *l = NULL;
1195
list_t *l_selected = NULL;
1196
1197
// select body
1198
for (int i = 0; i < mainwindow->glWidget->bodyMap.count(); i++) {
1199
int n = mainwindow->glWidget->bodyMap.key(i);
1200
if (n >= 0) {
1201
int m = mainwindow->glWidget->bodyMap.value(n);
1202
if (m >= 0 && m < mainwindow->bodyPropertyEditor.size() &&
1203
mainwindow->bodyPropertyEditor[m] != NULL) {
1204
BodyPropertyEditor *pe = mainwindow->bodyPropertyEditor[m];
1205
l = bodyList(n);
1206
1207
// new
1208
if (l != NULL /*&& pe_in_tree != NULL*/) {
1209
if (pe == pe_in_tree) {
1210
l->setSelected(select);
1211
l_selected = l;
1212
mainwindow->glWidget->currentlySelectedBody = select ? n : -1;
1213
}
1214
if (pe != pe_in_tree && append == false) {
1215
l->setSelected(!select);
1216
}
1217
}
1218
1219
// oled
1220
// if(l != NULL)l->setSelected(/*pe_in_tree != NULL &&*/ pe ==
1221
// pe_in_tree); if(l != NULL /*&& pe_in_tree != NULL*/ && pe ==
1222
// pe_in_tree){ l_selected = l;
1223
}
1224
}
1225
}
1226
1227
if (l_selected == NULL) {
1228
// For 3D geometry
1229
mainwindow->glWidget->currentlySelectedBody = -1;
1230
int index_selected = -1;
1231
if (l_selected == NULL) {
1232
for (int i = 0; i < mainwindow->glWidget->boundaryMap.count(); i++) {
1233
int n = mainwindow->glWidget->boundaryMap.key(i);
1234
if (n >= 0) {
1235
int m = mainwindow->glWidget->boundaryMap.value(n);
1236
if (m >= 0 && m < mainwindow->boundaryPropertyEditor.size() &&
1237
mainwindow->boundaryPropertyEditor[m] != NULL) {
1238
BoundaryPropertyEditor *pe = mainwindow->boundaryPropertyEditor[m];
1239
l = boundaryList(n);
1240
if (l != NULL /*&& pe_in_tree != NULL*/) {
1241
int index = boundaryListToBodyIndex(l);
1242
if (index >= 0) {
1243
int m2 = mainwindow->glWidget->bodyMap.value(index);
1244
if (m2 >= 0 && m2 < mainwindow->bodyPropertyEditor.size() &&
1245
mainwindow->bodyPropertyEditor[m2] != NULL) {
1246
BodyPropertyEditor *bpe = mainwindow->bodyPropertyEditor[m2];
1247
if (bpe == pe_in_tree) {
1248
l_selected = l;
1249
l = selectBoundary(pe, true, select);
1250
index_selected = index;
1251
}
1252
}
1253
}
1254
}
1255
}
1256
}
1257
}
1258
mainwindow->glWidget->currentlySelectedBody =
1259
select ? index_selected : -1;
1260
}
1261
}
1262
1263
if (!append) {
1264
mainwindow->glWidget->rebuildEdgeLists();
1265
mainwindow->glWidget->rebuildSurfaceLists();
1266
mainwindow->glWidget->updateGL();
1267
}
1268
return l_selected;
1269
}
1270
1271
int ObjectBrowser::boundaryListToBodyIndex(list_t *l) {
1272
1273
MainWindow *mainwindow = (MainWindow *)mainWindow;
1274
mesh_t *mesh = mainwindow->glWidget->getMesh();
1275
int ret = -1;
1276
1277
if (true) {
1278
// determine the max bulk index
1279
int MAX_BULK_INDEX = -1;
1280
1281
for (int i = 0; i < mesh->getElements(); i++) {
1282
element_t *elem = mesh->getElement(i);
1283
if (elem->getNature() != PDE_BULK)
1284
break;
1285
if (elem->getIndex() > MAX_BULK_INDEX)
1286
MAX_BULK_INDEX = elem->getIndex();
1287
}
1288
1289
for (int i = 0; i < mesh->getSurfaces(); i++) {
1290
surface_t *surf = mesh->getSurface(i);
1291
if (surf->getNature() != PDE_BULK)
1292
break;
1293
if (surf->getIndex() > MAX_BULK_INDEX)
1294
MAX_BULK_INDEX = surf->getIndex();
1295
}
1296
1297
for (int i = 0; i < mesh->getEdges(); i++) {
1298
edge_t *edge = mesh->getEdge(i);
1299
if (edge->getNature() != PDE_BULK)
1300
break;
1301
if (edge->getIndex() > MAX_BULK_INDEX)
1302
MAX_BULK_INDEX = edge->getIndex();
1303
}
1304
1305
MAX_BULK_INDEX++;
1306
if (MAX_BULK_INDEX == 0) {
1307
cout << "Error in body selection: "
1308
"There are no legal body indices from which to choose"
1309
<< endl;
1310
cout.flush();
1311
goto body_selection_finished;
1312
}
1313
1314
// allocate temp arrays:
1315
bool *tmp1 = new bool[MAX_BULK_INDEX];
1316
bool *tmp2 = new bool[MAX_BULK_INDEX];
1317
1318
for (int i = 0; i < MAX_BULK_INDEX; i++) {
1319
tmp1[i] = true;
1320
tmp2[i] = false;
1321
}
1322
1323
// check if the selected lists uniquely determine a bulk body:
1324
for (int i = 0; i < mainwindow->glWidget->getLists(); i++) {
1325
list_t *l2 = mainwindow->glWidget->getList(i);
1326
1327
if (l2 == l &&
1328
(l2->getNature() == PDE_BULK)) { //:-) if(l2->isSelected() &&
1329
//(l2->getNature() == PDE_BULK)) {
1330
for (int j = 0; j < MAX_BULK_INDEX; j++) {
1331
if (j != l2->getIndex())
1332
tmp1[j] = false;
1333
}
1334
}
1335
1336
if (l2 == l &&
1337
(l2->getNature() ==
1338
PDE_BOUNDARY) && //:-) if(l2->isSelected() && (l2->getNature()
1339
//== PDE_BOUNDARY) &&
1340
(l2->getType() == SURFACELIST)) {
1341
for (int j = 0; j < mesh->getSurfaces(); j++) {
1342
surface_t *surf = mesh->getSurface(j);
1343
if (surf->getIndex() == l2->getIndex()) {
1344
for (int k = 0; k < surf->getElements(); k++) {
1345
int l = surf->getElementIndex(k);
1346
if (l < 0)
1347
break;
1348
element_t *elem = mesh->getElement(l);
1349
if ((elem->getIndex() < 0) ||
1350
(elem->getIndex() >= MAX_BULK_INDEX))
1351
break;
1352
tmp2[elem->getIndex()] = true;
1353
}
1354
for (int k = 0; k < MAX_BULK_INDEX; k++) {
1355
tmp1[k] &= tmp2[k];
1356
tmp2[k] = false;
1357
}
1358
}
1359
}
1360
}
1361
}
1362
1363
// array "tmp1" should contain only one entry with value "true"
1364
int count = 0;
1365
int found = -1;
1366
for (int i = 0; i < MAX_BULK_INDEX; i++) {
1367
if (tmp1[i]) {
1368
count++;
1369
found = i;
1370
}
1371
}
1372
1373
if ((count == 1) && (found >= 0)) {
1374
mainwindow->glWidget->currentlySelectedBody = found;
1375
ret = found;
1376
// cout << "*****boundary found: " << found << endl;
1377
}else{
1378
ret = mainwindow->glWidget->mostVisibleBody(MAX_BULK_INDEX, tmp1);
1379
}
1380
delete[] tmp1;
1381
delete[] tmp2;
1382
}
1383
body_selection_finished:
1384
1385
// Emit result to mainwindow:
1386
// emit(signalBoundarySelected(l));
1387
1388
return ret;
1389
}
1390
1391
void ObjectBrowser::updateBodyProperties(
1392
BodyPropertyEditor *selectThis /*=NULL*/) {
1393
1394
MainWindow *mainwindow = (MainWindow *)mainWindow;
1395
if (tree->currentItem() != NULL &&
1396
tree->currentItem()->parent() == bodyPropertyParentTreeItem) {
1397
tree->setCurrentItem(bodyPropertyParentTreeItem); // to improve speed
1398
}
1399
QTreeWidgetItem *treeItem = 0;
1400
while (treeItem = bodyPropertyParentTreeItem->takeChild(0))
1401
delete treeItem;
1402
1403
int count = 1;
1404
1405
QMapIterator<int, int> itr(mainwindow->glWidget->bodyMap);
1406
while (itr.hasNext()) {
1407
itr.next();
1408
int n = itr.key();
1409
if (n >= 0) {
1410
int m = itr.value();
1411
1412
if (m >= mainwindow->bodyPropertyEditor.size())
1413
mainwindow->bodyPropertyEditor.resize(m + 1);
1414
1415
if (!mainwindow->bodyPropertyEditor[m])
1416
mainwindow->bodyPropertyEditor[m] = new BodyPropertyEditor;
1417
1418
BodyPropertyEditor *pe = mainwindow->bodyPropertyEditor[m];
1419
1420
treeItem = new QTreeWidgetItem();
1421
bodyPropertyParentTreeItem->addChild(treeItem);
1422
QString title = pe->ui.nameEdit->text().trimmed();
1423
if (title.isEmpty()) {
1424
title = "Body Property " + QString::number(n);
1425
}
1426
1427
if (!pe->touched) {
1428
treeItem->setText(0, title);
1429
if (pe->equation || pe->material || pe->force || pe->initial)
1430
treeItem->setText(1, "<Canceled>");
1431
} else {
1432
QString sifbody = "Body " + QString::number(count++);
1433
QString sifname = title;
1434
if (pe->ui.nameEdit->text().trimmed().isEmpty()) {
1435
sifname = sifbody;
1436
}
1437
treeItem->setText(0, title);
1438
// treeItem->setText(1, "<" + sifbody + " \"" + sifname +"\">");
1439
treeItem->setText(1, sifbody + " in sif");
1440
}
1441
1442
treeItem->setData(0, Qt::UserRole, QVariant::fromValue((qulonglong)pe));
1443
1444
if (pe->equation != 0) {
1445
QTreeWidgetItem *child = new QTreeWidgetItem();
1446
treeItem->addChild(child);
1447
child->setText(0, "Equation");
1448
child->setText(1, pe->equation->nameEdit->text().trimmed());
1449
child->setData(1, Qt::UserRole,
1450
QVariant::fromValue((qulonglong)pe->equation));
1451
}
1452
if (pe->material != 0) {
1453
QTreeWidgetItem *child = new QTreeWidgetItem();
1454
treeItem->addChild(child);
1455
child->setText(0, "Material");
1456
child->setText(1, pe->material->nameEdit->text().trimmed());
1457
child->setData(1, Qt::UserRole,
1458
QVariant::fromValue((qulonglong)pe->material));
1459
}
1460
if (pe->force != 0) {
1461
QTreeWidgetItem *child = new QTreeWidgetItem();
1462
treeItem->addChild(child);
1463
child->setText(0, "Body force");
1464
child->setText(1, pe->force->nameEdit->text().trimmed());
1465
child->setData(1, Qt::UserRole,
1466
QVariant::fromValue((qulonglong)pe->force));
1467
}
1468
if (pe->initial != 0) {
1469
QTreeWidgetItem *child = new QTreeWidgetItem();
1470
treeItem->addChild(child);
1471
child->setText(0, "Initial condition");
1472
child->setText(1, pe->initial->nameEdit->text().trimmed());
1473
child->setData(1, Qt::UserRole,
1474
QVariant::fromValue((qulonglong)pe->initial));
1475
}
1476
treeItem->setExpanded(true);
1477
}
1478
}
1479
1480
if (selectThis != NULL) {
1481
QTreeWidgetItem *item;
1482
for (int i = 0; i < bodyPropertyParentTreeItem->childCount(); i++) {
1483
item = bodyPropertyParentTreeItem->child(i);
1484
if (item->data(0, Qt::UserRole).value<qulonglong>() ==
1485
(qulonglong)selectThis) {
1486
tree->setCurrentItem(item);
1487
return;
1488
}
1489
}
1490
}
1491
1492
/*
1493
cout << "solverparametereditor:" << mainwindow->solverParameterEditor.size()
1494
<< endl; for(int i= 0; i < mainwindow->solverParameterEditor.size(); i++){
1495
if(mainwindow->solverParameterEditor.at(i)) mainwindow->logMessage(
1496
mainwindow->solverParameterEditor.at(i)->solverName ); else cout << "null" <<
1497
endl;
1498
}
1499
*/
1500
}
1501
1502
list_t *ObjectBrowser::bodyList(int index) {
1503
1504
MainWindow *mainwindow = (MainWindow *)mainWindow;
1505
1506
int n = mainwindow->glWidget->getLists();
1507
int bodyCount = 0;
1508
for (int i = 0; i < n; i++) {
1509
list_t *l = mainwindow->glWidget->getList(i);
1510
if (l->getNature() == PDE_BULK && l->getIndex() == index)
1511
return l;
1512
}
1513
return NULL;
1514
}
1515
1516
void ObjectBrowser::snap(QWidget *widget) {
1517
// widget->move(mapToGlobal(QPoint(width(),0)));
1518
}
1519
1520
void ObjectBrowser::updateEquation() {
1521
tree->setCurrentItem(equationParentTreeItem);
1522
QTreeWidgetItem *treeItem;
1523
while (treeItem = equationParentTreeItem->takeChild(0))
1524
delete treeItem;
1525
MainWindow *mainwindow = (MainWindow *)mainWindow;
1526
int n = mainwindow->equationEditor.size();
1527
for (int i = 0; i < n; i++) {
1528
addToTree(mainwindow->equationEditor.at(i));
1529
}
1530
}
1531
void ObjectBrowser::updateMaterial() {
1532
tree->setCurrentItem(materialParentTreeItem);
1533
QTreeWidgetItem *treeItem;
1534
while (treeItem = materialParentTreeItem->takeChild(0))
1535
delete treeItem;
1536
MainWindow *mainwindow = (MainWindow *)mainWindow;
1537
int n = mainwindow->materialEditor.size();
1538
for (int i = 0; i < n; i++) {
1539
addToTree(mainwindow->materialEditor.at(i));
1540
}
1541
}
1542
void ObjectBrowser::updateBodyForce() {
1543
tree->setCurrentItem(bodyForceParentTreeItem);
1544
QTreeWidgetItem *treeItem;
1545
while (treeItem = bodyForceParentTreeItem->takeChild(0))
1546
delete treeItem;
1547
MainWindow *mainwindow = (MainWindow *)mainWindow;
1548
int n = mainwindow->bodyForceEditor.size();
1549
for (int i = 0; i < n; i++) {
1550
addToTree(mainwindow->bodyForceEditor.at(i));
1551
}
1552
}
1553
void ObjectBrowser::updateInitialCondition() {
1554
tree->setCurrentItem(initialConditionParentTreeItem);
1555
QTreeWidgetItem *treeItem;
1556
while (treeItem = initialConditionParentTreeItem->takeChild(0))
1557
delete treeItem;
1558
MainWindow *mainwindow = (MainWindow *)mainWindow;
1559
int n = mainwindow->initialConditionEditor.size();
1560
for (int i = 0; i < n; i++) {
1561
addToTree(mainwindow->initialConditionEditor.at(i));
1562
}
1563
}
1564
void ObjectBrowser::updateBoundaryCondition() {
1565
tree->setCurrentItem(boundaryConditionParentTreeItem);
1566
QTreeWidgetItem *treeItem;
1567
while (treeItem = boundaryConditionParentTreeItem->takeChild(0))
1568
delete treeItem;
1569
MainWindow *mainwindow = (MainWindow *)mainWindow;
1570
int n = mainwindow->boundaryConditionEditor.size();
1571
for (int i = 0; i < n; i++) {
1572
addToTree(mainwindow->boundaryConditionEditor.at(i));
1573
}
1574
}
1575
void ObjectBrowser::boundaryComboChanged(BoundaryPropertyEditor *pe,
1576
QString text) {
1577
QTreeWidgetItem *treeItem;
1578
1579
int n = boundaryPropertyParentTreeItem->childCount();
1580
for (int i = 0; i < n; i++) {
1581
treeItem = boundaryPropertyParentTreeItem->child(i);
1582
if (treeItem->data(0, Qt::UserRole) == (qulonglong)pe) {
1583
if (pe->condition != 0) {
1584
treeItem->setText(1, pe->condition->nameEdit->text().trimmed());
1585
} else {
1586
treeItem->setText(1, "");
1587
}
1588
treeItem->setData(1, Qt::UserRole,
1589
QVariant::fromValue((qulonglong)pe->condition));
1590
return;
1591
}
1592
}
1593
}
1594
1595
void ObjectBrowser::bodyComboChanged(BodyPropertyEditor *pe, QString text) {
1596
MainWindow *mainwindow = (MainWindow *)mainWindow;
1597
QTreeWidgetItem *treeItem;
1598
QTreeWidgetItem *child;
1599
int n = bodyPropertyParentTreeItem->childCount();
1600
for (int i = 0; i < n; i++) {
1601
treeItem = bodyPropertyParentTreeItem->child(i);
1602
if (treeItem->data(0, Qt::UserRole) == (qulonglong)pe) {
1603
while (child = treeItem->takeChild(0))
1604
delete child;
1605
1606
if (pe->equation != 0) {
1607
child = new QTreeWidgetItem();
1608
treeItem->addChild(child);
1609
child->setText(0, "Equation");
1610
child->setText(1, pe->equation->nameEdit->text().trimmed());
1611
child->setData(1, Qt::UserRole,
1612
QVariant::fromValue((qulonglong)pe->equation));
1613
}
1614
1615
if (pe->material != 0) {
1616
child = new QTreeWidgetItem();
1617
treeItem->addChild(child);
1618
child->setText(0, "Material");
1619
child->setText(1, pe->material->nameEdit->text().trimmed());
1620
child->setData(1, Qt::UserRole,
1621
QVariant::fromValue((qulonglong)pe->material));
1622
}
1623
1624
if (pe->force != 0) {
1625
child = new QTreeWidgetItem();
1626
treeItem->addChild(child);
1627
child->setText(0, "Body force");
1628
child->setText(1, pe->force->nameEdit->text().trimmed());
1629
child->setData(1, Qt::UserRole,
1630
QVariant::fromValue((qulonglong)pe->force));
1631
}
1632
1633
if (pe->initial != 0) {
1634
child = new QTreeWidgetItem();
1635
treeItem->addChild(child);
1636
child->setText(0, "Initial condition");
1637
child->setText(1, pe->initial->nameEdit->text().trimmed());
1638
child->setData(1, Qt::UserRole,
1639
QVariant::fromValue((qulonglong)pe->initial));
1640
}
1641
1642
return;
1643
}
1644
}
1645
}
1646
1647
void ObjectBrowser::selectTreeItemByID(QTreeWidgetItem *parent, int id) {
1648
DynamicEditor *de;
1649
if (id >= 0) {
1650
for (int i = 0; i < parent->childCount(); i++) {
1651
de = (DynamicEditor *)parent->child(i)
1652
->data(0, Qt::UserRole)
1653
.value<qulonglong>();
1654
if (de == NULL)
1655
cout << "*** de==NULL" << endl;
1656
if (de != NULL && de->ID == id) {
1657
tree->setCurrentItem(parent->child(i));
1658
return;
1659
}
1660
}
1661
}
1662
tree->setCurrentItem(parent);
1663
}
1664
1665
void ObjectBrowser::bodyPropertyEditorAccepted(bool checked) {
1666
QWidget *a = (QWidget *)QObject::sender();
1667
updateBodyProperties((BodyPropertyEditor *)a->parent());
1668
}
1669
1670
void ObjectBrowser::bodyPropertyEditorDiscarded(bool checked) {
1671
QWidget *a = (QWidget *)QObject::sender();
1672
updateBodyProperties((BodyPropertyEditor *)a->parent());
1673
}
1674
void ObjectBrowser::boundaryPropertyEditorAccepted(bool checked) {
1675
QWidget *a = (QWidget *)QObject::sender();
1676
updateBoundaryProperties((BoundaryPropertyEditor *)a->parent());
1677
}
1678
void ObjectBrowser::boundaryPropertyEditorDiscarded(bool checked) {
1679
QWidget *a = (QWidget *)QObject::sender();
1680
updateBoundaryProperties((BoundaryPropertyEditor *)a->parent());
1681
}
1682
1683
void ObjectBrowser::viewFullScreenSlot() {
1684
if (isVisible())
1685
hide();
1686
else
1687
show();
1688
}
1689
1690
void ObjectBrowser::viewNormalModeSlot() { show(); }
1691
1692
bool ObjectBrowser::connect1(const QObject *sender, const char *signal,
1693
const QObject *receiver, const char *method,
1694
Qt::ConnectionType type /*= Qt::AutoConnection*/) {
1695
disconnect(sender, signal, receiver, method);
1696
return connect(sender, signal, receiver, method, type);
1697
}
1698
1699
void ObjectBrowser::bodyCheckBoxChangedSlot(int state) {
1700
updateBodyProperties();
1701
1702
QWidget *a = (QWidget *)QObject::sender();
1703
if (a == NULL)
1704
return;
1705
BodyPropertyEditor *pe =
1706
(BodyPropertyEditor *)a->property("body").toULongLong();
1707
if (pe == NULL)
1708
return;
1709
1710
selectBody(pe, true, state == Qt::Checked);
1711
MainWindow *mainwindow = (MainWindow *)mainWindow;
1712
mainwindow->glWidget->rebuildEdgeLists();
1713
mainwindow->glWidget->rebuildSurfaceLists();
1714
mainwindow->glWidget->updateGL();
1715
}
1716
1717
void ObjectBrowser::boundaryCheckBoxChangedSlot(int state) {
1718
updateBoundaryProperties();
1719
1720
QWidget *a = (QWidget *)QObject::sender();
1721
if (a == NULL)
1722
return;
1723
BoundaryPropertyEditor *pe =
1724
(BoundaryPropertyEditor *)a->property("boundary").toULongLong();
1725
if (pe == NULL)
1726
return;
1727
1728
selectBoundary(pe, true, state == Qt::Checked);
1729
MainWindow *mainwindow = (MainWindow *)mainWindow;
1730
mainwindow->glWidget->rebuildEdgeLists();
1731
mainwindow->glWidget->rebuildSurfaceLists();
1732
mainwindow->glWidget->updateGL();
1733
}
1734
1735
void ObjectBrowser::treeItemSelectionChangedSlot() {
1736
/*
1737
if(item == bodyPropertyParentTreeItem){
1738
updateBodyProperties();
1739
return;
1740
}
1741
if(item == boundaryPropertyParentTreeItem){
1742
updateBoundaryProperties();
1743
return;
1744
}
1745
*/
1746
1747
MainWindow *mainwindow = (MainWindow *)mainWindow;
1748
if (mainwindow->glWidget->getMesh() == NULL)
1749
return;
1750
1751
QTreeWidgetItem *item = tree->currentItem();
1752
1753
// select boundaries/bodies checked in DyanmicEditor
1754
if (item->parent() == equationParentTreeItem) {
1755
updateBodyProperties();
1756
updateBoundaryProperties();
1757
DynamicEditor *pe =
1758
(DynamicEditor *)item->data(0, Qt::UserRole).value<qulonglong>();
1759
mainwindow->createBodyCheckBoxes(BODY_EQUATION, pe);
1760
QGroupBox *box = (QGroupBox *)pe->spareScroll->widget();
1761
selectBody(NULL);
1762
for (int i = 2; i < box->children().size(); i++) {
1763
QCheckBox *cb = (QCheckBox *)box->children()[i];
1764
connect1(cb, SIGNAL(stateChanged(int)), this,
1765
SLOT(bodyCheckBoxChangedSlot(int)));
1766
if (cb->isChecked() && i - 2 < mainwindow->bodyPropertyEditor.size()) {
1767
selectBody(mainwindow->bodyPropertyEditor[i - 2], true);
1768
}
1769
}
1770
mainwindow->glWidget->rebuildEdgeLists();
1771
mainwindow->glWidget->rebuildSurfaceLists();
1772
mainwindow->glWidget->updateGL();
1773
return;
1774
}
1775
if (item->parent() == materialParentTreeItem) {
1776
updateBodyProperties();
1777
updateBoundaryProperties();
1778
DynamicEditor *pe =
1779
(DynamicEditor *)item->data(0, Qt::UserRole).value<qulonglong>();
1780
mainwindow->createBodyCheckBoxes(BODY_MATERIAL, pe);
1781
QGroupBox *box = (QGroupBox *)pe->spareScroll->widget();
1782
selectBody(NULL);
1783
for (int i = 2; i < box->children().size(); i++) {
1784
QCheckBox *cb = (QCheckBox *)box->children()[i];
1785
connect1(cb, SIGNAL(stateChanged(int)), this,
1786
SLOT(bodyCheckBoxChangedSlot(int)));
1787
if (cb->isChecked())
1788
selectBody(
1789
(BodyPropertyEditor *)bodyPropertyParentTreeItem->child(i - 2)
1790
->data(0, Qt::UserRole)
1791
.value<qulonglong>(),
1792
true);
1793
}
1794
mainwindow->glWidget->rebuildEdgeLists();
1795
mainwindow->glWidget->rebuildSurfaceLists();
1796
mainwindow->glWidget->updateGL();
1797
return;
1798
}
1799
if (item->parent() == bodyForceParentTreeItem) {
1800
updateBodyProperties();
1801
updateBoundaryProperties();
1802
DynamicEditor *pe =
1803
(DynamicEditor *)item->data(0, Qt::UserRole).value<qulonglong>();
1804
mainwindow->createBodyCheckBoxes(BODY_FORCE, pe);
1805
QGroupBox *box = (QGroupBox *)pe->spareScroll->widget();
1806
selectBody(NULL);
1807
for (int i = 2; i < box->children().size(); i++) {
1808
QCheckBox *cb = (QCheckBox *)box->children()[i];
1809
connect1(cb, SIGNAL(stateChanged(int)), this,
1810
SLOT(bodyCheckBoxChangedSlot(int)));
1811
if (cb->isChecked())
1812
selectBody(
1813
(BodyPropertyEditor *)bodyPropertyParentTreeItem->child(i - 2)
1814
->data(0, Qt::UserRole)
1815
.value<qulonglong>(),
1816
true);
1817
}
1818
mainwindow->glWidget->rebuildEdgeLists();
1819
mainwindow->glWidget->rebuildSurfaceLists();
1820
mainwindow->glWidget->updateGL();
1821
return;
1822
}
1823
if (item->parent() == initialConditionParentTreeItem) {
1824
updateBodyProperties();
1825
updateBoundaryProperties();
1826
DynamicEditor *pe =
1827
(DynamicEditor *)item->data(0, Qt::UserRole).value<qulonglong>();
1828
mainwindow->createBodyCheckBoxes(BODY_INITIAL, pe);
1829
QGroupBox *box = (QGroupBox *)pe->spareScroll->widget();
1830
selectBody(NULL);
1831
for (int i = 2; i < box->children().size(); i++) {
1832
QCheckBox *cb = (QCheckBox *)box->children()[i];
1833
connect1(cb, SIGNAL(stateChanged(int)), this,
1834
SLOT(bodyCheckBoxChangedSlot(int)));
1835
if (cb->isChecked())
1836
selectBody(
1837
(BodyPropertyEditor *)bodyPropertyParentTreeItem->child(i - 2)
1838
->data(0, Qt::UserRole)
1839
.value<qulonglong>(),
1840
true);
1841
}
1842
mainwindow->glWidget->rebuildEdgeLists();
1843
mainwindow->glWidget->rebuildSurfaceLists();
1844
mainwindow->glWidget->updateGL();
1845
return;
1846
}
1847
if (item->parent() == boundaryConditionParentTreeItem) {
1848
updateBodyProperties();
1849
updateBoundaryProperties();
1850
DynamicEditor *pe =
1851
(DynamicEditor *)item->data(0, Qt::UserRole).value<qulonglong>();
1852
mainwindow->createBoundaryCheckBoxes(pe);
1853
QGroupBox *box = (QGroupBox *)pe->spareScroll->widget();
1854
selectBoundary(NULL);
1855
for (int i = 2; i < box->children().size(); i++) {
1856
QCheckBox *cb = (QCheckBox *)box->children()[i];
1857
connect1(cb, SIGNAL(stateChanged(int)), this,
1858
SLOT(boundaryCheckBoxChangedSlot(int)));
1859
if (cb->isChecked())
1860
selectBoundary((BoundaryPropertyEditor *)boundaryPropertyParentTreeItem
1861
->child(i - 2)
1862
->data(0, Qt::UserRole)
1863
.value<qulonglong>(),
1864
true);
1865
}
1866
mainwindow->glWidget->rebuildEdgeLists();
1867
mainwindow->glWidget->rebuildSurfaceLists();
1868
mainwindow->glWidget->updateGL();
1869
return;
1870
}
1871
1872
// select boundary/body
1873
if (item->parent() == boundaryPropertyParentTreeItem) {
1874
BoundaryPropertyEditor *pe =
1875
(BoundaryPropertyEditor *)item->data(0, Qt::UserRole)
1876
.value<qulonglong>();
1877
if (pe == NULL) {
1878
cout << " BoundaryPropertyEditor NULL" << endl;
1879
return;
1880
}
1881
selectBoundary(pe);
1882
return;
1883
}
1884
if (item->parent() != NULL &&
1885
item->parent()->parent() == boundaryPropertyParentTreeItem) {
1886
BoundaryPropertyEditor *pe = (BoundaryPropertyEditor *)item->parent()
1887
->data(0, Qt::UserRole)
1888
.value<qulonglong>();
1889
if (pe == NULL) {
1890
cout << " BoundaryPropertyEditor NULL" << endl;
1891
return;
1892
}
1893
selectBoundary(pe);
1894
return;
1895
}
1896
if (item->parent() == bodyPropertyParentTreeItem) {
1897
BodyPropertyEditor *pe =
1898
(BodyPropertyEditor *)item->data(0, Qt::UserRole).value<qulonglong>();
1899
if (pe == NULL) {
1900
cout << " BodyPropertyEditor NULL" << endl;
1901
return;
1902
}
1903
selectBody(pe);
1904
return;
1905
}
1906
if (item->parent() != NULL &&
1907
item->parent()->parent() == bodyPropertyParentTreeItem) {
1908
BodyPropertyEditor *pe = (BodyPropertyEditor *)item->parent()
1909
->data(0, Qt::UserRole)
1910
.value<qulonglong>();
1911
if (pe == NULL) {
1912
cout << " BodyPropertyEditor NULL" << endl;
1913
return;
1914
}
1915
selectBody(pe);
1916
return;
1917
}
1918
1919
selectBoundary(NULL);
1920
selectBody(NULL);
1921
}
1922
1923
void ObjectBrowser::meshingStartedSlot() {}
1924
void ObjectBrowser::meshingTerminatedSlot() {
1925
updateBodyProperties();
1926
updateBoundaryProperties();
1927
}
1928
void ObjectBrowser::meshingFinishedSlot() {
1929
updateBodyProperties();
1930
updateBoundaryProperties();
1931
}
1932
1933