Physics Simulation & Visualization Tool 0.1
A C++ physics simulation engine with real-time 3D visualization
Loading...
Searching...
No Matches
InspectorWidget.cpp
Go to the documentation of this file.
1#include "InspectorWidget.h"
2
3#include <QTabWidget>
4#include <QVBoxLayout>
5#include <QWidget>
6
10#include "physics/PhysicsBody.h"
11
12#include "ui/ScalarWidget.h"
18
19InspectorWidget::InspectorWidget(SceneManager* sceneMgr, QWidget* parent) : QWidget(parent), sceneManager(sceneMgr) {
20 mainLayout = new QVBoxLayout(this);
21 mainLayout->setContentsMargins(5, 0, 5, 0);
22 mainLayout->setSpacing(6);
23
24 setMinimumWidth(350);
25
26 inspectorTabs = new QTabWidget(this);
27
28 transformWidget = new TransformInspectorWidget(this);
29 physicsWidget = new PhysicsInspectorWidget(this);
30 thermalWidget = new ThermalInspectorWidget(this);
31 forcesWidget = new ForcesInspectorWidget(this);
32 globalsWidget = new GlobalsInspectorWidget(sceneMgr, this);
33
34 auto* objectTab = new QWidget(inspectorTabs);
35 auto* objectLayout = new QVBoxLayout(objectTab);
36 objectLayout->setContentsMargins(6, 6, 6, 6);
37 objectLayout->setSpacing(6);
38 objectLayout->addWidget(transformWidget);
39 objectLayout->addWidget(physicsWidget);
40 objectLayout->addWidget(forcesWidget);
41 objectLayout->addStretch();
42
43 auto* thermalTab = new QWidget(inspectorTabs);
44 auto* thermalLayout = new QVBoxLayout(thermalTab);
45 thermalLayout->setContentsMargins(6, 6, 6, 6);
46 thermalLayout->setSpacing(6);
47 thermalLayout->addWidget(thermalWidget);
48 thermalLayout->addStretch();
49
50 auto* sceneTab = new QWidget(inspectorTabs);
51 auto* sceneLayout = new QVBoxLayout(sceneTab);
52 sceneLayout->setContentsMargins(6, 6, 6, 6);
53 sceneLayout->setSpacing(6);
54 sceneLayout->addWidget(globalsWidget);
55 sceneLayout->addStretch();
56
57 objectTabIndex = inspectorTabs->addTab(objectTab, "Object");
58 thermalTabIndex = inspectorTabs->addTab(thermalTab, "Thermal");
59 sceneTabIndex = inspectorTabs->addTab(sceneTab, "Scene");
60
61 mainLayout->addWidget(inspectorTabs);
62 mainLayout->addStretch();
63
64 connect(globalsWidget, &GlobalsInspectorWidget::solveRequested, this, &InspectorWidget::refresh);
65
66 refreshTimer.setInterval(100);
67 connect(&refreshTimer, &QTimer::timeout, this, &InspectorWidget::refresh);
68 refreshTimer.start();
69
71}
72
74 currentObject = obj;
75
76 transformWidget->load(obj);
77 physicsWidget->load(obj);
78 thermalWidget->load(obj);
79 forcesWidget->load(obj);
80
81 transformWidget->setVisible(true);
82 physicsWidget->setVisible(obj && obj->getPhysicsBody());
83 thermalWidget->setVisible(obj && obj->getPhysicsBody());
84 forcesWidget->setVisible(obj && obj->getPhysicsBody());
85
86 inspectorTabs->setTabEnabled(objectTabIndex, obj != nullptr);
87 inspectorTabs->setTabEnabled(thermalTabIndex, obj && obj->getPhysicsBody());
88 inspectorTabs->setCurrentIndex(objectTabIndex);
89}
90
92 currentObject = nullptr;
93
94 transformWidget->unload();
95 physicsWidget->unload();
96 thermalWidget->unload();
97 forcesWidget->unload();
98
99 transformWidget->setVisible(false);
100 physicsWidget->setVisible(false);
101 thermalWidget->setVisible(false);
102 forcesWidget->setVisible(false);
103
104 inspectorTabs->setTabEnabled(objectTabIndex, false);
105 inspectorTabs->setTabEnabled(thermalTabIndex, false);
106 inspectorTabs->setCurrentIndex(sceneTabIndex);
107}
108
109void InspectorWidget::refresh() {
110 if (!currentObject) {
111 globalsWidget->refresh();
112 return;
113 }
114
115 transformWidget->refresh();
116 physicsWidget->refresh();
117 thermalWidget->refresh();
118 forcesWidget->refresh();
119 globalsWidget->refresh();
120}
void load(SceneObject *object) override
Loads and binds this section to a scene object.
void refresh() override
Updates UI widgets from the current object's state.
void unload() override
Unloads the current object and clears section state.
void refresh() override
Updates UI widgets from the current object's state.
void loadObject(SceneObject *obj)
InspectorWidget(SceneManager *sceneMgr, QWidget *parent=nullptr)
void refresh() override
Updates UI widgets from the current object's state.
void load(SceneObject *object) override
Loads and binds this section to a scene object.
void unload() override
Unloads the current object and clears section state.
Physics::PhysicsBody * getPhysicsBody() const
Definition SceneObject.h:39
void unload() override
Unloads the current object and clears section state.
void load(SceneObject *object) override
Loads and binds this section to a scene object.
void refresh() override
Updates UI widgets from the current object's state.
void refresh() override
Updates UI widgets from the current object's state.
void unload() override
Unloads the current object and clears section state.
void load(SceneObject *object) override
Loads and binds this section to a scene object.