Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
plot/src/widget.cpp at develop · disorderedmaterials/plot · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Uh oh!
There was an error while loading.
Please reload this page
.
disorderedmaterials
/
plot
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
17
Pull requests
3
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Files
Expand file tree
develop
Breadcrumbs
plot
/
src
/
widget.cpp
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
238 lines (193 loc) · 8.3 KB
develop
Breadcrumbs
plot
/
src
/
widget.cpp
Copy path
Top
File metadata and controls
Code
Blame
238 lines (193 loc) · 8.3 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#
include
"
widget.h
"
#
include
"
material.h
"
#
include
<
QResizeEvent
>
#
include
<
Qt3DInput/QKeyboardDevice
>
#
include
<
Qt3DInput/QKeyboardHandler
>
#
include
<
Qt3DInput/QMouseHandler
>
#
include
<
Qt3DRender/QCamera
>
#
include
<
Qt3DRender/QPointLight
>
#
include
<
stdexcept
>
//
Initialise Qt resources
void
initialiseQtResources
()
{
static
auto
initialised =
false
;
if
(!initialised)
Q_INIT_RESOURCE
(shaders);
initialised =
true
;
}
using
namespace
Mildred
;
//
! Constructs a Mildred widget which is a child of \param parent.
MildredWidget::MildredWidget
(QWidget *parent) : QWidget(parent)
{
//
Initialise resources
initialiseQtResources
();
/*
* In order to get a suitable surface to draw on we must first create a full Qt3DWindow and then capture it in
* a container widget.
*/
viewWindow_ =
new
Qt3DExtras::Qt3DWindow
();
//
Create a container for the Qt3DWindow
viewContainer_ =
createWindowContainer
(viewWindow_,
this
);
//
Create our root entity
rootEntity_ =
Qt3DCore::QEntityPtr
(
new
Qt3DCore::QEntity);
//
Grab the QRenderSettings from the window
renderSettings_ = viewWindow_->
renderSettings
();
//
Create parameters
sceneDataAxesParameter_ =
new
Qt3DRender::QParameter
(
QStringLiteral
(
"
sceneDataAxes
"
),
QMatrix4x4
());
sceneDataAxesExtentsParameter_ =
new
Qt3DRender::QParameter
(
QStringLiteral
(
"
sceneDataAxesExtents
"
),
QVector3D
());
sceneDataAxesOriginParameter_ =
new
Qt3DRender::QParameter
(
QStringLiteral
(
"
sceneDataAxesOrigin
"
),
QVector3D
());
sceneDataTransformInverseParameter_ =
new
Qt3DRender::QParameter
(
QStringLiteral
(
"
sceneDataTransformInverse
"
),
QMatrix4x4
());
viewportSizeParameter_ =
new
Qt3DRender::QParameter
(
QStringLiteral
(
"
viewportSize
"
),
QVector2D
());
//
Add a mouse handler and connect it up
auto
*mouseHandler =
new
Qt3DInput::QMouseHandler
(rootEntity_.
data
());
auto
*mouseDevice =
new
Qt3DInput::QMouseDevice
(rootEntity_.
data
());
mouseHandler->
setSourceDevice
(mouseDevice);
rootEntity_->
addComponent
(mouseHandler);
connect
(mouseHandler,
SIGNAL
(
positionChanged
(Qt3DInput::QMouseEvent *)),
this
,
SLOT
(
mousePositionChanged
(Qt3DInput::QMouseEvent *)));
connect
(mouseHandler,
SIGNAL
(
pressed
(Qt3DInput::QMouseEvent *)),
this
,
SLOT
(
mouseButtonPressed
(Qt3DInput::QMouseEvent *)));
connect
(mouseHandler,
SIGNAL
(
released
(Qt3DInput::QMouseEvent *)),
this
,
SLOT
(
mouseButtonReleased
(Qt3DInput::QMouseEvent *)));
connect
(mouseHandler,
SIGNAL
(
wheel
(Qt3DInput::QWheelEvent *)),
this
,
SLOT
(
mouseWheeled
(Qt3DInput::QWheelEvent *)));
//
Construct a camera
camera_ =
new
Qt3DRender::QCamera
(rootEntity_.
data
());
//
camera_->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f, 1000.0f);
camera_->
lens
()->
setOrthographicProjection
(
0
,
width
(),
0
,
height
(),
0
.
1f
,
1000
.
0f
);
camera_->
setPosition
(
QVector3D
(
0
,
0
,
1
.
0f
));
camera_->
setViewCenter
(
QVector3D
(
0
,
0
, -
10.0
));
//
Create the framegraph
frameGraph_.
create
(renderSettings_, viewWindow_, camera_);
//
Set up basic scenegraph
createSceneGraph
();
//
Set the main root entity
viewWindow_->
setRootEntity
(rootEntity_.
data
());
//
Connect the metrics object and update
connect
(&metrics_,
SIGNAL
(
metricsChanged
()),
this
,
SLOT
(
updateTransforms
()));
}
/*
* QWidget
*/
//
! Handle QWidget resize events
/*
!
* Resizing the widget demands that the metrics information held in @class MildredMetrics is updated, ensuring the whole of the
* available drawing surface is used for visualisation.
*/
void
MildredWidget::resizeEvent
(QResizeEvent *event)
{
updateMetrics
();
//
Move the scene root position to be the centre of the XY plane and a suitable distance away
sceneRootTransform_->
setTranslation
(
QVector3D
(
width
() /
2.0
,
height
() /
2.0
, -
width
()));
//
Reset projection for new viewport
camera_->
lens
()->
setOrthographicProjection
(
0
,
width
(),
0
,
height
(),
0
.
1f
,
width
() *
2
.
0f
);
camera_->
setAspectRatio
(
float
(
width
()) /
float
(
height
()));
//
Debug objects
sceneBoundingCuboidTransform_->
setScale3D
(
QVector3D
(
width
(),
height
(),
width
()));
//
Update parameters and transforms
updateTransforms
();
updateShaderParameters
();
//
Lastly, resize our view container
viewContainer_->
resize
(
this
->
size
());
}
/*
* Metrics
*/
//
! Update metrics for current surface size
/*
!
* Updates the internal @class MildredMetrics object.
*/
void
MildredWidget::updateMetrics
() { metrics_.
update
(
width
(),
height
(), xAxis_, yAxis_); }
/*
* Appearance
*/
//
! Return whether the view is flat
bool
MildredWidget::isFlatView
()
const
{
return
flatView_; }
//
! Set whether view is flat
/*
!
* This controls whether the current view is set to fixed, flat (2D) drawing (@param flat = true) with only the x and y axes
* shown, or the view is full 3D in which case all axes (including the depth z axis) are visible.
*
* Changing the view type necessarily enforces a recalculation of the metrics object.
*/
void
MildredWidget::setFlatView
(
bool
flat)
{
if
(flatView_ == flat)
return
;
flatView_ = flat;
//
Set z-axis visibility
zAxis_->
setEnabled
(!flatView_);
//
Reset view and update
resetView
();
updateMetrics
();
}
/*
* Display Data
*/
//
! Create material for specified entity
/*
!
* Create and attach a new RenderableMaterial to the specified @param parent, with the specified @param vertexShader, @param
* geometryShader, and @param fragmentShader.
*/
RenderableMaterial *
MildredWidget::createMaterial
(Qt3DCore::QEntity *parent, RenderableMaterial::VertexShaderType vertexShader,
RenderableMaterial::GeometryShaderType geometryShader,
RenderableMaterial::FragmentShaderType fragmentShader)
{
auto
*material =
new
RenderableMaterial
(parent, vertexShader, geometryShader, fragmentShader);
//
Attach necessary parameters
material->
addParameter
(sceneDataAxesParameter_);
material->
addParameter
(sceneDataAxesExtentsParameter_);
material->
addParameter
(sceneDataAxesOriginParameter_);
material->
addParameter
(sceneDataTransformInverseParameter_);
material->
addParameter
(viewportSizeParameter_);
//
Add the material as a component on the parent
parent->
addComponent
(material);
return
material;
}
//
Return total number of data entities displayed on the graph
int
MildredWidget::nDataEntities
()
const
{
return
dataEntities_.
size
(); }
//
Add new 1-dimensional data entity for supplied data
Data1DEntity *
MildredWidget::addData1D
(
const
QString &tag)
{
//
Check for existing tag
auto
it =
std::find_if
(dataEntities_.
begin
(), dataEntities_.
end
(), [tag](
const
auto
&d) {
return
tag == d.
first
; });
if
(it != dataEntities_.
end
())
{
qDebug
() <<
QString
(
"
Data with tag '%1' already exists, so can't add it again.
\n
"
).
arg
(it->
first
);
throw
(
std::runtime_error
(
"
Duplicate DataEntity tag created.
\n
"
));
}
//
Create a new entity
auto
*entity =
new
Data1DEntity
(xAxis_, yAxis_, dataEntityParent_);
connect
(&metrics_,
SIGNAL
(
metricsChanged
()), entity,
SLOT
(
updateRenderables
()));
dataEntities_.
emplace_back
(tag, entity);
//
Add a material
auto
*material =
createMaterial
(entity, RenderableMaterial::VertexShaderType::ClippedToDataVolume,
RenderableMaterial::GeometryShaderType::LineTesselator,
RenderableMaterial::FragmentShaderType::PerVertexPhong);
entity->
setDataMaterial
(material);
entity->
setErrorMaterial
(material);
entity->
setSymbolMaterial
(material);
return
entity;
}
//
Remove data entity with the supplied data
bool
MildredWidget::removeData1D
(
const
QString &tag)
{
//
Check for existing tag
auto
it =
std::find_if
(dataEntities_.
begin
(), dataEntities_.
end
(), [tag](
const
auto
&d) {
return
tag == d.
first
; });
if
(it == dataEntities_.
end
())
{
qDebug
() <<
QString
(
"
Data with tag '%1' does not exist, so it can't be removed from the plot.
\n
"
).
arg
(it->
first
);
return
false
;
}
auto
&[entityTag, entity] = *it;
entity->
setParent
(
static_cast
<Qt3DCore::QNode *>(
nullptr
));
dataEntities_.
erase
(it);
return
true
;
}
/*
* Grouping
*/
//
Create new display group
DisplayGroup *
MildredWidget::addDisplayGroup
()
{
auto
newGroup = displayGroups_.
emplace_back
(std::make_shared<DisplayGroup>());
return
newGroup.
get
();
}
You can’t perform that action at this time.