Skip to content

Commit 70fa049

Browse files
committed
Treat the only loaded model as selected
1 parent d80bc64 commit 70fa049

6 files changed

Lines changed: 40 additions & 4 deletions

File tree

‎src/fea/src/main_window.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ void MainWindow::onModelAdded(uint position)
994994
R_LOG_TRACE;
995995
this->modelSubWindows->onModelAdded(position);
996996
this->modelManagerTree->onModelAdded(position);
997-
if (!this->session->isModelSelected(position))
997+
if (this->session->getModel(position).isSelected(false))
998998
{
999999
this->session->setModelSelected(position,true);
10001000
}

‎src/fea/src/session.cpp‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ void Session::removeModel(uint position)
124124
this->unlock();
125125
}
126126
emit this->modelRemoved(position);
127+
if (this->getNModels() == 1)
128+
{
129+
// Remaining model is now considered selected.
130+
emit this->modelSelectionChanged(0);
131+
}
127132
R_LOG_TRACE_OUT;
128133
}
129134

@@ -248,7 +253,7 @@ QList<uint> Session::getSelectedModelIDs() const
248253
for (uint i=0;i<this->getNModels();i++)
249254
{
250255
// Check if model is partialy selected (NOT completely unselected)
251-
if (!this->getModel(i).isSelected(false))
256+
if (this->isModelSelected(i))
252257
{
253258
selectedModelIDs.push_back(i);
254259
}
@@ -276,9 +281,14 @@ QList<uint> Session::getVisibleModelIDs() const
276281
return visibleModelIDs;
277282
}
278283

279-
bool Session::isModelSelected(uint modelID)
284+
bool Session::isModelSelected(uint modelID) const
280285
{
281286
// R_LOG_TRACE_IN;
287+
// Only loaded model is always considered selected.
288+
if (this->getNModels() == 1 && modelID == 0)
289+
{
290+
return true;
291+
}
282292
return (!this->getModel(modelID).isSelected(false));
283293
}
284294

‎src/fea/src/session.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ class Session : public QObject
9999
QList<uint> getVisibleModelIDs() const;
100100

101101
//! Return true if given model ID is selected.
102-
bool isModelSelected(uint modelID);
102+
//! If only one model is loaded it is always considered selected.
103+
bool isModelSelected(uint modelID) const;
103104

104105
//! Return list of all entity IDs.
105106
QList<SessionEntityID> getAllEntityIDs() const;

‎src/fea/src/shaders/main.frag‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ struct Light { vec3 position; vec4 ambient; vec4 diffuse; };
1515

1616
// Fraction by which a highlighted (selected) entity is moved towards white.
1717
const float highlightAmount = 0.2;
18+
// Glow added to a highlighted entity, strongest where its surface turns away from the viewer.
19+
const vec3 glowColor = vec3(0.4, 0.75, 1.0);
20+
const float glowStrength = 0.8;
21+
// Glow of elements without a surface normal (lines, points).
22+
const float glowFlat = 0.25;
1823

1924
uniform int uNumLights;
2025
uniform Light uLights[8];
@@ -44,6 +49,13 @@ void main()
4449
if (uHighlight)
4550
{
4651
color = mix(color, vec3(1.0), highlightAmount);
52+
// Projection is orthographic, the viewer looks along the eye space z axis.
53+
float rim = glowFlat;
54+
if (length(vNormal) > 1.0e-6)
55+
{
56+
rim = pow(1.0 - abs(normalize(vNormal).z), 2.0);
57+
}
58+
color = min(color + glowColor * glowStrength * rim, vec3(1.0));
4759
}
4860
gl_FragColor = vec4(color, baseColor.a);
4961
}

‎src/fea/src/shaders/rhi/main.frag‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ layout(std140, binding = 0) uniform Ubuf {
2323

2424
// Fraction by which a highlighted (selected) entity is moved towards white.
2525
const float highlightAmount = 0.2;
26+
// Glow added to a highlighted entity, strongest where its surface turns away from the viewer.
27+
const vec3 glowColor = vec3(0.4, 0.75, 1.0);
28+
const float glowStrength = 0.8;
29+
// Glow of elements without a surface normal (lines, points).
30+
const float glowFlat = 0.25;
2631

2732
// Colour map — an Nx1 strip standing in for the 1D texture of the OpenGL backend.
2833
layout(binding = 1) uniform sampler2D uColorMap;
@@ -68,6 +73,14 @@ void main()
6873
if (ubuf.params2.z > 0.5)
6974
{
7075
color = mix(color, vec3(1.0), highlightAmount);
76+
// Projection is orthographic, the viewer looks along the eye space z axis.
77+
// Expanded point quads carry the quad corner in the normal, not a surface normal.
78+
float rim = glowFlat;
79+
if (ubuf.params3.x < 0.5 && length(vNormal) > 1.0e-6)
80+
{
81+
rim = pow(1.0 - abs(normalize(vNormal).z), 2.0);
82+
}
83+
color = min(color + glowColor * glowStrength * rim, vec3(1.0));
7184
}
7285

7386
fragColor = vec4(color, baseColor.a);
562 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)