Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
DDqtVTKwidget.cpp
Go to the documentation of this file.
1/* This file is part of MODEL, the Mechanics Of Defect Evolution Library.
2 *
3 * Copyright (C) 2011 by Giacomo Po <gpo@ucla.edu>.
4 *
5 * model is distributed without any warranty under the
6 * GNU General Public License (GPL) v2 <http://www.gnu.org/licenses/>.
7 */
8
9#ifndef model_DDqtVTKwidget_cpp_
10#define model_DDqtVTKwidget_cpp_
11
12#include <QFileDialog>
13#include <QCoreApplication>
14#include <QDir>
15#include <QScrollArea>
16#include <QVTKInteractor.h>
17#include <vtkInteractorStyle.h>
18#include <vtkInteractorStyleSwitch.h>
19
20#include <DDqtVTKwidget.h>
22
23namespace model
24{
25
27 /* init */ mainLayout(new QGridLayout(this))
28 /* init */,tabWidget(new QTabWidget(this))
29 /* init */,openglWidget(new QVTKOpenGLStereoWidget(this))
30 /* init */,renderWindow(vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New())
31 /* init */,renderer(vtkSmartPointer<vtkRenderer>::New())
32 /* init */,ddBase(getWorkingDir())
33 /* init */,workingDirLabel(new QLabel(QString::fromStdString(ddBase.simulationParameters.traitsIO.simulationFolder)))
34 /* init */,meshActor(new SimplicialMeshActor(renderWindow,renderer,ddBase.mesh))
35 /* init */,defectiveCrystalActor(new DefectiveCrystalActor(renderWindow,renderer,openglWidget,ddBase))
36 {
37 renderer->SetBackground(1,1,1);
38 renderWindow->AddRenderer(renderer);
39 renderWindow->SetMultiSamples(4);
40
41 openglWidget->setRenderWindow(renderWindow);
42 auto* cameraStyle = vtkInteractorStyle::SafeDownCast(openglWidget->interactor()->GetInteractorStyle());
43 if(auto* styleSwitch = vtkInteractorStyleSwitch::SafeDownCast(cameraStyle))
44 {
45 cameraStyle = styleSwitch->GetCurrentStyle();
46 }
47 if(cameraStyle)
48 {
49 // Use smaller zoom steps for precise framing; leave rotation and pan unchanged.
50 cameraStyle->SetMouseWheelMotionFactor(0.25);
51 }
52
53
54 tabWidget->addTab(defectiveCrystalActor, tr(std::string("Defects").c_str()));
55 auto *meshScroll = new QScrollArea(this);
56 meshScroll->setWidgetResizable(true);
57 meshScroll->setFrameShape(QFrame::NoFrame);
58 meshScroll->setWidget(meshActor);
59 tabWidget->addTab(meshScroll, tr("Mesh"));
60
61 mainLayout->addWidget(workingDirLabel,0,0,1,2);
62 mainLayout->addWidget(tabWidget,1,0,1,1);
63 mainLayout->addWidget(openglWidget,1,1,1,1);
64 mainLayout->setColumnStretch(0, 3);
65 mainLayout->setColumnStretch(1, 7);
66 this->setLayout(mainLayout);
67 defectiveCrystalActor->updateConfiguration(0);
68 }
69
70
72 {
73 defectiveCrystalActor->stopConfigurations();
74 delete tabWidget; // Destroy actors while ddBase and renderer still exist.
75 renderer->RemoveAllViewProps();
76 delete openglWidget;
77 }
78
79 std::string DDqtVTKwidget::getWorkingDir()
80 {
81 QDir directory(QCoreApplication::applicationDirPath());
82 QString initialDirectory=directory.absolutePath();
83 // Find tutorials from the executable location, including build/tools/DDqt
84 // and application-bundle layouts, independently of the launch directory.
85 do
86 {
87 const QDir tutorials(directory.filePath("tutorials"));
88 if(tutorials.exists())
89 {
90 initialDirectory=tutorials.absolutePath();
91 break;
92 }
93 }
94 while(directory.cdUp());
95
96 return QFileDialog::getExistingDirectory(this, tr("Open Directory"),
97 initialDirectory,
98 QFileDialog::ShowDirsOnly
99 | QFileDialog::DontUseNativeDialog).toStdString();
100
101
102 }
103
104
105} // namespace model
106
107#endif
108
109
110
111
112
113
114
DDqtVTKwidget(QWidget *parent)
SimplicialMeshActor * meshActor
DefectiveCrystalBase< 3 > ddBase
DefectiveCrystalActor * defectiveCrystalActor