PeriDyno 1.0.0
Loading...
Searching...
No Matches
PAnimationWidget.cpp
Go to the documentation of this file.
1#include "PAnimationWidget.h"
2
3#include "SceneGraph.h"
4#include "SceneGraphFactory.h"
5#include "PSimulationThread.h"
6#include "Platform.h"
7
8#include <QString>
9#include <QGridLayout>
10#include <QPushButton>
11#include <QSpinBox>
12#include <QLineEdit>
13#include <QIntValidator>
14#include <QDebug>
15namespace dyno
16{
18 QWidget(parent),
19 mStartSim(nullptr),
20 mNextStep(nullptr),
21 mResetSim(nullptr),
22 mStartLabel(nullptr),
23 mNextStepLabel(nullptr),
24 mResetLabel(nullptr),
25 mStartIcon(nullptr),
26 mPauseIcon(nullptr),
27 mResetIcon(nullptr),
28 mNextStepIcon(nullptr),
29 mFinishIcon(nullptr)
30 {
32
33 QHBoxLayout* layout = new QHBoxLayout();
34 setLayout(layout);
35
36 QGridLayout* frameLayout = new QGridLayout();
37
38 mTotalFrameSpinbox = new QSpinBox();
39 mTotalFrameSpinbox->setFixedSize(96, 29);
40 mTotalFrameSpinbox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
41
42 mTotalFrameSpinbox->setMaximum(1000000);
44
46 mFrameSlider->setObjectName("AnimationSlider");
47 mFrameSlider->setStyleSheet("border-top-right-radius: 0px; border-bottom-right-radius: 0px;");
48 mFrameSlider->setFixedHeight(29);
49
50 frameLayout->addWidget(mFrameSlider, 0, 0, 0 , (labelSize - 1) * 2);
51
52 QHBoxLayout* operationLayout = new QHBoxLayout();
53
54 mStartSim = new QPushButton();
55 mNextStep = new QPushButton();
56 mResetSim = new QPushButton();
57 mStartSim->setStyleSheet("padding: 6px;");
58 mNextStep->setStyleSheet("padding: 6px;");
59 mResetSim->setStyleSheet("padding: 6px;");
60
61 mStartSim->setShortcut(QKeySequence(Qt::Key_Space));
62
63 mStartIcon = new QPixmap(QString::fromStdString(getAssetPath() + "icon/ToolBarIco/AnimationSlider/Start.png"));
64 mPauseIcon = new QPixmap(QString::fromStdString(getAssetPath() + "icon/ToolBarIco/AnimationSlider/Pause.png"));
65 mResetIcon = new QPixmap(QString::fromStdString(getAssetPath() + "icon/ToolBarIco/AnimationSlider/Reset.png"));
66 mFinishIcon = new QPixmap(QString::fromStdString(getAssetPath() + "icon/ToolBarIco/AnimationSlider/Finish.png"));
67 mNextStepIcon = new QPixmap(QString::fromStdString(getAssetPath() + "icon/ToolBarIco/AnimationSlider/NextFrame.png"));
68
69 mStartLabel = new QLabel;
71 mResetLabel = new QLabel;
73 mNextStepLabel = new QLabel;
75
76 mResetSim->setCheckable(false);
77
78 mPersistent = new QCheckBox();
79 mPersistent->setObjectName("SimulationCheckBox");
80 mPersistent->setChecked(false);
81 mPersistent->setFixedSize(29, 29);
82 mPersistent->setContentsMargins(0, 0, 0, 0);
83 mPersistent->setToolTip("Run the simulation permanently");
84
85 operationLayout->addWidget(mTotalFrameSpinbox, 0);
86 operationLayout->addWidget(mStartSim, 0);
87 operationLayout->addWidget(mNextStep, 0);
88 operationLayout->addWidget(mResetSim, 0);
89 operationLayout->addWidget(mPersistent, 0);
90 operationLayout->setSpacing(0);
91
92 mStartSim->setCheckable(true);
93
94 layout->addLayout(frameLayout, 10);
95 layout->addStretch();
96 layout->addLayout(operationLayout, 1);
97 layout->setSpacing(0);
98
99 connect(mStartSim, SIGNAL(released()), this, SLOT(toggleSimulation()));
100 connect(mResetSim, SIGNAL(released()), this, SLOT(resetSimulation()));
101 connect(mNextStep, SIGNAL(released()), this, SLOT(takeOneStep()));
102
103 connect(PSimulationThread::instance(), SIGNAL(simulationFinished()), this, SLOT(simulationFinished()));
104 connect(PSimulationThread::instance(), SIGNAL(oneFrameFinished(int)), this, SLOT(updateSlider(int)));
105 connect(PSimulationThread::instance(), SIGNAL(finished()), PSimulationThread::instance(), SLOT(deleteLater()));
106
107 connect(mTotalFrameSpinbox, SIGNAL(valueChanged(int)), mFrameSlider, SLOT(maximumChanged(int)));
108 connect(mTotalFrameSpinbox, SIGNAL(valueChanged(int)), this, SLOT(totalFrameChanged(int)));
109
110 connect(mPersistent, SIGNAL(stateChanged(int)), this, SLOT(runForever(int)));
111
113
114
115 }
116
118 {
120// PSimulationThread::instance()->deleteLater();
121// PSimulationThread::instance()->wait();
122 }
123
125 {
126 if (mStartSim->isChecked())
127 {
129 mStartSim->setText("");
130 //m_startSim->setIcon(*PauseIcon);
131 mStartLabel->setPixmap(*mPauseIcon);
132
133 mResetSim->setEnabled(false);
134 mNextStep->setEnabled(false);
135 mTotalFrameSpinbox->setEnabled(false);
136 mFrameSlider->setEnabled(false);
137
138 emit simulationStarted();
139 }
140 else
141 {
143 mStartSim->setText("");
144 mResetSim->setEnabled(true);
145 mStartLabel->setPixmap(*mStartIcon); //更新Label上的icon为Starticon
146
147 mNextStep->setEnabled(true);
148 mTotalFrameSpinbox->setEnabled(true);
149 mFrameSlider->setEnabled(true);
150
151 emit simulationStopped();
152 }
153 }
154
156 {
158
159 mStartSim->setText("");
160 mStartSim->setEnabled(true);
161 mStartSim->setChecked(false);
162 mStartLabel->setPixmap(*mStartIcon); //更新Label上的icon为Starticon
163
164 mTotalFrameSpinbox->setEnabled(true);
165 mFrameSlider->setEnabled(true);
166 mFrameSlider->setValue(0);
167 }
168
173
175 {
176 mStartLabel->setPixmap(*mFinishIcon); //更新Label上的icon为Finishicon
177
178 mStartSim->setText("");
179 mStartSim->setDisabled(true);
180 mStartSim->setChecked(false);
181
182 mResetSim->setDisabled(false);
183
184 mTotalFrameSpinbox->setEnabled(true);
185 }
186
188 {
189 mFrameSlider->setValue(frame);
190 }
191
192 void PAnimationWidget::buildIconLabel(QLabel* Label, QPixmap* Icon, QPushButton* btn, int size) {
193
194 Label->setScaledContents(true); //允许图标缩放
195 Label->setStyleSheet("background: transparent;");
196 Label->setPixmap(*Icon); //指定icon,设置背景透明,设置大小
197 Label->setFixedSize(size,size);
198
199 QHBoxLayout* iconLayout = new QHBoxLayout(); //创建HBoxLayout承载Label
200 iconLayout->addWidget(Label);
201 iconLayout->setSizeConstraint(QLayout::SetFixedSize);
202 iconLayout->setContentsMargins(0, 0, 0, 0);
203 btn->setLayout(iconLayout); //将Layout指定给目标Button
204 }
205
207 {
208 auto scn = SceneGraphFactory::instance()->active();
209
210 if (scn->getFrameNumber() < num)
211 {
212 mResetSim->setEnabled(true);
213 mStartSim->setEnabled(true);
214
215 mStartLabel->setPixmap(*mStartIcon);
216
218 }
219 }
220
222 {
223 switch (state)
224 {
225 case Qt::CheckState::Checked:
226 mStartSim->setDisabled(true);
227 mNextStep->setDisabled(true);
228 mResetSim->setDisabled(true);
229 mFrameSlider->setDisabled(true);
230 mTotalFrameSpinbox->setDisabled(true);
231
232 disconnect(PSimulationThread::instance(), SIGNAL(oneFrameFinished(int)), this, SLOT(updateSlider(int)));
233
234 PSimulationThread::instance()->setTotalFrames(std::numeric_limits<int>::max());
236
237 emit simulationStarted();
238
239 break;
240
241 case Qt::CheckState::Unchecked:
242 mStartSim->setDisabled(false);
243 mNextStep->setDisabled(false);
244 mResetSim->setDisabled(false);
245 mStartLabel->setPixmap(*mStartIcon);
246 mFrameSlider->setDisabled(false);
247 mTotalFrameSpinbox->setDisabled(false);
248
249 connect(PSimulationThread::instance(), SIGNAL(oneFrameFinished(int)), this, SLOT(updateSlider(int)));
250
253
254 emit simulationStopped();
255
256 break;
257
258 default:
259 break;
260 }
261 }
262
263}
PAnimationWidget(QWidget *parent=nullptr)
static const int labelSize
PAnimationQSlider * mFrameSlider
void buildIconLabel(QLabel *Label, QPixmap *Icon, QPushButton *btn, int size)
void reset(int num)
Reset the simulation.
static PSimulationThread * instance()
void proceed(int num)
Continue the simulation from the current frame.
static SceneGraphFactory * instance()
std::shared_ptr< SceneGraph > active()
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
void disconnect(Node *node, NodePort *port)
Definition NodePort.cpp:44