PeriDyno 1.0.0
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
144
145 connect(mNodeFlowView->flowScene(), &Qt::QtNodeFlowScene::nodePlaced, PSimulationThread::instance(), &PSimulationThread::resetQtNode);
146 connect(mNodeFlowView->flowScene(), &Qt::QtNodeFlowScene::nodeInputUpdated, PSimulationThread::instance(), &PSimulationThread::resetQtNode);
147
151
153
155
157
158 connect(this, &PMainWindow::updateSetting, mSettingEditor->getSettingWidget(), &PSettingWidget::updateData);
159
160 statusBar()->showMessage(tr("Status Bar"));
161 }
162
164 {
165 }
166
167 void PMainWindow::createWindow(int width, int height)
168 {
169
170 }
171
173 {
174 QMessageBox::StandardButton reply;
175
176 reply = QMessageBox::question(this, "Save", "Do you want to save your changes?",
177 QMessageBox::Ok | QMessageBox::Cancel);
178 }
179
181 {
182 QWidget* centralWidget = new QWidget();
183 setCentralWidget(centralWidget);
184
185 centralWidget->setContentsMargins(0, 0, 0, 0);
186 QVBoxLayout* mainLayout = new QVBoxLayout();
187 mainLayout->setContentsMargins(0, 0, 0, 0);
188 mainLayout->setSpacing(0);
189 centralWidget->setLayout(mainLayout);
190
191 //Setup views
192 QTabWidget* tabWidget = new QTabWidget();
193 tabWidget->setObjectName(QStringLiteral("tabWidget"));
194 tabWidget->setGeometry(QRect(140, 60, 361, 241));
195
196 mOpenGLWidget = new POpenGLWidget(this);
197 mOpenGLWidget->setContentsMargins(0, 0, 0, 0);
198 mainLayout->addWidget(mOpenGLWidget, 1);
199
200 //Setup animation widget
202 mAnimationWidget->layout()->setContentsMargins(0, 0, 0, 0);
203
204 mainLayout->addWidget(mAnimationWidget, 0);
205 }
206
208
209 {
210 QMessageBox msgBox(this);
211
212 msgBox.setWindowTitle("About");
213
214 msgBox.setTextFormat(Qt::RichText); //this is what makes the links clickable
215
216 msgBox.setText("this is diagWindows");
217
218 msgBox.setIconPixmap(QPixmap(":/ico/res/ExcelReport.ico"));
219
220 msgBox.exec();
221
222 }
223
224 void PMainWindow::addNodeByName(std::string name) {
225 mNodeFlowView->flowScene()->addNodeByString(name);
226 }
227
229 {
230 mToolBar = new PMainToolBar(mNodeFlowView, this, 61, 3);
231 mToolBar->setWindowTitle("Tool Bar");
232
233 addToolBar(Qt::TopToolBarArea, mToolBar);
234 }
235
237 {
238 mStatusBar = new PStatusBar(this);
239 setStatusBar(mStatusBar);
240 }
241
243 {
244 return;
245 }
246
248 {
249 return;
250 }
251
253 {
254 return;
255 }
256
258 {
259 QString versoin = QString("Version ") + QString::number(PERIDYNO_VERSION_MAJOR)+QString(".")+ QString::number(PERIDYNO_VERSION_MINOR)+QString(".")+QString::number(PERIDYNO_VERSION_PATCH);
260 QMessageBox::about(this, tr("PeriDyno Studio "), versoin);
261 return;
262 }
263
265 {
266 Qt::QtNodeWidget* clickedNode = nullptr;
267
268 clickedNode = dynamic_cast<Qt::QtNodeWidget*>(s.nodeDataModel());
269
270 if (clickedNode == nullptr)
271 return;
272
273 QString caption = s.nodeDataModel()->caption();
274
275 PModuleEditor* moduleEditor = new PModuleEditor(clickedNode);
276 moduleEditor->setWindowTitle("Module Editor -- " + caption);
277 moduleEditor->resize(1024, 600);
278 moduleEditor->setMinimumSize(512, 360);
279
280 moduleEditor->setWindowModality(Qt::WindowModal);
281 moduleEditor->setAttribute(Qt::WA_ShowModal, true);
282 moduleEditor->setAttribute(Qt::WA_DeleteOnClose, true);
283 moduleEditor->show();
284
287 }
288
290 {
291 std::cout << "ShowMessage" << std::endl;
292 }
293
295 {
296 return;
297 }
298
300 {
301 qRegisterMetaType<QDockWidget::DockWidgetFeatures>();
302
303 //windowMenu->addSeparator();
304
305 static const struct Set {
306 const char * name;
307 uint flags;
308 Qt::DockWidgetArea area;
309 } sets[] = {
310 { "SceneGraph", 0, Qt::RightDockWidgetArea },
311 { "Console", 0, Qt::BottomDockWidgetArea },
312 { "Property", 0, Qt::RightDockWidgetArea },
313 { "NodeEditor", 0, Qt::RightDockWidgetArea },
314 { "Module", 0, Qt::RightDockWidgetArea }
315 };
316 const int setCount = sizeof(sets) / sizeof(Set);
317
318 const QIcon qtIcon(QPixmap(":/res/qt.png"));
319
320
321 PDockWidget *nodeEditorDockWidget = new PDockWidget(tr(sets[3].name), this, Qt::WindowFlags(sets[3].flags));
322 nodeEditorDockWidget->setWindowTitle("Node Editor");
323 nodeEditorDockWidget->setWindowIcon(qtIcon);
324 addDockWidget(sets[3].area, nodeEditorDockWidget);
326 mNodeFlowView->setObjectName(QStringLiteral("tabEditor"));
327 nodeEditorDockWidget->setWidget(mNodeFlowView);
328
329 //Set up property dock widget
330 PDockWidget *propertyDockWidget = new PDockWidget(tr(sets[2].name), this, Qt::WindowFlags(sets[2].flags));
331 propertyDockWidget->setWindowTitle("Property Editor");
332 propertyDockWidget->setWindowIcon(qtIcon);
333 propertyDockWidget->setMinimumWidth(580);
334 addDockWidget(sets[2].area, propertyDockWidget);
336 propertyDockWidget->setWidget(mPropertyWidget);
337
338 mIoDockerWidget = new PIODockWidget(this, Qt::WindowFlags(sets[1].flags));
339 mIoDockerWidget->setWindowIcon(qtIcon);
340 addDockWidget(sets[1].area, mIoDockerWidget);
341 //windowMenu->addMenu(bottomDockWidget->colorSwatchMenu());
342
343 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
344 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
345
346 connect(mNodeFlowView->flowScene(), &Qt::QtNodeFlowScene::nodeSelected, mPropertyWidget, &PPropertyWidget::showProperty);
347 connect(mNodeFlowView->flowScene(), &Qt::QtNodeFlowScene::nodeDeselected, mPropertyWidget, &PPropertyWidget::clearProperty);
348// connect(m_moduleFlowView->module_scene, &QtNodes::QtModuleFlowScene::nodeSelected, m_propertyWidget, &PPropertyWidget::showBlockProperty);
349
350 connect(mNodeFlowView->flowScene(), &Qt::QtNodeFlowScene::nodeDoubleClicked, this, &PMainWindow::showModuleEditor);
351
353
354 // between OpenGL and property widget
355 connect(mOpenGLWidget, &POpenGLWidget::nodeSelected, [=](std::shared_ptr<Node> node) {
356 mPropertyWidget->showNodeProperty(node);
357 // TODO: high light selected node in node editor
358 auto qNodes = mNodeFlowView->flowScene()->allNodes();
359 for (auto qNode : qNodes)
360 {
361 if (dynamic_cast<Qt::QtNodeWidget*>(qNode->nodeDataModel())->getNode() == node)
362 qNode->nodeGraphicsObject().setSelected(true);
363 else
364 qNode->nodeGraphicsObject().setSelected(false);
365 }
366 });
367
368
369 connect(mNodeFlowView->flowScene(), &Qt::QtNodeFlowScene::nodeSelected, [=](Qt::QtNode& n)
370 {
371 auto model = n.nodeDataModel();
372 auto widget = dynamic_cast<Qt::QtNodeWidget*>(model);
373
374 if (widget != nullptr)
375 {
376 mOpenGLWidget->select(widget->getNode());
377 mOpenGLWidget->update();
378 }
379 });
380
381 connect(mNodeFlowView->flowScene(), &Qt::QtNodeFlowScene::nodeDeselected, [=]()
382 {
383 mOpenGLWidget->select(nullptr);
384 mOpenGLWidget->update();
385 });
386
387 connect(mAnimationWidget, &PAnimationWidget::simulationStarted, [=]()
388 {
389 mOpenGLWidget->setFocus();
390 });
391
392 connect(mAnimationWidget, &PAnimationWidget::simulationStopped, [=]()
393 {
394 });
395 }
396
397 void PMainWindow::mousePressEvent(QMouseEvent *event)
398 {
399 }
400
402 {
403 auto scn = SceneGraphFactory::instance()->active();
404
405 mSettingEditor = new PSettingEditor(nullptr);
406 mSettingEditor->setRenderEngine(mOpenGLWidget->getRenderEngine());
407
408 }
409
411 {
412 if (mSettingEditor == nullptr)
413 return;
414
416 mSettingEditor->show();
417 }
418
420 {
421 emit updateSetting();
422 }
423
424
425
426}
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)
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