PeriDyno 1.2.1
Loading...
Searching...
No Matches
PMainWindow.cpp
Go to the documentation of this file.
1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the demonstration applications of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:BSD$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** BSD License Usage
18** Alternatively, you may use this file under the terms of the BSD license
19** as follows:
20**
21** "Redistribution and use in source and binary forms, with or without
22** modification, are permitted provided that the following conditions are
23** met:
24** * Redistributions of source code must retain the above copyright
25** notice, this list of conditions and the following disclaimer.
26** * Redistributions in binary form must reproduce the above copyright
27** notice, this list of conditions and the following disclaimer in
28** the documentation and/or other materials provided with the
29** distribution.
30** * Neither the name of The Qt Company Ltd nor the names of its
31** contributors may be used to endorse or promote products derived
32** from this software without specific prior written permission.
33**
34**
35** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
46**
47** $QT_END_LICENSE$
48**
49****************************************************************************/
50#include "PMainWindow.h"
51#include "PDockWidget.h"
52#include "PStatusBar.h"
53#include "POpenGLWidget.h"
54#include "PAnimationWidget.h"
55
56#include "PIODockWidget.h"
57#include "PConsoleWidget.h"
58#include "PPropertyWidget.h"
59#include "PSimulationThread.h"
60#include "PModuleEditor.h"
61
64
65#include <QAction>
66#include <QLayout>
67#include <QMenu>
68#include <QMenuBar>
69#include <QStatusBar>
70#include <QTextEdit>
71#include <QFile>
72#include <QDataStream>
73#include <QFileDialog>
74#include <QDialogButtonBox>
75#include <QMessageBox>
76#include <QSignalMapper>
77#include <QApplication>
78#include <QPainter>
79#include <QMouseEvent>
80#include <QLineEdit>
81#include <QComboBox>
82#include <QLabel>
83#include <QPushButton>
84#include <QTextEdit>
85#include <QDebug>
86#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
87 #include <QtOpenGLWidgets/QtOpenGLWidgets>
88#else
89 #include <QtWidgets/QOpenGLWidget>
90#endif
91#include <QtSvg/QSvgRenderer>
92#include <QHBoxLayout>
93#include <QDialog>
94#include <QVBoxLayout>
95
98
99#include "nodes/QDataModelRegistry"
100#include "nodes/QNode"
101#include "ToolBar/TabToolbar.h"
102#include "ToolBar/Page.h"
103#include "ToolBar/Group.h"
104#include "ToolBar/SubGroup.h"
105#include "ToolBar/StyleTools.h"
106#include "ToolBar/Builder.h"
107#include "ToolBar/ToolBarPage.h"
108#include "Platform.h"
109
110#include "PMainToolBar.h"
111#include "PModuleEditorToolBar.h"
112#include "PSettingEditor.h"
113#include "SceneGraphFactory.h"
114
115
116namespace dyno
117{
118 //Q_DECLARE_METATYPE(QDockWidget::DockWidgetFeatures)
119
121 QtApp* app,
122 QWidget *parent, Qt::WindowFlags flags)
123 : QMainWindow(parent, flags),
124 mStatusBar(nullptr),
125 mPropertyWidget(nullptr),
126 mAnimationWidget(nullptr)
127 {
128 setObjectName("MainWindow");
129 setWindowTitle(QString("PeriDyno Studio ") + QString::number(PERIDYNO_VERSION_MAJOR) + QString(".") + QString::number(PERIDYNO_VERSION_MINOR) + QString(".") + QString::number(PERIDYNO_VERSION_PATCH) + QString(": An AI-targeted physical simulation platform"));
130 setWindowIcon(QIcon(QString::fromStdString(getAssetPath() + "logo/logo5.png")));
131
133
134
136// setupMenuBar();
138
139 setupToolBar();
140
142
145
146 connect(mNodeFlowView->flowScene(), &Qt::QtNodeFlowScene::nodePlaced, PSimulationThread::instance(), &PSimulationThread::resetQtNode);
147 connect(mNodeFlowView->flowScene(), &Qt::QtNodeFlowScene::nodeInputUpdated, PSimulationThread::instance(), &PSimulationThread::resetQtNode);
148
152
154
156
158
159 connect(this, &PMainWindow::updateSetting, mSettingEditor->getSettingWidget(), &PSettingWidget::updateData);
160
161 statusBar()->showMessage(tr("Status Bar"));
162 }
163
165 {
166 }
167
168 void PMainWindow::createWindow(int width, int height)
169 {
170
171 }
172
174 {
175 QMessageBox::StandardButton reply;
176
177 reply = QMessageBox::question(this, "Save", "Do you want to save your changes?",
178 QMessageBox::Ok | QMessageBox::Cancel);
179 }
180
182 {
183 QWidget* centralWidget = new QWidget();
184 setCentralWidget(centralWidget);
185
186 centralWidget->setContentsMargins(0, 0, 0, 0);
187 QVBoxLayout* mainLayout = new QVBoxLayout();
188 mainLayout->setContentsMargins(0, 0, 0, 0);
189 mainLayout->setSpacing(0);
190 centralWidget->setLayout(mainLayout);
191
192 //Setup views
193 QTabWidget* tabWidget = new QTabWidget();
194 tabWidget->setObjectName(QStringLiteral("tabWidget"));
195 tabWidget->setGeometry(QRect(140, 60, 361, 241));
196
197 mOpenGLWidget = new POpenGLWidget(this);
198 mOpenGLWidget->setContentsMargins(0, 0, 0, 0);
199 mainLayout->addWidget(mOpenGLWidget, 1);
200
201 //Setup animation widget
203 mAnimationWidget->layout()->setContentsMargins(0, 0, 0, 0);
204
205 mainLayout->addWidget(mAnimationWidget, 0);
206 }
207
209
210 {
211 QMessageBox msgBox(this);
212
213 msgBox.setWindowTitle("About");
214
215 msgBox.setTextFormat(Qt::RichText); //this is what makes the links clickable
216
217 msgBox.setText("this is diagWindows");
218
219 msgBox.setIconPixmap(QPixmap(":/ico/res/ExcelReport.ico"));
220
221 msgBox.exec();
222
223 }
224
225 void PMainWindow::addNodeByName(std::string name) {
226 mNodeFlowView->flowScene()->addNodeByString(name);
227 }
228
230 {
231 mToolBar = new PMainToolBar(mNodeFlowView, this, 61, 3);
232 mToolBar->setWindowTitle("Tool Bar");
233
234 addToolBar(Qt::TopToolBarArea, mToolBar);
235 }
236
238 {
239 mStatusBar = new PStatusBar(this);
240 setStatusBar(mStatusBar);
241 }
242
244 {
245 return;
246 }
247
249 {
250 return;
251 }
252
254 {
255 return;
256 }
257
259 {
260 QString versoin = QString("Version ") + QString::number(PERIDYNO_VERSION_MAJOR)+QString(".")+ QString::number(PERIDYNO_VERSION_MINOR)+QString(".")+QString::number(PERIDYNO_VERSION_PATCH);
261 QMessageBox::about(this, tr("PeriDyno Studio "), versoin);
262 return;
263 }
264
266 {
267 Qt::QtNodeWidget* clickedNode = nullptr;
268
269 clickedNode = dynamic_cast<Qt::QtNodeWidget*>(s.nodeDataModel());
270
271 if (clickedNode == nullptr)
272 return;
273
274 QString caption = s.nodeDataModel()->caption();
275
276 PModuleEditor* moduleEditor = new PModuleEditor(clickedNode);
277 moduleEditor->setWindowTitle("Module Editor -- " + caption);
278 moduleEditor->resize(1024, 600);
279 moduleEditor->setMinimumSize(512, 360);
280
281 moduleEditor->setWindowModality(Qt::WindowModal);
282 moduleEditor->setAttribute(Qt::WA_ShowModal, true);
283 moduleEditor->setAttribute(Qt::WA_DeleteOnClose, true);
284 moduleEditor->show();
285
288 }
289
291 {
292 std::cout << "ShowMessage" << std::endl;
293 }
294
296 {
297 return;
298 }
299
301 {
302 qRegisterMetaType<QDockWidget::DockWidgetFeatures>();
303
304 //windowMenu->addSeparator();
305
306 static const struct Set {
307 const char * name;
308 uint flags;
309 Qt::DockWidgetArea area;
310 } sets[] = {
311 { "SceneGraph", 0, Qt::RightDockWidgetArea },
312 { "Console", 0, Qt::BottomDockWidgetArea },
313 { "Property", 0, Qt::RightDockWidgetArea },
314 { "NodeEditor", 0, Qt::RightDockWidgetArea },
315 { "Module", 0, Qt::RightDockWidgetArea }
316 };
317 const int setCount = sizeof(sets) / sizeof(Set);
318
319 const QIcon qtIcon(QPixmap(":/res/qt.png"));
320
321
322 PDockWidget *nodeEditorDockWidget = new PDockWidget(tr(sets[3].name), this, Qt::WindowFlags(sets[3].flags));
323 nodeEditorDockWidget->setWindowTitle("Node Editor");
324 nodeEditorDockWidget->setWindowIcon(qtIcon);
325 addDockWidget(sets[3].area, nodeEditorDockWidget);
327 mNodeFlowView->setObjectName(QStringLiteral("tabEditor"));
328 nodeEditorDockWidget->setWidget(mNodeFlowView);
329
330 //Set up property dock widget
331 PDockWidget *propertyDockWidget = new PDockWidget(tr(sets[2].name), this, Qt::WindowFlags(sets[2].flags));
332 propertyDockWidget->setWindowTitle("Property Editor");
333 propertyDockWidget->setWindowIcon(qtIcon);
334 propertyDockWidget->setMinimumWidth(580);
335 addDockWidget(sets[2].area, propertyDockWidget);
337 propertyDockWidget->setWidget(mPropertyWidget);
338
339 mIoDockerWidget = new PIODockWidget(this, Qt::WindowFlags(sets[1].flags));
340 mIoDockerWidget->setWindowIcon(qtIcon);
341 addDockWidget(sets[1].area, mIoDockerWidget);
342 //windowMenu->addMenu(bottomDockWidget->colorSwatchMenu());
343
344 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
345 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
346
347 connect(mNodeFlowView->flowScene(), &Qt::QtNodeFlowScene::nodeSelected, mPropertyWidget, &PPropertyWidget::showProperty);
348 connect(mNodeFlowView->flowScene(), &Qt::QtNodeFlowScene::nodeDeselected, mPropertyWidget, &PPropertyWidget::clearProperty);
349// connect(m_moduleFlowView->module_scene, &QtNodes::QtModuleFlowScene::nodeSelected, m_propertyWidget, &PPropertyWidget::showBlockProperty);
350
351 connect(mNodeFlowView->flowScene(), &Qt::QtNodeFlowScene::nodeDoubleClicked, this, &PMainWindow::showModuleEditor);
352
354
355 // between OpenGL and property widget
356 connect(mOpenGLWidget, &POpenGLWidget::nodeSelected, [=](std::shared_ptr<Node> node) {
357 mPropertyWidget->showNodeProperty(node);
358 // TODO: high light selected node in node editor
359 auto qNodes = mNodeFlowView->flowScene()->allNodes();
360 for (auto qNode : qNodes)
361 {
362 if (dynamic_cast<Qt::QtNodeWidget*>(qNode->nodeDataModel())->getNode() == node)
363 qNode->nodeGraphicsObject().setSelected(true);
364 else
365 qNode->nodeGraphicsObject().setSelected(false);
366 }
367 });
368
369
370 connect(mNodeFlowView->flowScene(), &Qt::QtNodeFlowScene::nodeSelected, [=](Qt::QtNode& n)
371 {
372 auto model = n.nodeDataModel();
373 auto widget = dynamic_cast<Qt::QtNodeWidget*>(model);
374
375 if (widget != nullptr)
376 {
377 mOpenGLWidget->select(widget->getNode());
378 mOpenGLWidget->update();
379 }
380 });
381
382 connect(mNodeFlowView->flowScene(), &Qt::QtNodeFlowScene::nodeDeselected, [=]()
383 {
384 mOpenGLWidget->select(nullptr);
385 mOpenGLWidget->update();
386 });
387
388 connect(mAnimationWidget, &PAnimationWidget::simulationStarted, [=]()
389 {
390 mOpenGLWidget->setFocus();
391 });
392
393 connect(mAnimationWidget, &PAnimationWidget::simulationStopped, [=]()
394 {
395 });
396 }
397
398 void PMainWindow::mousePressEvent(QMouseEvent *event)
399 {
400 }
401
403 {
404 auto scn = SceneGraphFactory::instance()->active();
405
406 mSettingEditor = new PSettingEditor(nullptr);
407 mSettingEditor->setRenderEngine(mOpenGLWidget->getRenderEngine());
408
409 }
410
412 {
413 if (mSettingEditor == nullptr)
414 return;
415
417 mSettingEditor->show();
418 }
419
421 {
422 emit updateSetting();
423 }
424
425
426
427}
void createQtNode(std::shared_ptr< dyno::Node > node)
void updateNodeGraphView()
Update the view only for the active scene graph, the data model will not be changed.
void fieldUpdated(dyno::FBase *field, int status)
The model dictates the number of inputs and outputs for the Node.
QString caption() const override
std::shared_ptr< Node > getNode()
void nodeCreated(std::shared_ptr< Node > node)
void mousePressEvent(QMouseEvent *event) override
PStatusBar * mStatusBar
void createWindow(int width, int height)
POpenGLWidget * mOpenGLWidget
PSettingEditor * mSettingEditor
PPropertyWidget * mPropertyWidget
PMainWindow(QtApp *app, QWidget *parent=Q_NULLPTR, Qt::WindowFlags flags=Qt::WindowFlags())
Qt::QtNodeFlowWidget * mNodeFlowView
void showModuleEditor(Qt::QtNode &n)
PIODockWidget * mIoDockerWidget
PAnimationWidget * mAnimationWidget
PMainToolBar * mToolBar
void addNodeByName(std::string name)
Qt::QtModuleFlowScene * moduleFlowScene()
void changed(Node *node)
void nodeSelected(std::shared_ptr< Node > node)
void updateGraphicsContext(Node *node)
void updateOneFrame(int frame)
void showProperty(Qt::QtNode &block)
void nodeUpdated(std::shared_ptr< Node > node)
void stateFieldUpdated(FBase *field, int status)
virtual void updateData()
void oneFrameFinished(int frame)
static PSimulationThread * instance()
void syncNode(std::shared_ptr< Node > node)
void resetQtNode(Qt::QtNode &node)
void nodeCreated(std::shared_ptr< Node > node)
static SceneGraphFactory * instance()
An CPU/GPU implementation of the standard set suitable for small-size data.
Definition Set.h:20
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
unsigned int uint
Definition VkProgram.h:14