Skip to content

Commit aa3a1b1

Browse files
committed
List visible entities in model tree order with colour markers in the 3D view, dim unselected ones
1 parent 70fa049 commit aa3a1b1

2 files changed

Lines changed: 142 additions & 40 deletions

File tree

‎src/fea/src/gl_widget.cpp‎

Lines changed: 139 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -945,17 +945,61 @@ void GLWidget::drawMessageBox(QPainter &painter, bool drawBox)
945945

946946
const Model &rModel = Application::instance()->getSession()->getModel(this->getModelID());
947947

948-
QList<QString> messages;
949-
950-
if (rModel.getDescription().isEmpty())
951-
{
952-
messages.push_back(rModel.getName());
953-
}
954-
else
955-
{
956-
messages.push_back(rModel.getName() + " (" + rModel.getDescription() + ")");
948+
QString modelName = rModel.getName();
949+
if (!rModel.getDescription().isEmpty())
950+
{
951+
modelName += " (" + rModel.getDescription() + ")";
952+
}
953+
954+
// Visible entities in the same order as in the model tree.
955+
struct EntityName
956+
{
957+
QString name;
958+
QColor color;
959+
bool selected;
960+
};
961+
QList<EntityName> entityNames;
962+
963+
const REntityGroupType treeOrder[] = { R_ENTITY_GROUP_POINT,
964+
R_ENTITY_GROUP_LINE,
965+
R_ENTITY_GROUP_SURFACE,
966+
R_ENTITY_GROUP_VOLUME,
967+
R_ENTITY_GROUP_CUT,
968+
R_ENTITY_GROUP_ISO,
969+
R_ENTITY_GROUP_STREAM_LINE,
970+
R_ENTITY_GROUP_SCALAR_FIELD,
971+
R_ENTITY_GROUP_VECTOR_FIELD };
972+
for (REntityGroupType entityType : treeOrder)
973+
{
974+
uint nEntities = 0;
975+
switch (entityType)
976+
{
977+
case R_ENTITY_GROUP_POINT: nEntities = rModel.getNPoints(); break;
978+
case R_ENTITY_GROUP_LINE: nEntities = rModel.getNLines(); break;
979+
case R_ENTITY_GROUP_SURFACE: nEntities = rModel.getNSurfaces(); break;
980+
case R_ENTITY_GROUP_VOLUME: nEntities = rModel.getNVolumes(); break;
981+
case R_ENTITY_GROUP_CUT: nEntities = rModel.getNCuts(); break;
982+
case R_ENTITY_GROUP_ISO: nEntities = rModel.getNIsos(); break;
983+
case R_ENTITY_GROUP_STREAM_LINE: nEntities = rModel.getNStreamLines(); break;
984+
case R_ENTITY_GROUP_SCALAR_FIELD: nEntities = rModel.getNScalarFields(); break;
985+
case R_ENTITY_GROUP_VECTOR_FIELD: nEntities = rModel.getNVectorFields(); break;
986+
default: break;
987+
}
988+
for (uint i=0;i<nEntities;i++)
989+
{
990+
const REntityGroup *pEntityGroup = rModel.getEntityGroupPtr(rModel.getEntityGroupID(entityType,i));
991+
if (!pEntityGroup->getData().getVisible())
992+
{
993+
continue;
994+
}
995+
int r, g, b, a;
996+
pEntityGroup->getData().getColor(r,g,b,a);
997+
entityNames.append({pEntityGroup->getName(),QColor(r,g,b),pEntityGroup->getData().getSelected()});
998+
}
957999
}
958-
messages.push_back(QString());
1000+
1001+
// Messages following the entity list.
1002+
QList<QString> messages;
9591003

9601004
if (rModel.getNSlivers() > 0)
9611005
{
@@ -1014,21 +1058,37 @@ void GLWidget::drawMessageBox(QPainter &painter, bool drawBox)
10141058
}
10151059
}
10161060

1017-
if (messages.size() == 0)
1018-
{
1019-
return;
1020-
}
1021-
10221061
int offset = 10;
10231062
int padding = 2;
10241063

10251064
int fontPixelHeight = painter.fontInfo().pixelSize();
1065+
int lineHeight = fontPixelHeight+padding;
1066+
const QFontMetrics fontMetrics = painter.fontMetrics();
1067+
1068+
// Space above and below the entity list.
1069+
int entityListGap = fontPixelHeight/2;
10261070

1027-
int sizeX = this->width() - offset - offset;
1028-
int sizeY = offset + (fontPixelHeight+padding)*messages.size();
10291071
int posX = offset;
10301072
int posY = offset;
10311073

1074+
// Entity list is limited to lines which fit between the model name and the information box.
1075+
int infoBoxTop = this->height() - offset - GLWidget::lAxisWpHeight - (offset + lineHeight*int(this->findInfoMessages().size()));
1076+
int availableHeight = infoBoxTop - posY - lineHeight*(1+int(messages.size())) - 2*entityListGap - fontMetrics.descent();
1077+
int maxEntityLines = std::max(0,availableHeight/lineHeight);
1078+
1079+
int nShownEntities = int(entityNames.size());
1080+
int nHiddenEntities = 0;
1081+
if (nShownEntities > maxEntityLines)
1082+
{
1083+
// Last line is used for the number of entities which did not fit.
1084+
nShownEntities = std::max(0,maxEntityLines-1);
1085+
nHiddenEntities = int(entityNames.size()) - nShownEntities;
1086+
}
1087+
int nEntityLines = nShownEntities + ((nHiddenEntities > 0 && maxEntityLines > 0) ? 1 : 0);
1088+
1089+
int sizeX = this->width() - offset - offset;
1090+
int sizeY = offset + lineHeight*(1+nEntityLines+int(messages.size())) + 2*entityListGap;
1091+
10321092
int colorValue = qGray(this->getGLDisplayProperties().getBgColor().rgb()) < 96 ? 255 : 0;
10331093

10341094
// Outer box
@@ -1041,10 +1101,42 @@ void GLWidget::drawMessageBox(QPainter &painter, bool drawBox)
10411101
painter.fillRect(posX,posY,sizeX,sizeY,QColor(boxColorValue,boxColorValue,boxColorValue,200));
10421102
}
10431103

1044-
painter.setPen(QColor(colorValue,colorValue,colorValue,255));
1104+
const QColor textColor(colorValue,colorValue,colorValue,255);
1105+
const int indent = fontMetrics.horizontalAdvance(" ");
1106+
const int textX = posX+padding;
1107+
painter.setPen(textColor);
1108+
1109+
// Model name.
1110+
int textY = posY + lineHeight;
1111+
painter.drawText(textX,textY,modelName);
1112+
1113+
// Entity list, entities which are not selected are drawn 40% transparent.
1114+
textY += entityListGap;
1115+
for (int i=0;i<nShownEntities;i++)
1116+
{
1117+
const EntityName &entityName = entityNames.at(i);
1118+
textY += lineHeight;
1119+
painter.setOpacity(entityName.selected ? 1.0 : 0.4);
1120+
// Entity color square edged with text color in front of the entity name.
1121+
int squareSize = fontMetrics.ascent();
1122+
int squareX = textX + indent;
1123+
painter.fillRect(squareX,textY-squareSize,squareSize,squareSize,entityName.color);
1124+
painter.drawRect(squareX,textY-squareSize,squareSize-1,squareSize-1);
1125+
painter.drawText(squareX + squareSize + squareSize/2,textY,entityName.name);
1126+
}
1127+
painter.setOpacity(1.0);
1128+
if (nHiddenEntities > 0 && maxEntityLines > 0)
1129+
{
1130+
textY += lineHeight;
1131+
painter.drawText(textX + indent,textY,"+ " + QLocale().toString(nHiddenEntities) + " " + tr("more"));
1132+
}
1133+
textY += entityListGap;
1134+
1135+
// Remaining messages.
10451136
for (int i=0;i<messages.size();i++)
10461137
{
1047-
painter.drawText(posX+padding,posY+(fontPixelHeight+padding)*(i+1),messages[i]);
1138+
textY += lineHeight;
1139+
painter.drawText(textX,textY,messages[i]);
10481140
}
10491141
R_LOG_TRACE_OUT;
10501142
}
@@ -1054,27 +1146,7 @@ void GLWidget::drawInfoBox(QPainter &painter, bool drawBox)
10541146
R_LOG_TRACE_IN;
10551147
painter.setFont(QGuiApplication::font());
10561148

1057-
QList<QString> messages;
1058-
1059-
QStringList actionMessage;
1060-
QString keyMouseMessage(this->actionEvent.getKeyMouseCombination());
1061-
QString eventMessage(GLActionEvent::toString(this->actionEvent.getType()));
1062-
1063-
if (keyMouseMessage.length() != 0)
1064-
{
1065-
actionMessage.append(keyMouseMessage);
1066-
}
1067-
if (eventMessage.length() != 0)
1068-
{
1069-
actionMessage.append(eventMessage);
1070-
}
1071-
if (actionMessage.size() > 0)
1072-
{
1073-
messages.append(tr("Action") + ": " + actionMessage.join(" - "));
1074-
}
1075-
1076-
messages.append(tr("Zoom") + ": " + QLocale().toString(double(this->scale)));
1077-
messages.append(tr("Model draw time") + ": " + QLocale().toString(this->modelDrawTime) + " [ms]");
1149+
QStringList messages = this->findInfoMessages();
10781150

10791151
if (messages.size() == 0)
10801152
{
@@ -1111,6 +1183,33 @@ void GLWidget::drawInfoBox(QPainter &painter, bool drawBox)
11111183
R_LOG_TRACE_OUT;
11121184
}
11131185

1186+
QStringList GLWidget::findInfoMessages() const
1187+
{
1188+
QStringList messages;
1189+
1190+
QStringList actionMessage;
1191+
QString keyMouseMessage(this->actionEvent.getKeyMouseCombination());
1192+
QString eventMessage(GLActionEvent::toString(this->actionEvent.getType()));
1193+
1194+
if (keyMouseMessage.length() != 0)
1195+
{
1196+
actionMessage.append(keyMouseMessage);
1197+
}
1198+
if (eventMessage.length() != 0)
1199+
{
1200+
actionMessage.append(eventMessage);
1201+
}
1202+
if (actionMessage.size() > 0)
1203+
{
1204+
messages.append(tr("Action") + ": " + actionMessage.join(" - "));
1205+
}
1206+
1207+
messages.append(tr("Zoom") + ": " + QLocale().toString(double(this->scale)));
1208+
messages.append(tr("Model draw time") + ": " + QLocale().toString(this->modelDrawTime) + " [ms]");
1209+
1210+
return messages;
1211+
}
1212+
11141213
void GLWidget::applyTransformations()
11151214
{
11161215
R_LOG_TRACE_IN;

‎src/fea/src/gl_widget.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ class GLWidget : public QWidget
253253
//! Draw information box.
254254
void drawInfoBox(QPainter &painter, bool drawBox);
255255

256+
//! Return messages displayed in information box.
257+
QStringList findInfoMessages() const;
258+
256259
//! Apply transformations.
257260
void applyTransformations();
258261

0 commit comments

Comments
 (0)